From d8b61daacca489c69b3f21d2f8d6bd6e33e16e13 Mon Sep 17 00:00:00 2001 From: yshang1 Date: Mon, 6 Aug 2007 03:52:01 +0000 Subject: Fix bug in PciCfg to support PCI express address. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@3549 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Universal/PcatSingleSegmentPciCfgPei/PciCfg.c | 6 ++--- .../Universal/PcatSingleSegmentPciCfgPei/PciCfg2.c | 28 +++++++++++++++++++--- .../PcatSingleSegmentPciCfgPei/PciCfgInternal.h | 20 +++++++++++----- 3 files changed, 42 insertions(+), 12 deletions(-) (limited to 'IntelFrameworkModulePkg') diff --git a/IntelFrameworkModulePkg/Universal/PcatSingleSegmentPciCfgPei/PciCfg.c b/IntelFrameworkModulePkg/Universal/PcatSingleSegmentPciCfgPei/PciCfg.c index 20bee53355..361f5be40b 100644 --- a/IntelFrameworkModulePkg/Universal/PcatSingleSegmentPciCfgPei/PciCfg.c +++ b/IntelFrameworkModulePkg/Universal/PcatSingleSegmentPciCfgPei/PciCfg.c @@ -53,7 +53,7 @@ PciCfgRead ( { UINTN PciLibAddress; - PciLibAddress = COMMON_TO_PCILIB_ADDRESS (Address); + PciLibAddress = PciCfgAddressConvert ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS *) &Address); switch (Width) { case EfiPeiPciCfgWidthUint8: * (UINT8 *) Buffer = PciRead8 (PciLibAddress); @@ -103,7 +103,7 @@ PciCfgWrite ( { UINTN PciLibAddress; - PciLibAddress = COMMON_TO_PCILIB_ADDRESS (Address); + PciLibAddress = PciCfgAddressConvert ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS *) &Address); switch (Width) { case EfiPeiPciCfgWidthUint8: PciWrite8 (PciLibAddress, *(UINT8 *) Buffer); @@ -153,7 +153,7 @@ PciCfgModify ( { UINTN PciLibAddress; - PciLibAddress = COMMON_TO_PCILIB_ADDRESS (Address); + PciLibAddress = PciCfgAddressConvert ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS *) &Address); switch (Width) { case EfiPeiPciCfgWidthUint8: PciAndThenOr8 (PciLibAddress, (UINT8)~ClearBits, (UINT8)SetBits); diff --git a/IntelFrameworkModulePkg/Universal/PcatSingleSegmentPciCfgPei/PciCfg2.c b/IntelFrameworkModulePkg/Universal/PcatSingleSegmentPciCfgPei/PciCfg2.c index 214a505478..28af898b98 100644 --- a/IntelFrameworkModulePkg/Universal/PcatSingleSegmentPciCfgPei/PciCfg2.c +++ b/IntelFrameworkModulePkg/Universal/PcatSingleSegmentPciCfgPei/PciCfg2.c @@ -71,6 +71,28 @@ EFI_PEI_PPI_DESCRIPTOR gPciCfgPpiList = { &gPciCfgPpi }; + +/** + Convert EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS to PCI_LIB_ADDRESS. + + @param Address PCI address with + EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS format. + + @return The PCI address with PCI_LIB_ADDRESS format. + +**/ +UINTN +PciCfgAddressConvert ( + EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS *Address + ) +{ + if (Address->ExtendedRegister == 0) { + return PCI_LIB_ADDRESS (Address->Bus, Address->Device, Address->Function, Address->Register); + } + + return PCI_LIB_ADDRESS (Address->Bus, Address->Device, Address->Function, Address->ExtendedRegister); +} + /** Reads from a given location in the PCI configuration space. @@ -107,7 +129,7 @@ PciCfg2Read ( { UINTN PciLibAddress; - PciLibAddress = COMMON_TO_PCILIB_ADDRESS (Address); + PciLibAddress = PciCfgAddressConvert ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS *) &Address); if (Width == EfiPeiPciCfgWidthUint8) { *((UINT8 *) Buffer) = PciRead8 (PciLibAddress); @@ -158,7 +180,7 @@ PciCfg2Write ( { UINTN PciLibAddress; - PciLibAddress = COMMON_TO_PCILIB_ADDRESS (Address); + PciLibAddress = PciCfgAddressConvert ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS *) &Address); if (Width == EfiPeiPciCfgWidthUint8) { PciWrite8 (PciLibAddress, *((UINT8 *) Buffer)); @@ -216,7 +238,7 @@ PciCfg2Modify ( { UINTN PciLibAddress; - PciLibAddress = COMMON_TO_PCILIB_ADDRESS (Address); + PciLibAddress = PciCfgAddressConvert ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS *) &Address); if (Width == EfiPeiPciCfgWidthUint8) { PciAndThenOr8 (PciLibAddress, ~(*(UINT8 *)ClearBits), *((UINT8 *) SetBits)); diff --git a/IntelFrameworkModulePkg/Universal/PcatSingleSegmentPciCfgPei/PciCfgInternal.h b/IntelFrameworkModulePkg/Universal/PcatSingleSegmentPciCfgPei/PciCfgInternal.h index 2b6faa56f0..fed8f7277c 100644 --- a/IntelFrameworkModulePkg/Universal/PcatSingleSegmentPciCfgPei/PciCfgInternal.h +++ b/IntelFrameworkModulePkg/Universal/PcatSingleSegmentPciCfgPei/PciCfgInternal.h @@ -28,12 +28,20 @@ #include -#define COMMON_TO_PCILIB_ADDRESS(A) (UINTN)PCI_LIB_ADDRESS( \ - ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS *) &A)->Bus, \ - ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS *) &A)->Device, \ - ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS *) &A)->Function, \ - ((EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS *) &A)->Register \ - ) + +/** + Convert EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS to PCI_LIB_ADDRESS. + + @param Address PCI address with + EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS format. + + @return The PCI address with PCI_LIB_ADDRESS format. + +**/ +UINTN +PciCfgAddressConvert ( + EFI_PEI_PCI_CFG_PPI_PCI_ADDRESS *Address + ); /** -- cgit v1.2.3