]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c
ArmVirtPkg/FdtPciHostBridgeLib: map ECAM and I/O spaces in GCD memory map
[mirror_edk2.git] / ArmVirtPkg / Library / QemuVirtMemInfoLib / QemuVirtMemInfoLib.c
CommitLineData
30436034
AB
1/** @file\r
2\r
3 Copyright (c) 2014-2017, Linaro Limited. All rights reserved.\r
4\r
5 This program and the accompanying materials are licensed and made available\r
6 under the terms and conditions of the BSD License which accompanies this\r
7 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 <Base.h>\r
16#include <Library/ArmLib.h>\r
17#include <Library/BaseMemoryLib.h>\r
18#include <Library/DebugLib.h>\r
19#include <Library/MemoryAllocationLib.h>\r
20\r
21// Number of Virtual Memory Map Descriptors\r
22#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5\r
23\r
24EFI_PHYSICAL_ADDRESS\r
25ArmGetPhysAddrTop (\r
26 VOID\r
27 );\r
28\r
29/**\r
30 Return the Virtual Memory Map of your platform\r
31\r
32 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU\r
33 on your platform.\r
34\r
35 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR\r
36 describing a Physical-to-Virtual Memory\r
37 mapping. This array must be ended by a\r
38 zero-filled entry. The allocated memory\r
39 will not be freed.\r
40\r
41**/\r
42VOID\r
43ArmVirtGetMemoryMap (\r
44 OUT ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap\r
45 )\r
46{\r
47 ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;\r
48 UINT64 TopOfMemory;\r
49\r
50 ASSERT (VirtualMemoryMap != NULL);\r
51\r
52 VirtualMemoryTable = AllocatePool (sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *\r
53 MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);\r
54\r
55 if (VirtualMemoryTable == NULL) {\r
56 DEBUG ((DEBUG_ERROR, "%a: Error: Failed AllocatePool()\n", __FUNCTION__));\r
57 return;\r
58 }\r
59\r
60 // System DRAM\r
61 VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);\r
62 VirtualMemoryTable[0].VirtualBase = VirtualMemoryTable[0].PhysicalBase;\r
63 VirtualMemoryTable[0].Length = PcdGet64 (PcdSystemMemorySize);\r
64 VirtualMemoryTable[0].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;\r
65\r
66 DEBUG ((DEBUG_INFO, "%a: Dumping System DRAM Memory Map:\n"\r
67 "\tPhysicalBase: 0x%lX\n"\r
68 "\tVirtualBase: 0x%lX\n"\r
69 "\tLength: 0x%lX\n",\r
70 __FUNCTION__,\r
71 VirtualMemoryTable[0].PhysicalBase,\r
72 VirtualMemoryTable[0].VirtualBase,\r
73 VirtualMemoryTable[0].Length));\r
74\r
75 // Peripheral space before DRAM\r
76 VirtualMemoryTable[1].PhysicalBase = 0x0;\r
77 VirtualMemoryTable[1].VirtualBase = 0x0;\r
78 VirtualMemoryTable[1].Length = VirtualMemoryTable[0].PhysicalBase;\r
79 VirtualMemoryTable[1].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r
80\r
81 // Peripheral space after DRAM\r
82 TopOfMemory = MIN (1ULL << FixedPcdGet8 (PcdPrePiCpuMemorySize),\r
83 ArmGetPhysAddrTop ());\r
84 VirtualMemoryTable[2].PhysicalBase = VirtualMemoryTable[0].Length + VirtualMemoryTable[1].Length;\r
85 VirtualMemoryTable[2].VirtualBase = VirtualMemoryTable[2].PhysicalBase;\r
86 VirtualMemoryTable[2].Length = TopOfMemory -\r
87 VirtualMemoryTable[2].PhysicalBase;\r
88 VirtualMemoryTable[2].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r
89\r
90 // Remap the FD region as normal executable memory\r
91 VirtualMemoryTable[3].PhysicalBase = PcdGet64 (PcdFdBaseAddress);\r
92 VirtualMemoryTable[3].VirtualBase = VirtualMemoryTable[3].PhysicalBase;\r
93 VirtualMemoryTable[3].Length = FixedPcdGet32 (PcdFdSize);\r
94 VirtualMemoryTable[3].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;\r
95\r
96 // End of Table\r
97 ZeroMem (&VirtualMemoryTable[4], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));\r
98\r
99 *VirtualMemoryMap = VirtualMemoryTable;\r
100}\r