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