2 This module install ACPI Firmware Performance Data Table (FPDT).
4 This module register report status code listener to collect performance data
5 for Firmware Basic Boot Performance Record and other boot performance records,
6 and install FPDT to ACPI table.
8 Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>
9 This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include <Protocol/ReportStatusCodeHandler.h>
22 #include <Protocol/AcpiTable.h>
23 #include <Protocol/SmmCommunication.h>
24 #include <Protocol/LockBox.h>
25 #include <Protocol/Variable.h>
27 #include <Guid/Acpi.h>
28 #include <Guid/FirmwarePerformance.h>
29 #include <Guid/EventGroup.h>
30 #include <Guid/EventLegacyBios.h>
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <Library/UefiRuntimeServicesTableLib.h>
34 #include <Library/BaseLib.h>
35 #include <Library/DebugLib.h>
36 #include <Library/TimerLib.h>
37 #include <Library/BaseMemoryLib.h>
38 #include <Library/MemoryAllocationLib.h>
39 #include <Library/PcdLib.h>
40 #include <Library/HobLib.h>
41 #include <Library/LockBoxLib.h>
42 #include <Library/UefiLib.h>
44 #define EXTENSION_RECORD_SIZE 0x10000
45 #define SMM_BOOT_RECORD_COMM_SIZE OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(SMM_BOOT_RECORD_COMMUNICATE)
47 EFI_RSC_HANDLER_PROTOCOL
*mRscHandlerProtocol
= NULL
;
49 BOOLEAN mLockBoxReady
= FALSE
;
50 EFI_EVENT mReadyToBootEvent
;
51 EFI_EVENT mLegacyBootEvent
;
52 EFI_EVENT mExitBootServicesEvent
;
53 UINTN mFirmwarePerformanceTableTemplateKey
= 0;
54 UINT32 mBootRecordSize
= 0;
55 UINT32 mBootRecordMaxSize
= 0;
56 UINT8
*mBootRecordBuffer
= NULL
;
57 BOOLEAN mDxeCoreReportStatusCodeEnable
= FALSE
;
59 BOOT_PERFORMANCE_TABLE
*mAcpiBootPerformanceTable
= NULL
;
60 S3_PERFORMANCE_TABLE
*mAcpiS3PerformanceTable
= NULL
;
62 FIRMWARE_PERFORMANCE_TABLE mFirmwarePerformanceTableTemplate
= {
64 EFI_ACPI_5_0_FIRMWARE_PERFORMANCE_DATA_TABLE_SIGNATURE
,
65 sizeof (FIRMWARE_PERFORMANCE_TABLE
),
66 EFI_ACPI_5_0_FIRMWARE_PERFORMANCE_DATA_TABLE_REVISION
, // Revision
67 0x00, // Checksum will be updated at runtime
69 // It is expected that these values will be updated at EntryPoint.
71 {0x00}, // OEM ID is a 6 bytes long field
72 0x00, // OEM Table ID(8 bytes long)
75 0x00, // Creator Revision
78 // Firmware Basic Boot Performance Table Pointer Record.
82 EFI_ACPI_5_0_FPDT_RECORD_TYPE_FIRMWARE_BASIC_BOOT_POINTER
, // Type
83 sizeof (EFI_ACPI_5_0_FPDT_BOOT_PERFORMANCE_TABLE_POINTER_RECORD
), // Length
84 EFI_ACPI_5_0_FPDT_RECORD_REVISION_FIRMWARE_BASIC_BOOT_POINTER
// Revision
87 0 // BootPerformanceTablePointer will be updated at runtime.
90 // S3 Performance Table Pointer Record.
94 EFI_ACPI_5_0_FPDT_RECORD_TYPE_S3_PERFORMANCE_TABLE_POINTER
, // Type
95 sizeof (EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_POINTER_RECORD
), // Length
96 EFI_ACPI_5_0_FPDT_RECORD_REVISION_S3_PERFORMANCE_TABLE_POINTER
// Revision
99 0 // S3PerformanceTablePointer will be updated at runtime.
103 BOOT_PERFORMANCE_TABLE mBootPerformanceTableTemplate
= {
105 EFI_ACPI_5_0_FPDT_BOOT_PERFORMANCE_TABLE_SIGNATURE
,
106 sizeof (BOOT_PERFORMANCE_TABLE
)
110 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_FIRMWARE_BASIC_BOOT
, // Type
111 sizeof (EFI_ACPI_5_0_FPDT_FIRMWARE_BASIC_BOOT_RECORD
), // Length
112 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_FIRMWARE_BASIC_BOOT
// Revision
116 // These values will be updated at runtime.
119 0, // OsLoaderLoadImageStart
120 0, // OsLoaderStartImageStart
121 0, // ExitBootServicesEntry
122 0 // ExitBootServicesExit
126 S3_PERFORMANCE_TABLE mS3PerformanceTableTemplate
= {
128 EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_SIGNATURE
,
129 sizeof (S3_PERFORMANCE_TABLE
)
133 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_S3_RESUME
, // Type
134 sizeof (EFI_ACPI_5_0_FPDT_S3_RESUME_RECORD
), // Length
135 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_S3_RESUME
// Revision
138 // These values will be updated by Firmware Performance PEIM.
146 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_S3_SUSPEND
, // Type
147 sizeof (EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD
), // Length
148 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_S3_SUSPEND
// Revision
151 // These values will be updated bye Firmware Performance SMM driver.
159 This function calculates and updates an UINT8 checksum.
161 @param[in] Buffer Pointer to buffer to checksum
162 @param[in] Size Number of bytes to checksum
166 FpdtAcpiTableChecksum (
171 UINTN ChecksumOffset
;
173 ChecksumOffset
= OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
, Checksum
);
176 // Set checksum to 0 first.
178 Buffer
[ChecksumOffset
] = 0;
181 // Update checksum value.
183 Buffer
[ChecksumOffset
] = CalculateCheckSum8 (Buffer
, Size
);
187 Allocate EfiReservedMemoryType below 4G memory address.
189 This function allocates EfiReservedMemoryType below 4G memory address.
191 @param[in] Size Size of memory to allocate.
193 @return Allocated address for output.
197 FpdtAllocateReservedMemoryBelow4G (
202 EFI_PHYSICAL_ADDRESS Address
;
207 Pages
= EFI_SIZE_TO_PAGES (Size
);
208 Address
= 0xffffffff;
210 Status
= gBS
->AllocatePages (
212 EfiReservedMemoryType
,
216 ASSERT_EFI_ERROR (Status
);
218 if (!EFI_ERROR (Status
)) {
219 Buffer
= (VOID
*) (UINTN
) Address
;
220 ZeroMem (Buffer
, Size
);
227 Callback function upon VariableArchProtocol and LockBoxProtocol
228 to allocate S3 performance table memory and save the pointer to LockBox.
230 @param[in] Event Event whose notification function is being invoked.
231 @param[in] Context Pointer to the notification function's context.
235 FpdtAllocateS3PerformanceTableMemory (
242 FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable
;
244 EFI_PHYSICAL_ADDRESS S3PerformanceTablePointer
;
246 if (mLockBoxReady
&& (mAcpiS3PerformanceTable
!= NULL
)) {
248 // The memory for S3 performance table should have been ready,
249 // and the pointer should have been saved to LockBox, just return.
254 if (!mLockBoxReady
) {
255 Status
= gBS
->LocateProtocol (&gEfiLockBoxProtocolGuid
, NULL
, &Interface
);
256 if (!EFI_ERROR (Status
)) {
258 // LockBox services has been ready.
260 mLockBoxReady
= TRUE
;
264 if (mAcpiS3PerformanceTable
== NULL
) {
265 Status
= gBS
->LocateProtocol (&gEfiVariableArchProtocolGuid
, NULL
, &Interface
);
266 if (!EFI_ERROR (Status
)) {
268 // Try to allocate the same runtime buffer as last time boot.
270 ZeroMem (&PerformanceVariable
, sizeof (PerformanceVariable
));
271 Size
= sizeof (PerformanceVariable
);
272 Status
= gRT
->GetVariable (
273 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME
,
274 &gEfiFirmwarePerformanceGuid
,
279 if (!EFI_ERROR (Status
)) {
280 Status
= gBS
->AllocatePages (
282 EfiReservedMemoryType
,
283 EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE
)),
284 &PerformanceVariable
.S3PerformanceTablePointer
286 if (!EFI_ERROR (Status
)) {
287 mAcpiS3PerformanceTable
= (S3_PERFORMANCE_TABLE
*) (UINTN
) PerformanceVariable
.S3PerformanceTablePointer
;
290 if (mAcpiS3PerformanceTable
== NULL
) {
292 // Fail to allocate at specified address, continue to allocate at any address.
294 mAcpiS3PerformanceTable
= (S3_PERFORMANCE_TABLE
*) FpdtAllocateReservedMemoryBelow4G (sizeof (S3_PERFORMANCE_TABLE
));
296 DEBUG ((EFI_D_INFO
, "FPDT: ACPI S3 Performance Table address = 0x%x\n", mAcpiS3PerformanceTable
));
297 if (mAcpiS3PerformanceTable
!= NULL
) {
298 CopyMem (mAcpiS3PerformanceTable
, &mS3PerformanceTableTemplate
, sizeof (mS3PerformanceTableTemplate
));
303 if (mLockBoxReady
&& (mAcpiS3PerformanceTable
!= NULL
)) {
305 // If LockBox services has been ready and memory for FPDT S3 performance table has been allocated,
306 // save the pointer to LockBox for use in S3 resume.
308 S3PerformanceTablePointer
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) mAcpiS3PerformanceTable
;
309 Status
= SaveLockBox (
310 &gFirmwarePerformanceS3PointerGuid
,
311 &S3PerformanceTablePointer
,
312 sizeof (EFI_PHYSICAL_ADDRESS
)
314 ASSERT_EFI_ERROR (Status
);
319 Install ACPI Firmware Performance Data Table (FPDT).
325 InstallFirmwarePerformanceDataTable (
330 EFI_ACPI_TABLE_PROTOCOL
*AcpiTableProtocol
;
332 UINT8
*SmmBootRecordCommBuffer
;
333 EFI_SMM_COMMUNICATE_HEADER
*SmmCommBufferHeader
;
334 SMM_BOOT_RECORD_COMMUNICATE
*SmmCommData
;
336 UINTN BootPerformanceDataSize
;
337 UINT8
*BootPerformanceData
;
338 EFI_SMM_COMMUNICATION_PROTOCOL
*Communication
;
339 FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable
;
342 // Get AcpiTable Protocol.
344 Status
= gBS
->LocateProtocol (&gEfiAcpiTableProtocolGuid
, NULL
, (VOID
**) &AcpiTableProtocol
);
345 if (EFI_ERROR (Status
)) {
350 // Collect boot records from SMM drivers.
352 SmmBootRecordCommBuffer
= NULL
;
354 Status
= gBS
->LocateProtocol (&gEfiSmmCommunicationProtocolGuid
, NULL
, (VOID
**) &Communication
);
355 if (!EFI_ERROR (Status
)) {
357 // Initialize communicate buffer
359 SmmBootRecordCommBuffer
= AllocateZeroPool (SMM_BOOT_RECORD_COMM_SIZE
);
360 ASSERT (SmmBootRecordCommBuffer
!= NULL
);
361 SmmCommBufferHeader
= (EFI_SMM_COMMUNICATE_HEADER
*)SmmBootRecordCommBuffer
;
362 SmmCommData
= (SMM_BOOT_RECORD_COMMUNICATE
*)SmmCommBufferHeader
->Data
;
363 ZeroMem((UINT8
*)SmmCommData
, sizeof(SMM_BOOT_RECORD_COMMUNICATE
));
365 CopyGuid (&SmmCommBufferHeader
->HeaderGuid
, &gEfiFirmwarePerformanceGuid
);
366 SmmCommBufferHeader
->MessageLength
= sizeof(SMM_BOOT_RECORD_COMMUNICATE
);
367 CommSize
= SMM_BOOT_RECORD_COMM_SIZE
;
370 // Get the size of boot records.
372 SmmCommData
->Function
= SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE
;
373 SmmCommData
->BootRecordData
= NULL
;
374 Status
= Communication
->Communicate (Communication
, SmmBootRecordCommBuffer
, &CommSize
);
375 ASSERT_EFI_ERROR (Status
);
377 if (!EFI_ERROR (SmmCommData
->ReturnStatus
) && SmmCommData
->BootRecordSize
!= 0) {
379 // Get all boot records
381 SmmCommData
->Function
= SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA
;
382 SmmCommData
->BootRecordData
= AllocateZeroPool(SmmCommData
->BootRecordSize
);
383 ASSERT (SmmCommData
->BootRecordData
!= NULL
);
385 Status
= Communication
->Communicate (Communication
, SmmBootRecordCommBuffer
, &CommSize
);
386 ASSERT_EFI_ERROR (Status
);
387 ASSERT_EFI_ERROR(SmmCommData
->ReturnStatus
);
392 // Prepare memory for Boot Performance table.
393 // Boot Performance table includes BasicBoot record, and one or more appended Boot Records.
395 BootPerformanceDataSize
= sizeof (BOOT_PERFORMANCE_TABLE
) + mBootRecordSize
+ PcdGet32 (PcdExtFpdtBootRecordPadSize
);
396 if (SmmCommData
!= NULL
) {
397 BootPerformanceDataSize
+= SmmCommData
->BootRecordSize
;
401 // Try to allocate the same runtime buffer as last time boot.
403 ZeroMem (&PerformanceVariable
, sizeof (PerformanceVariable
));
404 Size
= sizeof (PerformanceVariable
);
405 Status
= gRT
->GetVariable (
406 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME
,
407 &gEfiFirmwarePerformanceGuid
,
412 if (!EFI_ERROR (Status
)) {
413 Status
= gBS
->AllocatePages (
415 EfiReservedMemoryType
,
416 EFI_SIZE_TO_PAGES (BootPerformanceDataSize
),
417 &PerformanceVariable
.BootPerformanceTablePointer
419 if (!EFI_ERROR (Status
)) {
420 mAcpiBootPerformanceTable
= (BOOT_PERFORMANCE_TABLE
*) (UINTN
) PerformanceVariable
.BootPerformanceTablePointer
;
424 if (mAcpiBootPerformanceTable
== NULL
) {
426 // Fail to allocate at specified address, continue to allocate at any address.
428 mAcpiBootPerformanceTable
= (BOOT_PERFORMANCE_TABLE
*) FpdtAllocateReservedMemoryBelow4G (BootPerformanceDataSize
);
430 DEBUG ((EFI_D_INFO
, "FPDT: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable
));
432 if (mAcpiBootPerformanceTable
== NULL
) {
433 if (SmmCommData
!= NULL
&& SmmCommData
->BootRecordData
!= NULL
) {
434 FreePool (SmmCommData
->BootRecordData
);
436 if (SmmBootRecordCommBuffer
!= NULL
) {
437 FreePool (SmmBootRecordCommBuffer
);
439 if (mAcpiS3PerformanceTable
!= NULL
) {
440 FreePages (mAcpiS3PerformanceTable
, EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE
)));
442 return EFI_OUT_OF_RESOURCES
;
446 // Prepare Boot Performance Table.
448 BootPerformanceData
= (UINT8
*) mAcpiBootPerformanceTable
;
450 // Fill Basic Boot record to Boot Performance Table.
452 CopyMem (mAcpiBootPerformanceTable
, &mBootPerformanceTableTemplate
, sizeof (mBootPerformanceTableTemplate
));
453 BootPerformanceData
= BootPerformanceData
+ mAcpiBootPerformanceTable
->Header
.Length
;
455 // Fill Boot records from boot drivers.
457 CopyMem (BootPerformanceData
, mBootRecordBuffer
, mBootRecordSize
);
458 mAcpiBootPerformanceTable
->Header
.Length
+= mBootRecordSize
;
459 BootPerformanceData
= BootPerformanceData
+ mBootRecordSize
;
460 if (SmmCommData
!= NULL
&& SmmCommData
->BootRecordData
!= NULL
) {
462 // Fill Boot records from SMM drivers.
464 CopyMem (BootPerformanceData
, SmmCommData
->BootRecordData
, SmmCommData
->BootRecordSize
);
465 FreePool (SmmCommData
->BootRecordData
);
466 mAcpiBootPerformanceTable
->Header
.Length
= (UINT32
) (mAcpiBootPerformanceTable
->Header
.Length
+ SmmCommData
->BootRecordSize
);
467 BootPerformanceData
= BootPerformanceData
+ SmmCommData
->BootRecordSize
;
469 if (SmmBootRecordCommBuffer
!= NULL
) {
470 FreePool (SmmBootRecordCommBuffer
);
474 // Save Boot Performance Table address to Variable for use in S4 resume.
476 PerformanceVariable
.BootPerformanceTablePointer
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) mAcpiBootPerformanceTable
;
478 // Update Boot Performance Table Pointer in template.
480 mFirmwarePerformanceTableTemplate
.BootPointerRecord
.BootPerformanceTablePointer
= (UINT64
) (UINTN
) mAcpiBootPerformanceTable
;
483 // Save S3 Performance Table address to Variable for use in S4 resume.
485 PerformanceVariable
.S3PerformanceTablePointer
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) mAcpiS3PerformanceTable
;
487 // Update S3 Performance Table Pointer in template.
489 mFirmwarePerformanceTableTemplate
.S3PointerRecord
.S3PerformanceTablePointer
= (UINT64
) (UINTN
) mAcpiS3PerformanceTable
;
491 // Save Runtime Performance Table pointers to Variable.
492 // Don't check SetVariable return status. It doesn't impact FPDT table generation.
495 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME
,
496 &gEfiFirmwarePerformanceGuid
,
497 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
498 sizeof (PerformanceVariable
),
503 // Publish Firmware Performance Data Table.
505 FpdtAcpiTableChecksum ((UINT8
*) &mFirmwarePerformanceTableTemplate
, mFirmwarePerformanceTableTemplate
.Header
.Length
);
506 Status
= AcpiTableProtocol
->InstallAcpiTable (
508 &mFirmwarePerformanceTableTemplate
,
509 mFirmwarePerformanceTableTemplate
.Header
.Length
,
510 &mFirmwarePerformanceTableTemplateKey
512 if (EFI_ERROR (Status
)) {
513 FreePages (mAcpiBootPerformanceTable
, EFI_SIZE_TO_PAGES (BootPerformanceDataSize
));
514 if (mAcpiS3PerformanceTable
!= NULL
) {
515 FreePages (mAcpiS3PerformanceTable
, EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE
)));
517 mAcpiBootPerformanceTable
= NULL
;
518 mAcpiS3PerformanceTable
= NULL
;
523 // Free temp Boot record, and update Boot Record to point to Basic Boot performance table.
525 if (mBootRecordBuffer
!= NULL
) {
526 FreePool (mBootRecordBuffer
);
528 mBootRecordBuffer
= (UINT8
*) mAcpiBootPerformanceTable
;
529 mBootRecordSize
= mAcpiBootPerformanceTable
->Header
.Length
;
530 mBootRecordMaxSize
= mBootRecordSize
+ PcdGet32 (PcdExtFpdtBootRecordPadSize
);
536 Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT. This is used to
537 install the Firmware Performance Data Table.
539 @param[in] Event The Event that is being processed.
540 @param[in] Context The Event Context.
545 FpdtReadyToBootEventNotify (
550 if (mAcpiBootPerformanceTable
== NULL
) {
552 // ACPI Firmware Performance Data Table not installed yet, install it now.
554 InstallFirmwarePerformanceDataTable ();
559 Report status code listener of FPDT. This is used to collect performance data
560 for OsLoaderLoadImageStart and OsLoaderStartImageStart in FPDT.
562 @param[in] CodeType Indicates the type of status code being reported.
563 @param[in] Value Describes the current status of a hardware or software entity.
564 This included information about the class and subclass that is used to
565 classify the entity as well as an operation.
566 @param[in] Instance The enumeration of a hardware or software entity within
567 the system. Valid instance numbers start with 1.
568 @param[in] CallerId This optional parameter may be used to identify the caller.
569 This parameter allows the status code driver to apply different rules to
571 @param[in] Data This optional parameter may be used to pass additional data.
573 @retval EFI_SUCCESS Status code is what we expected.
574 @retval EFI_UNSUPPORTED Status code not supported.
579 FpdtStatusCodeListenerDxe (
580 IN EFI_STATUS_CODE_TYPE CodeType
,
581 IN EFI_STATUS_CODE_VALUE Value
,
583 IN EFI_GUID
*CallerId
,
584 IN EFI_STATUS_CODE_DATA
*Data
590 // Check whether status code is what we are interested in.
592 if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) != EFI_PROGRESS_CODE
) {
593 return EFI_UNSUPPORTED
;
596 if (Value
== (EFI_SOFTWARE_DXE_CORE
| EFI_SW_DXE_CORE_PC_HANDOFF_TO_NEXT
)) {
598 // DxeCore ReportStatusCode Enable so that the capability can be supported.
600 mDxeCoreReportStatusCodeEnable
= TRUE
;
603 Status
= EFI_SUCCESS
;
604 if (Value
== PcdGet32 (PcdProgressCodeOsLoaderLoad
)) {
606 // Progress code for OS Loader LoadImage.
608 if (mAcpiBootPerformanceTable
== NULL
) {
613 // Update OS Loader LoadImage Start for UEFI boot.
615 mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderLoadImageStart
= GetTimeInNanoSecond (GetPerformanceCounter ());
616 } else if (Value
== PcdGet32 (PcdProgressCodeOsLoaderStart
)) {
618 // Progress code for OS Loader StartImage.
620 if (mAcpiBootPerformanceTable
== NULL
) {
625 // Update OS Loader StartImage Start for UEFI boot.
627 mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderStartImageStart
= GetTimeInNanoSecond (GetPerformanceCounter ());
628 } else if (Value
== (EFI_SOFTWARE_EFI_BOOT_SERVICE
| EFI_SW_BS_PC_EXIT_BOOT_SERVICES
)) {
630 // Unregister boot time report status code listener.
632 mRscHandlerProtocol
->Unregister (FpdtStatusCodeListenerDxe
);
635 // Progress code for ExitBootServices.
637 if (mAcpiBootPerformanceTable
== NULL
) {
642 // Update ExitBootServicesExit for UEFI boot.
644 mAcpiBootPerformanceTable
->BasicBoot
.ExitBootServicesExit
= GetTimeInNanoSecond (GetPerformanceCounter ());
645 } else if (Value
== (EFI_SOFTWARE_DXE_BS_DRIVER
| EFI_SW_DXE_BS_PC_LEGACY_BOOT_EVENT
)) {
646 if (mAcpiBootPerformanceTable
== NULL
) {
648 // Firmware Performance Data Table not installed, do nothing.
654 // Update Firmware Basic Boot Performance Record for legacy boot.
656 mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderStartImageStart
= GetTimeInNanoSecond (GetPerformanceCounter ());
659 // Dump FPDT Boot Performance record.
661 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - ResetEnd = %ld\n", mAcpiBootPerformanceTable
->BasicBoot
.ResetEnd
));
662 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - OsLoaderLoadImageStart = 0\n"));
663 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - OsLoaderStartImageStart = %ld\n", mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderStartImageStart
));
664 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - ExitBootServicesEntry = 0\n"));
665 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - ExitBootServicesExit = 0\n"));
666 } else if (Data
!= NULL
&& CompareGuid (&Data
->Type
, &gEfiFirmwarePerformanceGuid
)) {
668 // Append one or more Boot records
670 if (mAcpiBootPerformanceTable
== NULL
) {
672 // Append Boot records before FPDT ACPI table is installed.
674 if (mBootRecordSize
+ Data
->Size
> mBootRecordMaxSize
) {
675 mBootRecordBuffer
= ReallocatePool (mBootRecordSize
, mBootRecordSize
+ Data
->Size
+ EXTENSION_RECORD_SIZE
, mBootRecordBuffer
);
676 ASSERT (mBootRecordBuffer
!= NULL
);
677 mBootRecordMaxSize
= mBootRecordSize
+ Data
->Size
+ EXTENSION_RECORD_SIZE
;
680 // Save boot record into the temp memory space.
682 CopyMem (mBootRecordBuffer
+ mBootRecordSize
, Data
+ 1, Data
->Size
);
683 mBootRecordSize
+= Data
->Size
;
686 // Append Boot records after FPDT ACPI table is installed.
688 if (mBootRecordSize
+ Data
->Size
> mBootRecordMaxSize
) {
690 // No enough space to save boot record.
692 Status
= EFI_OUT_OF_RESOURCES
;
695 // Save boot record into BootPerformance table
697 CopyMem (mBootRecordBuffer
+ mBootRecordSize
, Data
+ 1, Data
->Size
);
698 mBootRecordSize
+= Data
->Size
;
699 mAcpiBootPerformanceTable
->Header
.Length
= mBootRecordSize
;
704 // Ignore else progress code.
706 Status
= EFI_UNSUPPORTED
;
714 Notify function for event EVT_SIGNAL_EXIT_BOOT_SERVICES. This is used to record
715 performance data for ExitBootServicesEntry in FPDT.
717 @param[in] Event The Event that is being processed.
718 @param[in] Context The Event Context.
723 FpdtExitBootServicesEventNotify (
728 if (!mDxeCoreReportStatusCodeEnable
) {
730 // When DxeCore Report Status Code is disabled,
731 // Unregister boot time report status code listener at ExitBootService Event.
733 mRscHandlerProtocol
->Unregister (FpdtStatusCodeListenerDxe
);
736 if (mAcpiBootPerformanceTable
== NULL
) {
738 // Firmware Performance Data Table not installed, do nothing.
744 // Update Firmware Basic Boot Performance Record for UEFI boot.
746 mAcpiBootPerformanceTable
->BasicBoot
.ExitBootServicesEntry
= GetTimeInNanoSecond (GetPerformanceCounter ());
749 // Dump FPDT Boot Performance record.
751 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - ResetEnd = %ld\n", mAcpiBootPerformanceTable
->BasicBoot
.ResetEnd
));
752 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - OsLoaderLoadImageStart = %ld\n", mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderLoadImageStart
));
753 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - OsLoaderStartImageStart = %ld\n", mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderStartImageStart
));
754 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - ExitBootServicesEntry = %ld\n", mAcpiBootPerformanceTable
->BasicBoot
.ExitBootServicesEntry
));
756 // ExitBootServicesExit will be updated later, so don't dump it here.
761 The module Entry Point of the Firmware Performance Data Table DXE driver.
763 @param[in] ImageHandle The firmware allocated handle for the EFI image.
764 @param[in] SystemTable A pointer to the EFI System Table.
766 @retval EFI_SUCCESS The entry point is executed successfully.
767 @retval Other Some error occurs when executing this entry point.
772 FirmwarePerformanceDxeEntryPoint (
773 IN EFI_HANDLE ImageHandle
,
774 IN EFI_SYSTEM_TABLE
*SystemTable
778 EFI_HOB_GUID_TYPE
*GuidHob
;
779 FIRMWARE_SEC_PERFORMANCE
*Performance
;
784 mFirmwarePerformanceTableTemplate
.Header
.OemId
,
785 PcdGetPtr (PcdAcpiDefaultOemId
),
786 sizeof (mFirmwarePerformanceTableTemplate
.Header
.OemId
)
788 OemTableId
= PcdGet64 (PcdAcpiDefaultOemTableId
);
789 CopyMem (&mFirmwarePerformanceTableTemplate
.Header
.OemTableId
, &OemTableId
, sizeof (UINT64
));
790 mFirmwarePerformanceTableTemplate
.Header
.OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
791 mFirmwarePerformanceTableTemplate
.Header
.CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
792 mFirmwarePerformanceTableTemplate
.Header
.CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
795 // Get Report Status Code Handler Protocol.
797 Status
= gBS
->LocateProtocol (&gEfiRscHandlerProtocolGuid
, NULL
, (VOID
**) &mRscHandlerProtocol
);
798 ASSERT_EFI_ERROR (Status
);
801 // Register report status code listener for OS Loader load and start.
803 Status
= mRscHandlerProtocol
->Register (FpdtStatusCodeListenerDxe
, TPL_HIGH_LEVEL
);
804 ASSERT_EFI_ERROR (Status
);
807 // Register the notify function to update FPDT on ExitBootServices Event.
809 Status
= gBS
->CreateEventEx (
812 FpdtExitBootServicesEventNotify
,
814 &gEfiEventExitBootServicesGuid
,
815 &mExitBootServicesEvent
817 ASSERT_EFI_ERROR (Status
);
820 // Create ready to boot event to install ACPI FPDT table.
822 Status
= gBS
->CreateEventEx (
825 FpdtReadyToBootEventNotify
,
827 &gEfiEventReadyToBootGuid
,
830 ASSERT_EFI_ERROR (Status
);
833 // Retrieve GUID HOB data that contains the ResetEnd.
835 GuidHob
= GetFirstGuidHob (&gEfiFirmwarePerformanceGuid
);
836 if (GuidHob
!= NULL
) {
837 Performance
= (FIRMWARE_SEC_PERFORMANCE
*) GET_GUID_HOB_DATA (GuidHob
);
838 mBootPerformanceTableTemplate
.BasicBoot
.ResetEnd
= Performance
->ResetEnd
;
841 // SEC Performance Data Hob not found, ResetEnd in ACPI FPDT table will be 0.
843 DEBUG ((EFI_D_ERROR
, "FPDT: WARNING: SEC Performance Data Hob not found, ResetEnd will be set to 0!\n"));
846 if (FeaturePcdGet (PcdFirmwarePerformanceDataTableS3Support
)) {
848 // Register callback function upon VariableArchProtocol and LockBoxProtocol
849 // to allocate S3 performance table memory and save the pointer to LockBox.
851 EfiCreateProtocolNotifyEvent (
852 &gEfiVariableArchProtocolGuid
,
854 FpdtAllocateS3PerformanceTableMemory
,
858 EfiCreateProtocolNotifyEvent (
859 &gEfiLockBoxProtocolGuid
,
861 FpdtAllocateS3PerformanceTableMemory
,
867 // Exclude S3 Performance Table Pointer from FPDT table template.
869 mFirmwarePerformanceTableTemplate
.Header
.Length
-= sizeof (EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_POINTER_RECORD
);