3 * Copyright (c) 2011, ARM Limited. All rights reserved.
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/ArmPlatformLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/HobLib.h>
20 #include <Library/MemoryAllocationLib.h>
21 #include <Library/PcdLib.h>
24 BuildMemoryTypeInformationHob (
33 ARM_MEMORY_REGION_DESCRIPTOR
*MemoryTable
;
34 VOID
*TranslationTableBase
;
35 UINTN TranslationTableSize
;
37 // Get Virtual Memory Map from the Platform Library
38 ArmPlatformGetVirtualMemoryMap (&MemoryTable
);
40 //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in
41 // DRAM (even at the top of DRAM as it is the first permanent memory allocation)
42 ArmConfigureMmu (MemoryTable
, &TranslationTableBase
, &TranslationTableSize
);
53 FileHandle - Handle of the file being invoked.
54 PeiServices - Describes the list of possible PEI Services.
58 Status - EFI_SUCCESS if the boot mode could be set
64 IN EFI_PHYSICAL_ADDRESS UefiMemoryBase
,
65 IN UINT64 UefiMemorySize
68 EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes
;
69 UINT64 ResourceLength
;
70 EFI_PEI_HOB_POINTERS NextHob
;
71 EFI_PHYSICAL_ADDRESS FdTop
;
72 EFI_PHYSICAL_ADDRESS SystemMemoryTop
;
73 EFI_PHYSICAL_ADDRESS ResourceTop
;
76 // Ensure PcdSystemMemorySize has been set
77 ASSERT (PcdGet32 (PcdSystemMemorySize
) != 0);
80 // Now, the permanent memory has been installed, we can call AllocatePages()
82 ResourceAttributes
= (
83 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
84 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
85 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
86 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
87 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
88 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
|
89 EFI_RESOURCE_ATTRIBUTE_TESTED
92 // Reserved the memory space occupied by the firmware volume
93 BuildResourceDescriptorHob (
94 EFI_RESOURCE_SYSTEM_MEMORY
,
96 PcdGet32 (PcdSystemMemoryBase
),
97 PcdGet32 (PcdSystemMemorySize
)
100 SystemMemoryTop
= PcdGet32 (PcdSystemMemoryBase
) + PcdGet32 (PcdSystemMemorySize
);
101 FdTop
= PcdGet32(PcdFdBaseAddress
) + PcdGet32(PcdFdSize
);
103 // EDK2 does not have the concept of boot firmware copied into DRAM. To avoid the DXE
104 // core to overwrite this area we must mark the region with the attribute non-present
105 if ((PcdGet32 (PcdFdBaseAddress
) >= PcdGet32 (PcdSystemMemoryBase
)) && (FdTop
<= SystemMemoryTop
)) {
108 // Search for System Memory Hob that contains the firmware
109 NextHob
.Raw
= GetHobList ();
110 while ((NextHob
.Raw
= GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
, NextHob
.Raw
)) != NULL
) {
111 if ((NextHob
.ResourceDescriptor
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
) &&
112 (PcdGet32(PcdFdBaseAddress
) >= NextHob
.ResourceDescriptor
->PhysicalStart
) &&
113 (FdTop
<= NextHob
.ResourceDescriptor
->PhysicalStart
+ NextHob
.ResourceDescriptor
->ResourceLength
))
115 ResourceAttributes
= NextHob
.ResourceDescriptor
->ResourceAttribute
;
116 ResourceLength
= NextHob
.ResourceDescriptor
->ResourceLength
;
117 ResourceTop
= NextHob
.ResourceDescriptor
->PhysicalStart
+ ResourceLength
;
119 if (PcdGet32(PcdFdBaseAddress
) == NextHob
.ResourceDescriptor
->PhysicalStart
) {
120 if (SystemMemoryTop
== FdTop
) {
121 NextHob
.ResourceDescriptor
->ResourceAttribute
= ResourceAttributes
& ~EFI_RESOURCE_ATTRIBUTE_PRESENT
;
123 // Create the System Memory HOB for the firmware with the non-present attribute
124 BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY
,
125 ResourceAttributes
& ~EFI_RESOURCE_ATTRIBUTE_PRESENT
,
126 PcdGet32(PcdFdBaseAddress
),
127 PcdGet32(PcdFdSize
));
129 // Top of the FD is system memory available for UEFI
130 NextHob
.ResourceDescriptor
->PhysicalStart
+= PcdGet32(PcdFdSize
);
131 NextHob
.ResourceDescriptor
->ResourceLength
-= PcdGet32(PcdFdSize
);
134 // Create the System Memory HOB for the firmware with the non-present attribute
135 BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY
,
136 ResourceAttributes
& ~EFI_RESOURCE_ATTRIBUTE_PRESENT
,
137 PcdGet32(PcdFdBaseAddress
),
138 PcdGet32(PcdFdSize
));
141 NextHob
.ResourceDescriptor
->ResourceLength
= PcdGet32(PcdFdBaseAddress
) - NextHob
.ResourceDescriptor
->PhysicalStart
;
143 // If there is some memory available on the top of the FD then create a HOB
144 if (FdTop
< NextHob
.ResourceDescriptor
->PhysicalStart
+ ResourceLength
) {
145 // Create the System Memory HOB for the remaining region (top of the FD)
146 BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY
,
149 ResourceTop
- FdTop
);
155 NextHob
.Raw
= GET_NEXT_HOB (NextHob
);
161 // Build Memory Allocation Hob
164 if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob
)) {
165 // Optional feature that helps prevent EFI memory map fragmentation.
166 BuildMemoryTypeInformationHob ();