]> git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c
ArmVirtPkg/QemuVirtMemInfoLib: trim the MMIO region mapping
[mirror_edk2.git] / ArmVirtPkg / Library / QemuVirtMemInfoLib / QemuVirtMemInfoLib.c
1 /** @file
2
3 Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
4
5 This program and the accompanying materials are licensed and made available
6 under the terms and conditions of the BSD License which accompanies this
7 distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <Base.h>
16 #include <Library/ArmLib.h>
17 #include <Library/BaseMemoryLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/MemoryAllocationLib.h>
20
21 // Number of Virtual Memory Map Descriptors
22 #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5
23
24 //
25 // mach-virt's core peripherals such as the UART, the GIC and the RTC are
26 // all mapped in the 'miscellaneous device I/O' region, which we just map
27 // in its entirety rather than device by device. Note that it does not
28 // cover any of the NOR flash banks or PCI resource windows.
29 //
30 #define MACH_VIRT_PERIPH_BASE 0x08000000
31 #define MACH_VIRT_PERIPH_SIZE SIZE_128MB
32
33 /**
34 Return the Virtual Memory Map of your platform
35
36 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
37 on your platform.
38
39 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR
40 describing a Physical-to-Virtual Memory
41 mapping. This array must be ended by a
42 zero-filled entry. The allocated memory
43 will not be freed.
44
45 **/
46 VOID
47 ArmVirtGetMemoryMap (
48 OUT ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap
49 )
50 {
51 ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
52
53 ASSERT (VirtualMemoryMap != NULL);
54
55 VirtualMemoryTable = AllocatePool (sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *
56 MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
57
58 if (VirtualMemoryTable == NULL) {
59 DEBUG ((DEBUG_ERROR, "%a: Error: Failed AllocatePool()\n", __FUNCTION__));
60 return;
61 }
62
63 // System DRAM
64 VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);
65 VirtualMemoryTable[0].VirtualBase = VirtualMemoryTable[0].PhysicalBase;
66 VirtualMemoryTable[0].Length = PcdGet64 (PcdSystemMemorySize);
67 VirtualMemoryTable[0].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
68
69 DEBUG ((DEBUG_INFO, "%a: Dumping System DRAM Memory Map:\n"
70 "\tPhysicalBase: 0x%lX\n"
71 "\tVirtualBase: 0x%lX\n"
72 "\tLength: 0x%lX\n",
73 __FUNCTION__,
74 VirtualMemoryTable[0].PhysicalBase,
75 VirtualMemoryTable[0].VirtualBase,
76 VirtualMemoryTable[0].Length));
77
78 // Memory mapped peripherals (UART, RTC, GIC, virtio-mmio, etc)
79 VirtualMemoryTable[1].PhysicalBase = MACH_VIRT_PERIPH_BASE;
80 VirtualMemoryTable[1].VirtualBase = MACH_VIRT_PERIPH_BASE;
81 VirtualMemoryTable[1].Length = MACH_VIRT_PERIPH_SIZE;
82 VirtualMemoryTable[1].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
83
84 // Map the FV region as normal executable memory
85 VirtualMemoryTable[2].PhysicalBase = PcdGet64 (PcdFvBaseAddress);
86 VirtualMemoryTable[2].VirtualBase = VirtualMemoryTable[2].PhysicalBase;
87 VirtualMemoryTable[2].Length = FixedPcdGet32 (PcdFvSize);
88 VirtualMemoryTable[2].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
89
90 // End of Table
91 ZeroMem (&VirtualMemoryTable[3], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));
92
93 *VirtualMemoryMap = VirtualMemoryTable;
94 }