blob: 055a911d08ef4ed033956ff9abb93a18bebdae2e [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
AlexeiFedorova13f5842024-03-13 12:16:51 +00002 * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta4f6ad662013-10-25 09:08:21 +01005 */
6
Antonio Nino Diaz519248b2018-10-31 15:55:57 +00007#ifndef SPINLOCK_H
8#define SPINLOCK_H
Achin Gupta4f6ad662013-10-25 09:08:21 +01009
Julius Werner53456fc2019-07-09 13:49:11 -070010#ifndef __ASSEMBLER__
Jeenu Viswambharan54ec86a2017-01-19 14:23:36 +000011
Antonio Nino Diaz4b32e622018-08-16 16:52:57 +010012#include <stdint.h>
Jeenu Viswambharan54ec86a2017-01-19 14:23:36 +000013
Dan Handleye2712bc2014-04-10 15:37:22 +010014typedef struct spinlock {
Jeenu Viswambharan54ec86a2017-01-19 14:23:36 +000015 volatile uint32_t lock;
Achin Gupta4f6ad662013-10-25 09:08:21 +010016} spinlock_t;
17
AlexeiFedorova13f5842024-03-13 12:16:51 +000018typedef struct bitlock {
19 volatile uint8_t lock;
20} bitlock_t;
21
Achin Gupta4f6ad662013-10-25 09:08:21 +010022void spin_lock(spinlock_t *lock);
23void spin_unlock(spinlock_t *lock);
24
AlexeiFedorova13f5842024-03-13 12:16:51 +000025void bit_lock(bitlock_t *lock, uint8_t mask);
26void bit_unlock(bitlock_t *lock, uint8_t mask);
27
Jeenu Viswambharan54ec86a2017-01-19 14:23:36 +000028#else
29
30/* Spin lock definitions for use in assembly */
31#define SPINLOCK_ASM_ALIGN 2
32#define SPINLOCK_ASM_SIZE 4
33
AlexeiFedorova13f5842024-03-13 12:16:51 +000034#endif /* __ASSEMBLER__ */
Antonio Nino Diaz519248b2018-10-31 15:55:57 +000035#endif /* SPINLOCK_H */