2 * Copyright (c) 1999 Doug Rabson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $Id: isa_common.c,v 1.4 1999/07/29 01:02:56 mdodd Exp $
29 * Modifications for Intel architecture by Garrett A. Wollman.
30 * Copyright 1998 Massachusetts Institute of Technology
32 * Permission to use, copy, modify, and distribute this software and
33 * its documentation for any purpose and without fee is hereby
34 * granted, provided that both the above copyright notice and this
35 * permission notice appear in all copies, that both the above
36 * copyright notice and this permission notice appear in all
37 * supporting documentation, and that the name of M.I.T. not be used
38 * in advertising or publicity pertaining to distribution of the
39 * software without specific, written prior permission. M.I.T. makes
40 * no representations about the suitability of this software for any
41 * purpose. It is provided "as is" without express or implied
44 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
45 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
46 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
47 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
48 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
50 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
51 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
52 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
54 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * Parts of the ISA bus implementation common to all architectures.
62 #include <sys/param.h>
63 #include <sys/systm.h>
64 #include <sys/kernel.h>
66 #include <sys/malloc.h>
67 #include <sys/module.h>
68 #include <machine/bus.h>
71 #include <machine/resource.h>
73 #include <isa/isavar.h>
74 #include <isa/isa_common.h>
75 #ifdef __alpha__ /* XXX workaround a stupid warning */
76 #include <alpha/isa/isavar.h>
79 MALLOC_DEFINE(M_ISADEV, "isadev", "ISA device");
81 static devclass_t isa_devclass;
84 * At 'probe' time, we add all the devices which we know about to the
85 * bus. The generic attach routine will probe and attach them if they
89 isa_probe(device_t dev)
91 device_set_desc(dev, "ISA bus");
92 isa_init(); /* Allow machdep code to initialise */
93 return bus_generic_probe(dev);
96 extern device_t isa_bus_device;
99 isa_attach(device_t dev)
102 * Arrange for bus_generic_attach(dev) to be called later.
104 isa_bus_device = dev;
109 * Add a new child with default ivars.
112 isa_add_child(device_t dev, int order, const char *name, int unit)
114 struct isa_device *idev;
116 idev = malloc(sizeof(struct isa_device), M_ISADEV, M_NOWAIT);
119 bzero(idev, sizeof *idev);
121 resource_list_init(&idev->id_resources);
124 return device_add_child_ordered(dev, order, name, unit, idev);
128 isa_print_resources(struct resource_list *rl, const char *name, int type,
131 struct resource_list_entry *rle0 = resource_list_find(rl, type, 0);
132 struct resource_list_entry *rle1 = resource_list_find(rl, type, 1);
135 printf(" %s ", name);
137 printf(format, rle0->start);
138 if (rle0->count > 1) {
140 printf(format, rle0->start + rle0->count - 1);
146 printf(format, rle1->start);
147 if (rle1->count > 1) {
149 printf(format, rle1->start + rle1->count - 1);
156 isa_print_child(device_t bus, device_t dev)
158 struct isa_device *idev = DEVTOISA(dev);
159 struct resource_list *rl = &idev->id_resources;
162 retval += bus_print_child_header(bus, dev);
164 if (SLIST_FIRST(rl) || idev->id_flags)
165 retval += printf(" at");
167 isa_print_resources(rl, "port", SYS_RES_IOPORT, "%#lx");
168 isa_print_resources(rl, "iomem", SYS_RES_MEMORY, "%#lx");
169 isa_print_resources(rl, "irq", SYS_RES_IRQ, "%ld");
170 isa_print_resources(rl, "drq", SYS_RES_DRQ, "%ld");
172 retval += printf(" flags %#x", idev->id_flags);
174 retval += bus_print_child_footer(bus, dev);
180 isa_read_ivar(device_t bus, device_t dev, int index, uintptr_t * result)
182 struct isa_device* idev = DEVTOISA(dev);
183 struct resource_list *rl = &idev->id_resources;
184 struct resource_list_entry *rle;
187 case ISA_IVAR_PORT_0:
188 rle = resource_list_find(rl, SYS_RES_IOPORT, 0);
190 *result = rle->start;
195 case ISA_IVAR_PORT_1:
196 rle = resource_list_find(rl, SYS_RES_IOPORT, 1);
198 *result = rle->start;
203 case ISA_IVAR_PORTSIZE_0:
204 rle = resource_list_find(rl, SYS_RES_IOPORT, 0);
206 *result = rle->count;
211 case ISA_IVAR_PORTSIZE_1:
212 rle = resource_list_find(rl, SYS_RES_IOPORT, 1);
214 *result = rle->count;
219 case ISA_IVAR_MADDR_0:
220 rle = resource_list_find(rl, SYS_RES_MEMORY, 0);
222 *result = rle->start;
227 case ISA_IVAR_MADDR_1:
228 rle = resource_list_find(rl, SYS_RES_MEMORY, 1);
230 *result = rle->start;
235 case ISA_IVAR_MSIZE_0:
236 rle = resource_list_find(rl, SYS_RES_MEMORY, 0);
238 *result = rle->count;
243 case ISA_IVAR_MSIZE_1:
244 rle = resource_list_find(rl, SYS_RES_MEMORY, 1);
246 *result = rle->count;
252 rle = resource_list_find(rl, SYS_RES_IRQ, 0);
254 *result = rle->start;
260 rle = resource_list_find(rl, SYS_RES_IRQ, 1);
262 *result = rle->start;
268 rle = resource_list_find(rl, SYS_RES_DRQ, 0);
270 *result = rle->start;
276 rle = resource_list_find(rl, SYS_RES_DRQ, 1);
278 *result = rle->start;
284 *result = idev->id_flags;
287 case ISA_IVAR_VENDORID:
288 *result = idev->id_vendorid;
291 case ISA_IVAR_SERIAL:
292 *result = idev->id_serial;
295 case ISA_IVAR_LOGICALID:
296 *result = idev->id_logicalid;
299 case ISA_IVAR_COMPATID:
300 *result = idev->id_compatid;
311 isa_write_ivar(device_t bus, device_t dev,
312 int index, uintptr_t value)
314 struct isa_device* idev = DEVTOISA(dev);
317 case ISA_IVAR_PORT_0:
318 case ISA_IVAR_PORT_1:
319 case ISA_IVAR_PORTSIZE_0:
320 case ISA_IVAR_PORTSIZE_1:
321 case ISA_IVAR_MADDR_0:
322 case ISA_IVAR_MADDR_1:
323 case ISA_IVAR_MSIZE_0:
324 case ISA_IVAR_MSIZE_1:
332 idev->id_flags = value;
335 case ISA_IVAR_VENDORID:
336 idev->id_vendorid = value;
339 case ISA_IVAR_SERIAL:
340 idev->id_serial = value;
343 case ISA_IVAR_LOGICALID:
344 idev->id_logicalid = value;
347 case ISA_IVAR_COMPATID:
348 idev->id_compatid = value;
359 isa_set_resource(device_t dev, device_t child, int type, int rid,
360 u_long start, u_long count)
362 struct isa_device* idev = DEVTOISA(child);
363 struct resource_list *rl = &idev->id_resources;
365 if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY
366 && type != SYS_RES_IRQ && type != SYS_RES_DRQ)
368 if (rid < 0 || rid > 1)
371 resource_list_add(rl, type, rid, start, start + count - 1, count);
377 isa_get_resource(device_t dev, device_t child, int type, int rid,
378 u_long *startp, u_long *countp)
380 struct isa_device* idev = DEVTOISA(child);
381 struct resource_list *rl = &idev->id_resources;
382 struct resource_list_entry *rle;
384 rle = resource_list_find(rl, type, rid);
388 *startp = rle->start;
389 *countp = rle->count;
395 isa_delete_resource(device_t dev, device_t child, int type, int rid)
397 struct isa_device* idev = DEVTOISA(child);
398 struct resource_list *rl = &idev->id_resources;
399 resource_list_delete(rl, type, rid);
402 static device_method_t isa_methods[] = {
403 /* Device interface */
404 DEVMETHOD(device_probe, isa_probe),
405 DEVMETHOD(device_attach, isa_attach),
406 DEVMETHOD(device_detach, bus_generic_detach),
407 DEVMETHOD(device_shutdown, bus_generic_shutdown),
408 DEVMETHOD(device_suspend, bus_generic_suspend),
409 DEVMETHOD(device_resume, bus_generic_resume),
412 DEVMETHOD(bus_add_child, isa_add_child),
413 DEVMETHOD(bus_print_child, isa_print_child),
414 DEVMETHOD(bus_read_ivar, isa_read_ivar),
415 DEVMETHOD(bus_write_ivar, isa_write_ivar),
416 DEVMETHOD(bus_alloc_resource, isa_alloc_resource),
417 DEVMETHOD(bus_release_resource, isa_release_resource),
418 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
419 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
420 DEVMETHOD(bus_setup_intr, isa_setup_intr),
421 DEVMETHOD(bus_teardown_intr, isa_teardown_intr),
424 DEVMETHOD(isa_set_resource, isa_set_resource),
425 DEVMETHOD(isa_get_resource, isa_get_resource),
426 DEVMETHOD(isa_delete_resource, isa_delete_resource),
431 static driver_t isa_driver = {
438 * ISA can be attached to a PCI-ISA bridge or directly to the nexus.
440 DRIVER_MODULE(isa, isab, isa_driver, isa_devclass, 0, 0);
442 DRIVER_MODULE(isa, nexus, isa_driver, isa_devclass, 0, 0);