Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
AlexeiFedorov | a13f584 | 2024-03-13 12:16:51 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 5 | */ |
6 | |||||
Antonio Nino Diaz | 519248b | 2018-10-31 15:55:57 +0000 | [diff] [blame] | 7 | #ifndef SPINLOCK_H |
8 | #define SPINLOCK_H | ||||
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 9 | |
Julius Werner | 53456fc | 2019-07-09 13:49:11 -0700 | [diff] [blame] | 10 | #ifndef __ASSEMBLER__ |
Jeenu Viswambharan | 54ec86a | 2017-01-19 14:23:36 +0000 | [diff] [blame] | 11 | |
Antonio Nino Diaz | 4b32e62 | 2018-08-16 16:52:57 +0100 | [diff] [blame] | 12 | #include <stdint.h> |
Jeenu Viswambharan | 54ec86a | 2017-01-19 14:23:36 +0000 | [diff] [blame] | 13 | |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 14 | typedef struct spinlock { |
Jeenu Viswambharan | 54ec86a | 2017-01-19 14:23:36 +0000 | [diff] [blame] | 15 | volatile uint32_t lock; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 16 | } spinlock_t; |
17 | |||||
AlexeiFedorov | a13f584 | 2024-03-13 12:16:51 +0000 | [diff] [blame] | 18 | typedef struct bitlock { |
19 | volatile uint8_t lock; | ||||
20 | } bitlock_t; | ||||
21 | |||||
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 22 | void spin_lock(spinlock_t *lock); |
23 | void spin_unlock(spinlock_t *lock); | ||||
24 | |||||
AlexeiFedorov | a13f584 | 2024-03-13 12:16:51 +0000 | [diff] [blame] | 25 | void bit_lock(bitlock_t *lock, uint8_t mask); |
26 | void bit_unlock(bitlock_t *lock, uint8_t mask); | ||||
27 | |||||
Jeenu Viswambharan | 54ec86a | 2017-01-19 14:23:36 +0000 | [diff] [blame] | 28 | #else |
29 | |||||
30 | /* Spin lock definitions for use in assembly */ | ||||
31 | #define SPINLOCK_ASM_ALIGN 2 | ||||
32 | #define SPINLOCK_ASM_SIZE 4 | ||||
33 | |||||
AlexeiFedorov | a13f584 | 2024-03-13 12:16:51 +0000 | [diff] [blame] | 34 | #endif /* __ASSEMBLER__ */ |
Antonio Nino Diaz | 519248b | 2018-10-31 15:55:57 +0000 | [diff] [blame] | 35 | #endif /* SPINLOCK_H */ |