1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include "atomisp_internal.h"
21
22#include "hive_isp_css_mm_hrt.h"
23#include "hmm/hmm.h"
24
25#define __page_align(size) (((size) + (PAGE_SIZE-1)) & (~(PAGE_SIZE-1)))
26
27static void *my_userptr;
28static unsigned my_num_pages;
29static enum hrt_userptr_type my_usr_type;
30
31void hrt_isp_css_mm_set_user_ptr(void *userptr,
32 unsigned int num_pages,
33 enum hrt_userptr_type type)
34{
35 my_userptr = userptr;
36 my_num_pages = num_pages;
37 my_usr_type = type;
38}
39
40static ia_css_ptr __hrt_isp_css_mm_alloc(size_t bytes, void *userptr,
41 unsigned int num_pages,
42 enum hrt_userptr_type type,
43 bool cached)
44{
45#ifdef CONFIG_ION
46 if (type == HRT_USR_ION)
47 return hmm_alloc(bytes, HMM_BO_ION, 0,
48 userptr, cached);
49
50#endif
51 if (type == HRT_USR_PTR) {
52 if (userptr == NULL)
53 return hmm_alloc(bytes, HMM_BO_PRIVATE, 0,
54 NULL, cached);
55 else {
56 if (num_pages < ((__page_align(bytes)) >> PAGE_SHIFT))
57 dev_err(atomisp_dev,
58 "user space memory size is less"
59 " than the expected size..\n");
60 else if (num_pages > ((__page_align(bytes))
61 >> PAGE_SHIFT))
62 dev_err(atomisp_dev,
63 "user space memory size is"
64 " large than the expected size..\n");
65
66 return hmm_alloc(bytes, HMM_BO_USER, 0,
67 userptr, cached);
68 }
69 } else {
70 dev_err(atomisp_dev, "user ptr type is incorrect.\n");
71 return 0;
72 }
73}
74
75ia_css_ptr hrt_isp_css_mm_alloc(size_t bytes)
76{
77 return __hrt_isp_css_mm_alloc(bytes, my_userptr,
78 my_num_pages, my_usr_type, false);
79}
80
81ia_css_ptr hrt_isp_css_mm_alloc_user_ptr(size_t bytes, void *userptr,
82 unsigned int num_pages,
83 enum hrt_userptr_type type,
84 bool cached)
85{
86 return __hrt_isp_css_mm_alloc(bytes, userptr, num_pages,
87 type, cached);
88}
89
90ia_css_ptr hrt_isp_css_mm_alloc_cached(size_t bytes)
91{
92 if (my_userptr == NULL)
93 return hmm_alloc(bytes, HMM_BO_PRIVATE, 0, NULL,
94 HMM_CACHED);
95 else {
96 if (my_num_pages < ((__page_align(bytes)) >> PAGE_SHIFT))
97 dev_err(atomisp_dev,
98 "user space memory size is less"
99 " than the expected size..\n");
100 else if (my_num_pages > ((__page_align(bytes)) >> PAGE_SHIFT))
101 dev_err(atomisp_dev,
102 "user space memory size is"
103 " large than the expected size..\n");
104
105 return hmm_alloc(bytes, HMM_BO_USER, 0,
106 my_userptr, HMM_CACHED);
107 }
108}
109
110ia_css_ptr hrt_isp_css_mm_calloc(size_t bytes)
111{
112 ia_css_ptr ptr = hrt_isp_css_mm_alloc(bytes);
113 if (ptr)
114 hmm_set(ptr, 0, bytes);
115 return ptr;
116}
117
118ia_css_ptr hrt_isp_css_mm_calloc_cached(size_t bytes)
119{
120 ia_css_ptr ptr = hrt_isp_css_mm_alloc_cached(bytes);
121 if (ptr)
122 hmm_set(ptr, 0, bytes);
123 return ptr;
124}
125
126