25#define CPU_MICROCODE_MEASUREMENT_DESCRIPTION "Microcode Measurement"
26#define CPU_MICROCODE_MEASUREMENT_EVENT_LOG_DESCRIPTION_LEN sizeof (CPU_MICROCODE_MEASUREMENT_DESCRIPTION)
30 UINT8 Description[CPU_MICROCODE_MEASUREMENT_EVENT_LOG_DESCRIPTION_LEN];
31 UINTN NumberOfMicrocodePatchesMeasured;
32 UINTN SizeOfMicrocodePatchesMeasured;
57 if (*(UINT64 *)(Offset1) > *(UINT64 *)(Offset2)) {
59 }
else if (*(UINT64 *)(Offset1) < *(UINT64 *)(Offset2)) {
83 UINT64 QuickSortBuffer;
98 (VOID *)&QuickSortBuffer
102 LastOffset = MAX_UINT64;
103 for (Index = 0; Index < *Count; Index++) {
107 if (Offsets[Index] == MAX_UINT64) {
114 if (Offsets[Index] != LastOffset) {
115 LastOffset = Offsets[Index];
116 Offsets[NewCount] = Offsets[Index];
150 UINTN TotalMicrocodeSize;
151 UINT8 *MicrocodePatchesBlob;
154 EventType = EV_CPU_MICROCODE;
156 (CHAR8 *)(EventLog.Description),
157 CPU_MICROCODE_MEASUREMENT_EVENT_LOG_DESCRIPTION_LEN,
158 CPU_MICROCODE_MEASUREMENT_DESCRIPTION
160 EventLog.NumberOfMicrocodePatchesMeasured = 0;
161 EventLog.SizeOfMicrocodePatchesMeasured = 0;
164 TotalMicrocodeSize = 0;
168 if (
NULL == GuidHob) {
169 DEBUG ((DEBUG_ERROR,
"ERROR: GetFirstGuidHob (&gEdkiiMicrocodePatchHobGuid) failed.\n"));
173 MicrocodePatchHob = GET_GUID_HOB_DATA (GuidHob);
176 "INFO: Got MicrocodePatchHob with microcode patches starting address:0x%x, microcode patches region size:0x%x, processor count:0x%x\n",
177 MicrocodePatchHob->MicrocodePatchAddress, MicrocodePatchHob->MicrocodePatchRegionSize,
178 MicrocodePatchHob->ProcessorCount)
182 MicrocodePatchHob->ProcessorCount * sizeof (UINT64),
183 MicrocodePatchHob->ProcessorSpecificPatchOffset
185 Count = MicrocodePatchHob->ProcessorCount;
190 DEBUG ((DEBUG_INFO,
"INFO: No microcode patch is ever applied, skip the measurement of microcode!\n"));
195 for (Index = 0; Index < Count; Index++) {
196 TotalMicrocodeSize +=
200 EventLog.NumberOfMicrocodePatchesMeasured = Count;
201 EventLog.SizeOfMicrocodePatchesMeasured = TotalMicrocodeSize;
204 if (
NULL == MicrocodePatchesBlob) {
205 DEBUG ((DEBUG_ERROR,
"ERROR: AllocateZeroPool to MicrocodePatchesBlob failed!\n"));
210 TotalMicrocodeSize = 0;
211 for (Index = 0; Index < Count; Index++) {
213 (VOID *)(MicrocodePatchesBlob + TotalMicrocodeSize),
214 (VOID *)((
UINTN)(MicrocodePatchHob->MicrocodePatchAddress + Offsets[Index])),
220 TotalMicrocodeSize +=
229 MicrocodePatchesBlob,
232 if (!EFI_ERROR (Status)) {
233 gBS->CloseEvent (Event);
236 "INFO: %d Microcode patches are successfully extended to TPM! The total size measured to TPM is 0x%x\n",
241 DEBUG ((DEBUG_ERROR,
"ERROR: TpmMeasureAndLogData failed with status %r!\n", Status));
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
VOID EFIAPI QuickSort(IN OUT VOID *BufferToSort, IN CONST UINTN Count, IN CONST UINTN ElementSize, IN BASE_SORT_COMPARE CompareFunction, OUT VOID *BufferOneElement)
RETURN_STATUS EFIAPI AsciiStrCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
#define DEBUG(Expression)
UINT32 EFIAPI GetMicrocodeLength(IN CPU_MICROCODE_HEADER *Microcode)
EFI_STATUS EFIAPI MicrocodeMeasurementDriverEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
INTN EFIAPI MicrocodePatchOffsetCompareFunction(IN CONST VOID *Offset1, IN CONST VOID *Offset2)
VOID EFIAPI MeasureMicrocodePatches(IN EFI_EVENT Event, IN VOID *Context)
VOID RemoveDuplicateAndInvalidOffset(IN UINT64 *Offsets, IN OUT UINTN *Count)
EFI_STATUS EFIAPI TpmMeasureAndLogData(IN UINT32 PcrIndex, IN UINT32 EventType, IN VOID *EventLog, IN UINT32 LogLen, IN VOID *HashData, IN UINT64 HashDataLen)
EFI_STATUS EFIAPI EfiCreateEventReadyToBootEx(IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL, IN VOID *NotifyContext OPTIONAL, OUT EFI_EVENT *ReadyToBootEvent)