• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2 *
3 *  Copyright (c) 2013-2015, 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/HobLib.h>
18 #include <Library/PcdLib.h>
19 #include <Library/IoLib.h>
20 #include <Library/MemoryAllocationLib.h>
21 
22 #include <ArmPlatform.h>
23 
24 // The total number of descriptors, including the final "end-of-table" descriptor.
25 #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 16
26 
27 // DDR attributes
28 #define DDR_ATTRIBUTES_CACHED           ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
29 #define DDR_ATTRIBUTES_UNCACHED         ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
30 
31 /**
32   Return the Virtual Memory Map of your platform
33 
34   This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.
35 
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
38                                     entry
39 
40 **/
41 VOID
ArmPlatformGetVirtualMemoryMap(IN ARM_MEMORY_REGION_DESCRIPTOR ** VirtualMemoryMap)42 ArmPlatformGetVirtualMemoryMap (
43   IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
44   )
45 {
46   ARM_MEMORY_REGION_ATTRIBUTES  CacheAttributes;
47   UINTN                         Index = 0;
48   ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;
49   EFI_RESOURCE_ATTRIBUTE_TYPE   ResourceAttributes;
50 
51   ASSERT (VirtualMemoryMap != NULL);
52 
53   //
54   // Declared the additional 6GB of memory
55   //
56   ResourceAttributes =
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;
64 
65   BuildResourceDescriptorHob (
66     EFI_RESOURCE_SYSTEM_MEMORY,
67     ResourceAttributes,
68     ARM_JUNO_EXTRA_SYSTEM_MEMORY_BASE,
69     ARM_JUNO_EXTRA_SYSTEM_MEMORY_SZ);
70 
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) {
73       return;
74   }
75 
76   if (FeaturePcdGet(PcdCacheEnable) == TRUE) {
77       CacheAttributes = DDR_ATTRIBUTES_CACHED;
78   } else {
79       CacheAttributes = DDR_ATTRIBUTES_UNCACHED;
80   }
81 
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;
92 
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;
98 
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;
104 
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;
110 
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;
116 
117   // PCI Root Complex
118   VirtualMemoryTable[++Index].PhysicalBase  = PcdGet64 (PcdPcieControlBaseAddress);
119   VirtualMemoryTable[Index].VirtualBase     = PcdGet64 (PcdPcieControlBaseAddress);
120   VirtualMemoryTable[Index].Length          = SIZE_128KB;
121   VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
122 
123   //
124   // PCI Configuration Space
125   //
126   VirtualMemoryTable[++Index].PhysicalBase  = PcdGet64 (PcdPciConfigurationSpaceBaseAddress);
127   VirtualMemoryTable[Index].VirtualBase     = PcdGet64 (PcdPciConfigurationSpaceBaseAddress);
128   VirtualMemoryTable[Index].Length          = PcdGet64 (PcdPciConfigurationSpaceSize);
129   VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
130 
131   //
132   // PCI Memory Space
133   //
134   VirtualMemoryTable[++Index].PhysicalBase  = PcdGet32 (PcdPciMmio32Base);
135   VirtualMemoryTable[Index].VirtualBase     = PcdGet32 (PcdPciMmio32Base);
136   VirtualMemoryTable[Index].Length          = PcdGet32 (PcdPciMmio32Size);
137   VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
138 
139   //
140   // 64-bit PCI Memory Space
141   //
142   VirtualMemoryTable[++Index].PhysicalBase  = PcdGet64 (PcdPciMmio64Base);
143   VirtualMemoryTable[Index].VirtualBase     = PcdGet64 (PcdPciMmio64Base);
144   VirtualMemoryTable[Index].Length          = PcdGet64 (PcdPciMmio64Size);
145   VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
146 
147   // Juno SOC peripherals
148   VirtualMemoryTable[++Index].PhysicalBase  = ARM_JUNO_SOC_PERIPHERALS_BASE;
149   VirtualMemoryTable[Index].VirtualBase     = ARM_JUNO_SOC_PERIPHERALS_BASE;
150   VirtualMemoryTable[Index].Length          = ARM_JUNO_SOC_PERIPHERALS_SZ;
151   VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
152 
153   // DDR - 2GB
154   VirtualMemoryTable[++Index].PhysicalBase  = PcdGet64 (PcdSystemMemoryBase);
155   VirtualMemoryTable[Index].VirtualBase     = PcdGet64 (PcdSystemMemoryBase);
156   VirtualMemoryTable[Index].Length          = PcdGet64 (PcdSystemMemorySize);
157   VirtualMemoryTable[Index].Attributes      = CacheAttributes;
158 
159   // DDR - 6GB
160   VirtualMemoryTable[++Index].PhysicalBase  = ARM_JUNO_EXTRA_SYSTEM_MEMORY_BASE;
161   VirtualMemoryTable[Index].VirtualBase     = ARM_JUNO_EXTRA_SYSTEM_MEMORY_BASE;
162   VirtualMemoryTable[Index].Length          = ARM_JUNO_EXTRA_SYSTEM_MEMORY_SZ;
163   VirtualMemoryTable[Index].Attributes      = CacheAttributes;
164 
165   // End of Table
166   VirtualMemoryTable[++Index].PhysicalBase  = 0;
167   VirtualMemoryTable[Index].VirtualBase     = 0;
168   VirtualMemoryTable[Index].Length          = 0;
169   VirtualMemoryTable[Index].Attributes      = (ARM_MEMORY_REGION_ATTRIBUTES)0;
170 
171   ASSERT((Index + 1) <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
172 
173   *VirtualMemoryMap = VirtualMemoryTable;
174 }
175