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