2 * Support for Medifield PNW Camera Imaging ISP subsystem.
4 * Copyright (c) 2010 Intel Corporation. All Rights Reserved.
6 * Copyright (c) 2010 Silicon Hive www.siliconhive.com.
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version
10 * 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include "atomisp_internal.h"
26 #include "hive_isp_css_mm_hrt.h"
29 #define __page_align(size) (((size) + (PAGE_SIZE-1)) & (~(PAGE_SIZE-1)))
31 static void *my_userptr;
32 static unsigned my_num_pages;
33 static enum hrt_userptr_type my_usr_type;
35 void hrt_isp_css_mm_set_user_ptr(void *userptr,
36 unsigned int num_pages,
37 enum hrt_userptr_type type)
40 my_num_pages = num_pages;
44 static ia_css_ptr __hrt_isp_css_mm_alloc(size_t bytes, void *userptr,
45 unsigned int num_pages,
46 enum hrt_userptr_type type,
50 if (type == HRT_USR_ION)
51 return hmm_alloc(bytes, HMM_BO_ION, 0,
55 if (type == HRT_USR_PTR) {
57 return hmm_alloc(bytes, HMM_BO_PRIVATE, 0,
60 if (num_pages < ((__page_align(bytes)) >> PAGE_SHIFT))
62 "user space memory size is less"
63 " than the expected size..\n");
64 else if (num_pages > ((__page_align(bytes))
67 "user space memory size is"
68 " large than the expected size..\n");
70 return hmm_alloc(bytes, HMM_BO_USER, 0,
74 dev_err(atomisp_dev, "user ptr type is incorrect.\n");
79 ia_css_ptr hrt_isp_css_mm_alloc(size_t bytes)
81 return __hrt_isp_css_mm_alloc(bytes, my_userptr,
82 my_num_pages, my_usr_type, false);
85 ia_css_ptr hrt_isp_css_mm_alloc_user_ptr(size_t bytes, void *userptr,
86 unsigned int num_pages,
87 enum hrt_userptr_type type,
90 return __hrt_isp_css_mm_alloc(bytes, userptr, num_pages,
94 ia_css_ptr hrt_isp_css_mm_alloc_cached(size_t bytes)
96 if (my_userptr == NULL)
97 return hmm_alloc(bytes, HMM_BO_PRIVATE, 0, NULL,
100 if (my_num_pages < ((__page_align(bytes)) >> PAGE_SHIFT))
102 "user space memory size is less"
103 " than the expected size..\n");
104 else if (my_num_pages > ((__page_align(bytes)) >> PAGE_SHIFT))
106 "user space memory size is"
107 " large than the expected size..\n");
109 return hmm_alloc(bytes, HMM_BO_USER, 0,
110 my_userptr, HMM_CACHED);
114 ia_css_ptr hrt_isp_css_mm_calloc(size_t bytes)
116 ia_css_ptr ptr = hrt_isp_css_mm_alloc(bytes);
118 hmm_set(ptr, 0, bytes);
122 ia_css_ptr hrt_isp_css_mm_calloc_cached(size_t bytes)
124 ia_css_ptr ptr = hrt_isp_css_mm_alloc_cached(bytes);
126 hmm_set(ptr, 0, bytes);