TianoCore EDK2 master
Loading...
Searching...
No Matches
Hob.c
Go to the documentation of this file.
1
9#include "PeiMain.h"
10
24EFIAPI
26 IN CONST EFI_PEI_SERVICES **PeiServices,
27 IN OUT VOID **HobList
28 )
29{
30 PEI_CORE_INSTANCE *PrivateData;
31
32 //
33 // Only check this parameter in debug mode
34 //
35 if (HobList == NULL) {
36 return EFI_INVALID_PARAMETER;
37 }
38
39 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
40
41 *HobList = PrivateData->HobList.Raw;
42
43 return EFI_SUCCESS;
44}
45
61EFIAPI
63 IN CONST EFI_PEI_SERVICES **PeiServices,
64 IN UINT16 Type,
65 IN UINT16 Length,
66 IN OUT VOID **Hob
67 )
68{
69 EFI_STATUS Status;
73
74 Status = PeiGetHobList (PeiServices, Hob);
75 if (EFI_ERROR (Status)) {
76 return Status;
77 }
78
79 HandOffHob = *Hob;
80
81 //
82 // Check Length to avoid data overflow.
83 //
84 if (0x10000 - Length <= 0x7) {
85 return EFI_INVALID_PARAMETER;
86 }
87
88 Length = (UINT16)((Length + 0x7) & (~0x7));
89
90 FreeMemory = HandOffHob->EfiFreeMemoryTop -
91 HandOffHob->EfiFreeMemoryBottom;
92
93 if (FreeMemory < Length) {
94 DEBUG ((DEBUG_ERROR, "PeiCreateHob fail: Length - 0x%08x\n", (UINTN)Length));
95 DEBUG ((DEBUG_ERROR, " FreeMemoryTop - 0x%08x\n", (UINTN)HandOffHob->EfiFreeMemoryTop));
96 DEBUG ((DEBUG_ERROR, " FreeMemoryBottom - 0x%08x\n", (UINTN)HandOffHob->EfiFreeMemoryBottom));
97 return EFI_OUT_OF_RESOURCES;
98 }
99
100 *Hob = (VOID *)(UINTN)HandOffHob->EfiEndOfHobList;
101 ((EFI_HOB_GENERIC_HEADER *)*Hob)->HobType = Type;
102 ((EFI_HOB_GENERIC_HEADER *)*Hob)->HobLength = Length;
103 ((EFI_HOB_GENERIC_HEADER *)*Hob)->Reserved = 0;
104
105 HobEnd = (EFI_HOB_GENERIC_HEADER *)((UINTN)*Hob + Length);
106 HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS)(UINTN)HobEnd;
107
108 HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
109 HobEnd->HobLength = (UINT16)sizeof (EFI_HOB_GENERIC_HEADER);
110 HobEnd->Reserved = 0;
111 HobEnd++;
112 HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS)(UINTN)HobEnd;
113
114 return EFI_SUCCESS;
115}
116
129 IN CONST EFI_PEI_SERVICES **PeiServices,
130 IN EFI_HOB_GENERIC_HEADER *SecHobList
131 )
132{
133 EFI_STATUS Status;
134 EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
135 EFI_PEI_HOB_POINTERS HobStart;
137 UINTN SecHobListLength;
140
141 HandOffHob = NULL;
142 Status = PeiGetHobList (PeiServices, (VOID **)&HandOffHob);
143 if (EFI_ERROR (Status)) {
144 return Status;
145 }
146
147 ASSERT (HandOffHob != NULL);
148
149 HobStart.Raw = (UINT8 *)SecHobList;
150 //
151 // The HobList must not contain a EFI_HOB_HANDOFF_INFO_TABLE HOB (PHIT) HOB.
152 //
153 ASSERT (HobStart.Header->HobType != EFI_HOB_TYPE_HANDOFF);
154 //
155 // Calculate the SEC HOB List length,
156 // not including the terminated HOB(EFI_HOB_TYPE_END_OF_HOB_LIST).
157 //
158 for (Hob.Raw = HobStart.Raw; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
159 }
160
161 SecHobListLength = (UINTN)Hob.Raw - (UINTN)HobStart.Raw;
162 //
163 // The length must be 8-bytes aligned.
164 //
165 ASSERT ((SecHobListLength & 0x7) == 0);
166
167 FreeMemory = HandOffHob->EfiFreeMemoryTop -
168 HandOffHob->EfiFreeMemoryBottom;
169
170 if (FreeMemory < SecHobListLength) {
171 DEBUG ((DEBUG_ERROR, "PeiInstallSecHobData fail: SecHobListLength - 0x%08x\n", SecHobListLength));
172 DEBUG ((DEBUG_ERROR, " FreeMemoryTop - 0x%08x\n", (UINTN)HandOffHob->EfiFreeMemoryTop));
173 DEBUG ((DEBUG_ERROR, " FreeMemoryBottom - 0x%08x\n", (UINTN)HandOffHob->EfiFreeMemoryBottom));
174 return EFI_OUT_OF_RESOURCES;
175 }
176
177 Hob.Raw = (UINT8 *)(UINTN)HandOffHob->EfiEndOfHobList;
178 CopyMem (Hob.Raw, HobStart.Raw, SecHobListLength);
179
180 HobEnd = (EFI_HOB_GENERIC_HEADER *)((UINTN)Hob.Raw + SecHobListLength);
181 HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS)(UINTN)HobEnd;
182
183 HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
184 HobEnd->HobLength = (UINT16)sizeof (EFI_HOB_GENERIC_HEADER);
185 HobEnd->Reserved = 0;
186 HobEnd++;
187 HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS)(UINTN)HobEnd;
188
189 return EFI_SUCCESS;
190}
191
201VOID
203 IN EFI_BOOT_MODE BootMode,
204 IN EFI_PHYSICAL_ADDRESS MemoryBegin,
205 IN UINT64 MemoryLength
206 )
207{
210
211 Hob = (VOID *)(UINTN)MemoryBegin;
212 HobEnd = (EFI_HOB_GENERIC_HEADER *)(Hob+1);
213 Hob->Header.HobType = EFI_HOB_TYPE_HANDOFF;
214 Hob->Header.HobLength = (UINT16)sizeof (EFI_HOB_HANDOFF_INFO_TABLE);
215 Hob->Header.Reserved = 0;
216
217 HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
218 HobEnd->HobLength = (UINT16)sizeof (EFI_HOB_GENERIC_HEADER);
219 HobEnd->Reserved = 0;
220
222 Hob->BootMode = BootMode;
223
224 Hob->EfiMemoryTop = MemoryBegin + MemoryLength;
225 Hob->EfiMemoryBottom = MemoryBegin;
226 Hob->EfiFreeMemoryTop = MemoryBegin + MemoryLength;
227 Hob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS)(UINTN)(HobEnd + 1);
229}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID FreeMemory(VOID)
Definition: Compress.c:216
EFI_STATUS EFIAPI PeiGetHobList(IN CONST EFI_PEI_SERVICES **PeiServices, IN OUT VOID **HobList)
Definition: Hob.c:25
VOID PeiCoreBuildHobHandoffInfoTable(IN EFI_BOOT_MODE BootMode, IN EFI_PHYSICAL_ADDRESS MemoryBegin, IN UINT64 MemoryLength)
Definition: Hob.c:202
EFI_STATUS PeiInstallSecHobData(IN CONST EFI_PEI_SERVICES **PeiServices, IN EFI_HOB_GENERIC_HEADER *SecHobList)
Definition: Hob.c:128
EFI_STATUS EFIAPI PeiCreateHob(IN CONST EFI_PEI_SERVICES **PeiServices, IN UINT16 Type, IN UINT16 Length, IN OUT VOID **Hob)
Definition: Hob.c:62
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define VOID
Definition: Base.h:269
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:435
#define PEI_CORE_INSTANCE_FROM_PS_THIS(a)
Definition: PeiMain.h:343
UINT32 EFI_BOOT_MODE
Definition: PiBootMode.h:18
#define EFI_HOB_HANDOFF_TABLE_VERSION
Definition: PiHob.h:54
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_MODE BootMode
Definition: PiHob.h:74
EFI_PHYSICAL_ADDRESS EfiFreeMemoryBottom
Definition: PiHob.h:92
EFI_PHYSICAL_ADDRESS EfiMemoryTop
Definition: PiHob.h:79
EFI_PHYSICAL_ADDRESS EfiFreeMemoryTop
Definition: PiHob.h:88
EFI_PHYSICAL_ADDRESS EfiMemoryBottom
Definition: PiHob.h:83
EFI_HOB_GENERIC_HEADER Header
Definition: PiHob.h:64
EFI_PHYSICAL_ADDRESS EfiEndOfHobList
Definition: PiHob.h:96