28 UINT32 LatestRevision;
33 if (CpuMpData->MicrocodePatchRegionSize == 0) {
50 if (ProcessorNumber != (
UINTN)CpuMpData->BspNumber) {
55 BspData = &(CpuMpData->CpuData[CpuMpData->BspNumber]);
56 if ((BspData->ProcessorSignature == MicrocodeCpuId.ProcessorSignature) &&
57 (BspData->PlatformId == MicrocodeCpuId.PlatformId) &&
58 (BspData->MicrocodeEntryAddr != 0))
72 LatestMicrocode =
NULL;
74 MicrocodeEnd = (
UINTN)Microcode + (
UINTN)CpuMpData->MicrocodePatchRegionSize;
89 LatestMicrocode = Microcode;
93 }
while ((
UINTN)Microcode < MicrocodeEnd);
96 if (LatestRevision != 0) {
102 CpuMpData->CpuData[ProcessorNumber].MicrocodeEntryAddr = (
UINTN)LatestMicrocode;
142 VOID *MicrocodePatchInRam;
145 ASSERT ((Patches !=
NULL) && (PatchCount != 0));
148 if (MicrocodePatchInRam ==
NULL) {
155 for (Walker = MicrocodePatchInRam, Index = 0; Index < PatchCount; Index++) {
158 (VOID *)Patches[Index].Address,
161 Walker += Patches[Index].Size;
167 CpuMpData->MicrocodePatchAddress = (
UINTN)MicrocodePatchInRam;
168 CpuMpData->MicrocodePatchRegionSize = TotalLoadSize;
172 "%a: Required microcode patches have been loaded at 0x%lx, with size 0x%lx.\n",
174 CpuMpData->MicrocodePatchAddress,
175 CpuMpData->MicrocodePatchRegionSize
197 UINTN MaxPatchNumber;
208 CpuMpData->MicrocodePatchAddress =
PcdGet64 (PcdCpuMicrocodePatchAddress);
209 CpuMpData->MicrocodePatchRegionSize =
PcdGet64 (PcdCpuMicrocodePatchRegionSize);
212 MicrocodeEnd = (
UINTN)MicrocodeEntryPoint +
213 (
UINTN)CpuMpData->MicrocodePatchRegionSize;
214 if ((MicrocodeEntryPoint ==
NULL) || ((
UINTN)MicrocodeEntryPoint == MicrocodeEnd)) {
222 MaxPatchNumber = DEFAULT_MAX_MICROCODE_PATCH_NUM;
225 if (PatchInfoBuffer ==
NULL) {
232 if (MicrocodeCpuIds ==
NULL) {
237 for (Index = 0; Index < CpuMpData->CpuCount; Index++) {
238 MicrocodeCpuIds[Index].PlatformId = CpuMpData->CpuData[Index].PlatformId;
239 MicrocodeCpuIds[Index].ProcessorSignature = CpuMpData->CpuData[Index].ProcessorSignature;
250 MicrocodeEnd - (
UINTN)MicrocodeEntryPoint,
265 if (PatchCount > MaxPatchNumber) {
282 if (PatchInfoBuffer ==
NULL) {
286 MaxPatchNumber = MaxPatchNumber * 2;
294 PatchInfoBuffer[PatchCount - 1].Address = (
UINTN)MicrocodeEntryPoint;
295 PatchInfoBuffer[PatchCount - 1].Size = TotalSize;
296 TotalLoadSize += TotalSize;
302 }
while ((
UINTN)MicrocodeEntryPoint < MicrocodeEnd);
304 if (PatchCount != 0) {
307 "%a: 0x%x microcode patches will be loaded into memory, with size 0x%x.\n",
317 if (PatchInfoBuffer !=
NULL) {
337 if (EFI_ERROR (Status)) {
367 if (GuidHob ==
NULL) {
368 DEBUG ((DEBUG_INFO,
"%a: Microcode patch cache HOB is not found.\n", __func__));
372 MicrocodePathHob = GET_GUID_HOB_DATA (GuidHob);
374 *Address = MicrocodePathHob->MicrocodePatchAddress;
375 *RegionSize = MicrocodePathHob->MicrocodePatchRegionSize;
379 "%a: MicrocodeBase = 0x%lx, MicrocodeSize = 0x%lx\n",
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_STATUS PlatformShadowMicrocode(IN OUT CPU_MP_DATA *CpuMpData)
VOID EFIAPI FreePages(IN VOID *Buffer, IN UINTN Pages)
VOID *EFIAPI ReallocatePool(IN UINTN OldSize, IN UINTN NewSize, IN VOID *OldBuffer OPTIONAL)
VOID EFIAPI FreePool(IN VOID *Buffer)
UINT32 EFIAPI GetInitialApicId(VOID)
VOID EFIAPI GetProcessorLocationByApicId(IN UINT32 InitialApicId, OUT UINT32 *Package OPTIONAL, OUT UINT32 *Core OPTIONAL, OUT UINT32 *Thread OPTIONAL)
#define DEBUG(Expression)
VOID ShadowMicrocodeUpdatePatch(IN OUT CPU_MP_DATA *CpuMpData)
VOID MicrocodeDetect(IN CPU_MP_DATA *CpuMpData, IN UINTN ProcessorNumber)
BOOLEAN GetMicrocodePatchInfoFromHob(UINT64 *Address, UINT64 *RegionSize)
VOID ShadowMicrocodePatchByPcd(IN OUT CPU_MP_DATA *CpuMpData)
VOID ShadowMicrocodePatchWorker(IN OUT CPU_MP_DATA *CpuMpData, IN MICROCODE_PATCH_INFO *Patches, IN UINTN PatchCount, IN UINTN TotalLoadSize)
BOOLEAN EFIAPI IsValidMicrocode(IN CPU_MICROCODE_HEADER *Microcode, IN UINTN MicrocodeLength, IN UINT32 MinimumRevision, IN EDKII_PEI_MICROCODE_CPU_ID *MicrocodeCpuIds, IN UINTN MicrocodeCpuIdCount, IN BOOLEAN VerifyChecksum)
VOID EFIAPI GetProcessorMicrocodeCpuId(EDKII_PEI_MICROCODE_CPU_ID *MicrocodeCpuId)
UINT32 EFIAPI GetMicrocodeLength(IN CPU_MICROCODE_HEADER *Microcode)
UINT32 EFIAPI GetProcessorMicrocodeSignature(VOID)
#define PcdGet64(TokenName)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
VOID *EFIAPI AllocatePages(IN UINTN Pages)
#define EFI_SIZE_TO_PAGES(Size)