summaryrefslogtreecommitdiff
path: root/drivers/gpu/arm/utgard/common/mali_spinlock_reentrant.h
blob: 6a62df850b2f562b96534057880443191f03183e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * Copyright (C) 2013, 2015 ARM Limited. All rights reserved.
 * 
 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
 * 
 * A copy of the licence is included with the program, and can also be obtained from Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef __MALI_SPINLOCK_REENTRANT_H__
#define __MALI_SPINLOCK_REENTRANT_H__

#include "mali_osk.h"
#include "mali_kernel_common.h"

/**
 * Reentrant spinlock.
 */
struct mali_spinlock_reentrant {
	_mali_osk_spinlock_irq_t *lock;
	u32               owner;
	u32               counter;
};

/**
 * Create a new reentrant spinlock.
 *
 * @param lock_order Lock order.
 * @return New reentrant spinlock.
 */
struct mali_spinlock_reentrant *mali_spinlock_reentrant_init(_mali_osk_lock_order_t lock_order);

/**
 * Terminate reentrant spinlock and free any associated resources.
 *
 * @param spinlock Reentrant spinlock to terminate.
 */
void mali_spinlock_reentrant_term(struct mali_spinlock_reentrant *spinlock);

/**
 * Wait for reentrant spinlock to be signaled.
 *
 * @param spinlock Reentrant spinlock.
 * @param tid Thread ID.
 */
void mali_spinlock_reentrant_wait(struct mali_spinlock_reentrant *spinlock, u32 tid);

/**
 * Signal reentrant spinlock.
 *
 * @param spinlock Reentrant spinlock.
 * @param tid Thread ID.
 */
void mali_spinlock_reentrant_signal(struct mali_spinlock_reentrant *spinlock, u32 tid);

/**
 * Check if thread is holding reentrant spinlock.
 *
 * @param spinlock Reentrant spinlock.
 * @param tid Thread ID.
 * @return MALI_TRUE if thread is holding spinlock, MALI_FALSE if not.
 */
MALI_STATIC_INLINE mali_bool mali_spinlock_reentrant_is_held(struct mali_spinlock_reentrant *spinlock, u32 tid)
{
	MALI_DEBUG_ASSERT_POINTER(spinlock->lock);
	return (tid == spinlock->owner && 0 < spinlock->counter);
}

#endif /* __MALI_SPINLOCK_REENTRANT_H__ */