]> git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/Library/ArmVirtPlatformLib/VirtMem.c
e5536ecd8e286a7d93319a785e12f2db6c60ed3a
[mirror_edk2.git] / ArmVirtPkg / Library / ArmVirtPlatformLib / VirtMem.c
1 /** @file
2 *
3 * Copyright (c) 2014, Linaro 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/BaseMemoryLib.h>
18 #include <Library/PcdLib.h>
19 #include <Library/IoLib.h>
20 #include <Library/MemoryAllocationLib.h>
21 #include <Library/ArmPlatformGlobalVariableLib.h>
22 #include <ArmPlatform.h>
23
24 // Number of Virtual Memory Map Descriptors
25 #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5
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 EFI_PHYSICAL_ADDRESS
32 ArmGetPhysAddrTop (
33 VOID
34 );
35
36 /**
37 Return the Virtual Memory Map of your platform
38
39 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
40 on your platform.
41
42 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR
43 describing a Physical-to-Virtual Memory
44 mapping. This array must be ended by a
45 zero-filled entry
46
47 **/
48 VOID
49 ArmPlatformGetVirtualMemoryMap (
50 IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
51 )
52 {
53 ARM_MEMORY_REGION_ATTRIBUTES CacheAttributes;
54 ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
55
56 ASSERT (VirtualMemoryMap != NULL);
57
58 VirtualMemoryTable = AllocatePages (
59 EFI_SIZE_TO_PAGES (
60 sizeof (ARM_MEMORY_REGION_DESCRIPTOR)
61 * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS
62 )
63 );
64
65 if (VirtualMemoryTable == NULL) {
66 DEBUG ((EFI_D_ERROR, "%a: Error: Failed AllocatePages()\n", __FUNCTION__));
67 return;
68 }
69
70 if (FeaturePcdGet (PcdCacheEnable) == TRUE) {
71 CacheAttributes = DDR_ATTRIBUTES_CACHED;
72 } else {
73 CacheAttributes = DDR_ATTRIBUTES_UNCACHED;
74 }
75
76 // System DRAM
77 VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);
78 VirtualMemoryTable[0].VirtualBase = VirtualMemoryTable[0].PhysicalBase;
79 VirtualMemoryTable[0].Length = PcdGet64 (PcdSystemMemorySize);
80 VirtualMemoryTable[0].Attributes = CacheAttributes;
81
82 DEBUG ((EFI_D_INFO, "%a: Dumping System DRAM Memory Map:\n"
83 "\tPhysicalBase: 0x%lX\n"
84 "\tVirtualBase: 0x%lX\n"
85 "\tLength: 0x%lX\n",
86 __FUNCTION__,
87 VirtualMemoryTable[0].PhysicalBase,
88 VirtualMemoryTable[0].VirtualBase,
89 VirtualMemoryTable[0].Length));
90
91 // Peripheral space before DRAM
92 VirtualMemoryTable[1].PhysicalBase = 0x0;
93 VirtualMemoryTable[1].VirtualBase = 0x0;
94 VirtualMemoryTable[1].Length = VirtualMemoryTable[0].PhysicalBase;
95 VirtualMemoryTable[1].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
96
97 // Peripheral space after DRAM
98 VirtualMemoryTable[2].PhysicalBase = VirtualMemoryTable[0].Length + VirtualMemoryTable[1].Length;
99 VirtualMemoryTable[2].VirtualBase = VirtualMemoryTable[2].PhysicalBase;
100 VirtualMemoryTable[2].Length = MIN (1ULL << FixedPcdGet8 (PcdPrePiCpuMemorySize),
101 ArmGetPhysAddrTop ()) -
102 VirtualMemoryTable[2].PhysicalBase;
103 VirtualMemoryTable[2].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
104
105 // Remap the FD region as normal executable memory
106 VirtualMemoryTable[3].PhysicalBase = FixedPcdGet64 (PcdFdBaseAddress);
107 VirtualMemoryTable[3].VirtualBase = VirtualMemoryTable[3].PhysicalBase;
108 VirtualMemoryTable[3].Length = FixedPcdGet32 (PcdFdSize);
109 VirtualMemoryTable[3].Attributes = CacheAttributes;
110
111 // End of Table
112 ZeroMem (&VirtualMemoryTable[4], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));
113
114 *VirtualMemoryMap = VirtualMemoryTable;
115 }