1 /* $OpenBSD: i82365_pci.c,v 1.7 2002/11/19 18:40:17 jason Exp $ */ 2 /* $NetBSD: i82365_pci.c,v 1.11 2000/02/24 03:42:44 itohy Exp $ */ 3 4 /* 5 * Copyright (c) 1997 Marc Horowitz. 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. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Marc Horowitz. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /* 34 * XXX this driver frontend is *very* i386 dependent and should be relocated 35 */ 36 37 #include <sys/types.h> 38 #include <sys/param.h> 39 #include <sys/systm.h> 40 #include <sys/kernel.h> 41 #include <sys/device.h> 42 43 #include <dev/ic/i82365reg.h> 44 #include <dev/ic/i82365var.h> 45 46 #include <dev/pci/pcivar.h> 47 #include <dev/pci/pcireg.h> 48 #include <dev/pci/pcidevs.h> 49 #include <dev/pci/i82365_pcivar.h> 50 51 #include <dev/isa/isavar.h> 52 #include <dev/isa/i82365_isavar.h> 53 54 /* 55 * PCI constants. 56 * XXX These should be in a common file! 57 */ 58 #define PCI_CBIO 0x10 /* Configuration Base IO Address */ 59 60 int pcic_pci_match(struct device *, void *, void *); 61 void pcic_pci_attach(struct device *, struct device *, void *); 62 63 struct cfattach pcic_pci_ca = { 64 sizeof(struct pcic_pci_softc), pcic_pci_match, pcic_pci_attach 65 }; 66 67 static struct pcmcia_chip_functions pcic_pci_functions = { 68 pcic_chip_mem_alloc, 69 pcic_chip_mem_free, 70 pcic_chip_mem_map, 71 pcic_chip_mem_unmap, 72 73 pcic_chip_io_alloc, 74 pcic_chip_io_free, 75 pcic_chip_io_map, 76 pcic_chip_io_unmap, 77 78 /* XXX */ 79 pcic_isa_chip_intr_establish, 80 pcic_isa_chip_intr_disestablish, 81 82 pcic_chip_socket_enable, 83 pcic_chip_socket_disable, 84 }; 85 86 int 87 pcic_pci_match(parent, match, aux) 88 struct device *parent; 89 void *match; 90 void *aux; 91 { 92 struct pci_attach_args *pa = (struct pci_attach_args *) aux; 93 94 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CIRRUS && 95 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CIRRUS_CL_PD6729) 96 return (1); 97 return (0); 98 } 99 100 void pcic_isa_config_interrupts(struct device *); 101 102 void 103 pcic_pci_attach(parent, self, aux) 104 struct device *parent, *self; 105 void *aux; 106 { 107 struct pcic_softc *sc = (void *) self; 108 struct pcic_pci_softc *psc = (void *) self; 109 struct pcic_handle *h; 110 struct pci_attach_args *pa = aux; 111 pci_chipset_tag_t pc = pa->pa_pc; 112 bus_space_tag_t memt = pa->pa_memt; 113 bus_space_handle_t memh; 114 bus_size_t size; 115 int irq, i; 116 117 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, 118 &sc->iot, &sc->ioh, NULL, &size, 0)) { 119 printf(": can't map i/o space\n"); 120 return; 121 } 122 123 /* 124 * XXX need some memory for mapping pcmcia cards into. Ideally, this 125 * would be completely dynamic. Practically this doesn't work, 126 * because the extent mapper doesn't know about all the devices all 127 * the time. With ISA we could finesse the issue by specifying the 128 * memory region in the config line. We can't do that here, so we 129 * cheat for now. Jason Thorpe, you are my Savior, come up with a fix 130 * :-) 131 */ 132 133 /* Map mem space. */ 134 if (bus_space_map(memt, 0xd0000, 0x10000, 0, &memh)) { 135 printf(": can't map mem space"); 136 bus_space_unmap(sc->iot, sc->ioh, size); 137 return; 138 } 139 140 sc->membase = 0xd0000; 141 sc->subregionmask = (1 << (0x10000 / PCIC_MEM_PAGESIZE)) - 1; 142 143 /* same deal for io allocation */ 144 145 sc->iobase = 0x400; 146 sc->iosize = 0xbff; 147 148 /* end XXX */ 149 150 sc->pct = (pcmcia_chipset_tag_t) & pcic_pci_functions; 151 152 sc->memt = memt; 153 sc->memh = memh; 154 155 /* Enable the card. */ 156 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, 157 pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) | 158 PCI_COMMAND_MASTER_ENABLE); 159 160 printf("\n"); 161 pcic_attach(sc); 162 pcic_attach_sockets(sc); 163 164 /* 165 * Check to see if we're using PCI or ISA interrupts. I don't 166 * know of any i386 systems that use the 6729 in PCI interrupt 167 * mode, but maybe when the PCMCIA code runs on other platforms 168 * we'll need to fix this. 169 */ 170 pcic_write(&sc->handle[0], PCIC_CIRRUS_EXTENDED_INDEX, 171 PCIC_CIRRUS_EXT_CONTROL_1); 172 if ((pcic_read(&sc->handle[0], PCIC_CIRRUS_EXTENDED_DATA) & 173 PCIC_CIRRUS_EXT_CONTROL_1_PCI_INTR_MASK)) { 174 printf("%s: PCI interrupts not supported\n", 175 sc->dev.dv_xname); 176 return; 177 } 178 179 psc->intr_est = pcic_pci_machdep_intr_est(pc); 180 181 irq = pcic_intr_find(sc, IST_EDGE); 182 183 /* Map and establish the interrupt. */ 184 if (irq) { 185 sc->ih = pcic_pci_machdep_pcic_intr_establish(sc, pcic_intr); 186 if (sc->ih == NULL) { 187 printf("%s: couldnt map interrupt\n", sc->dev.dv_xname); 188 bus_space_unmap(memt, memh, 0x10000); 189 bus_space_unmap(sc->iot, sc->ioh, size); 190 return; 191 } 192 } 193 sc->irq = irq; 194 195 if (irq) { 196 printf("%s: irq %d, ", sc->dev.dv_xname, irq); 197 198 /* Set up the pcic to interrupt on card detect. */ 199 for (i = 0; i < PCIC_NSLOTS; i++) { 200 h = &sc->handle[i]; 201 if (h->flags & PCIC_FLAG_SOCKETP) { 202 pcic_write(h, PCIC_CSC_INTR, 203 (sc->irq << PCIC_CSC_INTR_IRQ_SHIFT) | 204 PCIC_CSC_INTR_CD_ENABLE); 205 powerhook_establish(pcic_power, h); 206 } 207 } 208 } else 209 printf("%s: no irq, ", sc->dev.dv_xname); 210 211 printf("polling enabled\n"); 212 if (sc->poll_established == 0) { 213 timeout_set(&sc->poll_timeout, pcic_poll_intr, sc); 214 timeout_add(&sc->poll_timeout, hz / 2); 215 sc->poll_established = 1; 216 } 217 } 218