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
71 EFI_RESOURCE_ATTRIBUTE_TYPE Attributes
;
72 ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR
* EfiMemoryMap
;
74 EFI_PHYSICAL_ADDRESS SystemMemoryTop
;
76 // Ensure PcdSystemMemorySize has been set
77 ASSERT (PcdGet32 (PcdSystemMemorySize
) != 0);
79 SystemMemoryTop
= (EFI_PHYSICAL_ADDRESS
)((UINT32
)PcdGet32 (PcdSystemMemoryBase
) + (UINT32
)PcdGet32 (PcdSystemMemorySize
));
82 // Now, the permanent memory has been installed, we can call AllocatePages()
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 // If it is not a standalone build we must reserved the space above the base address of the firmware volume
95 if (!PcdGet32(PcdStandalone
)) {
96 // Check if firmware volume has not be copied at the top of DRAM then we must reserve the extra space
97 // between the firmware and the top
98 if (SystemMemoryTop
!= PcdGet32 (PcdNormalFdBaseAddress
) + PcdGet32 (PcdNormalFdSize
)) {
99 BuildResourceDescriptorHob (
100 EFI_RESOURCE_SYSTEM_MEMORY
,
101 Attributes
& (~EFI_RESOURCE_ATTRIBUTE_TESTED
),
102 PcdGet32 (PcdNormalFdBaseAddress
) + PcdGet32 (PcdNormalFdSize
),
103 SystemMemoryTop
- (PcdGet32 (PcdNormalFdBaseAddress
) + PcdGet32 (PcdNormalFdSize
))
107 // Reserved the memory space occupied by the firmware volume
108 BuildResourceDescriptorHob (
109 EFI_RESOURCE_SYSTEM_MEMORY
,
110 Attributes
& (~EFI_RESOURCE_ATTRIBUTE_PRESENT
),
111 (UINT32
)PcdGet32 (PcdNormalFdBaseAddress
),
112 (UINT32
)PcdGet32 (PcdNormalFdSize
)
116 // Check there is no overlap between UEFI and Fix Address Regions
117 ASSERT (PcdGet32 (PcdSystemMemoryBase
) + PcdGet32 (PcdSystemMemoryFixRegionSize
) <= UefiMemoryBase
);
119 // Reserved the UEFI Memory Region
120 BuildResourceDescriptorHob (
121 EFI_RESOURCE_SYSTEM_MEMORY
,
127 // Reserved the Fix Address Region
128 BuildResourceDescriptorHob (
129 EFI_RESOURCE_SYSTEM_MEMORY
,
131 PcdGet32 (PcdSystemMemoryBase
),
132 PcdGet32 (PcdSystemMemoryFixRegionSize
)
135 // Reserved the memory between UEFI and Fix Address regions
136 if (PcdGet32 (PcdSystemMemoryBase
) + PcdGet32 (PcdSystemMemoryFixRegionSize
) != UefiMemoryBase
) {
137 BuildResourceDescriptorHob (
138 EFI_RESOURCE_SYSTEM_MEMORY
,
139 Attributes
& (~EFI_RESOURCE_ATTRIBUTE_TESTED
),
140 PcdGet32 (PcdSystemMemoryBase
) + PcdGet32 (PcdSystemMemoryFixRegionSize
),
141 UefiMemoryBase
- (PcdGet32 (PcdSystemMemoryBase
) + PcdGet32 (PcdSystemMemoryFixRegionSize
))
145 // If a platform has system memory extensions, it can declare those in this function
146 Status
= ArmPlatformGetAdditionalSystemMemory (&EfiMemoryMap
);
147 if (!EFI_ERROR(Status
)) {
148 // Install the EFI Memory Map
149 for (Index
= 0; EfiMemoryMap
[Index
].ResourceAttribute
!= 0; Index
++) {
150 BuildResourceDescriptorHob (
151 EFI_RESOURCE_SYSTEM_MEMORY
,
152 EfiMemoryMap
[Index
].ResourceAttribute
,
153 EfiMemoryMap
[Index
].PhysicalStart
,
154 EfiMemoryMap
[Index
].NumberOfBytes
157 FreePool (EfiMemoryMap
);
160 // Build Memory Allocation Hob
163 if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob
)) {
164 // Optional feature that helps prevent EFI memory map fragmentation.
165 BuildMemoryTypeInformationHob ();