diff options
author | Joerg Roedel <joerg.roedel@amd.com> | 2011-06-09 13:03:15 -0400 |
---|---|---|
committer | Joerg Roedel <joerg.roedel@amd.com> | 2011-06-14 06:49:58 -0400 |
commit | 71f77580906b60eb43daff0efb99792e76a3d06d (patch) | |
tree | 1cf71fe8a31546ee2b5fe6febd86f99c29f33925 /arch/x86/kernel | |
parent | 3b03bb745eb9fcafc6ef80fcbd04f0f0512acdc9 (diff) |
x86/amd-iommu: Store device alias as dev_data pointer
This finally allows PCI-Device-IDs to be handled by the
IOMMU driver that have no corresponding struct device
present in the system.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Diffstat (limited to 'arch/x86/kernel')
-rw-r--r-- | arch/x86/kernel/amd_iommu.c | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c index f64799878d45..0ed1c940d76b 100644 --- a/arch/x86/kernel/amd_iommu.c +++ b/arch/x86/kernel/amd_iommu.c | |||
@@ -203,7 +203,6 @@ static bool check_device(struct device *dev) | |||
203 | static int iommu_init_device(struct device *dev) | 203 | static int iommu_init_device(struct device *dev) |
204 | { | 204 | { |
205 | struct iommu_dev_data *dev_data; | 205 | struct iommu_dev_data *dev_data; |
206 | struct pci_dev *pdev; | ||
207 | u16 alias; | 206 | u16 alias; |
208 | 207 | ||
209 | if (dev->archdata.iommu) | 208 | if (dev->archdata.iommu) |
@@ -215,13 +214,16 @@ static int iommu_init_device(struct device *dev) | |||
215 | 214 | ||
216 | alias = amd_iommu_alias_table[dev_data->devid]; | 215 | alias = amd_iommu_alias_table[dev_data->devid]; |
217 | if (alias != dev_data->devid) { | 216 | if (alias != dev_data->devid) { |
218 | pdev = pci_get_bus_and_slot(PCI_BUS(alias), alias & 0xff); | 217 | struct iommu_dev_data *alias_data; |
219 | if (pdev) | 218 | |
220 | dev_data->alias = &pdev->dev; | 219 | alias_data = find_dev_data(alias); |
221 | else { | 220 | if (alias_data == NULL) { |
221 | pr_err("AMD-Vi: Warning: Unhandled device %s\n", | ||
222 | dev_name(dev)); | ||
222 | free_dev_data(dev_data); | 223 | free_dev_data(dev_data); |
223 | return -ENOTSUPP; | 224 | return -ENOTSUPP; |
224 | } | 225 | } |
226 | dev_data->alias_data = alias_data; | ||
225 | } | 227 | } |
226 | 228 | ||
227 | dev->archdata.iommu = dev_data; | 229 | dev->archdata.iommu = dev_data; |
@@ -1642,14 +1644,8 @@ static int __attach_device(struct iommu_dev_data *dev_data, | |||
1642 | /* lock domain */ | 1644 | /* lock domain */ |
1643 | spin_lock(&domain->lock); | 1645 | spin_lock(&domain->lock); |
1644 | 1646 | ||
1645 | if (dev_data->alias != NULL) { | 1647 | if (dev_data->alias_data != NULL) { |
1646 | struct iommu_dev_data *alias_data; | 1648 | struct iommu_dev_data *alias_data = dev_data->alias_data; |
1647 | |||
1648 | alias_data = get_dev_data(dev_data->alias); | ||
1649 | |||
1650 | ret = -EINVAL; | ||
1651 | if (!alias_data) | ||
1652 | goto out_unlock; | ||
1653 | 1649 | ||
1654 | /* Some sanity checks */ | 1650 | /* Some sanity checks */ |
1655 | ret = -EBUSY; | 1651 | ret = -EBUSY; |
@@ -1721,7 +1717,6 @@ static int attach_device(struct device *dev, | |||
1721 | */ | 1717 | */ |
1722 | static void __detach_device(struct iommu_dev_data *dev_data) | 1718 | static void __detach_device(struct iommu_dev_data *dev_data) |
1723 | { | 1719 | { |
1724 | struct iommu_dev_data *alias_data; | ||
1725 | struct protection_domain *domain; | 1720 | struct protection_domain *domain; |
1726 | unsigned long flags; | 1721 | unsigned long flags; |
1727 | 1722 | ||
@@ -1731,8 +1726,9 @@ static void __detach_device(struct iommu_dev_data *dev_data) | |||
1731 | 1726 | ||
1732 | spin_lock_irqsave(&domain->lock, flags); | 1727 | spin_lock_irqsave(&domain->lock, flags); |
1733 | 1728 | ||
1734 | if (dev_data->alias) { | 1729 | if (dev_data->alias_data != NULL) { |
1735 | alias_data = get_dev_data(dev_data->alias); | 1730 | struct iommu_dev_data *alias_data = dev_data->alias_data; |
1731 | |||
1736 | if (atomic_dec_and_test(&alias_data->bind)) | 1732 | if (atomic_dec_and_test(&alias_data->bind)) |
1737 | do_detach(alias_data); | 1733 | do_detach(alias_data); |
1738 | } | 1734 | } |
@@ -1779,7 +1775,7 @@ static void detach_device(struct device *dev) | |||
1779 | */ | 1775 | */ |
1780 | static struct protection_domain *domain_for_device(struct device *dev) | 1776 | static struct protection_domain *domain_for_device(struct device *dev) |
1781 | { | 1777 | { |
1782 | struct iommu_dev_data *dev_data, *alias_data; | 1778 | struct iommu_dev_data *dev_data; |
1783 | struct protection_domain *dom = NULL; | 1779 | struct protection_domain *dom = NULL; |
1784 | unsigned long flags; | 1780 | unsigned long flags; |
1785 | 1781 | ||
@@ -1788,8 +1784,8 @@ static struct protection_domain *domain_for_device(struct device *dev) | |||
1788 | if (dev_data->domain) | 1784 | if (dev_data->domain) |
1789 | return dev_data->domain; | 1785 | return dev_data->domain; |
1790 | 1786 | ||
1791 | if (dev_data->alias != NULL) { | 1787 | if (dev_data->alias_data != NULL) { |
1792 | alias_data = get_dev_data(dev_data->alias); | 1788 | struct iommu_dev_data *alias_data = dev_data->alias_data; |
1793 | 1789 | ||
1794 | read_lock_irqsave(&amd_iommu_devtable_lock, flags); | 1790 | read_lock_irqsave(&amd_iommu_devtable_lock, flags); |
1795 | if (alias_data->domain != NULL) { | 1791 | if (alias_data->domain != NULL) { |