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
This commit is contained in:
yshang1 2007-12-29 02:26:26 +00:00
parent bbfa12f16e
commit 0c62737d38
2 changed files with 28 additions and 17 deletions

View File

@ -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;

View File

@ -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;