1 /*- 2 * Copyright (c) 1994,1995 Stefan Esser, Wolfgang StanglMeier 3 * Copyright (c) 2000 Michael Smith <msmith@freebsd.org> 4 * Copyright (c) 2000 BSDi 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 AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * $FreeBSD$ 31 */ 32 33 /* 34 * PCI:ISA bridge support 35 */ 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/kernel.h> 40 #include <machine/bus.h> 41 #include <machine/resource.h> 42 #include <sys/bus.h> 43 #include <sys/rman.h> 44 45 #include <isa/isavar.h> 46 #include <pci/pcivar.h> 47 #include <pci/pcireg.h> 48 49 #define ELCR_IOADDR 0x4d0 /* Interrupt Edge/Level Control Registers */ 50 #define ELCR_IOLEN 2 51 52 struct isab_softc { 53 struct resource *elcr_res; 54 u_char saved_elcr[ELCR_IOLEN]; 55 }; 56 57 static int isab_probe(device_t dev); 58 static int pci_isab_attach(device_t dev); 59 static int isab_detach(device_t dev); 60 static int isab_resume(device_t dev); 61 static int isab_suspend(device_t dev); 62 63 static device_method_t isab_methods[] = { 64 /* Device interface */ 65 DEVMETHOD(device_probe, isab_probe), 66 DEVMETHOD(device_attach, pci_isab_attach), 67 DEVMETHOD(device_detach, isab_detach), 68 DEVMETHOD(device_shutdown, bus_generic_shutdown), 69 DEVMETHOD(device_suspend, isab_suspend), 70 DEVMETHOD(device_resume, isab_resume), 71 72 /* Bus interface */ 73 DEVMETHOD(bus_print_child, bus_generic_print_child), 74 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource), 75 DEVMETHOD(bus_release_resource, bus_generic_release_resource), 76 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 77 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 78 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), 79 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 80 81 { 0, 0 } 82 }; 83 84 static driver_t isab_driver = { 85 "isab", 86 isab_methods, 87 sizeof(struct isab_softc), 88 }; 89 90 DRIVER_MODULE(isab, pci, isab_driver, isab_devclass, 0, 0); 91 92 /* 93 * XXX we need to add a quirk list here for bridges that don't correctly 94 * report themselves. 95 */ 96 static int 97 isab_probe(device_t dev) 98 { 99 int matched = 0; 100 101 /* 102 * Try for a generic match based on class/subclass. 103 */ 104 if ((pci_get_class(dev) == PCIC_BRIDGE) && 105 (pci_get_subclass(dev) == PCIS_BRIDGE_ISA)) { 106 matched = 1; 107 } else { 108 /* 109 * These are devices that we *know* are PCI:ISA bridges. 110 * Sometimes, however, they don't report themselves as 111 * such. Check in case one of them is pretending to be 112 * something else. 113 */ 114 switch (pci_get_devid(dev)) { 115 case 0x04848086: /* Intel 82378ZB/82378IB */ 116 case 0x122e8086: /* Intel 82371FB */ 117 case 0x70008086: /* Intel 82371SB */ 118 case 0x71108086: /* Intel 82371AB */ 119 case 0x71988086: /* Intel 82443MX */ 120 case 0x24108086: /* Intel 82801AA (ICH) */ 121 case 0x24208086: /* Intel 82801AB (ICH0) */ 122 case 0x24408086: /* Intel 82801AB (ICH2) */ 123 case 0x00061004: /* VLSI 82C593 */ 124 case 0x05861106: /* VIA 82C586 */ 125 case 0x05961106: /* VIA 82C596 */ 126 case 0x06861106: /* VIA 82C686 */ 127 case 0x153310b9: /* AcerLabs M1533 */ 128 case 0x154310b9: /* AcerLabs M1543 */ 129 case 0x00081039: /* SiS 85c503 */ 130 case 0x00001078: /* Cyrix Cx5510 */ 131 case 0x01001078: /* Cyrix Cx5530 */ 132 case 0xc7001045: /* OPTi 82C700 (FireStar) */ 133 case 0x00011033: /* NEC 0001 (C-bus) */ 134 case 0x002c1033: /* NEC 002C (C-bus) */ 135 case 0x003b1033: /* NEC 003B (C-bus) */ 136 case 0x886a1060: /* UMC UM8886 ISA */ 137 case 0x02001166: /* ServerWorks IB6566 PCI */ 138 if (bootverbose) 139 printf("PCI-ISA bridge with incorrect subclass 0x%x\n", 140 pci_get_subclass(dev)); 141 matched = 1; 142 break; 143 144 default: 145 break; 146 } 147 } 148 149 if (matched) { 150 device_set_desc(dev, "PCI-ISA bridge"); 151 return(-10000); 152 } 153 return(ENXIO); 154 } 155 156 static int 157 pci_isab_attach(device_t dev) 158 { 159 struct isab_softc *sc = device_get_softc(dev); 160 int error, rid; 161 162 /* 163 * Attach an ISA bus. Note that we can only have one ISA bus. 164 */ 165 error = isab_attach(dev); 166 if (error) 167 return (error); 168 169 switch (pci_get_devid(dev)) { 170 case 0x71108086: /* Intel 82371AB */ 171 /* 172 * Sometimes the ELCR (Edge/Level Control Register) is not restored 173 * correctly on resume by the BIOS, so we handle it ourselves. 174 */ 175 rid = 0; 176 bus_set_resource(dev, SYS_RES_IOPORT, rid, ELCR_IOADDR, ELCR_IOLEN); 177 sc->elcr_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, 178 RF_ACTIVE); 179 if (sc->elcr_res == NULL) 180 device_printf(dev, "failed to allocate ELCR resource\n"); 181 break; 182 } 183 184 return(0); 185 } 186 187 static int 188 isab_detach(device_t dev) 189 { 190 struct isab_softc *sc = device_get_softc(dev); 191 192 if (sc->elcr_res != NULL) 193 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->elcr_res); 194 195 return (bus_generic_detach(dev)); 196 } 197 198 static int 199 isab_suspend(device_t dev) 200 { 201 struct isab_softc *sc = device_get_softc(dev); 202 bus_space_tag_t bst; 203 bus_space_handle_t bsh; 204 int i; 205 206 /* Save the ELCR if required. */ 207 if (sc->elcr_res != NULL) { 208 bst = rman_get_bustag(sc->elcr_res); 209 bsh = rman_get_bushandle(sc->elcr_res); 210 for (i = 0; i < ELCR_IOLEN; i++) 211 sc->saved_elcr[i] = bus_space_read_1(bst, bsh, i); 212 } 213 214 return (bus_generic_suspend(dev)); 215 } 216 217 static int 218 isab_resume(device_t dev) 219 { 220 struct isab_softc *sc = device_get_softc(dev); 221 bus_space_tag_t bst; 222 bus_space_handle_t bsh; 223 int i; 224 225 /* Restore the ELCR if required. */ 226 if (sc->elcr_res != NULL) { 227 bst = rman_get_bustag(sc->elcr_res); 228 bsh = rman_get_bushandle(sc->elcr_res); 229 for (i = 0; i < ELCR_IOLEN; i++) 230 bus_space_write_1(bst, bsh, i, sc->saved_elcr[i]); 231 } 232 233 return (bus_generic_resume(dev)); 234 } 235