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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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_ADDRS ends with a zero, the driver's own list will
  20. * never be 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_IDX_LIMIT isa_extra_probe_addr_count
  35. #else
  36. # define ISA_PROBE_IDX_LIMIT ( ISA_MAX_PROBE_IDX + 1 )
  37. #endif
  38. /*
  39. * Increment a bus_loc structure to the next possible ISA location.
  40. * Leave the structure zeroed and return 0 if there are no more valid
  41. * locations.
  42. *
  43. */
  44. static int isa_next_location ( struct bus_loc *bus_loc ) {
  45. struct isa_loc *isa_loc = ( struct isa_loc * ) bus_loc;
  46. /*
  47. * Ensure that there is sufficient space in the shared bus
  48. * structures for a struct isa_loc and a struct
  49. * isa_dev, as mandated by bus.h.
  50. *
  51. */
  52. BUS_LOC_CHECK ( struct isa_loc );
  53. BUS_DEV_CHECK ( struct isa_device );
  54. return ( ( ++isa_loc->probe_idx < ISA_PROBE_IDX_LIMIT ) ?
  55. 1 : ( isa_loc->probe_idx = 0 ) );
  56. }
  57. /*
  58. * Fill in parameters (vendor & device ids, class, membase etc.) for
  59. * an ISA device based on bus_loc.
  60. *
  61. * Returns 1 if a device was found, 0 for no device present.
  62. *
  63. */
  64. static int isa_fill_device ( struct bus_dev *bus_dev,
  65. struct bus_loc *bus_loc ) {
  66. struct isa_loc *isa_loc = ( struct isa_loc * ) bus_loc;
  67. struct isa_device *isa = ( struct isa_device * ) bus_dev;
  68. signed int driver_probe_idx;
  69. driver_probe_idx = isa_loc->probe_idx - isa_extra_probe_addr_count;
  70. if ( driver_probe_idx < 0 ) {
  71. isa->ioaddr = isa_extra_probe_addrs[isa_loc->probe_idx];
  72. } else {
  73. isa->ioaddr = 0;
  74. isa->driver_probe_idx = driver_probe_idx;
  75. }
  76. isa->mfg_id = isa->prod_id = 0;
  77. isa->name = "?";
  78. return 1;
  79. }
  80. /*
  81. * Test whether or not a driver is capable of driving the specified
  82. * device.
  83. *
  84. */
  85. int isa_check_driver ( struct bus_dev *bus_dev,
  86. struct device_driver *device_driver ) {
  87. struct isa_device *isa = ( struct isa_device * ) bus_dev;
  88. struct isa_driver *driver
  89. = ( struct isa_driver * ) device_driver->bus_driver_info;
  90. /* If ioaddr is zero, it means we're using a driver-specified
  91. * ioaddr
  92. */
  93. if ( ! isa->ioaddr ) {
  94. if ( isa->driver_probe_idx >= driver->addr_count )
  95. return 0;
  96. isa->ioaddr = driver->probe_addrs[isa->driver_probe_idx];
  97. }
  98. /* Use probe_addr method to see if there's a device
  99. * present at this address.
  100. */
  101. if ( driver->probe_addr ( isa->ioaddr ) ) {
  102. DBG ( "ISA found %s device at address %hx\n",
  103. driver->name, isa->ioaddr );
  104. isa->name = driver->name;
  105. isa->mfg_id = driver->mfg_id;
  106. isa->prod_id = driver->prod_id;
  107. return 1;
  108. }
  109. /* No device found */
  110. return 0;
  111. }
  112. /*
  113. * Describe a ISA device
  114. *
  115. */
  116. static char * isa_describe_device ( struct bus_dev *bus_dev ) {
  117. struct isa_device *isa = ( struct isa_device * ) bus_dev;
  118. static char isa_description[] = "ISA 0000";
  119. sprintf ( isa_description + 4, "%hx", isa->ioaddr );
  120. return isa_description;
  121. }
  122. /*
  123. * Name a ISA device
  124. *
  125. */
  126. static const char * isa_name_device ( struct bus_dev *bus_dev ) {
  127. struct isa_device *isa = ( struct isa_device * ) bus_dev;
  128. return isa->name;
  129. }
  130. /*
  131. * ISA bus operations table
  132. *
  133. */
  134. struct bus_driver isa_driver __bus_driver = {
  135. .name = "ISA",
  136. .next_location = isa_next_location,
  137. .fill_device = isa_fill_device,
  138. .check_driver = isa_check_driver,
  139. .describe_device = isa_describe_device,
  140. .name_device = isa_name_device,
  141. };
  142. /*
  143. * Fill in a nic structure
  144. *
  145. */
  146. void isa_fill_nic ( struct nic *nic, struct isa_device *isa ) {
  147. /* Fill in ioaddr and irqno */
  148. nic->ioaddr = isa->ioaddr;
  149. nic->irqno = 0;
  150. /* Fill in DHCP device ID structure */
  151. nic->dhcp_dev_id.bus_type = ISA_BUS_TYPE;
  152. nic->dhcp_dev_id.vendor_id = htons ( isa->mfg_id );
  153. nic->dhcp_dev_id.device_id = htons ( isa->prod_id );
  154. }