2018-03-30 07:55:24

by Nipun Gupta

[permalink] [raw]
Subject: [PATCH v3 1/2] dma-mapping: move dma configuration to bus infrastructure

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.

Suggested-by: Christoph Hellwig <[email protected]>
Signed-off-by: Nipun Gupta <[email protected]>
Reviewed-by: Greg Kroah-Hartman <[email protected]>
---
- 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 <linux/sizes.h>
#include <linux/limits.h>
#include <linux/clk/clk-conf.h>
+#include <linux/platform_device.h>

#include <asm/irq.h>

@@ -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 <linux/pci.h>
-
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)
+ ret = acpi_dma_configure(dev, attr);
+ }
+
+ return ret;
+}
+
static const struct dev_pm_ops platform_dev_pm_ops = {
.runtime_suspend = pm_generic_runtime_suspend,
.runtime_resume = pm_generic_runtime_resume,
@@ -1141,6 +1157,7 @@ struct bus_type platform_bus_type = {
.dev_groups = platform_dev_groups,
.match = platform_match,
.uevent = platform_uevent,
+ .dma_configure = platform_dma_configure,
.pm = &platform_dev_pm_ops,
.force_dma = true,
};
diff --git a/drivers/gpu/host1x/bus.c b/drivers/gpu/host1x/bus.c
index 88a3558..a9ec99d 100644
--- a/drivers/gpu/host1x/bus.c
+++ b/drivers/gpu/host1x/bus.c
@@ -314,6 +314,13 @@ static int host1x_device_match(struct device *dev, struct device_driver *drv)
return strcmp(dev_name(dev), drv->name) == 0;
}

+static int host1x_dma_configure(struct device *dev)
+{
+ if (dev->of_node)
+ return of_dma_configure(dev, dev->of_node);
+ return 0;
+}
+
static const struct dev_pm_ops host1x_device_pm_ops = {
.suspend = pm_generic_suspend,
.resume = pm_generic_resume,
@@ -326,6 +333,7 @@ static int host1x_device_match(struct device *dev, struct device_driver *drv)
struct bus_type host1x_bus_type = {
.name = "host1x",
.match = host1x_device_match,
+ .dma_configure = host1x_dma_configure,
.pm = &host1x_device_pm_ops,
.force_dma = true,
};
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 3bed6be..78e507f 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -18,6 +18,8 @@
#include <linux/pm_runtime.h>
#include <linux/suspend.h>
#include <linux/kexec.h>
+#include <linux/of_device.h>
+#include <linux/acpi.h>
#include "pci.h"

struct pci_dynid {
@@ -1522,6 +1524,35 @@ static int pci_bus_num_vf(struct device *dev)
return pci_num_vf(to_pci_dev(dev));
}

+/**
+ * pci_dma_configure - Setup DMA configuration
+ * @dev: ptr to dev structure
+ *
+ * Function to update PCI devices's DMA configuration using the same
+ * info from the OF node or ACPI node of host bridge's parent (if any).
+ */
+static int pci_dma_configure(struct device *dev)
+{
+ struct device *bridge;
+ int ret = 0;
+
+ bridge = pci_get_host_bridge_device(to_pci_dev(dev));
+
+ if (IS_ENABLED(CONFIG_OF) && bridge->parent &&
+ bridge->parent->of_node) {
+ ret = of_dma_configure(dev, bridge->parent->of_node);
+ } else if (has_acpi_companion(bridge)) {
+ struct acpi_device *adev = to_acpi_device_node(bridge->fwnode);
+ enum dev_dma_attr attr = acpi_get_dma_attr(adev);
+
+ if (attr != DEV_DMA_NOT_SUPPORTED)
+ ret = acpi_dma_configure(dev, attr);
+ }
+
+ pci_put_host_bridge_device(bridge);
+ return ret;
+}
+
struct bus_type pci_bus_type = {
.name = "pci",
.match = pci_bus_match,
@@ -1534,6 +1565,7 @@ struct bus_type pci_bus_type = {
.drv_groups = pci_drv_groups,
.pm = PCI_PM_OPS_PTR,
.num_vf = pci_bus_num_vf,
+ .dma_configure = pci_dma_configure,
.force_dma = true,
};
EXPORT_SYMBOL(pci_bus_type);
diff --git a/include/linux/device.h b/include/linux/device.h
index b093405..1832d90 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -88,6 +88,8 @@ extern int __must_check bus_create_file(struct bus_type *,
* @resume: Called to bring a device on this bus out of sleep mode.
* @num_vf: Called to find out how many virtual functions a device on this
* bus supports.
+ * @dma_configure: Called to setup DMA configuration on a device on
+ this bus.
* @pm: Power management operations of this bus, callback the specific
* device driver's pm-ops.
* @iommu_ops: IOMMU specific operations for this bus, used to attach IOMMU
@@ -130,6 +132,8 @@ struct bus_type {

int (*num_vf)(struct device *dev);

+ int (*dma_configure)(struct device *dev);
+
const struct dev_pm_ops *pm;

const struct iommu_ops *iommu_ops;
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 49f634d..3097c94 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -356,6 +356,8 @@ static inline char *early_platform_driver_setup_func(void) \
#define platform_pm_restore NULL
#endif

+extern int platform_dma_configure(struct device *dev);
+
#ifdef CONFIG_PM_SLEEP
#define USE_PLATFORM_PM_SLEEP_OPS \
.suspend = platform_pm_suspend, \
--
1.9.1


2018-03-30 07:55:33

by Nipun Gupta

[permalink] [raw]
Subject: [PATCH v3 2/2] drivers: remove force dma flag from buses

With each bus implementing its own DMA configuration callback,
there is no need for bus to explicitly have force_dma in its
global structure. This patch modifies of_dma_configure API to
accept an input parameter which specifies if implicit DMA
configuration is required even when it is not described by the
firmware.

Signed-off-by: Nipun Gupta <[email protected]>
---
Changes in v2:
- This is a new change suggested by Robin and Christoph
and is added to the series.

Changes in v3:
- Rebase and changes corresponding to the changes in patch 1/2

drivers/amba/bus.c | 1 -
drivers/base/platform.c | 3 +--
drivers/bcma/main.c | 2 +-
drivers/dma/qcom/hidma_mgmt.c | 2 +-
drivers/gpu/host1x/bus.c | 5 ++---
drivers/of/device.c | 6 ++++--
drivers/of/of_reserved_mem.c | 2 +-
drivers/pci/pci-driver.c | 3 +--
include/linux/device.h | 4 ----
include/linux/of_device.h | 8 ++++++--
10 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 867dc2b..abe73c4 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -199,7 +199,6 @@ struct bus_type amba_bustype = {
.uevent = amba_uevent,
.dma_configure = platform_dma_configure,
.pm = &amba_pm,
- .force_dma = true,
};

static int __init amba_init(void)
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 72fdbf6..cfbc569 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -1136,7 +1136,7 @@ int platform_dma_configure(struct device *dev)
int ret = 0;

if (dev->of_node) {
- ret = of_dma_configure(dev, dev->of_node);
+ ret = of_dma_configure(dev, dev->of_node, true);
} else if (has_acpi_companion(dev)) {
attr = acpi_get_dma_attr(to_acpi_device_node(dev->fwnode));
if (attr != DEV_DMA_NOT_SUPPORTED)
@@ -1159,7 +1159,6 @@ struct bus_type platform_bus_type = {
.uevent = platform_uevent,
.dma_configure = platform_dma_configure,
.pm = &platform_dev_pm_ops,
- .force_dma = true,
};
EXPORT_SYMBOL_GPL(platform_bus_type);

diff --git a/drivers/bcma/main.c b/drivers/bcma/main.c
index e6986c7..fc1f4ac 100644
--- a/drivers/bcma/main.c
+++ b/drivers/bcma/main.c
@@ -207,7 +207,7 @@ static void bcma_of_fill_device(struct device *parent,

core->irq = bcma_of_get_irq(parent, core, 0);

- of_dma_configure(&core->dev, node);
+ of_dma_configure(&core->dev, node, false);
}

unsigned int bcma_core_irq(struct bcma_device *core, int num)
diff --git a/drivers/dma/qcom/hidma_mgmt.c b/drivers/dma/qcom/hidma_mgmt.c
index 000c7019..d64edeb 100644
--- a/drivers/dma/qcom/hidma_mgmt.c
+++ b/drivers/dma/qcom/hidma_mgmt.c
@@ -398,7 +398,7 @@ static int __init hidma_mgmt_of_populate_channels(struct device_node *np)
}
of_node_get(child);
new_pdev->dev.of_node = child;
- of_dma_configure(&new_pdev->dev, child);
+ of_dma_configure(&new_pdev->dev, child, true);
/*
* It is assumed that calling of_msi_configure is safe on
* platforms with or without MSI support.
diff --git a/drivers/gpu/host1x/bus.c b/drivers/gpu/host1x/bus.c
index a9ec99d..b39c1e9 100644
--- a/drivers/gpu/host1x/bus.c
+++ b/drivers/gpu/host1x/bus.c
@@ -317,7 +317,7 @@ static int host1x_device_match(struct device *dev, struct device_driver *drv)
static int host1x_dma_configure(struct device *dev)
{
if (dev->of_node)
- return of_dma_configure(dev, dev->of_node);
+ return of_dma_configure(dev, dev->of_node, true);
return 0;
}

@@ -335,7 +335,6 @@ struct bus_type host1x_bus_type = {
.match = host1x_device_match,
.dma_configure = host1x_dma_configure,
.pm = &host1x_device_pm_ops,
- .force_dma = true,
};

static void __host1x_device_del(struct host1x_device *device)
@@ -424,7 +423,7 @@ static int host1x_device_add(struct host1x *host1x,
device->dev.bus = &host1x_bus_type;
device->dev.parent = host1x->dev;

- of_dma_configure(&device->dev, host1x->dev->of_node);
+ of_dma_configure(&device->dev, host1x->dev->of_node, true);

err = host1x_device_parse_dt(device, driver);
if (err < 0) {
diff --git a/drivers/of/device.c b/drivers/of/device.c
index 064c818..33d8551 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -76,6 +76,8 @@ int of_device_add(struct platform_device *ofdev)
* of_dma_configure - Setup DMA configuration
* @dev: Device to apply DMA configuration
* @np: Pointer to OF node having DMA configuration
+ * @force_dma: Whether device is to be set up by of_dma_configure() even if
+ * DMA capability is not explicitly described by firmware.
*
* Try to get devices's DMA configuration from DT and update it
* accordingly.
@@ -84,7 +86,7 @@ int of_device_add(struct platform_device *ofdev)
* can use a platform bus notifier and handle BUS_NOTIFY_ADD_DEVICE events
* to fix up DMA configuration.
*/
-int of_dma_configure(struct device *dev, struct device_node *np)
+int of_dma_configure(struct device *dev, struct device_node *np, bool force_dma)
{
u64 dma_addr, paddr, size = 0;
int ret;
@@ -100,7 +102,7 @@ int of_dma_configure(struct device *dev, struct device_node *np)
* DMA configuration regardless of whether "dma-ranges" is
* correctly specified or not.
*/
- if (!dev->bus->force_dma)
+ if (!force_dma)
return ret == -ENODEV ? 0 : ret;

dma_addr = offset = 0;
diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index 9a4f4246..895c83e 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -353,7 +353,7 @@ int of_reserved_mem_device_init_by_idx(struct device *dev,
/* ensure that dma_ops is set for virtual devices
* using reserved memory
*/
- of_dma_configure(dev, np);
+ of_dma_configure(dev, np, true);

dev_info(dev, "assigned reserved memory node %s\n", rmem->name);
} else {
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 78e507f..27c832f 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -1540,7 +1540,7 @@ static int pci_dma_configure(struct device *dev)

if (IS_ENABLED(CONFIG_OF) && bridge->parent &&
bridge->parent->of_node) {
- ret = of_dma_configure(dev, bridge->parent->of_node);
+ ret = of_dma_configure(dev, bridge->parent->of_node, true);
} else if (has_acpi_companion(bridge)) {
struct acpi_device *adev = to_acpi_device_node(bridge->fwnode);
enum dev_dma_attr attr = acpi_get_dma_attr(adev);
@@ -1566,7 +1566,6 @@ struct bus_type pci_bus_type = {
.pm = PCI_PM_OPS_PTR,
.num_vf = pci_bus_num_vf,
.dma_configure = pci_dma_configure,
- .force_dma = true,
};
EXPORT_SYMBOL(pci_bus_type);

diff --git a/include/linux/device.h b/include/linux/device.h
index 1832d90..92c530e 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -98,8 +98,6 @@ extern int __must_check bus_create_file(struct bus_type *,
* @p: The private data of the driver core, only the driver core can
* touch this.
* @lock_key: Lock class key for use by the lock validator
- * @force_dma: Assume devices on this bus should be set up by dma_configure()
- * even if DMA capability is not explicitly described by firmware.
*
* A bus is a channel between the processor and one or more devices. For the
* purposes of the device model, all devices are connected via a bus, even if
@@ -140,8 +138,6 @@ struct bus_type {

struct subsys_private *p;
struct lock_class_key lock_key;
-
- bool force_dma;
};

extern int __must_check bus_register(struct bus_type *bus);
diff --git a/include/linux/of_device.h b/include/linux/of_device.h
index 8da5a1b..165fd30 100644
--- a/include/linux/of_device.h
+++ b/include/linux/of_device.h
@@ -55,7 +55,9 @@ static inline struct device_node *of_cpu_device_node_get(int cpu)
return of_node_get(cpu_dev->of_node);
}

-int of_dma_configure(struct device *dev, struct device_node *np);
+int of_dma_configure(struct device *dev,
+ struct device_node *np,
+ bool force_dma);
void of_dma_deconfigure(struct device *dev);
#else /* CONFIG_OF */

@@ -105,7 +107,9 @@ static inline struct device_node *of_cpu_device_node_get(int cpu)
return NULL;
}

-static inline int of_dma_configure(struct device *dev, struct device_node *np)
+static inline int of_dma_configure(struct device *dev,
+ struct device_node *np,
+ bool force_dma)
{
return 0;
}
--
1.9.1

2018-04-23 12:55:37

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] dma-mapping: move dma configuration to bus infrastructure

On Tue, Apr 10, 2018 at 02:20:41PM -0500, Bjorn Helgaas wrote:
> I assume you'll merge this via some non-PCI tree. Let me know if you
> need anything else from me.

I'll take it through the dma-mapping tree, so you should be fine.

2018-04-10 19:20:43

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] dma-mapping: move dma configuration to bus infrastructure

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 <[email protected]>
> Signed-off-by: Nipun Gupta <[email protected]>
> Reviewed-by: Greg Kroah-Hartman <[email protected]>

Acked-by: Bjorn Helgaas <[email protected]> # 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 <linux/sizes.h>
> #include <linux/limits.h>
> #include <linux/clk/clk-conf.h>
> +#include <linux/platform_device.h>
>
> #include <asm/irq.h>
>
> @@ -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 <linux/pci.h>
> -
> 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)
> + ret = acpi_dma_configure(dev, attr);
> + }
> +
> + return ret;
> +}
> +
> static const struct dev_pm_ops platform_dev_pm_ops = {
> .runtime_suspend = pm_generic_runtime_suspend,
> .runtime_resume = pm_generic_runtime_resume,
> @@ -1141,6 +1157,7 @@ struct bus_type platform_bus_type = {
> .dev_groups = platform_dev_groups,
> .match = platform_match,
> .uevent = platform_uevent,
> + .dma_configure = platform_dma_configure,
> .pm = &platform_dev_pm_ops,
> .force_dma = true,
> };
> diff --git a/drivers/gpu/host1x/bus.c b/drivers/gpu/host1x/bus.c
> index 88a3558..a9ec99d 100644
> --- a/drivers/gpu/host1x/bus.c
> +++ b/drivers/gpu/host1x/bus.c
> @@ -314,6 +314,13 @@ static int host1x_device_match(struct device *dev, struct device_driver *drv)
> return strcmp(dev_name(dev), drv->name) == 0;
> }
>
> +static int host1x_dma_configure(struct device *dev)
> +{
> + if (dev->of_node)
> + return of_dma_configure(dev, dev->of_node);
> + return 0;
> +}
> +
> static const struct dev_pm_ops host1x_device_pm_ops = {
> .suspend = pm_generic_suspend,
> .resume = pm_generic_resume,
> @@ -326,6 +333,7 @@ static int host1x_device_match(struct device *dev, struct device_driver *drv)
> struct bus_type host1x_bus_type = {
> .name = "host1x",
> .match = host1x_device_match,
> + .dma_configure = host1x_dma_configure,
> .pm = &host1x_device_pm_ops,
> .force_dma = true,
> };
> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
> index 3bed6be..78e507f 100644
> --- a/drivers/pci/pci-driver.c
> +++ b/drivers/pci/pci-driver.c
> @@ -18,6 +18,8 @@
> #include <linux/pm_runtime.h>
> #include <linux/suspend.h>
> #include <linux/kexec.h>
> +#include <linux/of_device.h>
> +#include <linux/acpi.h>
> #include "pci.h"
>
> struct pci_dynid {
> @@ -1522,6 +1524,35 @@ static int pci_bus_num_vf(struct device *dev)
> return pci_num_vf(to_pci_dev(dev));
> }
>
> +/**
> + * pci_dma_configure - Setup DMA configuration
> + * @dev: ptr to dev structure
> + *
> + * Function to update PCI devices's DMA configuration using the same
> + * info from the OF node or ACPI node of host bridge's parent (if any).
> + */
> +static int pci_dma_configure(struct device *dev)
> +{
> + struct device *bridge;
> + int ret = 0;
> +
> + bridge = pci_get_host_bridge_device(to_pci_dev(dev));
> +
> + if (IS_ENABLED(CONFIG_OF) && bridge->parent &&
> + bridge->parent->of_node) {
> + ret = of_dma_configure(dev, bridge->parent->of_node);
> + } else if (has_acpi_companion(bridge)) {
> + struct acpi_device *adev = to_acpi_device_node(bridge->fwnode);
> + enum dev_dma_attr attr = acpi_get_dma_attr(adev);
> +
> + if (attr != DEV_DMA_NOT_SUPPORTED)
> + ret = acpi_dma_configure(dev, attr);
> + }
> +
> + pci_put_host_bridge_device(bridge);
> + return ret;
> +}
> +
> struct bus_type pci_bus_type = {
> .name = "pci",
> .match = pci_bus_match,
> @@ -1534,6 +1565,7 @@ struct bus_type pci_bus_type = {
> .drv_groups = pci_drv_groups,
> .pm = PCI_PM_OPS_PTR,
> .num_vf = pci_bus_num_vf,
> + .dma_configure = pci_dma_configure,
> .force_dma = true,
> };
> EXPORT_SYMBOL(pci_bus_type);
> diff --git a/include/linux/device.h b/include/linux/device.h
> index b093405..1832d90 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -88,6 +88,8 @@ extern int __must_check bus_create_file(struct bus_type *,
> * @resume: Called to bring a device on this bus out of sleep mode.
> * @num_vf: Called to find out how many virtual functions a device on this
> * bus supports.
> + * @dma_configure: Called to setup DMA configuration on a device on
> + this bus.
> * @pm: Power management operations of this bus, callback the specific
> * device driver's pm-ops.
> * @iommu_ops: IOMMU specific operations for this bus, used to attach IOMMU
> @@ -130,6 +132,8 @@ struct bus_type {
>
> int (*num_vf)(struct device *dev);
>
> + int (*dma_configure)(struct device *dev);
> +
> const struct dev_pm_ops *pm;
>
> const struct iommu_ops *iommu_ops;
> diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
> index 49f634d..3097c94 100644
> --- a/include/linux/platform_device.h
> +++ b/include/linux/platform_device.h
> @@ -356,6 +356,8 @@ static inline char *early_platform_driver_setup_func(void) \
> #define platform_pm_restore NULL
> #endif
>
> +extern int platform_dma_configure(struct device *dev);
> +
> #ifdef CONFIG_PM_SLEEP
> #define USE_PLATFORM_PM_SLEEP_OPS \
> .suspend = platform_pm_suspend, \
> --
> 1.9.1
>

2018-04-10 19:21:53

by Bjorn Helgaas

[permalink] [raw]
Subject: Re: [PATCH v3 2/2] drivers: remove force dma flag from buses

On Fri, Mar 30, 2018 at 01:24:45PM +0530, Nipun Gupta wrote:
> With each bus implementing its own DMA configuration callback,
> there is no need for bus to explicitly have force_dma in its
> global structure. This patch modifies of_dma_configure API to
> accept an input parameter which specifies if implicit DMA
> configuration is required even when it is not described by the
> firmware.
>
> Signed-off-by: Nipun Gupta <[email protected]>

Acked-by: Bjorn Helgaas <[email protected]> # PCI parts

> ---
> Changes in v2:
> - This is a new change suggested by Robin and Christoph
> and is added to the series.
>
> Changes in v3:
> - Rebase and changes corresponding to the changes in patch 1/2
>
> drivers/amba/bus.c | 1 -
> drivers/base/platform.c | 3 +--
> drivers/bcma/main.c | 2 +-
> drivers/dma/qcom/hidma_mgmt.c | 2 +-
> drivers/gpu/host1x/bus.c | 5 ++---
> drivers/of/device.c | 6 ++++--
> drivers/of/of_reserved_mem.c | 2 +-
> drivers/pci/pci-driver.c | 3 +--
> include/linux/device.h | 4 ----
> include/linux/of_device.h | 8 ++++++--
> 10 files changed, 17 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
> index 867dc2b..abe73c4 100644
> --- a/drivers/amba/bus.c
> +++ b/drivers/amba/bus.c
> @@ -199,7 +199,6 @@ struct bus_type amba_bustype = {
> .uevent = amba_uevent,
> .dma_configure = platform_dma_configure,
> .pm = &amba_pm,
> - .force_dma = true,
> };
>
> static int __init amba_init(void)
> diff --git a/drivers/base/platform.c b/drivers/base/platform.c
> index 72fdbf6..cfbc569 100644
> --- a/drivers/base/platform.c
> +++ b/drivers/base/platform.c
> @@ -1136,7 +1136,7 @@ int platform_dma_configure(struct device *dev)
> int ret = 0;
>
> if (dev->of_node) {
> - ret = of_dma_configure(dev, dev->of_node);
> + ret = of_dma_configure(dev, dev->of_node, true);
> } else if (has_acpi_companion(dev)) {
> attr = acpi_get_dma_attr(to_acpi_device_node(dev->fwnode));
> if (attr != DEV_DMA_NOT_SUPPORTED)
> @@ -1159,7 +1159,6 @@ struct bus_type platform_bus_type = {
> .uevent = platform_uevent,
> .dma_configure = platform_dma_configure,
> .pm = &platform_dev_pm_ops,
> - .force_dma = true,
> };
> EXPORT_SYMBOL_GPL(platform_bus_type);
>
> diff --git a/drivers/bcma/main.c b/drivers/bcma/main.c
> index e6986c7..fc1f4ac 100644
> --- a/drivers/bcma/main.c
> +++ b/drivers/bcma/main.c
> @@ -207,7 +207,7 @@ static void bcma_of_fill_device(struct device *parent,
>
> core->irq = bcma_of_get_irq(parent, core, 0);
>
> - of_dma_configure(&core->dev, node);
> + of_dma_configure(&core->dev, node, false);
> }
>
> unsigned int bcma_core_irq(struct bcma_device *core, int num)
> diff --git a/drivers/dma/qcom/hidma_mgmt.c b/drivers/dma/qcom/hidma_mgmt.c
> index 000c7019..d64edeb 100644
> --- a/drivers/dma/qcom/hidma_mgmt.c
> +++ b/drivers/dma/qcom/hidma_mgmt.c
> @@ -398,7 +398,7 @@ static int __init hidma_mgmt_of_populate_channels(struct device_node *np)
> }
> of_node_get(child);
> new_pdev->dev.of_node = child;
> - of_dma_configure(&new_pdev->dev, child);
> + of_dma_configure(&new_pdev->dev, child, true);
> /*
> * It is assumed that calling of_msi_configure is safe on
> * platforms with or without MSI support.
> diff --git a/drivers/gpu/host1x/bus.c b/drivers/gpu/host1x/bus.c
> index a9ec99d..b39c1e9 100644
> --- a/drivers/gpu/host1x/bus.c
> +++ b/drivers/gpu/host1x/bus.c
> @@ -317,7 +317,7 @@ static int host1x_device_match(struct device *dev, struct device_driver *drv)
> static int host1x_dma_configure(struct device *dev)
> {
> if (dev->of_node)
> - return of_dma_configure(dev, dev->of_node);
> + return of_dma_configure(dev, dev->of_node, true);
> return 0;
> }
>
> @@ -335,7 +335,6 @@ struct bus_type host1x_bus_type = {
> .match = host1x_device_match,
> .dma_configure = host1x_dma_configure,
> .pm = &host1x_device_pm_ops,
> - .force_dma = true,
> };
>
> static void __host1x_device_del(struct host1x_device *device)
> @@ -424,7 +423,7 @@ static int host1x_device_add(struct host1x *host1x,
> device->dev.bus = &host1x_bus_type;
> device->dev.parent = host1x->dev;
>
> - of_dma_configure(&device->dev, host1x->dev->of_node);
> + of_dma_configure(&device->dev, host1x->dev->of_node, true);
>
> err = host1x_device_parse_dt(device, driver);
> if (err < 0) {
> diff --git a/drivers/of/device.c b/drivers/of/device.c
> index 064c818..33d8551 100644
> --- a/drivers/of/device.c
> +++ b/drivers/of/device.c
> @@ -76,6 +76,8 @@ int of_device_add(struct platform_device *ofdev)
> * of_dma_configure - Setup DMA configuration
> * @dev: Device to apply DMA configuration
> * @np: Pointer to OF node having DMA configuration
> + * @force_dma: Whether device is to be set up by of_dma_configure() even if
> + * DMA capability is not explicitly described by firmware.
> *
> * Try to get devices's DMA configuration from DT and update it
> * accordingly.
> @@ -84,7 +86,7 @@ int of_device_add(struct platform_device *ofdev)
> * can use a platform bus notifier and handle BUS_NOTIFY_ADD_DEVICE events
> * to fix up DMA configuration.
> */
> -int of_dma_configure(struct device *dev, struct device_node *np)
> +int of_dma_configure(struct device *dev, struct device_node *np, bool force_dma)
> {
> u64 dma_addr, paddr, size = 0;
> int ret;
> @@ -100,7 +102,7 @@ int of_dma_configure(struct device *dev, struct device_node *np)
> * DMA configuration regardless of whether "dma-ranges" is
> * correctly specified or not.
> */
> - if (!dev->bus->force_dma)
> + if (!force_dma)
> return ret == -ENODEV ? 0 : ret;
>
> dma_addr = offset = 0;
> diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
> index 9a4f4246..895c83e 100644
> --- a/drivers/of/of_reserved_mem.c
> +++ b/drivers/of/of_reserved_mem.c
> @@ -353,7 +353,7 @@ int of_reserved_mem_device_init_by_idx(struct device *dev,
> /* ensure that dma_ops is set for virtual devices
> * using reserved memory
> */
> - of_dma_configure(dev, np);
> + of_dma_configure(dev, np, true);
>
> dev_info(dev, "assigned reserved memory node %s\n", rmem->name);
> } else {
> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
> index 78e507f..27c832f 100644
> --- a/drivers/pci/pci-driver.c
> +++ b/drivers/pci/pci-driver.c
> @@ -1540,7 +1540,7 @@ static int pci_dma_configure(struct device *dev)
>
> if (IS_ENABLED(CONFIG_OF) && bridge->parent &&
> bridge->parent->of_node) {
> - ret = of_dma_configure(dev, bridge->parent->of_node);
> + ret = of_dma_configure(dev, bridge->parent->of_node, true);
> } else if (has_acpi_companion(bridge)) {
> struct acpi_device *adev = to_acpi_device_node(bridge->fwnode);
> enum dev_dma_attr attr = acpi_get_dma_attr(adev);
> @@ -1566,7 +1566,6 @@ struct bus_type pci_bus_type = {
> .pm = PCI_PM_OPS_PTR,
> .num_vf = pci_bus_num_vf,
> .dma_configure = pci_dma_configure,
> - .force_dma = true,
> };
> EXPORT_SYMBOL(pci_bus_type);
>
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 1832d90..92c530e 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -98,8 +98,6 @@ extern int __must_check bus_create_file(struct bus_type *,
> * @p: The private data of the driver core, only the driver core can
> * touch this.
> * @lock_key: Lock class key for use by the lock validator
> - * @force_dma: Assume devices on this bus should be set up by dma_configure()
> - * even if DMA capability is not explicitly described by firmware.
> *
> * A bus is a channel between the processor and one or more devices. For the
> * purposes of the device model, all devices are connected via a bus, even if
> @@ -140,8 +138,6 @@ struct bus_type {
>
> struct subsys_private *p;
> struct lock_class_key lock_key;
> -
> - bool force_dma;
> };
>
> extern int __must_check bus_register(struct bus_type *bus);
> diff --git a/include/linux/of_device.h b/include/linux/of_device.h
> index 8da5a1b..165fd30 100644
> --- a/include/linux/of_device.h
> +++ b/include/linux/of_device.h
> @@ -55,7 +55,9 @@ static inline struct device_node *of_cpu_device_node_get(int cpu)
> return of_node_get(cpu_dev->of_node);
> }
>
> -int of_dma_configure(struct device *dev, struct device_node *np);
> +int of_dma_configure(struct device *dev,
> + struct device_node *np,
> + bool force_dma);
> void of_dma_deconfigure(struct device *dev);
> #else /* CONFIG_OF */
>
> @@ -105,7 +107,9 @@ static inline struct device_node *of_cpu_device_node_get(int cpu)
> return NULL;
> }
>
> -static inline int of_dma_configure(struct device *dev, struct device_node *np)
> +static inline int of_dma_configure(struct device *dev,
> + struct device_node *np,
> + bool force_dma)
> {
> return 0;
> }
> --
> 1.9.1
>

2018-04-09 20:27:47

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH v3 2/2] drivers: remove force dma flag from buses

On Fri, Mar 30, 2018 at 01:24:45PM +0530, Nipun Gupta wrote:
> With each bus implementing its own DMA configuration callback,
> there is no need for bus to explicitly have force_dma in its
> global structure. This patch modifies of_dma_configure API to
> accept an input parameter which specifies if implicit DMA
> configuration is required even when it is not described by the
> firmware.
>
> Signed-off-by: Nipun Gupta <[email protected]>
> ---
> Changes in v2:
> - This is a new change suggested by Robin and Christoph
> and is added to the series.
>
> Changes in v3:
> - Rebase and changes corresponding to the changes in patch 1/2
>
> drivers/amba/bus.c | 1 -
> drivers/base/platform.c | 3 +--
> drivers/bcma/main.c | 2 +-
> drivers/dma/qcom/hidma_mgmt.c | 2 +-
> drivers/gpu/host1x/bus.c | 5 ++---
> drivers/of/device.c | 6 ++++--
> drivers/of/of_reserved_mem.c | 2 +-
> drivers/pci/pci-driver.c | 3 +--
> include/linux/device.h | 4 ----
> include/linux/of_device.h | 8 ++++++--
> 10 files changed, 17 insertions(+), 19 deletions(-)

Reviewed-by: Rob Herring <[email protected]>

2018-04-23 12:55:18

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] dma-mapping: move dma configuration to bus infrastructure

Can you resend your changes against Linux 4.17-rc2? There are a lot
of conflicts as-is.