]>
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 | |
9792fb0e | 6 | * SPDX-License-Identifier: BSD-2-Clause-Patent\r |
a1bcf5c3 AB |
7 | *\r |
8 | **/\r | |
9 | \r | |
10 | #include <PiPei.h>\r | |
11 | \r | |
5db1cce1 | 12 | #include <Library/ArmMmuLib.h>\r |
39da4861 | 13 | #include <Library/ArmVirtMemInfoLib.h>\r |
a1bcf5c3 AB |
14 | #include <Library/DebugLib.h>\r |
15 | #include <Library/HobLib.h>\r | |
16 | #include <Library/MemoryAllocationLib.h>\r | |
17 | #include <Library/PcdLib.h>\r | |
e1d52990 | 18 | #include <Library/CacheMaintenanceLib.h>\r |
a1bcf5c3 AB |
19 | \r |
20 | VOID\r | |
21 | BuildMemoryTypeInformationHob (\r | |
22 | VOID\r | |
23 | );\r | |
24 | \r | |
25 | VOID\r | |
26 | InitMmu (\r | |
27 | VOID\r | |
28 | )\r | |
29 | {\r | |
30 | ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;\r | |
31 | VOID *TranslationTableBase;\r | |
32 | UINTN TranslationTableSize;\r | |
33 | RETURN_STATUS Status;\r | |
34 | \r | |
35 | // Get Virtual Memory Map from the Platform Library\r | |
39da4861 | 36 | ArmVirtGetMemoryMap (&MemoryTable);\r |
a1bcf5c3 | 37 | \r |
2b16a4fb | 38 | // Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in\r |
a1bcf5c3 AB |
39 | // DRAM (even at the top of DRAM as it is the first permanent memory allocation)\r |
40 | Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r | |
41 | if (EFI_ERROR (Status)) {\r | |
c5b3a56e | 42 | DEBUG ((DEBUG_ERROR, "Error: Failed to enable MMU\n"));\r |
a1bcf5c3 AB |
43 | }\r |
44 | }\r | |
45 | \r | |
46 | EFI_STATUS\r | |
47 | EFIAPI\r | |
48 | MemoryPeim (\r | |
2b16a4fb MK |
49 | IN EFI_PHYSICAL_ADDRESS UefiMemoryBase,\r |
50 | IN UINT64 UefiMemorySize\r | |
a1bcf5c3 AB |
51 | )\r |
52 | {\r | |
2b16a4fb MK |
53 | EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;\r |
54 | UINT64 SystemMemoryTop;\r | |
a1bcf5c3 AB |
55 | \r |
56 | // Ensure PcdSystemMemorySize has been set\r | |
57 | ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);\r | |
58 | \r | |
59 | //\r | |
60 | // Now, the permanent memory has been installed, we can call AllocatePages()\r | |
61 | //\r | |
62 | ResourceAttributes = (\r | |
2b16a4fb MK |
63 | EFI_RESOURCE_ATTRIBUTE_PRESENT |\r |
64 | EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r | |
65 | EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |\r | |
66 | EFI_RESOURCE_ATTRIBUTE_TESTED\r | |
67 | );\r | |
a1bcf5c3 | 68 | \r |
72daeed8 AB |
69 | SystemMemoryTop = PcdGet64 (PcdSystemMemoryBase) +\r |
70 | PcdGet64 (PcdSystemMemorySize);\r | |
71 | \r | |
4a1500db | 72 | if (SystemMemoryTop - 1 > MAX_ALLOC_ADDRESS) {\r |
72daeed8 | 73 | BuildResourceDescriptorHob (\r |
2b16a4fb MK |
74 | EFI_RESOURCE_SYSTEM_MEMORY,\r |
75 | ResourceAttributes,\r | |
76 | PcdGet64 (PcdSystemMemoryBase),\r | |
77 | (UINT64)MAX_ALLOC_ADDRESS - PcdGet64 (PcdSystemMemoryBase) + 1\r | |
78 | );\r | |
72daeed8 | 79 | BuildResourceDescriptorHob (\r |
2b16a4fb MK |
80 | EFI_RESOURCE_SYSTEM_MEMORY,\r |
81 | ResourceAttributes,\r | |
82 | (UINT64)MAX_ALLOC_ADDRESS + 1,\r | |
83 | SystemMemoryTop - MAX_ALLOC_ADDRESS - 1\r | |
84 | );\r | |
72daeed8 AB |
85 | } else {\r |
86 | BuildResourceDescriptorHob (\r | |
2b16a4fb MK |
87 | EFI_RESOURCE_SYSTEM_MEMORY,\r |
88 | ResourceAttributes,\r | |
89 | PcdGet64 (PcdSystemMemoryBase),\r | |
90 | PcdGet64 (PcdSystemMemorySize)\r | |
91 | );\r | |
72daeed8 | 92 | }\r |
a1bcf5c3 | 93 | \r |
e1d52990 AB |
94 | //\r |
95 | // When running under virtualization, the PI/UEFI memory region may be\r | |
96 | // clean but not invalidated in system caches or in lower level caches\r | |
97 | // on other CPUs. So invalidate the region by virtual address, to ensure\r | |
98 | // that the contents we put there with the caches and MMU off will still\r | |
99 | // be visible after turning them on.\r | |
100 | //\r | |
2b16a4fb | 101 | InvalidateDataCacheRange ((VOID *)(UINTN)UefiMemoryBase, UefiMemorySize);\r |
e1d52990 | 102 | \r |
a1bcf5c3 AB |
103 | // Build Memory Allocation Hob\r |
104 | InitMmu ();\r | |
105 | \r | |
106 | if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {\r | |
107 | // Optional feature that helps prevent EFI memory map fragmentation.\r | |
108 | BuildMemoryTypeInformationHob ();\r | |
109 | }\r | |
110 | \r | |
111 | return EFI_SUCCESS;\r | |
112 | }\r |