]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BasePciCf8Lib/PciLib.c
Since PciXXXReadBuffer/PciXXXWriteBuffer does not check the alignment of user buffer...
[mirror_edk2.git] / MdePkg / Library / BasePciCf8Lib / PciLib.c
index d95f8366b1d9e1cce9dc5aa150b284becc8775a6..d61f80db6e1b28b21493de6d5cbfb0950dbaee28 100644 (file)
@@ -15,7 +15,7 @@
 \r
 #include <Base.h>\r
 \r
-\r
+#include <Library/BaseLib.h>\r
 #include <Library/PciCf8Lib.h>\r
 #include <Library/IoLib.h>\r
 #include <Library/DebugLib.h>\r
@@ -1301,7 +1301,8 @@ PciCf8ReadBuffer (
   OUT     VOID                      *Buffer\r
   )\r
 {\r
-  UINTN                             ReturnValue;\r
+  UINTN   ReturnValue;\r
+  UINTN   Value;\r
 \r
   ASSERT_INVALID_PCI_ADDRESS (StartAddress, 0);\r
   ASSERT (((StartAddress & 0xFFF) + Size) <= 0x100);\r
@@ -1331,7 +1332,9 @@ PciCf8ReadBuffer (
     //\r
     // Read a word if StartAddress is word aligned\r
     //\r
-    *(volatile UINT16 *)Buffer = PciCf8Read16 (StartAddress);\r
+    Value = (UINTN) PciCf8Read16 (StartAddress);\r
+    WriteUnaligned16 ((UINT16 *)Buffer, (UINT16) Value);\r
+\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
@@ -1341,7 +1344,8 @@ PciCf8ReadBuffer (
     //\r
     // Read as many double words as possible\r
     //\r
-    *(volatile UINT32 *)Buffer = PciCf8Read32 (StartAddress);\r
+    Value = (UINTN) PciCf8Read32 (StartAddress);\r
+    WriteUnaligned32 ((UINT32 *)Buffer, (UINT32) Value);\r
     StartAddress += sizeof (UINT32);\r
     Size -= sizeof (UINT32);\r
     Buffer = (UINT32*)Buffer + 1;\r
@@ -1351,7 +1355,8 @@ PciCf8ReadBuffer (
     //\r
     // Read the last remaining word if exist\r
     //\r
-    *(volatile UINT16 *)Buffer = PciCf8Read16 (StartAddress);\r
+    Value = (UINTN) PciCf8Read16 (StartAddress);\r
+    WriteUnaligned16 ((UINT16 *)Buffer, (UINT16) Value);\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
@@ -1400,7 +1405,7 @@ PciCf8WriteBuffer (
   IN      VOID                      *Buffer\r
   )\r
 {\r
-  UINTN                             ReturnValue;\r
+  UINTN   ReturnValue;\r
 \r
   ASSERT_INVALID_PCI_ADDRESS (StartAddress, 0);\r
   ASSERT (((StartAddress & 0xFFF) + Size) <= 0x100);\r
@@ -1430,7 +1435,7 @@ PciCf8WriteBuffer (
     //\r
     // Write a word if StartAddress is word aligned\r
     //\r
-    PciCf8Write16 (StartAddress, *(UINT16*)Buffer);\r
+    PciCf8Write16 (StartAddress, ReadUnaligned16 ((UINT16*)Buffer));\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
@@ -1440,7 +1445,7 @@ PciCf8WriteBuffer (
     //\r
     // Write as many double words as possible\r
     //\r
-    PciCf8Write32 (StartAddress, *(UINT32*)Buffer);\r
+    PciCf8Write32 (StartAddress, ReadUnaligned32 ((UINT32*)Buffer));\r
     StartAddress += sizeof (UINT32);\r
     Size -= sizeof (UINT32);\r
     Buffer = (UINT32*)Buffer + 1;\r
@@ -1450,7 +1455,7 @@ PciCf8WriteBuffer (
     //\r
     // Write the last remaining word if exist\r
     //\r
-    PciCf8Write16 (StartAddress, *(UINT16*)Buffer);\r
+    PciCf8Write16 (StartAddress, ReadUnaligned16 ((UINT16*)Buffer));\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r