Deleted Added
full compact
atkbdc_subr.c (82555) atkbdc_subr.c (83147)
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 unchanged lines hidden (view full) ---

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 *
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 unchanged lines hidden (view full) ---

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_subr.c 82555 2001-08-30 09:17:03Z msmith $
26 * $FreeBSD: head/sys/dev/atkbdc/atkbdc_subr.c 83147 2001-09-06 12:09:26Z yokota $
27 */
28
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>

--- 7 unchanged lines hidden (view full) ---

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 {
27 */
28
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>

--- 7 unchanged lines hidden (view full) ---

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 int flags; /* configuration flags */
51 int irq; /* ISA IRQ mask */
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 */
59devclass_t atkbdc_devclass;
60
61static int atkbdc_probe(device_t dev);
62static int atkbdc_attach(device_t dev);
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 */
59devclass_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);
63static int atkbdc_print_child(device_t bus, device_t dev);
64static int atkbdc_read_ivar(device_t bus, device_t dev, int index,
65 uintptr_t *val);
66static int atkbdc_write_ivar(device_t bus, device_t dev, int index,
67 uintptr_t val);
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);
68
69static device_method_t atkbdc_methods[] = {
70 DEVMETHOD(device_probe, atkbdc_probe),
71 DEVMETHOD(device_attach, atkbdc_attach),
72 DEVMETHOD(device_suspend, bus_generic_suspend),
73 DEVMETHOD(device_resume, bus_generic_resume),
74
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),
75 DEVMETHOD(bus_print_child, atkbdc_print_child),
76 DEVMETHOD(bus_read_ivar, atkbdc_read_ivar),
77 DEVMETHOD(bus_write_ivar, atkbdc_write_ivar),
86 DEVMETHOD(bus_print_child, atkbdc_print_child),
87 DEVMETHOD(bus_read_ivar, atkbdc_read_ivar),
88 DEVMETHOD(bus_write_ivar, atkbdc_write_ivar),
78 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
79 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
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),
80 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
81 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_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),
82 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
83 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
84
85 { 0, 0 }
86};
87
88static driver_t atkbdc_driver = {
89 ATKBDC_DRIVER_NAME,

--- 6 unchanged lines hidden (view full) ---

96 { 0 }
97};
98
99static int
100atkbdc_probe(device_t dev)
101{
102 struct resource *port0;
103 struct resource *port1;
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,

--- 6 unchanged lines hidden (view full) ---

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;
104 int error;
105 int rid;
106
107 /* check PnP IDs */
108 if (ISA_PNP_PROBE(device_get_parent(dev), dev, atkbdc_ids) == ENXIO)
109 return ENXIO;
110
111 device_set_desc(dev, "Keyboard controller (i8042)");
112
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);
113 rid = 0;
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);
114 port0 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
115 RF_ACTIVE);
116 if (port0 == NULL)
117 return ENXIO;
145 port0 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
146 RF_ACTIVE);
147 if (port0 == NULL)
148 return ENXIO;
118 /* XXX */
119 if (bus_get_resource_start(dev, SYS_RES_IOPORT, 1) <= 0) {
120 bus_set_resource(dev, SYS_RES_IOPORT, 1,
121 rman_get_start(port0) + KBD_STATUS_PORT, 1);
122 }
123 rid = 1;
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);
124 port1 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
125 RF_ACTIVE);
126 if (port1 == NULL) {
127 bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
128 return ENXIO;
129 }
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);
130
131 error = atkbdc_probe_unit(device_get_unit(dev), port0, port1);
160
161 error = atkbdc_probe_unit(device_get_unit(dev), port0, port1);
162 if (error == 0)
163 bus_generic_probe(dev);
132
133 bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
134 bus_release_resource(dev, SYS_RES_IOPORT, 1, port1);
135
136 return error;
137}
138
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
139static void
140atkbdc_add_device(device_t dev, const char *name, int unit)
141{
142 atkbdc_device_t *kdev;
143 device_t child;
144 int t;
145
146 if (resource_int_value(name, unit, "disabled", &t) == 0 && t != 0)
147 return;
148
149 kdev = malloc(sizeof(struct atkbdc_device), M_ATKBDDEV,
150 M_NOWAIT | M_ZERO);
151 if (!kdev)
152 return;
153
154 if (resource_int_value(name, unit, "irq", &t) == 0)
155 kdev->irq = t;
156 else
157 kdev->irq = -1;
158
159 if (resource_int_value(name, unit, "flags", &t) == 0)
160 kdev->flags = t;
161 else
162 kdev->flags = 0;
163
164 child = device_add_child(dev, name, unit);
165 device_set_ivars(child, kdev);
166}
167
168static int
169atkbdc_attach(device_t dev)
170{
171 atkbdc_softc_t *sc;
171static int
172atkbdc_attach(device_t dev)
173{
174 atkbdc_softc_t *sc;
172 int unit, dunit;
175 int unit;
173 int error;
174 int rid;
176 int error;
177 int rid;
175 int i;
176 const char *name, *dname;
177
178 unit = device_get_unit(dev);
179 sc = *(atkbdc_softc_t **)device_get_softc(dev);
180 if (sc == NULL) {
181 /*
182 * We have to maintain two copies of the kbdc_softc struct,
183 * as the low-level console needs to have access to the
184 * keyboard controller before kbdc is probed and attached.

--- 21 unchanged lines hidden (view full) ---

206 error = atkbdc_attach_unit(unit, sc, sc->port0, sc->port1);
207 if (error) {
208 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0);
209 bus_release_resource(dev, SYS_RES_IOPORT, 1, sc->port1);
210 return error;
211 }
212 *(atkbdc_softc_t **)device_get_softc(dev) = sc;
213
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.

--- 21 unchanged lines hidden (view full) ---

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
214 /*
215 * Add all devices configured to be attached to atkbdc0.
216 */
217 name = device_get_nameunit(dev);
218 i = 0;
219 while ((resource_find_match(&i, &dname, &dunit, "at", name)) == 0)
220 atkbdc_add_device(dev, dname, dunit);
215 bus_generic_attach(dev);
221
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(bus, NULL, -1);
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
222 /*
241 /*
223 * and atkbdc?
242 * If the device is not created by the PnP BIOS or ACPI,
243 * refer to device hints for IRQ.
224 */
244 */
225 name = device_get_name(dev);
226 i = 0;
227 while ((resource_find_match(&i, &dname, &dunit, "at", name)) == 0)
228 atkbdc_add_device(dev, dname, dunit);
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);
229
254
230 bus_generic_attach(dev);
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);
231
259
232 return 0;
260 device_set_ivars(child, ivar);
261
262 return child;
233}
234
235static int
236atkbdc_print_child(device_t bus, device_t dev)
237{
238 atkbdc_device_t *kbdcdev;
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;
239 int retval = 0;
240
241 kbdcdev = (atkbdc_device_t *)device_get_ivars(dev);
242
243 retval += bus_print_child_header(bus, dev);
271 int retval = 0;
272
273 kbdcdev = (atkbdc_device_t *)device_get_ivars(dev);
274
275 retval += bus_print_child_header(bus, dev);
244 if (kbdcdev->flags != 0)
245 retval += printf(" flags 0x%x", kbdcdev->flags);
246 if (kbdcdev->irq != -1)
247 retval += printf(" irq %d", kbdcdev->irq);
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);
248 retval += bus_print_child_footer(bus, dev);
249
250 return (retval);
251}
252
253static int
254atkbdc_read_ivar(device_t bus, device_t dev, int index, uintptr_t *val)
255{
256 atkbdc_device_t *ivar;
257
258 ivar = (atkbdc_device_t *)device_get_ivars(dev);
259 switch (index) {
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) {
260 case KBDC_IVAR_IRQ:
261 *val = (u_long)ivar->irq;
262 break;
263 case KBDC_IVAR_FLAGS:
264 *val = (u_long)ivar->flags;
265 break;
266 case KBDC_IVAR_VENDORID:
267 *val = (u_long)ivar->vendorid;
268 break;
269 case KBDC_IVAR_SERIAL:
270 *val = (u_long)ivar->serial;
271 break;
272 case KBDC_IVAR_LOGICALID:
273 *val = (u_long)ivar->logicalid;

--- 9 unchanged lines hidden (view full) ---

283
284static int
285atkbdc_write_ivar(device_t bus, device_t dev, int index, uintptr_t val)
286{
287 atkbdc_device_t *ivar;
288
289 ivar = (atkbdc_device_t *)device_get_ivars(dev);
290 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;

--- 9 unchanged lines hidden (view full) ---

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) {
291 case KBDC_IVAR_IRQ:
292 ivar->irq = (int)val;
293 break;
294 case KBDC_IVAR_FLAGS:
295 ivar->flags = (int)val;
296 break;
297 case KBDC_IVAR_VENDORID:
298 ivar->vendorid = (u_int32_t)val;
299 break;
300 case KBDC_IVAR_SERIAL:
301 ivar->serial = (u_int32_t)val;
302 break;
303 case KBDC_IVAR_LOGICALID:
304 ivar->logicalid = (u_int32_t)val;
305 break;
306 case KBDC_IVAR_COMPATID:
307 ivar->compatid = (u_int32_t)val;
308 break;
309 default:
310 return ENOENT;
311 }
312 return 0;
313}
314
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
315DRIVER_MODULE(atkbdc, isa, atkbdc_driver, atkbdc_devclass, 0, 0);
316DRIVER_MODULE(atkbdc, acpi, atkbdc_driver, atkbdc_devclass, 0, 0);
368DRIVER_MODULE(atkbdc, isa, atkbdc_driver, atkbdc_devclass, 0, 0);
369DRIVER_MODULE(atkbdc, acpi, atkbdc_driver, atkbdc_devclass, 0, 0);