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