Home | History | Annotate | Line # | Download | only in pci
gten.c revision 1.16.18.1
      1  1.16.18.1      yamt /*	$NetBSD: gten.c,v 1.16.18.1 2008/05/18 12:32:39 yamt 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.16.18.1      yamt __KERNEL_RCSID(0, "$NetBSD: gten.c,v 1.16.18.1 2008/05/18 12:32:39 yamt 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.1      matt #include <sys/malloc.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.1      matt #include <machine/bus.h>
     55        1.1      matt #include <machine/gtenvar.h>
     56        1.1      matt 
     57       1.14   garbled static	int	gten_match(struct device *, struct cfdata *, void *);
     58       1.14   garbled static	void	gten_attach(struct device *, struct device *, void *);
     59       1.14   garbled static	int	gten_print(void *, const char *);
     60        1.1      matt 
     61        1.7   thorpej CFATTACH_DECL(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.1      matt gten_match(struct device *parent, struct cfdata *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.1      matt gten_attach(struct device *parent, struct device *self, void *aux)
    121        1.1      matt {
    122        1.1      matt 	struct gten_softc *gt = (struct gten_softc *)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.1      matt 	if (console) {
    138        1.1      matt 		gt->gt_ri = &gten_console_ri;
    139        1.1      matt 		gt->gt_nscreens = 1;
    140        1.1      matt 	} else {
    141        1.1      matt 		MALLOC(gt->gt_ri, struct rasops_info *, sizeof(*gt->gt_ri),
    142        1.1      matt 			M_DEVBUF, M_NOWAIT);
    143        1.1      matt 		if (gt->gt_ri == NULL) {
    144       1.16   garbled 			aprint_error(": can't alloc memory\n");
    145        1.1      matt 			return;
    146        1.1      matt 		}
    147        1.1      matt 		memset(gt->gt_ri, 0, sizeof(*gt->gt_ri));
    148        1.1      matt #if 0
    149        1.1      matt 		error = pci_mapreg_map(pa, 0x14,
    150        1.1      matt 			PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT,
    151        1.1      matt 			BUS_SPACE_MAP_LINEAR, NULL,
    152        1.1      matt 			(bus_space_handle_t *) &gt->gt_ri->ri_bits,
    153        1.1      matt 			NULL, NULL);
    154        1.1      matt #else
    155        1.2      matt 		error = bus_space_map(pa->pa_memt, gt->gt_memaddr + GTEN_VRAM_OFFSET,
    156        1.2      matt 			960*1024, BUS_SPACE_MAP_LINEAR,
    157        1.1      matt 			(bus_space_handle_t *) &gt->gt_ri->ri_bits);
    158        1.1      matt #endif
    159        1.1      matt 		if (error) {
    160       1.16   garbled 			aprint_error(": can't map frame buffer: error=%d\n",
    161       1.16   garbled 			    error);
    162        1.1      matt 			return;
    163        1.1      matt 		}
    164        1.1      matt 
    165        1.1      matt 		gten_common_init(gt->gt_ri);
    166        1.1      matt 	}
    167        1.1      matt 
    168        1.1      matt 	gt->gt_paddr = vtophys((vaddr_t)gt->gt_ri->ri_bits);
    169        1.1      matt 	if (gt->gt_paddr == 0) {
    170       1.16   garbled 		aprint_error(": cannot map framebuffer\n");
    171        1.1      matt 		return;
    172        1.1      matt 	}
    173        1.2      matt 	gt->gt_psize = gt->gt_memsize - GTEN_VRAM_OFFSET;
    174        1.1      matt 
    175       1.11    itojun 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    176       1.16   garbled 	aprint_normal(": %s\n", devinfo);
    177        1.2      matt 	format_bytes(pbuf, sizeof(pbuf), gt->gt_psize);
    178       1.16   garbled 	aprint_normal("%s: %s, %dx%d, %dbpp\n", self->dv_xname, pbuf,
    179        1.2      matt 	       gt->gt_ri->ri_width, gt->gt_ri->ri_height,
    180        1.2      matt 	       gt->gt_ri->ri_depth);
    181        1.2      matt #if defined(DEBUG)
    182       1.16   garbled 	aprint_debug("%s: text %dx%d, =+%d+%d\n", self->dv_xname,
    183        1.2      matt 	       gt->gt_ri->ri_cols, gt->gt_ri->ri_rows,
    184        1.2      matt 	       gt->gt_ri->ri_xorigin, gt->gt_ri->ri_yorigin);
    185        1.2      matt 
    186        1.2      matt 	{ int i;
    187        1.2      matt 	  struct rasops_info *ri = gt->gt_ri;
    188        1.2      matt 	for (i = 0; i < 64; i++) {
    189        1.2      matt 		int j = i * ri->ri_stride;
    190        1.2      matt 		int k = (ri->ri_height - i - 1) * gt->gt_ri->ri_stride;
    191        1.2      matt 		memset(ri->ri_bits + j, 0, 64 - i);
    192        1.2      matt 		memset(ri->ri_bits + j + 64 - i, 255, i);
    193        1.2      matt 
    194        1.2      matt 		memset(ri->ri_bits + j + ri->ri_width - 64 + i, 0, 64 - i);
    195        1.2      matt 		memset(ri->ri_bits + j + ri->ri_width - 64, 255, i);
    196        1.2      matt 
    197        1.2      matt 		memset(ri->ri_bits + k, 0, 64 - i);
    198        1.2      matt 		memset(ri->ri_bits + k + 64 - i, 255, i);
    199        1.2      matt 
    200        1.2      matt 		memset(ri->ri_bits + k + ri->ri_width - 64 + i, 0, 64 - i);
    201        1.2      matt 		memset(ri->ri_bits + k + ri->ri_width - 64, 255, i);
    202        1.2      matt 	}}
    203        1.2      matt #endif
    204        1.1      matt 
    205        1.1      matt 	gt->gt_cmap_red[0] = gt->gt_cmap_green[0] = gt->gt_cmap_blue[0] = 0;
    206        1.1      matt 	gt->gt_cmap_red[15] = gt->gt_cmap_red[255] = 0xff;
    207        1.1      matt 	gt->gt_cmap_green[15] = gt->gt_cmap_green[255] = 0xff;
    208        1.1      matt 	gt->gt_cmap_blue[15] = gt->gt_cmap_blue[255] = 0xff;
    209        1.1      matt 
    210        1.1      matt 	a.console = console;
    211        1.1      matt 	a.scrdata = &gten_screenlist;
    212        1.1      matt 	a.accessops = &gten_accessops;
    213        1.1      matt 	a.accesscookie = gt;
    214        1.1      matt 
    215        1.1      matt 	config_found(self, &a, wsemuldisplaydevprint);
    216        1.1      matt }
    217        1.1      matt 
    218        1.1      matt static void
    219        1.1      matt gten_common_init(struct rasops_info *ri)
    220        1.1      matt {
    221        1.1      matt 	int32_t addr, width, height, linebytes, depth;
    222        1.1      matt 	int i, screenbytes;
    223        1.1      matt 
    224        1.1      matt 	/* initialize rasops */
    225        1.1      matt 	ri->ri_width = 640;
    226        1.1      matt 	ri->ri_height = 480;
    227        1.1      matt 	ri->ri_depth = 8;
    228        1.1      matt 	ri->ri_stride = 640;
    229        1.2      matt 	ri->ri_flg = RI_FORCEMONO | RI_FULLCLEAR;
    230        1.1      matt 
    231        1.2      matt 	rasops_init(ri, 30, 80);
    232        1.1      matt 	/* black on white */
    233        1.1      matt 	ri->ri_devcmap[0] = 0xffffffff;			/* bg */
    234        1.1      matt 	ri->ri_devcmap[1] = 0;				/* fg */
    235        1.1      matt 
    236        1.2      matt 	memset(ri->ri_bits, 0xff, ri->ri_stride * ri->ri_height);
    237        1.2      matt 
    238        1.1      matt 	gten_stdscreen.nrows = ri->ri_rows;
    239        1.1      matt 	gten_stdscreen.ncols = ri->ri_cols;
    240        1.1      matt 	gten_stdscreen.textops = &ri->ri_ops;
    241        1.1      matt 	gten_stdscreen.capabilities = ri->ri_caps;
    242        1.1      matt }
    243        1.1      matt 
    244        1.2      matt static int
    245       1.15  christos gten_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    246       1.14   garbled     struct proc *p)
    247        1.1      matt {
    248        1.1      matt 	struct gten_softc *gt = v;
    249        1.1      matt 	struct wsdisplay_fbinfo *wdf;
    250        1.1      matt 	struct grfinfo *gm;
    251        1.1      matt 
    252        1.1      matt 	switch (cmd) {
    253        1.1      matt 	case WSDISPLAYIO_GTYPE:
    254        1.1      matt 		*(u_int *)data = WSDISPLAY_TYPE_PCIMISC;	/* XXX ? */
    255        1.1      matt 		return 0;
    256        1.1      matt 
    257        1.1      matt 	case WSDISPLAYIO_GINFO:
    258        1.1      matt 		wdf = (void *)data;
    259        1.1      matt 		wdf->height = gt->gt_ri->ri_height;
    260        1.1      matt 		wdf->width = gt->gt_ri->ri_width;
    261        1.1      matt 		wdf->depth = gt->gt_ri->ri_depth;
    262        1.1      matt 		wdf->cmsize = 256;
    263        1.1      matt 		return 0;
    264        1.1      matt 
    265        1.1      matt 	case WSDISPLAYIO_GETCMAP:
    266        1.1      matt 		return gten_getcmap(gt, (struct wsdisplay_cmap *)data);
    267        1.1      matt 
    268        1.1      matt 	case WSDISPLAYIO_PUTCMAP:
    269        1.1      matt 		return gten_putcmap(gt, (struct wsdisplay_cmap *)data);
    270        1.1      matt 	}
    271        1.4    atatat 	return EPASSTHROUGH;
    272        1.1      matt }
    273        1.1      matt 
    274        1.2      matt static paddr_t
    275       1.14   garbled gten_mmap(void *v, void *vs, off_t offset, int prot)
    276        1.1      matt {
    277        1.1      matt 	struct gten_softc *gt = v;
    278        1.1      matt 
    279        1.2      matt 	if (offset >= 0 && offset < gt->gt_psize)
    280        1.1      matt 		return gt->gt_paddr + offset;
    281        1.2      matt 	if (offset >= 0x1000000 && offset < gt->gt_memsize)
    282        1.2      matt 		return gt->gt_memaddr + offset - 0x1000000;
    283        1.1      matt 
    284        1.1      matt 	return -1;
    285        1.1      matt }
    286        1.1      matt 
    287        1.2      matt static int
    288       1.14   garbled gten_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
    289       1.14   garbled     int *curxp, int *curyp, long *attrp)
    290        1.1      matt {
    291        1.1      matt 	struct gten_softc *gt = v;
    292        1.1      matt 	struct rasops_info *ri = gt->gt_ri;
    293        1.1      matt 	long defattr;
    294        1.1      matt 
    295        1.1      matt 	if (gt->gt_nscreens > 0)
    296        1.1      matt 		return (ENOMEM);
    297        1.1      matt 
    298        1.1      matt 	*cookiep = ri;			/* one and only for now */
    299        1.1      matt 	*curxp = 0;
    300        1.1      matt 	*curyp = 0;
    301        1.5  junyoung 	(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
    302        1.1      matt 	*attrp = defattr;
    303        1.1      matt 	gt->gt_nscreens++;
    304        1.1      matt 	return 0;
    305        1.1      matt }
    306        1.1      matt 
    307        1.2      matt static void
    308       1.14   garbled gten_free_screen(void *v, void *cookie)
    309        1.1      matt {
    310        1.1      matt 	struct gten_softc *gt = v;
    311        1.1      matt 
    312        1.1      matt 	if (gt->gt_ri == &gten_console_ri)
    313        1.1      matt 		panic("gten_free_screen: console");
    314        1.1      matt 
    315        1.1      matt 	gt->gt_nscreens--;
    316        1.1      matt }
    317        1.1      matt 
    318        1.2      matt static int
    319       1.14   garbled gten_show_screen(void *v, void *cookie, int waitok,
    320       1.14   garbled     void (*cb)(void *, int, int), void *cbarg)
    321        1.1      matt {
    322        1.1      matt 	return (0);
    323        1.1      matt }
    324        1.1      matt 
    325        1.1      matt int
    326        1.3    kleink gten_cnattach(pci_chipset_tag_t pc, bus_space_tag_t memt)
    327        1.1      matt {
    328        1.1      matt 	struct rasops_info *ri = &gten_console_ri;
    329        1.1      matt 	u_int32_t mapreg, id, mask, mapsize;
    330        1.1      matt 	long defattr;
    331        1.1      matt 	pcitag_t tag;
    332        1.1      matt 	int s, error;
    333        1.1      matt 	bus_size_t bussize;
    334        1.1      matt 	bus_addr_t busaddr;
    335        1.1      matt 
    336        1.3    kleink 	tag = pci_make_tag(pc, 0, 14, 0);
    337        1.1      matt 
    338        1.3    kleink 	id = pci_conf_read(pc, tag, PCI_ID_REG);
    339        1.1      matt 	if (PCI_VENDOR(id) != PCI_VENDOR_WD ||
    340        1.1      matt 	    PCI_PRODUCT(id) != PCI_PRODUCT_WD_90C)
    341        1.1      matt 		return ENXIO;
    342        1.1      matt 
    343        1.3    kleink 	mapreg = pci_conf_read(pc, tag, 0x14);
    344        1.1      matt 	if (PCI_MAPREG_TYPE(mapreg) != PCI_MAPREG_TYPE_MEM ||
    345        1.1      matt 	    PCI_MAPREG_MEM_TYPE(mapreg) != PCI_MAPREG_MEM_TYPE_32BIT)
    346        1.1      matt 		return ENXIO;
    347        1.1      matt 
    348        1.1      matt         s = splhigh();
    349        1.3    kleink         pci_conf_write(pc, tag, 0x14, 0xffffffff);
    350        1.3    kleink         mask = pci_conf_read(pc, tag, 0x14);
    351        1.3    kleink         pci_conf_write(pc, tag, 0x14, mapreg);
    352        1.1      matt 	splx(s);
    353        1.1      matt 	bussize = PCI_MAPREG_MEM_SIZE(mask);
    354        1.1      matt 	busaddr = PCI_MAPREG_MEM_ADDR(mapreg);
    355        1.1      matt 
    356        1.2      matt 	error = bus_space_map(memt, busaddr + GTEN_VRAM_OFFSET, 960*1024,
    357        1.1      matt 		BUS_SPACE_MAP_LINEAR, (bus_space_handle_t *) &ri->ri_bits);
    358        1.1      matt 	if (error)
    359        1.1      matt 		return error;
    360        1.1      matt 
    361        1.1      matt 	gten_common_init(ri);
    362        1.1      matt 
    363        1.5  junyoung 	(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
    364        1.1      matt 	wsdisplay_cnattach(&gten_stdscreen, ri, 0, 0, defattr);
    365        1.1      matt 
    366        1.1      matt 	gten_console_pcitag = tag;
    367        1.1      matt 
    368        1.1      matt 	return 0;
    369        1.1      matt }
    370        1.1      matt 
    371        1.2      matt static int
    372       1.14   garbled gten_getcmap(struct gten_softc *gt, struct wsdisplay_cmap *cm)
    373        1.1      matt {
    374        1.1      matt 	u_int index = cm->index;
    375        1.1      matt 	u_int count = cm->count;
    376        1.1      matt 	int error;
    377        1.1      matt 
    378        1.1      matt 	if (index >= 256 || count > 256 || index + count > 256)
    379        1.1      matt 		return EINVAL;
    380        1.1      matt 
    381        1.1      matt 	error = copyout(&gt->gt_cmap_red[index],   cm->red,   count);
    382        1.1      matt 	if (error)
    383        1.1      matt 		return error;
    384        1.1      matt 	error = copyout(&gt->gt_cmap_green[index], cm->green, count);
    385        1.1      matt 	if (error)
    386        1.1      matt 		return error;
    387        1.1      matt 	error = copyout(&gt->gt_cmap_blue[index],  cm->blue,  count);
    388        1.1      matt 	if (error)
    389        1.1      matt 		return error;
    390        1.1      matt 
    391        1.1      matt 	return 0;
    392        1.1      matt }
    393        1.1      matt 
    394        1.2      matt static int
    395       1.14   garbled gten_putcmap(struct gten_softc *gt, struct wsdisplay_cmap *cm)
    396        1.1      matt {
    397        1.1      matt 	int index = cm->index;
    398        1.1      matt 	int count = cm->count;
    399       1.10       chs 	int i, error;
    400       1.10       chs 	u_char rbuf[256], gbuf[256], bbuf[256];
    401        1.1      matt 
    402        1.1      matt 	if (cm->index >= 256 || cm->count > 256 ||
    403        1.1      matt 	    (cm->index + cm->count) > 256)
    404        1.1      matt 		return EINVAL;
    405       1.10       chs 	error = copyin(cm->red, &rbuf[index], count);
    406       1.10       chs 	if (error)
    407       1.10       chs 		return error;
    408       1.10       chs 	error = copyin(cm->green, &gbuf[index], count);
    409       1.10       chs 	if (error)
    410       1.10       chs 		return error;
    411       1.10       chs 	error = copyin(cm->blue, &bbuf[index], count);
    412       1.10       chs 	if (error)
    413       1.10       chs 		return error;
    414        1.1      matt 
    415       1.10       chs 	memcpy(&gt->gt_cmap_red[index], &rbuf[index], count);
    416       1.10       chs 	memcpy(&gt->gt_cmap_green[index], &gbuf[index], count);
    417       1.10       chs 	memcpy(&gt->gt_cmap_blue[index], &bbuf[index], count);
    418        1.1      matt 	return 0;
    419        1.1      matt }
    420