2 * DMA implementation for Hexagon
4 * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 and
8 * only version 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include <linux/dma-noncoherent.h>
22 #include <linux/memblock.h>
23 #include <linux/genalloc.h>
24 #include <linux/module.h>
27 static struct gen_pool
*coherent_pool
;
30 /* Allocates from a pool of uncached memory that was reserved at boot time */
32 void *arch_dma_alloc(struct device
*dev
, size_t size
, dma_addr_t
*dma_addr
,
33 gfp_t flag
, unsigned long attrs
)
38 * Our max_low_pfn should have been backed off by 16MB in
39 * mm/init.c to create DMA coherent space. Use that as the VA
43 if (coherent_pool
== NULL
) {
44 coherent_pool
= gen_pool_create(PAGE_SHIFT
, -1);
46 if (coherent_pool
== NULL
)
47 panic("Can't create %s() memory pool!", __func__
);
49 gen_pool_add(coherent_pool
,
50 (unsigned long)pfn_to_virt(max_low_pfn
),
51 hexagon_coherent_pool_size
, -1);
54 ret
= (void *) gen_pool_alloc(coherent_pool
, size
);
58 *dma_addr
= (dma_addr_t
) virt_to_phys(ret
);
65 void arch_dma_free(struct device
*dev
, size_t size
, void *vaddr
,
66 dma_addr_t dma_addr
, unsigned long attrs
)
68 gen_pool_free(coherent_pool
, (unsigned long) vaddr
, size
);
71 void arch_sync_dma_for_device(struct device
*dev
, phys_addr_t paddr
,
72 size_t size
, enum dma_data_direction dir
)
74 void *addr
= phys_to_virt(paddr
);
78 hexagon_clean_dcache_range((unsigned long) addr
,
79 (unsigned long) addr
+ size
);
82 hexagon_inv_dcache_range((unsigned long) addr
,
83 (unsigned long) addr
+ size
);
85 case DMA_BIDIRECTIONAL
:
86 flush_dcache_range((unsigned long) addr
,
87 (unsigned long) addr
+ size
);