3 * (C) COPYRIGHT 2014-2016 ARM Limited. All rights reserved.
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
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.
20 * HW access job manager common APIs
23 #ifndef _KBASE_HWACCESS_JM_H_
24 #define _KBASE_HWACCESS_JM_H_
27 * kbase_backend_run_atom() - Run an atom on the GPU
28 * @kbdev: Device pointer
31 * Caller must hold the HW access lock
33 void kbase_backend_run_atom(struct kbase_device *kbdev,
34 struct kbase_jd_atom *katom);
37 * kbase_backend_find_free_address_space() - Find a free address space.
38 * @kbdev: Device pointer
39 * @kctx: Context pointer
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.
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()
48 * Return: Number of free address space, or KBASEP_AS_NR_INVALID if none
51 int kbase_backend_find_free_address_space(struct kbase_device *kbdev,
52 struct kbase_context *kctx);
55 * kbase_backend_release_free_address_space() - Release an address space.
56 * @kbdev: Device pointer
57 * @as_nr: Address space to release
59 * The address space must have been returned by
60 * kbase_gpu_find_free_address_space().
62 void kbase_backend_release_free_address_space(struct kbase_device *kbdev,
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
72 * kbase_gpu_next_job() will pull atoms from the active context.
74 * Return: true if successful, false if ASID not assigned.
76 bool kbase_backend_use_ctx(struct kbase_device *kbdev,
77 struct kbase_context *kctx,
81 * kbase_backend_use_ctx_sched() - Activate a context.
82 * @kbdev: Device pointer
83 * @kctx: Context pointer
85 * kbase_gpu_next_job() will pull atoms from the active context.
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
91 * Caller must hold runpool_irq.lock
93 * Return: true if context is now active, false otherwise (ie if context does
94 * not have an address space assigned)
96 bool kbase_backend_use_ctx_sched(struct kbase_device *kbdev,
97 struct kbase_context *kctx);
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
105 * Caller must hold as->transaction_mutex and runpool_irq.lock
107 void kbase_backend_release_ctx_irq(struct kbase_device *kbdev,
108 struct kbase_context *kctx);
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
116 * Caller must hold as->transaction_mutex
118 * This function must perform any operations that could not be performed in IRQ
119 * context by kbase_backend_release_ctx_irq().
121 void kbase_backend_release_ctx_noirq(struct kbase_device *kbdev,
122 struct kbase_context *kctx);
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
130 * This function should only be called from kbase_jd_done_worker() or
131 * js_return_worker().
133 * Return: true if atom has completed, false if atom should be re-submitted
135 void kbase_backend_complete_wq(struct kbase_device *kbdev,
136 struct kbase_jd_atom *katom);
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
147 * This function should only be called from kbase_jd_done_worker() or
148 * js_return_worker().
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);
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
160 void kbase_backend_reset(struct kbase_device *kbdev, ktime_t *end_timestamp);
163 * kbase_backend_inspect_head() - Return the atom currently at the head of slot
165 * @kbdev: Device pointer
166 * @js: Job slot to inspect
168 * Return : Atom currently at the head of slot @js, or NULL
170 struct kbase_jd_atom *kbase_backend_inspect_head(struct kbase_device *kbdev,
174 * kbase_backend_inspect_tail - Return the atom currently at the tail of slot
176 * @kbdev: Device pointer
177 * @js: Job slot to inspect
179 * Return : Atom currently at the head of slot @js, or NULL
181 struct kbase_jd_atom *kbase_backend_inspect_tail(struct kbase_device *kbdev,
185 * kbase_backend_nr_atoms_on_slot() - Return the number of atoms currently on a
187 * @kbdev: Device pointer
188 * @js: Job slot to inspect
190 * Return : Number of atoms currently on slot
192 int kbase_backend_nr_atoms_on_slot(struct kbase_device *kbdev, int js);
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
200 * Return : Number of atoms currently on slot @js that are currently on the GPU.
202 int kbase_backend_nr_atoms_submitted(struct kbase_device *kbdev, int js);
205 * kbase_backend_ctx_count_changed() - Number of contexts ready to submit jobs
207 * @kbdev: Device pointer
209 * Perform any required backend-specific actions (eg starting/stopping
210 * scheduling timers).
212 void kbase_backend_ctx_count_changed(struct kbase_device *kbdev);
215 * kbase_backend_timeouts_changed() - Job Scheduler timeouts have changed.
216 * @kbdev: Device pointer
218 * Perform any required backend-specific actions (eg updating timeouts of
219 * currently running atoms).
221 void kbase_backend_timeouts_changed(struct kbase_device *kbdev);
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
229 * Return : Number of jobs that can be submitted.
231 int kbase_backend_slot_free(struct kbase_device *kbdev, int js);
234 * kbase_job_check_enter_disjoint - potentially leave disjoint state
235 * @kbdev: kbase device
236 * @target_katom: atom which is finishing
238 * Work out whether to leave disjoint state when finishing an atom that was
239 * originated by kbase_job_check_enter_disjoint().
241 void kbase_job_check_leave_disjoint(struct kbase_device *kbdev,
242 struct kbase_jd_atom *target_katom);
245 * kbase_backend_jm_kill_jobs_from_kctx - Kill all jobs that are currently
246 * running from a context
247 * @kctx: Context pointer
249 * This is used in response to a page fault to remove all jobs from the faulting
250 * context from the hardware.
252 void kbase_backend_jm_kill_jobs_from_kctx(struct kbase_context *kctx);
255 * kbase_jm_wait_for_zero_jobs - Wait for context to have zero jobs running, and
257 * @kctx: Context pointer
259 * This should be called following kbase_js_zap_context(), to ensure the context
260 * can be safely destroyed.
262 void kbase_jm_wait_for_zero_jobs(struct kbase_context *kctx);
265 * kbase_backend_get_current_flush_id - Return the current flush ID
267 * @kbdev: Device pointer
269 * Return: the current flush ID to be recorded for each job chain
271 u32 kbase_backend_get_current_flush_id(struct kbase_device *kbdev);
273 #if KBASE_GPU_RESET_EN
275 * kbase_prepare_to_reset_gpu - Prepare for resetting the GPU.
276 * @kbdev: Device pointer
278 * This function just soft-stops all the slots to ensure that as many jobs as
279 * possible are saved.
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
286 bool kbase_prepare_to_reset_gpu(struct kbase_device *kbdev);
289 * kbase_reset_gpu - Reset the GPU
290 * @kbdev: Device pointer
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.
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.
300 void kbase_reset_gpu(struct kbase_device *kbdev);
303 * kbase_prepare_to_reset_gpu_locked - Prepare for resetting the GPU.
304 * @kbdev: Device pointer
306 * This function just soft-stops all the slots to ensure that as many jobs as
307 * possible are saved.
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
314 bool kbase_prepare_to_reset_gpu_locked(struct kbase_device *kbdev);
317 * kbase_reset_gpu_locked - Reset the GPU
318 * @kbdev: Device pointer
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.
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.
328 void kbase_reset_gpu_locked(struct kbase_device *kbdev);
331 * kbase_reset_gpu_silent - Reset the GPU silently
332 * @kbdev: Device pointer
334 * Reset the GPU without trying to cancel jobs and don't emit messages into
335 * the kernel log while doing the reset.
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.
342 void kbase_reset_gpu_silent(struct kbase_device *kbdev);
345 * kbase_reset_gpu_active - Reports if the GPU is being reset
346 * @kbdev: Device pointer
348 * Return: True if the GPU is in the process of being reset.
350 bool kbase_reset_gpu_active(struct kbase_device *kbdev);
354 * kbase_job_slot_hardstop - Hard-stop the specified job slot
355 * @kctx: The kbase context that contains the job(s) that should
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)
361 * The job slot lock must be held when calling this function.
363 void kbase_job_slot_hardstop(struct kbase_context *kctx, int js,
364 struct kbase_jd_atom *target_katom);
366 #endif /* _KBASE_HWACCESS_JM_H_ */