xref: /netbsd-src/sys/arch/powerpc/pci/pcib.c (revision 8ac07aec990b9d2e483062509d0a9fa5b4f57cf2)
1 /*	$NetBSD: pcib.c,v 1.4 2008/04/04 16:04:19 matt 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.4 2008/04/04 16:04:19 matt 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 
59 int	pcibmatch(device_t, cfdata_t, void *);
60 void	pcibattach(device_t, device_t, void *);
61 
62 struct pcib_softc {
63 	device_t sc_dev;
64 	struct powerpc_isa_chipset *sc_chipset;
65 };
66 
67 extern struct powerpc_isa_chipset genppc_ict;
68 extern struct genppc_pci_chipset *genppc_pct;
69 
70 CFATTACH_DECL_NEW(pcib, sizeof(struct pcib_softc),
71     pcibmatch, pcibattach, NULL, NULL);
72 
73 void	pcib_callback(device_t);
74 
75 int
76 pcibmatch(device_t parent, cfdata_t 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 
107 void
108 pcibattach(device_t parent, device_t self, void *aux)
109 {
110 	struct pci_attach_args *pa = aux;
111 	struct pcib_softc *sc = device_private(self);
112 	char devinfo[256];
113 	u_int32_t v;
114 	int lvlmask = 0;
115 #ifdef prep
116 	prop_bool_t rav;
117 #endif
118 
119 	sc->sc_dev = self;
120 
121 	/*
122 	 * Just print out a description and defer configuration
123 	 * until all PCI devices have been attached.
124 	 */
125 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
126 	aprint_normal(": %s (rev. 0x%02x)\n", devinfo,
127 	    PCI_REVISION(pa->pa_class));
128 
129 	v = pci_conf_read(pa->pa_pc, pa->pa_tag, 0x40);
130 	if ((v & 0x20) == 0) {
131 		aprint_verbose("%s: PIRQ[0-3] not used\n", self->dv_xname);
132 	} else {
133 		v = pci_conf_read(pa->pa_pc, pa->pa_tag, 0x60);
134 		if ((v & 0x80808080) == 0x80808080) {
135 			aprint_verbose("%s: PIRQ[0-3] disabled\n",
136 			    self->dv_xname);
137 		} else {
138 			int i;
139 			aprint_verbose("%s:", device_xname(self));
140 			for (i = 0; i < 4; i++, v >>= 8) {
141 				if ((v & 0x80) == 0 && (v & 0x0f) != 0) {
142 					aprint_verbose(" PIRQ[%d]=%d", i,
143 					    v & 0x0f);
144 					lvlmask |= (1 << (v & 0x0f));
145 				}
146 			}
147 			aprint_verbose("\n");
148 		}
149 	}
150 
151 	/*
152 	 * If we have an 83C553F-G sitting on a RAVEN host bridge,
153 	 * then we need to rewire some interrupts.
154 	 * The IDE Interrupt Routing Control Register lives at 0x43,
155 	 * and defaults to 0xEF, which means the primary controller
156 	 * interrupts on ivr-14, and the secondary on ivr-15. We
157 	 * reset it to 0xEE to fire them both at ivr-14.
158 	 * We have to rewrite the interrupt map, because the bridge map told
159 	 * us that the interrupt is MPIC 0, which is the bridge intr for
160 	 * the 8259.
161 	 * Additionally, sometimes the PCI Interrupt Routing Control Register
162 	 * is improperly initialized, causing all sorts of wierd interrupt
163 	 * issues on the machine.  The manual says it should default to
164 	 * 0000h (index 45-44h) however it would appear that PPCBUG is
165 	 * setting it up differently.  Reset it to 0000h.
166 	 */
167 
168 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SYMPHONY &&
169 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SYMPHONY_83C553) {
170 		v = pci_conf_read(pa->pa_pc, pa->pa_tag, 0x44) & 0xffff0000;
171 		pci_conf_write(pa->pa_pc, pa->pa_tag, 0x44, v);
172 	}
173 
174 #ifdef prep
175 	rav = prop_dictionary_get(device_properties(parent),
176 	    "prep-raven-pchb");
177 
178 	if (rav != NULL && prop_bool_true(rav) &&
179 	    PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SYMPHONY &&
180 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SYMPHONY_83C553) {
181 
182 		prop_dictionary_t dict, devsub;
183 		prop_number_t pinsub;
184 		struct genppc_pci_chipset_businfo *pbi;
185 
186 		v = pci_conf_read(pa->pa_pc, pa->pa_tag, 0x40) & 0x00ffffff;
187 		v |= 0xee000000;
188 		pci_conf_write(pa->pa_pc, pa->pa_tag, 0x40, v);
189 
190 		pbi = SIMPLEQ_FIRST(&genppc_pct->pc_pbi);
191 		dict = prop_dictionary_get(pbi->pbi_properties,
192 		    "prep-pci-intrmap");
193 		devsub = prop_dictionary_get(dict, "devfunc-11");
194 		pinsub = prop_number_create_integer(14);
195 		prop_dictionary_set(devsub, "pin-A", pinsub);
196 		prop_object_release(pinsub);
197 		aprint_verbose_dev(self, "setting pciide irq to 14\n");
198 		/* irq 14 is level */
199 		lvlmask = 0x0040;
200 	}
201 #endif /* prep */
202 
203 	config_defer(self, pcib_callback);
204 }
205 
206 void
207 pcib_callback(device_t self)
208 {
209 	struct pcib_softc *sc = device_private(self);
210 #if NISA > 0
211 	struct isabus_attach_args iba;
212 
213 	/*
214 	 * Attach the ISA bus behind this bridge.
215 	 */
216 	memset(&iba, 0, sizeof(iba));
217 	sc->sc_chipset = &genppc_ict;
218 	iba.iba_ic = sc->sc_chipset;
219 	iba.iba_iot = &genppc_isa_io_space_tag;
220 	iba.iba_memt = &genppc_isa_mem_space_tag;
221 #if NISADMA > 0
222 	iba.iba_dmat = &isa_bus_dma_tag;
223 #endif
224 	config_found_ia(sc->sc_dev, "isabus", &iba, isabusprint);
225 #endif
226 }
227