]> git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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 <Uefi.h>
10 #include <Pi/PiMultiPhase.h>
11 #include <Library/ArmLib.h>
12 #include <Library/BaseMemoryLib.h>
13 #include <Library/DebugLib.h>
14 #include <Library/HobLib.h>
15 #include <Library/MemoryAllocationLib.h>
16
17 // Number of Virtual Memory Map Descriptors
18 #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5
19
20 //
21 // mach-virt's core peripherals such as the UART, the GIC and the RTC are
22 // all mapped in the 'miscellaneous device I/O' region, which we just map
23 // in its entirety rather than device by device. Note that it does not
24 // cover any of the NOR flash banks or PCI resource windows.
25 //
26 #define MACH_VIRT_PERIPH_BASE 0x08000000
27 #define MACH_VIRT_PERIPH_SIZE SIZE_128MB
28
29 /**
30 Default library constructur that obtains the memory size from a PCD.
31
32 @return Always returns RETURN_SUCCESS
33
34 **/
35 RETURN_STATUS
36 EFIAPI
37 QemuVirtMemInfoLibConstructor (
38 VOID
39 )
40 {
41 UINT64 Size;
42 VOID *Hob;
43
44 Size = PcdGet64 (PcdSystemMemorySize);
45 Hob = BuildGuidDataHob (&gArmVirtSystemMemorySizeGuid, &Size, sizeof Size);
46 ASSERT (Hob != NULL);
47
48 return RETURN_SUCCESS;
49 }
50
51 /**
52 Return the Virtual Memory Map of your platform
53
54 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
55 on your platform.
56
57 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR
58 describing a Physical-to-Virtual Memory
59 mapping. This array must be ended by a
60 zero-filled entry. The allocated memory
61 will not be freed.
62
63 **/
64 VOID
65 ArmVirtGetMemoryMap (
66 OUT ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap
67 )
68 {
69 ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
70 VOID *MemorySizeHob;
71
72 ASSERT (VirtualMemoryMap != NULL);
73
74 MemorySizeHob = GetFirstGuidHob (&gArmVirtSystemMemorySizeGuid);
75 ASSERT (MemorySizeHob != NULL);
76 if (MemorySizeHob == NULL) {
77 return;
78 }
79
80 VirtualMemoryTable = AllocatePool (
81 sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *
82 MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
83 );
84
85 if (VirtualMemoryTable == NULL) {
86 DEBUG ((DEBUG_ERROR, "%a: Error: Failed AllocatePool()\n", __FUNCTION__));
87 return;
88 }
89
90 // System DRAM
91 VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);
92 VirtualMemoryTable[0].VirtualBase = VirtualMemoryTable[0].PhysicalBase;
93 VirtualMemoryTable[0].Length = *(UINT64 *)GET_GUID_HOB_DATA (MemorySizeHob);
94 VirtualMemoryTable[0].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
95
96 DEBUG ((
97 DEBUG_INFO,
98 "%a: Dumping System DRAM Memory Map:\n"
99 "\tPhysicalBase: 0x%lX\n"
100 "\tVirtualBase: 0x%lX\n"
101 "\tLength: 0x%lX\n",
102 __FUNCTION__,
103 VirtualMemoryTable[0].PhysicalBase,
104 VirtualMemoryTable[0].VirtualBase,
105 VirtualMemoryTable[0].Length
106 ));
107
108 // Memory mapped peripherals (UART, RTC, GIC, virtio-mmio, etc)
109 VirtualMemoryTable[1].PhysicalBase = MACH_VIRT_PERIPH_BASE;
110 VirtualMemoryTable[1].VirtualBase = MACH_VIRT_PERIPH_BASE;
111 VirtualMemoryTable[1].Length = MACH_VIRT_PERIPH_SIZE;
112 VirtualMemoryTable[1].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
113
114 // Map the FV region as normal executable memory
115 VirtualMemoryTable[2].PhysicalBase = PcdGet64 (PcdFvBaseAddress);
116 VirtualMemoryTable[2].VirtualBase = VirtualMemoryTable[2].PhysicalBase;
117 VirtualMemoryTable[2].Length = FixedPcdGet32 (PcdFvSize);
118 VirtualMemoryTable[2].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
119
120 // End of Table
121 ZeroMem (&VirtualMemoryTable[3], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));
122
123 *VirtualMemoryMap = VirtualMemoryTable;
124 }