summaryrefslogtreecommitdiffstats
path: root/MdePkg/Library/DxeRuntimePciExpressLib
diff options
context:
space:
mode:
authorMarcello Sylvester Bauer <marcello.bauer@9elements.com>2020-07-22 10:55:27 +0200
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2020-09-16 06:36:18 +0000
commit5c065855284bd0ca65784d313e094054e23685bb (patch)
tree5e3614e6ab6bb719dceb4b08b236a11f235c6f22 /MdePkg/Library/DxeRuntimePciExpressLib
parent28d7eea97e80f76b7e4978298e86ef924bdd394b (diff)
downloadedk2-5c065855284bd0ca65784d313e094054e23685bb.tar.gz
edk2-5c065855284bd0ca65784d313e094054e23685bb.tar.bz2
edk2-5c065855284bd0ca65784d313e094054e23685bb.zip
MdePkg: PciExpressLib support variable size MMCONF
Add support for arbitrary sized MMCONF by introducing a new PCD. Add a return value to point out invalid PCI addresses. Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com> Signed-off-by: Marcello Sylvester Bauer <marcello.bauer@9elements.com> Cc: Patrick Rudolph <patrick.rudolph@9elements.com> Cc: Christian Walter <christian.walter@9elements.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Liming Gao <gaoliming@byosoft.com.cn> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Diffstat (limited to 'MdePkg/Library/DxeRuntimePciExpressLib')
-rw-r--r--MdePkg/Library/DxeRuntimePciExpressLib/DxeRuntimePciExpressLib.inf1
-rw-r--r--MdePkg/Library/DxeRuntimePciExpressLib/PciExpressLib.c247
2 files changed, 207 insertions, 41 deletions
diff --git a/MdePkg/Library/DxeRuntimePciExpressLib/DxeRuntimePciExpressLib.inf b/MdePkg/Library/DxeRuntimePciExpressLib/DxeRuntimePciExpressLib.inf
index 8d2ba1d187..26a59bda19 100644
--- a/MdePkg/Library/DxeRuntimePciExpressLib/DxeRuntimePciExpressLib.inf
+++ b/MdePkg/Library/DxeRuntimePciExpressLib/DxeRuntimePciExpressLib.inf
@@ -47,3 +47,4 @@
[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress ## CONSUMES
+ gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseSize ## CONSUMES
diff --git a/MdePkg/Library/DxeRuntimePciExpressLib/PciExpressLib.c b/MdePkg/Library/DxeRuntimePciExpressLib/PciExpressLib.c
index b899543510..cb80725c5f 100644
--- a/MdePkg/Library/DxeRuntimePciExpressLib/PciExpressLib.c
+++ b/MdePkg/Library/DxeRuntimePciExpressLib/PciExpressLib.c
@@ -25,6 +25,16 @@
#include <Library/DxeServicesTableLib.h>
#include <Library/UefiRuntimeLib.h>
+/**
+ Assert the validity of a PCI address. A valid PCI address should contain 1's
+ only in the low 28 bits.
+
+ @param A The address to validate.
+
+**/
+#define ASSERT_INVALID_PCI_ADDRESS(A) \
+ ASSERT (((A) & ~0xfffffff) == 0)
+
///
/// Define table for mapping PCI Express MMIO physical addresses to virtual addresses at OS runtime
///
@@ -39,9 +49,10 @@ typedef struct {
EFI_EVENT mDxeRuntimePciExpressLibVirtualNotifyEvent = NULL;
///
-/// Module global that contains the base physical address of the PCI Express MMIO range.
+/// Module global that contains the base physical address and size of the PCI Express MMIO range.
///
UINTN mDxeRuntimePciExpressLibPciExpressBaseAddress = 0;
+UINTN mDxeRuntimePciExpressLibPciExpressBaseSize = 0;
///
/// The number of PCI devices that have been registered for runtime access.
@@ -120,6 +131,7 @@ DxeRuntimePciExpressLibConstructor (
// Cache the physical address of the PCI Express MMIO range into a module global variable
//
mDxeRuntimePciExpressLibPciExpressBaseAddress = (UINTN) PcdGet64 (PcdPciExpressBaseAddress);
+ mDxeRuntimePciExpressLibPciExpressBaseSize = (UINTN) PcdGet64 (PcdPciExpressBaseSize);
//
// Register SetVirtualAddressMap () notify function
@@ -179,8 +191,12 @@ DxeRuntimePciExpressLibDestructor (
This internal functions retrieves PCI Express Base Address via a PCD entry
PcdPciExpressBaseAddress.
- @param Address The address that encodes the PCI Bus, Device, Function and Register.
- @return The base address of PCI Express.
+ If Address > 0x0FFFFFFF, then ASSERT().
+
+ @param Address The address that encodes the PCI Bus, Device, Function and Register.
+
+ @retval (UINTN)-1 Invalid PCI address.
+ @retval other The base address of PCI Express.
**/
UINTN
@@ -193,7 +209,14 @@ GetPciExpressAddress (
//
// Make sure Address is valid
//
- ASSERT (((Address) & ~0xfffffff) == 0);
+ ASSERT_INVALID_PCI_ADDRESS (Address);
+
+ //
+ // Make sure the Address is in MMCONF address space
+ //
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINTN) -1;
+ }
//
// Convert Address to a physical address in the MMIO PCI Express range
@@ -236,7 +259,6 @@ GetPciExpressAddress (
//
// No match was found. This is a critical error at OS runtime, so ASSERT() and force a breakpoint.
//
- ASSERT (FALSE);
CpuBreakpoint();
//
@@ -288,7 +310,14 @@ PciExpressRegisterForRuntimeAccess (
//
// Make sure Address is valid
//
- ASSERT (((Address) & ~0xfffffff) == 0);
+ ASSERT_INVALID_PCI_ADDRESS (Address);
+
+ //
+ // Make sure the Address is in MMCONF address space
+ //
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return RETURN_UNSUPPORTED;
+ }
//
// Convert Address to a physical address in the MMIO PCI Express range
@@ -354,8 +383,8 @@ PciExpressRegisterForRuntimeAccess (
@param Address The address that encodes the PCI Bus, Device, Function and
Register.
-
- @return The read value from the PCI configuration register.
+ @retval 0xFF Invalid PCI address.
+ @retval other The read value from the PCI configuration register.
**/
UINT8
@@ -364,6 +393,10 @@ PciExpressRead8 (
IN UINTN Address
)
{
+ ASSERT_INVALID_PCI_ADDRESS (Address);
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioRead8 (GetPciExpressAddress (Address));
}
@@ -380,7 +413,8 @@ PciExpressRead8 (
Register.
@param Value The value to write.
- @return The value written to the PCI configuration register.
+ @retval 0xFF Invalid PCI address.
+ @retval other The value written to the PCI configuration register.
**/
UINT8
@@ -390,6 +424,9 @@ PciExpressWrite8 (
IN UINT8 Value
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioWrite8 (GetPciExpressAddress (Address), Value);
}
@@ -410,7 +447,8 @@ PciExpressWrite8 (
Register.
@param OrData The value to OR with the PCI configuration register.
- @return The value written back to the PCI configuration register.
+ @retval 0xFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT8
@@ -420,6 +458,9 @@ PciExpressOr8 (
IN UINT8 OrData
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioOr8 (GetPciExpressAddress (Address), OrData);
}
@@ -440,7 +481,8 @@ PciExpressOr8 (
Register.
@param AndData The value to AND with the PCI configuration register.
- @return The value written back to the PCI configuration register.
+ @retval 0xFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT8
@@ -450,6 +492,9 @@ PciExpressAnd8 (
IN UINT8 AndData
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioAnd8 (GetPciExpressAddress (Address), AndData);
}
@@ -472,7 +517,8 @@ PciExpressAnd8 (
@param AndData The value to AND with the PCI configuration register.
@param OrData The value to OR with the result of the AND operation.
- @return The value written back to the PCI configuration register.
+ @retval 0xFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT8
@@ -483,6 +529,9 @@ PciExpressAndThenOr8 (
IN UINT8 OrData
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioAndThenOr8 (
GetPciExpressAddress (Address),
AndData,
@@ -508,7 +557,8 @@ PciExpressAndThenOr8 (
@param EndBit The ordinal of the most significant bit in the bit field.
Range 0..7.
- @return The value of the bit field read from the PCI configuration register.
+ @retval 0xFF Invalid PCI address.
+ @retval other The value of the bit field read from the PCI configuration register.
**/
UINT8
@@ -519,6 +569,9 @@ PciExpressBitFieldRead8 (
IN UINTN EndBit
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioBitFieldRead8 (
GetPciExpressAddress (Address),
StartBit,
@@ -547,7 +600,8 @@ PciExpressBitFieldRead8 (
Range 0..7.
@param Value The new value of the bit field.
- @return The value written back to the PCI configuration register.
+ @retval 0xFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT8
@@ -559,6 +613,9 @@ PciExpressBitFieldWrite8 (
IN UINT8 Value
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioBitFieldWrite8 (
GetPciExpressAddress (Address),
StartBit,
@@ -591,7 +648,8 @@ PciExpressBitFieldWrite8 (
Range 0..7.
@param OrData The value to OR with the PCI configuration register.
- @return The value written back to the PCI configuration register.
+ @retval 0xFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT8
@@ -603,6 +661,9 @@ PciExpressBitFieldOr8 (
IN UINT8 OrData
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioBitFieldOr8 (
GetPciExpressAddress (Address),
StartBit,
@@ -635,7 +696,8 @@ PciExpressBitFieldOr8 (
Range 0..7.
@param AndData The value to AND with the PCI configuration register.
- @return The value written back to the PCI configuration register.
+ @retval 0xFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT8
@@ -647,6 +709,9 @@ PciExpressBitFieldAnd8 (
IN UINT8 AndData
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioBitFieldAnd8 (
GetPciExpressAddress (Address),
StartBit,
@@ -683,7 +748,8 @@ PciExpressBitFieldAnd8 (
@param AndData The value to AND with the PCI configuration register.
@param OrData The value to OR with the result of the AND operation.
- @return The value written back to the PCI configuration register.
+ @retval 0xFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT8
@@ -696,6 +762,9 @@ PciExpressBitFieldAndThenOr8 (
IN UINT8 OrData
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioBitFieldAndThenOr8 (
GetPciExpressAddress (Address),
StartBit,
@@ -718,7 +787,8 @@ PciExpressBitFieldAndThenOr8 (
@param Address The address that encodes the PCI Bus, Device, Function and
Register.
- @return The read value from the PCI configuration register.
+ @retval 0xFFFF Invalid PCI address.
+ @retval other The read value from the PCI configuration register.
**/
UINT16
@@ -727,6 +797,9 @@ PciExpressRead16 (
IN UINTN Address
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioRead16 (GetPciExpressAddress (Address));
}
@@ -744,7 +817,8 @@ PciExpressRead16 (
Register.
@param Value The value to write.
- @return The value written to the PCI configuration register.
+ @retval 0xFFFF Invalid PCI address.
+ @retval other The value written to the PCI configuration register.
**/
UINT16
@@ -754,6 +828,9 @@ PciExpressWrite16 (
IN UINT16 Value
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioWrite16 (GetPciExpressAddress (Address), Value);
}
@@ -775,7 +852,8 @@ PciExpressWrite16 (
Register.
@param OrData The value to OR with the PCI configuration register.
- @return The value written back to the PCI configuration register.
+ @retval 0xFFFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT16
@@ -785,6 +863,9 @@ PciExpressOr16 (
IN UINT16 OrData
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioOr16 (GetPciExpressAddress (Address), OrData);
}
@@ -806,7 +887,8 @@ PciExpressOr16 (
Register.
@param AndData The value to AND with the PCI configuration register.
- @return The value written back to the PCI configuration register.
+ @retval 0xFFFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT16
@@ -816,6 +898,9 @@ PciExpressAnd16 (
IN UINT16 AndData
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioAnd16 (GetPciExpressAddress (Address), AndData);
}
@@ -839,7 +924,8 @@ PciExpressAnd16 (
@param AndData The value to AND with the PCI configuration register.
@param OrData The value to OR with the result of the AND operation.
- @return The value written back to the PCI configuration register.
+ @retval 0xFFFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT16
@@ -850,6 +936,9 @@ PciExpressAndThenOr16 (
IN UINT16 OrData
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioAndThenOr16 (
GetPciExpressAddress (Address),
AndData,
@@ -876,7 +965,8 @@ PciExpressAndThenOr16 (
@param EndBit The ordinal of the most significant bit in the bit field.
Range 0..15.
- @return The value of the bit field read from the PCI configuration register.
+ @retval 0xFFFF Invalid PCI address.
+ @retval other The value of the bit field read from the PCI configuration register.
**/
UINT16
@@ -887,6 +977,9 @@ PciExpressBitFieldRead16 (
IN UINTN EndBit
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioBitFieldRead16 (
GetPciExpressAddress (Address),
StartBit,
@@ -916,7 +1009,8 @@ PciExpressBitFieldRead16 (
Range 0..15.
@param Value The new value of the bit field.
- @return The value written back to the PCI configuration register.
+ @retval 0xFFFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT16
@@ -928,6 +1022,9 @@ PciExpressBitFieldWrite16 (
IN UINT16 Value
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioBitFieldWrite16 (
GetPciExpressAddress (Address),
StartBit,
@@ -961,7 +1058,8 @@ PciExpressBitFieldWrite16 (
Range 0..15.
@param OrData The value to OR with the PCI configuration register.
- @return The value written back to the PCI configuration register.
+ @retval 0xFFFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT16
@@ -973,6 +1071,9 @@ PciExpressBitFieldOr16 (
IN UINT16 OrData
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioBitFieldOr16 (
GetPciExpressAddress (Address),
StartBit,
@@ -1006,7 +1107,8 @@ PciExpressBitFieldOr16 (
Range 0..15.
@param AndData The value to AND with the PCI configuration register.
- @return The value written back to the PCI configuration register.
+ @retval 0xFFFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT16
@@ -1018,6 +1120,9 @@ PciExpressBitFieldAnd16 (
IN UINT16 AndData
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioBitFieldAnd16 (
GetPciExpressAddress (Address),
StartBit,
@@ -1055,7 +1160,8 @@ PciExpressBitFieldAnd16 (
@param AndData The value to AND with the PCI configuration register.
@param OrData The value to OR with the result of the AND operation.
- @return The value written back to the PCI configuration register.
+ @retval 0xFFFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT16
@@ -1068,6 +1174,9 @@ PciExpressBitFieldAndThenOr16 (
IN UINT16 OrData
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioBitFieldAndThenOr16 (
GetPciExpressAddress (Address),
StartBit,
@@ -1090,7 +1199,8 @@ PciExpressBitFieldAndThenOr16 (
@param Address The address that encodes the PCI Bus, Device, Function and
Register.
- @return The read value from the PCI configuration register.
+ @retval 0xFFFF Invalid PCI address.
+ @retval other The read value from the PCI configuration register.
**/
UINT32
@@ -1099,6 +1209,9 @@ PciExpressRead32 (
IN UINTN Address
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioRead32 (GetPciExpressAddress (Address));
}
@@ -1116,7 +1229,8 @@ PciExpressRead32 (
Register.
@param Value The value to write.
- @return The value written to the PCI configuration register.
+ @retval 0xFFFFFFFF Invalid PCI address.
+ @retval other The value written to the PCI configuration register.
**/
UINT32
@@ -1126,6 +1240,9 @@ PciExpressWrite32 (
IN UINT32 Value
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioWrite32 (GetPciExpressAddress (Address), Value);
}
@@ -1147,7 +1264,8 @@ PciExpressWrite32 (
Register.
@param OrData The value to OR with the PCI configuration register.
- @return The value written back to the PCI configuration register.
+ @retval 0xFFFFFFFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT32
@@ -1157,6 +1275,9 @@ PciExpressOr32 (
IN UINT32 OrData
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioOr32 (GetPciExpressAddress (Address), OrData);
}
@@ -1178,7 +1299,8 @@ PciExpressOr32 (
Register.
@param AndData The value to AND with the PCI configuration register.
- @return The value written back to the PCI configuration register.
+ @retval 0xFFFFFFFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT32
@@ -1188,6 +1310,9 @@ PciExpressAnd32 (
IN UINT32 AndData
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioAnd32 (GetPciExpressAddress (Address), AndData);
}
@@ -1211,7 +1336,8 @@ PciExpressAnd32 (
@param AndData The value to AND with the PCI configuration register.
@param OrData The value to OR with the result of the AND operation.
- @return The value written back to the PCI configuration register.
+ @retval 0xFFFFFFFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT32
@@ -1222,6 +1348,9 @@ PciExpressAndThenOr32 (
IN UINT32 OrData
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioAndThenOr32 (
GetPciExpressAddress (Address),
AndData,
@@ -1248,7 +1377,8 @@ PciExpressAndThenOr32 (
@param EndBit The ordinal of the most significant bit in the bit field.
Range 0..31.
- @return The value of the bit field read from the PCI configuration register.
+ @retval 0xFFFFFFFF Invalid PCI address.
+ @retval other The value of the bit field read from the PCI configuration register.
**/
UINT32
@@ -1259,6 +1389,9 @@ PciExpressBitFieldRead32 (
IN UINTN EndBit
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioBitFieldRead32 (
GetPciExpressAddress (Address),
StartBit,
@@ -1288,7 +1421,8 @@ PciExpressBitFieldRead32 (
Range 0..31.
@param Value The new value of the bit field.
- @return The value written back to the PCI configuration register.
+ @retval 0xFFFFFFFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT32
@@ -1300,6 +1434,9 @@ PciExpressBitFieldWrite32 (
IN UINT32 Value
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioBitFieldWrite32 (
GetPciExpressAddress (Address),
StartBit,
@@ -1333,7 +1470,8 @@ PciExpressBitFieldWrite32 (
Range 0..31.
@param OrData The value to OR with the PCI configuration register.
- @return The value written back to the PCI configuration register.
+ @retval 0xFFFFFFFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT32
@@ -1345,6 +1483,9 @@ PciExpressBitFieldOr32 (
IN UINT32 OrData
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioBitFieldOr32 (
GetPciExpressAddress (Address),
StartBit,
@@ -1378,7 +1519,8 @@ PciExpressBitFieldOr32 (
Range 0..31.
@param AndData The value to AND with the PCI configuration register.
- @return The value written back to the PCI configuration register.
+ @retval 0xFFFFFFFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT32
@@ -1390,6 +1532,9 @@ PciExpressBitFieldAnd32 (
IN UINT32 AndData
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioBitFieldAnd32 (
GetPciExpressAddress (Address),
StartBit,
@@ -1427,7 +1572,8 @@ PciExpressBitFieldAnd32 (
@param AndData The value to AND with the PCI configuration register.
@param OrData The value to OR with the result of the AND operation.
- @return The value written back to the PCI configuration register.
+ @retval 0xFFFFFFFF Invalid PCI address.
+ @retval other The value written back to the PCI configuration register.
**/
UINT32
@@ -1440,6 +1586,9 @@ PciExpressBitFieldAndThenOr32 (
IN UINT32 OrData
)
{
+ if (Address >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioBitFieldAndThenOr32 (
GetPciExpressAddress (Address),
StartBit,
@@ -1469,7 +1618,8 @@ PciExpressBitFieldAndThenOr32 (
@param Size The size in bytes of the transfer.
@param Buffer The pointer to a buffer receiving the data read.
- @return Size read data from StartAddress.
+ @retval 0xFFFFFFFF Invalid PCI address.
+ @retval other Size read data from StartAddress.
**/
UINTN
@@ -1485,9 +1635,16 @@ PciExpressReadBuffer (
//
// Make sure Address is valid
//
- ASSERT (((StartAddress) & ~0xfffffff) == 0);
+ ASSERT_INVALID_PCI_ADDRESS (StartAddress);
ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);
+ //
+ // Make sure the Address is in MMCONF address space
+ //
+ if (StartAddress >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINTN) -1;
+ }
+
if (Size == 0) {
return Size;
}
@@ -1572,7 +1729,8 @@ PciExpressReadBuffer (
@param Size The size in bytes of the transfer.
@param Buffer The pointer to a buffer containing the data to write.
- @return Size written to StartAddress.
+ @retval 0xFFFFFFFF Invalid PCI address.
+ @retval other Size written to StartAddress.
**/
UINTN
@@ -1588,9 +1746,16 @@ PciExpressWriteBuffer (
//
// Make sure Address is valid
//
- ASSERT (((StartAddress) & ~0xfffffff) == 0);
+ ASSERT_INVALID_PCI_ADDRESS (StartAddress);
ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);
+ //
+ // Make sure the Address is in MMCONF address space
+ //
+ if (StartAddress >= mDxeRuntimePciExpressLibPciExpressBaseSize) {
+ return (UINTN) -1;
+ }
+
if (Size == 0) {
return 0;
}