Home | History | Annotate | Line # | Download | only in wsfb
genfb.c revision 1.78
      1  1.78       rin /*	$NetBSD: genfb.c,v 1.78 2020/10/19 01:08:06 rin Exp $ */
      2   1.1  macallan 
      3   1.1  macallan /*-
      4   1.1  macallan  * Copyright (c) 2007 Michael Lorenz
      5   1.1  macallan  * All rights reserved.
      6   1.1  macallan  *
      7   1.1  macallan  * Redistribution and use in source and binary forms, with or without
      8   1.1  macallan  * modification, are permitted provided that the following conditions
      9   1.1  macallan  * are met:
     10   1.1  macallan  * 1. Redistributions of source code must retain the above copyright
     11   1.1  macallan  *    notice, this list of conditions and the following disclaimer.
     12   1.1  macallan  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  macallan  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  macallan  *    documentation and/or other materials provided with the distribution.
     15   1.1  macallan  *
     16   1.1  macallan  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17   1.1  macallan  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18   1.1  macallan  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19   1.1  macallan  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20   1.1  macallan  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21   1.1  macallan  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22   1.1  macallan  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23   1.1  macallan  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24   1.1  macallan  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25   1.1  macallan  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26   1.1  macallan  * POSSIBILITY OF SUCH DAMAGE.
     27   1.1  macallan  */
     28   1.1  macallan 
     29   1.1  macallan #include <sys/cdefs.h>
     30  1.78       rin __KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.78 2020/10/19 01:08:06 rin Exp $");
     31   1.1  macallan 
     32   1.1  macallan #include <sys/param.h>
     33   1.1  macallan #include <sys/systm.h>
     34   1.1  macallan #include <sys/kernel.h>
     35   1.1  macallan #include <sys/device.h>
     36   1.1  macallan #include <sys/proc.h>
     37   1.1  macallan #include <sys/mutex.h>
     38   1.1  macallan #include <sys/ioctl.h>
     39   1.1  macallan #include <sys/kernel.h>
     40   1.1  macallan #include <sys/systm.h>
     41  1.23  jmcneill #include <sys/kmem.h>
     42  1.71    martin #include <sys/reboot.h>
     43   1.1  macallan 
     44   1.1  macallan #include <dev/wscons/wsconsio.h>
     45   1.1  macallan #include <dev/wscons/wsdisplayvar.h>
     46   1.1  macallan #include <dev/rasops/rasops.h>
     47   1.1  macallan #include <dev/wsfont/wsfont.h>
     48   1.1  macallan 
     49   1.1  macallan #include <dev/wscons/wsdisplay_vconsvar.h>
     50   1.1  macallan 
     51   1.1  macallan #include <dev/wsfb/genfbvar.h>
     52   1.1  macallan 
     53  1.65  jmcneill #include <dev/videomode/videomode.h>
     54  1.65  jmcneill #include <dev/videomode/edidvar.h>
     55  1.65  jmcneill 
     56  1.29     ahoka #ifdef GENFB_DISABLE_TEXT
     57  1.29     ahoka #define DISABLESPLASH (boothowto & (RB_SINGLE | RB_USERCONF | RB_ASKNAME | \
     58  1.29     ahoka 		AB_VERBOSE | AB_DEBUG) )
     59  1.29     ahoka #endif
     60  1.29     ahoka 
     61  1.53  riastrad #ifdef _KERNEL_OPT
     62   1.1  macallan #include "opt_genfb.h"
     63   1.1  macallan #include "opt_wsfb.h"
     64  1.65  jmcneill #include "opt_rasops.h"
     65  1.53  riastrad #endif
     66   1.1  macallan 
     67  1.11  macallan #ifdef GENFB_DEBUG
     68  1.11  macallan #define GPRINTF panic
     69  1.11  macallan #else
     70  1.49  jmcneill #define GPRINTF aprint_debug
     71  1.11  macallan #endif
     72  1.11  macallan 
     73  1.42  macallan #define GENFB_BRIGHTNESS_STEP 15
     74  1.65  jmcneill #define	GENFB_CHAR_WIDTH_MM 3
     75  1.42  macallan 
     76   1.1  macallan static int	genfb_ioctl(void *, void *, u_long, void *, int, struct lwp *);
     77   1.1  macallan static paddr_t	genfb_mmap(void *, void *, off_t, int);
     78  1.52     skrll static void	genfb_pollc(void *, int);
     79  1.52     skrll 
     80   1.1  macallan static void	genfb_init_screen(void *, struct vcons_screen *, int, long *);
     81  1.65  jmcneill static int	genfb_calc_hsize(struct genfb_softc *);
     82  1.65  jmcneill static int	genfb_calc_cols(struct genfb_softc *);
     83   1.1  macallan 
     84   1.1  macallan static int	genfb_putcmap(struct genfb_softc *, struct wsdisplay_cmap *);
     85   1.1  macallan static int 	genfb_getcmap(struct genfb_softc *, struct wsdisplay_cmap *);
     86   1.1  macallan static int 	genfb_putpalreg(struct genfb_softc *, uint8_t, uint8_t,
     87   1.1  macallan 			    uint8_t, uint8_t);
     88  1.45  macallan static void	genfb_init_palette(struct genfb_softc *);
     89   1.1  macallan 
     90  1.31  macallan static void	genfb_brightness_up(device_t);
     91  1.31  macallan static void	genfb_brightness_down(device_t);
     92  1.31  macallan 
     93   1.1  macallan extern const u_char rasops_cmap[768];
     94   1.1  macallan 
     95  1.18  jmcneill static int genfb_cnattach_called = 0;
     96  1.20  jmcneill static int genfb_enabled = 1;
     97  1.18  jmcneill 
     98  1.19  jmcneill static struct genfb_softc *genfb_softc = NULL;
     99  1.19  jmcneill 
    100   1.2  macallan void
    101   1.2  macallan genfb_init(struct genfb_softc *sc)
    102   1.2  macallan {
    103   1.2  macallan 	prop_dictionary_t dict;
    104  1.42  macallan 	uint64_t cmap_cb, pmf_cb, mode_cb, bl_cb, br_cb, fbaddr;
    105  1.72   msaitoh 	uint64_t fboffset;
    106  1.31  macallan 	bool console;
    107   1.2  macallan 
    108  1.32  macallan 	dict = device_properties(sc->sc_dev);
    109   1.2  macallan #ifdef GENFB_DEBUG
    110  1.54  riastrad 	printf("%s", prop_dictionary_externalize(dict));
    111   1.2  macallan #endif
    112  1.31  macallan 	prop_dictionary_get_bool(dict, "is_console", &console);
    113  1.31  macallan 
    114  1.11  macallan 	if (!prop_dictionary_get_uint32(dict, "width", &sc->sc_width)) {
    115  1.12  macallan 		GPRINTF("no width property\n");
    116  1.11  macallan 		return;
    117  1.11  macallan 	}
    118  1.11  macallan 	if (!prop_dictionary_get_uint32(dict, "height", &sc->sc_height)) {
    119  1.12  macallan 		GPRINTF("no height property\n");
    120  1.11  macallan 		return;
    121  1.11  macallan 	}
    122  1.11  macallan 	if (!prop_dictionary_get_uint32(dict, "depth", &sc->sc_depth)) {
    123  1.12  macallan 		GPRINTF("no depth property\n");
    124  1.11  macallan 		return;
    125  1.11  macallan 	}
    126   1.2  macallan 
    127  1.72   msaitoh 	if (!prop_dictionary_get_uint64(dict, "address", &fboffset)) {
    128  1.12  macallan 		GPRINTF("no address property\n");
    129  1.11  macallan 		return;
    130  1.11  macallan 	}
    131  1.11  macallan 
    132  1.72   msaitoh 	sc->sc_fboffset = (bus_addr_t)fboffset;
    133   1.2  macallan 
    134  1.39  macallan 	sc->sc_fbaddr = NULL;
    135  1.39  macallan 	if (prop_dictionary_get_uint64(dict, "virtual_address", &fbaddr)) {
    136  1.40  macallan 		sc->sc_fbaddr = (void *)(uintptr_t)fbaddr;
    137  1.39  macallan 	}
    138  1.39  macallan 
    139  1.59    nonaka 	sc->sc_shadowfb = NULL;
    140  1.59    nonaka 	if (!prop_dictionary_get_bool(dict, "enable_shadowfb",
    141  1.59    nonaka 	    &sc->sc_enable_shadowfb))
    142  1.59    nonaka #ifdef GENFB_SHADOWFB
    143  1.59    nonaka 		sc->sc_enable_shadowfb = true;
    144  1.59    nonaka #else
    145  1.59    nonaka 		sc->sc_enable_shadowfb = false;
    146  1.59    nonaka #endif
    147  1.59    nonaka 
    148   1.2  macallan 	if (!prop_dictionary_get_uint32(dict, "linebytes", &sc->sc_stride))
    149   1.2  macallan 		sc->sc_stride = (sc->sc_width * sc->sc_depth) >> 3;
    150  1.13  macallan 
    151  1.13  macallan 	/*
    152  1.13  macallan 	 * deal with a bug in the Raptor firmware which always sets
    153  1.13  macallan 	 * stride = width even when depth != 8
    154  1.13  macallan 	 */
    155  1.13  macallan 	if (sc->sc_stride < sc->sc_width * (sc->sc_depth >> 3))
    156  1.13  macallan 		sc->sc_stride = sc->sc_width * (sc->sc_depth >> 3);
    157  1.13  macallan 
    158   1.6  macallan 	sc->sc_fbsize = sc->sc_height * sc->sc_stride;
    159   1.4  macallan 
    160   1.4  macallan 	/* optional colour map callback */
    161   1.4  macallan 	sc->sc_cmcb = NULL;
    162   1.4  macallan 	if (prop_dictionary_get_uint64(dict, "cmap_callback", &cmap_cb)) {
    163   1.4  macallan 		if (cmap_cb != 0)
    164   1.4  macallan 			sc->sc_cmcb = (void *)(vaddr_t)cmap_cb;
    165   1.4  macallan 	}
    166  1.31  macallan 
    167  1.28  jmcneill 	/* optional pmf callback */
    168  1.28  jmcneill 	sc->sc_pmfcb = NULL;
    169  1.28  jmcneill 	if (prop_dictionary_get_uint64(dict, "pmf_callback", &pmf_cb)) {
    170  1.28  jmcneill 		if (pmf_cb != 0)
    171  1.28  jmcneill 			sc->sc_pmfcb = (void *)(vaddr_t)pmf_cb;
    172  1.28  jmcneill 	}
    173  1.31  macallan 
    174  1.34  jmcneill 	/* optional mode callback */
    175  1.34  jmcneill 	sc->sc_modecb = NULL;
    176  1.34  jmcneill 	if (prop_dictionary_get_uint64(dict, "mode_callback", &mode_cb)) {
    177  1.34  jmcneill 		if (mode_cb != 0)
    178  1.34  jmcneill 			sc->sc_modecb = (void *)(vaddr_t)mode_cb;
    179  1.34  jmcneill 	}
    180  1.34  jmcneill 
    181  1.31  macallan 	/* optional backlight control callback */
    182  1.31  macallan 	sc->sc_backlight = NULL;
    183  1.31  macallan 	if (prop_dictionary_get_uint64(dict, "backlight_callback", &bl_cb)) {
    184  1.31  macallan 		if (bl_cb != 0) {
    185  1.31  macallan 			sc->sc_backlight = (void *)(vaddr_t)bl_cb;
    186  1.42  macallan 			aprint_naive_dev(sc->sc_dev,
    187  1.31  macallan 			    "enabling backlight control\n");
    188  1.42  macallan 		}
    189  1.42  macallan 	}
    190  1.42  macallan 
    191  1.42  macallan 	/* optional brightness control callback */
    192  1.42  macallan 	sc->sc_brightness = NULL;
    193  1.42  macallan 	if (prop_dictionary_get_uint64(dict, "brightness_callback", &br_cb)) {
    194  1.42  macallan 		if (br_cb != 0) {
    195  1.42  macallan 			sc->sc_brightness = (void *)(vaddr_t)br_cb;
    196  1.42  macallan 			aprint_naive_dev(sc->sc_dev,
    197  1.42  macallan 			    "enabling brightness control\n");
    198  1.42  macallan 			if (console &&
    199  1.42  macallan 			    sc->sc_brightness->gpc_upd_parameter != NULL) {
    200  1.42  macallan 				pmf_event_register(sc->sc_dev,
    201  1.31  macallan 				    PMFE_DISPLAY_BRIGHTNESS_UP,
    202  1.31  macallan 				    genfb_brightness_up, TRUE);
    203  1.42  macallan 				pmf_event_register(sc->sc_dev,
    204  1.31  macallan 				    PMFE_DISPLAY_BRIGHTNESS_DOWN,
    205  1.31  macallan 				    genfb_brightness_down, TRUE);
    206  1.31  macallan 			}
    207  1.31  macallan 		}
    208  1.31  macallan 	}
    209   1.2  macallan }
    210   1.2  macallan 
    211   1.2  macallan int
    212   1.2  macallan genfb_attach(struct genfb_softc *sc, struct genfb_ops *ops)
    213   1.1  macallan {
    214   1.1  macallan 	struct wsemuldisplaydev_attach_args aa;
    215   1.1  macallan 	prop_dictionary_t dict;
    216   1.1  macallan 	struct rasops_info *ri;
    217  1.21  jmcneill 	uint16_t crow;
    218   1.1  macallan 	long defattr;
    219   1.7  macallan 	bool console;
    220  1.33  jmcneill #ifdef SPLASHSCREEN
    221  1.45  macallan 	int i, j;
    222  1.33  jmcneill 	int error = ENXIO;
    223  1.33  jmcneill #endif
    224   1.9      jmmv 
    225  1.32  macallan 	dict = device_properties(sc->sc_dev);
    226  1.14       phx 	prop_dictionary_get_bool(dict, "is_console", &console);
    227  1.14       phx 
    228  1.21  jmcneill 	if (prop_dictionary_get_uint16(dict, "cursor-row", &crow) == false)
    229  1.21  jmcneill 		crow = 0;
    230  1.21  jmcneill 	if (prop_dictionary_get_bool(dict, "clear-screen", &sc->sc_want_clear)
    231  1.21  jmcneill 	    == false)
    232  1.21  jmcneill 		sc->sc_want_clear = true;
    233  1.21  jmcneill 
    234  1.42  macallan 	aprint_verbose_dev(sc->sc_dev, "framebuffer at %p, size %dx%d, depth %d, "
    235  1.42  macallan 	    "stride %d\n",
    236  1.26  christos 	    sc->sc_fboffset ? (void *)(intptr_t)sc->sc_fboffset : sc->sc_fbaddr,
    237   1.9      jmmv 	    sc->sc_width, sc->sc_height, sc->sc_depth, sc->sc_stride);
    238   1.9      jmmv 
    239   1.1  macallan 	sc->sc_defaultscreen_descr = (struct wsscreen_descr){
    240   1.1  macallan 		"default",
    241   1.1  macallan 		0, 0,
    242   1.1  macallan 		NULL,
    243   1.1  macallan 		8, 16,
    244  1.60  macallan 		WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_UNDERLINE |
    245  1.60  macallan 		  WSSCREEN_RESIZE,
    246   1.3  macallan 		NULL
    247   1.1  macallan 	};
    248   1.1  macallan 	sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
    249   1.1  macallan 	sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
    250   1.1  macallan 	memcpy(&sc->sc_ops, ops, sizeof(struct genfb_ops));
    251   1.1  macallan 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    252  1.36       phx 	if (sc->sc_modecb != NULL)
    253  1.34  jmcneill 		sc->sc_modecb->gmc_setmode(sc, sc->sc_mode);
    254   1.1  macallan 
    255  1.41  macallan 	sc->sc_accessops.ioctl = genfb_ioctl;
    256  1.41  macallan 	sc->sc_accessops.mmap = genfb_mmap;
    257  1.52     skrll 	sc->sc_accessops.pollc = genfb_pollc;
    258  1.41  macallan 
    259  1.59    nonaka 	if (sc->sc_enable_shadowfb) {
    260  1.59    nonaka 		sc->sc_shadowfb = kmem_alloc(sc->sc_fbsize, KM_SLEEP);
    261  1.61       chs 		if (sc->sc_want_clear == false)
    262  1.59    nonaka 			memcpy(sc->sc_shadowfb, sc->sc_fbaddr, sc->sc_fbsize);
    263  1.68       rin 		aprint_verbose_dev(sc->sc_dev,
    264  1.68       rin 		    "shadow framebuffer enabled, size %zu KB\n",
    265  1.68       rin 		    sc->sc_fbsize >> 10);
    266  1.59    nonaka 	}
    267   1.5  macallan 
    268   1.1  macallan 	vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
    269  1.41  macallan 	    &sc->sc_accessops);
    270   1.1  macallan 	sc->vd.init_screen = genfb_init_screen;
    271   1.1  macallan 
    272  1.10      jmmv 	/* Do not print anything between this point and the screen
    273  1.10      jmmv 	 * clear operation below.  Otherwise it will be lost. */
    274  1.10      jmmv 
    275   1.1  macallan 	ri = &sc->sc_console_screen.scr_ri;
    276   1.1  macallan 
    277  1.14       phx 	vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
    278  1.14       phx 	    &defattr);
    279  1.14       phx 	sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    280  1.14       phx 
    281  1.29     ahoka #ifdef SPLASHSCREEN
    282  1.29     ahoka /*
    283  1.29     ahoka  * If system isn't going to go multiuser, or user has requested to see
    284  1.29     ahoka  * boot text, don't render splash screen immediately
    285  1.29     ahoka  */
    286  1.29     ahoka 	if (DISABLESPLASH)
    287  1.29     ahoka #endif
    288  1.29     ahoka 		vcons_redraw_screen(&sc->sc_console_screen);
    289  1.29     ahoka 
    290  1.14       phx 	sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
    291  1.14       phx 	sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
    292  1.14       phx 	sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
    293  1.14       phx 	sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
    294  1.41  macallan 
    295  1.44  macallan 	if (crow >= ri->ri_rows) {
    296  1.44  macallan 		crow = 0;
    297  1.44  macallan 		sc->sc_want_clear = 1;
    298  1.44  macallan 	}
    299  1.44  macallan 
    300  1.41  macallan 	if (console)
    301  1.41  macallan 		wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, crow,
    302  1.41  macallan 		    defattr);
    303   1.1  macallan 
    304  1.10      jmmv 	/* Clear the whole screen to bring it to a known state. */
    305  1.21  jmcneill 	if (sc->sc_want_clear)
    306  1.21  jmcneill 		(*ri->ri_ops.eraserows)(ri, 0, ri->ri_rows, defattr);
    307  1.10      jmmv 
    308  1.45  macallan #ifdef SPLASHSCREEN
    309   1.1  macallan 	j = 0;
    310  1.64  riastrad 	for (i = 0; i < uimin(1 << sc->sc_depth, 256); i++) {
    311  1.33  jmcneill 		if (i >= SPLASH_CMAP_OFFSET &&
    312  1.29     ahoka 		    i < SPLASH_CMAP_OFFSET + SPLASH_CMAP_SIZE) {
    313  1.33  jmcneill 			splash_get_cmap(i,
    314  1.33  jmcneill 			    &sc->sc_cmap_red[i],
    315  1.33  jmcneill 			    &sc->sc_cmap_green[i],
    316  1.33  jmcneill 			    &sc->sc_cmap_blue[i]);
    317  1.29     ahoka 		} else {
    318  1.29     ahoka 			sc->sc_cmap_red[i] = rasops_cmap[j];
    319  1.29     ahoka 			sc->sc_cmap_green[i] = rasops_cmap[j + 1];
    320  1.29     ahoka 			sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
    321  1.29     ahoka 		}
    322  1.29     ahoka 		j += 3;
    323   1.1  macallan 	}
    324  1.33  jmcneill 	genfb_restore_palette(sc);
    325   1.1  macallan 
    326  1.29     ahoka 	sc->sc_splash.si_depth = sc->sc_depth;
    327  1.58       nat 	sc->sc_splash.si_bits = sc->sc_console_screen.scr_ri.ri_origbits;
    328  1.29     ahoka 	sc->sc_splash.si_hwbits = sc->sc_fbaddr;
    329  1.29     ahoka 	sc->sc_splash.si_width = sc->sc_width;
    330  1.29     ahoka 	sc->sc_splash.si_height = sc->sc_height;
    331  1.29     ahoka 	sc->sc_splash.si_stride = sc->sc_stride;
    332  1.29     ahoka 	sc->sc_splash.si_fillrect = NULL;
    333  1.33  jmcneill 	if (!DISABLESPLASH) {
    334  1.33  jmcneill 		error = splash_render(&sc->sc_splash,
    335  1.33  jmcneill 		    SPLASH_F_CENTER|SPLASH_F_FILL);
    336  1.33  jmcneill 		if (error) {
    337  1.33  jmcneill 			SCREEN_ENABLE_DRAWING(&sc->sc_console_screen);
    338  1.45  macallan 			genfb_init_palette(sc);
    339  1.33  jmcneill 			vcons_replay_msgbuf(&sc->sc_console_screen);
    340  1.33  jmcneill 		}
    341  1.33  jmcneill 	}
    342  1.29     ahoka #else
    343  1.45  macallan 	genfb_init_palette(sc);
    344  1.71    martin 	if (console && (boothowto & (AB_SILENT|AB_QUIET)) == 0)
    345  1.53  riastrad 		vcons_replay_msgbuf(&sc->sc_console_screen);
    346  1.29     ahoka #endif
    347  1.27  macallan 
    348  1.19  jmcneill 	if (genfb_softc == NULL)
    349  1.19  jmcneill 		genfb_softc = sc;
    350  1.19  jmcneill 
    351   1.1  macallan 	aa.console = console;
    352   1.1  macallan 	aa.scrdata = &sc->sc_screenlist;
    353  1.41  macallan 	aa.accessops = &sc->sc_accessops;
    354   1.1  macallan 	aa.accesscookie = &sc->vd;
    355   1.1  macallan 
    356  1.29     ahoka #ifdef GENFB_DISABLE_TEXT
    357  1.33  jmcneill 	if (!DISABLESPLASH && error == 0)
    358  1.29     ahoka 		SCREEN_DISABLE_DRAWING(&sc->sc_console_screen);
    359  1.29     ahoka #endif
    360  1.29     ahoka 
    361  1.53  riastrad 	config_found_ia(sc->sc_dev, "wsemuldisplaydev", &aa,
    362  1.53  riastrad 	    wsemuldisplaydevprint);
    363   1.1  macallan 
    364   1.1  macallan 	return 0;
    365   1.1  macallan }
    366   1.1  macallan 
    367   1.1  macallan static int
    368   1.1  macallan genfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    369   1.1  macallan 	struct lwp *l)
    370   1.1  macallan {
    371   1.1  macallan 	struct vcons_data *vd = v;
    372   1.1  macallan 	struct genfb_softc *sc = vd->cookie;
    373   1.1  macallan 	struct wsdisplay_fbinfo *wdf;
    374   1.1  macallan 	struct vcons_screen *ms = vd->active;
    375  1.31  macallan 	struct wsdisplay_param *param;
    376  1.56  macallan 	int new_mode, error, val, ret;
    377   1.1  macallan 
    378   1.1  macallan 	switch (cmd) {
    379   1.1  macallan 		case WSDISPLAYIO_GINFO:
    380   1.6  macallan 			if (ms == NULL)
    381   1.6  macallan 				return ENODEV;
    382   1.1  macallan 			wdf = (void *)data;
    383   1.1  macallan 			wdf->height = ms->scr_ri.ri_height;
    384   1.1  macallan 			wdf->width = ms->scr_ri.ri_width;
    385   1.1  macallan 			wdf->depth = ms->scr_ri.ri_depth;
    386   1.1  macallan 			wdf->cmsize = 256;
    387   1.1  macallan 			return 0;
    388   1.1  macallan 
    389   1.1  macallan 		case WSDISPLAYIO_GETCMAP:
    390   1.1  macallan 			return genfb_getcmap(sc,
    391   1.1  macallan 			    (struct wsdisplay_cmap *)data);
    392   1.1  macallan 
    393   1.1  macallan 		case WSDISPLAYIO_PUTCMAP:
    394   1.1  macallan 			return genfb_putcmap(sc,
    395   1.1  macallan 			    (struct wsdisplay_cmap *)data);
    396   1.1  macallan 
    397   1.3  macallan 		case WSDISPLAYIO_LINEBYTES:
    398   1.3  macallan 			*(u_int *)data = sc->sc_stride;
    399   1.3  macallan 			return 0;
    400   1.3  macallan 
    401   1.1  macallan 		case WSDISPLAYIO_SMODE:
    402  1.24  jmcneill 			new_mode = *(int *)data;
    403  1.11  macallan 
    404  1.24  jmcneill 			/* notify the bus backend */
    405  1.24  jmcneill 			error = 0;
    406  1.24  jmcneill 			if (sc->sc_ops.genfb_ioctl)
    407  1.24  jmcneill 				error = sc->sc_ops.genfb_ioctl(sc, vs,
    408  1.11  macallan 					    cmd, data, flag, l);
    409  1.50  jmcneill 			if (error && error != EPASSTHROUGH)
    410  1.24  jmcneill 				return error;
    411  1.11  macallan 
    412  1.24  jmcneill 			if (new_mode != sc->sc_mode) {
    413  1.24  jmcneill 				sc->sc_mode = new_mode;
    414  1.36       phx 				if (sc->sc_modecb != NULL)
    415  1.34  jmcneill 					sc->sc_modecb->gmc_setmode(sc,
    416  1.34  jmcneill 					    sc->sc_mode);
    417  1.24  jmcneill 				if (new_mode == WSDISPLAYIO_MODE_EMUL) {
    418  1.24  jmcneill 					genfb_restore_palette(sc);
    419  1.24  jmcneill 					vcons_redraw_screen(ms);
    420   1.1  macallan 				}
    421   1.1  macallan 			}
    422   1.1  macallan 			return 0;
    423  1.51  macallan 
    424  1.29     ahoka 		case WSDISPLAYIO_SSPLASH:
    425  1.29     ahoka #if defined(SPLASHSCREEN)
    426  1.29     ahoka 			if(*(int *)data == 1) {
    427  1.29     ahoka 				SCREEN_DISABLE_DRAWING(&sc->sc_console_screen);
    428  1.29     ahoka 				splash_render(&sc->sc_splash,
    429  1.29     ahoka 						SPLASH_F_CENTER|SPLASH_F_FILL);
    430  1.29     ahoka 			} else {
    431  1.29     ahoka 				SCREEN_ENABLE_DRAWING(&sc->sc_console_screen);
    432  1.45  macallan 				genfb_init_palette(sc);
    433  1.29     ahoka 			}
    434  1.29     ahoka 			vcons_redraw_screen(ms);
    435  1.29     ahoka 			return 0;
    436  1.29     ahoka #else
    437  1.29     ahoka 			return ENODEV;
    438  1.29     ahoka #endif
    439  1.31  macallan 		case WSDISPLAYIO_GETPARAM:
    440  1.31  macallan 			param = (struct wsdisplay_param *)data;
    441  1.31  macallan 			switch (param->param) {
    442  1.31  macallan 			case WSDISPLAYIO_PARAM_BRIGHTNESS:
    443  1.42  macallan 				if (sc->sc_brightness == NULL)
    444  1.42  macallan 					return EPASSTHROUGH;
    445  1.31  macallan 				param->min = 0;
    446  1.31  macallan 				param->max = 255;
    447  1.42  macallan 				return sc->sc_brightness->gpc_get_parameter(
    448  1.42  macallan 				    sc->sc_brightness->gpc_cookie,
    449  1.42  macallan 				    &param->curval);
    450  1.31  macallan 			case WSDISPLAYIO_PARAM_BACKLIGHT:
    451  1.42  macallan 				if (sc->sc_backlight == NULL)
    452  1.42  macallan 					return EPASSTHROUGH;
    453  1.31  macallan 				param->min = 0;
    454  1.31  macallan 				param->max = 1;
    455  1.42  macallan 				return sc->sc_backlight->gpc_get_parameter(
    456  1.42  macallan 				    sc->sc_backlight->gpc_cookie,
    457  1.42  macallan 				    &param->curval);
    458  1.31  macallan 			}
    459  1.31  macallan 			return EPASSTHROUGH;
    460  1.31  macallan 
    461  1.31  macallan 		case WSDISPLAYIO_SETPARAM:
    462  1.31  macallan 			param = (struct wsdisplay_param *)data;
    463  1.31  macallan 			switch (param->param) {
    464  1.31  macallan 			case WSDISPLAYIO_PARAM_BRIGHTNESS:
    465  1.42  macallan 				if (sc->sc_brightness == NULL)
    466  1.42  macallan 					return EPASSTHROUGH;
    467  1.42  macallan 				val = param->curval;
    468  1.42  macallan 				if (val < 0) val = 0;
    469  1.42  macallan 				if (val > 255) val = 255;
    470  1.42  macallan 				return sc->sc_brightness->gpc_set_parameter(
    471  1.42  macallan 				    sc->sc_brightness->gpc_cookie, val);
    472  1.31  macallan 			case WSDISPLAYIO_PARAM_BACKLIGHT:
    473  1.42  macallan 				if (sc->sc_backlight == NULL)
    474  1.42  macallan 					return EPASSTHROUGH;
    475  1.42  macallan 				val = param->curval;
    476  1.42  macallan 				if (val < 0) val = 0;
    477  1.42  macallan 				if (val > 1) val = 1;
    478  1.42  macallan 				return sc->sc_backlight->gpc_set_parameter(
    479  1.42  macallan 				    sc->sc_backlight->gpc_cookie, val);
    480  1.31  macallan 			}
    481  1.56  macallan 			return EPASSTHROUGH;
    482  1.56  macallan 	}
    483  1.56  macallan 	ret = EPASSTHROUGH;
    484  1.56  macallan 	if (sc->sc_ops.genfb_ioctl)
    485  1.56  macallan 		ret = sc->sc_ops.genfb_ioctl(sc, vs, cmd, data, flag, l);
    486  1.56  macallan 	if (ret != EPASSTHROUGH)
    487  1.56  macallan 		return ret;
    488  1.56  macallan 	/*
    489  1.56  macallan 	 * XXX
    490  1.56  macallan 	 * handle these only if there either is no ioctl() handler or it didn't
    491  1.56  macallan 	 * know how to deal with them. This allows bus frontends to override
    492  1.56  macallan 	 * them but still provides fallback implementations
    493  1.56  macallan 	 */
    494  1.56  macallan 	switch (cmd) {
    495  1.42  macallan 		case WSDISPLAYIO_GET_EDID: {
    496  1.42  macallan 			struct wsdisplayio_edid_info *d = data;
    497  1.42  macallan 			return wsdisplayio_get_edid(sc->sc_dev, d);
    498  1.42  macallan 		}
    499  1.51  macallan 
    500  1.51  macallan 		case WSDISPLAYIO_GET_FBINFO: {
    501  1.51  macallan 			struct wsdisplayio_fbinfo *fbi = data;
    502  1.77       rin 			return wsdisplayio_get_fbinfo(&ms->scr_ri, fbi);
    503  1.51  macallan 		}
    504   1.1  macallan 	}
    505   1.1  macallan 	return EPASSTHROUGH;
    506   1.1  macallan }
    507   1.1  macallan 
    508   1.1  macallan static paddr_t
    509   1.1  macallan genfb_mmap(void *v, void *vs, off_t offset, int prot)
    510   1.1  macallan {
    511   1.1  macallan 	struct vcons_data *vd = v;
    512   1.1  macallan 	struct genfb_softc *sc = vd->cookie;
    513   1.1  macallan 
    514   1.1  macallan 	if (sc->sc_ops.genfb_mmap)
    515   1.1  macallan 		return sc->sc_ops.genfb_mmap(sc, vs, offset, prot);
    516   1.1  macallan 
    517   1.1  macallan 	return -1;
    518   1.1  macallan }
    519   1.1  macallan 
    520   1.1  macallan static void
    521  1.52     skrll genfb_pollc(void *v, int on)
    522  1.52     skrll {
    523  1.52     skrll 	struct vcons_data *vd = v;
    524  1.52     skrll 	struct genfb_softc *sc = vd->cookie;
    525  1.52     skrll 
    526  1.52     skrll 	if (sc == NULL)
    527  1.52     skrll 		return;
    528  1.52     skrll 
    529  1.52     skrll 	if (on)
    530  1.52     skrll 		genfb_enable_polling(sc->sc_dev);
    531  1.52     skrll 	else
    532  1.52     skrll 		genfb_disable_polling(sc->sc_dev);
    533  1.52     skrll }
    534  1.52     skrll 
    535  1.52     skrll static void
    536   1.1  macallan genfb_init_screen(void *cookie, struct vcons_screen *scr,
    537   1.1  macallan     int existing, long *defattr)
    538   1.1  macallan {
    539   1.1  macallan 	struct genfb_softc *sc = cookie;
    540   1.1  macallan 	struct rasops_info *ri = &scr->scr_ri;
    541  1.65  jmcneill 	int wantcols;
    542  1.78       rin 	bool is_bgr, is_swapped;
    543   1.1  macallan 
    544   1.1  macallan 	ri->ri_depth = sc->sc_depth;
    545   1.1  macallan 	ri->ri_width = sc->sc_width;
    546   1.1  macallan 	ri->ri_height = sc->sc_height;
    547   1.1  macallan 	ri->ri_stride = sc->sc_stride;
    548  1.21  jmcneill 	ri->ri_flg = RI_CENTER;
    549  1.21  jmcneill 	if (sc->sc_want_clear)
    550  1.21  jmcneill 		ri->ri_flg |= RI_FULLCLEAR;
    551   1.1  macallan 
    552  1.60  macallan 	scr->scr_flags |= VCONS_LOADFONT;
    553  1.60  macallan 
    554   1.5  macallan 	if (sc->sc_shadowfb != NULL) {
    555   1.5  macallan 		ri->ri_hwbits = (char *)sc->sc_fbaddr;
    556   1.5  macallan 		ri->ri_bits = (char *)sc->sc_shadowfb;
    557  1.59    nonaka 	} else {
    558   1.5  macallan 		ri->ri_bits = (char *)sc->sc_fbaddr;
    559  1.30  macallan 		scr->scr_flags |= VCONS_DONT_READ;
    560  1.30  macallan 	}
    561   1.1  macallan 
    562  1.67       rin 	if (existing && sc->sc_want_clear)
    563   1.1  macallan 		ri->ri_flg |= RI_CLEAR;
    564   1.1  macallan 
    565  1.69       rin 	switch (ri->ri_depth) {
    566  1.69       rin 	case 32:
    567  1.69       rin 	case 24:
    568  1.78       rin 		ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 8;
    569  1.67       rin 		ri->ri_flg |= RI_ENABLE_ALPHA;
    570  1.67       rin 
    571  1.70       rin 		is_bgr = false;
    572  1.48  macallan 		prop_dictionary_get_bool(device_properties(sc->sc_dev),
    573  1.48  macallan 		    "is_bgr", &is_bgr);
    574  1.78       rin 
    575  1.78       rin 		is_swapped = false;
    576  1.78       rin 		prop_dictionary_get_bool(device_properties(sc->sc_dev),
    577  1.78       rin 		    "is_swapped", &is_swapped);
    578  1.78       rin 
    579  1.48  macallan 		if (is_bgr) {
    580  1.48  macallan 			/* someone requested BGR */
    581  1.48  macallan 			ri->ri_rpos = 0;
    582  1.48  macallan 			ri->ri_gpos = 8;
    583  1.48  macallan 			ri->ri_bpos = 16;
    584  1.78       rin 		} else if (is_swapped) {
    585  1.78       rin 			/* byte-swapped, must be 32 bpp */
    586  1.78       rin 			KASSERT(ri->ri_depth == 32);
    587  1.78       rin 			ri->ri_rpos = 8;
    588  1.78       rin 			ri->ri_gpos = 16;
    589  1.78       rin 			ri->ri_bpos = 24;
    590  1.48  macallan 		} else {
    591  1.48  macallan 			/* assume RGB */
    592  1.48  macallan 			ri->ri_rpos = 16;
    593  1.48  macallan 			ri->ri_gpos = 8;
    594  1.48  macallan 			ri->ri_bpos = 0;
    595  1.48  macallan 		}
    596  1.69       rin 		break;
    597  1.69       rin 
    598  1.69       rin 	case 16:
    599  1.69       rin 	case 15:
    600  1.69       rin 		ri->ri_flg |= RI_ENABLE_ALPHA;
    601  1.69       rin 		break;
    602  1.69       rin 
    603  1.69       rin 	case 8:
    604  1.69       rin 		if (sc->sc_cmcb != NULL)
    605  1.69       rin 			ri->ri_flg |= RI_ENABLE_ALPHA | RI_8BIT_IS_RGB;
    606  1.69       rin 		break;
    607  1.43  macallan 
    608  1.69       rin 	case 2:
    609  1.66       rin 		ri->ri_flg |= RI_ENABLE_ALPHA;
    610  1.69       rin 		break;
    611  1.66       rin 
    612  1.69       rin 	default:
    613  1.69       rin 		break;
    614  1.69       rin 	}
    615  1.45  macallan 
    616  1.65  jmcneill 	wantcols = genfb_calc_cols(sc);
    617  1.45  macallan 
    618  1.65  jmcneill 	rasops_init(ri, 0, wantcols);
    619  1.60  macallan 	ri->ri_caps = WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_UNDERLINE |
    620  1.60  macallan 		  WSSCREEN_RESIZE;
    621   1.1  macallan 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
    622   1.1  macallan 		    sc->sc_width / ri->ri_font->fontwidth);
    623   1.1  macallan 
    624  1.27  macallan 	/* TODO: actually center output */
    625   1.1  macallan 	ri->ri_hw = scr;
    626  1.29     ahoka 
    627  1.29     ahoka #ifdef GENFB_DISABLE_TEXT
    628  1.29     ahoka 	if (scr == &sc->sc_console_screen && !DISABLESPLASH)
    629  1.29     ahoka 		SCREEN_DISABLE_DRAWING(&sc->sc_console_screen);
    630  1.29     ahoka #endif
    631   1.1  macallan }
    632   1.1  macallan 
    633  1.65  jmcneill /* Returns the width of the display in millimeters, or 0 if not known. */
    634  1.65  jmcneill static int
    635  1.65  jmcneill genfb_calc_hsize(struct genfb_softc *sc)
    636  1.65  jmcneill {
    637  1.65  jmcneill 	device_t dev = sc->sc_dev;
    638  1.65  jmcneill 	prop_dictionary_t dict = device_properties(dev);
    639  1.65  jmcneill 	prop_data_t edid_data;
    640  1.73  jdolecek 	struct edid_info *edid;
    641  1.65  jmcneill 	const char *edid_ptr;
    642  1.73  jdolecek 	int hsize;
    643  1.65  jmcneill 
    644  1.65  jmcneill 	edid_data = prop_dictionary_get(dict, "EDID");
    645  1.65  jmcneill 	if (edid_data == NULL || prop_data_size(edid_data) < 128)
    646  1.65  jmcneill 		return 0;
    647  1.65  jmcneill 
    648  1.73  jdolecek 	edid = kmem_alloc(sizeof(*edid), KM_SLEEP);
    649  1.73  jdolecek 
    650  1.74   thorpej 	edid_ptr = prop_data_value(edid_data);
    651  1.73  jdolecek 	if (edid_parse(__UNCONST(edid_ptr), edid) == 0)
    652  1.73  jdolecek 		hsize = (int)edid->edid_max_hsize * 10;
    653  1.73  jdolecek 	else
    654  1.73  jdolecek 		hsize = 0;
    655  1.73  jdolecek 
    656  1.73  jdolecek 	kmem_free(edid, sizeof(*edid));
    657  1.65  jmcneill 
    658  1.73  jdolecek 	return hsize;
    659  1.65  jmcneill }
    660  1.65  jmcneill 
    661  1.65  jmcneill /* Return the minimum number of character columns based on DPI */
    662  1.65  jmcneill static int
    663  1.65  jmcneill genfb_calc_cols(struct genfb_softc *sc)
    664  1.65  jmcneill {
    665  1.65  jmcneill 	const int hsize = genfb_calc_hsize(sc);
    666  1.65  jmcneill 
    667  1.65  jmcneill 	return MAX(RASOPS_DEFAULT_WIDTH, hsize / GENFB_CHAR_WIDTH_MM);
    668  1.65  jmcneill }
    669  1.65  jmcneill 
    670   1.1  macallan static int
    671   1.1  macallan genfb_putcmap(struct genfb_softc *sc, struct wsdisplay_cmap *cm)
    672   1.1  macallan {
    673   1.1  macallan 	u_char *r, *g, *b;
    674   1.1  macallan 	u_int index = cm->index;
    675   1.1  macallan 	u_int count = cm->count;
    676   1.1  macallan 	int i, error;
    677   1.1  macallan 	u_char rbuf[256], gbuf[256], bbuf[256];
    678   1.1  macallan 
    679   1.1  macallan #ifdef GENFB_DEBUG
    680   1.1  macallan 	aprint_debug("putcmap: %d %d\n",index, count);
    681   1.1  macallan #endif
    682  1.63   mlelstv 	if (index >= 256 || count > 256 || index + count > 256)
    683   1.1  macallan 		return EINVAL;
    684  1.63   mlelstv 
    685   1.1  macallan 	error = copyin(cm->red, &rbuf[index], count);
    686   1.1  macallan 	if (error)
    687   1.1  macallan 		return error;
    688   1.1  macallan 	error = copyin(cm->green, &gbuf[index], count);
    689   1.1  macallan 	if (error)
    690   1.1  macallan 		return error;
    691   1.1  macallan 	error = copyin(cm->blue, &bbuf[index], count);
    692   1.1  macallan 	if (error)
    693   1.1  macallan 		return error;
    694   1.1  macallan 
    695   1.1  macallan 	memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
    696   1.1  macallan 	memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
    697   1.1  macallan 	memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
    698   1.1  macallan 
    699   1.1  macallan 	r = &sc->sc_cmap_red[index];
    700   1.1  macallan 	g = &sc->sc_cmap_green[index];
    701   1.1  macallan 	b = &sc->sc_cmap_blue[index];
    702   1.1  macallan 
    703   1.1  macallan 	for (i = 0; i < count; i++) {
    704   1.1  macallan 		genfb_putpalreg(sc, index, *r, *g, *b);
    705   1.1  macallan 		index++;
    706   1.1  macallan 		r++, g++, b++;
    707   1.1  macallan 	}
    708   1.1  macallan 	return 0;
    709   1.1  macallan }
    710   1.1  macallan 
    711   1.1  macallan static int
    712   1.1  macallan genfb_getcmap(struct genfb_softc *sc, struct wsdisplay_cmap *cm)
    713   1.1  macallan {
    714   1.1  macallan 	u_int index = cm->index;
    715   1.1  macallan 	u_int count = cm->count;
    716   1.1  macallan 	int error;
    717   1.1  macallan 
    718  1.63   mlelstv 	if (index >= 256 || count > 256 || index + count > 256)
    719   1.1  macallan 		return EINVAL;
    720   1.1  macallan 
    721   1.1  macallan 	error = copyout(&sc->sc_cmap_red[index],   cm->red,   count);
    722   1.1  macallan 	if (error)
    723   1.1  macallan 		return error;
    724   1.1  macallan 	error = copyout(&sc->sc_cmap_green[index], cm->green, count);
    725   1.1  macallan 	if (error)
    726   1.1  macallan 		return error;
    727   1.1  macallan 	error = copyout(&sc->sc_cmap_blue[index],  cm->blue,  count);
    728   1.1  macallan 	if (error)
    729   1.1  macallan 		return error;
    730   1.1  macallan 
    731   1.1  macallan 	return 0;
    732   1.1  macallan }
    733   1.1  macallan 
    734  1.28  jmcneill void
    735   1.1  macallan genfb_restore_palette(struct genfb_softc *sc)
    736   1.1  macallan {
    737   1.1  macallan 	int i;
    738   1.1  macallan 
    739  1.27  macallan 	if (sc->sc_depth <= 8) {
    740  1.27  macallan 		for (i = 0; i < (1 << sc->sc_depth); i++) {
    741  1.27  macallan 			genfb_putpalreg(sc, i, sc->sc_cmap_red[i],
    742  1.27  macallan 			    sc->sc_cmap_green[i], sc->sc_cmap_blue[i]);
    743  1.27  macallan 		}
    744   1.1  macallan 	}
    745   1.1  macallan }
    746   1.1  macallan 
    747  1.45  macallan static void
    748  1.45  macallan genfb_init_palette(struct genfb_softc *sc)
    749  1.45  macallan {
    750  1.45  macallan 	int i, j, tmp;
    751  1.45  macallan 
    752  1.45  macallan 	if (sc->sc_depth == 8) {
    753  1.45  macallan 		/* generate an r3g3b2 colour map */
    754  1.45  macallan 		for (i = 0; i < 256; i++) {
    755  1.45  macallan 			tmp = i & 0xe0;
    756  1.45  macallan 			/*
    757  1.45  macallan 			 * replicate bits so 0xe0 maps to a red value of 0xff
    758  1.45  macallan 			 * in order to make white look actually white
    759  1.45  macallan 			 */
    760  1.45  macallan 			tmp |= (tmp >> 3) | (tmp >> 6);
    761  1.45  macallan 			sc->sc_cmap_red[i] = tmp;
    762  1.45  macallan 
    763  1.45  macallan 			tmp = (i & 0x1c) << 3;
    764  1.45  macallan 			tmp |= (tmp >> 3) | (tmp >> 6);
    765  1.45  macallan 			sc->sc_cmap_green[i] = tmp;
    766  1.45  macallan 
    767  1.45  macallan 			tmp = (i & 0x03) << 6;
    768  1.45  macallan 			tmp |= tmp >> 2;
    769  1.45  macallan 			tmp |= tmp >> 4;
    770  1.45  macallan 			sc->sc_cmap_blue[i] = tmp;
    771  1.45  macallan 
    772  1.45  macallan 			genfb_putpalreg(sc, i, sc->sc_cmap_red[i],
    773  1.45  macallan 				       sc->sc_cmap_green[i],
    774  1.45  macallan 				       sc->sc_cmap_blue[i]);
    775  1.45  macallan 		}
    776  1.45  macallan 	} else {
    777  1.45  macallan 		/* steal rasops' ANSI cmap */
    778  1.45  macallan 		j = 0;
    779  1.45  macallan 		for (i = 0; i < 256; i++) {
    780  1.45  macallan 			sc->sc_cmap_red[i] = rasops_cmap[j];
    781  1.45  macallan 			sc->sc_cmap_green[i] = rasops_cmap[j + 1];
    782  1.45  macallan 			sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
    783  1.45  macallan 			j += 3;
    784  1.45  macallan 		}
    785  1.45  macallan 	}
    786  1.45  macallan }
    787  1.45  macallan 
    788   1.1  macallan static int
    789   1.1  macallan genfb_putpalreg(struct genfb_softc *sc, uint8_t idx, uint8_t r, uint8_t g,
    790   1.1  macallan     uint8_t b)
    791   1.1  macallan {
    792   1.1  macallan 
    793   1.4  macallan 	if (sc->sc_cmcb) {
    794   1.4  macallan 
    795   1.4  macallan 		sc->sc_cmcb->gcc_set_mapreg(sc->sc_cmcb->gcc_cookie,
    796   1.4  macallan 		    idx, r, g, b);
    797   1.4  macallan 	}
    798   1.1  macallan 	return 0;
    799   1.1  macallan }
    800   1.1  macallan 
    801  1.18  jmcneill void
    802  1.18  jmcneill genfb_cnattach(void)
    803  1.18  jmcneill {
    804  1.18  jmcneill 	genfb_cnattach_called = 1;
    805  1.18  jmcneill }
    806  1.18  jmcneill 
    807  1.20  jmcneill void
    808  1.20  jmcneill genfb_disable(void)
    809  1.20  jmcneill {
    810  1.20  jmcneill 	genfb_enabled = 0;
    811  1.20  jmcneill }
    812  1.20  jmcneill 
    813  1.18  jmcneill int
    814  1.18  jmcneill genfb_is_console(void)
    815  1.18  jmcneill {
    816  1.18  jmcneill 	return genfb_cnattach_called;
    817  1.18  jmcneill }
    818  1.19  jmcneill 
    819  1.19  jmcneill int
    820  1.20  jmcneill genfb_is_enabled(void)
    821  1.20  jmcneill {
    822  1.20  jmcneill 	return genfb_enabled;
    823  1.20  jmcneill }
    824  1.20  jmcneill 
    825  1.20  jmcneill int
    826  1.19  jmcneill genfb_borrow(bus_addr_t addr, bus_space_handle_t *hdlp)
    827  1.19  jmcneill {
    828  1.19  jmcneill 	struct genfb_softc *sc = genfb_softc;
    829  1.19  jmcneill 
    830  1.19  jmcneill 	if (sc && sc->sc_ops.genfb_borrow)
    831  1.19  jmcneill 		return sc->sc_ops.genfb_borrow(sc, addr, hdlp);
    832  1.19  jmcneill 	return 0;
    833  1.19  jmcneill }
    834  1.31  macallan 
    835  1.31  macallan static void
    836  1.31  macallan genfb_brightness_up(device_t dev)
    837  1.31  macallan {
    838  1.31  macallan 	struct genfb_softc *sc = device_private(dev);
    839  1.31  macallan 
    840  1.42  macallan 	KASSERT(sc->sc_brightness != NULL &&
    841  1.42  macallan 		sc->sc_brightness->gpc_upd_parameter != NULL);
    842  1.42  macallan 
    843  1.42  macallan 	(void)sc->sc_brightness->gpc_upd_parameter(
    844  1.42  macallan 	    sc->sc_brightness->gpc_cookie, GENFB_BRIGHTNESS_STEP);
    845  1.31  macallan }
    846  1.31  macallan 
    847  1.31  macallan static void
    848  1.31  macallan genfb_brightness_down(device_t dev)
    849  1.31  macallan {
    850  1.31  macallan 	struct genfb_softc *sc = device_private(dev);
    851  1.31  macallan 
    852  1.42  macallan 	KASSERT(sc->sc_brightness != NULL &&
    853  1.42  macallan 		sc->sc_brightness->gpc_upd_parameter != NULL);
    854  1.42  macallan 
    855  1.42  macallan 	(void)sc->sc_brightness->gpc_upd_parameter(
    856  1.42  macallan 	    sc->sc_brightness->gpc_cookie, - GENFB_BRIGHTNESS_STEP);
    857  1.31  macallan }
    858  1.35  jmcneill 
    859  1.35  jmcneill void
    860  1.35  jmcneill genfb_enable_polling(device_t dev)
    861  1.35  jmcneill {
    862  1.35  jmcneill 	struct genfb_softc *sc = device_private(dev);
    863  1.35  jmcneill 
    864  1.38  jmcneill 	if (sc->sc_console_screen.scr_vd) {
    865  1.38  jmcneill 		SCREEN_ENABLE_DRAWING(&sc->sc_console_screen);
    866  1.38  jmcneill 		vcons_hard_switch(&sc->sc_console_screen);
    867  1.38  jmcneill 		vcons_enable_polling(&sc->vd);
    868  1.55  riastrad 		if (sc->sc_ops.genfb_enable_polling)
    869  1.55  riastrad 			(*sc->sc_ops.genfb_enable_polling)(sc);
    870  1.38  jmcneill 	}
    871  1.35  jmcneill }
    872  1.35  jmcneill 
    873  1.35  jmcneill void
    874  1.35  jmcneill genfb_disable_polling(device_t dev)
    875  1.35  jmcneill {
    876  1.35  jmcneill 	struct genfb_softc *sc = device_private(dev);
    877  1.35  jmcneill 
    878  1.38  jmcneill 	if (sc->sc_console_screen.scr_vd) {
    879  1.55  riastrad 		if (sc->sc_ops.genfb_disable_polling)
    880  1.55  riastrad 			(*sc->sc_ops.genfb_disable_polling)(sc);
    881  1.38  jmcneill 		vcons_disable_polling(&sc->vd);
    882  1.38  jmcneill 	}
    883  1.35  jmcneill }
    884