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.

mca.c 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * MCA bus driver code
  3. *
  4. * Abstracted from 3c509.c.
  5. *
  6. */
  7. #include "string.h"
  8. #include "io.h"
  9. #include "console.h"
  10. #include "dev.h"
  11. #include "mca.h"
  12. /*
  13. * Increment a bus_loc structure to the next possible MCA location.
  14. * Leave the structure zeroed and return 0 if there are no more valid
  15. * locations.
  16. *
  17. */
  18. static int mca_next_location ( struct bus_loc *bus_loc ) {
  19. struct mca_loc *mca_loc = ( struct mca_loc * ) bus_loc;
  20. /*
  21. * Ensure that there is sufficient space in the shared bus
  22. * structures for a struct mca_loc and a struct
  23. * mca_dev, as mandated by bus.h.
  24. *
  25. */
  26. BUS_LOC_CHECK ( struct mca_loc );
  27. BUS_DEV_CHECK ( struct mca_device );
  28. return ( mca_loc->slot = ( ++mca_loc->slot & MCA_MAX_SLOT_NR ) );
  29. }
  30. /*
  31. * Fill in parameters for an MCA device based on slot number
  32. *
  33. */
  34. static int mca_fill_device ( struct bus_dev *bus_dev,
  35. struct bus_loc *bus_loc ) {
  36. struct mca_loc *mca_loc = ( struct mca_loc * ) bus_loc;
  37. struct mca_device *mca = ( struct mca_device * ) bus_dev;
  38. unsigned int i, seen_non_ff;
  39. /* Store slot in struct mca, set default values */
  40. mca->slot = mca_loc->slot;
  41. mca->name = "?";
  42. /* Make sure motherboard setup is off */
  43. outb_p ( 0xff, MCA_MOTHERBOARD_SETUP_REG );
  44. /* Select the slot */
  45. outb_p ( 0x8 | ( mca->slot & 0xf ), MCA_ADAPTER_SETUP_REG );
  46. /* Read the POS registers */
  47. seen_non_ff = 0;
  48. for ( i = 0 ; i < ( sizeof ( mca->pos ) / sizeof ( mca->pos[0] ) ) ;
  49. i++ ) {
  50. mca->pos[i] = inb_p ( MCA_POS_REG ( i ) );
  51. if ( mca->pos[i] != 0xff )
  52. seen_non_ff = 1;
  53. }
  54. /* If all POS registers are 0xff, this means there's no device
  55. * present
  56. */
  57. if ( ! seen_non_ff )
  58. return 0;
  59. /* Kill all setup modes */
  60. outb_p ( 0, MCA_ADAPTER_SETUP_REG );
  61. DBG ( "MCA found slot %d id %hx "
  62. "(POS %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx)\n",
  63. mca->slot, MCA_ID ( mca ),
  64. mca->pos[0], mca->pos[1], mca->pos[2], mca->pos[3],
  65. mca->pos[4], mca->pos[5], mca->pos[6], mca->pos[7] );
  66. return 1;
  67. }
  68. /*
  69. * Test whether or not a driver is capable of driving the device.
  70. *
  71. */
  72. static int mca_check_driver ( struct bus_dev *bus_dev,
  73. struct device_driver *device_driver ) {
  74. struct mca_device *mca = ( struct mca_device * ) bus_dev;
  75. struct mca_driver *driver
  76. = ( struct mca_driver * ) device_driver->bus_driver_info;
  77. unsigned int i;
  78. /* Compare against driver's ID list */
  79. for ( i = 0 ; i < driver->id_count ; i++ ) {
  80. struct mca_id *id = &driver->ids[i];
  81. if ( MCA_ID ( mca ) == id->id ) {
  82. DBG ( "MCA found ID %hx (device %s) "
  83. "matching driver %s\n",
  84. id->name, id->id, device_driver->name );
  85. mca->name = id->name;
  86. return 1;
  87. }
  88. }
  89. /* No device found */
  90. return 0;
  91. }
  92. /*
  93. * Describe an MCA device
  94. *
  95. */
  96. static char * mca_describe_device ( struct bus_dev *bus_dev ) {
  97. struct mca_device *mca = ( struct mca_device * ) bus_dev;
  98. static char mca_description[] = "MCA 00";
  99. sprintf ( mca_description + 4, "%hhx", mca->slot );
  100. return mca_description;
  101. }
  102. /*
  103. * Name an MCA device
  104. *
  105. */
  106. static const char * mca_name_device ( struct bus_dev *bus_dev ) {
  107. struct mca_device *mca = ( struct mca_device * ) bus_dev;
  108. return mca->name;
  109. }
  110. /*
  111. * MCA bus operations table
  112. *
  113. */
  114. struct bus_driver mca_driver __bus_driver = {
  115. .name = "MCA",
  116. .next_location = mca_next_location,
  117. .fill_device = mca_fill_device,
  118. .check_driver = mca_check_driver,
  119. .describe_device = mca_describe_device,
  120. .name_device = mca_name_device,
  121. };
  122. /*
  123. * Fill in a nic structure
  124. *
  125. */
  126. void mca_fill_nic ( struct nic *nic, struct mca_device *mca ) {
  127. /* ioaddr and irqno must be read in a device-dependent way
  128. * from the POS registers
  129. */
  130. nic->ioaddr = 0;
  131. nic->irqno = 0;
  132. /* Fill in DHCP device ID structure */
  133. nic->dhcp_dev_id.bus_type = MCA_BUS_TYPE;
  134. nic->dhcp_dev_id.vendor_id = htons ( GENERIC_MCA_VENDOR );
  135. nic->dhcp_dev_id.device_id = htons ( MCA_ID ( mca ) );
  136. }