IntelFsp2WrapperPkg: Support FSP Dispatch mode
[mirror_edk2.git] / IntelFsp2WrapperPkg / FspmWrapperPeim / FspmWrapperPeim.c
CommitLineData
cf1d4549
JY
1/** @file\r
2 This will be invoked only once. It will call FspMemoryInit API,\r
3 register TemporaryRamDonePpi to call TempRamExit API, and register MemoryDiscoveredPpi\r
4 notify to call FspSiliconInit API.\r
5\r
90c5bc08 6 Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>\r
cf1d4549
JY
7 This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php.\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17\r
18#include <PiPei.h>\r
19\r
20#include <Library/PeimEntryPoint.h>\r
21#include <Library/PeiServicesLib.h>\r
22#include <Library/PeiServicesTablePointerLib.h>\r
23#include <Library/BaseLib.h>\r
24#include <Library/DebugLib.h>\r
25#include <Library/BaseMemoryLib.h>\r
26#include <Library/MemoryAllocationLib.h>\r
27#include <Library/HobLib.h>\r
28#include <Library/PcdLib.h>\r
29#include <Library/TimerLib.h>\r
30#include <Library/PerformanceLib.h>\r
31#include <Library/FspWrapperPlatformLib.h>\r
32#include <Library/FspWrapperHobProcessLib.h>\r
33#include <Library/FspWrapperApiLib.h>\r
34\r
35#include <Ppi/FspSiliconInitDone.h>\r
36#include <Ppi/EndOfPeiPhase.h>\r
37#include <Ppi/MemoryDiscovered.h>\r
38#include <Ppi/SecPlatformInformation.h>\r
cf1d4549
JY
39#include <Library/FspWrapperApiTestLib.h>\r
40#include <FspEas.h>\r
19d29d35 41#include <FspStatusCode.h>\r
cf1d4549
JY
42\r
43extern EFI_GUID gFspHobGuid;\r
44\r
45/**\r
46 Call FspMemoryInit API.\r
47\r
48 @return Status returned by FspMemoryInit API.\r
49**/\r
50EFI_STATUS\r
51PeiFspMemoryInit (\r
52 VOID\r
53 )\r
54{\r
55 FSP_INFO_HEADER *FspmHeaderPtr;\r
56 EFI_STATUS Status;\r
57 UINT64 TimeStampCounterStart;\r
58 VOID *FspHobListPtr;\r
59 VOID *HobData;\r
60 FSPM_UPD_COMMON *FspmUpdDataPtr;\r
61 UINTN *SourceData;\r
62\r
63 DEBUG ((DEBUG_INFO, "PeiFspMemoryInit enter\n"));\r
64\r
65 FspHobListPtr = NULL;\r
e69dcef5 66 FspmUpdDataPtr = NULL;\r
cf1d4549 67\r
90c5bc08 68 FspmHeaderPtr = (FSP_INFO_HEADER *) FspFindFspHeader (PcdGet32 (PcdFspmBaseAddress));\r
599c45ff
HW
69 DEBUG ((DEBUG_INFO, "FspmHeaderPtr - 0x%x\n", FspmHeaderPtr));\r
70 if (FspmHeaderPtr == NULL) {\r
71 return EFI_DEVICE_ERROR;\r
72 }\r
73\r
e69dcef5
CC
74 if (PcdGet32 (PcdFspmUpdDataAddress) == 0 && (FspmHeaderPtr->CfgRegionSize != 0) && (FspmHeaderPtr->CfgRegionOffset != 0)) {\r
75 //\r
76 // Copy default FSP-M UPD data from Flash\r
77 //\r
78 FspmUpdDataPtr = (FSPM_UPD_COMMON *)AllocateZeroPool ((UINTN)FspmHeaderPtr->CfgRegionSize);\r
79 ASSERT (FspmUpdDataPtr != NULL);\r
80 SourceData = (UINTN *)((UINTN)FspmHeaderPtr->ImageBase + (UINTN)FspmHeaderPtr->CfgRegionOffset);\r
81 CopyMem (FspmUpdDataPtr, SourceData, (UINTN)FspmHeaderPtr->CfgRegionSize);\r
82 } else {\r
83 //\r
84 // External UPD is ready, get the buffer from PCD pointer.\r
85 //\r
86 FspmUpdDataPtr = (FSPM_UPD_COMMON *)PcdGet32 (PcdFspmUpdDataAddress);\r
87 ASSERT (FspmUpdDataPtr != NULL);\r
88 }\r
cf1d4549 89\r
1f1ec99d 90 DEBUG ((DEBUG_INFO, "UpdateFspmUpdData enter\n"));\r
cf1d4549
JY
91 UpdateFspmUpdData ((VOID *)FspmUpdDataPtr);\r
92 DEBUG ((DEBUG_INFO, " NvsBufferPtr - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.NvsBufferPtr));\r
93 DEBUG ((DEBUG_INFO, " StackBase - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.StackBase));\r
94 DEBUG ((DEBUG_INFO, " StackSize - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.StackSize));\r
95 DEBUG ((DEBUG_INFO, " BootLoaderTolumSize - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.BootLoaderTolumSize));\r
96 DEBUG ((DEBUG_INFO, " BootMode - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.BootMode));\r
97 DEBUG ((DEBUG_INFO, " HobListPtr - 0x%x\n", &FspHobListPtr));\r
98\r
99 TimeStampCounterStart = AsmReadTsc ();\r
100 Status = CallFspMemoryInit (FspmUpdDataPtr, &FspHobListPtr);\r
101 // Create hobs after memory initialization and not in temp RAM. Hence passing the recorded timestamp here\r
19d29d35
YS
102 PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, TimeStampCounterStart, FSP_STATUS_CODE_MEMORY_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_ENTRY);\r
103 PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, FSP_STATUS_CODE_MEMORY_INIT | FSP_STATUS_CODE_COMMON_CODE | FSP_STATUS_CODE_API_EXIT);\r
cf1d4549 104 DEBUG ((DEBUG_INFO, "Total time spent executing FspMemoryInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart), 1000000)));\r
f862a3b6
JY
105\r
106 //\r
107 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status\r
108 //\r
109 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {\r
110 DEBUG((DEBUG_INFO, "FspMemoryInitApi requested reset 0x%x\n", Status));\r
111 CallFspWrapperResetSystem ((UINT32)Status);\r
112 }\r
113\r
cf1d4549
JY
114 if (EFI_ERROR(Status)) {\r
115 DEBUG ((DEBUG_ERROR, "ERROR - Failed to execute FspMemoryInitApi(), Status = %r\n", Status));\r
116 }\r
117 DEBUG((DEBUG_INFO, "FspMemoryInit status: 0x%x\n", Status));\r
118 ASSERT_EFI_ERROR (Status);\r
119\r
120\r
121 Status = TestFspMemoryInitApiOutput (FspmUpdDataPtr, &FspHobListPtr);\r
122 if (EFI_ERROR (Status)) {\r
123 DEBUG ((DEBUG_ERROR, "ERROR - TestFspMemoryInitApiOutput () fail, Status = %r\n", Status));\r
124 }\r
125\r
126 DEBUG ((DEBUG_INFO, " FspHobListPtr (returned) - 0x%x\n", FspHobListPtr));\r
127 ASSERT (FspHobListPtr != NULL);\r
128\r
129 PostFspmHobProcess (FspHobListPtr);\r
130\r
131 //\r
132 // FspHobList is not complete at this moment.\r
133 // Save FspHobList pointer to hob, so that it can be got later\r
134 //\r
135 HobData = BuildGuidHob (\r
136 &gFspHobGuid,\r
137 sizeof (VOID *)\r
138 );\r
139 ASSERT (HobData != NULL);\r
140 CopyMem (HobData, &FspHobListPtr, sizeof (FspHobListPtr));\r
141\r
142 return Status;\r
143}\r
144\r
145/**\r
146 Do FSP initialization.\r
147\r
148 @return FSP initialization status.\r
149**/\r
150EFI_STATUS\r
151EFIAPI\r
152FspmWrapperInit (\r
153 VOID\r
154 )\r
155{\r
156 EFI_STATUS Status;\r
157\r
90c5bc08
CC
158 Status = EFI_SUCCESS;\r
159\r
160 if (FixedPcdGet8 (PcdFspModeSelection) == 1) {\r
161 Status = PeiFspMemoryInit ();\r
162 ASSERT_EFI_ERROR (Status);\r
163 } else {\r
164 PeiServicesInstallFvInfoPpi (\r
165 NULL,\r
166 (VOID *)(UINTN) PcdGet32 (PcdFspmBaseAddress),\r
167 (UINT32)((EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) PcdGet32 (PcdFspmBaseAddress))->FvLength,\r
168 NULL,\r
169 NULL\r
170 );\r
171 }\r
cf1d4549
JY
172\r
173 return Status;\r
174}\r
175\r
176/**\r
177 This is the entrypoint of PEIM\r
178\r
179 @param[in] FileHandle Handle of the file being invoked.\r
180 @param[in] PeiServices Describes the list of possible PEI Services.\r
181\r
182 @retval EFI_SUCCESS if it completed successfully.\r
183**/\r
184EFI_STATUS\r
185EFIAPI\r
186FspmWrapperPeimEntryPoint (\r
187 IN EFI_PEI_FILE_HANDLE FileHandle,\r
188 IN CONST EFI_PEI_SERVICES **PeiServices\r
189 )\r
190{\r
191 DEBUG((DEBUG_INFO, "FspmWrapperPeimEntryPoint\n"));\r
192\r
193 FspmWrapperInit ();\r
194\r
195 return EFI_SUCCESS;\r
196}\r