14ecca339SDan Handley /* 2*86822f24SManish V Badarkhe * Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved. 34ecca339SDan Handley * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 54ecca339SDan Handley */ 64ecca339SDan Handley 7f8b30ca8SAntonio Nino Diaz #ifndef SPINLOCK_H 8f8b30ca8SAntonio Nino Diaz #define SPINLOCK_H 94ecca339SDan Handley 10d5dfdeb6SJulius Werner #ifndef __ASSEMBLER__ 11b38bc68bSJeenu Viswambharan 12*86822f24SManish V Badarkhe #include <stdbool.h> 1393c78ed2SAntonio Nino Diaz #include <stdint.h> 14b38bc68bSJeenu Viswambharan 15fb037bfbSDan Handley typedef struct spinlock { 16b38bc68bSJeenu Viswambharan volatile uint32_t lock; 174ecca339SDan Handley } spinlock_t; 184ecca339SDan Handley 19222f885dSAlexeiFedorov typedef struct bitlock { 20222f885dSAlexeiFedorov volatile uint8_t lock; 21222f885dSAlexeiFedorov } bitlock_t; 22222f885dSAlexeiFedorov 234ecca339SDan Handley void spin_lock(spinlock_t *lock); 244ecca339SDan Handley void spin_unlock(spinlock_t *lock); 254ecca339SDan Handley 26222f885dSAlexeiFedorov void bit_lock(bitlock_t *lock, uint8_t mask); 27222f885dSAlexeiFedorov void bit_unlock(bitlock_t *lock, uint8_t mask); 28222f885dSAlexeiFedorov 29*86822f24SManish V Badarkhe bool spin_trylock(spinlock_t *lock); 30*86822f24SManish V Badarkhe 31b38bc68bSJeenu Viswambharan #else 32b38bc68bSJeenu Viswambharan 33b38bc68bSJeenu Viswambharan /* Spin lock definitions for use in assembly */ 34b38bc68bSJeenu Viswambharan #define SPINLOCK_ASM_ALIGN 2 35b38bc68bSJeenu Viswambharan #define SPINLOCK_ASM_SIZE 4 36b38bc68bSJeenu Viswambharan 37222f885dSAlexeiFedorov #endif /* __ASSEMBLER__ */ 38f8b30ca8SAntonio Nino Diaz #endif /* SPINLOCK_H */ 39