TianoCore EDK2 master
Loading...
Searching...
No Matches
ArmVirtMemoryInitPeiLib.c
Go to the documentation of this file.
1
10#include <PiPei.h>
11
12#include <Library/ArmMmuLib.h>
14#include <Library/DebugLib.h>
15#include <Library/HobLib.h>
17#include <Library/PcdLib.h>
19
20VOID
22 VOID
23 );
24
25VOID
26InitMmu (
27 VOID
28 )
29{
31 VOID *TranslationTableBase;
32 UINTN TranslationTableSize;
33 RETURN_STATUS Status;
34
35 // Get Virtual Memory Map from the Platform Library
36 ArmVirtGetMemoryMap (&MemoryTable);
37
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 ((DEBUG_ERROR, "Error: Failed to enable MMU\n"));
43 }
44}
45
47EFIAPI
49 IN EFI_PHYSICAL_ADDRESS UefiMemoryBase,
50 IN UINT64 UefiMemorySize
51 )
52{
53 EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;
54 UINT64 SystemMemoryTop;
55 UINT64 SystemMemorySize;
56 VOID *Hob;
57
58 // Ensure PcdSystemMemorySize has been set
59 ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);
60
61 SystemMemorySize = PcdGet64 (PcdSystemMemorySize);
62
63 Hob = GetFirstGuidHob (&gArmVirtSystemMemorySizeGuid);
64 if (Hob != NULL) {
65 SystemMemorySize = *(UINT64 *)GET_GUID_HOB_DATA (Hob);
66 }
67
68 //
69 // Now, the permanent memory has been installed, we can call AllocatePages()
70 //
71 ResourceAttributes = (
72 EFI_RESOURCE_ATTRIBUTE_PRESENT |
73 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
74 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
75 EFI_RESOURCE_ATTRIBUTE_TESTED
76 );
77
78 SystemMemoryTop = PcdGet64 (PcdSystemMemoryBase) + SystemMemorySize;
79
80 if (SystemMemoryTop - 1 > MAX_ALLOC_ADDRESS) {
82 EFI_RESOURCE_SYSTEM_MEMORY,
83 ResourceAttributes,
84 PcdGet64 (PcdSystemMemoryBase),
85 (UINT64)MAX_ALLOC_ADDRESS - PcdGet64 (PcdSystemMemoryBase) + 1
86 );
88 EFI_RESOURCE_SYSTEM_MEMORY,
89 ResourceAttributes,
90 (UINT64)MAX_ALLOC_ADDRESS + 1,
91 SystemMemoryTop - MAX_ALLOC_ADDRESS - 1
92 );
93 } else {
95 EFI_RESOURCE_SYSTEM_MEMORY,
96 ResourceAttributes,
97 PcdGet64 (PcdSystemMemoryBase),
98 SystemMemorySize
99 );
100 }
101
102 // Build Memory Allocation Hob
103 InitMmu ();
104
105 if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {
106 // Optional feature that helps prevent EFI memory map fragmentation.
108 }
109
110 return EFI_SUCCESS;
111}
UINT64 UINTN
#define MAX_ALLOC_ADDRESS
VOID EFIAPI ArmVirtGetMemoryMap(OUT ARM_MEMORY_REGION_DESCRIPTOR **VirtualMemoryMap)
VOID BuildMemoryTypeInformationHob(VOID)
EFI_STATUS EFIAPI MemoryPeim(IN EFI_PHYSICAL_ADDRESS UefiMemoryBase, IN UINT64 UefiMemorySize)
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
Definition: HobLib.c:215
VOID EFIAPI BuildResourceDescriptorHob(IN EFI_RESOURCE_TYPE ResourceType, IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute, IN EFI_PHYSICAL_ADDRESS PhysicalStart, IN UINT64 NumberOfBytes)
Definition: HobLib.c:299
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdGet64(TokenName)
Definition: PcdLib.h:375
#define FeaturePcdGet(TokenName)
Definition: PcdLib.h:50
UINT32 EFI_RESOURCE_ATTRIBUTE_TYPE
Definition: PiHob.h:241
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112