Advertisement
Guest User

Edited isa_probe()

a guest
Jan 20th, 2012
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.23 KB | None | 0 0
  1. static int
  2. atkbdc_isa_probe(device_t dev)
  3. {
  4.     printf("Entered isa_probe()\n");   
  5.     struct resource *port0;
  6.     struct resource *port1;
  7.     u_long      start;
  8.     u_long      count;
  9.     int     error;
  10.     int     rid;
  11. #if defined(__i386__) || defined(__amd64__)
  12.     printf("Recognised as  i386\n");   
  13.     bus_space_tag_t tag;
  14.     bus_space_handle_t ioh1;
  15.     volatile int    i;
  16.     register_t  flags;
  17. #endif
  18.  
  19.     /* check PnP IDs */
  20.     if (ISA_PNP_PROBE(device_get_parent(dev), dev, atkbdc_ids) == ENXIO){
  21.         printf("@ PnP ID check exited with ENXIO\n");  
  22.         return ENXIO;
  23.     }
  24.  
  25.     device_set_desc(dev, "Keyboard controller (i8042)");
  26.  
  27.     /*
  28.      * Adjust I/O port resources.
  29.      * The AT keyboard controller uses two ports (a command/data port
  30.      * 0x60 and a status port 0x64), which may be given to us in
  31.      * one resource (0x60 through 0x64) or as two separate resources
  32.      * (0x60 and 0x64). Some brain-damaged ACPI BIOS has reversed
  33.      * command/data port and status port. Furthermore, /boot/device.hints
  34.      * may contain just one port, 0x60. We shall adjust resource settings
  35.      * so that these two ports are available as two separate resources
  36.      * in correct order.
  37.      */
  38.     device_quiet(dev);
  39.     rid = 0;
  40.     if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count) != 0){
  41.         printf("bus_get_resource() returned 0, exited with ENXIO\n");
  42.         return ENXIO;
  43.     }
  44.     if (start == IO_KBD + KBD_STATUS_PORT) {
  45.         start = IO_KBD;
  46.         count++;
  47.     }
  48.     if (count > 1)  /* adjust the count and/or start port */
  49.         bus_set_resource(dev, SYS_RES_IOPORT, rid, start, 1);
  50.     port0 = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
  51.     if (port0 == NULL){
  52.         printf("port0==NULL, exited with ENXIO\n");
  53.         return ENXIO;
  54.     }
  55.     rid = 1;
  56.     if (bus_get_resource(dev, SYS_RES_IOPORT, rid, NULL, NULL) != 0)
  57.         bus_set_resource(dev, SYS_RES_IOPORT, 1,
  58.                  start + KBD_STATUS_PORT, 1);
  59.     port1 = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
  60.     if (port1 == NULL) {
  61.         printf("port1==NULL, exited with ENXIO\n");    
  62.         bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
  63.         return ENXIO;
  64.     }
  65.  
  66. #if defined(__i386__) || defined(__amd64__)
  67.     /*
  68.      * Check if we really have AT keyboard controller. Poll status
  69.      * register until we get "all clear" indication. If no such
  70.      * indication comes, it probably means that there is no AT
  71.      * keyboard controller present. Give up in such case. Check relies
  72.      * on the fact that reading from non-existing in/out port returns
  73.      * 0xff on i386. May or may not be true on other platforms.
  74.      */
  75.     tag = rman_get_bustag(port0);
  76.     ioh1 = rman_get_bushandle(port1);
  77.     flags = intr_disable();
  78.     for (i = 0; i != 65535; i++) {
  79.         if ((bus_space_read_1(tag, ioh1, 0) & 0x2) == 0)
  80.             break;
  81.     }
  82.     intr_restore(flags);
  83.     if (i == 65535) {
  84.         bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
  85.         bus_release_resource(dev, SYS_RES_IOPORT, 1, port1);
  86.         if (bootverbose)
  87.             device_printf(dev, "AT keyboard controller not found\n");
  88.         printf("No AT keyboard controller apparently, exited with ENXIO\n");       
  89.         return ENXIO;
  90.     }
  91. #endif
  92.  
  93.     device_verbose(dev);
  94.  
  95.     error = atkbdc_probe_unit(device_get_unit(dev), port0, port1);
  96.  
  97.     bus_release_resource(dev, SYS_RES_IOPORT, 0, port0);
  98.     bus_release_resource(dev, SYS_RES_IOPORT, 1, port1);
  99.    
  100.     printf("Error is %d\n", error);
  101.    
  102.     return error;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement