]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Pei/Memory/MemoryServices.c
remove a redefinition to pass ICC build
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Memory / MemoryServices.c
CommitLineData
615c6dd0 1/** @file\r
b1f6a7c6 2 EFI PEI Core memory services\r
3 \r
192f6d4c 4Copyright (c) 2006, Intel Corporation \r
5All rights reserved. This program and the accompanying materials \r
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
615c6dd0 13**/\r
192f6d4c 14\r
192f6d4c 15#include <PeiMain.h>\r
16\r
b1f6a7c6 17/**\r
192f6d4c 18\r
19 Initialize the memory services.\r
20\r
192f6d4c 21\r
b1f6a7c6 22 @param PrivateData Add parameter description\r
23 @param SecCoreData Points to a data structure containing information about the PEI core's operating\r
5aae0aa7 24 environment, such as the size and location of temporary RAM, the stack location and\r
25 the BFV location.\r
b1f6a7c6 26 @param OldCoreData Pointer to the PEI Core data.\r
192f6d4c 27 NULL if being run in non-permament memory mode.\r
28\r
b1f6a7c6 29**/\r
30VOID\r
31InitializeMemoryServices (\r
32 IN PEI_CORE_INSTANCE *PrivateData,\r
33 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r
34 IN PEI_CORE_INSTANCE *OldCoreData\r
35 )\r
192f6d4c 36{\r
58dcdada 37 \r
38 PrivateData->SwitchStackSignal = FALSE;\r
192f6d4c 39\r
40 if (OldCoreData == NULL) {\r
41\r
42 PrivateData->PeiMemoryInstalled = FALSE;\r
43\r
58dcdada 44 PrivateData->BottomOfCarHeap = SecCoreData->PeiTemporaryRamBase; \r
45 PrivateData->TopOfCarHeap = (VOID *)((UINTN)(PrivateData->BottomOfCarHeap) + SecCoreData->PeiTemporaryRamSize);\r
46 PrivateData->SizeOfTemporaryMemory = SecCoreData->TemporaryRamSize;\r
47 PrivateData->StackSize = (UINT64) SecCoreData->StackSize;\r
48 \r
192f6d4c 49 DEBUG_CODE_BEGIN ();\r
5aae0aa7 50 PrivateData->SizeOfCacheAsRam = SecCoreData->PeiTemporaryRamSize + SecCoreData->StackSize;\r
51 PrivateData->MaxTopOfCarHeap = (VOID *) ((UINTN) PrivateData->BottomOfCarHeap + (UINTN) PrivateData->SizeOfCacheAsRam);\r
b0d803fe 52 PrivateData->StackBase = (EFI_PHYSICAL_ADDRESS) (UINTN) SecCoreData->StackBase;\r
53 PrivateData->StackSize = (UINT64) SecCoreData->StackSize;\r
192f6d4c 54 DEBUG_CODE_END ();\r
55\r
56 PrivateData->HobList.Raw = PrivateData->BottomOfCarHeap;\r
57 \r
58 PeiCoreBuildHobHandoffInfoTable (\r
59 BOOT_WITH_FULL_CONFIGURATION,\r
60 (EFI_PHYSICAL_ADDRESS) (UINTN) PrivateData->BottomOfCarHeap,\r
5aae0aa7 61 (UINTN) SecCoreData->PeiTemporaryRamSize\r
192f6d4c 62 );\r
192f6d4c 63\r
64 //\r
65 // Set PS to point to ServiceTableShadow in Cache\r
66 //\r
67 PrivateData->PS = &(PrivateData->ServiceTableShadow);\r
b0d803fe 68 }\r
69 \r
192f6d4c 70 return;\r
71}\r
72\r
b1f6a7c6 73/**\r
74\r
75 Install the permanent memory is now available.\r
76 Creates HOB (PHIT and Stack).\r
77\r
78 @param PeiServices - The PEI core services table.\r
79 @param MemoryBegin - Start of memory address.\r
80 @param MemoryLength - Length of memory.\r
81\r
82 @return EFI_SUCCESS Always success.\r
83\r
84**/\r
192f6d4c 85EFI_STATUS\r
86EFIAPI\r
87PeiInstallPeiMemory (\r
58dcdada 88 IN CONST EFI_PEI_SERVICES **PeiServices,\r
89 IN EFI_PHYSICAL_ADDRESS MemoryBegin,\r
90 IN UINT64 MemoryLength\r
192f6d4c 91 )\r
192f6d4c 92{\r
93 PEI_CORE_INSTANCE *PrivateData;\r
58dcdada 94\r
a3a15d21 95 DEBUG ((EFI_D_INFO, "PeiInstallPeiMemory MemoryBegin 0x%LX, MemoryLength 0x%LX\n", MemoryBegin, MemoryLength));\r
192f6d4c 96 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
97\r
58dcdada 98 PrivateData->PhysicalMemoryBegin = MemoryBegin;\r
99 PrivateData->PhysicalMemoryLength = MemoryLength;\r
100 PrivateData->FreePhysicalMemoryTop = MemoryBegin + MemoryLength;\r
101 \r
102 PrivateData->SwitchStackSignal = TRUE;\r
192f6d4c 103\r
104 return EFI_SUCCESS; \r
105}\r
106\r
b1f6a7c6 107/**\r
108\r
109 Memory allocation service on permanent memory,\r
110 not usable prior to the memory installation.\r
111\r
112\r
113 @param PeiServices - The PEI core services table.\r
114 @param MemoryType - Type of memory to allocate.\r
115 @param Pages - Number of pages to allocate.\r
116 @param Memory - Pointer of memory allocated.\r
117\r
118 @retval EFI_SUCCESS The allocation was successful\r
119 @retval EFI_INVALID_PARAMETER Only AllocateAnyAddress is supported.\r
120 @retval EFI_NOT_AVAILABLE_YET Called with permanent memory not available\r
121 @retval EFI_OUT_OF_RESOURCES There is not enough HOB heap to satisfy the requirement\r
122 to allocate the number of pages.\r
123\r
124**/\r
192f6d4c 125EFI_STATUS\r
126EFIAPI\r
127PeiAllocatePages (\r
0c2b5da8 128 IN CONST EFI_PEI_SERVICES **PeiServices,\r
192f6d4c 129 IN EFI_MEMORY_TYPE MemoryType,\r
130 IN UINTN Pages,\r
131 OUT EFI_PHYSICAL_ADDRESS *Memory\r
132 )\r
192f6d4c 133{\r
134 PEI_CORE_INSTANCE *PrivateData;\r
135 EFI_PEI_HOB_POINTERS Hob;\r
136 EFI_PHYSICAL_ADDRESS Offset;\r
58dcdada 137 EFI_PHYSICAL_ADDRESS *FreeMemoryTop;\r
138 EFI_PHYSICAL_ADDRESS *FreeMemoryBottom;\r
192f6d4c 139\r
140 PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
58dcdada 141 Hob.Raw = PrivateData->HobList.Raw;\r
142 \r
192f6d4c 143 //\r
144 // Check if Hob already available\r
145 //\r
146 if (!PrivateData->PeiMemoryInstalled) {\r
58dcdada 147 //\r
148 // When PeiInstallMemory is called but CAR has *not* been moved to temporary memory,\r
149 // the AllocatePage will dependent the field of PEI_CORE_INSTANCE structure.\r
150 //\r
151 if (!PrivateData->SwitchStackSignal) {\r
152 return EFI_NOT_AVAILABLE_YET;\r
153 } else {\r
154 FreeMemoryTop = &(PrivateData->FreePhysicalMemoryTop);\r
155 FreeMemoryBottom = &(PrivateData->PhysicalMemoryBegin);\r
156 }\r
157 } else {\r
158 FreeMemoryTop = &(Hob.HandoffInformationTable->EfiFreeMemoryTop);\r
159 FreeMemoryBottom = &(Hob.HandoffInformationTable->EfiFreeMemoryBottom);\r
192f6d4c 160 }\r
161\r
58dcdada 162 \r
192f6d4c 163\r
164 //\r
165 // Check to see if on 4k boundary\r
166 //\r
58dcdada 167 Offset = *(FreeMemoryTop) & 0xFFF;\r
168 \r
192f6d4c 169 //\r
170 // If not aligned, make the allocation aligned.\r
171 //\r
172 if (Offset != 0) {\r
58dcdada 173 *(FreeMemoryTop) -= Offset;\r
192f6d4c 174 }\r
58dcdada 175 \r
192f6d4c 176 //\r
177 // Verify that there is sufficient memory to satisfy the allocation\r
178 //\r
58dcdada 179 if (*(FreeMemoryTop) - ((Pages * EFI_PAGE_SIZE) + sizeof (EFI_HOB_MEMORY_ALLOCATION)) < \r
180 *(FreeMemoryBottom)) {\r
192f6d4c 181 DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%x Pages is available.\n", Pages));\r
182 DEBUG ((EFI_D_ERROR, "There is only left 0x%x pages memory resource to be allocated.\n", \\r
58dcdada 183 EFI_SIZE_TO_PAGES ((UINTN) (*(FreeMemoryTop) - *(FreeMemoryBottom)))));\r
192f6d4c 184 return EFI_OUT_OF_RESOURCES;\r
185 } else {\r
186 //\r
187 // Update the PHIT to reflect the memory usage\r
188 //\r
58dcdada 189 *(FreeMemoryTop) -= Pages * EFI_PAGE_SIZE;\r
192f6d4c 190\r
191 //\r
192 // Update the value for the caller\r
193 //\r
58dcdada 194 *Memory = *(FreeMemoryTop);\r
192f6d4c 195\r
196 //\r
197 // Create a memory allocation HOB.\r
198 //\r
199 BuildMemoryAllocationHob (\r
58dcdada 200 *(FreeMemoryTop),\r
0a7d0741 201 Pages * EFI_PAGE_SIZE,\r
192f6d4c 202 MemoryType\r
203 );\r
204\r
205 return EFI_SUCCESS;\r
206 }\r
207}\r
208\r
b1f6a7c6 209/**\r
210\r
211 Memory allocation service on the CAR.\r
192f6d4c 212\r
b1f6a7c6 213\r
214 @param PeiServices - The PEI core services table.\r
215 @param Size - Amount of memory required\r
216 @param Buffer - Address of pointer to the buffer\r
217\r
218 @retval EFI_SUCCESS The allocation was successful\r
219 @retval EFI_OUT_OF_RESOURCES There is not enough heap to satisfy the requirement\r
220 to allocate the requested size.\r
221\r
222**/\r
192f6d4c 223EFI_STATUS\r
224EFIAPI\r
225PeiAllocatePool (\r
0c2b5da8 226 IN CONST EFI_PEI_SERVICES **PeiServices,\r
192f6d4c 227 IN UINTN Size,\r
228 OUT VOID **Buffer\r
229 )\r
192f6d4c 230{\r
231 EFI_STATUS Status;\r
232 EFI_HOB_MEMORY_POOL *Hob;\r
233\r
234 //\r
235 // If some "post-memory" PEIM wishes to allocate larger pool,\r
236 // it should use AllocatePages service instead.\r
237 //\r
238 ASSERT (Size < 0x10000 - sizeof (EFI_HOB_MEMORY_POOL));\r
239 Status = PeiServicesCreateHob (\r
240 EFI_HOB_TYPE_MEMORY_POOL,\r
241 (UINT16)(sizeof (EFI_HOB_MEMORY_POOL) + Size),\r
242 (VOID **)&Hob\r
243 );\r
244 *Buffer = Hob+1; \r
245\r
246\r
247 return Status;\r
248}\r