]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.c
ArmVirtualizationPkg: implement custom MemoryInitPeiLib
[mirror_edk2.git] / ArmPlatformPkg / ArmVirtualizationPkg / Library / ArmVirtualizationMemoryInitPeiLib / ArmVirtualizationMemoryInitPeiLib.c
CommitLineData
a1bcf5c3
AB
1/** @file\r
2*\r
3* Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
4* Copyright (c) 2014, Linaro Limited. All rights reserved.\r
5*\r
6* This program and the accompanying materials\r
7* are licensed and made available under the terms and conditions of the BSD License\r
8* which accompanies this distribution. The full text of the license may be found at\r
9* http://opensource.org/licenses/bsd-license.php\r
10*\r
11* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13*\r
14**/\r
15\r
16#include <PiPei.h>\r
17\r
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
24VOID\r
25BuildMemoryTypeInformationHob (\r
26 VOID\r
27 );\r
28\r
29VOID\r
30InitMmu (\r
31 VOID\r
32 )\r
33{\r
34 ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;\r
35 VOID *TranslationTableBase;\r
36 UINTN TranslationTableSize;\r
37 RETURN_STATUS Status;\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 Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r
45 if (EFI_ERROR (Status)) {\r
46 DEBUG ((EFI_D_ERROR, "Error: Failed to enable MMU\n"));\r
47 }\r
48}\r
49\r
50EFI_STATUS\r
51EFIAPI\r
52MemoryPeim (\r
53 IN EFI_PHYSICAL_ADDRESS UefiMemoryBase,\r
54 IN UINT64 UefiMemorySize\r
55 )\r
56{\r
57 EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;\r
58\r
59 // Ensure PcdSystemMemorySize has been set\r
60 ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);\r
61\r
62 //\r
63 // Now, the permanent memory has been installed, we can call AllocatePages()\r
64 //\r
65 ResourceAttributes = (\r
66 EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
67 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
68 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |\r
69 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r
70 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r
71 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |\r
72 EFI_RESOURCE_ATTRIBUTE_TESTED\r
73 );\r
74\r
75 BuildResourceDescriptorHob (\r
76 EFI_RESOURCE_SYSTEM_MEMORY,\r
77 ResourceAttributes,\r
78 PcdGet64 (PcdSystemMemoryBase),\r
79 PcdGet64 (PcdSystemMemorySize)\r
80 );\r
81\r
82 // Build Memory Allocation Hob\r
83 InitMmu ();\r
84\r
85 if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {\r
86 // Optional feature that helps prevent EFI memory map fragmentation.\r
87 BuildMemoryTypeInformationHob ();\r
88 }\r
89\r
90 return EFI_SUCCESS;\r
91}\r