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 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 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 27#include <sys/cdefs.h>
|
28__FBSDID("$FreeBSD: head/sys/dev/atkbdc/atkbdc_isa.c 147271 2005-06-10 20:56:38Z marius $");
| 28__FBSDID("$FreeBSD: head/sys/dev/atkbdc/atkbdc_isa.c 158041 2006-04-26 06:05:16Z sobomax $");
|
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/atkbdc/atkbdc_subr.h> 42#include <dev/atkbdc/atkbdcreg.h> 43 44#include <isa/isareg.h> 45#include <isa/isavar.h> 46 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, 50 int unit); 51 52static device_method_t atkbdc_isa_methods[] = { 53 DEVMETHOD(device_probe, atkbdc_isa_probe), 54 DEVMETHOD(device_attach, atkbdc_isa_attach), 55 DEVMETHOD(device_suspend, bus_generic_suspend), 56 DEVMETHOD(device_resume, bus_generic_resume), 57 58 DEVMETHOD(bus_add_child, atkbdc_isa_add_child), 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), 63 DEVMETHOD(bus_alloc_resource, bus_generic_rl_alloc_resource), 64 DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource), 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 76static driver_t atkbdc_isa_driver = { 77 ATKBDC_DRIVER_NAME, 78 atkbdc_isa_methods, 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 88atkbdc_isa_probe(device_t dev) 89{ 90 struct resource *port0; 91 struct resource *port1; 92 u_long start; 93 u_long count; 94 int error; 95 int rid;
| 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/atkbdc/atkbdc_subr.h> 42#include <dev/atkbdc/atkbdcreg.h> 43 44#include <isa/isareg.h> 45#include <isa/isavar.h> 46 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, 50 int unit); 51 52static device_method_t atkbdc_isa_methods[] = { 53 DEVMETHOD(device_probe, atkbdc_isa_probe), 54 DEVMETHOD(device_attach, atkbdc_isa_attach), 55 DEVMETHOD(device_suspend, bus_generic_suspend), 56 DEVMETHOD(device_resume, bus_generic_resume), 57 58 DEVMETHOD(bus_add_child, atkbdc_isa_add_child), 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), 63 DEVMETHOD(bus_alloc_resource, bus_generic_rl_alloc_resource), 64 DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource), 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 76static driver_t atkbdc_isa_driver = { 77 ATKBDC_DRIVER_NAME, 78 atkbdc_isa_methods, 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 88atkbdc_isa_probe(device_t dev) 89{ 90 struct resource *port0; 91 struct resource *port1; 92 u_long start; 93 u_long count; 94 int error; 95 int rid;
|
| 96#if defined(__i386__) 97 bus_space_tag_t tag; 98 bus_space_handle_t ioh1; 99 volatile int i; 100 register_t flags; 101#endif
|
96 97 /* check PnP IDs */ 98 if (ISA_PNP_PROBE(device_get_parent(dev), dev, atkbdc_ids) == ENXIO) 99 return ENXIO; 100 101 device_set_desc(dev, "Keyboard controller (i8042)"); 102 103 /* 104 * Adjust I/O port resources. 105 * The AT keyboard controller uses two ports (a command/data port 106 * 0x60 and a status port 0x64), which may be given to us in 107 * one resource (0x60 through 0x64) or as two separate resources 108 * (0x60 and 0x64). Furthermore, /boot/device.hints may contain 109 * just one port, 0x60. We shall adjust resource settings 110 * so that these two ports are available as two separate resources. 111 */ 112 device_quiet(dev); 113 rid = 0; 114 if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count) != 0) 115 return ENXIO; 116 if (count > 1) /* adjust the count */ 117 bus_set_resource(dev, SYS_RES_IOPORT, rid, start, 1); 118 port0 = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); 119 if (port0 == NULL) 120 return ENXIO; 121 rid = 1; 122 if (bus_get_resource(dev, SYS_RES_IOPORT, rid, NULL, NULL) != 0) 123 bus_set_resource(dev, SYS_RES_IOPORT, 1, 124 start + KBD_STATUS_PORT, 1); 125 port1 = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); 126 if (port1 == NULL) { 127 bus_release_resource(dev, SYS_RES_IOPORT, 0, port0); 128 return ENXIO; 129 }
| 102 103 /* check PnP IDs */ 104 if (ISA_PNP_PROBE(device_get_parent(dev), dev, atkbdc_ids) == ENXIO) 105 return ENXIO; 106 107 device_set_desc(dev, "Keyboard controller (i8042)"); 108 109 /* 110 * Adjust I/O port resources. 111 * The AT keyboard controller uses two ports (a command/data port 112 * 0x60 and a status port 0x64), which may be given to us in 113 * one resource (0x60 through 0x64) or as two separate resources 114 * (0x60 and 0x64). Furthermore, /boot/device.hints may contain 115 * just one port, 0x60. We shall adjust resource settings 116 * so that these two ports are available as two separate resources. 117 */ 118 device_quiet(dev); 119 rid = 0; 120 if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count) != 0) 121 return ENXIO; 122 if (count > 1) /* adjust the count */ 123 bus_set_resource(dev, SYS_RES_IOPORT, rid, start, 1); 124 port0 = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); 125 if (port0 == NULL) 126 return ENXIO; 127 rid = 1; 128 if (bus_get_resource(dev, SYS_RES_IOPORT, rid, NULL, NULL) != 0) 129 bus_set_resource(dev, SYS_RES_IOPORT, 1, 130 start + KBD_STATUS_PORT, 1); 131 port1 = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); 132 if (port1 == NULL) { 133 bus_release_resource(dev, SYS_RES_IOPORT, 0, port0); 134 return ENXIO; 135 }
|
| 136 137#if defined(__i386__) 138 /* 139 * Check if we really have AT keyboard controller. Poll status 140 * register until we get "all clear" indication. If no such 141 * indication comes, it probably means that there is no AT 142 * keyboard controller present. Give up in such case. Check relies 143 * on the fact that reading from non-existing in/out port returns 144 * 0xff on i386. May or may not be true on other platforms. 145 */ 146 tag = rman_get_bustag(port0); 147 ioh1 = rman_get_bushandle(port1); 148 flags = intr_disable(); 149 for (i = 0; i != 65535; i++) { 150 if ((bus_space_read_1(tag, ioh1, 0) & 0x2) == 0) 151 break; 152 } 153 intr_restore(flags); 154 if (i == 65535) { 155 bus_release_resource(dev, SYS_RES_IOPORT, 0, port0); 156 bus_release_resource(dev, SYS_RES_IOPORT, 1, port1); 157 return ENXIO; 158 } 159#endif 160
|
130 device_verbose(dev); 131 132 error = atkbdc_probe_unit(device_get_unit(dev), port0, port1); 133 if (error == 0) 134 bus_generic_probe(dev); 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 143atkbdc_isa_attach(device_t dev) 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 156 * keyboard controller before kbdc is probed and attached. 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 165 rid = 0; 166 sc->port0 = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, 167 RF_ACTIVE); 168 if (sc->port0 == NULL) 169 return ENXIO; 170 rid = 1; 171 sc->port1 = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, 172 RF_ACTIVE); 173 if (sc->port1 == NULL) { 174 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0); 175 return ENXIO; 176 } 177 178 error = atkbdc_attach_unit(unit, sc, sc->port0, sc->port1); 179 if (error) { 180 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0); 181 bus_release_resource(dev, SYS_RES_IOPORT, 1, sc->port1); 182 return error; 183 } 184 *(atkbdc_softc_t **)device_get_softc(dev) = sc; 185 186 bus_generic_attach(dev); 187 188 return 0; 189} 190 191static device_t 192atkbdc_isa_add_child(device_t bus, int order, char *name, int unit) 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) 201 return NULL; 202 203 child = device_add_child_ordered(bus, order, name, unit); 204 if (child == NULL) { 205 free(ivar, M_ATKBDDEV); 206 return child; 207 } 208 209 resource_list_init(&ivar->resources); 210 ivar->rid = order; 211 212 /* 213 * If the device is not created by the PnP BIOS or ACPI, 214 * refer to device hints for IRQ. 215 */ 216 if (ISA_PNP_PROBE(device_get_parent(bus), bus, atkbdc_ids) != 0) { 217 if (resource_int_value(name, unit, "irq", &t) != 0) 218 t = -1; 219 } else { 220 t = bus_get_resource_start(bus, SYS_RES_IRQ, ivar->rid); 221 } 222 if (t > 0) 223 resource_list_add(&ivar->resources, SYS_RES_IRQ, ivar->rid, 224 t, t, 1); 225 226 if (resource_disabled(name, unit)) 227 device_disable(child); 228 229 device_set_ivars(child, ivar); 230 231 return child; 232} 233 234DRIVER_MODULE(atkbdc, isa, atkbdc_isa_driver, atkbdc_devclass, 0, 0); 235DRIVER_MODULE(atkbdc, acpi, atkbdc_isa_driver, atkbdc_devclass, 0, 0);
| 161 device_verbose(dev); 162 163 error = atkbdc_probe_unit(device_get_unit(dev), port0, port1); 164 if (error == 0) 165 bus_generic_probe(dev); 166 167 bus_release_resource(dev, SYS_RES_IOPORT, 0, port0); 168 bus_release_resource(dev, SYS_RES_IOPORT, 1, port1); 169 170 return error; 171} 172 173static int 174atkbdc_isa_attach(device_t dev) 175{ 176 atkbdc_softc_t *sc; 177 int unit; 178 int error; 179 int rid; 180 181 unit = device_get_unit(dev); 182 sc = *(atkbdc_softc_t **)device_get_softc(dev); 183 if (sc == NULL) { 184 /* 185 * We have to maintain two copies of the kbdc_softc struct, 186 * as the low-level console needs to have access to the 187 * keyboard controller before kbdc is probed and attached. 188 * kbdc_soft[] contains the default entry for that purpose. 189 * See atkbdc.c. XXX 190 */ 191 sc = atkbdc_get_softc(unit); 192 if (sc == NULL) 193 return ENOMEM; 194 } 195 196 rid = 0; 197 sc->port0 = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, 198 RF_ACTIVE); 199 if (sc->port0 == NULL) 200 return ENXIO; 201 rid = 1; 202 sc->port1 = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, 203 RF_ACTIVE); 204 if (sc->port1 == NULL) { 205 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0); 206 return ENXIO; 207 } 208 209 error = atkbdc_attach_unit(unit, sc, sc->port0, sc->port1); 210 if (error) { 211 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0); 212 bus_release_resource(dev, SYS_RES_IOPORT, 1, sc->port1); 213 return error; 214 } 215 *(atkbdc_softc_t **)device_get_softc(dev) = sc; 216 217 bus_generic_attach(dev); 218 219 return 0; 220} 221 222static device_t 223atkbdc_isa_add_child(device_t bus, int order, char *name, int unit) 224{ 225 atkbdc_device_t *ivar; 226 device_t child; 227 int t; 228 229 ivar = malloc(sizeof(struct atkbdc_device), M_ATKBDDEV, 230 M_NOWAIT | M_ZERO); 231 if (!ivar) 232 return NULL; 233 234 child = device_add_child_ordered(bus, order, name, unit); 235 if (child == NULL) { 236 free(ivar, M_ATKBDDEV); 237 return child; 238 } 239 240 resource_list_init(&ivar->resources); 241 ivar->rid = order; 242 243 /* 244 * If the device is not created by the PnP BIOS or ACPI, 245 * refer to device hints for IRQ. 246 */ 247 if (ISA_PNP_PROBE(device_get_parent(bus), bus, atkbdc_ids) != 0) { 248 if (resource_int_value(name, unit, "irq", &t) != 0) 249 t = -1; 250 } else { 251 t = bus_get_resource_start(bus, SYS_RES_IRQ, ivar->rid); 252 } 253 if (t > 0) 254 resource_list_add(&ivar->resources, SYS_RES_IRQ, ivar->rid, 255 t, t, 1); 256 257 if (resource_disabled(name, unit)) 258 device_disable(child); 259 260 device_set_ivars(child, ivar); 261 262 return child; 263} 264 265DRIVER_MODULE(atkbdc, isa, atkbdc_isa_driver, atkbdc_devclass, 0, 0); 266DRIVER_MODULE(atkbdc, acpi, atkbdc_isa_driver, atkbdc_devclass, 0, 0);
|