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>
20 #include <ArmPlatform.h>
22 // Number of Virtual Memory Map Descriptors without a Logic Tile
23 #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5
26 #define DDR_ATTRIBUTES_CACHED ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
27 #define DDR_ATTRIBUTES_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
28 #define DDR_ATTRIBUTES_SECURE_CACHED ARM_MEMORY_REGION_ATTRIBUTE_SECURE_WRITE_BACK
29 #define DDR_ATTRIBUTES_SECURE_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_SECURE_UNCACHED_UNBUFFERED
32 Return the Virtual Memory Map of your platform
34 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.
36 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-
37 Virtual Memory mapping. This array must be ended by a zero-filled
42 ArmPlatformGetVirtualMemoryMap (
43 IN ARM_MEMORY_REGION_DESCRIPTOR
** VirtualMemoryMap
46 ARM_MEMORY_REGION_ATTRIBUTES CacheAttributes
;
47 BOOLEAN bTrustzoneSupport
;
49 ARM_MEMORY_REGION_DESCRIPTOR
*VirtualMemoryTable
;
51 ASSERT(VirtualMemoryMap
!= NULL
);
53 VirtualMemoryTable
= (ARM_MEMORY_REGION_DESCRIPTOR
*)AllocatePages(EFI_SIZE_TO_PAGES (sizeof(ARM_MEMORY_REGION_DESCRIPTOR
) * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
));
54 if (VirtualMemoryTable
== NULL
) {
58 // Check if SMC TZASC is enabled. If Trustzone not enabled then all the entries remain in Secure World.
59 // As this value can be changed in the Board Configuration file, the UEFI firmware needs to work for both case
60 if (ArmPlatformTrustzoneSupported ()) {
61 bTrustzoneSupport
= TRUE
;
63 bTrustzoneSupport
= FALSE
;
66 if (FeaturePcdGet(PcdCacheEnable
) == TRUE
) {
67 CacheAttributes
= (bTrustzoneSupport
? DDR_ATTRIBUTES_CACHED
: DDR_ATTRIBUTES_SECURE_CACHED
);
69 CacheAttributes
= (bTrustzoneSupport
? DDR_ATTRIBUTES_UNCACHED
: DDR_ATTRIBUTES_SECURE_UNCACHED
);
72 // ReMap (Either NOR Flash or DRAM)
73 VirtualMemoryTable
[Index
].PhysicalBase
= ARM_VE_REMAP_BASE
;
74 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_REMAP_BASE
;
75 VirtualMemoryTable
[Index
].Length
= ARM_VE_REMAP_SZ
;
77 if (FeaturePcdGet(PcdNorFlashRemapping
)) {
78 // Map the NOR Flash as Secure Memory
79 if (FeaturePcdGet(PcdCacheEnable
) == TRUE
) {
80 VirtualMemoryTable
[Index
].Attributes
= DDR_ATTRIBUTES_SECURE_CACHED
;
82 VirtualMemoryTable
[Index
].Attributes
= DDR_ATTRIBUTES_SECURE_UNCACHED
;
86 VirtualMemoryTable
[Index
].Attributes
= CacheAttributes
;
90 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_VE_DRAM_BASE
;
91 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_DRAM_BASE
;
92 VirtualMemoryTable
[Index
].Length
= ARM_VE_DRAM_SZ
;
93 VirtualMemoryTable
[Index
].Attributes
= CacheAttributes
;
95 // CPU peripherals. TRM. Manual says not all of them are implemented.
96 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_VE_ON_CHIP_PERIPH_BASE
;
97 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_ON_CHIP_PERIPH_BASE
;
98 VirtualMemoryTable
[Index
].Length
= ARM_VE_ON_CHIP_PERIPH_SZ
;
99 VirtualMemoryTable
[Index
].Attributes
= (bTrustzoneSupport
? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
: ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE
);
101 // SMB CS0-CS1 - NOR Flash 1 & 2
102 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_VE_SMB_NOR0_BASE
;
103 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_SMB_NOR0_BASE
;
104 VirtualMemoryTable
[Index
].Length
= ARM_VE_SMB_NOR0_SZ
+ ARM_VE_SMB_NOR1_SZ
;
105 VirtualMemoryTable
[Index
].Attributes
= (bTrustzoneSupport
? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
: ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE
);
108 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_VE_SMB_SRAM_BASE
;
109 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_SMB_SRAM_BASE
;
110 VirtualMemoryTable
[Index
].Length
= ARM_VE_SMB_SRAM_SZ
;
111 VirtualMemoryTable
[Index
].Attributes
= CacheAttributes
;
113 // Peripheral CS2 and CS3
114 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_VE_SMB_PERIPH_BASE
;
115 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_SMB_PERIPH_BASE
;
116 VirtualMemoryTable
[Index
].Length
= 2 * ARM_VE_SMB_PERIPH_SZ
;
117 VirtualMemoryTable
[Index
].Attributes
= (bTrustzoneSupport
? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
: ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE
);
119 //TODO:This should be enabled for final release. Right now, ARM VE RTSM crashes.
120 // // If a Logic Tile is connected to The ARM Versatile Express Motherboard
121 // if (MmioRead32(ARM_VE_SYS_PROCID1_REG) != 0) {
122 // VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_EXT_AXI_BASE;
123 // VirtualMemoryTable[Index].VirtualBase = ARM_VE_EXT_AXI_BASE;
124 // VirtualMemoryTable[Index].Length = ARM_VE_EXT_AXI_SZ;
125 // VirtualMemoryTable[Index].Attributes = (bTrustzoneSupport ? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE : ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE);
127 // ASSERT((Index + 1) == (MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS + 1));
129 // ASSERT((Index + 1) == MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
133 VirtualMemoryTable
[++Index
].PhysicalBase
= 0;
134 VirtualMemoryTable
[Index
].VirtualBase
= 0;
135 VirtualMemoryTable
[Index
].Length
= 0;
136 VirtualMemoryTable
[Index
].Attributes
= (ARM_MEMORY_REGION_ATTRIBUTES
)0;
138 *VirtualMemoryMap
= VirtualMemoryTable
;
142 Return the EFI Memory Map provided by extension memory on your platform
144 This EFI Memory Map of the System Memory is used by MemoryInitPei module to create the Resource
145 Descriptor HOBs used by DXE core.
146 TODO: CompleteMe .... say this is the memory not covered by the System Memory PCDs
148 @param[out] EfiMemoryMap Array of ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR describing an
149 EFI Memory region. This array must be ended by a zero-filled entry
153 ArmPlatformGetAdditionalSystemMemory (
154 OUT ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR
** EfiMemoryMap
157 return EFI_UNSUPPORTED
;