]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/ArmRealViewEbPkg/Library/ArmRealViewEbLibRTSM/ArmRealViewEbMem.c
616fa0ef8cafcd4863143e3462745b5d786109d3
[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 #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 6
22
23 // DDR attributes
24 #define DDR_ATTRIBUTES_CACHED ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
25 #define DDR_ATTRIBUTES_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
26 #define DDR_ATTRIBUTES_SECURE_CACHED ARM_MEMORY_REGION_ATTRIBUTE_SECURE_WRITE_BACK
27 #define DDR_ATTRIBUTES_SECURE_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_SECURE_UNCACHED_UNBUFFERED
28
29 /**
30 Return the Virtual Memory Map of your platform
31
32 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.
33
34 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-
35 Virtual Memory mapping. This array must be ended by a zero-filled
36 entry
37
38 **/
39 VOID
40 ArmPlatformGetVirtualMemoryMap (
41 IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
42 )
43 {
44 UINT32 CacheAttributes;
45 BOOLEAN bTrustzoneSupport = FALSE;
46 UINTN Index = 0;
47 ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
48
49 ASSERT(VirtualMemoryMap != NULL);
50
51 VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages(EFI_SIZE_TO_PAGES (sizeof(ARM_MEMORY_REGION_DESCRIPTOR) * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));
52 if (VirtualMemoryTable == NULL) {
53 return;
54 }
55
56 if (FeaturePcdGet(PcdCacheEnable) == TRUE) {
57 CacheAttributes = (bTrustzoneSupport ? DDR_ATTRIBUTES_CACHED : DDR_ATTRIBUTES_SECURE_CACHED);
58 } else {
59 CacheAttributes = (bTrustzoneSupport ? DDR_ATTRIBUTES_UNCACHED : DDR_ATTRIBUTES_SECURE_UNCACHED);
60 }
61
62 // ReMap (Either NOR Flash or DRAM)
63 VirtualMemoryTable[Index].PhysicalBase = ARM_EB_REMAP_BASE;
64 VirtualMemoryTable[Index].VirtualBase = ARM_EB_REMAP_BASE;
65 VirtualMemoryTable[Index].Length = ARM_EB_REMAP_SZ;
66 VirtualMemoryTable[Index].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)CacheAttributes;
67
68 // DDR
69 VirtualMemoryTable[++Index].PhysicalBase = ARM_EB_DRAM_BASE;
70 VirtualMemoryTable[Index].VirtualBase = ARM_EB_DRAM_BASE;
71 VirtualMemoryTable[Index].Length = ARM_EB_DRAM_SZ;
72 VirtualMemoryTable[Index].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)CacheAttributes;
73
74 // SMC CS7
75 VirtualMemoryTable[++Index].PhysicalBase = ARM_EB_SMB_MB_ON_CHIP_PERIPH_BASE;
76 VirtualMemoryTable[Index].VirtualBase = ARM_EB_SMB_MB_ON_CHIP_PERIPH_BASE;
77 VirtualMemoryTable[Index].Length = ARM_EB_SMB_MB_ON_CHIP_PERIPH_SZ;
78 VirtualMemoryTable[Index].Attributes = (bTrustzoneSupport ? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE : ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE);
79
80 // SMB CS0-CS1 - NOR Flash 1 & 2
81 VirtualMemoryTable[++Index].PhysicalBase = ARM_EB_SMB_NOR_BASE;
82 VirtualMemoryTable[Index].VirtualBase = ARM_EB_SMB_NOR_BASE;
83 VirtualMemoryTable[Index].Length = ARM_EB_SMB_NOR_SZ + ARM_EB_SMB_DOC_SZ;
84 VirtualMemoryTable[Index].Attributes = (bTrustzoneSupport ? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE : ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE);
85
86 // SMB CS2 - SRAM
87 VirtualMemoryTable[++Index].PhysicalBase = ARM_EB_SMB_SRAM_BASE;
88 VirtualMemoryTable[Index].VirtualBase = ARM_EB_SMB_SRAM_BASE;
89 VirtualMemoryTable[Index].Length = ARM_EB_SMB_SRAM_SZ;
90 VirtualMemoryTable[Index].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)CacheAttributes;
91
92 // SMB CS3-CS6 - Motherboard Peripherals
93 VirtualMemoryTable[++Index].PhysicalBase = ARM_EB_SMB_PERIPH_BASE;
94 VirtualMemoryTable[Index].VirtualBase = ARM_EB_SMB_PERIPH_BASE;
95 VirtualMemoryTable[Index].Length = ARM_EB_SMB_PERIPH_SZ;
96 VirtualMemoryTable[Index].Attributes = (bTrustzoneSupport ? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE : ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE);
97
98 // If a Logic Tile is connected to The ARM Versatile Express Motherboard
99 if (MmioRead32(ARM_EB_SYS_PROCID1_REG) != 0) {
100 VirtualMemoryTable[++Index].PhysicalBase = ARM_EB_LOGIC_TILE_BASE;
101 VirtualMemoryTable[Index].VirtualBase = ARM_EB_LOGIC_TILE_BASE;
102 VirtualMemoryTable[Index].Length = ARM_EB_LOGIC_TILE_SZ;
103 VirtualMemoryTable[Index].Attributes = (bTrustzoneSupport ? ARM_MEMORY_REGION_ATTRIBUTE_DEVICE : ARM_MEMORY_REGION_ATTRIBUTE_SECURE_DEVICE);
104
105 ASSERT((Index + 1) == (MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS + 1));
106 } else {
107 ASSERT((Index + 1) == MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
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 }