mali_760_driver : rk_ext on arm_release_ver, from r5p0-02dev0.
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / mali_kbase_mem_lowlevel.c
1 /*
2  *
3  * (C) COPYRIGHT ARM Limited. All rights reserved.
4  *
5  * This program is free software and is provided to you under the terms of the
6  * GNU General Public License version 2 as published by the Free Software
7  * Foundation, and any use by you of this program is subject to the terms
8  * of such GNU licence.
9  *
10  * A copy of the licence is included with the program, and can also be obtained
11  * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12  * Boston, MA  02110-1301, USA.
13  *
14  */
15
16
17
18
19
20 #include <mali_kbase.h>
21
22 #include <linux/io.h>
23 #include <linux/mm.h>
24 #include <linux/highmem.h>
25 #include <linux/dma-mapping.h>
26 #include <linux/mutex.h>
27 #include <asm/cacheflush.h>
28
29 void kbase_sync_to_memory(phys_addr_t paddr, void *vaddr, size_t sz)
30 {
31 #ifdef CONFIG_ARM
32         __cpuc_flush_dcache_area(vaddr, sz);
33         outer_flush_range(paddr, paddr + sz);
34 #elif defined(CONFIG_ARM64)
35         /* TODO (MID64-46): There's no other suitable cache flush function for ARM64 */
36         flush_cache_all();
37 #elif defined(CONFIG_X86)
38         struct scatterlist scl = { 0, };
39         sg_set_page(&scl, pfn_to_page(PFN_DOWN(paddr)), sz, paddr & (PAGE_SIZE - 1));
40         dma_sync_sg_for_cpu(NULL, &scl, 1, DMA_TO_DEVICE);
41         mb();                   /* for outer_sync (if needed) */
42 #else
43 #error Implement cache maintenance for your architecture here
44 #endif
45 }
46
47 void kbase_sync_to_cpu(phys_addr_t paddr, void *vaddr, size_t sz)
48 {
49 #ifdef CONFIG_ARM
50         __cpuc_flush_dcache_area(vaddr, sz);
51         outer_flush_range(paddr, paddr + sz);
52 #elif defined(CONFIG_ARM64)
53         /* TODO (MID64-46): There's no other suitable cache flush function for ARM64 */
54         flush_cache_all();
55 #elif defined(CONFIG_X86)
56         struct scatterlist scl = { 0, };
57         sg_set_page(&scl, pfn_to_page(PFN_DOWN(paddr)), sz, paddr & (PAGE_SIZE - 1));
58         dma_sync_sg_for_cpu(NULL, &scl, 1, DMA_FROM_DEVICE);
59 #else
60 #error Implement cache maintenance for your architecture here
61 #endif
62 }