blob: f6ffecb2cafef4e203e5f516c10332fc2ef97093 [file] [log] [blame]
Vishal Bhoj82c80712015-12-15 21:13:33 +05301/** @file
2 In FSP API V1 mode, it will be invoked twice by pei core. In 1st entry, it will
3 call FspInit API. In 2nd entry, it will parse the hoblist from fsp and report
4 them into pei core.
5
6 Copyright (c) 2015, 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 "FspInitPei.h"
19
20/**
21 FSP Init continuation function.
22 Control will be returned to this callback function after FspInit API call.
23
24 @param[in] Status Status of the FSP INIT API
25 @param[in] HobListPtr Pointer to the HOB data structure defined in the PI specification.
26
27**/
28VOID
29ContinuationFunc (
30 IN EFI_STATUS Status,
31 IN VOID *HobListPtr
32 )
33{
34 EFI_BOOT_MODE BootMode;
35 UINT64 StackSize;
36 EFI_PHYSICAL_ADDRESS StackBase;
37
38 DEBUG ((DEBUG_INFO, "ContinuationFunc - %r\n", Status));
39 DEBUG ((DEBUG_INFO, "HobListPtr - 0x%x\n", HobListPtr));
40
41 if (Status != EFI_SUCCESS) {
42 CpuDeadLoop ();
43 }
44
45 //
46 // Can not call any PeiServices
47 //
48 BootMode = GetBootMode ();
49
50 GetStackInfo (BootMode, TRUE, &StackBase, &StackSize);
51 DEBUG ((DEBUG_INFO, "StackBase - 0x%x\n", StackBase));
52 DEBUG ((DEBUG_INFO, "StackSize - 0x%x\n", StackSize));
53 CallPeiCoreEntryPoint (
54 HobListPtr,
55 (VOID *)(UINTN)StackBase,
56 (VOID *)(UINTN)(StackBase + StackSize)
57 );
58}
59
60/**
61 Call FspInit API.
62
63 @param[in] FspHeader FSP header pointer.
64**/
65VOID
66PeiFspInit (
67 IN FSP_INFO_HEADER *FspHeader
68 )
69{
70 FSP_INIT_PARAMS FspInitParams;
71 FSP_INIT_RT_COMMON_BUFFER FspRtBuffer;
72 UINT8 FspUpdRgn[FixedPcdGet32 (PcdMaxUpdRegionSize)];
73 UINT32 UpdRegionSize;
74 EFI_BOOT_MODE BootMode;
75 UINT64 StackSize;
76 EFI_PHYSICAL_ADDRESS StackBase;
77 EFI_STATUS Status;
78
79 DEBUG ((DEBUG_INFO, "PeiFspInit enter\n"));
80
81 PeiServicesGetBootMode (&BootMode);
82 DEBUG ((DEBUG_INFO, "BootMode - 0x%x\n", BootMode));
83
84 GetStackInfo (BootMode, FALSE, &StackBase, &StackSize);
85 DEBUG ((DEBUG_INFO, "StackBase - 0x%x\n", StackBase));
86 DEBUG ((DEBUG_INFO, "StackSize - 0x%x\n", StackSize));
87
88 ZeroMem (&FspRtBuffer, sizeof(FspRtBuffer));
89 FspRtBuffer.StackTop = (UINT32 *)(UINTN)(StackBase + StackSize);
90
91 FspRtBuffer.BootMode = BootMode;
92
93 /* Platform override any UPD configs */
94 UpdRegionSize = GetUpdRegionSize();
95 DEBUG ((DEBUG_INFO, "UpdRegionSize - 0x%x\n", UpdRegionSize));
96 DEBUG ((DEBUG_INFO, "sizeof(FspUpdRgn) - 0x%x\n", sizeof(FspUpdRgn)));
97 ASSERT(sizeof(FspUpdRgn) >= UpdRegionSize);
98 ZeroMem (FspUpdRgn, UpdRegionSize);
99 FspRtBuffer.UpdDataRgnPtr = UpdateFspUpdConfigs (FspUpdRgn);
100
101 ZeroMem (&FspInitParams, sizeof(FspInitParams));
102 FspInitParams.NvsBufferPtr = GetNvsBuffer ();
103 DEBUG ((DEBUG_INFO, "NvsBufferPtr - 0x%x\n", FspInitParams.NvsBufferPtr));
104 FspInitParams.RtBufferPtr = (VOID *)&FspRtBuffer;
105 FspInitParams.ContinuationFunc = (CONTINUATION_PROC)ContinuationFunc;
106
107 SaveSecContext (GetPeiServicesTablePointer ());
108
109 DEBUG ((DEBUG_INFO, "FspInitParams - 0x%x\n", &FspInitParams));
110 DEBUG ((DEBUG_INFO, " NvsBufferPtr - 0x%x\n", FspInitParams.NvsBufferPtr));
111 DEBUG ((DEBUG_INFO, " RtBufferPtr - 0x%x\n", FspInitParams.RtBufferPtr));
112 DEBUG ((DEBUG_INFO, " StackTop - 0x%x\n", FspRtBuffer.StackTop));
113 DEBUG ((DEBUG_INFO, " BootMode - 0x%x\n", FspRtBuffer.BootMode));
114 DEBUG ((DEBUG_INFO, " UpdDataRgnPtr - 0x%x\n", FspRtBuffer.UpdDataRgnPtr));
115 DEBUG ((DEBUG_INFO, " ContinuationFunc - 0x%x\n", FspInitParams.ContinuationFunc));
116
117 Status = CallFspInit (FspHeader, &FspInitParams);
118 //
119 // Should never return
120 //
121 DEBUG((DEBUG_ERROR, "FSP Init failed, status: 0x%x\n", Status));
122 CpuDeadLoop ();
123}
124
125/**
126 Do FSP initialization based on FspApi version 1.
127
128 @param[in] FspHeader FSP header pointer.
129
130 @return FSP initialization status.
131**/
132EFI_STATUS
133PeiFspInitV1 (
134 IN FSP_INFO_HEADER *FspHeader
135 )
136{
137 EFI_STATUS Status;
138 FSP_INIT_DONE_PPI *FspInitDone;
139 VOID *FspHobList;
140 EFI_BOOT_MODE BootMode;
141
142 Status = PeiServicesLocatePpi (
143 &gFspInitDonePpiGuid,
144 0,
145 NULL,
146 (VOID **) &FspInitDone
147 );
148 if (EFI_ERROR (Status)) {
149 //
150 // 1st entry
151 //
152 DEBUG ((DEBUG_INFO, "1st entry\n"));
153
154 PeiFspInit (FspHeader);
155 //
156 // Never return here, for FspApi version 1.
157 //
158 CpuDeadLoop ();
159 } else {
160 //
161 // 2nd entry for FspApi version 1 only.
162 //
163 DEBUG ((DEBUG_INFO, "2nd entry\n"));
164
165 Status = FspInitDone->GetFspHobList (GetPeiServicesTablePointer (), FspInitDone, &FspHobList);
166 ASSERT_EFI_ERROR (Status);
167 DEBUG ((DEBUG_INFO, "FspHobList - 0x%x\n", FspHobList));
168 FspHobProcess (FspHobList);
169
170 //
171 // Register EndOfPei Notify for S3 to run FspNotifyPhase
172 //
173 PeiServicesGetBootMode (&BootMode);
174 if (BootMode == BOOT_ON_S3_RESUME) {
175 Status = PeiServicesNotifyPpi (&mS3EndOfPeiNotifyDesc);
176 ASSERT_EFI_ERROR (Status);
177 }
178 }
179
180 return EFI_SUCCESS;
181}