aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/amd_iommu.c
diff options
context:
space:
mode:
authorJoerg Roedel <joerg.roedel@amd.com>2011-06-09 06:55:35 -0400
committerJoerg Roedel <joerg.roedel@amd.com>2011-06-14 06:49:57 -0400
commitf62dda66b5601396c28b563cc18b481af04a91b3 (patch)
tree76d336f8d6eabfe48222838bba0921805bd271a8 /arch/x86/kernel/amd_iommu.c
parent8fa5f802abf3cd374b5f07418cea72c5d9d204cc (diff)
x86/amd-iommu: Store devid in dev_data
This allows to use dev_data independent of struct device later. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Diffstat (limited to 'arch/x86/kernel/amd_iommu.c')
-rw-r--r--arch/x86/kernel/amd_iommu.c39
1 files changed, 15 insertions, 24 deletions
diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c
index 8b8489084649..4e8b176297b5 100644
--- a/arch/x86/kernel/amd_iommu.c
+++ b/arch/x86/kernel/amd_iommu.c
@@ -72,7 +72,7 @@ static void update_domain(struct protection_domain *domain);
72 * 72 *
73 ****************************************************************************/ 73 ****************************************************************************/
74 74
75static struct iommu_dev_data *alloc_dev_data(void) 75static struct iommu_dev_data *alloc_dev_data(u16 devid)
76{ 76{
77 struct iommu_dev_data *dev_data; 77 struct iommu_dev_data *dev_data;
78 unsigned long flags; 78 unsigned long flags;
@@ -81,6 +81,7 @@ static struct iommu_dev_data *alloc_dev_data(void)
81 if (!dev_data) 81 if (!dev_data)
82 return NULL; 82 return NULL;
83 83
84 dev_data->devid = devid;
84 atomic_set(&dev_data->bind, 0); 85 atomic_set(&dev_data->bind, 0);
85 86
86 spin_lock_irqsave(&dev_data_list_lock, flags); 87 spin_lock_irqsave(&dev_data_list_lock, flags);
@@ -177,13 +178,13 @@ static int iommu_init_device(struct device *dev)
177 if (dev->archdata.iommu) 178 if (dev->archdata.iommu)
178 return 0; 179 return 0;
179 180
180 dev_data = alloc_dev_data(); 181 dev_data = alloc_dev_data(get_device_id(dev));
181 if (!dev_data) 182 if (!dev_data)
182 return -ENOMEM; 183 return -ENOMEM;
183 184
184 dev_data->dev = dev; 185 dev_data->dev = dev;
185 186
186 alias = amd_iommu_alias_table[get_device_id(dev)]; 187 alias = amd_iommu_alias_table[dev_data->devid];
187 pdev = pci_get_bus_and_slot(PCI_BUS(alias), alias & 0xff); 188 pdev = pci_get_bus_and_slot(PCI_BUS(alias), alias & 0xff);
188 if (pdev) 189 if (pdev)
189 dev_data->alias = &pdev->dev; 190 dev_data->alias = &pdev->dev;
@@ -714,16 +715,16 @@ static int device_flush_iotlb(struct device *dev, u64 address, size_t size)
714 */ 715 */
715static int device_flush_dte(struct device *dev) 716static int device_flush_dte(struct device *dev)
716{ 717{
718 struct iommu_dev_data *dev_data;
717 struct amd_iommu *iommu; 719 struct amd_iommu *iommu;
718 struct pci_dev *pdev; 720 struct pci_dev *pdev;
719 u16 devid;
720 int ret; 721 int ret;
721 722
722 pdev = to_pci_dev(dev); 723 pdev = to_pci_dev(dev);
723 devid = get_device_id(dev); 724 dev_data = get_dev_data(dev);
724 iommu = amd_iommu_rlookup_table[devid]; 725 iommu = amd_iommu_rlookup_table[dev_data->devid];
725 726
726 ret = iommu_flush_dte(iommu, devid); 727 ret = iommu_flush_dte(iommu, dev_data->devid);
727 if (ret) 728 if (ret)
728 return ret; 729 return ret;
729 730
@@ -1570,11 +1571,9 @@ static void do_attach(struct device *dev, struct protection_domain *domain)
1570 struct amd_iommu *iommu; 1571 struct amd_iommu *iommu;
1571 struct pci_dev *pdev; 1572 struct pci_dev *pdev;
1572 bool ats = false; 1573 bool ats = false;
1573 u16 devid;
1574 1574
1575 devid = get_device_id(dev);
1576 iommu = amd_iommu_rlookup_table[devid];
1577 dev_data = get_dev_data(dev); 1575 dev_data = get_dev_data(dev);
1576 iommu = amd_iommu_rlookup_table[dev_data->devid];
1578 pdev = to_pci_dev(dev); 1577 pdev = to_pci_dev(dev);
1579 1578
1580 if (amd_iommu_iotlb_sup) 1579 if (amd_iommu_iotlb_sup)
@@ -1583,7 +1582,7 @@ static void do_attach(struct device *dev, struct protection_domain *domain)
1583 /* Update data structures */ 1582 /* Update data structures */
1584 dev_data->domain = domain; 1583 dev_data->domain = domain;
1585 list_add(&dev_data->list, &domain->dev_list); 1584 list_add(&dev_data->list, &domain->dev_list);
1586 set_dte_entry(devid, domain, ats); 1585 set_dte_entry(dev_data->devid, domain, ats);
1587 1586
1588 /* Do reference counting */ 1587 /* Do reference counting */
1589 domain->dev_iommu[iommu->index] += 1; 1588 domain->dev_iommu[iommu->index] += 1;
@@ -1597,11 +1596,9 @@ static void do_detach(struct device *dev)
1597{ 1596{
1598 struct iommu_dev_data *dev_data; 1597 struct iommu_dev_data *dev_data;
1599 struct amd_iommu *iommu; 1598 struct amd_iommu *iommu;
1600 u16 devid;
1601 1599
1602 devid = get_device_id(dev);
1603 iommu = amd_iommu_rlookup_table[devid];
1604 dev_data = get_dev_data(dev); 1600 dev_data = get_dev_data(dev);
1601 iommu = amd_iommu_rlookup_table[dev_data->devid];
1605 1602
1606 /* decrease reference counters */ 1603 /* decrease reference counters */
1607 dev_data->domain->dev_iommu[iommu->index] -= 1; 1604 dev_data->domain->dev_iommu[iommu->index] -= 1;
@@ -1610,7 +1607,7 @@ static void do_detach(struct device *dev)
1610 /* Update data structures */ 1607 /* Update data structures */
1611 dev_data->domain = NULL; 1608 dev_data->domain = NULL;
1612 list_del(&dev_data->list); 1609 list_del(&dev_data->list);
1613 clear_dte_entry(devid); 1610 clear_dte_entry(dev_data->devid);
1614 1611
1615 /* Flush the DTE entry */ 1612 /* Flush the DTE entry */
1616 device_flush_dte(dev); 1613 device_flush_dte(dev);
@@ -1760,9 +1757,7 @@ static struct protection_domain *domain_for_device(struct device *dev)
1760 struct protection_domain *dom; 1757 struct protection_domain *dom;
1761 struct iommu_dev_data *dev_data, *alias_data; 1758 struct iommu_dev_data *dev_data, *alias_data;
1762 unsigned long flags; 1759 unsigned long flags;
1763 u16 devid;
1764 1760
1765 devid = get_device_id(dev);
1766 dev_data = get_dev_data(dev); 1761 dev_data = get_dev_data(dev);
1767 alias_data = get_dev_data(dev_data->alias); 1762 alias_data = get_dev_data(dev_data->alias);
1768 if (!alias_data) 1763 if (!alias_data)
@@ -1897,8 +1892,7 @@ static void update_device_table(struct protection_domain *domain)
1897 1892
1898 list_for_each_entry(dev_data, &domain->dev_list, list) { 1893 list_for_each_entry(dev_data, &domain->dev_list, list) {
1899 struct pci_dev *pdev = to_pci_dev(dev_data->dev); 1894 struct pci_dev *pdev = to_pci_dev(dev_data->dev);
1900 u16 devid = get_device_id(dev_data->dev); 1895 set_dte_entry(dev_data->devid, domain, pci_ats_enabled(pdev));
1901 set_dte_entry(devid, domain, pci_ats_enabled(pdev));
1902 } 1896 }
1903} 1897}
1904 1898
@@ -2652,16 +2646,13 @@ static int amd_iommu_attach_device(struct iommu_domain *dom,
2652 struct iommu_dev_data *dev_data; 2646 struct iommu_dev_data *dev_data;
2653 struct amd_iommu *iommu; 2647 struct amd_iommu *iommu;
2654 int ret; 2648 int ret;
2655 u16 devid;
2656 2649
2657 if (!check_device(dev)) 2650 if (!check_device(dev))
2658 return -EINVAL; 2651 return -EINVAL;
2659 2652
2660 dev_data = dev->archdata.iommu; 2653 dev_data = dev->archdata.iommu;
2661 2654
2662 devid = get_device_id(dev); 2655 iommu = amd_iommu_rlookup_table[dev_data->devid];
2663
2664 iommu = amd_iommu_rlookup_table[devid];
2665 if (!iommu) 2656 if (!iommu)
2666 return -EINVAL; 2657 return -EINVAL;
2667 2658