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

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