xref: /linux/arch/hexagon/kernel/dma.c (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * DMA implementation for Hexagon
4  *
5  * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
6  */
7 
8 #include <linux/dma-map-ops.h>
9 #include <linux/memblock.h>
10 #include <asm/page.h>
11 
12 void arch_sync_dma_for_device(phys_addr_t paddr, size_t size,
13 		enum dma_data_direction dir)
14 {
15 	void *addr = phys_to_virt(paddr);
16 
17 	switch (dir) {
18 	case DMA_TO_DEVICE:
19 		hexagon_clean_dcache_range((unsigned long) addr,
20 		(unsigned long) addr + size);
21 		break;
22 	case DMA_FROM_DEVICE:
23 		hexagon_inv_dcache_range((unsigned long) addr,
24 		(unsigned long) addr + size);
25 		break;
26 	case DMA_BIDIRECTIONAL:
27 		flush_dcache_range((unsigned long) addr,
28 		(unsigned long) addr + size);
29 		break;
30 	default:
31 		BUG();
32 	}
33 }
34 
35 /*
36  * Our max_low_pfn should have been backed off by 16MB in mm/init.c to create
37  * DMA coherent space.  Use that for the pool.
38  */
39 static int __init hexagon_dma_init(void)
40 {
41 	return dma_init_global_coherent(PFN_PHYS(max_low_pfn),
42 					hexagon_coherent_pool_size);
43 }
44 core_initcall(hexagon_dma_init);
45