kernel: Replace struct device* by device_t
[dragonfly.git] / sys / dev / video / fb / splash.c
blob0bd6a0e44aaffee1bf426cbf5ab92d90dc67941f
1 /*-
2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer as
10 * the first lines of this file unmodified.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * $FreeBSD: src/sys/dev/fb/splash.c,v 1.8 2000/01/29 14:42:57 peter Exp $
27 * $DragonFly: src/sys/dev/video/fb/splash.c,v 1.6 2006/12/22 23:26:27 swildner Exp $
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/malloc.h>
34 #include <sys/linker.h>
35 #include <sys/fbio.h>
37 #include "fbreg.h"
38 #include "splashreg.h"
40 /* video adapter and image decoder */
41 static video_adapter_t *splash_adp;
42 static splash_decoder_t *splash_decoder;
44 /* decoder candidates */
45 static int decoders;
46 static splash_decoder_t **decoder_set;
47 #define DECODER_ARRAY_DELTA 4
49 /* console driver callback */
50 static int (*splash_callback)(int, void *);
51 static void *splash_arg;
53 static int
54 splash_find_data(splash_decoder_t *decoder)
56 caddr_t image_module;
57 caddr_t p;
59 if (decoder->data_type == NULL)
60 return 0;
61 image_module = preload_search_by_type(decoder->data_type);
62 if (image_module == NULL)
63 return ENOENT;
64 p = preload_search_info(image_module, MODINFO_ADDR);
65 if (p == NULL)
66 return ENOENT;
67 decoder->data = *(void **)p;
68 p = preload_search_info(image_module, MODINFO_SIZE);
69 if (p == NULL)
70 return ENOENT;
71 decoder->data_size = *(size_t *)p;
72 if (bootverbose)
73 kprintf("splash: image@%p, size:%lu\n",
74 (void *)decoder->data, (long)decoder->data_size);
75 return 0;
78 static int
79 splash_test(splash_decoder_t *decoder)
81 if (splash_find_data(decoder))
82 return ENOENT; /* XXX */
83 if (*decoder->init && (*decoder->init)(splash_adp)) {
84 decoder->data = NULL;
85 decoder->data_size = 0;
86 return ENODEV; /* XXX */
88 if (bootverbose)
89 kprintf("splash: image decoder found: %s\n", decoder->name);
90 return 0;
93 static void
94 splash_new(splash_decoder_t *decoder)
96 splash_decoder = decoder;
97 if (splash_callback != NULL)
98 (*splash_callback)(SPLASH_INIT, splash_arg);
102 splash_register(splash_decoder_t *decoder)
104 splash_decoder_t **p;
105 int error;
106 int i;
108 if (splash_adp != NULL) {
110 * If the video card has aleady been initialized, test
111 * this decoder immediately.
113 error = splash_test(decoder);
114 if (error == 0) {
115 /* replace the current decoder with new one */
116 if (splash_decoder != NULL)
117 error = splash_term(splash_adp);
118 if (error == 0)
119 splash_new(decoder);
121 return error;
122 } else {
123 /* register the decoder for later use */
124 for (i = 0; i < decoders; ++i) {
125 if (decoder_set[i] == NULL)
126 break;
128 if ((i >= decoders) && (decoders % DECODER_ARRAY_DELTA) == 0) {
129 p = kmalloc(sizeof(*p)*(decoders + DECODER_ARRAY_DELTA),
130 M_DEVBUF, M_NOWAIT);
131 if (p == NULL)
132 return ENOMEM;
133 if (decoder_set != NULL) {
134 bcopy(decoder_set, p, sizeof(*p)*decoders);
135 kfree(decoder_set, M_DEVBUF);
137 decoder_set = p;
138 i = decoders++;
140 decoder_set[i] = decoder;
143 return 0;
147 splash_unregister(splash_decoder_t *decoder)
149 int error;
151 if (splash_decoder == decoder) {
152 if ((error = splash_term(splash_adp)) != 0)
153 return error;
155 return 0;
159 splash_init(video_adapter_t *adp, int (*callback)(int, void *), void *arg)
161 int i;
163 splash_adp = adp;
164 splash_callback = callback;
165 splash_arg = arg;
167 splash_decoder = NULL;
168 for (i = 0; i < decoders; ++i) {
169 if (decoder_set[i] == NULL)
170 continue;
171 if (splash_test(decoder_set[i]) == 0) {
172 splash_new(decoder_set[i]);
173 break;
175 decoder_set[i] = NULL;
177 for (++i; i < decoders; ++i) {
178 decoder_set[i] = NULL;
180 return 0;
184 splash_term(video_adapter_t *adp)
186 int error = 0;
188 if (splash_adp != adp)
189 return EINVAL;
190 if (splash_decoder != NULL) {
191 if (splash_callback != NULL)
192 error = (*splash_callback)(SPLASH_TERM, splash_arg);
193 if (error == 0 && splash_decoder->term)
194 error = (*splash_decoder->term)(adp);
195 if (error == 0)
196 splash_decoder = NULL;
198 return error;
202 splash(video_adapter_t *adp, int on)
204 if (splash_decoder != NULL)
205 return (*splash_decoder->splash)(adp, on);
206 return ENODEV;