X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdePkg%2FLibrary%2FPeiPciSegmentLibPciCfg2%2FPciSegmentLib.c;h=26db2183ce80f28ddb8ab543bb903543ee57630c;hp=215fdabc2e819d30bc9d243e14abc6d58660e134;hb=9095d37b8fe5bfc3d02adad6ba7fd7359ebc0107;hpb=62991af27f84e5f20e55dee6e1f90eb77ec5325e diff --git a/MdePkg/Library/PeiPciSegmentLibPciCfg2/PciSegmentLib.c b/MdePkg/Library/PeiPciSegmentLibPciCfg2/PciSegmentLib.c index 215fdabc2e..26db2183ce 100644 --- a/MdePkg/Library/PeiPciSegmentLibPciCfg2/PciSegmentLib.c +++ b/MdePkg/Library/PeiPciSegmentLibPciCfg2/PciSegmentLib.c @@ -1,13 +1,13 @@ /** @file PCI Segment Library implementation using PCI CFG2 PPI. - Copyright (c) 2007 - 2008, Intel Corporation All rights - reserved. This program and the accompanying materials are + Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
+ This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php - + http://opensource.org/licenses/bsd-license.php. + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. @@ -25,31 +25,32 @@ /** Assert the validity of a PCI Segment address. - A valid PCI Segment address should not contain 1's in bits 31:28 + A valid PCI Segment address should not contain 1's in bits 28..31 and 48..63 @param A The address to validate. @param M Additional bits to assert to be zero. **/ #define ASSERT_INVALID_PCI_SEGMENT_ADDRESS(A,M) \ - ASSERT (((A) & (0xf0000000 | (M))) == 0) + ASSERT (((A) & (0xffff0000f0000000ULL | (M))) == 0) /** Translate PCI Lib address into format of PCI CFG2 PPI. - @param A Address that encodes the PCI Bus, Device, Function and + @param A The address that encodes the PCI Bus, Device, Function and Register. **/ #define PCI_TO_PCICFG2_ADDRESS(A) \ - ((((A) << 4) & 0xff000000) | (((A) >> 4) & 0x00000700) | (((A) << 1) & 0x001f0000) | (LShiftU64((A) & 0xfff, 32))) + ((((UINT32)(A) << 4) & 0xff000000) | (((UINT32)(A) >> 4) & 0x00000700) | (((UINT32)(A) << 1) & 0x001f0000) | (LShiftU64((A) & 0xfff, 32))) /** Gets PCI CFG2 PPI. This internal function retrieves PCI CFG2 PPI from PPI database. - @param Address Address that encodes the PCI Segment, Bus, Device, Function and Register. + @param Address The address that encodes the PCI Segment, Bus, Device, + Function and Register. @return The pointer to PCI CFG2 PPI. @@ -92,9 +93,9 @@ InternalGetPciCfg2Ppi ( It reads and returns the PCI configuration register specified by Address, the width of data is specified by Width. - @param Address Address that encodes the PCI Bus, Device, Function and + @param Address The address that encodes the PCI Bus, Device, Function and Register. - @param Width Width of data to read + @param Width The width of data to read @return The value read from the PCI configuration register. @@ -130,9 +131,9 @@ PeiPciSegmentLibPciCfg2ReadWorker ( value specified by Data. The width of data is specifed by Width. Data is returned. - @param Address Address that encodes the PCI Bus, Device, Function and + @param Address The address that encodes the PCI Bus, Device, Function and Register. - @param Width Width of data to write + @param Width The width of data to write @param Data The value to write. @return The value written to the PCI configuration register. @@ -162,16 +163,16 @@ PeiPciSegmentLibPciCfg2WriteWorker ( } /** - Register a PCI device so PCI configuration registers may be accessed after + Register a PCI device so PCI configuration registers may be accessed after SetVirtualAddressMap(). - - If Address > 0x0FFFFFFF, then ASSERT(). + + If any reserved bits in Address are set, then ASSERT(). @param Address Address that encodes the PCI Bus, Device, Function and Register. - + @retval RETURN_SUCCESS The PCI device was registered for runtime access. - @retval RETURN_UNSUPPORTED An attempt was made to call this function + @retval RETURN_UNSUPPORTED An attempt was made to call this function after ExitBootServices(). @retval RETURN_UNSUPPORTED The resources required to access the PCI device at runtime could not be mapped. @@ -185,6 +186,7 @@ PciSegmentRegisterForRuntimeAccess ( IN UINTN Address ) { + ASSERT_INVALID_PCI_SEGMENT_ADDRESS (Address, 0); return RETURN_UNSUPPORTED; } @@ -193,9 +195,9 @@ PciSegmentRegisterForRuntimeAccess ( Reads and returns the 8-bit PCI configuration register specified by Address. This function must guarantee that all PCI read and write operations are serialized. - + If any reserved bits in Address are set, then ASSERT(). - + @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register. @return The 8-bit PCI configuration register specified by Address. @@ -204,7 +206,7 @@ PciSegmentRegisterForRuntimeAccess ( UINT8 EFIAPI PciSegmentRead8 ( - IN UINT64 Address + IN UINT64 Address ) { ASSERT_INVALID_PCI_SEGMENT_ADDRESS (Address, 0); @@ -217,8 +219,8 @@ PciSegmentRead8 ( Writes the 8-bit PCI configuration register specified by Address with the value specified by Value. Value is returned. This function must guarantee that all PCI read and write operations are serialized. - - If Address > 0x0FFFFFFF, then ASSERT(). + + If any reserved bits in Address are set, then ASSERT(). @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register. @param Value The value to write. @@ -229,8 +231,8 @@ PciSegmentRead8 ( UINT8 EFIAPI PciSegmentWrite8 ( - IN UINT64 Address, - IN UINT8 Value + IN UINT64 Address, + IN UINT8 Value ) { ASSERT_INVALID_PCI_SEGMENT_ADDRESS (Address, 0); @@ -246,7 +248,7 @@ PciSegmentWrite8 ( and writes the result to the 8-bit PCI configuration register specified by Address. The value written to the PCI configuration register is returned. This function must guarantee that all PCI read and write operations are serialized. - + If any reserved bits in Address are set, then ASSERT(). @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register. @@ -258,8 +260,8 @@ PciSegmentWrite8 ( UINT8 EFIAPI PciSegmentOr8 ( - IN UINT64 Address, - IN UINT8 OrData + IN UINT64 Address, + IN UINT8 OrData ) { return PciSegmentWrite8 (Address, (UINT8) (PciSegmentRead8 (Address) | OrData)); @@ -284,8 +286,8 @@ PciSegmentOr8 ( UINT8 EFIAPI PciSegmentAnd8 ( - IN UINT64 Address, - IN UINT8 AndData + IN UINT64 Address, + IN UINT8 AndData ) { return PciSegmentWrite8 (Address, (UINT8) (PciSegmentRead8 (Address) & AndData)); @@ -294,18 +296,18 @@ PciSegmentAnd8 ( /** Performs a bitwise AND of an 8-bit PCI configuration register with an 8-bit value, followed a bitwise OR with another 8-bit value. - + Reads the 8-bit PCI configuration register specified by Address, performs a bitwise AND between the read result and the value specified by AndData, performs a bitwise OR between the result of the AND operation and the value specified by OrData, and writes the result to the 8-bit PCI configuration register specified by Address. The value written to the PCI configuration register is returned. This function must guarantee that all PCI read and write operations are serialized. - + If any reserved bits in Address are set, then ASSERT(). @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register. - @param AndData The value to AND with the PCI configuration register. + @param AndData The value to AND with the PCI configuration register. @param OrData The value to OR with the PCI configuration register. @return The value written to the PCI configuration register. @@ -314,9 +316,9 @@ PciSegmentAnd8 ( UINT8 EFIAPI PciSegmentAndThenOr8 ( - IN UINT64 Address, - IN UINT8 AndData, - IN UINT8 OrData + IN UINT64 Address, + IN UINT8 AndData, + IN UINT8 OrData ) { return PciSegmentWrite8 (Address, (UINT8) ((PciSegmentRead8 (Address) & AndData) | OrData)); @@ -346,9 +348,9 @@ PciSegmentAndThenOr8 ( UINT8 EFIAPI PciSegmentBitFieldRead8 ( - IN UINT64 Address, - IN UINTN StartBit, - IN UINTN EndBit + IN UINT64 Address, + IN UINTN StartBit, + IN UINTN EndBit ) { return BitFieldRead8 (PciSegmentRead8 (Address), StartBit, EndBit); @@ -366,6 +368,7 @@ PciSegmentBitFieldRead8 ( If StartBit is greater than 7, then ASSERT(). If EndBit is greater than 7, then ASSERT(). If EndBit is less than StartBit, then ASSERT(). + If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT(). @param Address PCI configuration register to write. @param StartBit The ordinal of the least significant bit in the bit field. @@ -380,10 +383,10 @@ PciSegmentBitFieldRead8 ( UINT8 EFIAPI PciSegmentBitFieldWrite8 ( - IN UINT64 Address, - IN UINTN StartBit, - IN UINTN EndBit, - IN UINT8 Value + IN UINT64 Address, + IN UINTN StartBit, + IN UINTN EndBit, + IN UINT8 Value ) { return PciSegmentWrite8 ( @@ -407,6 +410,7 @@ PciSegmentBitFieldWrite8 ( If StartBit is greater than 7, then ASSERT(). If EndBit is greater than 7, then ASSERT(). If EndBit is less than StartBit, then ASSERT(). + If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT(). @param Address PCI configuration register to write. @param StartBit The ordinal of the least significant bit in the bit field. @@ -421,10 +425,10 @@ PciSegmentBitFieldWrite8 ( UINT8 EFIAPI PciSegmentBitFieldOr8 ( - IN UINT64 Address, - IN UINTN StartBit, - IN UINTN EndBit, - IN UINT8 OrData + IN UINT64 Address, + IN UINTN StartBit, + IN UINTN EndBit, + IN UINT8 OrData ) { return PciSegmentWrite8 ( @@ -448,6 +452,7 @@ PciSegmentBitFieldOr8 ( If StartBit is greater than 7, then ASSERT(). If EndBit is greater than 7, then ASSERT(). If EndBit is less than StartBit, then ASSERT(). + If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT(). @param Address PCI configuration register to write. @param StartBit The ordinal of the least significant bit in the bit field. @@ -462,10 +467,10 @@ PciSegmentBitFieldOr8 ( UINT8 EFIAPI PciSegmentBitFieldAnd8 ( - IN UINT64 Address, - IN UINTN StartBit, - IN UINTN EndBit, - IN UINT8 AndData + IN UINT64 Address, + IN UINTN StartBit, + IN UINTN EndBit, + IN UINT8 AndData ) { return PciSegmentWrite8 ( @@ -476,8 +481,7 @@ PciSegmentBitFieldAnd8 ( /** Reads a bit field in an 8-bit port, performs a bitwise AND followed by a - bitwise OR, and writes the result back to the bit field in the - 8-bit port. + bitwise OR, and writes the result back to the bit field in the 8-bit port. Reads the 8-bit PCI configuration register specified by Address, performs a bitwise AND followed by a bitwise OR between the read result and @@ -491,6 +495,8 @@ PciSegmentBitFieldAnd8 ( If StartBit is greater than 7, then ASSERT(). If EndBit is greater than 7, then ASSERT(). If EndBit is less than StartBit, then ASSERT(). + If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT(). + If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT(). @param Address PCI configuration register to write. @param StartBit The ordinal of the least significant bit in the bit field. @@ -506,11 +512,11 @@ PciSegmentBitFieldAnd8 ( UINT8 EFIAPI PciSegmentBitFieldAndThenOr8 ( - IN UINT64 Address, - IN UINTN StartBit, - IN UINTN EndBit, - IN UINT8 AndData, - IN UINT8 OrData + IN UINT64 Address, + IN UINTN StartBit, + IN UINTN EndBit, + IN UINT8 AndData, + IN UINT8 OrData ) { return PciSegmentWrite8 ( @@ -524,10 +530,10 @@ PciSegmentBitFieldAndThenOr8 ( Reads and returns the 16-bit PCI configuration register specified by Address. This function must guarantee that all PCI read and write operations are serialized. - + If any reserved bits in Address are set, then ASSERT(). If Address is not aligned on a 16-bit boundary, then ASSERT(). - + @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register. @return The 16-bit PCI configuration register specified by Address. @@ -536,7 +542,7 @@ PciSegmentBitFieldAndThenOr8 ( UINT16 EFIAPI PciSegmentRead16 ( - IN UINT64 Address + IN UINT64 Address ) { ASSERT_INVALID_PCI_SEGMENT_ADDRESS (Address, 1); @@ -549,7 +555,7 @@ PciSegmentRead16 ( Writes the 16-bit PCI configuration register specified by Address with the value specified by Value. Value is returned. This function must guarantee that all PCI read and write operations are serialized. - + If any reserved bits in Address are set, then ASSERT(). If Address is not aligned on a 16-bit boundary, then ASSERT(). @@ -562,8 +568,8 @@ PciSegmentRead16 ( UINT16 EFIAPI PciSegmentWrite16 ( - IN UINT64 Address, - IN UINT16 Value + IN UINT64 Address, + IN UINT16 Value ) { ASSERT_INVALID_PCI_SEGMENT_ADDRESS (Address, 1); @@ -576,11 +582,10 @@ PciSegmentWrite16 ( a 16-bit value. Reads the 16-bit PCI configuration register specified by Address, performs a - bitwise OR between the read result and the value specified by - OrData, and writes the result to the 16-bit PCI configuration register - specified by Address. The value written to the PCI configuration register is - returned. This function must guarantee that all PCI read and write operations - are serialized. + bitwise OR between the read result and the value specified by OrData, and + writes the result to the 16-bit PCI configuration register specified by Address. + The value written to the PCI configuration register is returned. This function + must guarantee that all PCI read and write operations are serialized. If any reserved bits in Address are set, then ASSERT(). If Address is not aligned on a 16-bit boundary, then ASSERT(). @@ -595,8 +600,8 @@ PciSegmentWrite16 ( UINT16 EFIAPI PciSegmentOr16 ( - IN UINT64 Address, - IN UINT16 OrData + IN UINT64 Address, + IN UINT16 OrData ) { return PciSegmentWrite16 (Address, (UINT16) (PciSegmentRead16 (Address) | OrData)); @@ -610,10 +615,10 @@ PciSegmentOr16 ( and writes the result to the 16-bit PCI configuration register specified by Address. The value written to the PCI configuration register is returned. This function must guarantee that all PCI read and write operations are serialized. - + If any reserved bits in Address are set, then ASSERT(). If Address is not aligned on a 16-bit boundary, then ASSERT(). - + @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register. @param AndData The value to AND with the PCI configuration register. @@ -623,8 +628,8 @@ PciSegmentOr16 ( UINT16 EFIAPI PciSegmentAnd16 ( - IN UINT64 Address, - IN UINT16 AndData + IN UINT64 Address, + IN UINT16 AndData ) { return PciSegmentWrite16 (Address, (UINT16) (PciSegmentRead16 (Address) & AndData)); @@ -633,19 +638,19 @@ PciSegmentAnd16 ( /** Performs a bitwise AND of a 16-bit PCI configuration register with a 16-bit value, followed a bitwise OR with another 16-bit value. - + Reads the 16-bit PCI configuration register specified by Address, performs a bitwise AND between the read result and the value specified by AndData, performs a bitwise OR between the result of the AND operation and the value specified by OrData, and writes the result to the 16-bit PCI configuration register specified by Address. The value written to the PCI configuration register is returned. This function must guarantee that all PCI read and write operations are serialized. - + If any reserved bits in Address are set, then ASSERT(). If Address is not aligned on a 16-bit boundary, then ASSERT(). @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register. - @param AndData The value to AND with the PCI configuration register. + @param AndData The value to AND with the PCI configuration register. @param OrData The value to OR with the PCI configuration register. @return The value written to the PCI configuration register. @@ -654,9 +659,9 @@ PciSegmentAnd16 ( UINT16 EFIAPI PciSegmentAndThenOr16 ( - IN UINT64 Address, - IN UINT16 AndData, - IN UINT16 OrData + IN UINT64 Address, + IN UINT16 AndData, + IN UINT16 OrData ) { return PciSegmentWrite16 (Address, (UINT16) ((PciSegmentRead16 (Address) & AndData) | OrData)); @@ -687,9 +692,9 @@ PciSegmentAndThenOr16 ( UINT16 EFIAPI PciSegmentBitFieldRead16 ( - IN UINT64 Address, - IN UINTN StartBit, - IN UINTN EndBit + IN UINT64 Address, + IN UINTN StartBit, + IN UINTN EndBit ) { return BitFieldRead16 (PciSegmentRead16 (Address), StartBit, EndBit); @@ -708,6 +713,7 @@ PciSegmentBitFieldRead16 ( If StartBit is greater than 15, then ASSERT(). If EndBit is greater than 15, then ASSERT(). If EndBit is less than StartBit, then ASSERT(). + If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT(). @param Address PCI configuration register to write. @param StartBit The ordinal of the least significant bit in the bit field. @@ -722,10 +728,10 @@ PciSegmentBitFieldRead16 ( UINT16 EFIAPI PciSegmentBitFieldWrite16 ( - IN UINT64 Address, - IN UINTN StartBit, - IN UINTN EndBit, - IN UINT16 Value + IN UINT64 Address, + IN UINTN StartBit, + IN UINTN EndBit, + IN UINT16 Value ) { return PciSegmentWrite16 ( @@ -735,15 +741,22 @@ PciSegmentBitFieldWrite16 ( } /** - Reads the 16-bit PCI configuration register specified by Address, - performs a bitwise OR between the read result and the value specified by OrData, - and writes the result to the 16-bit PCI configuration register specified by Address. + Reads a bit field in a 16-bit PCI configuration, performs a bitwise OR, writes + the result back to the bit field in the 16-bit port. + + Reads the 16-bit PCI configuration register specified by Address, performs a + bitwise OR between the read result and the value specified by + OrData, and writes the result to the 16-bit PCI configuration register + specified by Address. The value written to the PCI configuration register is + returned. This function must guarantee that all PCI read and write operations + are serialized. Extra left bits in OrData are stripped. If any reserved bits in Address are set, then ASSERT(). If Address is not aligned on a 16-bit boundary, then ASSERT(). If StartBit is greater than 15, then ASSERT(). If EndBit is greater than 15, then ASSERT(). If EndBit is less than StartBit, then ASSERT(). + If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT(). @param Address PCI configuration register to write. @param StartBit The ordinal of the least significant bit in the bit field. @@ -758,10 +771,10 @@ PciSegmentBitFieldWrite16 ( UINT16 EFIAPI PciSegmentBitFieldOr16 ( - IN UINT64 Address, - IN UINTN StartBit, - IN UINTN EndBit, - IN UINT16 OrData + IN UINT64 Address, + IN UINTN StartBit, + IN UINTN EndBit, + IN UINT16 OrData ) { return PciSegmentWrite16 ( @@ -772,7 +785,7 @@ PciSegmentBitFieldOr16 ( /** Reads a bit field in a 16-bit PCI configuration register, performs a bitwise - AND, and writes the result back to the bit field in the 16-bit register. + AND, writes the result back to the bit field in the 16-bit register. Reads the 16-bit PCI configuration register specified by Address, performs a bitwise AND between the read result and the value specified by AndData, and @@ -782,11 +795,13 @@ PciSegmentBitFieldOr16 ( serialized. Extra left bits in AndData are stripped. If any reserved bits in Address are set, then ASSERT(). + If Address is not aligned on a 16-bit boundary, then ASSERT(). If StartBit is greater than 15, then ASSERT(). If EndBit is greater than 15, then ASSERT(). If EndBit is less than StartBit, then ASSERT(). + If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT(). - @param Address PCI configuration register to write. + @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register. @param StartBit The ordinal of the least significant bit in the bit field. Range 0..15. @param EndBit The ordinal of the most significant bit in the bit field. @@ -799,10 +814,10 @@ PciSegmentBitFieldOr16 ( UINT16 EFIAPI PciSegmentBitFieldAnd16 ( - IN UINT64 Address, - IN UINTN StartBit, - IN UINTN EndBit, - IN UINT16 AndData + IN UINT64 Address, + IN UINTN StartBit, + IN UINTN EndBit, + IN UINT16 AndData ) { return PciSegmentWrite16 ( @@ -828,6 +843,8 @@ PciSegmentBitFieldAnd16 ( If StartBit is greater than 15, then ASSERT(). If EndBit is greater than 15, then ASSERT(). If EndBit is less than StartBit, then ASSERT(). + If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT(). + If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT(). @param Address PCI configuration register to write. @param StartBit The ordinal of the least significant bit in the bit field. @@ -843,11 +860,11 @@ PciSegmentBitFieldAnd16 ( UINT16 EFIAPI PciSegmentBitFieldAndThenOr16 ( - IN UINT64 Address, - IN UINTN StartBit, - IN UINTN EndBit, - IN UINT16 AndData, - IN UINT16 OrData + IN UINT64 Address, + IN UINTN StartBit, + IN UINTN EndBit, + IN UINT16 AndData, + IN UINT16 OrData ) { return PciSegmentWrite16 ( @@ -861,7 +878,7 @@ PciSegmentBitFieldAndThenOr16 ( Reads and returns the 32-bit PCI configuration register specified by Address. This function must guarantee that all PCI read and write operations are serialized. - + If any reserved bits in Address are set, then ASSERT(). If Address is not aligned on a 32-bit boundary, then ASSERT(). @@ -873,7 +890,7 @@ PciSegmentBitFieldAndThenOr16 ( UINT32 EFIAPI PciSegmentRead32 ( - IN UINT64 Address + IN UINT64 Address ) { ASSERT_INVALID_PCI_SEGMENT_ADDRESS (Address, 3); @@ -886,7 +903,7 @@ PciSegmentRead32 ( Writes the 32-bit PCI configuration register specified by Address with the value specified by Value. Value is returned. This function must guarantee that all PCI read and write operations are serialized. - + If any reserved bits in Address are set, then ASSERT(). If Address is not aligned on a 32-bit boundary, then ASSERT(). @@ -899,8 +916,8 @@ PciSegmentRead32 ( UINT32 EFIAPI PciSegmentWrite32 ( - IN UINT64 Address, - IN UINT32 Value + IN UINT64 Address, + IN UINT32 Value ) { ASSERT_INVALID_PCI_SEGMENT_ADDRESS (Address, 3); @@ -916,7 +933,7 @@ PciSegmentWrite32 ( and writes the result to the 32-bit PCI configuration register specified by Address. The value written to the PCI configuration register is returned. This function must guarantee that all PCI read and write operations are serialized. - + If any reserved bits in Address are set, then ASSERT(). If Address is not aligned on a 32-bit boundary, then ASSERT(). @@ -929,8 +946,8 @@ PciSegmentWrite32 ( UINT32 EFIAPI PciSegmentOr32 ( - IN UINT64 Address, - IN UINT32 OrData + IN UINT64 Address, + IN UINT32 OrData ) { return PciSegmentWrite32 (Address, PciSegmentRead32 (Address) | OrData); @@ -944,7 +961,7 @@ PciSegmentOr32 ( and writes the result to the 32-bit PCI configuration register specified by Address. The value written to the PCI configuration register is returned. This function must guarantee that all PCI read and write operations are serialized. - + If any reserved bits in Address are set, then ASSERT(). If Address is not aligned on a 32-bit boundary, then ASSERT(). @@ -957,8 +974,8 @@ PciSegmentOr32 ( UINT32 EFIAPI PciSegmentAnd32 ( - IN UINT64 Address, - IN UINT32 AndData + IN UINT64 Address, + IN UINT32 AndData ) { return PciSegmentWrite32 (Address, PciSegmentRead32 (Address) & AndData); @@ -967,14 +984,14 @@ PciSegmentAnd32 ( /** Performs a bitwise AND of a 32-bit PCI configuration register with a 32-bit value, followed a bitwise OR with another 32-bit value. - + Reads the 32-bit PCI configuration register specified by Address, performs a bitwise AND between the read result and the value specified by AndData, performs a bitwise OR between the result of the AND operation and the value specified by OrData, and writes the result to the 32-bit PCI configuration register specified by Address. The value written to the PCI configuration register is returned. This function must guarantee that all PCI read and write operations are serialized. - + If any reserved bits in Address are set, then ASSERT(). If Address is not aligned on a 32-bit boundary, then ASSERT(). @@ -988,9 +1005,9 @@ PciSegmentAnd32 ( UINT32 EFIAPI PciSegmentAndThenOr32 ( - IN UINT64 Address, - IN UINT32 AndData, - IN UINT32 OrData + IN UINT64 Address, + IN UINT32 AndData, + IN UINT32 OrData ) { return PciSegmentWrite32 (Address, (PciSegmentRead32 (Address) & AndData) | OrData); @@ -1021,9 +1038,9 @@ PciSegmentAndThenOr32 ( UINT32 EFIAPI PciSegmentBitFieldRead32 ( - IN UINT64 Address, - IN UINTN StartBit, - IN UINTN EndBit + IN UINT64 Address, + IN UINTN StartBit, + IN UINTN EndBit ) { return BitFieldRead32 (PciSegmentRead32 (Address), StartBit, EndBit); @@ -1042,6 +1059,7 @@ PciSegmentBitFieldRead32 ( If StartBit is greater than 31, then ASSERT(). If EndBit is greater than 31, then ASSERT(). If EndBit is less than StartBit, then ASSERT(). + If Value is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT(). @param Address PCI configuration register to write. @param StartBit The ordinal of the least significant bit in the bit field. @@ -1056,10 +1074,10 @@ PciSegmentBitFieldRead32 ( UINT32 EFIAPI PciSegmentBitFieldWrite32 ( - IN UINT64 Address, - IN UINTN StartBit, - IN UINTN EndBit, - IN UINT32 Value + IN UINT64 Address, + IN UINTN StartBit, + IN UINTN EndBit, + IN UINT32 Value ) { return PciSegmentWrite32 ( @@ -1083,6 +1101,7 @@ PciSegmentBitFieldWrite32 ( If StartBit is greater than 31, then ASSERT(). If EndBit is greater than 31, then ASSERT(). If EndBit is less than StartBit, then ASSERT(). + If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT(). @param Address PCI configuration register to write. @param StartBit The ordinal of the least significant bit in the bit field. @@ -1097,10 +1116,10 @@ PciSegmentBitFieldWrite32 ( UINT32 EFIAPI PciSegmentBitFieldOr32 ( - IN UINT64 Address, - IN UINTN StartBit, - IN UINTN EndBit, - IN UINT32 OrData + IN UINT64 Address, + IN UINTN StartBit, + IN UINTN EndBit, + IN UINT32 OrData ) { return PciSegmentWrite32 ( @@ -1113,19 +1132,20 @@ PciSegmentBitFieldOr32 ( Reads a bit field in a 32-bit PCI configuration register, performs a bitwise AND, and writes the result back to the bit field in the 32-bit register. - Reads the 32-bit PCI configuration register specified by Address, performs a - bitwise AND between the read result and the value specified by AndData, and - writes the result to the 32-bit PCI configuration register specified by - Address. The value written to the PCI configuration register is returned. - This function must guarantee that all PCI read and write operations are - serialized. Extra left bits in AndData are stripped. + Reads the 32-bit PCI configuration register specified by Address, performs a bitwise + AND between the read result and the value specified by AndData, and writes the result + to the 32-bit PCI configuration register specified by Address. The value written to + the PCI configuration register is returned. This function must guarantee that all PCI + read and write operations are serialized. Extra left bits in AndData are stripped. If any reserved bits in Address are set, then ASSERT(). + If Address is not aligned on a 32-bit boundary, then ASSERT(). If StartBit is greater than 31, then ASSERT(). If EndBit is greater than 31, then ASSERT(). If EndBit is less than StartBit, then ASSERT(). + If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT(). - @param Address PCI configuration register to write. + @param Address Address that encodes the PCI Segment, Bus, Device, Function, and Register. @param StartBit The ordinal of the least significant bit in the bit field. Range 0..31. @param EndBit The ordinal of the most significant bit in the bit field. @@ -1138,10 +1158,10 @@ PciSegmentBitFieldOr32 ( UINT32 EFIAPI PciSegmentBitFieldAnd32 ( - IN UINT64 Address, - IN UINTN StartBit, - IN UINTN EndBit, - IN UINT32 AndData + IN UINT64 Address, + IN UINTN StartBit, + IN UINTN EndBit, + IN UINT32 AndData ) { return PciSegmentWrite32 ( @@ -1167,6 +1187,8 @@ PciSegmentBitFieldAnd32 ( If StartBit is greater than 31, then ASSERT(). If EndBit is greater than 31, then ASSERT(). If EndBit is less than StartBit, then ASSERT(). + If AndData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT(). + If OrData is larger than the bitmask value range specified by StartBit and EndBit, then ASSERT(). @param Address PCI configuration register to write. @param StartBit The ordinal of the least significant bit in the bit field. @@ -1182,11 +1204,11 @@ PciSegmentBitFieldAnd32 ( UINT32 EFIAPI PciSegmentBitFieldAndThenOr32 ( - IN UINT64 Address, - IN UINTN StartBit, - IN UINTN EndBit, - IN UINT32 AndData, - IN UINT32 OrData + IN UINT64 Address, + IN UINTN StartBit, + IN UINTN EndBit, + IN UINT32 AndData, + IN UINT32 OrData ) { return PciSegmentWrite32 ( @@ -1198,28 +1220,32 @@ PciSegmentBitFieldAndThenOr32 ( /** Reads a range of PCI configuration registers into a caller supplied buffer. - Reads the range of PCI configuration registers specified by StartAddress - and Size into the buffer specified by Buffer. - This function only allows the PCI configuration registers from a single PCI function to be read. - Size is returned. - + Reads the range of PCI configuration registers specified by StartAddress and + Size into the buffer specified by Buffer. This function only allows the PCI + configuration registers from a single PCI function to be read. Size is + returned. When possible 32-bit PCI configuration read cycles are used to read + from StartAdress to StartAddress + Size. Due to alignment restrictions, 8-bit + and 16-bit PCI configuration read cycles may be used at the beginning and the + end of the range. + If any reserved bits in StartAddress are set, then ASSERT(). If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT(). If Size > 0 and Buffer is NULL, then ASSERT(). - @param StartAddress Starting address that encodes the PCI Segment, Bus, Device, Function, and Register. + @param StartAddress Starting address that encodes the PCI Segment, Bus, Device, + Function and Register. @param Size Size in bytes of the transfer. @param Buffer Pointer to a buffer receiving the data read. - @return The parameter of Size. + @return Size **/ UINTN EFIAPI PciSegmentReadBuffer ( - IN UINT64 StartAddress, - IN UINTN Size, - OUT VOID *Buffer + IN UINT64 StartAddress, + IN UINTN Size, + OUT VOID *Buffer ) { UINTN ReturnValue; @@ -1252,7 +1278,7 @@ PciSegmentReadBuffer ( // // Read a word if StartAddress is word aligned // - *(volatile UINT16 *)Buffer = PciSegmentRead16 (StartAddress); + WriteUnaligned16 (Buffer, PciSegmentRead16 (StartAddress)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1262,7 +1288,7 @@ PciSegmentReadBuffer ( // // Read as many double words as possible // - *(volatile UINT32 *)Buffer = PciSegmentRead32 (StartAddress); + WriteUnaligned32 (Buffer, PciSegmentRead32 (StartAddress)); StartAddress += sizeof (UINT32); Size -= sizeof (UINT32); Buffer = (UINT32*)Buffer + 1; @@ -1272,7 +1298,7 @@ PciSegmentReadBuffer ( // // Read the last remaining word if exist // - *(volatile UINT16 *)Buffer = PciSegmentRead16 (StartAddress); + WriteUnaligned16 (Buffer, PciSegmentRead16 (StartAddress)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1290,18 +1316,23 @@ PciSegmentReadBuffer ( /** - Copies the data in a caller supplied buffer to a specified range of PCI configuration space. + Copies the data in a caller supplied buffer to a specified range of PCI + configuration space. + + Writes the range of PCI configuration registers specified by StartAddress and + Size from the buffer specified by Buffer. This function only allows the PCI + configuration registers from a single PCI function to be written. Size is + returned. When possible 32-bit PCI configuration write cycles are used to + write from StartAdress to StartAddress + Size. Due to alignment restrictions, + 8-bit and 16-bit PCI configuration write cycles may be used at the beginning + and the end of the range. - Writes the range of PCI configuration registers specified by StartAddress - and Size from the buffer specified by Buffer. - This function only allows the PCI configuration registers from a single PCI function to be written. - Size is returned. - If any reserved bits in StartAddress are set, then ASSERT(). If ((StartAddress & 0xFFF) + Size) > 0x1000, then ASSERT(). If Size > 0 and Buffer is NULL, then ASSERT(). - @param StartAddress Starting address that encodes the PCI Segment, Bus, Device, Function, and Register. + @param StartAddress Starting address that encodes the PCI Segment, Bus, Device, + Function and Register. @param Size Size in bytes of the transfer. @param Buffer Pointer to a buffer containing the data to write. @@ -1311,9 +1342,9 @@ PciSegmentReadBuffer ( UINTN EFIAPI PciSegmentWriteBuffer ( - IN UINT64 StartAddress, - IN UINTN Size, - IN VOID *Buffer + IN UINT64 StartAddress, + IN UINTN Size, + IN VOID *Buffer ) { UINTN ReturnValue; @@ -1346,7 +1377,7 @@ PciSegmentWriteBuffer ( // // Write a word if StartAddress is word aligned // - PciSegmentWrite16 (StartAddress, *(UINT16*)Buffer); + PciSegmentWrite16 (StartAddress, ReadUnaligned16 (Buffer)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1356,7 +1387,7 @@ PciSegmentWriteBuffer ( // // Write as many double words as possible // - PciSegmentWrite32 (StartAddress, *(UINT32*)Buffer); + PciSegmentWrite32 (StartAddress, ReadUnaligned32 (Buffer)); StartAddress += sizeof (UINT32); Size -= sizeof (UINT32); Buffer = (UINT32*)Buffer + 1; @@ -1366,7 +1397,7 @@ PciSegmentWriteBuffer ( // // Write the last remaining word if exist // - PciSegmentWrite16 (StartAddress, *(UINT16*)Buffer); + PciSegmentWrite16 (StartAddress, ReadUnaligned16 (Buffer)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1;