1 /*
2 * Copyright (C) 2013, 2016-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 #ifndef __MALI_SPINLOCK_REENTRANT_H__
12 #define __MALI_SPINLOCK_REENTRANT_H__
13
14 #include "mali_osk.h"
15 #include "mali_kernel_common.h"
16
17 /**
18 * Reentrant spinlock.
19 */
20 struct mali_spinlock_reentrant {
21 _mali_osk_spinlock_irq_t *lock;
22 u32 owner;
23 u32 counter;
24 };
25
26 /**
27 * Create a new reentrant spinlock.
28 *
29 * @param lock_order Lock order.
30 * @return New reentrant spinlock.
31 */
32 struct mali_spinlock_reentrant *mali_spinlock_reentrant_init(_mali_osk_lock_order_t lock_order);
33
34 /**
35 * Terminate reentrant spinlock and free any associated resources.
36 *
37 * @param spinlock Reentrant spinlock to terminate.
38 */
39 void mali_spinlock_reentrant_term(struct mali_spinlock_reentrant *spinlock);
40
41 /**
42 * Wait for reentrant spinlock to be signaled.
43 *
44 * @param spinlock Reentrant spinlock.
45 * @param tid Thread ID.
46 */
47 void mali_spinlock_reentrant_wait(struct mali_spinlock_reentrant *spinlock, u32 tid);
48
49 /**
50 * Signal reentrant spinlock.
51 *
52 * @param spinlock Reentrant spinlock.
53 * @param tid Thread ID.
54 */
55 void mali_spinlock_reentrant_signal(struct mali_spinlock_reentrant *spinlock, u32 tid);
56
57 /**
58 * Check if thread is holding reentrant spinlock.
59 *
60 * @param spinlock Reentrant spinlock.
61 * @param tid Thread ID.
62 * @return MALI_TRUE if thread is holding spinlock, MALI_FALSE if not.
63 */
mali_spinlock_reentrant_is_held(struct mali_spinlock_reentrant * spinlock,u32 tid)64 MALI_STATIC_INLINE mali_bool mali_spinlock_reentrant_is_held(struct mali_spinlock_reentrant *spinlock, u32 tid)
65 {
66 MALI_DEBUG_ASSERT_POINTER(spinlock->lock);
67 return (tid == spinlock->owner && 0 < spinlock->counter);
68 }
69
70 #endif /* __MALI_SPINLOCK_REENTRANT_H__ */
71