History

iommu: Remove add_device()/remove_device() code-paths

All drivers are converted to use the probe/release_device() call-backs, so the add_device/remove_device() pointers are unused and the code using them can be removed.

Joerg Roedel committed 6 years ago

Commit 3eeeb451 parent 3c51c052 files · +38 −124Browse files

Unified · Split

2 files
  1. drivers/iommu/iommu.c +38 −120
  2. include/linux/iommu.h +0 −4
drivers/iommu/iommu.c+38−120
@@ -220,12 +220,20 @@ out_release: · 219 unmodified lines
220 return ret;220 return ret;
221}221}
222 222
223static int __iommu_probe_device_helper(struct device *dev)223int iommu_probe_device(struct device *dev)
224{224{
225 const struct iommu_ops *ops = dev->bus->iommu_ops;225 const struct iommu_ops *ops = dev->bus->iommu_ops;
226 struct iommu_group *group;226 struct iommu_group *group;
227 int ret;227 int ret;
228 228
229 if (!dev_iommu_get(dev))
230 return -ENOMEM;
231
232 if (!try_module_get(ops->owner)) {
233 ret = -EINVAL;
234 goto err_out;
235 }
236
229 ret = __iommu_probe_device(dev, NULL);237 ret = __iommu_probe_device(dev, NULL);
230 if (ret)238 if (ret)
231 goto err_out;239 goto err_out;
@@ -259,75 +267,23 @@ static int __iommu_probe_device_helper(struct device *dev) · 27 unmodified lines
259 267
260err_release:268err_release:
261 iommu_release_device(dev);269 iommu_release_device(dev);
270
262err_out:271err_out:
263 return ret;272 return ret;
264 273
265}274}
266 275
267int iommu_probe_device(struct device *dev)276void iommu_release_device(struct device *dev)
268{277{
269 const struct iommu_ops *ops = dev->bus->iommu_ops;278 const struct iommu_ops *ops = dev->bus->iommu_ops;
270 struct iommu_group *group;
271 int ret;
272
273 WARN_ON(dev->iommu_group);
274
275 if (!ops)
276 return -EINVAL;
277
278 if (!dev_iommu_get(dev))
279 return -ENOMEM;
280
281 if (!try_module_get(ops->owner)) {
282 ret = -EINVAL;
283 goto err_free_dev_param;
284 }
285
286 if (ops->probe_device)
287 return __iommu_probe_device_helper(dev);
288
289 ret = ops->add_device(dev);
290 if (ret)
291 goto err_module_put;
292 279
293 group = iommu_group_get(dev);280 if (!dev->iommu)
294 iommu_create_device_direct_mappings(group, dev);281 return;
295 iommu_group_put(group);
296
297 if (ops->probe_finalize)
298 ops->probe_finalize(dev);
299
300 return 0;
301
302err_module_put:
303 module_put(ops->owner);
304err_free_dev_param:
305 dev_iommu_free(dev);
306 return ret;
307}
308
309static void __iommu_release_device(struct device *dev)
310{
311 const struct iommu_ops *ops = dev->bus->iommu_ops;
312 282
313 iommu_device_unlink(dev->iommu->iommu_dev, dev);283 iommu_device_unlink(dev->iommu->iommu_dev, dev);
314
315 iommu_group_remove_device(dev);284 iommu_group_remove_device(dev);
316 285
317 ops->release_device(dev);286 ops->release_device(dev);
318}
319
320void iommu_release_device(struct device *dev)
321{
322 const struct iommu_ops *ops = dev->bus->iommu_ops;
323
324 if (!dev->iommu)
325 return;
326
327 if (ops->release_device)
328 __iommu_release_device(dev);
329 else if (dev->iommu_group)
330 ops->remove_device(dev);
331 287
332 module_put(ops->owner);288 module_put(ops->owner);
333 dev_iommu_free(dev);289 dev_iommu_free(dev);
@@ -1560,23 +1516,6 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev) · 1226 unmodified lines
1560 if (ret)1516 if (ret)
1561 goto out_put_group;1517 goto out_put_group;
1562 1518
1563 /*
1564 * Try to allocate a default domain - needs support from the
1565 * IOMMU driver. There are still some drivers which don't support
1566 * default domains, so the return value is not yet checked. Only
1567 * allocate the domain here when the driver still has the
1568 * add_device/remove_device call-backs implemented.
1569 */
1570 if (!ops->probe_device) {
1571 iommu_alloc_default_domain(dev);
1572
1573 if (group->default_domain)
1574 ret = __iommu_attach_device(group->default_domain, dev);
1575
1576 if (ret)
1577 goto out_put_group;
1578 }
1579
1580 return group;1519 return group;
1581 1520
1582out_put_group:1521out_put_group:
@@ -1591,21 +1530,6 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group) · 8 unmodified lines
1591 return group->default_domain;1530 return group->default_domain;
1592}1531}
1593 1532
1594static int add_iommu_group(struct device *dev, void *data)
1595{
1596 int ret = iommu_probe_device(dev);
1597
1598 /*
1599 * We ignore -ENODEV errors for now, as they just mean that the
1600 * device is not translated by an IOMMU. We still care about
1601 * other errors and fail to initialize when they happen.
1602 */
1603 if (ret == -ENODEV)
1604 ret = 0;
1605
1606 return ret;
1607}
1608
1609static int probe_iommu_group(struct device *dev, void *data)1533static int probe_iommu_group(struct device *dev, void *data)
1610{1534{
1611 const struct iommu_ops *ops = dev->bus->iommu_ops;1535 const struct iommu_ops *ops = dev->bus->iommu_ops;
@@ -1793,47 +1717,41 @@ static int iommu_group_create_direct_mappings(struct iommu_group *group) · 181 unmodified lines
1793 1717
1794int bus_iommu_probe(struct bus_type *bus)1718int bus_iommu_probe(struct bus_type *bus)
1795{1719{
1796 const struct iommu_ops *ops = bus->iommu_ops;1720 struct iommu_group *group, *next;
1721 LIST_HEAD(group_list);
1797 int ret;1722 int ret;
1798 1723
1799 if (ops->probe_device) {1724 /*
1800 struct iommu_group *group, *next;1725 * This code-path does not allocate the default domain when
1801 LIST_HEAD(group_list);1726 * creating the iommu group, so do it after the groups are
1802 1727 * created.
1803 /*1728 */
1804 * This code-path does not allocate the default domain when1729 ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group);
1805 * creating the iommu group, so do it after the groups are1730 if (ret)
1806 * created.1731 return ret;
1807 */
1808 ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group);
1809 if (ret)
1810 return ret;
1811 1732
1812 list_for_each_entry_safe(group, next, &group_list, entry) {1733 list_for_each_entry_safe(group, next, &group_list, entry) {
1813 /* Remove item from the list */1734 /* Remove item from the list */
1814 list_del_init(&group->entry);1735 list_del_init(&group->entry);
1815 1736
1816 mutex_lock(&group->mutex);1737 mutex_lock(&group->mutex);
1817 1738
1818 /* Try to allocate default domain */1739 /* Try to allocate default domain */
1819 probe_alloc_default_domain(bus, group);1740 probe_alloc_default_domain(bus, group);
1820 1741
1821 if (!group->default_domain) {1742 if (!group->default_domain) {
1822 mutex_unlock(&group->mutex);1743 mutex_unlock(&group->mutex);
1823 continue;1744 continue;
1824 }1745 }
1825 1746
1826 iommu_group_create_direct_mappings(group);1747 iommu_group_create_direct_mappings(group);
1827 1748
1828 ret = __iommu_group_dma_attach(group);1749 ret = __iommu_group_dma_attach(group);
1829 1750
1830 mutex_unlock(&group->mutex);1751 mutex_unlock(&group->mutex);
1831 1752
1832 if (ret)1753 if (ret)
1833 break;1754 break;
1834 }
1835 } else {
1836 ret = bus_for_each_dev(bus, NULL, NULL, add_iommu_group);
1837 }1755 }
1838 1756
1839 return ret;1757 return ret;
include/linux/iommu.h+0−4
@@ -223,8 +223,6 @@ struct iommu_iotlb_gather { · 222 unmodified lines
223 * @iotlb_sync: Flush all queued ranges from the hardware TLBs and empty flush223 * @iotlb_sync: Flush all queued ranges from the hardware TLBs and empty flush
224 * queue224 * queue
225 * @iova_to_phys: translate iova to physical address225 * @iova_to_phys: translate iova to physical address
226 * @add_device: add device to iommu grouping
227 * @remove_device: remove device from iommu grouping
228 * @probe_device: Add device to iommu driver handling226 * @probe_device: Add device to iommu driver handling
229 * @release_device: Remove device from iommu driver handling227 * @release_device: Remove device from iommu driver handling
230 * @probe_finalize: Do final setup work after the device is added to an IOMMU228 * @probe_finalize: Do final setup work after the device is added to an IOMMU
@@ -277,8 +275,6 @@ struct iommu_ops { · 46 unmodified lines
277 void (*iotlb_sync)(struct iommu_domain *domain,275 void (*iotlb_sync)(struct iommu_domain *domain,
278 struct iommu_iotlb_gather *iotlb_gather);276 struct iommu_iotlb_gather *iotlb_gather);
279 phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova);277 phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova);
280 int (*add_device)(struct device *dev);
281 void (*remove_device)(struct device *dev);
282 struct iommu_device *(*probe_device)(struct device *dev);278 struct iommu_device *(*probe_device)(struct device *dev);
283 void (*release_device)(struct device *dev);279 void (*release_device)(struct device *dev);
284 void (*probe_finalize)(struct device *dev);280 void (*probe_finalize)(struct device *dev);