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
20 * This file contains types used for 3A statistics
23 #include <type_support.h>
24 #include "ia_css_types.h"
25 #include "ia_css_err.h"
26 #include "system_global.h"
28 enum ia_css_3a_tables {
35 /* Structure that holds 3A statistics in the ISP internal
36 * format. Use ia_css_get_3a_statistics() to translate
37 * this to the format used on the host (3A library).
39 struct ia_css_isp_3a_statistics {
45 ia_css_ptr s3a_tbl_hi;
46 ia_css_ptr s3a_tbl_lo;
52 u32 exp_id; /** exposure id, to match statistics to a frame,
53 see ia_css_event_public.h for more detail. */
54 u32 isp_config_id;/** Unique ID to track which config was actually applied to a particular frame */
55 ia_css_ptr data_ptr; /** pointer to base of all data */
56 u32 size; /** total size of all data */
58 u32 vmem_size; /** both lo and hi have this size */
62 #define SIZE_OF_DMEM_STRUCT \
65 #define SIZE_OF_VMEM_STRUCT \
66 (2 * SIZE_OF_IA_CSS_PTR)
68 #define SIZE_OF_DATA_UNION \
69 (MAX(SIZE_OF_DMEM_STRUCT, SIZE_OF_VMEM_STRUCT))
71 #define SIZE_OF_DATA_HMEM_STRUCT \
74 #define SIZE_OF_IA_CSS_ISP_3A_STATISTICS_STRUCT \
75 (SIZE_OF_DATA_UNION + \
76 SIZE_OF_DATA_HMEM_STRUCT + \
79 SIZE_OF_IA_CSS_PTR + \
82 /* Map with host-side pointers to ISP-format statistics.
83 * These pointers can either be copies of ISP data or memory mapped
85 * All of the data behind these pointers is allocated contiguously, the
86 * allocated pointer is stored in the data_ptr field. The other fields
87 * point into this one block of data.
89 struct ia_css_isp_3a_statistics_map {
90 void *data_ptr; /** Pointer to start of memory */
91 struct ia_css_3a_output *dmem_stats;
94 struct ia_css_bh_table *hmem_stats;
95 u32 size; /** total size in bytes of data_ptr */
96 u32 data_allocated; /** indicate whether data_ptr
97 was allocated or not. */
100 /* @brief Copy and translate 3A statistics from an ISP buffer to a host buffer
101 * @param[out] host_stats Host buffer.
102 * @param[in] isp_stats ISP buffer.
103 * @return error value if temporary memory cannot be allocated
105 * This copies 3a statistics from an ISP pointer to a host pointer and then
106 * translates some of the statistics, details depend on which ISP binary is
108 * Always use this function, never copy the buffer directly.
111 ia_css_get_3a_statistics(struct ia_css_3a_statistics *host_stats,
112 const struct ia_css_isp_3a_statistics *isp_stats);
114 /* @brief Translate 3A statistics from ISP format to host format.
115 * @param[out] host_stats host-format statistics
116 * @param[in] isp_stats ISP-format statistics
119 * This function translates statistics from the internal ISP-format to
120 * the host-format. This function does not include an additional copy
124 ia_css_translate_3a_statistics(
125 struct ia_css_3a_statistics *host_stats,
126 const struct ia_css_isp_3a_statistics_map *isp_stats);
128 /* Convenience functions for alloc/free of certain datatypes */
130 /* @brief Allocate memory for the 3a statistics on the ISP
131 * @param[in] grid The grid.
132 * @return Pointer to the allocated 3a statistics buffer on the ISP
134 struct ia_css_isp_3a_statistics *
135 ia_css_isp_3a_statistics_allocate(const struct ia_css_3a_grid_info *grid);
137 /* @brief Free the 3a statistics memory on the isp
138 * @param[in] me Pointer to the 3a statistics buffer on the ISP.
142 ia_css_isp_3a_statistics_free(struct ia_css_isp_3a_statistics *me);
144 /* @brief Allocate memory for the 3a statistics on the host
145 * @param[in] grid The grid.
146 * @return Pointer to the allocated 3a statistics buffer on the host
148 struct ia_css_3a_statistics *
149 ia_css_3a_statistics_allocate(const struct ia_css_3a_grid_info *grid);
151 /* @brief Free the 3a statistics memory on the host
152 * @param[in] me Pointer to the 3a statistics buffer on the host.
156 ia_css_3a_statistics_free(struct ia_css_3a_statistics *me);
158 /* @brief Allocate a 3a statistics map structure
159 * @param[in] isp_stats pointer to ISP 3a statistis struct
160 * @param[in] data_ptr host-side pointer to ISP 3a statistics.
161 * @return Pointer to the allocated 3a statistics map
163 * This function allocates the ISP 3a statistics map structure
164 * and uses the data_ptr as base pointer to set the appropriate
165 * pointers to all relevant subsets of the 3a statistics (dmem,
167 * If the data_ptr is NULL, this function will allocate the host-side
168 * memory. This information is stored in the struct and used in the
169 * ia_css_isp_3a_statistics_map_free() function to determine whether
170 * the memory should be freed or not.
171 * Note that this function does not allocate or map any ISP
174 struct ia_css_isp_3a_statistics_map *
175 ia_css_isp_3a_statistics_map_allocate(
176 const struct ia_css_isp_3a_statistics *isp_stats,
179 /* @brief Free the 3a statistics map
180 * @param[in] me Pointer to the 3a statistics map
183 * This function frees the map struct. If the data_ptr inside it
184 * was allocated inside ia_css_isp_3a_statistics_map_allocate(), it
185 * will be freed in this function. Otherwise it will not be freed.
188 ia_css_isp_3a_statistics_map_free(struct ia_css_isp_3a_statistics_map *me);
190 #endif /* __IA_CSS_3A_H */