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_SCHEDULE_H__
20 #define __OAL_SCHEDULE_H__
21
22 #include "hi_types.h"
23 #include "oal_err_wifi.h"
24 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
25 #include "los_swtmr.h"
26 #endif
27 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
28 #include <linux/proc_fs.h>
29 #include <asm/uaccess.h>
30 #include <linux/time.h>
31 #include <linux/version.h>
32 #endif
33
34 #include <linux/sched.h>
35 #include "hi_types.h"
36 #include "oal_mm.h"
37 #include "oal_time.h"
38 #include "oal_timer.h"
39 #include "oal_wakelock.h"
40 #include "oal_spinlock.h"
41 #include "oal_atomic.h"
42 #include "oal_file.h"
43 #include "oal_wait.h"
44 #include "oal_semaphore.h"
45 #include "oal_completion.h"
46
47 #include <linux/interrupt.h>
48 #include <linux/jiffies.h>
49 #include <linux/module.h>
50 #include "oal_util.h"
51 #include "oal_err_wifi.h"
52 #include "linux/completion.h"
53 #include "hi_atomic.h"
54 #include "hi_event.h"
55
56 #ifdef __cplusplus
57 #if __cplusplus
58 extern "C" {
59 #endif
60 #endif
61
62 /* ****************************************************************************
63 2 宏定义
64 **************************************************************************** */
65 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
66 #define in_atomic() 0
67 #define MAX_ERRNO 4095
68 #define EXPORT_SYMBOL_GPL(x)
69 #define OAL_EXPORT_SYMBOL(x)
70 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)(-MAX_ERRNO))
71 #define OAL_S_IRUGO S_IRUGO
72
73 #define oal_module_symbol(_symbol) EXPORT_SYMBOL(_symbol)
74 #define OAL_MODULE_DEVICE_TABLE(_type, _name) MODULE_DEVICE_TABLE(_type, _name)
75 #define oal_smp_call_function_single(core, task, info, wait) smp_call_function_single(core, task, info, wait)
76 #endif
77 #define oal_in_atomic() in_atomic()
78 #define oal_in_interrupt() in_interrupt()
79
80 /* module entry */
81 #define oal_module_init(_module_name) module_init(_module_name)
82 #define oal_module_exit(_module_name) module_exit(_module_name)
83 #define oal_module_license(_license_name)
84 #define oal_module_param(_symbol, _type, _name)
85
86 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
87 typedef hi_void (*oal_defer_func)(unsigned long);
88 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0))
89 typedef hi_void (*oal_timer_func)(struct timer_list *);
90 #else
91 typedef hi_void (*oal_timer_func)(unsigned long);
92 #endif
93 #endif
94 typedef hi_u32 (*oal_module_func_t)(hi_void);
95
96 typedef enum {
97 OAL_DFT_TRACE_OTHER = 0x0,
98 OAL_DFT_TRACE_SUCC,
99 OAL_DFT_TRACE_FAIL, /* fail while dump the key_info to kernel */
100 OAL_DFT_TRACE_EXCEP, /* exception */
101 OAL_DFT_TRACE_BUTT,
102 } oal_dft_type;
103
104 typedef struct proc_dir_entry oal_proc_dir_entry_stru;
105
106 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
107 enum {
108 TASKLET_STATE_SCHED, /* Tasklet is scheduled for execution */
109 TASKLET_STATE_RUN /* Tasklet is running (SMP only) */
110 };
111
IS_ERR_OR_NULL(const void * ptr)112 static inline hi_u32 IS_ERR_OR_NULL(const void *ptr)
113 {
114 return !ptr;
115 }
116 #endif
117
118 /* ****************************************************************************
119 功能描述 : 将用户态数据拷贝到内核态
120 输入参数 : [1]to 目的地
121 [2]len 长度
122 [3]from 源
123 [4]size 需要拷贝的长度
124 输出参数 : 无
125 返 回 值 : hi_u32
126 **************************************************************************** */
oal_copy_from_user(hi_void * to,hi_u32 len,const hi_void * from,hi_u32 size)127 static inline hi_u32 oal_copy_from_user(hi_void *to, hi_u32 len, const hi_void *from, hi_u32 size)
128 {
129 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
130 if (memcpy_s(to, len, from, size) != EOK) {
131 return HI_FAIL;
132 }
133 return HI_SUCCESS;
134 #else
135 hi_unref_param(len);
136 return (hi_u32)copy_from_user(to, from, (hi_u32)size);
137 #endif
138 }
139
140 /* ****************************************************************************
141 功能描述 : 将内核态数据拷贝到用户态
142 输入参数 : [1]to 目的地
143 [2]len 长度
144 [3]from 源
145 [4]size 需要拷贝的长度
146 输出参数 : 无
147 返 回 值 : hi_u32
148 **************************************************************************** */
oal_copy_to_user(hi_void * to,hi_u32 len,const hi_void * from,hi_u32 size)149 static inline hi_u32 oal_copy_to_user(hi_void *to, hi_u32 len, const hi_void *from, hi_u32 size)
150 {
151 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
152 if (memcpy_s(to, len, from, size) != EOK) {
153 return HI_FAIL;
154 }
155 return HI_SUCCESS;
156 #else
157 hi_unref_param(len);
158 return (hi_u32)copy_to_user(to, from, (hi_u32)size);
159 #endif
160 }
161
162 /* ****************************************************************************
163 功能描述 : 创建proc_entry结构体
164 输入参数 : name: 创建的proc_entry的名字
165 proc_dir: 母proc_entry结构体,继承属性
166 输出参数 : 无
167 返 回 值 : 无
168 **************************************************************************** */
oal_remove_proc_entry(const hi_char * name,oal_proc_dir_entry_stru * proc_dir)169 static inline hi_void oal_remove_proc_entry(const hi_char *name, oal_proc_dir_entry_stru *proc_dir)
170 {
171 #if ((LINUX_VERSION_CODE >= kernel_version(3, 10, 44)) || (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION))
172 hi_unref_param(name);
173 hi_unref_param(proc_dir);
174 #else
175 return remove_proc_entry(name, proc_dir);
176 #endif
177 }
178
179 #ifdef __cplusplus
180 #if __cplusplus
181 }
182 #endif
183 #endif
184
185 #endif /* end of oal_schedule.h */
186