PageRenderTime 56ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/gpu/mali/mali/common/mali_osk.h

https://bitbucket.org/ndreys/linux-sunxi
C++ Header | 1798 lines | 249 code | 185 blank | 1364 comment | 3 complexity | 139486b4bafa7eb97ee81909e2759f94 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*
  2. * Copyright (C) 2010-2012 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. * @file mali_osk.h
  12. * Defines the OS abstraction layer for the kernel device driver (OSK)
  13. */
  14. #ifndef __MALI_OSK_H__
  15. #define __MALI_OSK_H__
  16. #ifdef __cplusplus
  17. extern "C"
  18. {
  19. #endif
  20. /**
  21. * @addtogroup uddapi Unified Device Driver (UDD) APIs
  22. *
  23. * @{
  24. */
  25. /**
  26. * @addtogroup oskapi UDD OS Abstraction for Kernel-side (OSK) APIs
  27. *
  28. * @{
  29. */
  30. /** @defgroup _mali_osk_miscellaneous OSK Miscellaneous functions, constants and types
  31. * @{ */
  32. /* Define integer types used by OSK. Note: these currently clash with Linux so we only define them if not defined already */
  33. #ifndef __KERNEL__
  34. typedef unsigned char u8;
  35. typedef signed char s8;
  36. typedef unsigned short u16;
  37. typedef signed short s16;
  38. typedef unsigned int u32;
  39. typedef signed int s32;
  40. typedef unsigned long long u64;
  41. #define BITS_PER_LONG (sizeof(long)*8)
  42. #else
  43. /* Ensure Linux types u32, etc. are defined */
  44. #include <linux/types.h>
  45. #endif
  46. /** @brief Mali Boolean type which uses MALI_TRUE and MALI_FALSE
  47. */
  48. typedef unsigned long mali_bool;
  49. #ifndef MALI_TRUE
  50. #define MALI_TRUE ((mali_bool)1)
  51. #endif
  52. #ifndef MALI_FALSE
  53. #define MALI_FALSE ((mali_bool)0)
  54. #endif
  55. /**
  56. * @brief OSK Error codes
  57. *
  58. * Each OS may use its own set of error codes, and may require that the
  59. * User/Kernel interface take certain error code. This means that the common
  60. * error codes need to be sufficiently rich to pass the correct error code
  61. * thorugh from the OSK to U/K layer, across all OSs.
  62. *
  63. * The result is that some error codes will appear redundant on some OSs.
  64. * Under all OSs, the OSK layer must translate native OS error codes to
  65. * _mali_osk_errcode_t codes. Similarly, the U/K layer must translate from
  66. * _mali_osk_errcode_t codes to native OS error codes.
  67. */
  68. typedef enum
  69. {
  70. _MALI_OSK_ERR_OK = 0, /**< Success. */
  71. _MALI_OSK_ERR_FAULT = -1, /**< General non-success */
  72. _MALI_OSK_ERR_INVALID_FUNC = -2, /**< Invalid function requested through User/Kernel interface (e.g. bad IOCTL number) */
  73. _MALI_OSK_ERR_INVALID_ARGS = -3, /**< Invalid arguments passed through User/Kernel interface */
  74. _MALI_OSK_ERR_NOMEM = -4, /**< Insufficient memory */
  75. _MALI_OSK_ERR_TIMEOUT = -5, /**< Timeout occurred */
  76. _MALI_OSK_ERR_RESTARTSYSCALL = -6, /**< Special: On certain OSs, must report when an interruptable mutex is interrupted. Ignore otherwise. */
  77. _MALI_OSK_ERR_ITEM_NOT_FOUND = -7, /**< Table Lookup failed */
  78. _MALI_OSK_ERR_BUSY = -8, /**< Device/operation is busy. Try again later */
  79. _MALI_OSK_ERR_UNSUPPORTED = -9, /**< Optional part of the interface used, and is unsupported */
  80. } _mali_osk_errcode_t;
  81. /** @} */ /* end group _mali_osk_miscellaneous */
  82. /** @defgroup _mali_osk_irq OSK IRQ handling
  83. * @{ */
  84. /** @brief Private type for IRQ handling objects */
  85. typedef struct _mali_osk_irq_t_struct _mali_osk_irq_t;
  86. /** @brief Optional function to trigger an irq from a resource
  87. *
  88. * This function is implemented by the common layer to allow probing of a resource's IRQ.
  89. * @param arg resource-specific data */
  90. typedef void (*_mali_osk_irq_trigger_t)( void * arg );
  91. /** @brief Optional function to acknowledge an irq from a resource
  92. *
  93. * This function is implemented by the common layer to allow probing of a resource's IRQ.
  94. * @param arg resource-specific data
  95. * @return _MALI_OSK_ERR_OK if the IRQ was successful, or a suitable _mali_osk_errcode_t on failure. */
  96. typedef _mali_osk_errcode_t (*_mali_osk_irq_ack_t)( void * arg );
  97. /** @brief IRQ 'upper-half' handler callback.
  98. *
  99. * This function is implemented by the common layer to do the initial handling of a
  100. * resource's IRQ. This maps on to the concept of an ISR that does the minimum
  101. * work necessary before handing off to an IST.
  102. *
  103. * The communication of the resource-specific data from the ISR to the IST is
  104. * handled by the OSK implementation.
  105. *
  106. * On most systems, the IRQ upper-half handler executes in IRQ context.
  107. * Therefore, the system may have restrictions about what can be done in this
  108. * context
  109. *
  110. * If an IRQ upper-half handler requires more work to be done than can be
  111. * acheived in an IRQ context, then it may defer the work with
  112. * _mali_osk_irq_schedulework(). Refer to \ref _mali_osk_irq_schedulework() for
  113. * more information.
  114. *
  115. * @param arg resource-specific data
  116. * @return _MALI_OSK_ERR_OK if the IRQ was correctly handled, or a suitable
  117. * _mali_osk_errcode_t otherwise.
  118. */
  119. typedef _mali_osk_errcode_t (*_mali_osk_irq_uhandler_t)( void * arg );
  120. /** @brief IRQ 'bottom-half' handler callback.
  121. *
  122. * This function is implemented by the common layer to do the deferred handling
  123. * of a resource's IRQ. Usually, this work cannot be carried out in IRQ context
  124. * by the IRQ upper-half handler.
  125. *
  126. * The IRQ bottom-half handler maps on to the concept of an IST that may
  127. * execute some time after the actual IRQ has fired.
  128. *
  129. * All OSK-registered IRQ bottom-half handlers will be serialized, across all
  130. * CPU-cores in the system.
  131. *
  132. * Refer to \ref _mali_osk_irq_schedulework() for more information on the
  133. * IRQ work-queue, and the calling of the IRQ bottom-half handler.
  134. *
  135. * @param arg resource-specific data
  136. */
  137. typedef void (*_mali_osk_irq_bhandler_t)( void * arg );
  138. /** @} */ /* end group _mali_osk_irq */
  139. /** @defgroup _mali_osk_atomic OSK Atomic counters
  140. * @{ */
  141. /** @brief Public type of atomic counters
  142. *
  143. * This is public for allocation on stack. On systems that support it, this is just a single 32-bit value.
  144. * On others, it could be encapsulating an object stored elsewhere.
  145. *
  146. * Regardless of implementation, the \ref _mali_osk_atomic functions \b must be used
  147. * for all accesses to the variable's value, even if atomicity is not required.
  148. * Do not access u.val or u.obj directly.
  149. */
  150. typedef struct
  151. {
  152. union
  153. {
  154. u32 val;
  155. void *obj;
  156. } u;
  157. } _mali_osk_atomic_t;
  158. /** @} */ /* end group _mali_osk_atomic */
  159. /** @defgroup _mali_osk_lock OSK Mutual Exclusion Locks
  160. * @{ */
  161. /** @brief OSK Mutual Exclusion Lock ordered list
  162. *
  163. * This lists the various types of locks in the system and is used to check
  164. * that locks are taken in the correct order.
  165. *
  166. * Holding more than one lock of the same order at the same time is not
  167. * allowed.
  168. *
  169. */
  170. typedef enum
  171. {
  172. _MALI_OSK_LOCK_ORDER_LAST = 0,
  173. _MALI_OSK_LOCK_ORDER_PM_EXECUTE,
  174. _MALI_OSK_LOCK_ORDER_UTILIZATION,
  175. _MALI_OSK_LOCK_ORDER_L2_COUNTER,
  176. _MALI_OSK_LOCK_ORDER_PROFILING,
  177. _MALI_OSK_LOCK_ORDER_L2_COMMAND,
  178. _MALI_OSK_LOCK_ORDER_PM_CORE_STATE,
  179. _MALI_OSK_LOCK_ORDER_GROUP,
  180. _MALI_OSK_LOCK_ORDER_SCHEDULER,
  181. _MALI_OSK_LOCK_ORDER_DESCRIPTOR_MAP,
  182. _MALI_OSK_LOCK_ORDER_MEM_PT_CACHE,
  183. _MALI_OSK_LOCK_ORDER_MEM_INFO,
  184. _MALI_OSK_LOCK_ORDER_MEM_SESSION,
  185. _MALI_OSK_LOCK_ORDER_SESSIONS,
  186. _MALI_OSK_LOCK_ORDER_FIRST
  187. } _mali_osk_lock_order_t;
  188. /** @brief OSK Mutual Exclusion Lock flags type
  189. *
  190. * Flags are supplied at the point where the Lock is initialized. Each flag can
  191. * be combined with others using bitwise OR, '|'.
  192. *
  193. * The flags must be sufficiently rich to cope with all our OSs. This means
  194. * that on some OSs, certain flags can be completely ignored. We define a
  195. * number of terms that are significant across all OSs:
  196. *
  197. * - Sleeping/non-sleeping mutexs. Sleeping mutexs can block on waiting, and so
  198. * schedule out the current thread. This is significant on OSs where there are
  199. * situations in which the current thread must not be put to sleep. On OSs
  200. * without this restriction, sleeping and non-sleeping mutexes can be treated
  201. * as the same (if that is required).
  202. * - Interruptable/non-interruptable mutexes. For sleeping mutexes, it may be
  203. * possible for the sleep to be interrupted for a reason other than the thread
  204. * being able to obtain the lock. OSs behaving in this way may provide a
  205. * mechanism to control whether sleeping mutexes can be interrupted. On OSs
  206. * that do not support the concept of interruption, \b or they do not support
  207. * control of mutex interruption, then interruptable mutexes may be treated
  208. * as non-interruptable.
  209. *
  210. * Some constrains apply to the lock type flags:
  211. *
  212. * - Spinlocks are by nature, non-interruptable. Hence, they must always be
  213. * combined with the NONINTERRUPTABLE flag, because it is meaningless to ask
  214. * for a spinlock that is interruptable (and this highlights its
  215. * non-interruptable-ness). For example, on certain OSs they should be used when
  216. * you must not sleep.
  217. * - Reader/writer is an optimization hint, and any type of lock can be
  218. * reader/writer. Since this is an optimization hint, the implementation need
  219. * not respect this for any/all types of lock. For example, on certain OSs,
  220. * there's no interruptable reader/writer mutex. If such a thing were requested
  221. * on that OS, the fact that interruptable was requested takes priority over the
  222. * reader/writer-ness, because reader/writer-ness is not necessary for correct
  223. * operation.
  224. * - Any lock can use the order parameter.
  225. * - A onelock is an optimization hint specific to certain OSs. It can be
  226. * specified when it is known that only one lock will be held by the thread,
  227. * and so can provide faster mutual exclusion. This can be safely ignored if
  228. * such optimization is not required/present.
  229. *
  230. * The absence of any flags (the value 0) results in a sleeping-mutex, which is interruptable.
  231. */
  232. typedef enum
  233. {
  234. _MALI_OSK_LOCKFLAG_SPINLOCK = 0x1, /**< Specifically, don't sleep on those architectures that require it */
  235. _MALI_OSK_LOCKFLAG_NONINTERRUPTABLE = 0x2, /**< The mutex cannot be interrupted, e.g. delivery of signals on those architectures where this is required */
  236. _MALI_OSK_LOCKFLAG_READERWRITER = 0x4, /**< Optimise for readers/writers */
  237. _MALI_OSK_LOCKFLAG_ORDERED = 0x8, /**< Use the order parameter; otherwise use automatic ordering */
  238. _MALI_OSK_LOCKFLAG_ONELOCK = 0x10, /**< Each thread can only hold one lock at a time */
  239. _MALI_OSK_LOCKFLAG_SPINLOCK_IRQ = 0x20, /**< IRQ version of spinlock */
  240. /** @enum _mali_osk_lock_flags_t
  241. *
  242. * Flags from 0x10000--0x80000000 are RESERVED for User-mode */
  243. } _mali_osk_lock_flags_t;
  244. /** @brief Mutual Exclusion Lock Mode Optimization hint
  245. *
  246. * The lock mode is used to implement the read/write locking of locks specified
  247. * as _MALI_OSK_LOCKFLAG_READERWRITER. In this case, the RO mode can be used
  248. * to allow multiple concurrent readers, but no writers. The RW mode is used for
  249. * writers, and so will wait for all readers to release the lock (if any present).
  250. * Further readers and writers will wait until the writer releases the lock.
  251. *
  252. * The mode is purely an optimization hint: for example, it is permissible for
  253. * all locks to behave in RW mode, regardless of that supplied.
  254. *
  255. * It is an error to attempt to use locks in anything other that RW mode when
  256. * _MALI_OSK_LOCKFLAG_READERWRITER is not supplied.
  257. *
  258. */
  259. typedef enum
  260. {
  261. _MALI_OSK_LOCKMODE_UNDEF = -1, /**< Undefined lock mode. For internal use only */
  262. _MALI_OSK_LOCKMODE_RW = 0x0, /**< Read-write mode, default. All readers and writers are mutually-exclusive */
  263. _MALI_OSK_LOCKMODE_RO, /**< Read-only mode, to support multiple concurrent readers, but mutual exclusion in the presence of writers. */
  264. /** @enum _mali_osk_lock_mode_t
  265. *
  266. * Lock modes 0x40--0x7F are RESERVED for User-mode */
  267. } _mali_osk_lock_mode_t;
  268. /** @brief Private type for Mutual Exclusion lock objects */
  269. typedef struct _mali_osk_lock_t_struct _mali_osk_lock_t;
  270. #ifdef DEBUG
  271. /** @brief Macro for asserting that the current thread holds a given lock
  272. */
  273. #define MALI_DEBUG_ASSERT_LOCK_HELD(l) MALI_DEBUG_ASSERT(_mali_osk_lock_get_owner(l) == _mali_osk_get_tid());
  274. /** @brief returns a lock's owner (thread id) if debugging is enabled
  275. */
  276. u32 _mali_osk_lock_get_owner( _mali_osk_lock_t *lock );
  277. #endif
  278. /** @} */ /* end group _mali_osk_lock */
  279. /** @defgroup _mali_osk_low_level_memory OSK Low-level Memory Operations
  280. * @{ */
  281. /**
  282. * @brief Private data type for use in IO accesses to/from devices.
  283. *
  284. * This represents some range that is accessible from the device. Examples
  285. * include:
  286. * - Device Registers, which could be readable and/or writeable.
  287. * - Memory that the device has access to, for storing configuration structures.
  288. *
  289. * Access to this range must be made through the _mali_osk_mem_ioread32() and
  290. * _mali_osk_mem_iowrite32() functions.
  291. */
  292. typedef struct _mali_io_address * mali_io_address;
  293. /** @defgroup _MALI_OSK_CPU_PAGE CPU Physical page size macros.
  294. *
  295. * The order of the page size is supplied for
  296. * ease of use by algorithms that might require it, since it is easier to know
  297. * it ahead of time rather than calculating it.
  298. *
  299. * The Mali Page Mask macro masks off the lower bits of a physical address to
  300. * give the start address of the page for that physical address.
  301. *
  302. * @note The Mali device driver code is designed for systems with 4KB page size.
  303. * Changing these macros will not make the entire Mali device driver work with
  304. * page sizes other than 4KB.
  305. *
  306. * @note The CPU Physical Page Size has been assumed to be the same as the Mali
  307. * Physical Page Size.
  308. *
  309. * @{
  310. */
  311. /** CPU Page Order, as log to base 2 of the Page size. @see _MALI_OSK_CPU_PAGE_SIZE */
  312. #define _MALI_OSK_CPU_PAGE_ORDER ((u32)12)
  313. /** CPU Page Size, in bytes. */
  314. #define _MALI_OSK_CPU_PAGE_SIZE (((u32)1) << (_MALI_OSK_CPU_PAGE_ORDER))
  315. /** CPU Page Mask, which masks off the offset within a page */
  316. #define _MALI_OSK_CPU_PAGE_MASK (~((((u32)1) << (_MALI_OSK_CPU_PAGE_ORDER)) - ((u32)1)))
  317. /** @} */ /* end of group _MALI_OSK_CPU_PAGE */
  318. /** @defgroup _MALI_OSK_MALI_PAGE Mali Physical Page size macros
  319. *
  320. * Mali Physical page size macros. The order of the page size is supplied for
  321. * ease of use by algorithms that might require it, since it is easier to know
  322. * it ahead of time rather than calculating it.
  323. *
  324. * The Mali Page Mask macro masks off the lower bits of a physical address to
  325. * give the start address of the page for that physical address.
  326. *
  327. * @note The Mali device driver code is designed for systems with 4KB page size.
  328. * Changing these macros will not make the entire Mali device driver work with
  329. * page sizes other than 4KB.
  330. *
  331. * @note The Mali Physical Page Size has been assumed to be the same as the CPU
  332. * Physical Page Size.
  333. *
  334. * @{
  335. */
  336. /** Mali Page Order, as log to base 2 of the Page size. @see _MALI_OSK_MALI_PAGE_SIZE */
  337. #define _MALI_OSK_MALI_PAGE_ORDER ((u32)12)
  338. /** Mali Page Size, in bytes. */
  339. #define _MALI_OSK_MALI_PAGE_SIZE (((u32)1) << (_MALI_OSK_MALI_PAGE_ORDER))
  340. /** Mali Page Mask, which masks off the offset within a page */
  341. #define _MALI_OSK_MALI_PAGE_MASK (~((((u32)1) << (_MALI_OSK_MALI_PAGE_ORDER)) - ((u32)1)))
  342. /** @} */ /* end of group _MALI_OSK_MALI_PAGE*/
  343. /** @brief flags for mapping a user-accessible memory range
  344. *
  345. * Where a function with prefix '_mali_osk_mem_mapregion' accepts flags as one
  346. * of the function parameters, it will use one of these. These allow per-page
  347. * control over mappings. Compare with the mali_memory_allocation_flag type,
  348. * which acts over an entire range
  349. *
  350. * These may be OR'd together with bitwise OR (|), but must be cast back into
  351. * the type after OR'ing.
  352. */
  353. typedef enum
  354. {
  355. _MALI_OSK_MEM_MAPREGION_FLAG_OS_ALLOCATED_PHYSADDR = 0x1, /**< Physical address is OS Allocated */
  356. } _mali_osk_mem_mapregion_flags_t;
  357. /** @} */ /* end group _mali_osk_low_level_memory */
  358. /** @defgroup _mali_osk_notification OSK Notification Queues
  359. * @{ */
  360. /** @brief Private type for notification queue objects */
  361. typedef struct _mali_osk_notification_queue_t_struct _mali_osk_notification_queue_t;
  362. /** @brief Public notification data object type */
  363. typedef struct _mali_osk_notification_t_struct
  364. {
  365. u32 notification_type; /**< The notification type */
  366. u32 result_buffer_size; /**< Size of the result buffer to copy to user space */
  367. void * result_buffer; /**< Buffer containing any type specific data */
  368. } _mali_osk_notification_t;
  369. /** @} */ /* end group _mali_osk_notification */
  370. /** @defgroup _mali_osk_timer OSK Timer Callbacks
  371. * @{ */
  372. /** @brief Function to call when a timer expires
  373. *
  374. * When a timer expires, this function is called. Note that on many systems,
  375. * a timer callback will be executed in IRQ context. Therefore, restrictions
  376. * may apply on what can be done inside the timer callback.
  377. *
  378. * If a timer requires more work to be done than can be acheived in an IRQ
  379. * context, then it may defer the work with a work-queue. For example, it may
  380. * use \ref _mali_osk_irq_schedulework() to make use of the IRQ bottom-half handler
  381. * to carry out the remaining work.
  382. *
  383. * Stopping the timer with \ref _mali_osk_timer_del() blocks on compeletion of
  384. * the callback. Therefore, the callback may not obtain any mutexes also held
  385. * by any callers of _mali_osk_timer_del(). Otherwise, a deadlock may occur.
  386. *
  387. * @param arg Function-specific data */
  388. typedef void (*_mali_osk_timer_callback_t)(void * arg );
  389. /** @brief Private type for Timer Callback Objects */
  390. typedef struct _mali_osk_timer_t_struct _mali_osk_timer_t;
  391. /** @} */ /* end group _mali_osk_timer */
  392. /** @addtogroup _mali_osk_list OSK Doubly-Linked Circular Lists
  393. * @{ */
  394. /** @brief Public List objects.
  395. *
  396. * To use, add a _mali_osk_list_t member to the structure that may become part
  397. * of a list. When traversing the _mali_osk_list_t objects, use the
  398. * _MALI_OSK_CONTAINER_OF() macro to recover the structure from its
  399. *_mali_osk_list_t member
  400. *
  401. * Each structure may have multiple _mali_osk_list_t members, so that the
  402. * structure is part of multiple lists. When traversing lists, ensure that the
  403. * correct _mali_osk_list_t member is used, because type-checking will be
  404. * lost by the compiler.
  405. */
  406. typedef struct _mali_osk_list_s
  407. {
  408. struct _mali_osk_list_s *next;
  409. struct _mali_osk_list_s *prev;
  410. } _mali_osk_list_t;
  411. /** @brief Initialize a list to be a head of an empty list
  412. * @param exp the list to initialize. */
  413. #define _MALI_OSK_INIT_LIST_HEAD(exp) _mali_osk_list_init(exp)
  414. /** @brief Define a list variable, which is uninitialized.
  415. * @param exp the name of the variable that the list will be defined as. */
  416. #define _MALI_OSK_LIST_HEAD(exp) _mali_osk_list_t exp
  417. /** @brief Find the containing structure of another structure
  418. *
  419. * This is the reverse of the operation 'offsetof'. This means that the
  420. * following condition is satisfied:
  421. *
  422. * ptr == _MALI_OSK_CONTAINER_OF( &ptr->member, type, member )
  423. *
  424. * When ptr is of type 'type'.
  425. *
  426. * Its purpose it to recover a larger structure that has wrapped a smaller one.
  427. *
  428. * @note no type or memory checking occurs to ensure that a wrapper structure
  429. * does in fact exist, and that it is being recovered with respect to the
  430. * correct member.
  431. *
  432. * @param ptr the pointer to the member that is contained within the larger
  433. * structure
  434. * @param type the type of the structure that contains the member
  435. * @param member the name of the member in the structure that ptr points to.
  436. * @return a pointer to a \a type object which contains \a member, as pointed
  437. * to by \a ptr.
  438. */
  439. #define _MALI_OSK_CONTAINER_OF(ptr, type, member) \
  440. ((type *)( ((char *)ptr) - offsetof(type,member) ))
  441. /** @brief Find the containing structure of a list
  442. *
  443. * When traversing a list, this is used to recover the containing structure,
  444. * given that is contains a _mali_osk_list_t member.
  445. *
  446. * Each list must be of structures of one type, and must link the same members
  447. * together, otherwise it will not be possible to correctly recover the
  448. * sturctures that the lists link.
  449. *
  450. * @note no type or memory checking occurs to ensure that a structure does in
  451. * fact exist for the list entry, and that it is being recovered with respect
  452. * to the correct list member.
  453. *
  454. * @param ptr the pointer to the _mali_osk_list_t member in this structure
  455. * @param type the type of the structure that contains the member
  456. * @param member the member of the structure that ptr points to.
  457. * @return a pointer to a \a type object which contains the _mali_osk_list_t
  458. * \a member, as pointed to by the _mali_osk_list_t \a *ptr.
  459. */
  460. #define _MALI_OSK_LIST_ENTRY(ptr, type, member) \
  461. _MALI_OSK_CONTAINER_OF(ptr, type, member)
  462. /** @brief Enumerate a list safely
  463. *
  464. * With this macro, lists can be enumerated in a 'safe' manner. That is,
  465. * entries can be deleted from the list without causing an error during
  466. * enumeration. To achieve this, a 'temporary' pointer is required, which must
  467. * be provided to the macro.
  468. *
  469. * Use it like a 'for()', 'while()' or 'do()' construct, and so it must be
  470. * followed by a statement or compound-statement which will be executed for
  471. * each list entry.
  472. *
  473. * Upon loop completion, providing that an early out was not taken in the
  474. * loop body, then it is guaranteed that ptr->member == list, even if the loop
  475. * body never executed.
  476. *
  477. * @param ptr a pointer to an object of type 'type', which points to the
  478. * structure that contains the currently enumerated list entry.
  479. * @param tmp a pointer to an object of type 'type', which must not be used
  480. * inside the list-execution statement.
  481. * @param list a pointer to a _mali_osk_list_t, from which enumeration will
  482. * begin
  483. * @param type the type of the structure that contains the _mali_osk_list_t
  484. * member that is part of the list to be enumerated.
  485. * @param member the _mali_osk_list_t member of the structure that is part of
  486. * the list to be enumerated.
  487. */
  488. #define _MALI_OSK_LIST_FOREACHENTRY(ptr, tmp, list, type, member) \
  489. for (ptr = _MALI_OSK_LIST_ENTRY((list)->next, type, member), \
  490. tmp = _MALI_OSK_LIST_ENTRY(ptr->member.next, type, member); \
  491. &ptr->member != (list); \
  492. ptr = tmp, tmp = _MALI_OSK_LIST_ENTRY(tmp->member.next, type, member))
  493. /** @} */ /* end group _mali_osk_list */
  494. /** @addtogroup _mali_osk_miscellaneous
  495. * @{ */
  496. /** @brief The known resource types
  497. *
  498. * @note \b IMPORTANT: these must remain fixed, and only be extended. This is
  499. * because not all systems use a header file for reading in their resources.
  500. * The resources may instead come from a data file where these resources are
  501. * 'hard-coded' in, because there's no easy way of transferring the enum values
  502. * into such data files. E.g. the C-Pre-processor does \em not process enums.
  503. */
  504. typedef enum _mali_osk_resource_type
  505. {
  506. RESOURCE_TYPE_FIRST =0, /**< Duplicate resource marker for the first resource*/
  507. MEMORY =0, /**< Physically contiguous memory block, not managed by the OS */
  508. OS_MEMORY =1, /**< Memory managed by and shared with the OS */
  509. MALI_PP =2, /**< Mali Pixel Processor core */
  510. MALI450PP =2, /**< Compatibility option */
  511. MALI400PP =2, /**< Compatibility option */
  512. MALI300PP =2, /**< Compatibility option */
  513. MALI200 =2, /**< Compatibility option */
  514. MALI_GP =3, /**< Mali Geometry Processor core */
  515. MALI450GP =3, /**< Compatibility option */
  516. MALI400GP =3, /**< Compatibility option */
  517. MALI300GP =3, /**< Compatibility option */
  518. MALIGP2 =3, /**< Compatibility option */
  519. MMU =4, /**< Mali MMU (Memory Management Unit) */
  520. FPGA_FRAMEWORK =5, /**< Mali registers specific to FPGA implementations */
  521. MALI_L2 =6, /**< Mali Level 2 cache core */
  522. MALI450L2 =6, /**< Compatibility option */
  523. MALI400L2 =6, /**< Compatibility option */
  524. MALI300L2 =6, /**< Compatibility option */
  525. MEM_VALIDATION =7, /**< External Memory Validator */
  526. PMU =8, /**< Power Manangement Unit */
  527. RESOURCE_TYPE_COUNT /**< The total number of known resources */
  528. } _mali_osk_resource_type_t;
  529. /** @brief resource description struct
  530. *
  531. * _mali_osk_resources_init() will enumerate objects of this type. Not all
  532. * members have a valid meaning across all types.
  533. *
  534. * The mmu_id is used to group resources to a certain MMU, since there may be
  535. * more than one MMU in the system, and each resource may be using a different
  536. * MMU:
  537. * - For MMU resources, the setting of mmu_id is a uniquely identifying number.
  538. * - For Other resources, the setting of mmu_id determines which MMU the
  539. * resource uses.
  540. */
  541. typedef struct _mali_osk_resource
  542. {
  543. _mali_osk_resource_type_t type; /**< type of the resource */
  544. const char * description; /**< short description of the resource */
  545. u32 base; /**< Physical base address of the resource, as seen by Mali resources. */
  546. s32 cpu_usage_adjust; /**< Offset added to the base address of the resource to arrive at the CPU physical address of the resource (if different from the Mali physical address) */
  547. u32 size; /**< Size in bytes of the resource - either the size of its register range, or the size of the memory block. */
  548. u32 irq; /**< IRQ number delivered to the CPU, or -1 to tell the driver to probe for it (if possible) */
  549. u32 flags; /**< Resources-specific flags. */
  550. u32 mmu_id; /**< Identifier for Mali MMU resources. */
  551. u32 alloc_order; /**< Order in which MEMORY/OS_MEMORY resources are used */
  552. } _mali_osk_resource_t;
  553. /** @} */ /* end group _mali_osk_miscellaneous */
  554. #include "mali_kernel_memory_engine.h" /* include for mali_memory_allocation and mali_physical_memory_allocation type */
  555. /** @addtogroup _mali_osk_irq
  556. * @{ */
  557. /** @brief Fake IRQ number for testing purposes
  558. */
  559. #define _MALI_OSK_IRQ_NUMBER_FAKE ((u32)0xFFFFFFF1)
  560. /** @addtogroup _mali_osk_irq
  561. * @{ */
  562. /** @brief PMM Virtual IRQ number
  563. */
  564. #define _MALI_OSK_IRQ_NUMBER_PMM ((u32)0xFFFFFFF2)
  565. /** @brief Initialize IRQ handling for a resource
  566. *
  567. * The _mali_osk_irq_t returned must be written into the resource-specific data
  568. * pointed to by data. This is so that the upper and lower handlers can call
  569. * _mali_osk_irq_schedulework().
  570. *
  571. * @note The caller must ensure that the resource does not generate an
  572. * interrupt after _mali_osk_irq_init() finishes, and before the
  573. * _mali_osk_irq_t is written into the resource-specific data. Otherwise,
  574. * the upper-half handler will fail to call _mali_osk_irq_schedulework().
  575. *
  576. * @param irqnum The IRQ number that the resource uses, as seen by the CPU.
  577. * The value -1 has a special meaning which indicates the use of probing, and trigger_func and ack_func must be
  578. * non-NULL.
  579. * @param uhandler The upper-half handler, corresponding to a ISR handler for
  580. * the resource
  581. * @param bhandler The lower-half handler, corresponding to an IST handler for
  582. * the resource
  583. * @param trigger_func Optional: a function to trigger the resource's irq, to
  584. * probe for the interrupt. Use NULL if irqnum != -1.
  585. * @param ack_func Optional: a function to acknowledge the resource's irq, to
  586. * probe for the interrupt. Use NULL if irqnum != -1.
  587. * @param data resource-specific data, which will be passed to uhandler,
  588. * bhandler and (if present) trigger_func and ack_funnc
  589. * @param description textual description of the IRQ resource.
  590. * @return on success, a pointer to a _mali_osk_irq_t object, which represents
  591. * the IRQ handling on this resource. NULL on failure.
  592. */
  593. _mali_osk_irq_t *_mali_osk_irq_init( u32 irqnum, _mali_osk_irq_uhandler_t uhandler, _mali_osk_irq_bhandler_t bhandler, _mali_osk_irq_trigger_t trigger_func, _mali_osk_irq_ack_t ack_func, void *data, const char *description );
  594. /** @brief Cause a queued, deferred call of the IRQ bottom-half.
  595. *
  596. * _mali_osk_irq_schedulework provides a mechanism for enqueuing deferred calls
  597. * to the IRQ bottom-half handler. The queue is known as the IRQ work-queue.
  598. * After calling _mali_osk_irq_schedulework(), the IRQ bottom-half handler will
  599. * be scheduled to run at some point in the future.
  600. *
  601. * This is called by the IRQ upper-half to defer further processing of
  602. * IRQ-related work to the IRQ bottom-half handler. This is necessary for work
  603. * that cannot be done in an IRQ context by the IRQ upper-half handler. Timer
  604. * callbacks also use this mechanism, because they are treated as though they
  605. * operate in an IRQ context. Refer to \ref _mali_osk_timer_t for more
  606. * information.
  607. *
  608. * Code that operates in a kernel-process context (with no IRQ context
  609. * restrictions) may also enqueue deferred calls to the IRQ bottom-half. The
  610. * advantage over direct calling is that deferred calling allows the caller and
  611. * IRQ bottom half to hold the same mutex, with a guarantee that they will not
  612. * deadlock just by using this mechanism.
  613. *
  614. * _mali_osk_irq_schedulework() places deferred call requests on a queue, to
  615. * allow for more than one thread to make a deferred call. Therfore, if it is
  616. * called 'K' times, then the IRQ bottom-half will be scheduled 'K' times too.
  617. * 'K' is a number that is implementation-specific.
  618. *
  619. * _mali_osk_irq_schedulework() is guaranteed to not block on:
  620. * - enqueuing a deferred call request.
  621. * - the completion of the IRQ bottom-half handler.
  622. *
  623. * This is to prevent deadlock. For example, if _mali_osk_irq_schedulework()
  624. * blocked, then it would cause a deadlock when the following two conditions
  625. * hold:
  626. * - The IRQ bottom-half callback (of type _mali_osk_irq_bhandler_t) locks
  627. * a mutex
  628. * - And, at the same time, the caller of _mali_osk_irq_schedulework() also
  629. * holds the same mutex
  630. *
  631. * @note care must be taken to not overflow the queue that
  632. * _mali_osk_irq_schedulework() operates on. Code must be structured to
  633. * ensure that the number of requests made to the queue is bounded. Otherwise,
  634. * IRQs will be lost.
  635. *
  636. * The queue that _mali_osk_irq_schedulework implements is a FIFO of N-writer,
  637. * 1-reader type. The writers are the callers of _mali_osk_irq_schedulework
  638. * (all OSK-registered IRQ upper-half handlers in the system, watchdog timers,
  639. * callers from a Kernel-process context). The reader is a single thread that
  640. * handles all OSK-registered IRQs.
  641. *
  642. * The consequence of the queue being a 1-reader type is that calling
  643. * _mali_osk_irq_schedulework() on different _mali_osk_irq_t objects causes
  644. * their IRQ bottom-halves to be serialized, across all CPU-cores in the
  645. * system.
  646. *
  647. * @param irq a pointer to the _mali_osk_irq_t object corresponding to the
  648. * resource whose IRQ bottom-half must begin processing.
  649. */
  650. void _mali_osk_irq_schedulework( _mali_osk_irq_t *irq );
  651. /** @brief Terminate IRQ handling on a resource.
  652. *
  653. * This will disable the interrupt from the device, and then waits for the
  654. * IRQ work-queue to finish the work that is currently in the queue. That is,
  655. * for every deferred call currently in the IRQ work-queue, it waits for each
  656. * of those to be processed by their respective IRQ bottom-half handler.
  657. *
  658. * This function is used to ensure that the bottom-half handler of the supplied
  659. * IRQ object will not be running at the completion of this function call.
  660. * However, the caller must ensure that no other sources could call the
  661. * _mali_osk_irq_schedulework() on the same IRQ object. For example, the
  662. * relevant timers must be stopped.
  663. *
  664. * @note While this function is being called, other OSK-registered IRQs in the
  665. * system may enqueue work for their respective bottom-half handlers. This
  666. * function will not wait for those entries in the work-queue to be flushed.
  667. *
  668. * Since this blocks on the completion of work in the IRQ work-queue, the
  669. * caller of this function \b must \b not hold any mutexes that are taken by
  670. * any OSK-registered IRQ bottom-half handler. To do so may cause a deadlock.
  671. *
  672. * @param irq a pointer to the _mali_osk_irq_t object corresponding to the
  673. * resource whose IRQ handling is to be terminated.
  674. */
  675. void _mali_osk_irq_term( _mali_osk_irq_t *irq );
  676. /** @brief flushing workqueue.
  677. *
  678. * This will flush the workqueue.
  679. *
  680. * @param irq a pointer to the _mali_osk_irq_t object corresponding to the
  681. * resource whose IRQ handling is to be terminated.
  682. */
  683. void _mali_osk_flush_workqueue( _mali_osk_irq_t *irq );
  684. /** @} */ /* end group _mali_osk_irq */
  685. /** @addtogroup _mali_osk_atomic
  686. * @{ */
  687. /** @brief Decrement an atomic counter
  688. *
  689. * @note It is an error to decrement the counter beyond -(1<<23)
  690. *
  691. * @param atom pointer to an atomic counter */
  692. void _mali_osk_atomic_dec( _mali_osk_atomic_t *atom );
  693. /** @brief Decrement an atomic counter, return new value
  694. *
  695. * @param atom pointer to an atomic counter
  696. * @return The new value, after decrement */
  697. u32 _mali_osk_atomic_dec_return( _mali_osk_atomic_t *atom );
  698. /** @brief Increment an atomic counter
  699. *
  700. * @note It is an error to increment the counter beyond (1<<23)-1
  701. *
  702. * @param atom pointer to an atomic counter */
  703. void _mali_osk_atomic_inc( _mali_osk_atomic_t *atom );
  704. /** @brief Increment an atomic counter, return new value
  705. *
  706. * @param atom pointer to an atomic counter */
  707. u32 _mali_osk_atomic_inc_return( _mali_osk_atomic_t *atom );
  708. /** @brief Initialize an atomic counter
  709. *
  710. * @note the parameter required is a u32, and so signed integers should be
  711. * cast to u32.
  712. *
  713. * @param atom pointer to an atomic counter
  714. * @param val the value to initialize the atomic counter.
  715. * @return _MALI_OSK_ERR_OK on success, otherwise, a suitable
  716. * _mali_osk_errcode_t on failure.
  717. */
  718. _mali_osk_errcode_t _mali_osk_atomic_init( _mali_osk_atomic_t *atom, u32 val );
  719. /** @brief Read a value from an atomic counter
  720. *
  721. * This can only be safely used to determine the value of the counter when it
  722. * is guaranteed that other threads will not be modifying the counter. This
  723. * makes its usefulness limited.
  724. *
  725. * @param atom pointer to an atomic counter
  726. */
  727. u32 _mali_osk_atomic_read( _mali_osk_atomic_t *atom );
  728. /** @brief Terminate an atomic counter
  729. *
  730. * @param atom pointer to an atomic counter
  731. */
  732. void _mali_osk_atomic_term( _mali_osk_atomic_t *atom );
  733. /** @} */ /* end group _mali_osk_atomic */
  734. /** @defgroup _mali_osk_memory OSK Memory Allocation
  735. * @{ */
  736. /** @brief Allocate zero-initialized memory.
  737. *
  738. * Returns a buffer capable of containing at least \a n elements of \a size
  739. * bytes each. The buffer is initialized to zero.
  740. *
  741. * If there is a need for a bigger block of memory (16KB or bigger), then
  742. * consider to use _mali_osk_vmalloc() instead, as this function might
  743. * map down to a OS function with size limitations.
  744. *
  745. * The buffer is suitably aligned for storage and subsequent access of every
  746. * type that the compiler supports. Therefore, the pointer to the start of the
  747. * buffer may be cast into any pointer type, and be subsequently accessed from
  748. * such a pointer, without loss of information.
  749. *
  750. * When the buffer is no longer in use, it must be freed with _mali_osk_free().
  751. * Failure to do so will cause a memory leak.
  752. *
  753. * @note Most toolchains supply memory allocation functions that meet the
  754. * compiler's alignment requirements.
  755. *
  756. * @param n Number of elements to allocate
  757. * @param size Size of each element
  758. * @return On success, the zero-initialized buffer allocated. NULL on failure
  759. */
  760. void *_mali_osk_calloc( u32 n, u32 size );
  761. /** @brief Allocate memory.
  762. *
  763. * Returns a buffer capable of containing at least \a size bytes. The
  764. * contents of the buffer are undefined.
  765. *
  766. * If there is a need for a bigger block of memory (16KB or bigger), then
  767. * consider to use _mali_osk_vmalloc() instead, as this function might
  768. * map down to a OS function with size limitations.
  769. *
  770. * The buffer is suitably aligned for storage and subsequent access of every
  771. * type that the compiler supports. Therefore, the pointer to the start of the
  772. * buffer may be cast into any pointer type, and be subsequently accessed from
  773. * such a pointer, without loss of information.
  774. *
  775. * When the buffer is no longer in use, it must be freed with _mali_osk_free().
  776. * Failure to do so will cause a memory leak.
  777. *
  778. * @note Most toolchains supply memory allocation functions that meet the
  779. * compiler's alignment requirements.
  780. *
  781. * Remember to free memory using _mali_osk_free().
  782. * @param size Number of bytes to allocate
  783. * @return On success, the buffer allocated. NULL on failure.
  784. */
  785. void *_mali_osk_malloc( u32 size );
  786. /** @brief Free memory.
  787. *
  788. * Reclaims the buffer pointed to by the parameter \a ptr for the system.
  789. * All memory returned from _mali_osk_malloc() and _mali_osk_calloc()
  790. * must be freed before the application exits. Otherwise,
  791. * a memory leak will occur.
  792. *
  793. * Memory must be freed once. It is an error to free the same non-NULL pointer
  794. * more than once.
  795. *
  796. * It is legal to free the NULL pointer.
  797. *
  798. * @param ptr Pointer to buffer to free
  799. */
  800. void _mali_osk_free( void *ptr );
  801. /** @brief Allocate memory.
  802. *
  803. * Returns a buffer capable of containing at least \a size bytes. The
  804. * contents of the buffer are undefined.
  805. *
  806. * This function is potentially slower than _mali_osk_malloc() and _mali_osk_calloc(),
  807. * but do support bigger sizes.
  808. *
  809. * The buffer is suitably aligned for storage and subsequent access of every
  810. * type that the compiler supports. Therefore, the pointer to the start of the
  811. * buffer may be cast into any pointer type, and be subsequently accessed from
  812. * such a pointer, without loss of information.
  813. *
  814. * When the buffer is no longer in use, it must be freed with _mali_osk_free().
  815. * Failure to do so will cause a memory leak.
  816. *
  817. * @note Most toolchains supply memory allocation functions that meet the
  818. * compiler's alignment requirements.
  819. *
  820. * Remember to free memory using _mali_osk_free().
  821. * @param size Number of bytes to allocate
  822. * @return On success, the buffer allocated. NULL on failure.
  823. */
  824. void *_mali_osk_valloc( u32 size );
  825. /** @brief Free memory.
  826. *
  827. * Reclaims the buffer pointed to by the parameter \a ptr for the system.
  828. * All memory returned from _mali_osk_valloc() must be freed before the
  829. * application exits. Otherwise a memory leak will occur.
  830. *
  831. * Memory must be freed once. It is an error to free the same non-NULL pointer
  832. * more than once.
  833. *
  834. * It is legal to free the NULL pointer.
  835. *
  836. * @param ptr Pointer to buffer to free
  837. */
  838. void _mali_osk_vfree( void *ptr );
  839. /** @brief Copies memory.
  840. *
  841. * Copies the \a len bytes from the buffer pointed by the parameter \a src
  842. * directly to the buffer pointed by \a dst.
  843. *
  844. * It is an error for \a src to overlap \a dst anywhere in \a len bytes.
  845. *
  846. * @param dst Pointer to the destination array where the content is to be
  847. * copied.
  848. * @param src Pointer to the source of data to be copied.
  849. * @param len Number of bytes to copy.
  850. * @return \a dst is always passed through unmodified.
  851. */
  852. void *_mali_osk_memcpy( void *dst, const void *src, u32 len );
  853. /** @brief Fills memory.
  854. *
  855. * Sets the first \a n bytes of the block of memory pointed to by \a s to
  856. * the specified value
  857. * @param s Pointer to the block of memory to fill.
  858. * @param c Value to be set, passed as u32. Only the 8 Least Significant Bits (LSB)
  859. * are used.
  860. * @param n Number of bytes to be set to the value.
  861. * @return \a s is always passed through unmodified
  862. */
  863. void *_mali_osk_memset( void *s, u32 c, u32 n );
  864. /** @} */ /* end group _mali_osk_memory */
  865. /** @brief Checks the amount of memory allocated
  866. *
  867. * Checks that not more than \a max_allocated bytes are allocated.
  868. *
  869. * Some OS bring up an interactive out of memory dialogue when the
  870. * system runs out of memory. This can stall non-interactive
  871. * apps (e.g. automated test runs). This function can be used to
  872. * not trigger the OOM dialogue by keeping allocations
  873. * within a certain limit.
  874. *
  875. * @return MALI_TRUE when \a max_allocated bytes are not in use yet. MALI_FALSE
  876. * when at least \a max_allocated bytes are in use.
  877. */
  878. mali_bool _mali_osk_mem_check_allocated( u32 max_allocated );
  879. /** @addtogroup _mali_osk_lock
  880. * @{ */
  881. /** @brief Initialize a Mutual Exclusion Lock
  882. *
  883. * Locks are created in the signalled (unlocked) state.
  884. *
  885. * initial must be zero, since there is currently no means of expressing
  886. * whether a reader/writer lock should be initially locked as a reader or
  887. * writer. This would require some encoding to be used.
  888. *
  889. * 'Automatic' ordering means that locks must be obtained in the order that
  890. * they were created. For all locks that can be held at the same time, they must
  891. * either all provide the order parameter, or they all must use 'automatic'
  892. * ordering - because there is no way of mixing 'automatic' and 'manual'
  893. * ordering.
  894. *
  895. * @param flags flags combined with bitwise OR ('|'), or zero. There are
  896. * restrictions on which flags can be combined, @see _mali_osk_lock_flags_t.
  897. * @param initial For future expansion into semaphores. SBZ.
  898. * @param order The locking order of the mutex. That is, locks obtained by the
  899. * same thread must have been created with an increasing order parameter, for
  900. * deadlock prevention. Setting to zero causes 'automatic' ordering to be used.
  901. * @return On success, a pointer to a _mali_osk_lock_t object. NULL on failure.
  902. */
  903. _mali_osk_lock_t *_mali_osk_lock_init( _mali_osk_lock_flags_t flags, u32 initial, u32 order );
  904. /** @brief Wait for a lock to be signalled (obtained)
  905. * After a thread has successfully waited on the lock, the lock is obtained by
  906. * the thread, and is marked as unsignalled. The thread releases the lock by
  907. * signalling it.
  908. *
  909. * In the case of Reader/Writer locks, multiple readers can obtain a lock in
  910. * the absence of writers, which is a performance optimization (providing that
  911. * the readers never write to the protected resource).
  912. *
  913. * To prevent deadlock, locks must always be obtained in the same order.
  914. *
  915. * For locks marked as _MALI_OSK_LOCKFLAG_NONINTERRUPTABLE, it is a
  916. * programming error for the function to exit without obtaining the lock. This
  917. * means that the error code must only be checked for interruptible locks.
  918. *
  919. * @param lock the lock to wait upon (obtain).
  920. * @param mode the mode in which the lock should be obtained. Unless the lock
  921. * was created with _MALI_OSK_LOCKFLAG_READERWRITER, this must be
  922. * _MALI_OSK_LOCKMODE_RW.
  923. * @return On success, _MALI_OSK_ERR_OK. For interruptible locks, a suitable
  924. * _mali_osk_errcode_t will be returned on failure, and the lock will not be
  925. * obtained. In this case, the error code must be propagated up to the U/K
  926. * interface.
  927. */
  928. _mali_osk_errcode_t _mali_osk_lock_wait( _mali_osk_lock_t *lock, _mali_osk_lock_mode_t mode);
  929. /** @brief Signal (release) a lock
  930. *
  931. * Locks may only be signalled by the thread that originally waited upon the
  932. * lock.
  933. *
  934. * @note In the OSU, a flag exists to allow any thread to signal a
  935. * lock. Such functionality is not present in the OSK.
  936. *
  937. * @param lock the lock to signal (release).
  938. * @param mode the mode in which the lock should be obtained. This must match
  939. * the mode in which the lock was waited upon.
  940. */
  941. void _mali_osk_lock_signal( _mali_osk_lock_t *lock, _mali_osk_lock_mode_t mode );
  942. /** @brief Terminate a lock
  943. *
  944. * This terminates a lock and frees all associated resources.
  945. *
  946. * It is a programming error to terminate the lock when it is held (unsignalled)
  947. * by a thread.
  948. *
  949. * @param lock the lock to terminate.
  950. */
  951. void _mali_osk_lock_term( _mali_osk_lock_t *lock );
  952. /** @} */ /* end group _mali_osk_lock */
  953. /** @addtogroup _mali_osk_low_level_memory
  954. * @{ */
  955. /** @brief Issue a memory barrier
  956. *
  957. * This defines an arbitrary memory barrier operation, which forces an ordering constraint
  958. * on memory read and write operations.
  959. */
  960. void _mali_osk_mem_barrier( void );
  961. /** @brief Issue a write memory barrier
  962. *
  963. * This defines an write memory barrier operation which forces an ordering constraint
  964. * on memory write operations.
  965. */
  966. void _mali_osk_write_mem_barrier( void );
  967. /** @brief Map a physically contiguous region into kernel space
  968. *
  969. * This is primarily used for mapping in registers from resources, and Mali-MMU
  970. * page tables. The mapping is only visable from kernel-space.
  971. *
  972. * Access has to go through _mali_osk_mem_ioread32 and _mali_osk_mem_iowrite32
  973. *
  974. * @param phys CPU-physical base address of the memory to map in. This must
  975. * be aligned to the system's page size, which is assumed to be 4K.
  976. * @param size the number of bytes of physically contiguous address space to
  977. * map in
  978. * @param description A textual description of the memory being mapped in.
  979. * @return On success, a Mali IO address through which the mapped-in
  980. * memory/registers can be accessed. NULL on failure.
  981. */
  982. mali_io_address _mali_osk_mem_mapioregion( u32 phys, u32 size, const char *description );
  983. /** @brief Unmap a physically contiguous address range from kernel space.
  984. *
  985. * The address range should be one previously mapped in through
  986. * _mali_osk_mem_mapioregion.
  987. *
  988. * It is a programming error to do (but not limited to) the following:
  989. * - attempt an unmap twice
  990. * - unmap only part of a range obtained through _mali_osk_mem_mapioregion
  991. * - unmap more than the range obtained through _mali_osk_mem_mapioregion
  992. * - unmap an address range that was not successfully mapped using
  993. * _mali_osk_mem_mapioregion
  994. * - provide a mapping that does not map to phys.
  995. *
  996. * @param phys CPU-physical base address of the memory that was originally
  997. * mapped in. This must be aligned to the system's page size, which is assumed
  998. * to be 4K
  999. * @param size The number of bytes that were originally mapped in.
  1000. * @param mapping The Mali IO address through which the mapping is
  1001. * accessed.
  1002. */
  1003. void _mali_osk_mem_unmapioregion( u32 phys, u32 size, mali_io_address mapping );
  1004. /** @brief Allocate and Map a physically contiguous region into kernel space
  1005. *
  1006. * This is used for allocating physically contiguous regions (such as Mali-MMU
  1007. * page tables) and mapping them into kernel space. The mapping is only
  1008. * visible from kernel-space.
  1009. *
  1010. * The alignment of the returned memory is guaranteed to be at least
  1011. * _MALI_OSK_CPU_PAGE_SIZE.
  1012. *
  1013. * Access must go through _mali_osk_mem_ioread32 and _mali_osk_mem_iowrite32
  1014. *
  1015. * @note This function is primarily to provide support for OSs that are
  1016. * incapable of separating the tasks 'allocate physically contiguous memory'
  1017. * and 'map it into kernel space'
  1018. *
  1019. * @param[out] phys CPU-physical base address of memory that was allocated.
  1020. * (*phys) will be guaranteed to be aligned to at least
  1021. * _MALI_OSK_CPU_PAGE_SIZE on success.
  1022. *
  1023. * @param[in] size the number of bytes of physically contiguous memory to
  1024. * allocate. This must be a multiple of _MALI_OSK_CPU_PAGE_SIZE.
  1025. *
  1026. * @return On success, a Mali IO address through which the mapped-in
  1027. * memory/registers can be accessed. NULL on failure, and (*phys) is unmodified.
  1028. */
  1029. mali_io_address _mali_osk_mem_allocioregion( u32 *phys, u32 size );
  1030. /** @brief Free a physically contiguous address range from kernel space.
  1031. *
  1032. * The address range should be one previously mapped in through
  1033. * _mali_osk_mem_allocioregion.
  1034. *
  1035. * It is a programming error to do (but not limited to) the following:
  1036. * - attempt a free twice on the same ioregion
  1037. * - free only part of a range obtained through _mali_osk_mem_allocioregion
  1038. * - free more than the range obtained through _mali_osk_mem_allocioregion
  1039. * - free an address range that was not successfully mapped using
  1040. * _mali_osk_mem_allocioregion
  1041. * - provide a mapping that does not map to phys.
  1042. *
  1043. * @param phys CPU-physical base address of the memory that was originally
  1044. * mapped in, which was aligned to _MALI_OSK_CPU_PAGE_SIZE.
  1045. * @param size The number of bytes that were originally mapped in, which was
  1046. * a multiple of _MALI_OSK_CPU_PAGE_SIZE.
  1047. * @param mapping The Mali IO address through which the mapping is
  1048. * accessed.
  1049. */
  1050. void _mali_osk_mem_freeioregion( u32 phys, u32 size, mali_io_address mapping );
  1051. /** @brief Request a region of physically contiguous memory
  1052. *
  1053. * This is used to ensure exclusive access to a region of physically contigous
  1054. * memory.
  1055. *
  1056. * It is acceptable to implement this as a stub. However, it is then the job
  1057. * of the System Integrator to ensure that no other device driver will be using
  1058. * the physical address ranges used by Mali, while the Mali device driver is
  1059. * loaded.
  1060. *
  1061. * @param phys CPU-physical base address of the memory to request. This must
  1062. * be aligned to the system's page size, which is assumed to be 4K.
  1063. * @param size the number of bytes of physically contiguous address space to
  1064. * request.
  1065. * @param description A textual description of the memory being requested.
  1066. * @return _MALI_OSK_ERR_OK on success. Otherwise, a suitable
  1067. * _mali_osk_errcode_t on failure.
  1068. */
  1069. _mali_osk_errcode_t _mali_osk_mem_reqregion( u32 phys, u32 size, const char *description );
  1070. /** @brief Un-request a region of physically contiguous memory
  1071. *
  1072. * This is used to release a regious of physically contiguous memory previously
  1073. * requested through _mali_osk_mem_reqregion, so that other device drivers may
  1074. * use it. This will be called at time of Mali device driver termination.
  1075. *
  1076. * It is a programming error to attempt to:
  1077. * - unrequest a region twice
  1078. * - unrequest only part of a range obtained through _mali_osk_mem_reqregion
  1079. * - unrequest more than the range obtained through _mali_osk_mem_reqregion
  1080. * - unrequest an address range that was not successfully requested using
  1081. * _mali_osk_mem_reqregion
  1082. *
  1083. * @param phys CPU-physical base address of the memory to un-request. This must
  1084. * be aligned to the system's page size, which is assumed to be 4K
  1085. * @param size the number of bytes of physically contiguous address space to
  1086. * un-request.
  1087. */
  1088. void _mali_osk_mem_unreqregion( u32 phys, u32 size );
  1089. /** @brief Read from a location currently mapped in through
  1090. * _mali_osk_mem_mapioregion
  1091. *
  1092. * This reads a 32-bit word from a 32-bit aligned location. It is a programming
  1093. * error to provide unaligned locations, or to read from memory that is not
  1094. * mapped in, or not mapped through either _mali_osk_mem_mapioregion() or
  1095. * _mali_osk_mem_allocioregion().
  1096. *
  1097. * @param mapping Mali IO address to read from
  1098. * @param offset Byte offset from the given IO address to operate on, must be a multiple of 4
  1099. * @return the 32-bit word from the specified location.
  1100. */
  1101. u32 _mali_osk_mem_ioread32( volatile mali_io_address mapping, u32 offset );
  1102. /** @brief Write to a location currently mapped in through
  1103. * _mali_osk_mem_mapioregion without memory barriers
  1104. *
  1105. * This write a 32-bit word to a 32-bit aligned location without using memory barrier.
  1106. * It is a programming error to provide unaligned locations, or to write to memory that is not
  1107. * mapped in, or not mapped through either _mali_osk_mem_mapioregion() or
  1108. * _mali_osk_mem_allocioregion().
  1109. *
  1110. * @param mapping Mali IO address to write to
  1111. * @param offset Byte offset from the given IO address to operate on, must be a multiple of 4
  1112. * @param val the 32-bit word to write.
  1113. */
  1114. void _mali_osk_mem_iowrite32_relaxed( volatile mali_io_address addr, u32 offset, u32 val );
  1115. /** @brief Write to a location currently mapped in through
  1116. * _mali_osk_mem_mapioregion with write memory barrier
  1117. *
  1118. * This write a 32-bit word to a 32-bit aligned location. It is a programming
  1119. * error to provide unaligned locations, or to write to memory that is not
  1120. * mapped in, or not mapped through either _mali_osk_mem_mapioregion() or
  1121. * _mali_osk_mem_allocioregion().
  1122. *
  1123. * @param mapping Mali IO address to write to
  1124. * @param offset Byte offset from the given IO address to operate on, must be a multiple of 4
  1125. * @param val the 32-bit word to write.
  1126. */
  1127. void _mali_osk_mem_iowrite32( volatile mali_io_address mapping, u32 offset, u32 val );
  1128. /** @brief Flush all CPU caches
  1129. *
  1130. * This should only be implemented if flushing of the cache is required for
  1131. * memory mapped in through _mali_osk_mem_mapregion.
  1132. */
  1133. void _mali_osk_cache_flushall( void );
  1134. /** @brief Flush any caches necessary for the CPU and MALI to have the same view of a range of uncached mapped memory
  1135. *
  1136. * This should only be implemented if your OS doesn't do a full cache flush (inner & outer)
  1137. * after allocating uncached mapped memory.
  1138. *
  1139. * Some OS do not perform a full cache flush (including all outer caches) for uncached mapped memory.
  1140. * They zero the memory through a cached mapping, then flush the inner caches but not the outer caches.
  1141. * This is required for MALI to have the correct view of the memory.
  1142. */
  1143. void _mali_osk_cache_ensure_uncached_range_flushed( void *uncached_mapping, u32 offset, u32 size );
  1144. /** @} */ /* end group _mali_osk_low_level_memory */
  1145. /** @addtogroup _mali_osk_notification
  1146. *
  1147. * User space notification framework
  1148. *
  1149. * Communication with user space of asynchronous events is performed through a
  1150. * synchronous call to the \ref u_k_api.
  1151. *
  1152. * Since the events are asynchronous, the events have to be queued until a
  1153. * synchronous U/K API call can be made by user-space. A U/K API call might also
  1154. * be received before any event has happened. Therefore the notifications the
  1155. * different subsystems wants to send to user space has to be queued for later
  1156. * reception, or a U/K API call has to be blocked until an event has occured.
  1157. *
  1158. * Typical uses of notifications are after running of jobs on the hardware or
  1159. * when changes to the system is detected that needs to be relayed to user
  1160. * space.
  1161. *
  1162. * After an event has occured user space has to be notified using some kind of
  1163. * message. The notification framework supports sending messages to waiting
  1164. * threads or queueing of messages until a U/K API call is made.
  1165. *
  1166. * The notification queue is a FIFO. There are no restrictions on the numbers
  1167. * of readers or writers in the queue.
  1168. *
  1169. * A message contains what user space needs to identifiy how to handle an
  1170. * event. This includes a type field and a possible type specific payload.
  1171. *
  1172. * A notification to user space is represented by a
  1173. * \ref _mali_osk_notification_t object. A sender gets hold of such an object
  1174. * using _mali_osk_notification_create(). The buffer given by the
  1175. * _mali_osk_notification_t::result_buffer field in the object is used to store
  1176. * any type specific data. The other fields are internal to the queue system
  1177. * and should not be touched.
  1178. *
  1179. * @{ */
  1180. /** @brief Create a notification object
  1181. *
  1182. * Returns a notification object which can be added to the queue of
  1183. * notifications pending for user space transfer.
  1184. *
  1185. * The implementation will initialize all members of the
  1186. * \ref _mali_osk_notification_t object. In particular, the
  1187. * _mali_osk_notification_t::result_buffer member will be initialized to point
  1188. * to \a size bytes of storage, and that storage will be suitably aligned for
  1189. * storage of any structure. That is, the created buffer meets the same
  1190. * requirements as _mali_osk_malloc().
  1191. *
  1192. * The notification object must be deleted when not in use. Use
  1193. * _mali_osk_notification_delete() for deleting it.
  1194. *
  1195. * @note You \b must \b not call _mali_osk_free() on a \ref _mali_osk_notification_t,
  1196. * object, or on a _mali_osk_notification_t::result_buffer. You must only use
  1197. * _mali_osk_notification_delete() to free the resources assocaited with a
  1198. * \ref _mali_osk_notification_t object.
  1199. *
  1200. * @param type The notification type
  1201. * @param size The size of the type specific buffer to send
  1202. * @return Pointer to a notification object with a suitable buffer, or NULL on error.
  1203. */
  1204. _mali_osk_notification_t *_mali_osk_notification_create( u32 type, u32 size );
  1205. /** @brief Delete a notification object
  1206. *
  1207. * This must be called to reclaim the resources of a notification object. This
  1208. * includes:
  1209. * - The _mali_osk_notification_t::result_buffer
  1210. * - The \ref _mali_osk_notification_t itself.
  1211. *
  1212. * A notification object \b must \b not be used after it has been deleted by
  1213. * _mali_osk_notification_delete().
  1214. *
  1215. * In addition, the notification object may not be deleted while it is in a
  1216. * queue. That is, if it has been placed on a queue with
  1217. * _mali_osk_notification_queue_send(), then it must not be deleted until
  1218. * it has been received by a call to _mali_osk_notification_queue_receive().
  1219. * Otherwise, the queue may be corrupted.
  1220. *
  1221. * @param object the notification object to delete.
  1222. */
  1223. void _mali_osk_notification_delete( _mali_osk_notification_t *object );
  1224. /** @brief Create a notification queue
  1225. *
  1226. * Creates a notification queue which can be used to queue messages for user
  1227. * delivery and get queued messages from
  1228. *
  1229. * The queue is a FIFO, and has no restrictions on the numbers of readers or
  1230. * writers.
  1231. *
  1232. * When the queue is no longer in use, it must be terminated with
  1233. * \ref _mali_osk_notification_queue_term(). Failure to do so will result in a
  1234. * memory leak.
  1235. *
  1236. * @return Pointer to a new notification queue or NULL on error.
  1237. */
  1238. _mali_osk_notification_queue_t *_mali_osk_notification_queue_init( void );
  1239. /** @brief Destroy a notification queue
  1240. *
  1241. * Destroys a notification queue and frees associated resources from the queue.
  1242. *
  1243. * A notification queue \b must \b not be destroyed in the following cases:
  1244. * - while there are \ref _mali_osk_notification_t objects in the queue.
  1245. * - while there are writers currently acting upon the queue. That is, while
  1246. * a thread is currently calling \ref _mali_osk_notification_queue_send() on
  1247. * the queue, or while a thread may call
  1248. * \ref _mali_osk_notification_queue_send() on the queue in the future.
  1249. * - while there are readers currently waiting upon the queue. That is, while
  1250. * a thread is currently calling \ref _mali_osk_notification_queue_receive() on
  1251. * the queue, or while a thread may call
  1252. * \ref _mali_osk_notification_queue_receive() on the queue in the future.
  1253. *
  1254. * Therefore, all \ref _mali_osk_notification_t objects must be flushed and
  1255. * deleted by the code that makes use of the notification queues, since only
  1256. * they know the structure of the _mali_osk_notification_t::result_buffer
  1257. * (even if it may only be a flat sturcture).
  1258. *
  1259. * @note Since the queue is a FIFO, the code using notification queues may
  1260. * create its own 'flush' type of notification, to assist in flushing the
  1261. * queue.
  1262. *
  1263. * Once the queue has been destroyed, it must not be used again.
  1264. *
  1265. * @param queue The queue to destroy
  1266. */
  1267. void _mali_osk_notification_queue_term( _mali_osk_notification_queue_t *queue );
  1268. /** @brief Schedule notification for delivery
  1269. *
  1270. * When a \ref _mali_osk_notification_t object has been created successfully
  1271. * and set up, it may be added to the queue of objects waiting for user space
  1272. * transfer.
  1273. *
  1274. * The sending will not block if the queue is full.
  1275. *
  1276. * A \ref _mali_osk_notification_t object \b must \b not be put on two different
  1277. * queues at the same time, or enqueued twice onto a single queue before
  1278. * reception. However, it is acceptable for it to be requeued \em after reception
  1279. * from a call to _mali_osk_notification_queue_receive(), even onto the same queue.
  1280. *
  1281. * Again, requeuing must also not enqueue onto two different queues at the same
  1282. * time, or enqueue onto the same queue twice before reception.
  1283. *
  1284. * @param queue The notification queue to add this notification to
  1285. * @param object The entry to add
  1286. */
  1287. void _mali_osk_notification_queue_send( _mali_osk_notification_queue_t *queue, _mali_osk_notification_t *object );
  1288. #if MALI_STATE_TRACKING
  1289. /** @brief Receive a notification from a queue
  1290. *
  1291. * Check if a notification queue is empty.
  1292. *
  1293. * @param queue The queue to check.
  1294. * @return MALI_TRUE if queue is empty, otherwise MALI_FALSE.
  1295. */
  1296. mali_bool _mali_osk_notification_queue_is_empty( _mali_osk_notification_queue_t *queue );
  1297. #endif
  1298. /** @brief Receive a notification from a queue
  1299. *
  1300. * Receives a single notification from the given queue.
  1301. *
  1302. * If no notifciations are ready the thread will sleep until one becomes ready.
  1303. * Therefore, notifications may not be received into an
  1304. * IRQ or 'atomic' context (that is, a context where sleeping is disallowed).
  1305. *
  1306. * @param queue The queue to receive from
  1307. * @param result Pointer to storage of a pointer of type
  1308. * \ref _mali_osk_notification_t*. \a result will be written to such that the
  1309. * expression \a (*result) will evaluate to a pointer to a valid
  1310. * \ref _mali_osk_notification_t object, or NULL if none were received.
  1311. * @return _MALI_OSK_ERR_OK on success. _MALI_OSK_ERR_RESTARTSYSCALL if the sleep was interrupted.
  1312. */
  1313. _mali_osk_errcode_t _mali_osk_notification_queue_receive( _mali_osk_notification_queue_t *queue, _mali_osk_notification_t **result );
  1314. /** @brief Dequeues a notification from a queue
  1315. *
  1316. * Receives a single notification from the given queue.
  1317. *
  1318. * If no notifciations are ready the function call will return an error code.
  1319. *
  1320. * @param queue The queue to receive from
  1321. * @param result Pointer to storage of a pointer of type
  1322. * \ref _mali_osk_notification_t*. \a result will be written to such that the
  1323. * expression \a (*result) will evaluate to a pointer to a valid
  1324. * \ref _mali_osk_notification_t object, or NULL if none were received.
  1325. * @return _MALI_OSK_ERR_OK on success, _MALI_OSK_ERR_ITEM_NOT_FOUND if queue was empty.
  1326. */
  1327. _mali_osk_errcode_t _mali_osk_notification_queue_dequeue( _mali_osk_notification_queue_t *queue, _mali_osk_notification_t **result );
  1328. /** @} */ /* end group _mali_osk_notification */
  1329. /** @addtogroup _mali_osk_timer
  1330. *
  1331. * Timers use the OS's representation of time, which are 'ticks'. This is to
  1332. * prevent aliasing problems between the internal timer time, and the time
  1333. * asked for.
  1334. *
  1335. * @{ */
  1336. /** @brief Initialize a timer
  1337. *
  1338. * Allocates resources for a new timer, and initializes them. This does not
  1339. * start the timer.
  1340. *
  1341. * @return a pointer to the allocated timer object, or NULL on failure.
  1342. */
  1343. _mali_osk_timer_t *_mali_osk_timer_init(void);
  1344. /** @brief Start a timer
  1345. *
  1346. * It is an error to start a timer without setting the callback via
  1347. * _mali_osk_timer_setcallback().
  1348. *
  1349. * It is an error to use this to start an already started timer.
  1350. *
  1351. * The timer will expire in \a ticks_to_expire ticks, at which point, the
  1352. * callback function will be invoked with the callback-specific data,
  1353. * as registered by _mali_osk_timer_setcallback().
  1354. *
  1355. * @param tim the timer to start
  1356. * @param ticks_to_expire the amount of time in ticks for the timer to run
  1357. * before triggering.
  1358. */
  1359. void _mali_osk_timer_add( _mali_osk_timer_t *tim, u32 ticks_to_expire );
  1360. /** @brief Modify a timer
  1361. *
  1362. * Set the absolute time at which a timer will expire, and start it if it is
  1363. * stopped. If \a expiry_tick is in the past (determined by
  1364. * _mali_osk_time_after() ), the timer fires immediately.
  1365. *
  1366. * It is an error to modify a timer without setting the callback via
  1367. * _mali_osk_timer_setcallback().
  1368. *
  1369. * The timer will expire at absolute time \a expiry_tick, at which point, the
  1370. * callback function will be invoked with the callback-specific data, as set
  1371. * by _mali_osk_timer_setcallback().
  1372. *
  1373. * @param tim the timer to modify, and start if necessary
  1374. * @param expiry_tick the \em absolute time in ticks at which this timer should
  1375. * trigger.
  1376. *
  1377. */
  1378. void _mali_osk_timer_mod( _mali_osk_timer_t *tim, u32 expiry_tick);
  1379. /** @brief Stop a timer, and block on its completion.
  1380. *
  1381. * Stop the timer. When the function returns, it is guaranteed that the timer's
  1382. * callback will not be running on any CPU core.
  1383. *
  1384. * Since stoping the timer blocks on compeletion of the callback, the callback
  1385. * may not obtain any mutexes that the caller holds. Otherwise, a deadlock will
  1386. * occur.
  1387. *
  1388. * @note While the callback itself is guaranteed to not be running, work
  1389. * enqueued on the IRQ work-queue by the timer (with
  1390. * \ref _mali_osk_irq_schedulework()) may still run. The timer callback and IRQ
  1391. * bottom-half handler must take this into account.
  1392. *
  1393. * It is legal to stop an already stopped timer.
  1394. *
  1395. * @param tim the timer to stop.
  1396. *
  1397. */
  1398. void _mali_osk_timer_del( _mali_osk_timer_t *tim );
  1399. /** @brief Set a timer's callback parameters.
  1400. *
  1401. * This must be called at least once before a timer is started/modified.
  1402. *
  1403. * After a timer has been stopped or expires, the callback remains set. This
  1404. * means that restarting the timer will call the same function with the same
  1405. * parameters on expiry.
  1406. *
  1407. * @param tim the timer to set callback on.
  1408. * @param callback Function to call when timer expires
  1409. * @param data Function-specific data to supply to the function on expiry.
  1410. */
  1411. void _mali_osk_timer_setcallback( _mali_osk_timer_t *tim, _mali_osk_timer_callback_t callback, void *data );
  1412. /** @brief Terminate a timer, and deallocate resources.
  1413. *
  1414. * The timer must first be stopped by calling _mali_osk_timer_del().
  1415. *
  1416. * It is a programming error for _mali_osk_timer_term() to be called on:
  1417. * - timer that is currently running
  1418. * - a timer that is currently executing its callback.
  1419. *
  1420. * @param tim the timer to deallocate.
  1421. */
  1422. void _mali_osk_timer_term( _mali_osk_timer_t *tim );
  1423. /** @} */ /* end group _mali_osk_timer */
  1424. /** @defgroup _mali_osk_time OSK Time functions
  1425. *
  1426. * \ref _mali_osk_time use the OS's representation of time, which are
  1427. * 'ticks'. This is to prevent aliasing problems between the internal timer
  1428. * time, and the time asked for.
  1429. *
  1430. * OS tick time is measured as a u32. The time stored in a u32 may either be
  1431. * an absolute time, or a time delta between two events. Whilst it is valid to
  1432. * use math opeartors to \em change the tick value represented as a u32, it
  1433. * is often only meaningful to do such operations on time deltas, rather than
  1434. * on absolute time. However, it is meaningful to add/subtract time deltas to
  1435. * absolute times.
  1436. *
  1437. * Conversion between tick time and milliseconds (ms) may not be loss-less,
  1438. * and are \em implementation \em depenedant.
  1439. *
  1440. * Code use OS time must take this into account, since:
  1441. * - a small OS time may (or may not) be rounded
  1442. * - a large time may (or may not) overflow
  1443. *
  1444. * @{ */
  1445. /** @brief Return whether ticka occurs after tickb
  1446. *
  1447. * Some OSs handle tick 'rollover' specially, and so can be more robust against
  1448. * tick counters rolling-over. This function must therefore be called to
  1449. * determine if a time (in ticks) really occurs after another time (in ticks).
  1450. *
  1451. * @param ticka ticka
  1452. * @param tickb tickb
  1453. * @return non-zero if ticka represents a time that occurs after tickb.
  1454. * Zero otherwise.
  1455. */
  1456. int _mali_osk_time_after( u32 ticka, u32 tickb );
  1457. /** @brief Convert milliseconds to OS 'ticks'
  1458. *
  1459. * @param ms time interval in milliseconds
  1460. * @return the corresponding time interval in OS ticks.
  1461. */
  1462. u32 _mali_osk_time_mstoticks( u32 ms );
  1463. /** @brief Convert OS 'ticks' to milliseconds
  1464. *
  1465. * @param ticks time interval in OS ticks.
  1466. * @return the corresponding time interval in milliseconds
  1467. */
  1468. u32 _mali_osk_time_tickstoms( u32 ticks );
  1469. /** @brief Get the current time in OS 'ticks'.
  1470. * @return the current time in OS 'ticks'.
  1471. */
  1472. u32 _mali_osk_time_tickcount( void );
  1473. /** @brief Cause a microsecond delay
  1474. *
  1475. * The delay will have microsecond resolution, and is necessary for correct
  1476. * operation of the driver. At worst, the delay will be \b at least \a usecs
  1477. * microseconds, and so may be (significantly) more.
  1478. *
  1479. * This function may be implemented as a busy-wait, which is the most sensible
  1480. * implementation. On OSs where there are situations in which a thread must not
  1481. * sleep, this is definitely implemented as a busy-wait.
  1482. *
  1483. * @param usecs the number of microseconds to wait for.
  1484. */
  1485. void _mali_osk_time_ubusydelay( u32 usecs );
  1486. /** @brief Return time in nano seconds, since any given reference.
  1487. *
  1488. * @return Time in nano seconds
  1489. */
  1490. u64 _mali_osk_time_get_ns( void );
  1491. /** @} */ /* end group _mali_osk_time */
  1492. /** @defgroup _mali_osk_math OSK Math
  1493. * @{ */
  1494. /** @brief Count Leading Zeros (Little-endian)
  1495. *
  1496. * @note This function must be implemented to support the reference
  1497. * implementation of _mali_osk_find_first_zero_bit, as defined in
  1498. * mali_osk_bitops.h.
  1499. *
  1500. * @param val 32-bit words to count leading zeros on
  1501. * @return the number of leading zeros.
  1502. */
  1503. u32 _mali_osk_clz( u32 val );
  1504. /** @} */ /* end group _mali_osk_math */
  1505. /** @defgroup _mali_osk_wait_queue OSK Wait Queue functionality
  1506. * @{ */
  1507. /** @brief Private type for wait queue objects */
  1508. typedef struct _mali_osk_wait_queue_t_struct _mali_osk_wait_queue_t;
  1509. /** @brief Initialize an empty Wait Queue */
  1510. _mali_osk_wait_queue_t* _mali_osk_wait_queue_init( void );
  1511. /** @brief Sleep if condition is false
  1512. *
  1513. * @param queue the queue to use
  1514. * @param condition function pointer to a boolean function
  1515. *
  1516. * Put thread to sleep if the given \a codition function returns false. When
  1517. * being asked to wake up again, the condition will be re-checked and the
  1518. * thread only woken up if the condition is now true.
  1519. */
  1520. void _mali_osk_wait_queue_wait_event( _mali_osk_wait_queue_t *queue, mali_bool (*condition)(void) );
  1521. /** @brief Wake up all threads in wait queue if their respective conditions are
  1522. * true
  1523. *
  1524. * @param queue the queue whose threads should be woken up
  1525. *
  1526. * Wake up all threads in wait queue \a queue whose condition is now true.
  1527. */
  1528. void _mali_osk_wait_queue_wake_up( _mali_osk_wait_queue_t *queue );
  1529. /** @brief terminate a wait queue
  1530. *
  1531. * @param queue the queue to terminate.
  1532. */
  1533. void _mali_osk_wait_queue_term( _mali_osk_wait_queue_t *queue );
  1534. /** @} */ /* end group _mali_osk_wait_queue */
  1535. /** @addtogroup _mali_osk_miscellaneous
  1536. * @{ */
  1537. /** @brief Output a device driver debug message.
  1538. *
  1539. * The interpretation of \a fmt is the same as the \c format parameter in
  1540. * _mali_osu_vsnprintf().
  1541. *
  1542. * @param fmt a _mali_osu_vsnprintf() style format string
  1543. * @param ... a variable-number of parameters suitable for \a fmt
  1544. */
  1545. void _mali_osk_dbgmsg( const char *fmt, ... );
  1546. /** @brief Print fmt into buf.
  1547. *
  1548. * The interpretation of \a fmt is the same as the \c format parameter in
  1549. * _mali_osu_vsnprintf().
  1550. *
  1551. * @param buf a pointer to the result buffer
  1552. * @param size the total number of bytes allowed to write to \a buf
  1553. * @param fmt a _mali_osu_vsnprintf() style format string
  1554. * @param ... a variable-number of parameters suitable for \a fmt
  1555. * @return The number of bytes written to \a buf
  1556. */
  1557. u32 _mali_osk_snprintf( char *buf, u32 size, const char *fmt, ... );
  1558. /** @brief Abnormal process abort.
  1559. *
  1560. * Terminates the caller-process if this function is called.
  1561. *
  1562. * This function will be called from Debug assert-macros in mali_kernel_common.h.
  1563. *
  1564. * This function will never return - because to continue from a Debug assert
  1565. * could cause even more problems, and hinder debugging of the initial problem.
  1566. *
  1567. * This function is only used in Debug builds, and is not used in Release builds.
  1568. */
  1569. void _mali_osk_abort(void);
  1570. /** @brief Sets breakpoint at point where function is called.
  1571. *
  1572. * This function will be called from Debug assert-macros in mali_kernel_common.h,
  1573. * to assist in debugging. If debugging at this level is not required, then this
  1574. * function may be implemented as a stub.
  1575. *
  1576. * This function is only used in Debug builds, and is not used in Release builds.
  1577. */
  1578. void _mali_osk_break(void);
  1579. /** @brief Return an identificator for calling process.
  1580. *
  1581. * @return Identificator for calling process.
  1582. */
  1583. u32 _mali_osk_get_pid(void);
  1584. /** @brief Return an identificator for calling thread.
  1585. *
  1586. * @return Identificator for calling thread.
  1587. */
  1588. u32 _mali_osk_get_tid(void);
  1589. /** @brief Enable OS controlled runtime power management
  1590. */
  1591. void _mali_osk_pm_dev_enable(void);
  1592. /** @brief Tells the OS that device is now idle
  1593. */
  1594. _mali_osk_errcode_t _mali_osk_pm_dev_idle(void);
  1595. /** @brief Tells the OS that the device is about to become active
  1596. */
  1597. _mali_osk_errcode_t _mali_osk_pm_dev_activate(void);
  1598. /** @} */ /* end group _mali_osk_miscellaneous */
  1599. /** @} */ /* end group osuapi */
  1600. /** @} */ /* end group uddapi */
  1601. #ifdef __cplusplus
  1602. }
  1603. #endif
  1604. #include "mali_osk_specific.h" /* include any per-os specifics */
  1605. /* Check standard inlines */
  1606. #ifndef MALI_STATIC_INLINE
  1607. #error MALI_STATIC_INLINE not defined on your OS
  1608. #endif
  1609. #ifndef MALI_NON_STATIC_INLINE
  1610. #error MALI_NON_STATIC_INLINE not defined on your OS
  1611. #endif
  1612. #endif /* __MALI_OSK_H__ */