diff options
author | Joerg Roedel <joerg.roedel@amd.com> | 2012-01-09 07:06:28 -0500 |
---|---|---|
committer | Joerg Roedel <joerg.roedel@amd.com> | 2012-01-09 07:06:28 -0500 |
commit | f93ea733878733f3e98475bc3e2ccf789bebcfb8 (patch) | |
tree | ce4981e49a75d5bac7f0d2fa4ddcdcc130cf56f0 /drivers/iommu | |
parent | 00fb5430f547e411ab03385cfa548776aaac1c92 (diff) | |
parent | 95bdaf71ccf2cb4bba0c9a3d2baea0e7916f466b (diff) |
Merge branches 'iommu/page-sizes' and 'iommu/group-id' into next
Conflicts:
drivers/iommu/amd_iommu.c
drivers/iommu/intel-iommu.c
include/linux/iommu.h
Diffstat (limited to 'drivers/iommu')
-rw-r--r-- | drivers/iommu/amd_iommu.c | 21 | ||||
-rw-r--r-- | drivers/iommu/intel-iommu.c | 49 | ||||
-rw-r--r-- | drivers/iommu/iommu.c | 60 |
3 files changed, 130 insertions, 0 deletions
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index edd291070b0b..cce1f03b8895 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c | |||
@@ -3188,6 +3188,26 @@ static int amd_iommu_domain_has_cap(struct iommu_domain *domain, | |||
3188 | return 0; | 3188 | return 0; |
3189 | } | 3189 | } |
3190 | 3190 | ||
3191 | static int amd_iommu_device_group(struct device *dev, unsigned int *groupid) | ||
3192 | { | ||
3193 | struct iommu_dev_data *dev_data = dev->archdata.iommu; | ||
3194 | struct pci_dev *pdev = to_pci_dev(dev); | ||
3195 | u16 devid; | ||
3196 | |||
3197 | if (!dev_data) | ||
3198 | return -ENODEV; | ||
3199 | |||
3200 | if (pdev->is_virtfn || !iommu_group_mf) | ||
3201 | devid = dev_data->devid; | ||
3202 | else | ||
3203 | devid = calc_devid(pdev->bus->number, | ||
3204 | PCI_DEVFN(PCI_SLOT(pdev->devfn), 0)); | ||
3205 | |||
3206 | *groupid = amd_iommu_alias_table[devid]; | ||
3207 | |||
3208 | return 0; | ||
3209 | } | ||
3210 | |||
3191 | static struct iommu_ops amd_iommu_ops = { | 3211 | static struct iommu_ops amd_iommu_ops = { |
3192 | .domain_init = amd_iommu_domain_init, | 3212 | .domain_init = amd_iommu_domain_init, |
3193 | .domain_destroy = amd_iommu_domain_destroy, | 3213 | .domain_destroy = amd_iommu_domain_destroy, |
@@ -3197,6 +3217,7 @@ static struct iommu_ops amd_iommu_ops = { | |||
3197 | .unmap = amd_iommu_unmap, | 3217 | .unmap = amd_iommu_unmap, |
3198 | .iova_to_phys = amd_iommu_iova_to_phys, | 3218 | .iova_to_phys = amd_iommu_iova_to_phys, |
3199 | .domain_has_cap = amd_iommu_domain_has_cap, | 3219 | .domain_has_cap = amd_iommu_domain_has_cap, |
3220 | .device_group = amd_iommu_device_group, | ||
3200 | .pgsize_bitmap = AMD_IOMMU_PGSIZES, | 3221 | .pgsize_bitmap = AMD_IOMMU_PGSIZES, |
3201 | }; | 3222 | }; |
3202 | 3223 | ||
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index aea72e11e166..77e3b917c8da 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c | |||
@@ -4080,6 +4080,54 @@ static int intel_iommu_domain_has_cap(struct iommu_domain *domain, | |||
4080 | return 0; | 4080 | return 0; |
4081 | } | 4081 | } |
4082 | 4082 | ||
4083 | /* | ||
4084 | * Group numbers are arbitrary. Device with the same group number | ||
4085 | * indicate the iommu cannot differentiate between them. To avoid | ||
4086 | * tracking used groups we just use the seg|bus|devfn of the lowest | ||
4087 | * level we're able to differentiate devices | ||
4088 | */ | ||
4089 | static int intel_iommu_device_group(struct device *dev, unsigned int *groupid) | ||
4090 | { | ||
4091 | struct pci_dev *pdev = to_pci_dev(dev); | ||
4092 | struct pci_dev *bridge; | ||
4093 | union { | ||
4094 | struct { | ||
4095 | u8 devfn; | ||
4096 | u8 bus; | ||
4097 | u16 segment; | ||
4098 | } pci; | ||
4099 | u32 group; | ||
4100 | } id; | ||
4101 | |||
4102 | if (iommu_no_mapping(dev)) | ||
4103 | return -ENODEV; | ||
4104 | |||
4105 | id.pci.segment = pci_domain_nr(pdev->bus); | ||
4106 | id.pci.bus = pdev->bus->number; | ||
4107 | id.pci.devfn = pdev->devfn; | ||
4108 | |||
4109 | if (!device_to_iommu(id.pci.segment, id.pci.bus, id.pci.devfn)) | ||
4110 | return -ENODEV; | ||
4111 | |||
4112 | bridge = pci_find_upstream_pcie_bridge(pdev); | ||
4113 | if (bridge) { | ||
4114 | if (pci_is_pcie(bridge)) { | ||
4115 | id.pci.bus = bridge->subordinate->number; | ||
4116 | id.pci.devfn = 0; | ||
4117 | } else { | ||
4118 | id.pci.bus = bridge->bus->number; | ||
4119 | id.pci.devfn = bridge->devfn; | ||
4120 | } | ||
4121 | } | ||
4122 | |||
4123 | if (!pdev->is_virtfn && iommu_group_mf) | ||
4124 | id.pci.devfn = PCI_DEVFN(PCI_SLOT(id.pci.devfn), 0); | ||
4125 | |||
4126 | *groupid = id.group; | ||
4127 | |||
4128 | return 0; | ||
4129 | } | ||
4130 | |||
4083 | static struct iommu_ops intel_iommu_ops = { | 4131 | static struct iommu_ops intel_iommu_ops = { |
4084 | .domain_init = intel_iommu_domain_init, | 4132 | .domain_init = intel_iommu_domain_init, |
4085 | .domain_destroy = intel_iommu_domain_destroy, | 4133 | .domain_destroy = intel_iommu_domain_destroy, |
@@ -4089,6 +4137,7 @@ static struct iommu_ops intel_iommu_ops = { | |||
4089 | .unmap = intel_iommu_unmap, | 4137 | .unmap = intel_iommu_unmap, |
4090 | .iova_to_phys = intel_iommu_iova_to_phys, | 4138 | .iova_to_phys = intel_iommu_iova_to_phys, |
4091 | .domain_has_cap = intel_iommu_domain_has_cap, | 4139 | .domain_has_cap = intel_iommu_domain_has_cap, |
4140 | .device_group = intel_iommu_device_group, | ||
4092 | .pgsize_bitmap = INTEL_IOMMU_PGSIZES, | 4141 | .pgsize_bitmap = INTEL_IOMMU_PGSIZES, |
4093 | }; | 4142 | }; |
4094 | 4143 | ||
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 14d6f908196b..2198b2dbbcd3 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c | |||
@@ -27,8 +27,59 @@ | |||
27 | #include <linux/errno.h> | 27 | #include <linux/errno.h> |
28 | #include <linux/iommu.h> | 28 | #include <linux/iommu.h> |
29 | 29 | ||
30 | static ssize_t show_iommu_group(struct device *dev, | ||
31 | struct device_attribute *attr, char *buf) | ||
32 | { | ||
33 | unsigned int groupid; | ||
34 | |||
35 | if (iommu_device_group(dev, &groupid)) | ||
36 | return 0; | ||
37 | |||
38 | return sprintf(buf, "%u", groupid); | ||
39 | } | ||
40 | static DEVICE_ATTR(iommu_group, S_IRUGO, show_iommu_group, NULL); | ||
41 | |||
42 | static int add_iommu_group(struct device *dev, void *data) | ||
43 | { | ||
44 | unsigned int groupid; | ||
45 | |||
46 | if (iommu_device_group(dev, &groupid) == 0) | ||
47 | return device_create_file(dev, &dev_attr_iommu_group); | ||
48 | |||
49 | return 0; | ||
50 | } | ||
51 | |||
52 | static int remove_iommu_group(struct device *dev) | ||
53 | { | ||
54 | unsigned int groupid; | ||
55 | |||
56 | if (iommu_device_group(dev, &groupid) == 0) | ||
57 | device_remove_file(dev, &dev_attr_iommu_group); | ||
58 | |||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | static int iommu_device_notifier(struct notifier_block *nb, | ||
63 | unsigned long action, void *data) | ||
64 | { | ||
65 | struct device *dev = data; | ||
66 | |||
67 | if (action == BUS_NOTIFY_ADD_DEVICE) | ||
68 | return add_iommu_group(dev, NULL); | ||
69 | else if (action == BUS_NOTIFY_DEL_DEVICE) | ||
70 | return remove_iommu_group(dev); | ||
71 | |||
72 | return 0; | ||
73 | } | ||
74 | |||
75 | static struct notifier_block iommu_device_nb = { | ||
76 | .notifier_call = iommu_device_notifier, | ||
77 | }; | ||
78 | |||
30 | static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops) | 79 | static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops) |
31 | { | 80 | { |
81 | bus_register_notifier(bus, &iommu_device_nb); | ||
82 | bus_for_each_dev(bus, NULL, NULL, add_iommu_group); | ||
32 | } | 83 | } |
33 | 84 | ||
34 | /** | 85 | /** |
@@ -281,3 +332,12 @@ size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size) | |||
281 | return unmapped; | 332 | return unmapped; |
282 | } | 333 | } |
283 | EXPORT_SYMBOL_GPL(iommu_unmap); | 334 | EXPORT_SYMBOL_GPL(iommu_unmap); |
335 | |||
336 | int iommu_device_group(struct device *dev, unsigned int *groupid) | ||
337 | { | ||
338 | if (iommu_present(dev->bus) && dev->bus->iommu_ops->device_group) | ||
339 | return dev->bus->iommu_ops->device_group(dev, groupid); | ||
340 | |||
341 | return -ENODEV; | ||
342 | } | ||
343 | EXPORT_SYMBOL_GPL(iommu_device_group); | ||