Re: [PATCH V10 07/12] of/acpi: Configure dma operations at probe time for platform/amba/pci bus devices
Hi Robin, On 4/4/2017 5:47 PM, Robin Murphy wrote: On 04/04/17 11:18, Sricharan R wrote: Configuring DMA ops at probe time will allow deferring device probe when the IOMMU isn't available yet. The dma_configure for the device is now called from the generic device_attach callback just before the bus/driver probe is called. This way, configuring the DMA ops for the device would be called at the same place for all bus_types, hence the deferred probing mechanism should work for all buses as well. pci_bus_add_devices(platform/amba)(_device_create/driver_register) | | pci_bus_add_device (device_add/driver_register) | | device_attach device_initial_probe | | __device_attach_driver__device_attach_driver | driver_probe_device | really_probe | dma_configure Similarly on the device/driver_unregister path __device_release_driver is called which inturn calls dma_deconfigure. This patch changes the dma ops configuration to probe time for both OF and ACPI based platform/amba/pci bus devices. Reviewed-by: Robin Murphy It's possible we could subsume {of,acpi}_dma_deconfigure() into dma_deconfigure() entirely in future if it becomes clear that neither of them will ever need to do anything firmware-specific, but I think for now it's probably safer to keep the current symmetry - calling arch_teardown_dma_ops() twice is benign (and even if it weren't, I'd say it really should be!) Ya, calling it twice should cause no harm. If nothing firmware specific gets added this could simply be put in deconfigure itself in future. Thanks for all the reviews !! Regards, Sricharan Robin. Tested-by: Marek Szyprowski Tested-by: Hanjun Guo Acked-by: Bjorn Helgaas (drivers/pci part) Acked-by: Rafael J. Wysocki Signed-off-by: Sricharan R --- [V10] Added dummy dma_(de)configure functions in case of !CONFIG_HAS_DMA to avoid build breaks. drivers/acpi/glue.c | 5 - drivers/base/dd.c | 9 + drivers/base/dma-mapping.c | 40 drivers/of/platform.c | 5 + drivers/pci/probe.c | 28 include/linux/dma-mapping.h | 12 6 files changed, 62 insertions(+), 37 deletions(-) diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c index fb19e1c..c05f241 100644 --- a/drivers/acpi/glue.c +++ b/drivers/acpi/glue.c @@ -176,7 +176,6 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev) struct list_head *physnode_list; unsigned int node_id; int retval = -EINVAL; - enum dev_dma_attr attr; if (has_acpi_companion(dev)) { if (acpi_dev) { @@ -233,10 +232,6 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev) if (!has_acpi_companion(dev)) ACPI_COMPANION_SET(dev, acpi_dev); - attr = acpi_get_dma_attr(acpi_dev); - if (attr != DEV_DMA_NOT_SUPPORTED) - acpi_dma_configure(dev, attr); - acpi_physnode_link_name(physical_node_name, node_id); retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj, physical_node_name); diff --git a/drivers/base/dd.c b/drivers/base/dd.c index a1fbf55..4882f06 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -356,6 +357,10 @@ static int really_probe(struct device *dev, struct device_driver *drv) if (ret) goto pinctrl_bind_failed; + ret = dma_configure(dev); + if (ret) + goto dma_failed; + if (driver_sysfs_add(dev)) { printk(KERN_ERR "%s: driver_sysfs_add(%s) failed\n", __func__, dev_name(dev)); @@ -417,6 +422,8 @@ static int really_probe(struct device *dev, struct device_driver *drv) goto done; probe_failed: + dma_deconfigure(dev); +dma_failed: if (dev->bus) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, BUS_NOTIFY_DRIVER_NOT_BOUND, dev); @@ -826,6 +833,8 @@ static void __device_release_driver(struct device *dev, struct device *parent) drv->remove(dev); device_links_driver_cleanup(dev); + dma_deconfigure(dev); + devres_release_all(dev); dev->driver = NULL; dev_set_drvdata(dev, NULL); diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c index efd71cf..449b948 100644 --- a/drivers/base/dma-mapping.c +++ b/drivers/base/dma-mapping.c @@ -7,9 +7,11 @@ * This file is released under the GPLv2. */ +#include #include #include #include +#include #include #include @@ -341,3 +343,41 @@ void dma_common_free_remap(void *cpu_addr, size_t size, unsigned
Re: [PATCH V10 07/12] of/acpi: Configure dma operations at probe time for platform/amba/pci bus devices
On 04/04/17 11:18, Sricharan R wrote: > Configuring DMA ops at probe time will allow deferring device probe when > the IOMMU isn't available yet. The dma_configure for the device is > now called from the generic device_attach callback just before the > bus/driver probe is called. This way, configuring the DMA ops for the > device would be called at the same place for all bus_types, hence the > deferred probing mechanism should work for all buses as well. > > pci_bus_add_devices(platform/amba)(_device_create/driver_register) >| | > pci_bus_add_device (device_add/driver_register) >| | > device_attach device_initial_probe >| | > __device_attach_driver__device_attach_driver >| > driver_probe_device >| > really_probe >| > dma_configure > > Similarly on the device/driver_unregister path __device_release_driver is > called which inturn calls dma_deconfigure. > > This patch changes the dma ops configuration to probe time for > both OF and ACPI based platform/amba/pci bus devices. Reviewed-by: Robin Murphy It's possible we could subsume {of,acpi}_dma_deconfigure() into dma_deconfigure() entirely in future if it becomes clear that neither of them will ever need to do anything firmware-specific, but I think for now it's probably safer to keep the current symmetry - calling arch_teardown_dma_ops() twice is benign (and even if it weren't, I'd say it really should be!) Robin. > Tested-by: Marek Szyprowski > Tested-by: Hanjun Guo > Acked-by: Bjorn Helgaas (drivers/pci part) > Acked-by: Rafael J. Wysocki > Signed-off-by: Sricharan R > --- > > [V10] Added dummy dma_(de)configure functions in case >of !CONFIG_HAS_DMA to avoid build breaks. > > drivers/acpi/glue.c | 5 - > drivers/base/dd.c | 9 + > drivers/base/dma-mapping.c | 40 > drivers/of/platform.c | 5 + > drivers/pci/probe.c | 28 > include/linux/dma-mapping.h | 12 > 6 files changed, 62 insertions(+), 37 deletions(-) > > diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c > index fb19e1c..c05f241 100644 > --- a/drivers/acpi/glue.c > +++ b/drivers/acpi/glue.c > @@ -176,7 +176,6 @@ int acpi_bind_one(struct device *dev, struct acpi_device > *acpi_dev) > struct list_head *physnode_list; > unsigned int node_id; > int retval = -EINVAL; > - enum dev_dma_attr attr; > > if (has_acpi_companion(dev)) { > if (acpi_dev) { > @@ -233,10 +232,6 @@ int acpi_bind_one(struct device *dev, struct acpi_device > *acpi_dev) > if (!has_acpi_companion(dev)) > ACPI_COMPANION_SET(dev, acpi_dev); > > - attr = acpi_get_dma_attr(acpi_dev); > - if (attr != DEV_DMA_NOT_SUPPORTED) > - acpi_dma_configure(dev, attr); > - > acpi_physnode_link_name(physical_node_name, node_id); > retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj, > physical_node_name); > diff --git a/drivers/base/dd.c b/drivers/base/dd.c > index a1fbf55..4882f06 100644 > --- a/drivers/base/dd.c > +++ b/drivers/base/dd.c > @@ -19,6 +19,7 @@ > > #include > #include > +#include > #include > #include > #include > @@ -356,6 +357,10 @@ static int really_probe(struct device *dev, struct > device_driver *drv) > if (ret) > goto pinctrl_bind_failed; > > + ret = dma_configure(dev); > + if (ret) > + goto dma_failed; > + > if (driver_sysfs_add(dev)) { > printk(KERN_ERR "%s: driver_sysfs_add(%s) failed\n", > __func__, dev_name(dev)); > @@ -417,6 +422,8 @@ static int really_probe(struct device *dev, struct > device_driver *drv) > goto done; > > probe_failed: > + dma_deconfigure(dev); > +dma_failed: > if (dev->bus) > blocking_notifier_call_chain(&dev->bus->p->bus_notifier, >BUS_NOTIFY_DRIVER_NOT_BOUND, dev); > @@ -826,6 +833,8 @@ static void __device_release_driver(struct device *dev, > struct device *parent) > drv->remove(dev); > > device_links_driver_cleanup(dev); > + dma_deconfigure(dev); > + > devres_release_all(dev); > dev->driver = NULL; > dev_set_drvdata(dev, NULL); > diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c > index efd71cf..449b948 100644 > --- a/drivers/base/dma-mapping.c > +++ b/drivers/base/dma-mapping.c > @@ -7,9 +7,11 @@ > * This file is released under the GPLv2. > */ > > +#include > #include > #include > #include > +#include > #include > #include > > @@ -341,3 +343,41 @@ void dma_common_free_remap(void *cpu_addr, size_t size, > unsigned long vm_flags) > vunmap(cpu_addr); > } > #
[PATCH V10 07/12] of/acpi: Configure dma operations at probe time for platform/amba/pci bus devices
Configuring DMA ops at probe time will allow deferring device probe when the IOMMU isn't available yet. The dma_configure for the device is now called from the generic device_attach callback just before the bus/driver probe is called. This way, configuring the DMA ops for the device would be called at the same place for all bus_types, hence the deferred probing mechanism should work for all buses as well. pci_bus_add_devices(platform/amba)(_device_create/driver_register) | | pci_bus_add_device (device_add/driver_register) | | device_attach device_initial_probe | | __device_attach_driver__device_attach_driver | driver_probe_device | really_probe | dma_configure Similarly on the device/driver_unregister path __device_release_driver is called which inturn calls dma_deconfigure. This patch changes the dma ops configuration to probe time for both OF and ACPI based platform/amba/pci bus devices. Tested-by: Marek Szyprowski Tested-by: Hanjun Guo Acked-by: Bjorn Helgaas (drivers/pci part) Acked-by: Rafael J. Wysocki Signed-off-by: Sricharan R --- [V10] Added dummy dma_(de)configure functions in case of !CONFIG_HAS_DMA to avoid build breaks. drivers/acpi/glue.c | 5 - drivers/base/dd.c | 9 + drivers/base/dma-mapping.c | 40 drivers/of/platform.c | 5 + drivers/pci/probe.c | 28 include/linux/dma-mapping.h | 12 6 files changed, 62 insertions(+), 37 deletions(-) diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c index fb19e1c..c05f241 100644 --- a/drivers/acpi/glue.c +++ b/drivers/acpi/glue.c @@ -176,7 +176,6 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev) struct list_head *physnode_list; unsigned int node_id; int retval = -EINVAL; - enum dev_dma_attr attr; if (has_acpi_companion(dev)) { if (acpi_dev) { @@ -233,10 +232,6 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev) if (!has_acpi_companion(dev)) ACPI_COMPANION_SET(dev, acpi_dev); - attr = acpi_get_dma_attr(acpi_dev); - if (attr != DEV_DMA_NOT_SUPPORTED) - acpi_dma_configure(dev, attr); - acpi_physnode_link_name(physical_node_name, node_id); retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj, physical_node_name); diff --git a/drivers/base/dd.c b/drivers/base/dd.c index a1fbf55..4882f06 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -356,6 +357,10 @@ static int really_probe(struct device *dev, struct device_driver *drv) if (ret) goto pinctrl_bind_failed; + ret = dma_configure(dev); + if (ret) + goto dma_failed; + if (driver_sysfs_add(dev)) { printk(KERN_ERR "%s: driver_sysfs_add(%s) failed\n", __func__, dev_name(dev)); @@ -417,6 +422,8 @@ static int really_probe(struct device *dev, struct device_driver *drv) goto done; probe_failed: + dma_deconfigure(dev); +dma_failed: if (dev->bus) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, BUS_NOTIFY_DRIVER_NOT_BOUND, dev); @@ -826,6 +833,8 @@ static void __device_release_driver(struct device *dev, struct device *parent) drv->remove(dev); device_links_driver_cleanup(dev); + dma_deconfigure(dev); + devres_release_all(dev); dev->driver = NULL; dev_set_drvdata(dev, NULL); diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c index efd71cf..449b948 100644 --- a/drivers/base/dma-mapping.c +++ b/drivers/base/dma-mapping.c @@ -7,9 +7,11 @@ * This file is released under the GPLv2. */ +#include #include #include #include +#include #include #include @@ -341,3 +343,41 @@ void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags) vunmap(cpu_addr); } #endif + +/* + * Common configuration to enable DMA API use for a device + */ +#include + +int dma_configure(struct device *dev) +{ + struct device *bridge = NULL, *dma_dev = dev; + enum dev_dma_attr attr; + + if (dev_is_pci(dev)) { + bridge = pci_get_host_bridge_device(to_pci_dev(dev)); + dma_dev = bridge; + if (IS_ENABLED(CONFIG_OF) && dma_dev->parent && + dma_dev->parent->of_node) + dma_dev = dma_dev->parent; + } + + if (dma_dev->of_node) { + of_dma_configure(dev, dma_dev->of_node); + } else if (has_