SlotConfig.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /** @file
  2. Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. Module Name:
  5. SlotConfig.c
  6. Abstract:
  7. Sets platform/SKU specific expansion slot information.
  8. --*/
  9. #include "SlotConfig.h"
  10. //
  11. // Implementation
  12. //
  13. VOID
  14. InitializeSlotInfo (
  15. )
  16. {
  17. UINT16 BusSaveState;
  18. UINT16 Vendor;
  19. UINT8 CurrentBus;
  20. UINTN i;
  21. UINTN j;
  22. EFI_HANDLE Handle;
  23. EFI_STATUS Status;
  24. BOOLEAN RunNext;
  25. //
  26. // Loop through the slot table and see if any slots have cards in them
  27. //
  28. for (i = 0; i < mSlotBridgeTableSize; i++) {
  29. //
  30. // Initialize variable
  31. //
  32. RunNext = FALSE;
  33. //
  34. // Hide mini PCIe slots per SKU
  35. //
  36. for (j = 0; j < mSlotInformation.NumberOfEntries; j++) {
  37. if (mSlotInformation.SlotEntries[j].SmbiosSlotId == mSlotBridgeTable[i].SmbiosSlotId) {
  38. if ((mSlotInformation.SlotEntries[j].SmbiosSlotId == 0x02) &&
  39. (mBoardFeatures & B_BOARD_FEATURES_NO_MINIPCIE)
  40. ) {
  41. mSlotInformation.SlotEntries[j].Disabled = TRUE;
  42. RunNext = TRUE;
  43. }
  44. break;
  45. }
  46. }
  47. if (RunNext) {
  48. //
  49. // Skip slot device detection since the slot is disabled.
  50. //
  51. continue;
  52. }
  53. //
  54. // Check to see if the bridge has a bus number and assign one if not
  55. //
  56. BusSaveState = MmPci16 (
  57. 0,
  58. mSlotBridgeTable[i].Bus,
  59. mSlotBridgeTable[i].Dev,
  60. mSlotBridgeTable[i].Function,
  61. PCI_BRIDGE_SECONDARY_BUS_REGISTER_OFFSET
  62. );
  63. if (BusSaveState == 0) {
  64. //
  65. // Assign temp bus number
  66. //
  67. MmPci16 (
  68. 0,
  69. mSlotBridgeTable[i].Bus,
  70. mSlotBridgeTable[i].Dev,
  71. mSlotBridgeTable[i].Function,
  72. PCI_BRIDGE_SECONDARY_BUS_REGISTER_OFFSET
  73. ) = DEF_BUS_CONFIG;
  74. CurrentBus = DEF_BUS;
  75. } else if (BusSaveState == 0xFFFF) {
  76. //
  77. // Bridge is disabled so continue with next entry in the table
  78. //
  79. continue;
  80. } else {
  81. //
  82. // Use existing bus number
  83. //
  84. CurrentBus = (UINT8) BusSaveState & 0xFF;
  85. }
  86. //
  87. // Check to see if a device is behind the bridge
  88. //
  89. Vendor = MmPci16 (
  90. 0,
  91. CurrentBus,
  92. mSlotBridgeTable[i].TargetDevice,
  93. 0,
  94. 0
  95. );
  96. if (Vendor != 0xFFFF) {
  97. //
  98. // Device found so make sure the slot is marked that way
  99. //
  100. for (j = 0; j < mSlotInformation.NumberOfEntries; j++) {
  101. if (mSlotInformation.SlotEntries[j].SmbiosSlotId == mSlotBridgeTable[i].SmbiosSlotId) {
  102. mSlotInformation.SlotEntries[j].InUse = TRUE;
  103. break;
  104. }
  105. }
  106. }
  107. //
  108. // Restore previous bus information
  109. //
  110. if (BusSaveState == 0) {
  111. MmPci16 (
  112. 0,
  113. mSlotBridgeTable[i].Bus,
  114. mSlotBridgeTable[i].Dev,
  115. mSlotBridgeTable[i].Function,
  116. PCI_BRIDGE_SECONDARY_BUS_REGISTER_OFFSET
  117. ) = 0;
  118. }
  119. }
  120. Handle = NULL;
  121. Status = gBS->InstallProtocolInterface (
  122. &Handle,
  123. &gEfiSmbiosSlotPopulationGuid,
  124. EFI_NATIVE_INTERFACE,
  125. &mSlotInformation
  126. );
  127. ASSERT_EFI_ERROR(Status);
  128. }