SystemBoardPei.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /** @file
  2. Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. **/
  5. #include "SystemBoardPei.h"
  6. #include <Library/BaseMemoryLib.h>
  7. #include <Library/MemoryAllocationLib.h>
  8. #include <IioBifurcationSlotTable.h>
  9. extern IIO_BIFURCATION_ENTRY mIioBifurcationTable[];
  10. extern UINT8 mIioBifurcationTableEntries;
  11. extern IIO_SLOT_CONFIG_ENTRY mIioSlotTable[];
  12. extern UINT8 mIioSlotTableEntries;
  13. //
  14. // System board PPI structure
  15. //
  16. static SYSTEM_BOARD_PPI mSystemBoardPpi = {
  17. SystemIioPortBifurcationInit, // Set IIO Bifurcation ports configuration
  18. GetUplinkPortInformation,
  19. };
  20. static EFI_PEI_PPI_DESCRIPTOR mSystemBoardPpiDesc = {
  21. EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
  22. &gEfiPeiSystemBoardPpiGuid,
  23. &mSystemBoardPpi
  24. };
  25. /**
  26. GetUplinkPortInformation - Get uplink port information
  27. @param IioIndex - socket ID.
  28. @retval PortIndex for uplink port
  29. **/
  30. UINT8
  31. EFIAPI
  32. GetUplinkPortInformation (
  33. IN UINT8 IioIndex
  34. )
  35. {
  36. UINT8 UplinkPortIndex;
  37. UplinkPortIndex = GetUplinkPortInformationCommon(IioIndex);
  38. return UplinkPortIndex;
  39. }
  40. /**
  41. SystemIioPortBifurcationInit - Program the UDS data structure with OEM IIO init values
  42. for SLOTs and Bifurcation.
  43. @param mSB - pointer to this protocol
  44. @param IioUds - Pointer to the IIO UDS datastructure.
  45. @retval EFI_SUCCESS
  46. **/
  47. VOID
  48. InternalSystemIioPortBifurcationInitCommon (
  49. IN OUT IIO_GLOBALS *IioGlobalData,
  50. IN OUT IIO_BIFURCATION_ENTRY **BifurcationTable,
  51. IN OUT UINT8 *BifurcationEntries,
  52. IN OUT IIO_SLOT_CONFIG_ENTRY **SlotTable,
  53. IN OUT UINT8 *SlotEntries
  54. )
  55. {
  56. UINT8 PortIndex;//, iio;
  57. /// This function outline:
  58. //// 1 Based on platform apply the default bifurcation and slot configuration.
  59. //// 2 Apply dynamic overrides based on GPIO and other configurations.
  60. //// 3 Hide unused ports due bifurcation.
  61. for (PortIndex = 0; PortIndex < MAX_SOCKET*NUMBER_PORTS_PER_SOCKET; PortIndex++) {
  62. IioGlobalData->SetupData.PEXPHIDE[PortIndex] = 0;
  63. IioGlobalData->SetupData.HidePEXPMenu[PortIndex] = 0;
  64. }
  65. *BifurcationEntries = 0;
  66. *SlotEntries = 0;
  67. // Purley Intel boards are not Multi-PCH
  68. IioGlobalData->IioVar.IioVData.MultiPch = 0;
  69. *BifurcationTable = (IIO_BIFURCATION_ENTRY *)(UINTN)PcdGet64 (PcdIioBifurcationTable);
  70. *BifurcationEntries = PcdGet8 (PcdIioBifurcationTableEntries);
  71. *SlotTable = (IIO_SLOT_CONFIG_ENTRY *)(UINTN)PcdGet64 (PcdIioSlotTable);
  72. *SlotEntries = PcdGet8 (PcdIioSlotTableEntries);
  73. }
  74. /**
  75. SystemIioPortBifurcationInit - Program the IIO_GLOBALS data structure with OEM IIO init values
  76. for SLOTs and Bifurcation.
  77. @param mSB - pointer to this protocol
  78. @param IioUds - Pointer to the IIO UDS datastructure.
  79. @retval EFI_SUCCESS
  80. **/
  81. VOID
  82. SystemIioPortBifurcationInit (
  83. IN IIO_GLOBALS *IioGlobalData
  84. )
  85. {
  86. UINT8 IioIndex;
  87. IIO_BIFURCATION_ENTRY *BifurcationTable = NULL;
  88. UINT8 BifurcationEntries;
  89. IIO_SLOT_CONFIG_ENTRY *SlotTable = NULL;
  90. UINT8 SlotEntries;
  91. // This function outline:
  92. // 1. Based on platform apply the default bifurcation and slot configuration.
  93. // 2. Apply dynamic overrides based on GPIO and other configurations.
  94. // 3. Hide unused ports due bifurcation.
  95. SystemIioPortBifurcationInitCommon(IioGlobalData, &BifurcationTable, &BifurcationEntries, &SlotTable, &SlotEntries);
  96. /// Set the default bifurcations for this platform.
  97. SetBifurcations(IioGlobalData, BifurcationTable, BifurcationEntries);
  98. ConfigSlots(IioGlobalData, SlotTable, SlotEntries);
  99. OverrideConfigSlots(IioGlobalData, SlotTable, SlotEntries);
  100. // All overrides have been applied now.
  101. // Hide root ports whose lanes are assigned preceding ports.
  102. for (IioIndex = Iio_Socket0; IioIndex < MaxIIO; IioIndex++) {
  103. if (IioGlobalData->IioVar.IioVData.SocketPresent[IioIndex]) {
  104. SystemHideIioPortsCommon(IioGlobalData, IioIndex);
  105. }
  106. }
  107. }
  108. /**
  109. This function dump raw data.
  110. @param Data raw data
  111. @param Size raw data size
  112. **/
  113. VOID
  114. InternalDumpData (
  115. IN UINT8 *Data,
  116. IN UINTN Size
  117. )
  118. {
  119. UINTN Index;
  120. for (Index = 0; Index < Size; Index++) {
  121. DEBUG ((EFI_D_INFO, "%02x", (UINTN)Data[Index]));
  122. }
  123. }
  124. /**
  125. This function dump raw data with colume format.
  126. @param Data raw data
  127. @param Size raw data size
  128. **/
  129. VOID
  130. InternalDumpHex (
  131. IN UINT8 *Data,
  132. IN UINTN Size
  133. )
  134. {
  135. UINTN Index;
  136. UINTN Count;
  137. UINTN Left;
  138. #define COLUME_SIZE (16 * 2)
  139. Count = Size / COLUME_SIZE;
  140. Left = Size % COLUME_SIZE;
  141. for (Index = 0; Index < Count; Index++) {
  142. DEBUG ((EFI_D_INFO, "%04x: ", Index * COLUME_SIZE));
  143. InternalDumpData (Data + Index * COLUME_SIZE, COLUME_SIZE);
  144. DEBUG ((EFI_D_INFO, "\n"));
  145. }
  146. if (Left != 0) {
  147. DEBUG ((EFI_D_INFO, "%04x: ", Index * COLUME_SIZE));
  148. InternalDumpData (Data + Index * COLUME_SIZE, Left);
  149. DEBUG ((EFI_D_INFO, "\n"));
  150. }
  151. }
  152. VOID
  153. DumpConfig (
  154. VOID
  155. )
  156. {
  157. DEBUG ((DEBUG_INFO, "PcdSetupData - 0x%x\n", PcdGetSize (PcdSetupData)));
  158. InternalDumpHex (PcdGetPtr (PcdSetupData), PcdGetSize (PcdSetupData));
  159. DEBUG ((DEBUG_INFO, "PcdPchRcConfigurationData - 0x%x\n", PcdGetSize (PcdPchRcConfigurationData)));
  160. InternalDumpHex (PcdGetPtr (PcdPchRcConfigurationData), PcdGetSize (PcdPchRcConfigurationData));
  161. DEBUG ((DEBUG_INFO, "PcdSocketIioConfigData - 0x%x\n", PcdGetSize (PcdSocketIioConfigData)));
  162. InternalDumpHex (PcdGetPtr (PcdSocketIioConfigData), PcdGetSize (PcdSocketIioConfigData));
  163. DEBUG ((DEBUG_INFO, "PcdSocketCommonRcConfigData - 0x%x\n", PcdGetSize (PcdSocketCommonRcConfigData)));
  164. InternalDumpHex (PcdGetPtr (PcdSocketCommonRcConfigData), PcdGetSize (PcdSocketCommonRcConfigData));
  165. DEBUG ((DEBUG_INFO, "PcdSocketMpLinkConfigData - 0x%x\n", PcdGetSize (PcdSocketMpLinkConfigData)));
  166. InternalDumpHex (PcdGetPtr (PcdSocketMpLinkConfigData), PcdGetSize (PcdSocketMpLinkConfigData));
  167. DEBUG ((DEBUG_INFO, "PcdSocketMemoryConfigData - 0x%x\n", PcdGetSize (PcdSocketMemoryConfigData)));
  168. InternalDumpHex (PcdGetPtr (PcdSocketMemoryConfigData), PcdGetSize (PcdSocketMemoryConfigData));
  169. DEBUG ((DEBUG_INFO, "PcdSocketPowerManagementConfigData - 0x%x\n", PcdGetSize (PcdSocketPowerManagementConfigData)));
  170. InternalDumpHex (PcdGetPtr (PcdSocketPowerManagementConfigData), PcdGetSize (PcdSocketPowerManagementConfigData));
  171. DEBUG ((DEBUG_INFO, "PcdSocketProcessorCoreConfigData - 0x%x\n", PcdGetSize (PcdSocketProcessorCoreConfigData)));
  172. InternalDumpHex (PcdGetPtr (PcdSocketProcessorCoreConfigData), PcdGetSize (PcdSocketProcessorCoreConfigData));
  173. }
  174. //
  175. // PEI entry point - SystemBoardPpi entry point
  176. //
  177. /**
  178. PEI system board PPI intialization main entry point. This will setup up a PPI that will handle providing system board level
  179. configuration for the platform.
  180. @param FileHandle Pointer to the PEIM FFS file header.
  181. @param PeiServices General purpose services available to every PEIM.
  182. @retval EFI_SUCCESS Operation completed successfully.
  183. @retval Otherwise System board initialization failed.
  184. **/
  185. EFI_STATUS
  186. EFIAPI
  187. SystemBoardPeiEntry (
  188. IN EFI_PEI_FILE_HANDLE FileHandle,
  189. IN CONST EFI_PEI_SERVICES **PeiServices
  190. )
  191. {
  192. EFI_STATUS Status;
  193. DEBUG ((EFI_D_ERROR, "--> SystemBoard PEI BoardDetection\n"));
  194. //DumpConfig ();
  195. //
  196. // Initialize system board information PPI
  197. //
  198. Status = PeiServicesInstallPpi(&mSystemBoardPpiDesc);
  199. ASSERT_EFI_ERROR (Status);
  200. return Status;
  201. }