xref: /freebsd/sys/isa/isa_common.c (revision cfa84f46316d500ad9b4a7d62b98b498134d2584)
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  *
26cfa84f46SDoug Rabson  *	$Id: isa_common.c,v 1.2 1999/05/28 09:24:58 dfr Exp $
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 
155a3be63b3SDoug Rabson static void
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;
160a3be63b3SDoug Rabson 
161a3be63b3SDoug Rabson 	if (SLIST_FIRST(rl) || idev->id_flags)
162a3be63b3SDoug Rabson 		printf(" at");
163a3be63b3SDoug Rabson 
164a3be63b3SDoug Rabson 	isa_print_resources(rl, "port", SYS_RES_IOPORT, "%#lx");
165a3be63b3SDoug Rabson 	isa_print_resources(rl, "iomem", SYS_RES_MEMORY, "%#lx");
166a3be63b3SDoug Rabson 	isa_print_resources(rl, "irq", SYS_RES_IRQ, "%ld");
167a3be63b3SDoug Rabson 	isa_print_resources(rl, "drq", SYS_RES_DRQ, "%ld");
168a3be63b3SDoug Rabson 	if (idev->id_flags)
169a3be63b3SDoug Rabson 		printf(" flags %#x", idev->id_flags);
170a3be63b3SDoug Rabson 
171a3be63b3SDoug Rabson 	printf(" on %s%d",
172a3be63b3SDoug Rabson 	       device_get_name(bus), device_get_unit(bus));
173a3be63b3SDoug Rabson }
174a3be63b3SDoug Rabson 
175a3be63b3SDoug Rabson static int
176a3be63b3SDoug Rabson isa_read_ivar(device_t bus, device_t dev, int index, uintptr_t * result)
177a3be63b3SDoug Rabson {
178a3be63b3SDoug Rabson 	struct isa_device* idev = DEVTOISA(dev);
179a3be63b3SDoug Rabson 	struct resource_list *rl = &idev->id_resources;
180a3be63b3SDoug Rabson 	struct resource_list_entry *rle;
181a3be63b3SDoug Rabson 
182a3be63b3SDoug Rabson 	switch (index) {
183a3be63b3SDoug Rabson 	case ISA_IVAR_PORT_0:
184a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_IOPORT, 0);
185a3be63b3SDoug Rabson 		if (rle)
186a3be63b3SDoug Rabson 			*result = rle->start;
187a3be63b3SDoug Rabson 		else
188a3be63b3SDoug Rabson 			*result = -1;
189a3be63b3SDoug Rabson 		break;
190a3be63b3SDoug Rabson 
191a3be63b3SDoug Rabson 	case ISA_IVAR_PORT_1:
192a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_IOPORT, 1);
193a3be63b3SDoug Rabson 		if (rle)
194a3be63b3SDoug Rabson 			*result = rle->start;
195a3be63b3SDoug Rabson 		else
196a3be63b3SDoug Rabson 			*result = -1;
197a3be63b3SDoug Rabson 		break;
198a3be63b3SDoug Rabson 
199a3be63b3SDoug Rabson 	case ISA_IVAR_PORTSIZE_0:
200a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_IOPORT, 0);
201a3be63b3SDoug Rabson 		if (rle)
202a3be63b3SDoug Rabson 			*result = rle->count;
203a3be63b3SDoug Rabson 		else
204a3be63b3SDoug Rabson 			*result = 0;
205a3be63b3SDoug Rabson 		break;
206a3be63b3SDoug Rabson 
207a3be63b3SDoug Rabson 	case ISA_IVAR_PORTSIZE_1:
208a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_IOPORT, 1);
209a3be63b3SDoug Rabson 		if (rle)
210a3be63b3SDoug Rabson 			*result = rle->count;
211a3be63b3SDoug Rabson 		else
212a3be63b3SDoug Rabson 			*result = 0;
213a3be63b3SDoug Rabson 		break;
214a3be63b3SDoug Rabson 
215a3be63b3SDoug Rabson 	case ISA_IVAR_MADDR_0:
216a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_MEMORY, 0);
217a3be63b3SDoug Rabson 		if (rle)
218a3be63b3SDoug Rabson 			*result = rle->start;
219a3be63b3SDoug Rabson 		else
220a3be63b3SDoug Rabson 			*result = -1;
221a3be63b3SDoug Rabson 		break;
222a3be63b3SDoug Rabson 
223a3be63b3SDoug Rabson 	case ISA_IVAR_MADDR_1:
224a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_MEMORY, 1);
225a3be63b3SDoug Rabson 		if (rle)
226a3be63b3SDoug Rabson 			*result = rle->start;
227a3be63b3SDoug Rabson 		else
228a3be63b3SDoug Rabson 			*result = -1;
229a3be63b3SDoug Rabson 		break;
230a3be63b3SDoug Rabson 
231a3be63b3SDoug Rabson 	case ISA_IVAR_MSIZE_0:
232a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_MEMORY, 0);
233a3be63b3SDoug Rabson 		if (rle)
234a3be63b3SDoug Rabson 			*result = rle->count;
235a3be63b3SDoug Rabson 		else
236a3be63b3SDoug Rabson 			*result = 0;
237a3be63b3SDoug Rabson 		break;
238a3be63b3SDoug Rabson 
239a3be63b3SDoug Rabson 	case ISA_IVAR_MSIZE_1:
240a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_MEMORY, 1);
241a3be63b3SDoug Rabson 		if (rle)
242a3be63b3SDoug Rabson 			*result = rle->count;
243a3be63b3SDoug Rabson 		else
244a3be63b3SDoug Rabson 			*result = 0;
245a3be63b3SDoug Rabson 		break;
246a3be63b3SDoug Rabson 
247a3be63b3SDoug Rabson 	case ISA_IVAR_IRQ_0:
248a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_IRQ, 0);
249a3be63b3SDoug Rabson 		if (rle)
250a3be63b3SDoug Rabson 			*result = rle->start;
251a3be63b3SDoug Rabson 		else
252a3be63b3SDoug Rabson 			*result = -1;
253a3be63b3SDoug Rabson 		break;
254a3be63b3SDoug Rabson 
255a3be63b3SDoug Rabson 	case ISA_IVAR_IRQ_1:
256a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_IRQ, 1);
257a3be63b3SDoug Rabson 		if (rle)
258a3be63b3SDoug Rabson 			*result = rle->start;
259a3be63b3SDoug Rabson 		else
260a3be63b3SDoug Rabson 			*result = -1;
261a3be63b3SDoug Rabson 		break;
262a3be63b3SDoug Rabson 
263a3be63b3SDoug Rabson 	case ISA_IVAR_DRQ_0:
264a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_DRQ, 0);
265a3be63b3SDoug Rabson 		if (rle)
266a3be63b3SDoug Rabson 			*result = rle->start;
267a3be63b3SDoug Rabson 		else
268a3be63b3SDoug Rabson 			*result = -1;
269a3be63b3SDoug Rabson 		break;
270a3be63b3SDoug Rabson 
271a3be63b3SDoug Rabson 	case ISA_IVAR_DRQ_1:
272a3be63b3SDoug Rabson 		rle = resource_list_find(rl, SYS_RES_DRQ, 1);
273a3be63b3SDoug Rabson 		if (rle)
274a3be63b3SDoug Rabson 			*result = rle->start;
275a3be63b3SDoug Rabson 		else
276a3be63b3SDoug Rabson 			*result = -1;
277a3be63b3SDoug Rabson 		break;
278a3be63b3SDoug Rabson 
279a3be63b3SDoug Rabson 	case ISA_IVAR_FLAGS:
280a3be63b3SDoug Rabson 		*result = idev->id_flags;
281a3be63b3SDoug Rabson 		break;
282cfa84f46SDoug Rabson 
283cfa84f46SDoug Rabson 	case ISA_IVAR_VENDORID:
284cfa84f46SDoug Rabson 		*result = idev->id_vendorid;
285cfa84f46SDoug Rabson 		break;
286cfa84f46SDoug Rabson 
287cfa84f46SDoug Rabson 	case ISA_IVAR_SERIAL:
288cfa84f46SDoug Rabson 		*result = idev->id_serial;
289cfa84f46SDoug Rabson 		break;
290cfa84f46SDoug Rabson 
291cfa84f46SDoug Rabson 	case ISA_IVAR_LOGICALID:
292cfa84f46SDoug Rabson 		*result = idev->id_logicalid;
293cfa84f46SDoug Rabson 		break;
294cfa84f46SDoug Rabson 
295cfa84f46SDoug Rabson 	case ISA_IVAR_COMPATID:
296cfa84f46SDoug Rabson 		*result = idev->id_compatid;
297cfa84f46SDoug Rabson 		break;
298cfa84f46SDoug Rabson 
299cfa84f46SDoug Rabson 	default:
300a3be63b3SDoug Rabson 		return ENOENT;
301a3be63b3SDoug Rabson 	}
302a3be63b3SDoug Rabson 
303cfa84f46SDoug Rabson 	return 0;
304cfa84f46SDoug Rabson }
305cfa84f46SDoug Rabson 
306a3be63b3SDoug Rabson static int
307a3be63b3SDoug Rabson isa_write_ivar(device_t bus, device_t dev,
308a3be63b3SDoug Rabson 	       int index, uintptr_t value)
309a3be63b3SDoug Rabson {
310a3be63b3SDoug Rabson 	struct isa_device* idev = DEVTOISA(dev);
311a3be63b3SDoug Rabson 
312a3be63b3SDoug Rabson 	switch (index) {
313a3be63b3SDoug Rabson 	case ISA_IVAR_PORT_0:
314a3be63b3SDoug Rabson 	case ISA_IVAR_PORT_1:
315a3be63b3SDoug Rabson 	case ISA_IVAR_PORTSIZE_0:
316a3be63b3SDoug Rabson 	case ISA_IVAR_PORTSIZE_1:
317a3be63b3SDoug Rabson 	case ISA_IVAR_MADDR_0:
318a3be63b3SDoug Rabson 	case ISA_IVAR_MADDR_1:
319a3be63b3SDoug Rabson 	case ISA_IVAR_MSIZE_0:
320a3be63b3SDoug Rabson 	case ISA_IVAR_MSIZE_1:
321a3be63b3SDoug Rabson 	case ISA_IVAR_IRQ_0:
322a3be63b3SDoug Rabson 	case ISA_IVAR_IRQ_1:
323a3be63b3SDoug Rabson 	case ISA_IVAR_DRQ_0:
324a3be63b3SDoug Rabson 	case ISA_IVAR_DRQ_1:
325a3be63b3SDoug Rabson 		return EINVAL;
326a3be63b3SDoug Rabson 
327a3be63b3SDoug Rabson 	case ISA_IVAR_FLAGS:
328a3be63b3SDoug Rabson 		idev->id_flags = value;
329a3be63b3SDoug Rabson 		break;
330cfa84f46SDoug Rabson 
331cfa84f46SDoug Rabson 	case ISA_IVAR_VENDORID:
332cfa84f46SDoug Rabson 		idev->id_vendorid = value;
333cfa84f46SDoug Rabson 		break;
334cfa84f46SDoug Rabson 
335cfa84f46SDoug Rabson 	case ISA_IVAR_SERIAL:
336cfa84f46SDoug Rabson 		idev->id_serial = value;
337cfa84f46SDoug Rabson 		break;
338cfa84f46SDoug Rabson 
339cfa84f46SDoug Rabson 	case ISA_IVAR_LOGICALID:
340cfa84f46SDoug Rabson 		idev->id_logicalid = value;
341cfa84f46SDoug Rabson 		break;
342cfa84f46SDoug Rabson 
343cfa84f46SDoug Rabson 	case ISA_IVAR_COMPATID:
344cfa84f46SDoug Rabson 		idev->id_compatid = value;
345cfa84f46SDoug Rabson 		break;
346cfa84f46SDoug Rabson 
347a3be63b3SDoug Rabson 	default:
348a3be63b3SDoug Rabson 		return (ENOENT);
349a3be63b3SDoug Rabson 	}
350cfa84f46SDoug Rabson 
351a3be63b3SDoug Rabson 	return (0);
352a3be63b3SDoug Rabson }
353a3be63b3SDoug Rabson 
354a3be63b3SDoug Rabson static int
355a3be63b3SDoug Rabson isa_set_resource(device_t dev, device_t child, int type, int rid,
356a3be63b3SDoug Rabson 		 u_long start, u_long count)
357a3be63b3SDoug Rabson {
358a3be63b3SDoug Rabson 	struct isa_device* idev = DEVTOISA(child);
359a3be63b3SDoug Rabson 	struct resource_list *rl = &idev->id_resources;
360a3be63b3SDoug Rabson 
361a3be63b3SDoug Rabson 	if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY
362a3be63b3SDoug Rabson 	    && type != SYS_RES_IRQ && type != SYS_RES_DRQ)
363a3be63b3SDoug Rabson 		return EINVAL;
364a3be63b3SDoug Rabson 	if (rid < 0 || rid > 1)
365a3be63b3SDoug Rabson 		return EINVAL;
366a3be63b3SDoug Rabson 
367a3be63b3SDoug Rabson 	resource_list_add(rl, type, rid, start, start + count - 1, count);
368a3be63b3SDoug Rabson 
369a3be63b3SDoug Rabson 	return 0;
370a3be63b3SDoug Rabson }
371a3be63b3SDoug Rabson 
372a3be63b3SDoug Rabson static int
373a3be63b3SDoug Rabson isa_get_resource(device_t dev, device_t child, int type, int rid,
374a3be63b3SDoug Rabson 		 u_long *startp, u_long *countp)
375a3be63b3SDoug Rabson {
376a3be63b3SDoug Rabson 	struct isa_device* idev = DEVTOISA(child);
377a3be63b3SDoug Rabson 	struct resource_list *rl = &idev->id_resources;
378a3be63b3SDoug Rabson 	struct resource_list_entry *rle;
379a3be63b3SDoug Rabson 
380a3be63b3SDoug Rabson 	rle = resource_list_find(rl, type, rid);
381a3be63b3SDoug Rabson 	if (!rle)
382a3be63b3SDoug Rabson 		return ENOENT;
383a3be63b3SDoug Rabson 
384a3be63b3SDoug Rabson 	*startp = rle->start;
385a3be63b3SDoug Rabson 	*countp = rle->count;
386a3be63b3SDoug Rabson 
387a3be63b3SDoug Rabson 	return 0;
388a3be63b3SDoug Rabson }
389a3be63b3SDoug Rabson 
390cfa84f46SDoug Rabson static void
391cfa84f46SDoug Rabson isa_delete_resource(device_t dev, device_t child, int type, int rid)
392cfa84f46SDoug Rabson {
393cfa84f46SDoug Rabson 	struct isa_device* idev = DEVTOISA(child);
394cfa84f46SDoug Rabson 	struct resource_list *rl = &idev->id_resources;
395cfa84f46SDoug Rabson 	resource_list_delete(rl, type, rid);
396cfa84f46SDoug Rabson }
397cfa84f46SDoug Rabson 
398a3be63b3SDoug Rabson static device_method_t isa_methods[] = {
399a3be63b3SDoug Rabson 	/* Device interface */
400a3be63b3SDoug Rabson 	DEVMETHOD(device_probe,		isa_probe),
401a3be63b3SDoug Rabson 	DEVMETHOD(device_attach,	isa_attach),
402a3be63b3SDoug Rabson 	DEVMETHOD(device_detach,	bus_generic_detach),
403a3be63b3SDoug Rabson 	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
404a3be63b3SDoug Rabson 	DEVMETHOD(device_suspend,	bus_generic_suspend),
405a3be63b3SDoug Rabson 	DEVMETHOD(device_resume,	bus_generic_resume),
406a3be63b3SDoug Rabson 
407a3be63b3SDoug Rabson 	/* Bus interface */
408a3be63b3SDoug Rabson 	DEVMETHOD(bus_add_child,	isa_add_child),
409a3be63b3SDoug Rabson 	DEVMETHOD(bus_print_child,	isa_print_child),
410a3be63b3SDoug Rabson 	DEVMETHOD(bus_read_ivar,	isa_read_ivar),
411a3be63b3SDoug Rabson 	DEVMETHOD(bus_write_ivar,	isa_write_ivar),
412a3be63b3SDoug Rabson 	DEVMETHOD(bus_alloc_resource,	isa_alloc_resource),
413a3be63b3SDoug Rabson 	DEVMETHOD(bus_release_resource,	isa_release_resource),
414a3be63b3SDoug Rabson 	DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
415a3be63b3SDoug Rabson 	DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
416a3be63b3SDoug Rabson 	DEVMETHOD(bus_setup_intr,	isa_setup_intr),
417a3be63b3SDoug Rabson 	DEVMETHOD(bus_teardown_intr,	isa_teardown_intr),
418a3be63b3SDoug Rabson 
419a3be63b3SDoug Rabson 	/* ISA interface */
420a3be63b3SDoug Rabson 	DEVMETHOD(isa_set_resource,	isa_set_resource),
421a3be63b3SDoug Rabson 	DEVMETHOD(isa_get_resource,	isa_get_resource),
422cfa84f46SDoug Rabson 	DEVMETHOD(isa_delete_resource,	isa_delete_resource),
423a3be63b3SDoug Rabson 
424a3be63b3SDoug Rabson 	{ 0, 0 }
425a3be63b3SDoug Rabson };
426a3be63b3SDoug Rabson 
427a3be63b3SDoug Rabson static driver_t isa_driver = {
428a3be63b3SDoug Rabson 	"isa",
429a3be63b3SDoug Rabson 	isa_methods,
430a3be63b3SDoug Rabson 	1,			/* no softc */
431a3be63b3SDoug Rabson };
432a3be63b3SDoug Rabson 
433a3be63b3SDoug Rabson /*
434a3be63b3SDoug Rabson  * ISA can be attached to a PCI-ISA bridge or directly to the nexus.
435a3be63b3SDoug Rabson  */
436a3be63b3SDoug Rabson DRIVER_MODULE(isa, isab, isa_driver, isa_devclass, 0, 0);
437a3be63b3SDoug Rabson #ifdef __i386__
438a3be63b3SDoug Rabson DRIVER_MODULE(isa, nexus, isa_driver, isa_devclass, 0, 0);
439a3be63b3SDoug Rabson #endif
440