BaseTools/Capsule: Do not support -o with --dump-info
[mirror_edk2.git] / ArmPlatformPkg / MemoryInitPei / MemoryInitPeiLib.c
CommitLineData
3a6eaccf 1/** @file\r
2*\r
40a3f38f 3* Copyright (c) 2011-2015, ARM Limited. All rights reserved.\r
3a6eaccf 4*\r
5* This program and the accompanying materials\r
6* are licensed and made available under the terms and conditions of the BSD License\r
7* which accompanies this distribution. The full text of the license may be found at\r
8* http://opensource.org/licenses/bsd-license.php\r
9*\r
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12*\r
13**/\r
14\r
15#include <PiPei.h>\r
16\r
5db1cce1 17#include <Library/ArmMmuLib.h>\r
3a6eaccf 18#include <Library/ArmPlatformLib.h>\r
19#include <Library/DebugLib.h>\r
20#include <Library/HobLib.h>\r
21#include <Library/MemoryAllocationLib.h>\r
22#include <Library/PcdLib.h>\r
23\r
3a6eaccf 24VOID\r
25BuildMemoryTypeInformationHob (\r
26 VOID\r
27 );\r
28\r
40a3f38f 29STATIC\r
3a6eaccf 30VOID\r
31InitMmu (\r
40a3f38f 32 IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable\r
3a6eaccf 33 )\r
34{\r
40a3f38f 35\r
3a6eaccf 36 VOID *TranslationTableBase;\r
37 UINTN TranslationTableSize;\r
6f050ad6 38 RETURN_STATUS Status;\r
3a6eaccf 39\r
3a6eaccf 40 //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in\r
41 // DRAM (even at the top of DRAM as it is the first permanent memory allocation)\r
6f050ad6
OM
42 Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r
43 if (EFI_ERROR (Status)) {\r
44 DEBUG ((EFI_D_ERROR, "Error: Failed to enable MMU\n"));\r
45 }\r
3a6eaccf 46}\r
47\r
48/*++\r
49\r
50Routine Description:\r
51\r
52\r
53\r
54Arguments:\r
55\r
56 FileHandle - Handle of the file being invoked.\r
57 PeiServices - Describes the list of possible PEI Services.\r
58\r
59Returns:\r
60\r
61 Status - EFI_SUCCESS if the boot mode could be set\r
62\r
63--*/\r
64EFI_STATUS\r
65EFIAPI\r
66MemoryPeim (\r
67 IN EFI_PHYSICAL_ADDRESS UefiMemoryBase,\r
68 IN UINT64 UefiMemorySize\r
69 )\r
70{\r
40a3f38f
OM
71 ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;\r
72 EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;\r
e7f0a829 73 UINT64 ResourceLength;\r
40a3f38f 74 EFI_PEI_HOB_POINTERS NextHob;\r
e7f0a829
AB
75 EFI_PHYSICAL_ADDRESS FdTop;\r
76 EFI_PHYSICAL_ADDRESS SystemMemoryTop;\r
77 EFI_PHYSICAL_ADDRESS ResourceTop;\r
40a3f38f
OM
78 BOOLEAN Found;\r
79\r
80 // Get Virtual Memory Map from the Platform Library\r
81 ArmPlatformGetVirtualMemoryMap (&MemoryTable);\r
3a6eaccf 82\r
83 // Ensure PcdSystemMemorySize has been set\r
c357fd6a 84 ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);\r
3a6eaccf 85\r
3a6eaccf 86 //\r
87 // Now, the permanent memory has been installed, we can call AllocatePages()\r
88 //\r
d269095b 89 ResourceAttributes = (\r
3a6eaccf 90 EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
91 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
3a6eaccf 92 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r
93 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r
94 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |\r
95 EFI_RESOURCE_ATTRIBUTE_TESTED\r
96 );\r
97\r
40a3f38f
OM
98 //\r
99 // Check if the resource for the main system memory has been declared\r
100 //\r
101 Found = FALSE;\r
102 NextHob.Raw = GetHobList ();\r
103 while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) {\r
104 if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) &&\r
105 (PcdGet64 (PcdSystemMemoryBase) >= NextHob.ResourceDescriptor->PhysicalStart) &&\r
106 (NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength <= PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize)))\r
107 {\r
108 Found = TRUE;\r
109 break;\r
110 }\r
111 NextHob.Raw = GET_NEXT_HOB (NextHob);\r
112 }\r
113\r
114 if (!Found) {\r
115 // Reserved the memory space occupied by the firmware volume\r
116 BuildResourceDescriptorHob (\r
117 EFI_RESOURCE_SYSTEM_MEMORY,\r
118 ResourceAttributes,\r
119 PcdGet64 (PcdSystemMemoryBase),\r
120 PcdGet64 (PcdSystemMemorySize)\r
121 );\r
122 }\r
123\r
e7f0a829
AB
124 //\r
125 // Reserved the memory space occupied by the firmware volume\r
126 //\r
127\r
128 SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemorySize);\r
129 FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize);\r
130\r
131 // EDK2 does not have the concept of boot firmware copied into DRAM. To avoid the DXE\r
44d2e8d7
AB
132 // core to overwrite this area we must create a memory allocation HOB for the region,\r
133 // but this only works if we split off the underlying resource descriptor as well.\r
e7f0a829
AB
134 if ((PcdGet64 (PcdFdBaseAddress) >= PcdGet64 (PcdSystemMemoryBase)) && (FdTop <= SystemMemoryTop)) {\r
135 Found = FALSE;\r
136\r
137 // Search for System Memory Hob that contains the firmware\r
138 NextHob.Raw = GetHobList ();\r
139 while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) {\r
140 if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) &&\r
141 (PcdGet64 (PcdFdBaseAddress) >= NextHob.ResourceDescriptor->PhysicalStart) &&\r
142 (FdTop <= NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength))\r
143 {\r
144 ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute;\r
145 ResourceLength = NextHob.ResourceDescriptor->ResourceLength;\r
146 ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + ResourceLength;\r
147\r
148 if (PcdGet64 (PcdFdBaseAddress) == NextHob.ResourceDescriptor->PhysicalStart) {\r
44d2e8d7
AB
149 if (SystemMemoryTop != FdTop) {\r
150 // Create the System Memory HOB for the firmware\r
e7f0a829 151 BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,\r
44d2e8d7 152 ResourceAttributes,\r
e7f0a829
AB
153 PcdGet64 (PcdFdBaseAddress),\r
154 PcdGet32 (PcdFdSize));\r
155\r
156 // Top of the FD is system memory available for UEFI\r
157 NextHob.ResourceDescriptor->PhysicalStart += PcdGet32(PcdFdSize);\r
158 NextHob.ResourceDescriptor->ResourceLength -= PcdGet32(PcdFdSize);\r
159 }\r
160 } else {\r
44d2e8d7 161 // Create the System Memory HOB for the firmware\r
e7f0a829 162 BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,\r
44d2e8d7 163 ResourceAttributes,\r
e7f0a829
AB
164 PcdGet64 (PcdFdBaseAddress),\r
165 PcdGet32 (PcdFdSize));\r
166\r
167 // Update the HOB\r
168 NextHob.ResourceDescriptor->ResourceLength = PcdGet64 (PcdFdBaseAddress) - NextHob.ResourceDescriptor->PhysicalStart;\r
169\r
170 // If there is some memory available on the top of the FD then create a HOB\r
171 if (FdTop < NextHob.ResourceDescriptor->PhysicalStart + ResourceLength) {\r
172 // Create the System Memory HOB for the remaining region (top of the FD)\r
173 BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY,\r
174 ResourceAttributes,\r
175 FdTop,\r
176 ResourceTop - FdTop);\r
177 }\r
178 }\r
44d2e8d7
AB
179\r
180 // Mark the memory covering the Firmware Device as boot services data\r
181 BuildMemoryAllocationHob (PcdGet64 (PcdFdBaseAddress),\r
182 PcdGet32 (PcdFdSize),\r
183 EfiBootServicesData);\r
184\r
e7f0a829
AB
185 Found = TRUE;\r
186 break;\r
187 }\r
188 NextHob.Raw = GET_NEXT_HOB (NextHob);\r
189 }\r
190\r
191 ASSERT(Found);\r
192 }\r
193\r
3a6eaccf 194 // Build Memory Allocation Hob\r
40a3f38f 195 InitMmu (MemoryTable);\r
3a6eaccf 196\r
197 if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {\r
198 // Optional feature that helps prevent EFI memory map fragmentation.\r
199 BuildMemoryTypeInformationHob ();\r
200 }\r
201\r
202 return EFI_SUCCESS;\r
203}\r