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