]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Pei/Hob/Hob.c
Add PeiCore module for enabling NT32Pkg, please attention this PeiCore does follows...
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Hob / Hob.c
1 /*++
2
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
8
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.
11
12 Module Name:
13
14 Hob.c
15
16 Abstract:
17
18 EFI PEI Core HOB services
19
20 --*/
21
22 //
23 // Include common header file for this module.
24 //
25 #include "CommonHeader.h"
26
27 #include <PeiMain.h>
28
29 EFI_STATUS
30 EFIAPI
31 PeiGetHobList (
32 IN EFI_PEI_SERVICES **PeiServices,
33 IN OUT VOID **HobList
34 )
35 /*++
36
37 Routine Description:
38
39 Gets the pointer to the HOB List.
40
41 Arguments:
42
43 PeiServices - The PEI core services table.
44 HobList - Pointer to the HOB List.
45
46 Returns:
47
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)
51
52 --*/
53 {
54 PEI_CORE_INSTANCE *PrivateData;
55
56
57 //
58 // Only check this parameter in debug mode
59 //
60
61 DEBUG_CODE_BEGIN ();
62 if (HobList == NULL) {
63 return EFI_INVALID_PARAMETER;
64 }
65 DEBUG_CODE_END ();
66
67 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);
68
69 *HobList = PrivateData->HobList.Raw;
70
71
72 return EFI_SUCCESS;
73 }
74
75
76 EFI_STATUS
77 EFIAPI
78 PeiCreateHob (
79 IN EFI_PEI_SERVICES **PeiServices,
80 IN UINT16 Type,
81 IN UINT16 Length,
82 IN OUT VOID **Hob
83 )
84 /*++
85
86 Routine Description:
87
88 Add a new HOB to the HOB List.
89
90 Arguments:
91
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.
96
97 Returns:
98
99 Status - EFI_SUCCESS
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.
103
104 --*/
105 {
106 EFI_STATUS Status;
107 EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
108 EFI_HOB_GENERIC_HEADER *HobEnd;
109 EFI_PHYSICAL_ADDRESS FreeMemory;
110
111
112 Status = PeiGetHobList (PeiServices, Hob);
113 if (EFI_ERROR(Status)) {
114 return Status;
115 }
116
117 HandOffHob = *Hob;
118
119 Length = (UINT16)((Length + 0x7) & (~0x7));
120
121 FreeMemory = HandOffHob->EfiFreeMemoryTop -
122 HandOffHob->EfiFreeMemoryBottom;
123
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;
129 }
130
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;
135
136 HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN) *Hob + Length);
137 HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
138
139 HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
140 HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);
141 HobEnd->Reserved = 0;
142 HobEnd++;
143 HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
144
145
146 return EFI_SUCCESS;
147 }
148
149
150 EFI_STATUS
151 PeiCoreBuildHobHandoffInfoTable (
152 IN EFI_BOOT_MODE BootMode,
153 IN EFI_PHYSICAL_ADDRESS MemoryBegin,
154 IN UINT64 MemoryLength
155 )
156 /*++
157
158 Routine Description:
159
160 Builds a Handoff Information Table HOB
161
162 Arguments:
163
164 BootMode - Current Bootmode
165 MemoryBegin - Start Memory Address.
166 MemoryLength - Length of Memory.
167
168 Returns:
169
170 EFI_SUCCESS
171
172 --*/
173 {
174 EFI_HOB_HANDOFF_INFO_TABLE *Hob;
175 EFI_HOB_GENERIC_HEADER *HobEnd;
176
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;
182
183 HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
184 HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);
185 HobEnd->Reserved = 0;
186
187 Hob->Version = EFI_HOB_HANDOFF_TABLE_VERSION;
188 Hob->BootMode = BootMode;
189
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;
195
196 return EFI_SUCCESS;
197 }