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/ArmMmuLib.h>
19 #include <Library/ArmPlatformLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/HobLib.h>
22 #include <Library/MemoryAllocationLib.h>
23 #include <Library/PcdLib.h>
24 #include <Library/CacheMaintenanceLib.h>
27 BuildMemoryTypeInformationHob (
36 ARM_MEMORY_REGION_DESCRIPTOR
*MemoryTable
;
37 VOID
*TranslationTableBase
;
38 UINTN TranslationTableSize
;
41 // Get Virtual Memory Map from the Platform Library
42 ArmPlatformGetVirtualMemoryMap (&MemoryTable
);
44 //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in
45 // DRAM (even at the top of DRAM as it is the first permanent memory allocation)
46 Status
= ArmConfigureMmu (MemoryTable
, &TranslationTableBase
, &TranslationTableSize
);
47 if (EFI_ERROR (Status
)) {
48 DEBUG ((EFI_D_ERROR
, "Error: Failed to enable MMU\n"));
55 IN EFI_PHYSICAL_ADDRESS UefiMemoryBase
,
56 IN UINT64 UefiMemorySize
59 EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes
;
60 UINT64 SystemMemoryTop
;
62 // Ensure PcdSystemMemorySize has been set
63 ASSERT (PcdGet64 (PcdSystemMemorySize
) != 0);
66 // Now, the permanent memory has been installed, we can call AllocatePages()
68 ResourceAttributes
= (
69 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
70 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
71 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
72 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
73 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
74 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
|
75 EFI_RESOURCE_ATTRIBUTE_TESTED
78 SystemMemoryTop
= PcdGet64 (PcdSystemMemoryBase
) +
79 PcdGet64 (PcdSystemMemorySize
);
81 if (SystemMemoryTop
- 1 > MAX_ADDRESS
) {
82 BuildResourceDescriptorHob (
83 EFI_RESOURCE_SYSTEM_MEMORY
,
85 PcdGet64 (PcdSystemMemoryBase
),
86 (UINT64
)MAX_ADDRESS
- PcdGet64 (PcdSystemMemoryBase
) + 1
88 BuildResourceDescriptorHob (
89 EFI_RESOURCE_SYSTEM_MEMORY
,
91 (UINT64
)MAX_ADDRESS
+ 1,
92 SystemMemoryTop
- MAX_ADDRESS
- 1
95 BuildResourceDescriptorHob (
96 EFI_RESOURCE_SYSTEM_MEMORY
,
98 PcdGet64 (PcdSystemMemoryBase
),
99 PcdGet64 (PcdSystemMemorySize
)
104 // When running under virtualization, the PI/UEFI memory region may be
105 // clean but not invalidated in system caches or in lower level caches
106 // on other CPUs. So invalidate the region by virtual address, to ensure
107 // that the contents we put there with the caches and MMU off will still
108 // be visible after turning them on.
110 InvalidateDataCacheRange ((VOID
*)(UINTN
)UefiMemoryBase
, UefiMemorySize
);
112 // Build Memory Allocation Hob
115 if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob
)) {
116 // Optional feature that helps prevent EFI memory map fragmentation.
117 BuildMemoryTypeInformationHob ();