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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #include "string.h"
  2. #include "io.h"
  3. #include "timer.h"
  4. #include "console.h"
  5. #include "dev.h"
  6. #include "eisa.h"
  7. /*
  8. * Increment a bus_loc structure to the next possible EISA location.
  9. * Leave the structure zeroed and return 0 if there are no more valid
  10. * locations.
  11. *
  12. */
  13. static int eisa_next_location ( struct bus_loc *bus_loc ) {
  14. struct eisa_loc *eisa_loc = ( struct eisa_loc * ) bus_loc;
  15. /*
  16. * Ensure that there is sufficient space in the shared bus
  17. * structures for a struct isa_loc and a struct
  18. * isa_dev, as mandated by bus.h.
  19. *
  20. */
  21. BUS_LOC_CHECK ( struct eisa_loc );
  22. BUS_DEV_CHECK ( struct eisa_device );
  23. return ( eisa_loc->slot = ( ++eisa_loc->slot & EISA_MAX_SLOT ) );
  24. }
  25. /*
  26. * Fill in parameters for an EISA device based on slot number
  27. *
  28. * Return 1 if device present, 0 otherwise
  29. *
  30. */
  31. static int eisa_fill_device ( struct bus_dev *bus_dev,
  32. struct bus_loc *bus_loc ) {
  33. struct eisa_loc *eisa_loc = ( struct eisa_loc * ) bus_loc;
  34. struct eisa_device *eisa = ( struct eisa_device * ) bus_dev;
  35. uint8_t present;
  36. /* Copy slot number to struct eisa, set default values */
  37. eisa->slot = eisa_loc->slot;
  38. eisa->name = "?";
  39. /* Slot 0 is never valid */
  40. if ( ! eisa->slot )
  41. return 0;
  42. /* Set ioaddr */
  43. eisa->ioaddr = EISA_SLOT_BASE ( eisa->slot );
  44. /* Test for board present */
  45. outb ( 0xff, eisa->ioaddr + EISA_MFG_ID_HI );
  46. present = inb ( eisa->ioaddr + EISA_MFG_ID_HI );
  47. if ( present & 0x80 ) {
  48. /* No board present */
  49. return 0;
  50. }
  51. /* Read mfg and product IDs. Yes, the resulting uint16_ts
  52. * will be upside-down. This appears to be by design.
  53. */
  54. eisa->mfg_id = ( inb ( eisa->ioaddr + EISA_MFG_ID_LO ) << 8 )
  55. + present;
  56. eisa->prod_id = ( inb ( eisa->ioaddr + EISA_PROD_ID_LO ) << 8 )
  57. + inb ( eisa->ioaddr + EISA_PROD_ID_HI );
  58. DBG ( "EISA found slot %hhx (base %#hx) ID %hx:%hx (\"%s\")\n",
  59. eisa->slot, eisa->ioaddr, eisa->mfg_id, eisa->prod_id,
  60. isa_id_string ( eisa->mfg_id, eisa->prod_id ) );
  61. return 1;
  62. }
  63. /*
  64. * Test whether or not a driver is capable of driving the device.
  65. *
  66. */
  67. static int eisa_check_driver ( struct bus_dev *bus_dev,
  68. struct device_driver *device_driver ) {
  69. struct eisa_device *eisa = ( struct eisa_device * ) bus_dev;
  70. struct eisa_driver *driver
  71. = ( struct eisa_driver * ) device_driver->bus_driver_info;
  72. unsigned int i;
  73. /* Compare against driver's ID list */
  74. for ( i = 0 ; i < driver->id_count ; i++ ) {
  75. struct eisa_id *id = &driver->ids[i];
  76. if ( ( eisa->mfg_id == id->mfg_id ) &&
  77. ( ISA_PROD_ID ( eisa->prod_id ) ==
  78. ISA_PROD_ID ( id->prod_id ) ) ) {
  79. DBG ( "EISA found ID %hx:%hx (\"%s\") "
  80. "(device %s) matching driver %s\n",
  81. eisa->mfg_id, eisa->prod_id,
  82. isa_id_string ( eisa->mfg_id,
  83. eisa->prod_id ),
  84. id->name, driver->name );
  85. eisa->name = id->name;
  86. return 1;
  87. }
  88. }
  89. /* No device found */
  90. return 0;
  91. }
  92. /*
  93. * Describe an EISA device
  94. *
  95. */
  96. static char * eisa_describe_device ( struct bus_dev *bus_dev ) {
  97. struct eisa_device *eisa = ( struct eisa_device * ) bus_dev;
  98. static char eisa_description[] = "EISA 00";
  99. sprintf ( eisa_description + 5, "%hhx", eisa->slot );
  100. return eisa_description;
  101. }
  102. /*
  103. * Name an EISA device
  104. *
  105. */
  106. static const char * eisa_name_device ( struct bus_dev *bus_dev ) {
  107. struct eisa_device *eisa = ( struct eisa_device * ) bus_dev;
  108. return eisa->name;
  109. }
  110. /*
  111. * EISA bus operations table
  112. *
  113. */
  114. struct bus_driver eisa_driver __bus_driver = {
  115. .name = "EISA",
  116. .next_location = eisa_next_location,
  117. .fill_device = eisa_fill_device,
  118. .check_driver = eisa_check_driver,
  119. .describe_device = eisa_describe_device,
  120. .name_device = eisa_name_device,
  121. };
  122. /*
  123. * Fill in a nic structure
  124. *
  125. */
  126. void eisa_fill_nic ( struct nic *nic, struct eisa_device *eisa ) {
  127. /* Fill in ioaddr and irqno */
  128. nic->ioaddr = eisa->ioaddr;
  129. nic->irqno = 0;
  130. /* Fill in DHCP device ID structure */
  131. nic->dhcp_dev_id.bus_type = ISA_BUS_TYPE;
  132. nic->dhcp_dev_id.vendor_id = htons ( eisa->mfg_id );
  133. nic->dhcp_dev_id.device_id = htons ( eisa->prod_id );
  134. }
  135. /*
  136. * Reset and enable/disable an EISA device
  137. *
  138. */
  139. void eisa_device_enabled ( struct eisa_device *eisa, int enabled ) {
  140. /* Set reset line high for 1000 µs. Spec says 500 µs, but
  141. * this doesn't work for all cards, so we are conservative.
  142. */
  143. outb ( EISA_CMD_RESET, eisa->ioaddr + EISA_GLOBAL_CONFIG );
  144. udelay ( 1000 ); /* Must wait 800 */
  145. /* Set reset low and write a 1 to ENABLE. Delay again, in
  146. * case the card takes a while to wake up.
  147. */
  148. outb ( enabled ? EISA_CMD_ENABLE : 0,
  149. eisa->ioaddr + EISA_GLOBAL_CONFIG );
  150. udelay ( 1000 ); /* Must wait 800 */
  151. DBG ( "EISA %s device %hhx\n", ( enabled ? "enabled" : "disabled" ),
  152. eisa->slot );
  153. }