3 * Copyright (c) 2013-2014, 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 12
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_UNCACHEABLE
|
60 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
61 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
62 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
|
63 EFI_RESOURCE_ATTRIBUTE_TESTED
;
65 BuildResourceDescriptorHob (
66 EFI_RESOURCE_SYSTEM_MEMORY
,
68 ARM_JUNO_EXTRA_SYSTEM_MEMORY_BASE
,
69 ARM_JUNO_EXTRA_SYSTEM_MEMORY_SZ
);
71 VirtualMemoryTable
= (ARM_MEMORY_REGION_DESCRIPTOR
*)AllocatePages(EFI_SIZE_TO_PAGES (sizeof(ARM_MEMORY_REGION_DESCRIPTOR
) * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
));
72 if (VirtualMemoryTable
== NULL
) {
76 if (FeaturePcdGet(PcdCacheEnable
) == TRUE
) {
77 CacheAttributes
= DDR_ATTRIBUTES_CACHED
;
79 CacheAttributes
= DDR_ATTRIBUTES_UNCACHED
;
82 // SMB CS0 - NOR0 Flash
83 VirtualMemoryTable
[Index
].PhysicalBase
= ARM_VE_SMB_NOR0_BASE
;
84 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_SMB_NOR0_BASE
;
85 VirtualMemoryTable
[Index
].Length
= SIZE_256KB
* 255;
86 VirtualMemoryTable
[Index
].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
87 // Environment Variables region
88 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_VE_SMB_NOR0_BASE
+ (SIZE_256KB
* 255);
89 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_SMB_NOR0_BASE
+ (SIZE_256KB
* 255);
90 VirtualMemoryTable
[Index
].Length
= SIZE_64KB
* 4;
91 VirtualMemoryTable
[Index
].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
93 // SMB CS2 & CS3 - Off-chip (motherboard) peripherals
94 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_VE_SMB_PERIPH_BASE
;
95 VirtualMemoryTable
[Index
].VirtualBase
= ARM_VE_SMB_PERIPH_BASE
;
96 VirtualMemoryTable
[Index
].Length
= ARM_VE_SMB_PERIPH_SZ
;
97 VirtualMemoryTable
[Index
].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
99 // Juno OnChip non-secure ROM
100 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_JUNO_NON_SECURE_ROM_BASE
;
101 VirtualMemoryTable
[Index
].VirtualBase
= ARM_JUNO_NON_SECURE_ROM_BASE
;
102 VirtualMemoryTable
[Index
].Length
= ARM_JUNO_NON_SECURE_ROM_SZ
;
103 VirtualMemoryTable
[Index
].Attributes
= CacheAttributes
;
105 // Juno OnChip peripherals
106 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_JUNO_PERIPHERALS_BASE
;
107 VirtualMemoryTable
[Index
].VirtualBase
= ARM_JUNO_PERIPHERALS_BASE
;
108 VirtualMemoryTable
[Index
].Length
= ARM_JUNO_PERIPHERALS_SZ
;
109 VirtualMemoryTable
[Index
].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
111 // Juno OnChip non-secure SRAM
112 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_JUNO_NON_SECURE_SRAM_BASE
;
113 VirtualMemoryTable
[Index
].VirtualBase
= ARM_JUNO_NON_SECURE_SRAM_BASE
;
114 VirtualMemoryTable
[Index
].Length
= ARM_JUNO_NON_SECURE_SRAM_SZ
;
115 VirtualMemoryTable
[Index
].Attributes
= CacheAttributes
;
117 // Juno SOC peripherals
118 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_JUNO_SOC_PERIPHERALS_BASE
;
119 VirtualMemoryTable
[Index
].VirtualBase
= ARM_JUNO_SOC_PERIPHERALS_BASE
;
120 VirtualMemoryTable
[Index
].Length
= ARM_JUNO_SOC_PERIPHERALS_SZ
;
121 VirtualMemoryTable
[Index
].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
124 VirtualMemoryTable
[++Index
].PhysicalBase
= PcdGet64 (PcdSystemMemoryBase
);
125 VirtualMemoryTable
[Index
].VirtualBase
= PcdGet64 (PcdSystemMemoryBase
);
126 VirtualMemoryTable
[Index
].Length
= PcdGet64 (PcdSystemMemorySize
);
127 VirtualMemoryTable
[Index
].Attributes
= CacheAttributes
;
130 VirtualMemoryTable
[++Index
].PhysicalBase
= ARM_JUNO_EXTRA_SYSTEM_MEMORY_BASE
;
131 VirtualMemoryTable
[Index
].VirtualBase
= ARM_JUNO_EXTRA_SYSTEM_MEMORY_BASE
;
132 VirtualMemoryTable
[Index
].Length
= ARM_JUNO_EXTRA_SYSTEM_MEMORY_SZ
;
133 VirtualMemoryTable
[Index
].Attributes
= CacheAttributes
;
136 VirtualMemoryTable
[++Index
].PhysicalBase
= 0;
137 VirtualMemoryTable
[Index
].VirtualBase
= 0;
138 VirtualMemoryTable
[Index
].Length
= 0;
139 VirtualMemoryTable
[Index
].Attributes
= (ARM_MEMORY_REGION_ATTRIBUTES
)0;
141 ASSERT((Index
+ 1) <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
);
143 *VirtualMemoryMap
= VirtualMemoryTable
;