diff options
author | Joerg Roedel <joerg.roedel@amd.com> | 2009-11-20 08:31:51 -0500 |
---|---|---|
committer | Joerg Roedel <joerg.roedel@amd.com> | 2009-11-27 05:45:49 -0500 |
commit | bb52777ec4d736c2d7c4f037b32d4eeeb172ed89 (patch) | |
tree | dfeed02c76169a92fd04e12145c72f9a0cbaf6f7 /arch | |
parent | bf3118c1276d27fe9e84aa42382da25ee0750777 (diff) |
x86/amd-iommu: Add an index field to struct amd_iommu
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>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/x86/include/asm/amd_iommu_types.h | 17 | ||||
-rw-r--r-- | arch/x86/kernel/amd_iommu_init.c | 15 |
2 files changed, 32 insertions, 0 deletions
diff --git a/arch/x86/include/asm/amd_iommu_types.h b/arch/x86/include/asm/amd_iommu_types.h index df5e9c8a856a..ab3e7bf1af71 100644 --- a/arch/x86/include/asm/amd_iommu_types.h +++ b/arch/x86/include/asm/amd_iommu_types.h | |||
@@ -25,6 +25,11 @@ | |||
25 | #include <linux/spinlock.h> | 25 | #include <linux/spinlock.h> |
26 | 26 | ||
27 | /* | 27 | /* |
28 | * Maximum number of IOMMUs supported | ||
29 | */ | ||
30 | #define MAX_IOMMUS 32 | ||
31 | |||
32 | /* | ||
28 | * some size calculation constants | 33 | * some size calculation constants |
29 | */ | 34 | */ |
30 | #define DEV_TABLE_ENTRY_SIZE 32 | 35 | #define DEV_TABLE_ENTRY_SIZE 32 |
@@ -291,6 +296,9 @@ struct dma_ops_domain { | |||
291 | struct amd_iommu { | 296 | struct amd_iommu { |
292 | struct list_head list; | 297 | struct list_head list; |
293 | 298 | ||
299 | /* Index within the IOMMU array */ | ||
300 | int index; | ||
301 | |||
294 | /* locks the accesses to the hardware */ | 302 | /* locks the accesses to the hardware */ |
295 | spinlock_t lock; | 303 | spinlock_t lock; |
296 | 304 | ||
@@ -357,6 +365,15 @@ struct amd_iommu { | |||
357 | extern struct list_head amd_iommu_list; | 365 | extern struct list_head amd_iommu_list; |
358 | 366 | ||
359 | /* | 367 | /* |
368 | * Array with pointers to each IOMMU struct | ||
369 | * The indices are referenced in the protection domains | ||
370 | */ | ||
371 | extern struct amd_iommu *amd_iommus[MAX_IOMMUS]; | ||
372 | |||
373 | /* Number of IOMMUs present in the system */ | ||
374 | extern int amd_iommus_present; | ||
375 | |||
376 | /* | ||
360 | * Structure defining one entry in the device table | 377 | * Structure defining one entry in the device table |
361 | */ | 378 | */ |
362 | struct dev_table_entry { | 379 | struct dev_table_entry { |
diff --git a/arch/x86/kernel/amd_iommu_init.c b/arch/x86/kernel/amd_iommu_init.c index cee11424d412..8567d1698027 100644 --- a/arch/x86/kernel/amd_iommu_init.c +++ b/arch/x86/kernel/amd_iommu_init.c | |||
@@ -137,6 +137,10 @@ bool amd_iommu_unmap_flush; /* if true, flush on every unmap */ | |||
137 | LIST_HEAD(amd_iommu_list); /* list of all AMD IOMMUs in the | 137 | LIST_HEAD(amd_iommu_list); /* list of all AMD IOMMUs in the |
138 | system */ | 138 | system */ |
139 | 139 | ||
140 | /* Array to assign indices to IOMMUs*/ | ||
141 | struct amd_iommu *amd_iommus[MAX_IOMMUS]; | ||
142 | int amd_iommus_present; | ||
143 | |||
140 | /* | 144 | /* |
141 | * Pointer to the device table which is shared by all AMD IOMMUs | 145 | * Pointer to the device table which is shared by all AMD IOMMUs |
142 | * it is indexed by the PCI device id or the HT unit id and contains | 146 | * 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) | |||
840 | static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h) | 844 | static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h) |
841 | { | 845 | { |
842 | spin_lock_init(&iommu->lock); | 846 | spin_lock_init(&iommu->lock); |
847 | |||
848 | /* Add IOMMU to internal data structures */ | ||
843 | list_add_tail(&iommu->list, &amd_iommu_list); | 849 | list_add_tail(&iommu->list, &amd_iommu_list); |
850 | iommu->index = amd_iommus_present++; | ||
851 | |||
852 | if (unlikely(iommu->index >= MAX_IOMMUS)) { | ||
853 | WARN(1, "AMD-Vi: System has more IOMMUs than supported by this driver\n"); | ||
854 | return -ENOSYS; | ||
855 | } | ||
856 | |||
857 | /* Index is fine - add IOMMU to the array */ | ||
858 | amd_iommus[iommu->index] = iommu; | ||
844 | 859 | ||
845 | /* | 860 | /* |
846 | * Copy data from ACPI table entry to the iommu struct | 861 | * Copy data from ACPI table entry to the iommu struct |