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.
Unified · Split
| @@ -220,12 +220,20 @@ out_release: · 219 unmodified lines | ||
| 220 | 220 | return ret; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | −static int __iommu_probe_device_helper(struct device *dev) | |
| 223 | +int iommu_probe_device(struct device *dev) | |
| 224 | 224 | { |
| 225 | 225 | const struct iommu_ops *ops = dev->bus->iommu_ops; |
| 226 | 226 | struct iommu_group *group; |
| 227 | 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 | 237 | ret = __iommu_probe_device(dev, NULL); |
| 230 | 238 | if (ret) |
| 231 | 239 | goto err_out; |
| @@ -259,75 +267,23 @@ static int __iommu_probe_device_helper(struct device *dev) · 27 unmodified lines | ||
| 259 | 267 | |
| 260 | 268 | err_release: |
| 261 | 269 | iommu_release_device(dev); |
| 270 | + | |
| 262 | 271 | err_out: |
| 263 | 272 | return ret; |
| 264 | 273 | |
| 265 | 274 | } |
| 266 | 275 | |
| 267 | −int iommu_probe_device(struct device *dev) | |
| 276 | +void iommu_release_device(struct device *dev) | |
| 268 | 277 | { |
| 269 | 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); | |
| 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; | |
| 312 | 282 | |
| 313 | 283 | iommu_device_unlink(dev->iommu->iommu_dev, dev); |
| 314 | − | |
| 315 | 284 | iommu_group_remove_device(dev); |
| 316 | 285 | |
| 317 | 286 | 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); | |
| 331 | 287 | |
| 332 | 288 | module_put(ops->owner); |
| 333 | 289 | dev_iommu_free(dev); |
| @@ -1560,23 +1516,6 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev) · 1226 unmodified lines | ||
| 1560 | 1516 | if (ret) |
| 1561 | 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 | 1519 | return group; |
| 1581 | 1520 | |
| 1582 | 1521 | out_put_group: |
| @@ -1591,21 +1530,6 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group) · 8 unmodified lines | ||
| 1591 | 1530 | return group->default_domain; |
| 1592 | 1531 | } |
| 1593 | 1532 | |
| 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 | − | |
| 1609 | 1533 | static int probe_iommu_group(struct device *dev, void *data) |
| 1610 | 1534 | { |
| 1611 | 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 | |
| 1794 | 1718 | int 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 | 1722 | int ret; |
| 1798 | 1723 | |
| 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; | |
| 1811 | 1732 | |
| 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); | |
| 1815 | 1736 | |
| 1816 | − mutex_lock(&group->mutex); | |
| 1737 | + mutex_lock(&group->mutex); | |
| 1817 | 1738 | |
| 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); | |
| 1820 | 1741 | |
| 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 | + } | |
| 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) | |
| 1833 | − break; | |
| 1834 | − } | |
| 1835 | − } else { | |
| 1836 | − ret = bus_for_each_dev(bus, NULL, NULL, add_iommu_group); | |
| 1753 | + if (ret) | |
| 1754 | + break; | |
| 1837 | 1755 | } |
| 1838 | 1756 | |
| 1839 | 1757 | return ret; |
| @@ -223,8 +223,6 @@ struct iommu_iotlb_gather { · 222 unmodified lines | ||
| 223 | 223 | * @iotlb_sync: Flush all queued ranges from the hardware TLBs and empty flush |
| 224 | 224 | * queue |
| 225 | 225 | * @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 | 226 | * @probe_device: Add device to iommu driver handling |
| 229 | 227 | * @release_device: Remove device from iommu driver handling |
| 230 | 228 | * @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 | 275 | void (*iotlb_sync)(struct iommu_domain *domain, |
| 278 | 276 | struct iommu_iotlb_gather *iotlb_gather); |
| 279 | 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 | 278 | struct iommu_device *(*probe_device)(struct device *dev); |
| 283 | 279 | void (*release_device)(struct device *dev); |
| 284 | 280 | void (*probe_finalize)(struct device *dev); |