1 /* $OpenBSD: pcib.c,v 1.3 2010/10/14 21:23:04 pirofti 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 void pcib_callback(struct device *); 53 int pcib_print(void *, const char *); 54 55 struct pcib_softc { 56 struct device sc_dev; 57 bus_space_tag_t sc_iot; 58 bus_space_tag_t sc_memt; 59 bus_dma_tag_t sc_dmat; 60 }; 61 62 const struct cfattach pcib_ca = { 63 sizeof(struct pcib_softc), pcibmatch, pcibattach 64 }; 65 66 struct cfdriver pcib_cd = { 67 NULL, "pcib", DV_DULL 68 }; 69 70 int 71 pcibmatch(struct device *parent, void *match, void *aux) 72 { 73 struct pci_attach_args *pa = aux; 74 75 switch (PCI_VENDOR(pa->pa_id)) { 76 case PCI_VENDOR_INTEL: 77 switch (PCI_PRODUCT(pa->pa_id)) { 78 case PCI_PRODUCT_INTEL_SIO: 79 case PCI_PRODUCT_INTEL_82371MX: 80 case PCI_PRODUCT_INTEL_82371AB_ISA: 81 case PCI_PRODUCT_INTEL_82440MX_ISA: 82 /* The above bridges mis-identify themselves */ 83 return (1); 84 } 85 break; 86 case PCI_VENDOR_SIS: 87 switch (PCI_PRODUCT(pa->pa_id)) { 88 case PCI_PRODUCT_SIS_85C503: 89 /* mis-identifies itself as a miscellaneous prehistoric */ 90 return (1); 91 } 92 break; 93 case PCI_VENDOR_VIATECH: 94 switch (PCI_PRODUCT(pa->pa_id)) { 95 case PCI_PRODUCT_VIATECH_VT82C686A_SMB: 96 /* mis-identifies itself as a ISA bridge */ 97 return (0); 98 } 99 break; 100 } 101 102 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE && 103 PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA) 104 return (1); 105 106 return (0); 107 } 108 109 void 110 pcibattach(struct device *parent, struct device *self, void *aux) 111 { 112 struct pcib_softc *sc = (struct pcib_softc *)self; 113 struct pci_attach_args *pa = (struct pci_attach_args *)aux; 114 115 printf("\n"); 116 117 /* 118 * Wait until all PCI devices are attached before attaching isa; 119 * otherwise this might mess the interrupt setup on some systems. 120 */ 121 sc->sc_iot = pa->pa_iot; 122 sc->sc_memt = pa->pa_memt; 123 sc->sc_dmat = pa->pa_dmat; 124 config_defer(self, pcib_callback); 125 } 126 127 void 128 pcib_callback(struct device *self) 129 { 130 struct pcib_softc *sc = (struct pcib_softc *)self; 131 struct isabus_attach_args iba; 132 133 /* 134 * Attach the ISA bus behind this bridge. 135 * Note that, since we only have a few legacy I/O devices and 136 * no ISA slots, we can attach immediately. 137 */ 138 memset(&iba, 0, sizeof(iba)); 139 iba.iba_busname = "isa"; 140 iba.iba_iot = sc->sc_iot; 141 iba.iba_memt = sc->sc_memt; 142 #if NISADMA > 0 143 iba.iba_dmat = sc->sc_dmat; 144 #endif 145 iba.iba_ic = sys_platform->isa_chipset; 146 if (iba.iba_ic != NULL) 147 config_found(self, &iba, pcib_print); 148 } 149 150 int 151 pcib_print(void *aux, const char *pnp) 152 { 153 /* Only ISAs can attach to pcib's; easy. */ 154 if (pnp) 155 printf("isa at %s", pnp); 156 return (UNCONF); 157 } 158