Home | History | Annotate | Line # | Download | only in nubus
grf_nubus.c revision 1.22
      1  1.22    briggs /*	$NetBSD: grf_nubus.c,v 1.22 1997/05/01 03:34:07 briggs Exp $	*/
      2   1.1    briggs 
      3   1.1    briggs /*
      4   1.1    briggs  * Copyright (c) 1995 Allen Briggs.  All rights reserved.
      5   1.1    briggs  *
      6   1.1    briggs  * Redistribution and use in source and binary forms, with or without
      7   1.1    briggs  * modification, are permitted provided that the following conditions
      8   1.1    briggs  * are met:
      9   1.1    briggs  * 1. Redistributions of source code must retain the above copyright
     10   1.1    briggs  *    notice, this list of conditions and the following disclaimer.
     11   1.1    briggs  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1    briggs  *    notice, this list of conditions and the following disclaimer in the
     13   1.1    briggs  *    documentation and/or other materials provided with the distribution.
     14   1.1    briggs  * 3. All advertising materials mentioning features or use of this software
     15   1.1    briggs  *    must display the following acknowledgement:
     16   1.1    briggs  *	This product includes software developed by Allen Briggs.
     17   1.1    briggs  * 4. The name of the author may not be used to endorse or promote products
     18   1.1    briggs  *    derived from this software without specific prior written permission.
     19   1.1    briggs  *
     20   1.1    briggs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21   1.1    briggs  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22   1.1    briggs  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23   1.1    briggs  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24   1.1    briggs  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25   1.1    briggs  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26   1.1    briggs  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27   1.1    briggs  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28   1.1    briggs  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29   1.1    briggs  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30   1.1    briggs  */
     31   1.1    briggs /*
     32   1.1    briggs  * Device-specific routines for handling Nubus-based video cards.
     33   1.1    briggs  */
     34   1.1    briggs 
     35   1.1    briggs #include <sys/param.h>
     36   1.1    briggs 
     37   1.1    briggs #include <sys/device.h>
     38   1.1    briggs #include <sys/ioctl.h>
     39   1.1    briggs #include <sys/file.h>
     40   1.1    briggs #include <sys/malloc.h>
     41   1.1    briggs #include <sys/mman.h>
     42   1.1    briggs #include <sys/proc.h>
     43   1.8    briggs #include <sys/systm.h>
     44   1.1    briggs 
     45  1.16    scottr #include <machine/bus.h>
     46   1.8    briggs #include <machine/cpu.h>
     47   1.1    briggs #include <machine/grfioctl.h>
     48   1.8    briggs #include <machine/viareg.h>
     49   1.1    briggs 
     50   1.1    briggs #include "nubus.h"
     51   1.1    briggs #include "grfvar.h"
     52   1.1    briggs 
     53   1.8    briggs static void	load_image_data __P((caddr_t data, struct image_data *image));
     54   1.1    briggs 
     55  1.18    briggs static void	grfmv_intr_generic __P((void *vsc, int slot));
     56  1.18    briggs static void	grfmv_intr_cti __P((void *vsc, int slot));
     57  1.18    briggs static void	grfmv_intr_cb264 __P((void *vsc, int slot));
     58   1.1    briggs 
     59   1.8    briggs static int	grfmv_mode __P((struct grf_softc *gp, int cmd, void *arg));
     60   1.8    briggs static caddr_t	grfmv_phys __P((struct grf_softc *gp, vm_offset_t addr));
     61  1.15    scottr static int	grfmv_match __P((struct device *, struct cfdata *, void *));
     62   1.8    briggs static void	grfmv_attach __P((struct device *, struct device *, void *));
     63   1.8    briggs 
     64  1.11    scottr struct cfdriver macvid_cd = {
     65  1.11    scottr 	NULL, "macvid", DV_DULL
     66  1.11    scottr };
     67  1.11    scottr 
     68  1.11    scottr struct cfattach macvid_ca = {
     69  1.11    scottr 	sizeof(struct grfbus_softc), grfmv_match, grfmv_attach
     70   1.8    briggs };
     71   1.8    briggs 
     72   1.1    briggs static void
     73   1.1    briggs load_image_data(data, image)
     74   1.1    briggs 	caddr_t	data;
     75   1.1    briggs 	struct	image_data *image;
     76   1.1    briggs {
     77   1.1    briggs 	bcopy(data     , &image->size,       4);
     78   1.1    briggs 	bcopy(data +  4, &image->offset,     4);
     79   1.1    briggs 	bcopy(data +  8, &image->rowbytes,   2);
     80   1.1    briggs 	bcopy(data + 10, &image->top,        2);
     81   1.1    briggs 	bcopy(data + 12, &image->left,       2);
     82   1.1    briggs 	bcopy(data + 14, &image->bottom,     2);
     83   1.1    briggs 	bcopy(data + 16, &image->right,      2);
     84   1.1    briggs 	bcopy(data + 18, &image->version,    2);
     85   1.1    briggs 	bcopy(data + 20, &image->packType,   2);
     86   1.1    briggs 	bcopy(data + 22, &image->packSize,   4);
     87   1.1    briggs 	bcopy(data + 26, &image->hRes,       4);
     88   1.1    briggs 	bcopy(data + 30, &image->vRes,       4);
     89   1.1    briggs 	bcopy(data + 34, &image->pixelType,  2);
     90   1.1    briggs 	bcopy(data + 36, &image->pixelSize,  2);
     91   1.1    briggs 	bcopy(data + 38, &image->cmpCount,   2);
     92   1.1    briggs 	bcopy(data + 40, &image->cmpSize,    2);
     93   1.1    briggs 	bcopy(data + 42, &image->planeBytes, 4);
     94   1.1    briggs }
     95   1.1    briggs 
     96   1.1    briggs 
     97   1.7    briggs static int
     98  1.15    scottr grfmv_match(parent, cf, aux)
     99  1.11    scottr 	struct device *parent;
    100  1.15    scottr 	struct cfdata *cf;
    101  1.15    scottr 	void *aux;
    102   1.1    briggs {
    103  1.21    scottr 	struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
    104   1.1    briggs 
    105  1.15    scottr 	if (na->category != NUBUS_CATEGORY_DISPLAY)
    106   1.1    briggs 		return 0;
    107   1.1    briggs 
    108  1.15    scottr 	if (na->type != NUBUS_TYPE_VIDEO)
    109   1.1    briggs 		return 0;
    110   1.1    briggs 
    111  1.15    scottr 	if (na->drsw != NUBUS_DRSW_APPLE)
    112   1.1    briggs 		return 0;
    113   1.1    briggs 
    114   1.1    briggs 	/*
    115   1.1    briggs 	 * If we've gotten this far, then we're dealing with a real-live
    116   1.1    briggs 	 * Apple QuickDraw-compatible display card resource.  Now, how to
    117   1.1    briggs 	 * determine that this is an active resource???  Dunno.  But we'll
    118   1.1    briggs 	 * proceed like it is.
    119   1.1    briggs 	 */
    120   1.1    briggs 
    121   1.1    briggs 	return 1;
    122   1.1    briggs }
    123   1.1    briggs 
    124   1.8    briggs static void
    125   1.8    briggs grfmv_attach(parent, self, aux)
    126   1.8    briggs 	struct device *parent, *self;
    127   1.8    briggs 	void *aux;
    128   1.1    briggs {
    129  1.21    scottr 	struct grfbus_softc *sc = (struct grfbus_softc *)self;
    130  1.21    scottr 	struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
    131   1.1    briggs 	struct image_data image_store, image;
    132  1.15    scottr 	struct grfmode *gm;
    133  1.15    scottr 	char cardname[CARD_NAME_LEN];
    134  1.15    scottr 	nubus_dirent dirent;
    135  1.15    scottr 	nubus_dir dir, mode_dir;
    136  1.15    scottr 	int mode;
    137  1.15    scottr 
    138  1.15    scottr 	sc->card_id = na->drhw;
    139  1.15    scottr 
    140  1.15    scottr 	bcopy(na->fmt, &sc->sc_slot, sizeof(nubus_slot));
    141  1.15    scottr 
    142  1.15    scottr 	nubus_get_main_dir(&sc->sc_slot, &dir);
    143   1.1    briggs 
    144  1.15    scottr 	if (nubus_find_rsrc(&sc->sc_slot, &dir, na->rsrcid, &dirent) <= 0)
    145  1.15    scottr 		return;
    146  1.15    scottr 
    147  1.15    scottr 	nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &sc->board_dir);
    148  1.15    scottr 
    149  1.15    scottr 	if (nubus_find_rsrc(&sc->sc_slot, &sc->board_dir,
    150  1.15    scottr 	    NUBUS_RSRC_TYPE, &dirent) <= 0)
    151  1.15    scottr 		if ((na->rsrcid != 128) ||
    152  1.15    scottr 		    (nubus_find_rsrc(&sc->sc_slot, &dir, 129, &dirent) <= 0))
    153  1.15    scottr 			return;
    154   1.8    briggs 
    155   1.1    briggs 	mode = NUBUS_RSRC_FIRSTMODE;
    156   1.8    briggs 	if (nubus_find_rsrc(&sc->sc_slot, &sc->board_dir, mode, &dirent) <= 0) {
    157  1.14  christos 		printf("\n%s: probe failed to get board rsrc.\n",
    158  1.11    scottr 		    sc->sc_dev.dv_xname);
    159   1.8    briggs 		return;
    160   1.8    briggs 	}
    161   1.1    briggs 
    162   1.1    briggs 	nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &mode_dir);
    163   1.1    briggs 
    164   1.8    briggs 	if (nubus_find_rsrc(&sc->sc_slot, &mode_dir, VID_PARAMS, &dirent)
    165   1.8    briggs 	    <= 0) {
    166  1.14  christos 		printf("\n%s: probe failed to get mode dir.\n",
    167  1.11    scottr 		    sc->sc_dev.dv_xname);
    168   1.8    briggs 		return;
    169   1.8    briggs 	}
    170   1.1    briggs 
    171  1.21    scottr 	if (nubus_get_ind_data(&sc->sc_slot, &dirent, (caddr_t)&image_store,
    172   1.8    briggs 				sizeof(struct image_data)) <= 0) {
    173  1.14  christos 		printf("\n%s: probe failed to get indirect mode data.\n",
    174  1.11    scottr 		    sc->sc_dev.dv_xname);
    175   1.8    briggs 		return;
    176   1.8    briggs 	}
    177   1.1    briggs 
    178  1.15    scottr 	/* Need to load display info (and driver?), etc... (?) */
    179  1.15    scottr 
    180  1.21    scottr 	load_image_data((caddr_t)&image_store, &image);
    181   1.1    briggs 
    182  1.15    scottr 	gm = &sc->curr_mode;
    183  1.11    scottr 	gm->mode_id = mode;
    184  1.21    scottr 	gm->fbbase = (caddr_t)(sc->sc_slot.virtual_base + image.offset);
    185  1.11    scottr 	gm->fboff = image.offset;
    186  1.11    scottr 	gm->rowbytes = image.rowbytes;
    187  1.11    scottr 	gm->width = image.right - image.left;
    188  1.11    scottr 	gm->height = image.bottom - image.top;
    189  1.11    scottr 	gm->fbsize = sc->curr_mode.height * sc->curr_mode.rowbytes;
    190  1.11    scottr 	gm->hres = image.hRes;
    191  1.11    scottr 	gm->vres = image.vRes;
    192  1.11    scottr 	gm->ptype = image.pixelType;
    193  1.11    scottr 	gm->psize = image.pixelSize;
    194   1.1    briggs 
    195  1.11    scottr 	strncpy(cardname, nubus_get_card_name(&sc->sc_slot),
    196   1.1    briggs 		CARD_NAME_LEN);
    197  1.11    scottr 	cardname[CARD_NAME_LEN-1] = '\0';
    198  1.21    scottr 	printf(": %s\n", cardname);
    199   1.1    briggs 
    200  1.18    briggs 	if (sc->card_id == NUBUS_DRHW_TFB) {
    201  1.18    briggs 		/*
    202  1.18    briggs 		 * This is the Toby card, but apparently some manufacturers
    203  1.18    briggs 		 * (like Cornerstone) didn't bother to get/use their own
    204  1.18    briggs 		 * value here, even though the cards are different, so we
    205  1.18    briggs 		 * so we try to differentiate here.
    206  1.18    briggs 		 */
    207  1.21    scottr 		if (strncmp(cardname, "Samsung 768", 11) == 0)
    208  1.18    briggs 			sc->card_id = NUBUS_DRHW_SAM768;
    209  1.21    scottr 		else if (strncmp(cardname, "Toby frame", 10) != 0)
    210  1.21    scottr 			printf("%s: This display card pretends to be a TFB!",
    211  1.21    scottr 			    sc->sc_dev.dv_xname);
    212  1.18    briggs 	}
    213  1.18    briggs 
    214  1.18    briggs 	switch (sc->card_id) {
    215  1.18    briggs 	case NUBUS_DRHW_M2HRVC:
    216  1.18    briggs 	case NUBUS_DRHW_TFB:
    217  1.18    briggs 		sc->cli_offset = 0xa0000;
    218  1.22    briggs 		sc->cli_value = 0;
    219  1.18    briggs 		add_nubus_intr(sc->sc_slot.slot, grfmv_intr_generic, sc);
    220  1.18    briggs 		break;
    221  1.18    briggs 	case NUBUS_DRHW_WVC:
    222  1.18    briggs 		sc->cli_offset = 0xa00000;
    223  1.22    briggs 		sc->cli_value = 0;
    224  1.22    briggs 		add_nubus_intr(sc->sc_slot.slot, grfmv_intr_generic, sc);
    225  1.22    briggs 		break;
    226  1.22    briggs 	case NUBUS_DRHW_FIILX:
    227  1.22    briggs 	case NUBUS_DRHW_FIISXDSP:
    228  1.22    briggs 		sc->cli_offset = 0xF05000;
    229  1.22    briggs 		sc->cli_value = 0x80;
    230  1.18    briggs 		add_nubus_intr(sc->sc_slot.slot, grfmv_intr_generic, sc);
    231  1.18    briggs 		break;
    232  1.18    briggs 	case NUBUS_DRHW_SAM768:
    233  1.18    briggs 		add_nubus_intr(sc->sc_slot.slot, grfmv_intr_cti, sc);
    234  1.19    briggs 		break;
    235  1.19    briggs 	case NUBUS_DRHW_CB264:
    236  1.22    briggs 	case NUBUS_DRHW_CB364:
    237  1.19    briggs 		add_nubus_intr(sc->sc_slot.slot, grfmv_intr_cb264, sc);
    238  1.20    briggs 		break;
    239  1.20    briggs 	case NUBUS_DRHW_SE30:
    240  1.20    briggs 		/* Do nothing--SE/30 interrupts are disabled */
    241  1.18    briggs 		break;
    242  1.18    briggs 	case NUBUS_DRHW_MICRON:
    243  1.18    briggs 		/* What do we know about this one? */
    244  1.18    briggs 	default:
    245  1.21    scottr 		printf("%s: Unknown video card ID 0x%x --",
    246  1.21    scottr 		    sc->sc_dev.dv_xname, sc->card_id);
    247  1.21    scottr 		printf(" Not installing interrupt routine.\n");
    248  1.18    briggs 		break;
    249  1.18    briggs 	}
    250   1.1    briggs 
    251  1.11    scottr 	/* Perform common video attachment. */
    252  1.12    scottr 	grf_establish(sc, &sc->sc_slot, grfmv_mode, grfmv_phys);
    253   1.1    briggs }
    254   1.1    briggs 
    255   1.8    briggs static int
    256   1.1    briggs grfmv_mode(gp, cmd, arg)
    257   1.1    briggs 	struct grf_softc *gp;
    258   1.1    briggs 	int cmd;
    259   1.1    briggs 	void *arg;
    260   1.1    briggs {
    261   1.1    briggs 	switch (cmd) {
    262   1.4    briggs 	case GM_GRFON:
    263   1.4    briggs 	case GM_GRFOFF:
    264   1.4    briggs 		return 0;
    265   1.1    briggs 	case GM_CURRMODE:
    266   1.1    briggs 		break;
    267   1.1    briggs 	case GM_NEWMODE:
    268   1.1    briggs 		break;
    269   1.1    briggs 	case GM_LISTMODES:
    270   1.1    briggs 		break;
    271   1.1    briggs 	}
    272   1.1    briggs 	return EINVAL;
    273   1.6    briggs }
    274   1.6    briggs 
    275   1.8    briggs static caddr_t
    276   1.6    briggs grfmv_phys(gp, addr)
    277   1.6    briggs 	struct grf_softc *gp;
    278   1.6    briggs 	vm_offset_t addr;
    279   1.6    briggs {
    280  1.21    scottr 	return (caddr_t)(NUBUS_SLOT2PA(gp->sc_slot->slot) +
    281  1.11    scottr 				(addr - gp->sc_slot->virtual_base));
    282  1.18    briggs }
    283  1.18    briggs 
    284  1.18    briggs /* Interrupt handlers... */
    285  1.18    briggs /*
    286  1.18    briggs  * Generic routine to clear interrupts for cards where it simply takes
    287  1.18    briggs  * a CLR.B to clear the interrupt.  The offset of this byte varies between
    288  1.18    briggs  * cards.
    289  1.18    briggs  */
    290  1.18    briggs /*ARGSUSED*/
    291  1.18    briggs static void
    292  1.18    briggs grfmv_intr_generic(vsc, slot)
    293  1.18    briggs 	void	*vsc;
    294  1.18    briggs 	int	slot;
    295  1.18    briggs {
    296  1.21    scottr 	static char zero = 0;
    297  1.21    scottr 	struct grfbus_softc *sc;
    298  1.21    scottr 	volatile char *slotbase;
    299  1.18    briggs 
    300  1.21    scottr 	sc = (struct grfbus_softc *)vsc;
    301  1.21    scottr 	slotbase = (volatile char *)sc->sc_slot.virtual_base;
    302  1.18    briggs 	slotbase[sc->cli_offset] = zero;
    303  1.18    briggs }
    304  1.18    briggs 
    305  1.18    briggs /*
    306  1.18    briggs  * Routine to clear interrupts on Samsung 768x1006 video controller.
    307  1.18    briggs  * This controller was manufactured by Cornerstone Technology, Inc.,
    308  1.18    briggs  * now known as Cornerstone Imaging.
    309  1.18    briggs  *
    310  1.18    briggs  * To clear this interrupt, we apparently have to set, then clear,
    311  1.18    briggs  * bit 2 at byte offset 0x80000 from the card's base.
    312  1.18    briggs  *	Information for this provided by Brad Salai <bsalai (at) servtech.com>
    313  1.18    briggs  */
    314  1.18    briggs /*ARGSUSED*/
    315  1.18    briggs static void
    316  1.18    briggs grfmv_intr_cti(vsc, slot)
    317  1.18    briggs 	void	*vsc;
    318  1.18    briggs 	int	slot;
    319  1.18    briggs {
    320  1.21    scottr 	struct grfbus_softc *sc;
    321  1.21    scottr 	volatile char *slotbase;
    322  1.18    briggs 
    323  1.21    scottr 	sc = (struct grfbus_softc *)vsc;
    324  1.21    scottr 	slotbase = ((volatile char *)sc->sc_slot.virtual_base) + 0x00080000;
    325  1.18    briggs 	*slotbase = (*slotbase | 0x02);
    326  1.18    briggs 	*slotbase = (*slotbase & 0xFD);
    327  1.18    briggs }
    328  1.18    briggs 
    329  1.18    briggs /*ARGSUSED*/
    330  1.18    briggs static void
    331  1.18    briggs grfmv_intr_cb264(vsc, slot)
    332  1.18    briggs 	void	*vsc;
    333  1.18    briggs 	int	slot;
    334  1.18    briggs {
    335  1.18    briggs 	struct grfbus_softc *sc;
    336  1.21    scottr 	volatile char *slotbase;
    337  1.18    briggs 
    338  1.21    scottr 	sc = (struct grfbus_softc *)vsc;
    339  1.21    scottr 	slotbase = (volatile char *)sc->sc_slot.virtual_base;
    340  1.18    briggs 	asm volatile("	movl	%0,a0
    341  1.18    briggs 			movl	a0@(0xff6028),d0
    342  1.18    briggs 			andl	#0x2,d0
    343  1.18    briggs 			beq	_mv_intr0
    344  1.18    briggs 			movql	#0x3,d0
    345  1.18    briggs 		_mv_intr0:
    346  1.18    briggs 			movl	a0@(0xff600c),d1
    347  1.18    briggs 			andl	#0x3,d1
    348  1.18    briggs 			cmpl	d1,d0
    349  1.18    briggs 			beq	_mv_intr_fin
    350  1.18    briggs 			movl	d0,a0@(0xff600c)
    351  1.18    briggs 			nop
    352  1.18    briggs 			tstb	d0
    353  1.18    briggs 			beq	_mv_intr1
    354  1.18    briggs 			movl	#0x0002,a0@(0xff6040)
    355  1.18    briggs 			movl	#0x0102,a0@(0xff6044)
    356  1.18    briggs 			movl	#0x0105,a0@(0xff6048)
    357  1.18    briggs 			movl	#0x000e,a0@(0xff604c)
    358  1.18    briggs 			movl	#0x001c,a0@(0xff6050)
    359  1.18    briggs 			movl	#0x00bc,a0@(0xff6054)
    360  1.18    briggs 			movl	#0x00c3,a0@(0xff6058)
    361  1.18    briggs 			movl	#0x0061,a0@(0xff605c)
    362  1.18    briggs 			movl	#0x0012,a0@(0xff6060)
    363  1.18    briggs 			bra	_mv_intr_fin
    364  1.18    briggs 		_mv_intr1:
    365  1.18    briggs 			movl	#0x0002,a0@(0xff6040)
    366  1.18    briggs 			movl	#0x0209,a0@(0xff6044)
    367  1.18    briggs 			movl	#0x020c,a0@(0xff6048)
    368  1.18    briggs 			movl	#0x000f,a0@(0xff604c)
    369  1.18    briggs 			movl	#0x0027,a0@(0xff6050)
    370  1.18    briggs 			movl	#0x00c7,a0@(0xff6054)
    371  1.18    briggs 			movl	#0x00d7,a0@(0xff6058)
    372  1.18    briggs 			movl	#0x006b,a0@(0xff605c)
    373  1.18    briggs 			movl	#0x0029,a0@(0xff6060)
    374  1.18    briggs 		_mv_intr_fin:
    375  1.18    briggs 			movl	#0x1,a0@(0xff6014)"
    376  1.18    briggs 		: : "g" (slotbase) : "a0","d0","d1");
    377   1.1    briggs }
    378