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.
16 // The package level header files this module uses
20 // The protocols, PPI and GUID defintions for this module
22 #include <Ppi/MasterBootMode.h>
23 #include <Ppi/BootInRecoveryMode.h>
24 #include <Guid/MemoryTypeInformation.h>
26 // The Library classes this module consumes
28 #include <Library/DebugLib.h>
29 #include <Library/PeimEntryPoint.h>
30 #include <Library/PcdLib.h>
31 #include <Library/HobLib.h>
32 #include <Library/PeiServicesLib.h>
33 #include <Library/ArmLib.h>
34 #include <Library/IoLib.h>
35 #include <Library/ArmPlatformLib.h>
46 ARM_MEMORY_REGION_DESCRIPTOR
*MemoryTable
;
47 VOID
*TranslationTableBase
;
48 UINTN TranslationTableSize
;
50 // Get Virtual Memory Map from the Platform Library
51 ArmPlatformGetVirtualMemoryMap(&MemoryTable
);
53 //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in
54 // DRAM (even at the top of DRAM as it is the first permanent memory allocation)
55 ArmConfigureMmu (MemoryTable
, &TranslationTableBase
, &TranslationTableSize
);
58 // May want to put this into a library so you only need the PCD setings if you are using the feature?
60 BuildMemoryTypeInformationHob (
64 EFI_MEMORY_TYPE_INFORMATION Info
[10];
66 Info
[0].Type
= EfiACPIReclaimMemory
;
67 Info
[0].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory
);
68 Info
[1].Type
= EfiACPIMemoryNVS
;
69 Info
[1].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS
);
70 Info
[2].Type
= EfiReservedMemoryType
;
71 Info
[2].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiReservedMemoryType
);
72 Info
[3].Type
= EfiRuntimeServicesData
;
73 Info
[3].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiRuntimeServicesData
);
74 Info
[4].Type
= EfiRuntimeServicesCode
;
75 Info
[4].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode
);
76 Info
[5].Type
= EfiBootServicesCode
;
77 Info
[5].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiBootServicesCode
);
78 Info
[6].Type
= EfiBootServicesData
;
79 Info
[6].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiBootServicesData
);
80 Info
[7].Type
= EfiLoaderCode
;
81 Info
[7].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiLoaderCode
);
82 Info
[8].Type
= EfiLoaderData
;
83 Info
[8].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiLoaderData
);
85 // Terminator for the list
86 Info
[9].Type
= EfiMaxMemoryType
;
87 Info
[9].NumberOfPages
= 0;
90 BuildGuidDataHob (&gEfiMemoryTypeInformationGuid
, &Info
, sizeof (Info
));
96 IN EFI_PEI_FILE_HANDLE FileHandle
,
97 IN CONST EFI_PEI_SERVICES
**PeiServices
107 FileHandle - Handle of the file being invoked.
108 PeiServices - Describes the list of possible PEI Services.
112 Status - EFI_SUCCESS if the boot mode could be set
117 ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR
* EfiMemoryMap
;
122 DEBUG ((EFI_D_ERROR
, "Memory Init PEIM Loaded\n"));
124 // If it is not a standalone version, then we need to initialize the System Memory
125 // In case of a standalone version, the DRAM is already initialized
126 if (FeaturePcdGet(PcdStandalone
)) {
127 // Initialize the System Memory controller (DRAM)
128 ArmPlatformInitializeSystemMemory();
131 // Install the Memory to PEI
132 ArmPlatformGetPeiMemory (&PeiMemoryBase
,&PeiMemorySize
);
133 Status
= PeiServicesInstallPeiMemory (PeiMemoryBase
,PeiMemorySize
);
134 ASSERT_EFI_ERROR (Status
);
137 // Now, the permanent memory has been installed, we can call AllocatePages()
140 ArmPlatformGetEfiMemoryMap (&EfiMemoryMap
);
142 // Install the EFI Memory Map
143 for (Index
= 0; EfiMemoryMap
[Index
].ResourceAttribute
!= 0; Index
++) {
144 BuildResourceDescriptorHob (
145 EFI_RESOURCE_SYSTEM_MEMORY
,
146 EfiMemoryMap
[Index
].ResourceAttribute
,
147 EfiMemoryMap
[Index
].PhysicalStart
,
148 EfiMemoryMap
[Index
].NumberOfBytes
152 // Build Memory Allocation Hob
155 if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob
)) {
156 // Optional feature that helps prevent EFI memory map fragmentation.
157 BuildMemoryTypeInformationHob ();