diff options
Diffstat (limited to 'drivers/base/dma-mapping.c')
-rw-r--r-- | drivers/base/dma-mapping.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c index 51b7061ff7c0..f3deb6af42ad 100644 --- a/drivers/base/dma-mapping.c +++ b/drivers/base/dma-mapping.c | |||
@@ -7,9 +7,11 @@ | |||
7 | * This file is released under the GPLv2. | 7 | * This file is released under the GPLv2. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/acpi.h> | ||
10 | #include <linux/dma-mapping.h> | 11 | #include <linux/dma-mapping.h> |
11 | #include <linux/export.h> | 12 | #include <linux/export.h> |
12 | #include <linux/gfp.h> | 13 | #include <linux/gfp.h> |
14 | #include <linux/of_device.h> | ||
13 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
14 | #include <linux/vmalloc.h> | 16 | #include <linux/vmalloc.h> |
15 | 17 | ||
@@ -340,3 +342,42 @@ void dma_common_free_remap(void *cpu_addr, size_t size, unsigned long vm_flags) | |||
340 | vunmap(cpu_addr); | 342 | vunmap(cpu_addr); |
341 | } | 343 | } |
342 | #endif | 344 | #endif |
345 | |||
346 | /* | ||
347 | * Common configuration to enable DMA API use for a device | ||
348 | */ | ||
349 | #include <linux/pci.h> | ||
350 | |||
351 | int dma_configure(struct device *dev) | ||
352 | { | ||
353 | struct device *bridge = NULL, *dma_dev = dev; | ||
354 | enum dev_dma_attr attr; | ||
355 | int ret = 0; | ||
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 | ret = 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 | ret = acpi_dma_configure(dev, attr); | ||
371 | } | ||
372 | |||
373 | if (bridge) | ||
374 | pci_put_host_bridge_device(bridge); | ||
375 | |||
376 | return ret; | ||
377 | } | ||
378 | |||
379 | void dma_deconfigure(struct device *dev) | ||
380 | { | ||
381 | of_dma_deconfigure(dev); | ||
382 | acpi_dma_deconfigure(dev); | ||
383 | } | ||