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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * MCA bus driver code
  3. *
  4. * Abstracted from 3c509.c.
  5. *
  6. */
  7. #include "etherboot.h"
  8. #include "dev.h"
  9. #include "io.h"
  10. #include "mca.h"
  11. #define DEBUG_MCA
  12. #undef DBG
  13. #ifdef DEBUG_MCA
  14. #define DBG(...) printf ( __VA_ARGS__ )
  15. #else
  16. #define DBG(...)
  17. #endif
  18. /*
  19. * Fill in parameters for an MCA device based on slot number
  20. *
  21. */
  22. static int fill_mca_device ( struct mca_device *mca ) {
  23. unsigned int i;
  24. /* Make sure motherboard setup is off */
  25. outb_p ( 0xff, MCA_MOTHERBOARD_SETUP_REG );
  26. /* Select the slot */
  27. outb_p ( 0x8 | ( mca->slot & 0xf ), MCA_ADAPTER_SETUP_REG );
  28. /* Read the POS registers */
  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. }
  33. /* Kill all setup modes */
  34. outb_p ( 0, MCA_ADAPTER_SETUP_REG );
  35. DBG ( "MCA slot %d id %hx (%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx)\n",
  36. mca->slot, MCA_ID ( mca ),
  37. mca->pos[0], mca->pos[1], mca->pos[2], mca->pos[3],
  38. mca->pos[4], mca->pos[5], mca->pos[6], mca->pos[7] );
  39. return 1;
  40. }
  41. /*
  42. * Obtain a struct mca * from a struct dev *
  43. *
  44. * If dev has not previously been used for an MCA device scan, blank
  45. * out dev.mca
  46. */
  47. struct mca_device * mca_device ( struct dev *dev ) {
  48. struct mca_device *mca = &dev->mca;
  49. if ( dev->devid.bus_type != MCA_BUS_TYPE ) {
  50. memset ( mca, 0, sizeof ( *mca ) );
  51. dev->devid.bus_type = MCA_BUS_TYPE;
  52. }
  53. mca->dev = dev;
  54. return mca;
  55. }
  56. /*
  57. * Find an MCA device matching the specified driver
  58. *
  59. */
  60. int find_mca_device ( struct mca_device *mca, struct mca_driver *driver ) {
  61. unsigned int i;
  62. /* Iterate through all possible MCA slots, starting where we
  63. * left off/
  64. */
  65. for ( ; mca->slot < MCA_MAX_SLOT_NR ; mca->slot++ ) {
  66. /* If we've already used this device, skip it */
  67. if ( mca->already_tried ) {
  68. mca->already_tried = 0;
  69. continue;
  70. }
  71. /* Fill in device parameters */
  72. if ( ! fill_mca_device ( mca ) ) {
  73. continue;
  74. }
  75. /* Compare against driver's ID list */
  76. for ( i = 0 ; i < driver->id_count ; i++ ) {
  77. struct mca_id *id = &driver->ids[i];
  78. if ( MCA_ID ( mca ) == id->id ) {
  79. DBG ( "Device %s (driver %s) matches ID %hx\n",
  80. id->name, driver->name, id->id );
  81. if ( mca->dev ) {
  82. mca->dev->name = driver->name;
  83. mca->dev->devid.vendor_id =
  84. htons ( GENERIC_MCA_VENDOR );
  85. mca->dev->devid.device_id =
  86. htons ( id->id );
  87. }
  88. mca->already_tried = 1;
  89. return 1;
  90. }
  91. }
  92. }
  93. /* No device found */
  94. mca->slot = 0;
  95. return 0;
  96. }