Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int
- atkbdc_isa_probe(device_t dev)
- {
- printf("Entered isa_probe()\n");
- struct resource *port0;
- struct resource *port1;
- u_long start;
- u_long count;
- int error;
- int rid;
- #if defined(__i386__) || defined(__amd64__)
- printf("Recognised as i386\n");
- 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){
- printf("@ PnP ID check exited with ENXIO\n");
- 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){
- printf("bus_get_resource() returned 0, exited with ENXIO\n");
- 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){
- printf("port0==NULL, exited with ENXIO\n");
- 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) {
- printf("port1==NULL, exited with ENXIO\n");
- 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");
- printf("No AT keyboard controller apparently, exited with ENXIO\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);
- printf("Error is %d\n", error);
- return error;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement