TianoCore EDK2 master
Loading...
Searching...
No Matches
KvmtoolVirtMemInfoLib.c
Go to the documentation of this file.
1
10#include <Base.h>
11#include <Library/ArmLib.h>
12#include <Library/BaseLib.h>
14#include <Library/DebugLib.h>
16
17// Number of Virtual Memory Map Descriptors
18#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5
19
33VOID
35 OUT ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap
36 )
37{
38 ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
39 UINTN Idx;
40 EFI_PHYSICAL_ADDRESS TopOfAddressSpace;
41
42 ASSERT (VirtualMemoryMap != NULL);
43
44 TopOfAddressSpace = LShiftU64 (1ULL, ArmGetPhysicalAddressBits ());
45
46 VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR *)
50 MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
51 )
52 );
53 if (VirtualMemoryTable == NULL) {
54 DEBUG ((
55 DEBUG_ERROR,
56 "%a: Error: Failed to Allocate Pages\n",
57 __func__
58 ));
59 return;
60 }
61
62 Idx = 0;
63 // System DRAM
64 VirtualMemoryTable[Idx].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);
65 VirtualMemoryTable[Idx].VirtualBase = VirtualMemoryTable[Idx].PhysicalBase;
66 VirtualMemoryTable[Idx].Length = PcdGet64 (PcdSystemMemorySize);
67 VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
68
69 // Peripheral space before DRAM
70 VirtualMemoryTable[++Idx].PhysicalBase = 0x0;
71 VirtualMemoryTable[Idx].VirtualBase = 0x0;
72 VirtualMemoryTable[Idx].Length = PcdGet64 (PcdSystemMemoryBase);
73 VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
74
75 // Peripheral space after DRAM
76 VirtualMemoryTable[++Idx].PhysicalBase = PcdGet64 (PcdSystemMemoryBase) +
77 PcdGet64 (PcdSystemMemorySize);
78 VirtualMemoryTable[Idx].VirtualBase = VirtualMemoryTable[Idx].PhysicalBase;
79 VirtualMemoryTable[Idx].Length = TopOfAddressSpace -
80 VirtualMemoryTable[Idx].PhysicalBase;
81 VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
82
83 // Map the FV region as normal executable memory
84 VirtualMemoryTable[++Idx].PhysicalBase = PcdGet64 (PcdFvBaseAddress);
85 VirtualMemoryTable[Idx].VirtualBase = VirtualMemoryTable[Idx].PhysicalBase;
86 VirtualMemoryTable[Idx].Length = FixedPcdGet32 (PcdFvSize);
87 VirtualMemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
88
89 // End of Table
90 VirtualMemoryTable[++Idx].PhysicalBase = 0;
91 VirtualMemoryTable[Idx].VirtualBase = 0;
92 VirtualMemoryTable[Idx].Length = 0;
93 VirtualMemoryTable[Idx].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)0;
94
95 ASSERT ((Idx + 1) <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
96
97 *VirtualMemoryMap = VirtualMemoryTable;
98}
UINT64 UINTN
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
Definition: LShiftU64.c:28
VOID ArmVirtGetMemoryMap(OUT ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap)
#define NULL
Definition: Base.h:319
#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 AllocatePages(IN UINTN Pages)
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200