2 * Support for Intel Camera Imaging ISP subsystem.
3 * Copyright (c) 2015, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 #ifndef __IA_CSS_DVS_H
16 #define __IA_CSS_DVS_H
19 * This file contains types for DVS statistics
22 #include <type_support.h>
23 #include "ia_css_types.h"
24 #include "ia_css_err.h"
25 #include "ia_css_stream_public.h"
27 enum dvs_statistics_type {
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).
38 struct ia_css_isp_dvs_statistics {
43 uint32_t exp_id; /**< see ia_css_event_public.h for more detail */
44 ia_css_ptr data_ptr; /* base pointer containing all memory */
45 uint32_t size; /* size of allocated memory in data_ptr */
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.
52 struct ia_css_isp_skc_dvs_statistics;
55 #define SIZE_OF_IA_CSS_ISP_DVS_STATISTICS_STRUCT \
56 ((3 * SIZE_OF_IA_CSS_PTR) + \
57 (4 * sizeof(uint32_t)))
59 /* Map with host-side pointers to ISP-format statistics.
60 * These pointers can either be copies of ISP data or memory mapped
62 * All of the data behind these pointers is allocatd contiguously, the
63 * allocated pointer is stored in the data_ptr field. The other fields
64 * point into this one block of data.
66 struct ia_css_isp_dvs_statistics_map {
70 uint32_t size; /* total size in bytes */
71 uint32_t data_allocated; /* indicate whether data was allocated */
74 union ia_css_dvs_statistics_isp {
75 struct ia_css_isp_dvs_statistics *p_dvs_statistics_isp;
76 struct ia_css_isp_skc_dvs_statistics *p_skc_dvs_statistics_isp;
79 union ia_css_dvs_statistics_host {
80 struct ia_css_dvs_statistics *p_dvs_statistics_host;
81 struct ia_css_dvs2_statistics *p_dvs2_statistics_host;
82 struct ia_css_skc_dvs_statistics *p_skc_dvs_statistics_host;
85 /** @brief Copy DVS statistics from an ISP buffer to a host buffer.
86 * @param[in] host_stats Host buffer
87 * @param[in] isp_stats ISP buffer
88 * @return error value if temporary memory cannot be allocated
90 * This may include a translation step as well depending
92 * Always use this function, never copy the buffer directly.
93 * Note that this function uses the mem_load function from the CSS
95 * In certain environments this may be slow. In those cases it is
96 * advised to map the ISP memory into a host-side pointer and use
97 * the ia_css_translate_dvs_statistics() function instead.
100 ia_css_get_dvs_statistics(struct ia_css_dvs_statistics *host_stats,
101 const struct ia_css_isp_dvs_statistics *isp_stats);
103 /** @brief Translate DVS statistics from ISP format to host format
104 * @param[in] host_stats Host buffer
105 * @param[in] isp_stats ISP buffer
108 * This function translates the dvs statistics from the ISP-internal
109 * format to the format used by the DVS library on the CPU.
110 * This function takes a host-side pointer as input. This can either
111 * point to a copy of the data or be a memory mapped pointer to the
115 ia_css_translate_dvs_statistics(
116 struct ia_css_dvs_statistics *host_stats,
117 const struct ia_css_isp_dvs_statistics_map *isp_stats);
119 /** @brief Copy DVS 2.0 statistics from an ISP buffer to a host buffer.
120 * @param[in] host_stats Host buffer
121 * @param[in] isp_stats ISP buffer
122 * @return error value if temporary memory cannot be allocated
124 * This may include a translation step as well depending
125 * on the ISP version.
126 * Always use this function, never copy the buffer directly.
127 * Note that this function uses the mem_load function from the CSS
128 * environment struct.
129 * In certain environments this may be slow. In those cases it is
130 * advised to map the ISP memory into a host-side pointer and use
131 * the ia_css_translate_dvs2_statistics() function instead.
134 ia_css_get_dvs2_statistics(struct ia_css_dvs2_statistics *host_stats,
135 const struct ia_css_isp_dvs_statistics *isp_stats);
137 /** @brief Translate DVS2 statistics from ISP format to host format
138 * @param[in] host_stats Host buffer
139 * @param[in] isp_stats ISP buffer
142 * This function translates the dvs2 statistics from the ISP-internal
143 * format to the format used by the DVS2 library on the CPU.
144 * This function takes a host-side pointer as input. This can either
145 * point to a copy of the data or be a memory mapped pointer to the
149 ia_css_translate_dvs2_statistics(
150 struct ia_css_dvs2_statistics *host_stats,
151 const struct ia_css_isp_dvs_statistics_map *isp_stats);
153 /** @brief Copy DVS statistics from an ISP buffer to a host buffer.
154 * @param[in] type - DVS statistics type
155 * @param[in] host_stats Host buffer
156 * @param[in] isp_stats ISP buffer
160 ia_css_dvs_statistics_get(enum dvs_statistics_type type,
161 union ia_css_dvs_statistics_host *host_stats,
162 const union ia_css_dvs_statistics_isp *isp_stats);
164 /** @brief Allocate the DVS statistics memory on the ISP
165 * @param[in] grid The grid.
166 * @return Pointer to the allocated DVS statistics buffer on the ISP
168 struct ia_css_isp_dvs_statistics *
169 ia_css_isp_dvs_statistics_allocate(const struct ia_css_dvs_grid_info *grid);
171 /** @brief Free the DVS statistics memory on the ISP
172 * @param[in] me Pointer to the DVS statistics buffer on the ISP.
176 ia_css_isp_dvs_statistics_free(struct ia_css_isp_dvs_statistics *me);
178 /** @brief Allocate the DVS 2.0 statistics memory
179 * @param[in] grid The grid.
180 * @return Pointer to the allocated DVS statistics buffer on the ISP
182 struct ia_css_isp_dvs_statistics *
183 ia_css_isp_dvs2_statistics_allocate(const struct ia_css_dvs_grid_info *grid);
185 /** @brief Free the DVS 2.0 statistics memory
186 * @param[in] me Pointer to the DVS statistics buffer on the ISP.
190 ia_css_isp_dvs2_statistics_free(struct ia_css_isp_dvs_statistics *me);
192 /** @brief Allocate the DVS statistics memory on the host
193 * @param[in] grid The grid.
194 * @return Pointer to the allocated DVS statistics buffer on the host
196 struct ia_css_dvs_statistics *
197 ia_css_dvs_statistics_allocate(const struct ia_css_dvs_grid_info *grid);
199 /** @brief Free the DVS statistics memory on the host
200 * @param[in] me Pointer to the DVS statistics buffer on the host.
204 ia_css_dvs_statistics_free(struct ia_css_dvs_statistics *me);
206 /** @brief Allocate the DVS coefficients memory
207 * @param[in] grid The grid.
208 * @return Pointer to the allocated DVS coefficients buffer
210 struct ia_css_dvs_coefficients *
211 ia_css_dvs_coefficients_allocate(const struct ia_css_dvs_grid_info *grid);
213 /** @brief Free the DVS coefficients memory
214 * @param[in] me Pointer to the DVS coefficients buffer.
218 ia_css_dvs_coefficients_free(struct ia_css_dvs_coefficients *me);
220 /** @brief Allocate the DVS 2.0 statistics memory on the host
221 * @param[in] grid The grid.
222 * @return Pointer to the allocated DVS 2.0 statistics buffer on the host
224 struct ia_css_dvs2_statistics *
225 ia_css_dvs2_statistics_allocate(const struct ia_css_dvs_grid_info *grid);
227 /** @brief Free the DVS 2.0 statistics memory
228 * @param[in] me Pointer to the DVS 2.0 statistics buffer on the host.
232 ia_css_dvs2_statistics_free(struct ia_css_dvs2_statistics *me);
234 /** @brief Allocate the DVS 2.0 coefficients memory
235 * @param[in] grid The grid.
236 * @return Pointer to the allocated DVS 2.0 coefficients buffer
238 struct ia_css_dvs2_coefficients *
239 ia_css_dvs2_coefficients_allocate(const struct ia_css_dvs_grid_info *grid);
241 /** @brief Free the DVS 2.0 coefficients memory
242 * @param[in] me Pointer to the DVS 2.0 coefficients buffer.
246 ia_css_dvs2_coefficients_free(struct ia_css_dvs2_coefficients *me);
248 /** @brief Allocate the DVS 2.0 6-axis config memory
249 * @param[in] stream The stream.
250 * @return Pointer to the allocated DVS 6axis configuration buffer
252 struct ia_css_dvs_6axis_config *
253 ia_css_dvs2_6axis_config_allocate(const struct ia_css_stream *stream);
255 /** @brief Free the DVS 2.0 6-axis config memory
256 * @param[in] dvs_6axis_config Pointer to the DVS 6axis configuration buffer
260 ia_css_dvs2_6axis_config_free(struct ia_css_dvs_6axis_config *dvs_6axis_config);
262 /** @brief Allocate a dvs statistics map structure
263 * @param[in] isp_stats pointer to ISP dvs statistis struct
264 * @param[in] data_ptr host-side pointer to ISP dvs statistics.
265 * @return Pointer to the allocated dvs statistics map
267 * This function allocates the ISP dvs statistics map structure
268 * and uses the data_ptr as base pointer to set the appropriate
269 * pointers to all relevant subsets of the dvs statistics (dmem,
271 * If the data_ptr is NULL, this function will allocate the host-side
272 * memory. This information is stored in the struct and used in the
273 * ia_css_isp_dvs_statistics_map_free() function to determine whether
274 * the memory should be freed or not.
275 * Note that this function does not allocate or map any ISP
278 struct ia_css_isp_dvs_statistics_map *
279 ia_css_isp_dvs_statistics_map_allocate(
280 const struct ia_css_isp_dvs_statistics *isp_stats,
283 /** @brief Free the dvs statistics map
284 * @param[in] me Pointer to the dvs statistics map
287 * This function frees the map struct. If the data_ptr inside it
288 * was allocated inside ia_css_isp_dvs_statistics_map_allocate(), it
289 * will be freed in this function. Otherwise it will not be freed.
292 ia_css_isp_dvs_statistics_map_free(struct ia_css_isp_dvs_statistics_map *me);
294 /** @brief Allocate memory for the SKC DVS statistics on the ISP
295 * @return Pointer to the allocated ACC DVS statistics buffer on the ISP
297 struct ia_css_isp_skc_dvs_statistics *ia_css_skc_dvs_statistics_allocate(void);
299 #endif /* __IA_CSS_DVS_H */