blob: ad7d9963de34f1f970c000fd82639b49fffbe11e [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Christoph Hellwig68c60832018-12-06 07:06:04 -08002#include <linux/dma-direct.h>
Christoph Hellwig4fac8072017-12-24 13:57:08 +01003#include <linux/swiotlb.h>
Paul Gortmakerbd3ff192011-07-31 18:33:21 -04004#include <linux/export.h>
FUJITA Tomonori4d9b9772009-01-05 23:36:12 +09005
FUJITA Tomonorifb446722009-01-27 23:43:59 +09006/* Set this to 1 if there is a HW IOMMU in the system */
7int iommu_detected __read_mostly;
8
Bart Van Assche52997092017-01-20 13:04:01 -08009const struct dma_map_ops *dma_ops;
FUJITA Tomonori4d9b9772009-01-05 23:36:12 +090010EXPORT_SYMBOL(dma_ops);
FUJITA Tomonoric190ab02009-01-05 23:36:16 +090011
Bart Van Assche52997092017-01-20 13:04:01 -080012const struct dma_map_ops *dma_get_ops(struct device *dev)
FUJITA Tomonoric190ab02009-01-05 23:36:16 +090013{
14 return dma_ops;
15}
16EXPORT_SYMBOL(dma_get_ops);
Christoph Hellwig4fac8072017-12-24 13:57:08 +010017
18#ifdef CONFIG_SWIOTLB
Christoph Hellwig68c60832018-12-06 07:06:04 -080019void *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
25void 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
31long 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 Hellwig4fac8072017-12-24 13:57:08 +010037void __init swiotlb_dma_init(void)
38{
Christoph Hellwig4fac8072017-12-24 13:57:08 +010039 swiotlb_init(1);
40}
41#endif