• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_WORKQUEUE_H__
20 #define __OAL_LINUX_WORKQUEUE_H__
21 
22 /* ****************************************************************************
23   1 其他头文件包含
24 **************************************************************************** */
25 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
26 #include <linux/proc_fs.h>
27 #include <asm/uaccess.h>
28 #endif
29 #include <linux/interrupt.h>
30 #include <linux/sched.h>
31 #include <linux/workqueue.h>
32 #include "hi_types.h"
33 #include "oal_util.h"
34 
35 #ifdef __cplusplus
36 #if __cplusplus
37 extern "C" {
38 #endif
39 #endif
40 
41 /* ****************************************************************************
42   2 STRUCT定义
43 **************************************************************************** */
44 typedef struct workqueue_struct          oal_workqueue_stru;
45 typedef struct work_struct               oal_work_stru;
46 typedef struct delayed_work              oal_delayed_work;
47 
48 /* ****************************************************************************
49   3 枚举定义
50 **************************************************************************** */
51 /* ****************************************************************************
52   4 全局变量声明
53 **************************************************************************** */
54 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
55 extern struct workqueue_struct *g_pstSystemWq;
56 #endif
57 
58 /* ****************************************************************************
59   5 消息头定义
60 **************************************************************************** */
61 /* ****************************************************************************
62   6 消息定义
63 **************************************************************************** */
64 /* ****************************************************************************
65   7 宏定义
66 **************************************************************************** */
67 #define OAL_INIT_WORK(_p_work, _p_func)            INIT_WORK(_p_work, _p_func)
68 #define OAL_INIT_DELAYED_WORK(_work, _func)         INIT_DELAYED_WORK(_work, _func)
69 #define OAL_CREATE_SINGLETHREAD_WORKQUEUE(_name)   create_singlethread_workqueue(_name)
70 #define oal_create_workqueue(name)                 create_workqueue(name)
71 
72 hi_u32 oal_workqueue_init(hi_void);
73 hi_u32 oal_workqueue_exit(hi_void);
74 hi_u32 oal_workqueue_schedule(oal_work_stru *pst_work);
75 hi_u32 oal_workqueue_delay_schedule(oal_delayed_work *pst_work, unsigned long delay);
76 /* ****************************************************************************
77   8 UNION定义
78 **************************************************************************** */
79 /* ****************************************************************************
80   9 OTHERS定义
81 **************************************************************************** */
82 /* ****************************************************************************
83   10 函数声明
84 **************************************************************************** */
85 /* ****************************************************************************
86  功能描述  : 创建一个单线程的工作队列
87  输入参数  : 无
88  输出参数  : 无
89  返 回 值  :
90 **************************************************************************** */
oal_create_singlethread_workqueue(hi_char * pc_workqueue_name)91 static inline oal_workqueue_stru *oal_create_singlethread_workqueue(hi_char *pc_workqueue_name)
92 {
93     return create_singlethread_workqueue(pc_workqueue_name);
94 }
95 
96 /* ****************************************************************************
97  功能描述  : 销毁工作队列
98  输入参数  : 无
99  输出参数  : 无
100  返 回 值  :
101 **************************************************************************** */
oal_destroy_workqueue(oal_workqueue_stru * pst_workqueue)102 static inline hi_void oal_destroy_workqueue(oal_workqueue_stru *pst_workqueue)
103 {
104     destroy_workqueue(pst_workqueue);
105 }
106 
107 /* ****************************************************************************
108  功能描述  : 添加一个任务到工作队列
109  输入参数  : 无
110  输出参数  : 无
111  返 回 值  :
112 **************************************************************************** */
oal_queue_work(oal_workqueue_stru * pst_workqueue,oal_work_stru * pst_work)113 static inline hi_u32 oal_queue_work(oal_workqueue_stru *pst_workqueue, oal_work_stru *pst_work)
114 {
115     return queue_work(pst_workqueue, pst_work);
116 }
117 
118 /* *
119  * queue_delayed_work - queue work on a workqueue after delay
120  * @wq: workqueue to use
121  * @dwork: delayable work to queue
122  * @delay: number of jiffies to wait before queueing
123  *
124  * Equivalent to queue_delayed_work_on() but tries to use the local CPU.
125  */
oal_queue_delayed_work(oal_workqueue_stru * pst_workqueue,oal_delayed_work * pst_work,unsigned long delay)126 static inline hi_u32 oal_queue_delayed_work(oal_workqueue_stru *pst_workqueue, oal_delayed_work *pst_work,
127     unsigned long delay)
128 {
129     return queue_delayed_work(pst_workqueue, pst_work, delay);
130 }
131 
132 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
133 /* *
134  * queue_delayed_work_on - queue work on specific CPU after delay
135  * @cpu: CPU number to execute work on
136  * @wq: workqueue to use
137  * @dwork: work to queue
138  * @delay: number of jiffies to wait before queueing
139  *
140  * Returns %false if @work was already on a queue, %true otherwise.  If
141  * @delay is zero and @dwork is idle, it will be scheduled for immediate
142  *  */
oal_queue_delayed_work_on(hi_u32 cpu,oal_workqueue_stru * pst_workqueue,oal_delayed_work * pst_work,unsigned long delay)143 static inline hi_u32 oal_queue_delayed_work_on(hi_u32 cpu, oal_workqueue_stru *pst_workqueue,
144     oal_delayed_work *pst_work, unsigned long delay)
145 {
146     return queue_delayed_work_on(cpu, pst_workqueue, pst_work, delay);
147 }
148 #endif
149 
150 /* ****************************************************************************
151  功能描述  : queue work on system wq after delay
152  输入参数  :  @dwork: delayable work to queue
153               @delay: number of jiffies to wait before queueing
154  输出参数  : 无
155  返 回 值  :
156 **************************************************************************** */
oal_queue_delayed_system_work(oal_delayed_work * pst_work,unsigned long delay)157 static inline hi_u32 oal_queue_delayed_system_work(oal_delayed_work *pst_work, unsigned long delay)
158 {
159 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
160 #if (LINUX_VERSION_CODE >= kernel_version(3, 4, 35))
161     return queue_delayed_work(system_wq, pst_work, delay);
162 #else
163     return 1;
164 #endif
165 
166 #elif (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
167     if (queue_delayed_work(g_pstSystemWq, pst_work, delay)) {
168         return OAL_SUCC;
169     }
170     return OAL_EFAIL;
171 #endif
172 }
173 
174 #define oal_work_is_busy(work)              work_busy(work)
175 #define oal_cancel_delayed_work_sync(dwork) cancel_delayed_work_sync(dwork)
176 #define oal_cancel_work_sync(work)          cancel_work_sync(work)
177 
178 #ifdef __cplusplus
179 #if __cplusplus
180 }
181 #endif
182 #endif
183 
184 #endif /* end of oal_workqueue.h */
185