1 /*
2 * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #ifndef __OAL_LINUX_TASK_H__
20 #define __OAL_LINUX_TASK_H__
21
22 /* ****************************************************************************
23 1 其他头文件包含
24 **************************************************************************** */
25 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
26 #include <linux/mutex.h>
27 #endif
28 #include "oal_workqueue.h"
29 #include "oal_spinlock.h"
30 #include "oal_wait.h"
31 #include "oal_atomic.h"
32
33 #ifdef __cplusplus
34 #if __cplusplus
35 extern "C" {
36 #endif
37 #endif
38
39 /* ****************************************************************************
40 2 STRUCT定义
41 **************************************************************************** */
42 typedef struct _oal_task_lock_stru_ {
43 oal_wait_queue_head_stru wq;
44 struct task_struct *claimer; /* task that has host claimed */
45 oal_spin_lock_stru lock; /* lock for claim and bus ops */
46 unsigned long claim_addr;
47 hi_u32 claimed;
48 hi_s32 claim_cnt;
49 } oal_task_lock_stru;
50
51 typedef struct tasklet_struct oal_tasklet_stru;
52 typedef hi_void (*oal_defer_func)(unsigned long);
53
54 /* ****************************************************************************
55 3 枚举定义
56 **************************************************************************** */
57 /* ****************************************************************************
58 4 全局变量声明
59 **************************************************************************** */
60 /* ****************************************************************************
61 5 消息头定义
62 **************************************************************************** */
63 /* ****************************************************************************
64 6 消息定义
65 **************************************************************************** */
66 /* ****************************************************************************
67 7 宏定义
68 **************************************************************************** */
69 /* tasklet声明 */
70 #define OAL_DECLARE_TASK DECLARE_TASKLET
71
72 /* ****************************************************************************
73 8 UNION定义
74 **************************************************************************** */
75 /* ****************************************************************************
76 9 OTHERS定义
77 **************************************************************************** */
78 /* ****************************************************************************
79 10 函数声明
80 **************************************************************************** */
81 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
82 /* ****************************************************************************
83 功能描述 : 任务初始化。初始化完成后,任务处于挂起状态。
84 输入参数 : pst_task: 任务结构体指针
85 func: 任务处理函数入口地址
86 p_args: 需进行处理的函数的入参地址
87 输出参数 : 无
88 返 回 值 :
89 **************************************************************************** */
oal_task_init(oal_tasklet_stru * pst_task,oal_defer_func p_func,hi_void * p_args)90 static inline hi_void oal_task_init(oal_tasklet_stru *pst_task, oal_defer_func p_func, hi_void *p_args)
91 {
92 tasklet_init(pst_task, p_func, (uintptr_t)p_args);
93 }
94
95 /* ****************************************************************************
96 功能描述 : 退出task运行
97 输入参数 : pst_task: 任务结构体指针
98 输出参数 : 无
99 返 回 值 :
100 **************************************************************************** */
oal_task_kill(oal_tasklet_stru * pst_task)101 static inline hi_void oal_task_kill(oal_tasklet_stru *pst_task)
102 {
103 return tasklet_kill(pst_task);
104 }
105
106 /* ****************************************************************************
107 功能描述 : 任务调度,令任务处于准备就绪状态;当任务执行完后,又回到挂起状
108 态。
109 输入参数 : pst_task: 任务结构体指针
110 输出参数 : 无
111 返 回 值 :
112 **************************************************************************** */
oal_task_sched(oal_tasklet_stru * pst_task)113 static inline hi_void oal_task_sched(oal_tasklet_stru *pst_task)
114 {
115 tasklet_schedule(pst_task);
116 }
117
118 /* ****************************************************************************
119 功能描述 : 检测tasklet是否等待执行
120 输入参数 : pst_task: 任务结构体指针
121 输出参数 : 无
122 返 回 值 :
123 **************************************************************************** */
oal_task_is_scheduled(oal_tasklet_stru * pst_task)124 static inline unsigned long oal_task_is_scheduled(oal_tasklet_stru *pst_task)
125 {
126 return oal_bit_atomic_test(TASKLET_STATE_SCHED, (unsigned long *)&pst_task->state);
127 }
128 #endif
129
130 #ifdef __cplusplus
131 #if __cplusplus
132 }
133 #endif
134 #endif
135
136 #endif /* end of oal_task.h */
137