3 Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
5 This program and the accompanying materials are licensed and made available
6 under the terms and conditions of the BSD License which accompanies this
7 distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/ArmLib.h>
17 #include <Library/BaseMemoryLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/MemoryAllocationLib.h>
21 // Number of Virtual Memory Map Descriptors
22 #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5
25 // mach-virt's core peripherals such as the UART, the GIC and the RTC are
26 // all mapped in the 'miscellaneous device I/O' region, which we just map
27 // in its entirety rather than device by device. Note that it does not
28 // cover any of the NOR flash banks or PCI resource windows.
30 #define MACH_VIRT_PERIPH_BASE 0x08000000
31 #define MACH_VIRT_PERIPH_SIZE SIZE_128MB
34 Return the Virtual Memory Map of your platform
36 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
39 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR
40 describing a Physical-to-Virtual Memory
41 mapping. This array must be ended by a
42 zero-filled entry. The allocated memory
48 OUT ARM_MEMORY_REGION_DESCRIPTOR
**VirtualMemoryMap
51 ARM_MEMORY_REGION_DESCRIPTOR
*VirtualMemoryTable
;
53 ASSERT (VirtualMemoryMap
!= NULL
);
55 VirtualMemoryTable
= AllocatePool (sizeof (ARM_MEMORY_REGION_DESCRIPTOR
) *
56 MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
);
58 if (VirtualMemoryTable
== NULL
) {
59 DEBUG ((DEBUG_ERROR
, "%a: Error: Failed AllocatePool()\n", __FUNCTION__
));
64 VirtualMemoryTable
[0].PhysicalBase
= PcdGet64 (PcdSystemMemoryBase
);
65 VirtualMemoryTable
[0].VirtualBase
= VirtualMemoryTable
[0].PhysicalBase
;
66 VirtualMemoryTable
[0].Length
= PcdGet64 (PcdSystemMemorySize
);
67 VirtualMemoryTable
[0].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
;
69 DEBUG ((DEBUG_INFO
, "%a: Dumping System DRAM Memory Map:\n"
70 "\tPhysicalBase: 0x%lX\n"
71 "\tVirtualBase: 0x%lX\n"
74 VirtualMemoryTable
[0].PhysicalBase
,
75 VirtualMemoryTable
[0].VirtualBase
,
76 VirtualMemoryTable
[0].Length
));
78 // Memory mapped peripherals (UART, RTC, GIC, virtio-mmio, etc)
79 VirtualMemoryTable
[1].PhysicalBase
= MACH_VIRT_PERIPH_BASE
;
80 VirtualMemoryTable
[1].VirtualBase
= MACH_VIRT_PERIPH_BASE
;
81 VirtualMemoryTable
[1].Length
= MACH_VIRT_PERIPH_SIZE
;
82 VirtualMemoryTable
[1].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
84 // Map the FV region as normal executable memory
85 VirtualMemoryTable
[2].PhysicalBase
= PcdGet64 (PcdFvBaseAddress
);
86 VirtualMemoryTable
[2].VirtualBase
= VirtualMemoryTable
[2].PhysicalBase
;
87 VirtualMemoryTable
[2].Length
= FixedPcdGet32 (PcdFvSize
);
88 VirtualMemoryTable
[2].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
;
91 ZeroMem (&VirtualMemoryTable
[3], sizeof (ARM_MEMORY_REGION_DESCRIPTOR
));
93 *VirtualMemoryMap
= VirtualMemoryTable
;