OSDN Git Service

AMD IOMMU: refactor completion wait handling into separate functions
authorJoerg Roedel <joerg.roedel@amd.com>
Tue, 2 Dec 2008 19:34:41 +0000 (20:34 +0100)
committerJoerg Roedel <joerg.roedel@amd.com>
Sat, 3 Jan 2009 13:11:54 +0000 (14:11 +0100)
Impact: split one function into three

The separate functions are required synchronize commands across all
hardware IOMMUs in the system.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
arch/x86/kernel/amd_iommu.c

index 0922d5f..2280ef8 100644 (file)
@@ -196,6 +196,46 @@ static int iommu_queue_command(struct amd_iommu *iommu, struct iommu_cmd *cmd)
 }
 
 /*
+ * This function waits until an IOMMU has completed a completion
+ * wait command
+ */
+static void __iommu_wait_for_completion(struct amd_iommu *iommu)
+{
+       int ready = 0;
+       unsigned status = 0;
+       unsigned long i = 0;
+
+       while (!ready && (i < EXIT_LOOP_COUNT)) {
+               ++i;
+               /* wait for the bit to become one */
+               status = readl(iommu->mmio_base + MMIO_STATUS_OFFSET);
+               ready = status & MMIO_STATUS_COM_WAIT_INT_MASK;
+       }
+
+       /* set bit back to zero */
+       status &= ~MMIO_STATUS_COM_WAIT_INT_MASK;
+       writel(status, iommu->mmio_base + MMIO_STATUS_OFFSET);
+
+       if (unlikely(i == EXIT_LOOP_COUNT))
+               panic("AMD IOMMU: Completion wait loop failed\n");
+}
+
+/*
+ * This function queues a completion wait command into the command
+ * buffer of an IOMMU
+ */
+static int __iommu_completion_wait(struct amd_iommu *iommu)
+{
+       struct iommu_cmd cmd;
+
+        memset(&cmd, 0, sizeof(cmd));
+        cmd.data[0] = CMD_COMPL_WAIT_INT_MASK;
+        CMD_SET_TYPE(&cmd, CMD_COMPL_WAIT);
+
+        return __iommu_queue_command(iommu, &cmd);
+}
+
+/*
  * 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
@@ -204,40 +244,22 @@ static int iommu_queue_command(struct amd_iommu *iommu, struct iommu_cmd *cmd)
  */
 static int iommu_completion_wait(struct amd_iommu *iommu)
 {
-       int ret = 0, ready = 0;
-       unsigned status = 0;
-       struct iommu_cmd cmd;
-       unsigned long flags, i = 0;
-
-       memset(&cmd, 0, sizeof(cmd));
-       cmd.data[0] = CMD_COMPL_WAIT_INT_MASK;
-       CMD_SET_TYPE(&cmd, CMD_COMPL_WAIT);
+       int ret = 0;
+       unsigned long flags;
 
        spin_lock_irqsave(&iommu->lock, flags);
 
        if (!iommu->need_sync)
                goto out;
 
-       iommu->need_sync = 0;
+       ret = __iommu_completion_wait(iommu);
 
-       ret = __iommu_queue_command(iommu, &cmd);
+       iommu->need_sync = 0;
 
        if (ret)
                goto out;
 
-       while (!ready && (i < EXIT_LOOP_COUNT)) {
-               ++i;
-               /* wait for the bit to become one */
-               status = readl(iommu->mmio_base + MMIO_STATUS_OFFSET);
-               ready = status & MMIO_STATUS_COM_WAIT_INT_MASK;
-       }
-
-       /* set bit back to zero */
-       status &= ~MMIO_STATUS_COM_WAIT_INT_MASK;
-       writel(status, iommu->mmio_base + MMIO_STATUS_OFFSET);
-
-       if (unlikely(i == EXIT_LOOP_COUNT))
-               panic("AMD IOMMU: Completion wait loop failed\n");
+       __iommu_wait_for_completion(iommu);
 
 out:
        spin_unlock_irqrestore(&iommu->lock, flags);