Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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