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