3 Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
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>
17 // Number of Virtual Memory Map Descriptors
18 #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5
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.
26 #define MACH_VIRT_PERIPH_BASE 0x08000000
27 #define MACH_VIRT_PERIPH_SIZE SIZE_128MB
30 Default library constructur that obtains the memory size from a PCD.
32 @return Always returns RETURN_SUCCESS
37 QemuVirtMemInfoLibConstructor (
44 Size
= PcdGet64 (PcdSystemMemorySize
);
45 Hob
= BuildGuidDataHob (&gArmVirtSystemMemorySizeGuid
, &Size
, sizeof Size
);
48 return RETURN_SUCCESS
;
52 Return the Virtual Memory Map of your platform
54 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
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
66 OUT ARM_MEMORY_REGION_DESCRIPTOR
**VirtualMemoryMap
69 ARM_MEMORY_REGION_DESCRIPTOR
*VirtualMemoryTable
;
72 ASSERT (VirtualMemoryMap
!= NULL
);
74 MemorySizeHob
= GetFirstGuidHob (&gArmVirtSystemMemorySizeGuid
);
75 ASSERT (MemorySizeHob
!= NULL
);
76 if (MemorySizeHob
== NULL
) {
80 VirtualMemoryTable
= AllocatePool (
81 sizeof (ARM_MEMORY_REGION_DESCRIPTOR
) *
82 MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
85 if (VirtualMemoryTable
== NULL
) {
86 DEBUG ((DEBUG_ERROR
, "%a: Error: Failed AllocatePool()\n", __FUNCTION__
));
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
;
98 "%a: Dumping System DRAM Memory Map:\n"
99 "\tPhysicalBase: 0x%lX\n"
100 "\tVirtualBase: 0x%lX\n"
103 VirtualMemoryTable
[0].PhysicalBase
,
104 VirtualMemoryTable
[0].VirtualBase
,
105 VirtualMemoryTable
[0].Length
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
;
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
;
121 ZeroMem (&VirtualMemoryTable
[3], sizeof (ARM_MEMORY_REGION_DESCRIPTOR
));
123 *VirtualMemoryMap
= VirtualMemoryTable
;