xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/mali400/mali/linux/mali_sync.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright (C) 2012-2015, 2017 ARM Limited. All rights reserved.
3  *
4  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
6  *
7  * A copy of the licence is included with the program, and can also be obtained from Free Software
8  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
9  */
10 
11 /**
12  * @file mali_sync.h
13  *
14  * Mali interface for Linux sync objects.
15  */
16 
17 #ifndef _MALI_SYNC_H_
18 #define _MALI_SYNC_H_
19 
20 #if defined(CONFIG_SYNC) || defined(CONFIG_SYNC_FILE)
21 
22 #include <linux/seq_file.h>
23 #include <linux/version.h>
24 
25 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0)
26 #include <linux/sync.h>
27 #elif LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0)
28 #include <sync.h>
29 #else
30 #include "mali_internal_sync.h"
31 #endif
32 
33 
34 #include "mali_osk.h"
35 
36 struct mali_sync_flag;
37 struct mali_timeline;
38 
39 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0)
40 /**
41  * Create a sync timeline.
42  *
43  * @param name Name of the sync timeline.
44  * @return The new sync timeline if successful, NULL if not.
45  */
46 struct sync_timeline *mali_sync_timeline_create(struct mali_timeline *timeline, const char *name);
47 
48 /**
49  * Creates a file descriptor representing the sync fence.  Will release sync fence if allocation of
50  * file descriptor fails.
51  *
52  * @param sync_fence Sync fence.
53  * @return File descriptor representing sync fence if successful, or -1 if not.
54  */
55 s32 mali_sync_fence_fd_alloc(struct sync_fence *sync_fence);
56 
57 /**
58  * Merges two sync fences.  Both input sync fences will be released.
59  *
60  * @param sync_fence1 First sync fence.
61  * @param sync_fence2 Second sync fence.
62  * @return New sync fence that is the result of the merger if successful, or NULL if not.
63  */
64 struct sync_fence *mali_sync_fence_merge(struct sync_fence *sync_fence1, struct sync_fence *sync_fence2);
65 
66 /**
67  * Create a sync fence that is already signaled.
68  *
69  * @param tl Sync timeline.
70  * @return New signaled sync fence if successful, NULL if not.
71  */
72 struct sync_fence *mali_sync_timeline_create_signaled_fence(struct sync_timeline *sync_tl);
73 
74 
75 /**
76  * Create a sync flag.
77  *
78  * @param sync_tl Sync timeline.
79  * @param point Point on Mali timeline.
80  * @return New sync flag if successful, NULL if not.
81  */
82 struct mali_sync_flag *mali_sync_flag_create(struct sync_timeline *sync_tl, u32 point);
83 
84 /**
85  * Create a sync fence attached to given sync flag.
86  *
87  * @param flag Sync flag.
88  * @return New sync fence if successful, NULL if not.
89  */
90 struct sync_fence *mali_sync_flag_create_fence(struct mali_sync_flag *flag);
91 #else
92 /**
93  * Create a sync timeline.
94  *
95  * @param name Name of the sync timeline.
96  * @return The new sync timeline if successful, NULL if not.
97  */
98 struct mali_internal_sync_timeline *mali_sync_timeline_create(struct mali_timeline *timeline, const char *name);
99 
100 /**
101  * Creates a file descriptor representing the sync fence.  Will release sync fence if allocation of
102  * file descriptor fails.
103  *
104  * @param sync_fence Sync fence.
105  * @return File descriptor representing sync fence if successful, or -1 if not.
106  */
107 s32 mali_sync_fence_fd_alloc(struct mali_internal_sync_fence *sync_fence);
108 
109 /**
110  * Merges two sync fences.  Both input sync fences will be released.
111  *
112  * @param sync_fence1 First sync fence.
113  * @param sync_fence2 Second sync fence.
114  * @return New sync fence that is the result of the merger if successful, or NULL if not.
115  */
116 struct mali_internal_sync_fence *mali_sync_fence_merge(struct mali_internal_sync_fence *sync_fence1, struct mali_internal_sync_fence *sync_fence2);
117 
118 /**
119  * Create a sync fence that is already signaled.
120  *
121  * @param tl Sync timeline.
122  * @return New signaled sync fence if successful, NULL if not.
123  */
124 struct mali_internal_sync_fence *mali_sync_timeline_create_signaled_fence(struct mali_internal_sync_timeline *sync_tl);
125 
126 
127 /**
128  * Create a sync flag.
129  *
130  * @param sync_tl Sync timeline.
131  * @param point Point on Mali timeline.
132  * @return New sync flag if successful, NULL if not.
133  */
134 struct mali_sync_flag *mali_sync_flag_create(struct mali_internal_sync_timeline *sync_tl, u32 point);
135 
136 /**
137  * Create a sync fence attached to given sync flag.
138  *
139  * @param flag Sync flag.
140  * @return New sync fence if successful, NULL if not.
141  */
142 struct mali_internal_sync_fence *mali_sync_flag_create_fence(struct mali_sync_flag *flag);
143 
144 #endif
145 /**
146  * Grab sync flag reference.
147  *
148  * @param flag Sync flag.
149  */
150 void mali_sync_flag_get(struct mali_sync_flag *flag);
151 
152 /**
153  * Release sync flag reference.  If this was the last reference, the sync flag will be freed.
154  *
155  * @param flag Sync flag.
156  */
157 void mali_sync_flag_put(struct mali_sync_flag *flag);
158 
159 /**
160  * Signal sync flag.  All sync fences created from this flag will be signaled.
161  *
162  * @param flag Sync flag to signal.
163  * @param error Negative error code, or 0 if no error.
164  */
165 void mali_sync_flag_signal(struct mali_sync_flag *flag, int error);
166 
167 #endif /* defined(CONFIG_SYNC) || defined(CONFIG_SYNC_FILE) */
168 
169 #endif /* _MALI_SYNC_H_ */
170