/* Writes the command to the IOMMUs command buffer and informs the hardware about the new command. Must be called with iommu->lock held.  */
static int __iommu_queue_command(struct amd_iommu *iommu, struct iommu_cmd *cmd)
/* Writes the command to the IOMMUs command buffer and informs the hardware about the new command. Must be called with iommu->lock held.  */
static int __iommu_queue_command(struct amd_iommu *iommu, struct iommu_cmd *cmd)
{
	u32 tail, head;
	u8 *target;
	tail = readl(iommu->mmio_base + MMIO_CMD_TAIL_OFFSET);
	target = iommu->cmd_buf + tail;
	memcpy_toio(target, cmd, sizeof(*cmd));
	tail = (tail + sizeof(*cmd)) % iommu->cmd_buf_size;
	head = readl(iommu->mmio_base + MMIO_CMD_HEAD_OFFSET);
	if (tail == head)
		return -ENOMEM;
	writel(tail, iommu->mmio_base + MMIO_CMD_TAIL_OFFSET);
	return 0;
}