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.
18 // The protocols, PPI and GUID defintions for this module
20 #include <Ppi/MasterBootMode.h>
21 #include <Ppi/BootInRecoveryMode.h>
22 #include <Guid/MemoryTypeInformation.h>
24 // The Library classes this module consumes
26 #include <Library/ArmPlatformLib.h>
27 #include <Library/DebugLib.h>
28 #include <Library/HobLib.h>
29 #include <Library/PeimEntryPoint.h>
30 #include <Library/PeiServicesLib.h>
31 #include <Library/PcdLib.h>
36 IN EFI_PHYSICAL_ADDRESS UefiMemoryBase
,
37 IN UINT64 UefiMemorySize
40 // May want to put this into a library so you only need the PCD settings if you are using the feature?
42 BuildMemoryTypeInformationHob (
46 EFI_MEMORY_TYPE_INFORMATION Info
[10];
48 Info
[0].Type
= EfiACPIReclaimMemory
;
49 Info
[0].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory
);
50 Info
[1].Type
= EfiACPIMemoryNVS
;
51 Info
[1].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS
);
52 Info
[2].Type
= EfiReservedMemoryType
;
53 Info
[2].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiReservedMemoryType
);
54 Info
[3].Type
= EfiRuntimeServicesData
;
55 Info
[3].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiRuntimeServicesData
);
56 Info
[4].Type
= EfiRuntimeServicesCode
;
57 Info
[4].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode
);
58 Info
[5].Type
= EfiBootServicesCode
;
59 Info
[5].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiBootServicesCode
);
60 Info
[6].Type
= EfiBootServicesData
;
61 Info
[6].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiBootServicesData
);
62 Info
[7].Type
= EfiLoaderCode
;
63 Info
[7].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiLoaderCode
);
64 Info
[8].Type
= EfiLoaderData
;
65 Info
[8].NumberOfPages
= PcdGet32 (PcdMemoryTypeEfiLoaderData
);
67 // Terminator for the list
68 Info
[9].Type
= EfiMaxMemoryType
;
69 Info
[9].NumberOfPages
= 0;
71 BuildGuidDataHob (&gEfiMemoryTypeInformationGuid
, &Info
, sizeof (Info
));
82 FileHandle - Handle of the file being invoked.
83 PeiServices - Describes the list of possible PEI Services.
87 Status - EFI_SUCCESS if the boot mode could be set
93 IN EFI_PEI_FILE_HANDLE FileHandle
,
94 IN CONST EFI_PEI_SERVICES
**PeiServices
98 EFI_RESOURCE_ATTRIBUTE_TYPE Attributes
;
99 ARM_SYSTEM_MEMORY_REGION_DESCRIPTOR
* EfiMemoryMap
;
101 UINTN SystemMemoryTop
;
102 UINTN UefiMemoryBase
;
103 UINTN UefiMemorySize
;
105 DEBUG ((EFI_D_ERROR
, "Memory Init PEIM Loaded\n"));
107 // Ensure PcdSystemMemorySize has been set
108 ASSERT (FixedPcdGet32 (PcdSystemMemorySize
) != 0);
110 SystemMemoryTop
= (UINTN
)FixedPcdGet32 (PcdSystemMemoryBase
) + (UINTN
)FixedPcdGet32 (PcdSystemMemorySize
);
113 // Initialize the System Memory (DRAM)
115 if (PcdGet32 (PcdStandalone
)) {
116 // In case of a standalone version, the DRAM is already initialized
117 ArmPlatformInitializeSystemMemory();
121 // Declare the UEFI memory to PEI
123 if (PcdGet32 (PcdStandalone
)) {
124 // In case of standalone UEFI, we set the UEFI memory region at the top of the DRAM
125 UefiMemoryBase
= SystemMemoryTop
- FixedPcdGet32 (PcdSystemMemoryUefiRegionSize
);
127 // In case of a non standalone UEFI, we set the UEFI memory below the Firmware Volume
128 UefiMemoryBase
= FixedPcdGet32 (PcdNormalFdBaseAddress
) - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize
);
130 Status
= PeiServicesInstallPeiMemory (UefiMemoryBase
,FixedPcdGet32 (PcdSystemMemoryUefiRegionSize
));
131 ASSERT_EFI_ERROR (Status
);
133 // Initialize MMU and Memory HOBs (Resource Descriptor HOBs)
134 Status
= MemoryPeim (UefiMemoryBase
, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize
));
135 ASSERT_EFI_ERROR (Status
);