• 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 __DRV_OSAL_LIB_LINUX_H__
20 #define __DRV_OSAL_LIB_LINUX_H__
21 #include <linux/proc_fs.h>
22 #include <linux/module.h>
23 #include <linux/signal.h>
24 #include <linux/spinlock.h>
25 #include <linux/personality.h>
26 #include <linux/ptrace.h>
27 #include <linux/kallsyms.h>
28 #include <linux/init.h>
29 #include <linux/pci.h>
30 #include <linux/seq_file.h>
31 #include <linux/version.h>
32 #include <linux/sched.h>
33 #include <linux/interrupt.h>
34 #include <asm/atomic.h>
35 #include <asm/cacheflush.h>
36 #include <asm/io.h>
37 #include <asm/uaccess.h>
38 #include <asm/unistd.h>
39 #include <asm/traps.h>
40 #include <linux/miscdevice.h>
41 #include <linux/delay.h>
42 #include <asm/page.h>
43 #include "hi_types.h"
44 #include "hi_debug.h"
45 #include "drv_osal_chip.h"
46 #include "drv_cipher_kapi.h"
47 
48 #include "linux/uaccess.h"
49 
50 #if LINUX_VERSION_CODE > KERNEL_VERSION(5,6,0)
51 #define crypto_ioremap_nocache(addr, size)  ioremap(addr, size)
52 #else
53 #define crypto_ioremap_nocache(addr, size)  ioremap_nocache(addr, size)
54 #endif
55 #define crypto_iounmap(addr, size)          iounmap(addr)
56 
57 #define crypto_read(addr)       readl(addr)
58 #define crypto_write(addr, val) writel(val, addr)
59 
60 #define crypto_msleep(msec)     msleep(msec)
61 #define crypto_udelay(msec)     udelay(msec)
62 
63 #define MAX_MALLOC_BUF_SIZE     0x10000
64 hi_void *crypto_calloc(size_t n, size_t size);
65 #define crypto_malloc(x)        ((x) > 0 ? kzalloc((x), GFP_KERNEL) : HI_NULL)
66 #define crypto_free(x)        \
67     do {                      \
68         if ((x) != HI_NULL) { \
69             kfree((x));       \
70             x = HI_NULL;      \
71         }                     \
72     } while (0)
73 
74 /* 512M */
75 #define MAX_COPY_FROM_USER_SIZE    0x20000000
76 
77 hi_s32 crypto_copy_from_user(hi_void *to, unsigned long to_len,
78     const hi_void *from, unsigned long from_len);
79 
80 hi_s32 crypto_copy_to_user(hi_void *to, unsigned long to_len,
81     const hi_void *from, unsigned long from_len);
82 
83 #define CRYPTO_QUEUE_HEAD       wait_queue_head_t
84 #define crypto_queue_init(x)    init_waitqueue_head(x)
85 #define crypto_queue_wait_up(x) wake_up_interruptible(x)
86 
87 /*
88 * Returns of crypto_queue_wait_timeout:
89 * 0 if the @condition evaluated to %false after the @timeout elapsed,
90 * 1 if the @condition evaluated to %true after the @timeout elapsed,
91 * the remaining jiffies (at least 1) if the @condition evaluated
92 * to %true before the @timeout elapsed, or -%ERESTARTSYS if it was
93 * interrupted by a signal.
94 */
95 #define crypto_queue_wait_timeout(head, con, time) \
96     wait_event_interruptible_timeout(head, *(con), time)
97 
98 #define crypto_request_irq(irq, func, name) \
99     request_irq(irq, func, IRQF_SHARED, name, (hi_void *)(name))
100 
101 #define crypto_free_irq(irq, name)          \
102     free_irq(irq, (hi_void *)(name))
103 
104 #define CRYPTO_MUTEX                         struct semaphore
105 #define crypto_mutex_init(x)                 sema_init(x, 1)
106 #define crypto_mutex_lock(x)                 down_interruptible(x)
107 #define crypto_mutex_unlock(x)               up(x)
108 #define crypto_mutex_destroy(x)
109 
110 #define CRYPTO_OWNER                         pid_t
111 #define crypto_get_owner(x)                  *(x) = task_tgid_nr(current)
112 
113 #define CRYPTO_IRQRETURN_T                   irqreturn_t
114 
115 #define hi_log_fatal(fmt...) \
116     do { \
117         printk("[FATAL-HI_CIPHER]:%s[%d]:", __FUNCTION__, __LINE__); \
118         printk(fmt); \
119     } while (0)
120 #define hi_log_error(fmt...) \
121     do { \
122         printk("[ERROR-HI_CIPHER]:%s[%d]:", __FUNCTION__, __LINE__); \
123         printk(fmt); \
124     } while (0)
125 
126 #define hi_log_warn(fmt...)
127 #define hi_log_info(fmt...)
128 #define hi_log_debug(fmt...)
129 
130 #define CRYPTO_PROC_PRINT               seq_printf
131 #endif  /* End of #ifndef __DRV_OSAL_LIB_LINUX_H__ */
132