3 * Copyright (c) 2011, ARM Limited. All rights reserved.
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this 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.
15 #include <Library/ArmPlatformLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/PcdLib.h>
18 #include <Library/IoLib.h>
19 #include <Library/MemoryAllocationLib.h>
21 // Number of Virtual Memory Map Descriptors without a Logic Tile
22 #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 6
25 #define DDR_ATTRIBUTES_CACHED ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
26 #define DDR_ATTRIBUTES_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
27 #define DDR_ATTRIBUTES_SECURE_CACHED ARM_MEMORY_REGION_ATTRIBUTE_SECURE_WRITE_BACK
28 #define DDR_ATTRIBUTES_SECURE_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_SECURE_UNCACHED_UNBUFFERED
31 Return the Virtual Memory Map of your platform
33 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.
35 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-
36 Virtual Memory mapping. This array must be ended by a zero-filled
41 ArmPlatformGetVirtualMemoryMap (
42 IN ARM_MEMORY_REGION_DESCRIPTOR
** VirtualMemoryMap
45 ARM_MEMORY_REGION_ATTRIBUTES CacheAttributes
;
46 BOOLEAN bTrustzoneSupport
;
48 ARM_MEMORY_REGION_DESCRIPTOR
*VirtualMemoryTable
;
50 ASSERT(VirtualMemoryMap
!= NULL
);
52 VirtualMemoryTable
= (ARM_MEMORY_REGION_DESCRIPTOR
*)AllocatePages(EFI_SIZE_TO_PAGES (sizeof(ARM_MEMORY_REGION_DESCRIPTOR
) * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
));
53 if (VirtualMemoryTable
== NULL
) {
57 // Check if SMC TZASC is enabled. If Trustzone not enabled then all the entries remain in Secure World.
58 // As this value can be changed in the Board Configuration file, the UEFI firmware needs to work for both case
59 if (ArmPlatformTrustzoneSupported ()) {
60 bTrustzoneSupport
= TRUE
;
62 bTrustzoneSupport
= FALSE
;
65 if (FeaturePcdGet(PcdCacheEnable
) == TRUE
) {
66 CacheAttributes
= (bTrustzoneSupport
? DDR_ATTRIBUTES_CACHED
: DDR_ATTRIBUTES_SECURE_CACHED
);
68 CacheAttributes
= (bTrustzoneSupport
? DDR_ATTRIBUTES_UNCACHED
: DDR_ATTRIBUTES_SECURE_UNCACHED
);
71 // ReMap (Either NOR Flash or DRAM)
72 VirtualMemoryTable
[Index
].PhysicalBase
= ARM_VE_REMAP_BASE
;
73 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_REMAP_BASE
;
74 VirtualMemoryTable
[Index
].Length
= ARM_VE_REMAP_SZ
;
76 if (FeaturePcdGet(PcdNorFlashRemapping
)) {
77 // Map the NOR Flash as Secure Memory
78 if (FeaturePcdGet(PcdCacheEnable
) == TRUE
) {
79 VirtualMemoryTable
[Index
].Attributes
= DDR_ATTRIBUTES_SECURE_CACHED
;
81 VirtualMemoryTable
[Index
].Attributes
= DDR_ATTRIBUTES_SECURE_UNCACHED
;
85 VirtualMemoryTable
[Index
].Attributes
= CacheAttributes
;
89 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_VE_DRAM_BASE
;
90 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_DRAM_BASE
;
91 VirtualMemoryTable
[Index
].Length
= ARM_VE_DRAM_SZ
;
92 VirtualMemoryTable
[Index
].Attributes
= CacheAttributes
;
95 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_VE_SMB_MB_ON_CHIP_PERIPH_BASE
;
96 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_SMB_MB_ON_CHIP_PERIPH_BASE
;
97 VirtualMemoryTable
[Index
].Length
= ARM_VE_SMB_MB_ON_CHIP_PERIPH_SZ
;
98 VirtualMemoryTable
[Index
].Attributes
= (bTrustzoneSupport
? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
: ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE
);
100 // SMB CS0-CS1 - NOR Flash 1 & 2
101 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_VE_SMB_NOR0_BASE
;
102 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_SMB_NOR0_BASE
;
103 VirtualMemoryTable
[Index
].Length
= ARM_VE_SMB_NOR0_SZ
+ ARM_VE_SMB_NOR1_SZ
;
104 VirtualMemoryTable
[Index
].Attributes
= (bTrustzoneSupport
? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
: ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE
);
107 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_VE_SMB_SRAM_BASE
;
108 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_SMB_SRAM_BASE
;
109 VirtualMemoryTable
[Index
].Length
= ARM_VE_SMB_SRAM_SZ
;
110 VirtualMemoryTable
[Index
].Attributes
= CacheAttributes
;
112 // SMB CS3-CS6 - Motherboard Peripherals
113 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_VE_SMB_PERIPH_BASE
;
114 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_SMB_PERIPH_BASE
;
115 VirtualMemoryTable
[Index
].Length
= ARM_VE_SMB_PERIPH_SZ
;
116 VirtualMemoryTable
[Index
].Attributes
= (bTrustzoneSupport
? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
: ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE
);
118 // If a Logic Tile is connected to The ARM Versatile Express Motherboard
119 if (MmioRead32(ARM_VE_SYS_PROCID1_REG
) != 0) {
120 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_VE_EXT_AXI_BASE
;
121 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_EXT_AXI_BASE
;
122 VirtualMemoryTable
[Index
].Length
= ARM_VE_EXT_AXI_SZ
;
123 VirtualMemoryTable
[Index
].Attributes
= (bTrustzoneSupport
? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
: ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE
);
125 ASSERT((Index
+ 1) == (MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
+ 1));
127 ASSERT((Index
+ 1) == MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
);
131 VirtualMemoryTable
[++Index
].PhysicalBase
= 0;
132 VirtualMemoryTable
[Index
].VirtualBase
= 0;
133 VirtualMemoryTable
[Index
].Length
= 0;
134 VirtualMemoryTable
[Index
].Attributes
= (ARM_MEMORY_REGION_ATTRIBUTES
)0;
136 *VirtualMemoryMap
= VirtualMemoryTable
;
140 Return the EFI Memory Map provided by extension memory on your platform
142 This EFI Memory Map of the System Memory is used by MemoryInitPei module to create the Resource
143 Descriptor HOBs used by DXE core.
145 @param[out] EfiMemoryMap Array of ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR describing an
146 EFI Memory region. This array must be ended by a zero-filled entry
150 ArmPlatformGetAdditionalSystemMemory (
151 OUT ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR
** EfiMemoryMap
154 return EFI_UNSUPPORTED
;