Home | History | Annotate | Line # | Download | only in apbus
xafb.c revision 1.19
      1  1.19   thorpej /*	$NetBSD: xafb.c,v 1.19 2020/11/21 17:54:47 thorpej Exp $	*/
      2   1.1    tsubai 
      3   1.1    tsubai /*-
      4   1.1    tsubai  * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
      5   1.1    tsubai  *
      6   1.1    tsubai  * Redistribution and use in source and binary forms, with or without
      7   1.1    tsubai  * modification, are permitted provided that the following conditions
      8   1.1    tsubai  * are met:
      9   1.1    tsubai  * 1. Redistributions of source code must retain the above copyright
     10   1.1    tsubai  *    notice, this list of conditions and the following disclaimer.
     11   1.1    tsubai  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1    tsubai  *    notice, this list of conditions and the following disclaimer in the
     13   1.1    tsubai  *    documentation and/or other materials provided with the distribution.
     14   1.1    tsubai  * 3. The name of the author may not be used to endorse or promote products
     15   1.1    tsubai  *    derived from this software without specific prior written permission.
     16   1.1    tsubai  *
     17   1.1    tsubai  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18   1.1    tsubai  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19   1.1    tsubai  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20   1.1    tsubai  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21   1.1    tsubai  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22   1.1    tsubai  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23   1.1    tsubai  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24   1.1    tsubai  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25   1.1    tsubai  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26   1.1    tsubai  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27   1.1    tsubai  */
     28   1.1    tsubai 
     29   1.1    tsubai /* "xa" frame buffer driver.  Currently supports 1280x1024x8 only. */
     30   1.6     lukem 
     31   1.6     lukem #include <sys/cdefs.h>
     32  1.19   thorpej __KERNEL_RCSID(0, "$NetBSD: xafb.c,v 1.19 2020/11/21 17:54:47 thorpej Exp $");
     33   1.1    tsubai 
     34   1.1    tsubai #include <sys/param.h>
     35   1.1    tsubai #include <sys/buf.h>
     36   1.1    tsubai #include <sys/device.h>
     37   1.1    tsubai #include <sys/ioctl.h>
     38  1.19   thorpej #include <sys/kmem.h>
     39   1.1    tsubai #include <sys/systm.h>
     40   1.1    tsubai 
     41   1.1    tsubai #include <uvm/uvm_extern.h>
     42   1.1    tsubai 
     43  1.18  christos #include <mips/locore.h>
     44  1.18  christos 
     45   1.1    tsubai #include <machine/adrsmap.h>
     46   1.1    tsubai #include <machine/apcall.h>
     47  1.18  christos #include <machine/wsconsio.h>
     48   1.1    tsubai 
     49   1.1    tsubai #include <dev/wscons/wsdisplayvar.h>
     50   1.1    tsubai #include <dev/rasops/rasops.h>
     51   1.1    tsubai 
     52   1.1    tsubai #include <newsmips/apbus/apbusvar.h>
     53   1.1    tsubai 
     54   1.1    tsubai struct xafb_reg {
     55  1.15   tsutsui 	volatile uint32_t r0;
     56  1.15   tsutsui 	volatile uint32_t index;
     57  1.15   tsutsui 	volatile uint32_t r2;
     58  1.15   tsutsui 	volatile uint32_t zero;
     59  1.15   tsutsui 	volatile uint32_t r4;
     60  1.15   tsutsui 	volatile uint32_t r5;
     61  1.15   tsutsui 	volatile uint32_t r6;
     62  1.15   tsutsui 	volatile uint32_t rgb;
     63   1.1    tsubai };
     64   1.1    tsubai 
     65   1.1    tsubai struct xafb_devconfig {
     66  1.15   tsutsui 	uint8_t *dc_fbbase;		/* VRAM base address */
     67   1.8       uch 	paddr_t dc_fbpaddr;		/* VRAM physical address */
     68   1.1    tsubai 	struct xafb_reg *dc_reg;	/* register address */
     69   1.1    tsubai 	struct rasops_info dc_ri;
     70   1.1    tsubai };
     71   1.1    tsubai 
     72   1.1    tsubai struct xafb_softc {
     73  1.15   tsutsui 	device_t sc_dev;
     74   1.1    tsubai 	struct xafb_devconfig *sc_dc;
     75   1.1    tsubai 	int sc_nscreens;
     76  1.15   tsutsui 	uint8_t sc_cmap_red[256];
     77  1.15   tsutsui 	uint8_t sc_cmap_green[256];
     78  1.15   tsutsui 	uint8_t sc_cmap_blue[256];
     79   1.1    tsubai };
     80   1.1    tsubai 
     81  1.15   tsutsui int xafb_match(device_t, cfdata_t, void *);
     82  1.15   tsutsui void xafb_attach(device_t, device_t, void *);
     83   1.1    tsubai 
     84   1.9   tsutsui int xafb_common_init(struct xafb_devconfig *);
     85   1.9   tsutsui int xafb_is_console(void);
     86   1.1    tsubai 
     87  1.14  christos int xafb_ioctl(void *, void *, u_long, void *, int, struct lwp *);
     88  1.13      jmmv paddr_t xafb_mmap(void *, void *, off_t, int);
     89   1.9   tsutsui int xafb_alloc_screen(void *, const struct wsscreen_descr *, void **, int *,
     90   1.9   tsutsui     int *, long *);
     91   1.9   tsutsui void xafb_free_screen(void *, void *);
     92   1.9   tsutsui int xafb_show_screen(void *, void *, int, void (*) (void *, int, int), void *);
     93   1.9   tsutsui 
     94   1.9   tsutsui int xafb_cnattach(void);
     95   1.9   tsutsui int xafb_getcmap(struct xafb_softc *, struct wsdisplay_cmap *);
     96   1.9   tsutsui int xafb_putcmap(struct xafb_softc *, struct wsdisplay_cmap *);
     97   1.1    tsubai 
     98  1.12     perry static inline void xafb_setcolor(struct xafb_devconfig *, int, int, int, int);
     99   1.1    tsubai 
    100  1.15   tsutsui CFATTACH_DECL_NEW(xafb, sizeof(struct xafb_softc),
    101   1.5   thorpej     xafb_match, xafb_attach, NULL, NULL);
    102   1.1    tsubai 
    103   1.1    tsubai struct xafb_devconfig xafb_console_dc;
    104   1.1    tsubai 
    105   1.1    tsubai struct wsdisplay_accessops xafb_accessops = {
    106   1.1    tsubai 	xafb_ioctl,
    107   1.1    tsubai 	xafb_mmap,
    108   1.1    tsubai 	xafb_alloc_screen,
    109   1.1    tsubai 	xafb_free_screen,
    110   1.1    tsubai 	xafb_show_screen,
    111   1.1    tsubai 	NULL	/* load_font */
    112   1.1    tsubai };
    113   1.1    tsubai 
    114   1.1    tsubai struct wsscreen_descr xafb_stdscreen = {
    115   1.1    tsubai 	"std",
    116   1.1    tsubai 	0, 0,
    117   1.1    tsubai 	0,
    118   1.1    tsubai 	0, 0,
    119   1.1    tsubai 	WSSCREEN_REVERSE
    120   1.1    tsubai };
    121   1.1    tsubai 
    122   1.1    tsubai const struct wsscreen_descr *xafb_scrlist[] = {
    123   1.1    tsubai 	&xafb_stdscreen
    124   1.1    tsubai };
    125   1.1    tsubai 
    126   1.1    tsubai struct wsscreen_list xafb_screenlist = {
    127  1.15   tsutsui 	__arraycount(xafb_scrlist), xafb_scrlist
    128   1.1    tsubai };
    129   1.1    tsubai 
    130   1.1    tsubai int
    131  1.15   tsutsui xafb_match(device_t parent, cfdata_t cf, void *aux)
    132   1.1    tsubai {
    133   1.1    tsubai 	struct apbus_attach_args *apa = aux;
    134   1.1    tsubai 
    135   1.1    tsubai 	if (strcmp(apa->apa_name, "xa") != 0)
    136   1.1    tsubai 		return 0;
    137   1.1    tsubai 
    138   1.1    tsubai 	return 1;
    139   1.1    tsubai }
    140   1.1    tsubai 
    141   1.1    tsubai void
    142  1.15   tsutsui xafb_attach(device_t parent, device_t self, void *aux)
    143   1.1    tsubai {
    144  1.15   tsutsui 	struct xafb_softc *sc = device_private(self);
    145   1.1    tsubai 	struct apbus_attach_args *apa = aux;
    146   1.1    tsubai 	struct wsemuldisplaydev_attach_args wsa;
    147   1.1    tsubai 	struct xafb_devconfig *dc;
    148   1.1    tsubai 	struct rasops_info *ri;
    149   1.1    tsubai 	int console, i;
    150   1.1    tsubai 
    151  1.15   tsutsui 	sc->sc_dev = self;
    152   1.1    tsubai 	console = xafb_is_console();
    153   1.1    tsubai 
    154   1.1    tsubai 	if (console) {
    155   1.1    tsubai 		dc = &xafb_console_dc;
    156   1.1    tsubai 		ri = &dc->dc_ri;
    157  1.16   tsutsui 		ri->ri_flg &= ~RI_NO_AUTO;
    158   1.1    tsubai 		sc->sc_nscreens = 1;
    159   1.1    tsubai 	} else {
    160  1.19   thorpej 		dc = kmem_zalloc(sizeof(struct xafb_devconfig), KM_SLEEP);
    161   1.8       uch 		dc->dc_fbpaddr = (paddr_t)0x10000000;
    162   1.8       uch 		dc->dc_fbbase = (void *)MIPS_PHYS_TO_KSEG1(dc->dc_fbpaddr);
    163   1.1    tsubai 		dc->dc_reg = (void *)(apa->apa_hwbase + 0x3000);
    164   1.1    tsubai 		if (xafb_common_init(dc) != 0) {
    165  1.15   tsutsui 			aprint_error(": couldn't initialize device\n");
    166   1.1    tsubai 			return;
    167   1.1    tsubai 		}
    168   1.1    tsubai 
    169   1.1    tsubai 		ri = &dc->dc_ri;
    170   1.1    tsubai 
    171   1.1    tsubai 		/* clear screen */
    172   1.1    tsubai 		(*ri->ri_ops.eraserows)(ri, 0, ri->ri_rows, 0);
    173   1.1    tsubai 	}
    174   1.1    tsubai 	sc->sc_dc = dc;
    175   1.1    tsubai 
    176   1.1    tsubai 	for (i = 0; i < 256; i++) {
    177   1.1    tsubai 		sc->sc_cmap_red[i] = i;
    178   1.1    tsubai 		sc->sc_cmap_green[i] = i;
    179   1.1    tsubai 		sc->sc_cmap_blue[i] = i;
    180   1.1    tsubai 	}
    181   1.1    tsubai 
    182  1.15   tsutsui 	aprint_normal(": %d x %d, %dbpp\n",
    183  1.15   tsutsui 	    ri->ri_width, ri->ri_height, ri->ri_depth);
    184   1.1    tsubai 
    185   1.1    tsubai 	wsa.console = console;
    186   1.1    tsubai 	wsa.scrdata = &xafb_screenlist;
    187   1.1    tsubai 	wsa.accessops = &xafb_accessops;
    188   1.1    tsubai 	wsa.accesscookie = sc;
    189   1.1    tsubai 
    190   1.1    tsubai 	config_found(self, &wsa, wsemuldisplaydevprint);
    191   1.1    tsubai }
    192   1.1    tsubai 
    193   1.1    tsubai void
    194   1.9   tsutsui xafb_setcolor(struct xafb_devconfig *dc, int index, int r, int g, int b)
    195   1.1    tsubai {
    196   1.1    tsubai 	volatile struct xafb_reg *reg = dc->dc_reg;
    197   1.1    tsubai 
    198   1.1    tsubai 	reg->index = index;
    199   1.1    tsubai 	reg->zero = 0;
    200   1.1    tsubai 	reg->rgb = r;
    201   1.1    tsubai 	reg->rgb = g;
    202   1.1    tsubai 	reg->rgb = b;
    203   1.1    tsubai }
    204   1.1    tsubai 
    205   1.1    tsubai int
    206   1.9   tsutsui xafb_common_init(struct xafb_devconfig *dc)
    207   1.1    tsubai {
    208   1.1    tsubai 	struct rasops_info *ri = &dc->dc_ri;
    209   1.1    tsubai 	int i;
    210   1.1    tsubai 
    211   1.1    tsubai 	for (i = 0; i < 256; i++)
    212   1.1    tsubai 		xafb_setcolor(dc, i, i, i, i);
    213   1.1    tsubai 
    214   1.1    tsubai 	/* initialize rasops */
    215   1.1    tsubai 	ri->ri_width = 1280;
    216   1.1    tsubai 	ri->ri_height = 1024;
    217   1.1    tsubai 	ri->ri_depth = 8;
    218   1.1    tsubai 	ri->ri_stride = 2048;
    219   1.1    tsubai 	ri->ri_bits = (void *)dc->dc_fbbase;
    220   1.1    tsubai 	ri->ri_flg = RI_FORCEMONO | RI_FULLCLEAR;
    221  1.16   tsutsui 	if (dc == &xafb_console_dc)
    222  1.16   tsutsui 		ri->ri_flg |= RI_NO_AUTO;
    223   1.1    tsubai 
    224   1.1    tsubai 	rasops_init(ri, 44, 100);
    225   1.1    tsubai 
    226   1.1    tsubai 	/* mono */
    227   1.1    tsubai 	ri->ri_devcmap[0] = 0;				/* bg */
    228   1.1    tsubai 	ri->ri_devcmap[1] = 0xffffffff;			/* fg */
    229   1.1    tsubai 
    230   1.1    tsubai 	xafb_stdscreen.nrows = ri->ri_rows;
    231   1.1    tsubai 	xafb_stdscreen.ncols = ri->ri_cols;
    232   1.1    tsubai 	xafb_stdscreen.textops = &ri->ri_ops;
    233   1.1    tsubai 	xafb_stdscreen.capabilities = ri->ri_caps;
    234   1.1    tsubai 
    235   1.1    tsubai 	return 0;
    236   1.1    tsubai }
    237   1.1    tsubai 
    238   1.1    tsubai int
    239   1.9   tsutsui xafb_is_console(void)
    240   1.1    tsubai {
    241  1.15   tsutsui 	volatile uint32_t *dipsw = (void *)NEWS5000_DIP_SWITCH;
    242   1.1    tsubai 
    243   1.1    tsubai 	if (*dipsw & 1)					/* XXX right? */
    244   1.1    tsubai 		return 1;
    245   1.1    tsubai 
    246   1.1    tsubai 	return 0;
    247   1.1    tsubai }
    248   1.1    tsubai 
    249   1.1    tsubai int
    250  1.14  christos xafb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
    251   1.1    tsubai {
    252   1.1    tsubai 	struct xafb_softc *sc = v;
    253   1.1    tsubai 	struct xafb_devconfig *dc = sc->sc_dc;
    254   1.8       uch 	struct newsmips_wsdisplay_fbinfo *nwdf = (void *)data;
    255   1.8       uch 	struct wsdisplay_fbinfo *wdf = (void *)data;
    256   1.1    tsubai 
    257   1.1    tsubai 	switch (cmd) {
    258   1.1    tsubai 	case WSDISPLAYIO_GTYPE:
    259   1.1    tsubai 		*(int *)data = WSDISPLAY_TYPE_UNKNOWN;	/* XXX */
    260   1.1    tsubai 		return 0;
    261   1.1    tsubai 
    262   1.8       uch 	case NEWSMIPS_WSDISPLAYIO_GINFO:
    263   1.8       uch 		nwdf->stride = dc->dc_ri.ri_stride;
    264   1.8       uch 		/* FALLTHROUGH */
    265   1.1    tsubai 	case WSDISPLAYIO_GINFO:
    266   1.1    tsubai 		wdf->height = dc->dc_ri.ri_height;
    267   1.1    tsubai 		wdf->width = dc->dc_ri.ri_width;
    268   1.1    tsubai 		wdf->depth = dc->dc_ri.ri_depth;
    269   1.1    tsubai 		wdf->cmsize = 256;
    270   1.1    tsubai 		return 0;
    271   1.1    tsubai 
    272  1.17   tsutsui 	case WSDISPLAYIO_LINEBYTES:
    273  1.17   tsutsui 		*(u_int *)data = dc->dc_ri.ri_stride;
    274  1.17   tsutsui 		return 0;
    275  1.17   tsutsui 
    276   1.1    tsubai 	case WSDISPLAYIO_GETCMAP:
    277   1.1    tsubai 		return xafb_getcmap(sc, (struct wsdisplay_cmap *)data);
    278   1.1    tsubai 
    279   1.1    tsubai 	case WSDISPLAYIO_PUTCMAP:
    280   1.1    tsubai 		return xafb_putcmap(sc, (struct wsdisplay_cmap *)data);
    281   1.1    tsubai 
    282   1.1    tsubai 	/* case WSDISPLAYIO_SVIDEO: */
    283   1.1    tsubai 	}
    284   1.2    atatat 	return EPASSTHROUGH;
    285   1.1    tsubai }
    286   1.1    tsubai 
    287   1.1    tsubai paddr_t
    288  1.13      jmmv xafb_mmap(void *v, void *vs, off_t offset, int prot)
    289   1.1    tsubai {
    290   1.1    tsubai 	struct xafb_softc *sc = v;
    291   1.1    tsubai 	struct xafb_devconfig *dc = sc->sc_dc;
    292   1.1    tsubai 	struct rasops_info *ri = &dc->dc_ri;
    293   1.1    tsubai 
    294   1.1    tsubai 	if (offset >= (ri->ri_stride * ri->ri_height) || offset < 0)
    295   1.1    tsubai 		return -1;
    296   1.1    tsubai 
    297   1.8       uch 	return mips_btop(dc->dc_fbpaddr + offset);
    298   1.1    tsubai }
    299   1.1    tsubai 
    300   1.1    tsubai int
    301   1.9   tsutsui xafb_alloc_screen(void *v, const struct wsscreen_descr *scrdesc,
    302   1.9   tsutsui     void **cookiep, int *ccolp, int *crowp, long *attrp)
    303   1.1    tsubai {
    304   1.1    tsubai 	struct xafb_softc *sc = v;
    305   1.1    tsubai 	struct rasops_info *ri = &sc->sc_dc->dc_ri;
    306   1.1    tsubai 	long defattr;
    307   1.1    tsubai 
    308   1.1    tsubai 	if (sc->sc_nscreens > 0)
    309   1.1    tsubai 		return ENOMEM;
    310   1.1    tsubai 
    311   1.1    tsubai 	*cookiep = ri;
    312   1.1    tsubai 	*ccolp = *crowp = 0;
    313   1.3  junyoung 	(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
    314   1.1    tsubai 	*attrp = defattr;
    315   1.1    tsubai 	sc->sc_nscreens++;
    316   1.1    tsubai 
    317   1.1    tsubai 	return 0;
    318   1.1    tsubai }
    319   1.1    tsubai 
    320   1.1    tsubai void
    321   1.9   tsutsui xafb_free_screen(void *v, void *cookie)
    322   1.1    tsubai {
    323   1.1    tsubai 	struct xafb_softc *sc = v;
    324   1.1    tsubai 
    325   1.1    tsubai 	if (sc->sc_dc == &xafb_console_dc)
    326   1.1    tsubai 		panic("xafb_free_screen: console");
    327   1.1    tsubai 
    328   1.1    tsubai 	sc->sc_nscreens--;
    329   1.1    tsubai }
    330   1.1    tsubai 
    331   1.1    tsubai int
    332   1.9   tsutsui xafb_show_screen(void *v, void *cookie, int waitok,
    333   1.9   tsutsui     void (*cb)(void *, int, int), void *cbarg)
    334   1.1    tsubai {
    335   1.9   tsutsui 
    336   1.1    tsubai 	return 0;
    337   1.1    tsubai }
    338   1.1    tsubai 
    339   1.1    tsubai int
    340   1.9   tsutsui xafb_cnattach(void)
    341   1.1    tsubai {
    342   1.1    tsubai 	struct xafb_devconfig *dc = &xafb_console_dc;
    343   1.1    tsubai 	struct rasops_info *ri = &dc->dc_ri;
    344   1.1    tsubai 	long defattr;
    345   1.1    tsubai 	int crow = 0;
    346   1.1    tsubai 
    347   1.1    tsubai 	if (!xafb_is_console())
    348   1.1    tsubai 		return -1;
    349   1.1    tsubai 
    350   1.8       uch 	dc->dc_fbpaddr = (paddr_t)0x10000000;
    351   1.8       uch 	dc->dc_fbbase = (void *)MIPS_PHYS_TO_KSEG1(dc->dc_fbpaddr);
    352   1.1    tsubai 	dc->dc_reg = (void *)0xb4903000;			/* XXX */
    353   1.1    tsubai 	xafb_common_init(dc);
    354   1.1    tsubai 
    355   1.1    tsubai 	crow = 0;			/* XXX current cursor pos */
    356   1.1    tsubai 
    357   1.3  junyoung 	(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
    358   1.1    tsubai 	wsdisplay_cnattach(&xafb_stdscreen, &dc->dc_ri, 0, crow, defattr);
    359   1.1    tsubai 
    360   1.1    tsubai 	return 0;
    361   1.1    tsubai }
    362   1.1    tsubai 
    363   1.1    tsubai int
    364   1.9   tsutsui xafb_getcmap(struct xafb_softc *sc, struct wsdisplay_cmap *cm)
    365   1.1    tsubai {
    366   1.1    tsubai 	u_int index = cm->index;
    367   1.1    tsubai 	u_int count = cm->count;
    368   1.1    tsubai 	int error;
    369   1.1    tsubai 
    370   1.1    tsubai 	if (index >= 256 || count > 256 || index + count > 256)
    371   1.1    tsubai 		return EINVAL;
    372   1.1    tsubai 
    373   1.1    tsubai 	error = copyout(&sc->sc_cmap_red[index],   cm->red,   count);
    374   1.1    tsubai 	if (error)
    375   1.1    tsubai 		return error;
    376   1.1    tsubai 	error = copyout(&sc->sc_cmap_green[index], cm->green, count);
    377   1.1    tsubai 	if (error)
    378   1.1    tsubai 		return error;
    379   1.1    tsubai 	error = copyout(&sc->sc_cmap_blue[index],  cm->blue,  count);
    380   1.1    tsubai 	if (error)
    381   1.1    tsubai 		return error;
    382   1.1    tsubai 
    383   1.1    tsubai 	return 0;
    384   1.1    tsubai }
    385   1.1    tsubai 
    386   1.1    tsubai int
    387   1.9   tsutsui xafb_putcmap(struct xafb_softc *sc, struct wsdisplay_cmap *cm)
    388   1.1    tsubai {
    389   1.1    tsubai 	u_int index = cm->index;
    390   1.1    tsubai 	u_int count = cm->count;
    391   1.7       chs 	int i, error;
    392   1.7       chs 	u_char rbuf[256], gbuf[256], bbuf[256];
    393   1.1    tsubai 	u_char *r, *g, *b;
    394   1.1    tsubai 
    395   1.7       chs 	if (cm->index >= 256 || cm->count > 256 ||
    396   1.7       chs 	    (cm->index + cm->count) > 256)
    397   1.1    tsubai 		return EINVAL;
    398   1.7       chs 	error = copyin(cm->red, &rbuf[index], count);
    399   1.7       chs 	if (error)
    400   1.7       chs 		return error;
    401   1.7       chs 	error = copyin(cm->green, &gbuf[index], count);
    402   1.7       chs 	if (error)
    403   1.7       chs 		return error;
    404   1.7       chs 	error = copyin(cm->blue, &bbuf[index], count);
    405   1.7       chs 	if (error)
    406   1.7       chs 		return error;
    407   1.7       chs 
    408   1.7       chs 	memcpy(&sc->sc_cmap_red[index], &rbuf[index], count);
    409   1.7       chs 	memcpy(&sc->sc_cmap_green[index], &gbuf[index], count);
    410   1.7       chs 	memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count);
    411   1.1    tsubai 
    412   1.1    tsubai 	r = &sc->sc_cmap_red[index];
    413   1.1    tsubai 	g = &sc->sc_cmap_green[index];
    414   1.1    tsubai 	b = &sc->sc_cmap_blue[index];
    415   1.1    tsubai 	for (i = 0; i < count; i++)
    416   1.1    tsubai 		xafb_setcolor(sc->sc_dc, index++, *r++, *g++, *b++);
    417   1.1    tsubai 	return 0;
    418   1.1    tsubai }
    419