]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Pei/Hob/Hob.c
Update the copyright notice format
[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
cd5ebaa0
HT
4Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
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
92 Length = (UINT16)((Length + 0x7) & (~0x7));\r
93\r
94 FreeMemory = HandOffHob->EfiFreeMemoryTop -\r
95 HandOffHob->EfiFreeMemoryBottom;\r
96\r
97 if (FreeMemory < Length) {\r
98 DEBUG ((EFI_D_ERROR, "PeiCreateHob fail: Length - 0x%08x\n", (UINTN)Length));\r
99 DEBUG ((EFI_D_ERROR, " FreeMemoryTop - 0x%08x\n", (UINTN)HandOffHob->EfiFreeMemoryTop));\r
100 DEBUG ((EFI_D_ERROR, " FreeMemoryBottom - 0x%08x\n", (UINTN)HandOffHob->EfiFreeMemoryBottom));\r
101 return EFI_OUT_OF_RESOURCES;\r
102 }\r
103 \r
104 *Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList;\r
105 ((EFI_HOB_GENERIC_HEADER*) *Hob)->HobType = Type;\r
106 ((EFI_HOB_GENERIC_HEADER*) *Hob)->HobLength = Length;\r
107 ((EFI_HOB_GENERIC_HEADER*) *Hob)->Reserved = 0;\r
108\r
109 HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN) *Hob + Length);\r
110 HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r
111 \r
112 HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;\r
113 HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);\r
114 HobEnd->Reserved = 0;\r
115 HobEnd++;\r
116 HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r
117\r
192f6d4c 118 return EFI_SUCCESS; \r
119}\r
120\r
b1f6a7c6 121/**\r
122\r
123 Builds a Handoff Information Table HOB\r
124\r
125 @param BootMode - Current Bootmode\r
126 @param MemoryBegin - Start Memory Address.\r
127 @param MemoryLength - Length of Memory.\r
128\r
129 @return EFI_SUCCESS Always success to initialize HOB.\r
130\r
131**/\r
192f6d4c 132EFI_STATUS\r
133PeiCoreBuildHobHandoffInfoTable (\r
134 IN EFI_BOOT_MODE BootMode,\r
135 IN EFI_PHYSICAL_ADDRESS MemoryBegin,\r
136 IN UINT64 MemoryLength\r
137 )\r
192f6d4c 138{\r
139 EFI_HOB_HANDOFF_INFO_TABLE *Hob;\r
140 EFI_HOB_GENERIC_HEADER *HobEnd;\r
141\r
40f26b8f 142 Hob = (VOID *)(UINTN)MemoryBegin;\r
143 HobEnd = (EFI_HOB_GENERIC_HEADER*) (Hob+1);\r
144 Hob->Header.HobType = EFI_HOB_TYPE_HANDOFF;\r
145 Hob->Header.HobLength = sizeof(EFI_HOB_HANDOFF_INFO_TABLE);\r
146 Hob->Header.Reserved = 0;\r
192f6d4c 147 \r
40f26b8f 148 HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;\r
149 HobEnd->HobLength = sizeof(EFI_HOB_GENERIC_HEADER);\r
150 HobEnd->Reserved = 0;\r
192f6d4c 151\r
152 Hob->Version = EFI_HOB_HANDOFF_TABLE_VERSION;\r
153 Hob->BootMode = BootMode;\r
154 \r
155 Hob->EfiMemoryTop = MemoryBegin + MemoryLength;\r
156 Hob->EfiMemoryBottom = MemoryBegin;\r
157 Hob->EfiFreeMemoryTop = MemoryBegin + MemoryLength;\r
40f26b8f 158 Hob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN) (HobEnd + 1);\r
192f6d4c 159 Hob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN) HobEnd;\r
160\r
161 return EFI_SUCCESS;\r
162}\r