Home | History | Annotate | Line # | Download | only in dev
grf.c revision 1.59
      1 /*	$NetBSD: grf.c,v 1.59 2012/10/27 17:17:28 chs Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1988 University of Utah.
      5  * Copyright (c) 1990 The Regents of the University of California.
      6  * All rights reserved.
      7  *
      8  * This code is derived from software contributed to Berkeley by
      9  * the Systems Programming Group of the University of Utah Computer
     10  * Science Department.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  *
     36  * from: Utah $Hdr: grf.c 1.31 91/01/21$
     37  *
     38  *	@(#)grf.c	7.8 (Berkeley) 5/7/91
     39  */
     40 
     41 #include <sys/cdefs.h>
     42 __KERNEL_RCSID(0, "$NetBSD: grf.c,v 1.59 2012/10/27 17:17:28 chs Exp $");
     43 
     44 /*
     45  * Graphics display driver for the Amiga
     46  * This is the hardware-independent portion of the driver.
     47  * Hardware access is through the grf_softc->g_mode routine.
     48  */
     49 
     50 #include "view.h"
     51 #include "grf.h"
     52 #include "kbd.h"
     53 #include "wsdisplay.h"
     54 
     55 #include <sys/param.h>
     56 #include <sys/proc.h>
     57 #include <sys/ioctl.h>
     58 #include <sys/device.h>
     59 #include <sys/file.h>
     60 #include <sys/malloc.h>
     61 #include <sys/systm.h>
     62 #include <sys/vnode.h>
     63 #include <sys/mman.h>
     64 #include <sys/bus.h>
     65 #include <sys/kauth.h>
     66 
     67 #include <machine/cpu.h>
     68 
     69 #include <dev/cons.h>
     70 #include <dev/sun/fbio.h>
     71 #include <dev/wscons/wsconsio.h>
     72 #include <dev/wscons/wsdisplayvar.h>
     73 #include <dev/rasops/rasops.h>
     74 #include <dev/wscons/wsdisplay_vconsvar.h>
     75 
     76 #include <amiga/amiga/color.h>	/* DEBUG */
     77 #include <amiga/amiga/device.h>
     78 #include <amiga/dev/grfioctl.h>
     79 #include <amiga/dev/grfws.h>
     80 #include <amiga/dev/grfvar.h>
     81 #include <amiga/dev/itevar.h>
     82 #include <amiga/dev/kbdvar.h>
     83 #include <amiga/dev/viewioctl.h>
     84 
     85 #include <sys/conf.h>
     86 
     87 #if NGRF > 0
     88 #include "ite.h"
     89 #if NITE == 0
     90 #define	ite_on(u,f)
     91 #define	ite_off(u,f)
     92 #define ite_reinit(d)
     93 #endif
     94 
     95 int grfon(dev_t);
     96 int grfoff(dev_t);
     97 int grfsinfo(dev_t, struct grfdyninfo *);
     98 
     99 void grfattach(device_t, device_t, void *);
    100 int grfmatch(device_t, cfdata_t, void *);
    101 int grfprint(void *, const char *);
    102 #ifdef DEBUG
    103 void grfdebug(struct grf_softc *, const char *, ...);
    104 #endif
    105 /*
    106  * pointers to grf drivers device structs
    107  */
    108 struct grf_softc *grfsp[NGRF];
    109 
    110 CFATTACH_DECL_NEW(grf, 0,
    111     grfmatch, grfattach, NULL, NULL);
    112 
    113 dev_type_open(grfopen);
    114 dev_type_close(grfclose);
    115 dev_type_ioctl(grfioctl);
    116 dev_type_mmap(grfmmap);
    117 
    118 const struct cdevsw grf_cdevsw = {
    119 	grfopen, grfclose, nullread, nullwrite, grfioctl,
    120 	nostop, notty, nopoll, grfmmap, nokqfilter,
    121 };
    122 
    123 /*
    124  * only used in console init.
    125  */
    126 static cfdata_t cfdata;
    127 
    128 #if NWSDISPLAY > 0
    129 static struct vcons_screen console_vcons;
    130 
    131 static void grf_init_screen(void *, struct vcons_screen *, int, long *);
    132 static struct rasops_info *grf_setup_rasops(struct grf_softc *,
    133     struct vcons_screen *);
    134 static paddr_t grf_wsmmap_md(off_t off);
    135 
    136 cons_decl(grf);
    137 #endif
    138 
    139 /*
    140  * match if the unit of grf matches its perspective
    141  * low level board driver.
    142  */
    143 int
    144 grfmatch(device_t parent, cfdata_t cf, void *aux)
    145 {
    146 	struct grf_softc *psc;
    147 
    148 	psc = device_private(parent);
    149 	if (cf->cf_unit != psc->g_unit)
    150 		return(0);
    151 	cfdata = cf;
    152 	return(1);
    153 }
    154 
    155 /*
    156  * Attach.. plug pointer in and print some info.
    157  * Then try and attach a wsdisplay or ite to us.
    158  * Note: self is NULL durring console init.
    159  */
    160 void
    161 grfattach(device_t parent, device_t self, void *aux)
    162 {
    163 #if NWSDISPLAY > 0
    164 	struct wsemuldisplaydev_attach_args wa;
    165 	long defattr;
    166 #endif
    167 	struct grf_softc *gp;
    168 	int maj;
    169 
    170 	gp = device_private(parent);
    171 	gp->g_device = self;
    172 	grfsp[gp->g_unit] = gp;
    173 
    174 	/*
    175 	 * find our major device number
    176 	 */
    177 	maj = cdevsw_lookup_major(&grf_cdevsw);
    178 
    179 	gp->g_grfdev = makedev(maj, gp->g_unit);
    180 	if (self != NULL) {
    181 		printf(": width %d height %d", gp->g_display.gd_dwidth,
    182 		    gp->g_display.gd_dheight);
    183 		if (gp->g_display.gd_colors == 2)
    184 			printf(" monochrome\n");
    185 		else
    186 			printf(" colors %d\n", gp->g_display.gd_colors);
    187 #if NWSDISPLAY > 0
    188 		vcons_init(&gp->g_vd, gp, gp->g_screens[0], gp->g_accessops);
    189 		gp->g_vd.init_screen = grf_init_screen;
    190 		if (gp->g_flags & GF_CONSOLE) {
    191 			console_vcons.scr_flags |= VCONS_SCREEN_IS_STATIC;
    192 			vcons_init_screen(&gp->g_vd,
    193 			    &console_vcons, 1, &defattr);
    194 			gp->g_screens[0]->textops =
    195 			    &console_vcons.scr_ri.ri_ops;
    196 			wsdisplay_cnattach(gp->g_screens[0],
    197 			    &console_vcons.scr_ri, 0, 0, defattr);
    198 			vcons_replay_msgbuf(&console_vcons);
    199 		}
    200 
    201 		/* attach wsdisplay */
    202 		wa.console = (gp->g_flags & GF_CONSOLE) != 0;
    203 		wa.scrdata = &gp->g_screenlist;
    204 		wa.accessops = gp->g_accessops;
    205 		wa.accesscookie = &gp->g_vd;
    206 		config_found(self, &wa, wsemuldisplaydevprint);
    207 #endif  /* NWSDISPLAY > 0 */
    208 	}
    209 
    210 #if NWSDISPLAY == 0
    211 	/*
    212 	 * try and attach an ite
    213 	 */
    214 	amiga_config_found(cfdata, self, gp, grfprint);
    215 #endif
    216 }
    217 
    218 int
    219 grfprint(void *aux, const char *pnp)
    220 {
    221 	if (pnp)
    222 		aprint_normal("ite at %s", pnp);
    223 	return(UNCONF);
    224 }
    225 
    226 /*ARGSUSED*/
    227 int
    228 grfopen(dev_t dev, int flags, int devtype, struct lwp *l)
    229 {
    230 	struct grf_softc *gp;
    231 
    232 	if (GRFUNIT(dev) >= NGRF || (gp = grfsp[GRFUNIT(dev)]) == NULL)
    233 		return(ENXIO);
    234 
    235 	if ((gp->g_flags & GF_ALIVE) == 0)
    236 		return(ENXIO);
    237 
    238 	if ((gp->g_flags & (GF_OPEN|GF_EXCLUDE)) == (GF_OPEN|GF_EXCLUDE))
    239 		return(EBUSY);
    240 
    241 	return(0);
    242 }
    243 
    244 /*ARGSUSED*/
    245 int
    246 grfclose(dev_t dev, int flags, int mode, struct lwp *l)
    247 {
    248 	struct grf_softc *gp;
    249 
    250 	gp = grfsp[GRFUNIT(dev)];
    251 	(void)grfoff(dev);
    252 	gp->g_flags &= GF_ALIVE;
    253 	return(0);
    254 }
    255 
    256 /*ARGSUSED*/
    257 int
    258 grfioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
    259 {
    260 	struct grf_softc *gp;
    261 	int error;
    262 
    263 	gp = grfsp[GRFUNIT(dev)];
    264 	error = 0;
    265 
    266 	switch (cmd) {
    267 	case OGRFIOCGINFO:
    268 	        /* argl.. no bank-member.. */
    269 	  	memcpy(data, (void *)&gp->g_display, sizeof(struct grfinfo)-4);
    270 		break;
    271 	case GRFIOCGINFO:
    272 		memcpy(data, (void *)&gp->g_display, sizeof(struct grfinfo));
    273 		break;
    274 	case GRFIOCON:
    275 		error = grfon(dev);
    276 		break;
    277 	case GRFIOCOFF:
    278 		error = grfoff(dev);
    279 		break;
    280 	case GRFIOCSINFO:
    281 		error = grfsinfo(dev, (struct grfdyninfo *) data);
    282 		break;
    283 	case GRFGETVMODE:
    284 		return(gp->g_mode(gp, GM_GRFGETVMODE, data, 0, 0));
    285 	case GRFSETVMODE:
    286 		error = gp->g_mode(gp, GM_GRFSETVMODE, data, 0, 0);
    287 		if (error == 0 && gp->g_itedev && !(gp->g_flags & GF_GRFON))
    288 			ite_reinit(gp->g_itedev);
    289 		break;
    290 	case GRFGETNUMVM:
    291 		return(gp->g_mode(gp, GM_GRFGETNUMVM, data, 0, 0));
    292 	/*
    293 	 * these are all hardware dependent, and have to be resolved
    294 	 * in the respective driver.
    295 	 */
    296 	case GRFIOCPUTCMAP:
    297 	case GRFIOCGETCMAP:
    298 	case GRFIOCSSPRITEPOS:
    299 	case GRFIOCGSPRITEPOS:
    300 	case GRFIOCSSPRITEINF:
    301 	case GRFIOCGSPRITEINF:
    302 	case GRFIOCGSPRITEMAX:
    303 	case GRFIOCBITBLT:
    304     	case GRFIOCSETMON:
    305 	case GRFTOGGLE: /* Toggles between Cirrus boards and native ECS on
    306                      Amiga. 15/11/94 ill */
    307 		/*
    308 		 * We need the minor dev number to get the overlay/image
    309 		 * information for grf_ul.
    310 		 */
    311 		return(gp->g_mode(gp, GM_GRFIOCTL, data, cmd, dev));
    312 
    313 	case GRFIOCBLANK:	/* blank ioctl, IOCON/OFF will turn ite on */
    314 	case FBIOSVIDEO:
    315 		error = gp->g_mode(gp, GM_GRFIOCTL, data, GRFIOCBLANK, dev);
    316 		if (!error)
    317 			gp->g_blank = *(int *)data;
    318 		return (error);
    319 
    320 	case FBIOGVIDEO:
    321 		*(int *)data = gp->g_blank;
    322 		return (0);
    323 
    324 	default:
    325 #if NVIEW > 0
    326 		/*
    327 		 * check to see whether it's a command recognized by the
    328 		 * view code if the unit is 0
    329 		 * XXX
    330 		 */
    331 		if (GRFUNIT(dev) == 0) {
    332 			extern const struct cdevsw view_cdevsw;
    333 
    334 			return((*view_cdevsw.d_ioctl)(dev, cmd, data, flag, l));
    335 		}
    336 #endif
    337 		error = EPASSTHROUGH;
    338 		break;
    339 
    340 	}
    341 	return(error);
    342 }
    343 
    344 /*
    345  * map the contents of a graphics display card into process'
    346  * memory space.
    347  */
    348 paddr_t
    349 grfmmap(dev_t dev, off_t off, int prot)
    350 {
    351 	struct grf_softc *gp;
    352 	struct grfinfo *gi;
    353 
    354 	gp = grfsp[GRFUNIT(dev)];
    355 	gi = &gp->g_display;
    356 
    357 	/*
    358 	 * control registers
    359 	 */
    360 	if (off >= 0 && off < gi->gd_regsize)
    361 		return(((paddr_t)gi->gd_regaddr + off) >> PGSHIFT);
    362 
    363 	/*
    364 	 * frame buffer
    365 	 */
    366 	if (off >= gi->gd_regsize && off < gi->gd_regsize+gi->gd_fbsize) {
    367 		off -= gi->gd_regsize;
    368 		return(((paddr_t)gi->gd_fbaddr + off) >> PGSHIFT);
    369 	}
    370 	/* bogus */
    371 	return(-1);
    372 }
    373 
    374 int
    375 grfon(dev_t dev)
    376 {
    377 	struct grf_softc *gp;
    378 
    379 	gp = grfsp[GRFUNIT(dev)];
    380 
    381 	if (gp->g_flags & GF_GRFON)
    382 		return(0);
    383 
    384 	gp->g_flags |= GF_GRFON;
    385 	if (gp->g_itedev != NODEV)
    386 		ite_off(gp->g_itedev, 3);
    387 
    388 	return(gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVON : GM_GRFON,
    389 							NULL, 0, 0));
    390 }
    391 
    392 int
    393 grfoff(dev_t dev)
    394 {
    395 	struct grf_softc *gp;
    396 	int error;
    397 
    398 	gp = grfsp[GRFUNIT(dev)];
    399 
    400 	if ((gp->g_flags & GF_GRFON) == 0)
    401 		return(0);
    402 
    403 	gp->g_flags &= ~GF_GRFON;
    404 	error = gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVOFF : GM_GRFOFF,
    405 							NULL, 0, 0);
    406 
    407 	/*
    408 	 * Closely tied together no X's
    409 	 */
    410 	if (gp->g_itedev != NODEV)
    411 		ite_on(gp->g_itedev, 2);
    412 
    413 	return(error);
    414 }
    415 
    416 int
    417 grfsinfo(dev_t dev, struct grfdyninfo *dyninfo)
    418 {
    419 	struct grf_softc *gp;
    420 	int error;
    421 
    422 	gp = grfsp[GRFUNIT(dev)];
    423 	error = gp->g_mode(gp, GM_GRFCONFIG, dyninfo, 0, 0);
    424 
    425 	/*
    426 	 * Closely tied together no X's
    427 	 */
    428 	if (gp->g_itedev != NODEV)
    429 		ite_reinit(gp->g_itedev);
    430 	return(error);
    431 }
    432 
    433 #if NWSDISPLAY > 0
    434 void
    435 grfcnprobe(struct consdev *cd)
    436 {
    437 	struct grf_softc *gp;
    438 	int unit;
    439 
    440 	/*
    441 	 * Find the first working grf device for being console.
    442 	 * Ignore unit 0 (grfcc), which should use amidisplaycc instead.
    443 	 */
    444 	for (unit = 1; unit < NGRF; unit++) {
    445 		gp = grfsp[unit];
    446 		if (gp != NULL && (gp->g_flags & GF_ALIVE)) {
    447 			cd->cn_pri = CN_INTERNAL;
    448 			cd->cn_dev = NODEV;  /* initialized later by wscons */
    449 			return;
    450 		}
    451 	}
    452 
    453 	/* no grf console alive */
    454 	cd->cn_pri = CN_DEAD;
    455 }
    456 
    457 void
    458 grfcninit(struct consdev *cd)
    459 {
    460 	struct grf_softc *gp;
    461 	struct rasops_info *ri;
    462 	long defattr;
    463 	int unit;
    464 
    465 	/* find console grf and set up wsdisplay for it */
    466 	for (unit = 1; unit < NGRF; unit++) {
    467 		gp = grfsp[unit];
    468 		if (gp != NULL && (gp->g_flags & GF_ALIVE)) {
    469 			gp->g_flags |= GF_CONSOLE;  /* we are console! */
    470 			gp->g_screens[0]->ncols = gp->g_display.gd_fbwidth /
    471 			    gp->g_screens[0]->fontwidth;
    472 			gp->g_screens[0]->nrows = gp->g_display.gd_fbheight /
    473 			    gp->g_screens[0]->fontheight;
    474 
    475 			ri = grf_setup_rasops(gp, &console_vcons);
    476 			console_vcons.scr_cookie = gp;
    477 			defattr = 0;  /* XXX */
    478 
    479 			wsdisplay_preattach(gp->g_screens[0], ri, 0, 0,
    480 			    defattr);
    481 #if NKBD > 0
    482 			/* tell kbd device it is used as console keyboard */
    483 			kbd_cnattach();
    484 #endif
    485 			return;
    486 		}
    487 	}
    488 	panic("grfcninit: lost console");
    489 }
    490 
    491 static void
    492 grf_init_screen(void *cookie, struct vcons_screen *scr, int existing,
    493     long *defattr)
    494 {
    495 	struct grf_softc *gp;
    496 	struct rasops_info *ri;
    497 
    498 	gp = cookie;
    499 	ri = grf_setup_rasops(gp, scr);
    500 }
    501 
    502 static struct rasops_info *
    503 grf_setup_rasops(struct grf_softc *gp, struct vcons_screen *scr)
    504 {
    505 	struct rasops_info *ri;
    506 	int i;
    507 
    508 	ri = &scr->scr_ri;
    509 	scr->scr_flags |= VCONS_DONT_READ;
    510 	memset(ri, 0, sizeof(struct rasops_info));
    511 
    512 	ri->ri_rows = gp->g_screens[0]->nrows;
    513 	ri->ri_cols = gp->g_screens[0]->ncols;
    514 	ri->ri_hw = scr;
    515 	ri->ri_ops.cursor    = gp->g_emulops->cursor;
    516 	ri->ri_ops.mapchar   = gp->g_emulops->mapchar;
    517 	ri->ri_ops.copyrows  = gp->g_emulops->copyrows;
    518 	ri->ri_ops.eraserows = gp->g_emulops->eraserows;
    519 	ri->ri_ops.copycols  = gp->g_emulops->copycols;
    520 	ri->ri_ops.erasecols = gp->g_emulops->erasecols;
    521 	ri->ri_ops.putchar   = gp->g_emulops->putchar;
    522 	ri->ri_ops.allocattr = gp->g_emulops->allocattr;
    523 
    524 	/* multiplication table for row-offsets */
    525 	for (i = 0; i < ri->ri_rows; i++)
    526 		gp->g_rowoffset[i] = i * ri->ri_cols;
    527 
    528 	return ri;
    529 }
    530 
    531 paddr_t
    532 grf_wsmmap(void *v, void *vs, off_t off, int prot)
    533 {
    534 	struct vcons_data *vd;
    535 	struct grf_softc *gp;
    536 	struct grfinfo *gi;
    537 
    538 	vd = v;
    539 	gp = vd->cookie;
    540 	gi = &gp->g_display;
    541 
    542 	/* Normal fb mapping */
    543 	if (off < gi->gd_fbsize)
    544 		return grf_wsmmap_md(((bus_addr_t)gp->g_fbkva) + off);
    545 
    546 	if (kauth_authorize_machdep(kauth_cred_get(), KAUTH_MACHDEP_UNMANAGEDMEM,
    547 	    NULL, NULL, NULL, NULL) != 0) {
    548 		aprint_normal("%s: permission to mmap denied.\n",
    549 		    device_xname(gp->g_device));
    550 		return -1;
    551 	}
    552 
    553 	if ((off >= (bus_addr_t)gp->g_fbkva ) &&
    554 	    (off < ( (bus_addr_t)gp->g_fbkva + (size_t)gi->gd_fbsize)))
    555 		return grf_wsmmap_md(off);
    556 
    557 	/* Handle register mapping */
    558 	if ((off >= (bus_addr_t)gi->gd_regaddr) &&
    559 	    (off < ((bus_addr_t)gi->gd_regaddr + (size_t)gi->gd_regsize)))
    560 		return grf_wsmmap_md(off);
    561 
    562 	return -1;
    563 }
    564 
    565 static paddr_t
    566 grf_wsmmap_md(off_t off)
    567 {
    568 #if defined(__m68k__)
    569 	return (paddr_t) m68k_btop(off);
    570 #else
    571 	return -1; /* FIXME */
    572 #endif
    573 }
    574 
    575 int
    576 grf_wsioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
    577 {
    578 	struct vcons_data *vd;
    579 	struct grf_softc *gp;
    580 
    581 	vd = v;
    582 	gp = vd->cookie;
    583 
    584 	switch (cmd) {
    585 	/* XXX: check if ptr to implementation is not null */
    586 	case WSDISPLAYIO_GINFO:
    587 		return gp->g_wsioctl->ginfo(gp, data);
    588 	case WSDISPLAYIO_SMODE:
    589 		return gp->g_wsioctl->smode(gp, data);
    590 	case WSDISPLAYIO_GMODE:
    591 		return gp->g_wsioctl->gmode(gp, data);
    592 	case WSDISPLAYIO_GTYPE:
    593 		return gp->g_wsioctl->gtype(gp, data);
    594 	case WSDISPLAYIO_SVIDEO:
    595 		return gp->g_wsioctl->svideo(gp, data);
    596 	case WSDISPLAYIO_GVIDEO:
    597 		return gp->g_wsioctl->gvideo(gp, data);
    598 	case WSDISPLAYIO_GETCMAP:
    599 		return gp->g_wsioctl->getcmap(gp, data);
    600 	case WSDISPLAYIO_PUTCMAP:
    601 		return gp->g_wsioctl->putcmap(gp, data);
    602 	}
    603 
    604 	return EPASSTHROUGH;
    605 }
    606 
    607 /* wsdisplay_accessops ioctls */
    608 
    609 int
    610 grf_wsaogetcmap(void *c, void *data)
    611 {
    612 	u_int index, count;
    613 	struct grf_softc *gp;
    614 	struct wsdisplay_cmap *cm;
    615 
    616 	cm = (struct wsdisplay_cmap*) data;
    617 	gp = c;
    618 	index = 0;
    619 	count = 0;
    620 
    621 	if (gp->g_wsmode == WSDISPLAYIO_MODE_EMUL)
    622 		return EINVAL;
    623 
    624 	if (index >= 255 || count > 256 || index + count > 256)
    625 		return EINVAL;
    626 
    627 	/*
    628 	 * TODO: copyout values for r, g, b. This function should be
    629 	 * driver-specific...
    630 	 */
    631 
    632 	return 0;
    633 }
    634 
    635 int
    636 grf_wsaoputcmap(void *c, void *data)
    637 {
    638 	/*
    639 	 * We probably couldn't care less about color map in MODE_EMUL,
    640 	 * I don't know about X11 yet. Also, these ioctls could be used by
    641 	 * fullscreen console programs (think wsdisplay picture viewer, or
    642 	 * the wsimgshow tool written by Yasushi Oshima).
    643 	 */
    644 	struct grf_softc *gp;
    645 
    646 	gp = c;
    647 
    648 	if (gp->g_wsmode == WSDISPLAYIO_MODE_EMUL)
    649 		return EINVAL;
    650 	/* ... */
    651 
    652 	return 0;
    653 }
    654 
    655 int
    656 grf_wsaosvideo(void *c, void *data)
    657 {
    658 #if 0
    659 	struct grf_softc *gp;
    660 	dev_t dev;
    661 	int rv;
    662 
    663 	gp = c;
    664 	dev = (dev_t) &gp->g_grfdev;
    665 
    666 	if (*(u_int *)data == WSDISPLAYIO_VIDEO_OFF) {
    667 		if ((gp->g_flags & GF_GRFON) == 0)
    668 			rv = 0;
    669 		else {
    670 			gp->g_flags &= ~GF_GRFON;
    671 			rv = gp->g_mode(gp, (dev & GRFOVDEV) ?
    672 			    GM_GRFOVOFF : GM_GRFOFF, NULL, 0, 0);
    673 		}
    674 
    675 	} else {
    676 		if ((gp->g_flags & GF_GRFON))
    677         		rv = 0;
    678 		else
    679 			gp->g_flags |= GF_GRFON;
    680 			rv = gp->g_mode(gp, (dev & GRFOVDEV) ?
    681 			    GM_GRFOVON : GM_GRFON, NULL, 0, 0);
    682 	}
    683 
    684 	return rv;
    685 #endif
    686 	return 0;
    687 }
    688 
    689 int
    690 grf_wsaogvideo(void *c, void *data)
    691 {
    692 	struct grf_softc *gp;
    693 
    694 	gp = c;
    695 
    696 	if(gp->g_flags & GF_GRFON)
    697 		*(u_int *)data = WSDISPLAYIO_VIDEO_ON;
    698 	else
    699 		*(u_int *)data = WSDISPLAYIO_VIDEO_OFF;
    700 
    701 	return 0;
    702 }
    703 
    704 int
    705 grf_wsaogtype(void *c, void *data)
    706 {
    707 	struct grf_softc *gp;
    708 
    709 	gp = c;
    710 
    711 	*(u_int *)data = WSDISPLAY_TYPE_GRF;
    712 	return 0;
    713 }
    714 
    715 int
    716 grf_wsaogmode(void *c, void *data)
    717 {
    718 	struct grf_softc *gp;
    719 
    720 	gp = c;
    721 
    722 	*(u_int *)data = gp->g_wsmode;
    723 	return 0;
    724 }
    725 
    726 int
    727 grf_wsaosmode(void *c, void *data)
    728 {
    729 	/* XXX: should provide hw-dependent impl of this in grf_xxx driver? */
    730 	struct grf_softc *gp;
    731 
    732 	gp = c;
    733 
    734 	if ((*(int*) data) != gp->g_wsmode) {
    735 		gp->g_wsmode = (*(int*) data);
    736 		if ((*(int*) data) == WSDISPLAYIO_MODE_EMUL) {
    737 			//vcons_redraw_screen( active vcons screen );
    738 		}
    739 	}
    740 	return 0;
    741 }
    742 
    743 int
    744 grf_wsaoginfo(void *c, void *data)
    745 {
    746 	struct wsdisplay_fbinfo *fbinfo;
    747 	struct grf_softc *gp;
    748 	struct grfinfo *gi;
    749 
    750 	gp = c;
    751 
    752 	fbinfo = (struct wsdisplay_fbinfo *)data;
    753 	gi = &gp->g_display;
    754 
    755 	/*
    756 	 * TODO: better sanity checking, it is possible that
    757 	 * wsdisplay is initialized, but no screen is opened
    758 	 * (for example, device is not used).
    759 	 */
    760 
    761 	/*
    762 	 * We shold return truth about current mode here because
    763 	 * X11 wsfb driver denepds on this!
    764 	 */
    765 	fbinfo->height = gi->gd_fbheight;
    766 	fbinfo->width = gi->gd_fbwidth;
    767 	fbinfo->depth = gi->gd_planes;
    768 	fbinfo->cmsize = gi->gd_colors;
    769 
    770 	return 0;
    771 }
    772 
    773 #endif  /* NWSDISPLAY > 0 */
    774 
    775 #ifdef DEBUG
    776 void
    777 grfdebug(struct grf_softc *gp, const char *fmt, ...)
    778 {
    779 	static int ccol = 0, crow = 1;
    780 	volatile char *cp;
    781 	char buf[256];
    782 	va_list ap;
    783 	int ncols;
    784 	char *bp;
    785 
    786 	va_start(ap, fmt);
    787 	vsnprintf(buf, 256, fmt, ap);
    788 	va_end(ap);
    789 
    790 	cp = gp->g_fbkva;
    791 	ncols = gp->g_display.gd_fbwidth / 8;
    792 	cp += (crow * ncols + ccol) << 2;
    793 	for (bp = buf; *bp != '\0'; bp++) {
    794 		if (*bp == '\n') {
    795 			ccol = 0;
    796 			crow++;
    797 			continue;
    798 		}
    799 		*cp++ = *bp;
    800 		*cp = 0x0a;
    801 		cp += 3;
    802 		ccol++;
    803 	}
    804 }
    805 #endif  /* DEBUG */
    806 
    807 #endif	/* NGRF > 0 */
    808