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