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