Home | History | Annotate | Line # | Download | only in pci
igsfb_pci.c revision 1.2
      1 /*	$NetBSD: igsfb_pci.c,v 1.2 2002/04/04 18:50:28 uwe Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2002 Valeriy E. Ushakov
      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 /*
     31  * Integraphics Systems IGA 1682 and (untested) CyberPro 2k.
     32  */
     33 #include <sys/cdefs.h>
     34 __KERNEL_RCSID(0, "$NetBSD: igsfb_pci.c,v 1.2 2002/04/04 18:50:28 uwe Exp $");
     35 
     36 #include <sys/param.h>
     37 #include <sys/systm.h>
     38 #include <sys/kernel.h>
     39 #include <sys/device.h>
     40 #include <sys/malloc.h>
     41 #include <sys/buf.h>
     42 
     43 #include <machine/autoconf.h>
     44 #include <machine/bus.h>
     45 #include <machine/intr.h>
     46 
     47 #include <dev/pci/pcivar.h>
     48 #include <dev/pci/pcireg.h>
     49 #include <dev/pci/pcidevs.h>
     50 
     51 #include <dev/wscons/wsconsio.h>
     52 #include <dev/ic/igsfbreg.h>
     53 #include <dev/ic/igsfbvar.h>
     54 
     55 
     56 static int	igsfb_pci_match(struct device *, struct cfdata *, void *);
     57 static void	igsfb_pci_attach(struct device *, struct device *, void *);
     58 
     59 const struct cfattach igsfb_pci_ca = {
     60 	sizeof(struct igsfb_softc), igsfb_pci_match, igsfb_pci_attach,
     61 };
     62 
     63 
     64 static int
     65 igsfb_pci_match(parent, match, aux)
     66 	struct device *parent;
     67 	struct cfdata *match;
     68 	void *aux;
     69 {
     70 	struct pci_attach_args *pa = aux;
     71 
     72 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEGRAPHICS)
     73 		return (0);
     74 
     75 	/* probably can drive iga1680 and cyberpro cards as well */
     76 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEGRAPHICS_IGA1682)
     77 		return (1);
     78 
     79 	return (0);
     80 }
     81 
     82 
     83 /*
     84  * Note, that the chip may still be not enabled (e.g. JavaStation PROM
     85  * doesn't bother to init the chip if PROM output goes to serial).
     86  */
     87 static void
     88 igsfb_pci_attach(parent, self, aux)
     89 	struct device *parent, *self;
     90 	void *aux;
     91 {
     92 	struct igsfb_softc *sc = (struct igsfb_softc *)self;
     93 	struct pci_attach_args *pa = aux;
     94 	bus_addr_t iobase;
     95 	int ioflags;
     96 	int isconsole;
     97 	char devinfo[256];
     98 
     99 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
    100 	printf(": %s, revision 0x%02x\n", devinfo, PCI_REVISION(pa->pa_class));
    101 
    102 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEGRAPHICS_IGA1682)
    103 		sc->sc_is2k = 0;
    104 	else
    105 		sc->sc_is2k = 1;
    106 
    107 
    108 #ifdef __sparc__
    109 	/*
    110 	 * We run javastation with PCIC doing byte-swapping on data
    111 	 * travelling to/from PCI, so compensate for that.
    112 	 */
    113 	sc->sc_hwflags |= IGSFB_HW_BSWAP;
    114 #endif
    115 
    116 	/*
    117 	 * Memory space.  Configure it first since for cyber2k we also
    118 	 * use memory-mapped i/o access.  Note that we are not mapping
    119 	 * any of it yet.
    120 	 */
    121 #define IGS_MEM_MAPREG (PCI_MAPREG_START + 0)
    122 
    123 	sc->sc_memt = pa->pa_memt;
    124 	if (pci_mapreg_info(pa->pa_pc, pa->pa_tag,
    125 		IGS_MEM_MAPREG, PCI_MAPREG_TYPE_MEM,
    126 		&sc->sc_memaddr, &sc->sc_memsz, &sc->sc_memflags) != 0)
    127 	{
    128 		printf("unable to configure memory space\n");
    129 		return;
    130 	}
    131 
    132 	/*
    133 	 * I/O space.
    134 	 */
    135 	if (sc->sc_is2k) {	/* XXX: untested */
    136 		sc->sc_iot = sc->sc_memt;
    137 		iobase = sc->sc_memaddr | IGS_MEM_MMIO_SELECT;
    138 		ioflags = sc->sc_memflags;
    139 	} else {
    140 		/* feh, 1682 denies having io space registers */
    141 		sc->sc_iot = pa->pa_iot;
    142 		iobase = 0;
    143 		ioflags = 0;
    144 	}
    145 
    146 	if (bus_space_map(sc->sc_iot, iobase, IGS_IO_SIZE, ioflags,
    147 			  &sc->sc_ioh) != 0)
    148 	{
    149 		printf("unable to map io registers\n");
    150 		return;
    151 	}
    152 
    153 	/* TODO: Graphic coprocessor registers. */
    154 
    155 	if (igsfb_io_enable(sc->sc_iot, iobase) != 0)
    156 		return;
    157 
    158 	igsfb_mem_enable(sc);
    159 
    160 	/* XXX: sparc'ism */
    161 	if (PCITAG_NODE(pa->pa_tag) == prom_instance_to_package(prom_stdout()))
    162 		isconsole = 1;
    163 	else
    164 		isconsole = 0;
    165 
    166 	igsfb_common_attach(sc, isconsole);
    167 }
    168