3 * Copyright (c) 2011-2014, ARM Limited. All rights reserved.
4 * Copyright (c) 2014, Linaro Limited. All rights reserved.
6 * SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <Library/ArmMmuLib.h>
13 #include <Library/ArmVirtMemInfoLib.h>
14 #include <Library/DebugLib.h>
15 #include <Library/HobLib.h>
16 #include <Library/MemoryAllocationLib.h>
17 #include <Library/PcdLib.h>
18 #include <Library/CacheMaintenanceLib.h>
21 BuildMemoryTypeInformationHob (
30 ARM_MEMORY_REGION_DESCRIPTOR
*MemoryTable
;
31 VOID
*TranslationTableBase
;
32 UINTN TranslationTableSize
;
35 // Get Virtual Memory Map from the Platform Library
36 ArmVirtGetMemoryMap (&MemoryTable
);
38 //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in
39 // DRAM (even at the top of DRAM as it is the first permanent memory allocation)
40 Status
= ArmConfigureMmu (MemoryTable
, &TranslationTableBase
, &TranslationTableSize
);
41 if (EFI_ERROR (Status
)) {
42 DEBUG ((EFI_D_ERROR
, "Error: Failed to enable MMU\n"));
49 IN EFI_PHYSICAL_ADDRESS UefiMemoryBase
,
50 IN UINT64 UefiMemorySize
53 EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes
;
54 UINT64 SystemMemoryTop
;
56 // Ensure PcdSystemMemorySize has been set
57 ASSERT (PcdGet64 (PcdSystemMemorySize
) != 0);
60 // Now, the permanent memory has been installed, we can call AllocatePages()
62 ResourceAttributes
= (
63 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
64 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
65 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
|
66 EFI_RESOURCE_ATTRIBUTE_TESTED
69 SystemMemoryTop
= PcdGet64 (PcdSystemMemoryBase
) +
70 PcdGet64 (PcdSystemMemorySize
);
72 if (SystemMemoryTop
- 1 > MAX_ALLOC_ADDRESS
) {
73 BuildResourceDescriptorHob (
74 EFI_RESOURCE_SYSTEM_MEMORY
,
76 PcdGet64 (PcdSystemMemoryBase
),
77 (UINT64
)MAX_ALLOC_ADDRESS
- PcdGet64 (PcdSystemMemoryBase
) + 1
79 BuildResourceDescriptorHob (
80 EFI_RESOURCE_SYSTEM_MEMORY
,
82 (UINT64
)MAX_ALLOC_ADDRESS
+ 1,
83 SystemMemoryTop
- MAX_ALLOC_ADDRESS
- 1
86 BuildResourceDescriptorHob (
87 EFI_RESOURCE_SYSTEM_MEMORY
,
89 PcdGet64 (PcdSystemMemoryBase
),
90 PcdGet64 (PcdSystemMemorySize
)
95 // When running under virtualization, the PI/UEFI memory region may be
96 // clean but not invalidated in system caches or in lower level caches
97 // on other CPUs. So invalidate the region by virtual address, to ensure
98 // that the contents we put there with the caches and MMU off will still
99 // be visible after turning them on.
101 InvalidateDataCacheRange ((VOID
*)(UINTN
)UefiMemoryBase
, UefiMemorySize
);
103 // Build Memory Allocation Hob
106 if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob
)) {
107 // Optional feature that helps prevent EFI memory map fragmentation.
108 BuildMemoryTypeInformationHob ();