]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbMem.c
01720bb23eacf6a6f49c5a8b029aab9bf3e1eb85
[mirror_edk2.git] / ArmPlatformPkg / ArmRealViewEbPkg / Library / ArmRealViewEbLibRTSM / ArmRealViewEbMem.c
1 /** @file
2 *
3 * Copyright (c) 2011, ARM Limited. All rights reserved.
4 *
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
9 *
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.
12 *
13 **/
14
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>
20
21 // DDR attributes
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
26
27 /**
28 Return the information about the memory region in permanent memory used by PEI
29
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.
32
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
35
36 **/
37 VOID ArmPlatformGetPeiMemory (
38 OUT UINTN* PeiMemoryBase,
39 OUT UINTN* PeiMemorySize
40 ) {
41 ASSERT((PeiMemoryBase != NULL) && (PeiMemorySize != NULL));
42
43 *PeiMemoryBase = ARM_EB_DRAM_BASE + ARM_EB_EFI_FIX_ADDRESS_REGION_SZ;
44 *PeiMemorySize = ARM_EB_EFI_MEMORY_REGION_SZ;
45 }
46
47 /**
48 Return the Virtual Memory Map of your platform
49
50 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.
51
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
54 entry
55
56 **/
57 VOID ArmPlatformGetVirtualMemoryMap(ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap) {
58 UINT32 CacheAttributes;
59 BOOLEAN bTrustzoneSupport = FALSE;
60 UINTN Index = 0;
61 ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
62
63 ASSERT(VirtualMemoryMap != NULL);
64
65 VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages(sizeof(ARM_MEMORY_REGION_DESCRIPTOR) * 9);
66 if (VirtualMemoryTable == NULL) {
67 return;
68 }
69
70 if (FeaturePcdGet(PcdCacheEnable) == TRUE) {
71 CacheAttributes = (bTrustzoneSupport ? DDR_ATTRIBUTES_CACHED : DDR_ATTRIBUTES_SECURE_CACHED);
72 } else {
73 CacheAttributes = (bTrustzoneSupport ? DDR_ATTRIBUTES_UNCACHED : DDR_ATTRIBUTES_SECURE_UNCACHED);
74 }
75
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;
81
82 // DDR
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;
87
88 // SMC CS7
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);
93
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);
99
100 // SMB CS2 - SRAM
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;
105
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);
111
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);
118 }
119
120 // End of Table
121 VirtualMemoryTable[++Index].PhysicalBase = 0;
122 VirtualMemoryTable[Index].VirtualBase = 0;
123 VirtualMemoryTable[Index].Length = 0;
124 VirtualMemoryTable[Index].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)0;
125
126 *VirtualMemoryMap = VirtualMemoryTable;
127 }
128
129 /**
130 Return the EFI Memory Map of your platform
131
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.
134
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
137
138 **/
139 VOID ArmPlatformGetEfiMemoryMap (
140 OUT ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR** EfiMemoryMap
141 ) {
142 EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;
143 UINT64 MemoryBase;
144 UINTN Index = 0;
145 ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR *EfiMemoryTable;
146
147 ASSERT(EfiMemoryMap != NULL);
148
149 EfiMemoryTable = (ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR*)AllocatePages(sizeof(ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR) * 6);
150
151 Attributes =
152 (
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
160 );
161 MemoryBase = ARM_EB_DRAM_BASE;
162
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;
167
168 MemoryBase += ARM_EB_EFI_FIX_ADDRESS_REGION_SZ;
169
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;
174
175 MemoryBase += ARM_EB_EFI_MEMORY_REGION_SZ;
176
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(PcdNormalFdBaseAddress) - MemoryBase;
183
184 // Chunk reserved by the firmware in DRAM
185 EfiMemoryTable[++Index].ResourceAttribute = Attributes & (~EFI_RESOURCE_ATTRIBUTE_PRESENT);
186 EfiMemoryTable[Index].PhysicalStart = PcdGet32(PcdNormalFdBaseAddress);
187 EfiMemoryTable[Index].NumberOfBytes = PcdGet32(PcdNormalFdSize);
188
189 MemoryBase = PcdGet32(PcdNormalFdBaseAddress) + PcdGet32(PcdNormalFdSize);
190 }
191
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);
196
197 EfiMemoryTable[++Index].ResourceAttribute = 0;
198 EfiMemoryTable[Index].PhysicalStart = 0;
199 EfiMemoryTable[Index].NumberOfBytes = 0;
200
201 *EfiMemoryMap = EfiMemoryTable;
202 }