summaryrefslogtreecommitdiff
path: root/arch/riscv/mm/dma-noncoherent.c
blob: 86d23046b95818dc116574e35fafab4e66ec8049 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// SPDX-License-Identifier: GPL-2.0-only
/*
 * RISC-V specific functions to support DMA for non-coherent devices
 *
 * Copyright (c) 2021 Western Digital Corporation or its affiliates.
 */

#include <linux/dma-map-ops.h>

#include <soc/sifive/sifive_l2_cache.h>

void arch_sync_dma_for_device(phys_addr_t paddr, size_t size, enum dma_data_direction dir)
{
	if (sifive_l2_handle_noncoherent())
		sifive_l2_flush_range(paddr, size);
}

void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size, enum dma_data_direction dir)
{
	if (sifive_l2_handle_noncoherent())
		sifive_l2_flush_range(paddr, size);
}

void *arch_dma_set_uncached(void *addr, size_t size)
{
	if (sifive_l2_handle_noncoherent())
		return sifive_l2_set_uncached(addr, size);

	return addr;
}

void arch_dma_clear_uncached(void *addr, size_t size)
{
	if (sifive_l2_handle_noncoherent())
		sifive_l2_clear_uncached(addr, size);
}

void arch_dma_prep_coherent(struct page *page, size_t size)
{
	void *flush_addr = page_address(page);

	memset(flush_addr, 0, size);
	if (sifive_l2_handle_noncoherent())
		sifive_l2_flush_range(__pa(flush_addr), size);
}

void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
		const struct iommu_ops *iommu, bool coherent)
{
	/* If a specific device is dma-coherent, set it here */
	dev->dma_coherent = coherent;
}