TianoCore EDK2 master
Loading...
Searching...
No Matches
QemuVirtMemInfoLib.c
Go to the documentation of this file.
1
9#include <Uefi.h>
10#include <Pi/PiMultiPhase.h>
11#include <Library/ArmLib.h>
13#include <Library/DebugLib.h>
14#include <Library/HobLib.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
35RETURN_STATUS
36EFIAPI
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
64VOID
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 (
82 MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
83 );
84
85 if (VirtualMemoryTable == NULL) {
86 DEBUG ((DEBUG_ERROR, "%a: Error: Failed AllocatePool()\n", __func__));
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 __func__,
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_RO;
119
120 // End of Table
121 ZeroMem (&VirtualMemoryTable[3], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));
122
123 *VirtualMemoryMap = VirtualMemoryTable;
124}
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
VOID *EFIAPI BuildGuidDataHob(IN CONST EFI_GUID *Guid, IN VOID *Data, IN UINTN DataLength)
Definition: HobLib.c:375
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define RETURN_SUCCESS
Definition: Base.h:1066
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdGet64(TokenName)
Definition: PcdLib.h:375
#define FixedPcdGet32(TokenName)
Definition: PcdLib.h:92
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
RETURN_STATUS EFIAPI QemuVirtMemInfoLibConstructor(VOID)
VOID ArmVirtGetMemoryMap(OUT ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap)