Deleted Added
full compact
atkbdc_isa.c (147263) atkbdc_isa.c (147271)
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

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

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
27#include <sys/cdefs.h>
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

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

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
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/dev/atkbdc/atkbdc_isa.c 146734 2005-05-29 04:42:30Z nyan $");
28__FBSDID("$FreeBSD: head/sys/dev/atkbdc/atkbdc_isa.c 147271 2005-06-10 20:56:38Z marius $");
29
30#include "opt_kbd.h"
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/module.h>
36#include <sys/bus.h>
37#include <sys/malloc.h>
38#include <machine/resource.h>
39#include <sys/rman.h>
40
29
30#include "opt_kbd.h"
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/kernel.h>
35#include <sys/module.h>
36#include <sys/bus.h>
37#include <sys/malloc.h>
38#include <machine/resource.h>
39#include <sys/rman.h>
40
41#include <dev/kbd/atkbdcreg.h>
41#include <dev/atkbdc/atkbdc_subr.h>
42#include <dev/atkbdc/atkbdcreg.h>
42
43#include <isa/isareg.h>
44#include <isa/isavar.h>
45
43
44#include <isa/isareg.h>
45#include <isa/isavar.h>
46
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,
47static int atkbdc_isa_probe(device_t dev);
48static int atkbdc_isa_attach(device_t dev);
49static device_t atkbdc_isa_add_child(device_t bus, int order, char *name,
64 int unit);
50 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
51
79static device_method_t atkbdc_methods[] = {
80 DEVMETHOD(device_probe, atkbdc_probe),
81 DEVMETHOD(device_attach, atkbdc_attach),
52static device_method_t atkbdc_isa_methods[] = {
53 DEVMETHOD(device_probe, atkbdc_isa_probe),
54 DEVMETHOD(device_attach, atkbdc_isa_attach),
82 DEVMETHOD(device_suspend, bus_generic_suspend),
83 DEVMETHOD(device_resume, bus_generic_resume),
84
55 DEVMETHOD(device_suspend, bus_generic_suspend),
56 DEVMETHOD(device_resume, bus_generic_resume),
57
85 DEVMETHOD(bus_add_child, atkbdc_add_child),
58 DEVMETHOD(bus_add_child, atkbdc_isa_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),
59 DEVMETHOD(bus_print_child, atkbdc_print_child),
60 DEVMETHOD(bus_read_ivar, atkbdc_read_ivar),
61 DEVMETHOD(bus_write_ivar, atkbdc_write_ivar),
62 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),
63 DEVMETHOD(bus_alloc_resource, bus_generic_rl_alloc_resource),
64 DEVMETHOD(bus_release_resource, bus_generic_rl_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
65 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
66 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
67 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource),
68 DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource),
69 DEVMETHOD(bus_delete_resource, bus_generic_rl_delete_resource),
70 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
71 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
72
73 { 0, 0 }
74};
75
103static driver_t atkbdc_driver = {
76static driver_t atkbdc_isa_driver = {
104 ATKBDC_DRIVER_NAME,
77 ATKBDC_DRIVER_NAME,
105 atkbdc_methods,
78 atkbdc_isa_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
79 sizeof(atkbdc_softc_t *),
80};
81
82static struct isa_pnp_id atkbdc_ids[] = {
83 { 0x0303d041, "Keyboard controller (i8042)" }, /* PNP0303 */
84 { 0 }
85};
86
87static int
115atkbdc_probe(device_t dev)
88atkbdc_isa_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

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

162
163 bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
164 bus_release_resource(dev, SYS_RES_IOPORT, 1, port1);
165
166 return error;
167}
168
169static int
89{
90 struct resource *port0;
91 struct resource *port1;
92 u_long start;
93 u_long count;
94 int error;
95 int rid;
96

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

135
136 bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
137 bus_release_resource(dev, SYS_RES_IOPORT, 1, port1);
138
139 return error;
140}
141
142static int
170atkbdc_attach(device_t dev)
143atkbdc_isa_attach(device_t dev)
171{
172 atkbdc_softc_t *sc;
173 int unit;
174 int error;
175 int rid;
176
177 unit = device_get_unit(dev);
178 sc = *(atkbdc_softc_t **)device_get_softc(dev);
179 if (sc == NULL) {
180 /*
181 * We have to maintain two copies of the kbdc_softc struct,
182 * as the low-level console needs to have access to the
144{
145 atkbdc_softc_t *sc;
146 int unit;
147 int error;
148 int rid;
149
150 unit = device_get_unit(dev);
151 sc = *(atkbdc_softc_t **)device_get_softc(dev);
152 if (sc == NULL) {
153 /*
154 * We have to maintain two copies of the kbdc_softc struct,
155 * as the low-level console needs to have access to the
183 * keyboard controller before kbdc is probed and attached.
156 * keyboard controller before kbdc is probed and attached.
184 * kbdc_soft[] contains the default entry for that purpose.
185 * See atkbdc.c. XXX
186 */
187 sc = atkbdc_get_softc(unit);
188 if (sc == NULL)
189 return ENOMEM;
190 }
191

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

211 *(atkbdc_softc_t **)device_get_softc(dev) = sc;
212
213 bus_generic_attach(dev);
214
215 return 0;
216}
217
218static device_t
157 * kbdc_soft[] contains the default entry for that purpose.
158 * See atkbdc.c. XXX
159 */
160 sc = atkbdc_get_softc(unit);
161 if (sc == NULL)
162 return ENOMEM;
163 }
164

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

184 *(atkbdc_softc_t **)device_get_softc(dev) = sc;
185
186 bus_generic_attach(dev);
187
188 return 0;
189}
190
191static device_t
219atkbdc_add_child(device_t bus, int order, char *name, int unit)
192atkbdc_isa_add_child(device_t bus, int order, char *name, int unit)
220{
221 atkbdc_device_t *ivar;
222 device_t child;
223 int t;
224
225 ivar = malloc(sizeof(struct atkbdc_device), M_ATKBDDEV,
226 M_NOWAIT | M_ZERO);
227 if (!ivar)

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

253 if (resource_disabled(name, unit))
254 device_disable(child);
255
256 device_set_ivars(child, ivar);
257
258 return child;
259}
260
193{
194 atkbdc_device_t *ivar;
195 device_t child;
196 int t;
197
198 ivar = malloc(sizeof(struct atkbdc_device), M_ATKBDDEV,
199 M_NOWAIT | M_ZERO);
200 if (!ivar)

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

226 if (resource_disabled(name, unit))
227 device_disable(child);
228
229 device_set_ivars(child, ivar);
230
231 return child;
232}
233
261static int
262atkbdc_print_child(device_t bus, device_t dev)
263{
264 atkbdc_device_t *kbdcdev;
265 u_long irq;
266 int flags;
267 int retval = 0;
268
269 kbdcdev = (atkbdc_device_t *)device_get_ivars(dev);
270
271 retval += bus_print_child_header(bus, dev);
272 flags = device_get_flags(dev);
273 if (flags != 0)
274 retval += printf(" flags 0x%x", flags);
275 irq = bus_get_resource_start(dev, SYS_RES_IRQ, kbdcdev->rid);
276 if (irq != 0)
277 retval += printf(" irq %ld", irq);
278 retval += bus_print_child_footer(bus, dev);
279
280 return (retval);
281}
282
283static int
284atkbdc_read_ivar(device_t bus, device_t dev, int index, uintptr_t *val)
285{
286 atkbdc_device_t *ivar;
287
288 ivar = (atkbdc_device_t *)device_get_ivars(dev);
289 switch (index) {
290 case KBDC_IVAR_VENDORID:
291 *val = (u_long)ivar->vendorid;
292 break;
293 case KBDC_IVAR_SERIAL:
294 *val = (u_long)ivar->serial;
295 break;
296 case KBDC_IVAR_LOGICALID:
297 *val = (u_long)ivar->logicalid;
298 break;
299 case KBDC_IVAR_COMPATID:
300 *val = (u_long)ivar->compatid;
301 break;
302 default:
303 return ENOENT;
304 }
305 return 0;
306}
307
308static int
309atkbdc_write_ivar(device_t bus, device_t dev, int index, uintptr_t val)
310{
311 atkbdc_device_t *ivar;
312
313 ivar = (atkbdc_device_t *)device_get_ivars(dev);
314 switch (index) {
315 case KBDC_IVAR_VENDORID:
316 ivar->vendorid = (u_int32_t)val;
317 break;
318 case KBDC_IVAR_SERIAL:
319 ivar->serial = (u_int32_t)val;
320 break;
321 case KBDC_IVAR_LOGICALID:
322 ivar->logicalid = (u_int32_t)val;
323 break;
324 case KBDC_IVAR_COMPATID:
325 ivar->compatid = (u_int32_t)val;
326 break;
327 default:
328 return ENOENT;
329 }
330 return 0;
331}
332
333static struct resource_list
334*atkbdc_get_resource_list (device_t bus, device_t dev)
335{
336 atkbdc_device_t *ivar;
337
338 ivar = (atkbdc_device_t *)device_get_ivars(dev);
339 return &ivar->resources;
340}
341
342static struct resource
343*atkbdc_alloc_resource(device_t bus, device_t dev, int type, int *rid,
344 u_long start, u_long end, u_long count, u_int flags)
345{
346 atkbdc_device_t *ivar;
347
348 ivar = (atkbdc_device_t *)device_get_ivars(dev);
349 return resource_list_alloc(&ivar->resources, bus, dev, type, rid,
350 start, end, count, flags);
351}
352
353static int
354atkbdc_release_resource(device_t bus, device_t dev, int type, int rid,
355 struct resource *res)
356{
357 atkbdc_device_t *ivar;
358
359 ivar = (atkbdc_device_t *)device_get_ivars(dev);
360 return resource_list_release(&ivar->resources, bus, dev, type, rid,
361 res);
362}
363
364DRIVER_MODULE(atkbdc, isa, atkbdc_driver, atkbdc_devclass, 0, 0);
365DRIVER_MODULE(atkbdc, acpi, atkbdc_driver, atkbdc_devclass, 0, 0);
234DRIVER_MODULE(atkbdc, isa, atkbdc_isa_driver, atkbdc_devclass, 0, 0);
235DRIVER_MODULE(atkbdc, acpi, atkbdc_isa_driver, atkbdc_devclass, 0, 0);