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