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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #include "etherboot.h"
  2. #include "dev.h"
  3. #include "io.h"
  4. #include "timer.h"
  5. #include "eisa.h"
  6. #define DEBUG_EISA
  7. #undef DBG
  8. #ifdef DEBUG_EISA
  9. #define DBG(...) printf ( __VA_ARGS__ )
  10. #else
  11. #define DBG(...)
  12. #endif
  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. * Obtain a struct eisa * from a struct dev *
  44. *
  45. * If dev has not previously been used for an EISA device scan, blank
  46. * out dev.eisa
  47. */
  48. struct eisa_device * eisa_device ( struct dev *dev ) {
  49. struct eisa_device *eisa = &dev->eisa;
  50. if ( dev->devid.bus_type != EISA_BUS_TYPE ) {
  51. memset ( eisa, 0, sizeof ( *eisa ) );
  52. dev->devid.bus_type = EISA_BUS_TYPE;
  53. eisa->slot = EISA_MIN_SLOT;
  54. }
  55. eisa->dev = dev;
  56. return eisa;
  57. }
  58. /*
  59. * Find an EISA device matching the specified driver
  60. *
  61. */
  62. int find_eisa_device ( struct eisa_device *eisa, struct eisa_driver *driver ) {
  63. unsigned int i;
  64. /* Iterate through all possible EISA slots, starting where we
  65. * left off/
  66. */
  67. for ( ; eisa->slot <= EISA_MAX_SLOT ; eisa->slot++ ) {
  68. /* If we've already used this device, skip it */
  69. if ( eisa->already_tried ) {
  70. eisa->already_tried = 0;
  71. continue;
  72. }
  73. /* Fill in device parameters */
  74. if ( ! fill_eisa_device ( eisa ) ) {
  75. continue;
  76. }
  77. /* Compare against driver's ID list */
  78. for ( i = 0 ; i < driver->id_count ; i++ ) {
  79. struct eisa_id *id = &driver->ids[i];
  80. if ( ( eisa->mfg_id == id->mfg_id ) &&
  81. ( ISA_PROD_ID ( eisa->prod_id ) ==
  82. ISA_PROD_ID ( id->prod_id ) ) ) {
  83. DBG ( "Device %s (driver %s) matches ID %s\n",
  84. id->name, driver->name,
  85. isa_id_string ( eisa->mfg_id,
  86. eisa->prod_id ) );
  87. if ( eisa->dev ) {
  88. eisa->dev->name = driver->name;
  89. eisa->dev->devid.vendor_id
  90. = eisa->mfg_id;
  91. eisa->dev->devid.device_id
  92. = eisa->prod_id;
  93. }
  94. eisa->already_tried = 1;
  95. return 1;
  96. }
  97. }
  98. }
  99. /* No device found */
  100. eisa->slot = EISA_MIN_SLOT;
  101. return 0;
  102. }
  103. /*
  104. * Reset and enable an EISA device
  105. *
  106. */
  107. void enable_eisa_device ( struct eisa_device *eisa ) {
  108. /* Set reset line high for 1000 µs. Spec says 500 µs, but
  109. * this doesn't work for all cards, so we are conservative.
  110. */
  111. outb ( EISA_CMD_RESET, eisa->ioaddr + EISA_GLOBAL_CONFIG );
  112. udelay ( 1000 ); /* Must wait 800 */
  113. /* Set reset low and write a 1 to ENABLE. Delay again, in
  114. * case the card takes a while to wake up.
  115. */
  116. outb ( EISA_CMD_ENABLE, eisa->ioaddr + EISA_GLOBAL_CONFIG );
  117. udelay ( 1000 ); /* Must wait 800 */
  118. }