#include <Library/PcdLib.h>\r
\r
///\r
-/// Module global that contains the base physical address of the PCI Express MMIO range.\r
+/// Module global that contains the base physical address and size of the PCI Express MMIO range.\r
///\r
UINTN mSmmPciExpressLibPciExpressBaseAddress = 0;\r
+UINTN mSmmPciExpressLibPciExpressBaseSize = 0;\r
\r
/**\r
The constructor function caches the PCI Express Base Address\r
)\r
{\r
//\r
- // Cache the physical address of the PCI Express MMIO range into a module global variable\r
+ // Cache the physical address and size of the PCI Express MMIO range into a module global variable\r
//\r
mSmmPciExpressLibPciExpressBaseAddress = (UINTN) PcdGet64 (PcdPciExpressBaseAddress);\r
+ mSmmPciExpressLibPciExpressBaseSize = (UINTN) PcdGet64 (PcdPciExpressBaseSize);\r
\r
return EFI_SUCCESS;\r
}\r
mSmmPciExpressLibPciExpressBaseAddress is initialized in the library constructor from PCD entry\r
PcdPciExpressBaseAddress.\r
\r
+ If Address > 0x0FFFFFFF, then ASSERT().\r
+\r
@param Address The address that encodes the PCI Bus, Device, Function and Register.\r
- @return MMIO address corresponding to Address.\r
+\r
+ @retval (UINTN)-1 Invalid PCI address.\r
+ @retval other MMIO address corresponding to Address.\r
\r
**/\r
UINTN\r
// Make sure Address is valid\r
//\r
ASSERT_INVALID_PCI_ADDRESS (Address);\r
+ //\r
+ // Make sure the Address is in MMCONF address space\r
+ //\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINTN) -1;\r
+ }\r
return mSmmPciExpressLibPciExpressBaseAddress + Address;\r
}\r
\r
@param Address The address that encodes the PCI Bus, Device, Function and\r
Register.\r
\r
- @return The read value from the PCI configuration register.\r
+ @retval 0xFF Invalid PCI address.\r
+ @retval other The read value from the PCI configuration register.\r
\r
**/\r
UINT8\r
IN UINTN Address\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT8) -1;\r
+ }\r
return MmioRead8 (GetPciExpressAddress (Address));\r
}\r
\r
Register.\r
@param Value The value to write.\r
\r
- @return The value written to the PCI configuration register.\r
+ @retval 0xFF Invalid PCI address.\r
+ @retval other The value written to the PCI configuration register.\r
\r
**/\r
UINT8\r
IN UINT8 Value\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT8) -1;\r
+ }\r
return MmioWrite8 (GetPciExpressAddress (Address), Value);\r
}\r
\r
Register.\r
@param OrData The value to OR with the PCI configuration register.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT8\r
IN UINT8 OrData\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT8) -1;\r
+ }\r
return MmioOr8 (GetPciExpressAddress (Address), OrData);\r
}\r
\r
Register.\r
@param AndData The value to AND with the PCI configuration register.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT8\r
IN UINT8 AndData\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT8) -1;\r
+ }\r
return MmioAnd8 (GetPciExpressAddress (Address), AndData);\r
}\r
\r
@param AndData The value to AND with the PCI configuration register.\r
@param OrData The value to OR with the result of the AND operation.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT8\r
IN UINT8 OrData\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT8) -1;\r
+ }\r
return MmioAndThenOr8 (\r
GetPciExpressAddress (Address),\r
AndData,\r
@param EndBit The ordinal of the most significant bit in the bit field.\r
Range 0..7.\r
\r
- @return The value of the bit field read from the PCI configuration register.\r
+ @retval 0xFF Invalid PCI address.\r
+ @retval other The value of the bit field read from the PCI configuration register.\r
\r
**/\r
UINT8\r
IN UINTN EndBit\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT8) -1;\r
+ }\r
return MmioBitFieldRead8 (\r
GetPciExpressAddress (Address),\r
StartBit,\r
Range 0..7.\r
@param Value The new value of the bit field.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT8\r
IN UINT8 Value\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT8) -1;\r
+ }\r
return MmioBitFieldWrite8 (\r
GetPciExpressAddress (Address),\r
StartBit,\r
Range 0..7.\r
@param OrData The value to OR with the PCI configuration register.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT8\r
IN UINT8 OrData\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT8) -1;\r
+ }\r
return MmioBitFieldOr8 (\r
GetPciExpressAddress (Address),\r
StartBit,\r
Range 0..7.\r
@param AndData The value to AND with the PCI configuration register.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT8\r
IN UINT8 AndData\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT8) -1;\r
+ }\r
return MmioBitFieldAnd8 (\r
GetPciExpressAddress (Address),\r
StartBit,\r
@param AndData The value to AND with the PCI configuration register.\r
@param OrData The value to OR with the result of the AND operation.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT8\r
IN UINT8 OrData\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT8) -1;\r
+ }\r
return MmioBitFieldAndThenOr8 (\r
GetPciExpressAddress (Address),\r
StartBit,\r
@param Address The address that encodes the PCI Bus, Device, Function and\r
Register.\r
\r
- @return The read value from the PCI configuration register.\r
+ @retval 0xFF Invalid PCI address.\r
+ @retval other The read value from the PCI configuration register.\r
\r
**/\r
UINT16\r
IN UINTN Address\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT16) -1;\r
+ }\r
return MmioRead16 (GetPciExpressAddress (Address));\r
}\r
\r
Register.\r
@param Value The value to write.\r
\r
- @return The value written to the PCI configuration register.\r
+ @retval 0xFFFF Invalid PCI address.\r
+ @retval other The value written to the PCI configuration register.\r
\r
**/\r
UINT16\r
IN UINT16 Value\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT16) -1;\r
+ }\r
return MmioWrite16 (GetPciExpressAddress (Address), Value);\r
}\r
\r
Register.\r
@param OrData The value to OR with the PCI configuration register.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFFFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT16\r
IN UINT16 OrData\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT16) -1;\r
+ }\r
return MmioOr16 (GetPciExpressAddress (Address), OrData);\r
}\r
\r
Register.\r
@param AndData The value to AND with the PCI configuration register.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFFFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT16\r
IN UINT16 AndData\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT16) -1;\r
+ }\r
return MmioAnd16 (GetPciExpressAddress (Address), AndData);\r
}\r
\r
@param AndData The value to AND with the PCI configuration register.\r
@param OrData The value to OR with the result of the AND operation.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFFFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT16\r
IN UINT16 OrData\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT16) -1;\r
+ }\r
return MmioAndThenOr16 (\r
GetPciExpressAddress (Address),\r
AndData,\r
@param EndBit The ordinal of the most significant bit in the bit field.\r
Range 0..15.\r
\r
- @return The value of the bit field read from the PCI configuration register.\r
+ @retval 0xFFFF Invalid PCI address.\r
+ @retval other The value of the bit field read from the PCI configuration register.\r
\r
**/\r
UINT16\r
IN UINTN EndBit\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT16) -1;\r
+ }\r
return MmioBitFieldRead16 (\r
GetPciExpressAddress (Address),\r
StartBit,\r
Range 0..15.\r
@param Value The new value of the bit field.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFFFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT16\r
IN UINT16 Value\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT16) -1;\r
+ }\r
return MmioBitFieldWrite16 (\r
GetPciExpressAddress (Address),\r
StartBit,\r
Range 0..15.\r
@param OrData The value to OR with the PCI configuration register.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFFFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT16\r
IN UINT16 OrData\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT16) -1;\r
+ }\r
return MmioBitFieldOr16 (\r
GetPciExpressAddress (Address),\r
StartBit,\r
Range 0..15.\r
@param AndData The value to AND with the PCI configuration register.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFFFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT16\r
IN UINT16 AndData\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT16) -1;\r
+ }\r
return MmioBitFieldAnd16 (\r
GetPciExpressAddress (Address),\r
StartBit,\r
@param AndData The value to AND with the PCI configuration register.\r
@param OrData The value to OR with the result of the AND operation.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFFFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT16\r
IN UINT16 OrData\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT16) -1;\r
+ }\r
return MmioBitFieldAndThenOr16 (\r
GetPciExpressAddress (Address),\r
StartBit,\r
@param Address The address that encodes the PCI Bus, Device, Function and\r
Register.\r
\r
- @return The read value from the PCI configuration register.\r
+ @retval 0xFFFFFFFF Invalid PCI address.\r
+ @retval other The read value from the PCI configuration register.\r
\r
**/\r
UINT32\r
IN UINTN Address\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT32) -1;\r
+ }\r
return MmioRead32 (GetPciExpressAddress (Address));\r
}\r
\r
Register.\r
@param Value The value to write.\r
\r
- @return The value written to the PCI configuration register.\r
+ @retval 0xFFFFFFFF Invalid PCI address.\r
+ @retval other The value written to the PCI configuration register.\r
\r
**/\r
UINT32\r
IN UINT32 Value\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT32) -1;\r
+ }\r
return MmioWrite32 (GetPciExpressAddress (Address), Value);\r
}\r
\r
Register.\r
@param OrData The value to OR with the PCI configuration register.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFFFFFFFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT32\r
IN UINT32 OrData\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT32) -1;\r
+ }\r
return MmioOr32 (GetPciExpressAddress (Address), OrData);\r
}\r
\r
Register.\r
@param AndData The value to AND with the PCI configuration register.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFFFFFFFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT32\r
IN UINT32 AndData\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT32) -1;\r
+ }\r
return MmioAnd32 (GetPciExpressAddress (Address), AndData);\r
}\r
\r
@param AndData The value to AND with the PCI configuration register.\r
@param OrData The value to OR with the result of the AND operation.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFFFFFFFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT32\r
IN UINT32 OrData\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT32) -1;\r
+ }\r
return MmioAndThenOr32 (\r
GetPciExpressAddress (Address),\r
AndData,\r
@param EndBit The ordinal of the most significant bit in the bit field.\r
Range 0..31.\r
\r
- @return The value of the bit field read from the PCI configuration register.\r
+ @retval 0xFFFFFFFF Invalid PCI address.\r
+ @retval other The value of the bit field read from the PCI configuration register.\r
\r
**/\r
UINT32\r
IN UINTN EndBit\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT32) -1;\r
+ }\r
return MmioBitFieldRead32 (\r
GetPciExpressAddress (Address),\r
StartBit,\r
Range 0..31.\r
@param Value The new value of the bit field.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFFFFFFFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT32\r
IN UINT32 Value\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT32) -1;\r
+ }\r
return MmioBitFieldWrite32 (\r
GetPciExpressAddress (Address),\r
StartBit,\r
Range 0..31.\r
@param OrData The value to OR with the PCI configuration register.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFFFFFFFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT32\r
IN UINT32 OrData\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT32) -1;\r
+ }\r
return MmioBitFieldOr32 (\r
GetPciExpressAddress (Address),\r
StartBit,\r
Range 0..31.\r
@param AndData The value to AND with the PCI configuration register.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFFFFFFFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT32\r
IN UINT32 AndData\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT32) -1;\r
+ }\r
return MmioBitFieldAnd32 (\r
GetPciExpressAddress (Address),\r
StartBit,\r
@param AndData The value to AND with the PCI configuration register.\r
@param OrData The value to OR with the result of the AND operation.\r
\r
- @return The value written back to the PCI configuration register.\r
+ @retval 0xFFFFFFFF Invalid PCI address.\r
+ @retval other The value written back to the PCI configuration register.\r
\r
**/\r
UINT32\r
IN UINT32 OrData\r
)\r
{\r
+ if (Address >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINT32) -1;\r
+ }\r
return MmioBitFieldAndThenOr32 (\r
GetPciExpressAddress (Address),\r
StartBit,\r
@param Size The size in bytes of the transfer.\r
@param Buffer The pointer to a buffer receiving the data read.\r
\r
- @return Size read data from StartAddress.\r
+ @retval (UINTN)-1 Invalid PCI address.\r
+ @retval other Size read data from StartAddress.\r
\r
**/\r
UINTN\r
ASSERT_INVALID_PCI_ADDRESS (StartAddress);\r
ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);\r
\r
+ //\r
+ // Make sure the Address is in MMCONF address space\r
+ //\r
+ if (StartAddress >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINTN) -1;\r
+ }\r
+\r
if (Size == 0) {\r
return Size;\r
}\r
@param Size The size in bytes of the transfer.\r
@param Buffer The pointer to a buffer containing the data to write.\r
\r
- @return Size written to StartAddress.\r
+ @retval (UINTN)-1 Invalid PCI address.\r
+ @retval other Size written to StartAddress.\r
\r
**/\r
UINTN\r
ASSERT_INVALID_PCI_ADDRESS (StartAddress);\r
ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);\r
\r
+ //\r
+ // Make sure the Address is in MMCONF address space\r
+ //\r
+ if (StartAddress >= mSmmPciExpressLibPciExpressBaseSize) {\r
+ return (UINTN) -1;\r
+ }\r
+\r
\r
if (Size == 0) {\r
return 0;\r