TianoCore EDK2 master
Loading...
Searching...
No Matches
CpuPei.c
Go to the documentation of this file.
1
20//
21// The package level header files this module uses
22//
23#include <PiPei.h>
24//
25// The protocols, PPI and GUID definitions for this module
26//
27#include <Ppi/ArmMpCoreInfo.h>
28#include <Ppi/MemoryAttribute.h>
29
30//
31// The Library classes this module consumes
32//
33#include <Library/DebugLib.h>
36#include <Library/PcdLib.h>
37#include <Library/HobLib.h>
38#include <Library/ArmLib.h>
39#include <Library/ArmMmuLib.h>
40
80EFIAPI
83 IN EFI_PHYSICAL_ADDRESS BaseAddress,
84 IN UINT64 Length,
85 IN UINT64 Attributes,
86 IN UINT64 AttributeMask
87 )
88{
89 if ((Length == 0) ||
90 (AttributeMask == 0) ||
91 ((AttributeMask & (EFI_MEMORY_RP | EFI_MEMORY_RO | EFI_MEMORY_XP)) == 0) ||
92 ((Attributes & ~AttributeMask) != 0) ||
93 (((BaseAddress | Length) & EFI_PAGE_MASK) != 0))
94 {
95 return EFI_INVALID_PARAMETER;
96 }
97
98 return ArmSetMemoryAttributes (BaseAddress, Length, Attributes, AttributeMask);
99}
100
101STATIC CONST EDKII_MEMORY_ATTRIBUTE_PPI mMemoryAttributePpi = {
103};
104
105STATIC CONST EFI_PEI_PPI_DESCRIPTOR mMemoryAttributePpiDesc = {
106 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
107 &gEdkiiMemoryAttributePpiGuid,
108 (VOID *)&mMemoryAttributePpi
109};
110
111/*++
112
113Routine Description:
114
115Arguments:
116
117 FileHandle - Handle of the file being invoked.
118 PeiServices - Describes the list of possible PEI Services.
119
120Returns:
121
122 Status - EFI_SUCCESS if the boot mode could be set
123
124--*/
126EFIAPI
127InitializeCpuPeim (
128 IN EFI_PEI_FILE_HANDLE FileHandle,
129 IN CONST EFI_PEI_SERVICES **PeiServices
130 )
131{
132 EFI_STATUS Status;
133 ARM_MP_CORE_INFO_PPI *ArmMpCoreInfoPpi;
134 UINTN ArmCoreCount;
135 ARM_CORE_INFO *ArmCoreInfoTable;
136
137 // Enable program flow prediction, if supported.
138 ArmEnableBranchPrediction ();
139
140 // Publish the CPU memory and io spaces sizes
141 BuildCpuHob (ArmGetPhysicalAddressBits (), PcdGet8 (PcdPrePiCpuIoSize));
142
143 // Only MP Core platform need to produce gArmMpCoreInfoPpiGuid
144 Status = PeiServicesLocatePpi (&gArmMpCoreInfoPpiGuid, 0, NULL, (VOID **)&ArmMpCoreInfoPpi);
145 if (!EFI_ERROR (Status)) {
146 // Build the MP Core Info Table
147 ArmCoreCount = 0;
148 Status = ArmMpCoreInfoPpi->GetMpCoreInfo (&ArmCoreCount, &ArmCoreInfoTable);
149 if (!EFI_ERROR (Status) && (ArmCoreCount > 0)) {
150 // Build MPCore Info HOB
151 BuildGuidDataHob (&gArmMpCoreInfoGuid, ArmCoreInfoTable, sizeof (ARM_CORE_INFO) * ArmCoreCount);
152 }
153 }
154
155 Status = PeiServicesInstallPpi (&mMemoryAttributePpiDesc);
156 ASSERT_EFI_ERROR (Status);
157
158 return EFI_SUCCESS;
159}
UINT64 UINTN
EFI_STATUS ArmSetMemoryAttributes(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes, IN UINT64 AttributeMask)
VOID *EFIAPI BuildGuidDataHob(IN CONST EFI_GUID *Guid, IN VOID *Data, IN UINTN DataLength)
Definition: HobLib.c:375
VOID EFIAPI BuildCpuHob(IN UINT8 SizeOfMemorySpace, IN UINT8 SizeOfIoSpace)
Definition: HobLib.c:520
STATIC EFI_STATUS EFIAPI SetMemoryPermissions(IN EDKII_MEMORY_ATTRIBUTE_PPI *This, IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length, IN UINT64 Attributes, IN UINT64 AttributeMask)
Definition: CpuPei.c:81
EFI_STATUS EFIAPI PeiServicesLocatePpi(IN CONST EFI_GUID *Guid, IN UINTN Instance, IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, IN OUT VOID **Ppi)
EFI_STATUS EFIAPI PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
VOID * EFI_PEI_FILE_HANDLE
Definition: PiPeiCis.h:26
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112