]>
Commit | Line | Data |
---|---|---|
a1bcf5c3 AB |
1 | /** @file\r |
2 | *\r | |
3 | * Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r | |
4 | * Copyright (c) 2014, Linaro Limited. All rights reserved.\r | |
5 | *\r | |
6 | * This program and the accompanying materials\r | |
7 | * are licensed and made available under the terms and conditions of the BSD License\r | |
8 | * which accompanies this distribution. The full text of the license may be found at\r | |
9 | * http://opensource.org/licenses/bsd-license.php\r | |
10 | *\r | |
11 | * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | *\r | |
14 | **/\r | |
15 | \r | |
16 | #include <PiPei.h>\r | |
17 | \r | |
5db1cce1 | 18 | #include <Library/ArmMmuLib.h>\r |
39da4861 | 19 | #include <Library/ArmVirtMemInfoLib.h>\r |
a1bcf5c3 AB |
20 | #include <Library/DebugLib.h>\r |
21 | #include <Library/HobLib.h>\r | |
22 | #include <Library/MemoryAllocationLib.h>\r | |
23 | #include <Library/PcdLib.h>\r | |
e1d52990 | 24 | #include <Library/CacheMaintenanceLib.h>\r |
a1bcf5c3 AB |
25 | \r |
26 | VOID\r | |
27 | BuildMemoryTypeInformationHob (\r | |
28 | VOID\r | |
29 | );\r | |
30 | \r | |
31 | VOID\r | |
32 | InitMmu (\r | |
33 | VOID\r | |
34 | )\r | |
35 | {\r | |
36 | ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;\r | |
37 | VOID *TranslationTableBase;\r | |
38 | UINTN TranslationTableSize;\r | |
39 | RETURN_STATUS Status;\r | |
40 | \r | |
41 | // Get Virtual Memory Map from the Platform Library\r | |
39da4861 | 42 | ArmVirtGetMemoryMap (&MemoryTable);\r |
a1bcf5c3 AB |
43 | \r |
44 | //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in\r | |
45 | // DRAM (even at the top of DRAM as it is the first permanent memory allocation)\r | |
46 | Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r | |
47 | if (EFI_ERROR (Status)) {\r | |
48 | DEBUG ((EFI_D_ERROR, "Error: Failed to enable MMU\n"));\r | |
49 | }\r | |
50 | }\r | |
51 | \r | |
52 | EFI_STATUS\r | |
53 | EFIAPI\r | |
54 | MemoryPeim (\r | |
55 | IN EFI_PHYSICAL_ADDRESS UefiMemoryBase,\r | |
56 | IN UINT64 UefiMemorySize\r | |
57 | )\r | |
58 | {\r | |
59 | EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;\r | |
72daeed8 | 60 | UINT64 SystemMemoryTop;\r |
a1bcf5c3 AB |
61 | \r |
62 | // Ensure PcdSystemMemorySize has been set\r | |
63 | ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);\r | |
64 | \r | |
65 | //\r | |
66 | // Now, the permanent memory has been installed, we can call AllocatePages()\r | |
67 | //\r | |
68 | ResourceAttributes = (\r | |
69 | EFI_RESOURCE_ATTRIBUTE_PRESENT |\r | |
70 | EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r | |
a1bcf5c3 AB |
71 | EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |\r |
72 | EFI_RESOURCE_ATTRIBUTE_TESTED\r | |
73 | );\r | |
74 | \r | |
72daeed8 AB |
75 | SystemMemoryTop = PcdGet64 (PcdSystemMemoryBase) +\r |
76 | PcdGet64 (PcdSystemMemorySize);\r | |
77 | \r | |
4a1500db | 78 | if (SystemMemoryTop - 1 > MAX_ALLOC_ADDRESS) {\r |
72daeed8 AB |
79 | BuildResourceDescriptorHob (\r |
80 | EFI_RESOURCE_SYSTEM_MEMORY,\r | |
81 | ResourceAttributes,\r | |
82 | PcdGet64 (PcdSystemMemoryBase),\r | |
4a1500db | 83 | (UINT64)MAX_ALLOC_ADDRESS - PcdGet64 (PcdSystemMemoryBase) + 1\r |
72daeed8 AB |
84 | );\r |
85 | BuildResourceDescriptorHob (\r | |
86 | EFI_RESOURCE_SYSTEM_MEMORY,\r | |
87 | ResourceAttributes,\r | |
4a1500db AB |
88 | (UINT64)MAX_ALLOC_ADDRESS + 1,\r |
89 | SystemMemoryTop - MAX_ALLOC_ADDRESS - 1\r | |
72daeed8 AB |
90 | );\r |
91 | } else {\r | |
92 | BuildResourceDescriptorHob (\r | |
93 | EFI_RESOURCE_SYSTEM_MEMORY,\r | |
94 | ResourceAttributes,\r | |
95 | PcdGet64 (PcdSystemMemoryBase),\r | |
96 | PcdGet64 (PcdSystemMemorySize)\r | |
97 | );\r | |
98 | }\r | |
a1bcf5c3 | 99 | \r |
e1d52990 AB |
100 | //\r |
101 | // When running under virtualization, the PI/UEFI memory region may be\r | |
102 | // clean but not invalidated in system caches or in lower level caches\r | |
103 | // on other CPUs. So invalidate the region by virtual address, to ensure\r | |
104 | // that the contents we put there with the caches and MMU off will still\r | |
105 | // be visible after turning them on.\r | |
106 | //\r | |
107 | InvalidateDataCacheRange ((VOID*)(UINTN)UefiMemoryBase, UefiMemorySize);\r | |
108 | \r | |
a1bcf5c3 AB |
109 | // Build Memory Allocation Hob\r |
110 | InitMmu ();\r | |
111 | \r | |
112 | if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {\r | |
113 | // Optional feature that helps prevent EFI memory map fragmentation.\r | |
114 | BuildMemoryTypeInformationHob ();\r | |
115 | }\r | |
116 | \r | |
117 | return EFI_SUCCESS;\r | |
118 | }\r |