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