X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdePkg%2FLibrary%2FBasePciCf8Lib%2FPciCf8Lib.c;h=828508b2ebca13cce70cd1b63e6f0db836c08f11;hb=94952554cc604750f3df3d4e8ae068703481d258;hp=f0a23c3605ebe58e49f781bc08680c27c53d93b5;hpb=59ceeabe504f4c7814f9560c411690a1ffdc31b2;p=mirror_edk2.git diff --git a/MdePkg/Library/BasePciCf8Lib/PciCf8Lib.c b/MdePkg/Library/BasePciCf8Lib/PciCf8Lib.c index f0a23c3605..828508b2eb 100644 --- a/MdePkg/Library/BasePciCf8Lib/PciCf8Lib.c +++ b/MdePkg/Library/BasePciCf8Lib/PciCf8Lib.c @@ -2,11 +2,11 @@ PCI CF8 Library functions that use I/O ports 0xCF8 and 0xCFC to perform PCI Configuration cycles. Layers on top of an I/O Library instance. - Copyright (c) 2006 - 2009, Intel Corporation
- All rights reserved. This program and the accompanying materials + Copyright (c) 2006 - 2012, 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. @@ -70,7 +70,7 @@ If Address > 0x0FFFFFFF, then ASSERT(). If the register specified by Address >= 0x100, then ASSERT(). - @param Address Address that encodes the PCI Bus, Device, Function and + @param Address The address that encodes the PCI Bus, Device, Function and Register. @retval RETURN_SUCCESS The PCI device was registered for runtime access. @@ -102,7 +102,7 @@ PciCf8RegisterForRuntimeAccess ( If Address > 0x0FFFFFFF, then ASSERT(). If the register specified by Address >= 0x100, then ASSERT(). - @param Address Address that encodes the PCI Bus, Device, Function and + @param Address The address that encodes the PCI Bus, Device, Function and Register. @return The read value from the PCI configuration register. @@ -114,9 +114,18 @@ PciCf8Read8 ( IN UINTN Address ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT8 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 0); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoRead8 (PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3)); + Result = IoRead8 (PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3)); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -129,7 +138,7 @@ PciCf8Read8 ( If Address > 0x0FFFFFFF, then ASSERT(). If the register specified by Address >= 0x100, then ASSERT(). - @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 Value The value to write. @@ -143,12 +152,21 @@ PciCf8Write8 ( IN UINT8 Value ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT8 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 0); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoWrite8 ( - PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3), - Value - ); + Result = IoWrite8 ( + PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3), + Value + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -165,7 +183,7 @@ PciCf8Write8 ( If Address > 0x0FFFFFFF, then ASSERT(). If the register specified by Address >= 0x100, then ASSERT(). - @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 OrData The value to OR with the PCI configuration register. @@ -179,12 +197,21 @@ PciCf8Or8 ( IN UINT8 OrData ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT8 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 0); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoOr8 ( - PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3), - OrData - ); + Result = IoOr8 ( + PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3), + OrData + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -201,7 +228,7 @@ PciCf8Or8 ( If Address > 0x0FFFFFFF, then ASSERT(). If the register specified by Address >= 0x100, then ASSERT(). - @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 AndData The value to AND with the PCI configuration register. @@ -215,12 +242,21 @@ PciCf8And8 ( IN UINT8 AndData ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT8 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 0); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoAnd8 ( - PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3), - AndData - ); + Result = IoAnd8 ( + PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3), + AndData + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -238,7 +274,7 @@ PciCf8And8 ( If Address > 0x0FFFFFFF, then ASSERT(). If the register specified by Address >= 0x100, then ASSERT(). - @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 AndData The value to AND with the PCI configuration register. @param OrData The value to OR with the result of the AND operation. @@ -254,13 +290,22 @@ PciCf8AndThenOr8 ( IN UINT8 OrData ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT8 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 0); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoAndThenOr8 ( - PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3), - AndData, - OrData - ); + Result = IoAndThenOr8 ( + PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3), + AndData, + OrData + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -276,7 +321,7 @@ PciCf8AndThenOr8 ( If EndBit is greater than 7, then ASSERT(). If EndBit is less than StartBit, then ASSERT(). - @param Address PCI configuration register to read. + @param Address The PCI configuration register to read. @param StartBit The ordinal of the least significant bit in the bit field. Range 0..7. @param EndBit The ordinal of the most significant bit in the bit field. @@ -293,13 +338,22 @@ PciCf8BitFieldRead8 ( IN UINTN EndBit ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT8 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 0); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoBitFieldRead8 ( - PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3), - StartBit, - EndBit - ); + Result = IoBitFieldRead8 ( + PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3), + StartBit, + EndBit + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -315,13 +369,14 @@ PciCf8BitFieldRead8 ( 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 Address The PCI configuration register to write. @param StartBit The ordinal of the least significant bit in the bit field. Range 0..7. @param EndBit The ordinal of the most significant bit in the bit field. Range 0..7. - @param Value New value of the bit field. + @param Value The new value of the bit field. @return The value written back to the PCI configuration register. @@ -335,14 +390,23 @@ PciCf8BitFieldWrite8 ( IN UINT8 Value ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT8 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 0); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoBitFieldWrite8 ( - PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3), - StartBit, - EndBit, - Value - ); + Result = IoBitFieldWrite8 ( + PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3), + StartBit, + EndBit, + Value + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -361,8 +425,9 @@ PciCf8BitFieldWrite8 ( 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 Address The PCI configuration register to write. @param StartBit The ordinal of the least significant bit in the bit field. Range 0..7. @param EndBit The ordinal of the most significant bit in the bit field. @@ -381,14 +446,23 @@ PciCf8BitFieldOr8 ( IN UINT8 OrData ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT8 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 0); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoBitFieldOr8 ( - PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3), - StartBit, - EndBit, - OrData - ); + Result = IoBitFieldOr8 ( + PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3), + StartBit, + EndBit, + OrData + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -407,8 +481,9 @@ PciCf8BitFieldOr8 ( 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 Address The PCI configuration register to write. @param StartBit The ordinal of the least significant bit in the bit field. Range 0..7. @param EndBit The ordinal of the most significant bit in the bit field. @@ -427,14 +502,23 @@ PciCf8BitFieldAnd8 ( IN UINT8 AndData ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT8 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 0); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoBitFieldAnd8 ( - PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3), - StartBit, - EndBit, - AndData - ); + Result = IoBitFieldAnd8 ( + PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3), + StartBit, + EndBit, + AndData + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -455,8 +539,10 @@ PciCf8BitFieldAnd8 ( 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 Address The PCI configuration register to write. @param StartBit The ordinal of the least significant bit in the bit field. Range 0..7. @param EndBit The ordinal of the most significant bit in the bit field. @@ -477,15 +563,24 @@ PciCf8BitFieldAndThenOr8( IN UINT8 OrData ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT8 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 0); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoBitFieldAndThenOr8 ( - PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3), - StartBit, - EndBit, - AndData, - OrData - ); + Result = IoBitFieldAndThenOr8 ( + PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 3), + StartBit, + EndBit, + AndData, + OrData + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -499,7 +594,7 @@ PciCf8BitFieldAndThenOr8( If Address is not aligned on a 16-bit boundary, then ASSERT(). If the register specified by Address >= 0x100, then ASSERT(). - @param Address Address that encodes the PCI Bus, Device, Function and + @param Address The address that encodes the PCI Bus, Device, Function and Register. @return The read value from the PCI configuration register. @@ -511,9 +606,18 @@ PciCf8Read16 ( IN UINTN Address ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT16 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 1); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoRead16 (PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2)); + Result = IoRead16 (PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2)); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -527,7 +631,7 @@ PciCf8Read16 ( If Address is not aligned on a 16-bit boundary, then ASSERT(). If the register specified by Address >= 0x100, then ASSERT(). - @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 Value The value to write. @@ -541,12 +645,21 @@ PciCf8Write16 ( IN UINT16 Value ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT16 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 1); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoWrite16 ( - PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2), - Value - ); + Result = IoWrite16 ( + PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2), + Value + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -564,7 +677,7 @@ PciCf8Write16 ( If Address is not aligned on a 16-bit boundary, then ASSERT(). If the register specified by Address >= 0x100, then ASSERT(). - @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 OrData The value to OR with the PCI configuration register. @@ -578,12 +691,21 @@ PciCf8Or16 ( IN UINT16 OrData ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT16 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 1); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoOr16 ( - PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2), - OrData - ); + Result = IoOr16 ( + PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2), + OrData + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -601,7 +723,7 @@ PciCf8Or16 ( If Address is not aligned on a 16-bit boundary, then ASSERT(). If the register specified by Address >= 0x100, then ASSERT(). - @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 AndData The value to AND with the PCI configuration register. @@ -615,12 +737,21 @@ PciCf8And16 ( IN UINT16 AndData ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT16 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 1); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoAnd16 ( - PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2), - AndData - ); + Result = IoAnd16 ( + PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2), + AndData + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -639,7 +770,7 @@ PciCf8And16 ( If Address is not aligned on a 16-bit boundary, then ASSERT(). If the register specified by Address >= 0x100, then ASSERT(). - @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 AndData The value to AND with the PCI configuration register. @param OrData The value to OR with the result of the AND operation. @@ -655,13 +786,22 @@ PciCf8AndThenOr16 ( IN UINT16 OrData ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT16 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 1); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoAndThenOr16 ( - PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2), - AndData, - OrData - ); + Result = IoAndThenOr16 ( + PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2), + AndData, + OrData + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -678,7 +818,7 @@ PciCf8AndThenOr16 ( If EndBit is greater than 15, then ASSERT(). If EndBit is less than StartBit, then ASSERT(). - @param Address PCI configuration register to read. + @param Address The PCI configuration register to read. @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. @@ -695,13 +835,22 @@ PciCf8BitFieldRead16 ( IN UINTN EndBit ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT16 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 1); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoBitFieldRead16 ( - PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2), - StartBit, - EndBit - ); + Result = IoBitFieldRead16 ( + PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2), + StartBit, + EndBit + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -718,13 +867,14 @@ PciCf8BitFieldRead16 ( 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 Address The PCI configuration register to write. @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. Range 0..15. - @param Value New value of the bit field. + @param Value The new value of the bit field. @return The value written back to the PCI configuration register. @@ -738,14 +888,23 @@ PciCf8BitFieldWrite16 ( IN UINT16 Value ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT16 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 1); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoBitFieldWrite16 ( - PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2), - StartBit, - EndBit, - Value - ); + Result = IoBitFieldWrite16 ( + PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2), + StartBit, + EndBit, + Value + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -765,8 +924,9 @@ PciCf8BitFieldWrite16 ( 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 Address The PCI configuration register to write. @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. @@ -785,14 +945,23 @@ PciCf8BitFieldOr16 ( IN UINT16 OrData ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT16 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 1); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoBitFieldOr16 ( - PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2), - StartBit, - EndBit, - OrData - ); + Result = IoBitFieldOr16 ( + PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2), + StartBit, + EndBit, + OrData + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -812,8 +981,9 @@ PciCf8BitFieldOr16 ( 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 The PCI configuration register to write. @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. @@ -832,14 +1002,23 @@ PciCf8BitFieldAnd16 ( IN UINT16 AndData ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT16 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 1); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoBitFieldAnd16 ( - PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2), - StartBit, - EndBit, - AndData - ); + Result = IoBitFieldAnd16 ( + PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2), + StartBit, + EndBit, + AndData + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -861,8 +1040,10 @@ PciCf8BitFieldAnd16 ( 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 Address The PCI configuration register to write. @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. @@ -883,15 +1064,24 @@ PciCf8BitFieldAndThenOr16( IN UINT16 OrData ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT16 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 1); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoBitFieldAndThenOr16 ( - PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2), - StartBit, - EndBit, - AndData, - OrData - ); + Result = IoBitFieldAndThenOr16 ( + PCI_CONFIGURATION_DATA_PORT + (UINT16)(Address & 2), + StartBit, + EndBit, + AndData, + OrData + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -905,7 +1095,7 @@ PciCf8BitFieldAndThenOr16( If Address is not aligned on a 32-bit boundary, then ASSERT(). If the register specified by Address >= 0x100, then ASSERT(). - @param Address Address that encodes the PCI Bus, Device, Function and + @param Address The address that encodes the PCI Bus, Device, Function and Register. @return The read value from the PCI configuration register. @@ -917,9 +1107,18 @@ PciCf8Read32 ( IN UINTN Address ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT32 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 3); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoRead32 (PCI_CONFIGURATION_DATA_PORT); + Result = IoRead32 (PCI_CONFIGURATION_DATA_PORT); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -933,7 +1132,7 @@ PciCf8Read32 ( If Address is not aligned on a 32-bit boundary, then ASSERT(). If the register specified by Address >= 0x100, then ASSERT(). - @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 Value The value to write. @@ -947,12 +1146,21 @@ PciCf8Write32 ( IN UINT32 Value ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT32 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 3); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoWrite32 ( - PCI_CONFIGURATION_DATA_PORT, - Value - ); + Result = IoWrite32 ( + PCI_CONFIGURATION_DATA_PORT, + Value + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -970,7 +1178,7 @@ PciCf8Write32 ( If Address is not aligned on a 32-bit boundary, then ASSERT(). If the register specified by Address >= 0x100, then ASSERT(). - @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 OrData The value to OR with the PCI configuration register. @@ -984,12 +1192,21 @@ PciCf8Or32 ( IN UINT32 OrData ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT32 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 3); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoOr32 ( - PCI_CONFIGURATION_DATA_PORT, - OrData - ); + Result = IoOr32 ( + PCI_CONFIGURATION_DATA_PORT, + OrData + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -1007,7 +1224,7 @@ PciCf8Or32 ( If Address is not aligned on a 32-bit boundary, then ASSERT(). If the register specified by Address >= 0x100, then ASSERT(). - @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 AndData The value to AND with the PCI configuration register. @@ -1021,12 +1238,21 @@ PciCf8And32 ( IN UINT32 AndData ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT32 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 3); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoAnd32 ( - PCI_CONFIGURATION_DATA_PORT, - AndData - ); + Result = IoAnd32 ( + PCI_CONFIGURATION_DATA_PORT, + AndData + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -1045,7 +1271,7 @@ PciCf8And32 ( If Address is not aligned on a 32-bit boundary, then ASSERT(). If the register specified by Address >= 0x100, then ASSERT(). - @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 AndData The value to AND with the PCI configuration register. @param OrData The value to OR with the result of the AND operation. @@ -1061,13 +1287,22 @@ PciCf8AndThenOr32 ( IN UINT32 OrData ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT32 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 3); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoAndThenOr32 ( - PCI_CONFIGURATION_DATA_PORT, - AndData, - OrData - ); + Result = IoAndThenOr32 ( + PCI_CONFIGURATION_DATA_PORT, + AndData, + OrData + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -1084,7 +1319,7 @@ PciCf8AndThenOr32 ( If EndBit is greater than 31, then ASSERT(). If EndBit is less than StartBit, then ASSERT(). - @param Address PCI configuration register to read. + @param Address The PCI configuration register to read. @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. @@ -1101,13 +1336,22 @@ PciCf8BitFieldRead32 ( IN UINTN EndBit ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT32 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 3); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoBitFieldRead32 ( - PCI_CONFIGURATION_DATA_PORT, - StartBit, - EndBit - ); + Result = IoBitFieldRead32 ( + PCI_CONFIGURATION_DATA_PORT, + StartBit, + EndBit + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -1124,13 +1368,14 @@ PciCf8BitFieldRead32 ( 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 Address The PCI configuration register to write. @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. Range 0..31. - @param Value New value of the bit field. + @param Value The new value of the bit field. @return The value written back to the PCI configuration register. @@ -1144,14 +1389,23 @@ PciCf8BitFieldWrite32 ( IN UINT32 Value ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT32 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 3); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoBitFieldWrite32 ( - PCI_CONFIGURATION_DATA_PORT, - StartBit, - EndBit, - Value - ); + Result = IoBitFieldWrite32 ( + PCI_CONFIGURATION_DATA_PORT, + StartBit, + EndBit, + Value + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -1171,8 +1425,9 @@ PciCf8BitFieldWrite32 ( 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 Address The PCI configuration register to write. @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. @@ -1191,14 +1446,23 @@ PciCf8BitFieldOr32 ( IN UINT32 OrData ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT32 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 3); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoBitFieldOr32 ( - PCI_CONFIGURATION_DATA_PORT, - StartBit, - EndBit, - OrData - ); + Result = IoBitFieldOr32 ( + PCI_CONFIGURATION_DATA_PORT, + StartBit, + EndBit, + OrData + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -1218,8 +1482,9 @@ PciCf8BitFieldOr32 ( 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 The PCI configuration register to write. @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. @@ -1238,14 +1503,23 @@ PciCf8BitFieldAnd32 ( IN UINT32 AndData ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT32 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 3); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoBitFieldAnd32 ( - PCI_CONFIGURATION_DATA_PORT, - StartBit, - EndBit, - AndData - ); + Result = IoBitFieldAnd32 ( + PCI_CONFIGURATION_DATA_PORT, + StartBit, + EndBit, + AndData + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -1267,8 +1541,10 @@ PciCf8BitFieldAnd32 ( 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 Address The PCI configuration register to write. @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. @@ -1289,15 +1565,24 @@ PciCf8BitFieldAndThenOr32( IN UINT32 OrData ) { + BOOLEAN InterruptState; + UINT32 AddressPort; + UINT32 Result; + ASSERT_INVALID_PCI_ADDRESS (Address, 3); + InterruptState = SaveAndDisableInterrupts (); + AddressPort = IoRead32 (PCI_CONFIGURATION_ADDRESS_PORT); IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, PCI_TO_CF8_ADDRESS (Address)); - return IoBitFieldAndThenOr32 ( - PCI_CONFIGURATION_DATA_PORT, - StartBit, - EndBit, - AndData, - OrData - ); + Result = IoBitFieldAndThenOr32 ( + PCI_CONFIGURATION_DATA_PORT, + StartBit, + EndBit, + AndData, + OrData + ); + IoWrite32 (PCI_CONFIGURATION_ADDRESS_PORT, AddressPort); + SetInterruptState (InterruptState); + return Result; } /** @@ -1316,10 +1601,10 @@ PciCf8BitFieldAndThenOr32( If ((StartAddress & 0xFFF) + Size) > 0x100, then ASSERT(). If Size > 0 and Buffer is NULL, then ASSERT(). - @param StartAddress Starting address that encodes the PCI Bus, Device, + @param StartAddress The starting address that encodes the PCI Bus, Device, Function and Register. - @param Size Size in bytes of the transfer. - @param Buffer Pointer to a buffer receiving the data read. + @param Size The size in bytes of the transfer. + @param Buffer The pointer to a buffer receiving the data read. @return Size read from StartAddress. @@ -1416,10 +1701,10 @@ PciCf8ReadBuffer ( If ((StartAddress & 0xFFF) + Size) > 0x100, then ASSERT(). If Size > 0 and Buffer is NULL, then ASSERT(). - @param StartAddress Starting address that encodes the PCI Bus, Device, + @param StartAddress The starting address that encodes the PCI Bus, Device, Function and Register. - @param Size Size in bytes of the transfer. - @param Buffer Pointer to a buffer containing the data to write. + @param Size The size in bytes of the transfer. + @param Buffer The pointer to a buffer containing the data to write. @return Size written to StartAddress.