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