]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BasePciCf8Lib/PciLib.c
Cleanup MdePkg.dsc, UefiLib.inf and UefiLib.msa
[mirror_edk2.git] / MdePkg / Library / BasePciCf8Lib / PciLib.c
index 108c95291c0da95863c34c73c030741f43573f4c..77676b7eb7558ff345c51b0a0e4516e7d798e0de 100644 (file)
 \r
 **/\r
 \r
+//\r
+// Include common header file for this module.\r
+//\r
+#include "CommonHeader.h"\r
+\r
 //\r
 // Declare I/O Ports used to perform PCI Confguration Cycles\r
 //\r
@@ -237,7 +242,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 +282,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 +328,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 +374,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 +422,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 +644,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 +685,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 +732,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 +779,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 +828,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 +1050,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 +1091,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 +1138,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 +1185,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 +1234,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 +1282,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
@@ -1296,59 +1300,70 @@ PciCf8ReadBuffer (
   OUT     VOID                      *Buffer\r
   )\r
 {\r
-  UINTN                             EndAddress;\r
+  UINTN                             ReturnValue;\r
 \r
   ASSERT_INVALID_PCI_ADDRESS (StartAddress, 0);\r
-  ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);\r
-  ASSERT ((StartAddress + Size - 1) <= 0x0FFFFFFF);\r
+  ASSERT (((StartAddress & 0xFFF) + Size) <= 0x100);\r
+\r
+  if (Size == 0) {\r
+    return Size;\r
+  }\r
+\r
   ASSERT (Buffer != NULL);\r
 \r
-  EndAddress = StartAddress + Size;\r
+  //\r
+  // Save Size for return\r
+  //\r
+  ReturnValue = 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
-    *(UINT8*)Buffer = PciCf8Read8 (StartAddress);\r
+    *(volatile UINT8 *)Buffer = PciCf8Read8 (StartAddress);\r
     StartAddress += sizeof (UINT8);\r
+    Size -= sizeof (UINT8);\r
     Buffer = (UINT8*)Buffer + 1;\r
   }\r
 \r
-  if (StartAddress < EndAddress && (StartAddress & 2)) {\r
+  if (Size >= sizeof (UINT16) && (StartAddress & 2) != 0) {\r
     //\r
     // Read a word if StartAddress is word aligned\r
     //\r
-    *(UINT16*)Buffer = PciCf8Read16 (StartAddress);\r
+    *(volatile UINT16 *)Buffer = PciCf8Read16 (StartAddress);\r
     StartAddress += sizeof (UINT16);\r
+    Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
   }\r
 \r
-  while (EndAddress - StartAddress >= 4) {\r
+  while (Size >= sizeof (UINT32)) {\r
     //\r
     // Read as many double words as possible\r
     //\r
-    *(UINT32*)Buffer = PciCf8Read32 (StartAddress);\r
+    *(volatile UINT32 *)Buffer = PciCf8Read32 (StartAddress);\r
     StartAddress += sizeof (UINT32);\r
+    Size -= sizeof (UINT32);\r
     Buffer = (UINT32*)Buffer + 1;\r
   }\r
 \r
-  if ((EndAddress & 2) != 0) {\r
+  if (Size >= sizeof (UINT16)) {\r
     //\r
     // Read the last remaining word if exist\r
     //\r
-    *(UINT16*)Buffer = PciCf8Read16 (StartAddress);\r
+    *(volatile UINT16 *)Buffer = PciCf8Read16 (StartAddress);\r
     StartAddress += sizeof (UINT16);\r
+    Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
   }\r
 \r
-  if (EndAddress & 1) {\r
+  if (Size >= sizeof (UINT8)) {\r
     //\r
     // Read the last remaining byte if exist\r
     //\r
-    *(UINT8*)Buffer = PciCf8Read8 (StartAddress);\r
+    *(volatile UINT8 *)Buffer = PciCf8Read8 (StartAddress);\r
   }\r
 \r
-  return Size;\r
+  return ReturnValue;\r
 }\r
 \r
 /**\r
@@ -1366,8 +1381,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
@@ -1385,57 +1399,68 @@ PciCf8WriteBuffer (
   IN      VOID                      *Buffer\r
   )\r
 {\r
-  UINTN                             EndAddress;\r
+  UINTN                             ReturnValue;\r
 \r
   ASSERT_INVALID_PCI_ADDRESS (StartAddress, 0);\r
-  ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);\r
-  ASSERT ((StartAddress + Size - 1) <= 0x0FFFFFFF);\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
+  // Save Size for return\r
+  //\r
+  ReturnValue = 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
     PciCf8Write8 (StartAddress, *(UINT8*)Buffer);\r
     StartAddress += sizeof (UINT8);\r
+    Size -= sizeof (UINT8);\r
     Buffer = (UINT8*)Buffer + 1;\r
   }\r
 \r
-  if (StartAddress < EndAddress && (StartAddress & 2)) {\r
+  if (Size >= sizeof (UINT16) && (StartAddress & 2) != 0) {\r
     //\r
     // Write a word if StartAddress is word aligned\r
     //\r
     PciCf8Write16 (StartAddress, *(UINT16*)Buffer);\r
     StartAddress += sizeof (UINT16);\r
+    Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
   }\r
 \r
-  while (EndAddress - StartAddress >= 4) {\r
+  while (Size >= sizeof (UINT32)) {\r
     //\r
     // Write as many double words as possible\r
     //\r
     PciCf8Write32 (StartAddress, *(UINT32*)Buffer);\r
     StartAddress += sizeof (UINT32);\r
+    Size -= sizeof (UINT32);\r
     Buffer = (UINT32*)Buffer + 1;\r
   }\r
 \r
-  if (EndAddress & 2) {\r
+  if (Size >= sizeof (UINT16)) {\r
     //\r
     // Write the last remaining word if exist\r
     //\r
     PciCf8Write16 (StartAddress, *(UINT16*)Buffer);\r
     StartAddress += sizeof (UINT16);\r
+    Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
   }\r
 \r
-  if (EndAddress & 1) {\r
+  if (Size >= sizeof (UINT8)) {\r
     //\r
     // Write the last remaining byte if exist\r
     //\r
     PciCf8Write8 (StartAddress, *(UINT8*)Buffer);\r
   }\r
 \r
-  return Size;\r
+  return ReturnValue;\r
 }\r