• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Support for Intel Camera Imaging ISP subsystem.
4  * Copyright (c) 2015, Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  */
15 
16 #ifndef __IA_CSS_DVS_H
17 #define __IA_CSS_DVS_H
18 
19 /* @file
20  * This file contains types for DVS statistics
21  */
22 
23 #include <type_support.h>
24 #include "ia_css_types.h"
25 #include "ia_css_err.h"
26 #include "ia_css_stream_public.h"
27 
28 enum dvs_statistics_type {
29 	DVS_STATISTICS,
30 	DVS2_STATISTICS,
31 	SKC_DVS_STATISTICS
32 };
33 
34 /* Structure that holds DVS statistics in the ISP internal
35  * format. Use ia_css_get_dvs_statistics() to translate
36  * this to the format used on the host (DVS engine).
37  * */
38 struct ia_css_isp_dvs_statistics {
39 	ia_css_ptr hor_proj;
40 	ia_css_ptr ver_proj;
41 	u32   hor_size;
42 	u32   ver_size;
43 	u32   exp_id;   /** see ia_css_event_public.h for more detail */
44 	ia_css_ptr data_ptr; /* base pointer containing all memory */
45 	u32   size;     /* size of allocated memory in data_ptr */
46 };
47 
48 /* Structure that holds SKC DVS statistics in the ISP internal
49  * format. Use ia_css_dvs_statistics_get() to translate this to
50  * the format used on the host.
51  * */
52 struct ia_css_isp_skc_dvs_statistics;
53 
54 #define SIZE_OF_IA_CSS_ISP_DVS_STATISTICS_STRUCT			\
55 	((3 * SIZE_OF_IA_CSS_PTR) +					\
56 	 (4 * sizeof(uint32_t)))
57 
58 /* Map with host-side pointers to ISP-format statistics.
59  * These pointers can either be copies of ISP data or memory mapped
60  * ISP pointers.
61  * All of the data behind these pointers is allocatd contiguously, the
62  * allocated pointer is stored in the data_ptr field. The other fields
63  * point into this one block of data.
64  */
65 struct ia_css_isp_dvs_statistics_map {
66 	void    *data_ptr;
67 	s32 *hor_proj;
68 	s32 *ver_proj;
69 	u32 size;		 /* total size in bytes */
70 	u32 data_allocated; /* indicate whether data was allocated */
71 };
72 
73 union ia_css_dvs_statistics_isp {
74 	struct ia_css_isp_dvs_statistics *p_dvs_statistics_isp;
75 	struct ia_css_isp_skc_dvs_statistics *p_skc_dvs_statistics_isp;
76 };
77 
78 union ia_css_dvs_statistics_host {
79 	struct ia_css_dvs_statistics *p_dvs_statistics_host;
80 	struct ia_css_dvs2_statistics *p_dvs2_statistics_host;
81 	struct ia_css_skc_dvs_statistics *p_skc_dvs_statistics_host;
82 };
83 
84 /* @brief Copy DVS statistics from an ISP buffer to a host buffer.
85  * @param[in]	host_stats Host buffer
86  * @param[in]	isp_stats ISP buffer
87  * @return	error value if temporary memory cannot be allocated
88  *
89  * This may include a translation step as well depending
90  * on the ISP version.
91  * Always use this function, never copy the buffer directly.
92  * Note that this function uses the mem_load function from the CSS
93  * environment struct.
94  * In certain environments this may be slow. In those cases it is
95  * advised to map the ISP memory into a host-side pointer and use
96  * the ia_css_translate_dvs_statistics() function instead.
97  */
98 int
99 ia_css_get_dvs_statistics(struct ia_css_dvs_statistics *host_stats,
100 			  const struct ia_css_isp_dvs_statistics *isp_stats);
101 
102 /* @brief Translate DVS statistics from ISP format to host format
103  * @param[in]	host_stats Host buffer
104  * @param[in]	isp_stats ISP buffer
105  * @return	None
106  *
107  * This function translates the dvs statistics from the ISP-internal
108  * format to the format used by the DVS library on the CPU.
109  * This function takes a host-side pointer as input. This can either
110  * point to a copy of the data or be a memory mapped pointer to the
111  * ISP memory pages.
112  */
113 void
114 ia_css_translate_dvs_statistics(
115     struct ia_css_dvs_statistics *host_stats,
116     const struct ia_css_isp_dvs_statistics_map *isp_stats);
117 
118 /* @brief Copy DVS 2.0 statistics from an ISP buffer to a host buffer.
119  * @param[in]	host_stats Host buffer
120  * @param[in]	isp_stats ISP buffer
121  * @return	error value if temporary memory cannot be allocated
122  *
123  * This may include a translation step as well depending
124  * on the ISP version.
125  * Always use this function, never copy the buffer directly.
126  * Note that this function uses the mem_load function from the CSS
127  * environment struct.
128  * In certain environments this may be slow. In those cases it is
129  * advised to map the ISP memory into a host-side pointer and use
130  * the ia_css_translate_dvs2_statistics() function instead.
131  */
132 int
133 ia_css_get_dvs2_statistics(struct ia_css_dvs2_statistics *host_stats,
134 			   const struct ia_css_isp_dvs_statistics *isp_stats);
135 
136 /* @brief Translate DVS2 statistics from ISP format to host format
137  * @param[in]	host_stats Host buffer
138  * @param[in]	isp_stats ISP buffer
139  * @return		None
140  *
141  * This function translates the dvs2 statistics from the ISP-internal
142  * format to the format used by the DVS2 library on the CPU.
143  * This function takes a host-side pointer as input. This can either
144  * point to a copy of the data or be a memory mapped pointer to the
145  * ISP memory pages.
146  */
147 void
148 ia_css_translate_dvs2_statistics(
149     struct ia_css_dvs2_statistics	   *host_stats,
150     const struct ia_css_isp_dvs_statistics_map *isp_stats);
151 
152 /* @brief Copy DVS statistics from an ISP buffer to a host buffer.
153  * @param[in] type - DVS statistics type
154  * @param[in] host_stats Host buffer
155  * @param[in] isp_stats ISP buffer
156  * @return None
157  */
158 void
159 ia_css_dvs_statistics_get(enum dvs_statistics_type type,
160 			  union ia_css_dvs_statistics_host  *host_stats,
161 			  const union ia_css_dvs_statistics_isp *isp_stats);
162 
163 /* @brief Allocate the DVS statistics memory on the ISP
164  * @param[in]	grid The grid.
165  * @return	Pointer to the allocated DVS statistics buffer on the ISP
166 */
167 struct ia_css_isp_dvs_statistics *
168 ia_css_isp_dvs_statistics_allocate(const struct ia_css_dvs_grid_info *grid);
169 
170 /* @brief Free the DVS statistics memory on the ISP
171  * @param[in]	me Pointer to the DVS statistics buffer on the ISP.
172  * @return	None
173 */
174 void
175 ia_css_isp_dvs_statistics_free(struct ia_css_isp_dvs_statistics *me);
176 
177 /* @brief Allocate the DVS 2.0 statistics memory
178  * @param[in]	grid The grid.
179  * @return	Pointer to the allocated DVS statistics buffer on the ISP
180 */
181 struct ia_css_isp_dvs_statistics *
182 ia_css_isp_dvs2_statistics_allocate(const struct ia_css_dvs_grid_info *grid);
183 
184 /* @brief Free the DVS 2.0 statistics memory
185  * @param[in]	me Pointer to the DVS statistics buffer on the ISP.
186  * @return	None
187 */
188 void
189 ia_css_isp_dvs2_statistics_free(struct ia_css_isp_dvs_statistics *me);
190 
191 /* @brief Allocate the DVS statistics memory on the host
192  * @param[in]	grid The grid.
193  * @return	Pointer to the allocated DVS statistics buffer on the host
194 */
195 struct ia_css_dvs_statistics *
196 ia_css_dvs_statistics_allocate(const struct ia_css_dvs_grid_info *grid);
197 
198 /* @brief Free the DVS statistics memory on the host
199  * @param[in]	me Pointer to the DVS statistics buffer on the host.
200  * @return	None
201 */
202 void
203 ia_css_dvs_statistics_free(struct ia_css_dvs_statistics *me);
204 
205 /* @brief Allocate the DVS coefficients memory
206  * @param[in]	grid The grid.
207  * @return	Pointer to the allocated DVS coefficients buffer
208 */
209 struct ia_css_dvs_coefficients *
210 ia_css_dvs_coefficients_allocate(const struct ia_css_dvs_grid_info *grid);
211 
212 /* @brief Free the DVS coefficients memory
213  * @param[in]	me Pointer to the DVS coefficients buffer.
214  * @return	None
215  */
216 void
217 ia_css_dvs_coefficients_free(struct ia_css_dvs_coefficients *me);
218 
219 /* @brief Allocate the DVS 2.0 statistics memory on the host
220  * @param[in]	grid The grid.
221  * @return	Pointer to the allocated DVS 2.0 statistics buffer on the host
222  */
223 struct ia_css_dvs2_statistics *
224 ia_css_dvs2_statistics_allocate(const struct ia_css_dvs_grid_info *grid);
225 
226 /* @brief Free the DVS 2.0 statistics memory
227  * @param[in]	me Pointer to the DVS 2.0 statistics buffer on the host.
228  * @return	None
229 */
230 void
231 ia_css_dvs2_statistics_free(struct ia_css_dvs2_statistics *me);
232 
233 /* @brief Allocate the DVS 2.0 coefficients memory
234  * @param[in]	grid The grid.
235  * @return	Pointer to the allocated DVS 2.0 coefficients buffer
236 */
237 struct ia_css_dvs2_coefficients *
238 ia_css_dvs2_coefficients_allocate(const struct ia_css_dvs_grid_info *grid);
239 
240 /* @brief Free the DVS 2.0 coefficients memory
241  * @param[in]	me Pointer to the DVS 2.0 coefficients buffer.
242  * @return	None
243 */
244 void
245 ia_css_dvs2_coefficients_free(struct ia_css_dvs2_coefficients *me);
246 
247 /* @brief Allocate the DVS 2.0 6-axis config memory
248  * @param[in]	stream The stream.
249  * @return	Pointer to the allocated DVS 6axis configuration buffer
250 */
251 struct ia_css_dvs_6axis_config *
252 ia_css_dvs2_6axis_config_allocate(const struct ia_css_stream *stream);
253 
254 /* @brief Free the DVS 2.0 6-axis config memory
255  * @param[in]	dvs_6axis_config Pointer to the DVS 6axis configuration buffer
256  * @return	None
257  */
258 void
259 ia_css_dvs2_6axis_config_free(struct ia_css_dvs_6axis_config *dvs_6axis_config);
260 
261 /* @brief Allocate a dvs statistics map structure
262  * @param[in]	isp_stats pointer to ISP dvs statistis struct
263  * @param[in]	data_ptr  host-side pointer to ISP dvs statistics.
264  * @return	Pointer to the allocated dvs statistics map
265  *
266  * This function allocates the ISP dvs statistics map structure
267  * and uses the data_ptr as base pointer to set the appropriate
268  * pointers to all relevant subsets of the dvs statistics (dmem,
269  * vmem, hmem).
270  * If the data_ptr is NULL, this function will allocate the host-side
271  * memory. This information is stored in the struct and used in the
272  * ia_css_isp_dvs_statistics_map_free() function to determine whether
273  * the memory should be freed or not.
274  * Note that this function does not allocate or map any ISP
275  * memory.
276 */
277 struct ia_css_isp_dvs_statistics_map *
278 ia_css_isp_dvs_statistics_map_allocate(
279     const struct ia_css_isp_dvs_statistics *isp_stats,
280     void *data_ptr);
281 
282 /* @brief Free the dvs statistics map
283  * @param[in]	me Pointer to the dvs statistics map
284  * @return	None
285  *
286  * This function frees the map struct. If the data_ptr inside it
287  * was allocated inside ia_css_isp_dvs_statistics_map_allocate(), it
288  * will be freed in this function. Otherwise it will not be freed.
289  */
290 void
291 ia_css_isp_dvs_statistics_map_free(struct ia_css_isp_dvs_statistics_map *me);
292 
293 /* @brief Allocate memory for the SKC DVS statistics on the ISP
294  * @return		Pointer to the allocated ACC DVS statistics buffer on the ISP
295 */
296 struct ia_css_isp_skc_dvs_statistics *ia_css_skc_dvs_statistics_allocate(void);
297 
298 #endif /*  __IA_CSS_DVS_H */
299