]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/PcatSingleSegmentPciCfgPei/PciCfg2.c
1. EDK_RELEASE_VERSION removed;
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / PcatSingleSegmentPciCfgPei / PciCfg2.c
index a524fc346298822f3de23773c84cdb58b3621a43..852476ddd01a8df622899d24a1be328d0678e68c 100644 (file)
@@ -134,9 +134,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
@@ -185,9 +215,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
@@ -247,13 +307,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
@@ -265,15 +360,16 @@ PciCfg2Modify (
   This routine will install EFI_PEI_PCI_CFG2_PPI or EFI_PEI_PCI_CFG_PPI\r
   according to PeiServices's version.\r
   \r
-  @param FfsHeader    Image's header\r
-  @param PeiServices  Pointer of EFI_PEI_SERVICES\r
+  @param  FileHandle  Handle of the file being invoked.\r
+  @param  PeiServices Describes the list of possible PEI Services.\r
+\r
   @return Whether success to install service\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 PeimInitializePciCfg (\r
-  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r
-  IN EFI_PEI_SERVICES          **PeiServices\r
+  IN       EFI_PEI_FILE_HANDLE  FileHandle,\r
+  IN CONST EFI_PEI_SERVICES     **PeiServices\r
   )\r
 {\r
   EFI_STATUS            Status;\r
@@ -292,16 +388,16 @@ PeimInitializePciCfg (
     // FrameworkPeiServices = (FRAMEWORK_PEI_SERVICES **) PeiServices;\r
     // (**FrameworkPeiServices).PciCfg = &mPciCfgPpi;\r
     // \r
-    (**PeiServices).PciCfg = (EFI_PEI_PCI_CFG2_PPI *) &gPciCfgPpi;\r
+    (**(EFI_PEI_SERVICES**)PeiServices).PciCfg = (EFI_PEI_PCI_CFG2_PPI *) &gPciCfgPpi;\r
   } else {\r
-    (**PeiServices).PciCfg = &gPciCfg2Ppi;\r
+    (**(EFI_PEI_SERVICES**)PeiServices).PciCfg = &gPciCfg2Ppi;\r
   }\r
   \r
   if (!FeaturePcdGet (PcdPciCfgDisable)) {\r
-    Status = (**PeiServices).InstallPpi ((CONST EFI_PEI_SERVICES **)PeiServices, &gPciCfgPpiList);\r
+    Status = (**PeiServices).InstallPpi (PeiServices, &gPciCfgPpiList);\r
   } \r
   if (!FeaturePcdGet (PcdPciCfg2Disable)) {\r
-    Status = (**PeiServices).InstallPpi ((CONST EFI_PEI_SERVICES **)PeiServices, &gPciCfg2PpiList);\r
+    Status = (**PeiServices).InstallPpi (PeiServices, &gPciCfg2PpiList);\r
   }\r
 \r
   return Status;\r