2023-08-18 20:30:52 +08:00
|
|
|
|
#ifndef KERNEL_API_INC_SPINLOCK_H_
|
|
|
|
|
#define KERNEL_API_INC_SPINLOCK_H_
|
|
|
|
|
|
|
|
|
|
#include <ucps2-intrin.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
SLOCK_L3 = 0,
|
|
|
|
|
SLOCK_MAX = 15
|
|
|
|
|
}ape_spin_lock_index;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct{
|
|
|
|
|
union
|
|
|
|
|
{
|
2023-10-12 10:28:46 +08:00
|
|
|
|
unsigned int slock;
|
2023-08-18 20:30:52 +08:00
|
|
|
|
};
|
|
|
|
|
}spinlock_t;
|
|
|
|
|
|
|
|
|
|
#define APE_NR 12
|
|
|
|
|
|
|
|
|
|
typedef struct{
|
2023-10-12 10:28:46 +08:00
|
|
|
|
unsigned int spinlock_count;
|
|
|
|
|
unsigned int unspinlock_count;
|
|
|
|
|
unsigned int spinlock_loop;
|
2023-08-18 20:30:52 +08:00
|
|
|
|
unsigned int g_spin_count;
|
|
|
|
|
// unsigned int unspinlock_loop;
|
|
|
|
|
|
|
|
|
|
}spin_db_info ;
|
|
|
|
|
|
|
|
|
|
typedef struct{
|
2023-10-12 10:28:46 +08:00
|
|
|
|
// spin_db_info spin_per_ape[APE_NR];
|
|
|
|
|
spin_db_info spin_per_ape;
|
2023-08-18 20:30:52 +08:00
|
|
|
|
}spin_debug_t;
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
2023-10-12 10:28:46 +08:00
|
|
|
|
unsigned int lock_addr; //锁物理地址
|
|
|
|
|
unsigned int flag_addr; // 锁标志物理地址
|
2023-08-18 20:30:52 +08:00
|
|
|
|
|
|
|
|
|
}ddr_spinlock_t;
|
|
|
|
|
|
|
|
|
|
extern int smart_spinlock_init(int lock_index);
|
|
|
|
|
extern void smart_spinlock(int lock_index);
|
|
|
|
|
extern void smart_spinunlock(int lock_index);
|
2023-10-12 10:28:46 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
函数名称:smart_spin_debug_init
|
|
|
|
|
输入参数: lock_idx
|
|
|
|
|
输入参数:debug_base_addr
|
|
|
|
|
输入参数: len_bytes
|
|
|
|
|
返回类型: int
|
|
|
|
|
返回值: 小于0 表示失败
|
|
|
|
|
返回值: 0 表示成功
|
|
|
|
|
函数功能: 自旋锁调试接口,
|
|
|
|
|
注意:
|
|
|
|
|
通过lock_idx ,地址与长度指定相应的buf 数据空间,存放相应的自旋锁调试信息。
|
|
|
|
|
这些调试信息已经格式化,地址由用户指定,len_bytes 不能小于sizeof(spin_debug_t)
|
|
|
|
|
数据格式化内容是 spin_debug_t
|
|
|
|
|
*/
|
|
|
|
|
|
2023-08-18 20:30:52 +08:00
|
|
|
|
extern int smart_spin_debug_init(int lock_idx,unsigned int debug_base_addr, int len_bytes);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
参数:lock_idx
|
|
|
|
|
参数范围:1--15
|
|
|
|
|
*/
|
|
|
|
|
extern int smart_get_spin_loop_cnt(int lock_idx);
|
|
|
|
|
/*
|
|
|
|
|
参数:lock_idx
|
|
|
|
|
参数范围:1--15
|
|
|
|
|
*/
|
|
|
|
|
extern int smart_get_spin_cnt(int lock_idx);
|
|
|
|
|
/*
|
|
|
|
|
参数:lock_idx
|
|
|
|
|
参数范围:1--15
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
extern int smart_get_spinlock_cnt(int lock_idx);
|
|
|
|
|
/*
|
|
|
|
|
参数:lock_idx
|
|
|
|
|
参数范围:1--15
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
extern int smart_get_unspinlock_cnt(int lock_idx);
|
|
|
|
|
|
|
|
|
|
|
2023-10-12 10:28:46 +08:00
|
|
|
|
extern int smart_ddr_spinlock_init(ddr_spinlock_t *val);
|
2023-08-18 20:30:52 +08:00
|
|
|
|
extern void smart_ddr_spinlock(ddr_spinlock_t *val);
|
|
|
|
|
extern void smart_ddr_spinunlock(ddr_spinlock_t *val);
|
|
|
|
|
|
2023-10-12 10:28:46 +08:00
|
|
|
|
/*
|
|
|
|
|
函数名称:smart_ddr_spinlock_irq
|
|
|
|
|
函数参数: val
|
|
|
|
|
参数类型: ddr_spinlock_t
|
|
|
|
|
函数功能: 关中断加锁
|
|
|
|
|
函数说明: 非中断状态下使用
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static inline void smart_ddr_spinlock_irq(ddr_spinlock_t *d_lock)
|
2023-08-18 20:30:52 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
__ucps2_IntEn(f_Disable);
|
2023-10-12 10:28:46 +08:00
|
|
|
|
smart_ddr_spinlock(d_lock);
|
2023-08-18 20:30:52 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-12 10:28:46 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
函数名称:smart_ddr_spinunlock_irqrestore
|
|
|
|
|
函数参数: d_lock
|
|
|
|
|
参数类型: ddr_spinlock_t
|
|
|
|
|
函数功能: 解锁开中断
|
|
|
|
|
函数说明: 非中断状态下使用
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static inline void smart_ddr_spinunlock_irqrestore(ddr_spinlock_t *d_lock)
|
2023-08-18 20:30:52 +08:00
|
|
|
|
{
|
2023-10-12 10:28:46 +08:00
|
|
|
|
smart_ddr_spinunlock(d_lock);
|
2023-08-18 20:30:52 +08:00
|
|
|
|
__ucps2_IntEn(f_Enable);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-10-12 10:28:46 +08:00
|
|
|
|
/*
|
|
|
|
|
函数名称:smart_spinlock_irq
|
|
|
|
|
函数参数: lock
|
|
|
|
|
参数类型: int
|
|
|
|
|
函数功能: 关中断加锁
|
|
|
|
|
函数说明: 非中断状态下使用
|
|
|
|
|
*/
|
|
|
|
|
|
2023-08-18 20:30:52 +08:00
|
|
|
|
static inline void smart_spinlock_irq(int lock)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
__ucps2_IntEn(f_Disable);
|
|
|
|
|
smart_spinlock(lock);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-12 10:28:46 +08:00
|
|
|
|
/*
|
|
|
|
|
函数名称:smart_spinunlock_irqrestore
|
|
|
|
|
函数参数: d_lock
|
|
|
|
|
参数类型: int
|
|
|
|
|
函数功能: 解锁开中断
|
|
|
|
|
函数说明: 非中断状态下使用
|
|
|
|
|
*/
|
|
|
|
|
|
2023-08-18 20:30:52 +08:00
|
|
|
|
static inline void smart_spinunlock_irqrestore(int lock)
|
|
|
|
|
{
|
|
|
|
|
smart_spinunlock(lock);
|
|
|
|
|
__ucps2_IntEn(f_Enable);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* KERNEL_API_INC_SPINLOCK_H_ */
|
|
|
|
|
|