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