1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
//*************************************************************************
//*************************************************************************
//** **
//** (C)Copyright 1985-2010, American Megatrends, Inc. **
//** **
//** All Rights Reserved. **
//** **
//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
//** **
//** Phone: (770)-246-8600 **
//** **
//*************************************************************************
//*************************************************************************
//**********************************************************************
// $Header: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBootHook.c 8 8/28/15 3:51a Tristinchou $
//
// $Revision: 8 $
//
// $Date: 8/28/15 3:51a $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/PEI Ram Boot/PeiRamBootHook.c $
//
// 8 8/28/15 3:51a Tristinchou
// [TAG] EIP235157
// [Category] Improvement
// [Description] Security vulnerability - PeiRamBoot: Should leave cold
// boot optimization only
//
// 7 6/21/11 2:22a Calvinchen
// ¡P Bug Fixed:
// Bug Fixed:
// 1. Build failed if Core 4.6.4.0.
// 2. System could hang if SAVE_ENTIRE_FV_TO_MEM = 1with AMD platform.
//
// 6 5/27/11 7:22a Calvinchen
// Build failed if Core 4.6.4.1.
//
// 5 4/25/11 3:59a Calvinchen
// Build failed if Core version greater than 4.6.4.1 with PI 0.91.
//
// 4 4/22/11 1:27a Calvinchen
//
// 3 3/22/11 7:52a Calvinchen
// [TAG] EIP56322
// [Category] Bug Fix
// [Severity] Normal
// [Symptom] System hangs after changing TPM settings in SETUP.
// [RootCause] System Memory Mappings are changed with warm boot.
// [Solution] BIOS always go cold boot path if system memory mappings
// are changed
// [Files] PeiRamBoot.sdl
// PeiRamBoot.mak
// PeiRamBoot.dxs
// PeiRamBoot.h
// PeiRamBoot.c
// PeiRamBootHook.c
// PeiRamBootDxe.c
// PeiRamBootOfbd.c
// PeiRamBoot.chm
// PeiRamBoot.cif
//
// 2 12/14/10 2:25a Calvinchen
// Improvement :
// 1. Added an eLink "PeiRamBootList" for fast warm boot support
// (PEI_RAM_BOOT_S3_SUPPORT = 1). If system boots in warm boot state, BIOS
// directly boot to previous copied ROM image in RAM to save time of
// copying ROM.
// 2. Added "PEI_RAM_BOOT_S3_SUPPORT" = "2" for saving runtime memory, it
// only keep necessary PEIM FFS in runtime memory for S3 resume
// improvement.
//
// 1 10/27/10 2:48a Calvinchen
// Initial Check-in.
//
//
//**********************************************************************
//<AMI_FHDR_START>
//
// Name: PeiRamBootHook.c
//
// Description: Hook file for PEI Ram Boot module.
//
//<AMI_FHDR_END>
//**********************************************************************
//----------------------------------------------------------------------------
// Includes
// Statements that include other files
#include <Tiano.h>
#include <PeiCore.h>
#include <Token.h>
#include <PeiRamBoot.h>
//----------------------------------------------------------------------------
// Function Externs
//----------------------------------------------------------------------------
// Local prototypes
//----------------------------------------------------------------------------
// Local Variables
//----------------------------------------------------------------------------
// Function Definitions
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
//
// Procedure: PeiDebugPrint
//
// Description: Worker function for debug print.
//
// Input: EFI_PEI_SERVICES** - PeiServices
// UINTN - ErrorLevel
// CHAR8* - Format
//
// Output: None.
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
#ifdef EFI_DEBUG
VOID
PeiDebugPrint (
#if ((PI_SPECIFICATION_VERSION >= 0x0001000A) || (CORE_COMBINED_VERSION > 262785))
#if (CORE_COMBINED_VERSION > 262785)
IN CONST EFI_PEI_SERVICES **PeiServices,
#else
IN EFI_PEI_SERVICES **PeiServices,
#endif
#else
IN EFI_PEI_SERVICES **PeiServices,
#endif
IN UINTN ErrorLevel,
IN CHAR8 *Format,
IN ...
)
{
CHAR8 Buffer[256];
va_list ArgList = va_start(ArgList,Format);
PrepareStatusCodeString( Buffer, sizeof(Buffer), Format, ArgList );
(*PeiServices)->ReportStatusCode (
(EFI_PEI_SERVICES**)PeiServices, EFI_DEBUG_CODE,
EFI_SOFTWARE_UNSPECIFIED, 0, NULL,
(EFI_STATUS_CODE_DATA *)Buffer
);
va_end(ArgList);
}
#endif
#if (PI_SPECIFICATION_VERSION >= 0x0001000A)
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
//
// Procedure: IsPeimDispatched
//
// Description:
//
// Input: EFI_PEI_SERVICES** - PeiServices
// EFI_PHYSICAL_ADDRESS - Buffer
//
// Output: None.
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
BOOLEAN
IsPeimDispatched (
IN EFI_PEI_SERVICES **PeiServices,
IN EFI_FFS_FILE_HEADER *FfsFile,
IN UINTN Index
)
{
PEI_CORE_INSTANCE *Private = NULL;
Private = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);
return Private->Fv[Private->CurrentPeimFvCount].PeimState[Index];
}
#else
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
//
// Procedure: GetDispatchedPeimBitMap
//
// Description: This procedure gets current PEIM dispatched BitMap from
// DispatchedData of Privatedata of PeiService.
//
// Input: EFI_PEI_SERVICES** - PeiServices
// EFI_PHYSICAL_ADDRESS - Buffer
//
// Output: None.
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
UINT64
GetDispatchedPeimBitMap (
IN EFI_PEI_SERVICES **PeiServices
)
{
PEI_CORE_INSTANCE *PrivateData = NULL;
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);
return PrivateData->DispatchData.DispatchedPeimBitMap;
}
#endif
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
//
// Procedure: SwitchPeiServiceDataToRam
//
// Description: This procedure redirect the FV Bass Address of Private data of
// PEI Service from ROM to RAM.
//
// Input: EFI_PEI_SERVICES** - PeiServices
// EFI_PHYSICAL_ADDRESS - Buffer
//
// Output: None.
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID
SwitchPeiServiceDataToRam (
IN EFI_PEI_SERVICES **PeiServices,
IN HOB_ROM_IMAGE *HobRomImage
)
{
PEI_CORE_INSTANCE *PrivateData = NULL;
EFI_PHYSICAL_ADDRESS FvAddress = 0, PeimAddress = 0, Buffer = 0;
EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList = NULL;
UINTN i = 0, j = 0, Index;
EFI_STATUS Status = EFI_SUCCESS;
EFI_FFS_FILE_HEADER *FfsFile = NULL;
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);
#if defined(PI_SPECIFICATION_VERSION) && (PI_SPECIFICATION_VERSION >= 0x0001000A)
for (i = 0, Index = 0; i < HobRomImage->NumOfFv; i++) {
Index = PrivateData->CurrentPeimFvCount;
FvAddress = \
(EFI_PHYSICAL_ADDRESS)PrivateData->Fv[Index].FvHeader;
if ((UINT32)FvAddress != HobRomImage->FvInfo[i].FvAddress) continue;
Buffer = HobRomImage->FvInfo[i].MemAddress;
PrivateData->Fv[Index].FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Buffer;
for (j = 0; (j < PEI_CORE_MAX_PEIM_PER_FV) && \
(PrivateData->CurrentFvFileHandles[j] != NULL); j++) {
PrivateData->CurrentFvFileHandles[j] = \
(EFI_PEI_FILE_HANDLE)(((UINTN)PrivateData->CurrentFvFileHandles[j] - \
(UINTN)FvAddress) + Buffer);
PrivateData->Fv[Index].FvFileHandles[j] = \
(EFI_PEI_FILE_HANDLE)(((UINTN)PrivateData->Fv[Index].FvFileHandles[j] - \
(UINTN)FvAddress) + Buffer);
}
}
#else // // PI 0.9 & 1.0
// Update PrivateData.DispatchData of PeiService.
FvAddress = (EFI_PHYSICAL_ADDRESS)PrivateData->DispatchData.BootFvAddress;
for (i = 0, Index = 0; i < HobRomImage->NumOfFv; i++) {
if ((UINT32)FvAddress != HobRomImage->FvInfo[i].FvAddress) continue;
Buffer = HobRomImage->FvInfo[i].MemAddress;
PrivateData->DispatchData.BootFvAddress = \
(EFI_FIRMWARE_VOLUME_HEADER*)(Buffer);
PrivateData->DispatchData.CurrentFvAddress = \
(EFI_FIRMWARE_VOLUME_HEADER*)(Buffer);
// CurrentPeimAddress point to last PEIM, so, dispatcher will start at
// the 1st in next time.
// find last FFS..
PeimAddress = (EFI_PHYSICAL_ADDRESS)PrivateData->DispatchData.CurrentPeimAddress;
PrivateData->DispatchData.CurrentPeimAddress = \
(EFI_FFS_FILE_HEADER*)(Buffer + (PeimAddress - FvAddress));
break;
}
#endif // PI 0.9 & 1.0
}
//*************************************************************************
//*************************************************************************
//** **
//** (C)Copyright 1985-2009, American Megatrends, Inc. **
//** **
//** All Rights Reserved. **
//** **
//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
//** **
//** Phone: (770)-246-8600 **
//** **
//*************************************************************************
//*************************************************************************
|