Home | History | Annotate | Line # | Download | only in nubus
grf_nubus.c revision 1.15
      1 /*	$NetBSD: grf_nubus.c,v 1.15 1996/12/16 16:17:06 scottr Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1995 Allen Briggs.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by Allen Briggs.
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 /*
     32  * Device-specific routines for handling Nubus-based video cards.
     33  */
     34 
     35 #include <sys/param.h>
     36 
     37 #include <sys/device.h>
     38 #include <sys/ioctl.h>
     39 #include <sys/file.h>
     40 #include <sys/malloc.h>
     41 #include <sys/mman.h>
     42 #include <sys/proc.h>
     43 #include <sys/systm.h>
     44 
     45 #include <machine/cpu.h>
     46 #include <machine/grfioctl.h>
     47 #include <machine/viareg.h>
     48 
     49 #include "nubus.h"
     50 #include "grfvar.h"
     51 
     52 static void	load_image_data __P((caddr_t data, struct image_data *image));
     53 static void	grfmv_intr __P((void *vsc, int slot));
     54 
     55 static char zero = 0;
     56 
     57 static int	grfmv_mode __P((struct grf_softc *gp, int cmd, void *arg));
     58 static caddr_t	grfmv_phys __P((struct grf_softc *gp, vm_offset_t addr));
     59 static int	grfmv_match __P((struct device *, struct cfdata *, void *));
     60 static void	grfmv_attach __P((struct device *, struct device *, void *));
     61 
     62 struct cfdriver macvid_cd = {
     63 	NULL, "macvid", DV_DULL
     64 };
     65 
     66 struct cfattach macvid_ca = {
     67 	sizeof(struct grfbus_softc), grfmv_match, grfmv_attach
     68 };
     69 
     70 static void
     71 load_image_data(data, image)
     72 	caddr_t	data;
     73 	struct	image_data *image;
     74 {
     75 	bcopy(data     , &image->size,       4);
     76 	bcopy(data +  4, &image->offset,     4);
     77 	bcopy(data +  8, &image->rowbytes,   2);
     78 	bcopy(data + 10, &image->top,        2);
     79 	bcopy(data + 12, &image->left,       2);
     80 	bcopy(data + 14, &image->bottom,     2);
     81 	bcopy(data + 16, &image->right,      2);
     82 	bcopy(data + 18, &image->version,    2);
     83 	bcopy(data + 20, &image->packType,   2);
     84 	bcopy(data + 22, &image->packSize,   4);
     85 	bcopy(data + 26, &image->hRes,       4);
     86 	bcopy(data + 30, &image->vRes,       4);
     87 	bcopy(data + 34, &image->pixelType,  2);
     88 	bcopy(data + 36, &image->pixelSize,  2);
     89 	bcopy(data + 38, &image->cmpCount,   2);
     90 	bcopy(data + 40, &image->cmpSize,    2);
     91 	bcopy(data + 42, &image->planeBytes, 4);
     92 }
     93 
     94 /*ARGSUSED*/
     95 static void
     96 grfmv_intr(vsc, slot)
     97 	void	*vsc;
     98 	int	slot;
     99 {
    100 	caddr_t			 slotbase;
    101 	struct grfbus_softc	*sc;
    102 
    103 	sc = (struct grfbus_softc *) vsc;
    104 	slotbase = (caddr_t) sc->sc_slot.virtual_base;
    105 	slotbase[0xa0000] = zero;
    106 }
    107 
    108 static int
    109 grfmv_match(parent, cf, aux)
    110 	struct device *parent;
    111 	struct cfdata *cf;
    112 	void *aux;
    113 {
    114 	struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
    115 
    116 	if (na->category != NUBUS_CATEGORY_DISPLAY)
    117 		return 0;
    118 
    119 	if (na->type != NUBUS_TYPE_VIDEO)
    120 		return 0;
    121 
    122 	if (na->drsw != NUBUS_DRSW_APPLE)
    123 		return 0;
    124 
    125 	/*
    126 	 * If we've gotten this far, then we're dealing with a real-live
    127 	 * Apple QuickDraw-compatible display card resource.  Now, how to
    128 	 * determine that this is an active resource???  Dunno.  But we'll
    129 	 * proceed like it is.
    130 	 */
    131 
    132 	return 1;
    133 }
    134 
    135 static void
    136 grfmv_attach(parent, self, aux)
    137 	struct device *parent, *self;
    138 	void *aux;
    139 {
    140 	struct grfbus_softc *sc = (struct grfbus_softc *) self;
    141 	struct nubus_attach_args *na = (struct nubus_attach_args *) aux;
    142 	struct image_data image_store, image;
    143 	struct grfmode *gm;
    144 	char cardname[CARD_NAME_LEN];
    145 	nubus_dirent dirent;
    146 	nubus_dir dir, mode_dir;
    147 	int mode;
    148 
    149 	sc->card_id = na->drhw;
    150 
    151 	bcopy(na->fmt, &sc->sc_slot, sizeof(nubus_slot));
    152 
    153 	nubus_get_main_dir(&sc->sc_slot, &dir);
    154 
    155 	if (nubus_find_rsrc(&sc->sc_slot, &dir, na->rsrcid, &dirent) <= 0)
    156 		return;
    157 
    158 	nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &sc->board_dir);
    159 
    160 	if (nubus_find_rsrc(&sc->sc_slot, &sc->board_dir,
    161 	    NUBUS_RSRC_TYPE, &dirent) <= 0)
    162 		if ((na->rsrcid != 128) ||
    163 		    (nubus_find_rsrc(&sc->sc_slot, &dir, 129, &dirent) <= 0))
    164 			return;
    165 
    166 	mode = NUBUS_RSRC_FIRSTMODE;
    167 	if (nubus_find_rsrc(&sc->sc_slot, &sc->board_dir, mode, &dirent) <= 0) {
    168 		printf("\n%s: probe failed to get board rsrc.\n",
    169 		    sc->sc_dev.dv_xname);
    170 		return;
    171 	}
    172 
    173 	nubus_get_dir_from_rsrc(&sc->sc_slot, &dirent, &mode_dir);
    174 
    175 	if (nubus_find_rsrc(&sc->sc_slot, &mode_dir, VID_PARAMS, &dirent)
    176 	    <= 0) {
    177 		printf("\n%s: probe failed to get mode dir.\n",
    178 		    sc->sc_dev.dv_xname);
    179 		return;
    180 	}
    181 
    182 	if (nubus_get_ind_data(&sc->sc_slot, &dirent, (caddr_t) &image_store,
    183 				sizeof(struct image_data)) <= 0) {
    184 		printf("\n%s: probe failed to get indirect mode data.\n",
    185 		    sc->sc_dev.dv_xname);
    186 		return;
    187 	}
    188 
    189 	/* Need to load display info (and driver?), etc... (?) */
    190 
    191 	load_image_data((caddr_t) &image_store, &image);
    192 
    193 	gm = &sc->curr_mode;
    194 	gm->mode_id = mode;
    195 	gm->fbbase = (caddr_t) (sc->sc_slot.virtual_base + image.offset);
    196 	gm->fboff = image.offset;
    197 	gm->rowbytes = image.rowbytes;
    198 	gm->width = image.right - image.left;
    199 	gm->height = image.bottom - image.top;
    200 	gm->fbsize = sc->curr_mode.height * sc->curr_mode.rowbytes;
    201 	gm->hres = image.hRes;
    202 	gm->vres = image.vRes;
    203 	gm->ptype = image.pixelType;
    204 	gm->psize = image.pixelSize;
    205 
    206 	strncpy(cardname, nubus_get_card_name(&sc->sc_slot),
    207 		CARD_NAME_LEN);
    208 	cardname[CARD_NAME_LEN-1] = '\0';
    209 
    210 	printf(": %s\n", cardname);
    211 
    212 	add_nubus_intr(sc->sc_slot.slot, grfmv_intr, sc);
    213 
    214 	/* Perform common video attachment. */
    215 	grf_establish(sc, &sc->sc_slot, grfmv_mode, grfmv_phys);
    216 }
    217 
    218 static int
    219 grfmv_mode(gp, cmd, arg)
    220 	struct grf_softc *gp;
    221 	int cmd;
    222 	void *arg;
    223 {
    224 	switch (cmd) {
    225 	case GM_GRFON:
    226 	case GM_GRFOFF:
    227 		return 0;
    228 	case GM_CURRMODE:
    229 		break;
    230 	case GM_NEWMODE:
    231 		break;
    232 	case GM_LISTMODES:
    233 		break;
    234 	}
    235 	return EINVAL;
    236 }
    237 
    238 static caddr_t
    239 grfmv_phys(gp, addr)
    240 	struct grf_softc *gp;
    241 	vm_offset_t addr;
    242 {
    243 	return (caddr_t) (NUBUS_SLOT_TO_PADDR(gp->sc_slot->slot) +
    244 				(addr - gp->sc_slot->virtual_base));
    245 }
    246