Deleted Added
full compact
atkbdc_isa.c (114293) atkbdc_isa.c (116181)
1/*-
2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
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 as
10 * the first lines of this file unmodified.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1/*-
2 * Copyright (c) 1999 Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
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 as
10 * the first lines of this file unmodified.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/dev/atkbdc/atkbdc_isa.c 114293 2003-04-30 12:57:40Z markm $
27 */
28
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/dev/atkbdc/atkbdc_isa.c 116181 2003-06-11 00:34:37Z obrien $");
29
29#include "opt_kbd.h"
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/bus.h>
35#include <sys/malloc.h>
36#include <machine/bus_pio.h>
37#include <machine/bus.h>
38#include <machine/resource.h>
39#include <sys/rman.h>
40
41#include <dev/kbd/atkbdcreg.h>
42
43#include <isa/isareg.h>
44#include <isa/isavar.h>
45
46static MALLOC_DEFINE(M_ATKBDDEV, "atkbddev", "AT Keyboard device");
47
48/* children */
49typedef struct atkbdc_device {
50 struct resource_list resources;
51 int rid;
52 u_int32_t vendorid;
53 u_int32_t serial;
54 u_int32_t logicalid;
55 u_int32_t compatid;
56} atkbdc_device_t;
57
58/* kbdc */
59static devclass_t atkbdc_devclass;
60
61static int atkbdc_probe(device_t dev);
62static int atkbdc_attach(device_t dev);
63static device_t atkbdc_add_child(device_t bus, int order, char *name,
64 int unit);
65static int atkbdc_print_child(device_t bus, device_t dev);
66static int atkbdc_read_ivar(device_t bus, device_t dev, int index,
67 uintptr_t *val);
68static int atkbdc_write_ivar(device_t bus, device_t dev, int index,
69 uintptr_t val);
70static struct resource_list
71 *atkbdc_get_resource_list (device_t bus, device_t dev);
72static struct resource
73 *atkbdc_alloc_resource(device_t bus, device_t dev, int type,
74 int *rid, u_long start, u_long end,
75 u_long count, u_int flags);
76static int atkbdc_release_resource(device_t bus, device_t dev, int type,
77 int rid, struct resource *res);
78
79static device_method_t atkbdc_methods[] = {
80 DEVMETHOD(device_probe, atkbdc_probe),
81 DEVMETHOD(device_attach, atkbdc_attach),
82 DEVMETHOD(device_suspend, bus_generic_suspend),
83 DEVMETHOD(device_resume, bus_generic_resume),
84
85 DEVMETHOD(bus_add_child, atkbdc_add_child),
86 DEVMETHOD(bus_print_child, atkbdc_print_child),
87 DEVMETHOD(bus_read_ivar, atkbdc_read_ivar),
88 DEVMETHOD(bus_write_ivar, atkbdc_write_ivar),
89 DEVMETHOD(bus_get_resource_list,atkbdc_get_resource_list),
90 DEVMETHOD(bus_alloc_resource, atkbdc_alloc_resource),
91 DEVMETHOD(bus_release_resource, atkbdc_release_resource),
92 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
93 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
94 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
95 DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource),
96 DEVMETHOD(bus_delete_resource, bus_generic_rl_delete_resource),
97 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
98 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
99
100 { 0, 0 }
101};
102
103static driver_t atkbdc_driver = {
104 ATKBDC_DRIVER_NAME,
105 atkbdc_methods,
106 sizeof(atkbdc_softc_t *),
107};
108
109static struct isa_pnp_id atkbdc_ids[] = {
110 { 0x0303d041, "Keyboard controller (i8042)" }, /* PNP0303 */
111 { 0 }
112};
113
114static int
115atkbdc_probe(device_t dev)
116{
117 struct resource *port0;
118 struct resource *port1;
119 u_long start;
120 u_long count;
121 int error;
122 int rid;
123
124 /* check PnP IDs */
125 if (ISA_PNP_PROBE(device_get_parent(dev), dev, atkbdc_ids) == ENXIO)
126 return ENXIO;
127
128 device_set_desc(dev, "Keyboard controller (i8042)");
129
130 /*
131 * Adjust I/O port resources.
132 * The AT keyboard controller uses two ports (a command/data port
133 * 0x60 and a status port 0x64), which may be given to us in
134 * one resource (0x60 through 0x64) or as two separate resources
135 * (0x60 and 0x64). Furthermore, /boot/device.hints may contain
136 * just one port, 0x60. We shall adjust resource settings
137 * so that these two ports are available as two separate resources.
138 */
139 device_quiet(dev);
140 rid = 0;
141 if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count) != 0)
142 return ENXIO;
143 if (count > 1) /* adjust the count */
144 bus_set_resource(dev, SYS_RES_IOPORT, rid, start, 1);
145 port0 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
146 RF_ACTIVE);
147 if (port0 == NULL)
148 return ENXIO;
149 rid = 1;
150 if (bus_get_resource(dev, SYS_RES_IOPORT, rid, NULL, NULL) != 0)
151 bus_set_resource(dev, SYS_RES_IOPORT, 1,
152 start + KBD_STATUS_PORT, 1);
153 port1 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
154 RF_ACTIVE);
155 if (port1 == NULL) {
156 bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
157 return ENXIO;
158 }
159 device_verbose(dev);
160
161 error = atkbdc_probe_unit(device_get_unit(dev), port0, port1);
162 if (error == 0)
163 bus_generic_probe(dev);
164
165 bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
166 bus_release_resource(dev, SYS_RES_IOPORT, 1, port1);
167
168 return error;
169}
170
171static int
172atkbdc_attach(device_t dev)
173{
174 atkbdc_softc_t *sc;
175 int unit;
176 int error;
177 int rid;
178
179 unit = device_get_unit(dev);
180 sc = *(atkbdc_softc_t **)device_get_softc(dev);
181 if (sc == NULL) {
182 /*
183 * We have to maintain two copies of the kbdc_softc struct,
184 * as the low-level console needs to have access to the
185 * keyboard controller before kbdc is probed and attached.
186 * kbdc_soft[] contains the default entry for that purpose.
187 * See atkbdc.c. XXX
188 */
189 sc = atkbdc_get_softc(unit);
190 if (sc == NULL)
191 return ENOMEM;
192 }
193
194 rid = 0;
195 sc->port0 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
196 RF_ACTIVE);
197 if (sc->port0 == NULL)
198 return ENXIO;
199 rid = 1;
200 sc->port1 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
201 RF_ACTIVE);
202 if (sc->port1 == NULL) {
203 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0);
204 return ENXIO;
205 }
206
207 error = atkbdc_attach_unit(unit, sc, sc->port0, sc->port1);
208 if (error) {
209 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0);
210 bus_release_resource(dev, SYS_RES_IOPORT, 1, sc->port1);
211 return error;
212 }
213 *(atkbdc_softc_t **)device_get_softc(dev) = sc;
214
215 bus_generic_attach(dev);
216
217 return 0;
218}
219
220static device_t
221atkbdc_add_child(device_t bus, int order, char *name, int unit)
222{
223 atkbdc_device_t *ivar;
224 device_t child;
225 int t;
226
227 ivar = malloc(sizeof(struct atkbdc_device), M_ATKBDDEV,
228 M_NOWAIT | M_ZERO);
229 if (!ivar)
230 return NULL;
231
232 child = device_add_child_ordered(bus, order, name, unit);
233 if (child == NULL) {
234 free(ivar, M_ATKBDDEV);
235 return child;
236 }
237
238 resource_list_init(&ivar->resources);
239 ivar->rid = order;
240
241 /*
242 * If the device is not created by the PnP BIOS or ACPI,
243 * refer to device hints for IRQ.
244 */
245 if (ISA_PNP_PROBE(device_get_parent(bus), bus, atkbdc_ids) != 0) {
246 if (resource_int_value(name, unit, "irq", &t) != 0)
247 t = -1;
248 } else {
249 t = bus_get_resource_start(bus, SYS_RES_IRQ, ivar->rid);
250 }
251 if (t > 0)
252 resource_list_add(&ivar->resources, SYS_RES_IRQ, ivar->rid,
253 t, t, 1);
254
255 if (resource_int_value(name, unit, "flags", &t) == 0)
256 device_set_flags(child, t);
257 if (resource_int_value(name, unit, "disabled", &t) == 0 && t != 0)
258 device_disable(child);
259
260 device_set_ivars(child, ivar);
261
262 return child;
263}
264
265static int
266atkbdc_print_child(device_t bus, device_t dev)
267{
268 atkbdc_device_t *kbdcdev;
269 u_long irq;
270 int flags;
271 int retval = 0;
272
273 kbdcdev = (atkbdc_device_t *)device_get_ivars(dev);
274
275 retval += bus_print_child_header(bus, dev);
276 flags = device_get_flags(dev);
277 if (flags != 0)
278 retval += printf(" flags 0x%x", flags);
279 irq = bus_get_resource_start(dev, SYS_RES_IRQ, kbdcdev->rid);
280 if (irq != 0)
281 retval += printf(" irq %ld", irq);
282 retval += bus_print_child_footer(bus, dev);
283
284 return (retval);
285}
286
287static int
288atkbdc_read_ivar(device_t bus, device_t dev, int index, uintptr_t *val)
289{
290 atkbdc_device_t *ivar;
291
292 ivar = (atkbdc_device_t *)device_get_ivars(dev);
293 switch (index) {
294 case KBDC_IVAR_VENDORID:
295 *val = (u_long)ivar->vendorid;
296 break;
297 case KBDC_IVAR_SERIAL:
298 *val = (u_long)ivar->serial;
299 break;
300 case KBDC_IVAR_LOGICALID:
301 *val = (u_long)ivar->logicalid;
302 break;
303 case KBDC_IVAR_COMPATID:
304 *val = (u_long)ivar->compatid;
305 break;
306 default:
307 return ENOENT;
308 }
309 return 0;
310}
311
312static int
313atkbdc_write_ivar(device_t bus, device_t dev, int index, uintptr_t val)
314{
315 atkbdc_device_t *ivar;
316
317 ivar = (atkbdc_device_t *)device_get_ivars(dev);
318 switch (index) {
319 case KBDC_IVAR_VENDORID:
320 ivar->vendorid = (u_int32_t)val;
321 break;
322 case KBDC_IVAR_SERIAL:
323 ivar->serial = (u_int32_t)val;
324 break;
325 case KBDC_IVAR_LOGICALID:
326 ivar->logicalid = (u_int32_t)val;
327 break;
328 case KBDC_IVAR_COMPATID:
329 ivar->compatid = (u_int32_t)val;
330 break;
331 default:
332 return ENOENT;
333 }
334 return 0;
335}
336
337static struct resource_list
338*atkbdc_get_resource_list (device_t bus, device_t dev)
339{
340 atkbdc_device_t *ivar;
341
342 ivar = (atkbdc_device_t *)device_get_ivars(dev);
343 return &ivar->resources;
344}
345
346static struct resource
347*atkbdc_alloc_resource(device_t bus, device_t dev, int type, int *rid,
348 u_long start, u_long end, u_long count, u_int flags)
349{
350 atkbdc_device_t *ivar;
351
352 ivar = (atkbdc_device_t *)device_get_ivars(dev);
353 return resource_list_alloc(&ivar->resources, bus, dev, type, rid,
354 start, end, count, flags);
355}
356
357static int
358atkbdc_release_resource(device_t bus, device_t dev, int type, int rid,
359 struct resource *res)
360{
361 atkbdc_device_t *ivar;
362
363 ivar = (atkbdc_device_t *)device_get_ivars(dev);
364 return resource_list_release(&ivar->resources, bus, dev, type, rid,
365 res);
366}
367
368DRIVER_MODULE(atkbdc, isa, atkbdc_driver, atkbdc_devclass, 0, 0);
369DRIVER_MODULE(atkbdc, acpi, atkbdc_driver, atkbdc_devclass, 0, 0);
30#include "opt_kbd.h"
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/bus.h>
36#include <sys/malloc.h>
37#include <machine/bus_pio.h>
38#include <machine/bus.h>
39#include <machine/resource.h>
40#include <sys/rman.h>
41
42#include <dev/kbd/atkbdcreg.h>
43
44#include <isa/isareg.h>
45#include <isa/isavar.h>
46
47static MALLOC_DEFINE(M_ATKBDDEV, "atkbddev", "AT Keyboard device");
48
49/* children */
50typedef struct atkbdc_device {
51 struct resource_list resources;
52 int rid;
53 u_int32_t vendorid;
54 u_int32_t serial;
55 u_int32_t logicalid;
56 u_int32_t compatid;
57} atkbdc_device_t;
58
59/* kbdc */
60static devclass_t atkbdc_devclass;
61
62static int atkbdc_probe(device_t dev);
63static int atkbdc_attach(device_t dev);
64static device_t atkbdc_add_child(device_t bus, int order, char *name,
65 int unit);
66static int atkbdc_print_child(device_t bus, device_t dev);
67static int atkbdc_read_ivar(device_t bus, device_t dev, int index,
68 uintptr_t *val);
69static int atkbdc_write_ivar(device_t bus, device_t dev, int index,
70 uintptr_t val);
71static struct resource_list
72 *atkbdc_get_resource_list (device_t bus, device_t dev);
73static struct resource
74 *atkbdc_alloc_resource(device_t bus, device_t dev, int type,
75 int *rid, u_long start, u_long end,
76 u_long count, u_int flags);
77static int atkbdc_release_resource(device_t bus, device_t dev, int type,
78 int rid, struct resource *res);
79
80static device_method_t atkbdc_methods[] = {
81 DEVMETHOD(device_probe, atkbdc_probe),
82 DEVMETHOD(device_attach, atkbdc_attach),
83 DEVMETHOD(device_suspend, bus_generic_suspend),
84 DEVMETHOD(device_resume, bus_generic_resume),
85
86 DEVMETHOD(bus_add_child, atkbdc_add_child),
87 DEVMETHOD(bus_print_child, atkbdc_print_child),
88 DEVMETHOD(bus_read_ivar, atkbdc_read_ivar),
89 DEVMETHOD(bus_write_ivar, atkbdc_write_ivar),
90 DEVMETHOD(bus_get_resource_list,atkbdc_get_resource_list),
91 DEVMETHOD(bus_alloc_resource, atkbdc_alloc_resource),
92 DEVMETHOD(bus_release_resource, atkbdc_release_resource),
93 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
94 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
95 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
96 DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource),
97 DEVMETHOD(bus_delete_resource, bus_generic_rl_delete_resource),
98 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
99 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
100
101 { 0, 0 }
102};
103
104static driver_t atkbdc_driver = {
105 ATKBDC_DRIVER_NAME,
106 atkbdc_methods,
107 sizeof(atkbdc_softc_t *),
108};
109
110static struct isa_pnp_id atkbdc_ids[] = {
111 { 0x0303d041, "Keyboard controller (i8042)" }, /* PNP0303 */
112 { 0 }
113};
114
115static int
116atkbdc_probe(device_t dev)
117{
118 struct resource *port0;
119 struct resource *port1;
120 u_long start;
121 u_long count;
122 int error;
123 int rid;
124
125 /* check PnP IDs */
126 if (ISA_PNP_PROBE(device_get_parent(dev), dev, atkbdc_ids) == ENXIO)
127 return ENXIO;
128
129 device_set_desc(dev, "Keyboard controller (i8042)");
130
131 /*
132 * Adjust I/O port resources.
133 * The AT keyboard controller uses two ports (a command/data port
134 * 0x60 and a status port 0x64), which may be given to us in
135 * one resource (0x60 through 0x64) or as two separate resources
136 * (0x60 and 0x64). Furthermore, /boot/device.hints may contain
137 * just one port, 0x60. We shall adjust resource settings
138 * so that these two ports are available as two separate resources.
139 */
140 device_quiet(dev);
141 rid = 0;
142 if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count) != 0)
143 return ENXIO;
144 if (count > 1) /* adjust the count */
145 bus_set_resource(dev, SYS_RES_IOPORT, rid, start, 1);
146 port0 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
147 RF_ACTIVE);
148 if (port0 == NULL)
149 return ENXIO;
150 rid = 1;
151 if (bus_get_resource(dev, SYS_RES_IOPORT, rid, NULL, NULL) != 0)
152 bus_set_resource(dev, SYS_RES_IOPORT, 1,
153 start + KBD_STATUS_PORT, 1);
154 port1 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
155 RF_ACTIVE);
156 if (port1 == NULL) {
157 bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
158 return ENXIO;
159 }
160 device_verbose(dev);
161
162 error = atkbdc_probe_unit(device_get_unit(dev), port0, port1);
163 if (error == 0)
164 bus_generic_probe(dev);
165
166 bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
167 bus_release_resource(dev, SYS_RES_IOPORT, 1, port1);
168
169 return error;
170}
171
172static int
173atkbdc_attach(device_t dev)
174{
175 atkbdc_softc_t *sc;
176 int unit;
177 int error;
178 int rid;
179
180 unit = device_get_unit(dev);
181 sc = *(atkbdc_softc_t **)device_get_softc(dev);
182 if (sc == NULL) {
183 /*
184 * We have to maintain two copies of the kbdc_softc struct,
185 * as the low-level console needs to have access to the
186 * keyboard controller before kbdc is probed and attached.
187 * kbdc_soft[] contains the default entry for that purpose.
188 * See atkbdc.c. XXX
189 */
190 sc = atkbdc_get_softc(unit);
191 if (sc == NULL)
192 return ENOMEM;
193 }
194
195 rid = 0;
196 sc->port0 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
197 RF_ACTIVE);
198 if (sc->port0 == NULL)
199 return ENXIO;
200 rid = 1;
201 sc->port1 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
202 RF_ACTIVE);
203 if (sc->port1 == NULL) {
204 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0);
205 return ENXIO;
206 }
207
208 error = atkbdc_attach_unit(unit, sc, sc->port0, sc->port1);
209 if (error) {
210 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0);
211 bus_release_resource(dev, SYS_RES_IOPORT, 1, sc->port1);
212 return error;
213 }
214 *(atkbdc_softc_t **)device_get_softc(dev) = sc;
215
216 bus_generic_attach(dev);
217
218 return 0;
219}
220
221static device_t
222atkbdc_add_child(device_t bus, int order, char *name, int unit)
223{
224 atkbdc_device_t *ivar;
225 device_t child;
226 int t;
227
228 ivar = malloc(sizeof(struct atkbdc_device), M_ATKBDDEV,
229 M_NOWAIT | M_ZERO);
230 if (!ivar)
231 return NULL;
232
233 child = device_add_child_ordered(bus, order, name, unit);
234 if (child == NULL) {
235 free(ivar, M_ATKBDDEV);
236 return child;
237 }
238
239 resource_list_init(&ivar->resources);
240 ivar->rid = order;
241
242 /*
243 * If the device is not created by the PnP BIOS or ACPI,
244 * refer to device hints for IRQ.
245 */
246 if (ISA_PNP_PROBE(device_get_parent(bus), bus, atkbdc_ids) != 0) {
247 if (resource_int_value(name, unit, "irq", &t) != 0)
248 t = -1;
249 } else {
250 t = bus_get_resource_start(bus, SYS_RES_IRQ, ivar->rid);
251 }
252 if (t > 0)
253 resource_list_add(&ivar->resources, SYS_RES_IRQ, ivar->rid,
254 t, t, 1);
255
256 if (resource_int_value(name, unit, "flags", &t) == 0)
257 device_set_flags(child, t);
258 if (resource_int_value(name, unit, "disabled", &t) == 0 && t != 0)
259 device_disable(child);
260
261 device_set_ivars(child, ivar);
262
263 return child;
264}
265
266static int
267atkbdc_print_child(device_t bus, device_t dev)
268{
269 atkbdc_device_t *kbdcdev;
270 u_long irq;
271 int flags;
272 int retval = 0;
273
274 kbdcdev = (atkbdc_device_t *)device_get_ivars(dev);
275
276 retval += bus_print_child_header(bus, dev);
277 flags = device_get_flags(dev);
278 if (flags != 0)
279 retval += printf(" flags 0x%x", flags);
280 irq = bus_get_resource_start(dev, SYS_RES_IRQ, kbdcdev->rid);
281 if (irq != 0)
282 retval += printf(" irq %ld", irq);
283 retval += bus_print_child_footer(bus, dev);
284
285 return (retval);
286}
287
288static int
289atkbdc_read_ivar(device_t bus, device_t dev, int index, uintptr_t *val)
290{
291 atkbdc_device_t *ivar;
292
293 ivar = (atkbdc_device_t *)device_get_ivars(dev);
294 switch (index) {
295 case KBDC_IVAR_VENDORID:
296 *val = (u_long)ivar->vendorid;
297 break;
298 case KBDC_IVAR_SERIAL:
299 *val = (u_long)ivar->serial;
300 break;
301 case KBDC_IVAR_LOGICALID:
302 *val = (u_long)ivar->logicalid;
303 break;
304 case KBDC_IVAR_COMPATID:
305 *val = (u_long)ivar->compatid;
306 break;
307 default:
308 return ENOENT;
309 }
310 return 0;
311}
312
313static int
314atkbdc_write_ivar(device_t bus, device_t dev, int index, uintptr_t val)
315{
316 atkbdc_device_t *ivar;
317
318 ivar = (atkbdc_device_t *)device_get_ivars(dev);
319 switch (index) {
320 case KBDC_IVAR_VENDORID:
321 ivar->vendorid = (u_int32_t)val;
322 break;
323 case KBDC_IVAR_SERIAL:
324 ivar->serial = (u_int32_t)val;
325 break;
326 case KBDC_IVAR_LOGICALID:
327 ivar->logicalid = (u_int32_t)val;
328 break;
329 case KBDC_IVAR_COMPATID:
330 ivar->compatid = (u_int32_t)val;
331 break;
332 default:
333 return ENOENT;
334 }
335 return 0;
336}
337
338static struct resource_list
339*atkbdc_get_resource_list (device_t bus, device_t dev)
340{
341 atkbdc_device_t *ivar;
342
343 ivar = (atkbdc_device_t *)device_get_ivars(dev);
344 return &ivar->resources;
345}
346
347static struct resource
348*atkbdc_alloc_resource(device_t bus, device_t dev, int type, int *rid,
349 u_long start, u_long end, u_long count, u_int flags)
350{
351 atkbdc_device_t *ivar;
352
353 ivar = (atkbdc_device_t *)device_get_ivars(dev);
354 return resource_list_alloc(&ivar->resources, bus, dev, type, rid,
355 start, end, count, flags);
356}
357
358static int
359atkbdc_release_resource(device_t bus, device_t dev, int type, int rid,
360 struct resource *res)
361{
362 atkbdc_device_t *ivar;
363
364 ivar = (atkbdc_device_t *)device_get_ivars(dev);
365 return resource_list_release(&ivar->resources, bus, dev, type, rid,
366 res);
367}
368
369DRIVER_MODULE(atkbdc, isa, atkbdc_driver, atkbdc_devclass, 0, 0);
370DRIVER_MODULE(atkbdc, acpi, atkbdc_driver, atkbdc_devclass, 0, 0);