• 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 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/random.h>
22 #include <linux/version.h>
23 #include "hi_osal.h"
24 
25 /* the result of u64/u32. */
osal_div_u64(unsigned long long dividend,unsigned int divisor)26 unsigned long long osal_div_u64(unsigned long long dividend, unsigned int divisor)
27 {
28     return div_u64(dividend, divisor);
29 }
30 EXPORT_SYMBOL(osal_div_u64);
31 
32 /* the result of s64/s32. */
osal_div_s64(long long dividend,int divisor)33 long long osal_div_s64(long long dividend, int divisor)
34 {
35     return div_s64(dividend, divisor);
36 }
37 EXPORT_SYMBOL(osal_div_s64);
38 
39 /* the result of u64/u64. */
osal_div64_u64(unsigned long long dividend,unsigned long long divisor)40 unsigned long long osal_div64_u64(unsigned long long dividend, unsigned long long divisor)
41 {
42     return div64_u64(dividend, divisor);
43 }
44 EXPORT_SYMBOL(osal_div64_u64);
45 
46 /* the result of s64/s64. */
osal_div64_s64(long long dividend,long long divisor)47 long long osal_div64_s64(long long dividend, long long divisor)
48 {
49     return div64_s64(dividend, divisor);
50 }
51 EXPORT_SYMBOL(osal_div64_s64);
52 
53 /* the remainder of u64/u32. */
osal_div_u64_rem(unsigned long long dividend,unsigned int divisor)54 unsigned long long osal_div_u64_rem(unsigned long long dividend, unsigned int divisor)
55 {
56     unsigned int remainder;
57 
58     div_u64_rem(dividend, divisor, &remainder);
59 
60     return remainder;
61 }
62 EXPORT_SYMBOL(osal_div_u64_rem);
63 
64 /* the remainder of s64/s32. */
osal_div_s64_rem(long long dividend,int divisor)65 long long osal_div_s64_rem(long long dividend, int divisor)
66 {
67     int remainder;
68 
69     div_s64_rem(dividend, divisor, &remainder);
70 
71     return remainder;
72 }
73 EXPORT_SYMBOL(osal_div_s64_rem);
74 
75 /* the remainder of u64/u64. */
osal_div64_u64_rem(unsigned long long dividend,unsigned long long divisor)76 unsigned long long osal_div64_u64_rem(unsigned long long dividend, unsigned long long divisor)
77 {
78     unsigned long long remainder;
79 
80     div64_u64_rem(dividend, divisor, &remainder);
81 
82     return remainder;
83 }
84 EXPORT_SYMBOL(osal_div64_u64_rem);
85 
osal_random(void)86 unsigned int osal_random(void)
87 {
88 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0)
89     return random32();
90 #else
91     return get_random_int();
92 #endif
93 }
94 EXPORT_SYMBOL(osal_random);
95