]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.c
BaseTools: Improve build performance of structure PCD value generation
[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
40a3f38f 73 EFI_PEI_HOB_POINTERS NextHob;\r
40a3f38f
OM
74 BOOLEAN Found;\r
75\r
76 // Get Virtual Memory Map from the Platform Library\r
77 ArmPlatformGetVirtualMemoryMap (&MemoryTable);\r
3a6eaccf 78\r
79 // Ensure PcdSystemMemorySize has been set\r
c357fd6a 80 ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);\r
3a6eaccf 81\r
3a6eaccf 82 //\r
83 // Now, the permanent memory has been installed, we can call AllocatePages()\r
84 //\r
d269095b 85 ResourceAttributes = (\r
3a6eaccf 86 EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
87 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
3a6eaccf 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
40a3f38f
OM
94 //\r
95 // Check if the resource for the main system memory has been declared\r
96 //\r
97 Found = FALSE;\r
98 NextHob.Raw = GetHobList ();\r
99 while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) {\r
100 if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) &&\r
101 (PcdGet64 (PcdSystemMemoryBase) >= NextHob.ResourceDescriptor->PhysicalStart) &&\r
102 (NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength <= PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize)))\r
103 {\r
104 Found = TRUE;\r
105 break;\r
106 }\r
107 NextHob.Raw = GET_NEXT_HOB (NextHob);\r
108 }\r
109\r
110 if (!Found) {\r
111 // Reserved the memory space occupied by the firmware volume\r
112 BuildResourceDescriptorHob (\r
113 EFI_RESOURCE_SYSTEM_MEMORY,\r
114 ResourceAttributes,\r
115 PcdGet64 (PcdSystemMemoryBase),\r
116 PcdGet64 (PcdSystemMemorySize)\r
117 );\r
118 }\r
119\r
3a6eaccf 120 // Build Memory Allocation Hob\r
40a3f38f 121 InitMmu (MemoryTable);\r
3a6eaccf 122\r
123 if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {\r
124 // Optional feature that helps prevent EFI memory map fragmentation.\r
125 BuildMemoryTypeInformationHob ();\r
126 }\r
127\r
128 return EFI_SUCCESS;\r
129}\r