xref: /rk3399_ARM-atf/include/lib/spinlock.h (revision a540c4560b231047360453333fa49202b38d56ef)
1 /*
2  * Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef SPINLOCK_H
8 #define SPINLOCK_H
9 
10 #ifndef __ASSEMBLER__
11 
12 #include <stdbool.h>
13 #include <stdint.h>
14 
15 typedef struct spinlock {
16 	volatile uint32_t lock;
17 } spinlock_t;
18 
19 typedef struct bitlock {
20 	volatile uint8_t lock;
21 } bitlock_t;
22 
23 void spin_lock(spinlock_t *lock);
24 void spin_unlock(spinlock_t *lock);
25 
26 void bit_lock(bitlock_t *lock, uint8_t mask);
27 void bit_unlock(bitlock_t *lock, uint8_t mask);
28 
29 bool spin_trylock(spinlock_t *lock);
30 
31 #else
32 
33 /* Spin lock definitions for use in assembly */
34 #define SPINLOCK_ASM_ALIGN	2
35 #define SPINLOCK_ASM_SIZE	4
36 
37 #endif /* __ASSEMBLER__ */
38 #endif /* SPINLOCK_H */
39