]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.c
3d8e83250e658c4dea8e4f507e9a4923cea8cc3e
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / FirmwarePerformanceDataTableDxe / FirmwarePerformanceDxe.c
1 /** @file
2 This module install ACPI Firmware Performance Data Table (FPDT).
3
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.
7
8 Copyright (c) 2011 - 2018, 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
13
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.
16
17 **/
18
19 #include <PiDxe.h>
20
21 #include <Protocol/ReportStatusCodeHandler.h>
22 #include <Protocol/AcpiTable.h>
23 #include <Protocol/LockBox.h>
24 #include <Protocol/Variable.h>
25
26 #include <Guid/Acpi.h>
27 #include <Guid/FirmwarePerformance.h>
28 #include <Guid/EventGroup.h>
29 #include <Guid/EventLegacyBios.h>
30
31 #include <Library/UefiBootServicesTableLib.h>
32 #include <Library/UefiRuntimeServicesTableLib.h>
33 #include <Library/BaseLib.h>
34 #include <Library/DebugLib.h>
35 #include <Library/DxeServicesLib.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>
43
44 #define SMM_BOOT_RECORD_COMM_SIZE (OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(SMM_BOOT_RECORD_COMMUNICATE))
45
46 EFI_RSC_HANDLER_PROTOCOL *mRscHandlerProtocol = NULL;
47
48 BOOLEAN mLockBoxReady = FALSE;
49 EFI_EVENT mReadyToBootEvent;
50 EFI_EVENT mLegacyBootEvent;
51 EFI_EVENT mExitBootServicesEvent;
52 UINTN mFirmwarePerformanceTableTemplateKey = 0;
53 BOOLEAN mDxeCoreReportStatusCodeEnable = FALSE;
54
55 BOOT_PERFORMANCE_TABLE *mAcpiBootPerformanceTable = NULL;
56 BOOT_PERFORMANCE_TABLE *mReceivedAcpiBootPerformanceTable = NULL;
57 S3_PERFORMANCE_TABLE *mAcpiS3PerformanceTable = NULL;
58
59 FIRMWARE_PERFORMANCE_TABLE mFirmwarePerformanceTableTemplate = {
60 {
61 EFI_ACPI_5_0_FIRMWARE_PERFORMANCE_DATA_TABLE_SIGNATURE,
62 sizeof (FIRMWARE_PERFORMANCE_TABLE),
63 EFI_ACPI_5_0_FIRMWARE_PERFORMANCE_DATA_TABLE_REVISION, // Revision
64 0x00, // Checksum will be updated at runtime
65 //
66 // It is expected that these values will be updated at EntryPoint.
67 //
68 {0x00}, // OEM ID is a 6 bytes long field
69 0x00, // OEM Table ID(8 bytes long)
70 0x00, // OEM Revision
71 0x00, // Creator ID
72 0x00, // Creator Revision
73 },
74 //
75 // Firmware Basic Boot Performance Table Pointer Record.
76 //
77 {
78 {
79 EFI_ACPI_5_0_FPDT_RECORD_TYPE_FIRMWARE_BASIC_BOOT_POINTER , // Type
80 sizeof (EFI_ACPI_5_0_FPDT_BOOT_PERFORMANCE_TABLE_POINTER_RECORD), // Length
81 EFI_ACPI_5_0_FPDT_RECORD_REVISION_FIRMWARE_BASIC_BOOT_POINTER // Revision
82 },
83 0, // Reserved
84 0 // BootPerformanceTablePointer will be updated at runtime.
85 },
86 //
87 // S3 Performance Table Pointer Record.
88 //
89 {
90 {
91 EFI_ACPI_5_0_FPDT_RECORD_TYPE_S3_PERFORMANCE_TABLE_POINTER, // Type
92 sizeof (EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_POINTER_RECORD), // Length
93 EFI_ACPI_5_0_FPDT_RECORD_REVISION_S3_PERFORMANCE_TABLE_POINTER // Revision
94 },
95 0, // Reserved
96 0 // S3PerformanceTablePointer will be updated at runtime.
97 }
98 };
99
100 BOOT_PERFORMANCE_TABLE mBootPerformanceTableTemplate = {
101 {
102 EFI_ACPI_5_0_FPDT_BOOT_PERFORMANCE_TABLE_SIGNATURE,
103 sizeof (BOOT_PERFORMANCE_TABLE)
104 },
105 {
106 {
107 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_FIRMWARE_BASIC_BOOT, // Type
108 sizeof (EFI_ACPI_5_0_FPDT_FIRMWARE_BASIC_BOOT_RECORD), // Length
109 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_FIRMWARE_BASIC_BOOT // Revision
110 },
111 0, // Reserved
112 //
113 // These values will be updated at runtime.
114 //
115 0, // ResetEnd
116 0, // OsLoaderLoadImageStart
117 0, // OsLoaderStartImageStart
118 0, // ExitBootServicesEntry
119 0 // ExitBootServicesExit
120 }
121 };
122
123 S3_PERFORMANCE_TABLE mS3PerformanceTableTemplate = {
124 {
125 EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_SIGNATURE,
126 sizeof (S3_PERFORMANCE_TABLE)
127 },
128 {
129 {
130 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_S3_RESUME, // Type
131 sizeof (EFI_ACPI_5_0_FPDT_S3_RESUME_RECORD), // Length
132 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_S3_RESUME // Revision
133 },
134 //
135 // These values will be updated by Firmware Performance PEIM.
136 //
137 0, // ResumeCount
138 0, // FullResume
139 0 // AverageResume
140 },
141 {
142 {
143 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_TYPE_S3_SUSPEND, // Type
144 sizeof (EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD), // Length
145 EFI_ACPI_5_0_FPDT_RUNTIME_RECORD_REVISION_S3_SUSPEND // Revision
146 },
147 //
148 // These values will be updated bye Firmware Performance SMM driver.
149 //
150 0, // SuspendStart
151 0 // SuspendEnd
152 }
153 };
154
155 /**
156 This function calculates and updates an UINT8 checksum.
157
158 @param[in] Buffer Pointer to buffer to checksum
159 @param[in] Size Number of bytes to checksum
160
161 **/
162 VOID
163 FpdtAcpiTableChecksum (
164 IN UINT8 *Buffer,
165 IN UINTN Size
166 )
167 {
168 UINTN ChecksumOffset;
169
170 ChecksumOffset = OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum);
171
172 //
173 // Set checksum to 0 first.
174 //
175 Buffer[ChecksumOffset] = 0;
176
177 //
178 // Update checksum value.
179 //
180 Buffer[ChecksumOffset] = CalculateCheckSum8 (Buffer, Size);
181 }
182
183 /**
184 Callback function upon VariableArchProtocol and LockBoxProtocol
185 to allocate S3 performance table memory and save the pointer to LockBox.
186
187 @param[in] Event Event whose notification function is being invoked.
188 @param[in] Context Pointer to the notification function's context.
189 **/
190 VOID
191 EFIAPI
192 FpdtAllocateS3PerformanceTableMemory (
193 IN EFI_EVENT Event,
194 IN VOID *Context
195 )
196 {
197 EFI_STATUS Status;
198 VOID *Interface;
199 FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable;
200 UINTN Size;
201 EFI_PHYSICAL_ADDRESS S3PerformanceTablePointer;
202
203 if (mLockBoxReady && (mAcpiS3PerformanceTable != NULL)) {
204 //
205 // The memory for S3 performance table should have been ready,
206 // and the pointer should have been saved to LockBox, just return.
207 //
208 return;
209 }
210
211 if (!mLockBoxReady) {
212 Status = gBS->LocateProtocol (&gEfiLockBoxProtocolGuid, NULL, &Interface);
213 if (!EFI_ERROR (Status)) {
214 //
215 // LockBox services has been ready.
216 //
217 mLockBoxReady = TRUE;
218 }
219 }
220
221 if (mAcpiS3PerformanceTable == NULL) {
222 Status = gBS->LocateProtocol (&gEfiVariableArchProtocolGuid, NULL, &Interface);
223 if (!EFI_ERROR (Status)) {
224 //
225 // Try to allocate the same runtime buffer as last time boot.
226 //
227 ZeroMem (&PerformanceVariable, sizeof (PerformanceVariable));
228 Size = sizeof (PerformanceVariable);
229 Status = gRT->GetVariable (
230 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,
231 &gEfiFirmwarePerformanceGuid,
232 NULL,
233 &Size,
234 &PerformanceVariable
235 );
236 if (!EFI_ERROR (Status)) {
237 Status = gBS->AllocatePages (
238 AllocateAddress,
239 EfiReservedMemoryType,
240 EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE)),
241 &PerformanceVariable.S3PerformanceTablePointer
242 );
243 if (!EFI_ERROR (Status)) {
244 mAcpiS3PerformanceTable = (S3_PERFORMANCE_TABLE *) (UINTN) PerformanceVariable.S3PerformanceTablePointer;
245 }
246 }
247 if (mAcpiS3PerformanceTable == NULL) {
248 //
249 // Fail to allocate at specified address, continue to allocate at any address.
250 //
251 mAcpiS3PerformanceTable = (S3_PERFORMANCE_TABLE *) AllocatePeiAccessiblePages (
252 EfiReservedMemoryType,
253 EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE))
254 );
255 }
256 DEBUG ((EFI_D_INFO, "FPDT: ACPI S3 Performance Table address = 0x%x\n", mAcpiS3PerformanceTable));
257 if (mAcpiS3PerformanceTable != NULL) {
258 CopyMem (mAcpiS3PerformanceTable, &mS3PerformanceTableTemplate, sizeof (mS3PerformanceTableTemplate));
259 }
260 }
261 }
262
263 if (mLockBoxReady && (mAcpiS3PerformanceTable != NULL)) {
264 //
265 // If LockBox services has been ready and memory for FPDT S3 performance table has been allocated,
266 // save the pointer to LockBox for use in S3 resume.
267 //
268 S3PerformanceTablePointer = (EFI_PHYSICAL_ADDRESS) (UINTN) mAcpiS3PerformanceTable;
269 Status = SaveLockBox (
270 &gFirmwarePerformanceS3PointerGuid,
271 &S3PerformanceTablePointer,
272 sizeof (EFI_PHYSICAL_ADDRESS)
273 );
274 ASSERT_EFI_ERROR (Status);
275 }
276 }
277
278 /**
279 Install ACPI Firmware Performance Data Table (FPDT).
280
281 @return Status code.
282
283 **/
284 EFI_STATUS
285 InstallFirmwarePerformanceDataTable (
286 VOID
287 )
288 {
289 EFI_STATUS Status;
290 EFI_ACPI_TABLE_PROTOCOL *AcpiTableProtocol;
291 UINTN BootPerformanceDataSize;
292 FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable;
293 UINTN Size;
294
295 //
296 // Get AcpiTable Protocol.
297 //
298 Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID **) &AcpiTableProtocol);
299 if (EFI_ERROR (Status)) {
300 return Status;
301 }
302
303 if (mReceivedAcpiBootPerformanceTable != NULL) {
304 mAcpiBootPerformanceTable = mReceivedAcpiBootPerformanceTable;
305 mAcpiBootPerformanceTable->BasicBoot.ResetEnd = mBootPerformanceTableTemplate.BasicBoot.ResetEnd;
306 } else {
307 //
308 // Try to allocate the same runtime buffer as last time boot.
309 //
310 BootPerformanceDataSize = sizeof (BOOT_PERFORMANCE_TABLE);
311 ZeroMem (&PerformanceVariable, sizeof (PerformanceVariable));
312 Size = sizeof (PerformanceVariable);
313 Status = gRT->GetVariable (
314 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,
315 &gEfiFirmwarePerformanceGuid,
316 NULL,
317 &Size,
318 &PerformanceVariable
319 );
320 if (!EFI_ERROR (Status)) {
321 Status = gBS->AllocatePages (
322 AllocateAddress,
323 EfiReservedMemoryType,
324 EFI_SIZE_TO_PAGES (BootPerformanceDataSize),
325 &PerformanceVariable.BootPerformanceTablePointer
326 );
327 if (!EFI_ERROR (Status)) {
328 mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) (UINTN) PerformanceVariable.BootPerformanceTablePointer;
329 }
330 }
331 if (mAcpiBootPerformanceTable == NULL) {
332 //
333 // Fail to allocate at specified address, continue to allocate at any address.
334 //
335 mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) AllocatePeiAccessiblePages (
336 EfiReservedMemoryType,
337 EFI_SIZE_TO_PAGES (BootPerformanceDataSize)
338 );
339 }
340 DEBUG ((DEBUG_INFO, "FPDT: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable));
341 if (mAcpiBootPerformanceTable == NULL) {
342 return EFI_OUT_OF_RESOURCES;
343 }
344 //
345 // Fill Basic Boot record to Boot Performance Table.
346 //
347 CopyMem (mAcpiBootPerformanceTable, &mBootPerformanceTableTemplate, sizeof (mBootPerformanceTableTemplate));
348 }
349 BootPerformanceDataSize = mAcpiBootPerformanceTable->Header.Length;
350
351 //
352 // Save Boot Performance Table address to Variable for use in S4 resume.
353 //
354 PerformanceVariable.BootPerformanceTablePointer = (EFI_PHYSICAL_ADDRESS) (UINTN) mAcpiBootPerformanceTable;
355 //
356 // Update Boot Performance Table Pointer in template.
357 //
358 mFirmwarePerformanceTableTemplate.BootPointerRecord.BootPerformanceTablePointer = (UINT64) (UINTN) mAcpiBootPerformanceTable;
359
360 //
361 // Save S3 Performance Table address to Variable for use in S4 resume.
362 //
363 PerformanceVariable.S3PerformanceTablePointer = (EFI_PHYSICAL_ADDRESS) (UINTN) mAcpiS3PerformanceTable;
364 //
365 // Update S3 Performance Table Pointer in template.
366 //
367 mFirmwarePerformanceTableTemplate.S3PointerRecord.S3PerformanceTablePointer = (UINT64) (UINTN) mAcpiS3PerformanceTable;
368 //
369 // Save Runtime Performance Table pointers to Variable.
370 // Don't check SetVariable return status. It doesn't impact FPDT table generation.
371 //
372 gRT->SetVariable (
373 EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,
374 &gEfiFirmwarePerformanceGuid,
375 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
376 sizeof (PerformanceVariable),
377 &PerformanceVariable
378 );
379
380 //
381 // Publish Firmware Performance Data Table.
382 //
383 FpdtAcpiTableChecksum ((UINT8 *) &mFirmwarePerformanceTableTemplate, mFirmwarePerformanceTableTemplate.Header.Length);
384 Status = AcpiTableProtocol->InstallAcpiTable (
385 AcpiTableProtocol,
386 &mFirmwarePerformanceTableTemplate,
387 mFirmwarePerformanceTableTemplate.Header.Length,
388 &mFirmwarePerformanceTableTemplateKey
389 );
390 if (EFI_ERROR (Status)) {
391 if (mAcpiBootPerformanceTable != NULL) {
392 FreePages (mAcpiBootPerformanceTable, EFI_SIZE_TO_PAGES (BootPerformanceDataSize));
393 }
394 if (mAcpiS3PerformanceTable != NULL) {
395 FreePages (mAcpiS3PerformanceTable, EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE)));
396 }
397 mAcpiBootPerformanceTable = NULL;
398 mAcpiS3PerformanceTable = NULL;
399 return Status;
400 }
401 return EFI_SUCCESS;
402 }
403
404 /**
405 Report status code listener of FPDT. This is used to collect performance data
406 for OsLoaderLoadImageStart and OsLoaderStartImageStart in FPDT.
407
408 @param[in] CodeType Indicates the type of status code being reported.
409 @param[in] Value Describes the current status of a hardware or software entity.
410 This included information about the class and subclass that is used to
411 classify the entity as well as an operation.
412 @param[in] Instance The enumeration of a hardware or software entity within
413 the system. Valid instance numbers start with 1.
414 @param[in] CallerId This optional parameter may be used to identify the caller.
415 This parameter allows the status code driver to apply different rules to
416 different callers.
417 @param[in] Data This optional parameter may be used to pass additional data.
418
419 @retval EFI_SUCCESS Status code is what we expected.
420 @retval EFI_UNSUPPORTED Status code not supported.
421
422 **/
423 EFI_STATUS
424 EFIAPI
425 FpdtStatusCodeListenerDxe (
426 IN EFI_STATUS_CODE_TYPE CodeType,
427 IN EFI_STATUS_CODE_VALUE Value,
428 IN UINT32 Instance,
429 IN EFI_GUID *CallerId,
430 IN EFI_STATUS_CODE_DATA *Data
431 )
432 {
433 EFI_STATUS Status;
434
435 //
436 // Check whether status code is what we are interested in.
437 //
438 if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) != EFI_PROGRESS_CODE) {
439 return EFI_UNSUPPORTED;
440 }
441
442 if (Value == (EFI_SOFTWARE_DXE_CORE | EFI_SW_DXE_CORE_PC_HANDOFF_TO_NEXT)) {
443 //
444 // DxeCore ReportStatusCode Enable so that the capability can be supported.
445 //
446 mDxeCoreReportStatusCodeEnable = TRUE;
447 }
448
449 Status = EFI_SUCCESS;
450 if (Value == PcdGet32 (PcdProgressCodeOsLoaderLoad)) {
451 //
452 // Progress code for OS Loader LoadImage.
453 //
454 if (mAcpiBootPerformanceTable == NULL) {
455 return Status;
456 }
457
458 //
459 // Update OS Loader LoadImage Start for UEFI boot.
460 //
461 mAcpiBootPerformanceTable->BasicBoot.OsLoaderLoadImageStart = GetTimeInNanoSecond (GetPerformanceCounter ());
462 } else if (Value == PcdGet32 (PcdProgressCodeOsLoaderStart)) {
463 //
464 // Progress code for OS Loader StartImage.
465 //
466 if (mAcpiBootPerformanceTable == NULL) {
467 return Status;
468 }
469
470 //
471 // Update OS Loader StartImage Start for UEFI boot.
472 //
473 mAcpiBootPerformanceTable->BasicBoot.OsLoaderStartImageStart = GetTimeInNanoSecond (GetPerformanceCounter ());
474 } else if (Value == (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES)) {
475 //
476 // Unregister boot time report status code listener.
477 //
478 mRscHandlerProtocol->Unregister (FpdtStatusCodeListenerDxe);
479
480 //
481 // Progress code for ExitBootServices.
482 //
483 if (mAcpiBootPerformanceTable == NULL) {
484 return Status;
485 }
486
487 //
488 // Update ExitBootServicesExit for UEFI boot.
489 //
490 mAcpiBootPerformanceTable->BasicBoot.ExitBootServicesExit = GetTimeInNanoSecond (GetPerformanceCounter ());
491 } else if (Value == (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_LEGACY_BOOT_EVENT)) {
492 if (mAcpiBootPerformanceTable == NULL) {
493 //
494 // Firmware Performance Data Table not installed, do nothing.
495 //
496 return Status;
497 }
498
499 //
500 // Update Firmware Basic Boot Performance Record for legacy boot.
501 //
502 mAcpiBootPerformanceTable->BasicBoot.OsLoaderStartImageStart = GetTimeInNanoSecond (GetPerformanceCounter ());
503
504 //
505 // Dump FPDT Boot Performance record.
506 //
507 DEBUG ((EFI_D_INFO, "FPDT: Boot Performance - ResetEnd = %ld\n", mAcpiBootPerformanceTable->BasicBoot.ResetEnd));
508 DEBUG ((EFI_D_INFO, "FPDT: Boot Performance - OsLoaderLoadImageStart = 0\n"));
509 DEBUG ((EFI_D_INFO, "FPDT: Boot Performance - OsLoaderStartImageStart = %ld\n", mAcpiBootPerformanceTable->BasicBoot.OsLoaderStartImageStart));
510 DEBUG ((EFI_D_INFO, "FPDT: Boot Performance - ExitBootServicesEntry = 0\n"));
511 DEBUG ((EFI_D_INFO, "FPDT: Boot Performance - ExitBootServicesExit = 0\n"));
512 } else if (Value == (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT)) {
513 if (mAcpiBootPerformanceTable == NULL) {
514 //
515 // ACPI Firmware Performance Data Table not installed yet, install it now.
516 //
517 InstallFirmwarePerformanceDataTable ();
518 }
519 } else if (Data != NULL && CompareGuid (&Data->Type, &gEdkiiFpdtExtendedFirmwarePerformanceGuid)) {
520 //
521 // Get the Boot performance table and then install it to ACPI table.
522 //
523 CopyMem (&mReceivedAcpiBootPerformanceTable, Data + 1, Data->Size);
524 } else if (Data != NULL && CompareGuid (&Data->Type, &gEfiFirmwarePerformanceGuid)) {
525 DEBUG ((DEBUG_ERROR, "FpdtStatusCodeListenerDxe: Performance data reported through gEfiFirmwarePerformanceGuid will not be collected by FirmwarePerformanceDataTableDxe\n"));
526 Status = EFI_UNSUPPORTED;
527 } else {
528 //
529 // Ignore else progress code.
530 //
531 Status = EFI_UNSUPPORTED;
532 }
533
534 return Status;
535 }
536
537
538 /**
539 Notify function for event EVT_SIGNAL_EXIT_BOOT_SERVICES. This is used to record
540 performance data for ExitBootServicesEntry in FPDT.
541
542 @param[in] Event The Event that is being processed.
543 @param[in] Context The Event Context.
544
545 **/
546 VOID
547 EFIAPI
548 FpdtExitBootServicesEventNotify (
549 IN EFI_EVENT Event,
550 IN VOID *Context
551 )
552 {
553 if (!mDxeCoreReportStatusCodeEnable) {
554 //
555 // When DxeCore Report Status Code is disabled,
556 // Unregister boot time report status code listener at ExitBootService Event.
557 //
558 mRscHandlerProtocol->Unregister (FpdtStatusCodeListenerDxe);
559 }
560
561 if (mAcpiBootPerformanceTable == NULL) {
562 //
563 // Firmware Performance Data Table not installed, do nothing.
564 //
565 return ;
566 }
567
568 //
569 // Update Firmware Basic Boot Performance Record for UEFI boot.
570 //
571 mAcpiBootPerformanceTable->BasicBoot.ExitBootServicesEntry = GetTimeInNanoSecond (GetPerformanceCounter ());
572
573 //
574 // Dump FPDT Boot Performance record.
575 //
576 DEBUG ((EFI_D_INFO, "FPDT: Boot Performance - ResetEnd = %ld\n", mAcpiBootPerformanceTable->BasicBoot.ResetEnd));
577 DEBUG ((EFI_D_INFO, "FPDT: Boot Performance - OsLoaderLoadImageStart = %ld\n", mAcpiBootPerformanceTable->BasicBoot.OsLoaderLoadImageStart));
578 DEBUG ((EFI_D_INFO, "FPDT: Boot Performance - OsLoaderStartImageStart = %ld\n", mAcpiBootPerformanceTable->BasicBoot.OsLoaderStartImageStart));
579 DEBUG ((EFI_D_INFO, "FPDT: Boot Performance - ExitBootServicesEntry = %ld\n", mAcpiBootPerformanceTable->BasicBoot.ExitBootServicesEntry));
580 //
581 // ExitBootServicesExit will be updated later, so don't dump it here.
582 //
583 }
584
585 /**
586 The module Entry Point of the Firmware Performance Data Table DXE driver.
587
588 @param[in] ImageHandle The firmware allocated handle for the EFI image.
589 @param[in] SystemTable A pointer to the EFI System Table.
590
591 @retval EFI_SUCCESS The entry point is executed successfully.
592 @retval Other Some error occurs when executing this entry point.
593
594 **/
595 EFI_STATUS
596 EFIAPI
597 FirmwarePerformanceDxeEntryPoint (
598 IN EFI_HANDLE ImageHandle,
599 IN EFI_SYSTEM_TABLE *SystemTable
600 )
601 {
602 EFI_STATUS Status;
603 EFI_HOB_GUID_TYPE *GuidHob;
604 FIRMWARE_SEC_PERFORMANCE *Performance;
605 VOID *Registration;
606 UINT64 OemTableId;
607
608 CopyMem (
609 mFirmwarePerformanceTableTemplate.Header.OemId,
610 PcdGetPtr (PcdAcpiDefaultOemId),
611 sizeof (mFirmwarePerformanceTableTemplate.Header.OemId)
612 );
613 OemTableId = PcdGet64 (PcdAcpiDefaultOemTableId);
614 CopyMem (&mFirmwarePerformanceTableTemplate.Header.OemTableId, &OemTableId, sizeof (UINT64));
615 mFirmwarePerformanceTableTemplate.Header.OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
616 mFirmwarePerformanceTableTemplate.Header.CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
617 mFirmwarePerformanceTableTemplate.Header.CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
618
619 //
620 // Get Report Status Code Handler Protocol.
621 //
622 Status = gBS->LocateProtocol (&gEfiRscHandlerProtocolGuid, NULL, (VOID **) &mRscHandlerProtocol);
623 ASSERT_EFI_ERROR (Status);
624
625 //
626 // Register report status code listener for OS Loader load and start.
627 //
628 Status = mRscHandlerProtocol->Register (FpdtStatusCodeListenerDxe, TPL_HIGH_LEVEL);
629 ASSERT_EFI_ERROR (Status);
630
631 //
632 // Register the notify function to update FPDT on ExitBootServices Event.
633 //
634 Status = gBS->CreateEventEx (
635 EVT_NOTIFY_SIGNAL,
636 TPL_NOTIFY,
637 FpdtExitBootServicesEventNotify,
638 NULL,
639 &gEfiEventExitBootServicesGuid,
640 &mExitBootServicesEvent
641 );
642 ASSERT_EFI_ERROR (Status);
643
644 //
645 // Retrieve GUID HOB data that contains the ResetEnd.
646 //
647 GuidHob = GetFirstGuidHob (&gEfiFirmwarePerformanceGuid);
648 if (GuidHob != NULL) {
649 Performance = (FIRMWARE_SEC_PERFORMANCE *) GET_GUID_HOB_DATA (GuidHob);
650 mBootPerformanceTableTemplate.BasicBoot.ResetEnd = Performance->ResetEnd;
651 } else {
652 //
653 // SEC Performance Data Hob not found, ResetEnd in ACPI FPDT table will be 0.
654 //
655 DEBUG ((DEBUG_WARN, "FPDT: WARNING: SEC Performance Data Hob not found, ResetEnd will be set to 0!\n"));
656 }
657
658 if (FeaturePcdGet (PcdFirmwarePerformanceDataTableS3Support)) {
659 //
660 // Register callback function upon VariableArchProtocol and LockBoxProtocol
661 // to allocate S3 performance table memory and save the pointer to LockBox.
662 //
663 EfiCreateProtocolNotifyEvent (
664 &gEfiVariableArchProtocolGuid,
665 TPL_CALLBACK,
666 FpdtAllocateS3PerformanceTableMemory,
667 NULL,
668 &Registration
669 );
670 EfiCreateProtocolNotifyEvent (
671 &gEfiLockBoxProtocolGuid,
672 TPL_CALLBACK,
673 FpdtAllocateS3PerformanceTableMemory,
674 NULL,
675 &Registration
676 );
677 } else {
678 //
679 // Exclude S3 Performance Table Pointer from FPDT table template.
680 //
681 mFirmwarePerformanceTableTemplate.Header.Length -= sizeof (EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_POINTER_RECORD);
682 }
683
684 return EFI_SUCCESS;
685 }