xref: /freebsd/sys/isa/isa_common.c (revision c3aac50f284c6cca5b4f2eb46aaa13812cb8b630)
1a3be63b3SDoug Rabson /*-
2a3be63b3SDoug Rabson  * Copyright (c) 1999 Doug Rabson
3a3be63b3SDoug Rabson  * All rights reserved.
4a3be63b3SDoug Rabson  *
5a3be63b3SDoug Rabson  * Redistribution and use in source and binary forms, with or without
6a3be63b3SDoug Rabson  * modification, are permitted provided that the following conditions
7a3be63b3SDoug Rabson  * are met:
8a3be63b3SDoug Rabson  * 1. Redistributions of source code must retain the above copyright
9a3be63b3SDoug Rabson  *    notice, this list of conditions and the following disclaimer.
10a3be63b3SDoug Rabson  * 2. Redistributions in binary form must reproduce the above copyright
11a3be63b3SDoug Rabson  *    notice, this list of conditions and the following disclaimer in the
12a3be63b3SDoug Rabson  *    documentation and/or other materials provided with the distribution.
13a3be63b3SDoug Rabson  *
14a3be63b3SDoug Rabson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15a3be63b3SDoug Rabson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16a3be63b3SDoug Rabson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17a3be63b3SDoug Rabson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18a3be63b3SDoug Rabson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19a3be63b3SDoug Rabson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20a3be63b3SDoug Rabson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21a3be63b3SDoug Rabson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22a3be63b3SDoug Rabson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23a3be63b3SDoug Rabson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24a3be63b3SDoug Rabson  * SUCH DAMAGE.
25a3be63b3SDoug Rabson  *
26c3aac50fSPeter Wemm  * $FreeBSD$
27a3be63b3SDoug Rabson  */
28a3be63b3SDoug Rabson /*
29a3be63b3SDoug Rabson  * Modifications for Intel architecture by Garrett A. Wollman.
30a3be63b3SDoug Rabson  * Copyright 1998 Massachusetts Institute of Technology
31a3be63b3SDoug Rabson  *
32a3be63b3SDoug Rabson  * Permission to use, copy, modify, and distribute this software and
33a3be63b3SDoug Rabson  * its documentation for any purpose and without fee is hereby
34a3be63b3SDoug Rabson  * granted, provided that both the above copyright notice and this
35a3be63b3SDoug Rabson  * permission notice appear in all copies, that both the above
36a3be63b3SDoug Rabson  * copyright notice and this permission notice appear in all
37a3be63b3SDoug Rabson  * supporting documentation, and that the name of M.I.T. not be used
38a3be63b3SDoug Rabson  * in advertising or publicity pertaining to distribution of the
39a3be63b3SDoug Rabson  * software without specific, written prior permission.  M.I.T. makes
40a3be63b3SDoug Rabson  * no representations about the suitability of this software for any
41a3be63b3SDoug Rabson  * purpose.  It is provided "as is" without express or implied
42a3be63b3SDoug Rabson  * warranty.
43a3be63b3SDoug Rabson  *
44a3be63b3SDoug Rabson  * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
45a3be63b3SDoug Rabson  * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
46a3be63b3SDoug Rabson  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
47a3be63b3SDoug Rabson  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
48a3be63b3SDoug Rabson  * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49a3be63b3SDoug Rabson  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
50a3be63b3SDoug Rabson  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
51a3be63b3SDoug Rabson  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
52a3be63b3SDoug Rabson  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53a3be63b3SDoug Rabson  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
54a3be63b3SDoug Rabson  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55a3be63b3SDoug Rabson  * SUCH DAMAGE.
56a3be63b3SDoug Rabson  */
57a3be63b3SDoug Rabson 
58a3be63b3SDoug Rabson /*
59a3be63b3SDoug Rabson  * Parts of the ISA bus implementation common to all architectures.
60a3be63b3SDoug Rabson  */
61a3be63b3SDoug Rabson 
62a3be63b3SDoug Rabson #include <sys/param.h>
63a3be63b3SDoug Rabson #include <sys/systm.h>
64a3be63b3SDoug Rabson #include <sys/kernel.h>
65a3be63b3SDoug Rabson #include <sys/bus.h>
66a3be63b3SDoug Rabson #include <sys/malloc.h>
67a3be63b3SDoug Rabson #include <sys/module.h>
68a3be63b3SDoug Rabson #include <machine/bus.h>
69a3be63b3SDoug Rabson #include <sys/rman.h>
70a3be63b3SDoug Rabson 
71a3be63b3SDoug Rabson #include <machine/resource.h>
72a3be63b3SDoug Rabson 
73a3be63b3SDoug Rabson #include <isa/isavar.h>
74a3be63b3SDoug Rabson #include <isa/isa_common.h>
75a3be63b3SDoug Rabson #ifdef __alpha__		/* XXX workaround a stupid warning */
76a3be63b3SDoug Rabson #include <alpha/isa/isavar.h>
77a3be63b3SDoug Rabson #endif
78a3be63b3SDoug Rabson 
79a3be63b3SDoug Rabson MALLOC_DEFINE(M_ISADEV, "isadev", "ISA device");
80a3be63b3SDoug Rabson 
81a3be63b3SDoug Rabson static devclass_t isa_devclass;
82a3be63b3SDoug Rabson 
83a3be63b3SDoug Rabson /*
84a3be63b3SDoug Rabson  * At 'probe' time, we add all the devices which we know about to the
85a3be63b3SDoug Rabson  * bus.  The generic attach routine will probe and attach them if they
86a3be63b3SDoug Rabson  * are alive.
87a3be63b3SDoug Rabson  */
88a3be63b3SDoug Rabson static int
89a3be63b3SDoug Rabson isa_probe(device_t dev)
90a3be63b3SDoug Rabson {
91a3be63b3SDoug Rabson 	device_set_desc(dev, "ISA bus");
92a3be63b3SDoug Rabson 	isa_init();		/* Allow machdep code to initialise */
93a3be63b3SDoug Rabson 	return bus_generic_probe(dev);
94a3be63b3SDoug Rabson }
95a3be63b3SDoug Rabson 
96a3be63b3SDoug Rabson extern device_t isa_bus_device;
97a3be63b3SDoug Rabson 
98a3be63b3SDoug Rabson static int
99a3be63b3SDoug Rabson isa_attach(device_t dev)
100a3be63b3SDoug Rabson {
101a3be63b3SDoug Rabson 	/*
102a3be63b3SDoug Rabson 	 * Arrange for bus_generic_attach(dev) to be called later.
103a3be63b3SDoug Rabson 	 */
104a3be63b3SDoug Rabson 	isa_bus_device = dev;
105a3be63b3SDoug Rabson 	return 0;
106a3be63b3SDoug Rabson }
107a3be63b3SDoug Rabson 
108a3be63b3SDoug Rabson /*
109a3be63b3SDoug Rabson  * Add a new child with default ivars.
110a3be63b3SDoug Rabson  */
111a3be63b3SDoug Rabson static device_t
112bea6af4dSDoug Rabson isa_add_child(device_t dev, int order, const char *name, int unit)
113a3be63b3SDoug Rabson {
114a3be63b3SDoug Rabson 	struct	isa_device *idev;
115a3be63b3SDoug Rabson 
116a3be63b3SDoug Rabson 	idev = malloc(sizeof(struct isa_device), M_ISADEV, M_NOWAIT);
117a3be63b3SDoug Rabson 	if (!idev)
118a3be63b3SDoug Rabson 		return 0;
119a3be63b3SDoug Rabson 	bzero(idev, sizeof *idev);
120a3be63b3SDoug Rabson 
121a3be63b3SDoug Rabson 	resource_list_init(&idev->id_resources);
122a3be63b3SDoug Rabson 	idev->id_flags = 0;
123a3be63b3SDoug Rabson 
124bea6af4dSDoug Rabson 	return device_add_child_ordered(dev, order, name, unit, idev);
125a3be63b3SDoug Rabson }
126a3be63b3SDoug Rabson 
127a3be63b3SDoug Rabson static void
128a3be63b3SDoug Rabson isa_print_resources(struct resource_list *rl, const char *name, int type,
129a3be63b3SDoug Rabson 		    const char *format)
130a3be63b3SDoug Rabson {
131a3be63b3SDoug Rabson 	struct resource_list_entry *rle0 = resource_list_find(rl, type, 0);
132a3be63b3SDoug Rabson 	struct resource_list_entry *rle1 = resource_list_find(rl, type, 1);
133a3be63b3SDoug Rabson 
134a3be63b3SDoug Rabson 	if (rle0 || rle1) {
135a3be63b3SDoug Rabson 		printf(" %s ", name);
136a3be63b3SDoug Rabson 		if (rle0) {
137a3be63b3SDoug Rabson 			printf(format, rle0->start);
138a3be63b3SDoug Rabson 			if (rle0->count > 1) {
139a3be63b3SDoug Rabson 				printf("-");
140a3be63b3SDoug Rabson 				printf(format, rle0->start + rle0->count - 1);
141a3be63b3SDoug Rabson 			}
142a3be63b3SDoug Rabson 		}
143a3be63b3SDoug Rabson 		if (rle1) {
144a3be63b3SDoug Rabson 			if (rle0)
145a3be63b3SDoug Rabson 				printf(",");
146a3be63b3SDoug Rabson 			printf(format, rle1->start);
147a3be63b3SDoug Rabson 			if (rle1->count > 1) {
148a3be63b3SDoug Rabson 				printf("-");
149a3be63b3SDoug Rabson 				printf(format, rle1->start + rle1->count - 1);
150a3be63b3SDoug Rabson 			}
151a3be63b3SDoug Rabson 		}
152a3be63b3SDoug Rabson 	}
153a3be63b3SDoug Rabson }
154a3be63b3SDoug Rabson 
15515317dd8SMatthew N. Dodd static int
156a3be63b3SDoug Rabson isa_print_child(device_t bus, device_t dev)
157a3be63b3SDoug Rabson {
158a3be63b3SDoug Rabson 	struct	isa_device *idev = DEVTOISA(dev);
159a3be63b3SDoug Rabson 	struct resource_list *rl = &idev->id_resources;
16015317dd8SMatthew N. Dodd 	int retval = 0;
16115317dd8SMatthew N. Dodd 
16215317dd8SMatthew N. Dodd 	retval += bus_print_child_header(bus, dev);
163a3be63b3SDoug Rabson 
164a3be63b3SDoug Rabson 	if (SLIST_FIRST(rl) || idev->id_flags)
16515317dd8SMatthew N. Dodd 		retval += printf(" at");
166a3be63b3SDoug Rabson 
167f4e3b1e7SMatthew N. Dodd 	isa_print_resources(rl, "port", SYS_RES_IOPORT, "%#lx");
168f4e3b1e7SMatthew N. Dodd 	isa_print_resources(rl, "iomem", SYS_RES_MEMORY, "%#lx");
169f4e3b1e7SMatthew N. Dodd 	isa_print_resources(rl, "irq", SYS_RES_IRQ, "%ld");
170f4e3b1e7SMatthew N. Dodd 	isa_print_resources(rl, "drq", SYS_RES_DRQ, "%ld");
171a3be63b3SDoug Rabson 	if (idev->id_flags)
17215317dd8SMatthew N. Dodd 		retval += printf(" flags %#x", idev->id_flags);
173a3be63b3SDoug Rabson 
17415317dd8SMatthew N. Dodd 	retval += bus_print_child_footer(bus, dev);
17515317dd8SMatthew N. Dodd 
17615317dd8SMatthew N. Dodd 	return (retval);
177a3be63b3SDoug Rabson }
178a3be63b3SDoug Rabson 
179a3be63b3SDoug Rabson static int
180a3be63b3SDoug Rabson isa_read_ivar(device_t bus, device_t dev, int index, uintptr_t * result)
181a3be63b3SDoug Rabson {
182a3be63b3SDoug Rabson 	struct isa_device* idev = DEVTOISA(dev);
183a3be63b3SDoug Rabson 	struct resource_list *rl = &idev->id_resources;
184a3be63b3SDoug Rabson 	struct resource_list_entry *rle;
185a3be63b3SDoug Rabson 
186a3be63b3SDoug Rabson 	switch (index) {
187a3be63b3SDoug Rabson 	case ISA_IVAR_PORT_0:
188a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_IOPORT, 0);
189a3be63b3SDoug Rabson 		if (rle)
190a3be63b3SDoug Rabson 			*result = rle->start;
191a3be63b3SDoug Rabson 		else
192a3be63b3SDoug Rabson 			*result = -1;
193a3be63b3SDoug Rabson 		break;
194a3be63b3SDoug Rabson 
195a3be63b3SDoug Rabson 	case ISA_IVAR_PORT_1:
196a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_IOPORT, 1);
197a3be63b3SDoug Rabson 		if (rle)
198a3be63b3SDoug Rabson 			*result = rle->start;
199a3be63b3SDoug Rabson 		else
200a3be63b3SDoug Rabson 			*result = -1;
201a3be63b3SDoug Rabson 		break;
202a3be63b3SDoug Rabson 
203a3be63b3SDoug Rabson 	case ISA_IVAR_PORTSIZE_0:
204a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_IOPORT, 0);
205a3be63b3SDoug Rabson 		if (rle)
206a3be63b3SDoug Rabson 			*result = rle->count;
207a3be63b3SDoug Rabson 		else
208a3be63b3SDoug Rabson 			*result = 0;
209a3be63b3SDoug Rabson 		break;
210a3be63b3SDoug Rabson 
211a3be63b3SDoug Rabson 	case ISA_IVAR_PORTSIZE_1:
212a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_IOPORT, 1);
213a3be63b3SDoug Rabson 		if (rle)
214a3be63b3SDoug Rabson 			*result = rle->count;
215a3be63b3SDoug Rabson 		else
216a3be63b3SDoug Rabson 			*result = 0;
217a3be63b3SDoug Rabson 		break;
218a3be63b3SDoug Rabson 
219a3be63b3SDoug Rabson 	case ISA_IVAR_MADDR_0:
220a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_MEMORY, 0);
221a3be63b3SDoug Rabson 		if (rle)
222a3be63b3SDoug Rabson 			*result = rle->start;
223a3be63b3SDoug Rabson 		else
224a3be63b3SDoug Rabson 			*result = -1;
225a3be63b3SDoug Rabson 		break;
226a3be63b3SDoug Rabson 
227a3be63b3SDoug Rabson 	case ISA_IVAR_MADDR_1:
228a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_MEMORY, 1);
229a3be63b3SDoug Rabson 		if (rle)
230a3be63b3SDoug Rabson 			*result = rle->start;
231a3be63b3SDoug Rabson 		else
232a3be63b3SDoug Rabson 			*result = -1;
233a3be63b3SDoug Rabson 		break;
234a3be63b3SDoug Rabson 
235a3be63b3SDoug Rabson 	case ISA_IVAR_MSIZE_0:
236a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_MEMORY, 0);
237a3be63b3SDoug Rabson 		if (rle)
238a3be63b3SDoug Rabson 			*result = rle->count;
239a3be63b3SDoug Rabson 		else
240a3be63b3SDoug Rabson 			*result = 0;
241a3be63b3SDoug Rabson 		break;
242a3be63b3SDoug Rabson 
243a3be63b3SDoug Rabson 	case ISA_IVAR_MSIZE_1:
244a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_MEMORY, 1);
245a3be63b3SDoug Rabson 		if (rle)
246a3be63b3SDoug Rabson 			*result = rle->count;
247a3be63b3SDoug Rabson 		else
248a3be63b3SDoug Rabson 			*result = 0;
249a3be63b3SDoug Rabson 		break;
250a3be63b3SDoug Rabson 
251a3be63b3SDoug Rabson 	case ISA_IVAR_IRQ_0:
252a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_IRQ, 0);
253a3be63b3SDoug Rabson 		if (rle)
254a3be63b3SDoug Rabson 			*result = rle->start;
255a3be63b3SDoug Rabson 		else
256a3be63b3SDoug Rabson 			*result = -1;
257a3be63b3SDoug Rabson 		break;
258a3be63b3SDoug Rabson 
259a3be63b3SDoug Rabson 	case ISA_IVAR_IRQ_1:
260a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_IRQ, 1);
261a3be63b3SDoug Rabson 		if (rle)
262a3be63b3SDoug Rabson 			*result = rle->start;
263a3be63b3SDoug Rabson 		else
264a3be63b3SDoug Rabson 			*result = -1;
265a3be63b3SDoug Rabson 		break;
266a3be63b3SDoug Rabson 
267a3be63b3SDoug Rabson 	case ISA_IVAR_DRQ_0:
268a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_DRQ, 0);
269a3be63b3SDoug Rabson 		if (rle)
270a3be63b3SDoug Rabson 			*result = rle->start;
271a3be63b3SDoug Rabson 		else
272a3be63b3SDoug Rabson 			*result = -1;
273a3be63b3SDoug Rabson 		break;
274a3be63b3SDoug Rabson 
275a3be63b3SDoug Rabson 	case ISA_IVAR_DRQ_1:
276a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_DRQ, 1);
277a3be63b3SDoug Rabson 		if (rle)
278a3be63b3SDoug Rabson 			*result = rle->start;
279a3be63b3SDoug Rabson 		else
280a3be63b3SDoug Rabson 			*result = -1;
281a3be63b3SDoug Rabson 		break;
282a3be63b3SDoug Rabson 
283a3be63b3SDoug Rabson 	case ISA_IVAR_FLAGS:
284a3be63b3SDoug Rabson 		*result = idev->id_flags;
285a3be63b3SDoug Rabson 		break;
286cfa84f46SDoug Rabson 
287cfa84f46SDoug Rabson 	case ISA_IVAR_VENDORID:
288cfa84f46SDoug Rabson 		*result = idev->id_vendorid;
289cfa84f46SDoug Rabson 		break;
290cfa84f46SDoug Rabson 
291cfa84f46SDoug Rabson 	case ISA_IVAR_SERIAL:
292cfa84f46SDoug Rabson 		*result = idev->id_serial;
293cfa84f46SDoug Rabson 		break;
294cfa84f46SDoug Rabson 
295cfa84f46SDoug Rabson 	case ISA_IVAR_LOGICALID:
296cfa84f46SDoug Rabson 		*result = idev->id_logicalid;
297cfa84f46SDoug Rabson 		break;
298cfa84f46SDoug Rabson 
299cfa84f46SDoug Rabson 	case ISA_IVAR_COMPATID:
300cfa84f46SDoug Rabson 		*result = idev->id_compatid;
301cfa84f46SDoug Rabson 		break;
302cfa84f46SDoug Rabson 
303cfa84f46SDoug Rabson 	default:
304a3be63b3SDoug Rabson 		return ENOENT;
305a3be63b3SDoug Rabson 	}
306a3be63b3SDoug Rabson 
307cfa84f46SDoug Rabson 	return 0;
308cfa84f46SDoug Rabson }
309cfa84f46SDoug Rabson 
310a3be63b3SDoug Rabson static int
311a3be63b3SDoug Rabson isa_write_ivar(device_t bus, device_t dev,
312a3be63b3SDoug Rabson 	       int index, uintptr_t value)
313a3be63b3SDoug Rabson {
314a3be63b3SDoug Rabson 	struct isa_device* idev = DEVTOISA(dev);
315a3be63b3SDoug Rabson 
316a3be63b3SDoug Rabson 	switch (index) {
317a3be63b3SDoug Rabson 	case ISA_IVAR_PORT_0:
318a3be63b3SDoug Rabson 	case ISA_IVAR_PORT_1:
319a3be63b3SDoug Rabson 	case ISA_IVAR_PORTSIZE_0:
320a3be63b3SDoug Rabson 	case ISA_IVAR_PORTSIZE_1:
321a3be63b3SDoug Rabson 	case ISA_IVAR_MADDR_0:
322a3be63b3SDoug Rabson 	case ISA_IVAR_MADDR_1:
323a3be63b3SDoug Rabson 	case ISA_IVAR_MSIZE_0:
324a3be63b3SDoug Rabson 	case ISA_IVAR_MSIZE_1:
325a3be63b3SDoug Rabson 	case ISA_IVAR_IRQ_0:
326a3be63b3SDoug Rabson 	case ISA_IVAR_IRQ_1:
327a3be63b3SDoug Rabson 	case ISA_IVAR_DRQ_0:
328a3be63b3SDoug Rabson 	case ISA_IVAR_DRQ_1:
329a3be63b3SDoug Rabson 		return EINVAL;
330a3be63b3SDoug Rabson 
331a3be63b3SDoug Rabson 	case ISA_IVAR_FLAGS:
332a3be63b3SDoug Rabson 		idev->id_flags = value;
333a3be63b3SDoug Rabson 		break;
334cfa84f46SDoug Rabson 
335cfa84f46SDoug Rabson 	case ISA_IVAR_VENDORID:
336cfa84f46SDoug Rabson 		idev->id_vendorid = value;
337cfa84f46SDoug Rabson 		break;
338cfa84f46SDoug Rabson 
339cfa84f46SDoug Rabson 	case ISA_IVAR_SERIAL:
340cfa84f46SDoug Rabson 		idev->id_serial = value;
341cfa84f46SDoug Rabson 		break;
342cfa84f46SDoug Rabson 
343cfa84f46SDoug Rabson 	case ISA_IVAR_LOGICALID:
344cfa84f46SDoug Rabson 		idev->id_logicalid = value;
345cfa84f46SDoug Rabson 		break;
346cfa84f46SDoug Rabson 
347cfa84f46SDoug Rabson 	case ISA_IVAR_COMPATID:
348cfa84f46SDoug Rabson 		idev->id_compatid = value;
349cfa84f46SDoug Rabson 		break;
350cfa84f46SDoug Rabson 
351a3be63b3SDoug Rabson 	default:
352a3be63b3SDoug Rabson 		return (ENOENT);
353a3be63b3SDoug Rabson 	}
354cfa84f46SDoug Rabson 
355a3be63b3SDoug Rabson 	return (0);
356a3be63b3SDoug Rabson }
357a3be63b3SDoug Rabson 
358a3be63b3SDoug Rabson static int
359a3be63b3SDoug Rabson isa_set_resource(device_t dev, device_t child, int type, int rid,
360a3be63b3SDoug Rabson 		 u_long start, u_long count)
361a3be63b3SDoug Rabson {
362a3be63b3SDoug Rabson 	struct isa_device* idev = DEVTOISA(child);
363a3be63b3SDoug Rabson 	struct resource_list *rl = &idev->id_resources;
364a3be63b3SDoug Rabson 
365a3be63b3SDoug Rabson 	if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY
366a3be63b3SDoug Rabson 	    && type != SYS_RES_IRQ && type != SYS_RES_DRQ)
367a3be63b3SDoug Rabson 		return EINVAL;
368a3be63b3SDoug Rabson 	if (rid < 0 || rid > 1)
369a3be63b3SDoug Rabson 		return EINVAL;
370a3be63b3SDoug Rabson 
371a3be63b3SDoug Rabson 	resource_list_add(rl, type, rid, start, start + count - 1, count);
372a3be63b3SDoug Rabson 
373a3be63b3SDoug Rabson 	return 0;
374a3be63b3SDoug Rabson }
375a3be63b3SDoug Rabson 
376a3be63b3SDoug Rabson static int
377a3be63b3SDoug Rabson isa_get_resource(device_t dev, device_t child, int type, int rid,
378a3be63b3SDoug Rabson 		 u_long *startp, u_long *countp)
379a3be63b3SDoug Rabson {
380a3be63b3SDoug Rabson 	struct isa_device* idev = DEVTOISA(child);
381a3be63b3SDoug Rabson 	struct resource_list *rl = &idev->id_resources;
382a3be63b3SDoug Rabson 	struct resource_list_entry *rle;
383a3be63b3SDoug Rabson 
384a3be63b3SDoug Rabson 	rle = resource_list_find(rl, type, rid);
385a3be63b3SDoug Rabson 	if (!rle)
386a3be63b3SDoug Rabson 		return ENOENT;
387a3be63b3SDoug Rabson 
388a3be63b3SDoug Rabson 	*startp = rle->start;
389a3be63b3SDoug Rabson 	*countp = rle->count;
390a3be63b3SDoug Rabson 
391a3be63b3SDoug Rabson 	return 0;
392a3be63b3SDoug Rabson }
393a3be63b3SDoug Rabson 
394cfa84f46SDoug Rabson static void
395cfa84f46SDoug Rabson isa_delete_resource(device_t dev, device_t child, int type, int rid)
396cfa84f46SDoug Rabson {
397cfa84f46SDoug Rabson 	struct isa_device* idev = DEVTOISA(child);
398cfa84f46SDoug Rabson 	struct resource_list *rl = &idev->id_resources;
399cfa84f46SDoug Rabson 	resource_list_delete(rl, type, rid);
400cfa84f46SDoug Rabson }
401cfa84f46SDoug Rabson 
402a3be63b3SDoug Rabson static device_method_t isa_methods[] = {
403a3be63b3SDoug Rabson 	/* Device interface */
404a3be63b3SDoug Rabson 	DEVMETHOD(device_probe,		isa_probe),
405a3be63b3SDoug Rabson 	DEVMETHOD(device_attach,	isa_attach),
406a3be63b3SDoug Rabson 	DEVMETHOD(device_detach,	bus_generic_detach),
407a3be63b3SDoug Rabson 	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
408a3be63b3SDoug Rabson 	DEVMETHOD(device_suspend,	bus_generic_suspend),
409a3be63b3SDoug Rabson 	DEVMETHOD(device_resume,	bus_generic_resume),
410a3be63b3SDoug Rabson 
411a3be63b3SDoug Rabson 	/* Bus interface */
412a3be63b3SDoug Rabson 	DEVMETHOD(bus_add_child,	isa_add_child),
413a3be63b3SDoug Rabson 	DEVMETHOD(bus_print_child,	isa_print_child),
414a3be63b3SDoug Rabson 	DEVMETHOD(bus_read_ivar,	isa_read_ivar),
415a3be63b3SDoug Rabson 	DEVMETHOD(bus_write_ivar,	isa_write_ivar),
416a3be63b3SDoug Rabson 	DEVMETHOD(bus_alloc_resource,	isa_alloc_resource),
417a3be63b3SDoug Rabson 	DEVMETHOD(bus_release_resource,	isa_release_resource),
418a3be63b3SDoug Rabson 	DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
419a3be63b3SDoug Rabson 	DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
420a3be63b3SDoug Rabson 	DEVMETHOD(bus_setup_intr,	isa_setup_intr),
421a3be63b3SDoug Rabson 	DEVMETHOD(bus_teardown_intr,	isa_teardown_intr),
422a3be63b3SDoug Rabson 
423a3be63b3SDoug Rabson 	/* ISA interface */
424a3be63b3SDoug Rabson 	DEVMETHOD(isa_set_resource,	isa_set_resource),
425a3be63b3SDoug Rabson 	DEVMETHOD(isa_get_resource,	isa_get_resource),
426cfa84f46SDoug Rabson 	DEVMETHOD(isa_delete_resource,	isa_delete_resource),
427a3be63b3SDoug Rabson 
428a3be63b3SDoug Rabson 	{ 0, 0 }
429a3be63b3SDoug Rabson };
430a3be63b3SDoug Rabson 
431a3be63b3SDoug Rabson static driver_t isa_driver = {
432a3be63b3SDoug Rabson 	"isa",
433a3be63b3SDoug Rabson 	isa_methods,
434a3be63b3SDoug Rabson 	1,			/* no softc */
435a3be63b3SDoug Rabson };
436a3be63b3SDoug Rabson 
437a3be63b3SDoug Rabson /*
438a3be63b3SDoug Rabson  * ISA can be attached to a PCI-ISA bridge or directly to the nexus.
439a3be63b3SDoug Rabson  */
440a3be63b3SDoug Rabson DRIVER_MODULE(isa, isab, isa_driver, isa_devclass, 0, 0);
441a3be63b3SDoug Rabson #ifdef __i386__
442a3be63b3SDoug Rabson DRIVER_MODULE(isa, nexus, isa_driver, isa_devclass, 0, 0);
443a3be63b3SDoug Rabson #endif
444