Home | History | Annotate | Line # | Download | only in obio
grf_obio.c revision 1.18
      1  1.18  briggs /*	$OpenBSD: grf_iv.c,v 1.13 1997/03/29 03:16:18 briggs Exp $	*/
      2  1.18  briggs /*	$NetBSD: grf_obio.c,v 1.18 1997/04/01 05:41:59 briggs Exp $	*/
      3   1.1  briggs 
      4   1.1  briggs /*
      5   1.1  briggs  * Copyright (c) 1995 Allen Briggs.  All rights reserved.
      6   1.1  briggs  *
      7   1.1  briggs  * Redistribution and use in source and binary forms, with or without
      8   1.1  briggs  * modification, are permitted provided that the following conditions
      9   1.1  briggs  * are met:
     10   1.1  briggs  * 1. Redistributions of source code must retain the above copyright
     11   1.1  briggs  *    notice, this list of conditions and the following disclaimer.
     12   1.1  briggs  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  briggs  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  briggs  *    documentation and/or other materials provided with the distribution.
     15   1.1  briggs  * 3. All advertising materials mentioning features or use of this software
     16   1.1  briggs  *    must display the following acknowledgement:
     17   1.1  briggs  *	This product includes software developed by Allen Briggs.
     18   1.1  briggs  * 4. The name of the author may not be used to endorse or promote products
     19   1.1  briggs  *    derived from this software without specific prior written permission.
     20   1.1  briggs  *
     21   1.1  briggs  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22   1.1  briggs  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23   1.1  briggs  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24   1.1  briggs  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25   1.1  briggs  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26   1.1  briggs  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27   1.1  briggs  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28   1.1  briggs  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29   1.1  briggs  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30   1.1  briggs  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31   1.1  briggs  */
     32   1.1  briggs /*
     33   1.1  briggs  * Graphics display driver for the Macintosh internal video for machines
     34   1.1  briggs  * that don't map it into a fake nubus card.
     35   1.1  briggs  */
     36   1.1  briggs 
     37   1.1  briggs #include <sys/param.h>
     38   1.1  briggs 
     39   1.1  briggs #include <sys/device.h>
     40   1.1  briggs #include <sys/ioctl.h>
     41   1.1  briggs #include <sys/file.h>
     42   1.1  briggs #include <sys/malloc.h>
     43   1.1  briggs #include <sys/mman.h>
     44   1.1  briggs #include <sys/proc.h>
     45  1.11  briggs #include <sys/systm.h>
     46   1.1  briggs 
     47  1.18  briggs #include <machine/autoconf.h>
     48  1.17  scottr #include <machine/bus.h>
     49  1.17  scottr #include <machine/cpu.h>
     50   1.1  briggs #include <machine/grfioctl.h>
     51  1.18  briggs #include <machine/viareg.h>
     52   1.1  briggs 
     53   1.1  briggs #include "nubus.h"
     54  1.18  briggs #include "obiovar.h"
     55   1.1  briggs #include "grfvar.h"
     56   1.1  briggs 
     57   1.5  briggs extern u_int32_t	mac68k_vidlog;
     58   1.5  briggs extern u_int32_t	mac68k_vidphys;
     59  1.10  briggs extern long		videorowbytes;
     60  1.10  briggs extern long		videobitdepth;
     61  1.10  briggs extern unsigned long	videosize;
     62   1.5  briggs 
     63  1.11  briggs static int	grfiv_mode __P((struct grf_softc *gp, int cmd, void *arg));
     64  1.11  briggs static caddr_t	grfiv_phys __P((struct grf_softc *gp, vm_offset_t addr));
     65  1.16  scottr static int	grfiv_match __P((struct device *, struct cfdata *, void *));
     66  1.11  briggs static void	grfiv_attach __P((struct device *, struct device *, void *));
     67  1.11  briggs 
     68  1.12  scottr struct cfdriver intvid_cd = {
     69  1.12  scottr 	NULL, "intvid", DV_DULL
     70  1.12  scottr };
     71  1.12  scottr 
     72  1.12  scottr struct cfattach intvid_ca = {
     73  1.12  scottr 	sizeof(struct grfbus_softc), grfiv_match, grfiv_attach
     74  1.11  briggs };
     75  1.11  briggs 
     76  1.18  briggs #define QUADRA_DAFB_BASE	0xF9800000
     77  1.18  briggs 
     78  1.11  briggs static int
     79  1.16  scottr grfiv_match(parent, cf, aux)
     80  1.16  scottr 	struct device *parent;
     81  1.16  scottr 	struct cfdata *cf;
     82  1.16  scottr 	void *aux;
     83   1.1  briggs {
     84  1.18  briggs 	struct obio_attach_args *oa = (struct obio_attach_args *) aux;
     85  1.18  briggs 	bus_space_handle_t	bsh;
     86  1.18  briggs 	int			found, sense;
     87  1.18  briggs 
     88  1.18  briggs 	found = 1;
     89  1.18  briggs 
     90  1.18  briggs         switch (current_mac_model->class) {
     91  1.18  briggs         case MACH_CLASSQ:
     92  1.18  briggs         case MACH_CLASSQ2:
     93  1.18  briggs 
     94  1.18  briggs 		/* Assume DAFB for all of these */
     95  1.18  briggs 
     96  1.18  briggs 		if (bus_space_map(oa->oa_tag, QUADRA_DAFB_BASE, 0x1000,
     97  1.18  briggs 					0, &bsh)) {
     98  1.18  briggs 			panic("failed to map space for DAFB regs.\n");
     99  1.18  briggs 		}
    100  1.18  briggs 
    101  1.18  briggs 		sense = (bus_space_read_4(oa->oa_tag, bsh, 0x1C) & 7);
    102  1.18  briggs 
    103  1.18  briggs 		if (sense == 0)
    104  1.18  briggs 			found = 0;
    105  1.18  briggs 
    106  1.18  briggs 		/* Set "Turbo SCSI" configuration to default */
    107  1.18  briggs 		bus_space_write_4(oa->oa_tag, bsh, 0x24, 0x1d1); /* ch0 */
    108  1.18  briggs 		bus_space_write_4(oa->oa_tag, bsh, 0x28, 0x1d1); /* ch1 */
    109   1.1  briggs 
    110  1.18  briggs 		/* Disable interrupts */
    111  1.18  briggs 		bus_space_write_4(oa->oa_tag, bsh, 0x104, 0);
    112  1.18  briggs 
    113  1.18  briggs 		/* Clear any interrupts */
    114  1.18  briggs 		bus_space_write_4(oa->oa_tag, bsh, 0x10C, 0);
    115  1.18  briggs 		bus_space_write_4(oa->oa_tag, bsh, 0x110, 0);
    116  1.18  briggs 		bus_space_write_4(oa->oa_tag, bsh, 0x114, 0);
    117  1.18  briggs 
    118  1.18  briggs 		bus_space_unmap(oa->oa_tag, bsh, 0x1000);
    119  1.18  briggs 
    120  1.18  briggs 		break;
    121  1.18  briggs 
    122  1.18  briggs 	default:
    123  1.18  briggs 		if (mac68k_vidlog == 0) {
    124  1.18  briggs 			found = 0;
    125  1.18  briggs 		}
    126  1.18  briggs 
    127  1.18  briggs 		break;
    128   1.2  briggs 	}
    129   1.7  briggs 
    130  1.18  briggs 	return found;
    131   1.1  briggs }
    132   1.1  briggs 
    133  1.18  briggs #define R4(sc, o) (bus_space_read_4((sc)->sc_tag, (sc)->sc_regh, o) & 0xfff)
    134  1.18  briggs 
    135  1.11  briggs static void
    136  1.11  briggs grfiv_attach(parent, self, aux)
    137  1.11  briggs 	struct device *parent, *self;
    138  1.11  briggs 	void   *aux;
    139   1.1  briggs {
    140  1.18  briggs 	struct obio_attach_args *oa = (struct obio_attach_args *) aux;
    141  1.12  scottr 	struct grfbus_softc	*sc;
    142  1.11  briggs 	struct grfmode		*gm;
    143  1.11  briggs 
    144  1.12  scottr 	sc = (struct grfbus_softc *) self;
    145   1.1  briggs 
    146   1.1  briggs 	sc->card_id = 0;
    147   1.1  briggs 
    148  1.18  briggs         switch (current_mac_model->class) {
    149  1.18  briggs         case MACH_CLASSQ:
    150  1.18  briggs         case MACH_CLASSQ2:
    151  1.18  briggs 		sc->sc_tag = oa->oa_tag;
    152  1.18  briggs 		if (bus_space_map(sc->sc_tag, QUADRA_DAFB_BASE, 0x1000,
    153  1.18  briggs 					0, &sc->sc_regh)) {
    154  1.18  briggs 			panic("failed to map space for DAFB regs.\n");
    155  1.18  briggs 		}
    156  1.18  briggs 		printf(": DAFB: Monitor sense %x.\n", R4(sc,0x1C)&7);
    157  1.18  briggs 		break;
    158  1.18  briggs 	default:
    159  1.18  briggs 		printf(": Internal Video\n");
    160  1.18  briggs 		break;
    161  1.18  briggs 	}
    162   1.1  briggs 
    163   1.1  briggs 	gm = &(sc->curr_mode);
    164   1.1  briggs 	gm->mode_id = 0;
    165  1.10  briggs 	gm->psize = videobitdepth;
    166   1.1  briggs 	gm->ptype = 0;
    167  1.10  briggs 	gm->width = videosize & 0xffff;
    168  1.10  briggs 	gm->height = (videosize >> 16) & 0xffff;
    169  1.10  briggs 	gm->rowbytes = videorowbytes;
    170   1.1  briggs 	gm->hres = 80;		/* XXX Hack */
    171   1.1  briggs 	gm->vres = 80;		/* XXX Hack */
    172  1.10  briggs 	gm->fbsize = gm->rowbytes * gm->height;
    173  1.18  briggs 	gm->fbbase = (caddr_t) mac68k_trunc_page(mac68k_vidlog);
    174  1.18  briggs 	gm->fboff = mac68k_vidlog & PGOFSET;
    175   1.1  briggs 
    176  1.12  scottr 	/* Perform common video attachment. */
    177  1.13  scottr 	grf_establish(sc, NULL, grfiv_mode, grfiv_phys);
    178   1.1  briggs }
    179   1.1  briggs 
    180  1.11  briggs static int
    181   1.1  briggs grfiv_mode(sc, cmd, arg)
    182   1.1  briggs 	struct grf_softc *sc;
    183   1.1  briggs 	int cmd;
    184   1.1  briggs 	void *arg;
    185   1.1  briggs {
    186   1.4  briggs 	switch (cmd) {
    187   1.4  briggs 	case GM_GRFON:
    188   1.4  briggs 	case GM_GRFOFF:
    189   1.4  briggs 		return 0;
    190   1.4  briggs 	case GM_CURRMODE:
    191   1.4  briggs 		break;
    192   1.4  briggs 	case GM_NEWMODE:
    193   1.4  briggs 		break;
    194   1.4  briggs 	case GM_LISTMODES:
    195   1.4  briggs 		break;
    196   1.4  briggs 	}
    197   1.4  briggs 	return EINVAL;
    198   1.5  briggs }
    199   1.5  briggs 
    200  1.11  briggs static caddr_t
    201   1.5  briggs grfiv_phys(gp, addr)
    202   1.5  briggs 	struct grf_softc *gp;
    203   1.5  briggs 	vm_offset_t addr;
    204   1.5  briggs {
    205   1.5  briggs 	/*
    206   1.5  briggs 	 * If we're using IIsi or similar, this will be 0.
    207   1.5  briggs 	 * If we're using IIvx or similar, this will be correct.
    208   1.5  briggs 	 */
    209   1.5  briggs 	return (caddr_t) mac68k_vidphys;
    210   1.1  briggs }
    211