Enable Nt32 platform boot to DXE phase.
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Hob / Hob.c
CommitLineData
192f6d4c 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 Hob.c\r
15\r
16Abstract:\r
17\r
18 EFI PEI Core HOB services\r
19\r
20--*/\r
21\r
22//\r
23// Include common header file for this module.\r
24//\r
25#include "CommonHeader.h"\r
26\r
27#include <PeiMain.h>\r
28\r
29EFI_STATUS\r
30EFIAPI\r
31PeiGetHobList (\r
32 IN EFI_PEI_SERVICES **PeiServices,\r
33 IN OUT VOID **HobList\r
34 )\r
35/*++\r
36\r
37Routine Description:\r
38\r
39 Gets the pointer to the HOB List.\r
40\r
41Arguments:\r
42\r
43 PeiServices - The PEI core services table.\r
44 HobList - Pointer to the HOB List.\r
45\r
46Returns:\r
47\r
48 EFI_SUCCESS - Get the pointer of HOB List\r
49 EFI_NOT_AVAILABLE_YET - the HOB List is not yet published\r
50 EFI_INVALID_PARAMETER - HobList is NULL (in debug mode)\r
51 \r
52--*/\r
53{\r
54 PEI_CORE_INSTANCE *PrivateData;\r
55\r
56 \r
57 //\r
58 // Only check this parameter in debug mode\r
59 //\r
60 \r
61 DEBUG_CODE_BEGIN (); \r
62 if (HobList == NULL) {\r
63 return EFI_INVALID_PARAMETER;\r
64 }\r
65 DEBUG_CODE_END ();\r
66 \r
67 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);\r
68\r
69 *HobList = PrivateData->HobList.Raw;\r
70\r
71\r
72 return EFI_SUCCESS; \r
73}\r
74\r
75\r
76EFI_STATUS\r
77EFIAPI\r
78PeiCreateHob (\r
79 IN EFI_PEI_SERVICES **PeiServices,\r
80 IN UINT16 Type,\r
81 IN UINT16 Length,\r
82 IN OUT VOID **Hob\r
83 )\r
84/*++\r
85\r
86Routine Description:\r
87\r
88 Add a new HOB to the HOB List.\r
89\r
90Arguments:\r
91\r
92 PeiServices - The PEI core services table.\r
93 Type - Type of the new HOB.\r
94 Length - Length of the new HOB to allocate.\r
95 Hob - Pointer to the new HOB.\r
96\r
97Returns:\r
98\r
99 Status - EFI_SUCCESS\r
100 - EFI_INVALID_PARAMETER if Hob is NULL\r
101 - EFI_NOT_AVAILABLE_YET if HobList is still not available.\r
102 - EFI_OUT_OF_RESOURCES if there is no more memory to grow the Hoblist.\r
103 \r
104--*/\r
105{\r
106 EFI_STATUS Status;\r
107 EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;\r
108 EFI_HOB_GENERIC_HEADER *HobEnd;\r
109 EFI_PHYSICAL_ADDRESS FreeMemory;\r
110\r
111\r
112 Status = PeiGetHobList (PeiServices, Hob);\r
113 if (EFI_ERROR(Status)) {\r
114 return Status;\r
115 }\r
116\r
117 HandOffHob = *Hob;\r
118\r
119 Length = (UINT16)((Length + 0x7) & (~0x7));\r
120\r
121 FreeMemory = HandOffHob->EfiFreeMemoryTop -\r
122 HandOffHob->EfiFreeMemoryBottom;\r
123\r
124 if (FreeMemory < Length) {\r
125 DEBUG ((EFI_D_ERROR, "PeiCreateHob fail: Length - 0x%08x\n", (UINTN)Length));\r
126 DEBUG ((EFI_D_ERROR, " FreeMemoryTop - 0x%08x\n", (UINTN)HandOffHob->EfiFreeMemoryTop));\r
127 DEBUG ((EFI_D_ERROR, " FreeMemoryBottom - 0x%08x\n", (UINTN)HandOffHob->EfiFreeMemoryBottom));\r
128 return EFI_OUT_OF_RESOURCES;\r
129 }\r
130 \r
131 *Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList;\r
132 ((EFI_HOB_GENERIC_HEADER*) *Hob)->HobType = Type;\r
133 ((EFI_HOB_GENERIC_HEADER*) *Hob)->HobLength = Length;\r
134 ((EFI_HOB_GENERIC_HEADER*) *Hob)->Reserved = 0;\r
135\r
136 HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN) *Hob + Length);\r
137 HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r
138 \r
139 HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;\r
140 HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);\r
141 HobEnd->Reserved = 0;\r
142 HobEnd++;\r
143 HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r
144\r
145\r
146 return EFI_SUCCESS; \r
147}\r
148\r
149\r
150EFI_STATUS\r
151PeiCoreBuildHobHandoffInfoTable (\r
152 IN EFI_BOOT_MODE BootMode,\r
153 IN EFI_PHYSICAL_ADDRESS MemoryBegin,\r
154 IN UINT64 MemoryLength\r
155 )\r
156/*++\r
157\r
158Routine Description:\r
159\r
160 Builds a Handoff Information Table HOB\r
161\r
162Arguments:\r
163\r
164 BootMode - Current Bootmode\r
165 MemoryBegin - Start Memory Address.\r
166 MemoryLength - Length of Memory.\r
167\r
168Returns:\r
169\r
170 EFI_SUCCESS\r
171\r
172--*/\r
173{\r
174 EFI_HOB_HANDOFF_INFO_TABLE *Hob;\r
175 EFI_HOB_GENERIC_HEADER *HobEnd;\r
176\r
177 Hob = (VOID *)(UINTN)MemoryBegin;\r
178 HobEnd = (EFI_HOB_GENERIC_HEADER*) (Hob+1);\r
179 Hob->Header.HobType = EFI_HOB_TYPE_HANDOFF;\r
180 Hob->Header.HobLength = sizeof(EFI_HOB_HANDOFF_INFO_TABLE);\r
181 Hob->Header.Reserved = 0;\r
182 \r
183 HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;\r
184 HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);\r
185 HobEnd->Reserved = 0;\r
186\r
187 Hob->Version = EFI_HOB_HANDOFF_TABLE_VERSION;\r
188 Hob->BootMode = BootMode;\r
189 \r
190 Hob->EfiMemoryTop = MemoryBegin + MemoryLength;\r
191 Hob->EfiMemoryBottom = MemoryBegin;\r
192 Hob->EfiFreeMemoryTop = MemoryBegin + MemoryLength;\r
193 Hob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) (HobEnd+1);\r
194 Hob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r
195\r
196 return EFI_SUCCESS;\r
197}\r