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