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