xref: /dflybsd-src/sys/dev/video/fb/splash.c (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino /*-
286d7f5d3SJohn Marino  * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
386d7f5d3SJohn Marino  * All rights reserved.
486d7f5d3SJohn Marino  *
586d7f5d3SJohn Marino  * Redistribution and use in source and binary forms, with or without
686d7f5d3SJohn Marino  * modification, are permitted provided that the following conditions
786d7f5d3SJohn Marino  * are met:
886d7f5d3SJohn Marino  * 1. Redistributions of source code must retain the above copyright
986d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer as
1086d7f5d3SJohn Marino  *    the first lines of this file unmodified.
1186d7f5d3SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
1286d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
1386d7f5d3SJohn Marino  *    documentation and/or other materials provided with the distribution.
1486d7f5d3SJohn Marino  *
1586d7f5d3SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1686d7f5d3SJohn Marino  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1786d7f5d3SJohn Marino  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1886d7f5d3SJohn Marino  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1986d7f5d3SJohn Marino  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2086d7f5d3SJohn Marino  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2186d7f5d3SJohn Marino  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2286d7f5d3SJohn Marino  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2386d7f5d3SJohn Marino  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2486d7f5d3SJohn Marino  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2586d7f5d3SJohn Marino  *
2686d7f5d3SJohn Marino  * $FreeBSD: src/sys/dev/fb/splash.c,v 1.8 2000/01/29 14:42:57 peter Exp $
2786d7f5d3SJohn Marino  * $DragonFly: src/sys/dev/video/fb/splash.c,v 1.6 2006/12/22 23:26:27 swildner Exp $
2886d7f5d3SJohn Marino  */
2986d7f5d3SJohn Marino 
3086d7f5d3SJohn Marino #include <sys/param.h>
3186d7f5d3SJohn Marino #include <sys/systm.h>
3286d7f5d3SJohn Marino #include <sys/kernel.h>
3386d7f5d3SJohn Marino #include <sys/malloc.h>
3486d7f5d3SJohn Marino #include <sys/linker.h>
3586d7f5d3SJohn Marino #include <sys/fbio.h>
3686d7f5d3SJohn Marino 
3786d7f5d3SJohn Marino #include "fbreg.h"
3886d7f5d3SJohn Marino #include "splashreg.h"
3986d7f5d3SJohn Marino 
4086d7f5d3SJohn Marino /* video adapter and image decoder */
4186d7f5d3SJohn Marino static video_adapter_t	*splash_adp;
4286d7f5d3SJohn Marino static splash_decoder_t	*splash_decoder;
4386d7f5d3SJohn Marino 
4486d7f5d3SJohn Marino /* decoder candidates */
4586d7f5d3SJohn Marino static int		decoders;
4686d7f5d3SJohn Marino static splash_decoder_t **decoder_set;
4786d7f5d3SJohn Marino #define DECODER_ARRAY_DELTA 4
4886d7f5d3SJohn Marino 
4986d7f5d3SJohn Marino /* console driver callback */
5086d7f5d3SJohn Marino static int		(*splash_callback)(int, void *);
5186d7f5d3SJohn Marino static void		*splash_arg;
5286d7f5d3SJohn Marino 
5386d7f5d3SJohn Marino static int
splash_find_data(splash_decoder_t * decoder)5486d7f5d3SJohn Marino splash_find_data(splash_decoder_t *decoder)
5586d7f5d3SJohn Marino {
5686d7f5d3SJohn Marino         caddr_t image_module;
5786d7f5d3SJohn Marino 	caddr_t p;
5886d7f5d3SJohn Marino 
5986d7f5d3SJohn Marino 	if (decoder->data_type == NULL)
6086d7f5d3SJohn Marino 		return 0;
6186d7f5d3SJohn Marino 	image_module = preload_search_by_type(decoder->data_type);
6286d7f5d3SJohn Marino 	if (image_module == NULL)
6386d7f5d3SJohn Marino 		return ENOENT;
6486d7f5d3SJohn Marino 	p = preload_search_info(image_module, MODINFO_ADDR);
6586d7f5d3SJohn Marino 	if (p == NULL)
6686d7f5d3SJohn Marino 		return ENOENT;
6786d7f5d3SJohn Marino 	decoder->data = *(void **)p;
6886d7f5d3SJohn Marino 	p = preload_search_info(image_module, MODINFO_SIZE);
6986d7f5d3SJohn Marino 	if (p == NULL)
7086d7f5d3SJohn Marino 		return ENOENT;
7186d7f5d3SJohn Marino 	decoder->data_size = *(size_t *)p;
7286d7f5d3SJohn Marino 	if (bootverbose)
7386d7f5d3SJohn Marino 		kprintf("splash: image@%p, size:%lu\n",
7486d7f5d3SJohn Marino 		       (void *)decoder->data, (long)decoder->data_size);
7586d7f5d3SJohn Marino 	return 0;
7686d7f5d3SJohn Marino }
7786d7f5d3SJohn Marino 
7886d7f5d3SJohn Marino static int
splash_test(splash_decoder_t * decoder)7986d7f5d3SJohn Marino splash_test(splash_decoder_t *decoder)
8086d7f5d3SJohn Marino {
8186d7f5d3SJohn Marino 	if (splash_find_data(decoder))
8286d7f5d3SJohn Marino 		return ENOENT;	/* XXX */
8386d7f5d3SJohn Marino 	if (*decoder->init && (*decoder->init)(splash_adp)) {
8486d7f5d3SJohn Marino 		decoder->data = NULL;
8586d7f5d3SJohn Marino 		decoder->data_size = 0;
8686d7f5d3SJohn Marino 		return ENODEV;	/* XXX */
8786d7f5d3SJohn Marino 	}
8886d7f5d3SJohn Marino 	if (bootverbose)
8986d7f5d3SJohn Marino 		kprintf("splash: image decoder found: %s\n", decoder->name);
9086d7f5d3SJohn Marino 	return 0;
9186d7f5d3SJohn Marino }
9286d7f5d3SJohn Marino 
9386d7f5d3SJohn Marino static void
splash_new(splash_decoder_t * decoder)9486d7f5d3SJohn Marino splash_new(splash_decoder_t *decoder)
9586d7f5d3SJohn Marino {
9686d7f5d3SJohn Marino 	splash_decoder = decoder;
9786d7f5d3SJohn Marino 	if (splash_callback != NULL)
9886d7f5d3SJohn Marino 		(*splash_callback)(SPLASH_INIT, splash_arg);
9986d7f5d3SJohn Marino }
10086d7f5d3SJohn Marino 
10186d7f5d3SJohn Marino int
splash_register(splash_decoder_t * decoder)10286d7f5d3SJohn Marino splash_register(splash_decoder_t *decoder)
10386d7f5d3SJohn Marino {
10486d7f5d3SJohn Marino 	splash_decoder_t **p;
10586d7f5d3SJohn Marino 	int error;
10686d7f5d3SJohn Marino 	int i;
10786d7f5d3SJohn Marino 
10886d7f5d3SJohn Marino 	if (splash_adp != NULL) {
10986d7f5d3SJohn Marino 		/*
11086d7f5d3SJohn Marino 		 * If the video card has aleady been initialized, test
11186d7f5d3SJohn Marino 		 * this decoder immediately.
11286d7f5d3SJohn Marino 		 */
11386d7f5d3SJohn Marino 		error = splash_test(decoder);
11486d7f5d3SJohn Marino 		if (error == 0) {
11586d7f5d3SJohn Marino 			/* replace the current decoder with new one */
11686d7f5d3SJohn Marino 			if (splash_decoder != NULL)
11786d7f5d3SJohn Marino 				error = splash_term(splash_adp);
11886d7f5d3SJohn Marino 			if (error == 0)
11986d7f5d3SJohn Marino 				splash_new(decoder);
12086d7f5d3SJohn Marino 		}
12186d7f5d3SJohn Marino 		return error;
12286d7f5d3SJohn Marino 	} else {
12386d7f5d3SJohn Marino 		/* register the decoder for later use */
12486d7f5d3SJohn Marino 		for (i = 0; i < decoders; ++i) {
12586d7f5d3SJohn Marino 			if (decoder_set[i] == NULL)
12686d7f5d3SJohn Marino 				break;
12786d7f5d3SJohn Marino 		}
12886d7f5d3SJohn Marino 		if ((i >= decoders) && (decoders % DECODER_ARRAY_DELTA) == 0) {
12986d7f5d3SJohn Marino 			p = kmalloc(sizeof(*p)*(decoders + DECODER_ARRAY_DELTA),
13086d7f5d3SJohn Marino 			   	M_DEVBUF, M_NOWAIT);
13186d7f5d3SJohn Marino 			if (p == NULL)
13286d7f5d3SJohn Marino 				return ENOMEM;
13386d7f5d3SJohn Marino 			if (decoder_set != NULL) {
13486d7f5d3SJohn Marino 				bcopy(decoder_set, p, sizeof(*p)*decoders);
13586d7f5d3SJohn Marino 				kfree(decoder_set, M_DEVBUF);
13686d7f5d3SJohn Marino 			}
13786d7f5d3SJohn Marino 			decoder_set = p;
13886d7f5d3SJohn Marino 			i = decoders++;
13986d7f5d3SJohn Marino 		}
14086d7f5d3SJohn Marino 		decoder_set[i] = decoder;
14186d7f5d3SJohn Marino 	}
14286d7f5d3SJohn Marino 
14386d7f5d3SJohn Marino 	return 0;
14486d7f5d3SJohn Marino }
14586d7f5d3SJohn Marino 
14686d7f5d3SJohn Marino int
splash_unregister(splash_decoder_t * decoder)14786d7f5d3SJohn Marino splash_unregister(splash_decoder_t *decoder)
14886d7f5d3SJohn Marino {
14986d7f5d3SJohn Marino 	int error;
15086d7f5d3SJohn Marino 
15186d7f5d3SJohn Marino 	if (splash_decoder == decoder) {
15286d7f5d3SJohn Marino 		if ((error = splash_term(splash_adp)) != 0)
15386d7f5d3SJohn Marino 			return error;
15486d7f5d3SJohn Marino 	}
15586d7f5d3SJohn Marino 	return 0;
15686d7f5d3SJohn Marino }
15786d7f5d3SJohn Marino 
15886d7f5d3SJohn Marino int
splash_init(video_adapter_t * adp,int (* callback)(int,void *),void * arg)15986d7f5d3SJohn Marino splash_init(video_adapter_t *adp, int (*callback)(int, void *), void *arg)
16086d7f5d3SJohn Marino {
16186d7f5d3SJohn Marino 	int i;
16286d7f5d3SJohn Marino 
16386d7f5d3SJohn Marino 	splash_adp = adp;
16486d7f5d3SJohn Marino 	splash_callback = callback;
16586d7f5d3SJohn Marino 	splash_arg = arg;
16686d7f5d3SJohn Marino 
16786d7f5d3SJohn Marino 	splash_decoder = NULL;
16886d7f5d3SJohn Marino 	for (i = 0; i < decoders; ++i) {
16986d7f5d3SJohn Marino 		if (decoder_set[i] == NULL)
17086d7f5d3SJohn Marino 			continue;
17186d7f5d3SJohn Marino 		if (splash_test(decoder_set[i]) == 0) {
17286d7f5d3SJohn Marino 			splash_new(decoder_set[i]);
17386d7f5d3SJohn Marino 			break;
17486d7f5d3SJohn Marino 		}
17586d7f5d3SJohn Marino 		decoder_set[i] = NULL;
17686d7f5d3SJohn Marino 	}
17786d7f5d3SJohn Marino 	for (++i; i < decoders; ++i) {
17886d7f5d3SJohn Marino 		decoder_set[i] = NULL;
17986d7f5d3SJohn Marino 	}
18086d7f5d3SJohn Marino 	return 0;
18186d7f5d3SJohn Marino }
18286d7f5d3SJohn Marino 
18386d7f5d3SJohn Marino int
splash_term(video_adapter_t * adp)18486d7f5d3SJohn Marino splash_term(video_adapter_t *adp)
18586d7f5d3SJohn Marino {
18686d7f5d3SJohn Marino 	int error = 0;
18786d7f5d3SJohn Marino 
18886d7f5d3SJohn Marino 	if (splash_adp != adp)
18986d7f5d3SJohn Marino 		return EINVAL;
19086d7f5d3SJohn Marino 	if (splash_decoder != NULL) {
19186d7f5d3SJohn Marino 		if (splash_callback != NULL)
19286d7f5d3SJohn Marino 			error = (*splash_callback)(SPLASH_TERM, splash_arg);
19386d7f5d3SJohn Marino 		if (error == 0 && splash_decoder->term)
19486d7f5d3SJohn Marino 			error = (*splash_decoder->term)(adp);
19586d7f5d3SJohn Marino 		if (error == 0)
19686d7f5d3SJohn Marino 			splash_decoder = NULL;
19786d7f5d3SJohn Marino 	}
19886d7f5d3SJohn Marino 	return error;
19986d7f5d3SJohn Marino }
20086d7f5d3SJohn Marino 
20186d7f5d3SJohn Marino int
splash(video_adapter_t * adp,int on)20286d7f5d3SJohn Marino splash(video_adapter_t *adp, int on)
20386d7f5d3SJohn Marino {
20486d7f5d3SJohn Marino 	if (splash_decoder != NULL)
20586d7f5d3SJohn Marino 		return (*splash_decoder->splash)(adp, on);
20686d7f5d3SJohn Marino 	return ENODEV;
20786d7f5d3SJohn Marino }
208