Merge tag 'lsk-v4.4-16.06-android'
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / mali_kbase_cache_policy.c
1 /*
2  *
3  * (C) COPYRIGHT 2012-2016 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 /*
21  * Cache Policy API.
22  */
23
24 #include "mali_kbase_cache_policy.h"
25
26 /*
27  * The output flags should be a combination of the following values:
28  * KBASE_REG_CPU_CACHED: CPU cache should be enabled.
29  */
30 u32 kbase_cache_enabled(u32 flags, u32 nr_pages)
31 {
32         u32 cache_flags = 0;
33
34         CSTD_UNUSED(nr_pages);
35
36         if (flags & BASE_MEM_CACHED_CPU)
37                 cache_flags |= KBASE_REG_CPU_CACHED;
38
39         return cache_flags;
40 }
41
42
43 void kbase_sync_single_for_device(struct kbase_device *kbdev, dma_addr_t handle,
44                 size_t size, enum dma_data_direction dir)
45 {
46 /* Check if kernel is using coherency with GPU */
47 #ifdef CONFIG_MALI_COH_KERN
48         if (kbdev->system_coherency == COHERENCY_ACE)
49                 return;
50 #endif /* CONFIG_MALI_COH_KERN */
51         dma_sync_single_for_device(kbdev->dev, handle, size, dir);
52 }
53
54
55 void kbase_sync_single_for_cpu(struct kbase_device *kbdev, dma_addr_t handle,
56                 size_t size, enum dma_data_direction dir)
57 {
58 /* Check if kernel is using coherency with GPU */
59 #ifdef CONFIG_MALI_COH_KERN
60         if (kbdev->system_coherency == COHERENCY_ACE)
61                 return;
62 #endif /* CONFIG_MALI_COH_KERN */
63         dma_sync_single_for_cpu(kbdev->dev, handle, size, dir);
64 }