3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 EFI PEI Core HOB services
23 // Include common header file for this module.
25 #include "CommonHeader.h"
32 IN EFI_PEI_SERVICES
**PeiServices
,
39 Gets the pointer to the HOB List.
43 PeiServices - The PEI core services table.
44 HobList - Pointer to the HOB List.
48 EFI_SUCCESS - Get the pointer of HOB List
49 EFI_NOT_AVAILABLE_YET - the HOB List is not yet published
50 EFI_INVALID_PARAMETER - HobList is NULL (in debug mode)
54 PEI_CORE_INSTANCE
*PrivateData
;
58 // Only check this parameter in debug mode
62 if (HobList
== NULL
) {
63 return EFI_INVALID_PARAMETER
;
67 PrivateData
= PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices
);
69 *HobList
= PrivateData
->HobList
.Raw
;
79 IN EFI_PEI_SERVICES
**PeiServices
,
88 Add a new HOB to the HOB List.
92 PeiServices - The PEI core services table.
93 Type - Type of the new HOB.
94 Length - Length of the new HOB to allocate.
95 Hob - Pointer to the new HOB.
100 - EFI_INVALID_PARAMETER if Hob is NULL
101 - EFI_NOT_AVAILABLE_YET if HobList is still not available.
102 - EFI_OUT_OF_RESOURCES if there is no more memory to grow the Hoblist.
107 EFI_HOB_HANDOFF_INFO_TABLE
*HandOffHob
;
108 EFI_HOB_GENERIC_HEADER
*HobEnd
;
109 EFI_PHYSICAL_ADDRESS FreeMemory
;
112 Status
= PeiGetHobList (PeiServices
, Hob
);
113 if (EFI_ERROR(Status
)) {
119 Length
= (UINT16
)((Length
+ 0x7) & (~0x7));
121 FreeMemory
= HandOffHob
->EfiFreeMemoryTop
-
122 HandOffHob
->EfiFreeMemoryBottom
;
124 if (FreeMemory
< Length
) {
125 DEBUG ((EFI_D_ERROR
, "PeiCreateHob fail: Length - 0x%08x\n", (UINTN
)Length
));
126 DEBUG ((EFI_D_ERROR
, " FreeMemoryTop - 0x%08x\n", (UINTN
)HandOffHob
->EfiFreeMemoryTop
));
127 DEBUG ((EFI_D_ERROR
, " FreeMemoryBottom - 0x%08x\n", (UINTN
)HandOffHob
->EfiFreeMemoryBottom
));
128 return EFI_OUT_OF_RESOURCES
;
131 *Hob
= (VOID
*) (UINTN
) HandOffHob
->EfiEndOfHobList
;
132 ((EFI_HOB_GENERIC_HEADER
*) *Hob
)->HobType
= Type
;
133 ((EFI_HOB_GENERIC_HEADER
*) *Hob
)->HobLength
= Length
;
134 ((EFI_HOB_GENERIC_HEADER
*) *Hob
)->Reserved
= 0;
136 HobEnd
= (EFI_HOB_GENERIC_HEADER
*) ((UINTN
) *Hob
+ Length
);
137 HandOffHob
->EfiEndOfHobList
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) HobEnd
;
139 HobEnd
->HobType
= EFI_HOB_TYPE_END_OF_HOB_LIST
;
140 HobEnd
->HobLength
= sizeof(EFI_HOB_GENERIC_HEADER
);
141 HobEnd
->Reserved
= 0;
143 HandOffHob
->EfiFreeMemoryBottom
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) HobEnd
;
151 PeiCoreBuildHobHandoffInfoTable (
152 IN EFI_BOOT_MODE BootMode
,
153 IN EFI_PHYSICAL_ADDRESS MemoryBegin
,
154 IN UINT64 MemoryLength
160 Builds a Handoff Information Table HOB
164 BootMode - Current Bootmode
165 MemoryBegin - Start Memory Address.
166 MemoryLength - Length of Memory.
174 EFI_HOB_HANDOFF_INFO_TABLE
*Hob
;
175 EFI_HOB_GENERIC_HEADER
*HobEnd
;
177 Hob
= (VOID
*)(UINTN
)MemoryBegin
;
178 HobEnd
= (EFI_HOB_GENERIC_HEADER
*) (Hob
+1);
179 Hob
->Header
.HobType
= EFI_HOB_TYPE_HANDOFF
;
180 Hob
->Header
.HobLength
= sizeof(EFI_HOB_HANDOFF_INFO_TABLE
);
181 Hob
->Header
.Reserved
= 0;
183 HobEnd
->HobType
= EFI_HOB_TYPE_END_OF_HOB_LIST
;
184 HobEnd
->HobLength
= sizeof(EFI_HOB_GENERIC_HEADER
);
185 HobEnd
->Reserved
= 0;
187 Hob
->Version
= EFI_HOB_HANDOFF_TABLE_VERSION
;
188 Hob
->BootMode
= BootMode
;
190 Hob
->EfiMemoryTop
= MemoryBegin
+ MemoryLength
;
191 Hob
->EfiMemoryBottom
= MemoryBegin
;
192 Hob
->EfiFreeMemoryTop
= MemoryBegin
+ MemoryLength
;
193 Hob
->EfiFreeMemoryBottom
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) (HobEnd
+1);
194 Hob
->EfiEndOfHobList
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) HobEnd
;