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