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