X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FAcpi%2FFirmwarePerformanceDataTableDxe%2FFirmwarePerformanceDxe.c;h=caf924ccf8e7a9b04ab32e89b7d7ca6f2d1d9782;hp=fbd0046513eecceb73d27264f2009587010e312a;hb=fd704cbd17f6388520bcb57e6c9fec2a32362ca4;hpb=0284e90cc1fa6d2551874e66a662278a08b8055c diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.c b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.c index fbd0046513..caf924ccf8 100644 --- a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.c +++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.c @@ -2,9 +2,10 @@ This module install ACPI Firmware Performance Data Table (FPDT). This module register report status code listener to collect performance data - for Firmware Basic Boot Performance Record and install FPDT to ACPI table. + for Firmware Basic Boot Performance Record and other boot performance records, + and install FPDT to ACPI table. - Copyright (c) 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -17,10 +18,11 @@ #include -#include - #include #include +#include +#include +#include #include #include @@ -36,25 +38,23 @@ #include #include #include -#include +#include +#include -// -// ACPI table information used to initialize tables. -// -#define EFI_ACPI_OEM_ID "INTEL" -#define EFI_ACPI_OEM_TABLE_ID 0x2020204F4E414954ULL // "TIANO " -#define EFI_ACPI_OEM_REVISION 0x00000001 -#define EFI_ACPI_CREATOR_ID 0x5446534D // TBD "MSFT" -#define EFI_ACPI_CREATOR_REVISION 0x01000013 // TBD +#define EXTENSION_RECORD_SIZE 0x10000 +#define SMM_BOOT_RECORD_COMM_SIZE OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(SMM_BOOT_RECORD_COMMUNICATE) EFI_RSC_HANDLER_PROTOCOL *mRscHandlerProtocol = NULL; +BOOLEAN mLockBoxReady = FALSE; EFI_EVENT mReadyToBootEvent; EFI_EVENT mLegacyBootEvent; EFI_EVENT mExitBootServicesEvent; UINTN mFirmwarePerformanceTableTemplateKey = 0; +UINT32 mBootRecordSize = 0; +UINT32 mBootRecordMaxSize = 0; +UINT8 *mBootRecordBuffer = NULL; -FIRMWARE_PERFORMANCE_RUNTIME_DATA *mPerformanceRuntimeData = NULL; BOOT_PERFORMANCE_TABLE *mAcpiBootPerformanceTable = NULL; S3_PERFORMANCE_TABLE *mAcpiS3PerformanceTable = NULL; @@ -65,13 +65,13 @@ FIRMWARE_PERFORMANCE_TABLE mFirmwarePerformanceTableTemplate = { EFI_ACPI_5_0_FIRMWARE_PERFORMANCE_DATA_TABLE_REVISION, // Revision 0x00, // Checksum will be updated at runtime // - // It is expected that these values will be updated at runtime. + // It is expected that these values will be updated at EntryPoint. // - EFI_ACPI_OEM_ID, // OEMID is a 6 bytes long field - EFI_ACPI_OEM_TABLE_ID, // OEM table identification(8 bytes long) - EFI_ACPI_OEM_REVISION, // OEM revision number - EFI_ACPI_CREATOR_ID, // ASL compiler vendor ID - EFI_ACPI_CREATOR_REVISION, // ASL compiler revision number + {0x00}, // OEM ID is a 6 bytes long field + 0x00, // OEM Table ID(8 bytes long) + 0x00, // OEM Revision + 0x00, // Creator ID + 0x00, // Creator Revision }, // // Firmware Basic Boot Performance Table Pointer Record. @@ -202,6 +202,7 @@ FpdtAllocateReservedMemoryBelow4G ( EFI_STATUS Status; VOID *Buffer; + Buffer = NULL; Pages = EFI_SIZE_TO_PAGES (Size); Address = 0xffffffff; @@ -213,12 +214,106 @@ FpdtAllocateReservedMemoryBelow4G ( ); ASSERT_EFI_ERROR (Status); - Buffer = (VOID *) (UINTN) Address; - ZeroMem (Buffer, Size); + if (!EFI_ERROR (Status)) { + Buffer = (VOID *) (UINTN) Address; + ZeroMem (Buffer, Size); + } return Buffer; } +/** + Callback function upon VariableArchProtocol and LockBoxProtocol + to allocate S3 performance table memory and save the pointer to LockBox. + + @param[in] Event Event whose notification function is being invoked. + @param[in] Context Pointer to the notification function's context. +**/ +VOID +EFIAPI +FpdtAllocateS3PerformanceTableMemory ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + VOID *Interface; + FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable; + UINTN Size; + EFI_PHYSICAL_ADDRESS S3PerformanceTablePointer; + + if (mLockBoxReady && (mAcpiS3PerformanceTable != NULL)) { + // + // The memory for S3 performance table should have been ready, + // and the pointer should have been saved to LockBox, just return. + // + return; + } + + if (!mLockBoxReady) { + Status = gBS->LocateProtocol (&gEfiLockBoxProtocolGuid, NULL, &Interface); + if (!EFI_ERROR (Status)) { + // + // LockBox services has been ready. + // + mLockBoxReady = TRUE; + } + } + + if (mAcpiS3PerformanceTable == NULL) { + Status = gBS->LocateProtocol (&gEfiVariableArchProtocolGuid, NULL, &Interface); + if (!EFI_ERROR (Status)) { + // + // Try to allocate the same runtime buffer as last time boot. + // + ZeroMem (&PerformanceVariable, sizeof (PerformanceVariable)); + Size = sizeof (PerformanceVariable); + Status = gRT->GetVariable ( + EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME, + &gEfiFirmwarePerformanceGuid, + NULL, + &Size, + &PerformanceVariable + ); + if (!EFI_ERROR (Status)) { + Status = gBS->AllocatePages ( + AllocateAddress, + EfiReservedMemoryType, + EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE)), + &PerformanceVariable.S3PerformanceTablePointer + ); + if (!EFI_ERROR (Status)) { + mAcpiS3PerformanceTable = (S3_PERFORMANCE_TABLE *) (UINTN) PerformanceVariable.S3PerformanceTablePointer; + } + } + if (mAcpiS3PerformanceTable == NULL) { + // + // Fail to allocate at specified address, continue to allocate at any address. + // + mAcpiS3PerformanceTable = (S3_PERFORMANCE_TABLE *) FpdtAllocateReservedMemoryBelow4G (sizeof (S3_PERFORMANCE_TABLE)); + } + DEBUG ((EFI_D_INFO, "FPDT: ACPI S3 Performance Table address = 0x%x\n", mAcpiS3PerformanceTable)); + if (mAcpiS3PerformanceTable != NULL) { + CopyMem (mAcpiS3PerformanceTable, &mS3PerformanceTableTemplate, sizeof (mS3PerformanceTableTemplate)); + } + } + } + + if (mLockBoxReady && (mAcpiS3PerformanceTable != NULL)) { + // + // If LockBox services has been ready and memory for FPDT S3 performance table has been allocated, + // save the pointer to LockBox for use in S3 resume. + // + S3PerformanceTablePointer = (EFI_PHYSICAL_ADDRESS) (UINTN) mAcpiS3PerformanceTable; + Status = SaveLockBox ( + &gFirmwarePerformanceS3PointerGuid, + &S3PerformanceTablePointer, + sizeof (EFI_PHYSICAL_ADDRESS) + ); + ASSERT_EFI_ERROR (Status); + } +} + /** Install ACPI Firmware Performance Data Table (FPDT). @@ -232,9 +327,15 @@ InstallFirmwarePerformanceDataTable ( { EFI_STATUS Status; EFI_ACPI_TABLE_PROTOCOL *AcpiTableProtocol; - FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable; - EFI_PHYSICAL_ADDRESS Address; UINTN Size; + UINT8 *SmmBootRecordCommBuffer; + EFI_SMM_COMMUNICATE_HEADER *SmmCommBufferHeader; + SMM_BOOT_RECORD_COMMUNICATE *SmmCommData; + UINTN CommSize; + UINTN BootPerformanceDataSize; + UINT8 *BootPerformanceData; + EFI_SMM_COMMUNICATION_PROTOCOL *Communication; + FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable; // // Get AcpiTable Protocol. @@ -245,14 +346,61 @@ InstallFirmwarePerformanceDataTable ( } // - // Prepare memory for runtime Performance Record. + // Collect boot records from SMM drivers. // - mPerformanceRuntimeData = NULL; - ZeroMem (&PerformanceVariable, sizeof (PerformanceVariable)); + SmmBootRecordCommBuffer = NULL; + SmmCommData = NULL; + Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &Communication); + if (!EFI_ERROR (Status)) { + // + // Initialize communicate buffer + // + SmmBootRecordCommBuffer = AllocateZeroPool (SMM_BOOT_RECORD_COMM_SIZE); + ASSERT (SmmBootRecordCommBuffer != NULL); + SmmCommBufferHeader = (EFI_SMM_COMMUNICATE_HEADER*)SmmBootRecordCommBuffer; + SmmCommData = (SMM_BOOT_RECORD_COMMUNICATE*)SmmCommBufferHeader->Data; + ZeroMem((UINT8*)SmmCommData, sizeof(SMM_BOOT_RECORD_COMMUNICATE)); + + CopyGuid (&SmmCommBufferHeader->HeaderGuid, &gEfiFirmwarePerformanceGuid); + SmmCommBufferHeader->MessageLength = sizeof(SMM_BOOT_RECORD_COMMUNICATE); + CommSize = SMM_BOOT_RECORD_COMM_SIZE; + + // + // Get the size of boot records. + // + SmmCommData->Function = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE; + SmmCommData->BootRecordData = NULL; + Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize); + ASSERT_EFI_ERROR (Status); + + if (!EFI_ERROR (SmmCommData->ReturnStatus) && SmmCommData->BootRecordSize != 0) { + // + // Get all boot records + // + SmmCommData->Function = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA; + SmmCommData->BootRecordData = AllocateZeroPool(SmmCommData->BootRecordSize); + ASSERT (SmmCommData->BootRecordData != NULL); + + Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize); + ASSERT_EFI_ERROR (Status); + ASSERT_EFI_ERROR(SmmCommData->ReturnStatus); + } + } + + // + // Prepare memory for Boot Performance table. + // Boot Performance table includes BasicBoot record, and one or more appended Boot Records. + // + BootPerformanceDataSize = sizeof (BOOT_PERFORMANCE_TABLE) + mBootRecordSize + PcdGet32 (PcdExtFpdtBootRecordPadSize); + if (SmmCommData != NULL) { + BootPerformanceDataSize += SmmCommData->BootRecordSize; + } + // // Try to allocate the same runtime buffer as last time boot. // - Size = sizeof (FIRMWARE_PERFORMANCE_VARIABLE); + ZeroMem (&PerformanceVariable, sizeof (PerformanceVariable)); + Size = sizeof (PerformanceVariable); Status = gRT->GetVariable ( EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME, &gEfiFirmwarePerformanceGuid, @@ -261,36 +409,66 @@ InstallFirmwarePerformanceDataTable ( &PerformanceVariable ); if (!EFI_ERROR (Status)) { - Address = PerformanceVariable.BootPerformanceTablePointer; Status = gBS->AllocatePages ( AllocateAddress, EfiReservedMemoryType, - EFI_SIZE_TO_PAGES (sizeof (FIRMWARE_PERFORMANCE_RUNTIME_DATA)), - &Address + EFI_SIZE_TO_PAGES (BootPerformanceDataSize), + &PerformanceVariable.BootPerformanceTablePointer ); if (!EFI_ERROR (Status)) { - mPerformanceRuntimeData = (FIRMWARE_PERFORMANCE_RUNTIME_DATA *) (UINTN) Address; + mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) (UINTN) PerformanceVariable.BootPerformanceTablePointer; } } - if (mPerformanceRuntimeData == NULL) { + if (mAcpiBootPerformanceTable == NULL) { // // Fail to allocate at specified address, continue to allocate at any address. // - mPerformanceRuntimeData = FpdtAllocateReservedMemoryBelow4G (sizeof (FIRMWARE_PERFORMANCE_RUNTIME_DATA)); + mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) FpdtAllocateReservedMemoryBelow4G (BootPerformanceDataSize); } - DEBUG ((EFI_D_INFO, "FPDT: Performance Runtime Data address = 0x%x\n", mPerformanceRuntimeData)); + DEBUG ((EFI_D_INFO, "FPDT: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable)); - if (mPerformanceRuntimeData == NULL) { + if (mAcpiBootPerformanceTable == NULL) { + if (SmmCommData != NULL && SmmCommData->BootRecordData != NULL) { + FreePool (SmmCommData->BootRecordData); + } + if (SmmBootRecordCommBuffer != NULL) { + FreePool (SmmBootRecordCommBuffer); + } + if (mAcpiS3PerformanceTable != NULL) { + FreePages (mAcpiS3PerformanceTable, EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE))); + } return EFI_OUT_OF_RESOURCES; } // // Prepare Boot Performance Table. // - mAcpiBootPerformanceTable = &mPerformanceRuntimeData->BootPerformance; + BootPerformanceData = (UINT8 *) mAcpiBootPerformanceTable; + // + // Fill Basic Boot record to Boot Performance Table. + // CopyMem (mAcpiBootPerformanceTable, &mBootPerformanceTableTemplate, sizeof (mBootPerformanceTableTemplate)); - DEBUG ((EFI_D_INFO, "FPDT: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable)); + BootPerformanceData = BootPerformanceData + mAcpiBootPerformanceTable->Header.Length; + // + // Fill Boot records from boot drivers. + // + CopyMem (BootPerformanceData, mBootRecordBuffer, mBootRecordSize); + mAcpiBootPerformanceTable->Header.Length += mBootRecordSize; + BootPerformanceData = BootPerformanceData + mBootRecordSize; + if (SmmCommData != NULL && SmmCommData->BootRecordData != NULL) { + // + // Fill Boot records from SMM drivers. + // + CopyMem (BootPerformanceData, SmmCommData->BootRecordData, SmmCommData->BootRecordSize); + FreePool (SmmCommData->BootRecordData); + mAcpiBootPerformanceTable->Header.Length = (UINT32) (mAcpiBootPerformanceTable->Header.Length + SmmCommData->BootRecordSize); + BootPerformanceData = BootPerformanceData + SmmCommData->BootRecordSize; + } + if (SmmBootRecordCommBuffer != NULL) { + FreePool (SmmBootRecordCommBuffer); + } + // // Save Boot Performance Table address to Variable for use in S4 resume. // @@ -300,41 +478,25 @@ InstallFirmwarePerformanceDataTable ( // mFirmwarePerformanceTableTemplate.BootPointerRecord.BootPerformanceTablePointer = (UINT64) (UINTN) mAcpiBootPerformanceTable; - if (FeaturePcdGet (PcdFirmwarePerformanceDataTableS3Support)) { - // - // Prepare S3 Performance Table. - // - mAcpiS3PerformanceTable = &mPerformanceRuntimeData->S3Performance; - CopyMem (mAcpiS3PerformanceTable, &mS3PerformanceTableTemplate, sizeof (mS3PerformanceTableTemplate)); - DEBUG ((EFI_D_INFO, "FPDT: ACPI S3 Performance Table address = 0x%x\n", mAcpiS3PerformanceTable)); - - // - // Save S3 Performance Table address to Variable for use in Firmware Performance PEIM. - // - PerformanceVariable.S3PerformanceTablePointer = (EFI_PHYSICAL_ADDRESS) (UINTN) mAcpiS3PerformanceTable; - - // - // Update S3 Performance Table Pointer in template. - // - mFirmwarePerformanceTableTemplate.S3PointerRecord.S3PerformanceTablePointer = (UINT64) PerformanceVariable.S3PerformanceTablePointer; - } else { - // - // Exclude S3 Performance Table Pointer from FPDT table template. - // - mFirmwarePerformanceTableTemplate.Header.Length -= sizeof (EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD); - } - + // + // Save S3 Performance Table address to Variable for use in S4 resume. + // + PerformanceVariable.S3PerformanceTablePointer = (EFI_PHYSICAL_ADDRESS) (UINTN) mAcpiS3PerformanceTable; + // + // Update S3 Performance Table Pointer in template. + // + mFirmwarePerformanceTableTemplate.S3PointerRecord.S3PerformanceTablePointer = (UINT64) (UINTN) mAcpiS3PerformanceTable; // // Save Runtime Performance Table pointers to Variable. + // Don't check SetVariable return status. It doesn't impact FPDT table generation. // - Status = gRT->SetVariable ( - EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME, - &gEfiFirmwarePerformanceGuid, - EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, - sizeof (FIRMWARE_PERFORMANCE_VARIABLE), - &PerformanceVariable - ); - ASSERT_EFI_ERROR (Status); + gRT->SetVariable ( + EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME, + &gEfiFirmwarePerformanceGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS, + sizeof (PerformanceVariable), + &PerformanceVariable + ); // // Publish Firmware Performance Data Table. @@ -347,12 +509,25 @@ InstallFirmwarePerformanceDataTable ( &mFirmwarePerformanceTableTemplateKey ); if (EFI_ERROR (Status)) { - FreePool (mPerformanceRuntimeData); + FreePages (mAcpiBootPerformanceTable, EFI_SIZE_TO_PAGES (BootPerformanceDataSize)); + if (mAcpiS3PerformanceTable != NULL) { + FreePages (mAcpiS3PerformanceTable, EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE))); + } mAcpiBootPerformanceTable = NULL; mAcpiS3PerformanceTable = NULL; return Status; } - + + // + // Free temp Boot record, and update Boot Record to point to Basic Boot performance table. + // + if (mBootRecordBuffer != NULL) { + FreePool (mBootRecordBuffer); + } + mBootRecordBuffer = (UINT8 *) mAcpiBootPerformanceTable; + mBootRecordSize = mAcpiBootPerformanceTable->Header.Length; + mBootRecordMaxSize = mBootRecordSize + PcdGet32 (PcdExtFpdtBootRecordPadSize); + return EFI_SUCCESS; } @@ -538,6 +713,42 @@ FpdtStatusCodeListenerDxe ( // Unregister boot time report status code listener. // mRscHandlerProtocol->Unregister (FpdtStatusCodeListenerDxe); + } else if (Data != NULL && CompareGuid (&Data->Type, &gEfiFirmwarePerformanceGuid)) { + // + // Append one or more Boot records + // + if (mAcpiBootPerformanceTable == NULL) { + // + // Append Boot records before FPDT ACPI table is installed. + // + if (mBootRecordSize + Data->Size > mBootRecordMaxSize) { + mBootRecordBuffer = ReallocatePool (mBootRecordSize, mBootRecordSize + Data->Size + EXTENSION_RECORD_SIZE, mBootRecordBuffer); + ASSERT (mBootRecordBuffer != NULL); + mBootRecordMaxSize = mBootRecordSize + Data->Size + EXTENSION_RECORD_SIZE; + } + // + // Save boot record into the temp memory space. + // + CopyMem (mBootRecordBuffer + mBootRecordSize, Data + 1, Data->Size); + mBootRecordSize += Data->Size; + } else { + // + // Append Boot records after FPDT ACPI table is installed. + // + if (mBootRecordSize + Data->Size > mBootRecordMaxSize) { + // + // No enough space to save boot record. + // + Status = EFI_OUT_OF_RESOURCES; + } else { + // + // Save boot record into BootPerformance table + // + CopyMem (mBootRecordBuffer + mBootRecordSize, Data + 1, Data->Size); + mBootRecordSize += Data->Size; + mAcpiBootPerformanceTable->Header.Length = mBootRecordSize; + } + } } else { // // Ignore else progress code. @@ -568,6 +779,19 @@ FirmwarePerformanceDxeEntryPoint ( EFI_STATUS Status; EFI_HOB_GUID_TYPE *GuidHob; FIRMWARE_SEC_PERFORMANCE *Performance; + VOID *Registration; + UINT64 OemTableId; + + CopyMem ( + mFirmwarePerformanceTableTemplate.Header.OemId, + PcdGetPtr (PcdAcpiDefaultOemId), + sizeof (mFirmwarePerformanceTableTemplate.Header.OemId) + ); + OemTableId = PcdGet64 (PcdAcpiDefaultOemTableId); + CopyMem (&mFirmwarePerformanceTableTemplate.Header.OemTableId, &OemTableId, sizeof (UINT64)); + mFirmwarePerformanceTableTemplate.Header.OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision); + mFirmwarePerformanceTableTemplate.Header.CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId); + mFirmwarePerformanceTableTemplate.Header.CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision); // // Get Report Status Code Handler Protocol. @@ -634,5 +858,31 @@ FirmwarePerformanceDxeEntryPoint ( DEBUG ((EFI_D_ERROR, "FPDT: WARNING: SEC Performance Data Hob not found, ResetEnd will be set to 0!\n")); } + if (FeaturePcdGet (PcdFirmwarePerformanceDataTableS3Support)) { + // + // Register callback function upon VariableArchProtocol and LockBoxProtocol + // to allocate S3 performance table memory and save the pointer to LockBox. + // + EfiCreateProtocolNotifyEvent ( + &gEfiVariableArchProtocolGuid, + TPL_CALLBACK, + FpdtAllocateS3PerformanceTableMemory, + NULL, + &Registration + ); + EfiCreateProtocolNotifyEvent ( + &gEfiLockBoxProtocolGuid, + TPL_CALLBACK, + FpdtAllocateS3PerformanceTableMemory, + NULL, + &Registration + ); + } else { + // + // Exclude S3 Performance Table Pointer from FPDT table template. + // + mFirmwarePerformanceTableTemplate.Header.Length -= sizeof (EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_POINTER_RECORD); + } + return EFI_SUCCESS; }