Home | History | Annotate | Line # | Download | only in pci
igsfb_pci.c revision 1.1
      1  1.1  uwe /*	$NetBSD: igsfb_pci.c,v 1.1 2002/03/30 19:48:56 uwe Exp $ */
      2  1.1  uwe 
      3  1.1  uwe /*
      4  1.1  uwe  * Copyright (c) 2002 Valeriy E. Ushakov
      5  1.1  uwe  * All rights reserved.
      6  1.1  uwe  *
      7  1.1  uwe  * Redistribution and use in source and binary forms, with or without
      8  1.1  uwe  * modification, are permitted provided that the following conditions
      9  1.1  uwe  * are met:
     10  1.1  uwe  * 1. Redistributions of source code must retain the above copyright
     11  1.1  uwe  *    notice, this list of conditions and the following disclaimer.
     12  1.1  uwe  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  uwe  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  uwe  *    documentation and/or other materials provided with the distribution.
     15  1.1  uwe  * 3. The name of the author may not be used to endorse or promote products
     16  1.1  uwe  *    derived from this software without specific prior written permission
     17  1.1  uwe  *
     18  1.1  uwe  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.1  uwe  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.1  uwe  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.1  uwe  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.1  uwe  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  1.1  uwe  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  1.1  uwe  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  1.1  uwe  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  1.1  uwe  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  1.1  uwe  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  1.1  uwe  */
     29  1.1  uwe 
     30  1.1  uwe /*
     31  1.1  uwe  * Integraphics Systems IGA 1682 and (untested) CyberPro 2k.
     32  1.1  uwe  */
     33  1.1  uwe #include <sys/cdefs.h>
     34  1.1  uwe __KERNEL_RCSID(0, "$NetBSD: igsfb_pci.c,v 1.1 2002/03/30 19:48:56 uwe Exp $");
     35  1.1  uwe 
     36  1.1  uwe #include <sys/param.h>
     37  1.1  uwe #include <sys/systm.h>
     38  1.1  uwe #include <sys/kernel.h>
     39  1.1  uwe #include <sys/device.h>
     40  1.1  uwe #include <sys/malloc.h>
     41  1.1  uwe #include <sys/buf.h>
     42  1.1  uwe 
     43  1.1  uwe #include <machine/autoconf.h>
     44  1.1  uwe #include <machine/bus.h>
     45  1.1  uwe #include <machine/intr.h>
     46  1.1  uwe 
     47  1.1  uwe #include <dev/pci/pcivar.h>
     48  1.1  uwe #include <dev/pci/pcireg.h>
     49  1.1  uwe #include <dev/pci/pcidevs.h>
     50  1.1  uwe 
     51  1.1  uwe #include <dev/wscons/wsconsio.h>
     52  1.1  uwe #include <dev/ic/igsfbreg.h>
     53  1.1  uwe #include <dev/ic/igsfbvar.h>
     54  1.1  uwe 
     55  1.1  uwe 
     56  1.1  uwe static int	igsfb_pci_match(struct device *, struct cfdata *, void *);
     57  1.1  uwe static void	igsfb_pci_attach(struct device *, struct device *, void *);
     58  1.1  uwe 
     59  1.1  uwe const struct cfattach igsfb_pci_ca = {
     60  1.1  uwe 	sizeof(struct igsfb_softc), igsfb_pci_match, igsfb_pci_attach,
     61  1.1  uwe };
     62  1.1  uwe 
     63  1.1  uwe 
     64  1.1  uwe static int
     65  1.1  uwe igsfb_pci_match(parent, match, aux)
     66  1.1  uwe 	struct device *parent;
     67  1.1  uwe 	struct cfdata *match;
     68  1.1  uwe 	void *aux;
     69  1.1  uwe {
     70  1.1  uwe 	struct pci_attach_args *pa = aux;
     71  1.1  uwe 
     72  1.1  uwe 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEGRAPHICS)
     73  1.1  uwe 		return (0);
     74  1.1  uwe 
     75  1.1  uwe 	/* probably can drive iga1680 and cyberpro cards as well */
     76  1.1  uwe 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEGRAPHICS_IGA1682)
     77  1.1  uwe 		return (1);
     78  1.1  uwe 
     79  1.1  uwe 	return (0);
     80  1.1  uwe }
     81  1.1  uwe 
     82  1.1  uwe 
     83  1.1  uwe /*
     84  1.1  uwe  * Note, that the chip may still be not enabled (e.g. JavaStation PROM
     85  1.1  uwe  * doesn't bother to init the chip if PROM output goes to serial).
     86  1.1  uwe  */
     87  1.1  uwe static void
     88  1.1  uwe igsfb_pci_attach(parent, self, aux)
     89  1.1  uwe 	struct device *parent, *self;
     90  1.1  uwe 	void *aux;
     91  1.1  uwe {
     92  1.1  uwe 	struct igsfb_softc *sc = (struct igsfb_softc *)self;
     93  1.1  uwe 	struct pci_attach_args *pa = aux;
     94  1.1  uwe 	bus_addr_t iobase;
     95  1.1  uwe 	int ioflags;
     96  1.1  uwe 	int isconsole;
     97  1.1  uwe 	char devinfo[256];
     98  1.1  uwe 
     99  1.1  uwe 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
    100  1.1  uwe 	printf(": %s, revision 0x%02x\n", devinfo, PCI_REVISION(pa->pa_class));
    101  1.1  uwe 
    102  1.1  uwe 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEGRAPHICS_IGA1682)
    103  1.1  uwe 		sc->sc_is2k = 0;
    104  1.1  uwe 	else
    105  1.1  uwe 		sc->sc_is2k = 1;
    106  1.1  uwe 
    107  1.1  uwe 
    108  1.1  uwe #ifdef __sparc__
    109  1.1  uwe 	/*
    110  1.1  uwe 	 * We run javastation with PCIC doing byte-swapping on data
    111  1.1  uwe 	 * travelling to/from PCI, so compensate for that.
    112  1.1  uwe 	 */
    113  1.1  uwe 	sc->sc_hwflags |= IGSFB_HW_BSWAP;
    114  1.1  uwe #endif
    115  1.1  uwe 
    116  1.1  uwe 	/*
    117  1.1  uwe 	 * Memory space.  Configure it first since for cyber2k we also
    118  1.1  uwe 	 * use memory-mapped i/o access.  Note that we are not mapping
    119  1.1  uwe 	 * any of it yet.
    120  1.1  uwe 	 */
    121  1.1  uwe #define IGS_MEM_MAPREG (PCI_MAPREG_START + 0)
    122  1.1  uwe 
    123  1.1  uwe 	sc->sc_memt = pa->pa_memt;
    124  1.1  uwe 	if (pci_mapreg_info(pa->pa_pc, pa->pa_tag,
    125  1.1  uwe 		IGS_MEM_MAPREG, PCI_MAPREG_TYPE_MEM,
    126  1.1  uwe 		&sc->sc_memaddr, &sc->sc_memsz, &sc->sc_memflags) != 0)
    127  1.1  uwe 	{
    128  1.1  uwe 		printf("unable to configure memory space\n");
    129  1.1  uwe 		return;
    130  1.1  uwe 	}
    131  1.1  uwe 
    132  1.1  uwe 	/*
    133  1.1  uwe 	 * I/O space.
    134  1.1  uwe 	 */
    135  1.1  uwe 	if (sc->sc_is2k) {	/* XXX: untested */
    136  1.1  uwe 		sc->sc_iot = sc->sc_memt;
    137  1.1  uwe 		iobase = sc->sc_memaddr | IGS_MEM_MMIO_SELECT;
    138  1.1  uwe 		ioflags = sc->sc_memflags;
    139  1.1  uwe 	} else {
    140  1.1  uwe 		/* feh, 1682 denies having io space registers */
    141  1.1  uwe /* XXX: ms-IIep specific !!! */
    142  1.1  uwe #define IGS_IO_PADDR 0x30000000
    143  1.1  uwe 		sc->sc_iot = pa->pa_iot;
    144  1.1  uwe 		iobase = IGS_IO_PADDR;
    145  1.1  uwe 		ioflags = 0;
    146  1.1  uwe 	}
    147  1.1  uwe 
    148  1.1  uwe 	if (bus_space_map(sc->sc_iot, iobase, IGS_IO_SIZE, ioflags,
    149  1.1  uwe 			  &sc->sc_ioh) != 0)
    150  1.1  uwe 	{
    151  1.1  uwe 		printf("unable to map io registers\n");
    152  1.1  uwe 		return;
    153  1.1  uwe 	}
    154  1.1  uwe 
    155  1.1  uwe 	/* TODO: Graphic coprocessor registers. */
    156  1.1  uwe 
    157  1.1  uwe 	if (igsfb_io_enable(sc->sc_iot, iobase) != 0)
    158  1.1  uwe 		return;
    159  1.1  uwe 
    160  1.1  uwe 	igsfb_mem_enable(sc);
    161  1.1  uwe 
    162  1.1  uwe 	/* XXX: sparc'ism */
    163  1.1  uwe 	if (PCITAG_NODE(pa->pa_tag) == prom_instance_to_package(prom_stdout()))
    164  1.1  uwe 		isconsole = 1;
    165  1.1  uwe 	else
    166  1.1  uwe 		isconsole = 0;
    167  1.1  uwe 
    168  1.1  uwe 	igsfb_common_attach(sc, isconsole);
    169  1.1  uwe }
    170