Home | History | Annotate | Line # | Download | only in obio
grf_obio.c revision 1.36
      1 /*	$NetBSD: grf_obio.c,v 1.36 1998/08/12 02:36:38 scottr Exp $	*/
      2 
      3 /*
      4  * Copyright (C) 1998 Scott Reynolds
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 /*
     30  * Copyright (c) 1995 Allen Briggs.  All rights reserved.
     31  *
     32  * Redistribution and use in source and binary forms, with or without
     33  * modification, are permitted provided that the following conditions
     34  * are met:
     35  * 1. Redistributions of source code must retain the above copyright
     36  *    notice, this list of conditions and the following disclaimer.
     37  * 2. Redistributions in binary form must reproduce the above copyright
     38  *    notice, this list of conditions and the following disclaimer in the
     39  *    documentation and/or other materials provided with the distribution.
     40  * 3. All advertising materials mentioning features or use of this software
     41  *    must display the following acknowledgement:
     42  *	This product includes software developed by Allen Briggs.
     43  * 4. The name of the author may not be used to endorse or promote products
     44  *    derived from this software without specific prior written permission.
     45  *
     46  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     47  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     48  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     49  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     50  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     51  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     52  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     53  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     54  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     55  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     56  */
     57 /*
     58  * Graphics display driver for the Macintosh internal video for machines
     59  * that don't map it into a fake nubus card.
     60  */
     61 
     62 #include "opt_grf.h"
     63 
     64 #include <sys/param.h>
     65 #include <sys/device.h>
     66 #include <sys/ioctl.h>
     67 #include <sys/file.h>
     68 #include <sys/malloc.h>
     69 #include <sys/mman.h>
     70 #include <sys/proc.h>
     71 #include <sys/systm.h>
     72 
     73 #include <machine/autoconf.h>
     74 #include <machine/bus.h>
     75 #include <machine/cpu.h>
     76 #include <machine/grfioctl.h>
     77 #include <machine/viareg.h>
     78 
     79 #include <mac68k/nubus/nubus.h>
     80 #include <mac68k/obio/obiovar.h>
     81 #include <mac68k/dev/grfvar.h>
     82 
     83 extern u_int32_t	mac68k_vidphys;
     84 extern u_int32_t	mac68k_vidlen;
     85 extern long		videoaddr;
     86 extern long		videorowbytes;
     87 extern long		videobitdepth;
     88 extern u_long		videosize;
     89 
     90 static int	grfiv_mode __P((struct grf_softc *gp, int cmd, void *arg));
     91 static int	grfiv_match __P((struct device *, struct cfdata *, void *));
     92 static void	grfiv_attach __P((struct device *, struct device *, void *));
     93 
     94 struct cfattach intvid_ca = {
     95 	sizeof(struct grfbus_softc), grfiv_match, grfiv_attach
     96 };
     97 
     98 #define	DAFB_BASE		0xf9000000
     99 #define DAFB_CONTROL_BASE	0xf9800000
    100 #define	CIVIC_BASE		0x50100000
    101 #define CIVIC_CONTROL_BASE	0x50036000
    102 #define	VALKYRIE_BASE		0xf9000000
    103 #define VALKYRIE_CONTROL_BASE	0x50f2a000
    104 
    105 static int
    106 grfiv_match(parent, cf, aux)
    107 	struct device *parent;
    108 	struct cfdata *cf;
    109 	void *aux;
    110 {
    111 	struct obio_attach_args *oa = (struct obio_attach_args *)aux;
    112 	bus_space_handle_t bsh;
    113 	int found;
    114 	u_int base;
    115 
    116 	found = 1;
    117 
    118 	switch (current_mac_model->class) {
    119 	case MACH_CLASSQ2:
    120 		if (current_mac_model->machineid != MACH_MACLC575) {
    121 			base = VALKYRIE_CONTROL_BASE;
    122 
    123 			if (bus_space_map(oa->oa_tag, base, 0x40, 0, &bsh))
    124 				return 0;
    125 
    126 			/* Disable interrupts */
    127 			bus_space_write_1(oa->oa_tag, bsh, 0x18, 0x1);
    128 		}
    129 		/*
    130 		 * Note:  the only system in this class that does not have
    131 		 * the Valkyrie chip -- at least, that we know of -- is
    132 		 * the Performa/LC 57x series.  This system has a version
    133 		 * of the DAFB controller, instead.
    134 		 *
    135 		 * If this assumption proves false, we'll have to be more
    136 		 * intelligent here.
    137 		 */
    138 		/*FALLTHROUGH*/
    139 	case MACH_CLASSQ:
    140 		/*
    141 		 * Assume DAFB for all of these, unless we can't
    142 		 * access the memory.
    143 		 */
    144 		base = DAFB_CONTROL_BASE;
    145 
    146 		if (bus_space_map(oa->oa_tag, base, 0x1000, 0, &bsh))
    147 			return 0;
    148 
    149 		if (mac68k_bus_space_probe(oa->oa_tag, bsh, 0x1c, 4) == 0) {
    150 			bus_space_unmap(oa->oa_tag, bsh, 0x1000);
    151 			return 0;
    152 		}
    153 
    154 		/* Set "Turbo SCSI" configuration to default */
    155 		bus_space_write_4(oa->oa_tag, bsh, 0x24, 0x1d1); /* ch0 */
    156 		bus_space_write_4(oa->oa_tag, bsh, 0x28, 0x1d1); /* ch1 */
    157 
    158 		/* Disable interrupts */
    159 		bus_space_write_4(oa->oa_tag, bsh, 0x104, 0);
    160 
    161 		/* Clear any interrupts */
    162 		bus_space_write_4(oa->oa_tag, bsh, 0x10C, 0);
    163 		bus_space_write_4(oa->oa_tag, bsh, 0x110, 0);
    164 		bus_space_write_4(oa->oa_tag, bsh, 0x114, 0);
    165 
    166 		bus_space_unmap(oa->oa_tag, bsh, 0x1000);
    167 		break;
    168 	case MACH_CLASSAV:
    169 		base = CIVIC_CONTROL_BASE;
    170 
    171 		if (bus_space_map(oa->oa_tag, base, 0x1000, 0, &bsh))
    172 			return 0;
    173 
    174 		/* Disable interrupts */
    175 		bus_space_write_1(oa->oa_tag, bsh, 0x120, 0);
    176 
    177 		bus_space_unmap(oa->oa_tag, bsh, 0x1000);
    178 		break;
    179 	default:
    180 		if (mac68k_vidlen == 0)
    181 			found = 0;
    182 		break;
    183 	}
    184 
    185 	return found;
    186 }
    187 
    188 static void
    189 grfiv_attach(parent, self, aux)
    190 	struct device *parent, *self;
    191 	void   *aux;
    192 {
    193 	struct obio_attach_args *oa = (struct obio_attach_args *)aux;
    194 	struct grfbus_softc *sc;
    195 	struct grfmode *gm;
    196 	u_long base, length;
    197 	u_int32_t vbase1, vbase2;
    198 
    199 	sc = (struct grfbus_softc *)self;
    200 
    201 	sc->card_id = 0;
    202 
    203 	switch (current_mac_model->class) {
    204 	case MACH_CLASSQ2:
    205 		if (current_mac_model->machineid == MACH_MACQ630) {
    206 			printf(": Valkyrie video subsystem\n");
    207 			sc->sc_basepa = VALKYRIE_BASE;
    208 			length = 0x00100000;		/* 1MB */
    209 
    210 			if (sc->sc_basepa <= mac68k_vidphys &&
    211 			    mac68k_vidphys < (sc->sc_basepa + length))
    212 				sc->sc_fbofs = mac68k_vidphys - sc->sc_basepa;
    213 			else
    214 				sc->sc_fbofs = 0;
    215 
    216 			printf(" @ %lx: Valkyrie video subsystem\n",
    217 			    sc->sc_basepa + sc->sc_fbofs);
    218 			break;
    219 		}
    220 		/* See note in grfiv_match() */
    221 		/*FALLTHROUGH*/
    222 	case MACH_CLASSQ:
    223 		base = DAFB_CONTROL_BASE;
    224 		sc->sc_tag = oa->oa_tag;
    225 		if (bus_space_map(sc->sc_tag, base, 0x1000, 0, &sc->sc_regh)) {
    226 			printf(": failed to map DAFB register space\n");
    227 			return;
    228 		}
    229 
    230 		sc->sc_basepa = DAFB_BASE;
    231 		length = 0x00100000;		/* 1MB */
    232 
    233 		/* Compute the current frame buffer offset */
    234 		vbase1 = bus_space_read_4(sc->sc_tag, sc->sc_regh, 0x0) & 0xfff;
    235 		vbase2 = bus_space_read_4(sc->sc_tag, sc->sc_regh, 0x4) & 0xf;
    236 		sc->sc_fbofs = (vbase1 << 9) | (vbase2 << 5);
    237 		switch (current_mac_model->machineid) {	/* XXX */
    238 		case MACH_MACLC475:			/* XXX */
    239 		case MACH_MACLC475_33:			/* XXX */
    240 		case MACH_MACLC575:			/* XXX */
    241 		case MACH_MACP580:			/* XXX */
    242 			/* A guess... ? */		/* XXX */
    243 			sc->sc_fbofs = 0x1000;		/* XXX */
    244 			break;				/* XXX */
    245 		}					/* XXX */
    246 
    247 		printf(" @ %lx: DAFB video subsystem, monitor sense %x\n",
    248 		    sc->sc_basepa + sc->sc_fbofs,
    249 		    (bus_space_read_4(sc->sc_tag, sc->sc_regh, 0x1c) & 0x7));
    250 
    251 		bus_space_unmap(sc->sc_tag, sc->sc_regh, 0x1000);
    252 		break;
    253 	case MACH_CLASSAV:
    254 		sc->sc_basepa = CIVIC_BASE;
    255 		length = 0x00200000;		/* 2MB */
    256 
    257 		if (sc->sc_basepa <= mac68k_vidphys &&
    258 		    mac68k_vidphys < (sc->sc_basepa + length))
    259 			sc->sc_fbofs = mac68k_vidphys - sc->sc_basepa;
    260 		else
    261 			sc->sc_fbofs = 0;
    262 
    263 		printf(" @ %lx: Civic video subsystem\n",
    264 		    sc->sc_basepa + sc->sc_fbofs);
    265 		break;
    266 	default:
    267 		sc->sc_basepa = m68k_trunc_page(mac68k_vidphys);
    268 		sc->sc_fbofs = mac68k_vidphys & PGOFSET;
    269 		length = mac68k_vidlen + sc->sc_fbofs;
    270 
    271 		printf(" @ %lx: On-board video\n",
    272 		    sc->sc_basepa + sc->sc_fbofs);
    273 		break;
    274 	}
    275 
    276 	if (bus_space_map(sc->sc_tag, sc->sc_basepa, length, 0,
    277 	    &sc->sc_handle)) {
    278 		printf("%s: failed to map video RAM\n", sc->sc_dev.dv_xname);
    279 		return;
    280 	}
    281 
    282 	if (sc->sc_basepa <= mac68k_vidphys &&
    283 	    mac68k_vidphys < (sc->sc_basepa + length))
    284 		videoaddr = sc->sc_handle + sc->sc_fbofs; /* XXX big ol' hack */
    285 
    286 	gm = &(sc->curr_mode);
    287 	gm->mode_id = 0;
    288 	gm->psize = videobitdepth;
    289 	gm->ptype = 0;
    290 	gm->width = videosize & 0xffff;
    291 	gm->height = (videosize >> 16) & 0xffff;
    292 	gm->rowbytes = videorowbytes;
    293 	gm->hres = 80;				/* XXX hack */
    294 	gm->vres = 80;				/* XXX hack */
    295 	gm->fbsize = gm->height * gm->rowbytes;
    296 	gm->fbbase = (caddr_t)sc->sc_handle;	/* XXX yet another hack */
    297 	gm->fboff = sc->sc_fbofs;
    298 
    299 	/* Perform common video attachment. */
    300 	grf_establish(sc, NULL, grfiv_mode);
    301 }
    302 
    303 static int
    304 grfiv_mode(sc, cmd, arg)
    305 	struct grf_softc *sc;
    306 	int cmd;
    307 	void *arg;
    308 {
    309 	switch (cmd) {
    310 	case GM_GRFON:
    311 	case GM_GRFOFF:
    312 		return 0;
    313 	case GM_CURRMODE:
    314 		break;
    315 	case GM_NEWMODE:
    316 		break;
    317 	case GM_LISTMODES:
    318 		break;
    319 	}
    320 	return EINVAL;
    321 }
    322