Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Christoph Hellwig | 68c6083 | 2018-12-06 07:06:04 -0800 | [diff] [blame] | 2 | #include <linux/dma-direct.h> |
Christoph Hellwig | 4fac807 | 2017-12-24 13:57:08 +0100 | [diff] [blame] | 3 | #include <linux/swiotlb.h> |
Paul Gortmaker | bd3ff19 | 2011-07-31 18:33:21 -0400 | [diff] [blame] | 4 | #include <linux/export.h> |
FUJITA Tomonori | 4d9b977 | 2009-01-05 23:36:12 +0900 | [diff] [blame] | 5 | |
FUJITA Tomonori | fb44672 | 2009-01-27 23:43:59 +0900 | [diff] [blame] | 6 | /* Set this to 1 if there is a HW IOMMU in the system */ |
| 7 | int iommu_detected __read_mostly; |
| 8 | |
Bart Van Assche | 5299709 | 2017-01-20 13:04:01 -0800 | [diff] [blame] | 9 | const struct dma_map_ops *dma_ops; |
FUJITA Tomonori | 4d9b977 | 2009-01-05 23:36:12 +0900 | [diff] [blame] | 10 | EXPORT_SYMBOL(dma_ops); |
FUJITA Tomonori | c190ab0 | 2009-01-05 23:36:16 +0900 | [diff] [blame] | 11 | |
Bart Van Assche | 5299709 | 2017-01-20 13:04:01 -0800 | [diff] [blame] | 12 | const struct dma_map_ops *dma_get_ops(struct device *dev) |
FUJITA Tomonori | c190ab0 | 2009-01-05 23:36:16 +0900 | [diff] [blame] | 13 | { |
| 14 | return dma_ops; |
| 15 | } |
| 16 | EXPORT_SYMBOL(dma_get_ops); |
Christoph Hellwig | 4fac807 | 2017-12-24 13:57:08 +0100 | [diff] [blame] | 17 | |
| 18 | #ifdef CONFIG_SWIOTLB |
Christoph Hellwig | 68c6083 | 2018-12-06 07:06:04 -0800 | [diff] [blame] | 19 | void *arch_dma_alloc(struct device *dev, size_t size, |
| 20 | dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) |
| 21 | { |
| 22 | return dma_direct_alloc_pages(dev, size, dma_handle, gfp, attrs); |
| 23 | } |
| 24 | |
| 25 | void arch_dma_free(struct device *dev, size_t size, void *cpu_addr, |
| 26 | dma_addr_t dma_addr, unsigned long attrs) |
| 27 | { |
| 28 | dma_direct_free_pages(dev, size, cpu_addr, dma_addr, attrs); |
| 29 | } |
| 30 | |
| 31 | long arch_dma_coherent_to_pfn(struct device *dev, void *cpu_addr, |
| 32 | dma_addr_t dma_addr) |
| 33 | { |
| 34 | return page_to_pfn(virt_to_page(cpu_addr)); |
| 35 | } |
| 36 | |
Christoph Hellwig | 4fac807 | 2017-12-24 13:57:08 +0100 | [diff] [blame] | 37 | void __init swiotlb_dma_init(void) |
| 38 | { |
Christoph Hellwig | 4fac807 | 2017-12-24 13:57:08 +0100 | [diff] [blame] | 39 | swiotlb_init(1); |
| 40 | } |
| 41 | #endif |