Deleted Added
full compact
isa.c (90762) isa.c (115703)
1/*-
2 * Copyright (c) 1998 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
13 *
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
24 * SUCH DAMAGE.
1/*-
2 * Copyright (c) 1998 Doug Rabson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
13 *
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
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/i386/isa/isa.c 90762 2002-02-17 09:16:45Z nyan $
27 */
28
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/i386/isa/isa.c 115703 2003-06-02 16:32:55Z obrien $");
29
29/*
30 * Modifications for Intel architecture by Garrett A. Wollman.
31 * Copyright 1998 Massachusetts Institute of Technology
32 *
33 * Permission to use, copy, modify, and distribute this software and
34 * its documentation for any purpose and without fee is hereby
35 * granted, provided that both the above copyright notice and this
36 * permission notice appear in all copies, that both the above
37 * copyright notice and this permission notice appear in all
38 * supporting documentation, and that the name of M.I.T. not be used
39 * in advertising or publicity pertaining to distribution of the
40 * software without specific, written prior permission. M.I.T. makes
41 * no representations about the suitability of this software for any
42 * purpose. It is provided "as is" without express or implied
43 * warranty.
44 *
45 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
46 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
47 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
48 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
49 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * SUCH DAMAGE.
57 */
58
59#include <sys/param.h>
60#include <sys/bus.h>
61#include <sys/malloc.h>
62#include <machine/bus.h>
63#include <sys/rman.h>
64#ifdef PC98
65#include <sys/systm.h>
66#endif
67
68#include <machine/resource.h>
69
70#include <isa/isavar.h>
71#include <isa/isa_common.h>
72
73void
74isa_init(device_t dev)
75{
76}
77
78/*
79 * This implementation simply passes the request up to the parent
80 * bus, which in our case is the special i386 nexus, substituting any
81 * configured values if the caller defaulted. We can get away with
82 * this because there is no special mapping for ISA resources on an Intel
83 * platform. When porting this code to another architecture, it may be
84 * necessary to interpose a mapping layer here.
85 */
86struct resource *
87isa_alloc_resource(device_t bus, device_t child, int type, int *rid,
88 u_long start, u_long end, u_long count, u_int flags)
89{
90 /*
91 * Consider adding a resource definition. We allow rid 0-1 for
92 * irq and drq, 0-3 for memory and 0-7 for ports which is
93 * sufficient for isapnp.
94 */
95 int passthrough = (device_get_parent(child) != bus);
96 int isdefault = (start == 0UL && end == ~0UL);
97 struct isa_device* idev = DEVTOISA(child);
98 struct resource_list *rl = &idev->id_resources;
99 struct resource_list_entry *rle;
100
101 if (!passthrough && !isdefault) {
102 rle = resource_list_find(rl, type, *rid);
103 if (!rle) {
104 if (*rid < 0)
105 return 0;
106 switch (type) {
107 case SYS_RES_IRQ:
108 if (*rid >= ISA_NIRQ)
109 return 0;
110 break;
111 case SYS_RES_DRQ:
112 if (*rid >= ISA_NDRQ)
113 return 0;
114 break;
115 case SYS_RES_MEMORY:
116 if (*rid >= ISA_NMEM)
117 return 0;
118 break;
119 case SYS_RES_IOPORT:
120 if (*rid >= ISA_NPORT)
121 return 0;
122 break;
123 default:
124 return 0;
125 }
126 resource_list_add(rl, type, *rid, start, end, count);
127 }
128 }
129
130 return resource_list_alloc(rl, bus, child, type, rid,
131 start, end, count, flags);
132}
133
134#ifdef PC98
135/*
136 * Indirection support. The type of bus_space_handle_t is
137 * defined in sys/i386/include/bus_pc98.h.
138 */
139struct resource *
140isa_alloc_resourcev(device_t child, int type, int *rid,
141 bus_addr_t *res, bus_size_t count, u_int flags)
142{
143 struct isa_device* idev = DEVTOISA(child);
144 struct resource_list *rl = &idev->id_resources;
145
146 device_t bus = device_get_parent(child);
147 bus_addr_t start;
148 struct resource *re;
149 struct resource **bsre;
150 int i, j, k, linear_cnt, ressz, bsrid;
151
152 start = bus_get_resource_start(child, type, *rid);
153
154 linear_cnt = count;
155 ressz = 1;
156 for (i = 1; i < count; ++i) {
157 if (res[i] != res[i - 1] + 1) {
158 if (i < linear_cnt)
159 linear_cnt = i;
160 ++ressz;
161 }
162 }
163
164 re = isa_alloc_resource(bus, child, type, rid,
165 start + res[0], start + res[linear_cnt - 1],
166 linear_cnt, flags);
167 if (re == NULL)
168 return NULL;
169
170 bsre = malloc(sizeof (struct resource *) * ressz, M_DEVBUF, M_NOWAIT);
171 if (bsre == NULL) {
172 resource_list_release(rl, bus, child, type, *rid, re);
173 return NULL;
174 }
175 bsre[0] = re;
176
177 for (i = linear_cnt, k = 1; i < count; i = j, k++) {
178 for (j = i + 1; j < count; j++) {
179 if (res[j] != res[j - 1] + 1)
180 break;
181 }
182 bsrid = *rid + k;
183 bsre[k] = isa_alloc_resource(bus, child, type, &bsrid,
184 start + res[i], start + res[j - 1], j - i, flags);
185 if (bsre[k] == NULL) {
186 for (k--; k >= 0; k--)
187 resource_list_release(rl, bus, child, type,
188 *rid + k, bsre[k]);
189 free(bsre, M_DEVBUF);
190 return NULL;
191 }
192 }
193
194 re->r_bushandle->bsh_res = bsre;
195 re->r_bushandle->bsh_ressz = ressz;
196
197 return re;
198}
199
200int
201isa_load_resourcev(struct resource *re, bus_addr_t *res, bus_size_t count)
202{
203 bus_addr_t start;
204 int i;
205
206 if (count > re->r_bushandle->bsh_maxiatsz) {
207 printf("isa_load_resourcev: map size too large\n");
208 return EINVAL;
209 }
210
211 start = rman_get_start(re);
212 for (i = 0; i < re->r_bushandle->bsh_maxiatsz; i++) {
213 if (i < count)
214 re->r_bushandle->bsh_iat[i] = start + res[i];
215 else
216 re->r_bushandle->bsh_iat[i] = start;
217 }
218
219 re->r_bushandle->bsh_iatsz = count;
220 re->r_bushandle->bsh_bam = re->r_bustag->bs_ra; /* relocate access */
221
222 return 0;
223}
224#endif /* PC98 */
225
226int
227isa_release_resource(device_t bus, device_t child, int type, int rid,
228 struct resource *r)
229{
230 struct isa_device* idev = DEVTOISA(child);
231 struct resource_list *rl = &idev->id_resources;
232#ifdef PC98
233 /*
234 * Indirection support. The type of bus_space_handle_t is
235 * defined in sys/i386/include/bus_pc98.h.
236 */
237 int i;
238
239 if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) {
240 for (i = 1; i < r->r_bushandle->bsh_ressz; i++)
241 resource_list_release(rl, bus, child, type, rid + i,
242 r->r_bushandle->bsh_res[i]);
243 if (r->r_bushandle->bsh_res != NULL)
244 free(r->r_bushandle->bsh_res, M_DEVBUF);
245 }
246#endif
247 return resource_list_release(rl, bus, child, type, rid, r);
248}
249
250/*
251 * We can't use the bus_generic_* versions of these methods because those
252 * methods always pass the bus param as the requesting device, and we need
253 * to pass the child (the i386 nexus knows about this and is prepared to
254 * deal).
255 */
256int
257isa_setup_intr(device_t bus, device_t child, struct resource *r, int flags,
258 void (*ihand)(void *), void *arg, void **cookiep)
259{
260 return (BUS_SETUP_INTR(device_get_parent(bus), child, r, flags,
261 ihand, arg, cookiep));
262}
263
264int
265isa_teardown_intr(device_t bus, device_t child, struct resource *r,
266 void *cookie)
267{
268 return (BUS_TEARDOWN_INTR(device_get_parent(bus), child, r, cookie));
269}
30/*
31 * Modifications for Intel architecture by Garrett A. Wollman.
32 * Copyright 1998 Massachusetts Institute of Technology
33 *
34 * Permission to use, copy, modify, and distribute this software and
35 * its documentation for any purpose and without fee is hereby
36 * granted, provided that both the above copyright notice and this
37 * permission notice appear in all copies, that both the above
38 * copyright notice and this permission notice appear in all
39 * supporting documentation, and that the name of M.I.T. not be used
40 * in advertising or publicity pertaining to distribution of the
41 * software without specific, written prior permission. M.I.T. makes
42 * no representations about the suitability of this software for any
43 * purpose. It is provided "as is" without express or implied
44 * warranty.
45 *
46 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
47 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
48 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
49 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
50 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
51 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
52 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
53 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
54 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
55 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
56 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE.
58 */
59
60#include <sys/param.h>
61#include <sys/bus.h>
62#include <sys/malloc.h>
63#include <machine/bus.h>
64#include <sys/rman.h>
65#ifdef PC98
66#include <sys/systm.h>
67#endif
68
69#include <machine/resource.h>
70
71#include <isa/isavar.h>
72#include <isa/isa_common.h>
73
74void
75isa_init(device_t dev)
76{
77}
78
79/*
80 * This implementation simply passes the request up to the parent
81 * bus, which in our case is the special i386 nexus, substituting any
82 * configured values if the caller defaulted. We can get away with
83 * this because there is no special mapping for ISA resources on an Intel
84 * platform. When porting this code to another architecture, it may be
85 * necessary to interpose a mapping layer here.
86 */
87struct resource *
88isa_alloc_resource(device_t bus, device_t child, int type, int *rid,
89 u_long start, u_long end, u_long count, u_int flags)
90{
91 /*
92 * Consider adding a resource definition. We allow rid 0-1 for
93 * irq and drq, 0-3 for memory and 0-7 for ports which is
94 * sufficient for isapnp.
95 */
96 int passthrough = (device_get_parent(child) != bus);
97 int isdefault = (start == 0UL && end == ~0UL);
98 struct isa_device* idev = DEVTOISA(child);
99 struct resource_list *rl = &idev->id_resources;
100 struct resource_list_entry *rle;
101
102 if (!passthrough && !isdefault) {
103 rle = resource_list_find(rl, type, *rid);
104 if (!rle) {
105 if (*rid < 0)
106 return 0;
107 switch (type) {
108 case SYS_RES_IRQ:
109 if (*rid >= ISA_NIRQ)
110 return 0;
111 break;
112 case SYS_RES_DRQ:
113 if (*rid >= ISA_NDRQ)
114 return 0;
115 break;
116 case SYS_RES_MEMORY:
117 if (*rid >= ISA_NMEM)
118 return 0;
119 break;
120 case SYS_RES_IOPORT:
121 if (*rid >= ISA_NPORT)
122 return 0;
123 break;
124 default:
125 return 0;
126 }
127 resource_list_add(rl, type, *rid, start, end, count);
128 }
129 }
130
131 return resource_list_alloc(rl, bus, child, type, rid,
132 start, end, count, flags);
133}
134
135#ifdef PC98
136/*
137 * Indirection support. The type of bus_space_handle_t is
138 * defined in sys/i386/include/bus_pc98.h.
139 */
140struct resource *
141isa_alloc_resourcev(device_t child, int type, int *rid,
142 bus_addr_t *res, bus_size_t count, u_int flags)
143{
144 struct isa_device* idev = DEVTOISA(child);
145 struct resource_list *rl = &idev->id_resources;
146
147 device_t bus = device_get_parent(child);
148 bus_addr_t start;
149 struct resource *re;
150 struct resource **bsre;
151 int i, j, k, linear_cnt, ressz, bsrid;
152
153 start = bus_get_resource_start(child, type, *rid);
154
155 linear_cnt = count;
156 ressz = 1;
157 for (i = 1; i < count; ++i) {
158 if (res[i] != res[i - 1] + 1) {
159 if (i < linear_cnt)
160 linear_cnt = i;
161 ++ressz;
162 }
163 }
164
165 re = isa_alloc_resource(bus, child, type, rid,
166 start + res[0], start + res[linear_cnt - 1],
167 linear_cnt, flags);
168 if (re == NULL)
169 return NULL;
170
171 bsre = malloc(sizeof (struct resource *) * ressz, M_DEVBUF, M_NOWAIT);
172 if (bsre == NULL) {
173 resource_list_release(rl, bus, child, type, *rid, re);
174 return NULL;
175 }
176 bsre[0] = re;
177
178 for (i = linear_cnt, k = 1; i < count; i = j, k++) {
179 for (j = i + 1; j < count; j++) {
180 if (res[j] != res[j - 1] + 1)
181 break;
182 }
183 bsrid = *rid + k;
184 bsre[k] = isa_alloc_resource(bus, child, type, &bsrid,
185 start + res[i], start + res[j - 1], j - i, flags);
186 if (bsre[k] == NULL) {
187 for (k--; k >= 0; k--)
188 resource_list_release(rl, bus, child, type,
189 *rid + k, bsre[k]);
190 free(bsre, M_DEVBUF);
191 return NULL;
192 }
193 }
194
195 re->r_bushandle->bsh_res = bsre;
196 re->r_bushandle->bsh_ressz = ressz;
197
198 return re;
199}
200
201int
202isa_load_resourcev(struct resource *re, bus_addr_t *res, bus_size_t count)
203{
204 bus_addr_t start;
205 int i;
206
207 if (count > re->r_bushandle->bsh_maxiatsz) {
208 printf("isa_load_resourcev: map size too large\n");
209 return EINVAL;
210 }
211
212 start = rman_get_start(re);
213 for (i = 0; i < re->r_bushandle->bsh_maxiatsz; i++) {
214 if (i < count)
215 re->r_bushandle->bsh_iat[i] = start + res[i];
216 else
217 re->r_bushandle->bsh_iat[i] = start;
218 }
219
220 re->r_bushandle->bsh_iatsz = count;
221 re->r_bushandle->bsh_bam = re->r_bustag->bs_ra; /* relocate access */
222
223 return 0;
224}
225#endif /* PC98 */
226
227int
228isa_release_resource(device_t bus, device_t child, int type, int rid,
229 struct resource *r)
230{
231 struct isa_device* idev = DEVTOISA(child);
232 struct resource_list *rl = &idev->id_resources;
233#ifdef PC98
234 /*
235 * Indirection support. The type of bus_space_handle_t is
236 * defined in sys/i386/include/bus_pc98.h.
237 */
238 int i;
239
240 if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) {
241 for (i = 1; i < r->r_bushandle->bsh_ressz; i++)
242 resource_list_release(rl, bus, child, type, rid + i,
243 r->r_bushandle->bsh_res[i]);
244 if (r->r_bushandle->bsh_res != NULL)
245 free(r->r_bushandle->bsh_res, M_DEVBUF);
246 }
247#endif
248 return resource_list_release(rl, bus, child, type, rid, r);
249}
250
251/*
252 * We can't use the bus_generic_* versions of these methods because those
253 * methods always pass the bus param as the requesting device, and we need
254 * to pass the child (the i386 nexus knows about this and is prepared to
255 * deal).
256 */
257int
258isa_setup_intr(device_t bus, device_t child, struct resource *r, int flags,
259 void (*ihand)(void *), void *arg, void **cookiep)
260{
261 return (BUS_SETUP_INTR(device_get_parent(bus), child, r, flags,
262 ihand, arg, cookiep));
263}
264
265int
266isa_teardown_intr(device_t bus, device_t child, struct resource *r,
267 void *cookie)
268{
269 return (BUS_TEARDOWN_INTR(device_get_parent(bus), child, r, cookie));
270}