1 // SPDX-License-Identifier: GPL-2.0-only
3 * DMA implementation for Hexagon
5 * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
8 #include <linux/dma-noncoherent.h>
9 #include <linux/memblock.h>
10 #include <linux/genalloc.h>
11 #include <linux/module.h>
14 static struct gen_pool
*coherent_pool
;
17 /* Allocates from a pool of uncached memory that was reserved at boot time */
19 void *arch_dma_alloc(struct device
*dev
, size_t size
, dma_addr_t
*dma_addr
,
20 gfp_t flag
, unsigned long attrs
)
25 * Our max_low_pfn should have been backed off by 16MB in
26 * mm/init.c to create DMA coherent space. Use that as the VA
30 if (coherent_pool
== NULL
) {
31 coherent_pool
= gen_pool_create(PAGE_SHIFT
, -1);
33 if (coherent_pool
== NULL
)
34 panic("Can't create %s() memory pool!", __func__
);
36 gen_pool_add(coherent_pool
,
37 (unsigned long)pfn_to_virt(max_low_pfn
),
38 hexagon_coherent_pool_size
, -1);
41 ret
= (void *) gen_pool_alloc(coherent_pool
, size
);
45 *dma_addr
= (dma_addr_t
) virt_to_phys(ret
);
52 void arch_dma_free(struct device
*dev
, size_t size
, void *vaddr
,
53 dma_addr_t dma_addr
, unsigned long attrs
)
55 gen_pool_free(coherent_pool
, (unsigned long) vaddr
, size
);
58 void arch_sync_dma_for_device(phys_addr_t paddr
, size_t size
,
59 enum dma_data_direction dir
)
61 void *addr
= phys_to_virt(paddr
);
65 hexagon_clean_dcache_range((unsigned long) addr
,
66 (unsigned long) addr
+ size
);
69 hexagon_inv_dcache_range((unsigned long) addr
,
70 (unsigned long) addr
+ size
);
72 case DMA_BIDIRECTIONAL
:
73 flush_dcache_range((unsigned long) addr
,
74 (unsigned long) addr
+ size
);