summaryrefslogtreecommitdiffstats
path: root/freebsd/sys/dev
diff options
context:
space:
mode:
Diffstat (limited to 'freebsd/sys/dev')
-rw-r--r--freebsd/sys/dev/fb/fb.c762
-rw-r--r--freebsd/sys/dev/fb/fbd.c372
-rw-r--r--freebsd/sys/dev/fb/fbreg.h345
-rw-r--r--freebsd/sys/dev/vt/colors/vt_termcolors.h63
-rw-r--r--freebsd/sys/dev/vt/hw/fb/vt_fb.h54
-rw-r--r--freebsd/sys/dev/vt/vt.h474
6 files changed, 2070 insertions, 0 deletions
diff --git a/freebsd/sys/dev/fb/fb.c b/freebsd/sys/dev/fb/fb.c
new file mode 100644
index 00000000..a3263c91
--- /dev/null
+++ b/freebsd/sys/dev/fb/fb.c
@@ -0,0 +1,762 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <rtems/bsd/local/opt_fb.h>
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/module.h>
+#include <sys/uio.h>
+#include <sys/fbio.h>
+#include <sys/linker_set.h>
+
+#include <vm/vm.h>
+#include <vm/pmap.h>
+
+#include <dev/fb/fbreg.h>
+
+SET_DECLARE(videodriver_set, const video_driver_t);
+
+/* 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 int vid_malloc;
+static int adapters = 1;
+static video_adapter_t *adp_ini;
+static video_adapter_t **adapter = &adp_ini;
+static video_switch_t *vidsw_ini;
+ video_switch_t **vidsw = &vidsw_ini;
+
+#ifdef FB_INSTALL_CDEV
+static struct cdevsw *vidcdevsw_ini;
+static struct cdevsw **vidcdevsw = &vidcdevsw_ini;
+#endif
+
+#define ARRAY_DELTA 4
+
+static int
+vid_realloc_array(void)
+{
+ video_adapter_t **new_adp;
+ video_switch_t **new_vidsw;
+#ifdef FB_INSTALL_CDEV
+ struct cdevsw **new_cdevsw;
+#endif
+ int newsize;
+ int s;
+
+ if (!vid_malloc)
+ return ENOMEM;
+
+ s = spltty();
+ newsize = rounddown(adapters + ARRAY_DELTA, ARRAY_DELTA);
+ new_adp = malloc(sizeof(*new_adp)*newsize, M_DEVBUF, M_WAITOK | M_ZERO);
+ new_vidsw = malloc(sizeof(*new_vidsw)*newsize, M_DEVBUF,
+ M_WAITOK | M_ZERO);
+#ifdef FB_INSTALL_CDEV
+ new_cdevsw = malloc(sizeof(*new_cdevsw)*newsize, M_DEVBUF,
+ M_WAITOK | M_ZERO);
+#endif
+ bcopy(adapter, new_adp, sizeof(*adapter)*adapters);
+ bcopy(vidsw, new_vidsw, sizeof(*vidsw)*adapters);
+#ifdef FB_INSTALL_CDEV
+ bcopy(vidcdevsw, new_cdevsw, sizeof(*vidcdevsw)*adapters);
+#endif
+ if (adapters > 1) {
+ free(adapter, M_DEVBUF);
+ free(vidsw, M_DEVBUF);
+#ifdef FB_INSTALL_CDEV
+ free(vidcdevsw, M_DEVBUF);
+#endif
+ }
+ adapter = new_adp;
+ vidsw = new_vidsw;
+#ifdef FB_INSTALL_CDEV
+ vidcdevsw = new_cdevsw;
+#endif
+ adapters = newsize;
+ splx(s);
+
+ if (bootverbose)
+ printf("fb: new array size %d\n", adapters);
+
+ return 0;
+}
+
+static void
+vid_malloc_init(void *arg)
+{
+ vid_malloc = TRUE;
+}
+
+SYSINIT(vid_mem, SI_SUB_KMEM, SI_ORDER_ANY, vid_malloc_init, NULL);
+
+/*
+ * 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)
+{
+ const video_driver_t **list;
+ const video_driver_t *p;
+ int index;
+
+ for (index = 0; index < adapters; ++index) {
+ if (adapter[index] == NULL)
+ break;
+ }
+ if (index >= adapters) {
+ if (vid_realloc_array())
+ return -1;
+ }
+
+ adp->va_index = index;
+ adp->va_token = NULL;
+ SET_FOREACH(list, videodriver_set) {
+ p = *list;
+ 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)
+{
+ const video_driver_t **list;
+ const video_driver_t *p;
+
+ SET_FOREACH(list, videodriver_set) {
+ p = *list;
+ 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)
+{
+ const video_driver_t **list;
+ const video_driver_t *p;
+
+ SET_FOREACH(list, videodriver_set) {
+ p = *list;
+ 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 FB_DRIVER_NAME "fb"
+
+#ifdef FB_INSTALL_CDEV
+
+#if 0 /* experimental */
+
+static devclass_t fb_devclass;
+
+static int fbprobe(device_t dev);
+static int fbattach(device_t dev);
+
+static device_method_t fb_methods[] = {
+ DEVMETHOD(device_probe, fbprobe),
+ DEVMETHOD(device_attach, fbattach),
+
+ DEVMETHOD_END
+};
+
+static driver_t fb_driver = {
+ FB_DRIVER_NAME,
+ fb_methods,
+ 0,
+};
+
+static int
+fbprobe(device_t dev)
+{
+ int unit;
+
+ unit = device_get_unit(dev);
+ if (unit >= adapters)
+ return ENXIO;
+ if (adapter[unit] == NULL)
+ return ENXIO;
+
+ device_set_desc(dev, "generic frame buffer");
+ return 0;
+}
+
+static int
+fbattach(device_t dev)
+{
+ printf("fbattach: about to attach children\n");
+ bus_generic_attach(dev);
+ return 0;
+}
+
+#endif
+
+#define FB_UNIT(dev) dev2unit(dev)
+#define FB_MKMINOR(unit) (u)
+
+#if 0 /* experimental */
+static d_open_t fbopen;
+static d_close_t fbclose;
+static d_read_t fbread;
+static d_write_t fbwrite;
+static d_ioctl_t fbioctl;
+static d_mmap_t fbmmap;
+
+
+static struct cdevsw fb_cdevsw = {
+ .d_version = D_VERSION,
+ .d_flags = D_NEEDGIANT,
+ .d_open = fbopen,
+ .d_close = fbclose,
+ .d_read = fbread,
+ .d_write = fbwrite,
+ .d_ioctl = fbioctl,
+ .d_mmap = fbmmap,
+ .d_name = FB_DRIVER_NAME,
+};
+#endif
+
+
+static int
+fb_modevent(module_t mod, int type, void *data)
+{
+
+ switch (type) {
+ case MOD_LOAD:
+ break;
+ case MOD_UNLOAD:
+ printf("fb module unload - not possible for this module type\n");
+ return EINVAL;
+ default:
+ return EOPNOTSUPP;
+ }
+ return 0;
+}
+
+static moduledata_t fb_mod = {
+ "fb",
+ fb_modevent,
+ NULL
+};
+
+DECLARE_MODULE(fb, fb_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
+
+int
+fb_attach(int unit, video_adapter_t *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 = unit;
+ vidcdevsw[adp->va_index] = cdevsw;
+ splx(s);
+
+ printf("fb%d at %s%d\n", adp->va_index, adp->va_name, adp->va_unit);
+ return 0;
+}
+
+int
+fb_detach(int unit, video_adapter_t *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;
+}
+
+/*
+ * Generic frame buffer cdev driver functions
+ * Frame buffer subdrivers may call these functions to implement common
+ * driver functions.
+ */
+
+int genfbopen(genfb_softc_t *sc, video_adapter_t *adp, int flag, int mode,
+ struct thread *td)
+{
+ int s;
+
+ s = spltty();
+ if (!(sc->gfb_flags & FB_OPEN))
+ sc->gfb_flags |= FB_OPEN;
+ splx(s);
+ return 0;
+}
+
+int genfbclose(genfb_softc_t *sc, video_adapter_t *adp, int flag, int mode,
+ struct thread *td)
+{
+ int s;
+
+ s = spltty();
+ sc->gfb_flags &= ~FB_OPEN;
+ splx(s);
+ return 0;
+}
+
+int genfbread(genfb_softc_t *sc, video_adapter_t *adp, struct uio *uio,
+ int flag)
+{
+ int size;
+ int offset;
+ int error;
+ int len;
+
+ error = 0;
+ size = adp->va_buffer_size/adp->va_info.vi_planes;
+ while (uio->uio_resid > 0) {
+ if (uio->uio_offset >= size)
+ break;
+ offset = uio->uio_offset%adp->va_window_size;
+ len = imin(uio->uio_resid, size - uio->uio_offset);
+ len = imin(len, adp->va_window_size - offset);
+ if (len <= 0)
+ break;
+ vidd_set_win_org(adp, uio->uio_offset);
+ error = uiomove((caddr_t)(adp->va_window + offset), len, uio);
+ if (error)
+ break;
+ }
+ return error;
+}
+
+int genfbwrite(genfb_softc_t *sc, video_adapter_t *adp, struct uio *uio,
+ int flag)
+{
+ return ENODEV;
+}
+
+int genfbioctl(genfb_softc_t *sc, video_adapter_t *adp, u_long cmd,
+ caddr_t arg, int flag, struct thread *td)
+{
+ int error;
+
+ if (adp == NULL) /* XXX */
+ return ENXIO;
+ error = vidd_ioctl(adp, cmd, arg);
+ if (error == ENOIOCTL)
+ error = ENODEV;
+ return error;
+}
+
+int genfbmmap(genfb_softc_t *sc, video_adapter_t *adp, vm_ooffset_t offset,
+ vm_offset_t *paddr, int prot, vm_memattr_t *memattr)
+{
+ return vidd_mmap(adp, offset, paddr, prot, memattr);
+}
+
+#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_TGA, "TGA" },
+ { -1, "Unknown" },
+ };
+ int i;
+
+ for (i = 0; names[i].type != -1; ++i)
+ if (names[i].type == type)
+ break;
+ return names[i].name;
+}
+
+/*
+ * Generic low-level frame buffer functions
+ * The low-level functions in the frame buffer subdriver may use these
+ * functions.
+ */
+
+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",
+ FB_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%lx-0x%lx, crtc:0x%lx, mem:0x%lx 0x%x\n",
+ FB_DRIVER_NAME, adp->va_index, (u_long)adp->va_io_base,
+ (u_long)adp->va_io_base + adp->va_io_size - 1,
+ (u_long)adp->va_crtc_addr, (u_long)adp->va_mem_base,
+ adp->va_mem_size);
+ printf("%s%d: init mode:%d, bios mode:%d, current mode:%d\n",
+ FB_DRIVER_NAME, adp->va_index,
+ adp->va_initial_mode, adp->va_initial_bios_mode, adp->va_mode);
+ printf("%s%d: window:%p size:%dk gran:%dk, buf:%p size:%dk\n",
+ FB_DRIVER_NAME, adp->va_index,
+ (void *)adp->va_window, (int)adp->va_window_size/1024,
+ (int)adp->va_window_gran/1024, (void *)adp->va_buffer,
+ (int)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%lx\n", (u_long)info->vi_window);
+}
+
+int
+fb_type(int adp_type)
+{
+ static struct {
+ int fb_type;
+ int va_type;
+ } types[] = {
+ { FBTYPE_MDA, KD_MONO },
+ { FBTYPE_HERCULES, KD_HERCULES },
+ { FBTYPE_CGA, KD_CGA },
+ { FBTYPE_EGA, KD_EGA },
+ { FBTYPE_VGA, KD_VGA },
+ { FBTYPE_TGA, KD_TGA },
+ };
+ int i;
+
+ for (i = 0; i < nitems(types); ++i) {
+ if (types[i].va_type == adp_type)
+ return types[i].fb_type;
+ }
+ return -1;
+}
+
+int
+fb_commonioctl(video_adapter_t *adp, u_long cmd, caddr_t arg)
+{
+ int error;
+ int s;
+
+ /* assert(adp != NULL) */
+
+ error = 0;
+ s = spltty();
+
+ switch (cmd) {
+
+ case FBIO_ADAPTER: /* get video adapter index */
+ *(int *)arg = adp->va_index;
+ break;
+
+ case FBIO_ADPTYPE: /* get video adapter type */
+ *(int *)arg = adp->va_type;
+ break;
+
+ case FBIO_ADPINFO: /* get video adapter info */
+ ((video_adapter_info_t *)arg)->va_index = adp->va_index;
+ ((video_adapter_info_t *)arg)->va_type = adp->va_type;
+ bcopy(adp->va_name, ((video_adapter_info_t *)arg)->va_name,
+ imin(strlen(adp->va_name) + 1,
+ sizeof(((video_adapter_info_t *)arg)->va_name)));
+ ((video_adapter_info_t *)arg)->va_unit = adp->va_unit;
+ ((video_adapter_info_t *)arg)->va_flags = adp->va_flags;
+ ((video_adapter_info_t *)arg)->va_io_base = adp->va_io_base;
+ ((video_adapter_info_t *)arg)->va_io_size = adp->va_io_size;
+ ((video_adapter_info_t *)arg)->va_crtc_addr = adp->va_crtc_addr;
+ ((video_adapter_info_t *)arg)->va_mem_base = adp->va_mem_base;
+ ((video_adapter_info_t *)arg)->va_mem_size = adp->va_mem_size;
+ ((video_adapter_info_t *)arg)->va_window
+#if defined(__amd64__) || defined(__i386__)
+ = vtophys(adp->va_window);
+#else
+ = adp->va_window;
+#endif
+ ((video_adapter_info_t *)arg)->va_window_size
+ = adp->va_window_size;
+ ((video_adapter_info_t *)arg)->va_window_gran
+ = adp->va_window_gran;
+ ((video_adapter_info_t *)arg)->va_window_orig
+ = adp->va_window_orig;
+ ((video_adapter_info_t *)arg)->va_unused0
+#if defined(__amd64__) || defined(__i386__)
+ = adp->va_buffer != 0 ? vtophys(adp->va_buffer) : 0;
+#else
+ = adp->va_buffer;
+#endif
+ ((video_adapter_info_t *)arg)->va_buffer_size
+ = adp->va_buffer_size;
+ ((video_adapter_info_t *)arg)->va_mode = adp->va_mode;
+ ((video_adapter_info_t *)arg)->va_initial_mode
+ = adp->va_initial_mode;
+ ((video_adapter_info_t *)arg)->va_initial_bios_mode
+ = adp->va_initial_bios_mode;
+ ((video_adapter_info_t *)arg)->va_line_width
+ = adp->va_line_width;
+ ((video_adapter_info_t *)arg)->va_disp_start.x
+ = adp->va_disp_start.x;
+ ((video_adapter_info_t *)arg)->va_disp_start.y
+ = adp->va_disp_start.y;
+ break;
+
+ case FBIO_MODEINFO: /* get mode information */
+ error = vidd_get_info(adp,
+ ((video_info_t *)arg)->vi_mode,
+ (video_info_t *)arg);
+ if (error)
+ error = ENODEV;
+ break;
+
+ case FBIO_FINDMODE: /* find a matching video mode */
+ error = vidd_query_mode(adp, (video_info_t *)arg);
+ break;
+
+ case FBIO_GETMODE: /* get video mode */
+ *(int *)arg = adp->va_mode;
+ break;
+
+ case FBIO_SETMODE: /* set video mode */
+ error = vidd_set_mode(adp, *(int *)arg);
+ if (error)
+ error = ENODEV; /* EINVAL? */
+ break;
+
+ case FBIO_GETWINORG: /* get frame buffer window origin */
+ *(u_int *)arg = adp->va_window_orig;
+ break;
+
+ case FBIO_GETDISPSTART: /* get display start address */
+ ((video_display_start_t *)arg)->x = adp->va_disp_start.x;
+ ((video_display_start_t *)arg)->y = adp->va_disp_start.y;
+ break;
+
+ case FBIO_GETLINEWIDTH: /* get scan line width in bytes */
+ *(u_int *)arg = adp->va_line_width;
+ break;
+
+ case FBIO_BLANK: /* blank display */
+ error = vidd_blank_display(adp, *(int *)arg);
+ break;
+
+ case FBIO_GETPALETTE: /* get color palette */
+ case FBIO_SETPALETTE: /* set color palette */
+ /* XXX */
+
+ case FBIOPUTCMAP:
+ case FBIOGETCMAP:
+ case FBIOPUTCMAPI:
+ case FBIOGETCMAPI:
+ /* XXX */
+
+ case FBIO_SETWINORG: /* set frame buffer window origin */
+ case FBIO_SETDISPSTART: /* set display start address */
+ case FBIO_SETLINEWIDTH: /* set scan line width in pixel */
+
+ case FBIOGTYPE:
+ case FBIOGATTR:
+ case FBIOSVIDEO:
+ case FBIOGVIDEO:
+ case FBIOVERTICAL:
+ case FBIOSCURSOR:
+ case FBIOGCURSOR:
+ case FBIOSCURPOS:
+ case FBIOGCURPOS:
+ case FBIOGCURMAX:
+ case FBIOMONINFO:
+ case FBIOGXINFO:
+
+ default:
+ error = ENODEV;
+ break;
+ }
+
+ splx(s);
+ return error;
+}
diff --git a/freebsd/sys/dev/fb/fbd.c b/freebsd/sys/dev/fb/fbd.c
new file mode 100644
index 00000000..60ce4bc3
--- /dev/null
+++ b/freebsd/sys/dev/fb/fbd.c
@@ -0,0 +1,372 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Aleksandr Rybalko under sponsorship from the
+ * FreeBSD Foundation.
+ *
+ * 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.
+ * 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ * $FreeBSD$
+ */
+
+/* Generic framebuffer */
+/* TODO unlink from VT(9) */
+/* TODO done normal /dev/fb methods */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/conf.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/module.h>
+#include <sys/queue.h>
+#include <sys/fbio.h>
+
+#include <machine/bus.h>
+
+#include <dev/vt/vt.h>
+#include <dev/vt/hw/fb/vt_fb.h>
+
+#include <vm/vm.h>
+#include <vm/pmap.h>
+
+#include <rtems/bsd/local/fb_if.h>
+
+LIST_HEAD(fb_list_head_t, fb_list_entry) fb_list_head =
+ LIST_HEAD_INITIALIZER(fb_list_head);
+struct fb_list_entry {
+ struct fb_info *fb_info;
+ struct cdev *fb_si;
+ LIST_ENTRY(fb_list_entry) fb_list;
+};
+
+struct fbd_softc {
+ device_t sc_dev;
+ struct fb_info *sc_info;
+};
+
+static void fbd_evh_init(void *);
+/* SI_ORDER_SECOND, just after EVENTHANDLERs initialized. */
+SYSINIT(fbd_evh_init, SI_SUB_CONFIGURE, SI_ORDER_SECOND, fbd_evh_init, NULL);
+
+static d_open_t fb_open;
+static d_close_t fb_close;
+static d_read_t fb_read;
+static d_write_t fb_write;
+static d_ioctl_t fb_ioctl;
+static d_mmap_t fb_mmap;
+
+static struct cdevsw fb_cdevsw = {
+ .d_version = D_VERSION,
+ .d_flags = D_NEEDGIANT,
+ .d_open = fb_open,
+ .d_close = fb_close,
+ .d_read = fb_read,
+ .d_write = fb_write,
+ .d_ioctl = fb_ioctl,
+ .d_mmap = fb_mmap,
+ .d_name = "fb",
+};
+
+static int framebuffer_dev_unit = 0;
+
+static int
+fb_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
+{
+
+ return (0);
+}
+
+static int
+fb_close(struct cdev *dev, int fflag, int devtype, struct thread *td)
+{
+
+ return (0);
+}
+
+static int
+fb_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
+ struct thread *td)
+{
+ struct fb_info *info;
+ int error;
+
+ error = 0;
+ info = dev->si_drv1;
+
+ switch (cmd) {
+ case FBIOGTYPE:
+ bcopy(info, (struct fbtype *)data, sizeof(struct fbtype));
+ break;
+
+ case FBIO_GETWINORG: /* get frame buffer window origin */
+ *(u_int *)data = 0;
+ break;
+
+ case FBIO_GETDISPSTART: /* get display start address */
+ ((video_display_start_t *)data)->x = 0;
+ ((video_display_start_t *)data)->y = 0;
+ break;
+
+ case FBIO_GETLINEWIDTH: /* get scan line width in bytes */
+ *(u_int *)data = info->fb_stride;
+ break;
+
+ case FBIO_BLANK: /* blank display */
+ if (info->setblankmode != NULL)
+ error = info->setblankmode(info->fb_priv, *(int *)data);
+ break;
+
+ default:
+ error = ENOIOCTL;
+ break;
+ }
+ return (error);
+}
+
+static int
+fb_read(struct cdev *dev, struct uio *uio, int ioflag)
+{
+
+ return (0); /* XXX nothing to read, yet */
+}
+
+static int
+fb_write(struct cdev *dev, struct uio *uio, int ioflag)
+{
+
+ return (0); /* XXX nothing written */
+}
+
+static int
+fb_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, int nprot,
+ vm_memattr_t *memattr)
+{
+ struct fb_info *info;
+
+ info = dev->si_drv1;
+
+ if (info->fb_flags & FB_FLAG_NOMMAP)
+ return (ENODEV);
+
+ if (offset >= 0 && offset < info->fb_size) {
+ if (info->fb_pbase == 0)
+ *paddr = vtophys((uint8_t *)info->fb_vbase + offset);
+ else
+ *paddr = info->fb_pbase + offset;
+ if (info->fb_flags & FB_FLAG_MEMATTR)
+ *memattr = info->fb_memattr;
+ return (0);
+ }
+ return (EINVAL);
+}
+
+static int
+fb_init(struct fb_list_entry *entry, int unit)
+{
+ struct fb_info *info;
+
+ info = entry->fb_info;
+ entry->fb_si = make_dev(&fb_cdevsw, unit, UID_ROOT, GID_WHEEL,
+ 0600, "fb%d", unit);
+ entry->fb_si->si_drv1 = info;
+ info->fb_cdev = entry->fb_si;
+
+ return (0);
+}
+
+int
+fbd_list()
+{
+ struct fb_list_entry *entry;
+
+ if (LIST_EMPTY(&fb_list_head))
+ return (ENOENT);
+
+ LIST_FOREACH(entry, &fb_list_head, fb_list) {
+ printf("FB %s @%p\n", entry->fb_info->fb_name,
+ (void *)entry->fb_info->fb_pbase);
+ }
+
+ return (0);
+}
+
+static struct fb_list_entry *
+fbd_find(struct fb_info* info)
+{
+ struct fb_list_entry *entry, *tmp;
+
+ LIST_FOREACH_SAFE(entry, &fb_list_head, fb_list, tmp) {
+ if (entry->fb_info == info) {
+ return (entry);
+ }
+ }
+
+ return (NULL);
+}
+
+int
+fbd_register(struct fb_info* info)
+{
+ struct fb_list_entry *entry;
+ int err, first;
+
+ first = 0;
+ if (LIST_EMPTY(&fb_list_head))
+ first++;
+
+ entry = fbd_find(info);
+ if (entry != NULL) {
+ /* XXX Update framebuffer params */
+ return (0);
+ }
+
+ entry = malloc(sizeof(struct fb_list_entry), M_DEVBUF, M_WAITOK|M_ZERO);
+ entry->fb_info = info;
+
+ LIST_INSERT_HEAD(&fb_list_head, entry, fb_list);
+
+ err = fb_init(entry, framebuffer_dev_unit++);
+ if (err)
+ return (err);
+ if (first) {
+ err = vt_fb_attach(info);
+ if (err)
+ return (err);
+ }
+
+ return (0);
+}
+
+int
+fbd_unregister(struct fb_info* info)
+{
+ struct fb_list_entry *entry, *tmp;
+
+ LIST_FOREACH_SAFE(entry, &fb_list_head, fb_list, tmp) {
+ if (entry->fb_info == info) {
+ LIST_REMOVE(entry, fb_list);
+ if (LIST_EMPTY(&fb_list_head))
+ vt_fb_detach(info);
+ free(entry, M_DEVBUF);
+ return (0);
+ }
+ }
+
+ return (ENOENT);
+}
+
+static void
+register_fb_wrap(void *arg, void *ptr)
+{
+
+ fbd_register((struct fb_info *)ptr);
+}
+
+static void
+unregister_fb_wrap(void *arg, void *ptr)
+{
+
+ fbd_unregister((struct fb_info *)ptr);
+}
+
+static void
+fbd_evh_init(void *ctx)
+{
+
+ EVENTHANDLER_REGISTER(register_framebuffer, register_fb_wrap, NULL,
+ EVENTHANDLER_PRI_ANY);
+ EVENTHANDLER_REGISTER(unregister_framebuffer, unregister_fb_wrap, NULL,
+ EVENTHANDLER_PRI_ANY);
+}
+
+/* Newbus methods. */
+static int
+fbd_probe(device_t dev)
+{
+
+ return (BUS_PROBE_NOWILDCARD);
+}
+
+static int
+fbd_attach(device_t dev)
+{
+ struct fbd_softc *sc;
+ int err;
+
+ sc = device_get_softc(dev);
+
+ sc->sc_dev = dev;
+ sc->sc_info = FB_GETINFO(device_get_parent(dev));
+ if (sc->sc_info == NULL)
+ return (ENXIO);
+ err = fbd_register(sc->sc_info);
+
+ return (err);
+}
+
+static int
+fbd_detach(device_t dev)
+{
+ struct fbd_softc *sc;
+ int err;
+
+ sc = device_get_softc(dev);
+
+ err = fbd_unregister(sc->sc_info);
+
+ return (err);
+}
+
+static device_method_t fbd_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_probe, fbd_probe),
+ DEVMETHOD(device_attach, fbd_attach),
+ DEVMETHOD(device_detach, fbd_detach),
+
+ DEVMETHOD(device_shutdown, bus_generic_shutdown),
+
+ { 0, 0 }
+};
+
+driver_t fbd_driver = {
+ "fbd",
+ fbd_methods,
+ sizeof(struct fbd_softc)
+};
+
+devclass_t fbd_devclass;
+
+DRIVER_MODULE(fbd, fb, fbd_driver, fbd_devclass, 0, 0);
+DRIVER_MODULE(fbd, drmn, fbd_driver, fbd_devclass, 0, 0);
+DRIVER_MODULE(fbd, udl, fbd_driver, fbd_devclass, 0, 0);
+MODULE_VERSION(fbd, 1);
+
diff --git a/freebsd/sys/dev/fb/fbreg.h b/freebsd/sys/dev/fb/fbreg.h
new file mode 100644
index 00000000..d5bfd0da
--- /dev/null
+++ b/freebsd/sys/dev/fb/fbreg.h
@@ -0,0 +1,345 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _DEV_FB_FBREG_H_
+#define _DEV_FB_FBREG_H_
+
+#ifdef _KERNEL
+
+#define V_MAX_ADAPTERS 8 /* XXX */
+
+/* some macros */
+#if defined(__amd64__) || defined(__i386__)
+
+static __inline void
+copyw(uint16_t *src, uint16_t *dst, size_t size)
+{
+ size >>= 1;
+ while (size--)
+ *dst++ = *src++;
+}
+#define bcopy_io(s, d, c) copyw((void*)(s), (void*)(d), (c))
+#define bcopy_toio(s, d, c) copyw((void*)(s), (void*)(d), (c))
+#define bcopy_fromio(s, d, c) copyw((void*)(s), (void*)(d), (c))
+#define bzero_io(d, c) bzero((void *)(d), (c))
+#define fill_io(p, d, c) fill((p), (void *)(d), (c))
+#define fillw_io(p, d, c) fillw((p), (void *)(d), (c))
+#elif defined(__sparc64__)
+static __inline void
+fillw(int val, uint16_t *buf, size_t size)
+{
+ while (size--)
+ *buf++ = val;
+}
+#elif defined(__powerpc__)
+
+#define bcopy_io(s, d, c) ofwfb_bcopy((void *)(s), (void *)(d), (c))
+#define bcopy_toio(s, d, c) ofwfb_bcopy((void *)(s), (void *)(d), (c))
+#define bcopy_fromio(s, d, c) ofwfb_bcopy((void *)(s), (void *)(d), (c))
+#define bzero_io(d, c) ofwfb_bzero((void *)(d), (c))
+#define fillw(p, d, c) ofwfb_fillw((p), (void *)(d), (c))
+#define fillw_io(p, d, c) ofwfb_fillw((p), (void *)(d), (c))
+#define readw(a) ofwfb_readw((u_int16_t *)(a))
+#define writew(a, v) ofwfb_writew((u_int16_t *)(a), (v))
+void ofwfb_bcopy(const void *s, void *d, size_t c);
+void ofwfb_bzero(void *d, size_t c);
+void ofwfb_fillw(int pat, void *base, size_t cnt);
+u_int16_t ofwfb_readw(u_int16_t *addr);
+void ofwfb_writew(u_int16_t *addr, u_int16_t val);
+
+#elif defined(__mips__) || defined(__arm__)
+
+/*
+ * Use amd64/i386-like settings under the assumption that MIPS-based display
+ * drivers will have to add a level of indirection between a syscons-managed
+ * frame buffer and the actual video hardware. We are forced to do this
+ * because syscons doesn't carry around required busspace handles and tags to
+ * use here. This is only really a problem for true VGA devices hooked up to
+ * MIPS, as others will be performing a translation anyway.
+ */
+#define bcopy_io(s, d, c) memcpy((void *)(d), (void *)(s), (c))
+#define bcopy_toio(s, d, c) memcpy((void *)(d), (void *)(s), (c))
+#define bcopy_fromio(s, d, c) memcpy((void *)(d), (void *)(s), (c))
+#define bzero_io(d, c) memset((void *)(d), 0, (c))
+#define fill_io(p, d, c) memset((void *)(d), (p), (c))
+static __inline void
+fillw(int val, uint16_t *buf, size_t size)
+{
+ while (size--)
+ *buf++ = val;
+}
+#define fillw_io(p, d, c) fillw((p), (void *)(d), (c))
+
+#if defined(__arm__)
+#define readw(a) (*(uint16_t*)(a))
+#define writew(a, v) (*(uint16_t*)(a) = (v))
+#endif
+
+#else /* !__i386__ && !__amd64__ && !__sparc64__ && !__powerpc__ */
+#define bcopy_io(s, d, c) memcpy_io((d), (s), (c))
+#define bcopy_toio(s, d, c) memcpy_toio((d), (void *)(s), (c))
+#define bcopy_fromio(s, d, c) memcpy_fromio((void *)(d), (s), (c))
+#define bzero_io(d, c) memset_io((d), 0, (c))
+#define fill_io(p, d, c) memset_io((d), (p), (c))
+#define fillw(p, d, c) memsetw((d), (p), (c))
+#define fillw_io(p, d, c) memsetw_io((d), (p), (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, int width,
+ u_char *data, int c, int count);
+typedef int vi_load_font_t(video_adapter_t *adp, int page, int size, int width,
+ 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);
+/* defined in sys/fbio.h
+#define V_DISPLAY_ON 0
+#define V_DISPLAY_BLANK 1
+#define V_DISPLAY_STAND_BY 2
+#define V_DISPLAY_SUSPEND 3
+*/
+typedef int vi_mmap_t(video_adapter_t *adp, vm_ooffset_t offset,
+ vm_paddr_t *paddr, int prot, vm_memattr_t *memattr);
+typedef int vi_ioctl_t(video_adapter_t *adp, u_long cmd, caddr_t data);
+typedef int vi_clear_t(video_adapter_t *adp);
+typedef int vi_fill_rect_t(video_adapter_t *adp, int val, int x, int y,
+ int cx, int cy);
+typedef int vi_bitblt_t(video_adapter_t *adp, ...);
+typedef int vi_diag_t(video_adapter_t *adp, int level);
+typedef int vi_save_cursor_palette_t(video_adapter_t *adp, u_char *palette);
+typedef int vi_load_cursor_palette_t(video_adapter_t *adp, u_char *palette);
+typedef int vi_copy_t(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst,
+ int n);
+typedef int vi_putp_t(video_adapter_t *adp, vm_offset_t off, u_int32_t p,
+ u_int32_t a, int size, int bpp, int bit_ltor,
+ int byte_ltor);
+typedef int vi_putc_t(video_adapter_t *adp, vm_offset_t off, u_int8_t c,
+ u_int8_t a);
+typedef int vi_puts_t(video_adapter_t *adp, vm_offset_t off, u_int16_t *s,
+ int len);
+typedef int vi_putm_t(video_adapter_t *adp, int x, int y, u_int8_t *pixel_image,
+ u_int32_t pixel_mask, int size, int width);
+
+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_ioctl_t *ioctl;
+ vi_clear_t *clear;
+ vi_fill_rect_t *fill_rect;
+ vi_bitblt_t *bitblt;
+ int (*reserved1)(void);
+ int (*reserved2)(void);
+ vi_diag_t *diag;
+ vi_save_cursor_palette_t *save_cursor_palette;
+ vi_load_cursor_palette_t *load_cursor_palette;
+ vi_copy_t *copy;
+ vi_putp_t *putp;
+ vi_putc_t *putc;
+ vi_puts_t *puts;
+ vi_putm_t *putm;
+} video_switch_t;
+
+#define vidd_probe(unit, adpp, arg, flags) \
+ (*vidsw[(adp)->va_index]->probe)((unit), (adpp), (arg), (flags))
+#define vidd_init(unit, adp, flags) \
+ (*vidsw[(adp)->va_index]->init)((unit), (adp), (flags))
+#define vidd_get_info(adp, mode, info) \
+ (*vidsw[(adp)->va_index]->get_info)((adp), (mode), (info))
+#define vidd_query_mode(adp, mode) \
+ (*vidsw[(adp)->va_index]->query_mode)((adp), (mode))
+#define vidd_set_mode(adp, mode) \
+ (*vidsw[(adp)->va_index]->set_mode)((adp), (mode))
+#define vidd_save_font(adp, page, size, width, data, c, count) \
+ (*vidsw[(adp)->va_index]->save_font)((adp), (page), (size), \
+ (width), (data), (c), (count))
+#define vidd_load_font(adp, page, size, width, data, c, count) \
+ (*vidsw[(adp)->va_index]->load_font)((adp), (page), (size), \
+ (width), (data), (c), (count))
+#define vidd_show_font(adp, page) \
+ (*vidsw[(adp)->va_index]->show_font)((adp), (page))
+#define vidd_save_palette(adp, pallete) \
+ (*vidsw[(adp)->va_index]->save_palette)((adp), (pallete))
+#define vidd_load_palette(adp, pallete) \
+ (*vidsw[(adp)->va_index]->load_palette)((adp), (pallete))
+#define vidd_set_border(adp, border) \
+ (*vidsw[(adp)->va_index]->set_border)((adp), (border))
+#define vidd_save_state(adp, p, size) \
+ (*vidsw[(adp)->va_index]->save_state)((adp), (p), (size))
+#define vidd_load_state(adp, p) \
+ (*vidsw[(adp)->va_index]->load_state)((adp), (p))
+#define vidd_set_win_org(adp, offset) \
+ (*vidsw[(adp)->va_index]->set_win_org)((adp), (offset))
+#define vidd_read_hw_cursor(adp, col, row) \
+ (*vidsw[(adp)->va_index]->read_hw_cursor)((adp), (col), (row))
+#define vidd_set_hw_cursor(adp, col, row) \
+ (*vidsw[(adp)->va_index]->set_hw_cursor)((adp), (col), (row))
+#define vidd_set_hw_cursor_shape(adp, base, height, celsize, blink) \
+ (*vidsw[(adp)->va_index]->set_hw_cursor_shape)((adp), (base), \
+ (height), (celsize), (blink))
+#define vidd_blank_display(adp, mode) \
+ (*vidsw[(adp)->va_index]->blank_display)((adp), (mode))
+#define vidd_mmap(adp, offset, paddr, prot, memattr) \
+ (*vidsw[(adp)->va_index]->mmap)((adp), (offset), (paddr), \
+ (prot), (memattr))
+#define vidd_ioctl(adp, cmd, data) \
+ (*vidsw[(adp)->va_index]->ioctl)((adp), (cmd), (data))
+#define vidd_clear(adp) \
+ (*vidsw[(adp)->va_index]->clear)((adp))
+#define vidd_fill_rect(adp, val, x, y, cx, cy) \
+ (*vidsw[(adp)->va_index]->fill_rect)((adp), (val), (x), (y), \
+ (cx), (cy))
+#define vidd_bitblt(adp, ...) \
+ (*vidsw[(adp)->va_index]->bitblt)(adp, __VA_ARGS__)
+#define vidd_diag(adp, level) \
+ (*vidsw[(adp)->va_index]->diag)((adp), (level))
+#define vidd_save_cursor_palette(adp, palette) \
+ (*vidsw[(adp)->va_index]->save_cursor_palette)((adp), (palette))
+#define vidd_load_cursor_palette(adp, palette) \
+ (*vidsw[(adp)->va_index]->load_cursor_palette)((adp), (palette))
+#define vidd_copy(adp, src, dst, n) \
+ (*vidsw[(adp)->va_index]->copy)((adp), (src), (dst), (n))
+#define vidd_putp(adp, offset, p, a, size, bpp, bit_ltor1, byte_ltor2) \
+ (*vidsw[(adp)->va_index]->putp)((adp), (offset), (p), (a), \
+ (size), (bpp), (bit_ltor1), (bit_ltor2))
+#define vidd_putc(adp, offset, c, a) \
+ (*vidsw[(adp)->va_index]->putc)((adp), (offset), (c), (a))
+#define vidd_puts(adp, offset, s, len) \
+ (*vidsw[(adp)->va_index]->puts)((adp), (offset), (s), (len))
+#define vidd_putm(adp, x, y, pixel_image, pixel_mask, size, width) \
+ (*vidsw[(adp)->va_index]->putm)((adp), (x), (y), (pixel_image), \
+ (pixel_mask), (size), (width))
+
+/* 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;
+
+/* 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(int unit, video_adapter_t *adp,
+ struct cdevsw *cdevsw);
+int fb_detach(int unit, video_adapter_t *adp,
+ struct cdevsw *cdevsw);
+
+/* generic frame buffer cdev driver functions */
+
+typedef struct genfb_softc {
+ int gfb_flags; /* flag/status bits */
+#define FB_OPEN (1 << 0)
+} genfb_softc_t;
+
+int genfbopen(genfb_softc_t *sc, video_adapter_t *adp,
+ int flag, int mode, struct thread *td);
+int genfbclose(genfb_softc_t *sc, video_adapter_t *adp,
+ int flag, int mode, struct thread *td);
+int genfbread(genfb_softc_t *sc, video_adapter_t *adp,
+ struct uio *uio, int flag);
+int genfbwrite(genfb_softc_t *sc, video_adapter_t *adp,
+ struct uio *uio, int flag);
+int genfbioctl(genfb_softc_t *sc, video_adapter_t *adp,
+ u_long cmd, caddr_t arg, int flag, struct thread *td);
+int genfbmmap(genfb_softc_t *sc, video_adapter_t *adp,
+ vm_ooffset_t offset, vm_paddr_t *paddr,
+ int prot, vm_memattr_t *memattr);
+
+#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);
+int fb_type(int adp_type);
+int fb_commonioctl(video_adapter_t *adp, u_long cmd, caddr_t arg);
+
+#endif /* _KERNEL */
+
+#endif /* !_DEV_FB_FBREG_H_ */
diff --git a/freebsd/sys/dev/vt/colors/vt_termcolors.h b/freebsd/sys/dev/vt/colors/vt_termcolors.h
new file mode 100644
index 00000000..8a8c7b65
--- /dev/null
+++ b/freebsd/sys/dev/vt/colors/vt_termcolors.h
@@ -0,0 +1,63 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Aleksandr Rybalko under sponsorship from the
+ * FreeBSD Foundation.
+ *
+ * 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.
+ * 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ * $FreeBSD$
+ */
+
+enum vt_color_format {
+ COLOR_FORMAT_BW = 0,
+ COLOR_FORMAT_GRAY,
+ COLOR_FORMAT_VGA, /* Color Index. */
+ COLOR_FORMAT_RGB,
+ COLOR_FORMAT_ARGB,
+ COLOR_FORMAT_CMYK,
+ COLOR_FORMAT_HSL,
+ COLOR_FORMAT_YUV,
+ COLOR_FORMAT_YCbCr,
+ COLOR_FORMAT_YPbPr,
+
+ COLOR_FORMAT_MAX = 15,
+};
+
+#define NCOLORS 16
+
+/*
+ * Between console's palette and VGA's one:
+ * - blue and red are swapped (1 <-> 4)
+ * - yellow and cyan are swapped (3 <-> 6)
+ */
+static const int cons_to_vga_colors[NCOLORS] = {
+ 0, 4, 2, 6, 1, 5, 3, 7,
+ 8, 12, 10, 14, 9, 13, 11, 15
+};
+
+/* Helper to fill color map used by driver */
+int vt_generate_cons_palette(uint32_t *palette, int format, uint32_t rmax,
+ int roffset, uint32_t gmax, int goffset, uint32_t bmax, int boffset);
diff --git a/freebsd/sys/dev/vt/hw/fb/vt_fb.h b/freebsd/sys/dev/vt/hw/fb/vt_fb.h
new file mode 100644
index 00000000..42b395e8
--- /dev/null
+++ b/freebsd/sys/dev/vt/hw/fb/vt_fb.h
@@ -0,0 +1,54 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Aleksandr Rybalko under sponsorship from the
+ * FreeBSD Foundation.
+ *
+ * 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.
+ * 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _DEV_VT_HW_FB_VT_FB_H_
+#define _DEV_VT_HW_FB_VT_FB_H_
+/* Generic framebuffer interface call vt_fb_attach to init VT(9) */
+int vt_fb_attach(struct fb_info *info);
+void vt_fb_resume(struct vt_device *vd);
+void vt_fb_suspend(struct vt_device *vd);
+int vt_fb_detach(struct fb_info *info);
+
+vd_init_t vt_fb_init;
+vd_fini_t vt_fb_fini;
+vd_blank_t vt_fb_blank;
+vd_bitblt_text_t vt_fb_bitblt_text;
+vd_invalidate_text_t vt_fb_invalidate_text;
+vd_bitblt_bmp_t vt_fb_bitblt_bitmap;
+vd_drawrect_t vt_fb_drawrect;
+vd_setpixel_t vt_fb_setpixel;
+vd_postswitch_t vt_fb_postswitch;
+vd_fb_ioctl_t vt_fb_ioctl;
+vd_fb_mmap_t vt_fb_mmap;
+
+#endif /* _DEV_VT_HW_FB_VT_FB_H_ */
diff --git a/freebsd/sys/dev/vt/vt.h b/freebsd/sys/dev/vt/vt.h
new file mode 100644
index 00000000..34d4c228
--- /dev/null
+++ b/freebsd/sys/dev/vt/vt.h
@@ -0,0 +1,474 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2009, 2013 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Ed Schouten under sponsorship from the
+ * FreeBSD Foundation.
+ *
+ * Portions of this software were developed by Oleksandr Rybalko
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * 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.
+ * 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _DEV_VT_VT_H_
+#define _DEV_VT_VT_H_
+
+#include <sys/param.h>
+#include <sys/_lock.h>
+#include <sys/_mutex.h>
+#include <sys/callout.h>
+#include <sys/condvar.h>
+#include <sys/conf.h>
+#include <sys/consio.h>
+#include <sys/kbio.h>
+#include <sys/mouse.h>
+#include <sys/terminal.h>
+#include <sys/sysctl.h>
+
+#include <rtems/bsd/local/opt_syscons.h>
+#include <rtems/bsd/local/opt_splash.h>
+
+#ifndef VT_MAXWINDOWS
+#ifdef MAXCONS
+#define VT_MAXWINDOWS MAXCONS
+#else
+#define VT_MAXWINDOWS 12
+#endif
+#endif
+
+#ifndef VT_ALT_TO_ESC_HACK
+#define VT_ALT_TO_ESC_HACK 1
+#endif
+
+#define VT_CONSWINDOW 0
+
+#if defined(SC_TWOBUTTON_MOUSE) || defined(VT_TWOBUTTON_MOUSE)
+#define VT_MOUSE_PASTEBUTTON MOUSE_BUTTON3DOWN /* right button */
+#define VT_MOUSE_EXTENDBUTTON MOUSE_BUTTON2DOWN /* not really used */
+#else
+#define VT_MOUSE_PASTEBUTTON MOUSE_BUTTON2DOWN /* middle button */
+#define VT_MOUSE_EXTENDBUTTON MOUSE_BUTTON3DOWN /* right button */
+#endif /* defined(SC_TWOBUTTON_MOUSE) || defined(VT_TWOBUTTON_MOUSE) */
+
+#define SC_DRIVER_NAME "vt"
+#ifdef VT_DEBUG
+#define DPRINTF(_l, ...) if (vt_debug > (_l)) printf( __VA_ARGS__ )
+#define VT_CONSOLECTL_DEBUG
+#define VT_SYSMOUSE_DEBUG
+#else
+#define DPRINTF(_l, ...) do {} while (0)
+#endif
+#define ISSIGVALID(sig) ((sig) > 0 && (sig) < NSIG)
+
+#define VT_SYSCTL_INT(_name, _default, _descr) \
+int vt_##_name = (_default); \
+SYSCTL_INT(_kern_vt, OID_AUTO, _name, CTLFLAG_RWTUN, &vt_##_name, 0, _descr)
+
+struct vt_driver;
+
+void vt_allocate(const struct vt_driver *, void *);
+void vt_deallocate(const struct vt_driver *, void *);
+
+typedef unsigned int vt_axis_t;
+
+/*
+ * List of locks
+ * (d) locked by vd_lock
+ * (b) locked by vb_lock
+ * (G) locked by Giant
+ * (u) unlocked, locked by higher levels
+ * (c) const until freeing
+ * (?) yet to be determined
+ */
+
+/*
+ * Per-device datastructure.
+ */
+
+#ifndef SC_NO_CUTPASTE
+struct vt_mouse_cursor;
+#endif
+
+struct vt_pastebuf {
+ term_char_t *vpb_buf; /* Copy-paste buffer. */
+ unsigned int vpb_bufsz; /* Buffer size. */
+ unsigned int vpb_len; /* Length of a last selection. */
+};
+
+struct vt_device {
+ struct vt_window *vd_windows[VT_MAXWINDOWS]; /* (c) Windows. */
+ struct vt_window *vd_curwindow; /* (d) Current window. */
+ struct vt_window *vd_savedwindow;/* (?) Saved for suspend. */
+ struct vt_pastebuf vd_pastebuf; /* (?) Copy/paste buf. */
+ const struct vt_driver *vd_driver; /* (c) Graphics driver. */
+ void *vd_softc; /* (u) Driver data. */
+ const struct vt_driver *vd_prev_driver;/* (?) Previous driver. */
+ void *vd_prev_softc; /* (?) Previous driver data. */
+ device_t vd_video_dev; /* (?) Video adapter. */
+#ifndef SC_NO_CUTPASTE
+ struct vt_mouse_cursor *vd_mcursor; /* (?) Cursor bitmap. */
+ term_color_t vd_mcursor_fg; /* (?) Cursor fg color. */
+ term_color_t vd_mcursor_bg; /* (?) Cursor bg color. */
+ vt_axis_t vd_mx_drawn; /* (?) Mouse X and Y */
+ vt_axis_t vd_my_drawn; /* as of last redraw. */
+ int vd_mshown; /* (?) Mouse shown during */
+#endif /* last redrawn. */
+ uint16_t vd_mx; /* (?) Current mouse X. */
+ uint16_t vd_my; /* (?) current mouse Y. */
+ uint32_t vd_mstate; /* (?) Mouse state. */
+ vt_axis_t vd_width; /* (?) Screen width. */
+ vt_axis_t vd_height; /* (?) Screen height. */
+ size_t vd_transpose; /* (?) Screen offset in FB */
+ struct mtx vd_lock; /* Per-device lock. */
+ struct cv vd_winswitch; /* (d) Window switch notify. */
+ struct callout vd_timer; /* (d) Display timer. */
+ volatile unsigned int vd_timer_armed;/* (?) Display timer started.*/
+ int vd_flags; /* (d) Device flags. */
+#define VDF_TEXTMODE 0x01 /* Do text mode rendering. */
+#define VDF_SPLASH 0x02 /* Splash screen active. */
+#define VDF_ASYNC 0x04 /* vt_timer() running. */
+#define VDF_INVALID 0x08 /* Entire screen should be re-rendered. */
+#define VDF_DEAD 0x10 /* Early probing found nothing. */
+#define VDF_INITIALIZED 0x20 /* vtterm_cnprobe already done. */
+#define VDF_MOUSECURSOR 0x40 /* Mouse cursor visible. */
+#define VDF_QUIET_BELL 0x80 /* Disable bell. */
+#define VDF_SUSPENDED 0x100 /* Device has been suspended. */
+#define VDF_DOWNGRADE 0x8000 /* The driver is being downgraded. */
+ int vd_keyboard; /* (G) Keyboard index. */
+ unsigned int vd_kbstate; /* (?) Device unit. */
+ unsigned int vd_unit; /* (c) Device unit. */
+ int vd_altbrk; /* (?) Alt break seq. state */
+ term_char_t *vd_drawn; /* (?) Most recent char drawn. */
+ term_color_t *vd_drawnfg; /* (?) Most recent fg color drawn. */
+ term_color_t *vd_drawnbg; /* (?) Most recent bg color drawn. */
+};
+
+#define VD_PASTEBUF(vd) ((vd)->vd_pastebuf.vpb_buf)
+#define VD_PASTEBUFSZ(vd) ((vd)->vd_pastebuf.vpb_bufsz)
+#define VD_PASTEBUFLEN(vd) ((vd)->vd_pastebuf.vpb_len)
+
+#define VT_LOCK(vd) mtx_lock(&(vd)->vd_lock)
+#define VT_UNLOCK(vd) mtx_unlock(&(vd)->vd_lock)
+#define VT_LOCK_ASSERT(vd, what) mtx_assert(&(vd)->vd_lock, what)
+
+void vt_resume(struct vt_device *vd);
+void vt_resume_flush_timer(struct vt_window *vw, int ms);
+void vt_suspend(struct vt_device *vd);
+
+/*
+ * Per-window terminal screen buffer.
+ *
+ * Because redrawing is performed asynchronously, the buffer keeps track
+ * of a rectangle that needs to be redrawn (vb_dirtyrect). Because this
+ * approach seemed to cause suboptimal performance (when the top left
+ * and the bottom right of the screen are modified), it also uses a set
+ * of bitmasks to keep track of the rows and columns (mod 64) that have
+ * been modified.
+ */
+
+struct vt_buf {
+ struct mtx vb_lock; /* Buffer lock. */
+ term_pos_t vb_scr_size; /* (b) Screen dimensions. */
+ int vb_flags; /* (b) Flags. */
+#define VBF_CURSOR 0x1 /* Cursor visible. */
+#define VBF_STATIC 0x2 /* Buffer is statically allocated. */
+#define VBF_MTX_INIT 0x4 /* Mutex initialized. */
+#define VBF_SCROLL 0x8 /* scroll locked mode. */
+#define VBF_HISTORY_FULL 0x10 /* All rows filled. */
+ unsigned int vb_history_size;
+ unsigned int vb_roffset; /* (b) History rows offset. */
+ unsigned int vb_curroffset; /* (b) Saved rows offset. */
+ term_pos_t vb_cursor; /* (u) Cursor position. */
+ term_pos_t vb_mark_start; /* (b) Copy region start. */
+ term_pos_t vb_mark_end; /* (b) Copy region end. */
+ int vb_mark_last; /* Last mouse event. */
+ term_rect_t vb_dirtyrect; /* (b) Dirty rectangle. */
+ term_char_t *vb_buffer; /* (u) Data buffer. */
+ term_char_t **vb_rows; /* (u) Array of rows */
+};
+
+#ifdef SC_HISTORY_SIZE
+#define VBF_DEFAULT_HISTORY_SIZE SC_HISTORY_SIZE
+#else
+#define VBF_DEFAULT_HISTORY_SIZE 500
+#endif
+
+void vtbuf_lock(struct vt_buf *);
+void vtbuf_unlock(struct vt_buf *);
+void vtbuf_copy(struct vt_buf *, const term_rect_t *, const term_pos_t *);
+void vtbuf_fill(struct vt_buf *, const term_rect_t *, term_char_t);
+void vtbuf_init_early(struct vt_buf *);
+void vtbuf_init(struct vt_buf *, const term_pos_t *);
+void vtbuf_grow(struct vt_buf *, const term_pos_t *, unsigned int);
+void vtbuf_putchar(struct vt_buf *, const term_pos_t *, term_char_t);
+void vtbuf_cursor_position(struct vt_buf *, const term_pos_t *);
+void vtbuf_scroll_mode(struct vt_buf *vb, int yes);
+void vtbuf_dirty(struct vt_buf *vb, const term_rect_t *area);
+void vtbuf_undirty(struct vt_buf *, term_rect_t *);
+void vtbuf_sethistory_size(struct vt_buf *, unsigned int);
+int vtbuf_iscursor(const struct vt_buf *vb, int row, int col);
+void vtbuf_cursor_visibility(struct vt_buf *, int);
+#ifndef SC_NO_CUTPASTE
+int vtbuf_set_mark(struct vt_buf *vb, int type, int col, int row);
+int vtbuf_get_marked_len(struct vt_buf *vb);
+void vtbuf_extract_marked(struct vt_buf *vb, term_char_t *buf, int sz);
+#endif
+
+#define VTB_MARK_NONE 0
+#define VTB_MARK_END 1
+#define VTB_MARK_START 2
+#define VTB_MARK_WORD 3
+#define VTB_MARK_ROW 4
+#define VTB_MARK_EXTEND 5
+#define VTB_MARK_MOVE 6
+
+#define VTBUF_SLCK_ENABLE(vb) vtbuf_scroll_mode((vb), 1)
+#define VTBUF_SLCK_DISABLE(vb) vtbuf_scroll_mode((vb), 0)
+
+#define VTBUF_MAX_HEIGHT(vb) \
+ ((vb)->vb_history_size)
+#define VTBUF_GET_ROW(vb, r) \
+ ((vb)->vb_rows[((vb)->vb_roffset + (r)) % VTBUF_MAX_HEIGHT(vb)])
+#define VTBUF_GET_FIELD(vb, r, c) \
+ ((vb)->vb_rows[((vb)->vb_roffset + (r)) % VTBUF_MAX_HEIGHT(vb)][(c)])
+#define VTBUF_FIELD(vb, r, c) \
+ ((vb)->vb_rows[((vb)->vb_curroffset + (r)) % VTBUF_MAX_HEIGHT(vb)][(c)])
+#define VTBUF_ISCURSOR(vb, r, c) \
+ vtbuf_iscursor((vb), (r), (c))
+#define VTBUF_DIRTYROW(mask, row) \
+ ((mask)->vbm_row & ((uint64_t)1 << ((row) % 64)))
+#define VTBUF_DIRTYCOL(mask, col) \
+ ((mask)->vbm_col & ((uint64_t)1 << ((col) % 64)))
+#define VTBUF_SPACE_CHAR(attr) (' ' | (attr))
+
+#define VHS_SET 0
+#define VHS_CUR 1
+#define VHS_END 2
+int vthistory_seek(struct vt_buf *, int offset, int whence);
+void vthistory_addlines(struct vt_buf *vb, int offset);
+void vthistory_getpos(const struct vt_buf *, unsigned int *offset);
+
+/*
+ * Per-window datastructure.
+ */
+
+struct vt_window {
+ struct vt_device *vw_device; /* (c) Device. */
+ struct terminal *vw_terminal; /* (c) Terminal. */
+ struct vt_buf vw_buf; /* (u) Screen buffer. */
+ struct vt_font *vw_font; /* (d) Graphical font. */
+ term_rect_t vw_draw_area; /* (?) Drawable area. */
+ unsigned int vw_number; /* (c) Window number. */
+ int vw_kbdmode; /* (?) Keyboard mode. */
+ int vw_prev_kbdmode;/* (?) Previous mode. */
+ int vw_kbdstate; /* (?) Keyboard state. */
+ int vw_grabbed; /* (?) Grab count. */
+ char *vw_kbdsq; /* Escape sequence queue*/
+ unsigned int vw_flags; /* (d) Per-window flags. */
+ int vw_mouse_level;/* Mouse op mode. */
+#define VWF_BUSY 0x1 /* Busy reconfiguring device. */
+#define VWF_OPENED 0x2 /* TTY in use. */
+#define VWF_SCROLL 0x4 /* Keys influence scrollback. */
+#define VWF_CONSOLE 0x8 /* Kernel message console window. */
+#define VWF_VTYLOCK 0x10 /* Prevent window switch. */
+#define VWF_MOUSE_HIDE 0x20 /* Disable mouse events processing. */
+#define VWF_READY 0x40 /* Window fully initialized. */
+#define VWF_GRAPHICS 0x80 /* Window in graphics mode (KDSETMODE). */
+#define VWF_SWWAIT_REL 0x10000 /* Program wait for VT acquire is done. */
+#define VWF_SWWAIT_ACQ 0x20000 /* Program wait for VT release is done. */
+ pid_t vw_pid; /* Terminal holding process */
+ struct proc *vw_proc;
+ struct vt_mode vw_smode; /* switch mode */
+ struct callout vw_proc_dead_timer;
+ struct vt_window *vw_switch_to;
+};
+
+#define VT_AUTO 0 /* switching is automatic */
+#define VT_PROCESS 1 /* switching controlled by prog */
+#define VT_KERNEL 255 /* switching controlled in kernel */
+
+#define IS_VT_PROC_MODE(vw) ((vw)->vw_smode.mode == VT_PROCESS)
+
+/*
+ * Per-device driver routines.
+ */
+
+typedef int vd_init_t(struct vt_device *vd);
+typedef int vd_probe_t(struct vt_device *vd);
+typedef void vd_fini_t(struct vt_device *vd, void *softc);
+typedef void vd_postswitch_t(struct vt_device *vd);
+typedef void vd_blank_t(struct vt_device *vd, term_color_t color);
+typedef void vd_bitblt_text_t(struct vt_device *vd, const struct vt_window *vw,
+ const term_rect_t *area);
+typedef void vd_invalidate_text_t(struct vt_device *vd,
+ const term_rect_t *area);
+typedef void vd_bitblt_bmp_t(struct vt_device *vd, const struct vt_window *vw,
+ const uint8_t *pattern, const uint8_t *mask,
+ unsigned int width, unsigned int height,
+ unsigned int x, unsigned int y, term_color_t fg, term_color_t bg);
+typedef int vd_fb_ioctl_t(struct vt_device *, u_long, caddr_t, struct thread *);
+typedef int vd_fb_mmap_t(struct vt_device *, vm_ooffset_t, vm_paddr_t *, int,
+ vm_memattr_t *);
+typedef void vd_drawrect_t(struct vt_device *, int, int, int, int, int,
+ term_color_t);
+typedef void vd_setpixel_t(struct vt_device *, int, int, term_color_t);
+typedef void vd_suspend_t(struct vt_device *);
+typedef void vd_resume_t(struct vt_device *);
+
+struct vt_driver {
+ char vd_name[16];
+ /* Console attachment. */
+ vd_probe_t *vd_probe;
+ vd_init_t *vd_init;
+ vd_fini_t *vd_fini;
+
+ /* Drawing. */
+ vd_blank_t *vd_blank;
+ vd_drawrect_t *vd_drawrect;
+ vd_setpixel_t *vd_setpixel;
+ vd_bitblt_text_t *vd_bitblt_text;
+ vd_invalidate_text_t *vd_invalidate_text;
+ vd_bitblt_bmp_t *vd_bitblt_bmp;
+
+ /* Framebuffer ioctls, if present. */
+ vd_fb_ioctl_t *vd_fb_ioctl;
+
+ /* Framebuffer mmap, if present. */
+ vd_fb_mmap_t *vd_fb_mmap;
+
+ /* Update display setting on vt switch. */
+ vd_postswitch_t *vd_postswitch;
+
+ /* Suspend/resume handlers. */
+ vd_suspend_t *vd_suspend;
+ vd_resume_t *vd_resume;
+
+ /* Priority to know which one can override */
+ int vd_priority;
+#define VD_PRIORITY_DUMB 10
+#define VD_PRIORITY_GENERIC 100
+#define VD_PRIORITY_SPECIFIC 1000
+};
+
+/*
+ * Console device madness.
+ *
+ * Utility macro to make early vt(4) instances work.
+ */
+
+extern struct vt_device vt_consdev;
+extern struct terminal vt_consterm;
+extern const struct terminal_class vt_termclass;
+void vt_upgrade(struct vt_device *vd);
+
+#define PIXEL_WIDTH(w) ((w) / 8)
+#define PIXEL_HEIGHT(h) ((h) / 16)
+
+#ifndef VT_FB_MAX_WIDTH
+#define VT_FB_MAX_WIDTH 4096
+#endif
+#ifndef VT_FB_MAX_HEIGHT
+#define VT_FB_MAX_HEIGHT 2400
+#endif
+
+/* name argument is not used yet. */
+#define VT_DRIVER_DECLARE(name, drv) DATA_SET(vt_drv_set, drv)
+
+/*
+ * Fonts.
+ *
+ * Remapping tables are used to map Unicode points to glyphs. They need
+ * to be sorted, because vtfont_lookup() performs a binary search. Each
+ * font has two remapping tables, for normal and bold. When a character
+ * is not present in bold, it uses a normal glyph. When no glyph is
+ * available, it uses glyph 0, which is normally equal to U+FFFD.
+ */
+
+struct vt_font_map {
+ uint32_t vfm_src;
+ uint16_t vfm_dst;
+ uint16_t vfm_len;
+};
+
+struct vt_font {
+ struct vt_font_map *vf_map[VFNT_MAPS];
+ uint8_t *vf_bytes;
+ unsigned int vf_height, vf_width;
+ unsigned int vf_map_count[VFNT_MAPS];
+ unsigned int vf_refcount;
+};
+
+#ifndef SC_NO_CUTPASTE
+struct vt_mouse_cursor {
+ uint8_t map[64 * 64 / 8];
+ uint8_t mask[64 * 64 / 8];
+ uint8_t width;
+ uint8_t height;
+};
+#endif
+
+const uint8_t *vtfont_lookup(const struct vt_font *vf, term_char_t c);
+struct vt_font *vtfont_ref(struct vt_font *vf);
+void vtfont_unref(struct vt_font *vf);
+int vtfont_load(vfnt_t *f, struct vt_font **ret);
+
+/* Sysmouse. */
+void sysmouse_process_event(mouse_info_t *mi);
+#ifndef SC_NO_CUTPASTE
+void vt_mouse_event(int type, int x, int y, int event, int cnt, int mlevel);
+void vt_mouse_state(int show);
+#endif
+#define VT_MOUSE_SHOW 1
+#define VT_MOUSE_HIDE 0
+
+/* Utilities. */
+void vt_compute_drawable_area(struct vt_window *);
+void vt_determine_colors(term_char_t c, int cursor,
+ term_color_t *fg, term_color_t *bg);
+int vt_is_cursor_in_area(const struct vt_device *vd,
+ const term_rect_t *area);
+void vt_termsize(struct vt_device *, struct vt_font *, term_pos_t *);
+void vt_winsize(struct vt_device *, struct vt_font *, struct winsize *);
+
+/* Logos-on-boot. */
+#define VT_LOGOS_DRAW_BEASTIE 0
+#define VT_LOGOS_DRAW_ALT_BEASTIE 1
+#define VT_LOGOS_DRAW_ORB 2
+
+extern int vt_draw_logo_cpus;
+extern int vt_splash_cpu;
+extern int vt_splash_ncpu;
+extern int vt_splash_cpu_style;
+extern int vt_splash_cpu_duration;
+
+extern const unsigned int vt_logo_sprite_height;
+extern const unsigned int vt_logo_sprite_width;
+
+void vtterm_draw_cpu_logos(struct vt_device *);
+
+#endif /* !_DEV_VT_VT_H_ */
+