• 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 __MM_EXT_H__
20 #define __MM_EXT_H__
21 
22 #include "hi_osal.h"
23 #include "hi_math.h"
24 #include "hi_common.h"
25 #include "osal_mmz.h"
26 
27 #ifdef __cplusplus
28 #if __cplusplus
29 extern "C" {
30 #endif
31 #endif
32 
read_user_linear_space_valid(hi_u8 * addr_start,hi_u32 len)33 static inline hi_bool read_user_linear_space_valid(hi_u8 *addr_start, hi_u32 len)
34 {
35     hi_u8 check;
36     hi_u8 *addr_end = HI_NULL;
37 
38     if (len == 0) {
39         return HI_FALSE;
40     }
41 
42     if (!osal_access_ok(OSAL_VERIFY_READ, addr_start, len)) {
43         return HI_FALSE;
44     }
45 
46     addr_end = addr_start + len - 1;
47     if (osal_copy_from_user(&check, addr_end, 1)) {
48         return HI_FALSE;
49     }
50 
51     return HI_TRUE;
52 }
53 
write_user_linear_space_valid(hi_u8 * addr_start,hi_u32 len)54 static inline hi_bool write_user_linear_space_valid(hi_u8 *addr_start, hi_u32 len)
55 {
56     hi_u8 check = 0;
57     hi_u8 *addr_end = HI_NULL;
58 
59     if (len == 0) {
60         return HI_FALSE;
61     }
62 
63     if (!osal_access_ok(OSAL_VERIFY_WRITE, addr_start, len)) {
64         return HI_FALSE;
65     }
66 
67     addr_end = addr_start + len - 1;
68     if (osal_copy_to_user(addr_end, &check, 1)) {
69         return HI_FALSE;
70     }
71 
72     return HI_TRUE;
73 }
74 
75 #ifdef __cplusplus
76 #if __cplusplus
77 }
78 #endif
79 #endif
80 
81 #endif /* __MM_EXT_H__ */
82