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
= NULL
;
361 Status
= gBS
->LocateProtocol (&gEfiSmmCommunicationProtocolGuid
, NULL
, (VOID
**) &Communication
);
362 if (!EFI_ERROR (Status
)) {
364 // Initialize communicate buffer
366 SmmBootRecordCommBuffer
= AllocateZeroPool (SMM_BOOT_RECORD_COMM_SIZE
);
367 ASSERT (SmmBootRecordCommBuffer
!= NULL
);
368 SmmCommBufferHeader
= (EFI_SMM_COMMUNICATE_HEADER
*)SmmBootRecordCommBuffer
;
369 SmmCommData
= (SMM_BOOT_RECORD_COMMUNICATE
*)SmmCommBufferHeader
->Data
;
370 ZeroMem((UINT8
*)SmmCommData
, sizeof(SMM_BOOT_RECORD_COMMUNICATE
));
372 CopyGuid (&SmmCommBufferHeader
->HeaderGuid
, &gEfiFirmwarePerformanceGuid
);
373 SmmCommBufferHeader
->MessageLength
= sizeof(SMM_BOOT_RECORD_COMMUNICATE
);
374 CommSize
= SMM_BOOT_RECORD_COMM_SIZE
;
377 // Get the size of boot records.
379 SmmCommData
->Function
= SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE
;
380 SmmCommData
->BootRecordData
= NULL
;
381 Status
= Communication
->Communicate (Communication
, SmmBootRecordCommBuffer
, &CommSize
);
382 ASSERT_EFI_ERROR (Status
);
384 if (!EFI_ERROR (SmmCommData
->ReturnStatus
) && SmmCommData
->BootRecordSize
!= 0) {
386 // Get all boot records
388 SmmCommData
->Function
= SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA
;
389 SmmCommData
->BootRecordData
= AllocateZeroPool(SmmCommData
->BootRecordSize
);
390 ASSERT (SmmCommData
->BootRecordData
!= NULL
);
392 Status
= Communication
->Communicate (Communication
, SmmBootRecordCommBuffer
, &CommSize
);
393 ASSERT_EFI_ERROR (Status
);
394 ASSERT_EFI_ERROR(SmmCommData
->ReturnStatus
);
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 (SmmBootRecordCommBuffer
!= NULL
) {
444 FreePool (SmmBootRecordCommBuffer
);
446 if (mAcpiS3PerformanceTable
!= NULL
) {
447 FreePages (mAcpiS3PerformanceTable
, EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE
)));
449 return EFI_OUT_OF_RESOURCES
;
453 // Prepare Boot Performance Table.
455 BootPerformanceData
= (UINT8
*) mAcpiBootPerformanceTable
;
457 // Fill Basic Boot record to Boot Performance Table.
459 CopyMem (mAcpiBootPerformanceTable
, &mBootPerformanceTableTemplate
, sizeof (mBootPerformanceTableTemplate
));
460 BootPerformanceData
= BootPerformanceData
+ mAcpiBootPerformanceTable
->Header
.Length
;
462 // Fill Boot records from boot drivers.
464 CopyMem (BootPerformanceData
, mBootRecordBuffer
, mBootRecordSize
);
465 mAcpiBootPerformanceTable
->Header
.Length
+= mBootRecordSize
;
466 BootPerformanceData
= BootPerformanceData
+ mBootRecordSize
;
467 if (SmmCommData
!= NULL
&& SmmCommData
->BootRecordData
!= NULL
) {
469 // Fill Boot records from SMM drivers.
471 CopyMem (BootPerformanceData
, SmmCommData
->BootRecordData
, SmmCommData
->BootRecordSize
);
472 FreePool (SmmCommData
->BootRecordData
);
473 mAcpiBootPerformanceTable
->Header
.Length
= (UINT32
) (mAcpiBootPerformanceTable
->Header
.Length
+ SmmCommData
->BootRecordSize
);
474 BootPerformanceData
= BootPerformanceData
+ SmmCommData
->BootRecordSize
;
476 if (SmmBootRecordCommBuffer
!= NULL
) {
477 FreePool (SmmBootRecordCommBuffer
);
481 // Save Boot Performance Table address to Variable for use in S4 resume.
483 PerformanceVariable
.BootPerformanceTablePointer
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) mAcpiBootPerformanceTable
;
485 // Update Boot Performance Table Pointer in template.
487 mFirmwarePerformanceTableTemplate
.BootPointerRecord
.BootPerformanceTablePointer
= (UINT64
) (UINTN
) mAcpiBootPerformanceTable
;
490 // Save S3 Performance Table address to Variable for use in S4 resume.
492 PerformanceVariable
.S3PerformanceTablePointer
= (EFI_PHYSICAL_ADDRESS
) (UINTN
) mAcpiS3PerformanceTable
;
494 // Update S3 Performance Table Pointer in template.
496 mFirmwarePerformanceTableTemplate
.S3PointerRecord
.S3PerformanceTablePointer
= (UINT64
) (UINTN
) mAcpiS3PerformanceTable
;
498 // Save Runtime Performance Table pointers to Variable.
500 Status
= gRT
->SetVariable (
501 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME
,
502 &gEfiFirmwarePerformanceGuid
,
503 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
504 sizeof (PerformanceVariable
),
507 ASSERT_EFI_ERROR (Status
);
510 // Publish Firmware Performance Data Table.
512 FpdtAcpiTableChecksum ((UINT8
*) &mFirmwarePerformanceTableTemplate
, mFirmwarePerformanceTableTemplate
.Header
.Length
);
513 Status
= AcpiTableProtocol
->InstallAcpiTable (
515 &mFirmwarePerformanceTableTemplate
,
516 mFirmwarePerformanceTableTemplate
.Header
.Length
,
517 &mFirmwarePerformanceTableTemplateKey
519 if (EFI_ERROR (Status
)) {
520 FreePages (mAcpiBootPerformanceTable
, EFI_SIZE_TO_PAGES (BootPerformanceDataSize
));
521 if (mAcpiS3PerformanceTable
!= NULL
) {
522 FreePages (mAcpiS3PerformanceTable
, EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE
)));
524 mAcpiBootPerformanceTable
= NULL
;
525 mAcpiS3PerformanceTable
= NULL
;
530 // Free temp Boot record, and update Boot Record to point to Basic Boot performance table.
532 if (mBootRecordBuffer
!= NULL
) {
533 FreePool (mBootRecordBuffer
);
535 mBootRecordBuffer
= (UINT8
*) mAcpiBootPerformanceTable
;
536 mBootRecordSize
= mAcpiBootPerformanceTable
->Header
.Length
;
537 mBootRecordMaxSize
= mBootRecordSize
+ PcdGet32 (PcdExtFpdtBootRecordPadSize
);
543 Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT. This is used to
544 install the Firmware Performance Data Table.
546 @param[in] Event The Event that is being processed.
547 @param[in] Context The Event Context.
552 FpdtReadyToBootEventNotify (
557 if (mAcpiBootPerformanceTable
== NULL
) {
559 // ACPI Firmware Performance Data Table not installed yet, install it now.
561 InstallFirmwarePerformanceDataTable ();
566 Notify function for event group EFI_EVENT_LEGACY_BOOT_GUID. This is used to
567 record performance data for OsLoaderLoadImageStart in FPDT for legacy boot.
569 @param[in] Event The Event that is being processed.
570 @param[in] Context The Event Context.
575 FpdtLegacyBootEventNotify (
580 if (mAcpiBootPerformanceTable
== NULL
) {
582 // Firmware Performance Data Table not installed, do nothing.
588 // Update Firmware Basic Boot Performance Record for legacy boot.
590 mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderLoadImageStart
= 0;
591 mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderStartImageStart
= GetTimeInNanoSecond (GetPerformanceCounter ());
592 mAcpiBootPerformanceTable
->BasicBoot
.ExitBootServicesEntry
= 0;
593 mAcpiBootPerformanceTable
->BasicBoot
.ExitBootServicesExit
= 0;
596 // Dump FPDT Boot Performance record.
598 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - ResetEnd = %ld\n", mAcpiBootPerformanceTable
->BasicBoot
.ResetEnd
));
599 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - OsLoaderLoadImageStart = 0\n"));
600 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - OsLoaderStartImageStart = %ld\n", mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderStartImageStart
));
601 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - ExitBootServicesEntry = 0\n"));
602 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - ExitBootServicesExit = 0\n"));
606 Notify function for event EVT_SIGNAL_EXIT_BOOT_SERVICES. This is used to record
607 performance data for ExitBootServicesEntry in FPDT.
609 @param[in] Event The Event that is being processed.
610 @param[in] Context The Event Context.
615 FpdtExitBootServicesEventNotify (
620 if (mAcpiBootPerformanceTable
== NULL
) {
622 // Firmware Performance Data Table not installed, do nothing.
628 // Update Firmware Basic Boot Performance Record for UEFI boot.
630 mAcpiBootPerformanceTable
->BasicBoot
.ExitBootServicesEntry
= GetTimeInNanoSecond (GetPerformanceCounter ());
633 // Dump FPDT Boot Performance record.
635 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - ResetEnd = %ld\n", mAcpiBootPerformanceTable
->BasicBoot
.ResetEnd
));
636 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - OsLoaderLoadImageStart = %ld\n", mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderLoadImageStart
));
637 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - OsLoaderStartImageStart = %ld\n", mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderStartImageStart
));
638 DEBUG ((EFI_D_INFO
, "FPDT: Boot Performance - ExitBootServicesEntry = %ld\n", mAcpiBootPerformanceTable
->BasicBoot
.ExitBootServicesEntry
));
640 // ExitBootServicesExit will be updated later, so don't dump it here.
645 Report status code listener of FPDT. This is used to collect performance data
646 for OsLoaderLoadImageStart and OsLoaderStartImageStart in FPDT.
648 @param[in] CodeType Indicates the type of status code being reported.
649 @param[in] Value Describes the current status of a hardware or software entity.
650 This included information about the class and subclass that is used to
651 classify the entity as well as an operation.
652 @param[in] Instance The enumeration of a hardware or software entity within
653 the system. Valid instance numbers start with 1.
654 @param[in] CallerId This optional parameter may be used to identify the caller.
655 This parameter allows the status code driver to apply different rules to
657 @param[in] Data This optional parameter may be used to pass additional data.
659 @retval EFI_SUCCESS Status code is what we expected.
660 @retval EFI_UNSUPPORTED Status code not supported.
665 FpdtStatusCodeListenerDxe (
666 IN EFI_STATUS_CODE_TYPE CodeType
,
667 IN EFI_STATUS_CODE_VALUE Value
,
669 IN EFI_GUID
*CallerId
,
670 IN EFI_STATUS_CODE_DATA
*Data
676 // Check whether status code is what we are interested in.
678 if ((CodeType
& EFI_STATUS_CODE_TYPE_MASK
) != EFI_PROGRESS_CODE
) {
679 return EFI_UNSUPPORTED
;
682 Status
= EFI_SUCCESS
;
683 if (Value
== PcdGet32 (PcdProgressCodeOsLoaderLoad
)) {
685 // Progress code for OS Loader LoadImage.
687 if (mAcpiBootPerformanceTable
== NULL
) {
692 // Update OS Loader LoadImage Start for UEFI boot.
694 mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderLoadImageStart
= GetTimeInNanoSecond (GetPerformanceCounter ());
695 } else if (Value
== PcdGet32 (PcdProgressCodeOsLoaderStart
)) {
697 // Progress code for OS Loader StartImage.
699 if (mAcpiBootPerformanceTable
== NULL
) {
704 // Update OS Loader StartImage Start for UEFI boot.
706 mAcpiBootPerformanceTable
->BasicBoot
.OsLoaderStartImageStart
= GetTimeInNanoSecond (GetPerformanceCounter ());
707 } else if (Value
== (EFI_SOFTWARE_EFI_BOOT_SERVICE
| EFI_SW_BS_PC_EXIT_BOOT_SERVICES
)) {
709 // Progress code for ExitBootServices.
711 if (mAcpiBootPerformanceTable
== NULL
) {
716 // Update ExitBootServicesExit for UEFI boot.
718 mAcpiBootPerformanceTable
->BasicBoot
.ExitBootServicesExit
= GetTimeInNanoSecond (GetPerformanceCounter ());
721 // Unregister boot time report status code listener.
723 mRscHandlerProtocol
->Unregister (FpdtStatusCodeListenerDxe
);
724 } else if (Data
!= NULL
&& CompareGuid (&Data
->Type
, &gEfiFirmwarePerformanceGuid
)) {
726 // Append one or more Boot records
728 if (mAcpiBootPerformanceTable
== NULL
) {
730 // Append Boot records before FPDT ACPI table is installed.
732 if (mBootRecordSize
+ Data
->Size
> mBootRecordMaxSize
) {
733 mBootRecordBuffer
= ReallocatePool (mBootRecordSize
, mBootRecordSize
+ Data
->Size
+ EXTENSION_RECORD_SIZE
, mBootRecordBuffer
);
734 ASSERT (mBootRecordBuffer
!= NULL
);
735 mBootRecordMaxSize
= mBootRecordSize
+ Data
->Size
+ EXTENSION_RECORD_SIZE
;
738 // Save boot record into the temp memory space.
740 CopyMem (mBootRecordBuffer
+ mBootRecordSize
, Data
+ 1, Data
->Size
);
741 mBootRecordSize
+= Data
->Size
;
744 // Append Boot records after FPDT ACPI table is installed.
746 if (mBootRecordSize
+ Data
->Size
> mBootRecordMaxSize
) {
748 // No enough space to save boot record.
750 Status
= EFI_OUT_OF_RESOURCES
;
753 // Save boot record into BootPerformance table
755 CopyMem (mBootRecordBuffer
+ mBootRecordSize
, Data
+ 1, Data
->Size
);
756 mBootRecordSize
+= Data
->Size
;
757 mAcpiBootPerformanceTable
->Header
.Length
= mBootRecordSize
;
762 // Ignore else progress code.
764 Status
= EFI_UNSUPPORTED
;
771 The module Entry Point of the Firmware Performance Data Table DXE driver.
773 @param[in] ImageHandle The firmware allocated handle for the EFI image.
774 @param[in] SystemTable A pointer to the EFI System Table.
776 @retval EFI_SUCCESS The entry point is executed successfully.
777 @retval Other Some error occurs when executing this entry point.
782 FirmwarePerformanceDxeEntryPoint (
783 IN EFI_HANDLE ImageHandle
,
784 IN EFI_SYSTEM_TABLE
*SystemTable
788 EFI_HOB_GUID_TYPE
*GuidHob
;
789 FIRMWARE_SEC_PERFORMANCE
*Performance
;
793 // Get Report Status Code Handler Protocol.
795 Status
= gBS
->LocateProtocol (&gEfiRscHandlerProtocolGuid
, NULL
, (VOID
**) &mRscHandlerProtocol
);
796 ASSERT_EFI_ERROR (Status
);
799 // Register report status code listener for OS Loader load and start.
801 Status
= mRscHandlerProtocol
->Register (FpdtStatusCodeListenerDxe
, TPL_HIGH_LEVEL
);
802 ASSERT_EFI_ERROR (Status
);
805 // Register the notify function to update FPDT on ExitBootServices Event.
807 Status
= gBS
->CreateEventEx (
810 FpdtExitBootServicesEventNotify
,
812 &gEfiEventExitBootServicesGuid
,
813 &mExitBootServicesEvent
815 ASSERT_EFI_ERROR (Status
);
818 // Create ready to boot event to install ACPI FPDT table.
820 Status
= gBS
->CreateEventEx (
823 FpdtReadyToBootEventNotify
,
825 &gEfiEventReadyToBootGuid
,
828 ASSERT_EFI_ERROR (Status
);
831 // Create legacy boot event to log OsLoaderStartImageStart for legacy boot.
833 Status
= gBS
->CreateEventEx (
836 FpdtLegacyBootEventNotify
,
838 &gEfiEventLegacyBootGuid
,
841 ASSERT_EFI_ERROR (Status
);
844 // Retrieve GUID HOB data that contains the ResetEnd.
846 GuidHob
= GetFirstGuidHob (&gEfiFirmwarePerformanceGuid
);
847 if (GuidHob
!= NULL
) {
848 Performance
= (FIRMWARE_SEC_PERFORMANCE
*) GET_GUID_HOB_DATA (GuidHob
);
849 mBootPerformanceTableTemplate
.BasicBoot
.ResetEnd
= Performance
->ResetEnd
;
852 // SEC Performance Data Hob not found, ResetEnd in ACPI FPDT table will be 0.
854 DEBUG ((EFI_D_ERROR
, "FPDT: WARNING: SEC Performance Data Hob not found, ResetEnd will be set to 0!\n"));
857 if (FeaturePcdGet (PcdFirmwarePerformanceDataTableS3Support
)) {
859 // Register callback function upon VariableArchProtocol and LockBoxProtocol
860 // to allocate S3 performance table memory and save the pointer to LockBox.
862 EfiCreateProtocolNotifyEvent (
863 &gEfiVariableArchProtocolGuid
,
865 FpdtAllocateS3PerformanceTableMemory
,
869 EfiCreateProtocolNotifyEvent (
870 &gEfiLockBoxProtocolGuid
,
872 FpdtAllocateS3PerformanceTableMemory
,
878 // Exclude S3 Performance Table Pointer from FPDT table template.
880 mFirmwarePerformanceTableTemplate
.Header
.Length
-= sizeof (EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_POINTER_RECORD
);