1 /* $NetBSD: igsfb_pci.c,v 1.6 2002/10/02 16:51:38 thorpej 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 168x and CyberPro series. 32 * Only tested on IGA 1682 in Krups JavaStation-NC. 33 */ 34 #include <sys/cdefs.h> 35 __KERNEL_RCSID(0, "$NetBSD: igsfb_pci.c,v 1.6 2002/10/02 16:51:38 thorpej Exp $"); 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/kernel.h> 40 #include <sys/device.h> 41 #include <sys/malloc.h> 42 #include <sys/buf.h> 43 44 #ifdef __sparc__ /* XXX: this doesn't belong here */ 45 #include <machine/autoconf.h> 46 #endif 47 #include <machine/bus.h> 48 #include <machine/intr.h> 49 50 #include <dev/pci/pcivar.h> 51 #include <dev/pci/pcireg.h> 52 #include <dev/pci/pcidevs.h> 53 54 #include <dev/wscons/wsconsio.h> 55 #include <dev/ic/igsfbreg.h> 56 #include <dev/ic/igsfbvar.h> 57 58 59 static int igsfb_pci_match(struct device *, struct cfdata *, void *); 60 static void igsfb_pci_attach(struct device *, struct device *, void *); 61 62 CFATTACH_DECL(igsfb_pci, sizeof(struct igsfb_softc), 63 igsfb_pci_match, igsfb_pci_attach, NULL, NULL); 64 65 static int 66 igsfb_pci_match(parent, match, aux) 67 struct device *parent; 68 struct cfdata *match; 69 void *aux; 70 { 71 struct pci_attach_args *pa = aux; 72 73 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEGRAPHICS) 74 return (0); 75 76 /* probably can drive iga1680 and cyberpro cards as well */ 77 if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEGRAPHICS_IGA1682) 78 return (1); 79 80 if (PCI_PRODUCT(pa->pa_id) == 0x2000) /* XXX */ 81 return (1); 82 83 return (0); 84 } 85 86 87 /* 88 * Note, that the chip may still be not enabled (e.g. JavaStation PROM 89 * doesn't bother to init the chip if PROM output goes to serial). 90 */ 91 static void 92 igsfb_pci_attach(parent, self, aux) 93 struct device *parent, *self; 94 void *aux; 95 { 96 struct igsfb_softc *sc = (struct igsfb_softc *)self; 97 struct pci_attach_args *pa = aux; 98 bus_addr_t iobase; 99 int ioflags; 100 int isconsole; 101 char devinfo[256]; 102 103 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo); 104 printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class)); 105 106 if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEGRAPHICS_IGA1682) 107 sc->sc_is2k = 0; 108 else 109 sc->sc_is2k = 1; 110 111 /* 112 * Configure memory space first since for CyberPro we use 113 * memory-mapped i/o access. Note that we are NOT mapping any 114 * of it yet. (XXX: search for memory BAR?) 115 */ 116 #define IGS_MEM_MAPREG (PCI_MAPREG_START + 0) 117 118 sc->sc_memt = pa->pa_memt; 119 if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, 120 IGS_MEM_MAPREG, PCI_MAPREG_TYPE_MEM, 121 &sc->sc_memaddr, &sc->sc_memsz, &sc->sc_memflags) != 0) 122 { 123 printf("unable to configure memory space\n"); 124 return; 125 } 126 127 /* 128 * Configure I/O space. On CyberPro use MMIO. IGS 168x 129 * doesn't have a BAR for its i/o, so we have to hardcode it. 130 */ 131 if (sc->sc_is2k) { 132 sc->sc_iot = sc->sc_memt; 133 iobase = IGS_MEM_MMIO_SELECT | sc->sc_memaddr; 134 ioflags = sc->sc_memflags; 135 printf("mem = 0x%08x, io = 0x%08x\n", 136 (u_int32_t)sc->sc_memaddr, 137 (u_int32_t)iobase); 138 } else { 139 /* feh, 1682 config denies having io space registers */ 140 sc->sc_iot = pa->pa_iot; 141 iobase = 0; 142 ioflags = 0; 143 } 144 145 /* 146 * Map I/O registers. This is done in bus glue, not in common 147 * code because on e.g. ISA bus we'd need to access registers 148 * to obtain/program linear memory location. 149 */ 150 if (bus_space_map(sc->sc_iot, 151 iobase + IGS_REG_BASE, IGS_REG_SIZE, ioflags, 152 &sc->sc_ioh) != 0) 153 { 154 printf("unable to map I/O registers\n"); 155 return; 156 } 157 158 /* 159 * Enable the chip. 160 * 161 * XXX: for CyberPro sc->sc_iot is actually MMIO. Make sure 162 * that the card responds to memory cycles first? 163 */ 164 if (igsfb_enable(sc->sc_iot) != 0) 165 return; 166 167 #ifdef __arm__ /* XXX: uwe: netwinder */ 168 /* 169 * On Netwinder the card is absolutely out of whack. 170 * Program the registers to bring the card into a usable state. 171 * On Krups we rely on OFW to program the card correctly 172 * (XXX: re-check the case when the console is on serial). 173 */ 174 igsfb_hw_setup(sc); 175 #endif 176 177 /* 178 * TODO: Map graphic coprocessor registers. not sure if this 179 * needs to be done in bus glue or can be moved to common 180 * attach code. 181 */ 182 183 184 isconsole = 0; 185 #ifdef __arm__ 186 isconsole = 1; /* XXX */ 187 #endif 188 189 #ifdef __sparc__ /* XXX: this doesn't belong here */ 190 if (PCITAG_NODE(pa->pa_tag) == prom_instance_to_package(prom_stdout())) 191 isconsole = 1; 192 #endif 193 194 igsfb_common_attach(sc, isconsole); 195 } 196