]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4Mem.c
ArmPlatformPkg/ArmPlatformLib: Move the UEFI memory partionning to MemoryInitPei
[mirror_edk2.git] / ArmPlatformPkg / ArmVExpressPkg / Library / ArmVExpressLibCTA9x4 / CTA9x4Mem.c
CommitLineData
1d5d0ae9 1/** @file\r
2*\r
3* Copyright (c) 2011, ARM Limited. All rights reserved.\r
4* \r
5* This program and the accompanying materials \r
6* are licensed and made available under the terms and conditions of the BSD License \r
7* which accompanies this distribution. The full text of the license may be found at \r
8* http://opensource.org/licenses/bsd-license.php \r
9*\r
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12*\r
13**/\r
14\r
15#include <Library/ArmPlatformLib.h>\r
16#include <Library/DebugLib.h>\r
17#include <Library/PcdLib.h>\r
18#include <Library/IoLib.h>\r
19#include <Library/MemoryAllocationLib.h>\r
20\r
21// DDR attributes\r
22#define DDR_ATTRIBUTES_CACHED ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK\r
23#define DDR_ATTRIBUTES_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED\r
24#define DDR_ATTRIBUTES_SECURE_CACHED ARM_MEMORY_REGION_ATTRIBUTE_SECURE_WRITE_BACK\r
25#define DDR_ATTRIBUTES_SECURE_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_SECURE_UNCACHED_UNBUFFERED\r
26\r
1d5d0ae9 27/**\r
28 Return the Virtual Memory Map of your platform\r
29\r
30 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.\r
31\r
32 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-\r
33 Virtual Memory mapping. This array must be ended by a zero-filled\r
34 entry\r
35\r
36**/\r
37VOID ArmPlatformGetVirtualMemoryMap(ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap) {\r
38 UINT32 val32;\r
39 UINT32 CacheAttributes;\r
40 BOOLEAN bTrustzoneSupport;\r
41 UINTN Index = 0;\r
42 ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;\r
43\r
44 ASSERT(VirtualMemoryMap != NULL);\r
45\r
46 VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages(sizeof(ARM_MEMORY_REGION_DESCRIPTOR) * 9);\r
47 if (VirtualMemoryTable == NULL) {\r
48 return;\r
49 }\r
50\r
51 // Check if SMC TZASC is enabled. If Trustzone not enabled then all the entries remain in Secure World.\r
52 // As this value can be changed in the Board Configuration file, the UEFI firmware needs to work for both case\r
53 val32 = MmioRead32(ARM_VE_SYS_CFGRW1_REG);\r
54 if (ARM_VE_CFGRW1_TZASC_EN_BIT_MASK & val32) {\r
55 bTrustzoneSupport = TRUE;\r
56 } else {\r
57 bTrustzoneSupport = FALSE;\r
58 }\r
59\r
60 if (FeaturePcdGet(PcdCacheEnable) == TRUE) {\r
61 CacheAttributes = (bTrustzoneSupport ? DDR_ATTRIBUTES_CACHED : DDR_ATTRIBUTES_SECURE_CACHED);\r
62 } else {\r
63 CacheAttributes = (bTrustzoneSupport ? DDR_ATTRIBUTES_UNCACHED : DDR_ATTRIBUTES_SECURE_UNCACHED);\r
64 }\r
65\r
66 // ReMap (Either NOR Flash or DRAM)\r
67 VirtualMemoryTable[Index].PhysicalBase = ARM_VE_REMAP_BASE;\r
68 VirtualMemoryTable[Index].VirtualBase = ARM_VE_REMAP_BASE;\r
69 VirtualMemoryTable[Index].Length = ARM_VE_REMAP_SZ;\r
70 VirtualMemoryTable[Index].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)CacheAttributes;\r
71\r
72 // DDR\r
73 VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_DRAM_BASE;\r
74 VirtualMemoryTable[Index].VirtualBase = ARM_VE_DRAM_BASE;\r
75 VirtualMemoryTable[Index].Length = ARM_VE_DRAM_SZ;\r
76 VirtualMemoryTable[Index].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)CacheAttributes;\r
77\r
78 // SMC CS7\r
79 VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_MB_ON_CHIP_PERIPH_BASE;\r
80 VirtualMemoryTable[Index].VirtualBase = ARM_VE_SMB_MB_ON_CHIP_PERIPH_BASE;\r
81 VirtualMemoryTable[Index].Length = ARM_VE_SMB_MB_ON_CHIP_PERIPH_SZ;\r
82 VirtualMemoryTable[Index].Attributes = (bTrustzoneSupport ? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE : ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE);\r
83\r
84 // SMB CS0-CS1 - NOR Flash 1 & 2\r
85 VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_NOR0_BASE;\r
86 VirtualMemoryTable[Index].VirtualBase = ARM_VE_SMB_NOR0_BASE;\r
87 VirtualMemoryTable[Index].Length = ARM_VE_SMB_NOR0_SZ + ARM_VE_SMB_NOR1_SZ;\r
88 VirtualMemoryTable[Index].Attributes = (bTrustzoneSupport ? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE : ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE);\r
89\r
90 // SMB CS2 - SRAM\r
91 VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_SRAM_BASE;\r
92 VirtualMemoryTable[Index].VirtualBase = ARM_VE_SMB_SRAM_BASE;\r
93 VirtualMemoryTable[Index].Length = ARM_VE_SMB_SRAM_SZ;\r
94 VirtualMemoryTable[Index].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)CacheAttributes;\r
95\r
96 // SMB CS3-CS6 - Motherboard Peripherals\r
97 VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_PERIPH_BASE;\r
98 VirtualMemoryTable[Index].VirtualBase = ARM_VE_SMB_PERIPH_BASE;\r
99 VirtualMemoryTable[Index].Length = ARM_VE_SMB_PERIPH_SZ;\r
100 VirtualMemoryTable[Index].Attributes = (bTrustzoneSupport ? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE : ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE);\r
101\r
102 // If a Logic Tile is connected to The ARM Versatile Express Motherboard\r
103 if (MmioRead32(ARM_VE_SYS_PROCID1_REG) != 0) {\r
104 VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_EXT_AXI_BASE;\r
105 VirtualMemoryTable[Index].VirtualBase = ARM_VE_EXT_AXI_BASE;\r
106 VirtualMemoryTable[Index].Length = ARM_VE_EXT_AXI_SZ;\r
107 VirtualMemoryTable[Index].Attributes = (bTrustzoneSupport ? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE : ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE);\r
108 }\r
109\r
110 // End of Table\r
111 VirtualMemoryTable[++Index].PhysicalBase = 0;\r
112 VirtualMemoryTable[Index].VirtualBase = 0;\r
113 VirtualMemoryTable[Index].Length = 0;\r
114 VirtualMemoryTable[Index].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)0;\r
115\r
116 *VirtualMemoryMap = VirtualMemoryTable;\r
117}\r
118\r
119/**\r
120 Return the EFI Memory Map of your platform\r
121\r
122 This EFI Memory Map of the System Memory is used by MemoryInitPei module to create the Resource\r
123 Descriptor HOBs used by DXE core.\r
124\r
125 @param[out] EfiMemoryMap Array of ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR describing an\r
126 EFI Memory region. This array must be ended by a zero-filled entry\r
127\r
128**/\r
964680c1 129EFI_STATUS\r
130ArmPlatformGetAdditionalSystemMemory (\r
131 OUT ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR** EfiMemoryMap\r
132 )\r
133{\r
134 return EFI_UNSUPPORTED;\r
1d5d0ae9 135}\r