Home | History | Annotate | Line # | Download | only in pci
gten.c revision 1.22.2.1
      1  1.22.2.1   thorpej /*	$NetBSD: gten.c,v 1.22.2.1 2021/03/21 21:09:06 thorpej Exp $	*/
      2       1.2      matt 
      3       1.2      matt /*-
      4       1.2      matt  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5       1.2      matt  * All rights reserved.
      6       1.2      matt  *
      7       1.2      matt  * This code is derived from software contributed to The NetBSD Foundation
      8       1.2      matt  * by Matt Thomas <matt (at) 3am-software.com>
      9       1.2      matt  *
     10       1.2      matt  * Redistribution and use in source and binary forms, with or without
     11       1.2      matt  * modification, are permitted provided that the following conditions
     12       1.2      matt  * are met:
     13       1.2      matt  * 1. Redistributions of source code must retain the above copyright
     14       1.2      matt  *    notice, this list of conditions and the following disclaimer.
     15       1.2      matt  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.2      matt  *    notice, this list of conditions and the following disclaimer in the
     17       1.2      matt  *    documentation and/or other materials provided with the distribution.
     18       1.2      matt  *
     19       1.2      matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.2      matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.2      matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.2      matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.2      matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.2      matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.2      matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.2      matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.2      matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.2      matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.2      matt  * POSSIBILITY OF SUCH DAMAGE.
     30       1.2      matt  */
     31       1.9     lukem 
     32       1.9     lukem #include <sys/cdefs.h>
     33  1.22.2.1   thorpej __KERNEL_RCSID(0, "$NetBSD: gten.c,v 1.22.2.1 2021/03/21 21:09:06 thorpej Exp $");
     34       1.1      matt 
     35       1.1      matt #include <sys/param.h>
     36       1.1      matt #include <sys/buf.h>
     37       1.1      matt #include <sys/conf.h>
     38       1.1      matt #include <sys/device.h>
     39       1.1      matt #include <sys/ioctl.h>
     40       1.1      matt #include <sys/kernel.h>
     41      1.22   thorpej #include <sys/kmem.h>
     42       1.1      matt #include <sys/systm.h>
     43       1.1      matt 
     44       1.1      matt #include <uvm/uvm_extern.h>
     45       1.1      matt 
     46       1.1      matt #include <dev/pci/pcidevs.h>
     47       1.1      matt #include <dev/pci/pcireg.h>
     48       1.1      matt #include <dev/pci/pcivar.h>
     49       1.1      matt 
     50       1.1      matt #include <dev/wscons/wsconsio.h>
     51       1.1      matt #include <dev/wscons/wsdisplayvar.h>
     52       1.1      matt #include <dev/rasops/rasops.h>
     53       1.1      matt 
     54      1.20    dyoung #include <sys/bus.h>
     55       1.1      matt #include <machine/gtenvar.h>
     56       1.1      matt 
     57      1.19      matt static	int	gten_match(device_t, cfdata_t, void *);
     58      1.19      matt static	void	gten_attach(device_t, device_t, void *);
     59      1.14   garbled static	int	gten_print(void *, const char *);
     60       1.1      matt 
     61      1.19      matt CFATTACH_DECL_NEW(gten, sizeof(struct gten_softc),
     62       1.8   thorpej     gten_match, gten_attach, NULL, NULL);
     63       1.1      matt 
     64       1.1      matt static struct rasops_info gten_console_ri;
     65       1.1      matt static pcitag_t gten_console_pcitag;
     66       1.1      matt 
     67       1.1      matt static struct wsscreen_descr gten_stdscreen = {
     68       1.1      matt 	"std",
     69       1.1      matt 	0, 0,
     70       1.1      matt 	0,
     71       1.1      matt 	0, 0,
     72       1.1      matt 	WSSCREEN_REVERSE
     73       1.1      matt };
     74       1.1      matt 
     75       1.1      matt static const struct wsscreen_descr *_gten_scrlist[] = {
     76       1.1      matt 	&gten_stdscreen,
     77       1.1      matt 	/* XXX other formats, graphics screen? */
     78       1.1      matt };
     79       1.1      matt 
     80       1.1      matt static struct wsscreen_list gten_screenlist = {
     81       1.1      matt 	sizeof(_gten_scrlist) / sizeof(struct wsscreen_descr *), _gten_scrlist
     82       1.1      matt };
     83       1.1      matt 
     84      1.15  christos static int gten_ioctl(void *, void *, u_long, void *, int, struct proc *);
     85      1.14   garbled static paddr_t gten_mmap(void *, void *, off_t, int);
     86      1.14   garbled static int gten_alloc_screen(void *, const struct wsscreen_descr *,
     87      1.14   garbled 			     void **, int *, int *, long *);
     88      1.14   garbled static void gten_free_screen(void *, void *);
     89      1.14   garbled static int gten_show_screen(void *, void *, int,
     90      1.14   garbled 			    void (*) (void *, int, int), void *);
     91       1.1      matt 
     92       1.2      matt static struct wsdisplay_accessops gten_accessops = {
     93       1.1      matt 	gten_ioctl,
     94       1.1      matt 	gten_mmap,
     95       1.1      matt 	gten_alloc_screen,
     96       1.1      matt 	gten_free_screen,
     97       1.1      matt 	gten_show_screen,
     98       1.1      matt 	0 /* load_font */
     99       1.1      matt };
    100       1.1      matt 
    101      1.14   garbled static void gten_common_init(struct rasops_info *);
    102      1.14   garbled static int gten_getcmap(struct gten_softc *, struct wsdisplay_cmap *);
    103      1.14   garbled static int gten_putcmap(struct gten_softc *, struct wsdisplay_cmap *);
    104       1.1      matt 
    105       1.2      matt #define	GTEN_VRAM_OFFSET	0xf00000
    106       1.2      matt 
    107       1.2      matt static int
    108      1.19      matt gten_match(device_t parent, cfdata_t match, void *aux)
    109       1.1      matt {
    110       1.1      matt 	struct pci_attach_args *pa = aux;
    111       1.1      matt 
    112       1.1      matt 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_WD &&
    113       1.1      matt 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_WD_90C)
    114       1.1      matt 		return 2;
    115       1.1      matt 
    116       1.1      matt 	return 0;
    117       1.1      matt }
    118       1.1      matt 
    119       1.2      matt static void
    120      1.19      matt gten_attach(device_t parent, device_t self, void *aux)
    121       1.1      matt {
    122      1.19      matt 	struct gten_softc *gt = device_private(self);
    123       1.1      matt 	struct pci_attach_args *pa = aux;
    124       1.1      matt 	struct wsemuldisplaydev_attach_args a;
    125       1.1      matt 	int console = (pa->pa_tag == gten_console_pcitag);
    126       1.1      matt 	int error;
    127       1.1      matt 	char devinfo[256], pbuf[10];
    128       1.1      matt 
    129       1.1      matt 	error = pci_mapreg_info(pa->pa_pc, pa->pa_tag, 0x14,
    130       1.1      matt 		PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT,
    131       1.1      matt 		&gt->gt_memaddr, &gt->gt_memsize, NULL);
    132       1.1      matt 	if (error) {
    133      1.16   garbled 		aprint_error(": can't determine memory size: error=%d\n",
    134       1.1      matt 			error);
    135       1.1      matt 		return;
    136       1.1      matt 	}
    137      1.19      matt 	gt->gt_dev = self;
    138       1.1      matt 	if (console) {
    139       1.1      matt 		gt->gt_ri = &gten_console_ri;
    140       1.1      matt 		gt->gt_nscreens = 1;
    141       1.1      matt 	} else {
    142      1.22   thorpej 		gt->gt_ri = kmem_zalloc(sizeof(*gt->gt_ri),
    143      1.22   thorpej 			KM_SLEEP);
    144       1.1      matt #if 0
    145       1.1      matt 		error = pci_mapreg_map(pa, 0x14,
    146       1.1      matt 			PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT,
    147       1.1      matt 			BUS_SPACE_MAP_LINEAR, NULL,
    148       1.1      matt 			(bus_space_handle_t *) &gt->gt_ri->ri_bits,
    149       1.1      matt 			NULL, NULL);
    150       1.1      matt #else
    151       1.2      matt 		error = bus_space_map(pa->pa_memt, gt->gt_memaddr + GTEN_VRAM_OFFSET,
    152       1.2      matt 			960*1024, BUS_SPACE_MAP_LINEAR,
    153       1.1      matt 			(bus_space_handle_t *) &gt->gt_ri->ri_bits);
    154       1.1      matt #endif
    155       1.1      matt 		if (error) {
    156      1.16   garbled 			aprint_error(": can't map frame buffer: error=%d\n",
    157      1.16   garbled 			    error);
    158       1.1      matt 			return;
    159       1.1      matt 		}
    160       1.1      matt 
    161       1.1      matt 		gten_common_init(gt->gt_ri);
    162       1.1      matt 	}
    163       1.1      matt 
    164       1.1      matt 	gt->gt_paddr = vtophys((vaddr_t)gt->gt_ri->ri_bits);
    165       1.1      matt 	if (gt->gt_paddr == 0) {
    166      1.16   garbled 		aprint_error(": cannot map framebuffer\n");
    167       1.1      matt 		return;
    168       1.1      matt 	}
    169       1.2      matt 	gt->gt_psize = gt->gt_memsize - GTEN_VRAM_OFFSET;
    170       1.1      matt 
    171      1.11    itojun 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    172      1.16   garbled 	aprint_normal(": %s\n", devinfo);
    173       1.2      matt 	format_bytes(pbuf, sizeof(pbuf), gt->gt_psize);
    174      1.19      matt 	aprint_normal_dev(self, "%s: %s, %dx%d, %dbpp\n", pbuf,
    175       1.2      matt 	       gt->gt_ri->ri_width, gt->gt_ri->ri_height,
    176       1.2      matt 	       gt->gt_ri->ri_depth);
    177       1.2      matt #if defined(DEBUG)
    178      1.19      matt 	aprint_debug_dev(self, "%s: text %dx%d, =+%d+%d\n",
    179       1.2      matt 	       gt->gt_ri->ri_cols, gt->gt_ri->ri_rows,
    180       1.2      matt 	       gt->gt_ri->ri_xorigin, gt->gt_ri->ri_yorigin);
    181       1.2      matt 
    182       1.2      matt 	{ int i;
    183       1.2      matt 	  struct rasops_info *ri = gt->gt_ri;
    184       1.2      matt 	for (i = 0; i < 64; i++) {
    185       1.2      matt 		int j = i * ri->ri_stride;
    186       1.2      matt 		int k = (ri->ri_height - i - 1) * gt->gt_ri->ri_stride;
    187       1.2      matt 		memset(ri->ri_bits + j, 0, 64 - i);
    188       1.2      matt 		memset(ri->ri_bits + j + 64 - i, 255, i);
    189       1.2      matt 
    190       1.2      matt 		memset(ri->ri_bits + j + ri->ri_width - 64 + i, 0, 64 - i);
    191       1.2      matt 		memset(ri->ri_bits + j + ri->ri_width - 64, 255, i);
    192       1.2      matt 
    193       1.2      matt 		memset(ri->ri_bits + k, 0, 64 - i);
    194       1.2      matt 		memset(ri->ri_bits + k + 64 - i, 255, i);
    195       1.2      matt 
    196       1.2      matt 		memset(ri->ri_bits + k + ri->ri_width - 64 + i, 0, 64 - i);
    197       1.2      matt 		memset(ri->ri_bits + k + ri->ri_width - 64, 255, i);
    198       1.2      matt 	}}
    199       1.2      matt #endif
    200       1.1      matt 
    201       1.1      matt 	gt->gt_cmap_red[0] = gt->gt_cmap_green[0] = gt->gt_cmap_blue[0] = 0;
    202       1.1      matt 	gt->gt_cmap_red[15] = gt->gt_cmap_red[255] = 0xff;
    203       1.1      matt 	gt->gt_cmap_green[15] = gt->gt_cmap_green[255] = 0xff;
    204       1.1      matt 	gt->gt_cmap_blue[15] = gt->gt_cmap_blue[255] = 0xff;
    205       1.1      matt 
    206       1.1      matt 	a.console = console;
    207       1.1      matt 	a.scrdata = &gten_screenlist;
    208       1.1      matt 	a.accessops = &gten_accessops;
    209       1.1      matt 	a.accesscookie = gt;
    210       1.1      matt 
    211  1.22.2.1   thorpej 	config_found(self, &a, wsemuldisplaydevprint, CFARG_EOL);
    212       1.1      matt }
    213       1.1      matt 
    214       1.1      matt static void
    215       1.1      matt gten_common_init(struct rasops_info *ri)
    216       1.1      matt {
    217       1.1      matt 	int32_t addr, width, height, linebytes, depth;
    218       1.1      matt 	int i, screenbytes;
    219       1.1      matt 
    220       1.1      matt 	/* initialize rasops */
    221       1.1      matt 	ri->ri_width = 640;
    222       1.1      matt 	ri->ri_height = 480;
    223       1.1      matt 	ri->ri_depth = 8;
    224       1.1      matt 	ri->ri_stride = 640;
    225       1.2      matt 	ri->ri_flg = RI_FORCEMONO | RI_FULLCLEAR;
    226       1.1      matt 
    227       1.2      matt 	rasops_init(ri, 30, 80);
    228       1.1      matt 	/* black on white */
    229       1.1      matt 	ri->ri_devcmap[0] = 0xffffffff;			/* bg */
    230       1.1      matt 	ri->ri_devcmap[1] = 0;				/* fg */
    231       1.1      matt 
    232       1.2      matt 	memset(ri->ri_bits, 0xff, ri->ri_stride * ri->ri_height);
    233       1.2      matt 
    234       1.1      matt 	gten_stdscreen.nrows = ri->ri_rows;
    235       1.1      matt 	gten_stdscreen.ncols = ri->ri_cols;
    236       1.1      matt 	gten_stdscreen.textops = &ri->ri_ops;
    237       1.1      matt 	gten_stdscreen.capabilities = ri->ri_caps;
    238       1.1      matt }
    239       1.1      matt 
    240       1.2      matt static int
    241      1.15  christos gten_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    242      1.14   garbled     struct proc *p)
    243       1.1      matt {
    244       1.1      matt 	struct gten_softc *gt = v;
    245       1.1      matt 	struct wsdisplay_fbinfo *wdf;
    246       1.1      matt 	struct grfinfo *gm;
    247       1.1      matt 
    248       1.1      matt 	switch (cmd) {
    249       1.1      matt 	case WSDISPLAYIO_GTYPE:
    250       1.1      matt 		*(u_int *)data = WSDISPLAY_TYPE_PCIMISC;	/* XXX ? */
    251       1.1      matt 		return 0;
    252       1.1      matt 
    253       1.1      matt 	case WSDISPLAYIO_GINFO:
    254       1.1      matt 		wdf = (void *)data;
    255       1.1      matt 		wdf->height = gt->gt_ri->ri_height;
    256       1.1      matt 		wdf->width = gt->gt_ri->ri_width;
    257       1.1      matt 		wdf->depth = gt->gt_ri->ri_depth;
    258       1.1      matt 		wdf->cmsize = 256;
    259       1.1      matt 		return 0;
    260       1.1      matt 
    261       1.1      matt 	case WSDISPLAYIO_GETCMAP:
    262       1.1      matt 		return gten_getcmap(gt, (struct wsdisplay_cmap *)data);
    263       1.1      matt 
    264       1.1      matt 	case WSDISPLAYIO_PUTCMAP:
    265       1.1      matt 		return gten_putcmap(gt, (struct wsdisplay_cmap *)data);
    266       1.1      matt 	}
    267       1.4    atatat 	return EPASSTHROUGH;
    268       1.1      matt }
    269       1.1      matt 
    270       1.2      matt static paddr_t
    271      1.14   garbled gten_mmap(void *v, void *vs, off_t offset, int prot)
    272       1.1      matt {
    273       1.1      matt 	struct gten_softc *gt = v;
    274       1.1      matt 
    275       1.2      matt 	if (offset >= 0 && offset < gt->gt_psize)
    276       1.1      matt 		return gt->gt_paddr + offset;
    277       1.2      matt 	if (offset >= 0x1000000 && offset < gt->gt_memsize)
    278       1.2      matt 		return gt->gt_memaddr + offset - 0x1000000;
    279       1.1      matt 
    280       1.1      matt 	return -1;
    281       1.1      matt }
    282       1.1      matt 
    283       1.2      matt static int
    284      1.14   garbled gten_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
    285      1.14   garbled     int *curxp, int *curyp, long *attrp)
    286       1.1      matt {
    287       1.1      matt 	struct gten_softc *gt = v;
    288       1.1      matt 	struct rasops_info *ri = gt->gt_ri;
    289       1.1      matt 	long defattr;
    290       1.1      matt 
    291       1.1      matt 	if (gt->gt_nscreens > 0)
    292       1.1      matt 		return (ENOMEM);
    293       1.1      matt 
    294       1.1      matt 	*cookiep = ri;			/* one and only for now */
    295       1.1      matt 	*curxp = 0;
    296       1.1      matt 	*curyp = 0;
    297       1.5  junyoung 	(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
    298       1.1      matt 	*attrp = defattr;
    299       1.1      matt 	gt->gt_nscreens++;
    300       1.1      matt 	return 0;
    301       1.1      matt }
    302       1.1      matt 
    303       1.2      matt static void
    304      1.14   garbled gten_free_screen(void *v, void *cookie)
    305       1.1      matt {
    306       1.1      matt 	struct gten_softc *gt = v;
    307       1.1      matt 
    308       1.1      matt 	if (gt->gt_ri == &gten_console_ri)
    309       1.1      matt 		panic("gten_free_screen: console");
    310       1.1      matt 
    311       1.1      matt 	gt->gt_nscreens--;
    312       1.1      matt }
    313       1.1      matt 
    314       1.2      matt static int
    315      1.14   garbled gten_show_screen(void *v, void *cookie, int waitok,
    316      1.14   garbled     void (*cb)(void *, int, int), void *cbarg)
    317       1.1      matt {
    318       1.1      matt 	return (0);
    319       1.1      matt }
    320       1.1      matt 
    321       1.1      matt int
    322       1.3    kleink gten_cnattach(pci_chipset_tag_t pc, bus_space_tag_t memt)
    323       1.1      matt {
    324       1.1      matt 	struct rasops_info *ri = &gten_console_ri;
    325       1.1      matt 	u_int32_t mapreg, id, mask, mapsize;
    326       1.1      matt 	long defattr;
    327       1.1      matt 	pcitag_t tag;
    328       1.1      matt 	int s, error;
    329       1.1      matt 	bus_size_t bussize;
    330       1.1      matt 	bus_addr_t busaddr;
    331       1.1      matt 
    332       1.3    kleink 	tag = pci_make_tag(pc, 0, 14, 0);
    333       1.1      matt 
    334       1.3    kleink 	id = pci_conf_read(pc, tag, PCI_ID_REG);
    335       1.1      matt 	if (PCI_VENDOR(id) != PCI_VENDOR_WD ||
    336       1.1      matt 	    PCI_PRODUCT(id) != PCI_PRODUCT_WD_90C)
    337       1.1      matt 		return ENXIO;
    338       1.1      matt 
    339       1.3    kleink 	mapreg = pci_conf_read(pc, tag, 0x14);
    340       1.1      matt 	if (PCI_MAPREG_TYPE(mapreg) != PCI_MAPREG_TYPE_MEM ||
    341       1.1      matt 	    PCI_MAPREG_MEM_TYPE(mapreg) != PCI_MAPREG_MEM_TYPE_32BIT)
    342       1.1      matt 		return ENXIO;
    343       1.1      matt 
    344       1.1      matt         s = splhigh();
    345       1.3    kleink         pci_conf_write(pc, tag, 0x14, 0xffffffff);
    346       1.3    kleink         mask = pci_conf_read(pc, tag, 0x14);
    347       1.3    kleink         pci_conf_write(pc, tag, 0x14, mapreg);
    348       1.1      matt 	splx(s);
    349       1.1      matt 	bussize = PCI_MAPREG_MEM_SIZE(mask);
    350       1.1      matt 	busaddr = PCI_MAPREG_MEM_ADDR(mapreg);
    351       1.1      matt 
    352       1.2      matt 	error = bus_space_map(memt, busaddr + GTEN_VRAM_OFFSET, 960*1024,
    353       1.1      matt 		BUS_SPACE_MAP_LINEAR, (bus_space_handle_t *) &ri->ri_bits);
    354       1.1      matt 	if (error)
    355       1.1      matt 		return error;
    356       1.1      matt 
    357       1.1      matt 	gten_common_init(ri);
    358       1.1      matt 
    359       1.5  junyoung 	(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
    360       1.1      matt 	wsdisplay_cnattach(&gten_stdscreen, ri, 0, 0, defattr);
    361       1.1      matt 
    362       1.1      matt 	gten_console_pcitag = tag;
    363       1.1      matt 
    364       1.1      matt 	return 0;
    365       1.1      matt }
    366       1.1      matt 
    367       1.2      matt static int
    368      1.14   garbled gten_getcmap(struct gten_softc *gt, struct wsdisplay_cmap *cm)
    369       1.1      matt {
    370       1.1      matt 	u_int index = cm->index;
    371       1.1      matt 	u_int count = cm->count;
    372       1.1      matt 	int error;
    373       1.1      matt 
    374       1.1      matt 	if (index >= 256 || count > 256 || index + count > 256)
    375       1.1      matt 		return EINVAL;
    376       1.1      matt 
    377       1.1      matt 	error = copyout(&gt->gt_cmap_red[index],   cm->red,   count);
    378       1.1      matt 	if (error)
    379       1.1      matt 		return error;
    380       1.1      matt 	error = copyout(&gt->gt_cmap_green[index], cm->green, count);
    381       1.1      matt 	if (error)
    382       1.1      matt 		return error;
    383       1.1      matt 	error = copyout(&gt->gt_cmap_blue[index],  cm->blue,  count);
    384       1.1      matt 	if (error)
    385       1.1      matt 		return error;
    386       1.1      matt 
    387       1.1      matt 	return 0;
    388       1.1      matt }
    389       1.1      matt 
    390       1.2      matt static int
    391      1.14   garbled gten_putcmap(struct gten_softc *gt, struct wsdisplay_cmap *cm)
    392       1.1      matt {
    393       1.1      matt 	int index = cm->index;
    394       1.1      matt 	int count = cm->count;
    395      1.10       chs 	int i, error;
    396      1.10       chs 	u_char rbuf[256], gbuf[256], bbuf[256];
    397       1.1      matt 
    398       1.1      matt 	if (cm->index >= 256 || cm->count > 256 ||
    399       1.1      matt 	    (cm->index + cm->count) > 256)
    400       1.1      matt 		return EINVAL;
    401      1.10       chs 	error = copyin(cm->red, &rbuf[index], count);
    402      1.10       chs 	if (error)
    403      1.10       chs 		return error;
    404      1.10       chs 	error = copyin(cm->green, &gbuf[index], count);
    405      1.10       chs 	if (error)
    406      1.10       chs 		return error;
    407      1.10       chs 	error = copyin(cm->blue, &bbuf[index], count);
    408      1.10       chs 	if (error)
    409      1.10       chs 		return error;
    410       1.1      matt 
    411      1.10       chs 	memcpy(&gt->gt_cmap_red[index], &rbuf[index], count);
    412      1.10       chs 	memcpy(&gt->gt_cmap_green[index], &gbuf[index], count);
    413      1.10       chs 	memcpy(&gt->gt_cmap_blue[index], &bbuf[index], count);
    414       1.1      matt 	return 0;
    415       1.1      matt }
    416