Home | History | Annotate | Line # | Download | only in obio
grf_obio.c revision 1.49
      1 /*	$NetBSD: grf_obio.c,v 1.49 2002/10/02 05:36:39 thorpej 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 <sys/param.h>
     63 #include <sys/device.h>
     64 #include <sys/ioctl.h>
     65 #include <sys/file.h>
     66 #include <sys/malloc.h>
     67 #include <sys/mman.h>
     68 #include <sys/proc.h>
     69 #include <sys/systm.h>
     70 
     71 #include <machine/autoconf.h>
     72 #include <machine/bus.h>
     73 #include <machine/cpu.h>
     74 #include <machine/grfioctl.h>
     75 #include <machine/viareg.h>
     76 
     77 #include <mac68k/nubus/nubus.h>
     78 #include <mac68k/obio/obiovar.h>
     79 #include <mac68k/dev/grfvar.h>
     80 
     81 extern u_int32_t	mac68k_vidphys;
     82 extern u_int32_t	mac68k_vidlen;
     83 extern long		videoaddr;
     84 extern long		videorowbytes;
     85 extern long		videobitdepth;
     86 extern u_long		videosize;
     87 
     88 static int	grfiv_mode __P((struct grf_softc *gp, int cmd, void *arg));
     89 static int	grfiv_match __P((struct device *, struct cfdata *, void *));
     90 static void	grfiv_attach __P((struct device *, struct device *, void *));
     91 
     92 CFATTACH_DECL(intvid, sizeof(struct grfbus_softc),
     93     grfiv_match, grfiv_attach, NULL, NULL);
     94 
     95 #define	DAFB_BASE		0xf9000000
     96 #define DAFB_CONTROL_BASE	0xf9800000
     97 #define	CIVIC_BASE		0x50100000
     98 #define CIVIC_CONTROL_BASE	0x50036000
     99 #define	VALKYRIE_BASE		0xf9000000
    100 #define VALKYRIE_CONTROL_BASE	0x50f2a000
    101 
    102 static int
    103 grfiv_match(parent, cf, aux)
    104 	struct device *parent;
    105 	struct cfdata *cf;
    106 	void *aux;
    107 {
    108 	struct obio_attach_args *oa = (struct obio_attach_args *)aux;
    109 	bus_space_handle_t bsh;
    110 	int found;
    111 	u_int base;
    112 
    113 	found = 1;
    114 
    115 	switch (current_mac_model->class) {
    116 	case MACH_CLASSQ2:
    117 		if (current_mac_model->machineid != MACH_MACLC575) {
    118 			base = VALKYRIE_CONTROL_BASE;
    119 
    120 			if (bus_space_map(oa->oa_tag, base, 0x40, 0, &bsh))
    121 				return 0;
    122 
    123 			/* Disable interrupts */
    124 			bus_space_write_1(oa->oa_tag, bsh, 0x18, 0x1);
    125 
    126 			bus_space_unmap(oa->oa_tag, bsh, 0x40);
    127 			break;
    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, 0x20, 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, 0x20);
    151 			return 0;
    152 		}
    153 
    154 		bus_space_unmap(oa->oa_tag, bsh, 0x20);
    155 
    156 		if (bus_space_map(oa->oa_tag, base + 0x100, 0x20, 0, &bsh))
    157 			return 0;
    158 
    159 		if (mac68k_bus_space_probe(oa->oa_tag, bsh, 0x04, 4) == 0) {
    160 			bus_space_unmap(oa->oa_tag, bsh, 0x20);
    161 			return 0;
    162 		}
    163 
    164 		/* Disable interrupts */
    165 		bus_space_write_4(oa->oa_tag, bsh, 0x04, 0);
    166 
    167 		/* Clear any interrupts */
    168 		bus_space_write_4(oa->oa_tag, bsh, 0x0C, 0);
    169 		bus_space_write_4(oa->oa_tag, bsh, 0x10, 0);
    170 		bus_space_write_4(oa->oa_tag, bsh, 0x14, 0);
    171 
    172 		bus_space_unmap(oa->oa_tag, bsh, 0x20);
    173 		break;
    174 	case MACH_CLASSAV:
    175 		base = CIVIC_CONTROL_BASE;
    176 
    177 		if (bus_space_map(oa->oa_tag, base, 0x1000, 0, &bsh))
    178 			return 0;
    179 
    180 		/* Disable interrupts */
    181 		bus_space_write_1(oa->oa_tag, bsh, 0x120, 0);
    182 
    183 		bus_space_unmap(oa->oa_tag, bsh, 0x1000);
    184 		break;
    185 	case MACH_CLASSIIci:
    186 	case MACH_CLASSIIsi:
    187 		if (mac68k_vidlen == 0 ||
    188 		    (via2_reg(rMonitor) & RBVMonitorMask) == RBVMonIDNone)
    189 			found = 0;
    190 		break;
    191 	default:
    192 		if (mac68k_vidlen == 0)
    193 			found = 0;
    194 		break;
    195 	}
    196 
    197 	return found;
    198 }
    199 
    200 static void
    201 grfiv_attach(parent, self, aux)
    202 	struct device *parent, *self;
    203 	void   *aux;
    204 {
    205 	struct obio_attach_args *oa = (struct obio_attach_args *)aux;
    206 	struct grfbus_softc *sc;
    207 	struct grfmode *gm;
    208 	u_long base, length;
    209 	u_int32_t vbase1, vbase2;
    210 
    211 	sc = (struct grfbus_softc *)self;
    212 
    213 	sc->card_id = 0;
    214 
    215 	switch (current_mac_model->class) {
    216 	case MACH_CLASSQ2:
    217 		if (current_mac_model->machineid != MACH_MACLC575) {
    218 			sc->sc_basepa = VALKYRIE_BASE;
    219 			length = 0x00100000;		/* 1MB */
    220 
    221 			if (sc->sc_basepa <= mac68k_vidphys &&
    222 			    mac68k_vidphys < (sc->sc_basepa + length)) {
    223 				sc->sc_fbofs = mac68k_vidphys - sc->sc_basepa;
    224 			} else {
    225 				sc->sc_basepa = m68k_trunc_page(mac68k_vidphys);
    226 				sc->sc_fbofs = m68k_page_offset(mac68k_vidphys);
    227 				length = mac68k_vidlen + sc->sc_fbofs;
    228 			}
    229 
    230 			printf(" @ %lx: Valkyrie video subsystem\n",
    231 			    sc->sc_basepa + sc->sc_fbofs);
    232 			break;
    233 		}
    234 		/* See note in grfiv_match() */
    235 		/*FALLTHROUGH*/
    236 	case MACH_CLASSQ:
    237 		base = DAFB_CONTROL_BASE;
    238 		sc->sc_tag = oa->oa_tag;
    239 		if (bus_space_map(sc->sc_tag, base, 0x20, 0, &sc->sc_regh)) {
    240 			printf(": failed to map DAFB register space\n");
    241 			return;
    242 		}
    243 
    244 		sc->sc_basepa = DAFB_BASE;
    245 		length = 0x00100000;		/* 1MB */
    246 
    247 		/* Compute the current frame buffer offset */
    248 		vbase1 = bus_space_read_4(sc->sc_tag, sc->sc_regh, 0x0) & 0xfff;
    249 #if 1
    250 		/*
    251 		 * XXX The following exists because the DAFB v7 in these
    252 		 * systems doesn't return reasonable values to use for fbofs.
    253 		 * Ken'ichi Ishizaka gets credit for this hack.  (sar 19990426)
    254 		 * (Does this get us the correct result for _all_ DAFB-
    255 		 * equipped systems and monitor combinations?  It seems
    256 		 * possible, if not likely...)
    257 		 */
    258 		switch (current_mac_model->machineid) {
    259 		case MACH_MACLC475:
    260 		case MACH_MACLC475_33:
    261 		case MACH_MACLC575:
    262 		case MACH_MACQ605:
    263 		case MACH_MACQ605_33:
    264 			vbase1 &= 0x3f;
    265 			break;
    266 		}
    267 #endif
    268 		vbase2 = bus_space_read_4(sc->sc_tag, sc->sc_regh, 0x4) & 0xf;
    269 		sc->sc_fbofs = (vbase1 << 9) | (vbase2 << 5);
    270 
    271 		printf(" @ %lx: DAFB video subsystem, monitor sense %x\n",
    272 		    sc->sc_basepa + sc->sc_fbofs,
    273 		    (bus_space_read_4(sc->sc_tag, sc->sc_regh, 0x1c) & 0x7));
    274 
    275 		bus_space_unmap(sc->sc_tag, sc->sc_regh, 0x20);
    276 		break;
    277 	case MACH_CLASSAV:
    278 		sc->sc_basepa = CIVIC_BASE;
    279 		length = 0x00200000;		/* 2MB */
    280 		if (mac68k_vidphys >= sc->sc_basepa &&
    281 		    mac68k_vidphys < (sc->sc_basepa + length)) {
    282 			sc->sc_fbofs = mac68k_vidphys - sc->sc_basepa;
    283 		} else {
    284 			sc->sc_basepa = m68k_trunc_page(mac68k_vidphys);
    285 			sc->sc_fbofs = m68k_page_offset(mac68k_vidphys);
    286 			length = mac68k_vidlen + sc->sc_fbofs;
    287 		}
    288 
    289 		printf(" @ %lx: CIVIC video subsystem\n",
    290 		    sc->sc_basepa + sc->sc_fbofs);
    291 		break;
    292 	case MACH_CLASSIIci:
    293 	case MACH_CLASSIIsi:
    294 		sc->sc_basepa = m68k_trunc_page(mac68k_vidphys);
    295 		sc->sc_fbofs = m68k_page_offset(mac68k_vidphys);
    296 		length = mac68k_vidlen + sc->sc_fbofs;
    297 
    298 		printf(" @ %lx: RBV video subsystem, ",
    299 		    sc->sc_basepa + sc->sc_fbofs);
    300 		switch (via2_reg(rMonitor) & RBVMonitorMask) {
    301 		case RBVMonIDBWP:
    302 			printf("15\" monochrome portrait");
    303 			break;
    304 		case RBVMonIDRGB12:
    305 			printf("12\" color");
    306 			break;
    307 		case RBVMonIDRGB15:
    308 			printf("15\" color");
    309 			break;
    310 		case RBVMonIDStd:
    311 			printf("Macintosh II");
    312 			break;
    313 		default:
    314 			printf("unrecognized");
    315 			break;
    316 		}
    317 		printf(" display\n");
    318 
    319 		break;
    320 	default:
    321 		sc->sc_basepa = m68k_trunc_page(mac68k_vidphys);
    322 		sc->sc_fbofs = m68k_page_offset(mac68k_vidphys);
    323 		length = mac68k_vidlen + sc->sc_fbofs;
    324 
    325 		printf(" @ %lx: On-board video\n",
    326 		    sc->sc_basepa + sc->sc_fbofs);
    327 		break;
    328 	}
    329 
    330 	if (bus_space_map(sc->sc_tag, sc->sc_basepa, length, 0,
    331 	    &sc->sc_handle)) {
    332 		printf("%s: failed to map video RAM\n", sc->sc_dev.dv_xname);
    333 		return;
    334 	}
    335 
    336 	if (sc->sc_basepa <= mac68k_vidphys &&
    337 	    mac68k_vidphys < (sc->sc_basepa + length))
    338 		videoaddr = sc->sc_handle.base + sc->sc_fbofs; /* XXX hack */
    339 
    340 	gm = &(sc->curr_mode);
    341 	gm->mode_id = 0;
    342 	gm->psize = videobitdepth;
    343 	gm->ptype = 0;
    344 	gm->width = videosize & 0xffff;
    345 	gm->height = (videosize >> 16) & 0xffff;
    346 	gm->rowbytes = videorowbytes;
    347 	gm->hres = 80;				/* XXX hack */
    348 	gm->vres = 80;				/* XXX hack */
    349 	gm->fbsize = gm->height * gm->rowbytes;
    350 	gm->fbbase = (caddr_t)sc->sc_handle.base; /* XXX yet another hack */
    351 	gm->fboff = sc->sc_fbofs;
    352 
    353 	/* Perform common video attachment. */
    354 	grf_establish(sc, NULL, grfiv_mode);
    355 }
    356 
    357 static int
    358 grfiv_mode(sc, cmd, arg)
    359 	struct grf_softc *sc;
    360 	int cmd;
    361 	void *arg;
    362 {
    363 	switch (cmd) {
    364 	case GM_GRFON:
    365 	case GM_GRFOFF:
    366 		return 0;
    367 	case GM_CURRMODE:
    368 		break;
    369 	case GM_NEWMODE:
    370 		break;
    371 	case GM_LISTMODES:
    372 		break;
    373 	}
    374 	return EINVAL;
    375 }
    376