diff --git a/BootloaderCommonPkg/Include/Library/FirmwareUpdateLib.h b/BootloaderCommonPkg/Include/Library/FirmwareUpdateLib.h index c8dba27d..0a251613 100644 --- a/BootloaderCommonPkg/Include/Library/FirmwareUpdateLib.h +++ b/BootloaderCommonPkg/Include/Library/FirmwareUpdateLib.h @@ -494,6 +494,38 @@ UpdateCsme ( IN EFI_FW_MGMT_CAP_IMAGE_HEADER *ImageHdr ); +/** + Reads a range of PCI configuration registers into a caller supplied buffer. + + Reads the range of PCI configuration registers specified by StartAddress and + Size into the buffer specified by Buffer. This function only allows the PCI + configuration registers from a single PCI function to be read. Size is + returned. When possible 32-bit PCI configuration read cycles are used to read + from StartAddress to StartAddress + Size. Due to alignment restrictions, 8-bit + and 16-bit PCI configuration read cycles may be used at the beginning and the + end of the range. + + If StartAddress > 0x0FFFFFFF, then ASSERT(). + If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT(). + If Size > 0 and Buffer is NULL, then ASSERT(). + + @param StartAddress The starting address that encodes the PCI Bus, Device, + Function and Register. + @param Size The size in bytes of the transfer. + @param Buffer The pointer to a buffer receiving the data read. + + @return EFI_SUCCESS if data is read into buffer + @return EFI_NOT_FOUND if data is NOT read into buffer + @return EFI_INVALID_PARAMETER Invalid parameter +**/ +EFI_STATUS +EFIAPI +CsmePciReadBuffer ( + IN UINTN StartAddress, + IN UINTN Size, + OUT VOID *Buffer + ); + /** Platform hook point to clear firmware update trigger. diff --git a/PayloadPkg/FirmwareUpdate/CsmeFwUpdate.c b/PayloadPkg/FirmwareUpdate/CsmeFwUpdate.c index 66c27444..4cdce6fa 100644 --- a/PayloadPkg/FirmwareUpdate/CsmeFwUpdate.c +++ b/PayloadPkg/FirmwareUpdate/CsmeFwUpdate.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -76,6 +77,77 @@ DisplaySendStatus ( IN UINT32 totalBytesToSendToFw ); +/** + Reads a range of PCI configuration registers into a caller supplied buffer. + + Reads the range of PCI configuration registers specified by StartAddress and + Size into the buffer specified by Buffer. This function only allows the PCI + configuration registers from a single PCI function to be read. Size is + returned. When possible 32-bit PCI configuration read cycles are used to read + from StartAddress to StartAddress + Size. Due to alignment restrictions, 8-bit + and 16-bit PCI configuration read cycles may be used at the beginning and the + end of the range. + + If StartAddress > 0x0FFFFFFF, then ASSERT(). + If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT(). + If Size > 0 and Buffer is NULL, then ASSERT(). + + @param StartAddress The starting address that encodes the PCI Bus, Device, + Function and Register. + @param Size The size in bytes of the transfer. + @param Buffer The pointer to a buffer receiving the data read. + + @return EFI_SUCCESS if data is read into buffer + @return EFI_NOT_FOUND if data is NOT read into buffer + @return EFI_INVALID_PARAMETER Invalid parameter +**/ +EFI_STATUS +EFIAPI +CsmePciReadBuffer ( + IN UINTN StartAddress, + IN UINTN Size, + OUT VOID *Buffer + ) +{ + UINT8 Bus; + UINT8 Device; + UINT8 Function; + UINT8 Register; + UINTN ReadCount; + + if ((Buffer == NULL) || (Size == 0)) { + return EFI_INVALID_PARAMETER; + } + + // + // A valid PCI address should contain 1's only in the low 28 bits. + // + if (((StartAddress) & (~0xfffffff)) != 0) { + return EFI_INVALID_PARAMETER; + } + + if (((StartAddress & 0xFFF) + Size) > 0x1000) { + return EFI_INVALID_PARAMETER; + } + + Bus = (UINT8)((StartAddress >> 24) & 0xFF); + Device = (UINT8)((StartAddress >> 16) & 0xFF); + Function = (UINT8)((StartAddress >> 8) & 0xFF); + Register = (UINT8)(StartAddress & 0xFF); + + ReadCount = PciReadBuffer ( + PCI_LIB_ADDRESS(Bus, Device, Function, Register), + Size * sizeof(UINT32), + Buffer + ); + + if (ReadCount != 0) { + return EFI_SUCCESS; + } + + return EFI_NOT_FOUND; +} + /** Check if the update image has the same version as the flash image. @@ -112,12 +184,26 @@ IsUpdateToSameVersion( *IsSameVersion = FALSE; - Status = UpdateApi->FwuPartitionVersionFromFlash(FPT_PARTITION_NAME_FTPR, &flashMajor, &flashMinor, &flashHotfix, &flashBuild); + Status = UpdateApi->FwuPartitionVersionFromFlash( + FPT_PARTITION_NAME_FTPR, + &flashMajor, + &flashMinor, + &flashHotfix, + &flashBuild + ); if (Status != SUCCESS) { return Status; } - Status = UpdateApi->FwuPartitionVersionFromBuffer(Buffer, BufferLength, FPT_PARTITION_NAME_FTPR, &bufferMajor, &bufferMinor, &bufferHotfix, &bufferBuild); + Status = UpdateApi->FwuPartitionVersionFromBuffer( + Buffer, + BufferLength, + FPT_PARTITION_NAME_FTPR, + &bufferMajor, + &bufferMinor, + &bufferHotfix, + &bufferBuild + ); if (Status != SUCCESS) { return Status; } @@ -227,7 +313,12 @@ StartCsmeUpdate ( // // For full update, check if update to the same version // - UpdateStatus = IsUpdateToSameVersion(Buffer, (UINT32)BufferLength, UpdateApi, &IsSameVersion); + UpdateStatus = IsUpdateToSameVersion( + Buffer, + (UINT32)BufferLength, + UpdateApi, + &IsSameVersion + ); if (UpdateStatus != SUCCESS) { goto End; } diff --git a/Silicon/CoffeelakePkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c b/Silicon/CoffeelakePkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c index fc52df0b..0a14f943 100644 --- a/Silicon/CoffeelakePkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c +++ b/Silicon/CoffeelakePkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -146,7 +145,7 @@ InitCsmeUpdInputData ( CsmeUpdDriverInput->SetMem = (VOID *)((UINTN)SetMem); CsmeUpdDriverInput->CompareMem = (VOID *)((UINTN)CompareMem); CsmeUpdDriverInput->Stall = (VOID *)((UINTN)MicroSecondDelay); - CsmeUpdDriverInput->PciRead = (VOID *)((UINTN)PciReadBuffer); + CsmeUpdDriverInput->PciRead = (VOID *)((UINTN)CsmePciReadBuffer); if (HeciService != NULL) { CsmeUpdDriverInput->HeciReadMessage = (VOID *)((UINTN)HeciService->HeciReceive); CsmeUpdDriverInput->HeciSendMessage = (VOID *)((UINTN)HeciService->HeciSend); diff --git a/Silicon/CometlakePkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c b/Silicon/CometlakePkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c index f44e6448..51e28b64 100644 --- a/Silicon/CometlakePkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c +++ b/Silicon/CometlakePkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -144,7 +143,7 @@ InitCsmeUpdInputData ( CsmeUpdDriverInput->SetMem = (VOID *)((UINTN)SetMem); CsmeUpdDriverInput->CompareMem = (VOID *)((UINTN)CompareMem); CsmeUpdDriverInput->Stall = (VOID *)((UINTN)MicroSecondDelay); - CsmeUpdDriverInput->PciRead = (VOID *)((UINTN)PciReadBuffer); + CsmeUpdDriverInput->PciRead = (VOID *)((UINTN)CsmePciReadBuffer); CsmeUpdDriverInput->HeciReadMessage = (VOID *)((UINTN)HeciReceive); CsmeUpdDriverInput->HeciSendMessage = (VOID *)((UINTN)HeciSend); CsmeUpdDriverInput->HeciReset = (VOID *)((UINTN)ResetHeciInterface); diff --git a/Silicon/CometlakevPkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c b/Silicon/CometlakevPkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c index bf7d3d01..d50ddaf5 100644 --- a/Silicon/CometlakevPkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c +++ b/Silicon/CometlakevPkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -144,7 +143,7 @@ InitCsmeUpdInputData ( CsmeUpdDriverInput->SetMem = (VOID *)((UINTN)SetMem); CsmeUpdDriverInput->CompareMem = (VOID *)((UINTN)CompareMem); CsmeUpdDriverInput->Stall = (VOID *)((UINTN)MicroSecondDelay); - CsmeUpdDriverInput->PciRead = (VOID *)((UINTN)PciReadBuffer); + CsmeUpdDriverInput->PciRead = (VOID *)((UINTN)CsmePciReadBuffer); CsmeUpdDriverInput->HeciReadMessage = (VOID *)((UINTN)HeciReceive); CsmeUpdDriverInput->HeciSendMessage = (VOID *)((UINTN)HeciSend); CsmeUpdDriverInput->HeciReset = (VOID *)((UINTN)ResetHeciInterface); diff --git a/Silicon/ElkhartlakePkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c b/Silicon/ElkhartlakePkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c index d017b042..b7b2e59c 100644 --- a/Silicon/ElkhartlakePkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c +++ b/Silicon/ElkhartlakePkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -143,7 +142,7 @@ InitCsmeUpdInputData ( CsmeUpdDriverInput->SetMem = (VOID *)((UINTN)SetMem); CsmeUpdDriverInput->CompareMem = (VOID *)((UINTN)CompareMem); CsmeUpdDriverInput->Stall = (VOID *)((UINTN)MicroSecondDelay); - CsmeUpdDriverInput->PciRead = (VOID *)((UINTN)PciReadBuffer); + CsmeUpdDriverInput->PciRead = (VOID *)((UINTN)CsmePciReadBuffer); CsmeUpdDriverInput->HeciReadMessage = (VOID *)((UINTN)HeciReceive); CsmeUpdDriverInput->HeciSendMessage = (VOID *)((UINTN)HeciSend); CsmeUpdDriverInput->HeciReset = (VOID *)((UINTN)ResetHeciInterface); diff --git a/Silicon/TigerlakePkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c b/Silicon/TigerlakePkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c index 69f2faaf..bedab6b0 100644 --- a/Silicon/TigerlakePkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c +++ b/Silicon/TigerlakePkg/Library/FirmwareUpdateLib/FirmwareUpdateLib.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -145,7 +144,7 @@ InitCsmeUpdInputData ( CsmeUpdDriverInput->SetMem = (VOID *)((UINTN)SetMem); CsmeUpdDriverInput->CompareMem = (VOID *)((UINTN)CompareMem); CsmeUpdDriverInput->Stall = (VOID *)((UINTN)MicroSecondDelay); - CsmeUpdDriverInput->PciRead = (VOID *)((UINTN)PciReadBuffer); + CsmeUpdDriverInput->PciRead = (VOID *)((UINTN)CsmePciReadBuffer); CsmeUpdDriverInput->HeciReadMessage = (VOID *)((UINTN)HeciReceive); CsmeUpdDriverInput->HeciSendMessage = (VOID *)((UINTN)HeciSend); CsmeUpdDriverInput->HeciReset = (VOID *)((UINTN)ResetHeciInterface);