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

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