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