]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/ArmVirtPlatformLib/VirtMem.c
ArmVirtPkg: drop ArmPlatformGlobalVariableLib dependency
[mirror_edk2.git] / ArmVirtPkg / Library / ArmVirtPlatformLib / VirtMem.c
CommitLineData
a36d531f
MC
1/** @file\r
2*\r
3* Copyright (c) 2014, Linaro 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 <Library/ArmPlatformLib.h>\r
16#include <Library/DebugLib.h>\r
17#include <Library/BaseMemoryLib.h>\r
18#include <Library/PcdLib.h>\r
19#include <Library/IoLib.h>\r
20#include <Library/MemoryAllocationLib.h>\r
a36d531f
MC
21#include <ArmPlatform.h>\r
22\r
23// Number of Virtual Memory Map Descriptors\r
dca7f96f 24#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5\r
a36d531f
MC
25\r
26// DDR attributes\r
27#define DDR_ATTRIBUTES_CACHED ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK\r
28#define DDR_ATTRIBUTES_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED\r
29\r
30EFI_PHYSICAL_ADDRESS\r
31ArmGetPhysAddrTop (\r
32 VOID\r
33 );\r
34\r
35/**\r
36 Return the Virtual Memory Map of your platform\r
37\r
38 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU\r
39 on your platform.\r
40\r
41 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR\r
42 describing a Physical-to-Virtual Memory\r
43 mapping. This array must be ended by a\r
44 zero-filled entry\r
45\r
46**/\r
47VOID\r
48ArmPlatformGetVirtualMemoryMap (\r
49 IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap\r
50 )\r
51{\r
52 ARM_MEMORY_REGION_ATTRIBUTES CacheAttributes;\r
53 ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;\r
54\r
55 ASSERT (VirtualMemoryMap != NULL);\r
56\r
57 VirtualMemoryTable = AllocatePages (\r
58 EFI_SIZE_TO_PAGES (\r
59 sizeof (ARM_MEMORY_REGION_DESCRIPTOR)\r
60 * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS\r
61 )\r
62 );\r
63\r
64 if (VirtualMemoryTable == NULL) {\r
65 DEBUG ((EFI_D_ERROR, "%a: Error: Failed AllocatePages()\n", __FUNCTION__));\r
66 return;\r
67 }\r
68\r
69 if (FeaturePcdGet (PcdCacheEnable) == TRUE) {\r
70 CacheAttributes = DDR_ATTRIBUTES_CACHED;\r
71 } else {\r
72 CacheAttributes = DDR_ATTRIBUTES_UNCACHED;\r
73 }\r
74\r
75 // System DRAM\r
76 VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);\r
77 VirtualMemoryTable[0].VirtualBase = VirtualMemoryTable[0].PhysicalBase;\r
78 VirtualMemoryTable[0].Length = PcdGet64 (PcdSystemMemorySize);\r
79 VirtualMemoryTable[0].Attributes = CacheAttributes;\r
80\r
81 DEBUG ((EFI_D_INFO, "%a: Dumping System DRAM Memory Map:\n"\r
82 "\tPhysicalBase: 0x%lX\n"\r
83 "\tVirtualBase: 0x%lX\n"\r
84 "\tLength: 0x%lX\n",\r
85 __FUNCTION__,\r
86 VirtualMemoryTable[0].PhysicalBase,\r
87 VirtualMemoryTable[0].VirtualBase,\r
88 VirtualMemoryTable[0].Length));\r
89\r
90 // Peripheral space before DRAM\r
91 VirtualMemoryTable[1].PhysicalBase = 0x0;\r
92 VirtualMemoryTable[1].VirtualBase = 0x0;\r
93 VirtualMemoryTable[1].Length = VirtualMemoryTable[0].PhysicalBase;\r
94 VirtualMemoryTable[1].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r
95\r
96 // Peripheral space after DRAM\r
97 VirtualMemoryTable[2].PhysicalBase = VirtualMemoryTable[0].Length + VirtualMemoryTable[1].Length;\r
98 VirtualMemoryTable[2].VirtualBase = VirtualMemoryTable[2].PhysicalBase;\r
1dc3f34f
AB
99 VirtualMemoryTable[2].Length = MIN (1ULL << FixedPcdGet8 (PcdPrePiCpuMemorySize),\r
100 ArmGetPhysAddrTop ()) -\r
101 VirtualMemoryTable[2].PhysicalBase;\r
a36d531f
MC
102 VirtualMemoryTable[2].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r
103\r
dca7f96f
AB
104 // Remap the FD region as normal executable memory\r
105 VirtualMemoryTable[3].PhysicalBase = FixedPcdGet64 (PcdFdBaseAddress);\r
106 VirtualMemoryTable[3].VirtualBase = VirtualMemoryTable[3].PhysicalBase;\r
107 VirtualMemoryTable[3].Length = FixedPcdGet32 (PcdFdSize);\r
108 VirtualMemoryTable[3].Attributes = CacheAttributes;\r
109\r
a36d531f 110 // End of Table\r
dca7f96f 111 ZeroMem (&VirtualMemoryTable[4], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));\r
a36d531f
MC
112\r
113 *VirtualMemoryMap = VirtualMemoryTable;\r
114}\r