0f6a7bdf40555bb7c5f5acb62dc8eb27fc5b4422
[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 - 2016, 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
42 extern EFI_GUID gFspHobGuid;
43
44 /**
45 Call FspMemoryInit API.
46
47 @return Status returned by FspMemoryInit API.
48 **/
49 EFI_STATUS
50 PeiFspMemoryInit (
51 VOID
52 )
53 {
54 FSP_INFO_HEADER *FspmHeaderPtr;
55 EFI_STATUS Status;
56 UINT64 TimeStampCounterStart;
57 VOID *FspHobListPtr;
58 VOID *HobData;
59 FSPM_UPD_COMMON *FspmUpdDataPtr;
60 UINTN *SourceData;
61
62 DEBUG ((DEBUG_INFO, "PeiFspMemoryInit enter\n"));
63
64 FspHobListPtr = NULL;
65
66 //
67 // Copy default FSP-M UPD data from Flash
68 //
69 FspmHeaderPtr = (FSP_INFO_HEADER *)FspFindFspHeader (PcdGet32 (PcdFspmBaseAddress));
70 DEBUG ((DEBUG_INFO, "FspmHeaderPtr - 0x%x\n", FspmHeaderPtr));
71 if (FspmHeaderPtr == NULL) {
72 return EFI_DEVICE_ERROR;
73 }
74
75 FspmUpdDataPtr = (FSPM_UPD_COMMON *)AllocateZeroPool ((UINTN)FspmHeaderPtr->CfgRegionSize);
76 ASSERT (FspmUpdDataPtr != NULL);
77 SourceData = (UINTN *)((UINTN)FspmHeaderPtr->ImageBase + (UINTN)FspmHeaderPtr->CfgRegionOffset);
78 CopyMem (FspmUpdDataPtr, SourceData, (UINTN)FspmHeaderPtr->CfgRegionSize);
79
80 DEBUG ((DEBUG_INFO, "UpdateFspmUpdData enter\n"));
81 UpdateFspmUpdData ((VOID *)FspmUpdDataPtr);
82 DEBUG ((DEBUG_INFO, " NvsBufferPtr - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.NvsBufferPtr));
83 DEBUG ((DEBUG_INFO, " StackBase - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.StackBase));
84 DEBUG ((DEBUG_INFO, " StackSize - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.StackSize));
85 DEBUG ((DEBUG_INFO, " BootLoaderTolumSize - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.BootLoaderTolumSize));
86 DEBUG ((DEBUG_INFO, " BootMode - 0x%x\n", FspmUpdDataPtr->FspmArchUpd.BootMode));
87 DEBUG ((DEBUG_INFO, " HobListPtr - 0x%x\n", &FspHobListPtr));
88
89 TimeStampCounterStart = AsmReadTsc ();
90 Status = CallFspMemoryInit (FspmUpdDataPtr, &FspHobListPtr);
91 // Create hobs after memory initialization and not in temp RAM. Hence passing the recorded timestamp here
92 PERF_START_EX(&gFspApiPerformanceGuid, "EventRec", NULL, TimeStampCounterStart, 0xD000);
93 PERF_END_EX(&gFspApiPerformanceGuid, "EventRec", NULL, 0, 0xD07F);
94 DEBUG ((DEBUG_INFO, "Total time spent executing FspMemoryInitApi: %d millisecond\n", DivU64x32 (GetTimeInNanoSecond (AsmReadTsc () - TimeStampCounterStart), 1000000)));
95
96 //
97 // Reset the system if FSP API returned FSP_STATUS_RESET_REQUIRED status
98 //
99 if ((Status >= FSP_STATUS_RESET_REQUIRED_COLD) && (Status <= FSP_STATUS_RESET_REQUIRED_8)) {
100 DEBUG((DEBUG_INFO, "FspMemoryInitApi requested reset 0x%x\n", Status));
101 CallFspWrapperResetSystem ((UINT32)Status);
102 }
103
104 if (EFI_ERROR(Status)) {
105 DEBUG ((DEBUG_ERROR, "ERROR - Failed to execute FspMemoryInitApi(), Status = %r\n", Status));
106 }
107 DEBUG((DEBUG_INFO, "FspMemoryInit status: 0x%x\n", Status));
108 ASSERT_EFI_ERROR (Status);
109
110
111 Status = TestFspMemoryInitApiOutput (FspmUpdDataPtr, &FspHobListPtr);
112 if (EFI_ERROR (Status)) {
113 DEBUG ((DEBUG_ERROR, "ERROR - TestFspMemoryInitApiOutput () fail, Status = %r\n", Status));
114 }
115
116 DEBUG ((DEBUG_INFO, " FspHobListPtr (returned) - 0x%x\n", FspHobListPtr));
117 ASSERT (FspHobListPtr != NULL);
118
119 PostFspmHobProcess (FspHobListPtr);
120
121 //
122 // FspHobList is not complete at this moment.
123 // Save FspHobList pointer to hob, so that it can be got later
124 //
125 HobData = BuildGuidHob (
126 &gFspHobGuid,
127 sizeof (VOID *)
128 );
129 ASSERT (HobData != NULL);
130 CopyMem (HobData, &FspHobListPtr, sizeof (FspHobListPtr));
131
132 return Status;
133 }
134
135 /**
136 Do FSP initialization.
137
138 @return FSP initialization status.
139 **/
140 EFI_STATUS
141 EFIAPI
142 FspmWrapperInit (
143 VOID
144 )
145 {
146 EFI_STATUS Status;
147
148 Status = PeiFspMemoryInit ();
149 ASSERT_EFI_ERROR (Status);
150
151 return Status;
152 }
153
154 /**
155 This is the entrypoint of PEIM
156
157 @param[in] FileHandle Handle of the file being invoked.
158 @param[in] PeiServices Describes the list of possible PEI Services.
159
160 @retval EFI_SUCCESS if it completed successfully.
161 **/
162 EFI_STATUS
163 EFIAPI
164 FspmWrapperPeimEntryPoint (
165 IN EFI_PEI_FILE_HANDLE FileHandle,
166 IN CONST EFI_PEI_SERVICES **PeiServices
167 )
168 {
169 DEBUG((DEBUG_INFO, "FspmWrapperPeimEntryPoint\n"));
170
171 FspmWrapperInit ();
172
173 return EFI_SUCCESS;
174 }