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/MemoryAllocationLib.h>
19 #include <Library/IoLib.h>
22 #define DDR_ATTRIBUTES_CACHED ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
23 #define DDR_ATTRIBUTES_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
24 #define DDR_ATTRIBUTES_SECURE_CACHED ARM_MEMORY_REGION_ATTRIBUTE_SECURE_WRITE_BACK
25 #define DDR_ATTRIBUTES_SECURE_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_SECURE_UNCACHED_UNBUFFERED
28 Return the information about the memory region in permanent memory used by PEI
30 One of the PEI Module must install the permament memory used by PEI. This function returns the
31 information about this region for your platform to this PEIM module.
33 @param[out] PeiMemoryBase Base of the memory region used by PEI core and modules
34 @param[out] PeiMemorySize Size of the memory region used by PEI core and modules
37 VOID
ArmPlatformGetPeiMemory (
38 OUT UINTN
* PeiMemoryBase
,
39 OUT UINTN
* PeiMemorySize
41 ASSERT((PeiMemoryBase
!= NULL
) && (PeiMemorySize
!= NULL
));
43 *PeiMemoryBase
= ARM_EB_DRAM_BASE
+ ARM_EB_EFI_FIX_ADDRESS_REGION_SZ
;
44 *PeiMemorySize
= ARM_EB_EFI_MEMORY_REGION_SZ
;
48 Return the Virtual Memory Map of your platform
50 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.
52 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-
53 Virtual Memory mapping. This array must be ended by a zero-filled
57 VOID
ArmPlatformGetVirtualMemoryMap(ARM_MEMORY_REGION_DESCRIPTOR
** VirtualMemoryMap
) {
58 UINT32 CacheAttributes
;
59 BOOLEAN bTrustzoneSupport
= FALSE
;
61 ARM_MEMORY_REGION_DESCRIPTOR
*VirtualMemoryTable
;
63 ASSERT(VirtualMemoryMap
!= NULL
);
65 VirtualMemoryTable
= (ARM_MEMORY_REGION_DESCRIPTOR
*)AllocatePages(sizeof(ARM_MEMORY_REGION_DESCRIPTOR
) * 9);
66 if (VirtualMemoryTable
== NULL
) {
70 if (FeaturePcdGet(PcdCacheEnable
) == TRUE
) {
71 CacheAttributes
= (bTrustzoneSupport
? DDR_ATTRIBUTES_CACHED
: DDR_ATTRIBUTES_SECURE_CACHED
);
73 CacheAttributes
= (bTrustzoneSupport
? DDR_ATTRIBUTES_UNCACHED
: DDR_ATTRIBUTES_SECURE_UNCACHED
);
76 // ReMap (Either NOR Flash or DRAM)
77 VirtualMemoryTable
[Index
].PhysicalBase
= ARM_EB_REMAP_BASE
;
78 VirtualMemoryTable
[Index
].VirtualBase
= ARM_EB_REMAP_BASE
;
79 VirtualMemoryTable
[Index
].Length
= ARM_EB_REMAP_SZ
;
80 VirtualMemoryTable
[Index
].Attributes
= (ARM_MEMORY_REGION_ATTRIBUTES
)CacheAttributes
;
83 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_EB_DRAM_BASE
;
84 VirtualMemoryTable
[Index
].VirtualBase
= ARM_EB_DRAM_BASE
;
85 VirtualMemoryTable
[Index
].Length
= ARM_EB_DRAM_SZ
;
86 VirtualMemoryTable
[Index
].Attributes
= (ARM_MEMORY_REGION_ATTRIBUTES
)CacheAttributes
;
89 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_EB_SMB_MB_ON_CHIP_PERIPH_BASE
;
90 VirtualMemoryTable
[Index
].VirtualBase
= ARM_EB_SMB_MB_ON_CHIP_PERIPH_BASE
;
91 VirtualMemoryTable
[Index
].Length
= ARM_EB_SMB_MB_ON_CHIP_PERIPH_SZ
;
92 VirtualMemoryTable
[Index
].Attributes
= (bTrustzoneSupport
? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
: ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE
);
94 // SMB CS0-CS1 - NOR Flash 1 & 2
95 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_EB_SMB_NOR_BASE
;
96 VirtualMemoryTable
[Index
].VirtualBase
= ARM_EB_SMB_NOR_BASE
;
97 VirtualMemoryTable
[Index
].Length
= ARM_EB_SMB_NOR_SZ
+ ARM_EB_SMB_DOC_SZ
;
98 VirtualMemoryTable
[Index
].Attributes
= (bTrustzoneSupport
? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
: ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE
);
101 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_EB_SMB_SRAM_BASE
;
102 VirtualMemoryTable
[Index
].VirtualBase
= ARM_EB_SMB_SRAM_BASE
;
103 VirtualMemoryTable
[Index
].Length
= ARM_EB_SMB_SRAM_SZ
;
104 VirtualMemoryTable
[Index
].Attributes
= (ARM_MEMORY_REGION_ATTRIBUTES
)CacheAttributes
;
106 // SMB CS3-CS6 - Motherboard Peripherals
107 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_EB_SMB_PERIPH_BASE
;
108 VirtualMemoryTable
[Index
].VirtualBase
= ARM_EB_SMB_PERIPH_BASE
;
109 VirtualMemoryTable
[Index
].Length
= ARM_EB_SMB_PERIPH_SZ
;
110 VirtualMemoryTable
[Index
].Attributes
= (bTrustzoneSupport
? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
: ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE
);
112 // If a Logic Tile is connected to The ARM Versatile Express Motherboard
113 if (MmioRead32(ARM_EB_SYS_PROCID1_REG
) != 0) {
114 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_EB_LOGIC_TILE_BASE
;
115 VirtualMemoryTable
[Index
].VirtualBase
= ARM_EB_LOGIC_TILE_BASE
;
116 VirtualMemoryTable
[Index
].Length
= ARM_EB_LOGIC_TILE_SZ
;
117 VirtualMemoryTable
[Index
].Attributes
= (bTrustzoneSupport
? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
: ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE
);
121 VirtualMemoryTable
[++Index
].PhysicalBase
= 0;
122 VirtualMemoryTable
[Index
].VirtualBase
= 0;
123 VirtualMemoryTable
[Index
].Length
= 0;
124 VirtualMemoryTable
[Index
].Attributes
= (ARM_MEMORY_REGION_ATTRIBUTES
)0;
126 *VirtualMemoryMap
= VirtualMemoryTable
;
130 Return the EFI Memory Map of your platform
132 This EFI Memory Map of the System Memory is used by MemoryInitPei module to create the Resource
133 Descriptor HOBs used by DXE core.
135 @param[out] EfiMemoryMap Array of ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR describing an
136 EFI Memory region. This array must be ended by a zero-filled entry
139 VOID
ArmPlatformGetEfiMemoryMap (
140 OUT ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR
** EfiMemoryMap
142 EFI_RESOURCE_ATTRIBUTE_TYPE Attributes
;
145 ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR
*EfiMemoryTable
;
147 ASSERT(EfiMemoryMap
!= NULL
);
149 EfiMemoryTable
= (ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR
*)AllocatePages(sizeof(ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR
) * 6);
153 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
154 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
155 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
156 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
157 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
158 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
|
159 EFI_RESOURCE_ATTRIBUTE_TESTED
161 MemoryBase
= ARM_EB_DRAM_BASE
;
163 // Memory Reserved for fixed address allocations (such as Exception Vector Table)
164 EfiMemoryTable
[Index
].ResourceAttribute
= Attributes
;
165 EfiMemoryTable
[Index
].PhysicalStart
= MemoryBase
;
166 EfiMemoryTable
[Index
].NumberOfBytes
= ARM_EB_EFI_FIX_ADDRESS_REGION_SZ
;
168 MemoryBase
+= ARM_EB_EFI_FIX_ADDRESS_REGION_SZ
;
170 // Memory declared to PEI as permanent memory for PEI and DXE
171 EfiMemoryTable
[++Index
].ResourceAttribute
= Attributes
;
172 EfiMemoryTable
[Index
].PhysicalStart
= MemoryBase
;
173 EfiMemoryTable
[Index
].NumberOfBytes
= ARM_EB_EFI_MEMORY_REGION_SZ
;
175 MemoryBase
+= ARM_EB_EFI_MEMORY_REGION_SZ
;
177 // We must reserve the memory used by the Firmware Volume copied in DRAM at 0x80000000
178 if (FeaturePcdGet(PcdStandalone
) == FALSE
) {
179 // Chunk between the EFI Memory region and the firmware
180 EfiMemoryTable
[++Index
].ResourceAttribute
= Attributes
;
181 EfiMemoryTable
[Index
].PhysicalStart
= MemoryBase
;
182 EfiMemoryTable
[Index
].NumberOfBytes
= PcdGet32(PcdEmbeddedFdBaseAddress
) - MemoryBase
;
184 // Chunk reserved by the firmware in DRAM
185 EfiMemoryTable
[++Index
].ResourceAttribute
= Attributes
& (~EFI_RESOURCE_ATTRIBUTE_PRESENT
);
186 EfiMemoryTable
[Index
].PhysicalStart
= PcdGet32(PcdEmbeddedFdBaseAddress
);
187 EfiMemoryTable
[Index
].NumberOfBytes
= PcdGet32(PcdEmbeddedFdSize
);
189 MemoryBase
= PcdGet32(PcdEmbeddedFdBaseAddress
) + PcdGet32(PcdEmbeddedFdSize
);
192 // We allocate all the remain memory as untested system memory
193 EfiMemoryTable
[++Index
].ResourceAttribute
= Attributes
& (~EFI_RESOURCE_ATTRIBUTE_TESTED
);
194 EfiMemoryTable
[Index
].PhysicalStart
= MemoryBase
;
195 EfiMemoryTable
[Index
].NumberOfBytes
= ARM_EB_DRAM_SZ
- (MemoryBase
-ARM_EB_DRAM_BASE
);
197 EfiMemoryTable
[++Index
].ResourceAttribute
= 0;
198 EfiMemoryTable
[Index
].PhysicalStart
= 0;
199 EfiMemoryTable
[Index
].NumberOfBytes
= 0;
201 *EfiMemoryMap
= EfiMemoryTable
;