From 0c62737d3893f901cc4eccae8b123765f39b937d Mon Sep 17 00:00:00 2001 From: yshang1 Date: Sat, 29 Dec 2007 02:26:26 +0000 Subject: Since PciXXXReadBuffer/PciXXXWriteBuffer does not check the alignment of user buffer, if the alignment of user buffer is different than the PCI Address on IPF, the library would generate the Alignment Fault. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4447 6f19259b-4bc3-4df7-8a09-765794883524 --- MdePkg/Library/BasePciExpressLib/PciLib.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'MdePkg/Library/BasePciExpressLib') 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; -- cgit v1.2.3