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