TianoCore EDK2 master
Loading...
Searching...
No Matches
UnitTestPeiServicesTablePointerLibHob.c
Go to the documentation of this file.
1
10
24EFIAPI
26 IN CONST EFI_PEI_SERVICES **PeiServices,
27 IN OUT VOID **HobList
28 )
29{
30 PEI_CORE_INSTANCE *PrivateData;
31
32 if (HobList == NULL) {
33 return EFI_INVALID_PARAMETER;
34 }
35
36 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
37
38 *HobList = PrivateData->HobList.Raw;
39
40 return EFI_SUCCESS;
41}
42
58EFIAPI
60 IN CONST EFI_PEI_SERVICES **PeiServices,
61 IN UINT16 Type,
62 IN UINT16 Length,
63 IN OUT VOID **Hob
64 )
65{
66 EFI_STATUS Status;
70
71 Status = UnitTestGetHobList (PeiServices, Hob);
72 if (EFI_ERROR (Status)) {
73 return Status;
74 }
75
76 HandOffHob = *Hob;
77
78 //
79 // Check Length to avoid data overflow.
80 //
81 if (0x10000 - Length <= 0x7) {
82 return EFI_INVALID_PARAMETER;
83 }
84
85 Length = (UINT16)((Length + 0x7) & (~0x7));
86
87 FreeMemory = HandOffHob->EfiFreeMemoryTop -
88 HandOffHob->EfiFreeMemoryBottom;
89
90 if (FreeMemory < Length) {
91 DEBUG ((DEBUG_ERROR, "PeiCreateHob fail: Length - 0x%08x\n", (UINTN)Length));
92 DEBUG ((DEBUG_ERROR, " FreeMemoryTop - 0x%08x\n", (UINTN)HandOffHob->EfiFreeMemoryTop));
93 DEBUG ((DEBUG_ERROR, " FreeMemoryBottom - 0x%08x\n", (UINTN)HandOffHob->EfiFreeMemoryBottom));
94 return EFI_OUT_OF_RESOURCES;
95 }
96
97 *Hob = (VOID *)(UINTN)HandOffHob->EfiEndOfHobList;
98 ((EFI_HOB_GENERIC_HEADER *)*Hob)->HobType = Type;
99 ((EFI_HOB_GENERIC_HEADER *)*Hob)->HobLength = Length;
100 ((EFI_HOB_GENERIC_HEADER *)*Hob)->Reserved = 0;
101
102 HobEnd = (EFI_HOB_GENERIC_HEADER *)((UINTN)*Hob + Length);
103 HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS)(UINTN)HobEnd;
104
105 HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
106 HobEnd->HobLength = (UINT16)sizeof (EFI_HOB_GENERIC_HEADER);
107 HobEnd->Reserved = 0;
108 HobEnd++;
109 HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS)(UINTN)HobEnd;
110
111 return EFI_SUCCESS;
112}
113
127 IN EFI_BOOT_MODE BootMode,
128 IN EFI_PHYSICAL_ADDRESS MemoryBegin,
129 IN UINT64 MemoryLength
130 )
131{
134
135 Hob = (VOID *)(UINTN)MemoryBegin;
136 HobEnd = (EFI_HOB_GENERIC_HEADER *)(Hob+1);
137 Hob->Header.HobType = EFI_HOB_TYPE_HANDOFF;
138 Hob->Header.HobLength = (UINT16)sizeof (EFI_HOB_HANDOFF_INFO_TABLE);
139 Hob->Header.Reserved = 0;
140
141 HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
142 HobEnd->HobLength = (UINT16)sizeof (EFI_HOB_GENERIC_HEADER);
143 HobEnd->Reserved = 0;
144
146 Hob->BootMode = BootMode;
147
148 Hob->EfiMemoryTop = MemoryBegin + MemoryLength;
149 Hob->EfiMemoryBottom = MemoryBegin;
150 Hob->EfiFreeMemoryTop = MemoryBegin + MemoryLength;
151 Hob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS)(UINTN)(HobEnd + 1);
153
154 return EFI_SUCCESS;
155}
UINT64 UINTN
VOID FreeMemory(VOID)
Definition: Compress.c:216
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
#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_STATUS EFIAPI UnitTestGetHobList(IN CONST EFI_PEI_SERVICES **PeiServices, IN OUT VOID **HobList)
EFI_STATUS UnitTestCoreBuildHobHandoffInfoTable(IN EFI_BOOT_MODE BootMode, IN EFI_PHYSICAL_ADDRESS MemoryBegin, IN UINT64 MemoryLength)
EFI_STATUS EFIAPI UnitTestCreateHob(IN CONST EFI_PEI_SERVICES **PeiServices, IN UINT16 Type, IN UINT16 Length, IN OUT VOID **Hob)
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