On Fri, Mar 30, 2018 at 01:24:44PM +0530, Nipun Gupta wrote:
> It is bus specific aspect to map a given device on the bus and
> relevant firmware description of its DMA configuration.
> So, this change introduces 'dma_configure' as bus callback
> giving flexibility to busses for implementing its own dma
> configuration function.
>
> The change eases the addition of new busses w.r.t. adding the dma
> configuration functionality.
>
> This patch also updates the PCI, Platform, ACPI and host1x bus to
> use new introduced callbacks.
s/dma/DMA/ consistently above.
> Suggested-by: Christoph Hellwig
> Signed-off-by: Nipun Gupta
> Reviewed-by: Greg Kroah-Hartman
Acked-by: Bjorn Helgaas # PCI parts
I assume you'll merge this via some non-PCI tree. Let me know if you
need anything else from me.
> ---
> - The patches are based on the comments on:
>https://patchwork.kernel.org/patch/10259087/
>
> Changes in v2:
> - Do not have dma_deconfigure callback
> - Have '/dma_common_configure/' API to provide a common DMA
> configuration which can be used by busses if it suits them.
> - Platform and ACPI bus to use '/dma_common_configure/' in
> '/dma_configure/' callback.
> - Updated commit message
> - Updated pci_dma_configure API with changes suggested by Robin
>
> Changes in v3
> - Move dma_common_configure() within platform_dma_configure() and
> reuse platofrm_dma_configure() for AMBA bus too
> - Declare 'attr' in pci_dma_configure() inside the else statement
> where it is used.
>
> drivers/amba/bus.c | 4
> drivers/base/dma-mapping.c | 31 ---
> drivers/base/platform.c | 17 +
> drivers/gpu/host1x/bus.c| 8
> drivers/pci/pci-driver.c| 32
> include/linux/device.h | 4
> include/linux/platform_device.h | 2 ++
> 7 files changed, 71 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
> index 594c228..867dc2b 100644
> --- a/drivers/amba/bus.c
> +++ b/drivers/amba/bus.c
> @@ -20,6 +20,7 @@
> #include
> #include
> #include
> +#include
>
> #include
>
> @@ -188,12 +189,15 @@ static int amba_pm_runtime_resume(struct device *dev)
> /*
> * Primecells are part of the Advanced Microcontroller Bus Architecture,
> * so we call the bus "amba".
> + * DMA configuration for platform and AMBA bus is same. So here we reuse
> + * platform's DMA config routine.
> */
> struct bus_type amba_bustype = {
> .name = "amba",
> .dev_groups = amba_dev_groups,
> .match = amba_match,
> .uevent = amba_uevent,
> + .dma_configure = platform_dma_configure,
> .pm = &amba_pm,
> .force_dma = true,
> };
> diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c
> index 3b11835..fdc1502 100644
> --- a/drivers/base/dma-mapping.c
> +++ b/drivers/base/dma-mapping.c
> @@ -331,36 +331,13 @@ void dma_common_free_remap(void *cpu_addr, size_t size,
> unsigned long vm_flags)
> #endif
>
> /*
> - * Common configuration to enable DMA API use for a device
> + * enables 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;
> - int ret = 0;
> -
> - 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) {
> - ret = of_dma_configure(dev, dma_dev->of_node);
> - } else if (has_acpi_companion(dma_dev)) {
> - attr = acpi_get_dma_attr(to_acpi_device_node(dma_dev->fwnode));
> - if (attr != DEV_DMA_NOT_SUPPORTED)
> - ret = acpi_dma_configure(dev, attr);
> - }
> -
> - if (bridge)
> - pci_put_host_bridge_device(bridge);
> -
> - return ret;
> + if (dev->bus->dma_configure)
> + return dev->bus->dma_configure(dev);
> + return 0;
> }
>
> void dma_deconfigure(struct device *dev)
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index f1bf7b3..72fdbf6 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -1130,6 +1130,22 @@ int platform_pm_restore(struct device *dev)
>
> #endif /* CONFIG_HIBERNATE_CALLBACKS */
>
> +int platform_dma_configure(struct device *dev)
> +{
> + enum dev_dma_attr attr;
> + int ret = 0;
> +
> + if (dev->of_node) {
> + ret = of_dma_configure(dev, dev->of_node);
> + } else if (has_acpi_companion(dev)) {
> + attr = acpi_get_dma_attr(to_acpi_device_node(dev->fwnode));
> + if (attr != DEV_DMA_NOT_SUPPORTED)
> +