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