2019-06-02 23:44:50 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2012-03-05 04:49:30 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 ARM Ltd.
|
|
|
|
* Author: Catalin Marinas <catalin.marinas@arm.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/gfp.h>
|
2016-08-15 00:45:46 -06:00
|
|
|
#include <linux/cache.h>
|
2018-10-08 01:12:01 -06:00
|
|
|
#include <linux/dma-noncoherent.h>
|
2019-05-20 01:29:29 -06:00
|
|
|
#include <linux/dma-iommu.h>
|
2019-07-24 06:07:28 -06:00
|
|
|
#include <xen/xen.h>
|
2019-07-24 06:09:39 -06:00
|
|
|
#include <xen/swiotlb-xen.h>
|
2012-03-05 04:49:30 -07:00
|
|
|
|
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
|
2018-10-08 01:12:01 -06:00
|
|
|
void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr,
|
|
|
|
size_t size, enum dma_data_direction dir)
|
2013-05-21 10:35:19 -06:00
|
|
|
{
|
2018-10-08 01:12:01 -06:00
|
|
|
__dma_map_area(phys_to_virt(paddr), size, dir);
|
2013-05-21 10:35:19 -06:00
|
|
|
}
|
|
|
|
|
2018-10-08 01:12:01 -06:00
|
|
|
void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr,
|
|
|
|
size_t size, enum dma_data_direction dir)
|
2013-05-21 10:35:19 -06:00
|
|
|
{
|
2018-10-08 01:12:01 -06:00
|
|
|
__dma_unmap_area(phys_to_virt(paddr), size, dir);
|
2013-05-21 10:35:19 -06:00
|
|
|
}
|
|
|
|
|
2018-11-04 12:29:28 -07:00
|
|
|
void arch_dma_prep_coherent(struct page *page, size_t size)
|
|
|
|
{
|
|
|
|
__dma_flush_area(page_address(page), size);
|
|
|
|
}
|
|
|
|
|
2015-10-01 13:13:59 -06:00
|
|
|
#ifdef CONFIG_IOMMU_DMA
|
2015-10-01 13:14:00 -06:00
|
|
|
void arch_teardown_dma_ops(struct device *dev)
|
|
|
|
{
|
2017-01-20 14:04:02 -07:00
|
|
|
dev->dma_ops = NULL;
|
2015-10-01 13:14:00 -06:00
|
|
|
}
|
2019-05-20 01:29:29 -06:00
|
|
|
#endif
|
2015-10-01 13:13:59 -06:00
|
|
|
|
2015-10-01 13:14:00 -06:00
|
|
|
void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
|
2016-04-07 11:42:05 -06:00
|
|
|
const struct iommu_ops *iommu, bool coherent)
|
2015-10-01 13:14:00 -06:00
|
|
|
{
|
2019-06-14 07:11:41 -06:00
|
|
|
int cls = cache_line_size_of_cpu();
|
|
|
|
|
|
|
|
WARN_TAINT(!coherent && cls > ARCH_DMA_MINALIGN,
|
|
|
|
TAINT_CPU_OUT_OF_SPEC,
|
|
|
|
"%s %s: ARCH_DMA_MINALIGN smaller than CTR_EL0.CWG (%d < %d)",
|
|
|
|
dev_driver_string(dev), dev_name(dev),
|
|
|
|
ARCH_DMA_MINALIGN, cls);
|
|
|
|
|
2018-10-08 01:12:01 -06:00
|
|
|
dev->dma_coherent = coherent;
|
2019-05-20 01:29:29 -06:00
|
|
|
if (iommu)
|
|
|
|
iommu_setup_dma_ops(dev, dma_base, size);
|
2017-04-13 15:04:21 -06:00
|
|
|
|
|
|
|
#ifdef CONFIG_XEN
|
2019-01-16 11:01:48 -07:00
|
|
|
if (xen_initial_domain())
|
2019-07-24 06:09:39 -06:00
|
|
|
dev->dma_ops = &xen_swiotlb_dma_ops;
|
2017-04-13 15:04:21 -06:00
|
|
|
#endif
|
2015-10-01 13:14:00 -06:00
|
|
|
}
|
2017-06-07 08:54:10 -06:00
|
|
|
EXPORT_SYMBOL(arch_setup_dma_ops);
|