On 12/6/21 11:06 PM, Jason Gunthorpe wrote:
On Mon, Dec 06, 2021 at 06:36:27AM -0800, Christoph Hellwig wrote:
I really hate the amount of boilerplate code that having this in each
bus type causes.
+1

I liked the first version of this series better with the code near
really_probe().

Can we go back to that with some device_configure_dma() wrapper
condtionally called by really_probe as we discussed?


Are you talking about below change?

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 68ea1f949daa..368f9e530515 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -577,7 +577,13 @@ static int really_probe(struct device *dev, struct device_driver *drv)
        if (dev->bus->dma_configure) {
                ret = dev->bus->dma_configure(dev);
                if (ret)
-                       goto probe_failed;
+                       goto pinctrl_bind_failed;
+
+               if (!drv->no_kernel_dma) {
+                       ret = iommu_device_set_dma_owner(dev, 
DMA_OWNER_DMA_API, NULL);
+                       if (ret)
+                               goto pinctrl_bind_failed;
+                }
        }

        ret = driver_sysfs_add(dev);
@@ -660,6 +666,9 @@ static int really_probe(struct device *dev, struct device_driver *drv)
        if (dev->bus)
                blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
                                             BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
+
+       if (dev->bus->dma_configure && !drv->no_kernel_dma)
+               iommu_device_release_dma_owner(dev, DMA_OWNER_DMA_API);
 pinctrl_bind_failed:
        device_links_no_driver(dev);
        devres_release_all(dev);
@@ -1204,6 +1213,9 @@ static void __device_release_driver(struct device *dev, struct device *parent)
                else if (drv->remove)
                        drv->remove(dev);

+               if (dev->bus->dma_configure && !drv->no_kernel_dma)
+                       iommu_device_release_dma_owner(dev, DMA_OWNER_DMA_API);
+
                device_links_driver_cleanup(dev);

                devres_release_all(dev);
diff --git a/include/linux/device/driver.h b/include/linux/device/driver.h
index a498ebcf4993..2cf7b757b28e 100644
--- a/include/linux/device/driver.h
+++ b/include/linux/device/driver.h
@@ -100,6 +100,7 @@ struct device_driver {
        const char              *mod_name;      /* used for built-in modules */

        bool suppress_bind_attrs;       /* disables bind/unbind via sysfs */
+       bool no_kernel_dma;
        enum probe_type probe_type;

        const struct of_device_id       *of_match_table;

Best regards,
baolu
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to