Home | History | Annotate | Line # | Download | only in obio
grf_obio.c revision 1.31
      1  1.31  scottr /*	$NetBSD: grf_obio.c,v 1.31 1998/03/22 23:40:52 scottr 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  * Graphics display driver for the Macintosh internal video for machines
     33   1.1  briggs  * that don't map it into a fake nubus card.
     34   1.1  briggs  */
     35   1.1  briggs 
     36   1.1  briggs #include <sys/param.h>
     37   1.1  briggs 
     38   1.1  briggs #include <sys/device.h>
     39   1.1  briggs #include <sys/ioctl.h>
     40   1.1  briggs #include <sys/file.h>
     41   1.1  briggs #include <sys/malloc.h>
     42   1.1  briggs #include <sys/mman.h>
     43   1.1  briggs #include <sys/proc.h>
     44  1.11  briggs #include <sys/systm.h>
     45   1.1  briggs 
     46  1.18  briggs #include <machine/autoconf.h>
     47  1.17  scottr #include <machine/bus.h>
     48  1.17  scottr #include <machine/cpu.h>
     49   1.1  briggs #include <machine/grfioctl.h>
     50  1.18  briggs #include <machine/viareg.h>
     51   1.1  briggs 
     52  1.22  scottr #include <mac68k/dev/nubus.h>
     53  1.22  scottr #include <mac68k/dev/obiovar.h>
     54  1.22  scottr #include <mac68k/dev/grfvar.h>
     55   1.1  briggs 
     56   1.5  briggs extern u_int32_t	mac68k_vidlog;
     57   1.5  briggs extern u_int32_t	mac68k_vidphys;
     58  1.10  briggs extern long		videorowbytes;
     59  1.10  briggs extern long		videobitdepth;
     60  1.22  scottr extern u_long		videosize;
     61   1.5  briggs 
     62  1.11  briggs static int	grfiv_mode __P((struct grf_softc *gp, int cmd, void *arg));
     63  1.24  scottr static caddr_t	grfiv_phys __P((struct grf_softc *gp));
     64  1.16  scottr static int	grfiv_match __P((struct device *, struct cfdata *, void *));
     65  1.11  briggs static void	grfiv_attach __P((struct device *, struct device *, void *));
     66  1.12  scottr 
     67  1.12  scottr struct cfattach intvid_ca = {
     68  1.12  scottr 	sizeof(struct grfbus_softc), grfiv_match, grfiv_attach
     69  1.11  briggs };
     70  1.11  briggs 
     71  1.18  briggs #define QUADRA_DAFB_BASE	0xF9800000
     72  1.25  briggs #define CIVIC_CONTROL_BASE	0x50036000
     73  1.30  scottr #define VALKYRIE_CONTROL_BASE	0x50f2A000
     74  1.18  briggs 
     75  1.11  briggs static int
     76  1.16  scottr grfiv_match(parent, cf, aux)
     77  1.16  scottr 	struct device *parent;
     78  1.16  scottr 	struct cfdata *cf;
     79  1.16  scottr 	void *aux;
     80   1.1  briggs {
     81  1.22  scottr 	struct obio_attach_args *oa = (struct obio_attach_args *)aux;
     82  1.22  scottr 	bus_space_handle_t bsh;
     83  1.22  scottr 	int found, sense;
     84  1.27  scottr 	u_int base;
     85  1.18  briggs 
     86  1.18  briggs 	found = 1;
     87  1.18  briggs 
     88  1.27  scottr 	switch (current_mac_model->class) {
     89  1.20  briggs 	case MACH_CLASSQ:
     90  1.20  briggs 		/*
     91  1.20  briggs 		 * Assume DAFB for all of these, unless we can't
     92  1.20  briggs 		 * access the memory.
     93  1.20  briggs 		 */
     94  1.26  briggs 		base = QUADRA_DAFB_BASE;
     95  1.18  briggs 
     96  1.26  briggs 		if (bus_space_map(oa->oa_tag, base, 0x1000, 0, &bsh)) {
     97  1.18  briggs 			panic("failed to map space for DAFB regs.\n");
     98  1.18  briggs 		}
     99  1.18  briggs 
    100  1.29  scottr 		if (mac68k_bus_space_probe(oa->oa_tag, bsh, 0x1C, 4) == 0) {
    101  1.20  briggs 			bus_space_unmap(oa->oa_tag, bsh, 0x1000);
    102  1.20  briggs 			found = 0;
    103  1.20  briggs 			goto nodafb;
    104  1.20  briggs 		}
    105  1.20  briggs 
    106  1.18  briggs 		sense = (bus_space_read_4(oa->oa_tag, bsh, 0x1C) & 7);
    107  1.18  briggs 
    108  1.31  scottr #if 0 /* XXX - fails on Quadras with certain 17" monitors */
    109  1.18  briggs 		if (sense == 0)
    110  1.18  briggs 			found = 0;
    111  1.31  scottr #endif
    112  1.18  briggs 
    113  1.18  briggs 		/* Set "Turbo SCSI" configuration to default */
    114  1.18  briggs 		bus_space_write_4(oa->oa_tag, bsh, 0x24, 0x1d1); /* ch0 */
    115  1.18  briggs 		bus_space_write_4(oa->oa_tag, bsh, 0x28, 0x1d1); /* ch1 */
    116   1.1  briggs 
    117  1.18  briggs 		/* Disable interrupts */
    118  1.18  briggs 		bus_space_write_4(oa->oa_tag, bsh, 0x104, 0);
    119  1.18  briggs 
    120  1.18  briggs 		/* Clear any interrupts */
    121  1.18  briggs 		bus_space_write_4(oa->oa_tag, bsh, 0x10C, 0);
    122  1.18  briggs 		bus_space_write_4(oa->oa_tag, bsh, 0x110, 0);
    123  1.18  briggs 		bus_space_write_4(oa->oa_tag, bsh, 0x114, 0);
    124  1.18  briggs 
    125  1.18  briggs 		bus_space_unmap(oa->oa_tag, bsh, 0x1000);
    126  1.18  briggs 		break;
    127  1.18  briggs 
    128  1.27  scottr 	case MACH_CLASSAV:
    129  1.26  briggs 		base = CIVIC_CONTROL_BASE;
    130  1.26  briggs 
    131  1.26  briggs 		if (bus_space_map(oa->oa_tag, base, 0x1000, 0, &bsh)) {
    132  1.25  briggs 			panic("failed to map space for CIVIC control regs.\n");
    133  1.25  briggs 		}
    134  1.27  scottr 
    135  1.25  briggs 		/* Disable interrupts */
    136  1.25  briggs 		bus_space_write_1(oa->oa_tag, bsh, 0x120, 0);
    137  1.26  briggs 
    138  1.25  briggs 		bus_space_unmap(oa->oa_tag, bsh, 0x1000);
    139  1.25  briggs 		break;
    140  1.25  briggs 
    141  1.26  briggs 	case MACH_CLASSQ2:
    142  1.30  scottr 		if (current_mac_model->machineid == MACH_MACQ630) {
    143  1.30  scottr 			base = VALKYRIE_CONTROL_BASE;
    144  1.30  scottr 
    145  1.30  scottr 			if (bus_space_map(oa->oa_tag, base, 0x40, 0, &bsh)) {
    146  1.30  scottr 				panic("failed to map space for Valkyrie regs.\n");
    147  1.30  scottr 			}
    148  1.30  scottr 
    149  1.30  scottr 			/* Disable interrupts */
    150  1.30  scottr 			bus_space_write_1(oa->oa_tag, bsh, 0x18, 0x1);
    151  1.30  scottr 		}
    152  1.26  briggs 		break;
    153  1.26  briggs 
    154  1.18  briggs 	default:
    155  1.20  briggs nodafb:
    156  1.18  briggs 		if (mac68k_vidlog == 0) {
    157  1.18  briggs 			found = 0;
    158  1.18  briggs 		}
    159  1.18  briggs 		break;
    160   1.2  briggs 	}
    161   1.7  briggs 
    162  1.18  briggs 	return found;
    163   1.1  briggs }
    164   1.1  briggs 
    165  1.18  briggs #define R4(sc, o) (bus_space_read_4((sc)->sc_tag, (sc)->sc_regh, o) & 0xfff)
    166  1.18  briggs 
    167  1.11  briggs static void
    168  1.11  briggs grfiv_attach(parent, self, aux)
    169  1.11  briggs 	struct device *parent, *self;
    170  1.11  briggs 	void   *aux;
    171   1.1  briggs {
    172  1.22  scottr 	struct obio_attach_args *oa = (struct obio_attach_args *)aux;
    173  1.22  scottr 	struct grfbus_softc *sc;
    174  1.22  scottr 	struct grfmode *gm;
    175  1.27  scottr 	u_int base;
    176  1.11  briggs 
    177  1.22  scottr 	sc = (struct grfbus_softc *)self;
    178   1.1  briggs 
    179   1.1  briggs 	sc->card_id = 0;
    180   1.1  briggs 
    181  1.27  scottr 	switch (current_mac_model->class) {
    182  1.27  scottr 	case MACH_CLASSQ:
    183  1.27  scottr 		base = QUADRA_DAFB_BASE;
    184  1.18  briggs 		sc->sc_tag = oa->oa_tag;
    185  1.26  briggs 		if (bus_space_map(sc->sc_tag, base, 0x1000, 0, &sc->sc_regh)) {
    186  1.18  briggs 			panic("failed to map space for DAFB regs.\n");
    187  1.18  briggs 		}
    188  1.18  briggs 		printf(": DAFB: Monitor sense %x.\n", R4(sc,0x1C)&7);
    189  1.25  briggs 		bus_space_unmap(sc->sc_tag, sc->sc_regh, 0x1000);
    190  1.18  briggs 		break;
    191  1.27  scottr 	case MACH_CLASSQ2:
    192  1.27  scottr 	case MACH_CLASSAV:
    193  1.18  briggs 	default:
    194  1.18  briggs 		printf(": Internal Video\n");
    195  1.18  briggs 		break;
    196  1.18  briggs 	}
    197   1.1  briggs 
    198   1.1  briggs 	gm = &(sc->curr_mode);
    199   1.1  briggs 	gm->mode_id = 0;
    200  1.10  briggs 	gm->psize = videobitdepth;
    201   1.1  briggs 	gm->ptype = 0;
    202  1.10  briggs 	gm->width = videosize & 0xffff;
    203  1.10  briggs 	gm->height = (videosize >> 16) & 0xffff;
    204  1.10  briggs 	gm->rowbytes = videorowbytes;
    205   1.1  briggs 	gm->hres = 80;		/* XXX Hack */
    206   1.1  briggs 	gm->vres = 80;		/* XXX Hack */
    207  1.10  briggs 	gm->fbsize = gm->rowbytes * gm->height;
    208  1.22  scottr 	gm->fbbase = (caddr_t)m68k_trunc_page(mac68k_vidlog);
    209  1.18  briggs 	gm->fboff = mac68k_vidlog & PGOFSET;
    210   1.1  briggs 
    211  1.12  scottr 	/* Perform common video attachment. */
    212  1.13  scottr 	grf_establish(sc, NULL, grfiv_mode, grfiv_phys);
    213   1.1  briggs }
    214   1.1  briggs 
    215  1.11  briggs static int
    216   1.1  briggs grfiv_mode(sc, cmd, arg)
    217   1.1  briggs 	struct grf_softc *sc;
    218   1.1  briggs 	int cmd;
    219   1.1  briggs 	void *arg;
    220   1.1  briggs {
    221   1.4  briggs 	switch (cmd) {
    222   1.4  briggs 	case GM_GRFON:
    223   1.4  briggs 	case GM_GRFOFF:
    224   1.4  briggs 		return 0;
    225   1.4  briggs 	case GM_CURRMODE:
    226   1.4  briggs 		break;
    227   1.4  briggs 	case GM_NEWMODE:
    228   1.4  briggs 		break;
    229   1.4  briggs 	case GM_LISTMODES:
    230   1.4  briggs 		break;
    231   1.4  briggs 	}
    232   1.4  briggs 	return EINVAL;
    233   1.5  briggs }
    234   1.5  briggs 
    235  1.11  briggs static caddr_t
    236  1.23  scottr grfiv_phys(gp)
    237   1.5  briggs 	struct grf_softc *gp;
    238   1.5  briggs {
    239   1.5  briggs 	/*
    240   1.5  briggs 	 * If we're using IIsi or similar, this will be 0.
    241   1.5  briggs 	 * If we're using IIvx or similar, this will be correct.
    242   1.5  briggs 	 */
    243  1.22  scottr 	return (caddr_t)mac68k_vidphys;
    244   1.1  briggs }
    245