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 - 2013, 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>
45 // ACPI table information used to initialize tables.
47 #define EFI_ACPI_OEM_ID "INTEL"
48 #define EFI_ACPI_OEM_TABLE_ID 0x2020204F4E414954ULL // "TIANO "
49 #define EFI_ACPI_OEM_REVISION 0x00000001
50 #define EFI_ACPI_CREATOR_ID 0x5446534D // TBD "MSFT"
51 #define EFI_ACPI_CREATOR_REVISION 0x01000013 // TBD
52 #define EXTENSION_RECORD_SIZE 0x10000
53 #define SMM_BOOT_RECORD_COMM_SIZE OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(SMM_BOOT_RECORD_COMMUNICATE)
55 EFI_RSC_HANDLER_PROTOCOL
*mRscHandlerProtocol
= NULL
;
57 BOOLEAN mLockBoxReady
= FALSE
;
58 EFI_EVENT mReadyToBootEvent
;
59 EFI_EVENT mLegacyBootEvent
;
60 EFI_EVENT mExitBootServicesEvent
;
61 UINTN mFirmwarePerformanceTableTemplateKey
= 0;
62 UINT32 mBootRecordSize
= 0;
63 UINT32 mBootRecordMaxSize
= 0;
64 UINT8
*mBootRecordBuffer
= NULL
;
66 BOOT_PERFORMANCE_TABLE
*mAcpiBootPerformanceTable
= NULL
;
67 S3_PERFORMANCE_TABLE
*mAcpiS3PerformanceTable
= NULL
;
69 FIRMWARE_PERFORMANCE_TABLE mFirmwarePerformanceTableTemplate
= {
71 EFI_ACPI_5_0_FIRMWARE_PERFORMANCE_DATA_TABLE_SIGNATURE
,
72 sizeof (FIRMWARE_PERFORMANCE_TABLE
),
73 EFI_ACPI_5_0_FIRMWARE_PERFORMANCE_DATA_TABLE_REVISION
, // Revision
74 0x00, // Checksum will be updated at runtime
76 // It is expected that these values will be updated at runtime.
78 EFI_ACPI_OEM_ID
, // OEMID is a 6 bytes long field
79 EFI_ACPI_OEM_TABLE_ID
, // OEM table identification(8 bytes long)
80 EFI_ACPI_OEM_REVISION
, // OEM revision number
81 EFI_ACPI_CREATOR_ID
, // ASL compiler vendor ID
82 EFI_ACPI_CREATOR_REVISION
, // ASL compiler revision number
85 // Firmware Basic Boot Performance Table Pointer Record.
89 EFI_ACPI_5_0_FPDT_RECORD_TYPE_FIRMWARE_BASIC_BOOT_POINTER
, // Type
90 sizeof (EFI_ACPI_5_0_FPDT_BOOT_PERFORMANCE_TABLE_POINTER_RECORD
), // Length
91 EFI_ACPI_5_0_FPDT_RECORD_REVISION_FIRMWARE_BASIC_BOOT_POINTER
// Revision
94 0 // BootPerformanceTablePointer will be updated at runtime.
97 // S3 Performance Table Pointer Record.
101 EFI_ACPI_5_0_FPDT_RECORD_TYPE_S3_PERFORMANCE_TABLE_POINTER
, // Type
102 sizeof (EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_POINTER_RECORD
), // Length
103 EFI_ACPI_5_0_FPDT_RECORD_REVISION_S3_PERFORMANCE_TABLE_POINTER
// Revision
106 0 // S3PerformanceTablePointer will be updated at runtime.
110 BOOT_PERFORMANCE_TABLE mBootPerformanceTableTemplate
= {
112 EFI_ACPI_5_0_FPDT_BOOT_PERFORMANCE_TABLE_SIGNATURE
,
113 sizeof (BOOT_PERFORMANCE_TABLE
)
117 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_FIRMWARE_BASIC_BOOT
, // Type
118 sizeof (EFI_ACPI_5_0_FPDT_FIRMWARE_BASIC_BOOT_RECORD
), // Length
119 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_FIRMWARE_BASIC_BOOT
// Revision
123 // These values will be updated at runtime.
126 0, // OsLoaderLoadImageStart
127 0, // OsLoaderStartImageStart
128 0, // ExitBootServicesEntry
129 0 // ExitBootServicesExit
133 S3_PERFORMANCE_TABLE mS3PerformanceTableTemplate
= {
135 EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_SIGNATURE
,
136 sizeof (S3_PERFORMANCE_TABLE
)
140 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_S3_RESUME
, // Type
141 sizeof (EFI_ACPI_5_0_FPDT_S3_RESUME_RECORD
), // Length
142 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_S3_RESUME
// Revision
145 // These values will be updated by Firmware Performance PEIM.
153 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_S3_SUSPEND
, // Type
154 sizeof (EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD
), // Length
155 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_S3_SUSPEND
// Revision
158 // These values will be updated bye Firmware Performance SMM driver.
166 This function calculates and updates an UINT8 checksum.
168 @param[in] Buffer Pointer to buffer to checksum
169 @param[in] Size Number of bytes to checksum
173 FpdtAcpiTableChecksum (
178 UINTN ChecksumOffset
;
180 ChecksumOffset
= OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
, Checksum
);
183 // Set checksum to 0 first.
185 Buffer
[ChecksumOffset
] = 0;
188 // Update checksum value.
190 Buffer
[ChecksumOffset
] = CalculateCheckSum8 (Buffer
, Size
);
194 Allocate EfiReservedMemoryType below 4G memory address.
196 This function allocates EfiReservedMemoryType below 4G memory address.
198 @param[in] Size Size of memory to allocate.
200 @return Allocated address for output.
204 FpdtAllocateReservedMemoryBelow4G (
209 EFI_PHYSICAL_ADDRESS Address
;
214 Pages
= EFI_SIZE_TO_PAGES (Size
);
215 Address
= 0xffffffff;
217 Status
= gBS
->AllocatePages (
219 EfiReservedMemoryType
,
223 ASSERT_EFI_ERROR (Status
);
225 if (!EFI_ERROR (Status
)) {
226 Buffer
= (VOID
*) (UINTN
) Address
;
227 ZeroMem (Buffer
, Size
);
234 Callback function upon VariableArchProtocol and LockBoxProtocol
235 to allocate S3 performance table memory and save the pointer to LockBox.
237 @param[in] Event Event whose notification function is being invoked.
238 @param[in] Context Pointer to the notification function's context.
242 FpdtAllocateS3PerformanceTableMemory (
249 FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable
;
251 EFI_PHYSICAL_ADDRESS S3PerformanceTablePointer
;
253 if (mLockBoxReady
&& (mAcpiS3PerformanceTable
!= NULL
)) {
255 // The memory for S3 performance table should have been ready,
256 // and the pointer should have been saved to LockBox, just return.
261 if (!mLockBoxReady
) {
262 Status
= gBS
->LocateProtocol (&gEfiLockBoxProtocolGuid
, NULL
, &Interface
);
263 if (!EFI_ERROR (Status
)) {
265 // LockBox services has been ready.
267 mLockBoxReady
= TRUE
;
271 if (mAcpiS3PerformanceTable
== NULL
) {
272 Status
= gBS
->LocateProtocol (&gEfiVariableArchProtocolGuid
, NULL
, &Interface
);
273 if (!EFI_ERROR (Status
)) {
275 // Try to allocate the same runtime buffer as last time boot.
277 ZeroMem (&PerformanceVariable
, sizeof (PerformanceVariable
));
278 Size
= sizeof (PerformanceVariable
);
279 Status
= gRT
->GetVariable (
280 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME
,
281 &gEfiFirmwarePerformanceGuid
,
286 if (!EFI_ERROR (Status
)) {
287 Status
= gBS
->AllocatePages (
289 EfiReservedMemoryType
,
290 EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE
)),
291 &PerformanceVariable
.S3PerformanceTablePointer
293 if (!EFI_ERROR (Status
)) {
294 mAcpiS3PerformanceTable
= (S3_PERFORMANCE_TABLE
*) (UINTN
) PerformanceVariable
.S3PerformanceTablePointer
;
297 if (mAcpiS3PerformanceTable
== NULL
) {
299 // Fail to allocate at specified address, continue to allocate at any address.
301 mAcpiS3PerformanceTable
= (S3_PERFORMANCE_TABLE
*) FpdtAllocateReservedMemoryBelow4G (sizeof (S3_PERFORMANCE_TABLE
));
303 DEBUG ((EFI_D_INFO
, "FPDT: ACPI S3 Performance Table address = 0x%x\n", mAcpiS3PerformanceTable
));
304 if (mAcpiS3PerformanceTable
!= NULL
) {
305 CopyMem (mAcpiS3PerformanceTable
, &mS3PerformanceTableTemplate
, sizeof (mS3PerformanceTableTemplate
));
310 if (mLockBoxReady
&& (mAcpiS3PerformanceTable
!= NULL
)) {
312 // If LockBox services has been ready and memory for FPDT S3 performance table has been allocated,
313 // save the pointer to LockBox for use in S3 resume.
315 S3PerformanceTablePointer
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) mAcpiS3PerformanceTable
;
316 Status
= SaveLockBox (
317 &gFirmwarePerformanceS3PointerGuid
,
318 &S3PerformanceTablePointer
,
319 sizeof (EFI_PHYSICAL_ADDRESS
)
321 ASSERT_EFI_ERROR (Status
);
326 Install ACPI Firmware Performance Data Table (FPDT).
332 InstallFirmwarePerformanceDataTable (
337 EFI_ACPI_TABLE_PROTOCOL
*AcpiTableProtocol
;
339 UINT8
*SmmBootRecordCommBuffer
;
340 EFI_SMM_COMMUNICATE_HEADER
*SmmCommBufferHeader
;
341 SMM_BOOT_RECORD_COMMUNICATE
*SmmCommData
;
343 UINTN BootPerformanceDataSize
;
344 UINT8
*BootPerformanceData
;
345 EFI_SMM_COMMUNICATION_PROTOCOL
*Communication
;
346 FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable
;
349 // Get AcpiTable Protocol.
351 Status
= gBS
->LocateProtocol (&gEfiAcpiTableProtocolGuid
, NULL
, (VOID
**) &AcpiTableProtocol
);
352 if (EFI_ERROR (Status
)) {
357 // Collect boot records from SMM drivers.
359 SmmBootRecordCommBuffer
= AllocateZeroPool (SMM_BOOT_RECORD_COMM_SIZE
);
360 ASSERT (SmmBootRecordCommBuffer
!= NULL
);
362 Status
= gBS
->LocateProtocol (&gEfiSmmCommunicationProtocolGuid
, NULL
, (VOID
**) &Communication
);
363 if (!EFI_ERROR (Status
)) {
365 // Initialize communicate buffer
367 SmmCommBufferHeader
= (EFI_SMM_COMMUNICATE_HEADER
*)SmmBootRecordCommBuffer
;
368 SmmCommData
= (SMM_BOOT_RECORD_COMMUNICATE
*)SmmCommBufferHeader
->Data
;
369 ZeroMem((UINT8
*)SmmCommData
, sizeof(SMM_BOOT_RECORD_COMMUNICATE
));
371 CopyGuid (&SmmCommBufferHeader
->HeaderGuid
, &gEfiFirmwarePerformanceGuid
);
372 SmmCommBufferHeader
->MessageLength
= sizeof(SMM_BOOT_RECORD_COMMUNICATE
);
373 CommSize
= SMM_BOOT_RECORD_COMM_SIZE
;
376 // Get the size of boot records.
378 SmmCommData
->Function
= SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE
;
379 SmmCommData
->BootRecordData
= NULL
;
380 Status
= Communication
->Communicate (Communication
, SmmBootRecordCommBuffer
, &CommSize
);
381 ASSERT_EFI_ERROR (Status
);
383 if (!EFI_ERROR (SmmCommData
->ReturnStatus
) && SmmCommData
->BootRecordSize
!= 0) {
385 // Get all boot records
387 SmmCommData
->Function
= SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA
;
388 SmmCommData
->BootRecordData
= AllocateZeroPool(SmmCommData
->BootRecordSize
);
389 ASSERT (SmmCommData
->BootRecordData
!= NULL
);
391 Status
= Communication
->Communicate (Communication
, SmmBootRecordCommBuffer
, &CommSize
);
392 ASSERT_EFI_ERROR (Status
);
393 ASSERT_EFI_ERROR(SmmCommData
->ReturnStatus
);
396 FreePool (SmmBootRecordCommBuffer
);
399 // Prepare memory for Boot Performance table.
400 // Boot Performance table includes BasicBoot record, and one or more appended Boot Records.
402 BootPerformanceDataSize
= sizeof (BOOT_PERFORMANCE_TABLE
) + mBootRecordSize
+ PcdGet32 (PcdExtFpdtBootRecordPadSize
);
403 if (SmmCommData
!= NULL
) {
404 BootPerformanceDataSize
+= SmmCommData
->BootRecordSize
;
408 // Try to allocate the same runtime buffer as last time boot.
410 ZeroMem (&PerformanceVariable
, sizeof (PerformanceVariable
));
411 Size
= sizeof (PerformanceVariable
);
412 Status
= gRT
->GetVariable (
413 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME
,
414 &gEfiFirmwarePerformanceGuid
,
419 if (!EFI_ERROR (Status
)) {
420 Status
= gBS
->AllocatePages (
422 EfiReservedMemoryType
,
423 EFI_SIZE_TO_PAGES (BootPerformanceDataSize
),
424 &PerformanceVariable
.BootPerformanceTablePointer
426 if (!EFI_ERROR (Status
)) {
427 mAcpiBootPerformanceTable
= (BOOT_PERFORMANCE_TABLE
*) (UINTN
) PerformanceVariable
.BootPerformanceTablePointer
;
431 if (mAcpiBootPerformanceTable
== NULL
) {
433 // Fail to allocate at specified address, continue to allocate at any address.
435 mAcpiBootPerformanceTable
= (BOOT_PERFORMANCE_TABLE
*) FpdtAllocateReservedMemoryBelow4G (BootPerformanceDataSize
);
437 DEBUG ((EFI_D_INFO
, "FPDT: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable
));
439 if (mAcpiBootPerformanceTable
== NULL
) {
440 if (SmmCommData
!= NULL
&& SmmCommData
->BootRecordData
!= NULL
) {
441 FreePool (SmmCommData
->BootRecordData
);
443 if (mAcpiS3PerformanceTable
!= NULL
) {
444 FreePages (mAcpiS3PerformanceTable
, EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE
)));
446 return EFI_OUT_OF_RESOURCES
;
450 // Prepare Boot Performance Table.
452 BootPerformanceData
= (UINT8
*) mAcpiBootPerformanceTable
;
454 // Fill Basic Boot record to Boot Performance Table.
456 CopyMem (mAcpiBootPerformanceTable
, &mBootPerformanceTableTemplate
, sizeof (mBootPerformanceTableTemplate
));
457 BootPerformanceData
= BootPerformanceData
+ mAcpiBootPerformanceTable
->Header
.Length
;
459 // Fill Boot records from boot drivers.
461 CopyMem (BootPerformanceData
, mBootRecordBuffer
, mBootRecordSize
);
462 mAcpiBootPerformanceTable
->Header
.Length
+= mBootRecordSize
;
463 BootPerformanceData
= BootPerformanceData
+ mBootRecordSize
;
464 if (SmmCommData
!= NULL
&& SmmCommData
->BootRecordData
!= NULL
) {
466 // Fill Boot records from SMM drivers.
468 CopyMem (BootPerformanceData
, SmmCommData
->BootRecordData
, SmmCommData
->BootRecordSize
);
469 FreePool (SmmCommData
->BootRecordData
);
470 mAcpiBootPerformanceTable
->Header
.Length
= (UINT32
) (mAcpiBootPerformanceTable
->Header
.Length
+ SmmCommData
->BootRecordSize
);
471 BootPerformanceData
= BootPerformanceData
+ SmmCommData
->BootRecordSize
;
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.
493 Status
= gRT
->SetVariable (
494 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME
,
495 &gEfiFirmwarePerformanceGuid
,
496 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
497 sizeof (PerformanceVariable
),
500 ASSERT_EFI_ERROR (Status
);
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 Notify function for event group EFI_EVENT_LEGACY_BOOT_GUID. This is used to
560 record performance data for OsLoaderLoadImageStart in FPDT for legacy boot.
562 @param[in] Event The Event that is being processed.
563 @param[in] Context The Event Context.
568 FpdtLegacyBootEventNotify (
573 if (mAcpiBootPerformanceTable
== NULL
) {
575 // Firmware Performance Data Table not installed, do nothing.
581 // Update Firmware Basic Boot Performance Record for legacy boot.
583 mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderLoadImageStart
= 0;
584 mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderStartImageStart
= GetTimeInNanoSecond (GetPerformanceCounter ());
585 mAcpiBootPerformanceTable
->BasicBoot
.ExitBootServicesEntry
= 0;
586 mAcpiBootPerformanceTable
->BasicBoot
.ExitBootServicesExit
= 0;
589 // Dump FPDT Boot Performance record.
591 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - ResetEnd = %ld\n", mAcpiBootPerformanceTable
->BasicBoot
.ResetEnd
));
592 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - OsLoaderLoadImageStart = 0\n"));
593 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - OsLoaderStartImageStart = %ld\n", mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderStartImageStart
));
594 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - ExitBootServicesEntry = 0\n"));
595 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - ExitBootServicesExit = 0\n"));
599 Notify function for event EVT_SIGNAL_EXIT_BOOT_SERVICES. This is used to record
600 performance data for ExitBootServicesEntry in FPDT.
602 @param[in] Event The Event that is being processed.
603 @param[in] Context The Event Context.
608 FpdtExitBootServicesEventNotify (
613 if (mAcpiBootPerformanceTable
== NULL
) {
615 // Firmware Performance Data Table not installed, do nothing.
621 // Update Firmware Basic Boot Performance Record for UEFI boot.
623 mAcpiBootPerformanceTable
->BasicBoot
.ExitBootServicesEntry
= GetTimeInNanoSecond (GetPerformanceCounter ());
626 // Dump FPDT Boot Performance record.
628 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - ResetEnd = %ld\n", mAcpiBootPerformanceTable
->BasicBoot
.ResetEnd
));
629 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - OsLoaderLoadImageStart = %ld\n", mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderLoadImageStart
));
630 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - OsLoaderStartImageStart = %ld\n", mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderStartImageStart
));
631 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - ExitBootServicesEntry = %ld\n", mAcpiBootPerformanceTable
->BasicBoot
.ExitBootServicesEntry
));
633 // ExitBootServicesExit will be updated later, so don't dump it here.
638 Report status code listener of FPDT. This is used to collect performance data
639 for OsLoaderLoadImageStart and OsLoaderStartImageStart in FPDT.
641 @param[in] CodeType Indicates the type of status code being reported.
642 @param[in] Value Describes the current status of a hardware or software entity.
643 This included information about the class and subclass that is used to
644 classify the entity as well as an operation.
645 @param[in] Instance The enumeration of a hardware or software entity within
646 the system. Valid instance numbers start with 1.
647 @param[in] CallerId This optional parameter may be used to identify the caller.
648 This parameter allows the status code driver to apply different rules to
650 @param[in] Data This optional parameter may be used to pass additional data.
652 @retval EFI_SUCCESS Status code is what we expected.
653 @retval EFI_UNSUPPORTED Status code not supported.
658 FpdtStatusCodeListenerDxe (
659 IN EFI_STATUS_CODE_TYPE CodeType
,
660 IN EFI_STATUS_CODE_VALUE Value
,
662 IN EFI_GUID
*CallerId
,
663 IN EFI_STATUS_CODE_DATA
*Data
669 // Check whether status code is what we are interested in.
671 if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) != EFI_PROGRESS_CODE
) {
672 return EFI_UNSUPPORTED
;
675 Status
= EFI_SUCCESS
;
676 if (Value
== PcdGet32 (PcdProgressCodeOsLoaderLoad
)) {
678 // Progress code for OS Loader LoadImage.
680 if (mAcpiBootPerformanceTable
== NULL
) {
685 // Update OS Loader LoadImage Start for UEFI boot.
687 mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderLoadImageStart
= GetTimeInNanoSecond (GetPerformanceCounter ());
688 } else if (Value
== PcdGet32 (PcdProgressCodeOsLoaderStart
)) {
690 // Progress code for OS Loader StartImage.
692 if (mAcpiBootPerformanceTable
== NULL
) {
697 // Update OS Loader StartImage Start for UEFI boot.
699 mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderStartImageStart
= GetTimeInNanoSecond (GetPerformanceCounter ());
700 } else if (Value
== (EFI_SOFTWARE_EFI_BOOT_SERVICE
| EFI_SW_BS_PC_EXIT_BOOT_SERVICES
)) {
702 // Progress code for ExitBootServices.
704 if (mAcpiBootPerformanceTable
== NULL
) {
709 // Update ExitBootServicesExit for UEFI boot.
711 mAcpiBootPerformanceTable
->BasicBoot
.ExitBootServicesExit
= GetTimeInNanoSecond (GetPerformanceCounter ());
714 // Unregister boot time report status code listener.
716 mRscHandlerProtocol
->Unregister (FpdtStatusCodeListenerDxe
);
717 } else if (Data
!= NULL
&& CompareGuid (&Data
->Type
, &gEfiFirmwarePerformanceGuid
)) {
719 // Append one or more Boot records
721 if (mAcpiBootPerformanceTable
== NULL
) {
723 // Append Boot records before FPDT ACPI table is installed.
725 if (mBootRecordSize
+ Data
->Size
> mBootRecordMaxSize
) {
726 mBootRecordBuffer
= ReallocatePool (mBootRecordSize
, mBootRecordSize
+ Data
->Size
+ EXTENSION_RECORD_SIZE
, mBootRecordBuffer
);
727 ASSERT (mBootRecordBuffer
!= NULL
);
728 mBootRecordMaxSize
= mBootRecordSize
+ Data
->Size
+ EXTENSION_RECORD_SIZE
;
731 // Save boot record into the temp memory space.
733 CopyMem (mBootRecordBuffer
+ mBootRecordSize
, Data
+ 1, Data
->Size
);
734 mBootRecordSize
+= Data
->Size
;
737 // Append Boot records after FPDT ACPI table is installed.
739 if (mBootRecordSize
+ Data
->Size
> mBootRecordMaxSize
) {
741 // No enough space to save boot record.
743 Status
= EFI_OUT_OF_RESOURCES
;
746 // Save boot record into BootPerformance table
748 CopyMem (mBootRecordBuffer
+ mBootRecordSize
, Data
+ 1, Data
->Size
);
749 mBootRecordSize
+= Data
->Size
;
750 mAcpiBootPerformanceTable
->Header
.Length
= mBootRecordSize
;
755 // Ignore else progress code.
757 Status
= EFI_UNSUPPORTED
;
764 The module Entry Point of the Firmware Performance Data Table DXE driver.
766 @param[in] ImageHandle The firmware allocated handle for the EFI image.
767 @param[in] SystemTable A pointer to the EFI System Table.
769 @retval EFI_SUCCESS The entry point is executed successfully.
770 @retval Other Some error occurs when executing this entry point.
775 FirmwarePerformanceDxeEntryPoint (
776 IN EFI_HANDLE ImageHandle
,
777 IN EFI_SYSTEM_TABLE
*SystemTable
781 EFI_HOB_GUID_TYPE
*GuidHob
;
782 FIRMWARE_SEC_PERFORMANCE
*Performance
;
786 // Get Report Status Code Handler Protocol.
788 Status
= gBS
->LocateProtocol (&gEfiRscHandlerProtocolGuid
, NULL
, (VOID
**) &mRscHandlerProtocol
);
789 ASSERT_EFI_ERROR (Status
);
792 // Register report status code listener for OS Loader load and start.
794 Status
= mRscHandlerProtocol
->Register (FpdtStatusCodeListenerDxe
, TPL_HIGH_LEVEL
);
795 ASSERT_EFI_ERROR (Status
);
798 // Register the notify function to update FPDT on ExitBootServices Event.
800 Status
= gBS
->CreateEventEx (
803 FpdtExitBootServicesEventNotify
,
805 &gEfiEventExitBootServicesGuid
,
806 &mExitBootServicesEvent
808 ASSERT_EFI_ERROR (Status
);
811 // Create ready to boot event to install ACPI FPDT table.
813 Status
= gBS
->CreateEventEx (
816 FpdtReadyToBootEventNotify
,
818 &gEfiEventReadyToBootGuid
,
821 ASSERT_EFI_ERROR (Status
);
824 // Create legacy boot event to log OsLoaderStartImageStart for legacy boot.
826 Status
= gBS
->CreateEventEx (
829 FpdtLegacyBootEventNotify
,
831 &gEfiEventLegacyBootGuid
,
834 ASSERT_EFI_ERROR (Status
);
837 // Retrieve GUID HOB data that contains the ResetEnd.
839 GuidHob
= GetFirstGuidHob (&gEfiFirmwarePerformanceGuid
);
840 if (GuidHob
!= NULL
) {
841 Performance
= (FIRMWARE_SEC_PERFORMANCE
*) GET_GUID_HOB_DATA (GuidHob
);
842 mBootPerformanceTableTemplate
.BasicBoot
.ResetEnd
= Performance
->ResetEnd
;
845 // SEC Performance Data Hob not found, ResetEnd in ACPI FPDT table will be 0.
847 DEBUG ((EFI_D_ERROR
, "FPDT: WARNING: SEC Performance Data Hob not found, ResetEnd will be set to 0!\n"));
850 if (FeaturePcdGet (PcdFirmwarePerformanceDataTableS3Support
)) {
852 // Register callback function upon VariableArchProtocol and LockBoxProtocol
853 // to allocate S3 performance table memory and save the pointer to LockBox.
855 EfiCreateProtocolNotifyEvent (
856 &gEfiVariableArchProtocolGuid
,
858 FpdtAllocateS3PerformanceTableMemory
,
862 EfiCreateProtocolNotifyEvent (
863 &gEfiLockBoxProtocolGuid
,
865 FpdtAllocateS3PerformanceTableMemory
,
871 // Exclude S3 Performance Table Pointer from FPDT table template.
873 mFirmwarePerformanceTableTemplate
.Header
.Length
-= sizeof (EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_POINTER_RECORD
);