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
30 Return the Virtual Memory Map of your platform
32 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
35 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR
36 describing a Physical-to-Virtual Memory
37 mapping. This array must be ended by a
38 zero-filled entry. The allocated memory
44 OUT ARM_MEMORY_REGION_DESCRIPTOR
**VirtualMemoryMap
47 ARM_MEMORY_REGION_DESCRIPTOR
*VirtualMemoryTable
;
50 ASSERT (VirtualMemoryMap
!= NULL
);
52 VirtualMemoryTable
= AllocatePool (sizeof (ARM_MEMORY_REGION_DESCRIPTOR
) *
53 MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
);
55 if (VirtualMemoryTable
== NULL
) {
56 DEBUG ((DEBUG_ERROR
, "%a: Error: Failed AllocatePool()\n", __FUNCTION__
));
61 VirtualMemoryTable
[0].PhysicalBase
= PcdGet64 (PcdSystemMemoryBase
);
62 VirtualMemoryTable
[0].VirtualBase
= VirtualMemoryTable
[0].PhysicalBase
;
63 VirtualMemoryTable
[0].Length
= PcdGet64 (PcdSystemMemorySize
);
64 VirtualMemoryTable
[0].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
;
66 DEBUG ((DEBUG_INFO
, "%a: Dumping System DRAM Memory Map:\n"
67 "\tPhysicalBase: 0x%lX\n"
68 "\tVirtualBase: 0x%lX\n"
71 VirtualMemoryTable
[0].PhysicalBase
,
72 VirtualMemoryTable
[0].VirtualBase
,
73 VirtualMemoryTable
[0].Length
));
75 // Peripheral space before DRAM
76 VirtualMemoryTable
[1].PhysicalBase
= 0x0;
77 VirtualMemoryTable
[1].VirtualBase
= 0x0;
78 VirtualMemoryTable
[1].Length
= VirtualMemoryTable
[0].PhysicalBase
;
79 VirtualMemoryTable
[1].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
81 // Peripheral space after DRAM
82 TopOfMemory
= MIN (1ULL << FixedPcdGet8 (PcdPrePiCpuMemorySize
),
83 ArmGetPhysAddrTop ());
84 VirtualMemoryTable
[2].PhysicalBase
= VirtualMemoryTable
[0].Length
+ VirtualMemoryTable
[1].Length
;
85 VirtualMemoryTable
[2].VirtualBase
= VirtualMemoryTable
[2].PhysicalBase
;
86 VirtualMemoryTable
[2].Length
= TopOfMemory
-
87 VirtualMemoryTable
[2].PhysicalBase
;
88 VirtualMemoryTable
[2].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
90 // Remap the FD region as normal executable memory
91 VirtualMemoryTable
[3].PhysicalBase
= PcdGet64 (PcdFdBaseAddress
);
92 VirtualMemoryTable
[3].VirtualBase
= VirtualMemoryTable
[3].PhysicalBase
;
93 VirtualMemoryTable
[3].Length
= FixedPcdGet32 (PcdFdSize
);
94 VirtualMemoryTable
[3].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
;
97 ZeroMem (&VirtualMemoryTable
[4], sizeof (ARM_MEMORY_REGION_DESCRIPTOR
));
99 *VirtualMemoryMap
= VirtualMemoryTable
;