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.

isa.c 5.0KB

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