]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/PeiPciLibPciCfg2/PciLib.c
MdePkg: Clean up source files
[mirror_edk2.git] / MdePkg / Library / PeiPciLibPciCfg2 / PciLib.c
index bd2c17ccdf4f8b4f6c42093f39a2c82800cdd407..4154f7abcc1ddebf59f32b3073c89a811087cf31 100644 (file)
@@ -1,13 +1,13 @@
 /** @file\r
   PCI Library using PCI CFG2 PPI.\r
 \r
-  Copyright (c) 2007 - 2008, Intel Corporation All rights\r
-  reserved. This program and the accompanying materials are\r
+  Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials are\r
   licensed and made available under the terms and conditions of\r
   the BSD License which accompanies this distribution.  The full\r
   text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-  \r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
@@ -37,7 +37,7 @@
 /**\r
   Translate PCI Lib address into format of PCI CFG2 PPI.\r
 \r
-  @param  A  Address that encodes the PCI Bus, Device, Function and\r
+  @param  A  The address that encodes the PCI Bus, Device, Function and\r
              Register.\r
 \r
 **/\r
@@ -51,9 +51,9 @@
   It reads and returns the PCI configuration register specified by Address,\r
   the width of data is specified by Width.\r
 \r
-  @param  Address Address that encodes the PCI Bus, Device, Function and\r
+  @param  Address The address that encodes the PCI Bus, Device, Function and\r
                   Register.\r
-  @param  Width   Width of data to read\r
+  @param  Width   The width of data to read\r
 \r
   @return The value read from the PCI configuration register.\r
 \r
@@ -90,12 +90,12 @@ PeiPciLibPciCfg2ReadWorker (
 \r
   This function wraps EFI_PEI_PCI_CFG2_PPI.Write() service.\r
   It writes the PCI configuration register specified by Address with the\r
-  value specified by Data. The width of data is specifed by Width.\r
+  value specified by Data. The width of data is specified by Width.\r
   Data is returned.\r
 \r
-  @param  Address Address that encodes the PCI Bus, Device, Function and\r
+  @param  Address The address that encodes the PCI Bus, Device, Function and\r
                   Register.\r
-  @param  Width   Width of data to write\r
+  @param  Width   The width of data to write\r
   @param  Data    The value to write.\r
 \r
   @return The value written to the PCI configuration register.\r
@@ -129,19 +129,19 @@ PeiPciLibPciCfg2WriteWorker (
 }\r
 \r
 /**\r
-  Registers a PCI device so PCI configuration registers may be accessed after \r
+  Registers a PCI device so PCI configuration registers may be accessed after\r
   SetVirtualAddressMap().\r
-  \r
-  Registers the PCI device specified by Address so all the PCI configuration registers \r
+\r
+  Registers the PCI device specified by Address so all the PCI configuration registers\r
   associated with that PCI device may be accessed after SetVirtualAddressMap() is called.\r
-  \r
+\r
   If Address > 0x0FFFFFFF, then ASSERT().\r
 \r
-  @param  Address Address that encodes the PCI Bus, Device, Function and\r
+  @param  Address The address that encodes the PCI Bus, Device, Function and\r
                   Register.\r
-  \r
+\r
   @retval RETURN_SUCCESS           The PCI device was registered for runtime access.\r
-  @retval RETURN_UNSUPPORTED       An attempt was made to call this function \r
+  @retval RETURN_UNSUPPORTED       An attempt was made to call this function\r
                                    after ExitBootServices().\r
   @retval RETURN_UNSUPPORTED       The resources required to access the PCI device\r
                                    at runtime could not be mapped.\r
@@ -155,6 +155,7 @@ PciRegisterForRuntimeAccess (
   IN UINTN  Address\r
   )\r
 {\r
+  ASSERT_INVALID_PCI_ADDRESS (Address, 0);\r
   return RETURN_UNSUPPORTED;\r
 }\r
 \r
@@ -167,10 +168,10 @@ PciRegisterForRuntimeAccess (
 \r
   If Address > 0x0FFFFFFF, then ASSERT().\r
 \r
-  @param  Address Address that encodes the PCI Bus, Device, Function and\r
+  @param  Address The address that encodes the PCI Bus, Device, Function and\r
                   Register.\r
 \r
-  @return The value read from the PCI configuration register.\r
+  @return The read value from the PCI configuration register.\r
 \r
 **/\r
 UINT8\r
@@ -193,9 +194,9 @@ PciRead8 (
 \r
   If Address > 0x0FFFFFFF, then ASSERT().\r
 \r
-  @param  Address Address that encodes the PCI Bus, Device, Function and\r
+  @param  Address The address that encodes the PCI Bus, Device, Function and\r
                   Register.\r
-  @param  Data    The value to write.\r
+  @param  Value   The value to write.\r
 \r
   @return The value written to the PCI configuration register.\r
 \r
@@ -204,20 +205,20 @@ UINT8
 EFIAPI\r
 PciWrite8 (\r
   IN      UINTN                     Address,\r
-  IN      UINT8                     Data\r
+  IN      UINT8                     Value\r
   )\r
 {\r
   ASSERT_INVALID_PCI_ADDRESS (Address, 0);\r
 \r
-  return (UINT8) PeiPciLibPciCfg2WriteWorker (Address, EfiPeiPciCfgWidthUint8, Data);\r
+  return (UINT8) PeiPciLibPciCfg2WriteWorker (Address, EfiPeiPciCfgWidthUint8, Value);\r
 }\r
 \r
 /**\r
-  Performs a bitwise inclusive OR of an 8-bit PCI configuration register with\r
+  Performs a bitwise OR of an 8-bit PCI configuration register with\r
   an 8-bit value.\r
 \r
   Reads the 8-bit PCI configuration register specified by Address, performs a\r
-  bitwise inclusive OR between the read result and the value specified by\r
+  bitwise OR between the read result and the value specified by\r
   OrData, and writes the result to the 8-bit PCI configuration register\r
   specified by Address. The value written to the PCI configuration register is\r
   returned. This function must guarantee that all PCI read and write operations\r
@@ -225,7 +226,7 @@ PciWrite8 (
 \r
   If Address > 0x0FFFFFFF, then ASSERT().\r
 \r
-  @param  Address Address that encodes the PCI Bus, Device, Function and\r
+  @param  Address The address that encodes the PCI Bus, Device, Function and\r
                   Register.\r
   @param  OrData  The value to OR with the PCI configuration register.\r
 \r
@@ -255,7 +256,7 @@ PciOr8 (
 \r
   If Address > 0x0FFFFFFF, then ASSERT().\r
 \r
-  @param  Address Address that encodes the PCI Bus, Device, Function and\r
+  @param  Address The address that encodes the PCI Bus, Device, Function and\r
                   Register.\r
   @param  AndData The value to AND with the PCI configuration register.\r
 \r
@@ -274,11 +275,11 @@ PciAnd8 (
 \r
 /**\r
   Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit\r
-  value, followed a  bitwise inclusive OR with another 8-bit value.\r
+  value, followed a  bitwise OR with another 8-bit value.\r
 \r
   Reads the 8-bit PCI configuration register specified by Address, performs a\r
   bitwise AND between the read result and the value specified by AndData,\r
-  performs a bitwise inclusive OR between the result of the AND operation and\r
+  performs a bitwise OR between the result of the AND operation and\r
   the value specified by OrData, and writes the result to the 8-bit PCI\r
   configuration register specified by Address. The value written to the PCI\r
   configuration register is returned. This function must guarantee that all PCI\r
@@ -286,7 +287,7 @@ PciAnd8 (
 \r
   If Address > 0x0FFFFFFF, then ASSERT().\r
 \r
-  @param  Address Address that encodes the PCI Bus, Device, Function and\r
+  @param  Address The address that encodes the PCI Bus, Device, Function and\r
                   Register.\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
@@ -317,7 +318,7 @@ PciAndThenOr8 (
   If EndBit is greater than 7, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
 \r
-  @param  Address   PCI configuration register to read.\r
+  @param  Address   The PCI configuration register to read.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..7.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
@@ -349,13 +350,14 @@ PciBitFieldRead8 (
   If StartBit is greater than 7, then ASSERT().\r
   If EndBit is greater than 7, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
-  @param  Address   PCI configuration register to write.\r
+  @param  Address   The PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..7.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
                     Range 0..7.\r
-  @param  Value     New value of the bit field.\r
+  @param  Value     The new value of the bit field.\r
 \r
   @return The value written back to the PCI configuration register.\r
 \r
@@ -380,7 +382,7 @@ PciBitFieldWrite8 (
   writes the result back to the bit field in the 8-bit port.\r
 \r
   Reads the 8-bit PCI configuration register specified by Address, performs a\r
-  bitwise inclusive OR between the read result and the value specified by\r
+  bitwise OR between the read result and the value specified by\r
   OrData, and writes the result to the 8-bit PCI configuration register\r
   specified by Address. The value written to the PCI configuration register is\r
   returned. This function must guarantee that all PCI read and write operations\r
@@ -390,8 +392,9 @@ PciBitFieldWrite8 (
   If StartBit is greater than 7, then ASSERT().\r
   If EndBit is greater than 7, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
-  @param  Address   PCI configuration register to write.\r
+  @param  Address   The PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..7.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
@@ -431,8 +434,9 @@ PciBitFieldOr8 (
   If StartBit is greater than 7, then ASSERT().\r
   If EndBit is greater than 7, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
-  @param  Address   PCI configuration register to write.\r
+  @param  Address   The PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..7.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
@@ -459,11 +463,11 @@ PciBitFieldAnd8 (
 \r
 /**\r
   Reads a bit field in an 8-bit port, performs a bitwise AND followed by a\r
-  bitwise inclusive OR, and writes the result back to the bit field in the\r
+  bitwise OR, and writes the result back to the bit field in the\r
   8-bit port.\r
 \r
   Reads the 8-bit PCI configuration register specified by Address, performs a\r
-  bitwise AND followed by a bitwise inclusive OR between the read result and\r
+  bitwise AND followed by a bitwise OR between the read result and\r
   the value specified by AndData, and writes the result to the 8-bit PCI\r
   configuration register specified by Address. The value written to the PCI\r
   configuration register is returned. This function must guarantee that all PCI\r
@@ -474,8 +478,10 @@ PciBitFieldAnd8 (
   If StartBit is greater than 7, then ASSERT().\r
   If EndBit is greater than 7, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
-  @param  Address   PCI configuration register to write.\r
+  @param  Address   The PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..7.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
@@ -512,7 +518,7 @@ PciBitFieldAndThenOr8 (
   If Address > 0x0FFFFFFF, then ASSERT().\r
   If Address is not aligned on a 16-bit boundary, then ASSERT().\r
 \r
-  @param  Address Address that encodes the PCI Bus, Device, Function and\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
@@ -539,7 +545,7 @@ PciRead16 (
   If Address > 0x0FFFFFFF, then ASSERT().\r
   If Address is not aligned on a 16-bit boundary, then ASSERT().\r
 \r
-  @param  Address Address that encodes the PCI Bus, Device, Function and\r
+  @param  Address The address that encodes the PCI Bus, Device, Function and\r
                   Register.\r
   @param  Value   The value to write.\r
 \r
@@ -550,20 +556,20 @@ UINT16
 EFIAPI\r
 PciWrite16 (\r
   IN      UINTN                     Address,\r
-  IN      UINT16                    Data\r
+  IN      UINT16                    Value\r
   )\r
 {\r
   ASSERT_INVALID_PCI_ADDRESS (Address, 1);\r
 \r
-  return (UINT16) PeiPciLibPciCfg2WriteWorker (Address, EfiPeiPciCfgWidthUint16, Data);\r
+  return (UINT16) PeiPciLibPciCfg2WriteWorker (Address, EfiPeiPciCfgWidthUint16, Value);\r
 }\r
 \r
 /**\r
-  Performs a bitwise inclusive OR of a 16-bit PCI configuration register with\r
+  Performs a bitwise OR of a 16-bit PCI configuration register with\r
   a 16-bit value.\r
 \r
   Reads the 16-bit PCI configuration register specified by Address, performs a\r
-  bitwise inclusive OR between the read result and the value specified by\r
+  bitwise OR between the read result and the value specified by\r
   OrData, and writes the result to the 16-bit PCI configuration register\r
   specified by Address. The value written to the PCI configuration register is\r
   returned. This function must guarantee that all PCI read and write operations\r
@@ -572,7 +578,7 @@ PciWrite16 (
   If Address > 0x0FFFFFFF, then ASSERT().\r
   If Address is not aligned on a 16-bit boundary, then ASSERT().\r
 \r
-  @param  Address Address that encodes the PCI Bus, Device, Function and\r
+  @param  Address The address that encodes the PCI Bus, Device, Function and\r
                   Register.\r
   @param  OrData  The value to OR with the PCI configuration register.\r
 \r
@@ -603,7 +609,7 @@ PciOr16 (
   If Address > 0x0FFFFFFF, then ASSERT().\r
   If Address is not aligned on a 16-bit boundary, then ASSERT().\r
 \r
-  @param  Address Address that encodes the PCI Bus, Device, Function and\r
+  @param  Address The address that encodes the PCI Bus, Device, Function and\r
                   Register.\r
   @param  AndData The value to AND with the PCI configuration register.\r
 \r
@@ -622,11 +628,11 @@ PciAnd16 (
 \r
 /**\r
   Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit\r
-  value, followed a  bitwise inclusive OR with another 16-bit value.\r
+  value, followed a  bitwise OR with another 16-bit value.\r
 \r
   Reads the 16-bit PCI configuration register specified by Address, performs a\r
   bitwise AND between the read result and the value specified by AndData,\r
-  performs a bitwise inclusive OR between the result of the AND operation and\r
+  performs a bitwise OR between the result of the AND operation and\r
   the value specified by OrData, and writes the result to the 16-bit PCI\r
   configuration register specified by Address. The value written to the PCI\r
   configuration register is returned. This function must guarantee that all PCI\r
@@ -635,7 +641,7 @@ PciAnd16 (
   If Address > 0x0FFFFFFF, then ASSERT().\r
   If Address is not aligned on a 16-bit boundary, then ASSERT().\r
 \r
-  @param  Address Address that encodes the PCI Bus, Device, Function and\r
+  @param  Address The address that encodes the PCI Bus, Device, Function and\r
                   Register.\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
@@ -667,7 +673,7 @@ PciAndThenOr16 (
   If EndBit is greater than 15, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
 \r
-  @param  Address   PCI configuration register to read.\r
+  @param  Address   The PCI configuration register to read.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..15.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
@@ -700,13 +706,14 @@ PciBitFieldRead16 (
   If StartBit is greater than 15, then ASSERT().\r
   If EndBit is greater than 15, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
-  @param  Address   PCI configuration register to write.\r
+  @param  Address   The PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..15.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
                     Range 0..15.\r
-  @param  Value     New value of the bit field.\r
+  @param  Value     The new value of the bit field.\r
 \r
   @return The value written back to the PCI configuration register.\r
 \r
@@ -731,7 +738,7 @@ PciBitFieldWrite16 (
   writes the result back to the bit field in the 16-bit port.\r
 \r
   Reads the 16-bit PCI configuration register specified by Address, performs a\r
-  bitwise inclusive OR between the read result and the value specified by\r
+  bitwise OR between the read result and the value specified by\r
   OrData, and writes the result to the 16-bit PCI configuration register\r
   specified by Address. The value written to the PCI configuration register is\r
   returned. This function must guarantee that all PCI read and write operations\r
@@ -742,8 +749,9 @@ PciBitFieldWrite16 (
   If StartBit is greater than 15, then ASSERT().\r
   If EndBit is greater than 15, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
-  @param  Address   PCI configuration register to write.\r
+  @param  Address   The PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..15.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
@@ -784,8 +792,9 @@ PciBitFieldOr16 (
   If StartBit is greater than 15, then ASSERT().\r
   If EndBit is greater than 15, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
-  @param  Address   PCI configuration register to write.\r
+  @param  Address   The PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..15.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
@@ -812,11 +821,11 @@ PciBitFieldAnd16 (
 \r
 /**\r
   Reads a bit field in a 16-bit port, performs a bitwise AND followed by a\r
-  bitwise inclusive OR, and writes the result back to the bit field in the\r
+  bitwise OR, and writes the result back to the bit field in the\r
   16-bit port.\r
 \r
   Reads the 16-bit PCI configuration register specified by Address, performs a\r
-  bitwise AND followed by a bitwise inclusive OR between the read result and\r
+  bitwise AND followed by a bitwise OR between the read result and\r
   the value specified by AndData, and writes the result to the 16-bit PCI\r
   configuration register specified by Address. The value written to the PCI\r
   configuration register is returned. This function must guarantee that all PCI\r
@@ -828,8 +837,10 @@ PciBitFieldAnd16 (
   If StartBit is greater than 15, then ASSERT().\r
   If EndBit is greater than 15, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
-  @param  Address   PCI configuration register to write.\r
+  @param  Address   The PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..15.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
@@ -866,7 +877,7 @@ PciBitFieldAndThenOr16 (
   If Address > 0x0FFFFFFF, then ASSERT().\r
   If Address is not aligned on a 32-bit boundary, then ASSERT().\r
 \r
-  @param  Address Address that encodes the PCI Bus, Device, Function and\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
@@ -893,7 +904,7 @@ PciRead32 (
   If Address > 0x0FFFFFFF, then ASSERT().\r
   If Address is not aligned on a 32-bit boundary, then ASSERT().\r
 \r
-  @param  Address Address that encodes the PCI Bus, Device, Function and\r
+  @param  Address The address that encodes the PCI Bus, Device, Function and\r
                   Register.\r
   @param  Value   The value to write.\r
 \r
@@ -904,20 +915,20 @@ UINT32
 EFIAPI\r
 PciWrite32 (\r
   IN      UINTN                     Address,\r
-  IN      UINT32                    Data\r
+  IN      UINT32                    Value\r
   )\r
 {\r
   ASSERT_INVALID_PCI_ADDRESS (Address, 3);\r
 \r
-  return PeiPciLibPciCfg2WriteWorker (Address, EfiPeiPciCfgWidthUint32, Data);\r
+  return PeiPciLibPciCfg2WriteWorker (Address, EfiPeiPciCfgWidthUint32, Value);\r
 }\r
 \r
 /**\r
-  Performs a bitwise inclusive OR of a 32-bit PCI configuration register with\r
+  Performs a bitwise OR of a 32-bit PCI configuration register with\r
   a 32-bit value.\r
 \r
   Reads the 32-bit PCI configuration register specified by Address, performs a\r
-  bitwise inclusive OR between the read result and the value specified by\r
+  bitwise OR between the read result and the value specified by\r
   OrData, and writes the result to the 32-bit PCI configuration register\r
   specified by Address. The value written to the PCI configuration register is\r
   returned. This function must guarantee that all PCI read and write operations\r
@@ -926,7 +937,7 @@ PciWrite32 (
   If Address > 0x0FFFFFFF, then ASSERT().\r
   If Address is not aligned on a 32-bit boundary, then ASSERT().\r
 \r
-  @param  Address Address that encodes the PCI Bus, Device, Function and\r
+  @param  Address The address that encodes the PCI Bus, Device, Function and\r
                   Register.\r
   @param  OrData  The value to OR with the PCI configuration register.\r
 \r
@@ -957,7 +968,7 @@ PciOr32 (
   If Address > 0x0FFFFFFF, then ASSERT().\r
   If Address is not aligned on a 32-bit boundary, then ASSERT().\r
 \r
-  @param  Address Address that encodes the PCI Bus, Device, Function and\r
+  @param  Address The address that encodes the PCI Bus, Device, Function and\r
                   Register.\r
   @param  AndData The value to AND with the PCI configuration register.\r
 \r
@@ -976,11 +987,11 @@ PciAnd32 (
 \r
 /**\r
   Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit\r
-  value, followed a  bitwise inclusive OR with another 32-bit value.\r
+  value, followed a  bitwise OR with another 32-bit value.\r
 \r
   Reads the 32-bit PCI configuration register specified by Address, performs a\r
   bitwise AND between the read result and the value specified by AndData,\r
-  performs a bitwise inclusive OR between the result of the AND operation and\r
+  performs a bitwise OR between the result of the AND operation and\r
   the value specified by OrData, and writes the result to the 32-bit PCI\r
   configuration register specified by Address. The value written to the PCI\r
   configuration register is returned. This function must guarantee that all PCI\r
@@ -989,7 +1000,7 @@ PciAnd32 (
   If Address > 0x0FFFFFFF, then ASSERT().\r
   If Address is not aligned on a 32-bit boundary, then ASSERT().\r
 \r
-  @param  Address Address that encodes the PCI Bus, Device, Function and\r
+  @param  Address The address that encodes the PCI Bus, Device, Function and\r
                   Register.\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
@@ -1021,7 +1032,7 @@ PciAndThenOr32 (
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
 \r
-  @param  Address   PCI configuration register to read.\r
+  @param  Address   The PCI configuration register to read.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..31.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
@@ -1054,13 +1065,14 @@ PciBitFieldRead32 (
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
-  @param  Address   PCI configuration register to write.\r
+  @param  Address   The PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..31.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
                     Range 0..31.\r
-  @param  Value     New value of the bit field.\r
+  @param  Value     The new value of the bit field.\r
 \r
   @return The value written back to the PCI configuration register.\r
 \r
@@ -1085,7 +1097,7 @@ PciBitFieldWrite32 (
   writes the result back to the bit field in the 32-bit port.\r
 \r
   Reads the 32-bit PCI configuration register specified by Address, performs a\r
-  bitwise inclusive OR between the read result and the value specified by\r
+  bitwise OR between the read result and the value specified by\r
   OrData, and writes the result to the 32-bit PCI configuration register\r
   specified by Address. The value written to the PCI configuration register is\r
   returned. This function must guarantee that all PCI read and write operations\r
@@ -1096,8 +1108,9 @@ PciBitFieldWrite32 (
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
-  @param  Address   PCI configuration register to write.\r
+  @param  Address   The PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..31.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
@@ -1138,8 +1151,9 @@ PciBitFieldOr32 (
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
-  @param  Address   PCI configuration register to write.\r
+  @param  Address   The PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..31.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
@@ -1166,11 +1180,11 @@ PciBitFieldAnd32 (
 \r
 /**\r
   Reads a bit field in a 32-bit port, performs a bitwise AND followed by a\r
-  bitwise inclusive OR, and writes the result back to the bit field in the\r
+  bitwise OR, and writes the result back to the bit field in the\r
   32-bit port.\r
 \r
   Reads the 32-bit PCI configuration register specified by Address, performs a\r
-  bitwise AND followed by a bitwise inclusive OR between the read result and\r
+  bitwise AND followed by a bitwise OR between the read result and\r
   the value specified by AndData, and writes the result to the 32-bit PCI\r
   configuration register specified by Address. The value written to the PCI\r
   configuration register is returned. This function must guarantee that all PCI\r
@@ -1182,8 +1196,10 @@ PciBitFieldAnd32 (
   If StartBit is greater than 31, then ASSERT().\r
   If EndBit is greater than 31, then ASSERT().\r
   If EndBit is less than StartBit, then ASSERT().\r
+  If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
+  If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT().\r
 \r
-  @param  Address   PCI configuration register to write.\r
+  @param  Address   The PCI configuration register to write.\r
   @param  StartBit  The ordinal of the least significant bit in the bit field.\r
                     Range 0..31.\r
   @param  EndBit    The ordinal of the most significant bit in the bit field.\r
@@ -1225,10 +1241,10 @@ PciBitFieldAndThenOr32 (
   If ((StartAddress & 0xFFF) + Size) > 0x1000, 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
+  @param  StartAddress  The starting address that encodes the PCI Bus, Device,\r
                         Function and Register.\r
-  @param  Size          Size in bytes of the transfer.\r
-  @param  Buffer        Pointer to a buffer receiving the data read.\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\r
 \r
@@ -1271,7 +1287,7 @@ PciReadBuffer (
     //\r
     // Read a word if StartAddress is word aligned\r
     //\r
-    *(volatile UINT16 *)Buffer = PciRead16 (StartAddress);\r
+    WriteUnaligned16 (Buffer, PciRead16 (StartAddress));\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
@@ -1281,7 +1297,7 @@ PciReadBuffer (
     //\r
     // Read as many double words as possible\r
     //\r
-    *(volatile UINT32 *)Buffer = PciRead32 (StartAddress);\r
+    WriteUnaligned32 (Buffer, PciRead32 (StartAddress));\r
     StartAddress += sizeof (UINT32);\r
     Size -= sizeof (UINT32);\r
     Buffer = (UINT32*)Buffer + 1;\r
@@ -1291,7 +1307,7 @@ PciReadBuffer (
     //\r
     // Read the last remaining word if exist\r
     //\r
-    *(volatile UINT16 *)Buffer = PciRead16 (StartAddress);\r
+    WriteUnaligned16 (Buffer, PciRead16 (StartAddress));\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
@@ -1323,12 +1339,12 @@ PciReadBuffer (
   If ((StartAddress & 0xFFF) + Size) > 0x1000, 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
+  @param  StartAddress  The starting address that encodes the PCI Bus, Device,\r
                         Function and Register.\r
-  @param  Size          Size in bytes of the transfer.\r
-  @param  Buffer        Pointer to a buffer containing the data to write.\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\r
+  @return Size written to StartAddress.\r
 \r
 **/\r
 UINTN\r
@@ -1369,7 +1385,7 @@ PciWriteBuffer (
     //\r
     // Write a word if StartAddress is word aligned\r
     //\r
-    PciWrite16 (StartAddress, *(UINT16*)Buffer);\r
+    PciWrite16 (StartAddress, ReadUnaligned16 (Buffer));\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
@@ -1379,7 +1395,7 @@ PciWriteBuffer (
     //\r
     // Write as many double words as possible\r
     //\r
-    PciWrite32 (StartAddress, *(UINT32*)Buffer);\r
+    PciWrite32 (StartAddress, ReadUnaligned32 (Buffer));\r
     StartAddress += sizeof (UINT32);\r
     Size -= sizeof (UINT32);\r
     Buffer = (UINT32*)Buffer + 1;\r
@@ -1389,7 +1405,7 @@ PciWriteBuffer (
     //\r
     // Write the last remaining word if exist\r
     //\r
-    PciWrite16 (StartAddress, *(UINT16*)Buffer);\r
+    PciWrite16 (StartAddress, ReadUnaligned16 (Buffer));\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r