atkbdc_isa.c (212413) | atkbdc_isa.c (216492) |
---|---|
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 212413 2010-09-10 11:19:03Z avg $"); | 28__FBSDID("$FreeBSD: head/sys/dev/atkbdc/atkbdc_isa.c 216492 2010-12-16 17:14:37Z jhb $"); |
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> --- 7 unchanged lines hidden (view full) --- 44 45#include <isa/isareg.h> 46#include <isa/isavar.h> 47 48static int atkbdc_isa_probe(device_t dev); 49static int atkbdc_isa_attach(device_t dev); 50static device_t atkbdc_isa_add_child(device_t bus, u_int order, const char *name, 51 int unit); | 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> --- 7 unchanged lines hidden (view full) --- 44 45#include <isa/isareg.h> 46#include <isa/isavar.h> 47 48static int atkbdc_isa_probe(device_t dev); 49static int atkbdc_isa_attach(device_t dev); 50static device_t atkbdc_isa_add_child(device_t bus, u_int order, const char *name, 51 int unit); |
52static struct resource *atkbdc_isa_alloc_resource(device_t dev, device_t child, 53 int type, int *rid, u_long start, u_long end, 54 u_long count, u_int flags); 55static int atkbdc_isa_release_resource(device_t dev, device_t child, 56 int type, int rid, struct resource *r); |
|
52 53static device_method_t atkbdc_isa_methods[] = { 54 DEVMETHOD(device_probe, atkbdc_isa_probe), 55 DEVMETHOD(device_attach, atkbdc_isa_attach), 56 DEVMETHOD(device_suspend, bus_generic_suspend), 57 DEVMETHOD(device_resume, bus_generic_resume), 58 59 DEVMETHOD(bus_add_child, atkbdc_isa_add_child), 60 DEVMETHOD(bus_print_child, atkbdc_print_child), 61 DEVMETHOD(bus_read_ivar, atkbdc_read_ivar), 62 DEVMETHOD(bus_write_ivar, atkbdc_write_ivar), 63 DEVMETHOD(bus_get_resource_list,atkbdc_get_resource_list), | 57 58static device_method_t atkbdc_isa_methods[] = { 59 DEVMETHOD(device_probe, atkbdc_isa_probe), 60 DEVMETHOD(device_attach, atkbdc_isa_attach), 61 DEVMETHOD(device_suspend, bus_generic_suspend), 62 DEVMETHOD(device_resume, bus_generic_resume), 63 64 DEVMETHOD(bus_add_child, atkbdc_isa_add_child), 65 DEVMETHOD(bus_print_child, atkbdc_print_child), 66 DEVMETHOD(bus_read_ivar, atkbdc_read_ivar), 67 DEVMETHOD(bus_write_ivar, atkbdc_write_ivar), 68 DEVMETHOD(bus_get_resource_list,atkbdc_get_resource_list), |
64 DEVMETHOD(bus_alloc_resource, bus_generic_rl_alloc_resource), 65 DEVMETHOD(bus_release_resource, bus_generic_rl_release_resource), | 69 DEVMETHOD(bus_alloc_resource, atkbdc_isa_alloc_resource), 70 DEVMETHOD(bus_release_resource, atkbdc_isa_release_resource), |
66 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 67 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 68 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource), 69 DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource), 70 DEVMETHOD(bus_delete_resource, bus_generic_rl_delete_resource), 71 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), 72 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 73 --- 91 unchanged lines hidden (view full) --- 165 device_printf(dev, "AT keyboard controller not found\n"); 166 return ENXIO; 167 } 168#endif 169 170 device_verbose(dev); 171 172 error = atkbdc_probe_unit(device_get_unit(dev), port0, port1); | 71 DEVMETHOD(bus_activate_resource, bus_generic_activate_resource), 72 DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource), 73 DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource), 74 DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource), 75 DEVMETHOD(bus_delete_resource, bus_generic_rl_delete_resource), 76 DEVMETHOD(bus_setup_intr, bus_generic_setup_intr), 77 DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr), 78 --- 91 unchanged lines hidden (view full) --- 170 device_printf(dev, "AT keyboard controller not found\n"); 171 return ENXIO; 172 } 173#endif 174 175 device_verbose(dev); 176 177 error = atkbdc_probe_unit(device_get_unit(dev), port0, port1); |
173 if (error == 0) 174 bus_generic_probe(dev); | |
175 176 bus_release_resource(dev, SYS_RES_IOPORT, 0, port0); 177 bus_release_resource(dev, SYS_RES_IOPORT, 1, port1); 178 179 return error; 180} 181 182static int --- 28 unchanged lines hidden (view full) --- 211 rid = 1; 212 sc->port1 = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, 213 RF_ACTIVE); 214 if (sc->port1 == NULL) { 215 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0); 216 return ENXIO; 217 } 218 | 178 179 bus_release_resource(dev, SYS_RES_IOPORT, 0, port0); 180 bus_release_resource(dev, SYS_RES_IOPORT, 1, port1); 181 182 return error; 183} 184 185static int --- 28 unchanged lines hidden (view full) --- 214 rid = 1; 215 sc->port1 = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, 216 RF_ACTIVE); 217 if (sc->port1 == NULL) { 218 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0); 219 return ENXIO; 220 } 221 |
222 /* 223 * If the device is not created by the PnP BIOS or ACPI, then 224 * the hint for the IRQ is on the child atkbd device, not the 225 * keyboard controller, so this can fail. 226 */ 227 rid = 0; 228 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE); 229 |
|
219 error = atkbdc_attach_unit(unit, sc, sc->port0, sc->port1); 220 if (error) { 221 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0); 222 bus_release_resource(dev, SYS_RES_IOPORT, 1, sc->port1); | 230 error = atkbdc_attach_unit(unit, sc, sc->port0, sc->port1); 231 if (error) { 232 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->port0); 233 bus_release_resource(dev, SYS_RES_IOPORT, 1, sc->port1); |
234 if (sc->irq != NULL) 235 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq); |
|
223 return error; 224 } 225 *(atkbdc_softc_t **)device_get_softc(dev) = sc; 226 | 236 return error; 237 } 238 *(atkbdc_softc_t **)device_get_softc(dev) = sc; 239 |
240 bus_generic_probe(dev); |
|
227 bus_generic_attach(dev); 228 229 return 0; 230} 231 232static device_t 233atkbdc_isa_add_child(device_t bus, u_int order, const char *name, int unit) 234{ 235 atkbdc_device_t *ivar; | 241 bus_generic_attach(dev); 242 243 return 0; 244} 245 246static device_t 247atkbdc_isa_add_child(device_t bus, u_int order, const char *name, int unit) 248{ 249 atkbdc_device_t *ivar; |
250 atkbdc_softc_t *sc; |
|
236 device_t child; 237 int t; 238 | 251 device_t child; 252 int t; 253 |
254 sc = *(atkbdc_softc_t **)device_get_softc(bus); |
|
239 ivar = malloc(sizeof(struct atkbdc_device), M_ATKBDDEV, 240 M_NOWAIT | M_ZERO); 241 if (!ivar) 242 return NULL; 243 244 child = device_add_child_ordered(bus, order, name, unit); 245 if (child == NULL) { 246 free(ivar, M_ATKBDDEV); 247 return child; 248 } 249 250 resource_list_init(&ivar->resources); 251 ivar->rid = order; 252 253 /* | 255 ivar = malloc(sizeof(struct atkbdc_device), M_ATKBDDEV, 256 M_NOWAIT | M_ZERO); 257 if (!ivar) 258 return NULL; 259 260 child = device_add_child_ordered(bus, order, name, unit); 261 if (child == NULL) { 262 free(ivar, M_ATKBDDEV); 263 return child; 264 } 265 266 resource_list_init(&ivar->resources); 267 ivar->rid = order; 268 269 /* |
254 * If the device is not created by the PnP BIOS or ACPI, 255 * refer to device hints for IRQ. | 270 * If the device is not created by the PnP BIOS or ACPI, refer 271 * to device hints for IRQ. We always populate the resource 272 * list entry so we can use a standard bus_get_resource() 273 * method. |
256 */ | 274 */ |
257 if (ISA_PNP_PROBE(device_get_parent(bus), bus, atkbdc_ids) != 0) { | 275 if (sc->irq == NULL) { |
258 if (resource_int_value(name, unit, "irq", &t) != 0) 259 t = -1; | 276 if (resource_int_value(name, unit, "irq", &t) != 0) 277 t = -1; |
260 } else { 261 t = bus_get_resource_start(bus, SYS_RES_IRQ, ivar->rid); 262 } | 278 } else 279 t = rman_get_start(sc->irq); |
263 if (t > 0) 264 resource_list_add(&ivar->resources, SYS_RES_IRQ, ivar->rid, 265 t, t, 1); 266 267 if (resource_disabled(name, unit)) 268 device_disable(child); 269 270 device_set_ivars(child, ivar); 271 272 return child; 273} 274 | 280 if (t > 0) 281 resource_list_add(&ivar->resources, SYS_RES_IRQ, ivar->rid, 282 t, t, 1); 283 284 if (resource_disabled(name, unit)) 285 device_disable(child); 286 287 device_set_ivars(child, ivar); 288 289 return child; 290} 291 |
292struct resource * 293atkbdc_isa_alloc_resource(device_t dev, device_t child, int type, int *rid, 294 u_long start, u_long end, u_long count, u_int flags) 295{ 296 atkbdc_softc_t *sc; 297 298 sc = *(atkbdc_softc_t **)device_get_softc(dev); 299 if (type == SYS_RES_IRQ && *rid == KBDC_RID_KBD && sc->irq != NULL) 300 return (sc->irq); 301 return (bus_generic_rl_alloc_resource(dev, child, type, rid, start, 302 end, count, flags)); 303} 304 305static int 306atkbdc_isa_release_resource(device_t dev, device_t child, int type, int rid, 307 struct resource *r) 308{ 309 atkbdc_softc_t *sc; 310 311 sc = *(atkbdc_softc_t **)device_get_softc(dev); 312 if (type == SYS_RES_IRQ && rid == KBDC_RID_KBD && r == sc->irq) 313 return (0); 314 return (bus_generic_rl_release_resource(dev, child, type, rid, r)); 315} 316 |
|
275DRIVER_MODULE(atkbdc, isa, atkbdc_isa_driver, atkbdc_devclass, 0, 0); 276DRIVER_MODULE(atkbdc, acpi, atkbdc_isa_driver, atkbdc_devclass, 0, 0); | 317DRIVER_MODULE(atkbdc, isa, atkbdc_isa_driver, atkbdc_devclass, 0, 0); 318DRIVER_MODULE(atkbdc, acpi, atkbdc_isa_driver, atkbdc_devclass, 0, 0); |