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 Return the Virtual Memory Map of your platform
27 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
30 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR
31 describing a Physical-to-Virtual Memory
32 mapping. This array must be ended by a
33 zero-filled entry. The allocated memory
39 OUT ARM_MEMORY_REGION_DESCRIPTOR
**VirtualMemoryMap
42 ARM_MEMORY_REGION_DESCRIPTOR
*VirtualMemoryTable
;
44 ASSERT (VirtualMemoryMap
!= NULL
);
46 VirtualMemoryTable
= AllocatePool (sizeof (ARM_MEMORY_REGION_DESCRIPTOR
) *
47 MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
);
49 if (VirtualMemoryTable
== NULL
) {
50 DEBUG ((DEBUG_ERROR
, "%a: Error: Failed AllocatePool()\n", __FUNCTION__
));
55 VirtualMemoryTable
[0].PhysicalBase
= PcdGet64 (PcdSystemMemoryBase
);
56 VirtualMemoryTable
[0].VirtualBase
= VirtualMemoryTable
[0].PhysicalBase
;
57 VirtualMemoryTable
[0].Length
= PcdGet64 (PcdSystemMemorySize
);
58 VirtualMemoryTable
[0].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
;
60 DEBUG ((DEBUG_INFO
, "%a: Dumping System DRAM Memory Map:\n"
61 "\tPhysicalBase: 0x%lX\n"
62 "\tVirtualBase: 0x%lX\n"
65 VirtualMemoryTable
[0].PhysicalBase
,
66 VirtualMemoryTable
[0].VirtualBase
,
67 VirtualMemoryTable
[0].Length
));
69 // Peripheral space before DRAM
70 VirtualMemoryTable
[1].PhysicalBase
= 0x0;
71 VirtualMemoryTable
[1].VirtualBase
= 0x0;
72 VirtualMemoryTable
[1].Length
= VirtualMemoryTable
[0].PhysicalBase
;
73 VirtualMemoryTable
[1].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
75 // Remap the FD region as normal executable memory
76 VirtualMemoryTable
[2].PhysicalBase
= PcdGet64 (PcdFdBaseAddress
);
77 VirtualMemoryTable
[2].VirtualBase
= VirtualMemoryTable
[2].PhysicalBase
;
78 VirtualMemoryTable
[2].Length
= FixedPcdGet32 (PcdFdSize
);
79 VirtualMemoryTable
[2].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
;
82 ZeroMem (&VirtualMemoryTable
[3], sizeof (ARM_MEMORY_REGION_DESCRIPTOR
));
84 *VirtualMemoryMap
= VirtualMemoryTable
;