1 /*
2  *
3  * (C) COPYRIGHT 2010-2017 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 #ifndef _KBASE_H_
21 #define _KBASE_H_
22 
23 #include <mali_malisw.h>
24 
25 #include <mali_kbase_debug.h>
26 
27 #include <asm/page.h>
28 
29 #include <linux/atomic.h>
30 #include <linux/highmem.h>
31 #include <linux/hrtimer.h>
32 #include <linux/ktime.h>
33 #include <linux/list.h>
34 #include <linux/mm_types.h>
35 #include <linux/mutex.h>
36 #include <linux/rwsem.h>
37 #include <linux/sched.h>
38 #include <linux/slab.h>
39 #include <linux/spinlock.h>
40 #include <linux/vmalloc.h>
41 #include <linux/wait.h>
42 #include <linux/workqueue.h>
43 #include <linux/sched/task_stack.h>
44 
45 #include "mali_base_kernel.h"
46 #include <mali_kbase_uku.h>
47 #include <mali_kbase_linux.h>
48 
49 /*
50  * Include mali_kbase_defs.h first as this provides types needed by other local
51  * header files.
52  */
53 #include "mali_kbase_defs.h"
54 
55 #include "mali_kbase_context.h"
56 #include "mali_kbase_strings.h"
57 #include "mali_kbase_mem_lowlevel.h"
58 #include "mali_kbase_trace_timeline.h"
59 #include "mali_kbase_js.h"
60 #include "mali_kbase_mem.h"
61 #include "mali_kbase_utility.h"
62 #include "mali_kbase_gpu_memory_debugfs.h"
63 #include "mali_kbase_mem_profile_debugfs.h"
64 #include "mali_kbase_debug_job_fault.h"
65 #include "mali_kbase_jd_debugfs.h"
66 #include "mali_kbase_gpuprops.h"
67 #include "mali_kbase_jm.h"
68 #include "mali_kbase_vinstr.h"
69 
70 #include "ipa/mali_kbase_ipa.h"
71 
72 #ifdef CONFIG_GPU_TRACEPOINTS
73 #include <trace/events/gpu.h>
74 #endif
75 /**
76  * @page page_base_kernel_main Kernel-side Base (KBase) APIs
77  */
78 
79 /**
80  * @defgroup base_kbase_api Kernel-side Base (KBase) APIs
81  */
82 
83 struct kbase_device *kbase_device_alloc(void);
84 /*
85 * note: configuration attributes member of kbdev needs to have
86 * been setup before calling kbase_device_init
87 */
88 
89 /*
90 * API to acquire device list semaphore and return pointer
91 * to the device list head
92 */
93 const struct list_head *kbase_dev_list_get(void);
94 /* API to release the device list semaphore */
95 void kbase_dev_list_put(const struct list_head *dev_list);
96 
97 int kbase_device_init(struct kbase_device * const kbdev);
98 void kbase_device_term(struct kbase_device *kbdev);
99 void kbase_device_free(struct kbase_device *kbdev);
100 int kbase_device_has_feature(struct kbase_device *kbdev, u32 feature);
101 
102 /* Needed for gator integration and for reporting vsync information */
103 struct kbase_device *kbase_find_device(int minor);
104 void kbase_release_device(struct kbase_device *kbdev);
105 
106 void kbase_set_profiling_control(struct kbase_device *kbdev, u32 control, u32 value);
107 
108 struct kbase_context *
109 kbase_create_context(struct kbase_device *kbdev, bool is_compat);
110 void kbase_destroy_context(struct kbase_context *kctx);
111 
112 int kbase_jd_init(struct kbase_context *kctx);
113 void kbase_jd_exit(struct kbase_context *kctx);
114 
115 /**
116  * kbase_jd_submit - Submit atoms to the job dispatcher
117  *
118  * @kctx: The kbase context to submit to
119  * @user_addr: The address in user space of the struct base_jd_atom_v2 array
120  * @nr_atoms: The number of atoms in the array
121  * @stride: sizeof(struct base_jd_atom_v2)
122  * @uk6_atom: true if the atoms are legacy atoms (struct base_jd_atom_v2_uk6)
123  *
124  * Return: 0 on success or error code
125  */
126 int kbase_jd_submit(struct kbase_context *kctx,
127 		void __user *user_addr, u32 nr_atoms, u32 stride,
128 		bool uk6_atom);
129 
130 /**
131  * kbase_jd_done_worker - Handle a job completion
132  * @data: a &struct work_struct
133  *
134  * This function requeues the job from the runpool (if it was soft-stopped or
135  * removed from NEXT registers).
136  *
137  * Removes it from the system if it finished/failed/was cancelled.
138  *
139  * Resolves dependencies to add dependent jobs to the context, potentially
140  * starting them if necessary (which may add more references to the context)
141  *
142  * Releases the reference to the context from the no-longer-running job.
143  *
144  * Handles retrying submission outside of IRQ context if it failed from within
145  * IRQ context.
146  */
147 void kbase_jd_done_worker(struct work_struct *data);
148 
149 void kbase_jd_done(struct kbase_jd_atom *katom, int slot_nr, ktime_t *end_timestamp,
150 		kbasep_js_atom_done_code done_code);
151 void kbase_jd_cancel(struct kbase_device *kbdev, struct kbase_jd_atom *katom);
152 void kbase_jd_zap_context(struct kbase_context *kctx);
153 bool jd_done_nolock(struct kbase_jd_atom *katom,
154 		struct list_head *completed_jobs_ctx);
155 void kbase_jd_free_external_resources(struct kbase_jd_atom *katom);
156 bool jd_submit_atom(struct kbase_context *kctx,
157 			 const struct base_jd_atom_v2 *user_atom,
158 			 struct kbase_jd_atom *katom);
159 void kbase_jd_dep_clear_locked(struct kbase_jd_atom *katom);
160 
161 void kbase_job_done(struct kbase_device *kbdev, u32 done);
162 
163 /**
164  * kbase_job_slot_ctx_priority_check_locked(): - Check for lower priority atoms
165  *                                               and soft stop them
166  * @kctx: Pointer to context to check.
167  * @katom: Pointer to priority atom.
168  *
169  * Atoms from @kctx on the same job slot as @katom, which have lower priority
170  * than @katom will be soft stopped and put back in the queue, so that atoms
171  * with higher priority can run.
172  *
173  * The hwaccess_lock must be held when calling this function.
174  */
175 void kbase_job_slot_ctx_priority_check_locked(struct kbase_context *kctx,
176 				struct kbase_jd_atom *katom);
177 
178 void kbase_job_slot_softstop(struct kbase_device *kbdev, int js,
179 		struct kbase_jd_atom *target_katom);
180 void kbase_job_slot_softstop_swflags(struct kbase_device *kbdev, int js,
181 		struct kbase_jd_atom *target_katom, u32 sw_flags);
182 void kbase_job_slot_hardstop(struct kbase_context *kctx, int js,
183 		struct kbase_jd_atom *target_katom);
184 void kbase_job_check_enter_disjoint(struct kbase_device *kbdev, u32 action,
185 		base_jd_core_req core_reqs, struct kbase_jd_atom *target_katom);
186 void kbase_job_check_leave_disjoint(struct kbase_device *kbdev,
187 		struct kbase_jd_atom *target_katom);
188 
189 void kbase_event_post(struct kbase_context *ctx, struct kbase_jd_atom *event);
190 int kbase_event_dequeue(struct kbase_context *ctx, struct base_jd_event_v2 *uevent);
191 int kbase_event_pending(struct kbase_context *ctx);
192 int kbase_event_init(struct kbase_context *kctx);
193 void kbase_event_close(struct kbase_context *kctx);
194 void kbase_event_cleanup(struct kbase_context *kctx);
195 void kbase_event_wakeup(struct kbase_context *kctx);
196 
197 int kbase_process_soft_job(struct kbase_jd_atom *katom);
198 int kbase_prepare_soft_job(struct kbase_jd_atom *katom);
199 void kbase_finish_soft_job(struct kbase_jd_atom *katom);
200 void kbase_cancel_soft_job(struct kbase_jd_atom *katom);
201 void kbase_resume_suspended_soft_jobs(struct kbase_device *kbdev);
202 void kbasep_remove_waiting_soft_job(struct kbase_jd_atom *katom);
203 #if defined(CONFIG_SYNC) || defined(CONFIG_SYNC_FILE)
204 void kbase_soft_event_wait_callback(struct kbase_jd_atom *katom);
205 #endif
206 int kbase_soft_event_update(struct kbase_context *kctx,
207 			    u64 event,
208 			    unsigned char new_status);
209 
210 bool kbase_replay_process(struct kbase_jd_atom *katom);
211 
212 void kbasep_soft_job_timeout_worker(struct timer_list *t);
213 void kbasep_complete_triggered_soft_events(struct kbase_context *kctx, u64 evt);
214 
215 /* api used internally for register access. Contains validation and tracing */
216 void kbase_device_trace_register_access(struct kbase_context *kctx, enum kbase_reg_access_type type, u16 reg_offset, u32 reg_value);
217 int kbase_device_trace_buffer_install(
218 		struct kbase_context *kctx, u32 *tb, size_t size);
219 void kbase_device_trace_buffer_uninstall(struct kbase_context *kctx);
220 
221 /* api to be ported per OS, only need to do the raw register access */
222 void kbase_os_reg_write(struct kbase_device *kbdev, u16 offset, u32 value);
223 u32 kbase_os_reg_read(struct kbase_device *kbdev, u16 offset);
224 
225 void kbasep_as_do_poke(struct work_struct *work);
226 
227 /** Returns the name associated with a Mali exception code
228  *
229  * This function is called from the interrupt handler when a GPU fault occurs.
230  * It reports the details of the fault using KBASE_DEBUG_PRINT_WARN.
231  *
232  * @param[in] kbdev     The kbase device that the GPU fault occurred from.
233  * @param[in] exception_code  exception code
234  * @return name associated with the exception code
235  */
236 const char *kbase_exception_name(struct kbase_device *kbdev,
237 		u32 exception_code);
238 
239 /**
240  * Check whether a system suspend is in progress, or has already been suspended
241  *
242  * The caller should ensure that either kbdev->pm.active_count_lock is held, or
243  * a dmb was executed recently (to ensure the value is most
244  * up-to-date). However, without a lock the value could change afterwards.
245  *
246  * @return false if a suspend is not in progress
247  * @return !=false otherwise
248  */
kbase_pm_is_suspending(struct kbase_device *kbdev)249 static inline bool kbase_pm_is_suspending(struct kbase_device *kbdev)
250 {
251 	return kbdev->pm.suspending;
252 }
253 
254 /**
255  * Return the atom's ID, as was originally supplied by userspace in
256  * base_jd_atom_v2::atom_number
257  */
kbase_jd_atom_id(struct kbase_context *kctx, struct kbase_jd_atom *katom)258 static inline int kbase_jd_atom_id(struct kbase_context *kctx, struct kbase_jd_atom *katom)
259 {
260 	int result;
261 
262 	KBASE_DEBUG_ASSERT(kctx);
263 	KBASE_DEBUG_ASSERT(katom);
264 	KBASE_DEBUG_ASSERT(katom->kctx == kctx);
265 
266 	result = katom - &kctx->jctx.atoms[0];
267 	KBASE_DEBUG_ASSERT(result >= 0 && result <= BASE_JD_ATOM_COUNT);
268 	return result;
269 }
270 
271 /**
272  * kbase_jd_atom_from_id - Return the atom structure for the given atom ID
273  * @kctx: Context pointer
274  * @id:   ID of atom to retrieve
275  *
276  * Return: Pointer to struct kbase_jd_atom associated with the supplied ID
277  */
kbase_jd_atom_from_id( struct kbase_context *kctx, int id)278 static inline struct kbase_jd_atom *kbase_jd_atom_from_id(
279 		struct kbase_context *kctx, int id)
280 {
281 	return &kctx->jctx.atoms[id];
282 }
283 
284 /**
285  * Initialize the disjoint state
286  *
287  * The disjoint event count and state are both set to zero.
288  *
289  * Disjoint functions usage:
290  *
291  * The disjoint event count should be incremented whenever a disjoint event occurs.
292  *
293  * There are several cases which are regarded as disjoint behavior. Rather than just increment
294  * the counter during disjoint events we also increment the counter when jobs may be affected
295  * by what the GPU is currently doing. To facilitate this we have the concept of disjoint state.
296  *
297  * Disjoint state is entered during GPU reset and for the entire time that an atom is replaying
298  * (as part of the replay workaround). Increasing the disjoint state also increases the count of
299  * disjoint events.
300  *
301  * The disjoint state is then used to increase the count of disjoint events during job submission
302  * and job completion. Any atom submitted or completed while the disjoint state is greater than
303  * zero is regarded as a disjoint event.
304  *
305  * The disjoint event counter is also incremented immediately whenever a job is soft stopped
306  * and during context creation.
307  *
308  * @param kbdev The kbase device
309  */
310 void kbase_disjoint_init(struct kbase_device *kbdev);
311 
312 /**
313  * Increase the count of disjoint events
314  * called when a disjoint event has happened
315  *
316  * @param kbdev The kbase device
317  */
318 void kbase_disjoint_event(struct kbase_device *kbdev);
319 
320 /**
321  * Increase the count of disjoint events only if the GPU is in a disjoint state
322  *
323  * This should be called when something happens which could be disjoint if the GPU
324  * is in a disjoint state. The state refcount keeps track of this.
325  *
326  * @param kbdev The kbase device
327  */
328 void kbase_disjoint_event_potential(struct kbase_device *kbdev);
329 
330 /**
331  * Returns the count of disjoint events
332  *
333  * @param kbdev The kbase device
334  * @return the count of disjoint events
335  */
336 u32 kbase_disjoint_event_get(struct kbase_device *kbdev);
337 
338 /**
339  * Increment the refcount state indicating that the GPU is in a disjoint state.
340  *
341  * Also Increment the disjoint event count (calls @ref kbase_disjoint_event)
342  * eventually after the disjoint state has completed @ref kbase_disjoint_state_down
343  * should be called
344  *
345  * @param kbdev The kbase device
346  */
347 void kbase_disjoint_state_up(struct kbase_device *kbdev);
348 
349 /**
350  * Decrement the refcount state
351  *
352  * Also Increment the disjoint event count (calls @ref kbase_disjoint_event)
353  *
354  * Called after @ref kbase_disjoint_state_up once the disjoint state is over
355  *
356  * @param kbdev The kbase device
357  */
358 void kbase_disjoint_state_down(struct kbase_device *kbdev);
359 
360 /**
361  * If a job is soft stopped and the number of contexts is >= this value
362  * it is reported as a disjoint event
363  */
364 #define KBASE_DISJOINT_STATE_INTERLEAVED_CONTEXT_COUNT_THRESHOLD 2
365 
366 #if !defined(UINT64_MAX)
367 	#define UINT64_MAX ((uint64_t)0xFFFFFFFFFFFFFFFFULL)
368 #endif
369 
370 #if KBASE_TRACE_ENABLE
371 void kbasep_trace_debugfs_init(struct kbase_device *kbdev);
372 
373 #ifndef CONFIG_MALI_SYSTEM_TRACE
374 /** Add trace values about a job-slot
375  *
376  * @note Any functions called through this macro will still be evaluated in
377  * Release builds (CONFIG_MALI_DEBUG not defined). Therefore, when KBASE_TRACE_ENABLE == 0 any
378  * functions called to get the parameters supplied to this macro must:
379  * - be static or static inline
380  * - must just return 0 and have no other statements present in the body.
381  */
382 #define KBASE_TRACE_ADD_SLOT(kbdev, code, ctx, katom, gpu_addr, jobslot) \
383 	kbasep_trace_add(kbdev, KBASE_TRACE_CODE(code), ctx, katom, gpu_addr, \
384 			KBASE_TRACE_FLAG_JOBSLOT, 0, jobslot, 0)
385 
386 /** Add trace values about a job-slot, with info
387  *
388  * @note Any functions called through this macro will still be evaluated in
389  * Release builds (CONFIG_MALI_DEBUG not defined). Therefore, when KBASE_TRACE_ENABLE == 0 any
390  * functions called to get the parameters supplied to this macro must:
391  * - be static or static inline
392  * - must just return 0 and have no other statements present in the body.
393  */
394 #define KBASE_TRACE_ADD_SLOT_INFO(kbdev, code, ctx, katom, gpu_addr, jobslot, info_val) \
395 	kbasep_trace_add(kbdev, KBASE_TRACE_CODE(code), ctx, katom, gpu_addr, \
396 			KBASE_TRACE_FLAG_JOBSLOT, 0, jobslot, info_val)
397 
398 /** Add trace values about a ctx refcount
399  *
400  * @note Any functions called through this macro will still be evaluated in
401  * Release builds (CONFIG_MALI_DEBUG not defined). Therefore, when KBASE_TRACE_ENABLE == 0 any
402  * functions called to get the parameters supplied to this macro must:
403  * - be static or static inline
404  * - must just return 0 and have no other statements present in the body.
405  */
406 #define KBASE_TRACE_ADD_REFCOUNT(kbdev, code, ctx, katom, gpu_addr, refcount) \
407 	kbasep_trace_add(kbdev, KBASE_TRACE_CODE(code), ctx, katom, gpu_addr, \
408 			KBASE_TRACE_FLAG_REFCOUNT, refcount, 0, 0)
409 /** Add trace values about a ctx refcount, and info
410  *
411  * @note Any functions called through this macro will still be evaluated in
412  * Release builds (CONFIG_MALI_DEBUG not defined). Therefore, when KBASE_TRACE_ENABLE == 0 any
413  * functions called to get the parameters supplied to this macro must:
414  * - be static or static inline
415  * - must just return 0 and have no other statements present in the body.
416  */
417 #define KBASE_TRACE_ADD_REFCOUNT_INFO(kbdev, code, ctx, katom, gpu_addr, refcount, info_val) \
418 	kbasep_trace_add(kbdev, KBASE_TRACE_CODE(code), ctx, katom, gpu_addr, \
419 			KBASE_TRACE_FLAG_REFCOUNT, refcount, 0, info_val)
420 
421 /** Add trace values (no slot or refcount)
422  *
423  * @note Any functions called through this macro will still be evaluated in
424  * Release builds (CONFIG_MALI_DEBUG not defined). Therefore, when KBASE_TRACE_ENABLE == 0 any
425  * functions called to get the parameters supplied to this macro must:
426  * - be static or static inline
427  * - must just return 0 and have no other statements present in the body.
428  */
429 #define KBASE_TRACE_ADD(kbdev, code, ctx, katom, gpu_addr, info_val)     \
430 	kbasep_trace_add(kbdev, KBASE_TRACE_CODE(code), ctx, katom, gpu_addr, \
431 			0, 0, 0, info_val)
432 
433 /** Clear the trace */
434 #define KBASE_TRACE_CLEAR(kbdev) \
435 	kbasep_trace_clear(kbdev)
436 
437 /** Dump the slot trace */
438 #define KBASE_TRACE_DUMP(kbdev) \
439 	kbasep_trace_dump(kbdev)
440 
441 /** PRIVATE - do not use directly. Use KBASE_TRACE_ADD() instead */
442 void kbasep_trace_add(struct kbase_device *kbdev, enum kbase_trace_code code, void *ctx, struct kbase_jd_atom *katom, u64 gpu_addr, u8 flags, int refcount, int jobslot, unsigned long info_val);
443 /** PRIVATE - do not use directly. Use KBASE_TRACE_CLEAR() instead */
444 void kbasep_trace_clear(struct kbase_device *kbdev);
445 #else /* #ifndef CONFIG_MALI_SYSTEM_TRACE */
446 /* Dispatch kbase trace events as system trace events */
447 #include <mali_linux_kbase_trace.h>
448 #define KBASE_TRACE_ADD_SLOT(kbdev, code, ctx, katom, gpu_addr, jobslot)\
449 	trace_mali_##code(jobslot, 0)
450 
451 #define KBASE_TRACE_ADD_SLOT_INFO(kbdev, code, ctx, katom, gpu_addr, jobslot, info_val)\
452 	trace_mali_##code(jobslot, info_val)
453 
454 #define KBASE_TRACE_ADD_REFCOUNT(kbdev, code, ctx, katom, gpu_addr, refcount)\
455 	trace_mali_##code(refcount, 0)
456 
457 #define KBASE_TRACE_ADD_REFCOUNT_INFO(kbdev, code, ctx, katom, gpu_addr, refcount, info_val)\
458 	trace_mali_##code(refcount, info_val)
459 
460 #define KBASE_TRACE_ADD(kbdev, code, ctx, katom, gpu_addr, info_val)\
461 	trace_mali_##code(gpu_addr, info_val)
462 
463 #define KBASE_TRACE_CLEAR(kbdev)\
464 	do {\
465 		CSTD_UNUSED(kbdev);\
466 		CSTD_NOP(0);\
467 	} while (0)
468 #define KBASE_TRACE_DUMP(kbdev)\
469 	do {\
470 		CSTD_UNUSED(kbdev);\
471 		CSTD_NOP(0);\
472 	} while (0)
473 
474 #endif /* #ifndef CONFIG_MALI_SYSTEM_TRACE */
475 #else
476 #define KBASE_TRACE_ADD_SLOT(kbdev, code, ctx, katom, gpu_addr, jobslot)\
477 	do {\
478 		CSTD_UNUSED(kbdev);\
479 		CSTD_NOP(code);\
480 		CSTD_UNUSED(ctx);\
481 		CSTD_UNUSED(katom);\
482 		CSTD_UNUSED(gpu_addr);\
483 		CSTD_UNUSED(jobslot);\
484 	} while (0)
485 
486 #define KBASE_TRACE_ADD_SLOT_INFO(kbdev, code, ctx, katom, gpu_addr, jobslot, info_val)\
487 	do {\
488 		CSTD_UNUSED(kbdev);\
489 		CSTD_NOP(code);\
490 		CSTD_UNUSED(ctx);\
491 		CSTD_UNUSED(katom);\
492 		CSTD_UNUSED(gpu_addr);\
493 		CSTD_UNUSED(jobslot);\
494 		CSTD_UNUSED(info_val);\
495 		CSTD_NOP(0);\
496 	} while (0)
497 
498 #define KBASE_TRACE_ADD_REFCOUNT(kbdev, code, ctx, katom, gpu_addr, refcount)\
499 	do {\
500 		CSTD_UNUSED(kbdev);\
501 		CSTD_NOP(code);\
502 		CSTD_UNUSED(ctx);\
503 		CSTD_UNUSED(katom);\
504 		CSTD_UNUSED(gpu_addr);\
505 		CSTD_UNUSED(refcount);\
506 		CSTD_NOP(0);\
507 	} while (0)
508 
509 #define KBASE_TRACE_ADD_REFCOUNT_INFO(kbdev, code, ctx, katom, gpu_addr, refcount, info_val)\
510 	do {\
511 		CSTD_UNUSED(kbdev);\
512 		CSTD_NOP(code);\
513 		CSTD_UNUSED(ctx);\
514 		CSTD_UNUSED(katom);\
515 		CSTD_UNUSED(gpu_addr);\
516 		CSTD_UNUSED(info_val);\
517 		CSTD_NOP(0);\
518 	} while (0)
519 
520 #define KBASE_TRACE_ADD(kbdev, code, subcode, ctx, katom, val)\
521 	do {\
522 		CSTD_UNUSED(kbdev);\
523 		CSTD_NOP(code);\
524 		CSTD_UNUSED(subcode);\
525 		CSTD_UNUSED(ctx);\
526 		CSTD_UNUSED(katom);\
527 		CSTD_UNUSED(val);\
528 		CSTD_NOP(0);\
529 	} while (0)
530 
531 #define KBASE_TRACE_CLEAR(kbdev)\
532 	do {\
533 		CSTD_UNUSED(kbdev);\
534 		CSTD_NOP(0);\
535 	} while (0)
536 #define KBASE_TRACE_DUMP(kbdev)\
537 	do {\
538 		CSTD_UNUSED(kbdev);\
539 		CSTD_NOP(0);\
540 	} while (0)
541 #endif /* KBASE_TRACE_ENABLE */
542 /** PRIVATE - do not use directly. Use KBASE_TRACE_DUMP() instead */
543 void kbasep_trace_dump(struct kbase_device *kbdev);
544 
545 #ifdef CONFIG_MALI_DEBUG
546 /**
547  * kbase_set_driver_inactive - Force driver to go inactive
548  * @kbdev:    Device pointer
549  * @inactive: true if driver should go inactive, false otherwise
550  *
551  * Forcing the driver inactive will cause all future IOCTLs to wait until the
552  * driver is made active again. This is intended solely for the use of tests
553  * which require that no jobs are running while the test executes.
554  */
555 void kbase_set_driver_inactive(struct kbase_device *kbdev, bool inactive);
556 #endif /* CONFIG_MALI_DEBUG */
557 
558 
559 #if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_MALI_NO_MALI)
560 
561 /* kbase_io_history_init - initialize data struct for register access history
562  *
563  * @kbdev The register history to initialize
564  * @n The number of register accesses that the buffer could hold
565  *
566  * @return 0 if successfully initialized, failure otherwise
567  */
568 int kbase_io_history_init(struct kbase_io_history *h, u16 n);
569 
570 /* kbase_io_history_term - uninit all resources for the register access history
571  *
572  * @h The register history to terminate
573  */
574 void kbase_io_history_term(struct kbase_io_history *h);
575 
576 /* kbase_io_history_dump - print the register history to the kernel ring buffer
577  *
578  * @kbdev Pointer to kbase_device containing the register history to dump
579  */
580 void kbase_io_history_dump(struct kbase_device *kbdev);
581 
582 /**
583  * kbase_io_history_resize - resize the register access history buffer.
584  *
585  * @h: Pointer to a valid register history to resize
586  * @new_size: Number of accesses the buffer could hold
587  *
588  * A successful resize will clear all recent register accesses.
589  * If resizing fails for any reason (e.g., could not allocate memory, invalid
590  * buffer size) then the original buffer will be kept intact.
591  *
592  * @return 0 if the buffer was resized, failure otherwise
593  */
594 int kbase_io_history_resize(struct kbase_io_history *h, u16 new_size);
595 
596 #else /* CONFIG_DEBUG_FS */
597 
598 #define kbase_io_history_init(...) ((int)0)
599 
600 #define kbase_io_history_term CSTD_NOP
601 
602 #define kbase_io_history_dump CSTD_NOP
603 
604 #define kbase_io_history_resize CSTD_NOP
605 
606 #endif /* CONFIG_DEBUG_FS */
607 
608 
609 #endif
610 
611 
612 
613