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
19 * This file contains types used for 3A statistics
22 #include <type_support.h>
23 #include "ia_css_types.h"
24 #include "ia_css_err.h"
25 #include "system_global.h"
27 enum ia_css_3a_tables {
34 /** Structure that holds 3A statistics in the ISP internal
35 * format. Use ia_css_get_3a_statistics() to translate
36 * this to the format used on the host (3A library).
38 struct ia_css_isp_3a_statistics {
44 ia_css_ptr s3a_tbl_hi;
45 ia_css_ptr s3a_tbl_lo;
51 uint32_t exp_id; /**< exposure id, to match statistics to a frame,
52 see ia_css_event_public.h for more detail. */
53 uint32_t isp_config_id;/**< Unique ID to track which config was actually applied to a particular frame */
54 ia_css_ptr data_ptr; /**< pointer to base of all data */
55 uint32_t size; /**< total size of all data */
57 uint32_t vmem_size; /**< both lo and hi have this size */
60 #define SIZE_OF_DMEM_STRUCT \
63 #define SIZE_OF_VMEM_STRUCT \
64 (2 * SIZE_OF_IA_CSS_PTR)
66 #define SIZE_OF_DATA_UNION \
67 (MAX(SIZE_OF_DMEM_STRUCT, SIZE_OF_VMEM_STRUCT))
69 #define SIZE_OF_DATA_HMEM_STRUCT \
72 #define SIZE_OF_IA_CSS_ISP_3A_STATISTICS_STRUCT \
73 (SIZE_OF_DATA_UNION + \
74 SIZE_OF_DATA_HMEM_STRUCT + \
77 SIZE_OF_IA_CSS_PTR + \
80 /** Map with host-side pointers to ISP-format statistics.
81 * These pointers can either be copies of ISP data or memory mapped
83 * All of the data behind these pointers is allocated contiguously, the
84 * allocated pointer is stored in the data_ptr field. The other fields
85 * point into this one block of data.
87 struct ia_css_isp_3a_statistics_map {
88 void *data_ptr; /**< Pointer to start of memory */
89 struct ia_css_3a_output *dmem_stats;
90 uint16_t *vmem_stats_hi;
91 uint16_t *vmem_stats_lo;
92 struct ia_css_bh_table *hmem_stats;
93 uint32_t size; /**< total size in bytes of data_ptr */
94 uint32_t data_allocated; /**< indicate whether data_ptr
95 was allocated or not. */
98 /** @brief Copy and translate 3A statistics from an ISP buffer to a host buffer
99 * @param[out] host_stats Host buffer.
100 * @param[in] isp_stats ISP buffer.
101 * @return error value if temporary memory cannot be allocated
103 * This copies 3a statistics from an ISP pointer to a host pointer and then
104 * translates some of the statistics, details depend on which ISP binary is
106 * Always use this function, never copy the buffer directly.
109 ia_css_get_3a_statistics(struct ia_css_3a_statistics *host_stats,
110 const struct ia_css_isp_3a_statistics *isp_stats);
112 /** @brief Translate 3A statistics from ISP format to host format.
113 * @param[out] host_stats host-format statistics
114 * @param[in] isp_stats ISP-format statistics
117 * This function translates statistics from the internal ISP-format to
118 * the host-format. This function does not include an additional copy
122 ia_css_translate_3a_statistics(
123 struct ia_css_3a_statistics *host_stats,
124 const struct ia_css_isp_3a_statistics_map *isp_stats);
126 /* Convenience functions for alloc/free of certain datatypes */
128 /** @brief Allocate memory for the 3a statistics on the ISP
129 * @param[in] grid The grid.
130 * @return Pointer to the allocated 3a statistics buffer on the ISP
132 struct ia_css_isp_3a_statistics *
133 ia_css_isp_3a_statistics_allocate(const struct ia_css_3a_grid_info *grid);
135 /** @brief Free the 3a statistics memory on the isp
136 * @param[in] me Pointer to the 3a statistics buffer on the ISP.
140 ia_css_isp_3a_statistics_free(struct ia_css_isp_3a_statistics *me);
142 /** @brief Allocate memory for the 3a statistics on the host
143 * @param[in] grid The grid.
144 * @return Pointer to the allocated 3a statistics buffer on the host
146 struct ia_css_3a_statistics *
147 ia_css_3a_statistics_allocate(const struct ia_css_3a_grid_info *grid);
149 /** @brief Free the 3a statistics memory on the host
150 * @param[in] me Pointer to the 3a statistics buffer on the host.
154 ia_css_3a_statistics_free(struct ia_css_3a_statistics *me);
156 /** @brief Allocate a 3a statistics map structure
157 * @param[in] isp_stats pointer to ISP 3a statistis struct
158 * @param[in] data_ptr host-side pointer to ISP 3a statistics.
159 * @return Pointer to the allocated 3a statistics map
161 * This function allocates the ISP 3a statistics map structure
162 * and uses the data_ptr as base pointer to set the appropriate
163 * pointers to all relevant subsets of the 3a statistics (dmem,
165 * If the data_ptr is NULL, this function will allocate the host-side
166 * memory. This information is stored in the struct and used in the
167 * ia_css_isp_3a_statistics_map_free() function to determine whether
168 * the memory should be freed or not.
169 * Note that this function does not allocate or map any ISP
172 struct ia_css_isp_3a_statistics_map *
173 ia_css_isp_3a_statistics_map_allocate(
174 const struct ia_css_isp_3a_statistics *isp_stats,
177 /** @brief Free the 3a statistics map
178 * @param[in] me Pointer to the 3a statistics map
181 * This function frees the map struct. If the data_ptr inside it
182 * was allocated inside ia_css_isp_3a_statistics_map_allocate(), it
183 * will be freed in this function. Otherwise it will not be freed.
186 ia_css_isp_3a_statistics_map_free(struct ia_css_isp_3a_statistics_map *me);
188 #endif /* __IA_CSS_3A_H */