]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationMemoryInitPeiLib/ArmVirtualizationMemoryInitPeiLib.c
MdeModulePkg/UfsPciHcDxe: Fix EBC build error
[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
e1d52990 23#include <Library/CacheMaintenanceLib.h>\r
a1bcf5c3
AB
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 RETURN_STATUS Status;\r
39\r
40 // Get Virtual Memory Map from the Platform Library\r
41 ArmPlatformGetVirtualMemoryMap (&MemoryTable);\r
42\r
43 //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in\r
44 // DRAM (even at the top of DRAM as it is the first permanent memory allocation)\r
45 Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r
46 if (EFI_ERROR (Status)) {\r
47 DEBUG ((EFI_D_ERROR, "Error: Failed to enable MMU\n"));\r
48 }\r
49}\r
50\r
51EFI_STATUS\r
52EFIAPI\r
53MemoryPeim (\r
54 IN EFI_PHYSICAL_ADDRESS UefiMemoryBase,\r
55 IN UINT64 UefiMemorySize\r
56 )\r
57{\r
58 EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;\r
59\r
60 // Ensure PcdSystemMemorySize has been set\r
61 ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);\r
62\r
63 //\r
64 // Now, the permanent memory has been installed, we can call AllocatePages()\r
65 //\r
66 ResourceAttributes = (\r
67 EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
68 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
69 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |\r
70 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r
71 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r
72 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |\r
73 EFI_RESOURCE_ATTRIBUTE_TESTED\r
74 );\r
75\r
76 BuildResourceDescriptorHob (\r
77 EFI_RESOURCE_SYSTEM_MEMORY,\r
78 ResourceAttributes,\r
79 PcdGet64 (PcdSystemMemoryBase),\r
80 PcdGet64 (PcdSystemMemorySize)\r
81 );\r
82\r
e1d52990
AB
83 //\r
84 // When running under virtualization, the PI/UEFI memory region may be\r
85 // clean but not invalidated in system caches or in lower level caches\r
86 // on other CPUs. So invalidate the region by virtual address, to ensure\r
87 // that the contents we put there with the caches and MMU off will still\r
88 // be visible after turning them on.\r
89 //\r
90 InvalidateDataCacheRange ((VOID*)(UINTN)UefiMemoryBase, UefiMemorySize);\r
91\r
a1bcf5c3
AB
92 // Build Memory Allocation Hob\r
93 InitMmu ();\r
94\r
95 if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {\r
96 // Optional feature that helps prevent EFI memory map fragmentation.\r
97 BuildMemoryTypeInformationHob ();\r
98 }\r
99\r
100 return EFI_SUCCESS;\r
101}\r