]>
Commit | Line | Data |
---|---|---|
30436034 AB |
1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2014-2017, Linaro Limited. All rights reserved.\r | |
4 | \r | |
9792fb0e | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
30436034 AB |
6 | \r |
7 | **/\r | |
8 | \r | |
7136d549 AB |
9 | #include <Uefi.h>\r |
10 | #include <Pi/PiMultiPhase.h>\r | |
30436034 AB |
11 | #include <Library/ArmLib.h>\r |
12 | #include <Library/BaseMemoryLib.h>\r | |
13 | #include <Library/DebugLib.h>\r | |
7136d549 | 14 | #include <Library/HobLib.h>\r |
30436034 AB |
15 | #include <Library/MemoryAllocationLib.h>\r |
16 | \r | |
17 | // Number of Virtual Memory Map Descriptors\r | |
2b16a4fb | 18 | #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5\r |
30436034 | 19 | \r |
51bb05c7 AB |
20 | //\r |
21 | // mach-virt's core peripherals such as the UART, the GIC and the RTC are\r | |
22 | // all mapped in the 'miscellaneous device I/O' region, which we just map\r | |
23 | // in its entirety rather than device by device. Note that it does not\r | |
24 | // cover any of the NOR flash banks or PCI resource windows.\r | |
25 | //\r | |
2b16a4fb MK |
26 | #define MACH_VIRT_PERIPH_BASE 0x08000000\r |
27 | #define MACH_VIRT_PERIPH_SIZE SIZE_128MB\r | |
51bb05c7 | 28 | \r |
7136d549 AB |
29 | /**\r |
30 | Default library constructur that obtains the memory size from a PCD.\r | |
31 | \r | |
32 | @return Always returns RETURN_SUCCESS\r | |
33 | \r | |
34 | **/\r | |
35 | RETURN_STATUS\r | |
36 | EFIAPI\r | |
37 | QemuVirtMemInfoLibConstructor (\r | |
38 | VOID\r | |
39 | )\r | |
40 | {\r | |
41 | UINT64 Size;\r | |
42 | VOID *Hob;\r | |
43 | \r | |
44 | Size = PcdGet64 (PcdSystemMemorySize);\r | |
45 | Hob = BuildGuidDataHob (&gArmVirtSystemMemorySizeGuid, &Size, sizeof Size);\r | |
46 | ASSERT (Hob != NULL);\r | |
47 | \r | |
48 | return RETURN_SUCCESS;\r | |
49 | }\r | |
50 | \r | |
30436034 AB |
51 | /**\r |
52 | Return the Virtual Memory Map of your platform\r | |
53 | \r | |
54 | This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU\r | |
55 | on your platform.\r | |
56 | \r | |
57 | @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR\r | |
58 | describing a Physical-to-Virtual Memory\r | |
59 | mapping. This array must be ended by a\r | |
60 | zero-filled entry. The allocated memory\r | |
61 | will not be freed.\r | |
62 | \r | |
63 | **/\r | |
64 | VOID\r | |
65 | ArmVirtGetMemoryMap (\r | |
2b16a4fb | 66 | OUT ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap\r |
30436034 AB |
67 | )\r |
68 | {\r | |
69 | ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;\r | |
7136d549 | 70 | VOID *MemorySizeHob;\r |
30436034 AB |
71 | \r |
72 | ASSERT (VirtualMemoryMap != NULL);\r | |
73 | \r | |
7136d549 AB |
74 | MemorySizeHob = GetFirstGuidHob (&gArmVirtSystemMemorySizeGuid);\r |
75 | ASSERT (MemorySizeHob != NULL);\r | |
76 | if (MemorySizeHob == NULL) {\r | |
77 | return;\r | |
78 | }\r | |
79 | \r | |
2b16a4fb MK |
80 | VirtualMemoryTable = AllocatePool (\r |
81 | sizeof (ARM_MEMORY_REGION_DESCRIPTOR) *\r | |
82 | MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS\r | |
83 | );\r | |
30436034 AB |
84 | \r |
85 | if (VirtualMemoryTable == NULL) {\r | |
86 | DEBUG ((DEBUG_ERROR, "%a: Error: Failed AllocatePool()\n", __FUNCTION__));\r | |
87 | return;\r | |
88 | }\r | |
89 | \r | |
90 | // System DRAM\r | |
91 | VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);\r | |
92 | VirtualMemoryTable[0].VirtualBase = VirtualMemoryTable[0].PhysicalBase;\r | |
7136d549 | 93 | VirtualMemoryTable[0].Length = *(UINT64 *)GET_GUID_HOB_DATA (MemorySizeHob);\r |
30436034 AB |
94 | VirtualMemoryTable[0].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;\r |
95 | \r | |
2b16a4fb MK |
96 | DEBUG ((\r |
97 | DEBUG_INFO,\r | |
98 | "%a: Dumping System DRAM Memory Map:\n"\r | |
99 | "\tPhysicalBase: 0x%lX\n"\r | |
100 | "\tVirtualBase: 0x%lX\n"\r | |
101 | "\tLength: 0x%lX\n",\r | |
102 | __FUNCTION__,\r | |
103 | VirtualMemoryTable[0].PhysicalBase,\r | |
104 | VirtualMemoryTable[0].VirtualBase,\r | |
105 | VirtualMemoryTable[0].Length\r | |
106 | ));\r | |
30436034 | 107 | \r |
51bb05c7 AB |
108 | // Memory mapped peripherals (UART, RTC, GIC, virtio-mmio, etc)\r |
109 | VirtualMemoryTable[1].PhysicalBase = MACH_VIRT_PERIPH_BASE;\r | |
110 | VirtualMemoryTable[1].VirtualBase = MACH_VIRT_PERIPH_BASE;\r | |
111 | VirtualMemoryTable[1].Length = MACH_VIRT_PERIPH_SIZE;\r | |
30436034 AB |
112 | VirtualMemoryTable[1].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r |
113 | \r | |
51bb05c7 AB |
114 | // Map the FV region as normal executable memory\r |
115 | VirtualMemoryTable[2].PhysicalBase = PcdGet64 (PcdFvBaseAddress);\r | |
364eed84 | 116 | VirtualMemoryTable[2].VirtualBase = VirtualMemoryTable[2].PhysicalBase;\r |
51bb05c7 | 117 | VirtualMemoryTable[2].Length = FixedPcdGet32 (PcdFvSize);\r |
364eed84 | 118 | VirtualMemoryTable[2].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;\r |
30436034 AB |
119 | \r |
120 | // End of Table\r | |
364eed84 | 121 | ZeroMem (&VirtualMemoryTable[3], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));\r |
30436034 AB |
122 | \r |
123 | *VirtualMemoryMap = VirtualMemoryTable;\r | |
124 | }\r |