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 __FBSDID("$FreeBSD$");
33 #include "opt_splash.h"
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/malloc.h>
38 #include <sys/linker.h>
40 #include <sys/kernel.h>
41 #include <sys/module.h>
43 #include <dev/fb/fbreg.h>
44 #include <dev/fb/splashreg.h>
46 MODULE_VERSION(splash, 1);
48 /* video adapter and image decoder */
49 static video_adapter_t *splash_adp;
50 static splash_decoder_t *splash_decoder;
52 /* decoder candidates */
54 static splash_decoder_t **decoder_set;
55 #define DECODER_ARRAY_DELTA 4
57 /* console driver callback */
58 static int (*splash_callback)(int, void *);
59 static void *splash_arg;
62 splash_find_data(splash_decoder_t *decoder)
68 if (decoder->data_type == NULL)
71 image_module = preload_search_by_type(decoder->data_type);
72 if (image_module == NULL)
75 ptr = preload_fetch_addr(image_module);
76 sz = preload_fetch_size(image_module);
77 if (ptr == NULL || sz == 0)
81 printf("splash: image@%p, size:%zu\n", ptr, sz);
84 decoder->data_size = sz;
89 splash_test(splash_decoder_t *decoder)
91 if (splash_find_data(decoder))
92 return ENOENT; /* XXX */
93 if (*decoder->init && (*decoder->init)(splash_adp)) {
95 decoder->data_size = 0;
96 return ENODEV; /* XXX */
99 printf("splash: image decoder found: %s\n", decoder->name);
104 splash_new(splash_decoder_t *decoder)
106 splash_decoder = decoder;
107 if (splash_callback != NULL)
108 (*splash_callback)(SPLASH_INIT, splash_arg);
112 splash_register(splash_decoder_t *decoder)
114 splash_decoder_t **p;
118 if (splash_adp != NULL) {
120 * If the video card has already been initialized, test
121 * this decoder immediately.
123 error = splash_test(decoder);
125 /* replace the current decoder with new one */
126 if (splash_decoder != NULL)
127 error = splash_term(splash_adp);
133 /* register the decoder for later use */
134 for (i = 0; i < decoders; ++i) {
135 if (decoder_set[i] == NULL)
138 if ((i >= decoders) && (decoders % DECODER_ARRAY_DELTA) == 0) {
139 p = malloc(sizeof(*p)*(decoders + DECODER_ARRAY_DELTA),
143 if (decoder_set != NULL) {
144 bcopy(decoder_set, p, sizeof(*p)*decoders);
145 free(decoder_set, M_DEVBUF);
150 decoder_set[i] = decoder;
157 splash_unregister(splash_decoder_t *decoder)
161 if (splash_decoder == decoder) {
162 if ((error = splash_term(splash_adp)) != 0)
169 splash_init(video_adapter_t *adp, int (*callback)(int, void *), void *arg)
174 splash_callback = callback;
177 splash_decoder = NULL;
178 for (i = 0; i < decoders; ++i) {
179 if (decoder_set[i] == NULL)
181 if (splash_test(decoder_set[i]) == 0) {
182 splash_new(decoder_set[i]);
185 decoder_set[i] = NULL;
187 for (++i; i < decoders; ++i) {
188 decoder_set[i] = NULL;
194 splash_term(video_adapter_t *adp)
198 if (splash_adp != adp)
200 if (splash_decoder != NULL) {
201 if (splash_callback != NULL)
202 error = (*splash_callback)(SPLASH_TERM, splash_arg);
203 if (error == 0 && splash_decoder->term)
204 error = (*splash_decoder->term)(adp);
206 splash_decoder = NULL;
212 splash(video_adapter_t *adp, int on)
214 if (splash_decoder != NULL)
215 return (*splash_decoder->splash)(adp, on);