]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c
ArmVirtPkg/QemuVirtMemInfoLib: trim the MMIO region mapping
[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
51bb05c7
AB
24//\r
25// mach-virt's core peripherals such as the UART, the GIC and the RTC are\r
26// all mapped in the 'miscellaneous device I/O' region, which we just map\r
27// in its entirety rather than device by device. Note that it does not\r
28// cover any of the NOR flash banks or PCI resource windows.\r
29//\r
30#define MACH_VIRT_PERIPH_BASE 0x08000000\r
31#define MACH_VIRT_PERIPH_SIZE SIZE_128MB\r
32\r
30436034
AB
33/**\r
34 Return the Virtual Memory Map of your platform\r
35\r
36 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU\r
37 on your platform.\r
38\r
39 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR\r
40 describing a Physical-to-Virtual Memory\r
41 mapping. This array must be ended by a\r
42 zero-filled entry. The allocated memory\r
43 will not be freed.\r
44\r
45**/\r
46VOID\r
47ArmVirtGetMemoryMap (\r
48 OUT ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap\r
49 )\r
50{\r
51 ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;\r
30436034
AB
52\r
53 ASSERT (VirtualMemoryMap != NULL);\r
54\r
55 VirtualMemoryTable = AllocatePool (sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *\r
56 MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);\r
57\r
58 if (VirtualMemoryTable == NULL) {\r
59 DEBUG ((DEBUG_ERROR, "%a: Error: Failed AllocatePool()\n", __FUNCTION__));\r
60 return;\r
61 }\r
62\r
63 // System DRAM\r
64 VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);\r
65 VirtualMemoryTable[0].VirtualBase = VirtualMemoryTable[0].PhysicalBase;\r
66 VirtualMemoryTable[0].Length = PcdGet64 (PcdSystemMemorySize);\r
67 VirtualMemoryTable[0].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;\r
68\r
69 DEBUG ((DEBUG_INFO, "%a: Dumping System DRAM Memory Map:\n"\r
70 "\tPhysicalBase: 0x%lX\n"\r
71 "\tVirtualBase: 0x%lX\n"\r
72 "\tLength: 0x%lX\n",\r
73 __FUNCTION__,\r
74 VirtualMemoryTable[0].PhysicalBase,\r
75 VirtualMemoryTable[0].VirtualBase,\r
76 VirtualMemoryTable[0].Length));\r
77\r
51bb05c7
AB
78 // Memory mapped peripherals (UART, RTC, GIC, virtio-mmio, etc)\r
79 VirtualMemoryTable[1].PhysicalBase = MACH_VIRT_PERIPH_BASE;\r
80 VirtualMemoryTable[1].VirtualBase = MACH_VIRT_PERIPH_BASE;\r
81 VirtualMemoryTable[1].Length = MACH_VIRT_PERIPH_SIZE;\r
30436034
AB
82 VirtualMemoryTable[1].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r
83\r
51bb05c7
AB
84 // Map the FV region as normal executable memory\r
85 VirtualMemoryTable[2].PhysicalBase = PcdGet64 (PcdFvBaseAddress);\r
364eed84 86 VirtualMemoryTable[2].VirtualBase = VirtualMemoryTable[2].PhysicalBase;\r
51bb05c7 87 VirtualMemoryTable[2].Length = FixedPcdGet32 (PcdFvSize);\r
364eed84 88 VirtualMemoryTable[2].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;\r
30436034
AB
89\r
90 // End of Table\r
364eed84 91 ZeroMem (&VirtualMemoryTable[3], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));\r
30436034
AB
92\r
93 *VirtualMemoryMap = VirtualMemoryTable;\r
94}\r