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
220220 return ret;
221221 }
222222
223−static int __iommu_probe_device_helper(struct device *dev)
223+int iommu_probe_device(struct device *dev)
224224 {
225225 const struct iommu_ops *ops = dev->bus->iommu_ops;
226226 struct iommu_group *group;
227227 int ret;
228228
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+
229237 ret = __iommu_probe_device(dev, NULL);
230238 if (ret)
231239 goto err_out;
@@ -259,75 +267,23 @@ static int __iommu_probe_device_helper(struct device *dev) · 27 unmodified lines
259267
260268 err_release:
261269 iommu_release_device(dev);
270+
262271 err_out:
263272 return ret;
264273
265274 }
266275
267−int iommu_probe_device(struct device *dev)
276+void iommu_release_device(struct device *dev)
268277 {
269278 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;
292279
293− group = iommu_group_get(dev);
294− iommu_create_device_direct_mappings(group, dev);
295− iommu_group_put(group);
296−
297− if (ops->probe_finalize)
298− ops->probe_finalize(dev);
299−
300− return 0;
301−
302−err_module_put:
303− module_put(ops->owner);
304−err_free_dev_param:
305− dev_iommu_free(dev);
306− return ret;
307−}
308−
309−static void __iommu_release_device(struct device *dev)
310−{
311− const struct iommu_ops *ops = dev->bus->iommu_ops;
280+ if (!dev->iommu)
281+ return;
312282
313283 iommu_device_unlink(dev->iommu->iommu_dev, dev);
314−
315284 iommu_group_remove_device(dev);
316285
317286 ops->release_device(dev);
318−}
319−
320−void 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);
331287
332288 module_put(ops->owner);
333289 dev_iommu_free(dev);
@@ -1560,23 +1516,6 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev) · 1226 unmodified lines
15601516 if (ret)
15611517 goto out_put_group;
15621518
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−
15801519 return group;
15811520
15821521 out_put_group:
@@ -1591,21 +1530,6 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group) · 8 unmodified lines
15911530 return group->default_domain;
15921531 }
15931532
1594−static 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−
16091533 static int probe_iommu_group(struct device *dev, void *data)
16101534 {
16111535 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
17931717
17941718 int bus_iommu_probe(struct bus_type *bus)
17951719 {
1796− const struct iommu_ops *ops = bus->iommu_ops;
1720+ struct iommu_group *group, *next;
1721+ LIST_HEAD(group_list);
17971722 int ret;
17981723
1799− if (ops->probe_device) {
1800− struct iommu_group *group, *next;
1801− LIST_HEAD(group_list);
1802−
1803− /*
1804− * This code-path does not allocate the default domain when
1805− * creating the iommu group, so do it after the groups are
1806− * created.
1807− */
1808− ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group);
1809− if (ret)
1810− return ret;
1724+ /*
1725+ * This code-path does not allocate the default domain when
1726+ * creating the iommu group, so do it after the groups are
1727+ * created.
1728+ */
1729+ ret = bus_for_each_dev(bus, NULL, &group_list, probe_iommu_group);
1730+ if (ret)
1731+ return ret;
18111732
1812− list_for_each_entry_safe(group, next, &group_list, entry) {
1813− /* Remove item from the list */
1814− list_del_init(&group->entry);
1733+ list_for_each_entry_safe(group, next, &group_list, entry) {
1734+ /* Remove item from the list */
1735+ list_del_init(&group->entry);
18151736
1816− mutex_lock(&group->mutex);
1737+ mutex_lock(&group->mutex);
18171738
1818− /* Try to allocate default domain */
1819− probe_alloc_default_domain(bus, group);
1739+ /* Try to allocate default domain */
1740+ probe_alloc_default_domain(bus, group);
18201741
1821− if (!group->default_domain) {
1822− mutex_unlock(&group->mutex);
1823− continue;
1824− }
1742+ if (!group->default_domain) {
1743+ mutex_unlock(&group->mutex);
1744+ continue;
1745+ }
18251746
1826− iommu_group_create_direct_mappings(group);
1747+ iommu_group_create_direct_mappings(group);
18271748
1828− ret = __iommu_group_dma_attach(group);
1749+ ret = __iommu_group_dma_attach(group);
18291750
1830− mutex_unlock(&group->mutex);
1751+ mutex_unlock(&group->mutex);
18311752
1832− if (ret)
1833− break;
1834− }
1835− } else {
1836− ret = bus_for_each_dev(bus, NULL, NULL, add_iommu_group);
1753+ if (ret)
1754+ break;
18371755 }
18381756
18391757 return ret;
include/linux/iommu.h+0−4
@@ -223,8 +223,6 @@ struct iommu_iotlb_gather { · 222 unmodified lines
223223 * @iotlb_sync: Flush all queued ranges from the hardware TLBs and empty flush
224224 * queue
225225 * @iova_to_phys: translate iova to physical address
226− * @add_device: add device to iommu grouping
227− * @remove_device: remove device from iommu grouping
228226 * @probe_device: Add device to iommu driver handling
229227 * @release_device: Remove device from iommu driver handling
230228 * @probe_finalize: Do final setup work after the device is added to an IOMMU
@@ -277,8 +275,6 @@ struct iommu_ops { · 46 unmodified lines
277275 void (*iotlb_sync)(struct iommu_domain *domain,
278276 struct iommu_iotlb_gather *iotlb_gather);
279277 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);
282278 struct iommu_device *(*probe_device)(struct device *dev);
283279 void (*release_device)(struct device *dev);
284280 void (*probe_finalize)(struct device *dev);