xref: /netbsd-src/sys/arch/x86/pci/pcib.c (revision 274254cdae52594c1aa480a736aef78313d15c9c)
1 /*	$NetBSD: pcib.c,v 1.8 2009/04/02 00:09:32 dyoung 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  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: pcib.c,v 1.8 2009/04/02 00:09:32 dyoung Exp $");
34 
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39 
40 #include <machine/bus.h>
41 
42 #include <dev/isa/isavar.h>
43 
44 #include <dev/pci/pcivar.h>
45 #include <dev/pci/pcireg.h>
46 
47 #include <dev/pci/pcidevs.h>
48 
49 #include "isa.h"
50 #include "pcibvar.h"
51 
52 int	pcibmatch(device_t, cfdata_t, void *);
53 void	pcibattach(device_t, device_t, void *);
54 int	pcibdetach(device_t, int);
55 void	pcibchilddet(device_t, device_t);
56 
57 CFATTACH_DECL3_NEW(pcib, sizeof(struct pcib_softc),
58     pcibmatch, pcibattach, pcibdetach, NULL, NULL, pcibchilddet,
59     DVF_DETACH_SHUTDOWN);
60 
61 void	pcib_callback(device_t);
62 
63 int
64 pcibmatch(device_t parent, cfdata_t match, void *aux)
65 {
66 	struct pci_attach_args *pa = aux;
67 
68 #if 0
69 	/*
70 	 * PCI-ISA bridges are matched on class/subclass.
71 	 * This list contains only the bridges where correct
72 	 * (or incorrect) behaviour is not yet confirmed.
73 	 */
74 	switch (PCI_VENDOR(pa->pa_id)) {
75 	case PCI_VENDOR_INTEL:
76 		switch (PCI_PRODUCT(pa->pa_id)) {
77 		case PCI_PRODUCT_INTEL_82426EX:
78 		case PCI_PRODUCT_INTEL_82380AB:
79 			return (1);
80 		}
81 		break;
82 
83 	case PCI_VENDOR_UMC:
84 		switch (PCI_PRODUCT(pa->pa_id)) {
85 		case PCI_PRODUCT_UMC_UM8886F:
86 		case PCI_PRODUCT_UMC_UM82C886:
87 			return (1);
88 		}
89 		break;
90 	case PCI_VENDOR_ALI:
91 		switch (PCI_PRODUCT(pa->pa_id)) {
92 		case PCI_PRODUCT_ALI_M1449:
93 		case PCI_PRODUCT_ALI_M1543:
94 			return (1);
95 		}
96 		break;
97 	case PCI_VENDOR_COMPAQ:
98 		switch (PCI_PRODUCT(pa->pa_id)) {
99 		case PCI_PRODUCT_COMPAQ_PCI_ISA_BRIDGE:
100 			return (1);
101 		}
102 		break;
103 	case PCI_VENDOR_VIATECH:
104 		switch (PCI_PRODUCT(pa->pa_id)) {
105 		case PCI_PRODUCT_VIATECH_VT82C570MV:
106 		case PCI_PRODUCT_VIATECH_VT82C586_ISA:
107 			return (1);
108 		}
109 		break;
110 	}
111 #endif
112 
113 	/*
114 	 * some special cases:
115 	 */
116 	switch (PCI_VENDOR(pa->pa_id)) {
117 	case PCI_VENDOR_INTEL:
118 		switch (PCI_PRODUCT(pa->pa_id)) {
119 		case PCI_PRODUCT_INTEL_SIO:
120 			/*
121 			 * The Intel SIO identifies itself as a
122 			 * miscellaneous prehistoric.
123 			 */
124 		case PCI_PRODUCT_INTEL_82371MX:
125 			/*
126 			 * The Intel 82371MX identifies itself erroneously as a
127 			 * miscellaneous bridge.
128 			 */
129 		case PCI_PRODUCT_INTEL_82371AB_ISA:
130 			/*
131 			 * Some Intel 82371AB PCI-ISA bridge identifies
132 			 * itself as miscellaneous bridge.
133 			 */
134 			return (1);
135 		}
136 		break;
137 	case PCI_VENDOR_SIS:
138 		switch (PCI_PRODUCT(pa->pa_id)) {
139 		case PCI_PRODUCT_SIS_85C503:
140 			/*
141 			 * The SIS 85C503 identifies itself as a
142 			 * miscellaneous prehistoric.
143 			 */
144 			return (1);
145 		}
146 		break;
147 	case PCI_VENDOR_VIATECH:
148 		switch (PCI_PRODUCT(pa->pa_id)) {
149 		case PCI_PRODUCT_VIATECH_VT82C686A_SMB:
150 			/*
151 			 * The VIA VT82C686A SMBus Controller itself as
152 			 * ISA bridge, but it's wrong !
153 			 */
154 			return (0);
155 		}
156 	/*
157 	 * The Cyrix cs5530 PCI host bridge does not have a broken
158 	 * latch on the i8254 clock core, unlike its predecessors
159 	 * the cs5510 and cs5520. This reverses the setting from
160 	 * i386/i386/identcpu.c where it arguably should not have
161 	 * been set in the first place. XXX
162 	 */
163 	case PCI_VENDOR_CYRIX:
164 		switch (PCI_PRODUCT(pa->pa_id)) {
165 		case PCI_PRODUCT_CYRIX_CX5530_PCIB:
166 #if !defined(XEN)
167 			{
168 				extern int clock_broken_latch;
169 
170 				clock_broken_latch = 0;
171 			}
172 #endif
173 			return(1);
174 		}
175 		break;
176 	}
177 
178 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
179 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA) {
180 		return (1);
181 	}
182 
183 	return (0);
184 }
185 
186 void
187 pcibattach(device_t parent, device_t self, void *aux)
188 {
189 	struct pcib_softc *sc = device_private(self);
190 	struct pci_attach_args *pa = aux;
191 	char devinfo[256];
192 
193 	aprint_naive("\n");
194 	aprint_normal("\n");
195 
196 	/*
197 	 * Just print out a description and defer configuration
198 	 * until all PCI devices have been attached.
199 	 */
200 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
201 	aprint_normal_dev(self, "%s (rev. 0x%02x)\n", devinfo,
202 	    PCI_REVISION(pa->pa_class));
203 
204 	sc->sc_pc = pa->pa_pc;
205 	sc->sc_tag = pa->pa_tag;
206 
207 	/* If a more specific pcib implementation has already registered a
208 	 * power handler, don't overwrite it.
209 	 */
210  	if (!device_pmf_is_registered(self)) {
211  		if (!pmf_device_register(self, NULL, NULL))
212  	    		aprint_error_dev(self, "couldn't establish power handler\n");
213 	}
214 
215 	config_defer(self, pcib_callback);
216 }
217 
218 int
219 pcibdetach(device_t self, int flags)
220 {
221 	int rc;
222 
223 	if ((rc = config_detach_children(self, flags)) != 0)
224 		return rc;
225 	pmf_device_deregister(self);
226 	return 0;
227 }
228 
229 void
230 pcibchilddet(device_t self, device_t child)
231 {
232 	/* we keep no references to children, so do nothing */
233 }
234 
235 void
236 pcib_callback(device_t self)
237 {
238 	struct isabus_attach_args iba;
239 
240 	/*
241 	 * Attach the ISA bus behind this bridge.
242 	 */
243 	memset(&iba, 0, sizeof(iba));
244 	iba.iba_iot = X86_BUS_SPACE_IO;
245 	iba.iba_memt = X86_BUS_SPACE_MEM;
246 #if NISA > 0
247 	iba.iba_dmat = &isa_bus_dma_tag;
248 #endif
249 	config_found_ia(self, "isabus", &iba, isabusprint);
250 }
251