FreeBSD/Linux Kernel Cross Reference
sys/i386/i386/legacy.c
1 /*-
2 * Copyright 1998 Massachusetts Institute of Technology
3 *
4 * Permission to use, copy, modify, and distribute this software and
5 * its documentation for any purpose and without fee is hereby
6 * granted, provided that both the above copyright notice and this
7 * permission notice appear in all copies, that both the above
8 * copyright notice and this permission notice appear in all
9 * supporting documentation, and that the name of M.I.T. not be used
10 * in advertising or publicity pertaining to distribution of the
11 * software without specific, written prior permission. M.I.T. makes
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied
14 * warranty.
15 *
16 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
17 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
20 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD: releng/8.2/sys/i386/i386/legacy.c 212892 2010-09-20 07:31:08Z avg $");
32
33 /*
34 * This code implements a system driver for legacy systems that do not
35 * support ACPI or when ACPI support is not present in the kernel.
36 */
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/bus.h>
41 #include <sys/cpu.h>
42 #include <sys/kernel.h>
43 #include <sys/malloc.h>
44 #include <sys/module.h>
45 #include <machine/bus.h>
46 #include <sys/pcpu.h>
47 #include <sys/rman.h>
48 #include <sys/smp.h>
49
50 #include "opt_mca.h"
51 #ifdef DEV_MCA
52 #include <i386/bios/mca_machdep.h>
53 #endif
54
55 #include <machine/legacyvar.h>
56 #include <machine/resource.h>
57
58 static MALLOC_DEFINE(M_LEGACYDEV, "legacydrv", "legacy system device");
59 struct legacy_device {
60 int lg_pcibus;
61 };
62
63 #define DEVTOAT(dev) ((struct legacy_device *)device_get_ivars(dev))
64
65 static int legacy_probe(device_t);
66 static int legacy_attach(device_t);
67 static int legacy_print_child(device_t, device_t);
68 static device_t legacy_add_child(device_t bus, u_int order, const char *name,
69 int unit);
70 static int legacy_read_ivar(device_t, device_t, int, uintptr_t *);
71 static int legacy_write_ivar(device_t, device_t, int, uintptr_t);
72
73 static device_method_t legacy_methods[] = {
74 /* Device interface */
75 DEVMETHOD(device_probe, legacy_probe),
76 DEVMETHOD(device_attach, legacy_attach),
77 DEVMETHOD(device_detach, bus_generic_detach),
78 DEVMETHOD(device_shutdown, bus_generic_shutdown),
79 DEVMETHOD(device_suspend, bus_generic_suspend),
80 DEVMETHOD(device_resume, bus_generic_resume),
81
82 /* Bus interface */
83 DEVMETHOD(bus_print_child, legacy_print_child),
84 DEVMETHOD(bus_add_child, legacy_add_child),
85 DEVMETHOD(bus_read_ivar, legacy_read_ivar),
86 DEVMETHOD(bus_write_ivar, legacy_write_ivar),
87 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
88 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
89 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
90 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
91 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
92 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
93
94 { 0, 0 }
95 };
96
97 static driver_t legacy_driver = {
98 "legacy",
99 legacy_methods,
100 1, /* no softc */
101 };
102 static devclass_t legacy_devclass;
103
104 DRIVER_MODULE(legacy, nexus, legacy_driver, legacy_devclass, 0, 0);
105
106 static int
107 legacy_probe(device_t dev)
108 {
109
110 device_set_desc(dev, "legacy system");
111 device_quiet(dev);
112 return (0);
113 }
114
115 static int
116 legacy_attach(device_t dev)
117 {
118 device_t child;
119
120 /*
121 * Let our child drivers identify any child devices that they
122 * can find. Once that is done attach any devices that we
123 * found.
124 */
125 bus_generic_probe(dev);
126 bus_generic_attach(dev);
127
128 #ifndef PC98
129 /*
130 * If we didn't see EISA or ISA on a pci bridge, create some
131 * connection points now so they show up "on motherboard".
132 */
133 if (!devclass_get_device(devclass_find("eisa"), 0)) {
134 child = BUS_ADD_CHILD(dev, 0, "eisa", 0);
135 if (child == NULL)
136 panic("legacy_attach eisa");
137 device_probe_and_attach(child);
138 }
139 #endif
140 #ifdef DEV_MCA
141 if (MCA_system && !devclass_get_device(devclass_find("mca"), 0)) {
142 child = BUS_ADD_CHILD(dev, 0, "mca", 0);
143 if (child == 0)
144 panic("legacy_probe mca");
145 device_probe_and_attach(child);
146 }
147 #endif
148 if (!devclass_get_device(devclass_find("isa"), 0)) {
149 child = BUS_ADD_CHILD(dev, 0, "isa", 0);
150 if (child == NULL)
151 panic("legacy_attach isa");
152 device_probe_and_attach(child);
153 }
154
155 return 0;
156 }
157
158 static int
159 legacy_print_child(device_t bus, device_t child)
160 {
161 struct legacy_device *atdev = DEVTOAT(child);
162 int retval = 0;
163
164 retval += bus_print_child_header(bus, child);
165 if (atdev->lg_pcibus != -1)
166 retval += printf(" pcibus %d", atdev->lg_pcibus);
167 retval += printf(" on motherboard\n"); /* XXX "motherboard", ick */
168
169 return (retval);
170 }
171
172 static device_t
173 legacy_add_child(device_t bus, u_int order, const char *name, int unit)
174 {
175 device_t child;
176 struct legacy_device *atdev;
177
178 atdev = malloc(sizeof(struct legacy_device), M_LEGACYDEV,
179 M_NOWAIT | M_ZERO);
180 if (atdev == NULL)
181 return(NULL);
182 atdev->lg_pcibus = -1;
183
184 child = device_add_child_ordered(bus, order, name, unit);
185 if (child == NULL)
186 free(atdev, M_LEGACYDEV);
187 else
188 /* should we free this in legacy_child_detached? */
189 device_set_ivars(child, atdev);
190
191 return (child);
192 }
193
194 static int
195 legacy_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
196 {
197 struct legacy_device *atdev = DEVTOAT(child);
198
199 switch (which) {
200 case LEGACY_IVAR_PCIDOMAIN:
201 *result = 0;
202 break;
203 case LEGACY_IVAR_PCIBUS:
204 *result = atdev->lg_pcibus;
205 break;
206 default:
207 return ENOENT;
208 }
209 return 0;
210 }
211
212
213 static int
214 legacy_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
215 {
216 struct legacy_device *atdev = DEVTOAT(child);
217
218 switch (which) {
219 case LEGACY_IVAR_PCIDOMAIN:
220 return EINVAL;
221 case LEGACY_IVAR_PCIBUS:
222 atdev->lg_pcibus = value;
223 break;
224 default:
225 return ENOENT;
226 }
227 return 0;
228 }
229
230 /*
231 * Legacy CPU attachment when ACPI is not available. Drivers like
232 * cpufreq(4) hang off this.
233 */
234 static void cpu_identify(driver_t *driver, device_t parent);
235 static int cpu_read_ivar(device_t dev, device_t child, int index,
236 uintptr_t *result);
237 static device_t cpu_add_child(device_t bus, u_int order, const char *name,
238 int unit);
239 static struct resource_list *cpu_get_rlist(device_t dev, device_t child);
240
241 struct cpu_device {
242 struct resource_list cd_rl;
243 struct pcpu *cd_pcpu;
244 };
245
246 static device_method_t cpu_methods[] = {
247 /* Device interface */
248 DEVMETHOD(device_identify, cpu_identify),
249 DEVMETHOD(device_probe, bus_generic_probe),
250 DEVMETHOD(device_attach, bus_generic_attach),
251 DEVMETHOD(device_detach, bus_generic_detach),
252 DEVMETHOD(device_shutdown, bus_generic_shutdown),
253 DEVMETHOD(device_suspend, bus_generic_suspend),
254 DEVMETHOD(device_resume, bus_generic_resume),
255
256 /* Bus interface */
257 DEVMETHOD(bus_add_child, cpu_add_child),
258 DEVMETHOD(bus_read_ivar, cpu_read_ivar),
259 DEVMETHOD(bus_print_child, bus_generic_print_child),
260 DEVMETHOD(bus_get_resource_list, cpu_get_rlist),
261 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
262 DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource),
263 DEVMETHOD(bus_alloc_resource, bus_generic_rl_alloc_resource),
264 DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource),
265 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
266 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
267 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
268 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
269 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
270
271 { 0, 0 }
272 };
273
274 static driver_t cpu_driver = {
275 "cpu",
276 cpu_methods,
277 1, /* no softc */
278 };
279 static devclass_t cpu_devclass;
280 DRIVER_MODULE(cpu, legacy, cpu_driver, cpu_devclass, 0, 0);
281
282 static void
283 cpu_identify(driver_t *driver, device_t parent)
284 {
285 device_t child;
286 int i;
287
288 /*
289 * Attach a cpuX device for each CPU. We use an order of 150
290 * so that these devices are attached after the Host-PCI
291 * bridges (which are added at order 100).
292 */
293 for (i = 0; i <= mp_maxid; i++)
294 if (!CPU_ABSENT(i)) {
295 child = BUS_ADD_CHILD(parent, 150, "cpu", i);
296 if (child == NULL)
297 panic("legacy_attach cpu");
298 }
299 }
300
301 static device_t
302 cpu_add_child(device_t bus, u_int order, const char *name, int unit)
303 {
304 struct cpu_device *cd;
305 device_t child;
306 struct pcpu *pc;
307
308 if ((cd = malloc(sizeof(*cd), M_DEVBUF, M_NOWAIT | M_ZERO)) == NULL)
309 return (NULL);
310
311 resource_list_init(&cd->cd_rl);
312 pc = pcpu_find(device_get_unit(bus));
313 cd->cd_pcpu = pc;
314
315 child = device_add_child_ordered(bus, order, name, unit);
316 if (child != NULL) {
317 pc->pc_device = child;
318 device_set_ivars(child, cd);
319 } else
320 free(cd, M_DEVBUF);
321 return (child);
322 }
323
324 static struct resource_list *
325 cpu_get_rlist(device_t dev, device_t child)
326 {
327 struct cpu_device *cpdev;
328
329 cpdev = device_get_ivars(child);
330 return (&cpdev->cd_rl);
331 }
332
333 static int
334 cpu_read_ivar(device_t dev, device_t child, int index, uintptr_t *result)
335 {
336 struct cpu_device *cpdev;
337
338 if (index != CPU_IVAR_PCPU)
339 return (ENOENT);
340 cpdev = device_get_ivars(child);
341 *result = (uintptr_t)cpdev->cd_pcpu;
342 return (0);
343 }
Cache object: 86bd1cb693aa380a162af0e4762c714b
|