]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/ArmVExpressPkg/Library/ArmVExpressLibCTA9x4/CTA9x4Mem.c
ArmPlatformPkg/ArmPlatformLib: Move the UEFI memory partionning to MemoryInitPei
[mirror_edk2.git] / ArmPlatformPkg / ArmVExpressPkg / Library / ArmVExpressLibCTA9x4 / CTA9x4Mem.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/IoLib.h>
19 #include <Library/MemoryAllocationLib.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 Virtual Memory Map of your platform
29
30 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.
31
32 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-
33 Virtual Memory mapping. This array must be ended by a zero-filled
34 entry
35
36 **/
37 VOID ArmPlatformGetVirtualMemoryMap(ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap) {
38 UINT32 val32;
39 UINT32 CacheAttributes;
40 BOOLEAN bTrustzoneSupport;
41 UINTN Index = 0;
42 ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
43
44 ASSERT(VirtualMemoryMap != NULL);
45
46 VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages(sizeof(ARM_MEMORY_REGION_DESCRIPTOR) * 9);
47 if (VirtualMemoryTable == NULL) {
48 return;
49 }
50
51 // Check if SMC TZASC is enabled. If Trustzone not enabled then all the entries remain in Secure World.
52 // As this value can be changed in the Board Configuration file, the UEFI firmware needs to work for both case
53 val32 = MmioRead32(ARM_VE_SYS_CFGRW1_REG);
54 if (ARM_VE_CFGRW1_TZASC_EN_BIT_MASK & val32) {
55 bTrustzoneSupport = TRUE;
56 } else {
57 bTrustzoneSupport = FALSE;
58 }
59
60 if (FeaturePcdGet(PcdCacheEnable) == TRUE) {
61 CacheAttributes = (bTrustzoneSupport ? DDR_ATTRIBUTES_CACHED : DDR_ATTRIBUTES_SECURE_CACHED);
62 } else {
63 CacheAttributes = (bTrustzoneSupport ? DDR_ATTRIBUTES_UNCACHED : DDR_ATTRIBUTES_SECURE_UNCACHED);
64 }
65
66 // ReMap (Either NOR Flash or DRAM)
67 VirtualMemoryTable[Index].PhysicalBase = ARM_VE_REMAP_BASE;
68 VirtualMemoryTable[Index].VirtualBase = ARM_VE_REMAP_BASE;
69 VirtualMemoryTable[Index].Length = ARM_VE_REMAP_SZ;
70 VirtualMemoryTable[Index].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)CacheAttributes;
71
72 // DDR
73 VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_DRAM_BASE;
74 VirtualMemoryTable[Index].VirtualBase = ARM_VE_DRAM_BASE;
75 VirtualMemoryTable[Index].Length = ARM_VE_DRAM_SZ;
76 VirtualMemoryTable[Index].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)CacheAttributes;
77
78 // SMC CS7
79 VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_MB_ON_CHIP_PERIPH_BASE;
80 VirtualMemoryTable[Index].VirtualBase = ARM_VE_SMB_MB_ON_CHIP_PERIPH_BASE;
81 VirtualMemoryTable[Index].Length = ARM_VE_SMB_MB_ON_CHIP_PERIPH_SZ;
82 VirtualMemoryTable[Index].Attributes = (bTrustzoneSupport ? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE : ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE);
83
84 // SMB CS0-CS1 - NOR Flash 1 & 2
85 VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_NOR0_BASE;
86 VirtualMemoryTable[Index].VirtualBase = ARM_VE_SMB_NOR0_BASE;
87 VirtualMemoryTable[Index].Length = ARM_VE_SMB_NOR0_SZ + ARM_VE_SMB_NOR1_SZ;
88 VirtualMemoryTable[Index].Attributes = (bTrustzoneSupport ? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE : ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE);
89
90 // SMB CS2 - SRAM
91 VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_SRAM_BASE;
92 VirtualMemoryTable[Index].VirtualBase = ARM_VE_SMB_SRAM_BASE;
93 VirtualMemoryTable[Index].Length = ARM_VE_SMB_SRAM_SZ;
94 VirtualMemoryTable[Index].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)CacheAttributes;
95
96 // SMB CS3-CS6 - Motherboard Peripherals
97 VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_PERIPH_BASE;
98 VirtualMemoryTable[Index].VirtualBase = ARM_VE_SMB_PERIPH_BASE;
99 VirtualMemoryTable[Index].Length = ARM_VE_SMB_PERIPH_SZ;
100 VirtualMemoryTable[Index].Attributes = (bTrustzoneSupport ? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE : ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE);
101
102 // If a Logic Tile is connected to The ARM Versatile Express Motherboard
103 if (MmioRead32(ARM_VE_SYS_PROCID1_REG) != 0) {
104 VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_EXT_AXI_BASE;
105 VirtualMemoryTable[Index].VirtualBase = ARM_VE_EXT_AXI_BASE;
106 VirtualMemoryTable[Index].Length = ARM_VE_EXT_AXI_SZ;
107 VirtualMemoryTable[Index].Attributes = (bTrustzoneSupport ? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE : ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE);
108 }
109
110 // End of Table
111 VirtualMemoryTable[++Index].PhysicalBase = 0;
112 VirtualMemoryTable[Index].VirtualBase = 0;
113 VirtualMemoryTable[Index].Length = 0;
114 VirtualMemoryTable[Index].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)0;
115
116 *VirtualMemoryMap = VirtualMemoryTable;
117 }
118
119 /**
120 Return the EFI Memory Map of your platform
121
122 This EFI Memory Map of the System Memory is used by MemoryInitPei module to create the Resource
123 Descriptor HOBs used by DXE core.
124
125 @param[out] EfiMemoryMap Array of ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR describing an
126 EFI Memory region. This array must be ended by a zero-filled entry
127
128 **/
129 EFI_STATUS
130 ArmPlatformGetAdditionalSystemMemory (
131 OUT ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR** EfiMemoryMap
132 )
133 {
134 return EFI_UNSUPPORTED;
135 }