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
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
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
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
// 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