Deleted Added
full compact
atkbdc_subr.c (46836) atkbdc_subr.c (47296)
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 *
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 * $Id: atkbdc_isa.c,v 1.4 1999/05/08 21:59:29 dfr Exp $
26 * $Id: atkbdc_isa.c,v 1.5 1999/05/09 20:45:53 peter Exp $
27 */
28
29#include "atkbdc.h"
30#include "opt_kbd.h"
31
32#if NATKBDC > 0
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/kernel.h>
37#include <sys/bus.h>
38#include <sys/malloc.h>
39
40#include <dev/kbd/atkbdcreg.h>
41
42#include <isa/isareg.h>
43#include <isa/isavar.h>
44
45MALLOC_DEFINE(M_ATKBDDEV, "atkbddev", "AT Keyboard device");
46
47/* children */
48typedef struct atkbdc_device {
49 int flags; /* configuration flags */
50 int port; /* port number (same as the controller's) */
51 int irq; /* ISA IRQ mask */
52} atkbdc_device_t;
53
54/* kbdc */
55devclass_t atkbdc_devclass;
56
57static int atkbdc_probe(device_t dev);
58static int atkbdc_attach(device_t dev);
59static void atkbdc_print_child(device_t bus, device_t dev);
60static int atkbdc_read_ivar(device_t bus, device_t dev, int index,
61 u_long *val);
62static int atkbdc_write_ivar(device_t bus, device_t dev, int index,
63 u_long val);
64
65static device_method_t atkbdc_methods[] = {
66 DEVMETHOD(device_probe, atkbdc_probe),
67 DEVMETHOD(device_attach, atkbdc_attach),
27 */
28
29#include "atkbdc.h"
30#include "opt_kbd.h"
31
32#if NATKBDC > 0
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/kernel.h>
37#include <sys/bus.h>
38#include <sys/malloc.h>
39
40#include <dev/kbd/atkbdcreg.h>
41
42#include <isa/isareg.h>
43#include <isa/isavar.h>
44
45MALLOC_DEFINE(M_ATKBDDEV, "atkbddev", "AT Keyboard device");
46
47/* children */
48typedef struct atkbdc_device {
49 int flags; /* configuration flags */
50 int port; /* port number (same as the controller's) */
51 int irq; /* ISA IRQ mask */
52} atkbdc_device_t;
53
54/* kbdc */
55devclass_t atkbdc_devclass;
56
57static int atkbdc_probe(device_t dev);
58static int atkbdc_attach(device_t dev);
59static void atkbdc_print_child(device_t bus, device_t dev);
60static int atkbdc_read_ivar(device_t bus, device_t dev, int index,
61 u_long *val);
62static int atkbdc_write_ivar(device_t bus, device_t dev, int index,
63 u_long val);
64
65static device_method_t atkbdc_methods[] = {
66 DEVMETHOD(device_probe, atkbdc_probe),
67 DEVMETHOD(device_attach, atkbdc_attach),
68 DEVMETHOD(device_suspend, bus_generic_suspend),
69 DEVMETHOD(device_resume, bus_generic_resume),
68
69 DEVMETHOD(bus_print_child, atkbdc_print_child),
70 DEVMETHOD(bus_read_ivar, atkbdc_read_ivar),
71 DEVMETHOD(bus_write_ivar, atkbdc_write_ivar),
72 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
73 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
74 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
75 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
76 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
77 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
78
79 { 0, 0 }
80};
81
82static driver_t atkbdc_driver = {
83 ATKBDC_DRIVER_NAME,
84 atkbdc_methods,
85 sizeof(atkbdc_softc_t *),
86};
87
88static int
89atkbdc_probe(device_t dev)
90{
70
71 DEVMETHOD(bus_print_child, atkbdc_print_child),
72 DEVMETHOD(bus_read_ivar, atkbdc_read_ivar),
73 DEVMETHOD(bus_write_ivar, atkbdc_write_ivar),
74 DEVMETHOD(bus_alloc_resource, bus_generic_alloc_resource),
75 DEVMETHOD(bus_release_resource, bus_generic_release_resource),
76 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
77 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
78 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
79 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
80
81 { 0, 0 }
82};
83
84static driver_t atkbdc_driver = {
85 ATKBDC_DRIVER_NAME,
86 atkbdc_methods,
87 sizeof(atkbdc_softc_t *),
88};
89
90static int
91atkbdc_probe(device_t dev)
92{
91 atkbdc_softc_t *sc;
92 int unit;
93 int error;
94
93 int error;
94
95 unit = device_get_unit(dev);
96 sc = *(atkbdc_softc_t **)device_get_softc(dev);
97 if (sc == NULL) {
98 /*
99 * We have to maintain two copies of the kbdc_softc struct,
100 * as the low-level console needs to have access to the
101 * keyboard controller before kbdc is probed and attached.
102 * kbdc_soft[] contains the default entry for that purpose.
103 * See atkbdc.c. XXX
104 */
105 sc = atkbdc_get_softc(unit);
106 if (sc == NULL)
107 return ENOMEM;
108 }
109
110 device_set_desc(dev, "keyboard controller (i8042)");
95 device_set_desc(dev, "keyboard controller (i8042)");
111
112 error = atkbdc_probe_unit(sc, unit, isa_get_port(dev));
96 error = atkbdc_probe_unit(device_get_unit(dev), isa_get_port(dev));
113 if (error == 0)
97 if (error == 0)
114 *(atkbdc_softc_t **)device_get_softc(dev) = sc;
115
98 isa_set_portsize(dev, IO_KBDSIZE);
116 return error;
117}
118
119static void
120atkbdc_add_device(device_t dev, const char *name, int unit)
121{
122 atkbdc_softc_t *sc = *(atkbdc_softc_t **)device_get_softc(dev);
123 atkbdc_device_t *kdev;
124 device_t child;
125 int t;
126
127 kdev = malloc(sizeof(struct atkbdc_device), M_ATKBDDEV, M_NOWAIT);
128 if (!kdev)
129 return;
130 bzero(kdev, sizeof *kdev);
131
132 kdev->port = sc->port;
133
134 if (resource_int_value(name, unit, "irq", &t) == 0)
135 kdev->irq = t;
136 else
137 kdev->irq = -1;
138
139 if (resource_int_value(name, unit, "flags", &t) == 0)
140 kdev->flags = t;
141 else
142 kdev->flags = 0;
143
144 child = device_add_child(dev, name, unit, kdev);
145}
146
147static int
148atkbdc_attach(device_t dev)
149{
150 atkbdc_softc_t *sc;
99 return error;
100}
101
102static void
103atkbdc_add_device(device_t dev, const char *name, int unit)
104{
105 atkbdc_softc_t *sc = *(atkbdc_softc_t **)device_get_softc(dev);
106 atkbdc_device_t *kdev;
107 device_t child;
108 int t;
109
110 kdev = malloc(sizeof(struct atkbdc_device), M_ATKBDDEV, M_NOWAIT);
111 if (!kdev)
112 return;
113 bzero(kdev, sizeof *kdev);
114
115 kdev->port = sc->port;
116
117 if (resource_int_value(name, unit, "irq", &t) == 0)
118 kdev->irq = t;
119 else
120 kdev->irq = -1;
121
122 if (resource_int_value(name, unit, "flags", &t) == 0)
123 kdev->flags = t;
124 else
125 kdev->flags = 0;
126
127 child = device_add_child(dev, name, unit, kdev);
128}
129
130static int
131atkbdc_attach(device_t dev)
132{
133 atkbdc_softc_t *sc;
134 int unit;
135 int error;
151 int i;
152
136 int i;
137
138 unit = device_get_unit(dev);
153 sc = *(atkbdc_softc_t **)device_get_softc(dev);
139 sc = *(atkbdc_softc_t **)device_get_softc(dev);
154 if ((sc == NULL) || (sc->port <= 0))
155 return ENXIO;
140 if (sc == NULL) {
141 /*
142 * We have to maintain two copies of the kbdc_softc struct,
143 * as the low-level console needs to have access to the
144 * keyboard controller before kbdc is probed and attached.
145 * kbdc_soft[] contains the default entry for that purpose.
146 * See atkbdc.c. XXX
147 */
148 sc = atkbdc_get_softc(unit);
149 if (sc == NULL)
150 return ENOMEM;
151 }
156
152
153 error = atkbdc_attach_unit(unit, sc, isa_get_port(dev));
154 if (error)
155 return error;
156 *(atkbdc_softc_t **)device_get_softc(dev) = sc;
157
157 /*
158 * Add all devices configured to be attached to atkbdc0.
159 */
160 for (i = resource_query_string(-1, "at", "atkbdc0");
161 i != -1;
162 i = resource_query_string(i, "at", "atkbdc0")) {
163 atkbdc_add_device(dev, resource_query_name(i),
164 resource_query_unit(i));
165 }
166
167 /*
168 * and atkbdc?
169 */
170 for (i = resource_query_string(-1, "at", "atkbdc");
171 i != -1;
172 i = resource_query_string(i, "at", "atkbdc")) {
173 atkbdc_add_device(dev, resource_query_name(i),
174 resource_query_unit(i));
175 }
176
177 bus_generic_attach(dev);
178
179 return 0;
180}
181
182static void
183atkbdc_print_child(device_t bus, device_t dev)
184{
185 atkbdc_device_t *kbdcdev;
186
187 kbdcdev = (atkbdc_device_t *)device_get_ivars(dev);
188
189 if (kbdcdev->flags != 0)
190 printf(" flags 0x%x", kbdcdev->flags);
191 if (kbdcdev->irq != -1)
192 printf(" irq %d", kbdcdev->irq);
193
194 printf(" on %s%d", device_get_name(bus), device_get_unit(bus));
195}
196
197static int
198atkbdc_read_ivar(device_t bus, device_t dev, int index, u_long *val)
199{
200 atkbdc_device_t *ivar;
201
202 ivar = (atkbdc_device_t *)device_get_ivars(dev);
203 switch (index) {
204 case KBDC_IVAR_PORT:
205 *val = (u_long)ivar->port;
206 break;
207 case KBDC_IVAR_IRQ:
208 *val = (u_long)ivar->irq;
209 break;
210 case KBDC_IVAR_FLAGS:
211 *val = (u_long)ivar->flags;
212 break;
213 default:
214 return ENOENT;
215 }
216 return 0;
217}
218
219static int
220atkbdc_write_ivar(device_t bus, device_t dev, int index, u_long val)
221{
222 atkbdc_device_t *ivar;
223
224 ivar = (atkbdc_device_t *)device_get_ivars(dev);
225 switch (index) {
226 case KBDC_IVAR_PORT:
227 ivar->port = (int)val;
228 break;
229 case KBDC_IVAR_IRQ:
230 ivar->irq = (int)val;
231 break;
232 case KBDC_IVAR_FLAGS:
233 ivar->flags = (int)val;
234 break;
235 default:
236 return ENOENT;
237 }
238 return 0;
239}
240
241DRIVER_MODULE(atkbdc, isa, atkbdc_driver, atkbdc_devclass, 0, 0);
242
243#endif /* NATKBDC > 0 */
158 /*
159 * Add all devices configured to be attached to atkbdc0.
160 */
161 for (i = resource_query_string(-1, "at", "atkbdc0");
162 i != -1;
163 i = resource_query_string(i, "at", "atkbdc0")) {
164 atkbdc_add_device(dev, resource_query_name(i),
165 resource_query_unit(i));
166 }
167
168 /*
169 * and atkbdc?
170 */
171 for (i = resource_query_string(-1, "at", "atkbdc");
172 i != -1;
173 i = resource_query_string(i, "at", "atkbdc")) {
174 atkbdc_add_device(dev, resource_query_name(i),
175 resource_query_unit(i));
176 }
177
178 bus_generic_attach(dev);
179
180 return 0;
181}
182
183static void
184atkbdc_print_child(device_t bus, device_t dev)
185{
186 atkbdc_device_t *kbdcdev;
187
188 kbdcdev = (atkbdc_device_t *)device_get_ivars(dev);
189
190 if (kbdcdev->flags != 0)
191 printf(" flags 0x%x", kbdcdev->flags);
192 if (kbdcdev->irq != -1)
193 printf(" irq %d", kbdcdev->irq);
194
195 printf(" on %s%d", device_get_name(bus), device_get_unit(bus));
196}
197
198static int
199atkbdc_read_ivar(device_t bus, device_t dev, int index, u_long *val)
200{
201 atkbdc_device_t *ivar;
202
203 ivar = (atkbdc_device_t *)device_get_ivars(dev);
204 switch (index) {
205 case KBDC_IVAR_PORT:
206 *val = (u_long)ivar->port;
207 break;
208 case KBDC_IVAR_IRQ:
209 *val = (u_long)ivar->irq;
210 break;
211 case KBDC_IVAR_FLAGS:
212 *val = (u_long)ivar->flags;
213 break;
214 default:
215 return ENOENT;
216 }
217 return 0;
218}
219
220static int
221atkbdc_write_ivar(device_t bus, device_t dev, int index, u_long val)
222{
223 atkbdc_device_t *ivar;
224
225 ivar = (atkbdc_device_t *)device_get_ivars(dev);
226 switch (index) {
227 case KBDC_IVAR_PORT:
228 ivar->port = (int)val;
229 break;
230 case KBDC_IVAR_IRQ:
231 ivar->irq = (int)val;
232 break;
233 case KBDC_IVAR_FLAGS:
234 ivar->flags = (int)val;
235 break;
236 default:
237 return ENOENT;
238 }
239 return 0;
240}
241
242DRIVER_MODULE(atkbdc, isa, atkbdc_driver, atkbdc_devclass, 0, 0);
243
244#endif /* NATKBDC > 0 */