summaryrefslogtreecommitdiff
path: root/mali_kbase/mali_kbase_sync.h
blob: e820dccfc4838de86fd69e8c2ade29d57cd64b5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/*
 *
 * (C) COPYRIGHT 2012-2016, 2018-2022 ARM Limited. All rights reserved.
 *
 * This program is free software and is provided to you under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation, and any use by you of this program is subject to the terms
 * of such GNU license.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you can access it online at
 * http://www.gnu.org/licenses/gpl-2.0.html.
 *
 */

/**
 * DOC: This file contains our internal "API" for explicit fences.
 * It hides the implementation details of the actual explicit fence mechanism
 * used (Android fences or sync file with DMA fences).
 */

#ifndef MALI_KBASE_SYNC_H
#define MALI_KBASE_SYNC_H

#include <linux/fdtable.h>
#include <linux/syscalls.h>
#if IS_ENABLED(CONFIG_SYNC)
#include <sync.h>
#endif
#if IS_ENABLED(CONFIG_SYNC_FILE)
#include "mali_kbase_fence_defs.h"
#include <linux/sync_file.h>
#endif

#include "mali_kbase.h"

/**
 * struct kbase_sync_fence_info - Information about a fence
 * @fence: Pointer to fence (type is void*, as underlaying struct can differ)
 * @name: The name given to this fence when it was created
 * @status: < 0 means error, 0 means active, 1 means signaled
 *
 * Use kbase_sync_fence_in_info_get() or kbase_sync_fence_out_info_get()
 * to get the information.
 */
struct kbase_sync_fence_info {
	void *fence;
	char name[32];
	int status;
};

/**
 * kbase_sync_fence_stream_create() - Create a stream object
 * @name: Name of stream (only used to ease debugging/visualization)
 * @out_fd: A file descriptor representing the created stream object
 *
 * Can map down to a timeline implementation in some implementations.
 * Exposed as a file descriptor.
 * Life-time controlled via the file descriptor:
 * - dup to add a ref
 * - close to remove a ref
 *
 * Return: 0 on success, < 0 on error
 */
int kbase_sync_fence_stream_create(const char *name, int *const out_fd);

#if !MALI_USE_CSF
/**
 * kbase_sync_fence_out_create - Create an explicit output fence to specified atom
 *
 * @katom: Atom to assign the new explicit fence to
 * @stream_fd: File descriptor for stream object to create fence on
 *
 * Return: Valid file descriptor to fence or < 0 on error
 */
struct sync_file *kbase_sync_fence_out_create(struct kbase_jd_atom *katom, int stream_fd);

/**
 * kbase_sync_fence_in_from_fd() - Assigns an existing fence to specified atom
 * @katom: Atom to assign the existing explicit fence to
 * @fd: File descriptor to an existing fence
 *
 * Assigns an explicit input fence to atom.
 * This can later be waited for by calling @kbase_sync_fence_in_wait
 *
 * Return: 0 on success, < 0 on error
 */
int kbase_sync_fence_in_from_fd(struct kbase_jd_atom *katom, int fd);
#endif /* !MALI_USE_CSF */

/**
 * kbase_sync_fence_validate() - Validate a fd to be a valid fence
 *
 * @fd: File descriptor to check
 *
 * This function is only usable to catch unintentional user errors early,
 * it does not stop malicious code changing the fd after this function returns.
 *
 * Return: 0 if fd is for a valid fence, < 0 if invalid
 */
int kbase_sync_fence_validate(int fd);

#if !MALI_USE_CSF
/**
 * kbase_sync_fence_out_trigger - Signal explicit output fence attached on katom
 * @katom: Atom with an explicit fence to signal
 * @result: < 0 means signal with error, 0 >= indicates success
 *
 * Signal output fence attached on katom and remove the fence from the atom.
 *
 * Return: The "next" event code for atom, typically JOB_CANCELLED or EVENT_DONE
 */
enum base_jd_event_code
kbase_sync_fence_out_trigger(struct kbase_jd_atom *katom, int result);

/**
 * kbase_sync_fence_in_wait() - Wait for explicit input fence to be signaled
 * @katom: Atom with explicit fence to wait for
 *
 * If the fence is already signaled, then 0 is returned, and the caller must
 * continue processing of the katom.
 *
 * If the fence isn't already signaled, then this kbase_sync framework will
 * take responsibility to continue the processing once the fence is signaled.
 *
 * Return: 0 if already signaled, otherwise 1
 */
int kbase_sync_fence_in_wait(struct kbase_jd_atom *katom);

/**
 * kbase_sync_fence_in_cancel_wait() - Cancel explicit input fence waits
 * @katom: Atom to cancel wait for
 *
 * This function is fully responsible for continuing processing of this atom
 * (remove_waiting_soft_job + finish_soft_job + jd_done + js_sched_all)
 */
void kbase_sync_fence_in_cancel_wait(struct kbase_jd_atom *katom);

/**
 * kbase_sync_fence_in_remove() - Remove the input fence from the katom
 * @katom: Atom to remove explicit input fence for
 *
 * This will also release the corresponding reference.
 */
void kbase_sync_fence_in_remove(struct kbase_jd_atom *katom);

/**
 * kbase_sync_fence_out_remove() - Remove the output fence from the katom
 * @katom: Atom to remove explicit output fence for
 *
 * This will also release the corresponding reference.
 */
void kbase_sync_fence_out_remove(struct kbase_jd_atom *katom);
#endif /* !MALI_USE_CSF */

#if !MALI_USE_CSF
/**
 * kbase_sync_fence_in_info_get() - Retrieves information about input fence
 * @katom: Atom to get fence information from
 * @info: Struct to be filled with fence information
 *
 * Return: 0 on success, < 0 on error
 */
int kbase_sync_fence_in_info_get(struct kbase_jd_atom *katom,
				 struct kbase_sync_fence_info *info);

/**
 * kbase_sync_fence_out_info_get() - Retrieves information about output fence
 * @katom: Atom to get fence information from
 * @info: Struct to be filled with fence information
 *
 * Return: 0 on success, < 0 on error
 */
int kbase_sync_fence_out_info_get(struct kbase_jd_atom *katom,
				  struct kbase_sync_fence_info *info);
#endif /* !MALI_USE_CSF */

#if defined(CONFIG_SYNC_FILE)
#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
void kbase_sync_fence_info_get(struct fence *fence,
			       struct kbase_sync_fence_info *info);
#else
void kbase_sync_fence_info_get(struct dma_fence *fence,
			       struct kbase_sync_fence_info *info);
#endif
#endif

/**
 * kbase_sync_status_string() - Get string matching @status
 * @status: Value of fence status.
 *
 * Return: Pointer to string describing @status.
 */
const char *kbase_sync_status_string(int status);


#if !MALI_USE_CSF
/*
 * Internal worker used to continue processing of atom.
 */
void kbase_sync_fence_wait_worker(struct kthread_work *data);

#ifdef CONFIG_MALI_FENCE_DEBUG
/**
 * kbase_sync_fence_in_dump() - Trigger a debug dump of atoms input fence state
 *
 * @katom: Atom to trigger fence debug dump for
 */
void kbase_sync_fence_in_dump(struct kbase_jd_atom *katom);
#endif
#endif /* !MALI_USE_CSF */

#endif /* MALI_KBASE_SYNC_H */