3 Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/ArmLib.h>
11 #include <Library/BaseMemoryLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/MemoryAllocationLib.h>
15 // Number of Virtual Memory Map Descriptors
16 #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5
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.
24 #define MACH_VIRT_PERIPH_BASE 0x08000000
25 #define MACH_VIRT_PERIPH_SIZE SIZE_128MB
28 Return the Virtual Memory Map of your platform
30 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
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
42 OUT ARM_MEMORY_REGION_DESCRIPTOR
**VirtualMemoryMap
45 ARM_MEMORY_REGION_DESCRIPTOR
*VirtualMemoryTable
;
47 ASSERT (VirtualMemoryMap
!= NULL
);
49 VirtualMemoryTable
= AllocatePool (
50 sizeof (ARM_MEMORY_REGION_DESCRIPTOR
) *
51 MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
54 if (VirtualMemoryTable
== NULL
) {
55 DEBUG ((DEBUG_ERROR
, "%a: Error: Failed AllocatePool()\n", __FUNCTION__
));
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
;
67 "%a: Dumping System DRAM Memory Map:\n"
68 "\tPhysicalBase: 0x%lX\n"
69 "\tVirtualBase: 0x%lX\n"
72 VirtualMemoryTable
[0].PhysicalBase
,
73 VirtualMemoryTable
[0].VirtualBase
,
74 VirtualMemoryTable
[0].Length
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
;
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
;
90 ZeroMem (&VirtualMemoryTable
[3], sizeof (ARM_MEMORY_REGION_DESCRIPTOR
));
92 *VirtualMemoryMap
= VirtualMemoryTable
;