[PATCH 03/10] am335x display drivers: Import from FreeBSD
Vijay Kumar Banerjee
vijaykumar9597 at gmail.com
Fri Jul 26 11:22:49 UTC 2019
---
freebsd/sys/arm/ti/am335x/am335x_ecap.c | 202 ++++
freebsd/sys/arm/ti/am335x/am335x_lcd.c | 1085 ++++++++++++++++++++++
freebsd/sys/arm/ti/am335x/am335x_lcd.h | 60 ++
freebsd/sys/arm/ti/am335x/am335x_pwm.h | 35 +
freebsd/sys/arm/ti/am335x/am335x_pwmss.c | 165 ++++
freebsd/sys/dev/fb/fbreg.h | 345 +++++++
freebsd/sys/dev/syscons/syscons.h | 693 ++++++++++++++
freebsd/sys/dev/vt/vt.h | 474 ++++++++++
freebsd/sys/sys/consio.h | 468 ++++++++++
freebsd/sys/sys/fbio.h | 622 +++++++++++++
freebsd/sys/sys/terminal.h | 240 +++++
freebsd/sys/teken/teken.h | 221 +++++
12 files changed, 4610 insertions(+)
create mode 100644 freebsd/sys/arm/ti/am335x/am335x_ecap.c
create mode 100644 freebsd/sys/arm/ti/am335x/am335x_lcd.c
create mode 100644 freebsd/sys/arm/ti/am335x/am335x_lcd.h
create mode 100644 freebsd/sys/arm/ti/am335x/am335x_pwm.h
create mode 100644 freebsd/sys/arm/ti/am335x/am335x_pwmss.c
create mode 100644 freebsd/sys/dev/fb/fbreg.h
create mode 100644 freebsd/sys/dev/syscons/syscons.h
create mode 100644 freebsd/sys/dev/vt/vt.h
create mode 100644 freebsd/sys/sys/consio.h
create mode 100644 freebsd/sys/sys/fbio.h
create mode 100644 freebsd/sys/sys/terminal.h
create mode 100644 freebsd/sys/teken/teken.h
diff --git a/freebsd/sys/arm/ti/am335x/am335x_ecap.c b/freebsd/sys/arm/ti/am335x/am335x_ecap.c
new file mode 100644
index 00000000..9ebc51db
--- /dev/null
+++ b/freebsd/sys/arm/ti/am335x/am335x_ecap.c
@@ -0,0 +1,202 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
+/*-
+ * Copyright (c) 2013 Oleksandr Tymoshenko <gonzo at freebsd.org>
+ * 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.
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/limits.h>
+#include <sys/lock.h>
+#include <sys/module.h>
+#include <sys/mutex.h>
+#include <rtems/bsd/sys/resource.h>
+#include <sys/rman.h>
+#include <sys/sysctl.h>
+
+#include <machine/bus.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+
+#include "am335x_pwm.h"
+
+#define ECAP_TSCTR 0x00
+#define ECAP_CAP1 0x08
+#define ECAP_CAP2 0x0C
+#define ECAP_CAP3 0x10
+#define ECAP_CAP4 0x14
+#define ECAP_ECCTL2 0x2A
+#define ECCTL2_MODE_APWM (1 << 9)
+#define ECCTL2_SYNCO_SEL (3 << 6)
+#define ECCTL2_TSCTRSTOP_FREERUN (1 << 4)
+
+#define ECAP_READ2(_sc, reg) bus_read_2((_sc)->sc_mem_res, reg);
+#define ECAP_WRITE2(_sc, reg, value) \
+ bus_write_2((_sc)->sc_mem_res, reg, value);
+#define ECAP_READ4(_sc, reg) bus_read_4((_sc)->sc_mem_res, reg);
+#define ECAP_WRITE4(_sc, reg, value) \
+ bus_write_4((_sc)->sc_mem_res, reg, value);
+
+#define PWM_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
+#define PWM_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
+#define PWM_LOCK_INIT(_sc) mtx_init(&(_sc)->sc_mtx, \
+ device_get_nameunit(_sc->sc_dev), "am335x_ecap softc", MTX_DEF)
+#define PWM_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_mtx)
+
+static device_probe_t am335x_ecap_probe;
+static device_attach_t am335x_ecap_attach;
+static device_detach_t am335x_ecap_detach;
+
+struct am335x_ecap_softc {
+ device_t sc_dev;
+ struct mtx sc_mtx;
+ struct resource *sc_mem_res;
+ int sc_mem_rid;
+};
+
+static device_method_t am335x_ecap_methods[] = {
+ DEVMETHOD(device_probe, am335x_ecap_probe),
+ DEVMETHOD(device_attach, am335x_ecap_attach),
+ DEVMETHOD(device_detach, am335x_ecap_detach),
+
+ DEVMETHOD_END
+};
+
+static driver_t am335x_ecap_driver = {
+ "am335x_ecap",
+ am335x_ecap_methods,
+ sizeof(struct am335x_ecap_softc),
+};
+
+static devclass_t am335x_ecap_devclass;
+
+/*
+ * API function to set period/duty cycles for ECAPx
+ */
+int
+am335x_pwm_config_ecap(int unit, int period, int duty)
+{
+ device_t dev;
+ struct am335x_ecap_softc *sc;
+ uint16_t reg;
+
+ dev = devclass_get_device(am335x_ecap_devclass, unit);
+ if (dev == NULL)
+ return (ENXIO);
+
+ if (duty > period)
+ return (EINVAL);
+
+ if (period == 0)
+ return (EINVAL);
+
+ sc = device_get_softc(dev);
+ PWM_LOCK(sc);
+
+ reg = ECAP_READ2(sc, ECAP_ECCTL2);
+ reg |= ECCTL2_MODE_APWM | ECCTL2_TSCTRSTOP_FREERUN | ECCTL2_SYNCO_SEL;
+ ECAP_WRITE2(sc, ECAP_ECCTL2, reg);
+
+ /* CAP3 in APWM mode is APRD shadow register */
+ ECAP_WRITE4(sc, ECAP_CAP3, period - 1);
+
+ /* CAP4 in APWM mode is ACMP shadow register */
+ ECAP_WRITE4(sc, ECAP_CAP4, duty);
+ /* Restart counter */
+ ECAP_WRITE4(sc, ECAP_TSCTR, 0);
+
+ PWM_UNLOCK(sc);
+
+ return (0);
+}
+
+static int
+am335x_ecap_probe(device_t dev)
+{
+
+ if (!ofw_bus_status_okay(dev))
+ return (ENXIO);
+
+ if (!ofw_bus_is_compatible(dev, "ti,am33xx-ecap"))
+ return (ENXIO);
+
+ device_set_desc(dev, "AM335x eCAP");
+
+ return (BUS_PROBE_DEFAULT);
+}
+
+static int
+am335x_ecap_attach(device_t dev)
+{
+ struct am335x_ecap_softc *sc;
+
+ sc = device_get_softc(dev);
+ sc->sc_dev = dev;
+
+ PWM_LOCK_INIT(sc);
+
+ sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
+ &sc->sc_mem_rid, RF_ACTIVE);
+ if (sc->sc_mem_res == NULL) {
+ device_printf(dev, "cannot allocate memory resources\n");
+ goto fail;
+ }
+
+ return (0);
+
+fail:
+ PWM_LOCK_DESTROY(sc);
+ return (ENXIO);
+}
+
+static int
+am335x_ecap_detach(device_t dev)
+{
+ struct am335x_ecap_softc *sc;
+
+ sc = device_get_softc(dev);
+
+ PWM_LOCK(sc);
+ if (sc->sc_mem_res)
+ bus_release_resource(dev, SYS_RES_MEMORY,
+ sc->sc_mem_rid, sc->sc_mem_res);
+ PWM_UNLOCK(sc);
+
+ PWM_LOCK_DESTROY(sc);
+
+
+ return (0);
+}
+
+DRIVER_MODULE(am335x_ecap, am335x_pwmss, am335x_ecap_driver, am335x_ecap_devclass, 0, 0);
+MODULE_VERSION(am335x_ecap, 1);
+MODULE_DEPEND(am335x_ecap, am335x_pwmss, 1, 1, 1);
diff --git a/freebsd/sys/arm/ti/am335x/am335x_lcd.c b/freebsd/sys/arm/ti/am335x/am335x_lcd.c
new file mode 100644
index 00000000..7c0dd63e
--- /dev/null
+++ b/freebsd/sys/arm/ti/am335x/am335x_lcd.c
@@ -0,0 +1,1085 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright 2013 Oleksandr Tymoshenko <gonzo at freebsd.org>
+ * 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.
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <rtems/bsd/local/opt_syscons.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/clock.h>
+#include <sys/eventhandler.h>
+#include <sys/time.h>
+#include <sys/bus.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <rtems/bsd/sys/resource.h>
+#include <sys/rman.h>
+#include <sys/sysctl.h>
+#include <vm/vm.h>
+#include <vm/pmap.h>
+#include <sys/fbio.h>
+#include <sys/consio.h>
+
+#include <machine/bus.h>
+
+#include <dev/fdt/fdt_common.h>
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+
+#include <dev/videomode/videomode.h>
+#include <dev/videomode/edidvar.h>
+
+#include <dev/fb/fbreg.h>
+#ifdef DEV_SC
+#include <dev/syscons/syscons.h>
+#else /* VT */
+#include <dev/vt/vt.h>
+#endif
+
+#include <arm/ti/ti_prcm.h>
+#include <arm/ti/ti_scm.h>
+
+#include "am335x_lcd.h"
+#include "am335x_pwm.h"
+
+#include <rtems/bsd/local/fb_if.h>
+#include <rtems/bsd/local/hdmi_if.h>
+
+#define LCD_PID 0x00
+#define LCD_CTRL 0x04
+#define CTRL_DIV_MASK 0xff
+#define CTRL_DIV_SHIFT 8
+#define CTRL_AUTO_UFLOW_RESTART (1 << 1)
+#define CTRL_RASTER_MODE 1
+#define CTRL_LIDD_MODE 0
+#define LCD_LIDD_CTRL 0x0C
+#define LCD_LIDD_CS0_CONF 0x10
+#define LCD_LIDD_CS0_ADDR 0x14
+#define LCD_LIDD_CS0_DATA 0x18
+#define LCD_LIDD_CS1_CONF 0x1C
+#define LCD_LIDD_CS1_ADDR 0x20
+#define LCD_LIDD_CS1_DATA 0x24
+#define LCD_RASTER_CTRL 0x28
+#define RASTER_CTRL_TFT24_UNPACKED (1 << 26)
+#define RASTER_CTRL_TFT24 (1 << 25)
+#define RASTER_CTRL_STN565 (1 << 24)
+#define RASTER_CTRL_TFTPMAP (1 << 23)
+#define RASTER_CTRL_NIBMODE (1 << 22)
+#define RASTER_CTRL_PALMODE_SHIFT 20
+#define PALETTE_PALETTE_AND_DATA 0x00
+#define PALETTE_PALETTE_ONLY 0x01
+#define PALETTE_DATA_ONLY 0x02
+#define RASTER_CTRL_REQDLY_SHIFT 12
+#define RASTER_CTRL_MONO8B (1 << 9)
+#define RASTER_CTRL_RBORDER (1 << 8)
+#define RASTER_CTRL_LCDTFT (1 << 7)
+#define RASTER_CTRL_LCDBW (1 << 1)
+#define RASTER_CTRL_LCDEN (1 << 0)
+#define LCD_RASTER_TIMING_0 0x2C
+#define RASTER_TIMING_0_HBP_SHIFT 24
+#define RASTER_TIMING_0_HFP_SHIFT 16
+#define RASTER_TIMING_0_HSW_SHIFT 10
+#define RASTER_TIMING_0_PPLLSB_SHIFT 4
+#define RASTER_TIMING_0_PPLMSB_SHIFT 3
+#define LCD_RASTER_TIMING_1 0x30
+#define RASTER_TIMING_1_VBP_SHIFT 24
+#define RASTER_TIMING_1_VFP_SHIFT 16
+#define RASTER_TIMING_1_VSW_SHIFT 10
+#define RASTER_TIMING_1_LPP_SHIFT 0
+#define LCD_RASTER_TIMING_2 0x34
+#define RASTER_TIMING_2_HSWHI_SHIFT 27
+#define RASTER_TIMING_2_LPP_B10_SHIFT 26
+#define RASTER_TIMING_2_PHSVS (1 << 25)
+#define RASTER_TIMING_2_PHSVS_RISE (1 << 24)
+#define RASTER_TIMING_2_PHSVS_FALL (0 << 24)
+#define RASTER_TIMING_2_IOE (1 << 23)
+#define RASTER_TIMING_2_IPC (1 << 22)
+#define RASTER_TIMING_2_IHS (1 << 21)
+#define RASTER_TIMING_2_IVS (1 << 20)
+#define RASTER_TIMING_2_ACBI_SHIFT 16
+#define RASTER_TIMING_2_ACB_SHIFT 8
+#define RASTER_TIMING_2_HBPHI_SHIFT 4
+#define RASTER_TIMING_2_HFPHI_SHIFT 0
+#define LCD_RASTER_SUBPANEL 0x38
+#define LCD_RASTER_SUBPANEL2 0x3C
+#define LCD_LCDDMA_CTRL 0x40
+#define LCDDMA_CTRL_DMA_MASTER_PRIO_SHIFT 16
+#define LCDDMA_CTRL_TH_FIFO_RDY_SHIFT 8
+#define LCDDMA_CTRL_BURST_SIZE_SHIFT 4
+#define LCDDMA_CTRL_BYTES_SWAP (1 << 3)
+#define LCDDMA_CTRL_BE (1 << 1)
+#define LCDDMA_CTRL_FB0_ONLY 0
+#define LCDDMA_CTRL_FB0_FB1 (1 << 0)
+#define LCD_LCDDMA_FB0_BASE 0x44
+#define LCD_LCDDMA_FB0_CEILING 0x48
+#define LCD_LCDDMA_FB1_BASE 0x4C
+#define LCD_LCDDMA_FB1_CEILING 0x50
+#define LCD_SYSCONFIG 0x54
+#define SYSCONFIG_STANDBY_FORCE (0 << 4)
+#define SYSCONFIG_STANDBY_NONE (1 << 4)
+#define SYSCONFIG_STANDBY_SMART (2 << 4)
+#define SYSCONFIG_IDLE_FORCE (0 << 2)
+#define SYSCONFIG_IDLE_NONE (1 << 2)
+#define SYSCONFIG_IDLE_SMART (2 << 2)
+#define LCD_IRQSTATUS_RAW 0x58
+#define LCD_IRQSTATUS 0x5C
+#define LCD_IRQENABLE_SET 0x60
+#define LCD_IRQENABLE_CLEAR 0x64
+#define IRQ_EOF1 (1 << 9)
+#define IRQ_EOF0 (1 << 8)
+#define IRQ_PL (1 << 6)
+#define IRQ_FUF (1 << 5)
+#define IRQ_ACB (1 << 3)
+#define IRQ_SYNC_LOST (1 << 2)
+#define IRQ_RASTER_DONE (1 << 1)
+#define IRQ_FRAME_DONE (1 << 0)
+#define LCD_END_OF_INT_IND 0x68
+#define LCD_CLKC_ENABLE 0x6C
+#define CLKC_ENABLE_DMA (1 << 2)
+#define CLKC_ENABLE_LDID (1 << 1)
+#define CLKC_ENABLE_CORE (1 << 0)
+#define LCD_CLKC_RESET 0x70
+#define CLKC_RESET_MAIN (1 << 3)
+#define CLKC_RESET_DMA (1 << 2)
+#define CLKC_RESET_LDID (1 << 1)
+#define CLKC_RESET_CORE (1 << 0)
+
+#define LCD_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
+#define LCD_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
+#define LCD_LOCK_INIT(_sc) mtx_init(&(_sc)->sc_mtx, \
+ device_get_nameunit(_sc->sc_dev), "am335x_lcd", MTX_DEF)
+#define LCD_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->sc_mtx);
+
+#define LCD_READ4(_sc, reg) bus_read_4((_sc)->sc_mem_res, reg);
+#define LCD_WRITE4(_sc, reg, value) \
+ bus_write_4((_sc)->sc_mem_res, reg, value);
+
+/* Backlight is controlled by eCAS interface on PWM unit 0 */
+#define PWM_UNIT 0
+#define PWM_PERIOD 100
+
+#define MODE_HBP(mode) ((mode)->htotal - (mode)->hsync_end)
+#define MODE_HFP(mode) ((mode)->hsync_start - (mode)->hdisplay)
+#define MODE_HSW(mode) ((mode)->hsync_end - (mode)->hsync_start)
+#define MODE_VBP(mode) ((mode)->vtotal - (mode)->vsync_end)
+#define MODE_VFP(mode) ((mode)->vsync_start - (mode)->vdisplay)
+#define MODE_VSW(mode) ((mode)->vsync_end - (mode)->vsync_start)
+
+#define MAX_PIXEL_CLOCK 126000
+#define MAX_BANDWIDTH (1280*1024*60)
+
+struct am335x_lcd_softc {
+ device_t sc_dev;
+ struct fb_info sc_fb_info;
+ struct resource *sc_mem_res;
+ struct resource *sc_irq_res;
+ void *sc_intr_hl;
+ struct mtx sc_mtx;
+ int sc_backlight;
+ struct sysctl_oid *sc_oid;
+
+ struct panel_info sc_panel;
+
+ /* Framebuffer */
+ bus_dma_tag_t sc_dma_tag;
+ bus_dmamap_t sc_dma_map;
+ size_t sc_fb_size;
+ bus_addr_t sc_fb_phys;
+ uint8_t *sc_fb_base;
+
+ /* HDMI framer */
+ phandle_t sc_hdmi_framer;
+ eventhandler_tag sc_hdmi_evh;
+};
+
+static void
+am335x_fb_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int err)
+{
+ bus_addr_t *addr;
+
+ if (err)
+ return;
+
+ addr = (bus_addr_t*)arg;
+ *addr = segs[0].ds_addr;
+}
+
+static uint32_t
+am335x_lcd_calc_divisor(uint32_t reference, uint32_t freq)
+{
+ uint32_t div, i;
+ uint32_t delta, min_delta;
+
+ min_delta = freq;
+ div = 255;
+
+ /* Raster mode case: divisors are in range from 2 to 255 */
+ for (i = 2; i < 255; i++) {
+ delta = abs(reference/i - freq);
+ if (delta < min_delta) {
+ div = i;
+ min_delta = delta;
+ }
+ }
+
+ return (div);
+}
+
+static int
+am335x_lcd_sysctl_backlight(SYSCTL_HANDLER_ARGS)
+{
+ struct am335x_lcd_softc *sc = (struct am335x_lcd_softc*)arg1;
+ int error;
+ int backlight;
+
+ backlight = sc->sc_backlight;
+ error = sysctl_handle_int(oidp, &backlight, 0, req);
+
+ if (error != 0 || req->newptr == NULL)
+ return (error);
+
+ if (backlight < 0)
+ backlight = 0;
+ if (backlight > 100)
+ backlight = 100;
+
+ LCD_LOCK(sc);
+ error = am335x_pwm_config_ecap(PWM_UNIT, PWM_PERIOD,
+ backlight*PWM_PERIOD/100);
+ if (error == 0)
+ sc->sc_backlight = backlight;
+ LCD_UNLOCK(sc);
+
+ return (error);
+}
+
+static uint32_t
+am335x_mode_vrefresh(const struct videomode *mode)
+{
+ uint32_t refresh;
+
+ /* Calculate vertical refresh rate */
+ refresh = (mode->dot_clock * 1000 / mode->htotal);
+ refresh = (refresh + mode->vtotal / 2) / mode->vtotal;
+
+ if (mode->flags & VID_INTERLACE)
+ refresh *= 2;
+ if (mode->flags & VID_DBLSCAN)
+ refresh /= 2;
+
+ return refresh;
+}
+
+static int
+am335x_mode_is_valid(const struct videomode *mode)
+{
+ uint32_t hbp, hfp, hsw;
+ uint32_t vbp, vfp, vsw;
+
+ if (mode->dot_clock > MAX_PIXEL_CLOCK)
+ return (0);
+
+ if (mode->hdisplay & 0xf)
+ return (0);
+
+ if (mode->vdisplay > 2048)
+ return (0);
+
+ /* Check ranges for timing parameters */
+ hbp = MODE_HBP(mode) - 1;
+ hfp = MODE_HFP(mode) - 1;
+ hsw = MODE_HSW(mode) - 1;
+ vbp = MODE_VBP(mode);
+ vfp = MODE_VFP(mode);
+ vsw = MODE_VSW(mode) - 1;
+
+ if (hbp > 0x3ff)
+ return (0);
+ if (hfp > 0x3ff)
+ return (0);
+ if (hsw > 0x3ff)
+ return (0);
+
+ if (vbp > 0xff)
+ return (0);
+ if (vfp > 0xff)
+ return (0);
+ if (vsw > 0x3f)
+ return (0);
+ if (mode->vdisplay*mode->hdisplay*am335x_mode_vrefresh(mode)
+ > MAX_BANDWIDTH)
+ return (0);
+
+ return (1);
+}
+
+static void
+am335x_read_hdmi_property(device_t dev)
+{
+ phandle_t node, xref;
+ phandle_t endpoint;
+ phandle_t hdmi_xref;
+ struct am335x_lcd_softc *sc;
+
+ sc = device_get_softc(dev);
+ node = ofw_bus_get_node(dev);
+ sc->sc_hdmi_framer = 0;
+
+ /*
+ * Old FreeBSD way of referencing to HDMI framer
+ */
+ if (OF_getencprop(node, "hdmi", &hdmi_xref, sizeof(hdmi_xref)) != -1) {
+ sc->sc_hdmi_framer = hdmi_xref;
+ return;
+ }
+
+ /*
+ * Use bindings described in Linux docs:
+ * bindings/media/video-interfaces.txt
+ * We assume that the only endpoint in LCDC node
+ * is HDMI framer.
+ */
+ node = ofw_bus_find_child(node, "port");
+
+ /* No media bindings */
+ if (node == 0)
+ return;
+
+ for (endpoint = OF_child(node); endpoint != 0; endpoint = OF_peer(endpoint)) {
+ if (OF_getencprop(endpoint, "remote-endpoint", &xref, sizeof(xref)) != -1) {
+ /* port/port at 0/endpoint at 0 */
+ node = OF_node_from_xref(xref);
+ /* port/port at 0 */
+ node = OF_parent(node);
+ /* port */
+ node = OF_parent(node);
+ /* actual owner of port, in our case HDMI framer */
+ sc->sc_hdmi_framer = OF_xref_from_node(OF_parent(node));
+ if (sc->sc_hdmi_framer != 0)
+ return;
+ }
+ }
+}
+
+static int
+am335x_read_property(device_t dev, phandle_t node, const char *name, uint32_t *val)
+{
+ pcell_t cell;
+
+ if ((OF_getencprop(node, name, &cell, sizeof(cell))) <= 0) {
+ device_printf(dev, "missing '%s' attribute in LCD panel info\n",
+ name);
+ return (ENXIO);
+ }
+
+ *val = cell;
+
+ return (0);
+}
+
+static int
+am335x_read_timing(device_t dev, phandle_t node, struct panel_info *panel)
+{
+ int error;
+ phandle_t timings_node, timing_node, native;
+
+ timings_node = ofw_bus_find_child(node, "display-timings");
+ if (timings_node == 0) {
+ device_printf(dev, "no \"display-timings\" node\n");
+ return (-1);
+ }
+
+ if (OF_searchencprop(timings_node, "native-mode", &native,
+ sizeof(native)) == -1) {
+ device_printf(dev, "no \"native-mode\" reference in \"timings\" node\n");
+ return (-1);
+ }
+
+ timing_node = OF_node_from_xref(native);
+
+ error = 0;
+ if ((error = am335x_read_property(dev, timing_node,
+ "hactive", &panel->panel_width)))
+ goto out;
+
+ if ((error = am335x_read_property(dev, timing_node,
+ "vactive", &panel->panel_height)))
+ goto out;
+
+ if ((error = am335x_read_property(dev, timing_node,
+ "hfront-porch", &panel->panel_hfp)))
+ goto out;
+
+ if ((error = am335x_read_property(dev, timing_node,
+ "hback-porch", &panel->panel_hbp)))
+ goto out;
+
+ if ((error = am335x_read_property(dev, timing_node,
+ "hsync-len", &panel->panel_hsw)))
+ goto out;
+
+ if ((error = am335x_read_property(dev, timing_node,
+ "vfront-porch", &panel->panel_vfp)))
+ goto out;
+
+ if ((error = am335x_read_property(dev, timing_node,
+ "vback-porch", &panel->panel_vbp)))
+ goto out;
+
+ if ((error = am335x_read_property(dev, timing_node,
+ "vsync-len", &panel->panel_vsw)))
+ goto out;
+
+ if ((error = am335x_read_property(dev, timing_node,
+ "clock-frequency", &panel->panel_pxl_clk)))
+ goto out;
+
+ if ((error = am335x_read_property(dev, timing_node,
+ "pixelclk-active", &panel->pixelclk_active)))
+ goto out;
+
+ if ((error = am335x_read_property(dev, timing_node,
+ "hsync-active", &panel->hsync_active)))
+ goto out;
+
+ if ((error = am335x_read_property(dev, timing_node,
+ "vsync-active", &panel->vsync_active)))
+ goto out;
+
+out:
+ return (error);
+}
+
+static int
+am335x_read_panel_info(device_t dev, phandle_t node, struct panel_info *panel)
+{
+ phandle_t panel_info_node;
+
+ panel_info_node = ofw_bus_find_child(node, "panel-info");
+ if (panel_info_node == 0)
+ return (-1);
+
+ am335x_read_property(dev, panel_info_node,
+ "ac-bias", &panel->ac_bias);
+
+ am335x_read_property(dev, panel_info_node,
+ "ac-bias-intrpt", &panel->ac_bias_intrpt);
+
+ am335x_read_property(dev, panel_info_node,
+ "dma-burst-sz", &panel->dma_burst_sz);
+
+ am335x_read_property(dev, panel_info_node,
+ "bpp", &panel->bpp);
+
+ am335x_read_property(dev, panel_info_node,
+ "fdd", &panel->fdd);
+
+ am335x_read_property(dev, panel_info_node,
+ "sync-edge", &panel->sync_edge);
+
+ am335x_read_property(dev, panel_info_node,
+ "sync-ctrl", &panel->sync_ctrl);
+
+ return (0);
+}
+
+static void
+am335x_lcd_intr(void *arg)
+{
+ struct am335x_lcd_softc *sc = arg;
+ uint32_t reg;
+
+ reg = LCD_READ4(sc, LCD_IRQSTATUS);
+ LCD_WRITE4(sc, LCD_IRQSTATUS, reg);
+ /* Read value back to make sure it reached the hardware */
+ reg = LCD_READ4(sc, LCD_IRQSTATUS);
+
+ if (reg & IRQ_SYNC_LOST) {
+ reg = LCD_READ4(sc, LCD_RASTER_CTRL);
+ reg &= ~RASTER_CTRL_LCDEN;
+ LCD_WRITE4(sc, LCD_RASTER_CTRL, reg);
+
+ reg = LCD_READ4(sc, LCD_RASTER_CTRL);
+ reg |= RASTER_CTRL_LCDEN;
+ LCD_WRITE4(sc, LCD_RASTER_CTRL, reg);
+ goto done;
+ }
+
+ if (reg & IRQ_PL) {
+ reg = LCD_READ4(sc, LCD_RASTER_CTRL);
+ reg &= ~RASTER_CTRL_LCDEN;
+ LCD_WRITE4(sc, LCD_RASTER_CTRL, reg);
+
+ reg = LCD_READ4(sc, LCD_RASTER_CTRL);
+ reg |= RASTER_CTRL_LCDEN;
+ LCD_WRITE4(sc, LCD_RASTER_CTRL, reg);
+ goto done;
+ }
+
+ if (reg & IRQ_EOF0) {
+ LCD_WRITE4(sc, LCD_LCDDMA_FB0_BASE, sc->sc_fb_phys);
+ LCD_WRITE4(sc, LCD_LCDDMA_FB0_CEILING, sc->sc_fb_phys + sc->sc_fb_size - 1);
+ reg &= ~IRQ_EOF0;
+ }
+
+ if (reg & IRQ_EOF1) {
+ LCD_WRITE4(sc, LCD_LCDDMA_FB1_BASE, sc->sc_fb_phys);
+ LCD_WRITE4(sc, LCD_LCDDMA_FB1_CEILING, sc->sc_fb_phys + sc->sc_fb_size - 1);
+ reg &= ~IRQ_EOF1;
+ }
+
+ if (reg & IRQ_FUF) {
+ /* TODO: Handle FUF */
+ }
+
+ if (reg & IRQ_ACB) {
+ /* TODO: Handle ACB */
+ }
+
+done:
+ LCD_WRITE4(sc, LCD_END_OF_INT_IND, 0);
+ /* Read value back to make sure it reached the hardware */
+ reg = LCD_READ4(sc, LCD_END_OF_INT_IND);
+}
+
+static const struct videomode *
+am335x_lcd_pick_mode(struct edid_info *ei)
+{
+ const struct videomode *videomode;
+ const struct videomode *m;
+ int n;
+
+ /* Get standard VGA as default */
+ videomode = NULL;
+
+ /*
+ * Pick a mode.
+ */
+ if (ei->edid_preferred_mode != NULL) {
+ if (am335x_mode_is_valid(ei->edid_preferred_mode))
+ videomode = ei->edid_preferred_mode;
+ }
+
+ if (videomode == NULL) {
+ m = ei->edid_modes;
+
+ sort_modes(ei->edid_modes,
+ &ei->edid_preferred_mode,
+ ei->edid_nmodes);
+ for (n = 0; n < ei->edid_nmodes; n++)
+ if (am335x_mode_is_valid(&m[n])) {
+ videomode = &m[n];
+ break;
+ }
+ }
+
+ return videomode;
+}
+
+static int
+am335x_lcd_configure(struct am335x_lcd_softc *sc)
+{
+ int div;
+ uint32_t reg, timing0, timing1, timing2;
+ uint32_t burst_log;
+ size_t dma_size;
+ uint32_t hbp, hfp, hsw;
+ uint32_t vbp, vfp, vsw;
+ uint32_t width, height;
+ unsigned int ref_freq;
+ int err;
+
+ /*
+ * try to adjust clock to get double of requested frequency
+ * HDMI/DVI displays are very sensitive to error in frequncy value
+ */
+ if (ti_prcm_clk_set_source_freq(LCDC_CLK, sc->sc_panel.panel_pxl_clk*2)) {
+ device_printf(sc->sc_dev, "can't set source frequency\n");
+ return (ENXIO);
+ }
+
+ if (ti_prcm_clk_get_source_freq(LCDC_CLK, &ref_freq)) {
+ device_printf(sc->sc_dev, "can't get reference frequency\n");
+ return (ENXIO);
+ }
+
+ /* Panle initialization */
+ dma_size = round_page(sc->sc_panel.panel_width*sc->sc_panel.panel_height*sc->sc_panel.bpp/8);
+
+ /*
+ * Now allocate framebuffer memory
+ */
+ err = bus_dma_tag_create(
+ bus_get_dma_tag(sc->sc_dev),
+ 4, 0, /* alignment, boundary */
+ BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
+ BUS_SPACE_MAXADDR, /* highaddr */
+ NULL, NULL, /* filter, filterarg */
+ dma_size, 1, /* maxsize, nsegments */
+ dma_size, 0, /* maxsegsize, flags */
+ NULL, NULL, /* lockfunc, lockarg */
+ &sc->sc_dma_tag);
+ if (err)
+ goto done;
+
+ err = bus_dmamem_alloc(sc->sc_dma_tag, (void **)&sc->sc_fb_base,
+ BUS_DMA_COHERENT, &sc->sc_dma_map);
+
+ if (err) {
+ device_printf(sc->sc_dev, "cannot allocate framebuffer\n");
+ goto done;
+ }
+
+ err = bus_dmamap_load(sc->sc_dma_tag, sc->sc_dma_map, sc->sc_fb_base,
+ dma_size, am335x_fb_dmamap_cb, &sc->sc_fb_phys, BUS_DMA_NOWAIT);
+
+ if (err) {
+ device_printf(sc->sc_dev, "cannot load DMA map\n");
+ goto done;
+ }
+
+ /* Make sure it's blank */
+ memset(sc->sc_fb_base, 0x0, dma_size);
+
+ /* Calculate actual FB Size */
+ sc->sc_fb_size = sc->sc_panel.panel_width*sc->sc_panel.panel_height*sc->sc_panel.bpp/8;
+
+ /* Only raster mode is supported */
+ reg = CTRL_RASTER_MODE;
+ div = am335x_lcd_calc_divisor(ref_freq, sc->sc_panel.panel_pxl_clk);
+ reg |= (div << CTRL_DIV_SHIFT);
+ LCD_WRITE4(sc, LCD_CTRL, reg);
+
+ /* Set timing */
+ timing0 = timing1 = timing2 = 0;
+
+ hbp = sc->sc_panel.panel_hbp - 1;
+ hfp = sc->sc_panel.panel_hfp - 1;
+ hsw = sc->sc_panel.panel_hsw - 1;
+
+ vbp = sc->sc_panel.panel_vbp;
+ vfp = sc->sc_panel.panel_vfp;
+ vsw = sc->sc_panel.panel_vsw - 1;
+
+ height = sc->sc_panel.panel_height - 1;
+ width = sc->sc_panel.panel_width - 1;
+
+ /* Horizontal back porch */
+ timing0 |= (hbp & 0xff) << RASTER_TIMING_0_HBP_SHIFT;
+ timing2 |= ((hbp >> 8) & 3) << RASTER_TIMING_2_HBPHI_SHIFT;
+ /* Horizontal front porch */
+ timing0 |= (hfp & 0xff) << RASTER_TIMING_0_HFP_SHIFT;
+ timing2 |= ((hfp >> 8) & 3) << RASTER_TIMING_2_HFPHI_SHIFT;
+ /* Horizontal sync width */
+ timing0 |= (hsw & 0x3f) << RASTER_TIMING_0_HSW_SHIFT;
+ timing2 |= ((hsw >> 6) & 0xf) << RASTER_TIMING_2_HSWHI_SHIFT;
+
+ /* Vertical back porch, front porch, sync width */
+ timing1 |= (vbp & 0xff) << RASTER_TIMING_1_VBP_SHIFT;
+ timing1 |= (vfp & 0xff) << RASTER_TIMING_1_VFP_SHIFT;
+ timing1 |= (vsw & 0x3f) << RASTER_TIMING_1_VSW_SHIFT;
+
+ /* Pixels per line */
+ timing0 |= ((width >> 10) & 1)
+ << RASTER_TIMING_0_PPLMSB_SHIFT;
+ timing0 |= ((width >> 4) & 0x3f)
+ << RASTER_TIMING_0_PPLLSB_SHIFT;
+
+ /* Lines per panel */
+ timing1 |= (height & 0x3ff)
+ << RASTER_TIMING_1_LPP_SHIFT;
+ timing2 |= ((height >> 10 ) & 1)
+ << RASTER_TIMING_2_LPP_B10_SHIFT;
+
+ /* clock signal settings */
+ if (sc->sc_panel.sync_ctrl)
+ timing2 |= RASTER_TIMING_2_PHSVS;
+ if (sc->sc_panel.sync_edge)
+ timing2 |= RASTER_TIMING_2_PHSVS_RISE;
+ else
+ timing2 |= RASTER_TIMING_2_PHSVS_FALL;
+ if (sc->sc_panel.hsync_active == 0)
+ timing2 |= RASTER_TIMING_2_IHS;
+ if (sc->sc_panel.vsync_active == 0)
+ timing2 |= RASTER_TIMING_2_IVS;
+ if (sc->sc_panel.pixelclk_active == 0)
+ timing2 |= RASTER_TIMING_2_IPC;
+
+ /* AC bias */
+ timing2 |= (sc->sc_panel.ac_bias << RASTER_TIMING_2_ACB_SHIFT);
+ timing2 |= (sc->sc_panel.ac_bias_intrpt << RASTER_TIMING_2_ACBI_SHIFT);
+
+ LCD_WRITE4(sc, LCD_RASTER_TIMING_0, timing0);
+ LCD_WRITE4(sc, LCD_RASTER_TIMING_1, timing1);
+ LCD_WRITE4(sc, LCD_RASTER_TIMING_2, timing2);
+
+ /* DMA settings */
+ reg = LCDDMA_CTRL_FB0_FB1;
+ /* Find power of 2 for current burst size */
+ switch (sc->sc_panel.dma_burst_sz) {
+ case 1:
+ burst_log = 0;
+ break;
+ case 2:
+ burst_log = 1;
+ break;
+ case 4:
+ burst_log = 2;
+ break;
+ case 8:
+ burst_log = 3;
+ break;
+ case 16:
+ default:
+ burst_log = 4;
+ break;
+ }
+ reg |= (burst_log << LCDDMA_CTRL_BURST_SIZE_SHIFT);
+ /* XXX: FIFO TH */
+ reg |= (0 << LCDDMA_CTRL_TH_FIFO_RDY_SHIFT);
+ LCD_WRITE4(sc, LCD_LCDDMA_CTRL, reg);
+
+ LCD_WRITE4(sc, LCD_LCDDMA_FB0_BASE, sc->sc_fb_phys);
+ LCD_WRITE4(sc, LCD_LCDDMA_FB0_CEILING, sc->sc_fb_phys + sc->sc_fb_size - 1);
+ LCD_WRITE4(sc, LCD_LCDDMA_FB1_BASE, sc->sc_fb_phys);
+ LCD_WRITE4(sc, LCD_LCDDMA_FB1_CEILING, sc->sc_fb_phys + sc->sc_fb_size - 1);
+
+ /* Enable LCD */
+ reg = RASTER_CTRL_LCDTFT;
+ reg |= (sc->sc_panel.fdd << RASTER_CTRL_REQDLY_SHIFT);
+ reg |= (PALETTE_DATA_ONLY << RASTER_CTRL_PALMODE_SHIFT);
+ if (sc->sc_panel.bpp >= 24)
+ reg |= RASTER_CTRL_TFT24;
+ if (sc->sc_panel.bpp == 32)
+ reg |= RASTER_CTRL_TFT24_UNPACKED;
+ LCD_WRITE4(sc, LCD_RASTER_CTRL, reg);
+
+ LCD_WRITE4(sc, LCD_CLKC_ENABLE,
+ CLKC_ENABLE_DMA | CLKC_ENABLE_LDID | CLKC_ENABLE_CORE);
+
+ LCD_WRITE4(sc, LCD_CLKC_RESET, CLKC_RESET_MAIN);
+ DELAY(100);
+ LCD_WRITE4(sc, LCD_CLKC_RESET, 0);
+
+ reg = IRQ_EOF1 | IRQ_EOF0 | IRQ_FUF | IRQ_PL |
+ IRQ_ACB | IRQ_SYNC_LOST | IRQ_RASTER_DONE |
+ IRQ_FRAME_DONE;
+ LCD_WRITE4(sc, LCD_IRQENABLE_SET, reg);
+
+ reg = LCD_READ4(sc, LCD_RASTER_CTRL);
+ reg |= RASTER_CTRL_LCDEN;
+ LCD_WRITE4(sc, LCD_RASTER_CTRL, reg);
+
+ LCD_WRITE4(sc, LCD_SYSCONFIG,
+ SYSCONFIG_STANDBY_SMART | SYSCONFIG_IDLE_SMART);
+
+ sc->sc_fb_info.fb_name = device_get_nameunit(sc->sc_dev);
+ sc->sc_fb_info.fb_vbase = (intptr_t)sc->sc_fb_base;
+ sc->sc_fb_info.fb_pbase = sc->sc_fb_phys;
+ sc->sc_fb_info.fb_size = sc->sc_fb_size;
+ sc->sc_fb_info.fb_bpp = sc->sc_fb_info.fb_depth = sc->sc_panel.bpp;
+ sc->sc_fb_info.fb_stride = sc->sc_panel.panel_width*sc->sc_panel.bpp / 8;
+ sc->sc_fb_info.fb_width = sc->sc_panel.panel_width;
+ sc->sc_fb_info.fb_height = sc->sc_panel.panel_height;
+
+#ifdef DEV_SC
+ err = (sc_attach_unit(device_get_unit(sc->sc_dev),
+ device_get_flags(sc->sc_dev) | SC_AUTODETECT_KBD));
+
+ if (err) {
+ device_printf(sc->sc_dev, "failed to attach syscons\n");
+ goto fail;
+ }
+
+ am335x_lcd_syscons_setup((vm_offset_t)sc->sc_fb_base, sc->sc_fb_phys, &panel);
+#else /* VT */
+ device_t fbd = device_add_child(sc->sc_dev, "fbd",
+ device_get_unit(sc->sc_dev));
+ if (fbd != NULL) {
+ if (device_probe_and_attach(fbd) != 0)
+ device_printf(sc->sc_dev, "failed to attach fbd device\n");
+ } else
+ device_printf(sc->sc_dev, "failed to add fbd child\n");
+#endif
+
+done:
+ return (err);
+}
+
+static void
+am335x_lcd_hdmi_event(void *arg, device_t hdmi, int event)
+{
+ struct am335x_lcd_softc *sc;
+ const struct videomode *videomode;
+ struct videomode hdmi_mode;
+ device_t hdmi_dev;
+ uint8_t *edid;
+ uint32_t edid_len;
+ struct edid_info ei;
+
+ sc = arg;
+
+ /* Nothing to work with */
+ if (!sc->sc_hdmi_framer) {
+ device_printf(sc->sc_dev, "HDMI event without HDMI framer set\n");
+ return;
+ }
+
+ hdmi_dev = OF_device_from_xref(sc->sc_hdmi_framer);
+ if (!hdmi_dev) {
+ device_printf(sc->sc_dev, "no actual device for \"hdmi\" property\n");
+ return;
+ }
+
+ edid = NULL;
+ edid_len = 0;
+ if (HDMI_GET_EDID(hdmi_dev, &edid, &edid_len) != 0) {
+ device_printf(sc->sc_dev, "failed to get EDID info from HDMI framer\n");
+ return;
+ }
+
+ videomode = NULL;
+
+ if (edid_parse(edid, &ei) == 0) {
+ edid_print(&ei);
+ videomode = am335x_lcd_pick_mode(&ei);
+ } else
+ device_printf(sc->sc_dev, "failed to parse EDID\n");
+
+ /* Use standard VGA as fallback */
+ if (videomode == NULL)
+ videomode = pick_mode_by_ref(640, 480, 60);
+
+ if (videomode == NULL) {
+ device_printf(sc->sc_dev, "failed to find usable videomode");
+ return;
+ }
+
+ device_printf(sc->sc_dev, "detected videomode: %dx%d @ %dKHz\n", videomode->hdisplay,
+ videomode->vdisplay, am335x_mode_vrefresh(videomode));
+
+ sc->sc_panel.panel_width = videomode->hdisplay;
+ sc->sc_panel.panel_height = videomode->vdisplay;
+ sc->sc_panel.panel_hfp = videomode->hsync_start - videomode->hdisplay;
+ sc->sc_panel.panel_hbp = videomode->htotal - videomode->hsync_end;
+ sc->sc_panel.panel_hsw = videomode->hsync_end - videomode->hsync_start;
+ sc->sc_panel.panel_vfp = videomode->vsync_start - videomode->vdisplay;
+ sc->sc_panel.panel_vbp = videomode->vtotal - videomode->vsync_end;
+ sc->sc_panel.panel_vsw = videomode->vsync_end - videomode->vsync_start;
+ sc->sc_panel.pixelclk_active = 1;
+
+ /* logic for HSYNC should be reversed */
+ if (videomode->flags & VID_NHSYNC)
+ sc->sc_panel.hsync_active = 1;
+ else
+ sc->sc_panel.hsync_active = 0;
+
+ if (videomode->flags & VID_NVSYNC)
+ sc->sc_panel.vsync_active = 0;
+ else
+ sc->sc_panel.vsync_active = 1;
+
+ sc->sc_panel.panel_pxl_clk = videomode->dot_clock * 1000;
+
+ am335x_lcd_configure(sc);
+
+ memcpy(&hdmi_mode, videomode, sizeof(hdmi_mode));
+ hdmi_mode.hskew = videomode->hsync_end - videomode->hsync_start;
+ hdmi_mode.flags |= VID_HSKEW;
+
+ HDMI_SET_VIDEOMODE(hdmi_dev, &hdmi_mode);
+}
+
+static int
+am335x_lcd_probe(device_t dev)
+{
+#ifdef DEV_SC
+ int err;
+#endif
+
+ if (!ofw_bus_status_okay(dev))
+ return (ENXIO);
+
+ if (!ofw_bus_is_compatible(dev, "ti,am33xx-tilcdc"))
+ return (ENXIO);
+
+ device_set_desc(dev, "AM335x LCD controller");
+
+#ifdef DEV_SC
+ err = sc_probe_unit(device_get_unit(dev),
+ device_get_flags(dev) | SC_AUTODETECT_KBD);
+ if (err != 0)
+ return (err);
+#endif
+
+ return (BUS_PROBE_DEFAULT);
+}
+
+static int
+am335x_lcd_attach(device_t dev)
+{
+ struct am335x_lcd_softc *sc;
+
+ int err;
+ int rid;
+ struct sysctl_ctx_list *ctx;
+ struct sysctl_oid *tree;
+ phandle_t root, panel_node;
+
+ err = 0;
+ sc = device_get_softc(dev);
+ sc->sc_dev = dev;
+
+ am335x_read_hdmi_property(dev);
+
+ root = OF_finddevice("/");
+ if (root == -1) {
+ device_printf(dev, "failed to get FDT root node\n");
+ return (ENXIO);
+ }
+
+ sc->sc_panel.ac_bias = 255;
+ sc->sc_panel.ac_bias_intrpt = 0;
+ sc->sc_panel.dma_burst_sz = 16;
+ sc->sc_panel.bpp = 16;
+ sc->sc_panel.fdd = 128;
+ sc->sc_panel.sync_edge = 0;
+ sc->sc_panel.sync_ctrl = 1;
+
+ panel_node = fdt_find_compatible(root, "ti,tilcdc,panel", 1);
+ if (panel_node != 0) {
+ device_printf(dev, "using static panel info\n");
+ if (am335x_read_panel_info(dev, panel_node, &sc->sc_panel)) {
+ device_printf(dev, "failed to read panel info\n");
+ return (ENXIO);
+ }
+
+ if (am335x_read_timing(dev, panel_node, &sc->sc_panel)) {
+ device_printf(dev, "failed to read timings\n");
+ return (ENXIO);
+ }
+ }
+
+ ti_prcm_clk_enable(LCDC_CLK);
+
+ rid = 0;
+ sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
+ RF_ACTIVE);
+ if (!sc->sc_mem_res) {
+ device_printf(dev, "cannot allocate memory window\n");
+ return (ENXIO);
+ }
+
+ rid = 0;
+ sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
+ RF_ACTIVE);
+ if (!sc->sc_irq_res) {
+ bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res);
+ device_printf(dev, "cannot allocate interrupt\n");
+ return (ENXIO);
+ }
+
+ if (bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_MISC | INTR_MPSAFE,
+ NULL, am335x_lcd_intr, sc,
+ &sc->sc_intr_hl) != 0) {
+ bus_release_resource(dev, SYS_RES_IRQ, rid,
+ sc->sc_irq_res);
+ bus_release_resource(dev, SYS_RES_MEMORY, rid,
+ sc->sc_mem_res);
+ device_printf(dev, "Unable to setup the irq handler.\n");
+ return (ENXIO);
+ }
+
+ LCD_LOCK_INIT(sc);
+
+ /* Init backlight interface */
+ ctx = device_get_sysctl_ctx(sc->sc_dev);
+ tree = device_get_sysctl_tree(sc->sc_dev);
+ sc->sc_oid = SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
+ "backlight", CTLTYPE_INT | CTLFLAG_RW, sc, 0,
+ am335x_lcd_sysctl_backlight, "I", "LCD backlight");
+ sc->sc_backlight = 0;
+ /* Check if eCAS interface is available at this point */
+ if (am335x_pwm_config_ecap(PWM_UNIT,
+ PWM_PERIOD, PWM_PERIOD) == 0)
+ sc->sc_backlight = 100;
+
+ if (panel_node != 0)
+ am335x_lcd_configure(sc);
+ else
+ sc->sc_hdmi_evh = EVENTHANDLER_REGISTER(hdmi_event,
+ am335x_lcd_hdmi_event, sc, EVENTHANDLER_PRI_ANY);
+
+ return (0);
+}
+
+static int
+am335x_lcd_detach(device_t dev)
+{
+ /* Do not let unload driver */
+ return (EBUSY);
+}
+
+static struct fb_info *
+am335x_lcd_fb_getinfo(device_t dev)
+{
+ struct am335x_lcd_softc *sc;
+
+ sc = device_get_softc(dev);
+
+ return (&sc->sc_fb_info);
+}
+
+static device_method_t am335x_lcd_methods[] = {
+ DEVMETHOD(device_probe, am335x_lcd_probe),
+ DEVMETHOD(device_attach, am335x_lcd_attach),
+ DEVMETHOD(device_detach, am335x_lcd_detach),
+
+ /* Framebuffer service methods */
+ DEVMETHOD(fb_getinfo, am335x_lcd_fb_getinfo),
+
+ DEVMETHOD_END
+};
+
+static driver_t am335x_lcd_driver = {
+ "fb",
+ am335x_lcd_methods,
+ sizeof(struct am335x_lcd_softc),
+};
+
+static devclass_t am335x_lcd_devclass;
+
+DRIVER_MODULE(am335x_lcd, simplebus, am335x_lcd_driver, am335x_lcd_devclass, 0, 0);
+MODULE_VERSION(am335x_lcd, 1);
+MODULE_DEPEND(am335x_lcd, simplebus, 1, 1, 1);
diff --git a/freebsd/sys/arm/ti/am335x/am335x_lcd.h b/freebsd/sys/arm/ti/am335x/am335x_lcd.h
new file mode 100644
index 00000000..f230a930
--- /dev/null
+++ b/freebsd/sys/arm/ti/am335x/am335x_lcd.h
@@ -0,0 +1,60 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2013 Oleksandr Tymoshenko <gonzo at freebsd.org>
+ * 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.
+ * 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 __AM335X_LCD_H__
+#define __AM335X_LCD_H__
+
+struct panel_info {
+ /* Timing part */
+ uint32_t panel_width;
+ uint32_t panel_height;
+ uint32_t panel_hfp;
+ uint32_t panel_hbp;
+ uint32_t panel_hsw;
+ uint32_t panel_vfp;
+ uint32_t panel_vbp;
+ uint32_t panel_vsw;
+ uint32_t hsync_active;
+ uint32_t vsync_active;
+ uint32_t panel_pxl_clk;
+
+ uint32_t ac_bias;
+ uint32_t ac_bias_intrpt;
+ uint32_t dma_burst_sz;
+ uint32_t bpp;
+ uint32_t fdd;
+ uint32_t sync_edge;
+ uint32_t sync_ctrl;
+ uint32_t pixelclk_active;
+};
+
+int am335x_lcd_syscons_setup(vm_offset_t vaddr, vm_paddr_t paddr,
+ struct panel_info *panel);
+
+#endif /* __AM335X_LCD_H__ */
diff --git a/freebsd/sys/arm/ti/am335x/am335x_pwm.h b/freebsd/sys/arm/ti/am335x/am335x_pwm.h
new file mode 100644
index 00000000..956913dc
--- /dev/null
+++ b/freebsd/sys/arm/ti/am335x/am335x_pwm.h
@@ -0,0 +1,35 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2013 Oleksandr Tymoshenko <gonzo at freebsd.org>
+ * 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.
+ * 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 __AM335X_PWM_H__
+#define __AM335X_PWM_H__
+
+int am335x_pwm_config_ecap(int unit, int period, int duty);
+
+#endif /* __AM335X_PWM_H__ */
diff --git a/freebsd/sys/arm/ti/am335x/am335x_pwmss.c b/freebsd/sys/arm/ti/am335x/am335x_pwmss.c
new file mode 100644
index 00000000..f9249989
--- /dev/null
+++ b/freebsd/sys/arm/ti/am335x/am335x_pwmss.c
@@ -0,0 +1,165 @@
+#include <machine/rtems-bsd-kernel-space.h>
+
+/*-
+ * Copyright (c) 2013 Oleksandr Tymoshenko <gonzo at freebsd.org>
+ * 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.
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/limits.h>
+#include <sys/lock.h>
+#include <sys/module.h>
+#include <sys/mutex.h>
+#include <rtems/bsd/sys/resource.h>
+#include <sys/rman.h>
+#include <sys/sysctl.h>
+
+#include <machine/bus.h>
+
+#include <dev/fdt/simplebus.h>
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+
+#include <arm/ti/ti_prcm.h>
+#include <arm/ti/ti_hwmods.h>
+#include <arm/ti/ti_scm.h>
+
+#include "am335x_pwm.h"
+#include "am335x_scm.h"
+
+#define PWMSS_IDVER 0x00
+#define PWMSS_SYSCONFIG 0x04
+#define PWMSS_CLKCONFIG 0x08
+#define CLKCONFIG_EPWMCLK_EN (1 << 8)
+#define PWMSS_CLKSTATUS 0x0C
+
+static device_probe_t am335x_pwmss_probe;
+static device_attach_t am335x_pwmss_attach;
+static device_detach_t am335x_pwmss_detach;
+
+struct am335x_pwmss_softc {
+ struct simplebus_softc sc_simplebus;
+ device_t sc_dev;
+ clk_ident_t sc_clk;
+};
+
+static device_method_t am335x_pwmss_methods[] = {
+ DEVMETHOD(device_probe, am335x_pwmss_probe),
+ DEVMETHOD(device_attach, am335x_pwmss_attach),
+ DEVMETHOD(device_detach, am335x_pwmss_detach),
+
+ DEVMETHOD_END
+};
+
+static int
+am335x_pwmss_probe(device_t dev)
+{
+
+ if (!ofw_bus_status_okay(dev))
+ return (ENXIO);
+
+ if (!ofw_bus_is_compatible(dev, "ti,am33xx-pwmss"))
+ return (ENXIO);
+
+ device_set_desc(dev, "AM335x PWM");
+
+ return (BUS_PROBE_DEFAULT);
+}
+
+static int
+am335x_pwmss_attach(device_t dev)
+{
+ struct am335x_pwmss_softc *sc;
+ uint32_t reg, id;
+ phandle_t node;
+
+ sc = device_get_softc(dev);
+ sc->sc_dev = dev;
+
+ sc->sc_clk = ti_hwmods_get_clock(dev);
+ if (sc->sc_clk == INVALID_CLK_IDENT) {
+ device_printf(dev, "failed to get device id based on ti,hwmods\n");
+ return (EINVAL);
+ }
+
+ ti_prcm_clk_enable(sc->sc_clk);
+ ti_scm_reg_read_4(SCM_PWMSS_CTRL, ®);
+ switch (sc->sc_clk) {
+ case PWMSS0_CLK:
+ id = 0;
+ break;
+ case PWMSS1_CLK:
+ id = 1;
+ break;
+
+ case PWMSS2_CLK:
+ id = 2;
+ break;
+ default:
+ device_printf(dev, "unknown pwmss clock id: %d\n", sc->sc_clk);
+ return (EINVAL);
+ }
+ reg |= (1 << id);
+ ti_scm_reg_write_4(SCM_PWMSS_CTRL, reg);
+
+ node = ofw_bus_get_node(dev);
+
+ if (node == -1)
+ return (ENXIO);
+
+ simplebus_init(dev, node);
+
+ /*
+ * Allow devices to identify.
+ */
+ bus_generic_probe(dev);
+
+ /*
+ * Now walk the OFW tree and attach top-level devices.
+ */
+ for (node = OF_child(node); node > 0; node = OF_peer(node))
+ simplebus_add_device(dev, node, 0, NULL, -1, NULL);
+
+ return (bus_generic_attach(dev));
+}
+
+static int
+am335x_pwmss_detach(device_t dev)
+{
+
+ return (0);
+}
+
+DEFINE_CLASS_1(am335x_pwmss, am335x_pwmss_driver, am335x_pwmss_methods,
+ sizeof(struct am335x_pwmss_softc), simplebus_driver);
+static devclass_t am335x_pwmss_devclass;
+DRIVER_MODULE(am335x_pwmss, simplebus, am335x_pwmss_driver, am335x_pwmss_devclass, 0, 0);
+MODULE_VERSION(am335x_pwmss, 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 at 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/syscons/syscons.h b/freebsd/sys/dev/syscons/syscons.h
new file mode 100644
index 00000000..defdf0f2
--- /dev/null
+++ b/freebsd/sys/dev/syscons/syscons.h
@@ -0,0 +1,693 @@
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 1995-1998 Søren Schmidt
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The DragonFly Project
+ * by Sascha Wildner <saw at online.de>
+ *
+ * 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,
+ * without modification, immediately at the beginning of the file.
+ * 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 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_SYSCONS_SYSCONS_H_
+#define _DEV_SYSCONS_SYSCONS_H_
+
+#include <sys/kdb.h> /* XXX */
+#include <sys/_lock.h>
+#include <sys/_mutex.h>
+
+/* default values for configuration options */
+
+#ifndef MAXCONS
+#define MAXCONS 16
+#endif
+
+#ifdef SC_NO_SYSMOUSE
+#undef SC_NO_CUTPASTE
+#define SC_NO_CUTPASTE 1
+#endif
+
+#ifdef SC_NO_MODE_CHANGE
+#undef SC_PIXEL_MODE
+#endif
+
+/* Always load font data if the pixel (raster text) mode is to be used. */
+#ifdef SC_PIXEL_MODE
+#undef SC_NO_FONT_LOADING
+#endif
+
+/*
+ * If font data is not available, the `arrow'-shaped mouse cursor cannot
+ * be drawn. Use the alternative drawing method.
+ */
+#ifdef SC_NO_FONT_LOADING
+#undef SC_ALT_MOUSE_IMAGE
+#define SC_ALT_MOUSE_IMAGE 1
+#endif
+
+#ifndef SC_CURSOR_CHAR
+#define SC_CURSOR_CHAR 7
+#endif
+
+#ifndef SC_MOUSE_CHAR
+#define SC_MOUSE_CHAR 8
+#endif
+
+#if SC_MOUSE_CHAR <= SC_CURSOR_CHAR && SC_CURSOR_CHAR < (SC_MOUSE_CHAR + 4)
+#undef SC_CURSOR_CHAR
+#define SC_CURSOR_CHAR (SC_MOUSE_CHAR + 4)
+#endif
+
+#ifndef SC_DEBUG_LEVEL
+#define SC_DEBUG_LEVEL 0
+#endif
+
+#define DPRINTF(l, p) if (SC_DEBUG_LEVEL >= (l)) printf p
+
+#ifndef __sparc64__
+#define SC_DRIVER_NAME "sc"
+#else
+/*
+ * Use a different driver name on sparc64 so it does not get confused
+ * with the system controller devices which are also termed 'sc' in OFW.
+ */
+#define SC_DRIVER_NAME "syscons"
+#endif
+#define SC_VTY(dev) (((sc_ttysoftc *)tty_softc(tp))->st_index)
+#define SC_DEV(sc, vty) ((sc)->dev[(vty) - (sc)->first_vty])
+#define SC_STAT(tp) (*((scr_stat **)&((sc_ttysoftc *)tty_softc(tp))->st_stat))
+
+/* printable chars */
+#ifndef PRINTABLE
+#define PRINTABLE(ch) ((ch) > 0x1b || ((ch) > 0x0d && (ch) < 0x1b) \
+ || (ch) < 0x07)
+#endif
+
+/* macros for "intelligent" screen update */
+#define mark_for_update(scp, x) {\
+ if ((x) < scp->start) scp->start = (x);\
+ else if ((x) > scp->end) scp->end = (x);\
+ }
+#define mark_all(scp) {\
+ scp->start = 0;\
+ scp->end = scp->xsize * scp->ysize - 1;\
+ }
+
+/* vty status flags (scp->status) */
+#define UNKNOWN_MODE 0x00010 /* unknown video mode */
+#define SWITCH_WAIT_REL 0x00080 /* waiting for vty release */
+#define SWITCH_WAIT_ACQ 0x00100 /* waiting for vty ack */
+#define BUFFER_SAVED 0x00200 /* vty buffer is saved */
+#define CURSOR_ENABLED 0x00400 /* text cursor is enabled */
+#define MOUSE_MOVED 0x01000 /* mouse cursor has moved */
+#define MOUSE_CUTTING 0x02000 /* mouse cursor is cutting text */
+#define MOUSE_VISIBLE 0x04000 /* mouse cursor is showing */
+#define GRAPHICS_MODE 0x08000 /* vty is in a graphics mode */
+#define PIXEL_MODE 0x10000 /* vty is in a raster text mode */
+#define SAVER_RUNNING 0x20000 /* screen saver is running */
+#define VR_CURSOR_BLINK 0x40000 /* blinking text cursor */
+#define VR_CURSOR_ON 0x80000 /* text cursor is on */
+#define MOUSE_HIDDEN 0x100000 /* mouse cursor is temporarily hidden */
+
+/* misc defines */
+#define FALSE 0
+#define TRUE 1
+
+/*
+ The following #defines are hard-coded for a maximum text
+ resolution corresponding to a maximum framebuffer
+ resolution of 1920x1200 with an 8x8 font...
+*/
+#define COL 240
+#define ROW 150
+
+#define PCBURST 128
+
+#ifndef BELL_DURATION
+#define BELL_DURATION ((5 * hz + 99) / 100)
+#define BELL_PITCH 800
+#endif
+
+/* virtual terminal buffer */
+typedef struct sc_vtb {
+ int vtb_flags;
+#define VTB_VALID (1 << 0)
+#define VTB_ALLOCED (1 << 1)
+ int vtb_type;
+#define VTB_INVALID 0
+#define VTB_MEMORY 1
+#define VTB_FRAMEBUFFER 2
+#define VTB_RINGBUFFER 3
+ int vtb_cols;
+ int vtb_rows;
+ int vtb_size;
+ vm_offset_t vtb_buffer;
+ int vtb_tail; /* valid for VTB_RINGBUFFER only */
+} sc_vtb_t;
+
+/* text and some mouse cursor attributes */
+struct cursor_attr {
+ u_char flags;
+ u_char base;
+ u_char height;
+ u_char bg[3];
+ u_char mouse_ba;
+ u_char mouse_ia;
+};
+
+/* softc */
+
+struct keyboard;
+struct video_adapter;
+struct scr_stat;
+struct tty;
+
+struct sc_cnstate {
+ u_char kbd_locked;
+ u_char kdb_locked;
+ u_char mtx_locked;
+ u_char kbd_opened;
+ u_char scr_opened;
+};
+
+typedef struct sc_softc {
+ int unit; /* unit # */
+ int config; /* configuration flags */
+#define SC_VESAMODE (1 << 7)
+#define SC_AUTODETECT_KBD (1 << 8)
+#define SC_KERNEL_CONSOLE (1 << 9)
+
+ int flags; /* status flags */
+#define SC_VISUAL_BELL (1 << 0)
+#define SC_QUIET_BELL (1 << 1)
+#if 0 /* not used anymore */
+#define SC_BLINK_CURSOR (1 << 2)
+#define SC_CHAR_CURSOR (1 << 3)
+#endif
+#define SC_MOUSE_ENABLED (1 << 4)
+#define SC_SCRN_IDLE (1 << 5)
+#define SC_SCRN_BLANKED (1 << 6)
+#define SC_SAVER_FAILED (1 << 7)
+#define SC_SCRN_VTYLOCK (1 << 8)
+
+#define SC_INIT_DONE (1 << 16)
+#define SC_SPLASH_SCRN (1 << 17)
+
+ int keyboard; /* -1 if unavailable */
+ struct keyboard *kbd;
+
+ int adapter;
+ struct video_adapter *adp;
+ int initial_mode; /* initial video mode */
+
+ int first_vty;
+ int vtys;
+ struct tty **dev;
+ struct scr_stat *cur_scp;
+ struct scr_stat *new_scp;
+ struct scr_stat *old_scp;
+ int delayed_next_scr;
+
+ char font_loading_in_progress;
+ char switch_in_progress;
+ char write_in_progress;
+ char blink_in_progress;
+ int grab_level;
+ /* 2 is just enough for kdb to grab for stepping normal grabbing: */
+ struct sc_cnstate grab_state[2];
+ int kbd_open_level;
+ struct mtx video_mtx;
+
+ long scrn_time_stamp;
+
+ struct cursor_attr dflt_curs_attr;
+ struct cursor_attr curs_attr;
+
+ u_char scr_map[256];
+ u_char scr_rmap[256];
+
+#ifdef _SC_MD_SOFTC_DECLARED_
+ sc_md_softc_t md; /* machine dependent vars */
+#endif
+
+#ifndef SC_NO_PALETTE_LOADING
+ u_char palette[256 * 3];
+#ifdef SC_PIXEL_MODE
+ u_char palette2[256 * 3];
+#endif
+#endif
+
+#ifndef SC_NO_FONT_LOADING
+ int fonts_loaded;
+#define FONT_8 2
+#define FONT_14 4
+#define FONT_16 8
+#define FONT_22 8
+ u_char *font_8;
+ u_char *font_14;
+ u_char *font_16;
+ u_char *font_22;
+#endif
+
+ u_char cursor_char;
+ u_char mouse_char;
+
+#ifdef KDB
+ int sc_altbrk;
+#endif
+ struct callout ctimeout;
+ struct callout cblink;
+} sc_softc_t;
+
+/* virtual screen */
+typedef struct scr_stat {
+ int index; /* index of this vty */
+ struct sc_softc *sc; /* pointer to softc */
+ struct sc_rndr_sw *rndr; /* renderer */
+#ifndef __sparc64__
+ sc_vtb_t scr;
+#endif
+ sc_vtb_t vtb;
+
+ int xpos; /* current X position */
+ int ypos; /* current Y position */
+ int xsize; /* X text size */
+ int ysize; /* Y text size */
+ int xpixel; /* X graphics size */
+ int ypixel; /* Y graphics size */
+ int xoff; /* X offset in pixel mode */
+ int yoff; /* Y offset in pixel mode */
+
+ u_char *font; /* current font */
+ int font_size; /* fontsize in Y direction */
+ int font_width; /* fontsize in X direction */
+
+ int start; /* modified area start */
+ int end; /* modified area end */
+
+ struct sc_term_sw *tsw;
+ void *ts;
+
+ int status; /* status (bitfield) */
+ int kbd_mode; /* keyboard I/O mode */
+
+ int cursor_pos; /* cursor buffer position */
+ int cursor_oldpos; /* cursor old buffer position */
+ struct cursor_attr dflt_curs_attr;
+ struct cursor_attr base_curs_attr;
+ struct cursor_attr curs_attr;
+
+ int mouse_pos; /* mouse buffer position */
+ int mouse_oldpos; /* mouse old buffer position */
+ short mouse_xpos; /* mouse x coordinate */
+ short mouse_ypos; /* mouse y coordinate */
+ short mouse_oldxpos; /* mouse previous x coordinate */
+ short mouse_oldypos; /* mouse previous y coordinate */
+ short mouse_buttons; /* mouse buttons */
+ int mouse_cut_start; /* mouse cut start pos */
+ int mouse_cut_end; /* mouse cut end pos */
+ int mouse_level; /* xterm mouse protocol */
+ struct proc *mouse_proc; /* proc* of controlling proc */
+ pid_t mouse_pid; /* pid of controlling proc */
+ int mouse_signal; /* signal # to report with */
+ const void *mouse_data; /* renderer (pixmap) data */
+
+ u_short bell_duration;
+ u_short bell_pitch;
+
+ u_char border; /* border color */
+ int mode; /* mode */
+ pid_t pid; /* pid of controlling proc */
+ struct proc *proc; /* proc* of controlling proc */
+ struct vt_mode smode; /* switch mode */
+
+ sc_vtb_t *history; /* circular history buffer */
+ int history_pos; /* position shown on screen */
+ int history_size; /* size of history buffer */
+
+ int splash_save_mode; /* saved mode for splash screen */
+ int splash_save_status; /* saved status for splash screen */
+#ifdef _SCR_MD_STAT_DECLARED_
+ scr_md_stat_t md; /* machine dependent vars */
+#endif
+} scr_stat;
+
+/* TTY softc. */
+typedef struct sc_ttysoftc {
+ int st_index;
+ scr_stat *st_stat;
+} sc_ttysoftc;
+
+#ifndef SC_NORM_ATTR
+#define SC_NORM_ATTR (FG_LIGHTGREY | BG_BLACK)
+#endif
+#ifndef SC_NORM_REV_ATTR
+#define SC_NORM_REV_ATTR (FG_BLACK | BG_LIGHTGREY)
+#endif
+#ifndef SC_KERNEL_CONS_ATTR
+#define SC_KERNEL_CONS_ATTR (FG_WHITE | BG_BLACK)
+#endif
+#ifndef SC_KERNEL_CONS_REV_ATTR
+#define SC_KERNEL_CONS_REV_ATTR (FG_BLACK | BG_LIGHTGREY)
+#endif
+
+/* terminal emulator */
+
+#ifndef SC_DFLT_TERM
+#define SC_DFLT_TERM "scteken"
+#endif
+
+typedef int sc_term_init_t(scr_stat *scp, void **tcp, int code);
+#define SC_TE_COLD_INIT 0
+#define SC_TE_WARM_INIT 1
+typedef int sc_term_term_t(scr_stat *scp, void **tcp);
+typedef void sc_term_puts_t(scr_stat *scp, u_char *buf, int len);
+typedef int sc_term_ioctl_t(scr_stat *scp, struct tty *tp, u_long cmd,
+ caddr_t data, struct thread *td);
+typedef int sc_term_reset_t(scr_stat *scp, int code);
+#define SC_TE_HARD_RESET 0
+#define SC_TE_SOFT_RESET 1
+typedef void sc_term_default_attr_t(scr_stat *scp, int norm, int rev);
+typedef void sc_term_clear_t(scr_stat *scp);
+typedef void sc_term_notify_t(scr_stat *scp, int event);
+#define SC_TE_NOTIFY_VTSWITCH_IN 0
+#define SC_TE_NOTIFY_VTSWITCH_OUT 1
+typedef int sc_term_input_t(scr_stat *scp, int c, struct tty *tp);
+typedef const char *sc_term_fkeystr_t(scr_stat *scp, int c);
+typedef void sc_term_sync_t(scr_stat *scp);
+
+typedef struct sc_term_sw {
+ LIST_ENTRY(sc_term_sw) link;
+ char *te_name; /* name of the emulator */
+ char *te_desc; /* description */
+ char *te_renderer; /* matching renderer */
+ size_t te_size; /* size of internal buffer */
+ int te_refcount; /* reference counter */
+ sc_term_init_t *te_init;
+ sc_term_term_t *te_term;
+ sc_term_puts_t *te_puts;
+ sc_term_ioctl_t *te_ioctl;
+ sc_term_reset_t *te_reset;
+ sc_term_default_attr_t *te_default_attr;
+ sc_term_clear_t *te_clear;
+ sc_term_notify_t *te_notify;
+ sc_term_input_t *te_input;
+ sc_term_fkeystr_t *te_fkeystr;
+ sc_term_sync_t *te_sync;
+} sc_term_sw_t;
+
+#define SCTERM_MODULE(name, sw) \
+ DATA_SET(scterm_set, sw); \
+ static int \
+ scterm_##name##_event(module_t mod, int type, void *data) \
+ { \
+ switch (type) { \
+ case MOD_LOAD: \
+ return sc_term_add(&sw); \
+ case MOD_UNLOAD: \
+ if (sw.te_refcount > 0) \
+ return EBUSY; \
+ return sc_term_remove(&sw); \
+ default: \
+ return EOPNOTSUPP; \
+ break; \
+ } \
+ return 0; \
+ } \
+ static moduledata_t scterm_##name##_mod = { \
+ "scterm-" #name, \
+ scterm_##name##_event, \
+ NULL, \
+ }; \
+ DECLARE_MODULE(scterm_##name, scterm_##name##_mod, \
+ SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
+
+/* renderer function table */
+typedef void vr_init_t(scr_stat *scp);
+typedef void vr_clear_t(scr_stat *scp, int c, int attr);
+typedef void vr_draw_border_t(scr_stat *scp, int color);
+typedef void vr_draw_t(scr_stat *scp, int from, int count, int flip);
+typedef void vr_set_cursor_t(scr_stat *scp, int base, int height, int blink);
+typedef void vr_draw_cursor_t(scr_stat *scp, int at, int blink,
+ int on, int flip);
+typedef void vr_blink_cursor_t(scr_stat *scp, int at, int flip);
+typedef void vr_set_mouse_t(scr_stat *scp);
+typedef void vr_draw_mouse_t(scr_stat *scp, int x, int y, int on);
+
+typedef struct sc_rndr_sw {
+ vr_init_t *init;
+ vr_clear_t *clear;
+ vr_draw_border_t *draw_border;
+ vr_draw_t *draw;
+ vr_set_cursor_t *set_cursor;
+ vr_draw_cursor_t *draw_cursor;
+ vr_blink_cursor_t *blink_cursor;
+ vr_set_mouse_t *set_mouse;
+ vr_draw_mouse_t *draw_mouse;
+} sc_rndr_sw_t;
+
+typedef struct sc_renderer {
+ char *name;
+ int mode;
+ sc_rndr_sw_t *rndrsw;
+ LIST_ENTRY(sc_renderer) link;
+} sc_renderer_t;
+
+#define RENDERER(name, mode, sw, set) \
+ static struct sc_renderer scrndr_##name##_##mode = { \
+ #name, mode, &sw \
+ }; \
+ DATA_SET(scrndr_set, scrndr_##name##_##mode); \
+ DATA_SET(set, scrndr_##name##_##mode)
+
+#define RENDERER_MODULE(name, set) \
+ SET_DECLARE(set, sc_renderer_t); \
+ static int \
+ scrndr_##name##_event(module_t mod, int type, void *data) \
+ { \
+ sc_renderer_t **list; \
+ int error = 0; \
+ switch (type) { \
+ case MOD_LOAD: \
+ SET_FOREACH(list, set) { \
+ error = sc_render_add(*list); \
+ if (error) \
+ break; \
+ } \
+ break; \
+ case MOD_UNLOAD: \
+ SET_FOREACH(list, set) { \
+ error = sc_render_remove(*list);\
+ if (error) \
+ break; \
+ } \
+ break; \
+ default: \
+ return EOPNOTSUPP; \
+ break; \
+ } \
+ return error; \
+ } \
+ static moduledata_t scrndr_##name##_mod = { \
+ "scrndr-" #name, \
+ scrndr_##name##_event, \
+ NULL, \
+ }; \
+ DECLARE_MODULE(scrndr_##name, scrndr_##name##_mod, \
+ SI_SUB_DRIVERS, SI_ORDER_MIDDLE)
+
+typedef struct {
+ int shift_state;
+ int bell_pitch;
+} bios_values_t;
+
+/* other macros */
+#define ISTEXTSC(scp) (!((scp)->status \
+ & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE)))
+#define ISGRAPHSC(scp) (((scp)->status \
+ & (UNKNOWN_MODE | GRAPHICS_MODE)))
+#define ISPIXELSC(scp) (((scp)->status \
+ & (UNKNOWN_MODE | GRAPHICS_MODE | PIXEL_MODE))\
+ == PIXEL_MODE)
+#define ISUNKNOWNSC(scp) ((scp)->status & UNKNOWN_MODE)
+
+#define ISMOUSEAVAIL(af) ((af) & V_ADP_FONT)
+#define ISFONTAVAIL(af) ((af) & V_ADP_FONT)
+#define ISPALAVAIL(af) ((af) & V_ADP_PALETTE)
+
+#define ISSIGVALID(sig) ((sig) > 0 && (sig) < NSIG)
+
+#define SC_VIDEO_LOCKINIT(sc) \
+ mtx_init(&(sc)->video_mtx, "syscons video lock", NULL, \
+ MTX_SPIN | MTX_RECURSE);
+#define SC_VIDEO_LOCK(sc) \
+ do { \
+ if (!kdb_active) \
+ mtx_lock_spin(&(sc)->video_mtx); \
+ } while(0)
+#define SC_VIDEO_UNLOCK(sc) \
+ do { \
+ if (!kdb_active) \
+ mtx_unlock_spin(&(sc)->video_mtx); \
+ } while(0)
+
+/* syscons.c */
+extern int (*sc_user_ioctl)(struct tty *tp, u_long cmd, caddr_t data,
+ struct thread *td);
+
+int sc_probe_unit(int unit, int flags);
+int sc_attach_unit(int unit, int flags);
+
+int set_mode(scr_stat *scp);
+
+void sc_set_border(scr_stat *scp, int color);
+void sc_load_font(scr_stat *scp, int page, int size, int width,
+ u_char *font, int base, int count);
+void sc_save_font(scr_stat *scp, int page, int size, int width,
+ u_char *font, int base, int count);
+void sc_show_font(scr_stat *scp, int page);
+
+void sc_touch_scrn_saver(void);
+void sc_draw_cursor_image(scr_stat *scp);
+void sc_remove_cursor_image(scr_stat *scp);
+void sc_set_cursor_image(scr_stat *scp);
+void sc_change_cursor_shape(scr_stat *scp, int flags,
+ int base, int height);
+int sc_clean_up(scr_stat *scp);
+int sc_switch_scr(sc_softc_t *sc, u_int next_scr);
+void sc_alloc_scr_buffer(scr_stat *scp, int wait, int discard);
+int sc_init_emulator(scr_stat *scp, char *name);
+void sc_paste(scr_stat *scp, const u_char *p, int count);
+void sc_respond(scr_stat *scp, const u_char *p,
+ int count, int wakeup);
+void sc_bell(scr_stat *scp, int pitch, int duration);
+
+/* schistory.c */
+#ifndef SC_NO_HISTORY
+int sc_alloc_history_buffer(scr_stat *scp, int lines,
+ int prev_ysize, int wait);
+void sc_free_history_buffer(scr_stat *scp, int prev_ysize);
+void sc_hist_save(scr_stat *scp);
+#define sc_hist_save_one_line(scp, from) \
+ sc_vtb_append(&(scp)->vtb, (from), (scp)->history, (scp)->xsize)
+int sc_hist_restore(scr_stat *scp);
+void sc_hist_home(scr_stat *scp);
+void sc_hist_end(scr_stat *scp);
+int sc_hist_up_line(scr_stat *scp);
+int sc_hist_down_line(scr_stat *scp);
+int sc_hist_ioctl(struct tty *tp, u_long cmd, caddr_t data,
+ struct thread *td);
+#endif /* SC_NO_HISTORY */
+
+/* scmouse.c */
+#ifndef SC_NO_CUTPASTE
+void sc_alloc_cut_buffer(scr_stat *scp, int wait);
+void sc_draw_mouse_image(scr_stat *scp);
+void sc_remove_mouse_image(scr_stat *scp);
+int sc_inside_cutmark(scr_stat *scp, int pos);
+void sc_remove_cutmarking(scr_stat *scp);
+void sc_remove_all_cutmarkings(sc_softc_t *scp);
+void sc_remove_all_mouse(sc_softc_t *scp);
+void sc_mouse_paste(scr_stat *scp);
+#else
+#define sc_draw_mouse_image(scp)
+#define sc_remove_mouse_image(scp)
+#define sc_inside_cutmark(scp, pos) FALSE
+#define sc_remove_cutmarking(scp)
+#define sc_remove_all_cutmarkings(scp)
+#define sc_remove_all_mouse(scp)
+#define sc_mouse_paste(scp)
+#endif /* SC_NO_CUTPASTE */
+#ifndef SC_NO_SYSMOUSE
+void sc_mouse_move(scr_stat *scp, int x, int y);
+int sc_mouse_ioctl(struct tty *tp, u_long cmd, caddr_t data,
+ struct thread *td);
+#endif /* SC_NO_SYSMOUSE */
+
+/* scvidctl.c */
+int sc_set_text_mode(scr_stat *scp, struct tty *tp, int mode,
+ int xsize, int ysize, int fontsize,
+ int font_width);
+int sc_set_graphics_mode(scr_stat *scp, struct tty *tp, int mode);
+int sc_set_pixel_mode(scr_stat *scp, struct tty *tp, int xsize,
+ int ysize, int fontsize, int font_width);
+int sc_support_pixel_mode(void *arg);
+int sc_vid_ioctl(struct tty *tp, u_long cmd, caddr_t data,
+ struct thread *td);
+
+int sc_render_add(sc_renderer_t *rndr);
+int sc_render_remove(sc_renderer_t *rndr);
+sc_rndr_sw_t *sc_render_match(scr_stat *scp, char *name, int mode);
+
+/* scvtb.c */
+void sc_vtb_init(sc_vtb_t *vtb, int type, int cols, int rows,
+ void *buffer, int wait);
+void sc_vtb_destroy(sc_vtb_t *vtb);
+size_t sc_vtb_size(int cols, int rows);
+void sc_vtb_clear(sc_vtb_t *vtb, int c, int attr);
+
+int sc_vtb_getc(sc_vtb_t *vtb, int at);
+int sc_vtb_geta(sc_vtb_t *vtb, int at);
+void sc_vtb_putc(sc_vtb_t *vtb, int at, int c, int a);
+vm_offset_t sc_vtb_putchar(sc_vtb_t *vtb, vm_offset_t p, int c, int a);
+vm_offset_t sc_vtb_pointer(sc_vtb_t *vtb, int at);
+int sc_vtb_pos(sc_vtb_t *vtb, int pos, int offset);
+
+#define sc_vtb_tail(vtb) ((vtb)->vtb_tail)
+#define sc_vtb_rows(vtb) ((vtb)->vtb_rows)
+#define sc_vtb_cols(vtb) ((vtb)->vtb_cols)
+
+void sc_vtb_copy(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2, int to,
+ int count);
+void sc_vtb_append(sc_vtb_t *vtb1, int from, sc_vtb_t *vtb2,
+ int count);
+void sc_vtb_seek(sc_vtb_t *vtb, int pos);
+void sc_vtb_erase(sc_vtb_t *vtb, int at, int count, int c, int attr);
+void sc_vtb_move(sc_vtb_t *vtb, int from, int to, int count);
+void sc_vtb_delete(sc_vtb_t *vtb, int at, int count, int c, int attr);
+void sc_vtb_ins(sc_vtb_t *vtb, int at, int count, int c, int attr);
+
+/* sysmouse.c */
+int sysmouse_event(mouse_info_t *info);
+
+/* scterm.c */
+void sc_move_cursor(scr_stat *scp, int x, int y);
+void sc_clear_screen(scr_stat *scp);
+int sc_term_add(sc_term_sw_t *sw);
+int sc_term_remove(sc_term_sw_t *sw);
+sc_term_sw_t *sc_term_match(char *name);
+sc_term_sw_t *sc_term_match_by_number(int index);
+
+/* machine dependent functions */
+int sc_max_unit(void);
+sc_softc_t *sc_get_softc(int unit, int flags);
+sc_softc_t *sc_find_softc(struct video_adapter *adp, struct keyboard *kbd);
+int sc_get_cons_priority(int *unit, int *flags);
+void sc_get_bios_values(bios_values_t *values);
+int sc_tone(int herz);
+
+#endif /* !_DEV_SYSCONS_SYSCONS_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_ */
+
diff --git a/freebsd/sys/sys/consio.h b/freebsd/sys/sys/consio.h
new file mode 100644
index 00000000..5dfedc4b
--- /dev/null
+++ b/freebsd/sys/sys/consio.h
@@ -0,0 +1,468 @@
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 1991-1996 Søren Schmidt
+ * 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
+ * in this position and unchanged.
+ * 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 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 _SYS_CONSIO_H_
+#define _SYS_CONSIO_H_
+
+#ifndef _KERNEL
+#include <sys/types.h>
+#endif
+#include <sys/ioccom.h>
+
+/*
+ * Console ioctl commands. Some commands are named as KDXXXX, GIO_XXX, and
+ * PIO_XXX, rather than CONS_XXX, for historical and compatibility reasons.
+ * Some other CONS_XXX commands are works as wrapper around frame buffer
+ * ioctl commands FBIO_XXX. Do not try to change all these commands,
+ * otherwise we shall have compatibility problems.
+ */
+
+/* get/set video mode */
+#define KD_TEXT 0 /* set text mode restore fonts */
+#define KD_TEXT0 0 /* ditto */
+#define KD_GRAPHICS 1 /* set graphics mode */
+#define KD_TEXT1 2 /* set text mode !restore fonts */
+#define KD_PIXEL 3 /* set pixel mode */
+#define KDGETMODE _IOR('K', 9, int)
+#define KDSETMODE _IOWINT('K', 10)
+
+/* set border color */
+#define KDSBORDER _IOWINT('K', 13)
+
+/* set up raster(pixel) text mode */
+struct _scr_size {
+ int scr_size[3];
+};
+typedef struct _scr_size scr_size_t;
+
+#define KDRASTER _IOW('K', 100, scr_size_t)
+
+/* get/set screen char map */
+struct _scrmap {
+ char scrmap[256];
+};
+typedef struct _scrmap scrmap_t;
+
+#define GIO_SCRNMAP _IOR('k', 2, scrmap_t)
+#define PIO_SCRNMAP _IOW('k', 3, scrmap_t)
+
+/* get the current text attribute */
+#define GIO_ATTR _IOR('a', 0, int)
+
+/* get the current text color */
+#define GIO_COLOR _IOR('c', 0, int)
+
+/* get the adapter type (equivalent to FBIO_ADPTYPE) */
+#define CONS_CURRENT _IOR('c', 1, int)
+
+/* get the current video mode (equivalent to FBIO_GETMODE) */
+#define CONS_GET _IOR('c', 2, int)
+
+/* not supported? */
+#define CONS_IO _IO('c', 3)
+
+/* set blank time interval */
+#define CONS_BLANKTIME _IOW('c', 4, int)
+
+/* set/get the screen saver (these ioctls are current noop) */
+struct ssaver {
+#define MAXSSAVER 16
+ char name[MAXSSAVER];
+ int num;
+ long time;
+};
+typedef struct ssaver ssaver_t;
+
+#define CONS_SSAVER _IOW('c', 5, ssaver_t)
+#define CONS_GSAVER _IOWR('c', 6, ssaver_t)
+
+/*
+ * Set the text cursor type.
+ *
+ * This is an old interface extended to support the CONS_HIDDEN_CURSOR bit.
+ * New code should use CONS_CURSORSHAPE. CONS_CURSOR_ATTRS gives the 3
+ * bits supported by the (extended) old interface. The old interface is
+ * especially unusable for hiding the cursor (even with its extension)
+ * since it changes the cursor on all vtys.
+ */
+#define CONS_CURSORTYPE _IOW('c', 7, int)
+
+/* set the bell type to audible or visual */
+#define CONS_VISUAL_BELL (1 << 0)
+#define CONS_QUIET_BELL (1 << 1)
+#define CONS_BELLTYPE _IOW('c', 8, int)
+
+/* set the history (scroll back) buffer size (in lines) */
+#define CONS_HISTORY _IOW('c', 9, int)
+
+/* clear the history (scroll back) buffer */
+#define CONS_CLRHIST _IO('c', 10)
+
+/* mouse cursor ioctl */
+struct mouse_data {
+ int x;
+ int y;
+ int z;
+ int buttons;
+};
+typedef struct mouse_data mouse_data_t;
+
+struct mouse_mode {
+ int mode;
+ int signal;
+};
+typedef struct mouse_mode mouse_mode_t;
+
+struct mouse_event {
+ int id; /* one based */
+ int value;
+};
+typedef struct mouse_event mouse_event_t;
+
+struct mouse_info {
+ int operation;
+#define MOUSE_SHOW 0x01
+#define MOUSE_HIDE 0x02
+#define MOUSE_MOVEABS 0x03
+#define MOUSE_MOVEREL 0x04
+#define MOUSE_GETINFO 0x05
+#define MOUSE_MODE 0x06
+#define MOUSE_ACTION 0x07
+#define MOUSE_MOTION_EVENT 0x08
+#define MOUSE_BUTTON_EVENT 0x09
+#define MOUSE_MOUSECHAR 0x0a
+ union {
+ mouse_data_t data;
+ mouse_mode_t mode;
+ mouse_event_t event;
+ int mouse_char;
+ } u;
+};
+typedef struct mouse_info mouse_info_t;
+
+#define CONS_MOUSECTL _IOWR('c', 10, mouse_info_t)
+
+/* see if the vty has been idle */
+#define CONS_IDLE _IOR('c', 11, int)
+
+/* set the screen saver mode */
+#define CONS_NO_SAVER (-1)
+#define CONS_LKM_SAVER 0
+#define CONS_USR_SAVER 1
+#define CONS_SAVERMODE _IOW('c', 12, int)
+
+/* start the screen saver */
+#define CONS_SAVERSTART _IOW('c', 13, int)
+
+/* set the text cursor shape (see also CONS_CURSORTYPE above) */
+#define CONS_BLINK_CURSOR (1 << 0)
+#define CONS_CHAR_CURSOR (1 << 1)
+#define CONS_HIDDEN_CURSOR (1 << 2)
+#define CONS_CURSOR_ATTRS (CONS_BLINK_CURSOR | CONS_CHAR_CURSOR | \
+ CONS_HIDDEN_CURSOR)
+#define CONS_CHARCURSOR_COLORS (1 << 26)
+#define CONS_MOUSECURSOR_COLORS (1 << 27)
+#define CONS_DEFAULT_CURSOR (1 << 28)
+#define CONS_SHAPEONLY_CURSOR (1 << 29)
+#define CONS_RESET_CURSOR (1 << 30)
+#define CONS_LOCAL_CURSOR (1U << 31)
+struct cshape {
+ /* shape[0]: flags, shape[1]: base, shape[2]: height */
+ int shape[3];
+};
+#define CONS_GETCURSORSHAPE _IOWR('c', 14, struct cshape)
+#define CONS_SETCURSORSHAPE _IOW('c', 15, struct cshape)
+
+/* set/get font data */
+struct fnt8 {
+ char fnt8x8[8*256];
+};
+typedef struct fnt8 fnt8_t;
+
+struct fnt14 {
+ char fnt8x14[14*256];
+};
+typedef struct fnt14 fnt14_t;
+
+struct fnt16 {
+ char fnt8x16[16*256];
+};
+typedef struct fnt16 fnt16_t;
+
+struct vfnt_map {
+ uint32_t src;
+ uint16_t dst;
+ uint16_t len;
+};
+typedef struct vfnt_map vfnt_map_t;
+
+#define VFNT_MAP_NORMAL 0
+#define VFNT_MAP_NORMAL_RIGHT 1
+#define VFNT_MAP_BOLD 2
+#define VFNT_MAP_BOLD_RIGHT 3
+#define VFNT_MAPS 4
+struct vfnt {
+ vfnt_map_t *map[VFNT_MAPS];
+ uint8_t *glyphs;
+ unsigned int map_count[VFNT_MAPS];
+ unsigned int glyph_count;
+ unsigned int width;
+ unsigned int height;
+};
+typedef struct vfnt vfnt_t;
+
+#define PIO_FONT8x8 _IOW('c', 64, fnt8_t)
+#define GIO_FONT8x8 _IOR('c', 65, fnt8_t)
+#define PIO_FONT8x14 _IOW('c', 66, fnt14_t)
+#define GIO_FONT8x14 _IOR('c', 67, fnt14_t)
+#define PIO_FONT8x16 _IOW('c', 68, fnt16_t)
+#define GIO_FONT8x16 _IOR('c', 69, fnt16_t)
+#define PIO_VFONT _IOW('c', 70, vfnt_t)
+#define GIO_VFONT _IOR('c', 71, vfnt_t)
+#define PIO_VFONT_DEFAULT _IO('c', 72)
+
+/* get video mode information */
+struct colors {
+ char fore;
+ char back;
+};
+
+struct vid_info {
+ short size;
+ short m_num;
+ u_short font_size;
+ u_short mv_row, mv_col;
+ u_short mv_rsz, mv_csz;
+ u_short mv_hsz;
+ struct colors mv_norm,
+ mv_rev,
+ mv_grfc;
+ u_char mv_ovscan;
+ u_char mk_keylock;
+};
+typedef struct vid_info vid_info_t;
+
+#define CONS_GETINFO _IOWR('c', 73, vid_info_t)
+
+/* get version */
+#define CONS_GETVERS _IOR('c', 74, int)
+
+/* get the video adapter index (equivalent to FBIO_ADAPTER) */
+#define CONS_CURRENTADP _IOR('c', 100, int)
+
+/* get the video adapter information (equivalent to FBIO_ADPINFO) */
+#define CONS_ADPINFO _IOWR('c', 101, video_adapter_info_t)
+
+/* get the video mode information (equivalent to FBIO_MODEINFO) */
+#define CONS_MODEINFO _IOWR('c', 102, video_info_t)
+
+/* find a video mode (equivalent to FBIO_FINDMODE) */
+#define CONS_FINDMODE _IOWR('c', 103, video_info_t)
+
+/* set the frame buffer window origin (equivalent to FBIO_SETWINORG) */
+#define CONS_SETWINORG _IOWINT('c', 104)
+
+/* use the specified keyboard */
+#define CONS_SETKBD _IOWINT('c', 110)
+
+/* release the current keyboard */
+#define CONS_RELKBD _IO('c', 111)
+
+struct scrshot {
+ int x;
+ int y;
+ int xsize;
+ int ysize;
+ u_int16_t* buf;
+};
+typedef struct scrshot scrshot_t;
+
+/* Snapshot the current video buffer */
+#define CONS_SCRSHOT _IOWR('c', 105, scrshot_t)
+
+/* get/set the current terminal emulator info. */
+#define TI_NAME_LEN 32
+#define TI_DESC_LEN 64
+
+struct term_info {
+ int ti_index;
+ int ti_flags;
+ u_char ti_name[TI_NAME_LEN];
+ u_char ti_desc[TI_DESC_LEN];
+};
+typedef struct term_info term_info_t;
+
+#define CONS_GETTERM _IOWR('c', 112, term_info_t)
+#define CONS_SETTERM _IOW('c', 113, term_info_t)
+
+/*
+ * Vty switching ioctl commands.
+ */
+
+/* get the next available vty */
+#define VT_OPENQRY _IOR('v', 1, int)
+
+/* set/get vty switching mode */
+#ifndef _VT_MODE_DECLARED
+#define _VT_MODE_DECLARED
+struct vt_mode {
+ char mode;
+#define VT_AUTO 0 /* switching is automatic */
+#define VT_PROCESS 1 /* switching controlled by prog */
+#define VT_KERNEL 255 /* switching controlled in kernel */
+ char waitv; /* not implemented yet SOS */
+ short relsig;
+ short acqsig;
+ short frsig; /* not implemented yet SOS */
+};
+typedef struct vt_mode vtmode_t;
+#endif /* !_VT_MODE_DECLARED */
+
+#define VT_SETMODE _IOW('v', 2, vtmode_t)
+#define VT_GETMODE _IOR('v', 3, vtmode_t)
+
+/* acknowledge release or acquisition of a vty */
+#define VT_FALSE 0
+#define VT_TRUE 1
+#define VT_ACKACQ 2
+#define VT_RELDISP _IOWINT('v', 4)
+
+/* activate the specified vty */
+#define VT_ACTIVATE _IOWINT('v', 5)
+
+/* wait until the specified vty is activate */
+#define VT_WAITACTIVE _IOWINT('v', 6)
+
+/* get the currently active vty */
+#define VT_GETACTIVE _IOR('v', 7, int)
+
+/* get the index of the vty */
+#define VT_GETINDEX _IOR('v', 8, int)
+
+/* prevent switching vtys */
+#define VT_LOCKSWITCH _IOW('v', 9, int)
+
+/*
+ * Video mode switching ioctl. See sys/fbio.h for mode numbers.
+ */
+
+#define SW_B40x25 _IO('S', M_B40x25)
+#define SW_C40x25 _IO('S', M_C40x25)
+#define SW_B80x25 _IO('S', M_B80x25)
+#define SW_C80x25 _IO('S', M_C80x25)
+#define SW_BG320 _IO('S', M_BG320)
+#define SW_CG320 _IO('S', M_CG320)
+#define SW_BG640 _IO('S', M_BG640)
+#define SW_EGAMONO80x25 _IO('S', M_EGAMONO80x25)
+#define SW_CG320_D _IO('S', M_CG320_D)
+#define SW_CG640_E _IO('S', M_CG640_E)
+#define SW_EGAMONOAPA _IO('S', M_EGAMONOAPA)
+#define SW_CG640x350 _IO('S', M_CG640x350)
+#define SW_ENH_MONOAPA2 _IO('S', M_ENHMONOAPA2)
+#define SW_ENH_CG640 _IO('S', M_ENH_CG640)
+#define SW_ENH_B40x25 _IO('S', M_ENH_B40x25)
+#define SW_ENH_C40x25 _IO('S', M_ENH_C40x25)
+#define SW_ENH_B80x25 _IO('S', M_ENH_B80x25)
+#define SW_ENH_C80x25 _IO('S', M_ENH_C80x25)
+#define SW_ENH_B80x43 _IO('S', M_ENH_B80x43)
+#define SW_ENH_C80x43 _IO('S', M_ENH_C80x43)
+#define SW_MCAMODE _IO('S', M_MCA_MODE)
+#define SW_VGA_C40x25 _IO('S', M_VGA_C40x25)
+#define SW_VGA_C80x25 _IO('S', M_VGA_C80x25)
+#define SW_VGA_C80x30 _IO('S', M_VGA_C80x30)
+#define SW_VGA_C80x50 _IO('S', M_VGA_C80x50)
+#define SW_VGA_C80x60 _IO('S', M_VGA_C80x60)
+#define SW_VGA_M80x25 _IO('S', M_VGA_M80x25)
+#define SW_VGA_M80x30 _IO('S', M_VGA_M80x30)
+#define SW_VGA_M80x50 _IO('S', M_VGA_M80x50)
+#define SW_VGA_M80x60 _IO('S', M_VGA_M80x60)
+#define SW_VGA11 _IO('S', M_VGA11)
+#define SW_BG640x480 _IO('S', M_VGA11)
+#define SW_VGA12 _IO('S', M_VGA12)
+#define SW_CG640x480 _IO('S', M_VGA12)
+#define SW_VGA13 _IO('S', M_VGA13)
+#define SW_VGA_CG320 _IO('S', M_VGA13)
+#define SW_VGA_CG640 _IO('S', M_VGA_CG640)
+#define SW_VGA_MODEX _IO('S', M_VGA_MODEX)
+
+#define SW_VGA_C90x25 _IO('S', M_VGA_C90x25)
+#define SW_VGA_M90x25 _IO('S', M_VGA_M90x25)
+#define SW_VGA_C90x30 _IO('S', M_VGA_C90x30)
+#define SW_VGA_M90x30 _IO('S', M_VGA_M90x30)
+#define SW_VGA_C90x43 _IO('S', M_VGA_C90x43)
+#define SW_VGA_M90x43 _IO('S', M_VGA_M90x43)
+#define SW_VGA_C90x50 _IO('S', M_VGA_C90x50)
+#define SW_VGA_M90x50 _IO('S', M_VGA_M90x50)
+#define SW_VGA_C90x60 _IO('S', M_VGA_C90x60)
+#define SW_VGA_M90x60 _IO('S', M_VGA_M90x60)
+
+#define SW_TEXT_80x25 _IO('S', M_TEXT_80x25)
+#define SW_TEXT_80x30 _IO('S', M_TEXT_80x30)
+#define SW_TEXT_80x43 _IO('S', M_TEXT_80x43)
+#define SW_TEXT_80x50 _IO('S', M_TEXT_80x50)
+#define SW_TEXT_80x60 _IO('S', M_TEXT_80x60)
+#define SW_TEXT_132x25 _IO('S', M_TEXT_132x25)
+#define SW_TEXT_132x30 _IO('S', M_TEXT_132x30)
+#define SW_TEXT_132x43 _IO('S', M_TEXT_132x43)
+#define SW_TEXT_132x50 _IO('S', M_TEXT_132x50)
+#define SW_TEXT_132x60 _IO('S', M_TEXT_132x60)
+
+#define SW_VESA_CG640x400 _IO('V', M_VESA_CG640x400 - M_VESA_BASE)
+#define SW_VESA_CG640x480 _IO('V', M_VESA_CG640x480 - M_VESA_BASE)
+#define SW_VESA_800x600 _IO('V', M_VESA_800x600 - M_VESA_BASE)
+#define SW_VESA_CG800x600 _IO('V', M_VESA_CG800x600 - M_VESA_BASE)
+#define SW_VESA_1024x768 _IO('V', M_VESA_1024x768 - M_VESA_BASE)
+#define SW_VESA_CG1024x768 _IO('V', M_VESA_CG1024x768 - M_VESA_BASE)
+#define SW_VESA_1280x1024 _IO('V', M_VESA_1280x1024 - M_VESA_BASE)
+#define SW_VESA_CG1280x1024 _IO('V', M_VESA_CG1280x1024 - M_VESA_BASE)
+#define SW_VESA_C80x60 _IO('V', M_VESA_C80x60 - M_VESA_BASE)
+#define SW_VESA_C132x25 _IO('V', M_VESA_C132x25 - M_VESA_BASE)
+#define SW_VESA_C132x43 _IO('V', M_VESA_C132x43 - M_VESA_BASE)
+#define SW_VESA_C132x50 _IO('V', M_VESA_C132x50 - M_VESA_BASE)
+#define SW_VESA_C132x60 _IO('V', M_VESA_C132x60 - M_VESA_BASE)
+#define SW_VESA_32K_320 _IO('V', M_VESA_32K_320 - M_VESA_BASE)
+#define SW_VESA_64K_320 _IO('V', M_VESA_64K_320 - M_VESA_BASE)
+#define SW_VESA_FULL_320 _IO('V', M_VESA_FULL_320 - M_VESA_BASE)
+#define SW_VESA_32K_640 _IO('V', M_VESA_32K_640 - M_VESA_BASE)
+#define SW_VESA_64K_640 _IO('V', M_VESA_64K_640 - M_VESA_BASE)
+#define SW_VESA_FULL_640 _IO('V', M_VESA_FULL_640 - M_VESA_BASE)
+#define SW_VESA_32K_800 _IO('V', M_VESA_32K_800 - M_VESA_BASE)
+#define SW_VESA_64K_800 _IO('V', M_VESA_64K_800 - M_VESA_BASE)
+#define SW_VESA_FULL_800 _IO('V', M_VESA_FULL_800 - M_VESA_BASE)
+#define SW_VESA_32K_1024 _IO('V', M_VESA_32K_1024 - M_VESA_BASE)
+#define SW_VESA_64K_1024 _IO('V', M_VESA_64K_1024 - M_VESA_BASE)
+#define SW_VESA_FULL_1024 _IO('V', M_VESA_FULL_1024 - M_VESA_BASE)
+#define SW_VESA_32K_1280 _IO('V', M_VESA_32K_1280 - M_VESA_BASE)
+#define SW_VESA_64K_1280 _IO('V', M_VESA_64K_1280 - M_VESA_BASE)
+#define SW_VESA_FULL_1280 _IO('V', M_VESA_FULL_1280 - M_VESA_BASE)
+
+#endif /* !_SYS_CONSIO_H_ */
diff --git a/freebsd/sys/sys/fbio.h b/freebsd/sys/sys/fbio.h
new file mode 100644
index 00000000..4cc0cc6d
--- /dev/null
+++ b/freebsd/sys/sys/fbio.h
@@ -0,0 +1,622 @@
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software developed by the Computer Systems
+ * Engineering group at Lawrence Berkeley Laboratory under DARPA
+ * contract BG 91-66 and contributed to Berkeley.
+ *
+ * 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ *
+ * @(#)fbio.h 8.2 (Berkeley) 10/30/93
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _SYS_FBIO_H_
+#define _SYS_FBIO_H_
+
+#ifndef _KERNEL
+#include <sys/types.h>
+#else
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/eventhandler.h>
+#endif
+#include <sys/ioccom.h>
+
+/*
+ * Frame buffer ioctls (from Sprite, trimmed to essentials for X11).
+ */
+
+/*
+ * Frame buffer type codes.
+ */
+#define FBTYPE_SUN1BW 0 /* multibus mono */
+#define FBTYPE_SUN1COLOR 1 /* multibus color */
+#define FBTYPE_SUN2BW 2 /* memory mono */
+#define FBTYPE_SUN2COLOR 3 /* color w/rasterop chips */
+#define FBTYPE_SUN2GP 4 /* GP1/GP2 */
+#define FBTYPE_SUN5COLOR 5 /* RoadRunner accelerator */
+#define FBTYPE_SUN3COLOR 6 /* memory color */
+#define FBTYPE_MEMCOLOR 7 /* memory 24-bit */
+#define FBTYPE_SUN4COLOR 8 /* memory color w/overlay */
+
+#define FBTYPE_NOTSUN1 9 /* reserved for customer */
+#define FBTYPE_NOTSUN2 10 /* reserved for customer */
+#define FBTYPE_PCIMISC 11 /* (generic) PCI misc. disp. */
+
+#define FBTYPE_SUNFAST_COLOR 12 /* accelerated 8bit */
+#define FBTYPE_SUNROP_COLOR 13 /* MEMCOLOR with rop h/w */
+#define FBTYPE_SUNFB_VIDEO 14 /* Simple video mixing */
+#define FBTYPE_RESERVED5 15 /* reserved, do not use */
+#define FBTYPE_RESERVED4 16 /* reserved, do not use */
+#define FBTYPE_SUNGP3 17
+#define FBTYPE_SUNGT 18
+#define FBTYPE_SUNLEO 19 /* zx Leo */
+
+#define FBTYPE_MDA 20
+#define FBTYPE_HERCULES 21
+#define FBTYPE_CGA 22
+#define FBTYPE_EGA 23
+#define FBTYPE_VGA 24
+#define FBTYPE_TGA 26
+#define FBTYPE_TGA2 27
+
+#define FBTYPE_MDICOLOR 28 /* cg14 */
+#define FBTYPE_TCXCOLOR 29 /* SUNW,tcx */
+#define FBTYPE_CREATOR 30
+
+#define FBTYPE_LASTPLUSONE 31 /* max number of fbs (change as add) */
+
+/*
+ * Frame buffer descriptor as returned by FBIOGTYPE.
+ */
+struct fbtype {
+ int fb_type; /* as defined above */
+ int fb_height; /* in pixels */
+ int fb_width; /* in pixels */
+ int fb_depth; /* bits per pixel */
+ int fb_cmsize; /* size of color map (entries) */
+ int fb_size; /* total size in bytes */
+};
+#define FBIOGTYPE _IOR('F', 0, struct fbtype)
+
+#define FBTYPE_GET_STRIDE(_fb) ((_fb)->fb_size / (_fb)->fb_height)
+#define FBTYPE_GET_BPP(_fb) ((_fb)->fb_bpp)
+#define FBTYPE_GET_BYTESPP(_fb) ((_fb)->fb_bpp / 8)
+
+#ifdef _KERNEL
+
+struct fb_info;
+
+typedef int fb_enter_t(void *priv);
+typedef int fb_leave_t(void *priv);
+typedef int fb_setblankmode_t(void *priv, int mode);
+
+struct fb_info {
+ /* Raw copy of fbtype. Do not change. */
+ int fb_type; /* as defined above */
+ int fb_height; /* in pixels */
+ int fb_width; /* in pixels */
+ int fb_depth; /* bits to define color */
+ int fb_cmsize; /* size of color map (entries) */
+ int fb_size; /* total size in bytes */
+
+ struct cdev *fb_cdev;
+
+ device_t fb_fbd_dev; /* "fbd" device. */
+ device_t fb_video_dev; /* Video adapter. */
+
+ fb_enter_t *enter;
+ fb_leave_t *leave;
+ fb_setblankmode_t *setblankmode;
+
+ uintptr_t fb_pbase; /* For FB mmap. */
+ uintptr_t fb_vbase; /* if NULL, use fb_write/fb_read. */
+ void *fb_priv; /* First argument for read/write. */
+ const char *fb_name;
+ uint32_t fb_flags;
+#define FB_FLAG_NOMMAP 1 /* mmap unsupported. */
+#define FB_FLAG_NOWRITE 2 /* disable writes for the time being */
+#define FB_FLAG_MEMATTR 4 /* override memattr for mmap */
+ vm_memattr_t fb_memattr;
+ int fb_stride;
+ int fb_bpp; /* bits per pixel */
+ uint32_t fb_cmap[16];
+};
+
+int fbd_list(void);
+int fbd_register(struct fb_info *);
+int fbd_unregister(struct fb_info *);
+
+static inline int
+register_framebuffer(struct fb_info *info)
+{
+
+ EVENTHANDLER_INVOKE(register_framebuffer, info);
+ return (0);
+}
+
+static inline int
+unregister_framebuffer(struct fb_info *info)
+{
+
+ EVENTHANDLER_INVOKE(unregister_framebuffer, info);
+ return (0);
+}
+#endif
+
+#ifdef notdef
+/*
+ * General purpose structure for passing info in and out of frame buffers
+ * (used for gp1) -- unsupported.
+ */
+struct fbinfo {
+ int fb_physaddr; /* physical frame buffer address */
+ int fb_hwwidth; /* fb board width */
+ int fb_hwheight; /* fb board height */
+ int fb_addrdelta; /* phys addr diff between boards */
+ u_char *fb_ropaddr; /* fb virtual addr */
+ int fb_unit; /* minor devnum of fb */
+};
+#define FBIOGINFO _IOR('F', 2, struct fbinfo)
+#endif
+
+/*
+ * Color map I/O.
+ */
+struct fbcmap {
+ int index; /* first element (0 origin) */
+ int count; /* number of elements */
+ u_char *red; /* red color map elements */
+ u_char *green; /* green color map elements */
+ u_char *blue; /* blue color map elements */
+};
+#define FBIOPUTCMAP _IOW('F', 3, struct fbcmap)
+#define FBIOGETCMAP _IOW('F', 4, struct fbcmap)
+
+/*
+ * Set/get attributes.
+ */
+#define FB_ATTR_NDEVSPECIFIC 8 /* no. of device specific values */
+#define FB_ATTR_NEMUTYPES 4 /* no. of emulation types */
+
+struct fbsattr {
+ int flags; /* flags; see below */
+ int emu_type; /* emulation type (-1 if unused) */
+ int dev_specific[FB_ATTR_NDEVSPECIFIC]; /* catchall */
+};
+#define FB_ATTR_AUTOINIT 1 /* emulation auto init flag */
+#define FB_ATTR_DEVSPECIFIC 2 /* dev. specific stuff valid flag */
+
+struct fbgattr {
+ int real_type; /* real device type */
+ int owner; /* PID of owner, 0 if myself */
+ struct fbtype fbtype; /* fbtype info for real device */
+ struct fbsattr sattr; /* see above */
+ int emu_types[FB_ATTR_NEMUTYPES]; /* possible emulations */
+ /* (-1 if unused) */
+};
+#define FBIOSATTR _IOW('F', 5, struct fbsattr)
+#define FBIOGATTR _IOR('F', 6, struct fbgattr)
+
+/*
+ * Video control.
+ */
+#define FBVIDEO_OFF 0
+#define FBVIDEO_ON 1
+
+#define FBIOSVIDEO _IOW('F', 7, int)
+#define FBIOGVIDEO _IOR('F', 8, int)
+
+/* vertical retrace */
+#define FBIOVERTICAL _IO('F', 9)
+
+/*
+ * Hardware cursor control (for, e.g., CG6). A rather complex and icky
+ * interface that smells like VMS, but there it is....
+ */
+struct fbcurpos {
+ short x;
+ short y;
+};
+
+struct fbcursor {
+ short set; /* flags; see below */
+ short enable; /* nonzero => cursor on, 0 => cursor off */
+ struct fbcurpos pos; /* position on display */
+ struct fbcurpos hot; /* hot-spot within cursor */
+ struct fbcmap cmap; /* cursor color map */
+ struct fbcurpos size; /* number of valid bits in image & mask */
+ caddr_t image; /* cursor image bits */
+ caddr_t mask; /* cursor mask bits */
+};
+#define FB_CUR_SETCUR 0x01 /* set on/off (i.e., obey fbcursor.enable) */
+#define FB_CUR_SETPOS 0x02 /* set position */
+#define FB_CUR_SETHOT 0x04 /* set hot-spot */
+#define FB_CUR_SETCMAP 0x08 /* set cursor color map */
+#define FB_CUR_SETSHAPE 0x10 /* set size & bits */
+#define FB_CUR_SETALL (FB_CUR_SETCUR | FB_CUR_SETPOS | FB_CUR_SETHOT | \
+ FB_CUR_SETCMAP | FB_CUR_SETSHAPE)
+
+/* controls for cursor attributes & shape (including position) */
+#define FBIOSCURSOR _IOW('F', 24, struct fbcursor)
+#define FBIOGCURSOR _IOWR('F', 25, struct fbcursor)
+
+/* controls for cursor position only */
+#define FBIOSCURPOS _IOW('F', 26, struct fbcurpos)
+#define FBIOGCURPOS _IOW('F', 27, struct fbcurpos)
+
+/* get maximum cursor size */
+#define FBIOGCURMAX _IOR('F', 28, struct fbcurpos)
+
+/*
+ * Video board information
+ */
+struct brd_info {
+ u_short accessible_width; /* accessible bytes in scanline */
+ u_short accessible_height; /* number of accessible scanlines */
+ u_short line_bytes; /* number of bytes/scanline */
+ u_short hdb_capable; /* can this thing hardware db? */
+ u_short vmsize; /* video memory size */
+ u_char boardrev; /* board revision # */
+ u_char pad0;
+ u_long pad1;
+};
+#define FBIOGXINFO _IOR('F', 39, struct brd_info)
+
+/*
+ * Monitor information
+ */
+struct mon_info {
+ u_long mon_type; /* bit array */
+#define MON_TYPE_STEREO 0x8 /* stereo display */
+#define MON_TYPE_0_OFFSET 0x4 /* black level 0 ire instead of 7.5 */
+#define MON_TYPE_OVERSCAN 0x2 /* overscan */
+#define MON_TYPE_GRAY 0x1 /* greyscale monitor */
+ u_long pixfreq; /* pixel frequency in Hz */
+ u_long hfreq; /* horizontal freq in Hz */
+ u_long vfreq; /* vertical freq in Hz */
+ u_long vsync; /* vertical sync in scanlines */
+ u_long hsync; /* horizontal sync in pixels */
+ /* these are in pixel units */
+ u_short hfporch; /* horizontal front porch */
+ u_short hbporch; /* horizontal back porch */
+ u_short vfporch; /* vertical front porch */
+ u_short vbporch; /* vertical back porch */
+};
+#define FBIOMONINFO _IOR('F', 40, struct mon_info)
+
+/*
+ * Color map I/O.
+ */
+struct fbcmap_i {
+ unsigned int flags;
+#define FB_CMAP_BLOCK (1 << 0) /* wait for vertical refresh */
+#define FB_CMAP_KERNEL (1 << 1) /* called within kernel */
+ int id; /* color map id */
+ int index; /* first element (0 origin) */
+ int count; /* number of elements */
+ u_char *red; /* red color map elements */
+ u_char *green; /* green color map elements */
+ u_char *blue; /* blue color map elements */
+};
+#define FBIOPUTCMAPI _IOW('F', 41, struct fbcmap_i)
+#define FBIOGETCMAPI _IOW('F', 42, struct fbcmap_i)
+
+/* The new style frame buffer ioctls. */
+
+/* video mode information block */
+struct video_info {
+ int vi_mode; /* mode number, see below */
+ int vi_flags;
+#define V_INFO_COLOR (1 << 0)
+#define V_INFO_GRAPHICS (1 << 1)
+#define V_INFO_LINEAR (1 << 2)
+#define V_INFO_VESA (1 << 3)
+#define V_INFO_NONVGA (1 << 4)
+#define V_INFO_CWIDTH9 (1 << 5)
+ int vi_width;
+ int vi_height;
+ int vi_cwidth;
+ int vi_cheight;
+ int vi_depth;
+ int vi_planes;
+ vm_offset_t vi_window; /* physical address */
+ size_t vi_window_size;
+ size_t vi_window_gran;
+ vm_offset_t vi_buffer; /* physical address */
+ size_t vi_buffer_size;
+ int vi_mem_model;
+#define V_INFO_MM_OTHER (-1)
+#define V_INFO_MM_TEXT 0
+#define V_INFO_MM_PLANAR 1
+#define V_INFO_MM_PACKED 2
+#define V_INFO_MM_DIRECT 3
+#define V_INFO_MM_CGA 100
+#define V_INFO_MM_HGC 101
+#define V_INFO_MM_VGAX 102
+ /* for MM_PACKED and MM_DIRECT only */
+ int vi_pixel_size; /* in bytes */
+ /* for MM_DIRECT only */
+ int vi_pixel_fields[4]; /* RGB and reserved fields */
+ int vi_pixel_fsizes[4];
+ /* reserved */
+ u_char vi_reserved[64];
+ vm_offset_t vi_registers; /* physical address */
+ vm_offset_t vi_registers_size;
+};
+typedef struct video_info video_info_t;
+
+/* adapter infromation block */
+struct video_adapter {
+ int va_index;
+ int va_type;
+#define KD_OTHER 0 /* unknown */
+#define KD_MONO 1 /* monochrome adapter */
+#define KD_HERCULES 2 /* hercules adapter */
+#define KD_CGA 3 /* color graphics adapter */
+#define KD_EGA 4 /* enhanced graphics adapter */
+#define KD_VGA 5 /* video graphics adapter */
+#define KD_TGA 7 /* TGA */
+#define KD_TGA2 8 /* TGA2 */
+ char *va_name;
+ int va_unit;
+ int va_minor;
+ int va_flags;
+#define V_ADP_COLOR (1 << 0)
+#define V_ADP_MODECHANGE (1 << 1)
+#define V_ADP_STATESAVE (1 << 2)
+#define V_ADP_STATELOAD (1 << 3)
+#define V_ADP_FONT (1 << 4)
+#define V_ADP_PALETTE (1 << 5)
+#define V_ADP_BORDER (1 << 6)
+#define V_ADP_VESA (1 << 7)
+#define V_ADP_BOOTDISPLAY (1 << 8)
+#define V_ADP_PROBED (1 << 16)
+#define V_ADP_INITIALIZED (1 << 17)
+#define V_ADP_REGISTERED (1 << 18)
+#define V_ADP_ATTACHED (1 << 19)
+#define V_ADP_DAC8 (1 << 20)
+#define V_ADP_CWIDTH9 (1 << 21)
+ vm_offset_t va_io_base;
+ int va_io_size;
+ vm_offset_t va_crtc_addr;
+ vm_offset_t va_mem_base;
+ int va_mem_size;
+ vm_offset_t va_window; /* virtual address */
+ size_t va_window_size;
+ size_t va_window_gran;
+ u_int va_window_orig;
+ vm_offset_t va_buffer; /* virtual address */
+ size_t va_buffer_size;
+ int va_initial_mode;
+ int va_initial_bios_mode;
+ int va_mode;
+ struct video_info va_info;
+ int va_line_width;
+ struct {
+ int x;
+ int y;
+ } va_disp_start;
+ void *va_token;
+ int va_model;
+ int va_little_bitian;
+ int va_little_endian;
+ int va_buffer_alias;
+ vm_offset_t va_registers; /* virtual address */
+ vm_offset_t va_registers_size;
+};
+typedef struct video_adapter video_adapter_t;
+
+struct video_adapter_info {
+ int va_index;
+ int va_type;
+ char va_name[16];
+ int va_unit;
+ int va_flags;
+ vm_offset_t va_io_base;
+ int va_io_size;
+ vm_offset_t va_crtc_addr;
+ vm_offset_t va_mem_base;
+ int va_mem_size;
+ vm_offset_t va_window; /* virtual address */
+ size_t va_window_size;
+ size_t va_window_gran;
+ vm_offset_t va_unused0;
+ size_t va_buffer_size;
+ int va_initial_mode;
+ int va_initial_bios_mode;
+ int va_mode;
+ int va_line_width;
+ struct {
+ int x;
+ int y;
+ } va_disp_start;
+ u_int va_window_orig;
+ /* reserved */
+ u_char va_reserved[64];
+};
+typedef struct video_adapter_info video_adapter_info_t;
+
+/* some useful video adapter index */
+#define V_ADP_PRIMARY 0
+#define V_ADP_SECONDARY 1
+
+/* video mode numbers */
+
+#define M_B40x25 0 /* black & white 40 columns */
+#define M_C40x25 1 /* color 40 columns */
+#define M_B80x25 2 /* black & white 80 columns */
+#define M_C80x25 3 /* color 80 columns */
+#define M_BG320 4 /* black & white graphics 320x200 */
+#define M_CG320 5 /* color graphics 320x200 */
+#define M_BG640 6 /* black & white graphics 640x200 hi-res */
+#define M_EGAMONO80x25 7 /* ega-mono 80x25 */
+#define M_CG320_D 13 /* ega mode D */
+#define M_CG640_E 14 /* ega mode E */
+#define M_EGAMONOAPA 15 /* ega mode F */
+#define M_CG640x350 16 /* ega mode 10 */
+#define M_ENHMONOAPA2 17 /* ega mode F with extended memory */
+#define M_ENH_CG640 18 /* ega mode 10* */
+#define M_ENH_B40x25 19 /* ega enhanced black & white 40 columns */
+#define M_ENH_C40x25 20 /* ega enhanced color 40 columns */
+#define M_ENH_B80x25 21 /* ega enhanced black & white 80 columns */
+#define M_ENH_C80x25 22 /* ega enhanced color 80 columns */
+#define M_VGA_C40x25 23 /* vga 8x16 font on color */
+#define M_VGA_C80x25 24 /* vga 8x16 font on color */
+#define M_VGA_M80x25 25 /* vga 8x16 font on mono */
+
+#define M_VGA11 26 /* vga 640x480 2 colors */
+#define M_BG640x480 26
+#define M_VGA12 27 /* vga 640x480 16 colors */
+#define M_CG640x480 27
+#define M_VGA13 28 /* vga 320x200 256 colors */
+#define M_VGA_CG320 28
+
+#define M_VGA_C80x50 30 /* vga 8x8 font on color */
+#define M_VGA_M80x50 31 /* vga 8x8 font on color */
+#define M_VGA_C80x30 32 /* vga 8x16 font on color */
+#define M_VGA_M80x30 33 /* vga 8x16 font on color */
+#define M_VGA_C80x60 34 /* vga 8x8 font on color */
+#define M_VGA_M80x60 35 /* vga 8x8 font on color */
+#define M_VGA_CG640 36 /* vga 640x400 256 color */
+#define M_VGA_MODEX 37 /* vga 320x240 256 color */
+
+#define M_VGA_C90x25 40 /* vga 8x16 font on color */
+#define M_VGA_M90x25 41 /* vga 8x16 font on mono */
+#define M_VGA_C90x30 42 /* vga 8x16 font on color */
+#define M_VGA_M90x30 43 /* vga 8x16 font on mono */
+#define M_VGA_C90x43 44 /* vga 8x8 font on color */
+#define M_VGA_M90x43 45 /* vga 8x8 font on mono */
+#define M_VGA_C90x50 46 /* vga 8x8 font on color */
+#define M_VGA_M90x50 47 /* vga 8x8 font on mono */
+#define M_VGA_C90x60 48 /* vga 8x8 font on color */
+#define M_VGA_M90x60 49 /* vga 8x8 font on mono */
+
+#define M_ENH_B80x43 0x70 /* ega black & white 80x43 */
+#define M_ENH_C80x43 0x71 /* ega color 80x43 */
+
+#define M_HGC_P0 0xe0 /* hercules graphics - page 0 @ B0000 */
+#define M_HGC_P1 0xe1 /* hercules graphics - page 1 @ B8000 */
+#define M_MCA_MODE 0xff /* monochrome adapter mode */
+
+#define M_TEXT_80x25 200 /* generic text modes */
+#define M_TEXT_80x30 201
+#define M_TEXT_80x43 202
+#define M_TEXT_80x50 203
+#define M_TEXT_80x60 204
+#define M_TEXT_132x25 205
+#define M_TEXT_132x30 206
+#define M_TEXT_132x43 207
+#define M_TEXT_132x50 208
+#define M_TEXT_132x60 209
+
+#define M_VESA_BASE 0x100 /* VESA mode number base */
+#define M_VESA_CG640x400 0x100 /* 640x400, 256 color */
+#define M_VESA_CG640x480 0x101 /* 640x480, 256 color */
+#define M_VESA_800x600 0x102 /* 800x600, 16 color */
+#define M_VESA_CG800x600 0x103 /* 800x600, 256 color */
+#define M_VESA_1024x768 0x104 /* 1024x768, 16 color */
+#define M_VESA_CG1024x768 0x105 /* 1024x768, 256 color */
+#define M_VESA_1280x1024 0x106 /* 1280x1024, 16 color */
+#define M_VESA_CG1280x1024 0x107 /* 1280x1024, 256 color */
+#define M_VESA_C80x60 0x108 /* 8x8 font */
+#define M_VESA_C132x25 0x109 /* 8x16 font */
+#define M_VESA_C132x43 0x10a /* 8x14 font */
+#define M_VESA_C132x50 0x10b /* 8x8 font */
+#define M_VESA_C132x60 0x10c /* 8x8 font */
+#define M_VESA_32K_320 0x10d /* 320x200, 5:5:5 */
+#define M_VESA_64K_320 0x10e /* 320x200, 5:6:5 */
+#define M_VESA_FULL_320 0x10f /* 320x200, 8:8:8 */
+#define M_VESA_32K_640 0x110 /* 640x480, 5:5:5 */
+#define M_VESA_64K_640 0x111 /* 640x480, 5:6:5 */
+#define M_VESA_FULL_640 0x112 /* 640x480, 8:8:8 */
+#define M_VESA_32K_800 0x113 /* 800x600, 5:5:5 */
+#define M_VESA_64K_800 0x114 /* 800x600, 5:6:5 */
+#define M_VESA_FULL_800 0x115 /* 800x600, 8:8:8 */
+#define M_VESA_32K_1024 0x116 /* 1024x768, 5:5:5 */
+#define M_VESA_64K_1024 0x117 /* 1024x768, 5:6:5 */
+#define M_VESA_FULL_1024 0x118 /* 1024x768, 8:8:8 */
+#define M_VESA_32K_1280 0x119 /* 1280x1024, 5:5:5 */
+#define M_VESA_64K_1280 0x11a /* 1280x1024, 5:6:5 */
+#define M_VESA_FULL_1280 0x11b /* 1280x1024, 8:8:8 */
+#define M_VESA_MODE_MAX 0x1ff
+
+struct video_display_start {
+ int x;
+ int y;
+};
+typedef struct video_display_start video_display_start_t;
+
+struct video_color_palette {
+ int index; /* first element (zero-based) */
+ int count; /* number of elements */
+ u_char *red; /* red */
+ u_char *green; /* green */
+ u_char *blue; /* blue */
+ u_char *transparent; /* may be NULL */
+};
+typedef struct video_color_palette video_color_palette_t;
+
+/* adapter info. */
+#define FBIO_ADAPTER _IOR('F', 100, int)
+#define FBIO_ADPTYPE _IOR('F', 101, int)
+#define FBIO_ADPINFO _IOR('F', 102, struct video_adapter_info)
+
+/* video mode control */
+#define FBIO_MODEINFO _IOWR('F', 103, struct video_info)
+#define FBIO_FINDMODE _IOWR('F', 104, struct video_info)
+#define FBIO_GETMODE _IOR('F', 105, int)
+#define FBIO_SETMODE _IOW('F', 106, int)
+
+/* get/set frame buffer window origin */
+#define FBIO_GETWINORG _IOR('F', 107, u_int)
+#define FBIO_SETWINORG _IOW('F', 108, u_int)
+
+/* get/set display start address */
+#define FBIO_GETDISPSTART _IOR('F', 109, video_display_start_t)
+#define FBIO_SETDISPSTART _IOW('F', 110, video_display_start_t)
+
+/* get/set scan line width */
+#define FBIO_GETLINEWIDTH _IOR('F', 111, u_int)
+#define FBIO_SETLINEWIDTH _IOW('F', 112, u_int)
+
+/* color palette control */
+#define FBIO_GETPALETTE _IOW('F', 113, video_color_palette_t)
+#define FBIO_SETPALETTE _IOW('F', 114, video_color_palette_t)
+
+/* blank display */
+#define V_DISPLAY_ON 0
+#define V_DISPLAY_BLANK 1
+#define V_DISPLAY_STAND_BY 2
+#define V_DISPLAY_SUSPEND 3
+
+#define FBIO_BLANK _IOW('F', 115, int)
+
+#endif /* !_SYS_FBIO_H_ */
diff --git a/freebsd/sys/sys/terminal.h b/freebsd/sys/sys/terminal.h
new file mode 100644
index 00000000..e3413a79
--- /dev/null
+++ b/freebsd/sys/sys/terminal.h
@@ -0,0 +1,240 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2009 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Ed Schouten 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 _SYS_TERMINAL_H_
+#define _SYS_TERMINAL_H_
+
+#include <sys/param.h>
+#include <sys/_lock.h>
+#include <sys/_mutex.h>
+#include <sys/cons.h>
+#include <sys/linker_set.h>
+#include <sys/ttycom.h>
+
+#include <teken/teken.h>
+
+#include <rtems/bsd/local/opt_syscons.h>
+#include <rtems/bsd/local/opt_teken.h>
+
+struct terminal;
+struct thread;
+struct tty;
+
+/*
+ * The terminal layer is an abstraction on top of the TTY layer and the
+ * console interface. It can be used by system console drivers to
+ * easily interact with the kernel console and TTYs.
+ *
+ * Terminals contain terminal emulators, which means console drivers
+ * don't need to implement their own terminal emulator. The terminal
+ * emulator deals with UTF-8 exclusively. This means that term_char_t,
+ * the data type used to store input/output characters will always
+ * contain Unicode codepoints.
+ *
+ * To save memory usage, the top bits of term_char_t will contain other
+ * attributes, like colors. Right now term_char_t is composed as
+ * follows:
+ *
+ * Bits Meaning
+ * 0-20: Character value
+ * 21-25: Bold, underline, blink, reverse, right part of CJK fullwidth character
+ * 26-28: Foreground color
+ * 29-31: Background color
+ */
+
+typedef uint32_t term_char_t;
+#define TCHAR_CHARACTER(c) ((c) & 0x1fffff)
+#define TCHAR_FORMAT(c) (((c) >> 21) & 0x1f)
+#define TCHAR_FGCOLOR(c) (((c) >> 26) & 0x7)
+#define TCHAR_BGCOLOR(c) (((c) >> 29) & 0x7)
+
+typedef teken_attr_t term_attr_t;
+
+typedef teken_color_t term_color_t;
+#define TCOLOR_FG(c) (((c) & 0x7) << 26)
+#define TCOLOR_BG(c) (((c) & 0x7) << 29)
+#define TCOLOR_LIGHT(c) ((c) | 0x8)
+#define TCOLOR_DARK(c) ((c) & ~0x8)
+
+#define TFORMAT(c) (((c) & 0x1f) << 21)
+
+/* syscons(4) compatible color attributes for foreground text */
+#define FG_BLACK TCOLOR_FG(TC_BLACK)
+#define FG_BLUE TCOLOR_FG(TC_BLUE)
+#define FG_GREEN TCOLOR_FG(TC_GREEN)
+#define FG_CYAN TCOLOR_FG(TC_CYAN)
+#define FG_RED TCOLOR_FG(TC_RED)
+#define FG_MAGENTA TCOLOR_FG(TC_MAGENTA)
+#define FG_BROWN TCOLOR_FG(TC_BROWN)
+#define FG_LIGHTGREY TCOLOR_FG(TC_WHITE)
+#define FG_DARKGREY (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_BLACK))
+#define FG_LIGHTBLUE (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_BLUE))
+#define FG_LIGHTGREEN (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_GREEN))
+#define FG_LIGHTCYAN (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_CYAN))
+#define FG_LIGHTRED (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_RED))
+#define FG_LIGHTMAGENTA (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_MAGENTA))
+#define FG_YELLOW (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_BROWN))
+#define FG_WHITE (TFORMAT(TF_BOLD) | TCOLOR_FG(TC_WHITE))
+#define FG_BLINK TFORMAT(TF_BLINK)
+
+/* syscons(4) compatible color attributes for text background */
+#define BG_BLACK TCOLOR_BG(TC_BLACK)
+#define BG_BLUE TCOLOR_BG(TC_BLUE)
+#define BG_GREEN TCOLOR_BG(TC_GREEN)
+#define BG_CYAN TCOLOR_BG(TC_CYAN)
+#define BG_RED TCOLOR_BG(TC_RED)
+#define BG_MAGENTA TCOLOR_BG(TC_MAGENTA)
+#define BG_BROWN TCOLOR_BG(TC_BROWN)
+#define BG_LIGHTGREY TCOLOR_BG(TC_WHITE)
+#define BG_DARKGREY (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_BLACK))
+#define BG_LIGHTBLUE (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_BLUE))
+#define BG_LIGHTGREEN (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_GREEN))
+#define BG_LIGHTCYAN (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_CYAN))
+#define BG_LIGHTRED (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_RED))
+#define BG_LIGHTMAGENTA (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_MAGENTA))
+#define BG_YELLOW (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_BROWN))
+#define BG_WHITE (TFORMAT(TF_BOLD) | TCOLOR_BG(TC_WHITE))
+
+#ifndef TERMINAL_NORM_ATTR
+#ifdef SC_NORM_ATTR
+#define TERMINAL_NORM_ATTR SC_NORM_ATTR
+#else
+#define TERMINAL_NORM_ATTR (FG_LIGHTGREY | BG_BLACK)
+#endif
+#endif
+
+#ifndef TERMINAL_KERN_ATTR
+#ifdef SC_KERNEL_CONS_ATTR
+#define TERMINAL_KERN_ATTR SC_KERNEL_CONS_ATTR
+#else
+#define TERMINAL_KERN_ATTR (FG_WHITE | BG_BLACK)
+#endif
+#endif
+
+typedef teken_pos_t term_pos_t;
+typedef teken_rect_t term_rect_t;
+
+typedef void tc_cursor_t(struct terminal *tm, const term_pos_t *p);
+typedef void tc_putchar_t(struct terminal *tm, const term_pos_t *p,
+ term_char_t c);
+typedef void tc_fill_t(struct terminal *tm, const term_rect_t *r,
+ term_char_t c);
+typedef void tc_copy_t(struct terminal *tm, const term_rect_t *r,
+ const term_pos_t *p);
+typedef void tc_pre_input_t(struct terminal *tm);
+typedef void tc_post_input_t(struct terminal *tm);
+typedef void tc_param_t(struct terminal *tm, int cmd, unsigned int arg);
+typedef void tc_done_t(struct terminal *tm);
+
+typedef void tc_cnprobe_t(struct terminal *tm, struct consdev *cd);
+typedef int tc_cngetc_t(struct terminal *tm);
+
+typedef void tc_cngrab_t(struct terminal *tm);
+typedef void tc_cnungrab_t(struct terminal *tm);
+
+typedef void tc_opened_t(struct terminal *tm, int opened);
+typedef int tc_ioctl_t(struct terminal *tm, u_long cmd, caddr_t data,
+ struct thread *td);
+typedef int tc_mmap_t(struct terminal *tm, vm_ooffset_t offset,
+ vm_paddr_t * paddr, int nprot, vm_memattr_t *memattr);
+typedef void tc_bell_t(struct terminal *tm);
+
+struct terminal_class {
+ /* Terminal emulator. */
+ tc_cursor_t *tc_cursor;
+ tc_putchar_t *tc_putchar;
+ tc_fill_t *tc_fill;
+ tc_copy_t *tc_copy;
+ tc_pre_input_t *tc_pre_input;
+ tc_post_input_t *tc_post_input;
+ tc_param_t *tc_param;
+ tc_done_t *tc_done;
+
+ /* Low-level console interface. */
+ tc_cnprobe_t *tc_cnprobe;
+ tc_cngetc_t *tc_cngetc;
+
+ /* DDB & panic handling. */
+ tc_cngrab_t *tc_cngrab;
+ tc_cnungrab_t *tc_cnungrab;
+
+ /* Misc. */
+ tc_opened_t *tc_opened;
+ tc_ioctl_t *tc_ioctl;
+ tc_mmap_t *tc_mmap;
+ tc_bell_t *tc_bell;
+};
+
+struct terminal {
+ const struct terminal_class *tm_class;
+ void *tm_softc;
+ struct mtx tm_mtx;
+ struct tty *tm_tty;
+ teken_t tm_emulator;
+ struct winsize tm_winsize;
+ unsigned int tm_flags;
+#define TF_MUTE 0x1 /* Drop incoming data. */
+#define TF_BELL 0x2 /* Bell needs to be sent. */
+#define TF_CONS 0x4 /* Console device (needs spinlock). */
+ struct consdev *consdev;
+};
+
+#ifdef _KERNEL
+
+struct terminal *terminal_alloc(const struct terminal_class *tc, void *softc);
+void terminal_maketty(struct terminal *tm, const char *fmt, ...);
+void terminal_set_cursor(struct terminal *tm, const term_pos_t *pos);
+void terminal_set_winsize_blank(struct terminal *tm,
+ const struct winsize *size, int blank, const term_attr_t *attr);
+void terminal_set_winsize(struct terminal *tm, const struct winsize *size);
+void terminal_mute(struct terminal *tm, int yes);
+void terminal_input_char(struct terminal *tm, term_char_t c);
+void terminal_input_raw(struct terminal *tm, char c);
+void terminal_input_special(struct terminal *tm, unsigned int k);
+
+void termcn_cnregister(struct terminal *tm);
+
+/* Kernel console helper interface. */
+extern const struct consdev_ops termcn_cnops;
+
+#define TERMINAL_DECLARE_EARLY(name, class, softc) \
+ static struct terminal name = { \
+ .tm_class = &class, \
+ .tm_softc = softc, \
+ .tm_flags = TF_CONS, \
+ }; \
+ CONSOLE_DEVICE(name ## _consdev, termcn_cnops, &name)
+
+#endif /* _KERNEL */
+
+#endif /* !_SYS_TERMINAL_H_ */
diff --git a/freebsd/sys/teken/teken.h b/freebsd/sys/teken/teken.h
new file mode 100644
index 00000000..0a3928a9
--- /dev/null
+++ b/freebsd/sys/teken/teken.h
@@ -0,0 +1,221 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2008-2009 Ed Schouten <ed at FreeBSD.org>
+ * 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.
+ * 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 _TEKEN_H_
+#define _TEKEN_H_
+
+#include <sys/types.h>
+
+/*
+ * libteken: terminal emulation library.
+ *
+ * This library converts an UTF-8 stream of bytes to terminal drawing
+ * commands.
+ */
+
+typedef uint32_t teken_char_t;
+typedef unsigned short teken_unit_t;
+typedef unsigned char teken_format_t;
+#define TF_BOLD 0x01 /* Bold character. */
+#define TF_UNDERLINE 0x02 /* Underline character. */
+#define TF_BLINK 0x04 /* Blinking character. */
+#define TF_REVERSE 0x08 /* Reverse rendered character. */
+#define TF_CJK_RIGHT 0x10 /* Right-hand side of CJK character. */
+typedef unsigned char teken_color_t;
+#define TC_BLACK 0
+#define TC_RED 1
+#define TC_GREEN 2
+#define TC_BROWN 3
+#define TC_BLUE 4
+#define TC_MAGENTA 5
+#define TC_CYAN 6
+#define TC_WHITE 7
+#define TC_NCOLORS 8
+#define TC_LIGHT 8 /* ORed with the others. */
+
+typedef struct {
+ teken_unit_t tp_row;
+ teken_unit_t tp_col;
+} teken_pos_t;
+typedef struct {
+ teken_pos_t tr_begin;
+ teken_pos_t tr_end;
+} teken_rect_t;
+typedef struct {
+ teken_format_t ta_format;
+ teken_color_t ta_fgcolor;
+ teken_color_t ta_bgcolor;
+} teken_attr_t;
+typedef struct {
+ teken_unit_t ts_begin;
+ teken_unit_t ts_end;
+} teken_span_t;
+
+typedef struct __teken teken_t;
+
+typedef void teken_state_t(teken_t *, teken_char_t);
+
+/*
+ * Drawing routines supplied by the user.
+ */
+
+typedef void tf_bell_t(void *);
+typedef void tf_cursor_t(void *, const teken_pos_t *);
+typedef void tf_putchar_t(void *, const teken_pos_t *, teken_char_t,
+ const teken_attr_t *);
+typedef void tf_fill_t(void *, const teken_rect_t *, teken_char_t,
+ const teken_attr_t *);
+typedef void tf_copy_t(void *, const teken_rect_t *, const teken_pos_t *);
+typedef void tf_pre_input_t(void *);
+typedef void tf_post_input_t(void *);
+typedef void tf_param_t(void *, int, unsigned int);
+#define TP_SHOWCURSOR 0
+#define TP_KEYPADAPP 1
+#define TP_AUTOREPEAT 2
+#define TP_SWITCHVT 3
+#define TP_132COLS 4
+#define TP_SETBELLPD 5
+#define TP_SETBELLPD_PITCH(pd) ((pd) >> 16)
+#define TP_SETBELLPD_DURATION(pd) ((pd) & 0xffff)
+#define TP_MOUSE 6
+#define TP_SETBORDER 7
+#define TP_SETLOCALCURSOR 8
+#define TP_SETGLOBALCURSOR 9
+typedef void tf_respond_t(void *, const void *, size_t);
+
+typedef struct {
+ tf_bell_t *tf_bell;
+ tf_cursor_t *tf_cursor;
+ tf_putchar_t *tf_putchar;
+ tf_fill_t *tf_fill;
+ tf_copy_t *tf_copy;
+ tf_pre_input_t *tf_pre_input;
+ tf_post_input_t *tf_post_input;
+ tf_param_t *tf_param;
+ tf_respond_t *tf_respond;
+} teken_funcs_t;
+
+typedef teken_char_t teken_scs_t(const teken_t *, teken_char_t);
+
+/*
+ * Terminal state.
+ */
+
+struct __teken {
+ const teken_funcs_t *t_funcs;
+ void *t_softc;
+
+ teken_state_t *t_nextstate;
+ unsigned int t_stateflags;
+
+#define T_NUMSIZE 8
+ unsigned int t_nums[T_NUMSIZE];
+ unsigned int t_curnum;
+
+ teken_pos_t t_cursor;
+ teken_attr_t t_curattr;
+ teken_pos_t t_saved_cursor;
+ teken_attr_t t_saved_curattr;
+
+ teken_attr_t t_defattr;
+ teken_pos_t t_winsize;
+
+ /* For DECSTBM. */
+ teken_span_t t_scrollreg;
+ /* For DECOM. */
+ teken_span_t t_originreg;
+
+#define T_NUMCOL 160
+ unsigned int t_tabstops[T_NUMCOL / (sizeof(unsigned int) * 8)];
+
+ unsigned int t_utf8_left;
+ teken_char_t t_utf8_partial;
+ teken_char_t t_last;
+
+ unsigned int t_curscs;
+ teken_scs_t *t_saved_curscs;
+ teken_scs_t *t_scs[2];
+};
+
+/* Initialize teken structure. */
+void teken_init(teken_t *, const teken_funcs_t *, void *);
+
+/* Deliver character input. */
+void teken_input(teken_t *, const void *, size_t);
+
+/* Get/set teken attributes. */
+const teken_pos_t *teken_get_cursor(const teken_t *);
+const teken_attr_t *teken_get_curattr(const teken_t *);
+const teken_attr_t *teken_get_defattr(const teken_t *);
+void teken_get_defattr_cons25(const teken_t *, int *, int *);
+const teken_pos_t *teken_get_winsize(const teken_t *);
+void teken_set_cursor(teken_t *, const teken_pos_t *);
+void teken_set_curattr(teken_t *, const teken_attr_t *);
+void teken_set_defattr(teken_t *, const teken_attr_t *);
+void teken_set_winsize(teken_t *, const teken_pos_t *);
+void teken_set_winsize_noreset(teken_t *, const teken_pos_t *);
+
+/* Key input escape sequences. */
+#define TKEY_UP 0x00
+#define TKEY_DOWN 0x01
+#define TKEY_LEFT 0x02
+#define TKEY_RIGHT 0x03
+
+#define TKEY_HOME 0x04
+#define TKEY_END 0x05
+#define TKEY_INSERT 0x06
+#define TKEY_DELETE 0x07
+#define TKEY_PAGE_UP 0x08
+#define TKEY_PAGE_DOWN 0x09
+
+#define TKEY_F1 0x0a
+#define TKEY_F2 0x0b
+#define TKEY_F3 0x0c
+#define TKEY_F4 0x0d
+#define TKEY_F5 0x0e
+#define TKEY_F6 0x0f
+#define TKEY_F7 0x10
+#define TKEY_F8 0x11
+#define TKEY_F9 0x12
+#define TKEY_F10 0x13
+#define TKEY_F11 0x14
+#define TKEY_F12 0x15
+const char *teken_get_sequence(const teken_t *, unsigned int);
+
+/* Legacy features. */
+void teken_set_8bit(teken_t *);
+void teken_set_cons25(teken_t *);
+void teken_set_cons25keys(teken_t *);
+
+/* Color conversion. */
+teken_color_t teken_256to16(teken_color_t);
+teken_color_t teken_256to8(teken_color_t);
+
+#endif /* !_TEKEN_H_ */
--
2.20.1
More information about the devel
mailing list