abe66078029f7763ca8621f2bce3509b3e5bcd6a
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / mali_kbase_hwaccess_jm.h
1 /*
2  *
3  * (C) COPYRIGHT 2014-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  * HW access job manager common APIs
21  */
22
23 #ifndef _KBASE_HWACCESS_JM_H_
24 #define _KBASE_HWACCESS_JM_H_
25
26 /**
27  * kbase_backend_run_atom() - Run an atom on the GPU
28  * @kbdev:      Device pointer
29  * @atom:       Atom to run
30  *
31  * Caller must hold the HW access lock
32  */
33 void kbase_backend_run_atom(struct kbase_device *kbdev,
34                                 struct kbase_jd_atom *katom);
35
36 /**
37  * kbase_backend_find_free_address_space() - Find a free address space.
38  * @kbdev:      Device pointer
39  * @kctx:       Context pointer
40  *
41  * If no address spaces are currently free, then this function can evict an
42  * idle context from the runpool, freeing up the address space it was using.
43  *
44  * The address space is marked as in use. The caller must either assign a
45  * context using kbase_gpu_use_ctx(), or release it using
46  * kbase_gpu_release_free_address_space()
47  *
48  * Return: Number of free address space, or KBASEP_AS_NR_INVALID if none
49  *         available
50  */
51 int kbase_backend_find_free_address_space(struct kbase_device *kbdev,
52                                                 struct kbase_context *kctx);
53
54 /**
55  * kbase_backend_release_free_address_space() - Release an address space.
56  * @kbdev:      Device pointer
57  * @as_nr:      Address space to release
58  *
59  * The address space must have been returned by
60  * kbase_gpu_find_free_address_space().
61  */
62 void kbase_backend_release_free_address_space(struct kbase_device *kbdev,
63                                                 int as_nr);
64
65 /**
66  * kbase_backend_use_ctx() - Activate a currently unscheduled context, using the
67  *                           provided address space.
68  * @kbdev:      Device pointer
69  * @kctx:       Context pointer. May be NULL
70  * @as_nr:      Free address space to use
71  *
72  * kbase_gpu_next_job() will pull atoms from the active context.
73  *
74  * Return: true if successful, false if ASID not assigned.
75  */
76 bool kbase_backend_use_ctx(struct kbase_device *kbdev,
77                                 struct kbase_context *kctx,
78                                 int as_nr);
79
80 /**
81  * kbase_backend_use_ctx_sched() - Activate a context.
82  * @kbdev:      Device pointer
83  * @kctx:       Context pointer
84  *
85  * kbase_gpu_next_job() will pull atoms from the active context.
86  *
87  * The context must already be scheduled and assigned to an address space. If
88  * the context is not scheduled, then kbase_gpu_use_ctx() should be used
89  * instead.
90  *
91  * Caller must hold runpool_irq.lock
92  *
93  * Return: true if context is now active, false otherwise (ie if context does
94  *         not have an address space assigned)
95  */
96 bool kbase_backend_use_ctx_sched(struct kbase_device *kbdev,
97                                         struct kbase_context *kctx);
98
99 /**
100  * kbase_backend_release_ctx_irq - Release a context from the GPU. This will
101  *                                 de-assign the assigned address space.
102  * @kbdev: Device pointer
103  * @kctx:  Context pointer
104  *
105  * Caller must hold as->transaction_mutex and runpool_irq.lock
106  */
107 void kbase_backend_release_ctx_irq(struct kbase_device *kbdev,
108                                 struct kbase_context *kctx);
109
110 /**
111  * kbase_backend_release_ctx_noirq - Release a context from the GPU. This will
112  *                                   de-assign the assigned address space.
113  * @kbdev: Device pointer
114  * @kctx:  Context pointer
115  *
116  * Caller must hold as->transaction_mutex
117  *
118  * This function must perform any operations that could not be performed in IRQ
119  * context by kbase_backend_release_ctx_irq().
120  */
121 void kbase_backend_release_ctx_noirq(struct kbase_device *kbdev,
122                                                 struct kbase_context *kctx);
123
124 /**
125  * kbase_backend_complete_wq() - Perform backend-specific actions required on
126  *                               completing an atom.
127  * @kbdev:      Device pointer
128  * @katom:      Pointer to the atom to complete
129  *
130  * This function should only be called from kbase_jd_done_worker() or
131  * js_return_worker().
132  *
133  * Return: true if atom has completed, false if atom should be re-submitted
134  */
135 void kbase_backend_complete_wq(struct kbase_device *kbdev,
136                                 struct kbase_jd_atom *katom);
137
138 /**
139  * kbase_backend_complete_wq_post_sched - Perform backend-specific actions
140  *                                        required on completing an atom, after
141  *                                        any scheduling has taken place.
142  * @kbdev:         Device pointer
143  * @core_req:      Core requirements of atom
144  * @affinity:      Affinity of atom
145  * @coreref_state: Coreref state of atom
146  *
147  * This function should only be called from kbase_jd_done_worker() or
148  * js_return_worker().
149  */
150 void kbase_backend_complete_wq_post_sched(struct kbase_device *kbdev,
151                 base_jd_core_req core_req, u64 affinity,
152                 enum kbase_atom_coreref_state coreref_state);
153
154 /**
155  * kbase_backend_reset() - The GPU is being reset. Cancel all jobs on the GPU
156  *                         and remove any others from the ringbuffers.
157  * @kbdev:              Device pointer
158  * @end_timestamp:      Timestamp of reset
159  */
160 void kbase_backend_reset(struct kbase_device *kbdev, ktime_t *end_timestamp);
161
162 /**
163  * kbase_backend_inspect_head() - Return the atom currently at the head of slot
164  *                                @js
165  * @kbdev:      Device pointer
166  * @js:         Job slot to inspect
167  *
168  * Return : Atom currently at the head of slot @js, or NULL
169  */
170 struct kbase_jd_atom *kbase_backend_inspect_head(struct kbase_device *kbdev,
171                                         int js);
172
173 /**
174  * kbase_backend_inspect_tail - Return the atom currently at the tail of slot
175  *                              @js
176  * @kbdev: Device pointer
177  * @js:    Job slot to inspect
178  *
179  * Return : Atom currently at the head of slot @js, or NULL
180  */
181 struct kbase_jd_atom *kbase_backend_inspect_tail(struct kbase_device *kbdev,
182                                         int js);
183
184 /**
185  * kbase_backend_nr_atoms_on_slot() - Return the number of atoms currently on a
186  *                                    slot.
187  * @kbdev:      Device pointer
188  * @js:         Job slot to inspect
189  *
190  * Return : Number of atoms currently on slot
191  */
192 int kbase_backend_nr_atoms_on_slot(struct kbase_device *kbdev, int js);
193
194 /**
195  * kbase_backend_nr_atoms_submitted() - Return the number of atoms on a slot
196  *                                      that are currently on the GPU.
197  * @kbdev:      Device pointer
198  * @js:         Job slot to inspect
199  *
200  * Return : Number of atoms currently on slot @js that are currently on the GPU.
201  */
202 int kbase_backend_nr_atoms_submitted(struct kbase_device *kbdev, int js);
203
204 /**
205  * kbase_backend_ctx_count_changed() - Number of contexts ready to submit jobs
206  *                                     has changed.
207  * @kbdev:      Device pointer
208  *
209  * Perform any required backend-specific actions (eg starting/stopping
210  * scheduling timers).
211  */
212 void kbase_backend_ctx_count_changed(struct kbase_device *kbdev);
213
214 /**
215  * kbase_backend_timeouts_changed() - Job Scheduler timeouts have changed.
216  * @kbdev:      Device pointer
217  *
218  * Perform any required backend-specific actions (eg updating timeouts of
219  * currently running atoms).
220  */
221 void kbase_backend_timeouts_changed(struct kbase_device *kbdev);
222
223 /**
224  * kbase_backend_slot_free() - Return the number of jobs that can be currently
225  *                             submitted to slot @js.
226  * @kbdev:      Device pointer
227  * @js:         Job slot to inspect
228  *
229  * Return : Number of jobs that can be submitted.
230  */
231 int kbase_backend_slot_free(struct kbase_device *kbdev, int js);
232
233 /**
234  * kbase_job_check_enter_disjoint - potentially leave disjoint state
235  * @kbdev: kbase device
236  * @target_katom: atom which is finishing
237  *
238  * Work out whether to leave disjoint state when finishing an atom that was
239  * originated by kbase_job_check_enter_disjoint().
240  */
241 void kbase_job_check_leave_disjoint(struct kbase_device *kbdev,
242                 struct kbase_jd_atom *target_katom);
243
244 /**
245  * kbase_backend_jm_kill_jobs_from_kctx - Kill all jobs that are currently
246  *                                        running from a context
247  * @kctx: Context pointer
248  *
249  * This is used in response to a page fault to remove all jobs from the faulting
250  * context from the hardware.
251  */
252 void kbase_backend_jm_kill_jobs_from_kctx(struct kbase_context *kctx);
253
254 /**
255  * kbase_jm_wait_for_zero_jobs - Wait for context to have zero jobs running, and
256  *                               to be descheduled.
257  * @kctx: Context pointer
258  *
259  * This should be called following kbase_js_zap_context(), to ensure the context
260  * can be safely destroyed.
261  */
262 void kbase_jm_wait_for_zero_jobs(struct kbase_context *kctx);
263
264 /**
265  * kbase_backend_get_current_flush_id - Return the current flush ID
266  *
267  * @kbdev: Device pointer
268  *
269  * Return: the current flush ID to be recorded for each job chain
270  */
271 u32 kbase_backend_get_current_flush_id(struct kbase_device *kbdev);
272
273 #if KBASE_GPU_RESET_EN
274 /**
275  * kbase_prepare_to_reset_gpu - Prepare for resetting the GPU.
276  * @kbdev: Device pointer
277  *
278  * This function just soft-stops all the slots to ensure that as many jobs as
279  * possible are saved.
280  *
281  * Return: a boolean which should be interpreted as follows:
282  * - true  - Prepared for reset, kbase_reset_gpu should be called.
283  * - false - Another thread is performing a reset, kbase_reset_gpu should
284  *                not be called.
285  */
286 bool kbase_prepare_to_reset_gpu(struct kbase_device *kbdev);
287
288 /**
289  * kbase_reset_gpu - Reset the GPU
290  * @kbdev: Device pointer
291  *
292  * This function should be called after kbase_prepare_to_reset_gpu if it returns
293  * true. It should never be called without a corresponding call to
294  * kbase_prepare_to_reset_gpu.
295  *
296  * After this function is called (or not called if kbase_prepare_to_reset_gpu
297  * returned false), the caller should wait for kbdev->reset_waitq to be
298  * signalled to know when the reset has completed.
299  */
300 void kbase_reset_gpu(struct kbase_device *kbdev);
301
302 /**
303  * kbase_prepare_to_reset_gpu_locked - Prepare for resetting the GPU.
304  * @kbdev: Device pointer
305  *
306  * This function just soft-stops all the slots to ensure that as many jobs as
307  * possible are saved.
308  *
309  * Return: a boolean which should be interpreted as follows:
310  * - true  - Prepared for reset, kbase_reset_gpu should be called.
311  * - false - Another thread is performing a reset, kbase_reset_gpu should
312  *                not be called.
313  */
314 bool kbase_prepare_to_reset_gpu_locked(struct kbase_device *kbdev);
315
316 /**
317  * kbase_reset_gpu_locked - Reset the GPU
318  * @kbdev: Device pointer
319  *
320  * This function should be called after kbase_prepare_to_reset_gpu if it
321  * returns true. It should never be called without a corresponding call to
322  * kbase_prepare_to_reset_gpu.
323  *
324  * After this function is called (or not called if kbase_prepare_to_reset_gpu
325  * returned false), the caller should wait for kbdev->reset_waitq to be
326  * signalled to know when the reset has completed.
327  */
328 void kbase_reset_gpu_locked(struct kbase_device *kbdev);
329
330 /**
331  * kbase_reset_gpu_silent - Reset the GPU silently
332  * @kbdev: Device pointer
333  *
334  * Reset the GPU without trying to cancel jobs and don't emit messages into
335  * the kernel log while doing the reset.
336  *
337  * This function should be used in cases where we are doing a controlled reset
338  * of the GPU as part of normal processing (e.g. exiting protected mode) where
339  * the driver will have ensured the scheduler has been idled and all other
340  * users of the GPU (e.g. instrumentation) have been suspended.
341  */
342 void kbase_reset_gpu_silent(struct kbase_device *kbdev);
343
344 /**
345  * kbase_reset_gpu_active - Reports if the GPU is being reset
346  * @kbdev: Device pointer
347  *
348  * Return: True if the GPU is in the process of being reset.
349  */
350 bool kbase_reset_gpu_active(struct kbase_device *kbdev);
351 #endif
352
353 /**
354  * kbase_job_slot_hardstop - Hard-stop the specified job slot
355  * @kctx:         The kbase context that contains the job(s) that should
356  *                be hard-stopped
357  * @js:           The job slot to hard-stop
358  * @target_katom: The job that should be hard-stopped (or NULL for all
359  *                jobs from the context)
360  * Context:
361  *   The job slot lock must be held when calling this function.
362  */
363 void kbase_job_slot_hardstop(struct kbase_context *kctx, int js,
364                                 struct kbase_jd_atom *target_katom);
365
366 #endif /* _KBASE_HWACCESS_JM_H_ */