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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * MCA bus driver code
  3. *
  4. * Abstracted from 3c509.c.
  5. *
  6. */
  7. FILE_LICENCE ( BSD2 );
  8. #include <stdint.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <errno.h>
  13. #include <ipxe/io.h>
  14. #include <ipxe/mca.h>
  15. static void mcabus_remove ( struct root_device *rootdev );
  16. /**
  17. * Probe an MCA device
  18. *
  19. * @v mca MCA device
  20. * @ret rc Return status code
  21. *
  22. * Searches for a driver for the MCA device. If a driver is found,
  23. * its probe() routine is called.
  24. */
  25. static int mca_probe ( struct mca_device *mca ) {
  26. struct mca_driver *driver;
  27. struct mca_device_id *id;
  28. unsigned int i;
  29. int rc;
  30. DBG ( "Adding MCA slot %02x (ID %04x POS "
  31. "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x)\n",
  32. mca->slot, MCA_ID ( mca ),
  33. mca->pos[0], mca->pos[1], mca->pos[2], mca->pos[3],
  34. mca->pos[4], mca->pos[5], mca->pos[6], mca->pos[7] );
  35. for_each_table_entry ( driver, MCA_DRIVERS ) {
  36. for ( i = 0 ; i < driver->id_count ; i++ ) {
  37. id = &driver->ids[i];
  38. if ( id->id != MCA_ID ( mca ) )
  39. continue;
  40. mca->driver = driver;
  41. mca->dev.driver_name = id->name;
  42. DBG ( "...using driver %s\n", mca->dev.driver_name );
  43. if ( ( rc = driver->probe ( mca, id ) ) != 0 ) {
  44. DBG ( "......probe failed\n" );
  45. continue;
  46. }
  47. return 0;
  48. }
  49. }
  50. DBG ( "...no driver found\n" );
  51. return -ENOTTY;
  52. }
  53. /**
  54. * Remove an MCA device
  55. *
  56. * @v mca MCA device
  57. */
  58. static void mca_remove ( struct mca_device *mca ) {
  59. mca->driver->remove ( mca );
  60. DBG ( "Removed MCA device %02x\n", mca->slot );
  61. }
  62. /**
  63. * Probe MCA root bus
  64. *
  65. * @v rootdev MCA bus root device
  66. *
  67. * Scans the MCA bus for devices and registers all devices it can
  68. * find.
  69. */
  70. static int mcabus_probe ( struct root_device *rootdev ) {
  71. struct mca_device *mca = NULL;
  72. unsigned int slot;
  73. int seen_non_ff;
  74. unsigned int i;
  75. int rc;
  76. for ( slot = 0 ; slot <= MCA_MAX_SLOT_NR ; slot++ ) {
  77. /* Allocate struct mca_device */
  78. if ( ! mca )
  79. mca = malloc ( sizeof ( *mca ) );
  80. if ( ! mca ) {
  81. rc = -ENOMEM;
  82. goto err;
  83. }
  84. memset ( mca, 0, sizeof ( *mca ) );
  85. mca->slot = slot;
  86. /* Make sure motherboard setup is off */
  87. outb_p ( 0xff, MCA_MOTHERBOARD_SETUP_REG );
  88. /* Select the slot */
  89. outb_p ( 0x8 | ( mca->slot & 0xf ), MCA_ADAPTER_SETUP_REG );
  90. /* Read the POS registers */
  91. seen_non_ff = 0;
  92. for ( i = 0 ; i < ( sizeof ( mca->pos ) /
  93. sizeof ( mca->pos[0] ) ) ; i++ ) {
  94. mca->pos[i] = inb_p ( MCA_POS_REG ( i ) );
  95. if ( mca->pos[i] != 0xff )
  96. seen_non_ff = 1;
  97. }
  98. /* Kill all setup modes */
  99. outb_p ( 0, MCA_ADAPTER_SETUP_REG );
  100. /* If all POS registers are 0xff, this means there's no device
  101. * present
  102. */
  103. if ( ! seen_non_ff )
  104. continue;
  105. /* Add to device hierarchy */
  106. snprintf ( mca->dev.name, sizeof ( mca->dev.name ),
  107. "MCA%02x", slot );
  108. mca->dev.desc.bus_type = BUS_TYPE_MCA;
  109. mca->dev.desc.vendor = GENERIC_MCA_VENDOR;
  110. mca->dev.desc.device = MCA_ID ( mca );
  111. mca->dev.parent = &rootdev->dev;
  112. list_add ( &mca->dev.siblings, &rootdev->dev.children );
  113. INIT_LIST_HEAD ( &mca->dev.children );
  114. /* Look for a driver */
  115. if ( mca_probe ( mca ) == 0 ) {
  116. /* mcadev registered, we can drop our ref */
  117. mca = NULL;
  118. } else {
  119. /* Not registered; re-use struct */
  120. list_del ( &mca->dev.siblings );
  121. }
  122. }
  123. free ( mca );
  124. return 0;
  125. err:
  126. free ( mca );
  127. mcabus_remove ( rootdev );
  128. return rc;
  129. }
  130. /**
  131. * Remove MCA root bus
  132. *
  133. * @v rootdev MCA bus root device
  134. */
  135. static void mcabus_remove ( struct root_device *rootdev ) {
  136. struct mca_device *mca;
  137. struct mca_device *tmp;
  138. list_for_each_entry_safe ( mca, tmp, &rootdev->dev.children,
  139. dev.siblings ) {
  140. mca_remove ( mca );
  141. list_del ( &mca->dev.siblings );
  142. free ( mca );
  143. }
  144. }
  145. /** MCA bus root device driver */
  146. static struct root_driver mca_root_driver = {
  147. .probe = mcabus_probe,
  148. .remove = mcabus_remove,
  149. };
  150. /** MCA bus root device */
  151. struct root_device mca_root_device __root_device = {
  152. .dev = { .name = "MCA" },
  153. .driver = &mca_root_driver,
  154. };