3 * Copyright (c) 2011-2014, ARM Limited. All rights reserved.
4 * Copyright (c) 2014, Linaro Limited. All rights reserved.
6 * This program and the accompanying materials
7 * are licensed and made available under the terms and conditions of the BSD License
8 * which accompanies this distribution. The full text of the license may be found at
9 * http://opensource.org/licenses/bsd-license.php
11 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Library/ArmPlatformLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/HobLib.h>
21 #include <Library/MemoryAllocationLib.h>
22 #include <Library/PcdLib.h>
23 #include <Library/CacheMaintenanceLib.h>
26 BuildMemoryTypeInformationHob (
35 ARM_MEMORY_REGION_DESCRIPTOR
*MemoryTable
;
36 VOID
*TranslationTableBase
;
37 UINTN TranslationTableSize
;
40 // Get Virtual Memory Map from the Platform Library
41 ArmPlatformGetVirtualMemoryMap (&MemoryTable
);
43 //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in
44 // DRAM (even at the top of DRAM as it is the first permanent memory allocation)
45 Status
= ArmConfigureMmu (MemoryTable
, &TranslationTableBase
, &TranslationTableSize
);
46 if (EFI_ERROR (Status
)) {
47 DEBUG ((EFI_D_ERROR
, "Error: Failed to enable MMU\n"));
54 IN EFI_PHYSICAL_ADDRESS UefiMemoryBase
,
55 IN UINT64 UefiMemorySize
58 EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes
;
60 // Ensure PcdSystemMemorySize has been set
61 ASSERT (PcdGet64 (PcdSystemMemorySize
) != 0);
64 // Now, the permanent memory has been installed, we can call AllocatePages()
66 ResourceAttributes
= (
67 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
68 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
69 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
70 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
71 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
72 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
|
73 EFI_RESOURCE_ATTRIBUTE_TESTED
76 BuildResourceDescriptorHob (
77 EFI_RESOURCE_SYSTEM_MEMORY
,
79 PcdGet64 (PcdSystemMemoryBase
),
80 PcdGet64 (PcdSystemMemorySize
)
84 // When running under virtualization, the PI/UEFI memory region may be
85 // clean but not invalidated in system caches or in lower level caches
86 // on other CPUs. So invalidate the region by virtual address, to ensure
87 // that the contents we put there with the caches and MMU off will still
88 // be visible after turning them on.
90 InvalidateDataCacheRange ((VOID
*)(UINTN
)UefiMemoryBase
, UefiMemorySize
);
92 // Build Memory Allocation Hob
95 if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob
)) {
96 // Optional feature that helps prevent EFI memory map fragmentation.
97 BuildMemoryTypeInformationHob ();