splash.c revision 1.6 1 1.5 martin /* $NetBSD: splash.c,v 1.6 2008/05/10 15:31:05 martin Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2006 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
8 1.1 jmcneill * modification, are permitted provided that the following conditions
9 1.1 jmcneill * are met:
10 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
11 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
12 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
14 1.1 jmcneill * documentation and/or other materials provided with the distribution.
15 1.6 martin * 3. All advertising materials mentioning features or use of this software
16 1.6 martin * must display the following acknowledgement:
17 1.6 martin * This product includes software developed by the NetBSD
18 1.6 martin * Foundation, Inc. and its contributors.
19 1.6 martin * 4. Neither the name of The NetBSD Foundation nor the names of its
20 1.6 martin * contributors may be used to endorse or promote products derived
21 1.6 martin * from this software without specific prior written permission.
22 1.1 jmcneill *
23 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 1.1 jmcneill * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.1 jmcneill * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.1 jmcneill * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 1.1 jmcneill * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.1 jmcneill * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.1 jmcneill * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.1 jmcneill * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.1 jmcneill * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.1 jmcneill * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.1 jmcneill * POSSIBILITY OF SUCH DAMAGE.
34 1.1 jmcneill */
35 1.1 jmcneill
36 1.1 jmcneill #include <sys/cdefs.h>
37 1.5 martin __KERNEL_RCSID(0, "$NetBSD: splash.c,v 1.6 2008/05/10 15:31:05 martin Exp $");
38 1.1 jmcneill
39 1.1 jmcneill #include "opt_splash.h"
40 1.1 jmcneill
41 1.1 jmcneill /* XXX */
42 1.1 jmcneill #define NSPLASH8 1
43 1.1 jmcneill #define NSPLASH16 1
44 1.1 jmcneill #define NSPLASH32 1
45 1.1 jmcneill
46 1.1 jmcneill #include <sys/param.h>
47 1.1 jmcneill #include <sys/systm.h>
48 1.1 jmcneill #include <sys/types.h>
49 1.1 jmcneill #include <sys/kernel.h>
50 1.1 jmcneill #include <sys/kthread.h>
51 1.1 jmcneill
52 1.1 jmcneill #include <dev/splash/splash.h>
53 1.1 jmcneill
54 1.1 jmcneill #if !defined(SPLASHSCREEN) && defined(SPLASHSCREEN_PROGRESS)
55 1.1 jmcneill #error "options SPLASHSCREEN_PROGRESS requires SPLASHSCREEN"
56 1.1 jmcneill #endif
57 1.1 jmcneill
58 1.1 jmcneill #ifdef __HAVE_CPU_COUNTER
59 1.4 ad #include <sys/cpu.h>
60 1.1 jmcneill #include <machine/cpu_counter.h>
61 1.1 jmcneill #endif
62 1.1 jmcneill
63 1.1 jmcneill #ifndef SPLASHSCREEN_IMAGE
64 1.1 jmcneill #define SPLASHSCREEN_IMAGE "dev/splash/images/netbsd.h"
65 1.1 jmcneill #endif
66 1.1 jmcneill
67 1.1 jmcneill #ifdef SPLASHSCREEN
68 1.1 jmcneill #include SPLASHSCREEN_IMAGE
69 1.1 jmcneill
70 1.1 jmcneill #ifdef SPLASHSCREEN_PROGRESS
71 1.1 jmcneill struct splash_progress *splash_progress_state;
72 1.1 jmcneill #ifdef __HAVE_CPU_COUNTER
73 1.1 jmcneill static uint64_t splash_last_update;
74 1.1 jmcneill #endif
75 1.1 jmcneill #endif
76 1.1 jmcneill
77 1.1 jmcneill #if NSPLASH8 > 0
78 1.1 jmcneill static void splash_render8(struct splash_info *, const char *, int,
79 1.1 jmcneill int, int, int, int);
80 1.1 jmcneill #endif
81 1.1 jmcneill #if NSPLASH16 > 0
82 1.1 jmcneill static void splash_render16(struct splash_info *, const char *, int,
83 1.1 jmcneill int, int, int, int);
84 1.1 jmcneill #endif
85 1.1 jmcneill #if NSPLASH32 > 0
86 1.1 jmcneill static void splash_render32(struct splash_info *, const char *, int,
87 1.1 jmcneill int, int, int, int);
88 1.1 jmcneill #endif
89 1.1 jmcneill
90 1.1 jmcneill void
91 1.1 jmcneill splash_render(struct splash_info *si, int flg)
92 1.1 jmcneill {
93 1.1 jmcneill int xoff, yoff;
94 1.1 jmcneill
95 1.1 jmcneill /* XXX */
96 1.1 jmcneill if (flg & SPLASH_F_CENTER) {
97 1.1 jmcneill xoff = (si->si_width - _splash_width) / 2;
98 1.1 jmcneill yoff = (si->si_height - _splash_height) / 2;
99 1.1 jmcneill } else
100 1.1 jmcneill xoff = yoff = 0;
101 1.1 jmcneill
102 1.1 jmcneill switch (si->si_depth) {
103 1.1 jmcneill #if NSPLASH8 > 0
104 1.1 jmcneill case 8:
105 1.1 jmcneill splash_render8(si, _splash_header_data, xoff, yoff,
106 1.1 jmcneill _splash_width, _splash_height, flg);
107 1.1 jmcneill break;
108 1.1 jmcneill #endif
109 1.1 jmcneill #if NSPLASH16 > 0
110 1.1 jmcneill case 16:
111 1.1 jmcneill splash_render16(si, _splash_header_data, xoff, yoff,
112 1.1 jmcneill _splash_width, _splash_height, flg);
113 1.1 jmcneill break;
114 1.1 jmcneill #endif
115 1.1 jmcneill #if NSPLASH32 > 0
116 1.1 jmcneill case 32:
117 1.1 jmcneill splash_render32(si, _splash_header_data, xoff, yoff,
118 1.1 jmcneill _splash_width, _splash_height, flg);
119 1.1 jmcneill break;
120 1.1 jmcneill #endif
121 1.1 jmcneill default:
122 1.1 jmcneill aprint_error("WARNING: Splash not supported at %dbpp\n",
123 1.1 jmcneill si->si_depth);
124 1.1 jmcneill break;
125 1.1 jmcneill }
126 1.1 jmcneill
127 1.1 jmcneill return;
128 1.1 jmcneill }
129 1.1 jmcneill
130 1.1 jmcneill #if NSPLASH8 > 0
131 1.1 jmcneill static void
132 1.1 jmcneill splash_render8(struct splash_info *si, const char *data, int xoff, int yoff,
133 1.1 jmcneill int swidth, int sheight, int flg)
134 1.1 jmcneill {
135 1.1 jmcneill const char *p;
136 1.1 jmcneill u_char *fb, pix;
137 1.1 jmcneill int x, y, i;
138 1.1 jmcneill int filled;
139 1.1 jmcneill
140 1.1 jmcneill fb = si->si_bits;
141 1.1 jmcneill if (flg & SPLASH_F_FILL)
142 1.1 jmcneill filled = 0;
143 1.1 jmcneill else
144 1.1 jmcneill filled = 1;
145 1.1 jmcneill
146 1.1 jmcneill p = data;
147 1.1 jmcneill fb += xoff + (yoff * si->si_width);
148 1.1 jmcneill for (y = 0; y < sheight; y++) {
149 1.1 jmcneill for (x = 0; x < swidth; x++) {
150 1.1 jmcneill pix = *p++;
151 1.1 jmcneill pix += SPLASH_CMAP_OFFSET;
152 1.1 jmcneill if (filled == 0) {
153 1.1 jmcneill for (i = 0; i < (si->si_width * si->si_height);
154 1.1 jmcneill i++)
155 1.1 jmcneill si->si_bits[i] = pix;
156 1.1 jmcneill filled = 1;
157 1.1 jmcneill }
158 1.1 jmcneill fb[x] = pix;
159 1.1 jmcneill }
160 1.1 jmcneill fb += si->si_width;
161 1.1 jmcneill }
162 1.1 jmcneill
163 1.1 jmcneill /* If we've just written to the shadow fb, copy it to the display */
164 1.1 jmcneill if (si->si_hwbits) {
165 1.1 jmcneill if (flg & SPLASH_F_FILL) {
166 1.1 jmcneill memcpy(si->si_hwbits, si->si_bits,
167 1.1 jmcneill si->si_width*si->si_height);
168 1.1 jmcneill } else {
169 1.1 jmcneill u_char *rp, *hrp;
170 1.1 jmcneill
171 1.1 jmcneill rp = si->si_bits + xoff + (yoff * si->si_width);
172 1.1 jmcneill hrp = si->si_hwbits + xoff + (yoff * si->si_width);
173 1.1 jmcneill
174 1.1 jmcneill for (y = 0; y < sheight; y++) {
175 1.1 jmcneill memcpy(hrp, rp, swidth);
176 1.1 jmcneill hrp += si->si_stride;
177 1.1 jmcneill rp += si->si_stride;
178 1.1 jmcneill }
179 1.1 jmcneill }
180 1.1 jmcneill }
181 1.1 jmcneill
182 1.1 jmcneill return;
183 1.1 jmcneill }
184 1.1 jmcneill #endif /* !NSPLASH8 > 0 */
185 1.1 jmcneill
186 1.1 jmcneill #if NSPLASH16 > 0
187 1.1 jmcneill #define RGBTO16(b, o, x, c) \
188 1.1 jmcneill do { \
189 1.1 jmcneill uint16_t *_ptr = (uint16_t *)(&(b)[(o)]); \
190 1.1 jmcneill *_ptr = (((c)[(x)*3+0] / 8) << 11) | \
191 1.1 jmcneill (((c)[(x)*3+1] / 4) << 5) | \
192 1.1 jmcneill (((c)[(x)*3+2] / 8) << 0); \
193 1.1 jmcneill } while (0)
194 1.1 jmcneill
195 1.1 jmcneill static void
196 1.1 jmcneill splash_render16(struct splash_info *si, const char *data, int xoff, int yoff,
197 1.1 jmcneill int swidth, int sheight, int flg)
198 1.1 jmcneill {
199 1.1 jmcneill const char *d;
200 1.1 jmcneill u_char *fb, *p;
201 1.1 jmcneill u_char pix[3];
202 1.1 jmcneill int x, y, i;
203 1.1 jmcneill int filled;
204 1.1 jmcneill
205 1.1 jmcneill fb = si->si_bits;
206 1.1 jmcneill
207 1.1 jmcneill if (flg & SPLASH_F_FILL)
208 1.1 jmcneill filled = 0;
209 1.1 jmcneill else
210 1.1 jmcneill filled = 1;
211 1.1 jmcneill
212 1.1 jmcneill d = data;
213 1.1 jmcneill fb += xoff * 2 + yoff * si->si_stride;
214 1.1 jmcneill
215 1.1 jmcneill for (y = 0; y < sheight; y++) {
216 1.1 jmcneill for (x = 0; x < swidth; x++) {
217 1.1 jmcneill _SPLASH_HEADER_PIXEL(d, pix);
218 1.1 jmcneill if (filled == 0) {
219 1.1 jmcneill p = si->si_bits;
220 1.1 jmcneill i = 0;
221 1.1 jmcneill while (i < si->si_height*si->si_stride) {
222 1.1 jmcneill RGBTO16(p, i, 0, pix);
223 1.1 jmcneill i += 2;
224 1.1 jmcneill }
225 1.1 jmcneill filled = 1;
226 1.1 jmcneill }
227 1.1 jmcneill RGBTO16(fb, x*2, 0, pix);
228 1.1 jmcneill }
229 1.1 jmcneill fb += si->si_stride;
230 1.1 jmcneill }
231 1.1 jmcneill
232 1.1 jmcneill /* If we've just written to the shadow fb, copy it to the display */
233 1.1 jmcneill if (si->si_hwbits) {
234 1.1 jmcneill if (flg & SPLASH_F_FILL) {
235 1.1 jmcneill memcpy(si->si_hwbits, si->si_bits,
236 1.1 jmcneill si->si_height*si->si_stride);
237 1.1 jmcneill } else {
238 1.1 jmcneill u_char *rp, *hrp;
239 1.1 jmcneill
240 1.1 jmcneill rp = si->si_bits + (xoff * 2) + (yoff * si->si_stride);
241 1.1 jmcneill hrp = si->si_hwbits + (xoff * 2) +
242 1.1 jmcneill (yoff * si->si_stride);
243 1.1 jmcneill
244 1.1 jmcneill for (y = 0; y < sheight; y++) {
245 1.1 jmcneill memcpy(hrp, rp, swidth * 2);
246 1.1 jmcneill rp += si->si_stride;
247 1.1 jmcneill hrp += si->si_stride;
248 1.1 jmcneill }
249 1.1 jmcneill }
250 1.1 jmcneill }
251 1.1 jmcneill
252 1.1 jmcneill return;
253 1.1 jmcneill }
254 1.1 jmcneill #undef RGBTO16
255 1.1 jmcneill #endif /* !NSPLASH16 > 0 */
256 1.1 jmcneill
257 1.1 jmcneill #if NSPLASH32 > 0
258 1.1 jmcneill static void
259 1.1 jmcneill splash_render32(struct splash_info *si, const char *data, int xoff, int yoff,
260 1.1 jmcneill int swidth, int sheight, int flg)
261 1.1 jmcneill {
262 1.1 jmcneill const char *d;
263 1.1 jmcneill u_char *fb, *p;
264 1.1 jmcneill u_char pix[3];
265 1.1 jmcneill int x, y, i;
266 1.1 jmcneill int filled;
267 1.1 jmcneill
268 1.1 jmcneill fb = si->si_bits;
269 1.1 jmcneill
270 1.1 jmcneill if (flg & SPLASH_F_FILL)
271 1.1 jmcneill filled = 0;
272 1.1 jmcneill else
273 1.1 jmcneill filled = 1;
274 1.1 jmcneill
275 1.1 jmcneill d = data;
276 1.1 jmcneill fb += xoff * 4 + yoff * si->si_stride;
277 1.1 jmcneill
278 1.1 jmcneill for (y = 0; y < sheight; y++) {
279 1.1 jmcneill for (x = 0; x < swidth; x++) {
280 1.1 jmcneill _SPLASH_HEADER_PIXEL(d, pix);
281 1.1 jmcneill if (filled == 0) {
282 1.1 jmcneill p = si->si_bits;
283 1.1 jmcneill i = 0;
284 1.1 jmcneill while (i < si->si_height*si->si_stride) {
285 1.1 jmcneill p[i++] = pix[2];
286 1.1 jmcneill p[i++] = pix[1];
287 1.1 jmcneill p[i++] = pix[0];
288 1.1 jmcneill p[i++] = 0;
289 1.1 jmcneill }
290 1.1 jmcneill filled = 1;
291 1.1 jmcneill }
292 1.1 jmcneill fb[x*4+0] = pix[2];
293 1.1 jmcneill fb[x*4+1] = pix[1];
294 1.1 jmcneill fb[x*4+2] = pix[0];
295 1.1 jmcneill fb[x*4+3] = 0;
296 1.1 jmcneill }
297 1.1 jmcneill fb += si->si_stride;
298 1.1 jmcneill }
299 1.1 jmcneill
300 1.1 jmcneill /* If we've just written to the shadow fb, copy it to the display */
301 1.1 jmcneill if (si->si_hwbits) {
302 1.1 jmcneill if (flg & SPLASH_F_FILL) {
303 1.1 jmcneill memcpy(si->si_hwbits, si->si_bits,
304 1.1 jmcneill si->si_height*si->si_stride);
305 1.1 jmcneill } else {
306 1.1 jmcneill u_char *rp, *hrp;
307 1.1 jmcneill
308 1.1 jmcneill rp = si->si_bits + (xoff * 4) + (yoff * si->si_stride);
309 1.1 jmcneill hrp = si->si_hwbits + (xoff * 4) +
310 1.1 jmcneill (yoff * si->si_stride);
311 1.1 jmcneill
312 1.1 jmcneill for (y = 0; y < sheight; y++) {
313 1.1 jmcneill memcpy(hrp, rp, swidth * 4);
314 1.1 jmcneill rp += si->si_stride;
315 1.1 jmcneill hrp += si->si_stride;
316 1.1 jmcneill }
317 1.1 jmcneill }
318 1.1 jmcneill }
319 1.1 jmcneill
320 1.1 jmcneill return;
321 1.1 jmcneill }
322 1.1 jmcneill #endif /* !NSPLASH32 > 0 */
323 1.1 jmcneill
324 1.1 jmcneill #ifdef SPLASHSCREEN_PROGRESS
325 1.1 jmcneill
326 1.1 jmcneill static void
327 1.1 jmcneill splash_progress_render(struct splash_progress *sp)
328 1.1 jmcneill {
329 1.1 jmcneill struct splash_info *si;
330 1.1 jmcneill int i;
331 1.1 jmcneill int w;
332 1.1 jmcneill int spacing;
333 1.1 jmcneill int xoff;
334 1.1 jmcneill int yoff;
335 1.1 jmcneill int flg;
336 1.1 jmcneill
337 1.1 jmcneill si = sp->sp_si;
338 1.1 jmcneill flg = 0;
339 1.1 jmcneill
340 1.1 jmcneill /* where should we draw the pulsers? */
341 1.1 jmcneill yoff = (si->si_height / 8) * 7;
342 1.1 jmcneill w = _pulse_off_width * SPLASH_PROGRESS_NSTATES;
343 1.1 jmcneill xoff = (si->si_width / 4) * 3;
344 1.1 jmcneill spacing = _pulse_off_width; /* XXX */
345 1.1 jmcneill
346 1.1 jmcneill for (i = 0; i < SPLASH_PROGRESS_NSTATES; i++) {
347 1.1 jmcneill const char *d = (sp->sp_state == i ? _pulse_on_header_data :
348 1.1 jmcneill _pulse_off_header_data);
349 1.1 jmcneill switch (si->si_depth) {
350 1.1 jmcneill #if NSPLASH8 > 0
351 1.1 jmcneill case 8:
352 1.1 jmcneill splash_render8(si, d, (xoff + (i * spacing)),
353 1.1 jmcneill yoff, _pulse_off_width, _pulse_off_height, flg);
354 1.1 jmcneill break;
355 1.1 jmcneill #endif
356 1.1 jmcneill #if NSPLASH16 > 0
357 1.1 jmcneill case 16:
358 1.1 jmcneill splash_render16(si, d, (xoff + (i * spacing)),
359 1.1 jmcneill yoff, _pulse_off_width, _pulse_off_height, flg);
360 1.1 jmcneill break;
361 1.1 jmcneill #endif
362 1.1 jmcneill #if NSPLASH32 > 0
363 1.1 jmcneill case 32:
364 1.1 jmcneill splash_render32(si, d, (xoff + (i * spacing)),
365 1.1 jmcneill yoff, _pulse_off_width, _pulse_off_height, flg);
366 1.1 jmcneill break;
367 1.1 jmcneill #endif
368 1.1 jmcneill default:
369 1.1 jmcneill /* do nothing */
370 1.1 jmcneill break;
371 1.1 jmcneill }
372 1.1 jmcneill }
373 1.1 jmcneill }
374 1.1 jmcneill
375 1.1 jmcneill static int
376 1.1 jmcneill splash_progress_stop(struct device *dev)
377 1.1 jmcneill {
378 1.1 jmcneill struct splash_progress *sp;
379 1.1 jmcneill
380 1.1 jmcneill sp = (struct splash_progress *)dev;
381 1.1 jmcneill sp->sp_running = 0;
382 1.1 jmcneill
383 1.1 jmcneill return 0;
384 1.1 jmcneill }
385 1.1 jmcneill
386 1.1 jmcneill void
387 1.1 jmcneill splash_progress_init(struct splash_progress *sp)
388 1.1 jmcneill {
389 1.1 jmcneill #ifdef __HAVE_CPU_COUNTER
390 1.1 jmcneill if (cpu_hascounter())
391 1.1 jmcneill splash_last_update = cpu_counter();
392 1.1 jmcneill else
393 1.1 jmcneill splash_last_update = 0;
394 1.1 jmcneill #endif
395 1.1 jmcneill
396 1.1 jmcneill sp->sp_running = 1;
397 1.1 jmcneill sp->sp_force = 0;
398 1.1 jmcneill splash_progress_state = sp;
399 1.1 jmcneill splash_progress_render(sp);
400 1.1 jmcneill config_finalize_register((struct device *)sp, splash_progress_stop);
401 1.1 jmcneill
402 1.1 jmcneill return;
403 1.1 jmcneill }
404 1.1 jmcneill
405 1.1 jmcneill void
406 1.1 jmcneill splash_progress_update(struct splash_progress *sp)
407 1.1 jmcneill {
408 1.1 jmcneill if (sp->sp_running == 0 && sp->sp_force == 0)
409 1.1 jmcneill return;
410 1.1 jmcneill
411 1.1 jmcneill #ifdef __HAVE_CPU_COUNTER
412 1.1 jmcneill if (cpu_hascounter()) {
413 1.1 jmcneill uint64_t now;
414 1.1 jmcneill
415 1.1 jmcneill if (splash_last_update == 0) {
416 1.1 jmcneill splash_last_update = cpu_counter();
417 1.1 jmcneill } else {
418 1.1 jmcneill now = cpu_counter();
419 1.3 freza if (splash_last_update + cpu_frequency(curcpu())/4 >
420 1.3 freza now)
421 1.1 jmcneill return;
422 1.1 jmcneill splash_last_update = now;
423 1.1 jmcneill }
424 1.1 jmcneill }
425 1.1 jmcneill #endif
426 1.1 jmcneill sp->sp_state++;
427 1.1 jmcneill if (sp->sp_state >= SPLASH_PROGRESS_NSTATES)
428 1.1 jmcneill sp->sp_state = 0;
429 1.1 jmcneill
430 1.1 jmcneill splash_progress_render(sp);
431 1.1 jmcneill }
432 1.1 jmcneill
433 1.1 jmcneill #endif /* !SPLASHSCREEN_PROGRESS */
434 1.1 jmcneill
435 1.1 jmcneill #endif /* !SPLASHSCREEN */
436