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>
23 #include <Chipset/ArmV7.h>
26 BuildMemoryTypeInformationHob (
35 ARM_MEMORY_REGION_DESCRIPTOR
*MemoryTable
;
36 VOID
*TranslationTableBase
;
37 UINTN TranslationTableSize
;
39 // Get Virtual Memory Map from the Platform Library
40 ArmPlatformGetVirtualMemoryMap(&MemoryTable
);
42 //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in
43 // DRAM (even at the top of DRAM as it is the first permanent memory allocation)
44 ArmConfigureMmu (MemoryTable
, &TranslationTableBase
, &TranslationTableSize
);
55 FileHandle - Handle of the file being invoked.
56 PeiServices - Describes the list of possible PEI Services.
60 Status - EFI_SUCCESS if the boot mode could be set
66 IN EFI_PHYSICAL_ADDRESS UefiMemoryBase
,
67 IN UINT64 UefiMemorySize
70 EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes
;
71 UINT64 ResourceLength
;
72 EFI_PEI_HOB_POINTERS NextHob
;
73 EFI_PHYSICAL_ADDRESS FdTop
;
74 EFI_PHYSICAL_ADDRESS SystemMemoryTop
;
75 EFI_PHYSICAL_ADDRESS ResourceTop
;
78 // Ensure PcdSystemMemorySize has been set
79 ASSERT (PcdGet32 (PcdSystemMemorySize
) != 0);
82 // Now, the permanent memory has been installed, we can call AllocatePages()
84 ResourceAttributes
= (
85 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
86 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
87 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
88 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
89 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
90 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
|
91 EFI_RESOURCE_ATTRIBUTE_TESTED
94 // Reserved the memory space occupied by the firmware volume
95 BuildResourceDescriptorHob (
96 EFI_RESOURCE_SYSTEM_MEMORY
,
98 PcdGet32 (PcdSystemMemoryBase
),
99 PcdGet32 (PcdSystemMemorySize
)
102 SystemMemoryTop
= PcdGet32 (PcdSystemMemoryBase
) + PcdGet32 (PcdSystemMemorySize
);
103 FdTop
= PcdGet32(PcdNormalFdBaseAddress
) + PcdGet32(PcdNormalFdSize
);
105 // EDK2 does not have the concept of boot firmware copied into DRAM. To avoid the DXE
106 // core to overwrite this area we must mark the region with the attribute non-present
107 if ((PcdGet32 (PcdNormalFdBaseAddress
) >= PcdGet32 (PcdSystemMemoryBase
)) && (FdTop
<= SystemMemoryTop
)) {
110 // Search for System Memory Hob that contains the firmware
111 NextHob
.Raw
= GetHobList ();
112 while ((NextHob
.Raw
= GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
, NextHob
.Raw
)) != NULL
) {
113 if ((NextHob
.ResourceDescriptor
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
) &&
114 (PcdGet32(PcdNormalFdBaseAddress
) >= NextHob
.ResourceDescriptor
->PhysicalStart
) &&
115 (FdTop
<= NextHob
.ResourceDescriptor
->PhysicalStart
+ NextHob
.ResourceDescriptor
->ResourceLength
))
117 ResourceAttributes
= NextHob
.ResourceDescriptor
->ResourceAttribute
;
118 ResourceLength
= NextHob
.ResourceDescriptor
->ResourceLength
;
119 ResourceTop
= NextHob
.ResourceDescriptor
->PhysicalStart
+ ResourceLength
;
121 if (PcdGet32(PcdNormalFdBaseAddress
) == NextHob
.ResourceDescriptor
->PhysicalStart
) {
122 if (SystemMemoryTop
== FdTop
) {
123 NextHob
.ResourceDescriptor
->ResourceAttribute
= ResourceAttributes
& ~EFI_RESOURCE_ATTRIBUTE_PRESENT
;
125 // Create the System Memory HOB for the firmware with the non-present attribute
126 BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY
,
127 ResourceAttributes
& ~EFI_RESOURCE_ATTRIBUTE_PRESENT
,
128 PcdGet32(PcdNormalFdBaseAddress
),
129 PcdGet32(PcdNormalFdSize
));
131 // Top of the FD is system memory available for UEFI
132 NextHob
.ResourceDescriptor
->PhysicalStart
+= PcdGet32(PcdNormalFdSize
);
133 NextHob
.ResourceDescriptor
->ResourceLength
-= PcdGet32(PcdNormalFdSize
);
136 // Create the System Memory HOB for the firmware with the non-present attribute
137 BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY
,
138 ResourceAttributes
& ~EFI_RESOURCE_ATTRIBUTE_PRESENT
,
139 PcdGet32(PcdNormalFdBaseAddress
),
140 PcdGet32(PcdNormalFdSize
));
143 NextHob
.ResourceDescriptor
->ResourceLength
= PcdGet32(PcdNormalFdBaseAddress
) - NextHob
.ResourceDescriptor
->PhysicalStart
;
145 // If there is some memory available on the top of the FD then create a HOB
146 if (FdTop
< NextHob
.ResourceDescriptor
->PhysicalStart
+ ResourceLength
) {
147 // Create the System Memory HOB for the remaining region (top of the FD)
148 BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY
,
151 ResourceTop
- FdTop
);
157 NextHob
.Raw
= GET_NEXT_HOB (NextHob
);
163 // Build Memory Allocation Hob
166 if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob
)) {
167 // Optional feature that helps prevent EFI memory map fragmentation.
168 BuildMemoryTypeInformationHob ();