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