1 /* $OpenBSD: pcib.c,v 1.4 2012/08/18 16:00:20 miod Exp $ */ 2 3 /*- 4 * Copyright (c) 1996 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/param.h> 33 #include <sys/systm.h> 34 #include <sys/device.h> 35 36 #include <machine/autoconf.h> 37 #include <machine/bus.h> 38 39 #include <dev/pci/pcireg.h> 40 #include <dev/pci/pcivar.h> 41 #include <dev/pci/pcidevs.h> 42 43 #include <dev/isa/isavar.h> 44 45 #include <dev/pci/glxreg.h> 46 #include <dev/pci/glxvar.h> 47 48 #include "isa.h" 49 50 int pcibmatch(struct device *, void *, void *); 51 void pcibattach(struct device *, struct device *, void *); 52 53 struct pcib_softc { 54 struct device sc_dev; 55 bus_space_tag_t sc_iot; 56 bus_space_tag_t sc_memt; 57 bus_dma_tag_t sc_dmat; 58 }; 59 60 const struct cfattach pcib_ca = { 61 sizeof(struct pcib_softc), pcibmatch, pcibattach 62 }; 63 64 void pcib_callback(struct device *); 65 void pcib_isa_attach(struct pcib_softc *, bus_space_tag_t, bus_space_tag_t, 66 bus_dma_tag_t); 67 int pcib_print(void *, const char *); 68 69 struct cfdriver pcib_cd = { 70 NULL, "pcib", DV_DULL 71 }; 72 73 int 74 pcibmatch(struct device *parent, void *match, void *aux) 75 { 76 struct pci_attach_args *pa = aux; 77 78 switch (PCI_VENDOR(pa->pa_id)) { 79 case PCI_VENDOR_INTEL: 80 switch (PCI_PRODUCT(pa->pa_id)) { 81 case PCI_PRODUCT_INTEL_SIO: 82 case PCI_PRODUCT_INTEL_82371MX: 83 case PCI_PRODUCT_INTEL_82371AB_ISA: 84 case PCI_PRODUCT_INTEL_82440MX_ISA: 85 /* The above bridges mis-identify themselves */ 86 return (1); 87 } 88 break; 89 case PCI_VENDOR_SIS: 90 switch (PCI_PRODUCT(pa->pa_id)) { 91 case PCI_PRODUCT_SIS_85C503: 92 /* mis-identifies itself as a miscellaneous prehistoric */ 93 return (1); 94 } 95 break; 96 case PCI_VENDOR_VIATECH: 97 switch (PCI_PRODUCT(pa->pa_id)) { 98 case PCI_PRODUCT_VIATECH_VT82C686A_SMB: 99 /* mis-identifies itself as a ISA bridge */ 100 return (0); 101 } 102 break; 103 } 104 105 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE && 106 PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA) 107 return (1); 108 109 return (0); 110 } 111 112 void 113 pcibattach(struct device *parent, struct device *self, void *aux) 114 { 115 struct pcib_softc *sc = (struct pcib_softc *)self; 116 struct pci_attach_args *pa = (struct pci_attach_args *)aux; 117 118 printf("\n"); 119 120 /* 121 * If we are actually a glxpcib, we can't use softc fields 122 * beyond the base struct device, for this would corrupt 123 * the glxpcib softc. Decide to attach isa immediately in this 124 * case - glxpcib-based designs are not expected to have ISA 125 * slots and attaching isa early should not cause problems. 126 */ 127 if (strncmp(self->dv_xname, "glxpcib", 7) == 0) { 128 pcib_isa_attach(sc, pa->pa_iot, pa->pa_memt, pa->pa_dmat); 129 } else { 130 /* 131 * Wait until all PCI devices are attached before attaching isa; 132 * existing pcib code on other platforms mentions that not 133 * doing this ``might mess the interrupt setup on some 134 * systems'', although this is very unlikely to be the case 135 * on loongson. 136 */ 137 sc->sc_iot = pa->pa_iot; 138 sc->sc_memt = pa->pa_memt; 139 sc->sc_dmat = pa->pa_dmat; 140 config_defer(self, pcib_callback); 141 } 142 } 143 144 void 145 pcib_callback(struct device *self) 146 { 147 struct pcib_softc *sc = (struct pcib_softc *)self; 148 149 pcib_isa_attach(sc, sc->sc_iot, sc->sc_memt, sc->sc_dmat); 150 } 151 152 void 153 pcib_isa_attach(struct pcib_softc *sc, bus_space_tag_t iot, 154 bus_space_tag_t memt, bus_dma_tag_t dmat) 155 { 156 struct isabus_attach_args iba; 157 158 /* 159 * Attach the ISA bus behind this bridge. 160 */ 161 memset(&iba, 0, sizeof(iba)); 162 iba.iba_busname = "isa"; 163 iba.iba_iot = iot; 164 iba.iba_memt = memt; 165 #if NISADMA > 0 166 iba.iba_dmat = dmat; 167 #endif 168 iba.iba_ic = sys_platform->isa_chipset; 169 if (iba.iba_ic != NULL) 170 config_found(&sc->sc_dev, &iba, pcib_print); 171 } 172 173 int 174 pcib_print(void *aux, const char *pnp) 175 { 176 /* Only ISAs can attach to pcib's; easy. */ 177 if (pnp) 178 printf("isa at %s", pnp); 179 return (UNCONF); 180 } 181