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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #include <stdint.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <errno.h>
  6. #include <io.h>
  7. #include <unistd.h>
  8. #include <gpxe/eisa.h>
  9. static struct eisa_driver eisa_drivers[0]
  10. __table_start ( struct eisa_driver, eisa_drivers );
  11. static struct eisa_driver eisa_drivers_end[0]
  12. __table_end ( struct eisa_driver, eisa_drivers );
  13. static void eisabus_remove ( struct root_device *rootdev );
  14. /**
  15. * Reset and enable/disable an EISA device
  16. *
  17. * @v eisa EISA device
  18. * @v enabled 1=enable, 0=disable
  19. */
  20. void eisa_device_enabled ( struct eisa_device *eisa, int enabled ) {
  21. /* Set reset line high for 1000 µs. Spec says 500 µs, but
  22. * this doesn't work for all cards, so we are conservative.
  23. */
  24. outb ( EISA_CMD_RESET, eisa->ioaddr + EISA_GLOBAL_CONFIG );
  25. udelay ( 1000 ); /* Must wait 800 */
  26. /* Set reset low and write a 1 to ENABLE. Delay again, in
  27. * case the card takes a while to wake up.
  28. */
  29. outb ( enabled ? EISA_CMD_ENABLE : 0,
  30. eisa->ioaddr + EISA_GLOBAL_CONFIG );
  31. udelay ( 1000 ); /* Must wait 800 */
  32. DBG ( "EISA %s device %02x\n", ( enabled ? "enabled" : "disabled" ),
  33. eisa->slot );
  34. }
  35. /**
  36. * Probe an EISA device
  37. *
  38. * @v eisa EISA device
  39. * @ret rc Return status code
  40. *
  41. * Searches for a driver for the EISA device. If a driver is found,
  42. * its probe() routine is called.
  43. */
  44. static int eisa_probe ( struct eisa_device *eisa ) {
  45. struct eisa_driver *driver;
  46. struct eisa_device_id *id;
  47. unsigned int i;
  48. int rc;
  49. DBG ( "Adding EISA device %02x (%04x:%04x (\"%s\") io %x)\n",
  50. eisa->slot, eisa->vendor_id, eisa->prod_id,
  51. isa_id_string ( eisa->vendor_id, eisa->prod_id ), eisa->ioaddr );
  52. for ( driver = eisa_drivers; driver < eisa_drivers_end; driver++ ) {
  53. for ( i = 0 ; i < driver->id_count ; i++ ) {
  54. id = &driver->ids[i];
  55. if ( id->vendor_id != eisa->vendor_id )
  56. continue;
  57. if ( ISA_PROD_ID ( id->prod_id ) !=
  58. ISA_PROD_ID ( eisa->prod_id ) )
  59. continue;
  60. eisa->driver = driver;
  61. eisa->driver_name = id->name;
  62. DBG ( "...using driver %s\n", eisa->driver_name );
  63. if ( ( rc = driver->probe ( eisa, id ) ) != 0 ) {
  64. DBG ( "......probe failed\n" );
  65. continue;
  66. }
  67. return 0;
  68. }
  69. }
  70. DBG ( "...no driver found\n" );
  71. return -ENOTTY;
  72. }
  73. /**
  74. * Remove an EISA device
  75. *
  76. * @v eisa EISA device
  77. */
  78. static void eisa_remove ( struct eisa_device *eisa ) {
  79. eisa->driver->remove ( eisa );
  80. DBG ( "Removed EISA device %02x\n", eisa->slot );
  81. }
  82. /**
  83. * Probe EISA root bus
  84. *
  85. * @v rootdev EISA bus root device
  86. *
  87. * Scans the EISA bus for devices and registers all devices it can
  88. * find.
  89. */
  90. static int eisabus_probe ( struct root_device *rootdev ) {
  91. struct eisa_device *eisa = NULL;
  92. unsigned int slot;
  93. int rc;
  94. for ( slot = EISA_MIN_SLOT ; slot <= EISA_MAX_SLOT ; slot++ ) {
  95. /* Allocate struct eisa_device */
  96. if ( ! eisa )
  97. eisa = malloc ( sizeof ( *eisa ) );
  98. if ( ! eisa ) {
  99. rc = -ENOMEM;
  100. goto err;
  101. }
  102. memset ( eisa, 0, sizeof ( *eisa ) );
  103. eisa->slot = slot;
  104. eisa->ioaddr = EISA_SLOT_BASE ( eisa->slot );
  105. /* Test for board present */
  106. outb ( 0xff, eisa->ioaddr + EISA_VENDOR_ID );
  107. eisa->vendor_id =
  108. le16_to_cpu ( inw ( eisa->ioaddr + EISA_VENDOR_ID ) );
  109. eisa->prod_id =
  110. le16_to_cpu ( inw ( eisa->ioaddr + EISA_PROD_ID ) );
  111. if ( eisa->vendor_id & 0x80 ) {
  112. /* No board present */
  113. continue;
  114. }
  115. /* Add to device hierarchy */
  116. snprintf ( eisa->dev.name, sizeof ( eisa->dev.name ),
  117. "EISA%02x", slot );
  118. eisa->dev.desc.bus_type = BUS_TYPE_EISA;
  119. eisa->dev.desc.vendor = eisa->vendor_id;
  120. eisa->dev.desc.device = eisa->prod_id;
  121. eisa->dev.parent = &rootdev->dev;
  122. list_add ( &eisa->dev.siblings, &rootdev->dev.children );
  123. INIT_LIST_HEAD ( &eisa->dev.children );
  124. /* Look for a driver */
  125. if ( eisa_probe ( eisa ) == 0 ) {
  126. /* eisadev registered, we can drop our ref */
  127. eisa = NULL;
  128. } else {
  129. /* Not registered; re-use struct */
  130. list_del ( &eisa->dev.siblings );
  131. }
  132. }
  133. free ( eisa );
  134. return 0;
  135. err:
  136. free ( eisa );
  137. eisabus_remove ( rootdev );
  138. return rc;
  139. }
  140. /**
  141. * Remove EISA root bus
  142. *
  143. * @v rootdev EISA bus root device
  144. */
  145. static void eisabus_remove ( struct root_device *rootdev ) {
  146. struct eisa_device *eisa;
  147. struct eisa_device *tmp;
  148. list_for_each_entry_safe ( eisa, tmp, &rootdev->dev.children,
  149. dev.siblings ) {
  150. eisa_remove ( eisa );
  151. list_del ( &eisa->dev.siblings );
  152. free ( eisa );
  153. }
  154. }
  155. /** EISA bus root device driver */
  156. static struct root_driver eisa_root_driver = {
  157. .probe = eisabus_probe,
  158. .remove = eisabus_remove,
  159. };
  160. /** EISA bus root device */
  161. struct root_device eisa_root_device __root_device = {
  162. .dev = { .name = "EISA" },
  163. .driver = &eisa_root_driver,
  164. };