summaryrefslogtreecommitdiffstats
path: root/MdePkg/Library/SmmPciExpressLib/PciExpressLib.c
diff options
context:
space:
mode:
Diffstat (limited to 'MdePkg/Library/SmmPciExpressLib/PciExpressLib.c')
-rw-r--r--MdePkg/Library/SmmPciExpressLib/PciExpressLib.c218
1 files changed, 183 insertions, 35 deletions
diff --git a/MdePkg/Library/SmmPciExpressLib/PciExpressLib.c b/MdePkg/Library/SmmPciExpressLib/PciExpressLib.c
index 35b9f775a8..97bd32c8d2 100644
--- a/MdePkg/Library/SmmPciExpressLib/PciExpressLib.c
+++ b/MdePkg/Library/SmmPciExpressLib/PciExpressLib.c
@@ -20,9 +20,10 @@
#include <Library/PcdLib.h>
///
-/// 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 mSmmPciExpressLibPciExpressBaseAddress = 0;
+UINTN mSmmPciExpressLibPciExpressBaseSize = 0;
/**
The constructor function caches the PCI Express Base Address
@@ -40,9 +41,10 @@ SmmPciExpressLibConstructor (
)
{
//
- // Cache the physical address of the PCI Express MMIO range into a module global variable
+ // Cache the physical address and size of the PCI Express MMIO range into a module global variable
//
mSmmPciExpressLibPciExpressBaseAddress = (UINTN) PcdGet64 (PcdPciExpressBaseAddress);
+ mSmmPciExpressLibPciExpressBaseSize = (UINTN) PcdGet64 (PcdPciExpressBaseSize);
return EFI_SUCCESS;
}
@@ -97,8 +99,12 @@ PciExpressRegisterForRuntimeAccess (
mSmmPciExpressLibPciExpressBaseAddress is initialized in the library constructor from PCD entry
PcdPciExpressBaseAddress.
+ If Address > 0x0FFFFFFF, then ASSERT().
+
@param Address The address that encodes the PCI Bus, Device, Function and Register.
- @return MMIO address corresponding to Address.
+
+ @retval (UINTN)-1 Invalid PCI address.
+ @retval other MMIO address corresponding to Address.
**/
UINTN
@@ -110,6 +116,12 @@ GetPciExpressAddress (
// Make sure Address is valid
//
ASSERT_INVALID_PCI_ADDRESS (Address);
+ //
+ // Make sure the Address is in MMCONF address space
+ //
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINTN) -1;
+ }
return mSmmPciExpressLibPciExpressBaseAddress + Address;
}
@@ -125,7 +137,8 @@ GetPciExpressAddress (
@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
@@ -134,6 +147,9 @@ PciExpressRead8 (
IN UINTN Address
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioRead8 (GetPciExpressAddress (Address));
}
@@ -150,7 +166,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
@@ -160,6 +177,9 @@ PciExpressWrite8 (
IN UINT8 Value
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioWrite8 (GetPciExpressAddress (Address), Value);
}
@@ -180,7 +200,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
@@ -190,6 +211,9 @@ PciExpressOr8 (
IN UINT8 OrData
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioOr8 (GetPciExpressAddress (Address), OrData);
}
@@ -210,7 +234,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
@@ -220,6 +245,9 @@ PciExpressAnd8 (
IN UINT8 AndData
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioAnd8 (GetPciExpressAddress (Address), AndData);
}
@@ -242,7 +270,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
@@ -253,6 +282,9 @@ PciExpressAndThenOr8 (
IN UINT8 OrData
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioAndThenOr8 (
GetPciExpressAddress (Address),
AndData,
@@ -278,7 +310,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
@@ -289,6 +322,9 @@ PciExpressBitFieldRead8 (
IN UINTN EndBit
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioBitFieldRead8 (
GetPciExpressAddress (Address),
StartBit,
@@ -317,7 +353,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
@@ -329,6 +366,9 @@ PciExpressBitFieldWrite8 (
IN UINT8 Value
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioBitFieldWrite8 (
GetPciExpressAddress (Address),
StartBit,
@@ -361,7 +401,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
@@ -373,6 +414,9 @@ PciExpressBitFieldOr8 (
IN UINT8 OrData
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioBitFieldOr8 (
GetPciExpressAddress (Address),
StartBit,
@@ -405,7 +449,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
@@ -417,6 +462,9 @@ PciExpressBitFieldAnd8 (
IN UINT8 AndData
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioBitFieldAnd8 (
GetPciExpressAddress (Address),
StartBit,
@@ -453,7 +501,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
@@ -466,6 +515,9 @@ PciExpressBitFieldAndThenOr8 (
IN UINT8 OrData
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT8) -1;
+ }
return MmioBitFieldAndThenOr8 (
GetPciExpressAddress (Address),
StartBit,
@@ -488,7 +540,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 0xFF Invalid PCI address.
+ @retval other The read value from the PCI configuration register.
**/
UINT16
@@ -497,6 +550,9 @@ PciExpressRead16 (
IN UINTN Address
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioRead16 (GetPciExpressAddress (Address));
}
@@ -514,7 +570,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
@@ -524,6 +581,9 @@ PciExpressWrite16 (
IN UINT16 Value
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioWrite16 (GetPciExpressAddress (Address), Value);
}
@@ -545,7 +605,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
@@ -555,6 +616,9 @@ PciExpressOr16 (
IN UINT16 OrData
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioOr16 (GetPciExpressAddress (Address), OrData);
}
@@ -576,7 +640,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
@@ -586,6 +651,9 @@ PciExpressAnd16 (
IN UINT16 AndData
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioAnd16 (GetPciExpressAddress (Address), AndData);
}
@@ -609,7 +677,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
@@ -620,6 +689,9 @@ PciExpressAndThenOr16 (
IN UINT16 OrData
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioAndThenOr16 (
GetPciExpressAddress (Address),
AndData,
@@ -646,7 +718,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
@@ -657,6 +730,9 @@ PciExpressBitFieldRead16 (
IN UINTN EndBit
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioBitFieldRead16 (
GetPciExpressAddress (Address),
StartBit,
@@ -686,7 +762,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
@@ -698,6 +775,9 @@ PciExpressBitFieldWrite16 (
IN UINT16 Value
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioBitFieldWrite16 (
GetPciExpressAddress (Address),
StartBit,
@@ -731,7 +811,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
@@ -743,6 +824,9 @@ PciExpressBitFieldOr16 (
IN UINT16 OrData
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioBitFieldOr16 (
GetPciExpressAddress (Address),
StartBit,
@@ -776,7 +860,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
@@ -788,6 +873,9 @@ PciExpressBitFieldAnd16 (
IN UINT16 AndData
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioBitFieldAnd16 (
GetPciExpressAddress (Address),
StartBit,
@@ -825,7 +913,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
@@ -838,6 +927,9 @@ PciExpressBitFieldAndThenOr16 (
IN UINT16 OrData
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT16) -1;
+ }
return MmioBitFieldAndThenOr16 (
GetPciExpressAddress (Address),
StartBit,
@@ -860,7 +952,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 0xFFFFFFFF Invalid PCI address.
+ @retval other The read value from the PCI configuration register.
**/
UINT32
@@ -869,6 +962,9 @@ PciExpressRead32 (
IN UINTN Address
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioRead32 (GetPciExpressAddress (Address));
}
@@ -886,7 +982,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
@@ -896,6 +993,9 @@ PciExpressWrite32 (
IN UINT32 Value
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioWrite32 (GetPciExpressAddress (Address), Value);
}
@@ -917,7 +1017,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
@@ -927,6 +1028,9 @@ PciExpressOr32 (
IN UINT32 OrData
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioOr32 (GetPciExpressAddress (Address), OrData);
}
@@ -948,7 +1052,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
@@ -958,6 +1063,9 @@ PciExpressAnd32 (
IN UINT32 AndData
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioAnd32 (GetPciExpressAddress (Address), AndData);
}
@@ -981,7 +1089,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
@@ -992,6 +1101,9 @@ PciExpressAndThenOr32 (
IN UINT32 OrData
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioAndThenOr32 (
GetPciExpressAddress (Address),
AndData,
@@ -1018,7 +1130,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
@@ -1029,6 +1142,9 @@ PciExpressBitFieldRead32 (
IN UINTN EndBit
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioBitFieldRead32 (
GetPciExpressAddress (Address),
StartBit,
@@ -1058,7 +1174,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
@@ -1070,6 +1187,9 @@ PciExpressBitFieldWrite32 (
IN UINT32 Value
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioBitFieldWrite32 (
GetPciExpressAddress (Address),
StartBit,
@@ -1103,7 +1223,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
@@ -1115,6 +1236,9 @@ PciExpressBitFieldOr32 (
IN UINT32 OrData
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioBitFieldOr32 (
GetPciExpressAddress (Address),
StartBit,
@@ -1148,7 +1272,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
@@ -1160,6 +1285,9 @@ PciExpressBitFieldAnd32 (
IN UINT32 AndData
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioBitFieldAnd32 (
GetPciExpressAddress (Address),
StartBit,
@@ -1197,7 +1325,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
@@ -1210,6 +1339,9 @@ PciExpressBitFieldAndThenOr32 (
IN UINT32 OrData
)
{
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINT32) -1;
+ }
return MmioBitFieldAndThenOr32 (
GetPciExpressAddress (Address),
StartBit,
@@ -1239,7 +1371,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 (UINTN)-1 Invalid PCI address.
+ @retval other Size read data from StartAddress.
**/
UINTN
@@ -1258,6 +1391,13 @@ PciExpressReadBuffer (
ASSERT_INVALID_PCI_ADDRESS (StartAddress);
ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);
+ //
+ // Make sure the Address is in MMCONF address space
+ //
+ if (StartAddress >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINTN) -1;
+ }
+
if (Size == 0) {
return Size;
}
@@ -1342,7 +1482,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 (UINTN)-1 Invalid PCI address.
+ @retval other Size written to StartAddress.
**/
UINTN
@@ -1361,6 +1502,13 @@ PciExpressWriteBuffer (
ASSERT_INVALID_PCI_ADDRESS (StartAddress);
ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);
+ //
+ // Make sure the Address is in MMCONF address space
+ //
+ if (StartAddress >= mSmmPciExpressLibPciExpressBaseSize) {
+ return (UINTN) -1;
+ }
+
if (Size == 0) {
return 0;