1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
/*-
* Copyright (c) 1998 Doug Rabson
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/malloc.h>
#include <sys/module.h>
#include <machine/bus.h>
#include <sys/rman.h>
#include <machine/vmparam.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <machine/pmap.h>
#include <machine/md_var.h>
#include <machine/resource.h>
#include <isa/isavar.h>
#include <i386/isa/isa_compat.h>
#include <i386/isa/isa_device.h>
struct isa_compat_resources {
struct resource *ports;
struct resource *memory;
struct resource *drq;
struct resource *irq;
};
int
isa_compat_nextid(void)
{
static int id = 2; /* id_id of -1, 0 and 1 are "used" */
return id++;
}
static void
isa_compat_alloc_resources(device_t dev, struct isa_compat_resources *res)
{
device_t parent = device_get_parent(dev);
int rid;
u_long start, count;
if (ISA_GET_RESOURCE(parent, dev, SYS_RES_IOPORT, 0,
&start, &count) == 0) {
rid = 0;
res->ports = bus_alloc_resource(dev, SYS_RES_IOPORT,
&rid, 0ul, ~0ul, 1,
RF_ACTIVE);
if (res->ports == NULL)
printf("isa_compat: didn't get ports for %s\n",
device_get_name(dev));
} else
res->ports = 0;
if (ISA_GET_RESOURCE(parent, dev, SYS_RES_MEMORY, 0,
&start, &count) == 0
&& start != 0) {
rid = 0;
res->memory = bus_alloc_resource(dev, SYS_RES_MEMORY,
&rid, 0ul, ~0ul, 1,
RF_ACTIVE);
if (res->memory == NULL)
printf("isa_compat: didn't get memory for %s\n",
device_get_name(dev));
} else
res->memory = 0;
if (ISA_GET_RESOURCE(parent, dev, SYS_RES_DRQ, 0,
&start, &count) == 0) {
rid = 0;
res->drq = bus_alloc_resource(dev, SYS_RES_DRQ,
&rid, 0ul, ~0ul, 1,
RF_ACTIVE);
if (res->drq == NULL)
printf("isa_compat: didn't get drq for %s\n",
device_get_name(dev));
} else
res->drq = 0;
if (ISA_GET_RESOURCE(parent, dev, SYS_RES_IRQ, 0,
&start, &count) == 0) {
rid = 0;
res->irq = bus_alloc_resource(dev, SYS_RES_IRQ,
&rid, 0ul, ~0ul, 1,
RF_SHAREABLE | RF_ACTIVE);
if (res->irq == NULL)
printf("isa_compat: didn't get irq for %s\n",
device_get_name(dev));
} else
res->irq = 0;
}
static void
isa_compat_release_resources(device_t dev, struct isa_compat_resources *res)
{
if (res->ports) {
bus_release_resource(dev, SYS_RES_IOPORT, 0, res->ports);
res->ports = 0;
}
if (res->memory) {
bus_release_resource(dev, SYS_RES_MEMORY, 0, res->memory);
res->memory = 0;
}
if (res->drq) {
bus_release_resource(dev, SYS_RES_DRQ, 0, res->drq);
res->drq = 0;
}
if (res->irq) {
bus_release_resource(dev, SYS_RES_IRQ, 0, res->irq);
res->irq = 0;
}
}
#define irqmask(x) ((x) < 0 ? 0 : (1 << (x)))
static int
isa_compat_probe(device_t dev)
{
device_t parent = device_get_parent(dev);
struct isa_device *dvp = device_get_softc(dev);
struct isa_compat_resources res;
struct old_isa_driver *op;
u_long start, count;
/* No pnp support */
if (isa_get_vendorid(dev))
return (ENXIO);
bzero(&res, sizeof(res));
/*
* Fill in the isa_device fields.
*/
op = device_get_driver(dev)->priv;
dvp->id_id = isa_compat_nextid();
dvp->id_driver = op->driver;
if (ISA_GET_RESOURCE(parent, dev, SYS_RES_IOPORT, 0,
&start, &count) == 0)
dvp->id_iobase = start;
else
dvp->id_iobase = -1;
if (ISA_GET_RESOURCE(parent, dev, SYS_RES_IRQ, 0,
&start, &count) == 0)
dvp->id_irq = irqmask(start);
else
dvp->id_irq = 0;
if (ISA_GET_RESOURCE(parent, dev, SYS_RES_DRQ, 0,
&start, &count) == 0)
dvp->id_drq = start;
else
dvp->id_drq = -1;
if (ISA_GET_RESOURCE(parent, dev, SYS_RES_MEMORY,
0, &start, &count) == 0) {
dvp->id_maddr = (void *)(uintptr_t)start;
dvp->id_msize = count;
} else {
dvp->id_maddr = NULL;
dvp->id_msize = 0;
}
dvp->id_unit = device_get_unit(dev);
dvp->id_flags = device_get_flags(dev);
dvp->id_enabled = device_is_enabled(dev); /* XXX unused */
dvp->id_device = dev;
/*
* Do the wrapped probe.
*/
if (dvp->id_driver->probe) {
int portsize;
void *maddr;
struct isa_device old;
isa_compat_alloc_resources(dev, &res);
if (res.memory)
maddr = rman_get_virtual(res.memory);
else
maddr = 0;
dvp->id_maddr = maddr;
old = *dvp;
portsize = dvp->id_driver->probe(dvp);
isa_compat_release_resources(dev, &res);
if (portsize != 0) {
if (portsize > 0 || dvp->id_iobase != old.id_iobase)
ISA_SET_RESOURCE(parent, dev, SYS_RES_IOPORT,
0, dvp->id_iobase, portsize);
if (dvp->id_irq != old.id_irq)
ISA_SET_RESOURCE(parent, dev, SYS_RES_IRQ, 0,
ffs(dvp->id_irq) - 1, 1);
if (dvp->id_drq != old.id_drq)
ISA_SET_RESOURCE(parent, dev, SYS_RES_DRQ, 0,
dvp->id_drq, 1);
if (dvp->id_maddr != old.id_maddr
|| dvp->id_msize != old.id_msize) {
maddr = dvp->id_maddr;
if (maddr != NULL)
ISA_SET_RESOURCE(parent, dev,
SYS_RES_MEMORY,
0,
kvtop(maddr),
dvp->id_msize);
else
ISA_DELETE_RESOURCE(parent, dev,
SYS_RES_MEMORY,
0);
}
return 0;
}
}
return ENXIO;
}
static int
isa_compat_attach(device_t dev)
{
struct isa_device *dvp = device_get_softc(dev);
struct isa_compat_resources res;
int error;
bzero(&res, sizeof(res));
isa_compat_alloc_resources(dev, &res);
if (dvp->id_driver->attach)
dvp->id_driver->attach(dvp);
if (res.irq && dvp->id_irq && dvp->id_intr) {
struct old_isa_driver *op;
void *ih;
op = device_get_driver(dev)->priv;
error = BUS_SETUP_INTR(device_get_parent(dev), dev,
res.irq, op->type,
dvp->id_intr,
(void *)(uintptr_t)dvp->id_unit,
&ih);
if (error)
printf("isa_compat_attach: failed to setup intr: %d\n",
error);
}
return 0;
}
static device_method_t isa_compat_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, isa_compat_probe),
DEVMETHOD(device_attach, isa_compat_attach),
{ 0, 0 }
};
/*
* Create a new style driver around each old isa driver.
*/
void
isa_wrap_old_drivers(void)
{
int i;
struct old_isa_driver *op;
devclass_t isa_devclass = devclass_find("isa");
for (i = 0, op = &old_drivers[0]; i < old_drivers_count; i++, op++) {
driver_t *driver;
driver = malloc(sizeof(driver_t), M_DEVBUF, M_NOWAIT);
if (!driver)
continue;
bzero(driver, sizeof(driver_t));
driver->name = op->driver->name;
driver->methods = isa_compat_methods;
driver->softc = sizeof(struct isa_device);
driver->priv = op;
if (op->driver->sensitive_hw)
resource_set_int(op->driver->name, -1, "sensitive", 1);
devclass_add_driver(isa_devclass, driver);
}
}
int
haveseen_iobase(struct isa_device *dvp, int size)
{
int rid;
struct resource *res;
device_t dev = dvp->id_device;
int base = dvp->id_iobase;
/*
* Ask for resource 1 so that we don't hurt our hints. In theory
* this should work, but....
*/
rid = 1;
res = bus_alloc_resource(dev, SYS_RES_IOPORT,
&rid, base, base + size, size, RF_ACTIVE);
if (res)
bus_release_resource(dev, SYS_RES_IOPORT, rid, res);
return res ? 0 : 1;
}
void
reconfig_isadev(isdp, mp)
struct isa_device *isdp;
u_int *mp;
{
printf("reconfig_isadev() called - FIXME!\n");
}
|