您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #include "string.h"
  2. #include "console.h"
  3. #include "config/isa.h"
  4. #include "dev.h"
  5. #include "isa.h"
  6. /*
  7. * isa.c implements a "classical" port-scanning method of ISA device
  8. * detection. The driver must provide a list of probe addresses
  9. * (probe_addrs), together with a function (probe_addr) that can be
  10. * used to test for the physical presence of a device at any given
  11. * address.
  12. *
  13. * Note that this should probably be considered the "last resort" for
  14. * device probing. If the card supports ISAPnP or EISA, use that
  15. * instead. Some cards (e.g. the 3c509) implement a proprietary
  16. * ISAPnP-like mechanism.
  17. *
  18. * The ISA probe address list can be overridden by config.h; if the
  19. * user specifies ISA_PROBE_ADDRS then that list will be used first.
  20. * (If ISA_PROBE_ONLY is defined, the driver's own list will never be
  21. * used).
  22. */
  23. /*
  24. * User-supplied probe address list
  25. *
  26. */
  27. static isa_probe_addr_t isa_extra_probe_addrs[] = {
  28. #ifdef ISA_PROBE_ADDRS
  29. ISA_PROBE_ADDRS
  30. #endif
  31. };
  32. #define isa_extra_probe_addr_count \
  33. ( sizeof ( isa_extra_probe_addrs ) / sizeof ( isa_extra_probe_addrs[0] ) )
  34. #ifdef ISA_PROBE_ONLY
  35. #define ISA_PROBE_ADDR_COUNT(driver) ( isa_extra_probe_addr_count )
  36. #else
  37. #define ISA_PROBE_ADDR_COUNT(driver) \
  38. ( isa_extra_probe_addr_count + (driver)->addr_count )
  39. #endif
  40. /*
  41. * Symbols defined by linker
  42. *
  43. */
  44. static struct isa_driver isa_drivers[0] __table_start ( isa_driver );
  45. static struct isa_driver isa_drivers_end[0] __table_end ( isa_driver );
  46. /*
  47. * Increment a bus_loc structure to the next possible ISA location.
  48. * Leave the structure zeroed and return 0 if there are no more valid
  49. * locations.
  50. *
  51. * There is no sensible concept of a device location on an ISA bus, so
  52. * we use the probe address list for each ISA driver to define the
  53. * list of ISA locations.
  54. *
  55. */
  56. static int isa_next_location ( struct bus_loc *bus_loc ) {
  57. struct isa_loc *isa_loc = ( struct isa_loc * ) bus_loc;
  58. struct isa_driver *driver;
  59. /*
  60. * Ensure that there is sufficient space in the shared bus
  61. * structures for a struct isa_loc and a struct
  62. * isa_dev, as mandated by bus.h.
  63. *
  64. */
  65. BUS_LOC_CHECK ( struct isa_loc );
  66. BUS_DEV_CHECK ( struct isa_device );
  67. /* Move to next probe address within this driver */
  68. driver = &isa_drivers[isa_loc->driver];
  69. if ( ++isa_loc->probe_idx < ISA_PROBE_ADDR_COUNT ( driver ) )
  70. return 1;
  71. /* Move to next driver */
  72. isa_loc->probe_idx = 0;
  73. if ( ( ++isa_loc->driver, ++driver ) < isa_drivers_end )
  74. return 1;
  75. isa_loc->driver = 0;
  76. return 0;
  77. }
  78. /*
  79. * Fill in parameters (vendor & device ids, class, membase etc.) for
  80. * an ISA device based on bus_loc.
  81. *
  82. * Returns 1 if a device was found, 0 for no device present.
  83. *
  84. */
  85. static int isa_fill_device ( struct bus_dev *bus_dev,
  86. struct bus_loc *bus_loc ) {
  87. struct isa_loc *isa_loc = ( struct isa_loc * ) bus_loc;
  88. struct isa_device *isa = ( struct isa_device * ) bus_dev;
  89. signed int driver_probe_idx;
  90. /* Fill in struct isa from struct isa_loc */
  91. isa->driver = &isa_drivers[isa_loc->driver];
  92. driver_probe_idx = isa_loc->probe_idx - isa_extra_probe_addr_count;
  93. if ( driver_probe_idx < 0 ) {
  94. isa->ioaddr = isa_extra_probe_addrs[isa_loc->probe_idx];
  95. } else {
  96. isa->ioaddr = isa->driver->probe_addrs[driver_probe_idx];
  97. }
  98. /* Call driver's probe_addr method to determine if a device is
  99. * physically present
  100. */
  101. if ( isa->driver->probe_addr ( isa->ioaddr ) ) {
  102. isa->name = isa->driver->name;
  103. isa->mfg_id = isa->driver->mfg_id;
  104. isa->prod_id = isa->driver->prod_id;
  105. DBG ( "ISA found %s device at address %hx\n",
  106. isa->name, isa->ioaddr );
  107. return 1;
  108. }
  109. return 0;
  110. }
  111. /*
  112. * Test whether or not a driver is capable of driving the specified
  113. * device.
  114. *
  115. */
  116. int isa_check_driver ( struct bus_dev *bus_dev,
  117. struct device_driver *device_driver ) {
  118. struct isa_device *isa = ( struct isa_device * ) bus_dev;
  119. struct isa_driver *driver
  120. = ( struct isa_driver * ) device_driver->bus_driver_info;
  121. return ( driver == isa->driver );
  122. }
  123. /*
  124. * Describe a ISA device
  125. *
  126. */
  127. static char * isa_describe_device ( struct bus_dev *bus_dev ) {
  128. struct isa_device *isa = ( struct isa_device * ) bus_dev;
  129. static char isa_description[] = "ISA 0000 (00)";
  130. sprintf ( isa_description + 4, "%hx (%hhx)", isa->ioaddr,
  131. isa->driver - isa_drivers );
  132. return isa_description;
  133. }
  134. /*
  135. * Name a ISA device
  136. *
  137. */
  138. static const char * isa_name_device ( struct bus_dev *bus_dev ) {
  139. struct isa_device *isa = ( struct isa_device * ) bus_dev;
  140. return isa->name;
  141. }
  142. /*
  143. * ISA bus operations table
  144. *
  145. */
  146. struct bus_driver isa_driver __bus_driver = {
  147. .name = "ISA",
  148. .next_location = isa_next_location,
  149. .fill_device = isa_fill_device,
  150. .check_driver = isa_check_driver,
  151. .describe_device = isa_describe_device,
  152. .name_device = isa_name_device,
  153. };
  154. /*
  155. * Fill in a nic structure
  156. *
  157. */
  158. void isa_fill_nic ( struct nic *nic, struct isa_device *isa ) {
  159. /* Fill in ioaddr and irqno */
  160. nic->ioaddr = isa->ioaddr;
  161. nic->irqno = 0;
  162. /* Fill in DHCP device ID structure */
  163. nic->dhcp_dev_id.bus_type = ISA_BUS_TYPE;
  164. nic->dhcp_dev_id.vendor_id = htons ( isa->mfg_id );
  165. nic->dhcp_dev_id.device_id = htons ( isa->prod_id );
  166. }