FspMultiPhaseLib.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /** @file
  2. FSP MultiPhase library.
  3. Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <PiPei.h>
  7. #include <Library/FspCommonLib.h>
  8. #include <Library/FspSwitchStackLib.h>
  9. #include <Library/FspSecPlatformLib.h>
  10. #include <Library/DebugLib.h>
  11. #include <Library/PcdLib.h>
  12. #include <FspEas/FspApi.h>
  13. #include <FspGlobalData.h>
  14. EFI_STATUS
  15. EFIAPI
  16. FspMultiPhaseSwitchStack (
  17. )
  18. {
  19. SetFspApiReturnStatus (EFI_SUCCESS);
  20. Pei2LoaderSwitchStack ();
  21. return EFI_SUCCESS;
  22. }
  23. EFI_STATUS
  24. EFIAPI
  25. FspVariableRequestSwitchStack (
  26. IN FSP_MULTI_PHASE_VARIABLE_REQUEST_INFO_PARAMS *FspVariableRequestParams
  27. )
  28. {
  29. FSP_GLOBAL_DATA *FspData;
  30. FspData = GetFspGlobalDataPointer ();
  31. if (((UINTN)FspData == 0) || ((UINTN)FspData == 0xFFFFFFFF)) {
  32. return EFI_UNSUPPORTED;
  33. }
  34. FspData->VariableRequestParameterPtr = (VOID *)FspVariableRequestParams;
  35. SetFspApiReturnStatus (FSP_STATUS_VARIABLE_REQUEST);
  36. Pei2LoaderSwitchStack ();
  37. return EFI_SUCCESS;
  38. }
  39. /**
  40. This function supports FspMultiPhase implementation.
  41. @param[in] ApiIdx Internal index of the FSP API.
  42. @param[in] ApiParam Parameter of the FSP API.
  43. @retval EFI_SUCCESS FSP execution was successful.
  44. @retval EFI_INVALID_PARAMETER Input parameters are invalid.
  45. @retval EFI_UNSUPPORTED The FSP calling conditions were not met.
  46. @retval EFI_DEVICE_ERROR FSP initialization failed.
  47. **/
  48. EFI_STATUS
  49. EFIAPI
  50. FspMultiPhaseWorker (
  51. IN UINT32 ApiIdx,
  52. IN VOID *ApiParam
  53. )
  54. {
  55. FSP_MULTI_PHASE_PARAMS *FspMultiPhaseParams;
  56. FSP_GLOBAL_DATA *FspData;
  57. FSP_MULTI_PHASE_GET_NUMBER_OF_PHASES_PARAMS *FspMultiPhaseGetNumber;
  58. BOOLEAN FspDataValid;
  59. UINT32 NumberOfPhasesSupported;
  60. FspDataValid = TRUE;
  61. FspData = GetFspGlobalDataPointer ();
  62. if (((UINTN)FspData == 0) || ((UINTN)FspData == 0xFFFFFFFF)) {
  63. FspDataValid = FALSE;
  64. }
  65. //
  66. // It is required that FspData->NumberOfPhases to be reset to 0 after
  67. // current FSP component finished.
  68. // The next component FspData->NumberOfPhases will only be re-initialized when FspData->NumberOfPhases = 0
  69. //
  70. if ((FspDataValid == TRUE) && (FspData->NumberOfPhases == 0)) {
  71. FspData->NumberOfPhases = PcdGet32 (PcdMultiPhaseNumberOfPhases);
  72. FspData->PhasesExecuted = 0;
  73. if (FspMultiPhasePlatformGetNumberOfPhases (ApiIdx, &NumberOfPhasesSupported) == TRUE) {
  74. //
  75. // Platform has implemented runtime controlling for NumberOfPhasesSupported
  76. //
  77. FspData->NumberOfPhases = NumberOfPhasesSupported;
  78. }
  79. }
  80. FspMultiPhaseParams = (FSP_MULTI_PHASE_PARAMS *)ApiParam;
  81. if (FspDataValid == FALSE) {
  82. return EFI_DEVICE_ERROR;
  83. } else {
  84. switch (FspMultiPhaseParams->MultiPhaseAction) {
  85. case EnumMultiPhaseGetNumberOfPhases:
  86. if ((FspMultiPhaseParams->MultiPhaseParamPtr == NULL) || (FspMultiPhaseParams->PhaseIndex != 0)) {
  87. return EFI_INVALID_PARAMETER;
  88. }
  89. FspMultiPhaseGetNumber = (FSP_MULTI_PHASE_GET_NUMBER_OF_PHASES_PARAMS *)FspMultiPhaseParams->MultiPhaseParamPtr;
  90. FspMultiPhaseGetNumber->NumberOfPhases = FspData->NumberOfPhases;
  91. FspMultiPhaseGetNumber->PhasesExecuted = FspData->PhasesExecuted;
  92. break;
  93. case EnumMultiPhaseExecutePhase:
  94. if ((FspMultiPhaseParams->PhaseIndex > FspData->PhasesExecuted) && (FspMultiPhaseParams->PhaseIndex <= FspData->NumberOfPhases)) {
  95. FspData->PhasesExecuted = FspMultiPhaseParams->PhaseIndex;
  96. return Loader2PeiSwitchStack ();
  97. } else {
  98. return EFI_INVALID_PARAMETER;
  99. }
  100. break;
  101. case EnumMultiPhaseGetVariableRequestInfo:
  102. //
  103. // return variable request info
  104. //
  105. FspMultiPhaseParams->MultiPhaseParamPtr = FspData->VariableRequestParameterPtr;
  106. break;
  107. case EnumMultiPhaseCompleteVariableRequest:
  108. //
  109. // retrieve complete variable request params
  110. //
  111. FspData->VariableRequestParameterPtr = FspMultiPhaseParams->MultiPhaseParamPtr;
  112. return Loader2PeiSwitchStack ();
  113. break;
  114. default:
  115. return EFI_UNSUPPORTED;
  116. }
  117. }
  118. return EFI_SUCCESS;
  119. }
  120. /**
  121. This function handles FspMultiPhaseMemInitApi.
  122. @param[in] ApiIdx Internal index of the FSP API.
  123. @param[in] ApiParam Parameter of the FSP API.
  124. @retval EFI_SUCCESS FSP execution was successful.
  125. @retval EFI_INVALID_PARAMETER Input parameters are invalid.
  126. @retval EFI_UNSUPPORTED The FSP calling conditions were not met.
  127. @retval EFI_DEVICE_ERROR FSP initialization failed.
  128. **/
  129. EFI_STATUS
  130. EFIAPI
  131. FspMultiPhaseMemInitApiHandler (
  132. IN UINT32 ApiIdx,
  133. IN VOID *ApiParam
  134. )
  135. {
  136. return FspMultiPhaseWorker (ApiIdx, ApiParam);
  137. }
  138. /**
  139. This function handles FspMultiPhaseSiInitApi.
  140. @param[in] ApiIdx Internal index of the FSP API.
  141. @param[in] ApiParam Parameter of the FSP API.
  142. @retval EFI_SUCCESS FSP execution was successful.
  143. @retval EFI_INVALID_PARAMETER Input parameters are invalid.
  144. @retval EFI_UNSUPPORTED The FSP calling conditions were not met.
  145. @retval EFI_DEVICE_ERROR FSP initialization failed.
  146. **/
  147. EFI_STATUS
  148. EFIAPI
  149. FspMultiPhaseSiInitApiHandlerV2 (
  150. IN UINT32 ApiIdx,
  151. IN VOID *ApiParam
  152. )
  153. {
  154. return FspMultiPhaseWorker (ApiIdx, ApiParam);
  155. }