1 /*
2  * ko_adapt.h
3  *
4  * function for find symbols not exported
5  *
6  * Copyright (C) 2022 Huawei Technologies Co., Ltd.
7  *
8  * This software is licensed under the terms of the GNU General Public
9  * License version 2, as published by the Free Software Foundation, and
10  * may be copied, distributed, and modified under those terms.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  */
17 
18 #ifndef KO_ADAPT_H
19 #define KO_ADAPT_H
20 
21 #include <linux/types.h>
22 #include <linux/cred.h>
23 #include <linux/version.h>
24 #if (KERNEL_VERSION(4, 14, 0) <= LINUX_VERSION_CODE)
25 #include <linux/sched/task.h>
26 #endif
27 #include <linux/kthread.h>
28 #include <linux/cpumask.h>
29 #include <linux/syscalls.h>
30 #include <linux/version.h>
31 #include <linux/gfp.h>
32 
33 #ifdef CONFIG_TZDRIVER_MODULE
34 
35 const struct cred *koadpt_get_task_cred(struct task_struct *task);
36 void koadpt_kthread_bind_mask(struct task_struct *task,
37 	const struct cpumask *mask);
38 struct page *koadpt_alloc_pages(gfp_t gfp_mask, unsigned int order);
39 struct workqueue_attrs *koadpt_alloc_workqueue_attrs(gfp_t gfp_mask);
40 void koadpt_free_workqueue_attrs(struct workqueue_attrs *attrs);
41 
42 #else
43 
koadpt_get_task_cred(struct task_struct *task)44 static inline const struct cred *koadpt_get_task_cred(struct task_struct *task)
45 {
46 	return get_task_cred(task);
47 }
48 
koadpt_kthread_bind_mask(struct task_struct *task, const struct cpumask *mask)49 static inline void koadpt_kthread_bind_mask(struct task_struct *task,
50 	const struct cpumask *mask)
51 {
52 	kthread_bind_mask(task, mask);
53 }
54 
koadpt_alloc_pages(gfp_t gfp_mask, unsigned int order)55 static inline struct page *koadpt_alloc_pages(gfp_t gfp_mask, unsigned int order)
56 {
57 	return alloc_pages(gfp_mask, order);
58 }
59 
koadpt_alloc_workqueue_attrs( gfp_t gfp_mask)60 static inline struct workqueue_attrs *koadpt_alloc_workqueue_attrs(
61 	gfp_t gfp_mask)
62 {
63 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(4, 19, 0))
64 	return alloc_workqueue_attrs(gfp_mask);
65 #else
66 	(void)gfp_mask;
67 	return alloc_workqueue_attrs();
68 #endif
69 }
70 
koadpt_free_workqueue_attrs(struct workqueue_attrs *attrs)71 static inline void koadpt_free_workqueue_attrs(struct workqueue_attrs *attrs)
72 {
73 	return free_workqueue_attrs(attrs);
74 }
75 
76 #endif
77 
78 #endif
79