]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Enhance PciCfg2 driver to handle unaligned Pci access according to PI spec.
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 18 Dec 2008 07:40:19 +0000 (07:40 +0000)
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 18 Dec 2008 07:40:19 +0000 (07:40 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7077 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/PcatSingleSegmentPciCfg2Pei/PcatSingleSegmentPciCfg2Pei.inf
MdeModulePkg/Universal/PcatSingleSegmentPciCfg2Pei/PciCfg2.c

index 2894e75b707e186fddef0ca7d8ad1d5df788fff2..e46a1c32c8a82efa783bcd9421351f18ccab4075 100644 (file)
 \r
 [Depex]\r
   TRUE\r
-\r
-[FixedPcd.common]\r
-  ##\r
-  #  Disable ASSERT for unalign PCI IO access according to PI Spec Volume 1\r
-  #  Spec has not this requirement.\r
-  ##\r
-       gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x0E\r
index 6ea2cfb8e8b1fe02064a77559813eb318fd74fb7..fdd67f7abb86b66483fca1a04631ea4c1e8b20e9 100644 (file)
@@ -227,9 +227,39 @@ PciCfg2Read (
   if (Width == EfiPeiPciCfgWidthUint8) {\r
     *((UINT8 *) Buffer) = PciRead8 (PciLibAddress);\r
   } else if (Width == EfiPeiPciCfgWidthUint16) {\r
-    *((UINT16 *) Buffer) = PciRead16 (PciLibAddress);\r
+    if ((PciLibAddress & 0x01) == 0) {\r
+      //\r
+      // Aligned Pci address access\r
+      //\r
+      WriteUnaligned16 (((UINT16 *) Buffer), PciRead16 (PciLibAddress));\r
+    } else {\r
+      //\r
+      // Unaligned Pci address access, break up the request into byte by byte.\r
+      //\r
+      *((UINT8 *) Buffer) = PciRead8 (PciLibAddress);\r
+      *((UINT8 *) Buffer + 1) = PciRead8 (PciLibAddress + 1);\r
+    }\r
   } else if (Width == EfiPeiPciCfgWidthUint32) {\r
-    *((UINT32 *) Buffer) = PciRead32 (PciLibAddress);\r
+    if ((PciLibAddress & 0x03) == 0) {\r
+      //\r
+      // Aligned Pci address access\r
+      //\r
+      WriteUnaligned32 (((UINT32 *) Buffer), PciRead32 (PciLibAddress));\r
+    } else if ((PciLibAddress & 0x01) == 0) {\r
+      //\r
+      // Unaligned Pci address access, break up the request into word by word.\r
+      //\r
+      WriteUnaligned16 (((UINT16 *) Buffer), PciRead16 (PciLibAddress));\r
+      WriteUnaligned16 (((UINT16 *) Buffer + 1), PciRead16 (PciLibAddress + 2));\r
+    } else {\r
+      //\r
+      // Unaligned Pci address access, break up the request into byte by byte.\r
+      //\r
+      *((UINT8 *) Buffer) = PciRead8 (PciLibAddress);\r
+      *((UINT8 *) Buffer + 1) = PciRead8 (PciLibAddress + 1);\r
+      *((UINT8 *) Buffer + 2) = PciRead8 (PciLibAddress + 2);\r
+      *((UINT8 *) Buffer + 3) = PciRead8 (PciLibAddress + 3);\r
+    }\r
   } else {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -278,9 +308,39 @@ PciCfg2Write (
   if (Width == EfiPeiPciCfgWidthUint8) {\r
     PciWrite8 (PciLibAddress, *((UINT8 *) Buffer));\r
   } else if (Width == EfiPeiPciCfgWidthUint16) {\r
-    PciWrite16 (PciLibAddress, *((UINT16 *) Buffer));\r
+    if ((PciLibAddress & 0x01) == 0) {\r
+      //\r
+      // Aligned Pci address access\r
+      //\r
+      PciWrite16 (PciLibAddress, ReadUnaligned16 ((UINT16 *) Buffer));\r
+    } else {\r
+      //\r
+      // Unaligned Pci address access, break up the request into byte by byte.\r
+      //\r
+      PciWrite8 (PciLibAddress, *((UINT8 *) Buffer));\r
+      PciWrite8 (PciLibAddress + 1, *((UINT8 *) Buffer + 1)); \r
+    }\r
   } else if (Width == EfiPeiPciCfgWidthUint32) {\r
-    PciWrite32 (PciLibAddress, *((UINT32 *) Buffer));\r
+    if ((PciLibAddress & 0x03) == 0) {\r
+      //\r
+      // Aligned Pci address access\r
+      //\r
+      PciWrite32 (PciLibAddress, ReadUnaligned32 ((UINT32 *) Buffer));\r
+    } else if ((PciLibAddress & 0x01) == 0) {\r
+      //\r
+      // Unaligned Pci address access, break up the request into word by word.\r
+      //\r
+      PciWrite16 (PciLibAddress, ReadUnaligned16 ((UINT16 *) Buffer));\r
+      PciWrite16 (PciLibAddress + 2, ReadUnaligned16 ((UINT16 *) Buffer + 1));\r
+    } else {\r
+      //\r
+      // Unaligned Pci address access, break up the request into byte by byte.\r
+      //\r
+      PciWrite8 (PciLibAddress, *((UINT8 *) Buffer));\r
+      PciWrite8 (PciLibAddress + 1, *((UINT8 *) Buffer + 1)); \r
+      PciWrite8 (PciLibAddress + 2, *((UINT8 *) Buffer + 2)); \r
+      PciWrite8 (PciLibAddress + 3, *((UINT8 *) Buffer + 3)); \r
+    }\r
   } else {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -340,13 +400,48 @@ PciCfg2Modify (
   if (Width == EfiPeiPciCfgWidthUint8) {\r
     PciAndThenOr8 (PciLibAddress, (UINT8) (~(*(UINT8 *) ClearBits)), *((UINT8 *) SetBits));\r
   } else if (Width == EfiPeiPciCfgWidthUint16) {\r
-    ClearValue16  = (UINT16) (~ReadUnaligned16 ((UINT16 *) ClearBits));\r
-    SetValue16    = ReadUnaligned16 ((UINT16 *) SetBits);\r
-    PciAndThenOr16 (PciLibAddress, ClearValue16, SetValue16);\r
+    if ((PciLibAddress & 0x01) == 0) {\r
+      //\r
+      // Aligned Pci address access\r
+      //\r
+      ClearValue16  = (UINT16) (~ReadUnaligned16 ((UINT16 *) ClearBits));\r
+      SetValue16    = ReadUnaligned16 ((UINT16 *) SetBits);\r
+      PciAndThenOr16 (PciLibAddress, ClearValue16, SetValue16);\r
+    } else {\r
+      //\r
+      // Unaligned Pci address access, break up the request into byte by byte.\r
+      //\r
+      PciAndThenOr8 (PciLibAddress, (UINT8) (~(*(UINT8 *) ClearBits)), *((UINT8 *) SetBits));\r
+      PciAndThenOr8 (PciLibAddress + 1, (UINT8) (~(*((UINT8 *) ClearBits + 1))), *((UINT8 *) SetBits + 1));\r
+    }\r
   } else if (Width == EfiPeiPciCfgWidthUint32) {\r
-    ClearValue32  = (UINT32) (~ReadUnaligned32 ((UINT32 *) ClearBits));\r
-    SetValue32    = ReadUnaligned32 ((UINT32 *) SetBits);\r
-    PciAndThenOr32 (PciLibAddress, ClearValue32, SetValue32);\r
+    if ((PciLibAddress & 0x03) == 0) {\r
+      //\r
+      // Aligned Pci address access\r
+      //\r
+      ClearValue32  = (UINT32) (~ReadUnaligned32 ((UINT32 *) ClearBits));\r
+      SetValue32    = ReadUnaligned32 ((UINT32 *) SetBits);\r
+      PciAndThenOr32 (PciLibAddress, ClearValue32, SetValue32);\r
+    } else if ((PciLibAddress & 0x01) == 0) {\r
+      //\r
+      // Unaligned Pci address access, break up the request into word by word.\r
+      //\r
+      ClearValue16  = (UINT16) (~ReadUnaligned16 ((UINT16 *) ClearBits));\r
+      SetValue16    = ReadUnaligned16 ((UINT16 *) SetBits);\r
+      PciAndThenOr16 (PciLibAddress, ClearValue16, SetValue16);\r
+\r
+      ClearValue16  = (UINT16) (~ReadUnaligned16 ((UINT16 *) ClearBits + 1));\r
+      SetValue16    = ReadUnaligned16 ((UINT16 *) SetBits + 1);\r
+      PciAndThenOr16 (PciLibAddress + 2, ClearValue16, SetValue16);\r
+    } else {\r
+      //\r
+      // Unaligned Pci address access, break up the request into byte by byte.\r
+      //\r
+      PciAndThenOr8 (PciLibAddress, (UINT8) (~(*(UINT8 *) ClearBits)), *((UINT8 *) SetBits));\r
+      PciAndThenOr8 (PciLibAddress + 1, (UINT8) (~(*((UINT8 *) ClearBits + 1))), *((UINT8 *) SetBits + 1));\r
+      PciAndThenOr8 (PciLibAddress + 2, (UINT8) (~(*((UINT8 *) ClearBits + 2))), *((UINT8 *) SetBits + 2));\r
+      PciAndThenOr8 (PciLibAddress + 3, (UINT8) (~(*((UINT8 *) ClearBits + 3))), *((UINT8 *) SetBits + 3));\r
+    }\r
   } else {\r
     return EFI_INVALID_PARAMETER;\r
   }\r