]> git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c
ArmVirtPkg/QemuVirtMemInfoLib: remove 1:1 mapping of top of PA range
[mirror_edk2.git] / ArmVirtPkg / Library / QemuVirtMemInfoLib / QemuVirtMemInfoLib.c
1 /** @file
2
3 Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
4
5 This program and the accompanying materials are licensed and made available
6 under the terms and conditions of the BSD License which accompanies this
7 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 <Base.h>
16 #include <Library/ArmLib.h>
17 #include <Library/BaseMemoryLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/MemoryAllocationLib.h>
20
21 // Number of Virtual Memory Map Descriptors
22 #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5
23
24 /**
25 Return the Virtual Memory Map of your platform
26
27 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
28 on your platform.
29
30 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR
31 describing a Physical-to-Virtual Memory
32 mapping. This array must be ended by a
33 zero-filled entry. The allocated memory
34 will not be freed.
35
36 **/
37 VOID
38 ArmVirtGetMemoryMap (
39 OUT ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap
40 )
41 {
42 ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
43
44 ASSERT (VirtualMemoryMap != NULL);
45
46 VirtualMemoryTable = AllocatePool (sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *
47 MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
48
49 if (VirtualMemoryTable == NULL) {
50 DEBUG ((DEBUG_ERROR, "%a: Error: Failed AllocatePool()\n", __FUNCTION__));
51 return;
52 }
53
54 // System DRAM
55 VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);
56 VirtualMemoryTable[0].VirtualBase = VirtualMemoryTable[0].PhysicalBase;
57 VirtualMemoryTable[0].Length = PcdGet64 (PcdSystemMemorySize);
58 VirtualMemoryTable[0].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
59
60 DEBUG ((DEBUG_INFO, "%a: Dumping System DRAM Memory Map:\n"
61 "\tPhysicalBase: 0x%lX\n"
62 "\tVirtualBase: 0x%lX\n"
63 "\tLength: 0x%lX\n",
64 __FUNCTION__,
65 VirtualMemoryTable[0].PhysicalBase,
66 VirtualMemoryTable[0].VirtualBase,
67 VirtualMemoryTable[0].Length));
68
69 // Peripheral space before DRAM
70 VirtualMemoryTable[1].PhysicalBase = 0x0;
71 VirtualMemoryTable[1].VirtualBase = 0x0;
72 VirtualMemoryTable[1].Length = VirtualMemoryTable[0].PhysicalBase;
73 VirtualMemoryTable[1].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
74
75 // Remap the FD region as normal executable memory
76 VirtualMemoryTable[2].PhysicalBase = PcdGet64 (PcdFdBaseAddress);
77 VirtualMemoryTable[2].VirtualBase = VirtualMemoryTable[2].PhysicalBase;
78 VirtualMemoryTable[2].Length = FixedPcdGet32 (PcdFdSize);
79 VirtualMemoryTable[2].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
80
81 // End of Table
82 ZeroMem (&VirtualMemoryTable[3], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));
83
84 *VirtualMemoryMap = VirtualMemoryTable;
85 }