/* This function is called whenever we need to ensure that the IOMMU has completed execution of all commands we sent. It sends a COMPLETION_WAIT command and waits for it to finish. The IOMMU informs us about that by writing a value to a physical address we pass with the command.  */
static int iommu_completion_wait(struct amd_iommu *iommu)
/* This function is called whenever we need to ensure that the IOMMU has completed execution of all commands we sent. It sends a COMPLETION_WAIT command and waits for it to finish. The IOMMU informs us about that by writing a value to a physical address we pass with the command.  */
static int iommu_completion_wait(struct amd_iommu *iommu)
{
	int ret = 0;
	unsigned long flags;
	spin_lock_irqsave(&iommu->lock, flags);
	if (!iommu->need_sync)
		goto out;
	ret = __iommu_completion_wait(iommu);
	iommu->need_sync = false;
	if (ret)
		goto out;
	__iommu_wait_for_completion(iommu);
out:
	spin_unlock_irqrestore(&iommu->lock, flags);
	if (iommu->reset_in_progress)
		reset_iommu_command_buffer(iommu);
	return 0;
}