1 // SPDX-License-Identifier: BSD-3-Clause
2 //
3 // Copyright(c) 2020 Intel Corporation. All rights reserved.
4 //
5 // Author: Tomasz Lauda <tomasz.lauda@linux.intel.com>
6
7 #include <rtos/interrupt.h>
8 #if CONFIG_DEBUG_LOCKS
9 #include <sof/lib/uuid.h>
10 #endif
11 #include <rtos/spinlock.h>
12
13 #include <stdint.h>
14
15 #if CONFIG_DEBUG_LOCKS
16
17 /* 9d346d98-203d-4791-baee-1770a03d4a71 */
18 DECLARE_SOF_UUID("spinlock", spinlock_uuid, 0x9d346d98, 0x203d, 0x4791,
19 0xba, 0xee, 0x17, 0x70, 0xa0, 0x3d, 0x4a, 0x71);
20
21 DECLARE_TR_CTX(sl_tr, SOF_UUID(spinlock_uuid), LOG_LEVEL_INFO);
22
23 #endif
24
25 #ifndef __ZEPHYR__
_k_spin_lock_irq(struct k_spinlock * lock)26 k_spinlock_key_t _k_spin_lock_irq(struct k_spinlock *lock)
27 {
28 k_spinlock_key_t key = interrupt_global_disable();
29 #if CONFIG_DEBUG_LOCKS
30 lock_dbg_atomic++;
31 #endif
32 arch_spin_lock(lock);
33 #if CONFIG_DEBUG_LOCKS
34 if (lock_dbg_atomic < DBG_LOCK_USERS)
35 lock_dbg_user[lock_dbg_atomic - 1] = (lock)->user;
36 #endif
37 return key;
38 }
39
_k_spin_unlock_irq(struct k_spinlock * lock,k_spinlock_key_t key,int line)40 void _k_spin_unlock_irq(struct k_spinlock *lock, k_spinlock_key_t key, int line)
41 {
42 arch_spin_unlock(lock);
43 #if CONFIG_DEBUG_LOCKS
44 lock_dbg_atomic--;
45 #endif
46 interrupt_global_enable(key);
47 }
48 #endif
49