]>
Commit | Line | Data |
---|---|---|
a36d531f MC |
1 | /** @file\r |
2 | *\r | |
3 | * Copyright (c) 2014, Linaro Limited. All rights reserved.\r | |
4 | *\r | |
5 | * This program and the accompanying materials\r | |
6 | * are licensed and made available under the terms and conditions of the BSD License\r | |
7 | * which accompanies this distribution. The full text of the license may be found at\r | |
8 | * http://opensource.org/licenses/bsd-license.php\r | |
9 | *\r | |
10 | * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | *\r | |
13 | **/\r | |
14 | \r | |
15 | #include <Library/ArmPlatformLib.h>\r | |
16 | #include <Library/DebugLib.h>\r | |
17 | #include <Library/BaseMemoryLib.h>\r | |
18 | #include <Library/PcdLib.h>\r | |
19 | #include <Library/IoLib.h>\r | |
20 | #include <Library/MemoryAllocationLib.h>\r | |
a36d531f MC |
21 | \r |
22 | // Number of Virtual Memory Map Descriptors\r | |
dca7f96f | 23 | #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 5\r |
a36d531f | 24 | \r |
a36d531f MC |
25 | EFI_PHYSICAL_ADDRESS\r |
26 | ArmGetPhysAddrTop (\r | |
27 | VOID\r | |
28 | );\r | |
29 | \r | |
30 | /**\r | |
31 | Return the Virtual Memory Map of your platform\r | |
32 | \r | |
33 | This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU\r | |
34 | on your platform.\r | |
35 | \r | |
36 | @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR\r | |
37 | describing a Physical-to-Virtual Memory\r | |
38 | mapping. This array must be ended by a\r | |
39 | zero-filled entry\r | |
40 | \r | |
41 | **/\r | |
42 | VOID\r | |
43 | ArmPlatformGetVirtualMemoryMap (\r | |
44 | IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap\r | |
45 | )\r | |
46 | {\r | |
a36d531f MC |
47 | ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;\r |
48 | \r | |
49 | ASSERT (VirtualMemoryMap != NULL);\r | |
50 | \r | |
51 | VirtualMemoryTable = AllocatePages (\r | |
52 | EFI_SIZE_TO_PAGES (\r | |
53 | sizeof (ARM_MEMORY_REGION_DESCRIPTOR)\r | |
54 | * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS\r | |
55 | )\r | |
56 | );\r | |
57 | \r | |
58 | if (VirtualMemoryTable == NULL) {\r | |
59 | DEBUG ((EFI_D_ERROR, "%a: Error: Failed AllocatePages()\n", __FUNCTION__));\r | |
60 | return;\r | |
61 | }\r | |
62 | \r | |
a36d531f MC |
63 | // System DRAM\r |
64 | VirtualMemoryTable[0].PhysicalBase = PcdGet64 (PcdSystemMemoryBase);\r | |
65 | VirtualMemoryTable[0].VirtualBase = VirtualMemoryTable[0].PhysicalBase;\r | |
66 | VirtualMemoryTable[0].Length = PcdGet64 (PcdSystemMemorySize);\r | |
dc1235c1 | 67 | VirtualMemoryTable[0].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;\r |
a36d531f MC |
68 | \r |
69 | DEBUG ((EFI_D_INFO, "%a: Dumping System DRAM Memory Map:\n"\r | |
70 | "\tPhysicalBase: 0x%lX\n"\r | |
71 | "\tVirtualBase: 0x%lX\n"\r | |
72 | "\tLength: 0x%lX\n",\r | |
73 | __FUNCTION__,\r | |
74 | VirtualMemoryTable[0].PhysicalBase,\r | |
75 | VirtualMemoryTable[0].VirtualBase,\r | |
76 | VirtualMemoryTable[0].Length));\r | |
77 | \r | |
78 | // Peripheral space before DRAM\r | |
79 | VirtualMemoryTable[1].PhysicalBase = 0x0;\r | |
80 | VirtualMemoryTable[1].VirtualBase = 0x0;\r | |
81 | VirtualMemoryTable[1].Length = VirtualMemoryTable[0].PhysicalBase;\r | |
82 | VirtualMemoryTable[1].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r | |
83 | \r | |
84 | // Peripheral space after DRAM\r | |
85 | VirtualMemoryTable[2].PhysicalBase = VirtualMemoryTable[0].Length + VirtualMemoryTable[1].Length;\r | |
86 | VirtualMemoryTable[2].VirtualBase = VirtualMemoryTable[2].PhysicalBase;\r | |
1dc3f34f AB |
87 | VirtualMemoryTable[2].Length = MIN (1ULL << FixedPcdGet8 (PcdPrePiCpuMemorySize),\r |
88 | ArmGetPhysAddrTop ()) -\r | |
89 | VirtualMemoryTable[2].PhysicalBase;\r | |
a36d531f MC |
90 | VirtualMemoryTable[2].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r |
91 | \r | |
dca7f96f AB |
92 | // Remap the FD region as normal executable memory\r |
93 | VirtualMemoryTable[3].PhysicalBase = FixedPcdGet64 (PcdFdBaseAddress);\r | |
94 | VirtualMemoryTable[3].VirtualBase = VirtualMemoryTable[3].PhysicalBase;\r | |
95 | VirtualMemoryTable[3].Length = FixedPcdGet32 (PcdFdSize);\r | |
dc1235c1 | 96 | VirtualMemoryTable[3].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK;\r |
dca7f96f | 97 | \r |
a36d531f | 98 | // End of Table\r |
dca7f96f | 99 | ZeroMem (&VirtualMemoryTable[4], sizeof (ARM_MEMORY_REGION_DESCRIPTOR));\r |
a36d531f MC |
100 | \r |
101 | *VirtualMemoryMap = VirtualMemoryTable;\r | |
102 | }\r |