]> git.openfabrics.org - ~emulex/infiniband.git/commitdiff
x86/amd-iommu: Add an index field to struct amd_iommu
authorJoerg Roedel <joerg.roedel@amd.com>
Fri, 20 Nov 2009 13:31:51 +0000 (14:31 +0100)
committerJoerg Roedel <joerg.roedel@amd.com>
Fri, 27 Nov 2009 10:45:49 +0000 (11:45 +0100)
This patch adds an index field to struct amd_iommu which can
be used to lookup it up in an array. This index will be used
in struct protection_domain to keep track which protection
domain has devices behind which IOMMU.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
arch/x86/include/asm/amd_iommu_types.h
arch/x86/kernel/amd_iommu_init.c

index df5e9c8a856af8cfe05b0cc932067cf571efbb4d..ab3e7bf1af7158e4ed422f042bc2ca075f1ba1d4 100644 (file)
 #include <linux/list.h>
 #include <linux/spinlock.h>
 
+/*
+ * Maximum number of IOMMUs supported
+ */
+#define MAX_IOMMUS     32
+
 /*
  * some size calculation constants
  */
@@ -291,6 +296,9 @@ struct dma_ops_domain {
 struct amd_iommu {
        struct list_head list;
 
+       /* Index within the IOMMU array */
+       int index;
+
        /* locks the accesses to the hardware */
        spinlock_t lock;
 
@@ -356,6 +364,15 @@ struct amd_iommu {
  */
 extern struct list_head amd_iommu_list;
 
+/*
+ * Array with pointers to each IOMMU struct
+ * The indices are referenced in the protection domains
+ */
+extern struct amd_iommu *amd_iommus[MAX_IOMMUS];
+
+/* Number of IOMMUs present in the system */
+extern int amd_iommus_present;
+
 /*
  * Structure defining one entry in the device table
  */
index cee11424d412d992cb69dd2fa848b38b733ffe8f..8567d16980274879bda5352f9e0de4a4cd9236ac 100644 (file)
@@ -137,6 +137,10 @@ bool amd_iommu_unmap_flush;                /* if true, flush on every unmap */
 LIST_HEAD(amd_iommu_list);             /* list of all AMD IOMMUs in the
                                           system */
 
+/* Array to assign indices to IOMMUs*/
+struct amd_iommu *amd_iommus[MAX_IOMMUS];
+int amd_iommus_present;
+
 /*
  * Pointer to the device table which is shared by all AMD IOMMUs
  * it is indexed by the PCI device id or the HT unit id and contains
@@ -840,7 +844,18 @@ static void __init free_iommu_all(void)
 static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h)
 {
        spin_lock_init(&iommu->lock);
+
+       /* Add IOMMU to internal data structures */
        list_add_tail(&iommu->list, &amd_iommu_list);
+       iommu->index             = amd_iommus_present++;
+
+       if (unlikely(iommu->index >= MAX_IOMMUS)) {
+               WARN(1, "AMD-Vi: System has more IOMMUs than supported by this driver\n");
+               return -ENOSYS;
+       }
+
+       /* Index is fine - add IOMMU to the array */
+       amd_iommus[iommu->index] = iommu;
 
        /*
         * Copy data from ACPI table entry to the iommu struct