]> git.proxmox.com Git - mirror_edk2.git/blob - EdkModulePkg/Core/Pei/Hob/Hob.c
259d44b457cd5a7c1a31955e6fea953c77433ef7
[mirror_edk2.git] / EdkModulePkg / 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 #include <PeiMain.h>
23
24 EFI_STATUS
25 EFIAPI
26 PeiGetHobList (
27 IN EFI_PEI_SERVICES **PeiServices,
28 IN OUT VOID **HobList
29 )
30 /*++
31
32 Routine Description:
33
34 Gets the pointer to the HOB List.
35
36 Arguments:
37
38 PeiServices - The PEI core services table.
39 HobList - Pointer to the HOB List.
40
41 Returns:
42
43 EFI_SUCCESS - Get the pointer of HOB List
44 EFI_NOT_AVAILABLE_YET - the HOB List is not yet published
45 EFI_INVALID_PARAMETER - HobList is NULL (in debug mode)
46
47 --*/
48 {
49 PEI_CORE_INSTANCE *PrivateData;
50
51
52 //
53 // Only check this parameter in debug mode
54 //
55
56 DEBUG_CODE_BEGIN ();
57 if (HobList == NULL) {
58 return EFI_INVALID_PARAMETER;
59 }
60 DEBUG_CODE_END ();
61
62 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS(PeiServices);
63
64 *HobList = PrivateData->HobList.Raw;
65
66
67 return EFI_SUCCESS;
68 }
69
70
71 EFI_STATUS
72 EFIAPI
73 PeiCreateHob (
74 IN EFI_PEI_SERVICES **PeiServices,
75 IN UINT16 Type,
76 IN UINT16 Length,
77 IN OUT VOID **Hob
78 )
79 /*++
80
81 Routine Description:
82
83 Add a new HOB to the HOB List.
84
85 Arguments:
86
87 PeiServices - The PEI core services table.
88 Type - Type of the new HOB.
89 Length - Length of the new HOB to allocate.
90 Hob - Pointer to the new HOB.
91
92 Returns:
93
94 Status - EFI_SUCCESS
95 - EFI_INVALID_PARAMETER if Hob is NULL
96 - EFI_NOT_AVAILABLE_YET if HobList is still not available.
97 - EFI_OUT_OF_RESOURCES if there is no more memory to grow the Hoblist.
98
99 --*/
100 {
101 EFI_STATUS Status;
102 EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;
103 EFI_HOB_GENERIC_HEADER *HobEnd;
104 EFI_PHYSICAL_ADDRESS FreeMemory;
105
106
107 Status = PeiGetHobList (PeiServices, Hob);
108 if (EFI_ERROR(Status)) {
109 return Status;
110 }
111
112 HandOffHob = *Hob;
113
114 Length = (UINT16)((Length + 0x7) & (~0x7));
115
116 FreeMemory = HandOffHob->EfiFreeMemoryTop -
117 HandOffHob->EfiFreeMemoryBottom;
118
119 if (FreeMemory < Length) {
120 return EFI_OUT_OF_RESOURCES;
121 }
122
123 *Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList;
124 ((EFI_HOB_GENERIC_HEADER*) *Hob)->HobType = Type;
125 ((EFI_HOB_GENERIC_HEADER*) *Hob)->HobLength = Length;
126 ((EFI_HOB_GENERIC_HEADER*) *Hob)->Reserved = 0;
127
128 HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN) *Hob + Length);
129 HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
130
131 HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
132 HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);
133 HobEnd->Reserved = 0;
134 HobEnd++;
135 HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
136
137
138 return EFI_SUCCESS;
139 }
140
141
142 EFI_STATUS
143 PeiCoreBuildHobHandoffInfoTable (
144 IN EFI_BOOT_MODE BootMode,
145 IN EFI_PHYSICAL_ADDRESS MemoryBegin,
146 IN UINT64 MemoryLength
147 )
148 /*++
149
150 Routine Description:
151
152 Builds a Handoff Information Table HOB
153
154 Arguments:
155
156 BootMode - Current Bootmode
157 MemoryBegin - Start Memory Address.
158 MemoryLength - Length of Memory.
159
160 Returns:
161
162 EFI_SUCCESS
163
164 --*/
165 {
166 EFI_HOB_HANDOFF_INFO_TABLE *Hob;
167 EFI_HOB_GENERIC_HEADER *HobEnd;
168
169 Hob = (VOID *)(UINTN)MemoryBegin;
170 HobEnd = (EFI_HOB_GENERIC_HEADER*) (Hob+1);
171 Hob->Header.HobType = EFI_HOB_TYPE_HANDOFF;
172 Hob->Header.HobLength = sizeof(EFI_HOB_HANDOFF_INFO_TABLE);
173 Hob->Header.Reserved = 0;
174
175 HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;
176 HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);
177 HobEnd->Reserved = 0;
178
179 Hob->Version = EFI_HOB_HANDOFF_TABLE_VERSION;
180 Hob->BootMode = BootMode;
181
182 Hob->EfiMemoryTop = MemoryBegin + MemoryLength;
183 Hob->EfiMemoryBottom = MemoryBegin;
184 Hob->EfiFreeMemoryTop = MemoryBegin + MemoryLength;
185 Hob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) (HobEnd+1);
186 Hob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;
187
188 return EFI_SUCCESS;
189 }