UPSTREAM: DT/arm,gic-v3: Documment PPI partition support
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / mali400 / mali / common / mali_osk.h
1 /*
2  * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
3  * 
4  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
6  * 
7  * A copy of the licence is included with the program, and can also be obtained from Free Software
8  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
9  */
10
11 /**
12  * @file mali_osk.h
13  * Defines the OS abstraction layer for the kernel device driver (OSK)
14  */
15
16 #ifndef __MALI_OSK_H__
17 #define __MALI_OSK_H__
18
19 #include "mali_osk_types.h"
20 #include "mali_osk_specific.h"           /* include any per-os specifics */
21 #include "mali_osk_locks.h"
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /**
28  * @addtogroup uddapi Unified Device Driver (UDD) APIs
29  *
30  * @{
31  */
32
33 /**
34  * @addtogroup oskapi UDD OS Abstraction for Kernel-side (OSK) APIs
35  *
36  * @{
37  */
38
39 /** @addtogroup _mali_osk_lock OSK Mutual Exclusion Locks
40  * @{ */
41
42 #ifdef DEBUG
43 /** @brief Macro for asserting that the current thread holds a given lock
44  */
45 #define MALI_DEBUG_ASSERT_LOCK_HELD(l) MALI_DEBUG_ASSERT(_mali_osk_lock_get_owner((_mali_osk_lock_debug_t *)l) == _mali_osk_get_tid());
46
47 /** @brief returns a lock's owner (thread id) if debugging is enabled
48  */
49 #else
50 #define MALI_DEBUG_ASSERT_LOCK_HELD(l) do {} while(0)
51 #endif
52
53 /** @} */ /* end group _mali_osk_lock */
54
55 /** @addtogroup _mali_osk_miscellaneous
56  * @{ */
57
58 /** @brief Find the containing structure of another structure
59  *
60  * This is the reverse of the operation 'offsetof'. This means that the
61  * following condition is satisfied:
62  *
63  *   ptr == _MALI_OSK_CONTAINER_OF( &ptr->member, type, member )
64  *
65  * When ptr is of type 'type'.
66  *
67  * Its purpose it to recover a larger structure that has wrapped a smaller one.
68  *
69  * @note no type or memory checking occurs to ensure that a wrapper structure
70  * does in fact exist, and that it is being recovered with respect to the
71  * correct member.
72  *
73  * @param ptr the pointer to the member that is contained within the larger
74  * structure
75  * @param type the type of the structure that contains the member
76  * @param member the name of the member in the structure that ptr points to.
77  * @return a pointer to a \a type object which contains \a member, as pointed
78  * to by \a ptr.
79  */
80 #define _MALI_OSK_CONTAINER_OF(ptr, type, member) \
81         ((type *)( ((char *)ptr) - offsetof(type,member) ))
82
83 /** @addtogroup _mali_osk_wq
84  * @{ */
85
86 /** @brief Initialize work queues (for deferred work)
87  *
88  * @return _MALI_OSK_ERR_OK on success, otherwise failure.
89  */
90 _mali_osk_errcode_t _mali_osk_wq_init(void);
91
92 /** @brief Terminate work queues (for deferred work)
93  */
94 void _mali_osk_wq_term(void);
95
96 /** @brief Create work in the work queue
97  *
98  * Creates a work object which can be scheduled in the work queue. When
99  * scheduled, \a handler will be called with \a data as the argument.
100  *
101  * Refer to \ref _mali_osk_wq_schedule_work() for details on how work
102  * is scheduled in the queue.
103  *
104  * The returned pointer must be freed with \ref _mali_osk_wq_delete_work()
105  * when no longer needed.
106  */
107 _mali_osk_wq_work_t *_mali_osk_wq_create_work(_mali_osk_wq_work_handler_t handler, void *data);
108
109 /** @brief A high priority version of \a _mali_osk_wq_create_work()
110  *
111  * Creates a work object which can be scheduled in the high priority work queue.
112  *
113  * This is unfortunately needed to get low latency scheduling of the Mali cores.  Normally we would
114  * schedule the next job in hw_irq or tasklet, but often we can't since we need to synchronously map
115  * and unmap shared memory when a job is connected to external fences (timelines). And this requires
116  * taking a mutex.
117  *
118  * We do signal a lot of other (low priority) work also as part of the job being finished, and if we
119  * don't set this Mali scheduling thread as high priority, we see that the CPU scheduler often runs
120  * random things instead of starting the next GPU job when the GPU is idle.  So setting the gpu
121  * scheduler to high priority does give a visually more responsive system.
122  *
123  * Start the high priority work with: \a _mali_osk_wq_schedule_work_high_pri()
124  */
125 _mali_osk_wq_work_t *_mali_osk_wq_create_work_high_pri(_mali_osk_wq_work_handler_t handler, void *data);
126
127 /** @brief Delete a work object
128  *
129  * This will flush the work queue to ensure that the work handler will not
130  * be called after deletion.
131  */
132 void _mali_osk_wq_delete_work(_mali_osk_wq_work_t *work);
133
134 /** @brief Delete a work object
135  *
136  * This will NOT flush the work queue, so only call this if you are sure that the work handler will
137  * not be called after deletion.
138  */
139 void _mali_osk_wq_delete_work_nonflush(_mali_osk_wq_work_t *work);
140
141 /** @brief Cause a queued, deferred call of the work handler
142  *
143  * _mali_osk_wq_schedule_work provides a mechanism for enqueuing deferred calls
144  * to the work handler. After calling \ref _mali_osk_wq_schedule_work(), the
145  * work handler will be scheduled to run at some point in the future.
146  *
147  * Typically this is called by the IRQ upper-half to defer further processing of
148  * IRQ-related work to the IRQ bottom-half handler. This is necessary for work
149  * that cannot be done in an IRQ context by the IRQ upper-half handler. Timer
150  * callbacks also use this mechanism, because they are treated as though they
151  * operate in an IRQ context. Refer to \ref _mali_osk_timer_t for more
152  * information.
153  *
154  * Code that operates in a kernel-process context (with no IRQ context
155  * restrictions) may also enqueue deferred calls to the IRQ bottom-half. The
156  * advantage over direct calling is that deferred calling allows the caller and
157  * IRQ bottom half to hold the same mutex, with a guarantee that they will not
158  * deadlock just by using this mechanism.
159  *
160  * _mali_osk_wq_schedule_work() places deferred call requests on a queue, to
161  * allow for more than one thread to make a deferred call. Therfore, if it is
162  * called 'K' times, then the IRQ bottom-half will be scheduled 'K' times too.
163  * 'K' is a number that is implementation-specific.
164  *
165  * _mali_osk_wq_schedule_work() is guaranteed to not block on:
166  * - enqueuing a deferred call request.
167  * - the completion of the work handler.
168  *
169  * This is to prevent deadlock. For example, if _mali_osk_wq_schedule_work()
170  * blocked, then it would cause a deadlock when the following two conditions
171  * hold:
172  * - The work handler callback (of type _mali_osk_wq_work_handler_t) locks
173  * a mutex
174  * - And, at the same time, the caller of _mali_osk_wq_schedule_work() also
175  * holds the same mutex
176  *
177  * @note care must be taken to not overflow the queue that
178  * _mali_osk_wq_schedule_work() operates on. Code must be structured to
179  * ensure that the number of requests made to the queue is bounded. Otherwise,
180  * work will be lost.
181  *
182  * The queue that _mali_osk_wq_schedule_work implements is a FIFO of N-writer,
183  * 1-reader type. The writers are the callers of _mali_osk_wq_schedule_work
184  * (all OSK-registered IRQ upper-half handlers in the system, watchdog timers,
185  * callers from a Kernel-process context). The reader is a single thread that
186  * handles all OSK-registered work.
187  *
188  * @param work a pointer to the _mali_osk_wq_work_t object corresponding to the
189  * work to begin processing.
190  */
191 void _mali_osk_wq_schedule_work(_mali_osk_wq_work_t *work);
192
193 /** @brief Cause a queued, deferred call of the high priority work handler
194  *
195  * Function is the same as \a _mali_osk_wq_schedule_work() with the only
196  * difference that it runs in a high (real time) priority on the system.
197  *
198  * Should only be used as a substitue for doing the same work in interrupts.
199  *
200  * This is allowed to sleep, but the work should be small since it will block
201  * all other applications.
202 */
203 void _mali_osk_wq_schedule_work_high_pri(_mali_osk_wq_work_t *work);
204
205 /** @brief Flush the work queue
206  *
207  * This will flush the OSK work queue, ensuring all work in the queue has
208  * completed before returning.
209  *
210  * Since this blocks on the completion of work in the work-queue, the
211  * caller of this function \b must \b not hold any mutexes that are taken by
212  * any registered work handler. To do so may cause a deadlock.
213  *
214  */
215 void _mali_osk_wq_flush(void);
216
217 /** @brief Create work in the delayed work queue
218  *
219  * Creates a work object which can be scheduled in the work queue. When
220  * scheduled, a timer will be start and the \a handler will be called with
221  * \a data as the argument when timer out
222  *
223  * Refer to \ref _mali_osk_wq_delayed_schedule_work() for details on how work
224  * is scheduled in the queue.
225  *
226  * The returned pointer must be freed with \ref _mali_osk_wq_delayed_delete_work_nonflush()
227  * when no longer needed.
228  */
229 _mali_osk_wq_delayed_work_t *_mali_osk_wq_delayed_create_work(_mali_osk_wq_work_handler_t handler, void *data);
230
231 /** @brief Delete a work object
232  *
233  * This will NOT flush the work queue, so only call this if you are sure that the work handler will
234  * not be called after deletion.
235  */
236 void _mali_osk_wq_delayed_delete_work_nonflush(_mali_osk_wq_delayed_work_t *work);
237
238 /** @brief Cancel a delayed work without waiting for it to finish
239  *
240  * Note that the \a work callback function may still be running on return from
241  * _mali_osk_wq_delayed_cancel_work_async().
242  *
243  * @param work The delayed work to be cancelled
244  */
245 void _mali_osk_wq_delayed_cancel_work_async(_mali_osk_wq_delayed_work_t *work);
246
247 /** @brief Cancel a delayed work and wait for it to finish
248  *
249  * When this function returns, the \a work was either cancelled or it finished running.
250  *
251  * @param work The delayed work to be cancelled
252  */
253 void _mali_osk_wq_delayed_cancel_work_sync(_mali_osk_wq_delayed_work_t *work);
254
255 /** @brief Put \a work task in global workqueue after delay
256  *
257  * After waiting for a given time this puts a job in the kernel-global
258  * workqueue.
259  *
260  * If \a work was already on a queue, this function will return without doing anything
261  *
262  * @param work job to be done
263  * @param delay number of jiffies to wait or 0 for immediate execution
264  */
265 void _mali_osk_wq_delayed_schedule_work(_mali_osk_wq_delayed_work_t *work, u32 delay);
266
267 /** @} */ /* end group _mali_osk_wq */
268
269
270 /** @addtogroup _mali_osk_irq
271  * @{ */
272
273 /** @brief Initialize IRQ handling for a resource
274  *
275  * Registers an interrupt handler \a uhandler for the given IRQ number \a irqnum.
276  * \a data will be passed as argument to the handler when an interrupt occurs.
277  *
278  * If \a irqnum is -1, _mali_osk_irq_init will probe for the IRQ number using
279  * the supplied \a trigger_func and \a ack_func. These functions will also
280  * receive \a data as their argument.
281  *
282  * @param irqnum The IRQ number that the resource uses, as seen by the CPU.
283  * The value -1 has a special meaning which indicates the use of probing, and
284  * trigger_func and ack_func must be non-NULL.
285  * @param uhandler The interrupt handler, corresponding to a ISR handler for
286  * the resource
287  * @param int_data resource specific data, which will be passed to uhandler
288  * @param trigger_func Optional: a function to trigger the resource's irq, to
289  * probe for the interrupt. Use NULL if irqnum != -1.
290  * @param ack_func Optional: a function to acknowledge the resource's irq, to
291  * probe for the interrupt. Use NULL if irqnum != -1.
292  * @param probe_data resource-specific data, which will be passed to
293  * (if present) trigger_func and ack_func
294  * @param description textual description of the IRQ resource.
295  * @return on success, a pointer to a _mali_osk_irq_t object, which represents
296  * the IRQ handling on this resource. NULL on failure.
297  */
298 _mali_osk_irq_t *_mali_osk_irq_init(u32 irqnum, _mali_osk_irq_uhandler_t uhandler, void *int_data, _mali_osk_irq_trigger_t trigger_func, _mali_osk_irq_ack_t ack_func, void *probe_data, const char *description);
299
300 /** @brief Terminate IRQ handling on a resource.
301  *
302  * This will disable the interrupt from the device, and then waits for any
303  * currently executing IRQ handlers to complete.
304  *
305  * @note If work is deferred to an IRQ bottom-half handler through
306  * \ref _mali_osk_wq_schedule_work(), be sure to flush any remaining work
307  * with \ref _mali_osk_wq_flush() or (implicitly) with \ref _mali_osk_wq_delete_work()
308  *
309  * @param irq a pointer to the _mali_osk_irq_t object corresponding to the
310  * resource whose IRQ handling is to be terminated.
311  */
312 void _mali_osk_irq_term(_mali_osk_irq_t *irq);
313
314 /** @} */ /* end group _mali_osk_irq */
315
316
317 /** @addtogroup _mali_osk_atomic
318  * @{ */
319
320 /** @brief Decrement an atomic counter
321  *
322  * @note It is an error to decrement the counter beyond -(1<<23)
323  *
324  * @param atom pointer to an atomic counter */
325 void _mali_osk_atomic_dec(_mali_osk_atomic_t *atom);
326
327 /** @brief Decrement an atomic counter, return new value
328  *
329  * @param atom pointer to an atomic counter
330  * @return The new value, after decrement */
331 u32 _mali_osk_atomic_dec_return(_mali_osk_atomic_t *atom);
332
333 /** @brief Increment an atomic counter
334  *
335  * @note It is an error to increment the counter beyond (1<<23)-1
336  *
337  * @param atom pointer to an atomic counter */
338 void _mali_osk_atomic_inc(_mali_osk_atomic_t *atom);
339
340 /** @brief Increment an atomic counter, return new value
341  *
342  * @param atom pointer to an atomic counter */
343 u32 _mali_osk_atomic_inc_return(_mali_osk_atomic_t *atom);
344
345 /** @brief Initialize an atomic counter
346  *
347  * @note the parameter required is a u32, and so signed integers should be
348  * cast to u32.
349  *
350  * @param atom pointer to an atomic counter
351  * @param val the value to initialize the atomic counter.
352  */
353 void _mali_osk_atomic_init(_mali_osk_atomic_t *atom, u32 val);
354
355 /** @brief Read a value from an atomic counter
356  *
357  * This can only be safely used to determine the value of the counter when it
358  * is guaranteed that other threads will not be modifying the counter. This
359  * makes its usefulness limited.
360  *
361  * @param atom pointer to an atomic counter
362  */
363 u32 _mali_osk_atomic_read(_mali_osk_atomic_t *atom);
364
365 /** @brief Terminate an atomic counter
366  *
367  * @param atom pointer to an atomic counter
368  */
369 void _mali_osk_atomic_term(_mali_osk_atomic_t *atom);
370
371 /** @brief Assign a new val to atomic counter, and return the old atomic counter
372  *
373  * @param atom pointer to an atomic counter
374  * @param val the new value assign to the atomic counter
375  * @return the old value of the atomic counter
376  */
377 u32 _mali_osk_atomic_xchg(_mali_osk_atomic_t *atom, u32 val);
378 /** @} */  /* end group _mali_osk_atomic */
379
380
381 /** @defgroup _mali_osk_memory OSK Memory Allocation
382  * @{ */
383
384 /** @brief Allocate zero-initialized memory.
385  *
386  * Returns a buffer capable of containing at least \a n elements of \a size
387  * bytes each. The buffer is initialized to zero.
388  *
389  * If there is a need for a bigger block of memory (16KB or bigger), then
390  * consider to use _mali_osk_vmalloc() instead, as this function might
391  * map down to a OS function with size limitations.
392  *
393  * The buffer is suitably aligned for storage and subsequent access of every
394  * type that the compiler supports. Therefore, the pointer to the start of the
395  * buffer may be cast into any pointer type, and be subsequently accessed from
396  * such a pointer, without loss of information.
397  *
398  * When the buffer is no longer in use, it must be freed with _mali_osk_free().
399  * Failure to do so will cause a memory leak.
400  *
401  * @note Most toolchains supply memory allocation functions that meet the
402  * compiler's alignment requirements.
403  *
404  * @param n Number of elements to allocate
405  * @param size Size of each element
406  * @return On success, the zero-initialized buffer allocated. NULL on failure
407  */
408 void *_mali_osk_calloc(u32 n, u32 size);
409
410 /** @brief Allocate memory.
411  *
412  * Returns a buffer capable of containing at least \a size bytes. The
413  * contents of the buffer are undefined.
414  *
415  * If there is a need for a bigger block of memory (16KB or bigger), then
416  * consider to use _mali_osk_vmalloc() instead, as this function might
417  * map down to a OS function with size limitations.
418  *
419  * The buffer is suitably aligned for storage and subsequent access of every
420  * type that the compiler supports. Therefore, the pointer to the start of the
421  * buffer may be cast into any pointer type, and be subsequently accessed from
422  * such a pointer, without loss of information.
423  *
424  * When the buffer is no longer in use, it must be freed with _mali_osk_free().
425  * Failure to do so will cause a memory leak.
426  *
427  * @note Most toolchains supply memory allocation functions that meet the
428  * compiler's alignment requirements.
429  *
430  * Remember to free memory using _mali_osk_free().
431  * @param size Number of bytes to allocate
432  * @return On success, the buffer allocated. NULL on failure.
433  */
434 void *_mali_osk_malloc(u32 size);
435
436 /** @brief Free memory.
437  *
438  * Reclaims the buffer pointed to by the parameter \a ptr for the system.
439  * All memory returned from _mali_osk_malloc() and _mali_osk_calloc()
440  * must be freed before the application exits. Otherwise,
441  * a memory leak will occur.
442  *
443  * Memory must be freed once. It is an error to free the same non-NULL pointer
444  * more than once.
445  *
446  * It is legal to free the NULL pointer.
447  *
448  * @param ptr Pointer to buffer to free
449  */
450 void _mali_osk_free(void *ptr);
451
452 /** @brief Allocate memory.
453  *
454  * Returns a buffer capable of containing at least \a size bytes. The
455  * contents of the buffer are undefined.
456  *
457  * This function is potentially slower than _mali_osk_malloc() and _mali_osk_calloc(),
458  * but do support bigger sizes.
459  *
460  * The buffer is suitably aligned for storage and subsequent access of every
461  * type that the compiler supports. Therefore, the pointer to the start of the
462  * buffer may be cast into any pointer type, and be subsequently accessed from
463  * such a pointer, without loss of information.
464  *
465  * When the buffer is no longer in use, it must be freed with _mali_osk_free().
466  * Failure to do so will cause a memory leak.
467  *
468  * @note Most toolchains supply memory allocation functions that meet the
469  * compiler's alignment requirements.
470  *
471  * Remember to free memory using _mali_osk_free().
472  * @param size Number of bytes to allocate
473  * @return On success, the buffer allocated. NULL on failure.
474  */
475 void *_mali_osk_valloc(u32 size);
476
477 /** @brief Free memory.
478  *
479  * Reclaims the buffer pointed to by the parameter \a ptr for the system.
480  * All memory returned from _mali_osk_valloc() must be freed before the
481  * application exits. Otherwise a memory leak will occur.
482  *
483  * Memory must be freed once. It is an error to free the same non-NULL pointer
484  * more than once.
485  *
486  * It is legal to free the NULL pointer.
487  *
488  * @param ptr Pointer to buffer to free
489  */
490 void _mali_osk_vfree(void *ptr);
491
492 /** @brief Copies memory.
493  *
494  * Copies the \a len bytes from the buffer pointed by the parameter \a src
495  * directly to the buffer pointed by \a dst.
496  *
497  * It is an error for \a src to overlap \a dst anywhere in \a len bytes.
498  *
499  * @param dst Pointer to the destination array where the content is to be
500  * copied.
501  * @param src Pointer to the source of data to be copied.
502  * @param len Number of bytes to copy.
503  * @return \a dst is always passed through unmodified.
504  */
505 void *_mali_osk_memcpy(void *dst, const void *src, u32 len);
506
507 /** @brief Fills memory.
508  *
509  * Sets the first \a n bytes of the block of memory pointed to by \a s to
510  * the specified value
511  * @param s Pointer to the block of memory to fill.
512  * @param c Value to be set, passed as u32. Only the 8 Least Significant Bits (LSB)
513  * are used.
514  * @param n Number of bytes to be set to the value.
515  * @return \a s is always passed through unmodified
516  */
517 void *_mali_osk_memset(void *s, u32 c, u32 n);
518 /** @} */ /* end group _mali_osk_memory */
519
520
521 /** @brief Checks the amount of memory allocated
522  *
523  * Checks that not more than \a max_allocated bytes are allocated.
524  *
525  * Some OS bring up an interactive out of memory dialogue when the
526  * system runs out of memory. This can stall non-interactive
527  * apps (e.g. automated test runs). This function can be used to
528  * not trigger the OOM dialogue by keeping allocations
529  * within a certain limit.
530  *
531  * @return MALI_TRUE when \a max_allocated bytes are not in use yet. MALI_FALSE
532  * when at least \a max_allocated bytes are in use.
533  */
534 mali_bool _mali_osk_mem_check_allocated(u32 max_allocated);
535
536
537 /** @addtogroup _mali_osk_low_level_memory
538  * @{ */
539
540 /** @brief Issue a memory barrier
541  *
542  * This defines an arbitrary memory barrier operation, which forces an ordering constraint
543  * on memory read and write operations.
544  */
545 void _mali_osk_mem_barrier(void);
546
547 /** @brief Issue a write memory barrier
548  *
549  * This defines an write memory barrier operation which forces an ordering constraint
550  * on memory write operations.
551  */
552 void _mali_osk_write_mem_barrier(void);
553
554 /** @brief Map a physically contiguous region into kernel space
555  *
556  * This is primarily used for mapping in registers from resources, and Mali-MMU
557  * page tables. The mapping is only visable from kernel-space.
558  *
559  * Access has to go through _mali_osk_mem_ioread32 and _mali_osk_mem_iowrite32
560  *
561  * @param phys CPU-physical base address of the memory to map in. This must
562  * be aligned to the system's page size, which is assumed to be 4K.
563  * @param size the number of bytes of physically contiguous address space to
564  * map in
565  * @param description A textual description of the memory being mapped in.
566  * @return On success, a Mali IO address through which the mapped-in
567  * memory/registers can be accessed. NULL on failure.
568  */
569 mali_io_address _mali_osk_mem_mapioregion(uintptr_t phys, u32 size, const char *description);
570
571 /** @brief Unmap a physically contiguous address range from kernel space.
572  *
573  * The address range should be one previously mapped in through
574  * _mali_osk_mem_mapioregion.
575  *
576  * It is a programming error to do (but not limited to) the following:
577  * - attempt an unmap twice
578  * - unmap only part of a range obtained through _mali_osk_mem_mapioregion
579  * - unmap more than the range obtained through  _mali_osk_mem_mapioregion
580  * - unmap an address range that was not successfully mapped using
581  * _mali_osk_mem_mapioregion
582  * - provide a mapping that does not map to phys.
583  *
584  * @param phys CPU-physical base address of the memory that was originally
585  * mapped in. This must be aligned to the system's page size, which is assumed
586  * to be 4K
587  * @param size The number of bytes that were originally mapped in.
588  * @param mapping The Mali IO address through which the mapping is
589  * accessed.
590  */
591 void _mali_osk_mem_unmapioregion(uintptr_t phys, u32 size, mali_io_address mapping);
592
593 /** @brief Allocate and Map a physically contiguous region into kernel space
594  *
595  * This is used for allocating physically contiguous regions (such as Mali-MMU
596  * page tables) and mapping them into kernel space. The mapping is only
597  * visible from kernel-space.
598  *
599  * The alignment of the returned memory is guaranteed to be at least
600  * _MALI_OSK_CPU_PAGE_SIZE.
601  *
602  * Access must go through _mali_osk_mem_ioread32 and _mali_osk_mem_iowrite32
603  *
604  * @note This function is primarily to provide support for OSs that are
605  * incapable of separating the tasks 'allocate physically contiguous memory'
606  * and 'map it into kernel space'
607  *
608  * @param[out] phys CPU-physical base address of memory that was allocated.
609  * (*phys) will be guaranteed to be aligned to at least
610  * _MALI_OSK_CPU_PAGE_SIZE on success.
611  *
612  * @param[in] size the number of bytes of physically contiguous memory to
613  * allocate. This must be a multiple of _MALI_OSK_CPU_PAGE_SIZE.
614  *
615  * @return On success, a Mali IO address through which the mapped-in
616  * memory/registers can be accessed. NULL on failure, and (*phys) is unmodified.
617  */
618 mali_io_address _mali_osk_mem_allocioregion(u32 *phys, u32 size);
619
620 /** @brief Free a physically contiguous address range from kernel space.
621  *
622  * The address range should be one previously mapped in through
623  * _mali_osk_mem_allocioregion.
624  *
625  * It is a programming error to do (but not limited to) the following:
626  * - attempt a free twice on the same ioregion
627  * - free only part of a range obtained through _mali_osk_mem_allocioregion
628  * - free more than the range obtained through  _mali_osk_mem_allocioregion
629  * - free an address range that was not successfully mapped using
630  * _mali_osk_mem_allocioregion
631  * - provide a mapping that does not map to phys.
632  *
633  * @param phys CPU-physical base address of the memory that was originally
634  * mapped in, which was aligned to _MALI_OSK_CPU_PAGE_SIZE.
635  * @param size The number of bytes that were originally mapped in, which was
636  * a multiple of _MALI_OSK_CPU_PAGE_SIZE.
637  * @param mapping The Mali IO address through which the mapping is
638  * accessed.
639  */
640 void _mali_osk_mem_freeioregion(u32 phys, u32 size, mali_io_address mapping);
641
642 /** @brief Request a region of physically contiguous memory
643  *
644  * This is used to ensure exclusive access to a region of physically contigous
645  * memory.
646  *
647  * It is acceptable to implement this as a stub. However, it is then the job
648  * of the System Integrator to ensure that no other device driver will be using
649  * the physical address ranges used by Mali, while the Mali device driver is
650  * loaded.
651  *
652  * @param phys CPU-physical base address of the memory to request. This must
653  * be aligned to the system's page size, which is assumed to be 4K.
654  * @param size the number of bytes of physically contiguous address space to
655  * request.
656  * @param description A textual description of the memory being requested.
657  * @return _MALI_OSK_ERR_OK on success. Otherwise, a suitable
658  * _mali_osk_errcode_t on failure.
659  */
660 _mali_osk_errcode_t _mali_osk_mem_reqregion(uintptr_t phys, u32 size, const char *description);
661
662 /** @brief Un-request a region of physically contiguous memory
663  *
664  * This is used to release a regious of physically contiguous memory previously
665  * requested through _mali_osk_mem_reqregion, so that other device drivers may
666  * use it. This will be called at time of Mali device driver termination.
667  *
668  * It is a programming error to attempt to:
669  * - unrequest a region twice
670  * - unrequest only part of a range obtained through _mali_osk_mem_reqregion
671  * - unrequest more than the range obtained through  _mali_osk_mem_reqregion
672  * - unrequest an address range that was not successfully requested using
673  * _mali_osk_mem_reqregion
674  *
675  * @param phys CPU-physical base address of the memory to un-request. This must
676  * be aligned to the system's page size, which is assumed to be 4K
677  * @param size the number of bytes of physically contiguous address space to
678  * un-request.
679  */
680 void _mali_osk_mem_unreqregion(uintptr_t phys, u32 size);
681
682 /** @brief Read from a location currently mapped in through
683  * _mali_osk_mem_mapioregion
684  *
685  * This reads a 32-bit word from a 32-bit aligned location. It is a programming
686  * error to provide unaligned locations, or to read from memory that is not
687  * mapped in, or not mapped through either _mali_osk_mem_mapioregion() or
688  * _mali_osk_mem_allocioregion().
689  *
690  * @param mapping Mali IO address to read from
691  * @param offset Byte offset from the given IO address to operate on, must be a multiple of 4
692  * @return the 32-bit word from the specified location.
693  */
694 u32 _mali_osk_mem_ioread32(volatile mali_io_address mapping, u32 offset);
695
696 /** @brief Write to a location currently mapped in through
697  * _mali_osk_mem_mapioregion without memory barriers
698  *
699  * This write a 32-bit word to a 32-bit aligned location without using memory barrier.
700  * It is a programming error to provide unaligned locations, or to write to memory that is not
701  * mapped in, or not mapped through either _mali_osk_mem_mapioregion() or
702  * _mali_osk_mem_allocioregion().
703  *
704  * @param mapping Mali IO address to write to
705  * @param offset Byte offset from the given IO address to operate on, must be a multiple of 4
706  * @param val the 32-bit word to write.
707  */
708 void _mali_osk_mem_iowrite32_relaxed(volatile mali_io_address addr, u32 offset, u32 val);
709
710 /** @brief Write to a location currently mapped in through
711  * _mali_osk_mem_mapioregion with write memory barrier
712  *
713  * This write a 32-bit word to a 32-bit aligned location. It is a programming
714  * error to provide unaligned locations, or to write to memory that is not
715  * mapped in, or not mapped through either _mali_osk_mem_mapioregion() or
716  * _mali_osk_mem_allocioregion().
717  *
718  * @param mapping Mali IO address to write to
719  * @param offset Byte offset from the given IO address to operate on, must be a multiple of 4
720  * @param val the 32-bit word to write.
721  */
722 void _mali_osk_mem_iowrite32(volatile mali_io_address mapping, u32 offset, u32 val);
723
724 /** @brief Flush all CPU caches
725  *
726  * This should only be implemented if flushing of the cache is required for
727  * memory mapped in through _mali_osk_mem_mapregion.
728  */
729 void _mali_osk_cache_flushall(void);
730
731 /** @brief Flush any caches necessary for the CPU and MALI to have the same view of a range of uncached mapped memory
732  *
733  * This should only be implemented if your OS doesn't do a full cache flush (inner & outer)
734  * after allocating uncached mapped memory.
735  *
736  * Some OS do not perform a full cache flush (including all outer caches) for uncached mapped memory.
737  * They zero the memory through a cached mapping, then flush the inner caches but not the outer caches.
738  * This is required for MALI to have the correct view of the memory.
739  */
740 void _mali_osk_cache_ensure_uncached_range_flushed(void *uncached_mapping, u32 offset, u32 size);
741
742 /** @brief Safely copy as much data as possible from src to dest
743  *
744  * Do not crash if src or dest isn't available.
745  *
746  * @param dest Destination buffer (limited to user space mapped Mali memory)
747  * @param src Source buffer
748  * @param size Number of bytes to copy
749  * @return Number of bytes actually copied
750  */
751 u32 _mali_osk_mem_write_safe(void *dest, const void *src, u32 size);
752
753 /** @} */ /* end group _mali_osk_low_level_memory */
754
755
756 /** @addtogroup _mali_osk_notification
757  *
758  * User space notification framework
759  *
760  * Communication with user space of asynchronous events is performed through a
761  * synchronous call to the \ref u_k_api.
762  *
763  * Since the events are asynchronous, the events have to be queued until a
764  * synchronous U/K API call can be made by user-space. A U/K API call might also
765  * be received before any event has happened. Therefore the notifications the
766  * different subsystems wants to send to user space has to be queued for later
767  * reception, or a U/K API call has to be blocked until an event has occured.
768  *
769  * Typical uses of notifications are after running of jobs on the hardware or
770  * when changes to the system is detected that needs to be relayed to user
771  * space.
772  *
773  * After an event has occured user space has to be notified using some kind of
774  * message. The notification framework supports sending messages to waiting
775  * threads or queueing of messages until a U/K API call is made.
776  *
777  * The notification queue is a FIFO. There are no restrictions on the numbers
778  * of readers or writers in the queue.
779  *
780  * A message contains what user space needs to identifiy how to handle an
781  * event. This includes a type field and a possible type specific payload.
782  *
783  * A notification to user space is represented by a
784  * \ref _mali_osk_notification_t object. A sender gets hold of such an object
785  * using _mali_osk_notification_create(). The buffer given by the
786  * _mali_osk_notification_t::result_buffer field in the object is used to store
787  * any type specific data. The other fields are internal to the queue system
788  * and should not be touched.
789  *
790  * @{ */
791
792 /** @brief Create a notification object
793  *
794  * Returns a notification object which can be added to the queue of
795  * notifications pending for user space transfer.
796  *
797  * The implementation will initialize all members of the
798  * \ref _mali_osk_notification_t object. In particular, the
799  * _mali_osk_notification_t::result_buffer member will be initialized to point
800  * to \a size bytes of storage, and that storage will be suitably aligned for
801  * storage of any structure. That is, the created buffer meets the same
802  * requirements as _mali_osk_malloc().
803  *
804  * The notification object must be deleted when not in use. Use
805  * _mali_osk_notification_delete() for deleting it.
806  *
807  * @note You \b must \b not call _mali_osk_free() on a \ref _mali_osk_notification_t,
808  * object, or on a _mali_osk_notification_t::result_buffer. You must only use
809  * _mali_osk_notification_delete() to free the resources assocaited with a
810  * \ref _mali_osk_notification_t object.
811  *
812  * @param type The notification type
813  * @param size The size of the type specific buffer to send
814  * @return Pointer to a notification object with a suitable buffer, or NULL on error.
815  */
816 _mali_osk_notification_t *_mali_osk_notification_create(u32 type, u32 size);
817
818 /** @brief Delete a notification object
819  *
820  * This must be called to reclaim the resources of a notification object. This
821  * includes:
822  * - The _mali_osk_notification_t::result_buffer
823  * - The \ref _mali_osk_notification_t itself.
824  *
825  * A notification object \b must \b not be used after it has been deleted by
826  * _mali_osk_notification_delete().
827  *
828  * In addition, the notification object may not be deleted while it is in a
829  * queue. That is, if it has been placed on a queue with
830  * _mali_osk_notification_queue_send(), then it must not be deleted until
831  * it has been received by a call to _mali_osk_notification_queue_receive().
832  * Otherwise, the queue may be corrupted.
833  *
834  * @param object the notification object to delete.
835  */
836 void _mali_osk_notification_delete(_mali_osk_notification_t *object);
837
838 /** @brief Create a notification queue
839  *
840  * Creates a notification queue which can be used to queue messages for user
841  * delivery and get queued messages from
842  *
843  * The queue is a FIFO, and has no restrictions on the numbers of readers or
844  * writers.
845  *
846  * When the queue is no longer in use, it must be terminated with
847  * \ref _mali_osk_notification_queue_term(). Failure to do so will result in a
848  * memory leak.
849  *
850  * @return Pointer to a new notification queue or NULL on error.
851  */
852 _mali_osk_notification_queue_t *_mali_osk_notification_queue_init(void);
853
854 /** @brief Destroy a notification queue
855  *
856  * Destroys a notification queue and frees associated resources from the queue.
857  *
858  * A notification queue \b must \b not be destroyed in the following cases:
859  * - while there are \ref _mali_osk_notification_t objects in the queue.
860  * - while there are writers currently acting upon the queue. That is, while
861  * a thread is currently calling \ref _mali_osk_notification_queue_send() on
862  * the queue, or while a thread may call
863  * \ref _mali_osk_notification_queue_send() on the queue in the future.
864  * - while there are readers currently waiting upon the queue. That is, while
865  * a thread is currently calling \ref _mali_osk_notification_queue_receive() on
866  * the queue, or while a thread may call
867  * \ref _mali_osk_notification_queue_receive() on the queue in the future.
868  *
869  * Therefore, all \ref _mali_osk_notification_t objects must be flushed and
870  * deleted by the code that makes use of the notification queues, since only
871  * they know the structure of the _mali_osk_notification_t::result_buffer
872  * (even if it may only be a flat sturcture).
873  *
874  * @note Since the queue is a FIFO, the code using notification queues may
875  * create its own 'flush' type of notification, to assist in flushing the
876  * queue.
877  *
878  * Once the queue has been destroyed, it must not be used again.
879  *
880  * @param queue The queue to destroy
881  */
882 void _mali_osk_notification_queue_term(_mali_osk_notification_queue_t *queue);
883
884 /** @brief Schedule notification for delivery
885  *
886  * When a \ref _mali_osk_notification_t object has been created successfully
887  * and set up, it may be added to the queue of objects waiting for user space
888  * transfer.
889  *
890  * The sending will not block if the queue is full.
891  *
892  * A \ref _mali_osk_notification_t object \b must \b not be put on two different
893  * queues at the same time, or enqueued twice onto a single queue before
894  * reception. However, it is acceptable for it to be requeued \em after reception
895  * from a call to _mali_osk_notification_queue_receive(), even onto the same queue.
896  *
897  * Again, requeuing must also not enqueue onto two different queues at the same
898  * time, or enqueue onto the same queue twice before reception.
899  *
900  * @param queue The notification queue to add this notification to
901  * @param object The entry to add
902  */
903 void _mali_osk_notification_queue_send(_mali_osk_notification_queue_t *queue, _mali_osk_notification_t *object);
904
905 /** @brief Receive a notification from a queue
906  *
907  * Receives a single notification from the given queue.
908  *
909  * If no notifciations are ready the thread will sleep until one becomes ready.
910  * Therefore, notifications may not be received into an
911  * IRQ or 'atomic' context (that is, a context where sleeping is disallowed).
912  *
913  * @param queue The queue to receive from
914  * @param result Pointer to storage of a pointer of type
915  * \ref _mali_osk_notification_t*. \a result will be written to such that the
916  * expression \a (*result) will evaluate to a pointer to a valid
917  * \ref _mali_osk_notification_t object, or NULL if none were received.
918  * @return _MALI_OSK_ERR_OK on success. _MALI_OSK_ERR_RESTARTSYSCALL if the sleep was interrupted.
919  */
920 _mali_osk_errcode_t _mali_osk_notification_queue_receive(_mali_osk_notification_queue_t *queue, _mali_osk_notification_t **result);
921
922 /** @brief Dequeues a notification from a queue
923  *
924  * Receives a single notification from the given queue.
925  *
926  * If no notifciations are ready the function call will return an error code.
927  *
928  * @param queue The queue to receive from
929  * @param result Pointer to storage of a pointer of type
930  * \ref _mali_osk_notification_t*. \a result will be written to such that the
931  * expression \a (*result) will evaluate to a pointer to a valid
932  * \ref _mali_osk_notification_t object, or NULL if none were received.
933  * @return _MALI_OSK_ERR_OK on success, _MALI_OSK_ERR_ITEM_NOT_FOUND if queue was empty.
934  */
935 _mali_osk_errcode_t _mali_osk_notification_queue_dequeue(_mali_osk_notification_queue_t *queue, _mali_osk_notification_t **result);
936
937 /** @} */ /* end group _mali_osk_notification */
938
939
940 /** @addtogroup _mali_osk_timer
941  *
942  * Timers use the OS's representation of time, which are 'ticks'. This is to
943  * prevent aliasing problems between the internal timer time, and the time
944  * asked for.
945  *
946  * @{ */
947
948 /** @brief Initialize a timer
949  *
950  * Allocates resources for a new timer, and initializes them. This does not
951  * start the timer.
952  *
953  * @return a pointer to the allocated timer object, or NULL on failure.
954  */
955 _mali_osk_timer_t *_mali_osk_timer_init(void);
956
957 /** @brief Start a timer
958  *
959  * It is an error to start a timer without setting the callback via
960  * _mali_osk_timer_setcallback().
961  *
962  * It is an error to use this to start an already started timer.
963  *
964  * The timer will expire in \a ticks_to_expire ticks, at which point, the
965  * callback function will be invoked with the callback-specific data,
966  * as registered by _mali_osk_timer_setcallback().
967  *
968  * @param tim the timer to start
969  * @param ticks_to_expire the amount of time in ticks for the timer to run
970  * before triggering.
971  */
972 void _mali_osk_timer_add(_mali_osk_timer_t *tim, unsigned long ticks_to_expire);
973
974 /** @brief Modify a timer
975  *
976  * Set the relative time at which a timer will expire, and start it if it is
977  * stopped. If \a ticks_to_expire 0 the timer fires immediately.
978  *
979  * It is an error to modify a timer without setting the callback via
980  *  _mali_osk_timer_setcallback().
981  *
982  * The timer will expire at \a ticks_to_expire from the time of the call, at
983  * which point, the callback function will be invoked with the
984  * callback-specific data, as set by _mali_osk_timer_setcallback().
985  *
986  * @param tim the timer to modify, and start if necessary
987  * @param ticks_to_expire the \em absolute time in ticks at which this timer
988  * should trigger.
989  *
990  */
991 void _mali_osk_timer_mod(_mali_osk_timer_t *tim, unsigned long ticks_to_expire);
992
993 /** @brief Stop a timer, and block on its completion.
994  *
995  * Stop the timer. When the function returns, it is guaranteed that the timer's
996  * callback will not be running on any CPU core.
997  *
998  * Since stoping the timer blocks on compeletion of the callback, the callback
999  * may not obtain any mutexes that the caller holds. Otherwise, a deadlock will
1000  * occur.
1001  *
1002  * @note While the callback itself is guaranteed to not be running, work
1003  * enqueued on the work-queue by the timer (with
1004  * \ref _mali_osk_wq_schedule_work()) may still run. The timer callback and
1005  * work handler must take this into account.
1006  *
1007  * It is legal to stop an already stopped timer.
1008  *
1009  * @param tim the timer to stop.
1010  *
1011  */
1012 void _mali_osk_timer_del(_mali_osk_timer_t *tim);
1013
1014 /** @brief Stop a timer.
1015  *
1016  * Stop the timer. When the function returns, the timer's callback may still be
1017  * running on any CPU core.
1018  *
1019  * It is legal to stop an already stopped timer.
1020  *
1021  * @param tim the timer to stop.
1022  */
1023 void _mali_osk_timer_del_async(_mali_osk_timer_t *tim);
1024
1025 /** @brief Check if timer is pending.
1026  *
1027  * Check if timer is active.
1028  *
1029  * @param tim the timer to check
1030  * @return MALI_TRUE if time is active, MALI_FALSE if it is not active
1031  */
1032 mali_bool _mali_osk_timer_pending(_mali_osk_timer_t *tim);
1033
1034 /** @brief Set a timer's callback parameters.
1035  *
1036  * This must be called at least once before a timer is started/modified.
1037  *
1038  * After a timer has been stopped or expires, the callback remains set. This
1039  * means that restarting the timer will call the same function with the same
1040  * parameters on expiry.
1041  *
1042  * @param tim the timer to set callback on.
1043  * @param callback Function to call when timer expires
1044  * @param data Function-specific data to supply to the function on expiry.
1045  */
1046 void _mali_osk_timer_setcallback(_mali_osk_timer_t *tim, _mali_osk_timer_callback_t callback, void *data);
1047
1048 /** @brief Terminate a timer, and deallocate resources.
1049  *
1050  * The timer must first be stopped by calling _mali_osk_timer_del().
1051  *
1052  * It is a programming error for _mali_osk_timer_term() to be called on:
1053  * - timer that is currently running
1054  * - a timer that is currently executing its callback.
1055  *
1056  * @param tim the timer to deallocate.
1057  */
1058 void _mali_osk_timer_term(_mali_osk_timer_t *tim);
1059 /** @} */ /* end group _mali_osk_timer */
1060
1061
1062 /** @defgroup _mali_osk_time OSK Time functions
1063  *
1064  * \ref _mali_osk_time use the OS's representation of time, which are
1065  * 'ticks'. This is to prevent aliasing problems between the internal timer
1066  * time, and the time asked for.
1067  *
1068  * OS tick time is measured as a u32. The time stored in a u32 may either be
1069  * an absolute time, or a time delta between two events. Whilst it is valid to
1070  * use math opeartors to \em change the tick value represented as a u32, it
1071  * is often only meaningful to do such operations on time deltas, rather than
1072  * on absolute time. However, it is meaningful to add/subtract time deltas to
1073  * absolute times.
1074  *
1075  * Conversion between tick time and milliseconds (ms) may not be loss-less,
1076  * and are \em implementation \em depenedant.
1077  *
1078  * Code use OS time must take this into account, since:
1079  * - a small OS time may (or may not) be rounded
1080  * - a large time may (or may not) overflow
1081  *
1082  * @{ */
1083
1084 /** @brief Return whether ticka occurs after or at the same time as  tickb
1085  *
1086  * Systems where ticks can wrap must handle that.
1087  *
1088  * @param ticka ticka
1089  * @param tickb tickb
1090  * @return MALI_TRUE if ticka represents a time that occurs at or after tickb.
1091  */
1092 mali_bool _mali_osk_time_after_eq(unsigned long ticka, unsigned long tickb);
1093
1094 /** @brief Convert milliseconds to OS 'ticks'
1095  *
1096  * @param ms time interval in milliseconds
1097  * @return the corresponding time interval in OS ticks.
1098  */
1099 unsigned long _mali_osk_time_mstoticks(u32 ms);
1100
1101 /** @brief Convert OS 'ticks' to milliseconds
1102  *
1103  * @param ticks time interval in OS ticks.
1104  * @return the corresponding time interval in milliseconds
1105  */
1106 u32 _mali_osk_time_tickstoms(unsigned long ticks);
1107
1108
1109 /** @brief Get the current time in OS 'ticks'.
1110  * @return the current time in OS 'ticks'.
1111  */
1112 unsigned long _mali_osk_time_tickcount(void);
1113
1114 /** @brief Cause a microsecond delay
1115  *
1116  * The delay will have microsecond resolution, and is necessary for correct
1117  * operation of the driver. At worst, the delay will be \b at least \a usecs
1118  * microseconds, and so may be (significantly) more.
1119  *
1120  * This function may be implemented as a busy-wait, which is the most sensible
1121  * implementation. On OSs where there are situations in which a thread must not
1122  * sleep, this is definitely implemented as a busy-wait.
1123  *
1124  * @param usecs the number of microseconds to wait for.
1125  */
1126 void _mali_osk_time_ubusydelay(u32 usecs);
1127
1128 /** @brief Return time in nano seconds, since any given reference.
1129  *
1130  * @return Time in nano seconds
1131  */
1132 u64 _mali_osk_time_get_ns(void);
1133
1134 /** @brief Return time in nano seconds, since boot time.
1135  *
1136  * @return Time in nano seconds
1137  */
1138 u64 _mali_osk_boot_time_get_ns(void);
1139
1140 /** @} */ /* end group _mali_osk_time */
1141
1142 /** @defgroup _mali_osk_math OSK Math
1143  * @{ */
1144
1145 /** @brief Count Leading Zeros (Little-endian)
1146  *
1147  * @note This function must be implemented to support the reference
1148  * implementation of _mali_osk_find_first_zero_bit, as defined in
1149  * mali_osk_bitops.h.
1150  *
1151  * @param val 32-bit words to count leading zeros on
1152  * @return the number of leading zeros.
1153  */
1154 u32 _mali_osk_clz(u32 val);
1155
1156 /** @brief find last (most-significant) bit set
1157  *
1158  * @param val 32-bit words to count last bit set on
1159  * @return last bit set.
1160  */
1161 u32 _mali_osk_fls(u32 val);
1162
1163 /** @} */ /* end group _mali_osk_math */
1164
1165 /** @addtogroup _mali_osk_wait_queue OSK Wait Queue functionality
1166  * @{ */
1167
1168 /** @brief Initialize an empty Wait Queue */
1169 _mali_osk_wait_queue_t *_mali_osk_wait_queue_init(void);
1170
1171 /** @brief Sleep if condition is false
1172  *
1173  * @param queue the queue to use
1174  * @param condition function pointer to a boolean function
1175  * @param data data parameter for condition function
1176  *
1177  * Put thread to sleep if the given \a condition function returns false. When
1178  * being asked to wake up again, the condition will be re-checked and the
1179  * thread only woken up if the condition is now true.
1180  */
1181 void _mali_osk_wait_queue_wait_event(_mali_osk_wait_queue_t *queue, mali_bool(*condition)(void *), void *data);
1182
1183 /** @brief Sleep if condition is false
1184  *
1185  * @param queue the queue to use
1186  * @param condition function pointer to a boolean function
1187  * @param data data parameter for condition function
1188  * @param timeout timeout in ms
1189  *
1190  * Put thread to sleep if the given \a condition function returns false. When
1191  * being asked to wake up again, the condition will be re-checked and the
1192  * thread only woken up if the condition is now true.  Will return if time
1193  * exceeds timeout.
1194  */
1195 void _mali_osk_wait_queue_wait_event_timeout(_mali_osk_wait_queue_t *queue, mali_bool(*condition)(void *), void *data, u32 timeout);
1196
1197 /** @brief Wake up all threads in wait queue if their respective conditions are
1198  * true
1199  *
1200  * @param queue the queue whose threads should be woken up
1201  *
1202  * Wake up all threads in wait queue \a queue whose condition is now true.
1203  */
1204 void _mali_osk_wait_queue_wake_up(_mali_osk_wait_queue_t *queue);
1205
1206 /** @brief terminate a wait queue
1207  *
1208  * @param queue the queue to terminate.
1209  */
1210 void _mali_osk_wait_queue_term(_mali_osk_wait_queue_t *queue);
1211 /** @} */ /* end group _mali_osk_wait_queue */
1212
1213
1214 /** @addtogroup _mali_osk_miscellaneous
1215  * @{ */
1216
1217 /** @brief Output a device driver debug message.
1218  *
1219  * The interpretation of \a fmt is the same as the \c format parameter in
1220  * _mali_osu_vsnprintf().
1221  *
1222  * @param fmt a _mali_osu_vsnprintf() style format string
1223  * @param ... a variable-number of parameters suitable for \a fmt
1224  */
1225 void _mali_osk_dbgmsg(const char *fmt, ...);
1226
1227 /** @brief Print fmt into buf.
1228  *
1229  * The interpretation of \a fmt is the same as the \c format parameter in
1230  * _mali_osu_vsnprintf().
1231  *
1232  * @param buf a pointer to the result buffer
1233  * @param size the total number of bytes allowed to write to \a buf
1234  * @param fmt a _mali_osu_vsnprintf() style format string
1235  * @param ... a variable-number of parameters suitable for \a fmt
1236  * @return The number of bytes written to \a buf
1237  */
1238 u32 _mali_osk_snprintf(char *buf, u32 size, const char *fmt, ...);
1239
1240 /** @brief Print fmt into print_ctx.
1241  *
1242  * The interpretation of \a fmt is the same as the \c format parameter in
1243  * _mali_osu_vsnprintf().
1244  *
1245  * @param print_ctx a pointer to the result file buffer
1246  * @param fmt a _mali_osu_vsnprintf() style format string
1247  * @param ... a variable-number of parameters suitable for \a fmt
1248  */
1249 void _mali_osk_ctxprintf(_mali_osk_print_ctx *print_ctx, const char *fmt, ...);
1250
1251 /** @brief Abnormal process abort.
1252  *
1253  * Terminates the caller-process if this function is called.
1254  *
1255  * This function will be called from Debug assert-macros in mali_kernel_common.h.
1256  *
1257  * This function will never return - because to continue from a Debug assert
1258  * could cause even more problems, and hinder debugging of the initial problem.
1259  *
1260  * This function is only used in Debug builds, and is not used in Release builds.
1261  */
1262 void _mali_osk_abort(void);
1263
1264 /** @brief Sets breakpoint at point where function is called.
1265  *
1266  * This function will be called from Debug assert-macros in mali_kernel_common.h,
1267  * to assist in debugging. If debugging at this level is not required, then this
1268  * function may be implemented as a stub.
1269  *
1270  * This function is only used in Debug builds, and is not used in Release builds.
1271  */
1272 void _mali_osk_break(void);
1273
1274 /** @brief Return an identificator for calling process.
1275  *
1276  * @return Identificator for calling process.
1277  */
1278 u32 _mali_osk_get_pid(void);
1279
1280 /** @brief Return an name for calling process.
1281  *
1282  * @return name for calling process.
1283  */
1284 char *_mali_osk_get_comm(void);
1285
1286 /** @brief Return an identificator for calling thread.
1287  *
1288  * @return Identificator for calling thread.
1289  */
1290 u32 _mali_osk_get_tid(void);
1291
1292
1293 /** @brief Take a reference to the power manager system for the Mali device (synchronously).
1294  *
1295  * When function returns successfully, Mali is ON.
1296  *
1297  * @note Call \a _mali_osk_pm_dev_ref_put() to release this reference.
1298  */
1299 _mali_osk_errcode_t _mali_osk_pm_dev_ref_get_sync(void);
1300
1301 /** @brief Take a reference to the external power manager system for the Mali device (asynchronously).
1302  *
1303  * Mali might not yet be on after this function as returned.
1304  * Please use \a _mali_osk_pm_dev_barrier() or \a _mali_osk_pm_dev_ref_get_sync()
1305  * to wait for Mali to be powered on.
1306  *
1307  * @note Call \a _mali_osk_pm_dev_ref_dec() to release this reference.
1308  */
1309 _mali_osk_errcode_t _mali_osk_pm_dev_ref_get_async(void);
1310
1311 /** @brief Release the reference to the external power manger system for the Mali device.
1312  *
1313  * When reference count reach zero, the cores can be off.
1314  *
1315  * @note This must be used to release references taken with
1316  * \a _mali_osk_pm_dev_ref_get_sync() or \a _mali_osk_pm_dev_ref_get_sync().
1317  */
1318 void _mali_osk_pm_dev_ref_put(void);
1319
1320 /** @brief Block until pending PM operations are done
1321  */
1322 void _mali_osk_pm_dev_barrier(void);
1323
1324 /** @} */ /* end group  _mali_osk_miscellaneous */
1325
1326 /** @} */ /* end group osuapi */
1327
1328 /** @} */ /* end group uddapi */
1329
1330
1331
1332 #ifdef __cplusplus
1333 }
1334 #endif
1335
1336 /* Check standard inlines */
1337 #ifndef MALI_STATIC_INLINE
1338 #error MALI_STATIC_INLINE not defined on your OS
1339 #endif
1340
1341 #ifndef MALI_NON_STATIC_INLINE
1342 #error MALI_NON_STATIC_INLINE not defined on your OS
1343 #endif
1344
1345 #endif /* __MALI_OSK_H__ */