From: xli24 Date: Tue, 19 May 2009 07:09:45 +0000 (+0000) Subject: Fix the unaligned issue of PCI read/write buffer. X-Git-Tag: edk2-stable201903~17939 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;ds=sidebyside;h=5dc4fd785603177d77d186f0d8d56ce7613db2cf;p=mirror_edk2.git Fix the unaligned issue of PCI read/write buffer. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8333 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/MdePkg/Library/PeiPciLibPciCfg2/PciLib.c b/MdePkg/Library/PeiPciLibPciCfg2/PciLib.c index 01306b7b92..65de76046b 100644 --- a/MdePkg/Library/PeiPciLibPciCfg2/PciLib.c +++ b/MdePkg/Library/PeiPciLibPciCfg2/PciLib.c @@ -1272,7 +1272,7 @@ PciReadBuffer ( // // Read a word if StartAddress is word aligned // - *(volatile UINT16 *)Buffer = PciRead16 (StartAddress); + WriteUnaligned16 (Buffer, PciRead16 (StartAddress)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1282,7 +1282,7 @@ PciReadBuffer ( // // Read as many double words as possible // - *(volatile UINT32 *)Buffer = PciRead32 (StartAddress); + WriteUnaligned32 (Buffer, PciRead32 (StartAddress)); StartAddress += sizeof (UINT32); Size -= sizeof (UINT32); Buffer = (UINT32*)Buffer + 1; @@ -1292,7 +1292,7 @@ PciReadBuffer ( // // Read the last remaining word if exist // - *(volatile UINT16 *)Buffer = PciRead16 (StartAddress); + WriteUnaligned16 (Buffer, PciRead16 (StartAddress)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1370,7 +1370,7 @@ PciWriteBuffer ( // // Write a word if StartAddress is word aligned // - PciWrite16 (StartAddress, *(UINT16*)Buffer); + PciWrite16 (StartAddress, ReadUnaligned16 (Buffer)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1380,7 +1380,7 @@ PciWriteBuffer ( // // Write as many double words as possible // - PciWrite32 (StartAddress, *(UINT32*)Buffer); + PciWrite32 (StartAddress, ReadUnaligned32 (Buffer)); StartAddress += sizeof (UINT32); Size -= sizeof (UINT32); Buffer = (UINT32*)Buffer + 1; @@ -1390,7 +1390,7 @@ PciWriteBuffer ( // // Write the last remaining word if exist // - PciWrite16 (StartAddress, *(UINT16*)Buffer); + PciWrite16 (StartAddress, ReadUnaligned16 (Buffer)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; diff --git a/MdePkg/Library/PeiPciSegmentLibPciCfg2/PciSegmentLib.c b/MdePkg/Library/PeiPciSegmentLibPciCfg2/PciSegmentLib.c index 332d2a9b45..a08298aaa2 100644 --- a/MdePkg/Library/PeiPciSegmentLibPciCfg2/PciSegmentLib.c +++ b/MdePkg/Library/PeiPciSegmentLibPciCfg2/PciSegmentLib.c @@ -1259,7 +1259,7 @@ PciSegmentReadBuffer ( // // Read a word if StartAddress is word aligned // - *(volatile UINT16 *)Buffer = PciSegmentRead16 (StartAddress); + WriteUnaligned16 (Buffer, PciSegmentRead16 (StartAddress)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1269,7 +1269,7 @@ PciSegmentReadBuffer ( // // Read as many double words as possible // - *(volatile UINT32 *)Buffer = PciSegmentRead32 (StartAddress); + WriteUnaligned32 (Buffer, PciSegmentRead32 (StartAddress)); StartAddress += sizeof (UINT32); Size -= sizeof (UINT32); Buffer = (UINT32*)Buffer + 1; @@ -1279,7 +1279,7 @@ PciSegmentReadBuffer ( // // Read the last remaining word if exist // - *(volatile UINT16 *)Buffer = PciSegmentRead16 (StartAddress); + WriteUnaligned16 (Buffer, PciSegmentRead16 (StartAddress)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1358,7 +1358,7 @@ PciSegmentWriteBuffer ( // // Write a word if StartAddress is word aligned // - PciSegmentWrite16 (StartAddress, *(UINT16*)Buffer); + PciSegmentWrite16 (StartAddress, ReadUnaligned16 (Buffer)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1368,7 +1368,7 @@ PciSegmentWriteBuffer ( // // Write as many double words as possible // - PciSegmentWrite32 (StartAddress, *(UINT32*)Buffer); + PciSegmentWrite32 (StartAddress, ReadUnaligned32 (Buffer)); StartAddress += sizeof (UINT32); Size -= sizeof (UINT32); Buffer = (UINT32*)Buffer + 1; @@ -1378,7 +1378,7 @@ PciSegmentWriteBuffer ( // // Write the last remaining word if exist // - PciSegmentWrite16 (StartAddress, *(UINT16*)Buffer); + PciSegmentWrite16 (StartAddress, ReadUnaligned16 (Buffer)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; diff --git a/MdePkg/Library/UefiPciLibPciRootBridgeIo/PciLib.c b/MdePkg/Library/UefiPciLibPciRootBridgeIo/PciLib.c index 1f23675364..913b97cc1a 100644 --- a/MdePkg/Library/UefiPciLibPciRootBridgeIo/PciLib.c +++ b/MdePkg/Library/UefiPciLibPciRootBridgeIo/PciLib.c @@ -1286,7 +1286,7 @@ PciReadBuffer ( // // Read a word if StartAddress is word aligned // - *(volatile UINT16 *)Buffer = PciRead16 (StartAddress); + WriteUnaligned16 (Buffer, PciRead16 (StartAddress)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1296,7 +1296,7 @@ PciReadBuffer ( // // Read as many double words as possible // - *(volatile UINT32 *)Buffer = PciRead32 (StartAddress); + WriteUnaligned32 (Buffer, PciRead32 (StartAddress)); StartAddress += sizeof (UINT32); Size -= sizeof (UINT32); Buffer = (UINT32*)Buffer + 1; @@ -1306,7 +1306,7 @@ PciReadBuffer ( // // Read the last remaining word if exist // - *(volatile UINT16 *)Buffer = PciRead16 (StartAddress); + WriteUnaligned16 (Buffer, PciRead16 (StartAddress)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1384,7 +1384,7 @@ PciWriteBuffer ( // // Write a word if StartAddress is word aligned // - PciWrite16 (StartAddress, *(UINT16*)Buffer); + PciWrite16 (StartAddress, ReadUnaligned16 (Buffer)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1394,7 +1394,7 @@ PciWriteBuffer ( // // Write as many double words as possible // - PciWrite32 (StartAddress, *(UINT32*)Buffer); + PciWrite32 (StartAddress, ReadUnaligned32 (Buffer)); StartAddress += sizeof (UINT32); Size -= sizeof (UINT32); Buffer = (UINT32*)Buffer + 1; @@ -1404,7 +1404,7 @@ PciWriteBuffer ( // // Write the last remaining word if exist // - PciWrite16 (StartAddress, *(UINT16*)Buffer); + PciWrite16 (StartAddress, ReadUnaligned16 (Buffer)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; diff --git a/MdePkg/Library/UefiPciSegmentLibPciRootBridgeIo/PciSegmentLib.c b/MdePkg/Library/UefiPciSegmentLibPciRootBridgeIo/PciSegmentLib.c index 97fd240a0e..da153f994a 100644 --- a/MdePkg/Library/UefiPciSegmentLibPciRootBridgeIo/PciSegmentLib.c +++ b/MdePkg/Library/UefiPciSegmentLibPciRootBridgeIo/PciSegmentLib.c @@ -1338,7 +1338,7 @@ PciSegmentReadBuffer ( // // Read a word if StartAddress is word aligned // - *(volatile UINT16 *)Buffer = PciSegmentRead16 (StartAddress); + WriteUnaligned16 (Buffer, PciSegmentRead16 (StartAddress)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1348,7 +1348,7 @@ PciSegmentReadBuffer ( // // Read as many double words as possible // - *(volatile UINT32 *)Buffer = PciSegmentRead32 (StartAddress); + WriteUnaligned32 (Buffer, PciSegmentRead32 (StartAddress)); StartAddress += sizeof (UINT32); Size -= sizeof (UINT32); Buffer = (UINT32*)Buffer + 1; @@ -1358,7 +1358,7 @@ PciSegmentReadBuffer ( // // Read the last remaining word if exist // - *(volatile UINT16 *)Buffer = PciSegmentRead16 (StartAddress); + WriteUnaligned16 (Buffer, PciSegmentRead16 (StartAddress)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1436,7 +1436,7 @@ PciSegmentWriteBuffer ( // // Write a word if StartAddress is word aligned // - PciSegmentWrite16 (StartAddress, *(UINT16*)Buffer); + PciSegmentWrite16 (StartAddress, ReadUnaligned16 (Buffer)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1; @@ -1446,7 +1446,7 @@ PciSegmentWriteBuffer ( // // Write as many double words as possible // - PciSegmentWrite32 (StartAddress, *(UINT32*)Buffer); + PciSegmentWrite32 (StartAddress, ReadUnaligned32 (Buffer)); StartAddress += sizeof (UINT32); Size -= sizeof (UINT32); Buffer = (UINT32*)Buffer + 1; @@ -1456,7 +1456,7 @@ PciSegmentWriteBuffer ( // // Write the last remaining word if exist // - PciSegmentWrite16 (StartAddress, *(UINT16*)Buffer); + PciSegmentWrite16 (StartAddress, ReadUnaligned16 (Buffer)); StartAddress += sizeof (UINT16); Size -= sizeof (UINT16); Buffer = (UINT16*)Buffer + 1;