]>
Commit | Line | Data |
---|---|---|
1ddb209e | 1 | /** @file\r |
2 | *\r | |
3e8ddb4a | 3 | * Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r |
1ddb209e | 4 | *\r |
3402aac7 RC |
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 | |
1ddb209e | 12 | *\r |
13 | **/\r | |
14 | \r | |
15 | #include <Library/ArmPlatformLib.h>\r | |
16 | #include <Library/DebugLib.h>\r | |
df44112b | 17 | #include <Library/HobLib.h>\r |
1ddb209e | 18 | #include <Library/PcdLib.h>\r |
19 | #include <Library/IoLib.h>\r | |
20 | #include <Library/MemoryAllocationLib.h>\r | |
21 | #include <ArmPlatform.h>\r | |
22 | \r | |
3e8ddb4a | 23 | // Number of Virtual Memory Map Descriptors\r |
df44112b | 24 | #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 6\r |
1ddb209e | 25 | \r |
26 | // DDR attributes\r | |
05153ff2 EL |
27 | #define DDR_ATTRIBUTES_CACHED ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK\r |
28 | #define DDR_ATTRIBUTES_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED\r | |
1ddb209e | 29 | \r |
30 | /**\r | |
31 | Return the Virtual Memory Map of your platform\r | |
32 | \r | |
05153ff2 EL |
33 | This Virtual Memory Map is used by MemoryInitPei Module to initialize\r |
34 | the MMU on your platform.\r | |
1ddb209e | 35 | \r |
05153ff2 EL |
36 | @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR\r |
37 | describing a Physical-to-Virtual Memory\r | |
38 | mapping. This array must be ended by a\r | |
39 | zero-filled entry.\r | |
1ddb209e | 40 | \r |
41 | **/\r | |
42 | VOID\r | |
43 | ArmPlatformGetVirtualMemoryMap (\r | |
44 | IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap\r | |
45 | )\r | |
46 | {\r | |
47 | ARM_MEMORY_REGION_ATTRIBUTES CacheAttributes;\r | |
df44112b | 48 | EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;\r |
1ddb209e | 49 | UINTN Index = 0;\r |
50 | ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;\r | |
df44112b OM |
51 | UINT32 SysId;\r |
52 | BOOLEAN HasSparseMemory;\r | |
53 | EFI_VIRTUAL_ADDRESS SparseMemoryBase;\r | |
54 | UINT64 SparseMemorySize;\r | |
55 | \r | |
56 | ASSERT (VirtualMemoryMap != NULL);\r | |
57 | \r | |
58 | // The FVP model has Sparse memory\r | |
59 | SysId = MmioRead32 (ARM_VE_SYS_ID_REG);\r | |
60 | if (SysId != ARM_RTSM_SYS_ID) {\r | |
61 | HasSparseMemory = TRUE;\r | |
62 | \r | |
63 | ResourceAttributes =\r | |
05153ff2 EL |
64 | EFI_RESOURCE_ATTRIBUTE_PRESENT |\r |
65 | EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r | |
66 | EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r | |
67 | EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r | |
68 | EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |\r | |
69 | EFI_RESOURCE_ATTRIBUTE_TESTED;\r | |
df44112b OM |
70 | \r |
71 | // Declared the additional DRAM from 2GB to 4GB\r | |
72 | SparseMemoryBase = 0x0880000000;\r | |
73 | SparseMemorySize = SIZE_2GB;\r | |
74 | \r | |
75 | BuildResourceDescriptorHob (\r | |
76 | EFI_RESOURCE_SYSTEM_MEMORY,\r | |
77 | ResourceAttributes,\r | |
78 | SparseMemoryBase,\r | |
79 | SparseMemorySize);\r | |
80 | } else {\r | |
81 | HasSparseMemory = FALSE;\r | |
f9e420d5 HL |
82 | SparseMemoryBase = 0x0;\r |
83 | SparseMemorySize = 0x0;\r | |
df44112b | 84 | }\r |
1ddb209e | 85 | \r |
05153ff2 EL |
86 | VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)\r |
87 | AllocatePages (EFI_SIZE_TO_PAGES (sizeof(ARM_MEMORY_REGION_DESCRIPTOR)\r | |
88 | * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));\r | |
1ddb209e | 89 | if (VirtualMemoryTable == NULL) {\r |
05153ff2 | 90 | return;\r |
1ddb209e | 91 | }\r |
92 | \r | |
05153ff2 EL |
93 | CacheAttributes = (FeaturePcdGet(PcdCacheEnable))\r |
94 | ? DDR_ATTRIBUTES_CACHED\r | |
95 | : DDR_ATTRIBUTES_UNCACHED;\r | |
1ddb209e | 96 | \r |
97 | // ReMap (Either NOR Flash or DRAM)\r | |
98 | VirtualMemoryTable[Index].PhysicalBase = ARM_VE_REMAP_BASE;\r | |
05153ff2 EL |
99 | VirtualMemoryTable[Index].VirtualBase = ARM_VE_REMAP_BASE;\r |
100 | VirtualMemoryTable[Index].Length = ARM_VE_REMAP_SZ;\r | |
101 | VirtualMemoryTable[Index].Attributes = CacheAttributes;\r | |
1ddb209e | 102 | \r |
103 | // DDR\r | |
104 | VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_DRAM_BASE;\r | |
05153ff2 EL |
105 | VirtualMemoryTable[Index].VirtualBase = ARM_VE_DRAM_BASE;\r |
106 | VirtualMemoryTable[Index].Length = ARM_VE_DRAM_SZ;\r | |
107 | VirtualMemoryTable[Index].Attributes = CacheAttributes;\r | |
1ddb209e | 108 | \r |
109 | // CPU peripherals. TRM. Manual says not all of them are implemented.\r | |
110 | VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_ON_CHIP_PERIPH_BASE;\r | |
05153ff2 EL |
111 | VirtualMemoryTable[Index].VirtualBase = ARM_VE_ON_CHIP_PERIPH_BASE;\r |
112 | VirtualMemoryTable[Index].Length = ARM_VE_ON_CHIP_PERIPH_SZ;\r | |
113 | VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r | |
1ddb209e | 114 | \r |
115 | // SMB CS0-CS1 - NOR Flash 1 & 2\r | |
116 | VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_NOR0_BASE;\r | |
05153ff2 EL |
117 | VirtualMemoryTable[Index].VirtualBase = ARM_VE_SMB_NOR0_BASE;\r |
118 | VirtualMemoryTable[Index].Length = ARM_VE_SMB_NOR0_SZ + ARM_VE_SMB_NOR1_SZ;\r | |
119 | VirtualMemoryTable[Index].Attributes = CacheAttributes;\r | |
1ddb209e | 120 | \r |
121 | // SMB CS2 - SRAM\r | |
122 | VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_SRAM_BASE;\r | |
05153ff2 EL |
123 | VirtualMemoryTable[Index].VirtualBase = ARM_VE_SMB_SRAM_BASE;\r |
124 | VirtualMemoryTable[Index].Length = ARM_VE_SMB_SRAM_SZ;\r | |
125 | VirtualMemoryTable[Index].Attributes = CacheAttributes;\r | |
1ddb209e | 126 | \r |
127 | // Peripheral CS2 and CS3\r | |
128 | VirtualMemoryTable[++Index].PhysicalBase = ARM_VE_SMB_PERIPH_BASE;\r | |
05153ff2 EL |
129 | VirtualMemoryTable[Index].VirtualBase = ARM_VE_SMB_PERIPH_BASE;\r |
130 | VirtualMemoryTable[Index].Length = 2 * ARM_VE_SMB_PERIPH_SZ;\r | |
131 | VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r | |
1ddb209e | 132 | \r |
df44112b OM |
133 | // Map sparse memory region if present\r |
134 | if (HasSparseMemory) {\r | |
135 | VirtualMemoryTable[++Index].PhysicalBase = SparseMemoryBase;\r | |
05153ff2 EL |
136 | VirtualMemoryTable[Index].VirtualBase = SparseMemoryBase;\r |
137 | VirtualMemoryTable[Index].Length = SparseMemorySize;\r | |
138 | VirtualMemoryTable[Index].Attributes = CacheAttributes;\r | |
df44112b OM |
139 | }\r |
140 | \r | |
1ddb209e | 141 | // End of Table\r |
142 | VirtualMemoryTable[++Index].PhysicalBase = 0;\r | |
05153ff2 EL |
143 | VirtualMemoryTable[Index].VirtualBase = 0;\r |
144 | VirtualMemoryTable[Index].Length = 0;\r | |
145 | VirtualMemoryTable[Index].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)0;\r | |
1ddb209e | 146 | \r |
147 | *VirtualMemoryMap = VirtualMemoryTable;\r | |
148 | }\r |