Home | History | Annotate | Line # | Download | only in dev
grf.c revision 1.66
      1  1.66   thorpej /*	$NetBSD: grf.c,v 1.66 2021/04/27 14:48:28 thorpej 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.66   thorpej __KERNEL_RCSID(0, "$NetBSD: grf.c,v 1.66 2021/04/27 14:48:28 thorpej 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.11    chopps #include <amiga/dev/grfvar.h>
     80  1.11    chopps #include <amiga/dev/itevar.h>
     81  1.57       phx #include <amiga/dev/kbdvar.h>
     82  1.26     veego #include <amiga/dev/viewioctl.h>
     83  1.26     veego 
     84  1.26     veego #include <sys/conf.h>
     85   1.8    chopps 
     86  1.11    chopps #if NGRF > 0
     87   1.1        mw #include "ite.h"
     88   1.1        mw #if NITE == 0
     89   1.9    chopps #define	ite_on(u,f)
     90   1.9    chopps #define	ite_off(u,f)
     91   1.9    chopps #define ite_reinit(d)
     92   1.1        mw #endif
     93   1.1        mw 
     94  1.39   aymeric int grfon(dev_t);
     95  1.39   aymeric int grfoff(dev_t);
     96  1.39   aymeric int grfsinfo(dev_t, struct grfdyninfo *);
     97   1.1        mw 
     98  1.55      matt void grfattach(device_t, device_t, void *);
     99  1.55      matt int grfmatch(device_t, cfdata_t, void *);
    100  1.39   aymeric int grfprint(void *, const char *);
    101  1.57       phx #ifdef DEBUG
    102  1.57       phx void grfdebug(struct grf_softc *, const char *, ...);
    103  1.57       phx #endif
    104   1.1        mw /*
    105  1.39   aymeric  * pointers to grf drivers device structs
    106   1.1        mw  */
    107  1.11    chopps struct grf_softc *grfsp[NGRF];
    108  1.11    chopps 
    109  1.55      matt CFATTACH_DECL_NEW(grf, 0,
    110  1.44   thorpej     grfmatch, grfattach, NULL, NULL);
    111  1.11    chopps 
    112  1.42   gehenna dev_type_open(grfopen);
    113  1.42   gehenna dev_type_close(grfclose);
    114  1.42   gehenna dev_type_ioctl(grfioctl);
    115  1.42   gehenna dev_type_mmap(grfmmap);
    116  1.42   gehenna 
    117  1.42   gehenna const struct cdevsw grf_cdevsw = {
    118  1.60  dholland 	.d_open = grfopen,
    119  1.60  dholland 	.d_close = grfclose,
    120  1.60  dholland 	.d_read = nullread,
    121  1.60  dholland 	.d_write = nullwrite,
    122  1.60  dholland 	.d_ioctl = grfioctl,
    123  1.60  dholland 	.d_stop = nostop,
    124  1.60  dholland 	.d_tty = notty,
    125  1.60  dholland 	.d_poll = nopoll,
    126  1.60  dholland 	.d_mmap = grfmmap,
    127  1.60  dholland 	.d_kqfilter = nokqfilter,
    128  1.62  dholland 	.d_discard = nodiscard,
    129  1.60  dholland 	.d_flag = 0
    130  1.42   gehenna };
    131  1.42   gehenna 
    132  1.11    chopps /*
    133  1.11    chopps  * only used in console init.
    134  1.11    chopps  */
    135  1.55      matt static cfdata_t cfdata;
    136  1.11    chopps 
    137  1.57       phx #if NWSDISPLAY > 0
    138  1.57       phx static struct vcons_screen console_vcons;
    139  1.57       phx 
    140  1.57       phx static void grf_init_screen(void *, struct vcons_screen *, int, long *);
    141  1.57       phx static struct rasops_info *grf_setup_rasops(struct grf_softc *,
    142  1.57       phx     struct vcons_screen *);
    143  1.57       phx 
    144  1.57       phx cons_decl(grf);
    145  1.57       phx #endif
    146  1.57       phx 
    147  1.11    chopps /*
    148  1.39   aymeric  * match if the unit of grf matches its perspective
    149  1.11    chopps  * low level board driver.
    150  1.11    chopps  */
    151  1.11    chopps int
    152  1.59       chs grfmatch(device_t parent, cfdata_t cf, void *aux)
    153   1.1        mw {
    154  1.59       chs 	struct grf_softc *psc;
    155  1.25   thorpej 
    156  1.59       chs 	psc = device_private(parent);
    157  1.59       chs 	if (cf->cf_unit != psc->g_unit)
    158  1.11    chopps 		return(0);
    159  1.59       chs 	cfdata = cf;
    160  1.11    chopps 	return(1);
    161   1.1        mw }
    162   1.1        mw 
    163   1.1        mw /*
    164  1.57       phx  * Attach.. plug pointer in and print some info.
    165  1.57       phx  * Then try and attach a wsdisplay or ite to us.
    166  1.59       chs  * Note: self is NULL durring console init.
    167   1.1        mw  */
    168  1.11    chopps void
    169  1.59       chs grfattach(device_t parent, device_t self, void *aux)
    170   1.1        mw {
    171  1.57       phx #if NWSDISPLAY > 0
    172  1.57       phx 	struct wsemuldisplaydev_attach_args wa;
    173  1.57       phx 	long defattr;
    174  1.57       phx #endif
    175  1.11    chopps 	struct grf_softc *gp;
    176  1.11    chopps 	int maj;
    177  1.11    chopps 
    178  1.59       chs 	gp = device_private(parent);
    179  1.59       chs 	gp->g_device = self;
    180  1.59       chs 	grfsp[gp->g_unit] = gp;
    181   1.1        mw 
    182  1.11    chopps 	/*
    183  1.63       phx 	 * find our major device number, make device
    184  1.11    chopps 	 */
    185  1.42   gehenna 	maj = cdevsw_lookup_major(&grf_cdevsw);
    186  1.63       phx 	gp->g_grfdev = makedev(maj, gp->g_unit);
    187  1.11    chopps 
    188  1.59       chs 	if (self != NULL) {
    189  1.31  christos 		printf(": width %d height %d", gp->g_display.gd_dwidth,
    190  1.11    chopps 		    gp->g_display.gd_dheight);
    191  1.11    chopps 		if (gp->g_display.gd_colors == 2)
    192  1.31  christos 			printf(" monochrome\n");
    193  1.11    chopps 		else
    194  1.31  christos 			printf(" colors %d\n", gp->g_display.gd_colors);
    195  1.63       phx 
    196  1.57       phx #if NWSDISPLAY > 0
    197  1.63       phx 		vcons_init(&gp->g_vd, gp, gp->g_defaultscr, gp->g_accessops);
    198  1.57       phx 		gp->g_vd.init_screen = grf_init_screen;
    199  1.63       phx 
    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.63       phx 			gp->g_defaultscr->textops =
    205  1.57       phx 			    &console_vcons.scr_ri.ri_ops;
    206  1.63       phx 			wsdisplay_cnattach(gp->g_defaultscr,
    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.63       phx 		wa.scrdata = gp->g_scrlist;
    214  1.57       phx 		wa.accessops = gp->g_accessops;
    215  1.57       phx 		wa.accesscookie = &gp->g_vd;
    216  1.66   thorpej 		config_found(self, &wa, wsemuldisplaydevprint,
    217  1.66   thorpej 		    CFARG_IATTR, "wsemuldisplaydev",
    218  1.66   thorpej 		    CFARG_EOL);
    219  1.57       phx #endif  /* NWSDISPLAY > 0 */
    220  1.11    chopps 	}
    221  1.39   aymeric 
    222  1.57       phx #if NWSDISPLAY == 0
    223  1.11    chopps 	/*
    224  1.11    chopps 	 * try and attach an ite
    225  1.11    chopps 	 */
    226  1.66   thorpej 	amiga_config_found(cfdata, self, gp, grfprint,
    227  1.66   thorpej 	    CFARG_IATTR, "grf",
    228  1.66   thorpej 	    CFARG_EOL);
    229  1.57       phx #endif
    230   1.1        mw }
    231   1.1        mw 
    232  1.11    chopps int
    233  1.59       chs grfprint(void *aux, const char *pnp)
    234  1.11    chopps {
    235  1.11    chopps 	if (pnp)
    236  1.47   thorpej 		aprint_normal("ite at %s", pnp);
    237  1.11    chopps 	return(UNCONF);
    238   1.1        mw }
    239   1.1        mw 
    240   1.1        mw /*ARGSUSED*/
    241  1.11    chopps int
    242  1.49  christos grfopen(dev_t dev, int flags, int devtype, struct lwp *l)
    243   1.1        mw {
    244  1.11    chopps 	struct grf_softc *gp;
    245  1.11    chopps 
    246  1.24       jtc 	if (GRFUNIT(dev) >= NGRF || (gp = grfsp[GRFUNIT(dev)]) == NULL)
    247  1.11    chopps 		return(ENXIO);
    248  1.11    chopps 
    249  1.11    chopps 	if ((gp->g_flags & GF_ALIVE) == 0)
    250   1.1        mw 		return(ENXIO);
    251  1.11    chopps 
    252   1.1        mw 	if ((gp->g_flags & (GF_OPEN|GF_EXCLUDE)) == (GF_OPEN|GF_EXCLUDE))
    253   1.1        mw 		return(EBUSY);
    254  1.11    chopps 
    255  1.11    chopps 	return(0);
    256   1.1        mw }
    257   1.1        mw 
    258   1.1        mw /*ARGSUSED*/
    259  1.11    chopps int
    260  1.49  christos grfclose(dev_t dev, int flags, int mode, struct lwp *l)
    261   1.1        mw {
    262  1.11    chopps 	struct grf_softc *gp;
    263   1.1        mw 
    264  1.11    chopps 	gp = grfsp[GRFUNIT(dev)];
    265  1.11    chopps 	(void)grfoff(dev);
    266   1.1        mw 	gp->g_flags &= GF_ALIVE;
    267   1.1        mw 	return(0);
    268   1.1        mw }
    269   1.1        mw 
    270   1.1        mw /*ARGSUSED*/
    271  1.11    chopps int
    272  1.50  christos grfioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
    273   1.1        mw {
    274  1.11    chopps 	struct grf_softc *gp;
    275   1.1        mw 	int error;
    276   1.1        mw 
    277  1.11    chopps 	gp = grfsp[GRFUNIT(dev)];
    278   1.1        mw 	error = 0;
    279  1.11    chopps 
    280   1.1        mw 	switch (cmd) {
    281   1.5        mw 	case OGRFIOCGINFO:
    282   1.5        mw 	        /* argl.. no bank-member.. */
    283  1.52    cegger 	  	memcpy(data, (void *)&gp->g_display, sizeof(struct grfinfo)-4);
    284   1.5        mw 		break;
    285   1.1        mw 	case GRFIOCGINFO:
    286  1.52    cegger 		memcpy(data, (void *)&gp->g_display, sizeof(struct grfinfo));
    287   1.1        mw 		break;
    288   1.1        mw 	case GRFIOCON:
    289   1.1        mw 		error = grfon(dev);
    290   1.1        mw 		break;
    291   1.1        mw 	case GRFIOCOFF:
    292   1.1        mw 		error = grfoff(dev);
    293   1.1        mw 		break;
    294   1.1        mw 	case GRFIOCSINFO:
    295  1.11    chopps 		error = grfsinfo(dev, (struct grfdyninfo *) data);
    296   1.1        mw 		break;
    297   1.3        mw 	case GRFGETVMODE:
    298  1.26     veego 		return(gp->g_mode(gp, GM_GRFGETVMODE, data, 0, 0));
    299   1.3        mw 	case GRFSETVMODE:
    300  1.26     veego 		error = gp->g_mode(gp, GM_GRFSETVMODE, data, 0, 0);
    301  1.18    chopps 		if (error == 0 && gp->g_itedev && !(gp->g_flags & GF_GRFON))
    302  1.11    chopps 			ite_reinit(gp->g_itedev);
    303   1.3        mw 		break;
    304   1.3        mw 	case GRFGETNUMVM:
    305  1.26     veego 		return(gp->g_mode(gp, GM_GRFGETNUMVM, data, 0, 0));
    306  1.11    chopps 	/*
    307  1.56       wiz 	 * these are all hardware dependent, and have to be resolved
    308  1.11    chopps 	 * in the respective driver.
    309  1.11    chopps 	 */
    310   1.5        mw 	case GRFIOCPUTCMAP:
    311   1.5        mw 	case GRFIOCGETCMAP:
    312   1.5        mw 	case GRFIOCSSPRITEPOS:
    313   1.5        mw 	case GRFIOCGSPRITEPOS:
    314   1.5        mw 	case GRFIOCSSPRITEINF:
    315   1.5        mw 	case GRFIOCGSPRITEINF:
    316   1.5        mw 	case GRFIOCGSPRITEMAX:
    317  1.18    chopps 	case GRFIOCBITBLT:
    318  1.20    chopps     	case GRFIOCSETMON:
    319  1.17    chopps 	case GRFTOGGLE: /* Toggles between Cirrus boards and native ECS on
    320  1.17    chopps                      Amiga. 15/11/94 ill */
    321  1.22    chopps 		/*
    322  1.22    chopps 		 * We need the minor dev number to get the overlay/image
    323  1.22    chopps 		 * information for grf_ul.
    324  1.22    chopps 		 */
    325  1.26     veego 		return(gp->g_mode(gp, GM_GRFIOCTL, data, cmd, dev));
    326  1.27        is 
    327  1.34        is 	case GRFIOCBLANK:	/* blank ioctl, IOCON/OFF will turn ite on */
    328  1.27        is 	case FBIOSVIDEO:
    329  1.34        is 		error = gp->g_mode(gp, GM_GRFIOCTL, data, GRFIOCBLANK, dev);
    330  1.34        is 		if (!error)
    331  1.34        is 			gp->g_blank = *(int *)data;
    332  1.34        is 		return (error);
    333  1.34        is 
    334  1.34        is 	case FBIOGVIDEO:
    335  1.34        is 		*(int *)data = gp->g_blank;
    336  1.34        is 		return (0);
    337  1.27        is 
    338   1.1        mw 	default:
    339  1.21    chopps #if NVIEW > 0
    340  1.11    chopps 		/*
    341  1.11    chopps 		 * check to see whether it's a command recognized by the
    342  1.11    chopps 		 * view code if the unit is 0
    343  1.39   aymeric 		 * XXX
    344  1.11    chopps 		 */
    345  1.42   gehenna 		if (GRFUNIT(dev) == 0) {
    346  1.42   gehenna 			extern const struct cdevsw view_cdevsw;
    347  1.42   gehenna 
    348  1.49  christos 			return((*view_cdevsw.d_ioctl)(dev, cmd, data, flag, l));
    349  1.42   gehenna 		}
    350  1.21    chopps #endif
    351  1.41    atatat 		error = EPASSTHROUGH;
    352   1.1        mw 		break;
    353   1.1        mw 
    354   1.1        mw 	}
    355   1.1        mw 	return(error);
    356   1.1        mw }
    357   1.1        mw 
    358  1.11    chopps /*
    359  1.39   aymeric  * map the contents of a graphics display card into process'
    360  1.11    chopps  * memory space.
    361  1.11    chopps  */
    362  1.35    simonb paddr_t
    363  1.39   aymeric grfmmap(dev_t dev, off_t off, int prot)
    364   1.1        mw {
    365  1.11    chopps 	struct grf_softc *gp;
    366  1.11    chopps 	struct grfinfo *gi;
    367  1.39   aymeric 
    368  1.11    chopps 	gp = grfsp[GRFUNIT(dev)];
    369  1.11    chopps 	gi = &gp->g_display;
    370   1.1        mw 
    371  1.39   aymeric 	/*
    372  1.11    chopps 	 * control registers
    373  1.11    chopps 	 */
    374  1.11    chopps 	if (off >= 0 && off < gi->gd_regsize)
    375  1.64       phx 		return MD_BTOP((paddr_t)gi->gd_regaddr + off);
    376   1.1        mw 
    377  1.11    chopps 	/*
    378  1.11    chopps 	 * frame buffer
    379  1.11    chopps 	 */
    380  1.11    chopps 	if (off >= gi->gd_regsize && off < gi->gd_regsize+gi->gd_fbsize) {
    381  1.11    chopps 		off -= gi->gd_regsize;
    382  1.64       phx 		return MD_BTOP((paddr_t)gi->gd_fbaddr + off);
    383   1.1        mw 	}
    384  1.11    chopps 	/* bogus */
    385  1.11    chopps 	return(-1);
    386   1.1        mw }
    387   1.1        mw 
    388  1.11    chopps int
    389  1.39   aymeric grfon(dev_t dev)
    390   1.1        mw {
    391  1.11    chopps 	struct grf_softc *gp;
    392   1.1        mw 
    393  1.11    chopps 	gp = grfsp[GRFUNIT(dev)];
    394   1.1        mw 
    395   1.3        mw 	if (gp->g_flags & GF_GRFON)
    396  1.11    chopps 		return(0);
    397  1.11    chopps 
    398   1.3        mw 	gp->g_flags |= GF_GRFON;
    399  1.11    chopps 	if (gp->g_itedev != NODEV)
    400  1.11    chopps 		ite_off(gp->g_itedev, 3);
    401   1.3        mw 
    402  1.26     veego 	return(gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVON : GM_GRFON,
    403  1.26     veego 							NULL, 0, 0));
    404   1.1        mw }
    405   1.1        mw 
    406  1.11    chopps int
    407  1.39   aymeric grfoff(dev_t dev)
    408   1.1        mw {
    409  1.11    chopps 	struct grf_softc *gp;
    410   1.1        mw 	int error;
    411   1.3        mw 
    412  1.11    chopps 	gp = grfsp[GRFUNIT(dev)];
    413  1.11    chopps 
    414  1.11    chopps 	if ((gp->g_flags & GF_GRFON) == 0)
    415  1.11    chopps 		return(0);
    416  1.11    chopps 
    417   1.3        mw 	gp->g_flags &= ~GF_GRFON;
    418  1.26     veego 	error = gp->g_mode(gp, (dev & GRFOVDEV) ? GM_GRFOVOFF : GM_GRFOFF,
    419  1.26     veego 							NULL, 0, 0);
    420  1.11    chopps 
    421  1.11    chopps 	/*
    422  1.11    chopps 	 * Closely tied together no X's
    423  1.11    chopps 	 */
    424  1.11    chopps 	if (gp->g_itedev != NODEV)
    425  1.11    chopps 		ite_on(gp->g_itedev, 2);
    426   1.1        mw 
    427   1.1        mw 	return(error);
    428   1.1        mw }
    429   1.1        mw 
    430  1.11    chopps int
    431  1.39   aymeric grfsinfo(dev_t dev, struct grfdyninfo *dyninfo)
    432   1.1        mw {
    433  1.11    chopps 	struct grf_softc *gp;
    434   1.1        mw 	int error;
    435   1.1        mw 
    436  1.11    chopps 	gp = grfsp[GRFUNIT(dev)];
    437  1.26     veego 	error = gp->g_mode(gp, GM_GRFCONFIG, dyninfo, 0, 0);
    438   1.1        mw 
    439  1.11    chopps 	/*
    440  1.11    chopps 	 * Closely tied together no X's
    441  1.11    chopps 	 */
    442  1.11    chopps 	if (gp->g_itedev != NODEV)
    443  1.11    chopps 		ite_reinit(gp->g_itedev);
    444   1.1        mw 	return(error);
    445   1.1        mw }
    446   1.1        mw 
    447  1.57       phx #if NWSDISPLAY > 0
    448  1.57       phx void
    449  1.57       phx grfcnprobe(struct consdev *cd)
    450  1.57       phx {
    451  1.57       phx 	struct grf_softc *gp;
    452  1.57       phx 	int unit;
    453  1.57       phx 
    454  1.57       phx 	/*
    455  1.57       phx 	 * Find the first working grf device for being console.
    456  1.57       phx 	 * Ignore unit 0 (grfcc), which should use amidisplaycc instead.
    457  1.57       phx 	 */
    458  1.57       phx 	for (unit = 1; unit < NGRF; unit++) {
    459  1.57       phx 		gp = grfsp[unit];
    460  1.57       phx 		if (gp != NULL && (gp->g_flags & GF_ALIVE)) {
    461  1.57       phx 			cd->cn_pri = CN_INTERNAL;
    462  1.57       phx 			cd->cn_dev = NODEV;  /* initialized later by wscons */
    463  1.57       phx 			return;
    464  1.57       phx 		}
    465  1.57       phx 	}
    466  1.57       phx 
    467  1.57       phx 	/* no grf console alive */
    468  1.57       phx 	cd->cn_pri = CN_DEAD;
    469  1.57       phx }
    470  1.57       phx 
    471  1.57       phx void
    472  1.57       phx grfcninit(struct consdev *cd)
    473  1.57       phx {
    474  1.57       phx 	struct grf_softc *gp;
    475  1.57       phx 	struct rasops_info *ri;
    476  1.57       phx 	long defattr;
    477  1.57       phx 	int unit;
    478  1.57       phx 
    479  1.57       phx 	/* find console grf and set up wsdisplay for it */
    480  1.57       phx 	for (unit = 1; unit < NGRF; unit++) {
    481  1.57       phx 		gp = grfsp[unit];
    482  1.57       phx 		if (gp != NULL && (gp->g_flags & GF_ALIVE)) {
    483  1.57       phx 			gp->g_flags |= GF_CONSOLE;  /* we are console! */
    484  1.63       phx 
    485  1.63       phx 			gp->g_defaultscr->ncols = gp->g_display.gd_fbwidth /
    486  1.63       phx 			    gp->g_defaultscr->fontwidth;
    487  1.63       phx 			gp->g_defaultscr->nrows = gp->g_display.gd_fbheight /
    488  1.63       phx 			    gp->g_defaultscr->fontheight;
    489  1.57       phx 
    490  1.57       phx 			ri = grf_setup_rasops(gp, &console_vcons);
    491  1.57       phx 			console_vcons.scr_cookie = gp;
    492  1.57       phx 			defattr = 0;  /* XXX */
    493  1.57       phx 
    494  1.63       phx 			wsdisplay_preattach(gp->g_defaultscr, ri, 0, 0,
    495  1.57       phx 			    defattr);
    496  1.57       phx #if NKBD > 0
    497  1.57       phx 			/* tell kbd device it is used as console keyboard */
    498  1.57       phx 			kbd_cnattach();
    499  1.57       phx #endif
    500  1.57       phx 			return;
    501  1.57       phx 		}
    502  1.57       phx 	}
    503  1.57       phx 	panic("grfcninit: lost console");
    504  1.57       phx }
    505  1.57       phx 
    506  1.57       phx static void
    507  1.57       phx grf_init_screen(void *cookie, struct vcons_screen *scr, int existing,
    508  1.57       phx     long *defattr)
    509  1.57       phx {
    510  1.57       phx 	struct grf_softc *gp;
    511  1.61   mlelstv 	struct rasops_info *ri __unused;
    512  1.57       phx 
    513  1.57       phx 	gp = cookie;
    514  1.57       phx 	ri = grf_setup_rasops(gp, scr);
    515  1.57       phx }
    516  1.57       phx 
    517  1.57       phx static struct rasops_info *
    518  1.57       phx grf_setup_rasops(struct grf_softc *gp, struct vcons_screen *scr)
    519  1.57       phx {
    520  1.57       phx 	struct rasops_info *ri;
    521  1.57       phx 	int i;
    522  1.57       phx 
    523  1.57       phx 	ri = &scr->scr_ri;
    524  1.57       phx 	scr->scr_flags |= VCONS_DONT_READ;
    525  1.57       phx 	memset(ri, 0, sizeof(struct rasops_info));
    526  1.57       phx 
    527  1.63       phx 	ri->ri_rows = gp->g_defaultscr->nrows;
    528  1.63       phx 	ri->ri_cols = gp->g_defaultscr->ncols;
    529  1.57       phx 	ri->ri_hw = scr;
    530  1.57       phx 	ri->ri_ops.cursor    = gp->g_emulops->cursor;
    531  1.57       phx 	ri->ri_ops.mapchar   = gp->g_emulops->mapchar;
    532  1.57       phx 	ri->ri_ops.copyrows  = gp->g_emulops->copyrows;
    533  1.57       phx 	ri->ri_ops.eraserows = gp->g_emulops->eraserows;
    534  1.57       phx 	ri->ri_ops.copycols  = gp->g_emulops->copycols;
    535  1.57       phx 	ri->ri_ops.erasecols = gp->g_emulops->erasecols;
    536  1.57       phx 	ri->ri_ops.putchar   = gp->g_emulops->putchar;
    537  1.57       phx 	ri->ri_ops.allocattr = gp->g_emulops->allocattr;
    538  1.57       phx 
    539  1.57       phx 	/* multiplication table for row-offsets */
    540  1.57       phx 	for (i = 0; i < ri->ri_rows; i++)
    541  1.57       phx 		gp->g_rowoffset[i] = i * ri->ri_cols;
    542  1.57       phx 
    543  1.57       phx 	return ri;
    544  1.57       phx }
    545  1.57       phx 
    546  1.63       phx /*
    547  1.63       phx  * Called as fallback for ioctls which are not handled by the specific
    548  1.63       phx  * grf driver.
    549  1.63       phx  */
    550  1.63       phx int
    551  1.63       phx grf_wsioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
    552  1.63       phx {
    553  1.63       phx 	struct wsdisplayio_fbinfo *iofbi;
    554  1.63       phx 	struct wsdisplay_fbinfo *fbinfo;
    555  1.63       phx 	struct vcons_data *vd;
    556  1.63       phx 	struct grf_softc *gp;
    557  1.63       phx 	struct vcons_screen *scr;
    558  1.63       phx 	struct grfinfo *gi;
    559  1.63       phx 
    560  1.63       phx 	vd = v;
    561  1.63       phx 	gp = vd->cookie;
    562  1.63       phx 	scr = vd->active;
    563  1.63       phx 
    564  1.63       phx 	switch (cmd) {
    565  1.63       phx 	case WSDISPLAYIO_GET_FBINFO:
    566  1.63       phx 		if (scr != NULL) {
    567  1.63       phx 			iofbi = data;
    568  1.63       phx 			return wsdisplayio_get_fbinfo(&scr->scr_ri, iofbi);
    569  1.63       phx 		}
    570  1.63       phx 		return ENODEV;
    571  1.63       phx 
    572  1.63       phx 	case WSDISPLAYIO_GINFO:
    573  1.63       phx 		if (scr != NULL) {
    574  1.63       phx 			fbinfo = (struct wsdisplay_fbinfo *)data;
    575  1.63       phx 			gi = &gp->g_display;
    576  1.63       phx 
    577  1.63       phx 			/*
    578  1.63       phx 			 * We should return truth about the current mode here,
    579  1.63       phx 			 * because X11 wsfb driver depends on this!
    580  1.63       phx 			 */
    581  1.63       phx 			fbinfo->height = gi->gd_fbheight;
    582  1.63       phx 			fbinfo->width = gi->gd_fbwidth;
    583  1.63       phx 			fbinfo->depth = gi->gd_planes;
    584  1.63       phx 			fbinfo->cmsize = gi->gd_colors;
    585  1.63       phx 			return 0;
    586  1.63       phx 		}
    587  1.63       phx 		return ENODEV;
    588  1.63       phx 
    589  1.63       phx 	case WSDISPLAYIO_GTYPE:
    590  1.63       phx 		*(u_int *)data = WSDISPLAY_TYPE_GRF;
    591  1.63       phx 		return 0;
    592  1.63       phx 
    593  1.63       phx 	case WSDISPLAYIO_SMODE:
    594  1.63       phx 		if ((*(int *)data) != gp->g_wsmode) {
    595  1.63       phx 			gp->g_wsmode = *(int *)data;
    596  1.63       phx 			if (gp->g_wsmode == WSDISPLAYIO_MODE_EMUL &&
    597  1.63       phx 			    scr != NULL)
    598  1.63       phx 				vcons_redraw_screen(scr);
    599  1.63       phx 		}
    600  1.63       phx 		return 0;
    601  1.63       phx 	}
    602  1.63       phx 
    603  1.63       phx 	return EPASSTHROUGH;
    604  1.63       phx }
    605  1.63       phx 
    606  1.57       phx paddr_t
    607  1.57       phx grf_wsmmap(void *v, void *vs, off_t off, int prot)
    608  1.57       phx {
    609  1.57       phx 	struct vcons_data *vd;
    610  1.57       phx 	struct grf_softc *gp;
    611  1.57       phx 	struct grfinfo *gi;
    612  1.57       phx 
    613  1.57       phx 	vd = v;
    614  1.57       phx 	gp = vd->cookie;
    615  1.57       phx 	gi = &gp->g_display;
    616  1.57       phx 
    617  1.57       phx 	/* Normal fb mapping */
    618  1.57       phx 	if (off < gi->gd_fbsize)
    619  1.64       phx 		return MD_BTOP(((paddr_t)gi->gd_fbaddr) + off);
    620  1.57       phx 
    621  1.64       phx 	/*
    622  1.64       phx 	 * restrict all other mappings to processes with superuser privileges
    623  1.64       phx 	 * or the kernel itself
    624  1.64       phx 	 */
    625  1.58      elad 	if (kauth_authorize_machdep(kauth_cred_get(), KAUTH_MACHDEP_UNMANAGEDMEM,
    626  1.58      elad 	    NULL, NULL, NULL, NULL) != 0) {
    627  1.57       phx 		aprint_normal("%s: permission to mmap denied.\n",
    628  1.59       chs 		    device_xname(gp->g_device));
    629  1.57       phx 		return -1;
    630  1.57       phx 	}
    631  1.57       phx 
    632  1.57       phx 	/* Handle register mapping */
    633  1.64       phx 	if ((off >= (paddr_t)gi->gd_regaddr) &&
    634  1.64       phx 	    (off < ((paddr_t)gi->gd_regaddr + (size_t)gi->gd_regsize)))
    635  1.64       phx 		return MD_BTOP(off);
    636  1.64       phx 
    637  1.64       phx 	if ((off >= (paddr_t)gi->gd_fbaddr) &&
    638  1.64       phx 	    (off < ((paddr_t)gi->gd_fbaddr + (size_t)gi->gd_fbsize)))
    639  1.64       phx 		return MD_BTOP(off);
    640  1.57       phx 
    641  1.57       phx 	return -1;
    642  1.57       phx }
    643  1.57       phx 
    644  1.57       phx #endif  /* NWSDISPLAY > 0 */
    645  1.57       phx 
    646   1.1        mw #endif	/* NGRF > 0 */
    647