1 /* 2 * Copyright (c) 2025, Mediatek Inc. All rights resrved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef MT_SPM_COMMON_H 8 #define MT_SPM_COMMON_H 9 10 #include <lib/bakery_lock.h> 11 #include <lib/spinlock.h> 12 /* 13 * ARM v8.2, the cache will turn off automatically when cpu 14 * power down. So, there is no doubt to use the spin_lock here 15 */ 16 #if !HW_ASSISTED_COHERENCY 17 #define MT_SPM_USING_BAKERY_LOCK 18 #endif 19 20 #ifdef MT_SPM_USING_BAKERY_LOCK 21 DECLARE_BAKERY_LOCK(spm_lock); 22 #define plat_spm_lock() \ 23 bakery_lock_get(&spm_lock) 24 25 #define plat_spm_unlock() \ 26 bakery_lock_release(&spm_lock) 27 #else 28 extern spinlock_t spm_lock; 29 #define plat_spm_lock() \ 30 spin_lock(&spm_lock) 31 32 #define plat_spm_unlock() \ 33 spin_unlock(&spm_lock) 34 #endif 35 36 #define MT_SPM_ERR_NO_FW_LOAD -1 37 #define MT_SPM_ERR_KICKED -2 38 #define MT_SPM_ERR_RUNNING -3 39 #define MT_SPM_ERR_FW_NOT_FOUND -4 40 #define MT_SPM_ERR_INVALID -5 41 #define MT_SPM_ERR_OVERFLOW -6 42 spm_lock_get(void)43static inline void spm_lock_get(void) 44 { 45 plat_spm_lock(); 46 } 47 spm_lock_release(void)48static inline void spm_lock_release(void) 49 { 50 plat_spm_unlock(); 51 } 52 53 #endif /* MT_SPM_COMMON_H */ 54