]>
Commit | Line | Data |
---|---|---|
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 | * SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
7 | *\r | |
8 | **/\r | |
9 | \r | |
10 | #include <PiPei.h>\r | |
11 | \r | |
12 | #include <Library/ArmMmuLib.h>\r | |
13 | #include <Library/ArmVirtMemInfoLib.h>\r | |
14 | #include <Library/DebugLib.h>\r | |
15 | #include <Library/HobLib.h>\r | |
16 | #include <Library/MemoryAllocationLib.h>\r | |
17 | #include <Library/PcdLib.h>\r | |
18 | #include <Library/CacheMaintenanceLib.h>\r | |
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 | |
36 | ArmVirtGetMemoryMap (&MemoryTable);\r | |
37 | \r | |
38 | //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in\r | |
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 | |
42 | DEBUG ((DEBUG_ERROR, "Error: Failed to enable MMU\n"));\r | |
43 | }\r | |
44 | }\r | |
45 | \r | |
46 | EFI_STATUS\r | |
47 | EFIAPI\r | |
48 | MemoryPeim (\r | |
49 | IN EFI_PHYSICAL_ADDRESS UefiMemoryBase,\r | |
50 | IN UINT64 UefiMemorySize\r | |
51 | )\r | |
52 | {\r | |
53 | EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;\r | |
54 | UINT64 SystemMemoryTop;\r | |
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 | |
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 | |
68 | \r | |
69 | SystemMemoryTop = PcdGet64 (PcdSystemMemoryBase) +\r | |
70 | PcdGet64 (PcdSystemMemorySize);\r | |
71 | \r | |
72 | if (SystemMemoryTop - 1 > MAX_ALLOC_ADDRESS) {\r | |
73 | BuildResourceDescriptorHob (\r | |
74 | EFI_RESOURCE_SYSTEM_MEMORY,\r | |
75 | ResourceAttributes,\r | |
76 | PcdGet64 (PcdSystemMemoryBase),\r | |
77 | (UINT64)MAX_ALLOC_ADDRESS - PcdGet64 (PcdSystemMemoryBase) + 1\r | |
78 | );\r | |
79 | BuildResourceDescriptorHob (\r | |
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 | |
85 | } else {\r | |
86 | BuildResourceDescriptorHob (\r | |
87 | EFI_RESOURCE_SYSTEM_MEMORY,\r | |
88 | ResourceAttributes,\r | |
89 | PcdGet64 (PcdSystemMemoryBase),\r | |
90 | PcdGet64 (PcdSystemMemorySize)\r | |
91 | );\r | |
92 | }\r | |
93 | \r | |
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 | |
101 | InvalidateDataCacheRange ((VOID*)(UINTN)UefiMemoryBase, UefiMemorySize);\r | |
102 | \r | |
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 |