2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer as
12 * the first lines of this file unmodified.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/cdefs.h>
31 #include "opt_splash.h"
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/malloc.h>
36 #include <sys/linker.h>
38 #include <sys/kernel.h>
39 #include <sys/module.h>
41 #include <dev/fb/fbreg.h>
42 #include <dev/fb/splashreg.h>
44 MODULE_VERSION(splash, 1);
46 /* video adapter and image decoder */
47 static video_adapter_t *splash_adp;
48 static splash_decoder_t *splash_decoder;
50 /* decoder candidates */
52 static splash_decoder_t **decoder_set;
53 #define DECODER_ARRAY_DELTA 4
55 /* console driver callback */
56 static int (*splash_callback)(int, void *);
57 static void *splash_arg;
60 splash_find_data(splash_decoder_t *decoder)
66 if (decoder->data_type == NULL)
69 image_module = preload_search_by_type(decoder->data_type);
70 if (image_module == NULL)
73 ptr = preload_fetch_addr(image_module);
74 sz = preload_fetch_size(image_module);
75 if (ptr == NULL || sz == 0)
79 printf("splash: image@%p, size:%zu\n", ptr, sz);
82 decoder->data_size = sz;
87 splash_test(splash_decoder_t *decoder)
89 if (splash_find_data(decoder))
90 return ENOENT; /* XXX */
91 if (*decoder->init && (*decoder->init)(splash_adp)) {
93 decoder->data_size = 0;
94 return ENODEV; /* XXX */
97 printf("splash: image decoder found: %s\n", decoder->name);
102 splash_new(splash_decoder_t *decoder)
104 splash_decoder = decoder;
105 if (splash_callback != NULL)
106 (*splash_callback)(SPLASH_INIT, splash_arg);
110 splash_register(splash_decoder_t *decoder)
112 splash_decoder_t **p;
116 if (splash_adp != NULL) {
118 * If the video card has already been initialized, test
119 * this decoder immediately.
121 error = splash_test(decoder);
123 /* replace the current decoder with new one */
124 if (splash_decoder != NULL)
125 error = splash_term(splash_adp);
131 /* register the decoder for later use */
132 for (i = 0; i < decoders; ++i) {
133 if (decoder_set[i] == NULL)
136 if ((i >= decoders) && (decoders % DECODER_ARRAY_DELTA) == 0) {
137 p = malloc(sizeof(*p)*(decoders + DECODER_ARRAY_DELTA),
141 if (decoder_set != NULL) {
142 bcopy(decoder_set, p, sizeof(*p)*decoders);
143 free(decoder_set, M_DEVBUF);
148 decoder_set[i] = decoder;
155 splash_unregister(splash_decoder_t *decoder)
159 if (splash_decoder == decoder) {
160 if ((error = splash_term(splash_adp)) != 0)
167 splash_init(video_adapter_t *adp, int (*callback)(int, void *), void *arg)
172 splash_callback = callback;
175 splash_decoder = NULL;
176 for (i = 0; i < decoders; ++i) {
177 if (decoder_set[i] == NULL)
179 if (splash_test(decoder_set[i]) == 0) {
180 splash_new(decoder_set[i]);
183 decoder_set[i] = NULL;
185 for (++i; i < decoders; ++i) {
186 decoder_set[i] = NULL;
192 splash_term(video_adapter_t *adp)
196 if (splash_adp != adp)
198 if (splash_decoder != NULL) {
199 if (splash_callback != NULL)
200 error = (*splash_callback)(SPLASH_TERM, splash_arg);
201 if (error == 0 && splash_decoder->term)
202 error = (*splash_decoder->term)(adp);
204 splash_decoder = NULL;
210 splash(video_adapter_t *adp, int on)
212 if (splash_decoder != NULL)
213 return (*splash_decoder->splash)(adp, on);