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