FreeBSD/Linux Kernel Cross Reference
sys/dev/fb/splash.c
1 /*-
2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
3 * All rights reserved.
4 *
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.
14 *
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.
25 *
26 */
27
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD: releng/5.2/sys/dev/fb/splash.c 119418 2003-08-24 17:55:58Z obrien $");
30
31 #include "opt_splash.h"
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/malloc.h>
36 #include <sys/linker.h>
37 #include <sys/fbio.h>
38 #include <sys/kernel.h>
39
40 #include <dev/fb/fbreg.h>
41 #include <dev/fb/splashreg.h>
42
43 MODULE_VERSION(splash, 1);
44
45 /* video adapter and image decoder */
46 static video_adapter_t *splash_adp;
47 static splash_decoder_t *splash_decoder;
48
49 /* decoder candidates */
50 static int decoders;
51 static splash_decoder_t **decoder_set;
52 #define DECODER_ARRAY_DELTA 4
53
54 /* console driver callback */
55 static int (*splash_callback)(int, void *);
56 static void *splash_arg;
57
58 static int
59 splash_find_data(splash_decoder_t *decoder)
60 {
61 caddr_t image_module;
62 caddr_t p;
63
64 if (decoder->data_type == NULL)
65 return 0;
66 image_module = preload_search_by_type(decoder->data_type);
67 if (image_module == NULL)
68 return ENOENT;
69 p = preload_search_info(image_module, MODINFO_ADDR);
70 if (p == NULL)
71 return ENOENT;
72 decoder->data = *(void **)p;
73 p = preload_search_info(image_module, MODINFO_SIZE);
74 if (p == NULL)
75 return ENOENT;
76 decoder->data_size = *(size_t *)p;
77 if (bootverbose)
78 printf("splash: image@%p, size:%lu\n",
79 (void *)decoder->data, (long)decoder->data_size);
80 return 0;
81 }
82
83 static int
84 splash_test(splash_decoder_t *decoder)
85 {
86 if (splash_find_data(decoder))
87 return ENOENT; /* XXX */
88 if (*decoder->init && (*decoder->init)(splash_adp)) {
89 decoder->data = NULL;
90 decoder->data_size = 0;
91 return ENODEV; /* XXX */
92 }
93 if (bootverbose)
94 printf("splash: image decoder found: %s\n", decoder->name);
95 return 0;
96 }
97
98 static void
99 splash_new(splash_decoder_t *decoder)
100 {
101 splash_decoder = decoder;
102 if (splash_callback != NULL)
103 (*splash_callback)(SPLASH_INIT, splash_arg);
104 }
105
106 int
107 splash_register(splash_decoder_t *decoder)
108 {
109 splash_decoder_t **p;
110 int error;
111 int i;
112
113 if (splash_adp != NULL) {
114 /*
115 * If the video card has aleady been initialized, test
116 * this decoder immediately.
117 */
118 error = splash_test(decoder);
119 if (error == 0) {
120 /* replace the current decoder with new one */
121 if (splash_decoder != NULL)
122 error = splash_term(splash_adp);
123 if (error == 0)
124 splash_new(decoder);
125 }
126 return error;
127 } else {
128 /* register the decoder for later use */
129 for (i = 0; i < decoders; ++i) {
130 if (decoder_set[i] == NULL)
131 break;
132 }
133 if ((i >= decoders) && (decoders % DECODER_ARRAY_DELTA) == 0) {
134 p = malloc(sizeof(*p)*(decoders + DECODER_ARRAY_DELTA),
135 M_DEVBUF, M_NOWAIT);
136 if (p == NULL)
137 return ENOMEM;
138 if (decoder_set != NULL) {
139 bcopy(decoder_set, p, sizeof(*p)*decoders);
140 free(decoder_set, M_DEVBUF);
141 }
142 decoder_set = p;
143 i = decoders++;
144 }
145 decoder_set[i] = decoder;
146 }
147
148 return 0;
149 }
150
151 int
152 splash_unregister(splash_decoder_t *decoder)
153 {
154 int error;
155
156 if (splash_decoder == decoder) {
157 if ((error = splash_term(splash_adp)) != 0)
158 return error;
159 }
160 return 0;
161 }
162
163 int
164 splash_init(video_adapter_t *adp, int (*callback)(int, void *), void *arg)
165 {
166 int i;
167
168 splash_adp = adp;
169 splash_callback = callback;
170 splash_arg = arg;
171
172 splash_decoder = NULL;
173 for (i = 0; i < decoders; ++i) {
174 if (decoder_set[i] == NULL)
175 continue;
176 if (splash_test(decoder_set[i]) == 0) {
177 splash_new(decoder_set[i]);
178 break;
179 }
180 decoder_set[i] = NULL;
181 }
182 for (++i; i < decoders; ++i) {
183 decoder_set[i] = NULL;
184 }
185 return 0;
186 }
187
188 int
189 splash_term(video_adapter_t *adp)
190 {
191 int error = 0;
192
193 if (splash_adp != adp)
194 return EINVAL;
195 if (splash_decoder != NULL) {
196 if (splash_callback != NULL)
197 error = (*splash_callback)(SPLASH_TERM, splash_arg);
198 if (error == 0 && splash_decoder->term)
199 error = (*splash_decoder->term)(adp);
200 if (error == 0)
201 splash_decoder = NULL;
202 }
203 return error;
204 }
205
206 int
207 splash(video_adapter_t *adp, int on)
208 {
209 if (splash_decoder != NULL)
210 return (*splash_decoder->splash)(adp, on);
211 return ENODEV;
212 }
Cache object: 5fc6d72f680bbf0cffdead40697e8f83
|