mali_spinlock_reentrant.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * This confidential and proprietary software may be used only as
  3. * authorised by a licensing agreement from ARM Limited
  4. * (C) COPYRIGHT 2013 ARM Limited
  5. * ALL RIGHTS RESERVED
  6. * The entire notice above must be reproduced on all authorised
  7. * copies and copies may only be made to the extent permitted
  8. * by a licensing agreement from ARM Limited.
  9. */
  10. #include "mali_spinlock_reentrant.h"
  11. #include "mali_osk.h"
  12. #include "mali_kernel_common.h"
  13. struct mali_spinlock_reentrant *mali_spinlock_reentrant_init(_mali_osk_lock_order_t lock_order)
  14. {
  15. struct mali_spinlock_reentrant *spinlock;
  16. spinlock = _mali_osk_calloc(1, sizeof(struct mali_spinlock_reentrant));
  17. if (NULL == spinlock) {
  18. return NULL;
  19. }
  20. spinlock->lock = _mali_osk_spinlock_irq_init(_MALI_OSK_LOCKFLAG_ORDERED, lock_order);
  21. if (NULL == spinlock->lock) {
  22. mali_spinlock_reentrant_term(spinlock);
  23. return NULL;
  24. }
  25. return spinlock;
  26. }
  27. void mali_spinlock_reentrant_term(struct mali_spinlock_reentrant *spinlock)
  28. {
  29. MALI_DEBUG_ASSERT_POINTER(spinlock);
  30. MALI_DEBUG_ASSERT(0 == spinlock->counter && 0 == spinlock->owner);
  31. if (NULL != spinlock->lock) {
  32. _mali_osk_spinlock_irq_term(spinlock->lock);
  33. }
  34. _mali_osk_free(spinlock);
  35. }
  36. void mali_spinlock_reentrant_wait(struct mali_spinlock_reentrant *spinlock, u32 tid)
  37. {
  38. MALI_DEBUG_ASSERT_POINTER(spinlock);
  39. MALI_DEBUG_ASSERT_POINTER(spinlock->lock);
  40. MALI_DEBUG_ASSERT(0 != tid);
  41. MALI_DEBUG_PRINT(5, ("%s ^\n", __FUNCTION__));
  42. if (tid != spinlock->owner) {
  43. _mali_osk_spinlock_irq_lock(spinlock->lock);
  44. MALI_DEBUG_ASSERT(0 == spinlock->owner && 0 == spinlock->counter);
  45. spinlock->owner = tid;
  46. }
  47. MALI_DEBUG_PRINT(5, ("%s v\n", __FUNCTION__));
  48. ++spinlock->counter;
  49. }
  50. void mali_spinlock_reentrant_signal(struct mali_spinlock_reentrant *spinlock, u32 tid)
  51. {
  52. MALI_DEBUG_ASSERT_POINTER(spinlock);
  53. MALI_DEBUG_ASSERT_POINTER(spinlock->lock);
  54. MALI_DEBUG_ASSERT(0 != tid && tid == spinlock->owner);
  55. --spinlock->counter;
  56. if (0 == spinlock->counter) {
  57. spinlock->owner = 0;
  58. MALI_DEBUG_PRINT(5, ("%s release last\n", __FUNCTION__));
  59. _mali_osk_spinlock_irq_unlock(spinlock->lock);
  60. }
  61. }