2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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>
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 */
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
;
54 splash_find_data(splash_decoder_t
*decoder
)
59 if (decoder
->data_type
== NULL
)
61 image_module
= preload_search_by_type(decoder
->data_type
);
62 if (image_module
== NULL
)
64 p
= preload_search_info(image_module
, MODINFO_ADDR
);
67 decoder
->data
= *(void **)p
;
68 p
= preload_search_info(image_module
, MODINFO_SIZE
);
71 decoder
->data_size
= *(size_t *)p
;
73 kprintf("splash: image@%p, size:%lu\n",
74 (void *)decoder
->data
, (long)decoder
->data_size
);
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
)) {
85 decoder
->data_size
= 0;
86 return ENODEV
; /* XXX */
89 kprintf("splash: image decoder found: %s\n", decoder
->name
);
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
;
108 if (splash_adp
!= NULL
) {
110 * If the video card has aleady been initialized, test
111 * this decoder immediately.
113 error
= splash_test(decoder
);
115 /* replace the current decoder with new one */
116 if (splash_decoder
!= NULL
)
117 error
= splash_term(splash_adp
);
123 /* register the decoder for later use */
124 for (i
= 0; i
< decoders
; ++i
) {
125 if (decoder_set
[i
] == NULL
)
128 if ((i
>= decoders
) && (decoders
% DECODER_ARRAY_DELTA
) == 0) {
129 p
= kmalloc(sizeof(*p
)*(decoders
+ DECODER_ARRAY_DELTA
),
133 if (decoder_set
!= NULL
) {
134 bcopy(decoder_set
, p
, sizeof(*p
)*decoders
);
135 kfree(decoder_set
, M_DEVBUF
);
140 decoder_set
[i
] = decoder
;
147 splash_unregister(splash_decoder_t
*decoder
)
151 if (splash_decoder
== decoder
) {
152 if ((error
= splash_term(splash_adp
)) != 0)
159 splash_init(video_adapter_t
*adp
, int (*callback
)(int, void *), void *arg
)
164 splash_callback
= callback
;
167 splash_decoder
= NULL
;
168 for (i
= 0; i
< decoders
; ++i
) {
169 if (decoder_set
[i
] == NULL
)
171 if (splash_test(decoder_set
[i
]) == 0) {
172 splash_new(decoder_set
[i
]);
175 decoder_set
[i
] = NULL
;
177 for (++i
; i
< decoders
; ++i
) {
178 decoder_set
[i
] = NULL
;
184 splash_term(video_adapter_t
*adp
)
188 if (splash_adp
!= adp
)
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
);
196 splash_decoder
= NULL
;
202 splash(video_adapter_t
*adp
, int on
)
204 if (splash_decoder
!= NULL
)
205 return (*splash_decoder
->splash
)(adp
, on
);