pcib.c revision 1.1.4.2 1 1.1.4.2 joerg /* $NetBSD: pcib.c,v 1.1.4.2 2007/10/28 20:11:00 joerg Exp $ */
2 1.1.4.2 joerg
3 1.1.4.2 joerg /*-
4 1.1.4.2 joerg * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
5 1.1.4.2 joerg * All rights reserved.
6 1.1.4.2 joerg *
7 1.1.4.2 joerg * This code is derived from software contributed to The NetBSD Foundation
8 1.1.4.2 joerg * by Jason R. Thorpe.
9 1.1.4.2 joerg *
10 1.1.4.2 joerg * Redistribution and use in source and binary forms, with or without
11 1.1.4.2 joerg * modification, are permitted provided that the following conditions
12 1.1.4.2 joerg * are met:
13 1.1.4.2 joerg * 1. Redistributions of source code must retain the above copyright
14 1.1.4.2 joerg * notice, this list of conditions and the following disclaimer.
15 1.1.4.2 joerg * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.4.2 joerg * notice, this list of conditions and the following disclaimer in the
17 1.1.4.2 joerg * documentation and/or other materials provided with the distribution.
18 1.1.4.2 joerg * 3. All advertising materials mentioning features or use of this software
19 1.1.4.2 joerg * must display the following acknowledgement:
20 1.1.4.2 joerg * This product includes software developed by the NetBSD
21 1.1.4.2 joerg * Foundation, Inc. and its contributors.
22 1.1.4.2 joerg * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.4.2 joerg * contributors may be used to endorse or promote products derived
24 1.1.4.2 joerg * from this software without specific prior written permission.
25 1.1.4.2 joerg *
26 1.1.4.2 joerg * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.4.2 joerg * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.4.2 joerg * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.4.2 joerg * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.4.2 joerg * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.4.2 joerg * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.4.2 joerg * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.4.2 joerg * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.4.2 joerg * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.4.2 joerg * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.4.2 joerg * POSSIBILITY OF SUCH DAMAGE.
37 1.1.4.2 joerg */
38 1.1.4.2 joerg
39 1.1.4.2 joerg #include <sys/cdefs.h>
40 1.1.4.2 joerg __KERNEL_RCSID(0, "$NetBSD: pcib.c,v 1.1.4.2 2007/10/28 20:11:00 joerg Exp $");
41 1.1.4.2 joerg
42 1.1.4.2 joerg #include <sys/types.h>
43 1.1.4.2 joerg #include <sys/param.h>
44 1.1.4.2 joerg #include <sys/systm.h>
45 1.1.4.2 joerg #include <sys/device.h>
46 1.1.4.2 joerg
47 1.1.4.2 joerg #include <machine/bus.h>
48 1.1.4.2 joerg
49 1.1.4.2 joerg #include <dev/isa/isavar.h>
50 1.1.4.2 joerg
51 1.1.4.2 joerg #include <dev/pci/pcivar.h>
52 1.1.4.2 joerg #include <dev/pci/pcireg.h>
53 1.1.4.2 joerg
54 1.1.4.2 joerg #include <dev/pci/pcidevs.h>
55 1.1.4.2 joerg
56 1.1.4.2 joerg #include "isa.h"
57 1.1.4.2 joerg
58 1.1.4.2 joerg struct pcib_softc {
59 1.1.4.2 joerg pci_chipset_tag_t sc_pc;
60 1.1.4.2 joerg pcitag_t sc_tag;
61 1.1.4.2 joerg struct pci_conf_state sc_pciconf;
62 1.1.4.2 joerg };
63 1.1.4.2 joerg
64 1.1.4.2 joerg int pcibmatch(struct device *, struct cfdata *, void *);
65 1.1.4.2 joerg void pcibattach(struct device *, struct device *, void *);
66 1.1.4.2 joerg
67 1.1.4.2 joerg static pnp_status_t pcib_power(device_t, pnp_request_t, void *);
68 1.1.4.2 joerg
69 1.1.4.2 joerg CFATTACH_DECL_NEW(pcib, sizeof(struct pcib_softc),
70 1.1.4.2 joerg pcibmatch, pcibattach, NULL, NULL);
71 1.1.4.2 joerg
72 1.1.4.2 joerg void pcib_callback(struct device *);
73 1.1.4.2 joerg
74 1.1.4.2 joerg int
75 1.1.4.2 joerg pcibmatch(struct device *parent, struct cfdata *match, void *aux)
76 1.1.4.2 joerg {
77 1.1.4.2 joerg struct pci_attach_args *pa = aux;
78 1.1.4.2 joerg
79 1.1.4.2 joerg #if 0
80 1.1.4.2 joerg /*
81 1.1.4.2 joerg * PCI-ISA bridges are matched on class/subclass.
82 1.1.4.2 joerg * This list contains only the bridges where correct
83 1.1.4.2 joerg * (or incorrect) behaviour is not yet confirmed.
84 1.1.4.2 joerg */
85 1.1.4.2 joerg switch (PCI_VENDOR(pa->pa_id)) {
86 1.1.4.2 joerg case PCI_VENDOR_INTEL:
87 1.1.4.2 joerg switch (PCI_PRODUCT(pa->pa_id)) {
88 1.1.4.2 joerg case PCI_PRODUCT_INTEL_82426EX:
89 1.1.4.2 joerg case PCI_PRODUCT_INTEL_82380AB:
90 1.1.4.2 joerg return (1);
91 1.1.4.2 joerg }
92 1.1.4.2 joerg break;
93 1.1.4.2 joerg
94 1.1.4.2 joerg case PCI_VENDOR_UMC:
95 1.1.4.2 joerg switch (PCI_PRODUCT(pa->pa_id)) {
96 1.1.4.2 joerg case PCI_PRODUCT_UMC_UM8886F:
97 1.1.4.2 joerg case PCI_PRODUCT_UMC_UM82C886:
98 1.1.4.2 joerg return (1);
99 1.1.4.2 joerg }
100 1.1.4.2 joerg break;
101 1.1.4.2 joerg case PCI_VENDOR_ALI:
102 1.1.4.2 joerg switch (PCI_PRODUCT(pa->pa_id)) {
103 1.1.4.2 joerg case PCI_PRODUCT_ALI_M1449:
104 1.1.4.2 joerg case PCI_PRODUCT_ALI_M1543:
105 1.1.4.2 joerg return (1);
106 1.1.4.2 joerg }
107 1.1.4.2 joerg break;
108 1.1.4.2 joerg case PCI_VENDOR_COMPAQ:
109 1.1.4.2 joerg switch (PCI_PRODUCT(pa->pa_id)) {
110 1.1.4.2 joerg case PCI_PRODUCT_COMPAQ_PCI_ISA_BRIDGE:
111 1.1.4.2 joerg return (1);
112 1.1.4.2 joerg }
113 1.1.4.2 joerg break;
114 1.1.4.2 joerg case PCI_VENDOR_VIATECH:
115 1.1.4.2 joerg switch (PCI_PRODUCT(pa->pa_id)) {
116 1.1.4.2 joerg case PCI_PRODUCT_VIATECH_VT82C570MV:
117 1.1.4.2 joerg case PCI_PRODUCT_VIATECH_VT82C586_ISA:
118 1.1.4.2 joerg return (1);
119 1.1.4.2 joerg }
120 1.1.4.2 joerg break;
121 1.1.4.2 joerg }
122 1.1.4.2 joerg #endif
123 1.1.4.2 joerg
124 1.1.4.2 joerg /*
125 1.1.4.2 joerg * some special cases:
126 1.1.4.2 joerg */
127 1.1.4.2 joerg switch (PCI_VENDOR(pa->pa_id)) {
128 1.1.4.2 joerg case PCI_VENDOR_INTEL:
129 1.1.4.2 joerg switch (PCI_PRODUCT(pa->pa_id)) {
130 1.1.4.2 joerg case PCI_PRODUCT_INTEL_SIO:
131 1.1.4.2 joerg /*
132 1.1.4.2 joerg * The Intel SIO identifies itself as a
133 1.1.4.2 joerg * miscellaneous prehistoric.
134 1.1.4.2 joerg */
135 1.1.4.2 joerg case PCI_PRODUCT_INTEL_82371MX:
136 1.1.4.2 joerg /*
137 1.1.4.2 joerg * The Intel 82371MX identifies itself erroneously as a
138 1.1.4.2 joerg * miscellaneous bridge.
139 1.1.4.2 joerg */
140 1.1.4.2 joerg case PCI_PRODUCT_INTEL_82371AB_ISA:
141 1.1.4.2 joerg /*
142 1.1.4.2 joerg * Some Intel 82371AB PCI-ISA bridge identifies
143 1.1.4.2 joerg * itself as miscellaneous bridge.
144 1.1.4.2 joerg */
145 1.1.4.2 joerg return (1);
146 1.1.4.2 joerg }
147 1.1.4.2 joerg break;
148 1.1.4.2 joerg case PCI_VENDOR_SIS:
149 1.1.4.2 joerg switch (PCI_PRODUCT(pa->pa_id)) {
150 1.1.4.2 joerg case PCI_PRODUCT_SIS_85C503:
151 1.1.4.2 joerg /*
152 1.1.4.2 joerg * The SIS 85C503 identifies itself as a
153 1.1.4.2 joerg * miscellaneous prehistoric.
154 1.1.4.2 joerg */
155 1.1.4.2 joerg return (1);
156 1.1.4.2 joerg }
157 1.1.4.2 joerg break;
158 1.1.4.2 joerg case PCI_VENDOR_VIATECH:
159 1.1.4.2 joerg switch (PCI_PRODUCT(pa->pa_id)) {
160 1.1.4.2 joerg case PCI_PRODUCT_VIATECH_VT82C686A_SMB:
161 1.1.4.2 joerg /*
162 1.1.4.2 joerg * The VIA VT82C686A SMBus Controller itself as
163 1.1.4.2 joerg * ISA bridge, but it's wrong !
164 1.1.4.2 joerg */
165 1.1.4.2 joerg return (0);
166 1.1.4.2 joerg }
167 1.1.4.2 joerg /*
168 1.1.4.2 joerg * The Cyrix cs5530 PCI host bridge does not have a broken
169 1.1.4.2 joerg * latch on the i8254 clock core, unlike its predecessors
170 1.1.4.2 joerg * the cs5510 and cs5520. This reverses the setting from
171 1.1.4.2 joerg * i386/i386/identcpu.c where it arguably should not have
172 1.1.4.2 joerg * been set in the first place. XXX
173 1.1.4.2 joerg */
174 1.1.4.2 joerg case PCI_VENDOR_CYRIX:
175 1.1.4.2 joerg switch (PCI_PRODUCT(pa->pa_id)) {
176 1.1.4.2 joerg case PCI_PRODUCT_CYRIX_CX5530_PCIB:
177 1.1.4.2 joerg {
178 1.1.4.2 joerg extern int clock_broken_latch;
179 1.1.4.2 joerg
180 1.1.4.2 joerg clock_broken_latch = 0;
181 1.1.4.2 joerg }
182 1.1.4.2 joerg return(1);
183 1.1.4.2 joerg }
184 1.1.4.2 joerg break;
185 1.1.4.2 joerg }
186 1.1.4.2 joerg
187 1.1.4.2 joerg if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
188 1.1.4.2 joerg PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA) {
189 1.1.4.2 joerg return (1);
190 1.1.4.2 joerg }
191 1.1.4.2 joerg
192 1.1.4.2 joerg return (0);
193 1.1.4.2 joerg }
194 1.1.4.2 joerg
195 1.1.4.2 joerg void
196 1.1.4.2 joerg pcibattach(struct device *parent, struct device *self, void *aux)
197 1.1.4.2 joerg {
198 1.1.4.2 joerg struct pcib_softc *sc = device_private(self);
199 1.1.4.2 joerg struct pci_attach_args *pa = aux;
200 1.1.4.2 joerg pnp_device_t *pnp;
201 1.1.4.2 joerg char devinfo[256];
202 1.1.4.2 joerg
203 1.1.4.2 joerg aprint_naive("\n");
204 1.1.4.2 joerg aprint_normal("\n");
205 1.1.4.2 joerg
206 1.1.4.2 joerg /*
207 1.1.4.2 joerg * Just print out a description and defer configuration
208 1.1.4.2 joerg * until all PCI devices have been attached.
209 1.1.4.2 joerg */
210 1.1.4.2 joerg pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
211 1.1.4.2 joerg aprint_normal("%s: %s (rev. 0x%02x)\n", self->dv_xname, devinfo,
212 1.1.4.2 joerg PCI_REVISION(pa->pa_class));
213 1.1.4.2 joerg
214 1.1.4.2 joerg sc->sc_pc = pa->pa_pc;
215 1.1.4.2 joerg sc->sc_tag = pa->pa_tag;
216 1.1.4.2 joerg
217 1.1.4.2 joerg pnp = device_pnp(self);
218 1.1.4.2 joerg
219 1.1.4.2 joerg /* If a more specific pcib implementation has already registered a
220 1.1.4.2 joerg * power handler, don't overwrite it.
221 1.1.4.2 joerg */
222 1.1.4.2 joerg if (pnp->pnp_power == NULL) {
223 1.1.4.2 joerg if (pnp_register(self, pcib_power) != PNP_STATUS_SUCCESS)
224 1.1.4.2 joerg aprint_error("%s: couldn't establish power handler\n",
225 1.1.4.2 joerg device_xname(self));
226 1.1.4.2 joerg }
227 1.1.4.2 joerg
228 1.1.4.2 joerg config_defer(self, pcib_callback);
229 1.1.4.2 joerg }
230 1.1.4.2 joerg
231 1.1.4.2 joerg static pnp_status_t
232 1.1.4.2 joerg pcib_power(device_t dv, pnp_request_t req, void *opaque)
233 1.1.4.2 joerg {
234 1.1.4.2 joerg struct pcib_softc *sc;
235 1.1.4.2 joerg pnp_capabilities_t *pcaps;
236 1.1.4.2 joerg pnp_state_t *pstate;
237 1.1.4.2 joerg pci_chipset_tag_t pc;
238 1.1.4.2 joerg pcitag_t tag;
239 1.1.4.2 joerg
240 1.1.4.2 joerg sc = device_private(dv);
241 1.1.4.2 joerg pc = sc->sc_pc;
242 1.1.4.2 joerg tag = sc->sc_tag;
243 1.1.4.2 joerg
244 1.1.4.2 joerg switch (req) {
245 1.1.4.2 joerg case PNP_REQUEST_GET_CAPABILITIES:
246 1.1.4.2 joerg pcaps = opaque;
247 1.1.4.2 joerg pcaps->state = PNP_STATE_D0 | PNP_STATE_D3;
248 1.1.4.2 joerg break;
249 1.1.4.2 joerg case PNP_REQUEST_GET_STATE:
250 1.1.4.2 joerg pstate = opaque;
251 1.1.4.2 joerg *pstate = PNP_STATE_D0; /* XXX */
252 1.1.4.2 joerg break;
253 1.1.4.2 joerg case PNP_REQUEST_SET_STATE:
254 1.1.4.2 joerg pstate = opaque;
255 1.1.4.2 joerg switch (*pstate) {
256 1.1.4.2 joerg case PNP_STATE_D0:
257 1.1.4.2 joerg pci_conf_restore(pc, tag, &sc->sc_pciconf);
258 1.1.4.2 joerg break;
259 1.1.4.2 joerg case PNP_STATE_D3:
260 1.1.4.2 joerg pci_conf_capture(pc, tag, &sc->sc_pciconf);
261 1.1.4.2 joerg break;
262 1.1.4.2 joerg default:
263 1.1.4.2 joerg return PNP_STATUS_UNSUPPORTED;
264 1.1.4.2 joerg }
265 1.1.4.2 joerg break;
266 1.1.4.2 joerg default:
267 1.1.4.2 joerg return PNP_STATUS_UNSUPPORTED;
268 1.1.4.2 joerg }
269 1.1.4.2 joerg
270 1.1.4.2 joerg return PNP_STATUS_SUCCESS;
271 1.1.4.2 joerg }
272 1.1.4.2 joerg
273 1.1.4.2 joerg void
274 1.1.4.2 joerg pcib_callback(struct device *self)
275 1.1.4.2 joerg {
276 1.1.4.2 joerg struct isabus_attach_args iba;
277 1.1.4.2 joerg
278 1.1.4.2 joerg /*
279 1.1.4.2 joerg * Attach the ISA bus behind this bridge.
280 1.1.4.2 joerg */
281 1.1.4.2 joerg memset(&iba, 0, sizeof(iba));
282 1.1.4.2 joerg iba.iba_iot = X86_BUS_SPACE_IO;
283 1.1.4.2 joerg iba.iba_memt = X86_BUS_SPACE_MEM;
284 1.1.4.2 joerg #if NISA > 0
285 1.1.4.2 joerg iba.iba_dmat = &isa_bus_dma_tag;
286 1.1.4.2 joerg #endif
287 1.1.4.2 joerg config_found_ia(self, "isabus", &iba, isabusprint);
288 1.1.4.2 joerg }
289