X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FBus%2FPci%2FPciBusDxe%2FPciCommand.c;h=6283d602207cb09d89d8330d52fde94ac3d7c152;hp=601af309b7c2e76d7aa2b9f2944d39146e7b5ea5;hb=e5b4d825afc474a8cb916a2476dc0bb85fb32b2d;hpb=9060e3ec6dfd6048724832947933650cde873381 diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciCommand.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciCommand.c index 601af309b7..6283d60220 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciCommand.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciCommand.c @@ -1,14 +1,8 @@ /** @file PCI command register operations supporting functions implementation for PCI Bus module. -Copyright (c) 2006 - 2009, 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 -http://opensource.org/licenses/bsd-license.php - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -75,12 +69,12 @@ PciOperateRegister ( } /** - Check the cpability supporting by given device. + Check the capability supporting by given device. @param PciIoDevice Pointer to instance of PCI_IO_DEVICE. - @retval TRUE Cpability supportted. - @retval FALSE Cpability not supportted. + @retval TRUE Capability supported. + @retval FALSE Capability not supported. **/ BOOLEAN @@ -103,7 +97,7 @@ PciCapabilitySupport ( @param Offset A pointer to the offset returned. @param NextRegBlock A pointer to the next block returned. - @retval EFI_SUCCESS Successfuly located capability register block. + @retval EFI_SUCCESS Successfully located capability register block. @retval EFI_UNSUPPORTED Pci device does not support capability. @retval EFI_NOT_FOUND Pci device support but can not find register block. @@ -121,7 +115,7 @@ LocateCapabilityRegBlock ( UINT8 CapabilityID; // - // To check the cpability of this device supports + // To check the capability of this device supports // if (!PciCapabilitySupport (PciIoDevice)) { return EFI_UNSUPPORTED; @@ -173,6 +167,14 @@ LocateCapabilityRegBlock ( return EFI_SUCCESS; } + // + // Certain PCI device may incorrectly have capability pointing to itself, + // break to avoid dead loop. + // + if (CapabilityPtr == (UINT8) (CapabilityEntry >> 8)) { + break; + } + CapabilityPtr = (UINT8) (CapabilityEntry >> 8); } @@ -187,7 +189,7 @@ LocateCapabilityRegBlock ( @param Offset A pointer to the offset returned. @param NextRegBlock A pointer to the next block returned. - @retval EFI_SUCCESS Successfuly located capability register block. + @retval EFI_SUCCESS Successfully located capability register block. @retval EFI_UNSUPPORTED Pci device does not support capability. @retval EFI_NOT_FOUND Pci device support but can not find register block. @@ -200,9 +202,10 @@ LocatePciExpressCapabilityRegBlock ( OUT UINT32 *NextRegBlock OPTIONAL ) { - UINT32 CapabilityPtr; - UINT32 CapabilityEntry; - UINT16 CapabilityID; + EFI_STATUS Status; + UINT32 CapabilityPtr; + UINT32 CapabilityEntry; + UINT16 CapabilityID; // // To check the capability of this device supports @@ -222,13 +225,29 @@ LocatePciExpressCapabilityRegBlock ( // Mask it to DWORD alignment per PCI spec // CapabilityPtr &= 0xFFC; - PciIoDevice->PciIo.Pci.Read ( - &PciIoDevice->PciIo, - EfiPciIoWidthUint32, - CapabilityPtr, - 1, - &CapabilityEntry - ); + Status = PciIoDevice->PciIo.Pci.Read ( + &PciIoDevice->PciIo, + EfiPciIoWidthUint32, + CapabilityPtr, + 1, + &CapabilityEntry + ); + if (EFI_ERROR (Status)) { + break; + } + + if (CapabilityEntry == MAX_UINT32) { + DEBUG (( + DEBUG_WARN, + "%a: [%02x|%02x|%02x] failed to access config space at offset 0x%x\n", + __FUNCTION__, + PciIoDevice->BusNumber, + PciIoDevice->DeviceNumber, + PciIoDevice->FunctionNumber, + CapabilityPtr + )); + break; + } CapabilityID = (UINT16) CapabilityEntry;