/* Write the config space of a given PCI device (both normal and extended). */
STATIC RETURN_STATUS EFIAPI SegmentDevWriteConfig(IN PCI_CAP_DEV *PciDevice, IN UINT16 DestinationOffset, IN VOID *SourceBuffer, IN UINT16 Size)
/* Write the config space of a given PCI device (both normal and extended). */
STATIC RETURN_STATUS EFIAPI SegmentDevWriteConfig(IN PCI_CAP_DEV *PciDevice, IN UINT16 DestinationOffset, IN VOID *SourceBuffer, IN UINT16 Size)
{
  SEGMENT_DEV  *SegmentDev;
  UINT16       ConfigSpaceSize;
  UINT64       DestinationAddress;
  SegmentDev      = SEGMENT_DEV_FROM_PCI_CAP_DEV (PciDevice);
  ConfigSpaceSize = (SegmentDev->MaxDomain == PciCapNormal ?
                     PCI_MAX_CONFIG_OFFSET : PCI_EXP_MAX_CONFIG_OFFSET);
  if (DestinationOffset + Size > ConfigSpaceSize) {
    return RETURN_UNSUPPORTED;
  }
  DestinationAddress = PCI_SEGMENT_LIB_ADDRESS (
                         SegmentDev->SegmentNr,
                         SegmentDev->BusNr,
                         SegmentDev->DeviceNr,
                         SegmentDev->FunctionNr,
                         DestinationOffset
                         );
  PciSegmentWriteBuffer (DestinationAddress, Size, SourceBuffer);
  return RETURN_SUCCESS;
}