You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

eisa.c 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #include "etherboot.h"
  2. #include "dev.h"
  3. #include "io.h"
  4. #include "timer.h"
  5. #include "eisa.h"
  6. /*
  7. * Ensure that there is sufficient space in the shared dev_bus
  8. * structure for a struct pci_device.
  9. *
  10. */
  11. DEV_BUS( struct eisa_device, eisa_dev );
  12. static char eisa_magic[0]; /* guaranteed unique symbol */
  13. /*
  14. * Fill in parameters for an EISA device based on slot number
  15. *
  16. * Return 1 if device present, 0 otherwise
  17. *
  18. */
  19. static int fill_eisa_device ( struct eisa_device *eisa ) {
  20. uint8_t present;
  21. /* Set ioaddr */
  22. eisa->ioaddr = EISA_SLOT_BASE ( eisa->slot );
  23. /* Test for board present */
  24. outb ( 0xff, eisa->ioaddr + EISA_MFG_ID_HI );
  25. present = inb ( eisa->ioaddr + EISA_MFG_ID_HI );
  26. if ( present & 0x80 ) {
  27. /* No board present */
  28. return 0;
  29. }
  30. /* Read mfg and product IDs. Yes, the resulting uint16_ts
  31. * will be upside-down. This appears to be by design.
  32. */
  33. eisa->mfg_id = ( inb ( eisa->ioaddr + EISA_MFG_ID_LO ) << 8 )
  34. + present;
  35. eisa->prod_id = ( inb ( eisa->ioaddr + EISA_PROD_ID_LO ) << 8 )
  36. + inb ( eisa->ioaddr + EISA_PROD_ID_HI );
  37. DBG ( "EISA slot %d (base %#hx) ID %hx:%hx (\"%s\")\n",
  38. eisa->slot, eisa->ioaddr, eisa->mfg_id, eisa->prod_id,
  39. isa_id_string ( eisa->mfg_id, eisa->prod_id ) );
  40. return 1;
  41. }
  42. /*
  43. * Find an EISA device matching the specified driver
  44. *
  45. */
  46. int find_eisa_device ( struct eisa_device *eisa, struct eisa_driver *driver ) {
  47. unsigned int i;
  48. /* Initialise struct eisa if it's the first time it's been used. */
  49. if ( eisa->magic != eisa_magic ) {
  50. memset ( eisa, 0, sizeof ( *eisa ) );
  51. eisa->magic = eisa_magic;
  52. eisa->slot = EISA_MIN_SLOT;
  53. }
  54. /* Iterate through all possible EISA slots, starting where we
  55. * left off.
  56. */
  57. for ( ; eisa->slot <= EISA_MAX_SLOT ; eisa->slot++ ) {
  58. /* If we've already used this device, skip it */
  59. if ( eisa->already_tried ) {
  60. eisa->already_tried = 0;
  61. continue;
  62. }
  63. /* Fill in device parameters */
  64. if ( ! fill_eisa_device ( eisa ) ) {
  65. continue;
  66. }
  67. /* Compare against driver's ID list */
  68. for ( i = 0 ; i < driver->id_count ; i++ ) {
  69. struct eisa_id *id = &driver->ids[i];
  70. if ( ( eisa->mfg_id == id->mfg_id ) &&
  71. ( ISA_PROD_ID ( eisa->prod_id ) ==
  72. ISA_PROD_ID ( id->prod_id ) ) ) {
  73. DBG ( "Device %s (driver %s) matches ID %s\n",
  74. id->name, driver->name,
  75. isa_id_string ( eisa->mfg_id,
  76. eisa->prod_id ) );
  77. eisa->name = id->name;
  78. eisa->already_tried = 1;
  79. return 1;
  80. }
  81. }
  82. }
  83. /* No device found */
  84. eisa->slot = EISA_MIN_SLOT;
  85. return 0;
  86. }
  87. /*
  88. * Find the next EISA device that can be used to boot using the
  89. * specified driver.
  90. *
  91. */
  92. int find_eisa_boot_device ( struct dev *dev, struct eisa_driver *driver ) {
  93. struct eisa_device *eisa = ( struct eisa_device * )dev->bus;
  94. if ( ! find_eisa_device ( eisa, driver ) )
  95. return 0;
  96. dev->name = eisa->name;
  97. dev->devid.bus_type = ISA_BUS_TYPE;
  98. dev->devid.vendor_id = eisa->mfg_id;
  99. dev->devid.device_id = eisa->prod_id;
  100. return 1;
  101. }
  102. /*
  103. * Reset and enable an EISA device
  104. *
  105. */
  106. void enable_eisa_device ( struct eisa_device *eisa ) {
  107. /* Set reset line high for 1000 µs. Spec says 500 µs, but
  108. * this doesn't work for all cards, so we are conservative.
  109. */
  110. outb ( EISA_CMD_RESET, eisa->ioaddr + EISA_GLOBAL_CONFIG );
  111. udelay ( 1000 ); /* Must wait 800 */
  112. /* Set reset low and write a 1 to ENABLE. Delay again, in
  113. * case the card takes a while to wake up.
  114. */
  115. outb ( EISA_CMD_ENABLE, eisa->ioaddr + EISA_GLOBAL_CONFIG );
  116. udelay ( 1000 ); /* Must wait 800 */
  117. }