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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * MCA bus driver code
  3. *
  4. * Abstracted from 3c509.c.
  5. *
  6. */
  7. #include "string.h"
  8. #include "io.h"
  9. #include "mca.h"
  10. /*
  11. * Ensure that there is sufficient space in the shared dev_bus
  12. * structure for a struct pci_device.
  13. *
  14. */
  15. DEV_BUS( struct mca_device, mca_dev );
  16. static char mca_magic[0]; /* guaranteed unique symbol */
  17. /*
  18. * Fill in parameters for an MCA device based on slot number
  19. *
  20. */
  21. static int fill_mca_device ( struct mca_device *mca ) {
  22. unsigned int i, seen_non_ff;
  23. /* Make sure motherboard setup is off */
  24. outb_p ( 0xff, MCA_MOTHERBOARD_SETUP_REG );
  25. /* Select the slot */
  26. outb_p ( 0x8 | ( mca->slot & 0xf ), MCA_ADAPTER_SETUP_REG );
  27. /* Read the POS registers */
  28. seen_non_ff = 0;
  29. for ( i = 0 ; i < ( sizeof ( mca->pos ) / sizeof ( mca->pos[0] ) ) ;
  30. i++ ) {
  31. mca->pos[i] = inb_p ( MCA_POS_REG ( i ) );
  32. if ( mca->pos[i] != 0xff )
  33. seen_non_ff = 1;
  34. }
  35. /* If all POS registers are 0xff, this means there's no device
  36. * present
  37. */
  38. if ( ! seen_non_ff )
  39. return 0;
  40. /* Kill all setup modes */
  41. outb_p ( 0, MCA_ADAPTER_SETUP_REG );
  42. DBG ( "MCA found slot %d id %hx "
  43. "(POS %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx)\n",
  44. mca->slot, MCA_ID ( mca ),
  45. mca->pos[0], mca->pos[1], mca->pos[2], mca->pos[3],
  46. mca->pos[4], mca->pos[5], mca->pos[6], mca->pos[7] );
  47. return 1;
  48. }
  49. /*
  50. * Find an MCA device matching the specified driver
  51. *
  52. */
  53. int find_mca_device ( struct mca_device *mca, struct mca_driver *driver ) {
  54. unsigned int i;
  55. /* Initialise struct mca if it's the first time it's been used. */
  56. if ( mca->magic != mca_magic ) {
  57. memset ( mca, 0, sizeof ( *mca ) );
  58. mca->magic = mca_magic;
  59. }
  60. /* Iterate through all possible MCA slots, starting where we
  61. * left off
  62. */
  63. DBG ( "MCA searching for device matching driver %s\n", driver->name );
  64. for ( ; mca->slot < MCA_MAX_SLOT_NR ; mca->slot++ ) {
  65. /* If we've already used this device, skip it */
  66. if ( mca->already_tried ) {
  67. mca->already_tried = 0;
  68. continue;
  69. }
  70. /* Fill in device parameters */
  71. if ( ! fill_mca_device ( mca ) ) {
  72. continue;
  73. }
  74. /* Compare against driver's ID list */
  75. for ( i = 0 ; i < driver->id_count ; i++ ) {
  76. struct mca_id *id = &driver->ids[i];
  77. if ( MCA_ID ( mca ) == id->id ) {
  78. DBG ( "MCA found ID %hx (device %s) "
  79. "matching driver %s\n",
  80. id->name, id->id, driver->name );
  81. mca->name = id->name;
  82. mca->already_tried = 1;
  83. return 1;
  84. }
  85. }
  86. }
  87. /* No device found */
  88. DBG ( "MCA found no device matching driver %s\n", driver->name );
  89. mca->slot = 0;
  90. return 0;
  91. }
  92. /*
  93. * Find the next MCA device that can be used to boot using the
  94. * specified driver.
  95. *
  96. */
  97. int find_mca_boot_device ( struct dev *dev, struct mca_driver *driver ) {
  98. struct mca_device *mca = ( struct mca_device * )dev->bus;
  99. if ( ! find_mca_device ( mca, driver ) )
  100. return 0;
  101. dev->name = mca->name;
  102. dev->devid.bus_type = MCA_BUS_TYPE;
  103. dev->devid.vendor_id = GENERIC_MCA_VENDOR;
  104. dev->devid.device_id = MCA_ID ( mca );
  105. return 1;
  106. }