riscv_locks.h 843 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2019 Western Digital Corporation or its affiliates.
  5. * Copyright (c) 2021 Christoph Müllner <cmuellner@linux.com>
  6. */
  7. #ifndef __RISCV_LOCKS_H__
  8. #define __RISCV_LOCKS_H__
  9. #include <sbi/sbi_types.h>
  10. #define TICKET_SHIFT 16
  11. typedef struct {
  12. #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
  13. u16 next;
  14. u16 owner;
  15. #else
  16. u16 owner;
  17. u16 next;
  18. #endif
  19. } __aligned(4) spinlock_t;
  20. #define __SPIN_LOCK_UNLOCKED \
  21. (spinlock_t) { 0, 0 }
  22. #define SPIN_LOCK_INIT(x) \
  23. x = __SPIN_LOCK_UNLOCKED
  24. #define SPIN_LOCK_INITIALIZER \
  25. __SPIN_LOCK_UNLOCKED
  26. #define DEFINE_SPIN_LOCK(x) \
  27. spinlock_t SPIN_LOCK_INIT(x)
  28. int spin_lock_check(spinlock_t *lock);
  29. int spin_trylock(spinlock_t *lock);
  30. void spin_lock(spinlock_t *lock);
  31. void spin_unlock(spinlock_t *lock);
  32. #endif