Skip to content

Commit c1dec34

Browse files
author
Christoph Hellwig
committed
hexagon: use the generic global coherent pool
Switch hexagon to use the generic code for dma_alloc_coherent from a global pre-filled pool. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Brian Cain <bcain@codeaurora.org>
1 parent 22f9feb commit c1dec34

File tree

2 files changed

+12
-46
lines changed

2 files changed

+12
-46
lines changed

arch/hexagon/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ config HEXAGON
77
select ARCH_32BIT_OFF_T
88
select ARCH_HAS_SYNC_DMA_FOR_DEVICE
99
select ARCH_NO_PREEMPT
10+
select DMA_GLOBAL_POOL
1011
# Other pending projects/to-do items.
1112
# select HAVE_REGS_AND_STACK_ACCESS_API
1213
# select HAVE_HW_BREAKPOINT if PERF_EVENTS

arch/hexagon/kernel/dma.c

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,54 +7,8 @@
77

88
#include <linux/dma-map-ops.h>
99
#include <linux/memblock.h>
10-
#include <linux/genalloc.h>
11-
#include <linux/module.h>
1210
#include <asm/page.h>
1311

14-
static struct gen_pool *coherent_pool;
15-
16-
17-
/* Allocates from a pool of uncached memory that was reserved at boot time */
18-
19-
void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_addr,
20-
gfp_t flag, unsigned long attrs)
21-
{
22-
void *ret;
23-
24-
/*
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
27-
* for the pool.
28-
*/
29-
30-
if (coherent_pool == NULL) {
31-
coherent_pool = gen_pool_create(PAGE_SHIFT, -1);
32-
33-
if (coherent_pool == NULL)
34-
panic("Can't create %s() memory pool!", __func__);
35-
else
36-
gen_pool_add(coherent_pool,
37-
(unsigned long)pfn_to_virt(max_low_pfn),
38-
hexagon_coherent_pool_size, -1);
39-
}
40-
41-
ret = (void *) gen_pool_alloc(coherent_pool, size);
42-
43-
if (ret) {
44-
memset(ret, 0, size);
45-
*dma_addr = (dma_addr_t) virt_to_phys(ret);
46-
} else
47-
*dma_addr = ~0;
48-
49-
return ret;
50-
}
51-
52-
void arch_dma_free(struct device *dev, size_t size, void *vaddr,
53-
dma_addr_t dma_addr, unsigned long attrs)
54-
{
55-
gen_pool_free(coherent_pool, (unsigned long) vaddr, size);
56-
}
57-
5812
void arch_sync_dma_for_device(phys_addr_t paddr, size_t size,
5913
enum dma_data_direction dir)
6014
{
@@ -77,3 +31,14 @@ void arch_sync_dma_for_device(phys_addr_t paddr, size_t size,
7731
BUG();
7832
}
7933
}
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);

0 commit comments

Comments
 (0)