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 #include "hi_osal.h"
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/version.h>
23 #include <asm/io.h>
24 #include <asm/uaccess.h>
25 #include <linux/version.h>
26 #include <linux/uaccess.h>
27
28 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
29
30 #ifndef CONFIG_64BIT
31 #include <mach/io.h>
32 #endif
33
34 #endif
35
osal_ioremap(unsigned long phys_addr,unsigned long size)36 void *osal_ioremap(unsigned long phys_addr, unsigned long size)
37 {
38 return ioremap(phys_addr, size);
39 }
40 EXPORT_SYMBOL(osal_ioremap);
41
osal_ioremap_nocache(unsigned long phys_addr,unsigned long size)42 void *osal_ioremap_nocache(unsigned long phys_addr, unsigned long size)
43 {
44 #if LINUX_VERSION_CODE > KERNEL_VERSION(5,10,0)
45 return ioremap(phys_addr, size);
46 #else
47 return ioremap_nocache(phys_addr, size);
48 #endif
49 }
50 EXPORT_SYMBOL(osal_ioremap_nocache);
51
osal_ioremap_cached(unsigned long phys_addr,unsigned long size)52 void *osal_ioremap_cached(unsigned long phys_addr, unsigned long size)
53 {
54 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0)
55 return ioremap_cached(phys_addr, size);
56 #else
57 return ioremap_cache(phys_addr, size);
58 #endif
59 }
60
osal_ioremap_wc(unsigned long phys_addr,unsigned long size)61 void *osal_ioremap_wc(unsigned long phys_addr, unsigned long size)
62 {
63 return ioremap_wc(phys_addr, size);
64 }
65 EXPORT_SYMBOL(osal_ioremap_wc);
66
67 EXPORT_SYMBOL(osal_ioremap_cached);
68
osal_iounmap(void * addr,unsigned long size)69 void osal_iounmap(void *addr, unsigned long size)
70 {
71 iounmap(addr);
72 }
73 EXPORT_SYMBOL(osal_iounmap);
74
osal_copy_from_user(void * to,const void * from,unsigned long n)75 unsigned long osal_copy_from_user(void *to, const void *from, unsigned long n)
76 {
77 return copy_from_user(to, from, n);
78 }
79 EXPORT_SYMBOL(osal_copy_from_user);
80
osal_copy_to_user(void * to,const void * from,unsigned long n)81 unsigned long osal_copy_to_user(void *to, const void *from, unsigned long n)
82 {
83 return copy_to_user(to, from, n);
84 }
85 EXPORT_SYMBOL(osal_copy_to_user);
86
osal_access_ok(int type,const void * addr,unsigned long size)87 int osal_access_ok(int type, const void *addr, unsigned long size)
88 {
89 #if LINUX_VERSION_CODE > KERNEL_VERSION(5,10,0)
90 return access_ok(addr, size);
91 #else
92 return access_ok(type, addr, size);
93 #endif
94 }
95 EXPORT_SYMBOL(osal_access_ok);
96