]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/QemuVirtMem.c
NetworkPkg: Define the prompt and help information for new PCD.
[mirror_edk2.git] / ArmVirtPkg / Library / ArmQemuRelocatablePlatformLib / QemuVirtMem.c
CommitLineData
577393c2
AB
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 <ArmPlatform.h>\r
22\r
23// Number of Virtual Memory Map Descriptors\r
24#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5\r
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_DESCRIPTOR *VirtualMemoryTable;\r
53\r
54 ASSERT (VirtualMemoryMap != NULL);\r
55\r
56 VirtualMemoryTable = AllocatePages (\r
57 EFI_SIZE_TO_PAGES (\r
58 sizeof (ARM_MEMORY_REGION_DESCRIPTOR)\r
59 * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS\r
60 )\r
61 );\r
62\r
63 if (VirtualMemoryTable == NULL) {\r
64 DEBUG ((EFI_D_ERROR, "%a: Error: Failed AllocatePages()\n", __FUNCTION__));\r
65 return;\r
66 }\r
67\r
68 // System DRAM\r
69 VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);\r
70 VirtualMemoryTable[0].VirtualBase = VirtualMemoryTable[0].PhysicalBase;\r
71 VirtualMemoryTable[0].Length = PcdGet64 (PcdSystemMemorySize);\r
72 VirtualMemoryTable[0].Attributes = DDR_ATTRIBUTES_CACHED;\r
73\r
74 DEBUG ((EFI_D_INFO, "%a: Dumping System DRAM Memory Map:\n"\r
75 "\tPhysicalBase: 0x%lX\n"\r
76 "\tVirtualBase: 0x%lX\n"\r
77 "\tLength: 0x%lX\n",\r
78 __FUNCTION__,\r
79 VirtualMemoryTable[0].PhysicalBase,\r
80 VirtualMemoryTable[0].VirtualBase,\r
81 VirtualMemoryTable[0].Length));\r
82\r
83 // Peripheral space before DRAM\r
84 VirtualMemoryTable[1].PhysicalBase = 0x0;\r
85 VirtualMemoryTable[1].VirtualBase = 0x0;\r
86 VirtualMemoryTable[1].Length = VirtualMemoryTable[0].PhysicalBase;\r
87 VirtualMemoryTable[1].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r
88\r
89 // Peripheral space after DRAM\r
90 VirtualMemoryTable[2].PhysicalBase = VirtualMemoryTable[0].Length + VirtualMemoryTable[1].Length;\r
91 VirtualMemoryTable[2].VirtualBase = VirtualMemoryTable[2].PhysicalBase;\r
92 VirtualMemoryTable[2].Length = MIN (1ULL << FixedPcdGet8 (PcdPrePiCpuMemorySize),\r
93 ArmGetPhysAddrTop ()) -\r
94 VirtualMemoryTable[2].PhysicalBase;\r
95 VirtualMemoryTable[2].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r
96\r
97 // Remap the FD region as normal executable memory\r
98 VirtualMemoryTable[3].PhysicalBase = PcdGet64 (PcdFdBaseAddress);\r
99 VirtualMemoryTable[3].VirtualBase = VirtualMemoryTable[3].PhysicalBase;\r
100 VirtualMemoryTable[3].Length = FixedPcdGet32 (PcdFdSize);\r
101 VirtualMemoryTable[3].Attributes = DDR_ATTRIBUTES_CACHED;\r
102\r
103 // End of Table\r
104 ZeroMem (&VirtualMemoryTable[4], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));\r
105\r
106 *VirtualMemoryMap = VirtualMemoryTable;\r
107}\r