pcib.c revision 1.1.2.4 1 /* $NetBSD: pcib.c,v 1.1.2.4 2008/02/27 08:36:29 yamt 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 FOUNDATION OR CONTRIBUTORS
30 * BE 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.1.2.4 2008/02/27 08:36:29 yamt 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
58 struct pcib_softc {
59 pci_chipset_tag_t sc_pc;
60 pcitag_t sc_tag;
61 };
62
63 int pcibmatch(device_t, struct cfdata *, void *);
64 void pcibattach(device_t, device_t, void *);
65 int pcibdetach(device_t, int);
66 void pcibchilddet(device_t, device_t);
67
68 CFATTACH_DECL2_NEW(pcib, sizeof(struct pcib_softc),
69 pcibmatch, pcibattach, pcibdetach, NULL, NULL, pcibchilddet);
70
71 void pcib_callback(device_t);
72
73 int
74 pcibmatch(device_t parent, struct cfdata *match, void *aux)
75 {
76 struct pci_attach_args *pa = aux;
77
78 #if 0
79 /*
80 * PCI-ISA bridges are matched on class/subclass.
81 * This list contains only the bridges where correct
82 * (or incorrect) behaviour is not yet confirmed.
83 */
84 switch (PCI_VENDOR(pa->pa_id)) {
85 case PCI_VENDOR_INTEL:
86 switch (PCI_PRODUCT(pa->pa_id)) {
87 case PCI_PRODUCT_INTEL_82426EX:
88 case PCI_PRODUCT_INTEL_82380AB:
89 return (1);
90 }
91 break;
92
93 case PCI_VENDOR_UMC:
94 switch (PCI_PRODUCT(pa->pa_id)) {
95 case PCI_PRODUCT_UMC_UM8886F:
96 case PCI_PRODUCT_UMC_UM82C886:
97 return (1);
98 }
99 break;
100 case PCI_VENDOR_ALI:
101 switch (PCI_PRODUCT(pa->pa_id)) {
102 case PCI_PRODUCT_ALI_M1449:
103 case PCI_PRODUCT_ALI_M1543:
104 return (1);
105 }
106 break;
107 case PCI_VENDOR_COMPAQ:
108 switch (PCI_PRODUCT(pa->pa_id)) {
109 case PCI_PRODUCT_COMPAQ_PCI_ISA_BRIDGE:
110 return (1);
111 }
112 break;
113 case PCI_VENDOR_VIATECH:
114 switch (PCI_PRODUCT(pa->pa_id)) {
115 case PCI_PRODUCT_VIATECH_VT82C570MV:
116 case PCI_PRODUCT_VIATECH_VT82C586_ISA:
117 return (1);
118 }
119 break;
120 }
121 #endif
122
123 /*
124 * some special cases:
125 */
126 switch (PCI_VENDOR(pa->pa_id)) {
127 case PCI_VENDOR_INTEL:
128 switch (PCI_PRODUCT(pa->pa_id)) {
129 case PCI_PRODUCT_INTEL_SIO:
130 /*
131 * The Intel SIO identifies itself as a
132 * miscellaneous prehistoric.
133 */
134 case PCI_PRODUCT_INTEL_82371MX:
135 /*
136 * The Intel 82371MX identifies itself erroneously as a
137 * miscellaneous bridge.
138 */
139 case PCI_PRODUCT_INTEL_82371AB_ISA:
140 /*
141 * Some Intel 82371AB PCI-ISA bridge identifies
142 * itself as miscellaneous bridge.
143 */
144 return (1);
145 }
146 break;
147 case PCI_VENDOR_SIS:
148 switch (PCI_PRODUCT(pa->pa_id)) {
149 case PCI_PRODUCT_SIS_85C503:
150 /*
151 * The SIS 85C503 identifies itself as a
152 * miscellaneous prehistoric.
153 */
154 return (1);
155 }
156 break;
157 case PCI_VENDOR_VIATECH:
158 switch (PCI_PRODUCT(pa->pa_id)) {
159 case PCI_PRODUCT_VIATECH_VT82C686A_SMB:
160 /*
161 * The VIA VT82C686A SMBus Controller itself as
162 * ISA bridge, but it's wrong !
163 */
164 return (0);
165 }
166 /*
167 * The Cyrix cs5530 PCI host bridge does not have a broken
168 * latch on the i8254 clock core, unlike its predecessors
169 * the cs5510 and cs5520. This reverses the setting from
170 * i386/i386/identcpu.c where it arguably should not have
171 * been set in the first place. XXX
172 */
173 case PCI_VENDOR_CYRIX:
174 switch (PCI_PRODUCT(pa->pa_id)) {
175 case PCI_PRODUCT_CYRIX_CX5530_PCIB:
176 {
177 extern int clock_broken_latch;
178
179 clock_broken_latch = 0;
180 }
181 return(1);
182 }
183 break;
184 }
185
186 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
187 PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA) {
188 return (1);
189 }
190
191 return (0);
192 }
193
194 void
195 pcibattach(device_t parent, device_t self, void *aux)
196 {
197 struct pcib_softc *sc = device_private(self);
198 struct pci_attach_args *pa = aux;
199 char devinfo[256];
200
201 aprint_naive("\n");
202 aprint_normal("\n");
203
204 /*
205 * Just print out a description and defer configuration
206 * until all PCI devices have been attached.
207 */
208 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
209 aprint_normal_dev(self, "%s (rev. 0x%02x)\n", devinfo,
210 PCI_REVISION(pa->pa_class));
211
212 sc->sc_pc = pa->pa_pc;
213 sc->sc_tag = pa->pa_tag;
214
215 /* If a more specific pcib implementation has already registered a
216 * power handler, don't overwrite it.
217 */
218 if (!device_pmf_is_registered(self)) {
219 if (!pmf_device_register(self, NULL, NULL))
220 aprint_error_dev(self, "couldn't establish power handler\n");
221 }
222
223 config_defer(self, pcib_callback);
224 }
225
226 int
227 pcibdetach(device_t self, int flags)
228 {
229 int rc;
230
231 if ((rc = config_detach_children(self, flags)) != 0)
232 return rc;
233 pmf_device_deregister(self);
234 return 0;
235 }
236
237 void
238 pcibchilddet(device_t self, device_t child)
239 {
240 /* we keep no references to children, so do nothing */
241 }
242
243 void
244 pcib_callback(device_t self)
245 {
246 struct isabus_attach_args iba;
247
248 /*
249 * Attach the ISA bus behind this bridge.
250 */
251 memset(&iba, 0, sizeof(iba));
252 iba.iba_iot = X86_BUS_SPACE_IO;
253 iba.iba_memt = X86_BUS_SPACE_MEM;
254 #if NISA > 0
255 iba.iba_dmat = &isa_bus_dma_tag;
256 #endif
257 config_found_ia(self, "isabus", &iba, isabusprint);
258 }
259