]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BasePciCf8Lib/PciLib.c
PciLib:
[mirror_edk2.git] / MdePkg / Library / BasePciCf8Lib / PciLib.c
index 2f82fbe2c8a6ece88bab53a0007ff6425547ad7f..9421d8b99d3cb4ba942e8153491d08901e33265e 100644 (file)
@@ -237,7 +237,7 @@ PciCf8AndThenOr8 (
   If the register specified by Address >= 0x100, then ASSERT().\r
   If StartBit is greater than 7, then ASSERT().\r
   If EndBit is greater than 7, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Address   PCI configuration register to read.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -277,7 +277,7 @@ PciCf8BitFieldRead8 (
   If the register specified by Address >= 0x100, then ASSERT().\r
   If StartBit is greater than 7, then ASSERT().\r
   If EndBit is greater than 7, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Address   PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -323,7 +323,7 @@ PciCf8BitFieldWrite8 (
   If the register specified by Address >= 0x100, then ASSERT().\r
   If StartBit is greater than 7, then ASSERT().\r
   If EndBit is greater than 7, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Address   PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -369,7 +369,7 @@ PciCf8BitFieldOr8 (
   If the register specified by Address >= 0x100, then ASSERT().\r
   If StartBit is greater than 7, then ASSERT().\r
   If EndBit is greater than 7, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Address   PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -417,7 +417,7 @@ PciCf8BitFieldAnd8 (
   If the register specified by Address >= 0x100, then ASSERT().\r
   If StartBit is greater than 7, then ASSERT().\r
   If EndBit is greater than 7, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Address   PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -639,7 +639,7 @@ PciCf8AndThenOr16 (
   If the register specified by Address >= 0x100, then ASSERT().\r
   If StartBit is greater than 15, then ASSERT().\r
   If EndBit is greater than 15, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Address   PCI configuration register to read.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -680,7 +680,7 @@ PciCf8BitFieldRead16 (
   If the register specified by Address >= 0x100, then ASSERT().\r
   If StartBit is greater than 15, then ASSERT().\r
   If EndBit is greater than 15, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Address   PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -727,7 +727,7 @@ PciCf8BitFieldWrite16 (
   If the register specified by Address >= 0x100, then ASSERT().\r
   If StartBit is greater than 15, then ASSERT().\r
   If EndBit is greater than 15, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Address   PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -774,7 +774,7 @@ PciCf8BitFieldOr16 (
   If the register specified by Address >= 0x100, then ASSERT().\r
   If StartBit is greater than 15, then ASSERT().\r
   If EndBit is greater than 15, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Address   PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -823,7 +823,7 @@ PciCf8BitFieldAnd16 (
   If the register specified by Address >= 0x100, then ASSERT().\r
   If StartBit is greater than 15, then ASSERT().\r
   If EndBit is greater than 15, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Address   PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -1045,7 +1045,7 @@ PciCf8AndThenOr32 (
   If the register specified by Address >= 0x100, then ASSERT().\r
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Address   PCI configuration register to read.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -1086,7 +1086,7 @@ PciCf8BitFieldRead32 (
   If the register specified by Address >= 0x100, then ASSERT().\r
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Address   PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -1133,7 +1133,7 @@ PciCf8BitFieldWrite32 (
   If the register specified by Address >= 0x100, then ASSERT().\r
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Address   PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -1180,7 +1180,7 @@ PciCf8BitFieldOr32 (
   If the register specified by Address >= 0x100, then ASSERT().\r
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Address   PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -1229,7 +1229,7 @@ PciCf8BitFieldAnd32 (
   If the register specified by Address >= 0x100, then ASSERT().\r
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
-  If EndBit is less than or equal to StartBit, then ASSERT().\r
+  If EndBit is less than StartBit, then ASSERT().\r
 \r
   @param  Address   PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
@@ -1277,8 +1277,7 @@ PciCf8BitFieldAndThenOr32(
   If StartAddress > 0x0FFFFFFF, then ASSERT().\r
   If the register specified by StartAddress >= 0x100, then ASSERT().\r
   If ((StartAddress & 0xFFF) + Size) > 0x100, then ASSERT().\r
-  If (StartAddress + Size - 1)  > 0x0FFFFFFF, then ASSERT().\r
-  If Buffer is NULL, then ASSERT().\r
+  If Size > 0 and Buffer is NULL, then ASSERT().\r
 \r
   @param  StartAddress  Starting address that encodes the PCI Bus, Device,\r
                         Function and Register.\r
@@ -1299,11 +1298,17 @@ PciCf8ReadBuffer (
   UINTN                             EndAddress;\r
 \r
   ASSERT_INVALID_PCI_ADDRESS (StartAddress, 0);\r
+  ASSERT (((StartAddress & 0xFFF) + Size) <= 0x100);\r
+\r
+  if (Size == 0) {\r
+    return 0;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
 \r
   EndAddress = StartAddress + Size;\r
 \r
-  if (StartAddress < EndAddress && (StartAddress & 1)) {\r
+  if ((StartAddress & 1) != 0) {\r
     //\r
     // Read a byte if StartAddress is byte aligned\r
     //\r
@@ -1312,7 +1317,7 @@ PciCf8ReadBuffer (
     Buffer = (UINT8*)Buffer + 1;\r
   }\r
 \r
-  if (StartAddress < EndAddress && (StartAddress & 2)) {\r
+  if ((StartAddress < EndAddress) && ((StartAddress & 2) != 0)) {\r
     //\r
     // Read a word if StartAddress is word aligned\r
     //\r
@@ -1321,7 +1326,7 @@ PciCf8ReadBuffer (
     Buffer = (UINT16*)Buffer + 1;\r
   }\r
 \r
-  while (EndAddress - StartAddress >= 4) {\r
+  while ((EndAddress - StartAddress) >= 4) {\r
     //\r
     // Read as many double words as possible\r
     //\r
@@ -1339,7 +1344,7 @@ PciCf8ReadBuffer (
     Buffer = (UINT16*)Buffer + 1;\r
   }\r
 \r
-  if (EndAddress & 1) {\r
+  if ((EndAddress & 1) != 0) {\r
     //\r
     // Read the last remaining byte if exist\r
     //\r
@@ -1364,8 +1369,7 @@ PciCf8ReadBuffer (
   If StartAddress > 0x0FFFFFFF, then ASSERT().\r
   If the register specified by StartAddress >= 0x100, then ASSERT().\r
   If ((StartAddress & 0xFFF) + Size) > 0x100, then ASSERT().\r
-  If (StartAddress + Size - 1)  > 0x0FFFFFFF, then ASSERT().\r
-  If Buffer is NULL, then ASSERT().\r
+  If Size > 0 and Buffer is NULL, then ASSERT().\r
 \r
   @param  StartAddress  Starting address that encodes the PCI Bus, Device,\r
                         Function and Register.\r
@@ -1386,11 +1390,17 @@ PciCf8WriteBuffer (
   UINTN                             EndAddress;\r
 \r
   ASSERT_INVALID_PCI_ADDRESS (StartAddress, 0);\r
-  ASSERT (Buffer != NULL);\r
+  ASSERT (((StartAddress & 0xFFF) + Size) <= 0x100);\r
+\r
+  if (Size == 0) {\r
+    return 0;\r
+  }\r
+\r
+  ASSERT (Buffer != 0);\r
 \r
   EndAddress = StartAddress + Size;\r
 \r
-  if ((StartAddress < EndAddress) && ((StartAddress & 1)!= 0)) {\r
+  if ((StartAddress & 1)!= 0) {\r
     //\r
     // Write a byte if StartAddress is byte aligned\r
     //\r
@@ -1399,7 +1409,7 @@ PciCf8WriteBuffer (
     Buffer = (UINT8*)Buffer + 1;\r
   }\r
 \r
-  if (StartAddress < EndAddress && (StartAddress & 2)) {\r
+  if ((StartAddress < EndAddress) && ((StartAddress & 2) != 0)) {\r
     //\r
     // Write a word if StartAddress is word aligned\r
     //\r
@@ -1408,7 +1418,7 @@ PciCf8WriteBuffer (
     Buffer = (UINT16*)Buffer + 1;\r
   }\r
 \r
-  while (EndAddress - StartAddress >= 4) {\r
+  while ((EndAddress - StartAddress) >= 4) {\r
     //\r
     // Write as many double words as possible\r
     //\r
@@ -1417,7 +1427,7 @@ PciCf8WriteBuffer (
     Buffer = (UINT32*)Buffer + 1;\r
   }\r
 \r
-  if (EndAddress & 2) {\r
+  if ((EndAddress & 2) != 0) {\r
     //\r
     // Write the last remaining word if exist\r
     //\r
@@ -1426,7 +1436,7 @@ PciCf8WriteBuffer (
     Buffer = (UINT16*)Buffer + 1;\r
   }\r
 \r
-  if (EndAddress & 1) {\r
+  if ((EndAddress & 1) != 0) {\r
     //\r
     // Write the last remaining byte if exist\r
     //\r