Skip to content

Commit 07397df

Browse files
nipungupta87Christoph Hellwig
authored andcommitted
dma-mapping: move dma configuration to bus infrastructure
ACPI/OF support for configuration of DMA is a bus specific aspect, and thus should be configured by the bus. Introduces a 'dma_configure' bus method so that busses can control their DMA capabilities. Also update the PCI, Platform, ACPI and host1x buses to use the new method. Suggested-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Nipun Gupta <nipun.gupta@nxp.com> Acked-by: Bjorn Helgaas <bhelgaas@google.com> # PCI parts Acked-by: Thierry Reding <treding@nvidia.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> [hch: simplified host1x_dma_configure based on a comment from Thierry, rewrote changelog] Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 892a0be commit 07397df

7 files changed

Lines changed: 69 additions & 27 deletions

File tree

‎drivers/amba/bus.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/sizes.h>
2121
#include <linux/limits.h>
2222
#include <linux/clk/clk-conf.h>
23+
#include <linux/platform_device.h>
2324

2425
#include <asm/irq.h>
2526

@@ -193,12 +194,15 @@ static const struct dev_pm_ops amba_pm = {
193194
/*
194195
* Primecells are part of the Advanced Microcontroller Bus Architecture,
195196
* so we call the bus "amba".
197+
* DMA configuration for platform and AMBA bus is same. So here we reuse
198+
* platform's DMA config routine.
196199
*/
197200
struct bus_type amba_bustype = {
198201
.name = "amba",
199202
.dev_groups = amba_dev_groups,
200203
.match = amba_match,
201204
.uevent = amba_uevent,
205+
.dma_configure = platform_dma_configure,
202206
.pm = &amba_pm,
203207
.force_dma = true,
204208
};

‎drivers/base/dma-mapping.c‎

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -329,36 +329,13 @@ void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags)
329329
#endif
330330

331331
/*
332-
* Common configuration to enable DMA API use for a device
332+
* enables DMA API use for a device
333333
*/
334-
#include <linux/pci.h>
335-
336334
int dma_configure(struct device *dev)
337335
{
338-
struct device *bridge = NULL, *dma_dev = dev;
339-
enum dev_dma_attr attr;
340-
int ret = 0;
341-
342-
if (dev_is_pci(dev)) {
343-
bridge = pci_get_host_bridge_device(to_pci_dev(dev));
344-
dma_dev = bridge;
345-
if (IS_ENABLED(CONFIG_OF) && dma_dev->parent &&
346-
dma_dev->parent->of_node)
347-
dma_dev = dma_dev->parent;
348-
}
349-
350-
if (dma_dev->of_node) {
351-
ret = of_dma_configure(dev, dma_dev->of_node);
352-
} else if (has_acpi_companion(dma_dev)) {
353-
attr = acpi_get_dma_attr(to_acpi_device_node(dma_dev->fwnode));
354-
if (attr != DEV_DMA_NOT_SUPPORTED)
355-
ret = acpi_dma_configure(dev, attr);
356-
}
357-
358-
if (bridge)
359-
pci_put_host_bridge_device(bridge);
360-
361-
return ret;
336+
if (dev->bus->dma_configure)
337+
return dev->bus->dma_configure(dev);
338+
return 0;
362339
}
363340

364341
void dma_deconfigure(struct device *dev)

‎drivers/base/platform.c‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,22 @@ int platform_pm_restore(struct device *dev)
11301130

11311131
#endif /* CONFIG_HIBERNATE_CALLBACKS */
11321132

1133+
int platform_dma_configure(struct device *dev)
1134+
{
1135+
enum dev_dma_attr attr;
1136+
int ret = 0;
1137+
1138+
if (dev->of_node) {
1139+
ret = of_dma_configure(dev, dev->of_node);
1140+
} else if (has_acpi_companion(dev)) {
1141+
attr = acpi_get_dma_attr(to_acpi_device_node(dev->fwnode));
1142+
if (attr != DEV_DMA_NOT_SUPPORTED)
1143+
ret = acpi_dma_configure(dev, attr);
1144+
}
1145+
1146+
return ret;
1147+
}
1148+
11331149
static const struct dev_pm_ops platform_dev_pm_ops = {
11341150
.runtime_suspend = pm_generic_runtime_suspend,
11351151
.runtime_resume = pm_generic_runtime_resume,
@@ -1141,6 +1157,7 @@ struct bus_type platform_bus_type = {
11411157
.dev_groups = platform_dev_groups,
11421158
.match = platform_match,
11431159
.uevent = platform_uevent,
1160+
.dma_configure = platform_dma_configure,
11441161
.pm = &platform_dev_pm_ops,
11451162
.force_dma = true,
11461163
};

‎drivers/gpu/host1x/bus.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,11 @@ static int host1x_device_match(struct device *dev, struct device_driver *drv)
314314
return strcmp(dev_name(dev), drv->name) == 0;
315315
}
316316

317+
static int host1x_dma_configure(struct device *dev)
318+
{
319+
return of_dma_configure(dev, dev->of_node);
320+
}
321+
317322
static const struct dev_pm_ops host1x_device_pm_ops = {
318323
.suspend = pm_generic_suspend,
319324
.resume = pm_generic_resume,
@@ -326,6 +331,7 @@ static const struct dev_pm_ops host1x_device_pm_ops = {
326331
struct bus_type host1x_bus_type = {
327332
.name = "host1x",
328333
.match = host1x_device_match,
334+
.dma_configure = host1x_dma_configure,
329335
.pm = &host1x_device_pm_ops,
330336
.force_dma = true,
331337
};

‎drivers/pci/pci-driver.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <linux/pm_runtime.h>
1717
#include <linux/suspend.h>
1818
#include <linux/kexec.h>
19+
#include <linux/of_device.h>
20+
#include <linux/acpi.h>
1921
#include "pci.h"
2022
#include "pcie/portdrv.h"
2123

@@ -1577,6 +1579,35 @@ static int pci_bus_num_vf(struct device *dev)
15771579
return pci_num_vf(to_pci_dev(dev));
15781580
}
15791581

1582+
/**
1583+
* pci_dma_configure - Setup DMA configuration
1584+
* @dev: ptr to dev structure
1585+
*
1586+
* Function to update PCI devices's DMA configuration using the same
1587+
* info from the OF node or ACPI node of host bridge's parent (if any).
1588+
*/
1589+
static int pci_dma_configure(struct device *dev)
1590+
{
1591+
struct device *bridge;
1592+
int ret = 0;
1593+
1594+
bridge = pci_get_host_bridge_device(to_pci_dev(dev));
1595+
1596+
if (IS_ENABLED(CONFIG_OF) && bridge->parent &&
1597+
bridge->parent->of_node) {
1598+
ret = of_dma_configure(dev, bridge->parent->of_node);
1599+
} else if (has_acpi_companion(bridge)) {
1600+
struct acpi_device *adev = to_acpi_device_node(bridge->fwnode);
1601+
enum dev_dma_attr attr = acpi_get_dma_attr(adev);
1602+
1603+
if (attr != DEV_DMA_NOT_SUPPORTED)
1604+
ret = acpi_dma_configure(dev, attr);
1605+
}
1606+
1607+
pci_put_host_bridge_device(bridge);
1608+
return ret;
1609+
}
1610+
15801611
struct bus_type pci_bus_type = {
15811612
.name = "pci",
15821613
.match = pci_bus_match,
@@ -1589,6 +1620,7 @@ struct bus_type pci_bus_type = {
15891620
.drv_groups = pci_drv_groups,
15901621
.pm = PCI_PM_OPS_PTR,
15911622
.num_vf = pci_bus_num_vf,
1623+
.dma_configure = pci_dma_configure,
15921624
.force_dma = true,
15931625
};
15941626
EXPORT_SYMBOL(pci_bus_type);

‎include/linux/device.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *);
8888
* @resume: Called to bring a device on this bus out of sleep mode.
8989
* @num_vf: Called to find out how many virtual functions a device on this
9090
* bus supports.
91+
* @dma_configure: Called to setup DMA configuration on a device on
92+
this bus.
9193
* @pm: Power management operations of this bus, callback the specific
9294
* device driver's pm-ops.
9395
* @iommu_ops: IOMMU specific operations for this bus, used to attach IOMMU
@@ -130,6 +132,8 @@ struct bus_type {
130132

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

135+
int (*dma_configure)(struct device *dev);
136+
133137
const struct dev_pm_ops *pm;
134138

135139
const struct iommu_ops *iommu_ops;

‎include/linux/platform_device.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ extern int platform_pm_restore(struct device *dev);
356356
#define platform_pm_restore NULL
357357
#endif
358358

359+
extern int platform_dma_configure(struct device *dev);
360+
359361
#ifdef CONFIG_PM_SLEEP
360362
#define USE_PLATFORM_PM_SLEEP_OPS \
361363
.suspend = platform_pm_suspend, \

0 commit comments

Comments
 (0)