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