static int atkbdc_probe(device_t dev) { int error; int rid; struct resource *port; /* Check isapnp ids */ if (isa_get_vendorid(dev)) return (ENXIO); device_set_desc(dev, "keyboard controller (i8042)"); rid = 0; port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, IO_KBDSIZE, RF_ACTIVE); if (!port) return ENXIO; error = atkbdc_probe_unit(device_get_unit(dev), rman_get_start(port)); bus_release_resource(dev, SYS_RES_IOPORT, rid, port); return error; }
static int atkbdc_ebus_probe(device_t dev) { struct resource *port0, *port1; u_long count, start; int error, rid; if (strcmp(ofw_bus_get_name(dev), "8042") != 0) return (ENXIO); /* * On AXi and AXmp boards the NS16550 (used to connect keyboard/ * mouse) share their IRQ lines with the i8042. Any IRQ activity * (typically during attach) of the NS16550 used to connect the * keyboard when actually the PS/2 keyboard is selected in OFW * causes interaction with the OBP i8042 driver resulting in a * hang and vice versa. As RS232 keyboards and mice obviously * aren't meant to be used in parallel with PS/2 ones on these * boards don't attach to the i8042 in case the PS/2 keyboard * isn't selected in order to prevent such hangs. * Note that it's not sufficient here to rely on the '8042' node * only showing up when a PS/2 keyboard is actually connected as * the user still might have adjusted the 'keyboard' alias to * point to the RS232 keyboard. */ if ((!strcmp(sparc64_model, "SUNW,UltraAX-MP") || !strcmp(sparc64_model, "SUNW,UltraSPARC-IIi-Engine")) && OF_finddevice("keyboard") != ofw_bus_get_node(dev)) { device_disable(dev); return (ENXIO); } device_set_desc(dev, "Keyboard controller (i8042)"); /* * The '8042' node has two identical 8 addresses wide resources * which are apparently meant to be used one for the keyboard * half and the other one for the mouse half. To simplify matters * we use one for the command/data port resource and the other * one for the status port resource as the atkbdc(4) back-end * expects two struct resource rather than two bus space handles. */ rid = 0; if (bus_get_resource(dev, SYS_RES_MEMORY, rid, &start, &count) != 0) { device_printf(dev, "cannot determine command/data port resource\n"); return (ENXIO); } port0 = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, start, start, 1, RF_ACTIVE); if (port0 == NULL) { device_printf(dev, "cannot allocate command/data port resource\n"); return (ENXIO); } rid = 1; if (bus_get_resource(dev, SYS_RES_MEMORY, rid, &start, &count) != 0) { device_printf(dev, "cannot determine status port resource\n"); error = ENXIO; goto fail_port0; } start += KBD_STATUS_PORT; port1 = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, start, start, 1, RF_ACTIVE); if (port1 == NULL) { device_printf(dev, "cannot allocate status port resource\n"); error = ENXIO; goto fail_port0; } error = atkbdc_probe_unit(device_get_unit(dev), port0, port1); if (error != 0) device_printf(dev, "atkbdc_porbe_unit failed\n"); bus_release_resource(dev, SYS_RES_MEMORY, 1, port1); fail_port0: bus_release_resource(dev, SYS_RES_MEMORY, 0, port0); return (error); }
static int atkbdc_isa_probe(device_t dev) { struct resource *port0; struct resource *port1; u_long start; u_long count; int error; int rid; #if defined(__i386__) || defined(__amd64__) bus_space_tag_t tag; bus_space_handle_t ioh1; volatile int i; register_t flags; #endif /* check PnP IDs */ if (ISA_PNP_PROBE(device_get_parent(dev), dev, atkbdc_ids) == ENXIO) return ENXIO; device_set_desc(dev, "Keyboard controller (i8042)"); /* * Adjust I/O port resources. * The AT keyboard controller uses two ports (a command/data port * 0x60 and a status port 0x64), which may be given to us in * one resource (0x60 through 0x64) or as two separate resources * (0x60 and 0x64). Some brain-damaged ACPI BIOS has reversed * command/data port and status port. Furthermore, /boot/device.hints * may contain just one port, 0x60. We shall adjust resource settings * so that these two ports are available as two separate resources * in correct order. */ device_quiet(dev); rid = 0; if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count) != 0) return ENXIO; if (start == IO_KBD + KBD_STATUS_PORT) { start = IO_KBD; count++; } if (count > 1) /* adjust the count and/or start port */ bus_set_resource(dev, SYS_RES_IOPORT, rid, start, 1); port0 = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); if (port0 == NULL) return ENXIO; rid = 1; if (bus_get_resource(dev, SYS_RES_IOPORT, rid, NULL, NULL) != 0) bus_set_resource(dev, SYS_RES_IOPORT, 1, start + KBD_STATUS_PORT, 1); port1 = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE); if (port1 == NULL) { bus_release_resource(dev, SYS_RES_IOPORT, 0, port0); return ENXIO; } #if defined(__i386__) || defined(__amd64__) /* * Check if we really have AT keyboard controller. Poll status * register until we get "all clear" indication. If no such * indication comes, it probably means that there is no AT * keyboard controller present. Give up in such case. Check relies * on the fact that reading from non-existing in/out port returns * 0xff on i386. May or may not be true on other platforms. */ tag = rman_get_bustag(port0); ioh1 = rman_get_bushandle(port1); flags = intr_disable(); for (i = 0; i != 65535; i++) { if ((bus_space_read_1(tag, ioh1, 0) & 0x2) == 0) break; } intr_restore(flags); if (i == 65535) { bus_release_resource(dev, SYS_RES_IOPORT, 0, port0); bus_release_resource(dev, SYS_RES_IOPORT, 1, port1); if (bootverbose) device_printf(dev, "AT keyboard controller not found\n"); return ENXIO; } #endif device_verbose(dev); error = atkbdc_probe_unit(device_get_unit(dev), port0, port1); bus_release_resource(dev, SYS_RES_IOPORT, 0, port0); bus_release_resource(dev, SYS_RES_IOPORT, 1, port1); return error; }
static int atkbdc_probe(device_t dev) { struct resource *port0; struct resource *port1; int error; int rid; #if defined(__i386__) bus_space_tag_t tag; bus_space_handle_t ioh1; volatile int i; #endif /* check PnP IDs */ if (ISA_PNP_PROBE(device_get_parent(dev), dev, atkbdc_ids) == ENXIO) return ENXIO; device_set_desc(dev, "Keyboard controller (i8042)"); rid = 0; port0 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE); if (port0 == NULL) return ENXIO; /* XXX */ if (bus_get_resource_start(dev, SYS_RES_IOPORT, 1) <= 0) { bus_set_resource(dev, SYS_RES_IOPORT, 1, rman_get_start(port0) + KBD_STATUS_PORT, 1); } rid = 1; port1 = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE); if (port1 == NULL) { bus_release_resource(dev, SYS_RES_IOPORT, 0, port0); return ENXIO; } #if defined(__i386__) /* * Check if we really have AT keyboard controller. Poll status * register until we get "all clear" indication. If no such * indication comes, it probably means that there is no AT * keyboard controller present. Give up in such case. Check relies * on the fact that reading from non-existing in/out port returns * 0xff on i386. May or may not be true on other platforms. */ tag = rman_get_bustag(port0); ioh1 = rman_get_bushandle(port1); for (i = 65536; i != 0; --i) { if ((bus_space_read_1(tag, ioh1, 0) & 0x2) == 0) break; DELAY(16); } if (i == 0) { bus_release_resource(dev, SYS_RES_IOPORT, 0, port0); bus_release_resource(dev, SYS_RES_IOPORT, 1, port1); return ENXIO; } #endif error = atkbdc_probe_unit(device_get_unit(dev), port0, port1); bus_release_resource(dev, SYS_RES_IOPORT, 0, port0); bus_release_resource(dev, SYS_RES_IOPORT, 1, port1); return error; }