pcib.c revision 1.3
1/* $NetBSD: pcib.c,v 1.3 2008/01/17 23:42:59 garbled Exp $ */ 2 3/*- 4 * Copyright (c) 1996, 1998 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 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39#include <sys/cdefs.h> 40__KERNEL_RCSID(0, "$NetBSD: pcib.c,v 1.3 2008/01/17 23:42:59 garbled Exp $"); 41 42#include <sys/types.h> 43#include <sys/param.h> 44#include <sys/systm.h> 45#include <sys/device.h> 46 47#include <machine/bus.h> 48 49#include <dev/isa/isavar.h> 50 51#include <dev/pci/pcivar.h> 52#include <dev/pci/pcireg.h> 53 54#include <dev/pci/pcidevs.h> 55 56#include "isa.h" 57#include "isadma.h" 58 59int pcibmatch(struct device *, struct cfdata *, void *); 60void pcibattach(struct device *, struct device *, void *); 61 62struct pcib_softc { 63 struct device sc_dev; 64 struct powerpc_isa_chipset *sc_chipset; 65}; 66 67extern struct powerpc_isa_chipset genppc_ict; 68extern struct genppc_pci_chipset *genppc_pct; 69 70CFATTACH_DECL(pcib, sizeof(struct pcib_softc), 71 pcibmatch, pcibattach, NULL, NULL); 72 73void pcib_callback(struct device *); 74 75int 76pcibmatch(struct device *parent, struct cfdata *cf, void *aux) 77{ 78 struct pci_attach_args *pa = aux; 79 80 /* 81 * Match PCI-ISA bridge. 82 */ 83 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE && 84 PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA) { 85 return (1); 86 } 87 88 /* 89 * some special cases: 90 */ 91 switch (PCI_VENDOR(pa->pa_id)) { 92 case PCI_VENDOR_INTEL: 93 switch (PCI_PRODUCT(pa->pa_id)) { 94 case PCI_PRODUCT_INTEL_SIO: 95 /* 96 * The Intel SIO identifies itself as a 97 * miscellaneous prehistoric. 98 */ 99 return (1); 100 } 101 break; 102 } 103 104 return (0); 105} 106 107void 108pcibattach(struct device *parent, struct device *self, void *aux) 109{ 110 struct pci_attach_args *pa = aux; 111 char devinfo[256]; 112 u_int32_t v; 113 int lvlmask = 0; 114#ifdef prep 115 prop_bool_t rav; 116#endif 117 118 /* 119 * Just print out a description and defer configuration 120 * until all PCI devices have been attached. 121 */ 122 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo)); 123 aprint_normal(": %s (rev. 0x%02x)\n", devinfo, 124 PCI_REVISION(pa->pa_class)); 125 126 v = pci_conf_read(pa->pa_pc, pa->pa_tag, 0x40); 127 if ((v & 0x20) == 0) { 128 aprint_verbose("%s: PIRQ[0-3] not used\n", self->dv_xname); 129 } else { 130 v = pci_conf_read(pa->pa_pc, pa->pa_tag, 0x60); 131 if ((v & 0x80808080) == 0x80808080) { 132 aprint_verbose("%s: PIRQ[0-3] disabled\n", 133 self->dv_xname); 134 } else { 135 int i; 136 aprint_verbose("%s:", self->dv_xname); 137 for (i = 0; i < 4; i++, v >>= 8) { 138 if ((v & 0x80) == 0 && (v & 0x0f) != 0) { 139 aprint_verbose(" PIRQ[%d]=%d", i, 140 v & 0x0f); 141 lvlmask |= (1 << (v & 0x0f)); 142 } 143 } 144 aprint_verbose("\n"); 145 } 146 } 147 148 /* 149 * If we have an 83C553F-G sitting on a RAVEN host bridge, 150 * then we need to rewire some interrupts. 151 * The IDE Interrupt Routing Control Register lives at 0x43, 152 * and defaults to 0xEF, which means the primary controller 153 * interrupts on ivr-14, and the secondary on ivr-15. We 154 * reset it to 0xEE to fire them both at ivr-14. 155 * We have to rewrite the interrupt map, because the bridge map told 156 * us that the interrupt is MPIC 0, which is the bridge intr for 157 * the 8259. 158 * Additionally, sometimes the PCI Interrupt Routing Control Register 159 * is improperly initialized, causing all sorts of wierd interrupt 160 * issues on the machine. The manual says it should default to 161 * 0000h (index 45-44h) however it would appear that PPCBUG is 162 * setting it up differently. Reset it to 0000h. 163 */ 164 165 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SYMPHONY && 166 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SYMPHONY_83C553) { 167 v = pci_conf_read(pa->pa_pc, pa->pa_tag, 0x44) & 0xffff0000; 168 pci_conf_write(pa->pa_pc, pa->pa_tag, 0x44, v); 169 } 170 171#ifdef prep 172 rav = prop_dictionary_get(device_properties(parent), 173 "prep-raven-pchb"); 174 175 if (rav != NULL && prop_bool_true(rav) && 176 PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SYMPHONY && 177 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SYMPHONY_83C553) { 178 179 prop_dictionary_t dict, devsub; 180 prop_number_t pinsub; 181 struct genppc_pci_chipset_businfo *pbi; 182 183 v = pci_conf_read(pa->pa_pc, pa->pa_tag, 0x40) & 0x00ffffff; 184 v |= 0xee000000; 185 pci_conf_write(pa->pa_pc, pa->pa_tag, 0x40, v); 186 187 pbi = SIMPLEQ_FIRST(&genppc_pct->pc_pbi); 188 dict = prop_dictionary_get(pbi->pbi_properties, 189 "prep-pci-intrmap"); 190 devsub = prop_dictionary_get(dict, "devfunc-11"); 191 pinsub = prop_number_create_integer(14); 192 prop_dictionary_set(devsub, "pin-A", pinsub); 193 prop_object_release(pinsub); 194 aprint_verbose("%s: setting pciide irq to 14\n", 195 self->dv_xname); 196 /* irq 14 is level */ 197 lvlmask = 0x0040; 198 } 199#endif /* prep */ 200 201 config_defer(self, pcib_callback); 202} 203 204void 205pcib_callback(struct device *self) 206{ 207 struct pcib_softc *sc = (struct pcib_softc *)self; 208#if NISA > 0 209 struct isabus_attach_args iba; 210 211 /* 212 * Attach the ISA bus behind this bridge. 213 */ 214 memset(&iba, 0, sizeof(iba)); 215 sc->sc_chipset = &genppc_ict; 216 iba.iba_ic = sc->sc_chipset; 217 iba.iba_iot = &genppc_isa_io_space_tag; 218 iba.iba_memt = &genppc_isa_mem_space_tag; 219#if NISADMA > 0 220 iba.iba_dmat = &isa_bus_dma_tag; 221#endif 222 config_found_ia(&sc->sc_dev, "isabus", &iba, isabusprint); 223#endif 224} 225