1 // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
2 /*
3 *
4 * (C) COPYRIGHT 2020-2022 ARM Limited. All rights reserved.
5 *
6 * This program is free software and is provided to you under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation, and any use by you of this program is subject to the terms
9 * of such GNU license.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you can access it online at
18 * http://www.gnu.org/licenses/gpl-2.0.html.
19 *
20 */
21
22 #include <linux/atomic.h>
23 #include <linux/list.h>
24 #include <mali_kbase_fence.h>
25 #include <mali_kbase.h>
26
27 static const char *
28 #if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
kbase_fence_get_driver_name(struct fence * fence)29 kbase_fence_get_driver_name(struct fence *fence)
30 #else
31 kbase_fence_get_driver_name(struct dma_fence *fence)
32 #endif
33 {
34 return kbase_drv_name;
35 }
36
37 static const char *
38 #if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
kbase_fence_get_timeline_name(struct fence * fence)39 kbase_fence_get_timeline_name(struct fence *fence)
40 #else
41 kbase_fence_get_timeline_name(struct dma_fence *fence)
42 #endif
43 {
44 #if MALI_USE_CSF
45 struct kbase_kcpu_dma_fence *kcpu_fence = (struct kbase_kcpu_dma_fence *)fence;
46
47 return kcpu_fence->metadata->timeline_name;
48 #else
49 return kbase_timeline_name;
50 #endif /* MALI_USE_CSF */
51 }
52
53 static bool
54 #if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
kbase_fence_enable_signaling(struct fence * fence)55 kbase_fence_enable_signaling(struct fence *fence)
56 #else
57 kbase_fence_enable_signaling(struct dma_fence *fence)
58 #endif
59 {
60 return true;
61 }
62
63 static void
64 #if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
kbase_fence_fence_value_str(struct fence * fence,char * str,int size)65 kbase_fence_fence_value_str(struct fence *fence, char *str, int size)
66 #else
67 kbase_fence_fence_value_str(struct dma_fence *fence, char *str, int size)
68 #endif
69 {
70 #if (KERNEL_VERSION(5, 1, 0) > LINUX_VERSION_CODE)
71 const char *format = "%u";
72 #else
73 const char *format = "%llu";
74 #endif
75 if (unlikely(!scnprintf(str, size, format, fence->seqno)))
76 pr_err("Fail to encode fence seqno to string");
77 }
78
79 #if MALI_USE_CSF
80 static void
81 #if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
kbase_fence_release(struct fence * fence)82 kbase_fence_release(struct fence *fence)
83 #else
84 kbase_fence_release(struct dma_fence *fence)
85 #endif
86 {
87 struct kbase_kcpu_dma_fence *kcpu_fence = (struct kbase_kcpu_dma_fence *)fence;
88
89 kbase_kcpu_dma_fence_meta_put(kcpu_fence->metadata);
90 kfree(kcpu_fence);
91 }
92 #endif
93
94 #if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
95 extern const struct fence_ops kbase_fence_ops; /* silence checker warning */
96 const struct fence_ops kbase_fence_ops = { .wait = fence_default_wait,
97 #else
98 extern const struct dma_fence_ops kbase_fence_ops; /* silence checker warning */
99 const struct dma_fence_ops kbase_fence_ops = { .wait = dma_fence_default_wait,
100 #endif
101 .get_driver_name = kbase_fence_get_driver_name,
102 .get_timeline_name = kbase_fence_get_timeline_name,
103 .enable_signaling = kbase_fence_enable_signaling,
104 #if MALI_USE_CSF
105 .fence_value_str = kbase_fence_fence_value_str,
106 .release = kbase_fence_release
107 #else
108 .fence_value_str = kbase_fence_fence_value_str
109 #endif
110 };
111 KBASE_EXPORT_TEST_API(kbase_fence_ops);
112