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 | |
parent | bbfa12f16e9218fcc425c006620392c11e921d87 (diff) | |
download | edk2-0c62737d3893f901cc4eccae8b123765f39b937d.zip edk2-0c62737d3893f901cc4eccae8b123765f39b937d.tar.gz edk2-0c62737d3893f901cc4eccae8b123765f39b937d.tar.bz2 |
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')
-rw-r--r-- | MdePkg/Library/BasePciCf8Lib/PciLib.c | 23 | ||||
-rw-r--r-- | MdePkg/Library/BasePciExpressLib/PciLib.c | 22 |
2 files changed, 28 insertions, 17 deletions
diff --git a/MdePkg/Library/BasePciCf8Lib/PciLib.c b/MdePkg/Library/BasePciCf8Lib/PciLib.c index d95f836..d61f80d 100644 --- a/MdePkg/Library/BasePciCf8Lib/PciLib.c +++ b/MdePkg/Library/BasePciCf8Lib/PciLib.c @@ -15,7 +15,7 @@ #include <Base.h>
-
+#include <Library/BaseLib.h>
#include <Library/PciCf8Lib.h>
#include <Library/IoLib.h>
#include <Library/DebugLib.h>
@@ -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 9042dc4..d368f67 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;
|