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