1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Support for Intel Camera Imaging ISP subsystem.
4 * Copyright (c) 2015, Intel Corporation.
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.
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
16 #ifndef __IA_CSS_DVS_H
17 #define __IA_CSS_DVS_H
20 * This file contains types for DVS statistics
23 #include <type_support.h>
24 #include "ia_css_types.h"
25 #include "ia_css_err.h"
26 #include "ia_css_stream_public.h"
28 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 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 */
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;
54 #define SIZE_OF_IA_CSS_ISP_DVS_STATISTICS_STRUCT \
55 ((3 * SIZE_OF_IA_CSS_PTR) + \
56 (4 * sizeof(uint32_t)))
58 /* Map with host-side pointers to ISP-format statistics.
59 * These pointers can either be copies of ISP data or memory mapped
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.
65 struct ia_css_isp_dvs_statistics_map {
69 u32 size; /* total size in bytes */
70 u32 data_allocated; /* indicate whether data was allocated */
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;
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;
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
89 * This may include a translation step as well depending
91 * Always use this function, never copy the buffer directly.
92 * Note that this function uses the mem_load function from the CSS
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.
99 ia_css_get_dvs_statistics(struct ia_css_dvs_statistics *host_stats,
100 const struct ia_css_isp_dvs_statistics *isp_stats);
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
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
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);
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
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.
133 ia_css_get_dvs2_statistics(struct ia_css_dvs2_statistics *host_stats,
134 const struct ia_css_isp_dvs_statistics *isp_stats);
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
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
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);
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
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);
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
167 struct ia_css_isp_dvs_statistics *
168 ia_css_isp_dvs_statistics_allocate(const struct ia_css_dvs_grid_info *grid);
170 /* @brief Free the DVS statistics memory on the ISP
171 * @param[in] me Pointer to the DVS statistics buffer on the ISP.
175 ia_css_isp_dvs_statistics_free(struct ia_css_isp_dvs_statistics *me);
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
181 struct ia_css_isp_dvs_statistics *
182 ia_css_isp_dvs2_statistics_allocate(const struct ia_css_dvs_grid_info *grid);
184 /* @brief Free the DVS 2.0 statistics memory
185 * @param[in] me Pointer to the DVS statistics buffer on the ISP.
189 ia_css_isp_dvs2_statistics_free(struct ia_css_isp_dvs_statistics *me);
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
195 struct ia_css_dvs_statistics *
196 ia_css_dvs_statistics_allocate(const struct ia_css_dvs_grid_info *grid);
198 /* @brief Free the DVS statistics memory on the host
199 * @param[in] me Pointer to the DVS statistics buffer on the host.
203 ia_css_dvs_statistics_free(struct ia_css_dvs_statistics *me);
205 /* @brief Allocate the DVS coefficients memory
206 * @param[in] grid The grid.
207 * @return Pointer to the allocated DVS coefficients buffer
209 struct ia_css_dvs_coefficients *
210 ia_css_dvs_coefficients_allocate(const struct ia_css_dvs_grid_info *grid);
212 /* @brief Free the DVS coefficients memory
213 * @param[in] me Pointer to the DVS coefficients buffer.
217 ia_css_dvs_coefficients_free(struct ia_css_dvs_coefficients *me);
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
223 struct ia_css_dvs2_statistics *
224 ia_css_dvs2_statistics_allocate(const struct ia_css_dvs_grid_info *grid);
226 /* @brief Free the DVS 2.0 statistics memory
227 * @param[in] me Pointer to the DVS 2.0 statistics buffer on the host.
231 ia_css_dvs2_statistics_free(struct ia_css_dvs2_statistics *me);
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
237 struct ia_css_dvs2_coefficients *
238 ia_css_dvs2_coefficients_allocate(const struct ia_css_dvs_grid_info *grid);
240 /* @brief Free the DVS 2.0 coefficients memory
241 * @param[in] me Pointer to the DVS 2.0 coefficients buffer.
245 ia_css_dvs2_coefficients_free(struct ia_css_dvs2_coefficients *me);
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
251 struct ia_css_dvs_6axis_config *
252 ia_css_dvs2_6axis_config_allocate(const struct ia_css_stream *stream);
254 /* @brief Free the DVS 2.0 6-axis config memory
255 * @param[in] dvs_6axis_config Pointer to the DVS 6axis configuration buffer
259 ia_css_dvs2_6axis_config_free(struct ia_css_dvs_6axis_config *dvs_6axis_config);
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
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,
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
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,
282 /* @brief Free the dvs statistics map
283 * @param[in] me Pointer to the dvs statistics map
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.
291 ia_css_isp_dvs_statistics_map_free(struct ia_css_isp_dvs_statistics_map *me);
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
296 struct ia_css_isp_skc_dvs_statistics *ia_css_skc_dvs_statistics_allocate(void);
298 #endif /* __IA_CSS_DVS_H */