Skip to content

Commit 09515ef

Browse files
Sricharan Rjoergroedel
authored andcommitted
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 <m.szyprowski@samsung.com> Tested-by: Hanjun Guo <hanjun.guo@linaro.org> Reviewed-by: Robin Murphy <robin.murphy@arm.com> Acked-by: Rob Herring <robh@kernel.org> Acked-by: Bjorn Helgaas <bhelgaas@google.com> (drivers/pci part) Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Sricharan R <sricharan@codeaurora.org> Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent efc8551 commit 09515ef

6 files changed

Lines changed: 62 additions & 37 deletions

File tree

‎drivers/acpi/glue.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
176176
struct list_head *physnode_list;
177177
unsigned int node_id;
178178
int retval = -EINVAL;
179-
enum dev_dma_attr attr;
180179

181180
if (has_acpi_companion(dev)) {
182181
if (acpi_dev) {
@@ -233,10 +232,6 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
233232
if (!has_acpi_companion(dev))
234233
ACPI_COMPANION_SET(dev, acpi_dev);
235234

236-
attr = acpi_get_dma_attr(acpi_dev);
237-
if (attr != DEV_DMA_NOT_SUPPORTED)
238-
acpi_dma_configure(dev, attr);
239-
240235
acpi_physnode_link_name(physical_node_name, node_id);
241236
retval = sysfs_create_link(&acpi_dev->dev.kobj, &dev->kobj,
242237
physical_node_name);

‎drivers/base/dd.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <linux/device.h>
2121
#include <linux/delay.h>
22+
#include <linux/dma-mapping.h>
2223
#include <linux/module.h>
2324
#include <linux/kthread.h>
2425
#include <linux/wait.h>
@@ -356,6 +357,10 @@ static int really_probe(struct device *dev, struct device_driver *drv)
356357
if (ret)
357358
goto pinctrl_bind_failed;
358359

360+
ret = dma_configure(dev);
361+
if (ret)
362+
goto dma_failed;
363+
359364
if (driver_sysfs_add(dev)) {
360365
printk(KERN_ERR "%s: driver_sysfs_add(%s) failed\n",
361366
__func__, dev_name(dev));
@@ -417,6 +422,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)
417422
goto done;
418423

419424
probe_failed:
425+
dma_deconfigure(dev);
426+
dma_failed:
420427
if (dev->bus)
421428
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
422429
BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
@@ -826,6 +833,8 @@ static void __device_release_driver(struct device *dev, struct device *parent)
826833
drv->remove(dev);
827834

828835
device_links_driver_cleanup(dev);
836+
dma_deconfigure(dev);
837+
829838
devres_release_all(dev);
830839
dev->driver = NULL;
831840
dev_set_drvdata(dev, NULL);

‎drivers/base/dma-mapping.c‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
* This file is released under the GPLv2.
88
*/
99

10+
#include <linux/acpi.h>
1011
#include <linux/dma-mapping.h>
1112
#include <linux/export.h>
1213
#include <linux/gfp.h>
14+
#include <linux/of_device.h>
1315
#include <linux/slab.h>
1416
#include <linux/vmalloc.h>
1517

@@ -341,3 +343,41 @@ void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags)
341343
vunmap(cpu_addr);
342344
}
343345
#endif
346+
347+
/*
348+
* Common configuration to enable DMA API use for a device
349+
*/
350+
#include <linux/pci.h>
351+
352+
int dma_configure(struct device *dev)
353+
{
354+
struct device *bridge = NULL, *dma_dev = dev;
355+
enum dev_dma_attr attr;
356+
357+
if (dev_is_pci(dev)) {
358+
bridge = pci_get_host_bridge_device(to_pci_dev(dev));
359+
dma_dev = bridge;
360+
if (IS_ENABLED(CONFIG_OF) && dma_dev->parent &&
361+
dma_dev->parent->of_node)
362+
dma_dev = dma_dev->parent;
363+
}
364+
365+
if (dma_dev->of_node) {
366+
of_dma_configure(dev, dma_dev->of_node);
367+
} else if (has_acpi_companion(dma_dev)) {
368+
attr = acpi_get_dma_attr(to_acpi_device_node(dma_dev->fwnode));
369+
if (attr != DEV_DMA_NOT_SUPPORTED)
370+
acpi_dma_configure(dev, attr);
371+
}
372+
373+
if (bridge)
374+
pci_put_host_bridge_device(bridge);
375+
376+
return 0;
377+
}
378+
379+
void dma_deconfigure(struct device *dev)
380+
{
381+
of_dma_deconfigure(dev);
382+
acpi_dma_deconfigure(dev);
383+
}

‎drivers/of/platform.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/slab.h>
2323
#include <linux/of_address.h>
2424
#include <linux/of_device.h>
25+
#include <linux/of_iommu.h>
2526
#include <linux/of_irq.h>
2627
#include <linux/of_platform.h>
2728
#include <linux/platform_device.h>
@@ -186,11 +187,9 @@ static struct platform_device *of_platform_device_create_pdata(
186187

187188
dev->dev.bus = &platform_bus_type;
188189
dev->dev.platform_data = platform_data;
189-
of_dma_configure(&dev->dev, dev->dev.of_node);
190190
of_msi_configure(&dev->dev, dev->dev.of_node);
191191

192192
if (of_device_add(dev) != 0) {
193-
of_dma_deconfigure(&dev->dev);
194193
platform_device_put(dev);
195194
goto err_clear_flag;
196195
}
@@ -248,7 +247,6 @@ static struct amba_device *of_amba_device_create(struct device_node *node,
248247
dev_set_name(&dev->dev, "%s", bus_id);
249248
else
250249
of_device_make_bus_id(&dev->dev);
251-
of_dma_configure(&dev->dev, dev->dev.of_node);
252250

253251
/* Allow the HW Peripheral ID to be overridden */
254252
prop = of_get_property(node, "arm,primecell-periphid", NULL);
@@ -542,7 +540,6 @@ static int of_platform_device_destroy(struct device *dev, void *data)
542540
amba_device_unregister(to_amba_device(dev));
543541
#endif
544542

545-
of_dma_deconfigure(dev);
546543
of_node_clear_flag(dev->of_node, OF_POPULATED);
547544
of_node_clear_flag(dev->of_node, OF_POPULATED_BUS);
548545
return 0;

‎drivers/pci/probe.c‎

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,33 +1893,6 @@ static void pci_set_msi_domain(struct pci_dev *dev)
18931893
dev_set_msi_domain(&dev->dev, d);
18941894
}
18951895

1896-
/**
1897-
* pci_dma_configure - Setup DMA configuration
1898-
* @dev: ptr to pci_dev struct of the PCI device
1899-
*
1900-
* Function to update PCI devices's DMA configuration using the same
1901-
* info from the OF node or ACPI node of host bridge's parent (if any).
1902-
*/
1903-
static void pci_dma_configure(struct pci_dev *dev)
1904-
{
1905-
struct device *bridge = pci_get_host_bridge_device(dev);
1906-
1907-
if (IS_ENABLED(CONFIG_OF) &&
1908-
bridge->parent && bridge->parent->of_node) {
1909-
of_dma_configure(&dev->dev, bridge->parent->of_node);
1910-
} else if (has_acpi_companion(bridge)) {
1911-
struct acpi_device *adev = to_acpi_device_node(bridge->fwnode);
1912-
enum dev_dma_attr attr = acpi_get_dma_attr(adev);
1913-
1914-
if (attr == DEV_DMA_NOT_SUPPORTED)
1915-
dev_warn(&dev->dev, "DMA not supported.\n");
1916-
else
1917-
acpi_dma_configure(&dev->dev, attr);
1918-
}
1919-
1920-
pci_put_host_bridge_device(bridge);
1921-
}
1922-
19231896
void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
19241897
{
19251898
int ret;
@@ -1933,7 +1906,6 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
19331906
dev->dev.dma_mask = &dev->dma_mask;
19341907
dev->dev.dma_parms = &dev->dma_parms;
19351908
dev->dev.coherent_dma_mask = 0xffffffffull;
1936-
pci_dma_configure(dev);
19371909

19381910
pci_set_dma_max_seg_size(dev, 65536);
19391911
pci_set_dma_seg_boundary(dev, 0xffffffff);

‎include/linux/dma-mapping.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,18 @@ dma_mark_declared_memory_occupied(struct device *dev,
728728
}
729729
#endif /* CONFIG_HAVE_GENERIC_DMA_COHERENT */
730730

731+
#ifdef CONFIG_HAS_DMA
732+
int dma_configure(struct device *dev);
733+
void dma_deconfigure(struct device *dev);
734+
#else
735+
static inline int dma_configure(struct device *dev)
736+
{
737+
return 0;
738+
}
739+
740+
static inline void dma_deconfigure(struct device *dev) {}
741+
#endif
742+
731743
/*
732744
* Managed DMA API
733745
*/

0 commit comments

Comments
 (0)