]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPlatformPkg/ArmJunoPkg/Library/ArmJunoLib/ArmJunoMem.c
ArmPlatformPkg/ArmJunoPkg: Added Juno development board support
[mirror_edk2.git] / ArmPlatformPkg / ArmJunoPkg / Library / ArmJunoLib / ArmJunoMem.c
1 /** @file
2 *
3 * Copyright (c) 2013-2014, 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 12
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
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 // 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;
122
123 // DDR - 2GB
124 VirtualMemoryTable[++Index].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);
125 VirtualMemoryTable[Index].VirtualBase = PcdGet64 (PcdSystemMemoryBase);
126 VirtualMemoryTable[Index].Length = PcdGet64 (PcdSystemMemorySize);
127 VirtualMemoryTable[Index].Attributes = CacheAttributes;
128
129 // DDR - 6GB
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;
134
135 // End of Table
136 VirtualMemoryTable[++Index].PhysicalBase = 0;
137 VirtualMemoryTable[Index].VirtualBase = 0;
138 VirtualMemoryTable[Index].Length = 0;
139 VirtualMemoryTable[Index].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)0;
140
141 ASSERT((Index + 1) <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
142
143 *VirtualMemoryMap = VirtualMemoryTable;
144 }