]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c
ArmPkg: Move ARM Platform drivers from ArmPkg/Drivers/ to ArmPlatformPkg/Drivers/
[mirror_edk2.git] / ArmPlatformPkg / MemoryInitPei / MemoryInitPeiLib.c
CommitLineData
3a6eaccf 1/** @file\r
2*\r
3* Copyright (c) 2011, ARM Limited. All rights reserved.\r
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
17#include <Library/ArmPlatformLib.h>\r
18#include <Library/DebugLib.h>\r
19#include <Library/HobLib.h>\r
20#include <Library/MemoryAllocationLib.h>\r
21#include <Library/PcdLib.h>\r
22\r
23#include <Chipset/ArmV7.h>\r
24\r
25VOID\r
26BuildMemoryTypeInformationHob (\r
27 VOID\r
28 );\r
29\r
30VOID\r
31InitMmu (\r
32 VOID\r
33 )\r
34{\r
35 ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;\r
36 VOID *TranslationTableBase;\r
37 UINTN TranslationTableSize;\r
38\r
39 // Get Virtual Memory Map from the Platform Library\r
40 ArmPlatformGetVirtualMemoryMap(&MemoryTable);\r
41\r
42 //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in\r
43 // DRAM (even at the top of DRAM as it is the first permanent memory allocation)\r
44 ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r
45}\r
46\r
47/*++\r
48\r
49Routine Description:\r
50\r
51\r
52\r
53Arguments:\r
54\r
55 FileHandle - Handle of the file being invoked.\r
56 PeiServices - Describes the list of possible PEI Services.\r
57\r
58Returns:\r
59\r
60 Status - EFI_SUCCESS if the boot mode could be set\r
61\r
62--*/\r
63EFI_STATUS\r
64EFIAPI\r
65MemoryPeim (\r
66 IN EFI_PHYSICAL_ADDRESS UefiMemoryBase,\r
67 IN UINT64 UefiMemorySize\r
68 )\r
69{\r
70 EFI_STATUS Status;\r
71 EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;\r
72 ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR* EfiMemoryMap;\r
73 UINTN Index;\r
74 EFI_PHYSICAL_ADDRESS SystemMemoryTop;\r
75\r
76 // Ensure PcdSystemMemorySize has been set\r
77 ASSERT (PcdGet32 (PcdSystemMemorySize) != 0);\r
78\r
79 SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)((UINT32)PcdGet32 (PcdSystemMemoryBase) + (UINT32)PcdGet32 (PcdSystemMemorySize));\r
80\r
81 //\r
82 // Now, the permanent memory has been installed, we can call AllocatePages()\r
83 //\r
84 Attributes = (\r
85 EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
86 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
87 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |\r
88 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r
89 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r
90 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |\r
91 EFI_RESOURCE_ATTRIBUTE_TESTED\r
92 );\r
93\r
94 // If it is not a standalone build we must reserved the space above the base address of the firmware volume\r
95 if (!PcdGet32(PcdStandalone)) {\r
96 // Check if firmware volume has not be copied at the top of DRAM then we must reserve the extra space\r
97 // between the firmware and the top\r
98 if (SystemMemoryTop != PcdGet32 (PcdNormalFdBaseAddress) + PcdGet32 (PcdNormalFdSize)) {\r
99 BuildResourceDescriptorHob (\r
100 EFI_RESOURCE_SYSTEM_MEMORY,\r
101 Attributes & (~EFI_RESOURCE_ATTRIBUTE_TESTED),\r
102 PcdGet32 (PcdNormalFdBaseAddress) + PcdGet32 (PcdNormalFdSize),\r
103 SystemMemoryTop - (PcdGet32 (PcdNormalFdBaseAddress) + PcdGet32 (PcdNormalFdSize))\r
104 );\r
105 }\r
106\r
107 // Reserved the memory space occupied by the firmware volume\r
108 BuildResourceDescriptorHob (\r
109 EFI_RESOURCE_SYSTEM_MEMORY,\r
110 Attributes & (~EFI_RESOURCE_ATTRIBUTE_PRESENT),\r
111 (UINT32)PcdGet32 (PcdNormalFdBaseAddress),\r
112 (UINT32)PcdGet32 (PcdNormalFdSize)\r
113 );\r
114 }\r
115\r
116 // Check there is no overlap between UEFI and Fix Address Regions\r
117 ASSERT (PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemoryFixRegionSize) <= UefiMemoryBase);\r
118\r
119 // Reserved the UEFI Memory Region\r
120 BuildResourceDescriptorHob (\r
121 EFI_RESOURCE_SYSTEM_MEMORY,\r
122 Attributes,\r
123 UefiMemoryBase,\r
124 UefiMemorySize\r
125 );\r
126\r
127 // Reserved the Fix Address Region\r
128 BuildResourceDescriptorHob (\r
129 EFI_RESOURCE_SYSTEM_MEMORY,\r
130 Attributes,\r
131 PcdGet32 (PcdSystemMemoryBase),\r
132 PcdGet32 (PcdSystemMemoryFixRegionSize)\r
133 );\r
134\r
135 // Reserved the memory between UEFI and Fix Address regions\r
136 if (PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemoryFixRegionSize) != UefiMemoryBase) {\r
137 BuildResourceDescriptorHob (\r
138 EFI_RESOURCE_SYSTEM_MEMORY,\r
139 Attributes & (~EFI_RESOURCE_ATTRIBUTE_TESTED),\r
140 PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemoryFixRegionSize),\r
141 UefiMemoryBase - (PcdGet32 (PcdSystemMemoryBase) + PcdGet32 (PcdSystemMemoryFixRegionSize))\r
142 );\r
143 }\r
144\r
145 // If a platform has system memory extensions, it can declare those in this function\r
146 Status = ArmPlatformGetAdditionalSystemMemory (&EfiMemoryMap);\r
147 if (!EFI_ERROR(Status)) {\r
148 // Install the EFI Memory Map\r
149 for (Index = 0; EfiMemoryMap[Index].ResourceAttribute != 0; Index++) {\r
150 BuildResourceDescriptorHob (\r
151 EFI_RESOURCE_SYSTEM_MEMORY,\r
152 EfiMemoryMap[Index].ResourceAttribute,\r
153 EfiMemoryMap[Index].PhysicalStart,\r
154 EfiMemoryMap[Index].NumberOfBytes\r
155 );\r
156 }\r
157 FreePool (EfiMemoryMap);\r
158 }\r
159\r
160 // Build Memory Allocation Hob\r
161 InitMmu ();\r
162\r
163 if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {\r
164 // Optional feature that helps prevent EFI memory map fragmentation.\r
165 BuildMemoryTypeInformationHob ();\r
166 }\r
167\r
168 return EFI_SUCCESS;\r
169}\r