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