3 * Copyright (c) 2013-2015, ARM Limited. All rights reserved.
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
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.
15 #include <Library/ArmPlatformLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/HobLib.h>
18 #include <Library/PcdLib.h>
19 #include <Library/IoLib.h>
20 #include <Library/MemoryAllocationLib.h>
22 #include <ArmPlatform.h>
24 // The total number of descriptors, including the final "end-of-table" descriptor.
25 #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 16
28 #define DDR_ATTRIBUTES_CACHED ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
29 #define DDR_ATTRIBUTES_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
32 Return the Virtual Memory Map of your platform
34 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.
36 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-
37 Virtual Memory mapping. This array must be ended by a zero-filled
42 ArmPlatformGetVirtualMemoryMap (
43 IN ARM_MEMORY_REGION_DESCRIPTOR
** VirtualMemoryMap
46 ARM_MEMORY_REGION_ATTRIBUTES CacheAttributes
;
48 ARM_MEMORY_REGION_DESCRIPTOR
*VirtualMemoryTable
;
49 EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes
;
51 ASSERT (VirtualMemoryMap
!= NULL
);
54 // Declared the additional 6GB of memory
57 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
58 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
59 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
60 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
61 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
|
62 EFI_RESOURCE_ATTRIBUTE_TESTED
;
64 BuildResourceDescriptorHob (
65 EFI_RESOURCE_SYSTEM_MEMORY
,
67 ARM_JUNO_EXTRA_SYSTEM_MEMORY_BASE
,
68 ARM_JUNO_EXTRA_SYSTEM_MEMORY_SZ
);
70 VirtualMemoryTable
= (ARM_MEMORY_REGION_DESCRIPTOR
*)AllocatePages(EFI_SIZE_TO_PAGES (sizeof(ARM_MEMORY_REGION_DESCRIPTOR
) * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
));
71 if (VirtualMemoryTable
== NULL
) {
75 if (FeaturePcdGet(PcdCacheEnable
) == TRUE
) {
76 CacheAttributes
= DDR_ATTRIBUTES_CACHED
;
78 CacheAttributes
= DDR_ATTRIBUTES_UNCACHED
;
81 // SMB CS0 - NOR0 Flash
82 VirtualMemoryTable
[Index
].PhysicalBase
= ARM_VE_SMB_NOR0_BASE
;
83 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_SMB_NOR0_BASE
;
84 VirtualMemoryTable
[Index
].Length
= SIZE_256KB
* 255;
85 VirtualMemoryTable
[Index
].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
86 // Environment Variables region
87 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_VE_SMB_NOR0_BASE
+ (SIZE_256KB
* 255);
88 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_SMB_NOR0_BASE
+ (SIZE_256KB
* 255);
89 VirtualMemoryTable
[Index
].Length
= SIZE_64KB
* 4;
90 VirtualMemoryTable
[Index
].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
92 // SMB CS2 & CS3 - Off-chip (motherboard) peripherals
93 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_VE_SMB_PERIPH_BASE
;
94 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_SMB_PERIPH_BASE
;
95 VirtualMemoryTable
[Index
].Length
= ARM_VE_SMB_PERIPH_SZ
;
96 VirtualMemoryTable
[Index
].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
98 // Juno OnChip non-secure ROM
99 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_JUNO_NON_SECURE_ROM_BASE
;
100 VirtualMemoryTable
[Index
].VirtualBase
= ARM_JUNO_NON_SECURE_ROM_BASE
;
101 VirtualMemoryTable
[Index
].Length
= ARM_JUNO_NON_SECURE_ROM_SZ
;
102 VirtualMemoryTable
[Index
].Attributes
= CacheAttributes
;
104 // Juno OnChip peripherals
105 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_JUNO_PERIPHERALS_BASE
;
106 VirtualMemoryTable
[Index
].VirtualBase
= ARM_JUNO_PERIPHERALS_BASE
;
107 VirtualMemoryTable
[Index
].Length
= ARM_JUNO_PERIPHERALS_SZ
;
108 VirtualMemoryTable
[Index
].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
110 // Juno OnChip non-secure SRAM
111 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_JUNO_NON_SECURE_SRAM_BASE
;
112 VirtualMemoryTable
[Index
].VirtualBase
= ARM_JUNO_NON_SECURE_SRAM_BASE
;
113 VirtualMemoryTable
[Index
].Length
= ARM_JUNO_NON_SECURE_SRAM_SZ
;
114 VirtualMemoryTable
[Index
].Attributes
= CacheAttributes
;
117 VirtualMemoryTable
[++Index
].PhysicalBase
= PcdGet64 (PcdPcieControlBaseAddress
);
118 VirtualMemoryTable
[Index
].VirtualBase
= PcdGet64 (PcdPcieControlBaseAddress
);
119 VirtualMemoryTable
[Index
].Length
= SIZE_128KB
;
120 VirtualMemoryTable
[Index
].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
123 // PCI Configuration Space
125 VirtualMemoryTable
[++Index
].PhysicalBase
= PcdGet64 (PcdPciConfigurationSpaceBaseAddress
);
126 VirtualMemoryTable
[Index
].VirtualBase
= PcdGet64 (PcdPciConfigurationSpaceBaseAddress
);
127 VirtualMemoryTable
[Index
].Length
= PcdGet64 (PcdPciConfigurationSpaceSize
);
128 VirtualMemoryTable
[Index
].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
133 VirtualMemoryTable
[++Index
].PhysicalBase
= PcdGet32 (PcdPciMmio32Base
);
134 VirtualMemoryTable
[Index
].VirtualBase
= PcdGet32 (PcdPciMmio32Base
);
135 VirtualMemoryTable
[Index
].Length
= PcdGet32 (PcdPciMmio32Size
);
136 VirtualMemoryTable
[Index
].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
139 // 64-bit PCI Memory Space
141 VirtualMemoryTable
[++Index
].PhysicalBase
= PcdGet64 (PcdPciMmio64Base
);
142 VirtualMemoryTable
[Index
].VirtualBase
= PcdGet64 (PcdPciMmio64Base
);
143 VirtualMemoryTable
[Index
].Length
= PcdGet64 (PcdPciMmio64Size
);
144 VirtualMemoryTable
[Index
].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
146 // Juno SOC peripherals
147 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_JUNO_SOC_PERIPHERALS_BASE
;
148 VirtualMemoryTable
[Index
].VirtualBase
= ARM_JUNO_SOC_PERIPHERALS_BASE
;
149 VirtualMemoryTable
[Index
].Length
= ARM_JUNO_SOC_PERIPHERALS_SZ
;
150 VirtualMemoryTable
[Index
].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
153 VirtualMemoryTable
[++Index
].PhysicalBase
= PcdGet64 (PcdSystemMemoryBase
);
154 VirtualMemoryTable
[Index
].VirtualBase
= PcdGet64 (PcdSystemMemoryBase
);
155 VirtualMemoryTable
[Index
].Length
= PcdGet64 (PcdSystemMemorySize
);
156 VirtualMemoryTable
[Index
].Attributes
= CacheAttributes
;
159 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_JUNO_EXTRA_SYSTEM_MEMORY_BASE
;
160 VirtualMemoryTable
[Index
].VirtualBase
= ARM_JUNO_EXTRA_SYSTEM_MEMORY_BASE
;
161 VirtualMemoryTable
[Index
].Length
= ARM_JUNO_EXTRA_SYSTEM_MEMORY_SZ
;
162 VirtualMemoryTable
[Index
].Attributes
= CacheAttributes
;
165 VirtualMemoryTable
[++Index
].PhysicalBase
= 0;
166 VirtualMemoryTable
[Index
].VirtualBase
= 0;
167 VirtualMemoryTable
[Index
].Length
= 0;
168 VirtualMemoryTable
[Index
].Attributes
= (ARM_MEMORY_REGION_ATTRIBUTES
)0;
170 ASSERT((Index
+ 1) <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
);
172 *VirtualMemoryMap
= VirtualMemoryTable
;