diff options
author | yshang1 <yshang1@6f19259b-4bc3-4df7-8a09-765794883524> | 2007-12-29 02:26:26 +0000 |
---|---|---|
committer | yshang1 <yshang1@6f19259b-4bc3-4df7-8a09-765794883524> | 2007-12-29 02:26:26 +0000 |
commit | 0c62737d3893f901cc4eccae8b123765f39b937d (patch) | |
tree | 0749f799c98d7dfd7fe40a7cf37e50b3dc30c636 /MdePkg/Library/BasePciExpressLib | |
parent | bbfa12f16e9218fcc425c006620392c11e921d87 (diff) | |
download | edk2-platforms-0c62737d3893f901cc4eccae8b123765f39b937d.tar.xz |
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
Diffstat (limited to 'MdePkg/Library/BasePciExpressLib')
-rw-r--r-- | MdePkg/Library/BasePciExpressLib/PciLib.c | 22 |
1 files changed, 14 insertions, 8 deletions
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 <Base.h>
-
+#include <Library/BaseLib.h>
#include <Library/PciExpressLib.h>
#include <Library/IoLib.h>
#include <Library/DebugLib.h>
@@ -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;
|