diff --git a/MdePkg/Library/BasePciCf8Lib/PciLib.c b/MdePkg/Library/BasePciCf8Lib/PciLib.c index d95f8366b1..d61f80db6e 100644 --- a/MdePkg/Library/BasePciCf8Lib/PciLib.c +++ b/MdePkg/Library/BasePciCf8Lib/PciLib.c @@ -15,7 +15,7 @@ #include - +#include #include #include #include @@ -1301,7 +1301,8 @@ PciCf8ReadBuffer ( OUT VOID *Buffer ) { - UINTN ReturnValue; + UINTN ReturnValue; + UINTN Value; ASSERT_INVALID_PCI_ADDRESS (StartAddress, 0); ASSERT (((StartAddress & 0xFFF) + Size) <= 0x100); @@ -1331,7 +1332,9 @@ PciCf8ReadBuffer ( // // Read a word if StartAddress is word aligned // - *(volatile UINT16 *)Buffer = PciCf8Read16 (StartAddress); + Value = (UINTN) PciCf8Read16 (StartAddress); + WriteUnaligned16 ((UINT16 *)Buffer, (UINT16) Value); + StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1341,7 +1344,8 @@ PciCf8ReadBuffer ( // // Read as many double words as possible // - *(volatile UINT32 *)Buffer = PciCf8Read32 (StartAddress); + Value = (UINTN) PciCf8Read32 (StartAddress); + WriteUnaligned32 ((UINT32 *)Buffer, (UINT32) Value); StartAddress += sizeof (UINT32); Size -= sizeof (UINT32); Buffer = (UINT32*)Buffer + 1; @@ -1351,7 +1355,8 @@ PciCf8ReadBuffer ( // // Read the last remaining word if exist // - *(volatile UINT16 *)Buffer = PciCf8Read16 (StartAddress); + Value = (UINTN) PciCf8Read16 (StartAddress); + WriteUnaligned16 ((UINT16 *)Buffer, (UINT16) Value); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1400,7 +1405,7 @@ PciCf8WriteBuffer ( IN VOID *Buffer ) { - UINTN ReturnValue; + UINTN ReturnValue; ASSERT_INVALID_PCI_ADDRESS (StartAddress, 0); ASSERT (((StartAddress & 0xFFF) + Size) <= 0x100); @@ -1430,7 +1435,7 @@ PciCf8WriteBuffer ( // // Write a word if StartAddress is word aligned // - PciCf8Write16 (StartAddress, *(UINT16*)Buffer); + PciCf8Write16 (StartAddress, ReadUnaligned16 ((UINT16*)Buffer)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1440,7 +1445,7 @@ PciCf8WriteBuffer ( // // Write as many double words as possible // - PciCf8Write32 (StartAddress, *(UINT32*)Buffer); + PciCf8Write32 (StartAddress, ReadUnaligned32 ((UINT32*)Buffer)); StartAddress += sizeof (UINT32); Size -= sizeof (UINT32); Buffer = (UINT32*)Buffer + 1; @@ -1450,7 +1455,7 @@ PciCf8WriteBuffer ( // // Write the last remaining word if exist // - PciCf8Write16 (StartAddress, *(UINT16*)Buffer); + PciCf8Write16 (StartAddress, ReadUnaligned16 ((UINT16*)Buffer)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; diff --git a/MdePkg/Library/BasePciExpressLib/PciLib.c b/MdePkg/Library/BasePciExpressLib/PciLib.c index 9042dc4f84..d368f674b5 100644 --- a/MdePkg/Library/BasePciExpressLib/PciLib.c +++ b/MdePkg/Library/BasePciExpressLib/PciLib.c @@ -21,7 +21,7 @@ #include - +#include #include #include #include @@ -1209,7 +1209,8 @@ PciExpressReadBuffer ( OUT VOID *Buffer ) { - UINTN ReturnValue; + UINTN ReturnValue; + UINTN Value; ASSERT_INVALID_PCI_ADDRESS (StartAddress); ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000); @@ -1239,7 +1240,9 @@ PciExpressReadBuffer ( // // Read a word if StartAddress is word aligned // - *(volatile UINT16 *)Buffer = PciExpressRead16 (StartAddress); + Value = (UINTN) PciExpressRead16 (StartAddress); + WriteUnaligned16 ((UINT16 *) Buffer, (UINT16) Value); + StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1249,7 +1252,9 @@ PciExpressReadBuffer ( // // Read as many double words as possible // - *(volatile UINT32 *)Buffer = PciExpressRead32 (StartAddress); + Value = (UINTN) PciExpressRead32 (StartAddress); + WriteUnaligned32 ((UINT32 *) Buffer, (UINT32) Value); + StartAddress += sizeof (UINT32); Size -= sizeof (UINT32); Buffer = (UINT32*)Buffer + 1; @@ -1259,7 +1264,8 @@ PciExpressReadBuffer ( // // Read the last remaining word if exist // - *(volatile UINT16 *)Buffer = PciExpressRead16 (StartAddress); + Value = (UINTN) PciExpressRead16 (StartAddress); + WriteUnaligned16 ((UINT16 *) Buffer, (UINT16) Value); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1337,7 +1343,7 @@ PciExpressWriteBuffer ( // // Write a word if StartAddress is word aligned // - PciExpressWrite16 (StartAddress, *(UINT16*)Buffer); + PciExpressWrite16 (StartAddress, ReadUnaligned16 ((UINT16*)Buffer)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1347,7 +1353,7 @@ PciExpressWriteBuffer ( // // Write as many double words as possible // - PciExpressWrite32 (StartAddress, *(UINT32*)Buffer); + PciExpressWrite32 (StartAddress, ReadUnaligned32 ((UINT32*)Buffer)); StartAddress += sizeof (UINT32); Size -= sizeof (UINT32); Buffer = (UINT32*)Buffer + 1; @@ -1357,7 +1363,7 @@ PciExpressWriteBuffer ( // // Write the last remaining word if exist // - PciExpressWrite16 (StartAddress, *(UINT16*)Buffer); + PciExpressWrite16 (StartAddress, ReadUnaligned16 ((UINT16*)Buffer)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1;