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