Home | History | Annotate | Line # | Download | only in wsfb
genfb.c revision 1.4.8.3
      1  1.4.8.3     joerg /*	$NetBSD: genfb.c,v 1.4.8.3 2007/11/06 19:25:23 joerg 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  * 3. Neither the name of The NetBSD Foundation nor the names of its
     16      1.1  macallan  *    contributors may be used to endorse or promote products derived
     17      1.1  macallan  *    from this software without specific prior written permission.
     18      1.1  macallan  *
     19      1.1  macallan  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20      1.1  macallan  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21      1.1  macallan  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22      1.1  macallan  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23      1.1  macallan  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24      1.1  macallan  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25      1.1  macallan  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26      1.1  macallan  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27      1.1  macallan  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28      1.1  macallan  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29      1.1  macallan  * POSSIBILITY OF SUCH DAMAGE.
     30      1.1  macallan  */
     31      1.1  macallan 
     32      1.1  macallan #include <sys/cdefs.h>
     33  1.4.8.3     joerg __KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.4.8.3 2007/11/06 19:25:23 joerg Exp $");
     34      1.1  macallan 
     35      1.1  macallan #include <sys/param.h>
     36      1.1  macallan #include <sys/systm.h>
     37      1.1  macallan #include <sys/kernel.h>
     38      1.1  macallan #include <sys/device.h>
     39      1.1  macallan #include <sys/proc.h>
     40      1.1  macallan #include <sys/mutex.h>
     41      1.1  macallan #include <sys/ioctl.h>
     42      1.1  macallan #include <sys/kernel.h>
     43      1.1  macallan #include <sys/systm.h>
     44  1.4.8.1  jmcneill #include <sys/malloc.h>
     45      1.1  macallan 
     46      1.1  macallan #include <dev/wscons/wsconsio.h>
     47      1.1  macallan #include <dev/wscons/wsdisplayvar.h>
     48      1.1  macallan #include <dev/rasops/rasops.h>
     49      1.1  macallan #include <dev/wsfont/wsfont.h>
     50      1.1  macallan 
     51      1.1  macallan #include <dev/wscons/wsdisplay_vconsvar.h>
     52      1.1  macallan 
     53      1.1  macallan #include <dev/wsfb/genfbvar.h>
     54      1.1  macallan 
     55      1.1  macallan #include "opt_genfb.h"
     56      1.1  macallan #include "opt_wsfb.h"
     57      1.1  macallan 
     58  1.4.8.3     joerg #ifdef GENFB_DEBUG
     59  1.4.8.3     joerg #define GPRINTF panic
     60  1.4.8.3     joerg #else
     61  1.4.8.3     joerg #define GPRINTF aprint_verbose
     62  1.4.8.3     joerg #endif
     63  1.4.8.3     joerg 
     64      1.1  macallan static int	genfb_ioctl(void *, void *, u_long, void *, int, struct lwp *);
     65      1.1  macallan static paddr_t	genfb_mmap(void *, void *, off_t, int);
     66      1.1  macallan static void	genfb_init_screen(void *, struct vcons_screen *, int, long *);
     67      1.1  macallan 
     68      1.1  macallan static int	genfb_putcmap(struct genfb_softc *, struct wsdisplay_cmap *);
     69      1.1  macallan static int 	genfb_getcmap(struct genfb_softc *, struct wsdisplay_cmap *);
     70      1.1  macallan static void	genfb_restore_palette(struct genfb_softc *);
     71      1.1  macallan static int 	genfb_putpalreg(struct genfb_softc *, uint8_t, uint8_t,
     72      1.1  macallan 			    uint8_t, uint8_t);
     73      1.1  macallan 
     74      1.1  macallan extern const u_char rasops_cmap[768];
     75      1.1  macallan 
     76      1.1  macallan struct wsdisplay_accessops genfb_accessops = {
     77      1.1  macallan 	genfb_ioctl,
     78      1.1  macallan 	genfb_mmap,
     79      1.3  macallan 	NULL,	/* alloc_screen */
     80      1.3  macallan 	NULL,	/* free_screen */
     81      1.3  macallan 	NULL,	/* show_screen */
     82      1.3  macallan 	NULL, 	/* load_font */
     83      1.3  macallan 	NULL,	/* pollc */
     84      1.3  macallan 	NULL	/* scroll */
     85      1.1  macallan };
     86      1.1  macallan 
     87      1.2  macallan void
     88      1.2  macallan genfb_init(struct genfb_softc *sc)
     89      1.2  macallan {
     90      1.2  macallan 	prop_dictionary_t dict;
     91      1.4  macallan 	uint64_t cmap_cb;
     92      1.2  macallan 	uint32_t fboffset;
     93      1.2  macallan 
     94      1.2  macallan 	dict = device_properties(&sc->sc_dev);
     95      1.2  macallan #ifdef GENFB_DEBUG
     96      1.2  macallan 	printf(prop_dictionary_externalize(dict));
     97      1.2  macallan #endif
     98  1.4.8.3     joerg 	if (!prop_dictionary_get_uint32(dict, "width", &sc->sc_width)) {
     99  1.4.8.3     joerg 		GPRINTF("no width property");
    100  1.4.8.3     joerg 		return;
    101  1.4.8.3     joerg 	}
    102  1.4.8.3     joerg 	if (!prop_dictionary_get_uint32(dict, "height", &sc->sc_height)) {
    103  1.4.8.3     joerg 		GPRINTF("no height property");
    104  1.4.8.3     joerg 		return;
    105  1.4.8.3     joerg 	}
    106  1.4.8.3     joerg 	if (!prop_dictionary_get_uint32(dict, "depth", &sc->sc_depth)) {
    107  1.4.8.3     joerg 		GPRINTF("no depth property");
    108  1.4.8.3     joerg 		return;
    109  1.4.8.3     joerg 	}
    110      1.2  macallan 
    111      1.2  macallan 	/* XXX should be a 64bit value */
    112  1.4.8.3     joerg 	if (!prop_dictionary_get_uint32(dict, "address", &fboffset)) {
    113  1.4.8.3     joerg 		GPRINTF("no address property");
    114  1.4.8.3     joerg 		return;
    115  1.4.8.3     joerg 	}
    116  1.4.8.3     joerg 
    117      1.2  macallan 	sc->sc_fboffset = fboffset;
    118      1.2  macallan 
    119      1.2  macallan 	if (!prop_dictionary_get_uint32(dict, "linebytes", &sc->sc_stride))
    120      1.2  macallan 		sc->sc_stride = (sc->sc_width * sc->sc_depth) >> 3;
    121  1.4.8.1  jmcneill 	sc->sc_fbsize = sc->sc_height * sc->sc_stride;
    122      1.4  macallan 
    123      1.4  macallan 	/* optional colour map callback */
    124      1.4  macallan 	sc->sc_cmcb = NULL;
    125      1.4  macallan 	if (prop_dictionary_get_uint64(dict, "cmap_callback", &cmap_cb)) {
    126      1.4  macallan 		if (cmap_cb != 0)
    127      1.4  macallan 			sc->sc_cmcb = (void *)(vaddr_t)cmap_cb;
    128      1.4  macallan 	}
    129      1.2  macallan }
    130      1.2  macallan 
    131      1.2  macallan int
    132      1.2  macallan genfb_attach(struct genfb_softc *sc, struct genfb_ops *ops)
    133      1.1  macallan {
    134      1.1  macallan 	struct wsemuldisplaydev_attach_args aa;
    135      1.1  macallan 	prop_dictionary_t dict;
    136      1.1  macallan 	struct rasops_info *ri;
    137      1.1  macallan 	long defattr;
    138  1.4.8.2  jmcneill 	int i, j;
    139  1.4.8.2  jmcneill 	bool console;
    140  1.4.8.2  jmcneill 
    141  1.4.8.2  jmcneill 	aprint_verbose("%s: framebuffer at %p, size %dx%d, depth %d, "
    142  1.4.8.2  jmcneill 	    "stride %d\n", sc->sc_dev.dv_xname, sc->sc_fbaddr,
    143  1.4.8.2  jmcneill 	    sc->sc_width, sc->sc_height, sc->sc_depth, sc->sc_stride);
    144  1.4.8.2  jmcneill 
    145      1.1  macallan 	sc->sc_defaultscreen_descr = (struct wsscreen_descr){
    146      1.1  macallan 		"default",
    147      1.1  macallan 		0, 0,
    148      1.1  macallan 		NULL,
    149      1.1  macallan 		8, 16,
    150      1.1  macallan 		WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
    151      1.3  macallan 		NULL
    152      1.1  macallan 	};
    153      1.1  macallan 	sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
    154      1.1  macallan 	sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
    155      1.1  macallan 	memcpy(&sc->sc_ops, ops, sizeof(struct genfb_ops));
    156      1.1  macallan 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
    157      1.1  macallan 
    158  1.4.8.1  jmcneill 	sc->sc_shadowfb = malloc(sc->sc_fbsize, M_DEVBUF, M_WAITOK);
    159  1.4.8.1  jmcneill 
    160      1.1  macallan 	dict = device_properties(&sc->sc_dev);
    161      1.1  macallan 
    162      1.1  macallan 	prop_dictionary_get_bool(dict, "is_console", &console);
    163      1.1  macallan 
    164      1.1  macallan 	vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
    165      1.1  macallan 	    &genfb_accessops);
    166      1.1  macallan 	sc->vd.init_screen = genfb_init_screen;
    167      1.1  macallan 
    168  1.4.8.2  jmcneill 	/* Do not print anything between this point and the screen
    169  1.4.8.2  jmcneill 	 * clear operation below.  Otherwise it will be lost. */
    170  1.4.8.2  jmcneill 
    171      1.1  macallan 	ri = &sc->sc_console_screen.scr_ri;
    172      1.1  macallan 
    173      1.1  macallan 	if (console) {
    174      1.1  macallan 		vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
    175      1.1  macallan 		    &defattr);
    176      1.1  macallan 		sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    177      1.1  macallan 
    178      1.1  macallan 		sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
    179      1.1  macallan 		sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
    180      1.1  macallan 		sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
    181      1.1  macallan 		sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
    182      1.1  macallan 		wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
    183      1.1  macallan 		    defattr);
    184      1.1  macallan 	} else {
    185      1.1  macallan 		/*
    186      1.1  macallan 		 * since we're not the console we can postpone the rest
    187      1.1  macallan 		 * until someone actually allocates a screen for us
    188      1.1  macallan 		 */
    189  1.4.8.2  jmcneill 		(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
    190      1.1  macallan 	}
    191      1.1  macallan 
    192  1.4.8.2  jmcneill 	/* Clear the whole screen to bring it to a known state. */
    193  1.4.8.2  jmcneill 	(*ri->ri_ops.eraserows)(ri, 0, ri->ri_rows, defattr);
    194  1.4.8.2  jmcneill 
    195      1.1  macallan 	j = 0;
    196  1.4.8.2  jmcneill 	for (i = 0; i < (1 << sc->sc_depth); i++) {
    197      1.4  macallan 
    198      1.4  macallan 		sc->sc_cmap_red[i] = rasops_cmap[j];
    199      1.4  macallan 		sc->sc_cmap_green[i] = rasops_cmap[j + 1];
    200      1.4  macallan 		sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
    201      1.1  macallan 		genfb_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
    202      1.1  macallan 		    rasops_cmap[j + 2]);
    203      1.1  macallan 		j += 3;
    204      1.1  macallan 	}
    205      1.1  macallan 
    206      1.1  macallan 	aa.console = console;
    207      1.1  macallan 	aa.scrdata = &sc->sc_screenlist;
    208      1.1  macallan 	aa.accessops = &genfb_accessops;
    209      1.1  macallan 	aa.accesscookie = &sc->vd;
    210      1.1  macallan 
    211      1.1  macallan 	config_found(&sc->sc_dev, &aa, wsemuldisplaydevprint);
    212      1.1  macallan 
    213      1.1  macallan 	return 0;
    214      1.1  macallan }
    215      1.1  macallan 
    216      1.1  macallan static int
    217      1.1  macallan genfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    218      1.1  macallan 	struct lwp *l)
    219      1.1  macallan {
    220      1.1  macallan 	struct vcons_data *vd = v;
    221      1.1  macallan 	struct genfb_softc *sc = vd->cookie;
    222      1.1  macallan 	struct wsdisplay_fbinfo *wdf;
    223      1.1  macallan 	struct vcons_screen *ms = vd->active;
    224      1.1  macallan 
    225      1.1  macallan 	switch (cmd) {
    226      1.1  macallan 
    227      1.1  macallan 		case WSDISPLAYIO_GINFO:
    228  1.4.8.1  jmcneill 			if (ms == NULL)
    229  1.4.8.1  jmcneill 				return ENODEV;
    230      1.1  macallan 			wdf = (void *)data;
    231      1.1  macallan 			wdf->height = ms->scr_ri.ri_height;
    232      1.1  macallan 			wdf->width = ms->scr_ri.ri_width;
    233      1.1  macallan 			wdf->depth = ms->scr_ri.ri_depth;
    234      1.1  macallan 			wdf->cmsize = 256;
    235      1.1  macallan 			return 0;
    236      1.1  macallan 
    237      1.1  macallan 		case WSDISPLAYIO_GETCMAP:
    238      1.1  macallan 			return genfb_getcmap(sc,
    239      1.1  macallan 			    (struct wsdisplay_cmap *)data);
    240      1.1  macallan 
    241      1.1  macallan 		case WSDISPLAYIO_PUTCMAP:
    242      1.1  macallan 			return genfb_putcmap(sc,
    243      1.1  macallan 			    (struct wsdisplay_cmap *)data);
    244      1.1  macallan 
    245      1.3  macallan 		case WSDISPLAYIO_LINEBYTES:
    246      1.3  macallan 			*(u_int *)data = sc->sc_stride;
    247      1.3  macallan 			return 0;
    248      1.3  macallan 
    249      1.1  macallan 		case WSDISPLAYIO_SMODE:
    250      1.1  macallan 			{
    251      1.1  macallan 				int new_mode = *(int*)data;
    252  1.4.8.3     joerg 
    253  1.4.8.3     joerg 				/* notify the bus backend */
    254  1.4.8.3     joerg 				if (sc->sc_ops.genfb_ioctl)
    255  1.4.8.3     joerg 					return sc->sc_ops.genfb_ioctl(sc, vs,
    256  1.4.8.3     joerg 					    cmd, data, flag, l);
    257  1.4.8.3     joerg 
    258      1.1  macallan 				if (new_mode != sc->sc_mode) {
    259      1.1  macallan 					sc->sc_mode = new_mode;
    260      1.1  macallan 					if(new_mode == WSDISPLAYIO_MODE_EMUL) {
    261      1.1  macallan 						genfb_restore_palette(sc);
    262      1.1  macallan 						vcons_redraw_screen(ms);
    263      1.1  macallan 					}
    264      1.1  macallan 				}
    265      1.1  macallan 			}
    266      1.1  macallan 			return 0;
    267      1.1  macallan 		default:
    268      1.1  macallan 			if (sc->sc_ops.genfb_ioctl)
    269      1.1  macallan 				return sc->sc_ops.genfb_ioctl(sc, vs, cmd,
    270      1.1  macallan 				    data, flag, l);
    271      1.1  macallan 	}
    272      1.1  macallan 	return EPASSTHROUGH;
    273      1.1  macallan }
    274      1.1  macallan 
    275      1.1  macallan static paddr_t
    276      1.1  macallan genfb_mmap(void *v, void *vs, off_t offset, int prot)
    277      1.1  macallan {
    278      1.1  macallan 	struct vcons_data *vd = v;
    279      1.1  macallan 	struct genfb_softc *sc = vd->cookie;
    280      1.1  macallan 
    281      1.1  macallan 	if (sc->sc_ops.genfb_mmap)
    282      1.1  macallan 		return sc->sc_ops.genfb_mmap(sc, vs, offset, prot);
    283      1.1  macallan 
    284      1.1  macallan 	return -1;
    285      1.1  macallan }
    286      1.1  macallan 
    287      1.1  macallan static void
    288      1.1  macallan genfb_init_screen(void *cookie, struct vcons_screen *scr,
    289      1.1  macallan     int existing, long *defattr)
    290      1.1  macallan {
    291      1.1  macallan 	struct genfb_softc *sc = cookie;
    292      1.1  macallan 	struct rasops_info *ri = &scr->scr_ri;
    293      1.1  macallan 
    294      1.1  macallan 	ri->ri_depth = sc->sc_depth;
    295      1.1  macallan 	ri->ri_width = sc->sc_width;
    296      1.1  macallan 	ri->ri_height = sc->sc_height;
    297      1.1  macallan 	ri->ri_stride = sc->sc_stride;
    298      1.1  macallan 	ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
    299      1.1  macallan 
    300  1.4.8.1  jmcneill 	if (sc->sc_shadowfb != NULL) {
    301  1.4.8.1  jmcneill 
    302  1.4.8.1  jmcneill 		ri->ri_hwbits = (char *)sc->sc_fbaddr;
    303  1.4.8.1  jmcneill 		ri->ri_bits = (char *)sc->sc_shadowfb;
    304  1.4.8.1  jmcneill 	} else
    305  1.4.8.1  jmcneill 		ri->ri_bits = (char *)sc->sc_fbaddr;
    306      1.1  macallan 
    307      1.1  macallan 	if (existing) {
    308      1.1  macallan 		ri->ri_flg |= RI_CLEAR;
    309      1.1  macallan 	}
    310      1.1  macallan 
    311      1.1  macallan 	rasops_init(ri, sc->sc_height / 8, sc->sc_width / 8);
    312      1.1  macallan 	ri->ri_caps = WSSCREEN_WSCOLORS;
    313      1.1  macallan 
    314      1.1  macallan 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
    315      1.1  macallan 		    sc->sc_width / ri->ri_font->fontwidth);
    316      1.1  macallan 
    317      1.1  macallan 	ri->ri_hw = scr;
    318      1.1  macallan }
    319      1.1  macallan 
    320      1.1  macallan static int
    321      1.1  macallan genfb_putcmap(struct genfb_softc *sc, struct wsdisplay_cmap *cm)
    322      1.1  macallan {
    323      1.1  macallan 	u_char *r, *g, *b;
    324      1.1  macallan 	u_int index = cm->index;
    325      1.1  macallan 	u_int count = cm->count;
    326      1.1  macallan 	int i, error;
    327      1.1  macallan 	u_char rbuf[256], gbuf[256], bbuf[256];
    328      1.1  macallan 
    329      1.1  macallan #ifdef GENFB_DEBUG
    330      1.1  macallan 	aprint_debug("putcmap: %d %d\n",index, count);
    331      1.1  macallan #endif
    332      1.1  macallan 	if (cm->index >= 256 || cm->count > 256 ||
    333      1.1  macallan 	    (cm->index + cm->count) > 256)
    334      1.1  macallan 		return EINVAL;
    335      1.1  macallan 	error = copyin(cm->red, &rbuf[index], count);
    336      1.1  macallan 	if (error)
    337      1.1  macallan 		return error;
    338      1.1  macallan 	error = copyin(cm->green, &gbuf[index], count);
    339      1.1  macallan 	if (error)
    340      1.1  macallan 		return error;
    341      1.1  macallan 	error = copyin(cm->blue, &bbuf[index], count);
    342      1.1  macallan 	if (error)
    343      1.1  macallan 		return error;
    344      1.1  macallan 
    345      1.1  macallan 	memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
    346      1.1  macallan 	memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
    347      1.1  macallan 	memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
    348      1.1  macallan 
    349      1.1  macallan 	r = &sc->sc_cmap_red[index];
    350      1.1  macallan 	g = &sc->sc_cmap_green[index];
    351      1.1  macallan 	b = &sc->sc_cmap_blue[index];
    352      1.1  macallan 
    353      1.1  macallan 	for (i = 0; i < count; i++) {
    354      1.1  macallan 		genfb_putpalreg(sc, index, *r, *g, *b);
    355      1.1  macallan 		index++;
    356      1.1  macallan 		r++, g++, b++;
    357      1.1  macallan 	}
    358      1.1  macallan 	return 0;
    359      1.1  macallan }
    360      1.1  macallan 
    361      1.1  macallan static int
    362      1.1  macallan genfb_getcmap(struct genfb_softc *sc, struct wsdisplay_cmap *cm)
    363      1.1  macallan {
    364      1.1  macallan 	u_int index = cm->index;
    365      1.1  macallan 	u_int count = cm->count;
    366      1.1  macallan 	int error;
    367      1.1  macallan 
    368      1.1  macallan 	if (index >= 255 || count > 256 || index + count > 256)
    369      1.1  macallan 		return EINVAL;
    370      1.1  macallan 
    371      1.1  macallan 	error = copyout(&sc->sc_cmap_red[index],   cm->red,   count);
    372      1.1  macallan 	if (error)
    373      1.1  macallan 		return error;
    374      1.1  macallan 	error = copyout(&sc->sc_cmap_green[index], cm->green, count);
    375      1.1  macallan 	if (error)
    376      1.1  macallan 		return error;
    377      1.1  macallan 	error = copyout(&sc->sc_cmap_blue[index],  cm->blue,  count);
    378      1.1  macallan 	if (error)
    379      1.1  macallan 		return error;
    380      1.1  macallan 
    381      1.1  macallan 	return 0;
    382      1.1  macallan }
    383      1.1  macallan 
    384      1.1  macallan static void
    385      1.1  macallan genfb_restore_palette(struct genfb_softc *sc)
    386      1.1  macallan {
    387      1.1  macallan 	int i;
    388      1.1  macallan 
    389  1.4.8.2  jmcneill 	for (i = 0; i < (1 << sc->sc_depth); i++) {
    390      1.1  macallan 		genfb_putpalreg(sc, i, sc->sc_cmap_red[i],
    391      1.1  macallan 		    sc->sc_cmap_green[i], sc->sc_cmap_blue[i]);
    392      1.1  macallan 	}
    393      1.1  macallan }
    394      1.1  macallan 
    395      1.1  macallan static int
    396      1.1  macallan genfb_putpalreg(struct genfb_softc *sc, uint8_t idx, uint8_t r, uint8_t g,
    397      1.1  macallan     uint8_t b)
    398      1.1  macallan {
    399      1.1  macallan 
    400      1.4  macallan 	if (sc->sc_cmcb) {
    401      1.4  macallan 
    402      1.4  macallan 		sc->sc_cmcb->gcc_set_mapreg(sc->sc_cmcb->gcc_cookie,
    403      1.4  macallan 		    idx, r, g, b);
    404      1.4  macallan 	}
    405      1.1  macallan 	return 0;
    406      1.1  macallan }
    407      1.1  macallan 
    408