]> git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/Library/QemuVirtMemInfoLib/QemuVirtMemInfoLib.c
ArmVirtPkg/FdtPciHostBridgeLib: map ECAM and I/O spaces in GCD memory map
[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 EFI_PHYSICAL_ADDRESS
25 ArmGetPhysAddrTop (
26 VOID
27 );
28
29 /**
30 Return the Virtual Memory Map of your platform
31
32 This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU
33 on your platform.
34
35 @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR
36 describing a Physical-to-Virtual Memory
37 mapping. This array must be ended by a
38 zero-filled entry. The allocated memory
39 will not be freed.
40
41 **/
42 VOID
43 ArmVirtGetMemoryMap (
44 OUT ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap
45 )
46 {
47 ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
48 UINT64 TopOfMemory;
49
50 ASSERT (VirtualMemoryMap != NULL);
51
52 VirtualMemoryTable = AllocatePool (sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *
53 MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
54
55 if (VirtualMemoryTable == NULL) {
56 DEBUG ((DEBUG_ERROR, "%a: Error: Failed AllocatePool()\n", __FUNCTION__));
57 return;
58 }
59
60 // System DRAM
61 VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);
62 VirtualMemoryTable[0].VirtualBase = VirtualMemoryTable[0].PhysicalBase;
63 VirtualMemoryTable[0].Length = PcdGet64 (PcdSystemMemorySize);
64 VirtualMemoryTable[0].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
65
66 DEBUG ((DEBUG_INFO, "%a: Dumping System DRAM Memory Map:\n"
67 "\tPhysicalBase: 0x%lX\n"
68 "\tVirtualBase: 0x%lX\n"
69 "\tLength: 0x%lX\n",
70 __FUNCTION__,
71 VirtualMemoryTable[0].PhysicalBase,
72 VirtualMemoryTable[0].VirtualBase,
73 VirtualMemoryTable[0].Length));
74
75 // Peripheral space before DRAM
76 VirtualMemoryTable[1].PhysicalBase = 0x0;
77 VirtualMemoryTable[1].VirtualBase = 0x0;
78 VirtualMemoryTable[1].Length = VirtualMemoryTable[0].PhysicalBase;
79 VirtualMemoryTable[1].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
80
81 // Peripheral space after DRAM
82 TopOfMemory = MIN (1ULL << FixedPcdGet8 (PcdPrePiCpuMemorySize),
83 ArmGetPhysAddrTop ());
84 VirtualMemoryTable[2].PhysicalBase = VirtualMemoryTable[0].Length + VirtualMemoryTable[1].Length;
85 VirtualMemoryTable[2].VirtualBase = VirtualMemoryTable[2].PhysicalBase;
86 VirtualMemoryTable[2].Length = TopOfMemory -
87 VirtualMemoryTable[2].PhysicalBase;
88 VirtualMemoryTable[2].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
89
90 // Remap the FD region as normal executable memory
91 VirtualMemoryTable[3].PhysicalBase = PcdGet64 (PcdFdBaseAddress);
92 VirtualMemoryTable[3].VirtualBase = VirtualMemoryTable[3].PhysicalBase;
93 VirtualMemoryTable[3].Length = FixedPcdGet32 (PcdFdSize);
94 VirtualMemoryTable[3].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;
95
96 // End of Table
97 ZeroMem (&VirtualMemoryTable[4], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));
98
99 *VirtualMemoryMap = VirtualMemoryTable;
100 }