summaryrefslogtreecommitdiffstats
path: root/sys/dev/fb
diff options
context:
space:
mode:
authoryokota <yokota@FreeBSD.org>1999-01-09 02:44:50 +0000
committeryokota <yokota@FreeBSD.org>1999-01-09 02:44:50 +0000
commitf10c5df4354e9dcf241989c9490f57fcd2ced1fc (patch)
tree595cc3d8efe3870b612f2264ba6a30474322c94c /sys/dev/fb
parentdc29b5609b3591deb088424bce52f2d654b06b2c (diff)
downloadFreeBSD-src-f10c5df4354e9dcf241989c9490f57fcd2ced1fc.zip
FreeBSD-src-f10c5df4354e9dcf241989c9490f57fcd2ced1fc.tar.gz
Add the new keyboard driver and video card driver. They will be
used by console drivers. (They are not yet activated yet. Wait for announcement later.)
Diffstat (limited to 'sys/dev/fb')
-rw-r--r--sys/dev/fb/fb.c415
-rw-r--r--sys/dev/fb/fbreg.h154
-rw-r--r--sys/dev/fb/splash.c181
-rw-r--r--sys/dev/fb/splashreg.h51
-rw-r--r--sys/dev/fb/vgareg.h67
5 files changed, 868 insertions, 0 deletions
diff --git a/sys/dev/fb/fb.c b/sys/dev/fb/fb.c
new file mode 100644
index 0000000..e765bc2
--- /dev/null
+++ b/sys/dev/fb/fb.c
@@ -0,0 +1,415 @@
+/*-
+ * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id: $
+ */
+
+#include "fb.h"
+#include "opt_fb.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+
+#include <machine/console.h>
+
+#include <dev/fb/fbreg.h>
+
+/* local arrays */
+
+/*
+ * We need at least one entry each in order to initialize a video card
+ * for the kernel console. The arrays will be increased dynamically
+ * when necessary.
+ */
+static video_adapter_t *adp_ini;
+static video_switch_t *vidsw_ini;
+static struct cdevsw *vidcdevsw_ini;
+
+static video_adapter_t **adapter = &adp_ini;
+static int adapters = 1;
+ video_switch_t **vidsw = &vidsw_ini;
+static struct cdevsw **vidcdevsw = &vidcdevsw_ini;
+
+#define ARRAY_DELTA 4
+
+static void
+vid_realloc_array(void)
+{
+ video_adapter_t **new_adp;
+ video_switch_t **new_vidsw;
+ struct cdevsw **new_cdevsw;
+ int newsize;
+ int s;
+
+ s = spltty();
+ newsize = ((adapters + ARRAY_DELTA)/ARRAY_DELTA)*ARRAY_DELTA;
+ new_adp = malloc(sizeof(*new_adp)*newsize, M_DEVBUF, M_WAITOK);
+ new_vidsw = malloc(sizeof(*new_vidsw)*newsize, M_DEVBUF, M_WAITOK);
+ new_cdevsw = malloc(sizeof(*new_cdevsw)*newsize, M_DEVBUF, M_WAITOK);
+ bzero(new_adp, sizeof(*new_adp)*newsize);
+ bzero(new_vidsw, sizeof(*new_vidsw)*newsize);
+ bzero(new_cdevsw, sizeof(*new_cdevsw)*newsize);
+ bcopy(adapter, new_adp, sizeof(*adapter)*adapters);
+ bcopy(vidsw, new_vidsw, sizeof(*vidsw)*adapters);
+ bcopy(vidcdevsw, new_cdevsw, sizeof(*vidcdevsw)*adapters);
+ if (adapters > 1) {
+ free(adapter, M_DEVBUF);
+ free(vidsw, M_DEVBUF);
+ free(vidcdevsw, M_DEVBUF);
+ }
+ adapter = new_adp;
+ vidsw = new_vidsw;
+ vidcdevsw = new_cdevsw;
+ adapters = newsize;
+ splx(s);
+
+ if (bootverbose)
+ printf("fb: new array size %d\n", adapters);
+}
+
+/*
+ * Low-level frame buffer driver functions
+ * frame buffer subdrivers, such as the VGA driver, call these functions
+ * to initialize the video_adapter structure and register it to the virtual
+ * frame buffer driver `fb'.
+ */
+
+/* initialize the video_adapter_t structure */
+void
+vid_init_struct(video_adapter_t *adp, char *name, int type, int unit)
+{
+ adp->va_flags = 0;
+ adp->va_name = name;
+ adp->va_type = type;
+ adp->va_unit = unit;
+}
+
+/* Register a video adapter */
+int
+vid_register(video_adapter_t *adp)
+{
+ video_driver_t **list;
+ video_driver_t *p;
+ int index;
+
+ for (index = 0; index < adapters; ++index) {
+ if (adapter[index] == NULL)
+ break;
+ }
+ if (index >= adapters)
+ return -1;
+
+ adp->va_index = index;
+ adp->va_token = NULL;
+ list = (video_driver_t **)videodriver_set.ls_items;
+ while ((p = *list++) != NULL) {
+ if (strcmp(p->name, adp->va_name) == 0) {
+ adapter[index] = adp;
+ vidsw[index] = p->vidsw;
+ return index;
+ }
+ }
+
+ return -1;
+}
+
+int
+vid_unregister(video_adapter_t *adp)
+{
+ if ((adp->va_index < 0) || (adp->va_index >= adapters))
+ return ENOENT;
+ if (adapter[adp->va_index] != adp)
+ return ENOENT;
+
+ adapter[adp->va_index] = NULL;
+ vidsw[adp->va_index] = NULL;
+ return 0;
+}
+
+/* Get video I/O function table */
+video_switch_t
+*vid_get_switch(char *name)
+{
+ video_driver_t **list;
+ video_driver_t *p;
+
+ list = (video_driver_t **)videodriver_set.ls_items;
+ while ((p = *list++) != NULL) {
+ if (strcmp(p->name, name) == 0)
+ return p->vidsw;
+ }
+
+ return NULL;
+}
+
+/*
+ * Video card client functions
+ * Video card clients, such as the console driver `syscons' and the frame
+ * buffer cdev driver, use these functions to claim and release a card for
+ * exclusive use.
+ */
+
+/* find the video card specified by a driver name and a unit number */
+int
+vid_find_adapter(char *driver, int unit)
+{
+ int i;
+
+ for (i = 0; i < adapters; ++i) {
+ if (adapter[i] == NULL)
+ continue;
+ if (strcmp("*", driver) && strcmp(adapter[i]->va_name, driver))
+ continue;
+ if ((unit != -1) && (adapter[i]->va_unit != unit))
+ continue;
+ return i;
+ }
+ return -1;
+}
+
+/* allocate a video card */
+int
+vid_allocate(char *driver, int unit, void *id)
+{
+ int index;
+ int s;
+
+ s = spltty();
+ index = vid_find_adapter(driver, unit);
+ if (index >= 0) {
+ if (adapter[index]->va_token) {
+ splx(s);
+ return -1;
+ }
+ adapter[index]->va_token = id;
+ }
+ splx(s);
+ return index;
+}
+
+int
+vid_release(video_adapter_t *adp, void *id)
+{
+ int error;
+ int s;
+
+ s = spltty();
+ if (adp->va_token == NULL) {
+ error = EINVAL;
+ } else if (adp->va_token != id) {
+ error = EPERM;
+ } else {
+ adp->va_token = NULL;
+ error = 0;
+ }
+ splx(s);
+ return error;
+}
+
+/* Get a video adapter structure */
+video_adapter_t
+*vid_get_adapter(int index)
+{
+ if ((index < 0) || (index >= adapters))
+ return NULL;
+ return adapter[index];
+}
+
+/* Configure drivers: this is a backdoor for the console driver XXX */
+int
+vid_configure(int flags)
+{
+ video_driver_t **list;
+ video_driver_t *p;
+
+ list = (video_driver_t **)videodriver_set.ls_items;
+ while ((p = *list++) != NULL) {
+ if (p->configure != NULL)
+ (*p->configure)(flags);
+ }
+
+ return 0;
+}
+
+/*
+ * Virtual frame buffer cdev driver functions
+ * The virtual frame buffer driver dispatches driver functions to
+ * appropriate subdrivers.
+ */
+
+#define DRIVER_NAME "fb"
+
+#ifdef FB_INSTALL_CDEV
+
+#define FB_UNIT(dev) minor(dev)
+#define FB_MKMINOR(unit) (u)
+
+#if notyet
+
+static d_open_t fbopen;
+static d_close_t fbclose;
+static d_ioctl_t fbioctl;
+static d_mmap_t fbmmap;
+
+#define CDEV_MAJOR 141 /* XXX */
+
+static struct cdevsw fb_cdevsw = {
+ fbopen, fbclose, noread, nowrite, /* ??? */
+ fbioctl, nostop, nullreset, nodevtotty,
+ seltrue, fbmmap, NULL, DRIVER_NAME,
+ NULL, -1, nodump, nopsize,
+};
+
+static void
+vfbattach(void *arg)
+{
+ static int fb_devsw_installed = FALSE;
+ dev_t dev;
+
+ if (!fb_devsw_installed) {
+ dev = makedev(CDEV_MAJOR, 0);
+ cdevsw_add(&dev, &fb_cdevsw, NULL);
+ fb_devsw_installed = TRUE;
+ }
+}
+
+PSEUDO_SET(vfbattach, fb);
+
+#endif /* notyet */
+
+int
+fb_attach(dev_t dev, video_adapter *adp, struct cdevsw *cdevsw)
+{
+ int s;
+
+ if (adp->va_index >= adapters)
+ return EINVAL;
+ if (adapter[adp->va_index] != adp)
+ return EINVAL;
+
+ s = spltty();
+ adp->va_minor = minor(dev);
+ vidcdevsw[adp->va_index] = cdevsw;
+ splx(s);
+
+ /* XXX: DEVFS? */
+
+ if (adp->va_index + 1 >= adapters)
+ vid_realloc_array();
+
+ printf("fb%d at %s%d\n", adp->va_index, adp->va_name, adp->va_unit);
+ return 0;
+}
+
+int
+fb_detach(dev_t dev, video_adapter *adp, struct cdevsw *cdevsw)
+{
+ int s;
+
+ if (adp->va_index >= adapters)
+ return EINVAL;
+ if (adapter[adp->va_index] != adp)
+ return EINVAL;
+ if (vidcdevsw[adp->va_index] != cdevsw)
+ return EINVAL;
+
+ s = spltty();
+ vidcdevsw[adp->va_index] = NULL;
+ splx(s);
+ return 0;
+}
+
+#endif /* FB_INSTALL_CDEV */
+
+static char
+*adapter_name(int type)
+{
+ static struct {
+ int type;
+ char *name;
+ } names[] = {
+ { KD_MONO, "MDA" },
+ { KD_HERCULES, "Hercules" },
+ { KD_CGA, "CGA" },
+ { KD_EGA, "EGA" },
+ { KD_VGA, "VGA" },
+ { KD_PC98, "PC-98x1" },
+ { -1, "Unknown" },
+ };
+ int i;
+
+ for (i = 0; names[i].type != -1; ++i)
+ if (names[i].type == type)
+ break;
+ return names[i].name;
+}
+
+void
+fb_dump_adp_info(char *driver, video_adapter_t *adp, int level)
+{
+ if (level <= 0)
+ return;
+
+ printf("%s%d: %s%d, %s, type:%s (%d), flags:0x%x\n",
+ DRIVER_NAME, adp->va_index, driver, adp->va_unit, adp->va_name,
+ adapter_name(adp->va_type), adp->va_type, adp->va_flags);
+ printf("%s%d: port:0x%x-0x%x, crtc:0x%x, mem:0x%x 0x%x\n",
+ DRIVER_NAME, adp->va_index,
+ adp->va_io_base, adp->va_io_base + adp->va_io_size - 1,
+ adp->va_crtc_addr, adp->va_mem_base, adp->va_mem_size);
+ printf("%s%d: init mode:%d, bios mode:%d, current mode:%d\n",
+ DRIVER_NAME, adp->va_index,
+ adp->va_initial_mode, adp->va_initial_bios_mode, adp->va_mode);
+ printf("%s%d: window:0x%x size:%dk gran:%dk, buf:0x%x size:%dk\n",
+ DRIVER_NAME, adp->va_index,
+ adp->va_window, adp->va_window_size/1024, adp->va_window_gran/1024,
+ adp->va_buffer, adp->va_buffer_size/1024);
+}
+
+void
+fb_dump_mode_info(char *driver, video_adapter_t *adp, video_info_t *info,
+ int level)
+{
+ if (level <= 0)
+ return;
+
+ printf("%s%d: %s, mode:%d, flags:0x%x ",
+ driver, adp->va_unit, adp->va_name, info->vi_mode, info->vi_flags);
+ if (info->vi_flags & V_INFO_GRAPHICS)
+ printf("G %dx%dx%d, %d plane(s), font:%dx%d, ",
+ info->vi_width, info->vi_height,
+ info->vi_depth, info->vi_planes,
+ info->vi_cwidth, info->vi_cheight);
+ else
+ printf("T %dx%d, font:%dx%d, ",
+ info->vi_width, info->vi_height,
+ info->vi_cwidth, info->vi_cheight);
+ printf("win:0x%x\n", info->vi_window);
+}
diff --git a/sys/dev/fb/fbreg.h b/sys/dev/fb/fbreg.h
new file mode 100644
index 0000000..ee5b1f2
--- /dev/null
+++ b/sys/dev/fb/fbreg.h
@@ -0,0 +1,154 @@
+/*-
+ * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id: $
+ */
+
+#ifndef _DEV_FB_FBREG_H_
+#define _DEV_FB_FBREG_H_
+
+#ifdef KERNEL
+
+#define V_MAX_ADAPTERS 8 /* XXX */
+
+/* some macros */
+#ifdef __i386__
+#define bcopy_toio(s, d, c) generic_bcopy(s, d, c)
+#define bcopy_fromio(s, d, c) generic_bcopy(s, d, c)
+#define bzero_io(d, c) generic_bzero(d, c)
+void generic_bcopy(const void *s, void *d, size_t c);
+void generic_bzero(void *d, size_t c);
+#else /* !__i386__ */
+#define bcopy_toio(s, d, c) memcpy_toio(d, s, c)
+#define bcopy_fromio(s, d, c) memcpy_fromio(d, s, c)
+#define bzero_io(d, c) memset_io(d, 0, c)
+#endif /* !__i386__ */
+
+/* video function table */
+typedef int vi_probe_t(int unit, video_adapter_t **adpp, void *arg, int flags);
+typedef int vi_init_t(int unit, video_adapter_t *adp, int flags);
+typedef int vi_get_info_t(video_adapter_t *adp, int mode, video_info_t *info);
+typedef int vi_query_mode_t(video_adapter_t *adp, video_info_t *info);
+typedef int vi_set_mode_t(video_adapter_t *adp, int mode);
+typedef int vi_save_font_t(video_adapter_t *adp, int page, int size,
+ u_char *data, int c, int count);
+typedef int vi_load_font_t(video_adapter_t *adp, int page, int size,
+ u_char *data, int c, int count);
+typedef int vi_show_font_t(video_adapter_t *adp, int page);
+typedef int vi_save_palette_t(video_adapter_t *adp, u_char *palette);
+typedef int vi_load_palette_t(video_adapter_t *adp, u_char *palette);
+typedef int vi_set_border_t(video_adapter_t *adp, int border);
+typedef int vi_save_state_t(video_adapter_t *adp, void *p, size_t size);
+typedef int vi_load_state_t(video_adapter_t *adp, void *p);
+typedef int vi_set_win_org_t(video_adapter_t *adp, off_t offset);
+typedef int vi_read_hw_cursor_t(video_adapter_t *adp, int *col, int *row);
+typedef int vi_set_hw_cursor_t(video_adapter_t *adp, int col, int row);
+typedef int vi_set_hw_cursor_shape_t(video_adapter_t *adp, int base,
+ int height, int celsize, int blink);
+typedef int vi_blank_display_t(video_adapter_t *adp, int mode);
+#define V_DISPLAY_POWER_ON 0
+#define V_DISPLAY_SUSPEND 1
+#define V_DISPLAY_SUSPEND1 1
+#define V_DISPLAY_SUSPEND2 2
+#define V_DISPLAY_POWER_OFF 3
+typedef int vi_mmap_t(video_adapter_t *adp, vm_offset_t offset);
+typedef int vi_diag_t(video_adapter_t *adp, int level);
+
+typedef struct video_switch {
+ vi_probe_t *probe;
+ vi_init_t *init;
+ vi_get_info_t *get_info;
+ vi_query_mode_t *query_mode;
+ vi_set_mode_t *set_mode;
+ vi_save_font_t *save_font;
+ vi_load_font_t *load_font;
+ vi_show_font_t *show_font;
+ vi_save_palette_t *save_palette;
+ vi_load_palette_t *load_palette;
+ vi_set_border_t *set_border;
+ vi_save_state_t *save_state;
+ vi_load_state_t *load_state;
+ vi_set_win_org_t *set_win_org;
+ vi_read_hw_cursor_t *read_hw_cursor;
+ vi_set_hw_cursor_t *set_hw_cursor;
+ vi_set_hw_cursor_shape_t *set_hw_cursor_shape;
+ vi_blank_display_t *blank_display;
+ vi_mmap_t *mmap;
+ vi_diag_t *diag;
+} video_switch_t;
+
+/* video driver */
+typedef struct video_driver {
+ char *name;
+ video_switch_t *vidsw;
+ int (*configure)(int); /* backdoor for the console driver */
+} video_driver_t;
+
+#define VIDEO_DRIVER(name, sw, config) \
+ static struct video_driver name##_driver = { \
+ #name, &sw, config \
+ }; \
+ DATA_SET(videodriver_set, name##_driver);
+
+/* global variables */
+extern struct video_switch **vidsw;
+extern struct linker_set videodriver_set;
+
+/* functions for the video card driver */
+int vid_register(video_adapter_t *adp);
+int vid_unregister(video_adapter_t *adp);
+video_switch_t *vid_get_switch(char *name);
+void vid_init_struct(video_adapter_t *adp, char *name, int type,
+ int unit);
+
+/* functions for the video card client */
+int vid_allocate(char *driver, int unit, void *id);
+int vid_release(video_adapter_t *adp, void *id);
+int vid_find_adapter(char *driver, int unit);
+video_adapter_t *vid_get_adapter(int index);
+
+/* a backdoor for the console driver to tickle the video driver XXX */
+int vid_configure(int flags);
+#define VIO_PROBE_ONLY (1 << 0) /* probe only, don't initialize */
+
+#ifdef FB_INSTALL_CDEV
+
+/* virtual frame buffer driver functions */
+int fb_attach(dev_t dev, video_adapter_t *adp,
+ struct cdevsw *cdevsw);
+int fb_detach(dev_t dev, video_adapter_t *adp,
+ struct cdevsw *cdevsw);
+
+#endif /* FB_INSTALL_CDEV */
+
+/* generic low-level driver functions */
+
+void fb_dump_adp_info(char *driver, video_adapter_t *adp, int level);
+void fb_dump_mode_info(char *driver, video_adapter_t *adp,
+ video_info_t *info, int level);
+
+#endif /* KERNEL */
+
+#endif /* !_DEV_FB_FBREG_H_ */
diff --git a/sys/dev/fb/splash.c b/sys/dev/fb/splash.c
new file mode 100644
index 0000000..7d0b90e
--- /dev/null
+++ b/sys/dev/fb/splash.c
@@ -0,0 +1,181 @@
+/*-
+ * $Id:$
+ */
+
+#include "splash.h"
+
+#if NSPLASH > 0
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/linker.h>
+
+#include <machine/console.h>
+
+#include <dev/fb/fbreg.h>
+#include <dev/fb/splashreg.h>
+
+/* video adapter and image decoder */
+static video_adapter_t *splash_adp;
+static splash_decoder_t *splash_decoder;
+
+/* decoder candidates */
+static int decoders;
+static splash_decoder_t **decoder_set;
+#define DECODER_ARRAY_DELTA 4
+
+/* splash image data file */
+static void *splash_image_data;
+static size_t splash_image_size;
+
+/* console driver callback */
+static int (*splash_callback)(int);
+
+static int
+splash_find_image(void)
+{
+ caddr_t image_module;
+ caddr_t p;
+
+ if (splash_image_data == NULL) {
+ image_module = preload_search_by_type(SPLASH_IMAGE);
+ if (image_module == NULL)
+ return ENOENT;
+ p = preload_search_info(image_module, MODINFO_ADDR);
+ if (p == NULL)
+ return ENOENT;
+ splash_image_data = *(void **)p;
+ p = preload_search_info(image_module, MODINFO_SIZE);
+ if (p == NULL)
+ return ENOENT;
+ splash_image_size = *(size_t *)p;
+ }
+ return 0;
+}
+
+static int
+splash_test(splash_decoder_t *decoder)
+{
+ if ((*decoder->init)(splash_adp, splash_image_data, splash_image_size))
+ return ENODEV; /* XXX */
+ if (bootverbose)
+ printf("splash: image decoder found: %s\n", decoder->name);
+ splash_decoder = decoder;
+ if (splash_callback != NULL)
+ (*splash_callback)(SPLASH_INIT);
+ return 0;
+}
+
+int
+splash_register(splash_decoder_t *decoder)
+{
+ splash_decoder_t **p;
+ int i;
+
+ /* only one decoder can be active */
+ if (splash_decoder != NULL)
+ return ENODEV; /* XXX */
+
+ /* if the splash image is not in memory, abort */
+ splash_find_image();
+ if (bootverbose)
+ printf("splash: image@%p, size:%u\n",
+ splash_image_data, splash_image_size);
+ if (splash_image_data == NULL)
+ return ENOENT;
+
+ /*
+ * If the video card has aleady been initialized, test this
+ * decoder immediately.
+ */
+ if (splash_adp != NULL)
+ return splash_test(decoder);
+
+ /* register the decoder for later use */
+ for (i = 0; i < decoders; ++i) {
+ if (decoder_set[i] == NULL)
+ break;
+ }
+ if ((i >= decoders) && (decoders % DECODER_ARRAY_DELTA) == 0) {
+ p = malloc(sizeof(*p)*(decoders + DECODER_ARRAY_DELTA),
+ M_DEVBUF, M_NOWAIT);
+ if (p == NULL)
+ return ENOMEM;
+ if (decoder_set != NULL)
+ bcopy(decoder_set, p, sizeof(*p)*decoders);
+ free(decoder_set, M_DEVBUF);
+ decoder_set = p;
+ i = decoders++;
+ }
+ decoder_set[i] = decoder;
+ return 0;
+}
+
+int
+splash_unregister(splash_decoder_t *decoder)
+{
+ int error;
+ int i;
+
+ if (splash_decoder == decoder) {
+ if ((error = splash_term(splash_adp)) != 0)
+ return error;
+ }
+ for (i = 0; i < decoders; ++i) {
+ if (decoder_set[i] == decoder) {
+ decoder_set[i] = NULL;
+ break;
+ }
+ }
+ return 0;
+}
+
+int
+splash_init(video_adapter_t *adp, int (*callback)(int))
+{
+ int i;
+
+ splash_adp = adp;
+ splash_callback = callback;
+
+ /* try registered decoders with this adapter and loaded image */
+ splash_decoder = NULL;
+ splash_find_image();
+ if (splash_image_data == NULL)
+ return 0;
+ for (i = 0; i < decoders; ++i) {
+ if (decoder_set[i] == NULL)
+ continue;
+ if (splash_test(decoder_set[i]) == 0)
+ break;
+ }
+ return 0;
+}
+
+int
+splash_term(video_adapter_t *adp)
+{
+ int error = 0;
+
+ if (splash_decoder != NULL) {
+ if (splash_callback != NULL)
+ error = (*splash_callback)(SPLASH_TERM);
+ if (error == 0)
+ error = (*splash_decoder->term)(adp);
+ if (error == 0)
+ splash_decoder = NULL;
+ }
+ return error;
+}
+
+int
+splash(video_adapter_t *adp, int on)
+{
+ if (splash_decoder != NULL)
+ return (*splash_decoder->splash)(adp, on);
+ return ENODEV;
+}
+
+#endif /* NSPLASH > 0 */
diff --git a/sys/dev/fb/splashreg.h b/sys/dev/fb/splashreg.h
new file mode 100644
index 0000000..83496fa
--- /dev/null
+++ b/sys/dev/fb/splashreg.h
@@ -0,0 +1,51 @@
+/*-
+ * $Id: $
+ */
+
+#ifndef _DEV_FB_SPLASHREG_H_
+#define _DEV_FB_SPLASHREG_H_
+
+#define SPLASH_IMAGE "splash_image_data"
+
+struct video_adapter;
+
+typedef struct splash_decoder {
+ char *name;
+ int (*init)(struct video_adapter *adp, void *data,
+ size_t size);
+ int (*term)(struct video_adapter *adp);
+ int (*splash)(struct video_adapter *adp, int on);
+} splash_decoder_t;
+
+#define SPLASH_DECODER(name, sw) \
+ static int name##_modevent(module_t mod, int type, void *data) \
+ { \
+ switch ((modeventtype_t)type) { \
+ case MOD_LOAD: \
+ return splash_register(&sw); \
+ case MOD_UNLOAD: \
+ return splash_unregister(&sw); \
+ } \
+ return 0; \
+ } \
+ static moduledata_t name##_mod = { \
+ #name, \
+ name##_modevent, \
+ NULL \
+ }; \
+ DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, SI_ORDER_ANY)
+
+/* entry point for the splash image decoder */
+int splash_register(splash_decoder_t *decoder);
+int splash_unregister(splash_decoder_t *decoder);
+
+/* entry points for the console driver */
+int splash_init(video_adapter_t *adp, int (*callback)(int));
+int splash_term(video_adapter_t *adp);
+int splash(video_adapter_t *adp, int on);
+
+/* event types for the callback function */
+#define SPLASH_INIT 0
+#define SPLASH_TERM 1
+
+#endif /* _DEV_FB_SPLASHREG_H_ */
diff --git a/sys/dev/fb/vgareg.h b/sys/dev/fb/vgareg.h
new file mode 100644
index 0000000..841408e
--- /dev/null
+++ b/sys/dev/fb/vgareg.h
@@ -0,0 +1,67 @@
+/*-
+ * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer as
+ * the first lines of this file unmodified.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $Id:$
+ */
+
+#ifndef _DEV_FB_VGAREG_H_
+#define _DEV_FB_VGAREG_H_
+
+/* physical addresses */
+#define MDA_BUF_BASE 0xb0000
+#define MDA_BUF_SIZE 0x08000
+#define MDA_BUF BIOS_PADDRTOVADDR(MDA_BUF_BASE)
+#define CGA_BUF_BASE 0xb8000
+#define CGA_BUF_SIZE 0x08000
+#define CGA_BUF BIOS_PADDRTOVADDR(CGA_BUF_BASE)
+#define EGA_BUF_BASE 0xa0000
+#define EGA_BUF_SIZE 0x20000
+#define EGA_BUF BIOS_PADDRTOVADDR(EGA_BUF_BASE)
+#define GRAPHICS_BUF_BASE 0xa0000
+#define GRAPHICS_BUF_SIZE 0x10000
+#define GRAPHICS_BUF BIOS_PADDRTOVADDR(GRAPHICS_BUF_BASE)
+#define FONT_BUF BIOS_PADDRTOVADDR(GRAPHICS_BUF_BASE)
+#define VIDEO_BUF_BASE 0xa0000
+#define VIDEO_BUF_SIZE 0x20000
+
+/* I/O port addresses */
+#define MONO_CRTC (IO_MDA + 0x04) /* crt controller base mono */
+#define COLOR_CRTC (IO_CGA + 0x04) /* crt controller base color */
+#define MISC (IO_VGA + 0x02) /* misc output register */
+#define ATC (IO_VGA + 0x00) /* attribute controller */
+#define TSIDX (IO_VGA + 0x04) /* timing sequencer idx */
+#define TSREG (IO_VGA + 0x05) /* timing sequencer data */
+#define PIXMASK (IO_VGA + 0x06) /* pixel write mask */
+#define PALRADR (IO_VGA + 0x07) /* palette read address */
+#define PALWADR (IO_VGA + 0x08) /* palette write address */
+#define PALDATA (IO_VGA + 0x09) /* palette data register */
+#define GDCIDX (IO_VGA + 0x0E) /* graph data controller idx */
+#define GDCREG (IO_VGA + 0x0F) /* graph data controller data */
+
+#ifdef KERNEL
+extern int (*vga_sub_configure)(int flags);
+#endif
+
+#endif /* _DEV_FB_VGAREG_H_ */
OpenPOWER on IntegriCloud