xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/mali_kbase_sync.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * (C) COPYRIGHT 2012-2016, 2018-2022 ARM Limited. All rights reserved.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * This program is free software and is provided to you under the terms of the
7*4882a593Smuzhiyun  * GNU General Public License version 2 as published by the Free Software
8*4882a593Smuzhiyun  * Foundation, and any use by you of this program is subject to the terms
9*4882a593Smuzhiyun  * of such GNU license.
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * This program is distributed in the hope that it will be useful,
12*4882a593Smuzhiyun  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*4882a593Smuzhiyun  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*4882a593Smuzhiyun  * GNU General Public License for more details.
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  * You should have received a copy of the GNU General Public License
17*4882a593Smuzhiyun  * along with this program; if not, you can access it online at
18*4882a593Smuzhiyun  * http://www.gnu.org/licenses/gpl-2.0.html.
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  */
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /**
23*4882a593Smuzhiyun  * DOC: This file contains our internal "API" for explicit fences.
24*4882a593Smuzhiyun  * It hides the implementation details of the actual explicit fence mechanism
25*4882a593Smuzhiyun  * used (Android fences or sync file with DMA fences).
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun #ifndef MALI_KBASE_SYNC_H
29*4882a593Smuzhiyun #define MALI_KBASE_SYNC_H
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #include <linux/fdtable.h>
32*4882a593Smuzhiyun #include <linux/syscalls.h>
33*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SYNC_FILE)
34*4882a593Smuzhiyun #include "mali_kbase_fence_defs.h"
35*4882a593Smuzhiyun #include <linux/sync_file.h>
36*4882a593Smuzhiyun #endif
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun #include "mali_kbase.h"
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun /**
41*4882a593Smuzhiyun  * struct kbase_sync_fence_info - Information about a fence
42*4882a593Smuzhiyun  * @fence: Pointer to fence (type is void*, as underlaying struct can differ)
43*4882a593Smuzhiyun  * @name: The name given to this fence when it was created
44*4882a593Smuzhiyun  * @status: < 0 means error, 0 means active, 1 means signaled
45*4882a593Smuzhiyun  *
46*4882a593Smuzhiyun  * Use kbase_sync_fence_in_info_get() or kbase_sync_fence_out_info_get()
47*4882a593Smuzhiyun  * to get the information.
48*4882a593Smuzhiyun  */
49*4882a593Smuzhiyun struct kbase_sync_fence_info {
50*4882a593Smuzhiyun 	void *fence;
51*4882a593Smuzhiyun 	char name[32];
52*4882a593Smuzhiyun 	int status;
53*4882a593Smuzhiyun };
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun /**
56*4882a593Smuzhiyun  * kbase_sync_fence_stream_create() - Create a stream object
57*4882a593Smuzhiyun  * @name: Name of stream (only used to ease debugging/visualization)
58*4882a593Smuzhiyun  * @out_fd: A file descriptor representing the created stream object
59*4882a593Smuzhiyun  *
60*4882a593Smuzhiyun  * Can map down to a timeline implementation in some implementations.
61*4882a593Smuzhiyun  * Exposed as a file descriptor.
62*4882a593Smuzhiyun  * Life-time controlled via the file descriptor:
63*4882a593Smuzhiyun  * - dup to add a ref
64*4882a593Smuzhiyun  * - close to remove a ref
65*4882a593Smuzhiyun  *
66*4882a593Smuzhiyun  * Return: 0 on success, < 0 on error
67*4882a593Smuzhiyun  */
68*4882a593Smuzhiyun int kbase_sync_fence_stream_create(const char *name, int *const out_fd);
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun #if !MALI_USE_CSF
71*4882a593Smuzhiyun /**
72*4882a593Smuzhiyun  * kbase_sync_fence_out_create - Create an explicit output fence to specified atom
73*4882a593Smuzhiyun  *
74*4882a593Smuzhiyun  * @katom: Atom to assign the new explicit fence to
75*4882a593Smuzhiyun  * @stream_fd: File descriptor for stream object to create fence on
76*4882a593Smuzhiyun  *
77*4882a593Smuzhiyun  * Return: Valid file descriptor to fence or < 0 on error
78*4882a593Smuzhiyun  */
79*4882a593Smuzhiyun int kbase_sync_fence_out_create(struct kbase_jd_atom *katom, int stream_fd);
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun /**
82*4882a593Smuzhiyun  * kbase_sync_fence_in_from_fd() - Assigns an existing fence to specified atom
83*4882a593Smuzhiyun  * @katom: Atom to assign the existing explicit fence to
84*4882a593Smuzhiyun  * @fd: File descriptor to an existing fence
85*4882a593Smuzhiyun  *
86*4882a593Smuzhiyun  * Assigns an explicit input fence to atom.
87*4882a593Smuzhiyun  * This can later be waited for by calling @kbase_sync_fence_in_wait
88*4882a593Smuzhiyun  *
89*4882a593Smuzhiyun  * Return: 0 on success, < 0 on error
90*4882a593Smuzhiyun  */
91*4882a593Smuzhiyun int kbase_sync_fence_in_from_fd(struct kbase_jd_atom *katom, int fd);
92*4882a593Smuzhiyun #endif /* !MALI_USE_CSF */
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun /**
95*4882a593Smuzhiyun  * kbase_sync_fence_validate() - Validate a fd to be a valid fence
96*4882a593Smuzhiyun  *
97*4882a593Smuzhiyun  * @fd: File descriptor to check
98*4882a593Smuzhiyun  *
99*4882a593Smuzhiyun  * This function is only usable to catch unintentional user errors early,
100*4882a593Smuzhiyun  * it does not stop malicious code changing the fd after this function returns.
101*4882a593Smuzhiyun  *
102*4882a593Smuzhiyun  * Return: 0 if fd is for a valid fence, < 0 if invalid
103*4882a593Smuzhiyun  */
104*4882a593Smuzhiyun int kbase_sync_fence_validate(int fd);
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun #if !MALI_USE_CSF
107*4882a593Smuzhiyun /**
108*4882a593Smuzhiyun  * kbase_sync_fence_out_trigger - Signal explicit output fence attached on katom
109*4882a593Smuzhiyun  * @katom: Atom with an explicit fence to signal
110*4882a593Smuzhiyun  * @result: < 0 means signal with error, 0 >= indicates success
111*4882a593Smuzhiyun  *
112*4882a593Smuzhiyun  * Signal output fence attached on katom and remove the fence from the atom.
113*4882a593Smuzhiyun  *
114*4882a593Smuzhiyun  * Return: The "next" event code for atom, typically JOB_CANCELLED or EVENT_DONE
115*4882a593Smuzhiyun  */
116*4882a593Smuzhiyun enum base_jd_event_code
117*4882a593Smuzhiyun kbase_sync_fence_out_trigger(struct kbase_jd_atom *katom, int result);
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun /**
120*4882a593Smuzhiyun  * kbase_sync_fence_in_wait() - Wait for explicit input fence to be signaled
121*4882a593Smuzhiyun  * @katom: Atom with explicit fence to wait for
122*4882a593Smuzhiyun  *
123*4882a593Smuzhiyun  * If the fence is already signaled, then 0 is returned, and the caller must
124*4882a593Smuzhiyun  * continue processing of the katom.
125*4882a593Smuzhiyun  *
126*4882a593Smuzhiyun  * If the fence isn't already signaled, then this kbase_sync framework will
127*4882a593Smuzhiyun  * take responsibility to continue the processing once the fence is signaled.
128*4882a593Smuzhiyun  *
129*4882a593Smuzhiyun  * Return: 0 if already signaled, otherwise 1
130*4882a593Smuzhiyun  */
131*4882a593Smuzhiyun int kbase_sync_fence_in_wait(struct kbase_jd_atom *katom);
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun /**
134*4882a593Smuzhiyun  * kbase_sync_fence_in_cancel_wait() - Cancel explicit input fence waits
135*4882a593Smuzhiyun  * @katom: Atom to cancel wait for
136*4882a593Smuzhiyun  *
137*4882a593Smuzhiyun  * This function is fully responsible for continuing processing of this atom
138*4882a593Smuzhiyun  * (remove_waiting_soft_job + finish_soft_job + jd_done + js_sched_all)
139*4882a593Smuzhiyun  */
140*4882a593Smuzhiyun void kbase_sync_fence_in_cancel_wait(struct kbase_jd_atom *katom);
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun /**
143*4882a593Smuzhiyun  * kbase_sync_fence_in_remove() - Remove the input fence from the katom
144*4882a593Smuzhiyun  * @katom: Atom to remove explicit input fence for
145*4882a593Smuzhiyun  *
146*4882a593Smuzhiyun  * This will also release the corresponding reference.
147*4882a593Smuzhiyun  */
148*4882a593Smuzhiyun void kbase_sync_fence_in_remove(struct kbase_jd_atom *katom);
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun /**
151*4882a593Smuzhiyun  * kbase_sync_fence_out_remove() - Remove the output fence from the katom
152*4882a593Smuzhiyun  * @katom: Atom to remove explicit output fence for
153*4882a593Smuzhiyun  *
154*4882a593Smuzhiyun  * This will also release the corresponding reference.
155*4882a593Smuzhiyun  */
156*4882a593Smuzhiyun void kbase_sync_fence_out_remove(struct kbase_jd_atom *katom);
157*4882a593Smuzhiyun #endif /* !MALI_USE_CSF */
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun #if !MALI_USE_CSF
160*4882a593Smuzhiyun /**
161*4882a593Smuzhiyun  * kbase_sync_fence_in_info_get() - Retrieves information about input fence
162*4882a593Smuzhiyun  * @katom: Atom to get fence information from
163*4882a593Smuzhiyun  * @info: Struct to be filled with fence information
164*4882a593Smuzhiyun  *
165*4882a593Smuzhiyun  * Return: 0 on success, < 0 on error
166*4882a593Smuzhiyun  */
167*4882a593Smuzhiyun int kbase_sync_fence_in_info_get(struct kbase_jd_atom *katom,
168*4882a593Smuzhiyun 				 struct kbase_sync_fence_info *info);
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun /**
171*4882a593Smuzhiyun  * kbase_sync_fence_out_info_get() - Retrieves information about output fence
172*4882a593Smuzhiyun  * @katom: Atom to get fence information from
173*4882a593Smuzhiyun  * @info: Struct to be filled with fence information
174*4882a593Smuzhiyun  *
175*4882a593Smuzhiyun  * Return: 0 on success, < 0 on error
176*4882a593Smuzhiyun  */
177*4882a593Smuzhiyun int kbase_sync_fence_out_info_get(struct kbase_jd_atom *katom,
178*4882a593Smuzhiyun 				  struct kbase_sync_fence_info *info);
179*4882a593Smuzhiyun #endif /* !MALI_USE_CSF */
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_SYNC_FILE)
182*4882a593Smuzhiyun #if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
183*4882a593Smuzhiyun void kbase_sync_fence_info_get(struct fence *fence,
184*4882a593Smuzhiyun 			       struct kbase_sync_fence_info *info);
185*4882a593Smuzhiyun #else
186*4882a593Smuzhiyun void kbase_sync_fence_info_get(struct dma_fence *fence,
187*4882a593Smuzhiyun 			       struct kbase_sync_fence_info *info);
188*4882a593Smuzhiyun #endif
189*4882a593Smuzhiyun #endif
190*4882a593Smuzhiyun 
191*4882a593Smuzhiyun /**
192*4882a593Smuzhiyun  * kbase_sync_status_string() - Get string matching @status
193*4882a593Smuzhiyun  * @status: Value of fence status.
194*4882a593Smuzhiyun  *
195*4882a593Smuzhiyun  * Return: Pointer to string describing @status.
196*4882a593Smuzhiyun  */
197*4882a593Smuzhiyun const char *kbase_sync_status_string(int status);
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun #if !MALI_USE_CSF
201*4882a593Smuzhiyun /*
202*4882a593Smuzhiyun  * Internal worker used to continue processing of atom.
203*4882a593Smuzhiyun  */
204*4882a593Smuzhiyun void kbase_sync_fence_wait_worker(struct work_struct *data);
205*4882a593Smuzhiyun 
206*4882a593Smuzhiyun #ifdef CONFIG_MALI_BIFROST_FENCE_DEBUG
207*4882a593Smuzhiyun /**
208*4882a593Smuzhiyun  * kbase_sync_fence_in_dump() - Trigger a debug dump of atoms input fence state
209*4882a593Smuzhiyun  *
210*4882a593Smuzhiyun  * @katom: Atom to trigger fence debug dump for
211*4882a593Smuzhiyun  */
212*4882a593Smuzhiyun void kbase_sync_fence_in_dump(struct kbase_jd_atom *katom);
213*4882a593Smuzhiyun #endif
214*4882a593Smuzhiyun #endif /* !MALI_USE_CSF */
215*4882a593Smuzhiyun 
216*4882a593Smuzhiyun #endif /* MALI_KBASE_SYNC_H */
217