1 /* $NetBSD: i82365_pci.c,v 1.12 2001/11/13 07:48:42 lukem Exp $ */ 2 3 /* 4 * Copyright (c) 1997 Marc Horowitz. 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 Marc Horowitz. 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 /* 33 * XXX this driver frontend is *very* i386 dependent and should be relocated 34 */ 35 36 #include <sys/cdefs.h> 37 __KERNEL_RCSID(0, "$NetBSD: i82365_pci.c,v 1.12 2001/11/13 07:48:42 lukem Exp $"); 38 39 #include <sys/types.h> 40 #include <sys/param.h> 41 #include <sys/systm.h> 42 #include <sys/device.h> 43 44 #include <dev/ic/i82365reg.h> 45 #include <dev/ic/i82365var.h> 46 47 #include <dev/pci/pcivar.h> 48 #include <dev/pci/pcireg.h> 49 #include <dev/pci/pcidevs.h> 50 #include <dev/pci/i82365_pcivar.h> 51 52 #include <dev/isa/isavar.h> 53 #include <dev/isa/i82365_isavar.h> 54 55 /* 56 * PCI constants. 57 * XXX These should be in a common file! 58 */ 59 #define PCI_CBIO 0x10 /* Configuration Base IO Address */ 60 61 int pcic_pci_match __P((struct device *, struct cfdata *, void *)); 62 void pcic_pci_attach __P((struct device *, struct device *, void *)); 63 64 struct cfattach pcic_pci_ca = { 65 sizeof(struct pcic_pci_softc), pcic_pci_match, pcic_pci_attach 66 }; 67 68 static struct pcmcia_chip_functions pcic_pci_functions = { 69 pcic_chip_mem_alloc, 70 pcic_chip_mem_free, 71 pcic_chip_mem_map, 72 pcic_chip_mem_unmap, 73 74 pcic_chip_io_alloc, 75 pcic_chip_io_free, 76 pcic_chip_io_map, 77 pcic_chip_io_unmap, 78 79 /* XXX */ 80 pcic_isa_chip_intr_establish, 81 pcic_isa_chip_intr_disestablish, 82 83 pcic_chip_socket_enable, 84 pcic_chip_socket_disable, 85 }; 86 87 static void pcic_pci_callback(struct device *); 88 89 int 90 pcic_pci_match(parent, match, aux) 91 struct device *parent; 92 struct cfdata *match; 93 void *aux; 94 { 95 struct pci_attach_args *pa = (struct pci_attach_args *) aux; 96 97 switch (PCI_VENDOR(pa->pa_id)) { 98 case PCI_VENDOR_CIRRUS: 99 switch(PCI_PRODUCT(pa->pa_id)) { 100 case PCI_PRODUCT_CIRRUS_CL_PD6729: 101 break; 102 default: 103 return (0); 104 } 105 break; 106 default: 107 return (0); 108 } 109 return (1); 110 } 111 112 void pcic_isa_config_interrupts __P((struct device *)); 113 114 void 115 pcic_pci_attach(parent, self, aux) 116 struct device *parent, *self; 117 void *aux; 118 { 119 struct pcic_softc *sc = (void *) self; 120 struct pcic_pci_softc *psc = (void *) self; 121 struct pci_attach_args *pa = aux; 122 pci_chipset_tag_t pc = pa->pa_pc; 123 bus_space_tag_t memt = pa->pa_memt; 124 bus_space_handle_t memh; 125 char *model; 126 127 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, 128 &sc->iot, &sc->ioh, NULL, NULL)) { 129 printf(": can't map i/o space\n"); 130 return; 131 } 132 133 /* 134 * XXX need some memory for mapping pcmcia cards into. Ideally, this 135 * would be completely dynamic. Practically this doesn't work, 136 * because the extent mapper doesn't know about all the devices all 137 * the time. With ISA we could finesse the issue by specifying the 138 * memory region in the config line. We can't do that here, so we 139 * cheat for now. Jason Thorpe, you are my Savior, come up with a fix 140 * :-) 141 */ 142 143 /* Map mem space. */ 144 if (bus_space_map(memt, 0xd0000, 0x4000, 0, &memh)) 145 panic("pcic_pci_attach: can't map mem space"); 146 147 sc->membase = 0xd0000; 148 sc->subregionmask = (1 << (0x4000 / PCIC_MEM_PAGESIZE)) - 1; 149 150 /* same deal for io allocation */ 151 152 sc->iobase = 0x400; 153 sc->iosize = 0xbff; 154 155 /* end XXX */ 156 157 sc->pct = (pcmcia_chipset_tag_t) & pcic_pci_functions; 158 159 sc->memt = memt; 160 sc->memh = memh; 161 162 switch (PCI_PRODUCT(pa->pa_id)) { 163 case PCI_PRODUCT_CIRRUS_CL_PD6729: 164 model = "Cirrus Logic PD6729 PCMCIA controller"; 165 break; 166 default: 167 model = "Model unknown"; 168 break; 169 } 170 171 printf(": %s\n", model); 172 173 /* Enable the card. */ 174 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, 175 pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) | 176 PCI_COMMAND_MASTER_ENABLE); 177 178 pcic_attach(sc); 179 180 /* 181 * Check to see if we're using PCI or ISA interrupts. I don't 182 * know of any i386 systems that use the 6729 in PCI interrupt 183 * mode, but maybe when the PCMCIA code runs on other platforms 184 * we'll need to fix this. 185 */ 186 pcic_write(&sc->handle[0], PCIC_CIRRUS_EXTENDED_INDEX, 187 PCIC_CIRRUS_EXT_CONTROL_1); 188 if ((pcic_read(&sc->handle[0], PCIC_CIRRUS_EXTENDED_DATA) & 189 PCIC_CIRRUS_EXT_CONTROL_1_PCI_INTR_MASK)) { 190 printf("%s: PCI interrupts not supported\n", 191 sc->dev.dv_xname); 192 return; 193 } 194 195 psc->intr_est = pcic_pci_machdep_intr_est(pc); 196 sc->irq = -1; 197 198 #if 0 199 /* Map and establish the interrupt. */ 200 sc->ih = pcic_pci_machdep_pcic_intr_establish(sc, pcic_intr); 201 if (sc->ih == NULL) { 202 printf("%s: couldn't map interrupt\n", sc->dev.dv_xname); 203 return; 204 } 205 #endif 206 207 /* 208 * Defer configuration of children until ISA has had its chance 209 * to use up whatever IO space and IRQs it wants. XXX This will 210 * only work if ISA is attached to a pcib, AND the PCI probe finds 211 * and defers the ISA attachment before this one. 212 */ 213 config_defer(self, pcic_pci_callback); 214 config_interrupts(self, pcic_isa_config_interrupts); 215 } 216 217 static void 218 pcic_pci_callback(self) 219 struct device *self; 220 { 221 struct pcic_softc *sc = (void *) self; 222 223 pcic_attach_sockets(sc); 224 } 225