aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_dvs.h
blob: 147bf81959d3b1a5e113ac01497c778b49f62253 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*
 * Support for Intel Camera Imaging ISP subsystem.
 * Copyright (c) 2015, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 */

#ifndef __IA_CSS_DVS_H
#define __IA_CSS_DVS_H

/** @file
 * This file contains types for DVS statistics
 */

#include <type_support.h>
#include "ia_css_types.h"
#include "ia_css_err.h"
#include "ia_css_stream_public.h"

enum dvs_statistics_type {
	DVS_STATISTICS,
	DVS2_STATISTICS,
	SKC_DVS_STATISTICS
};


/** Structure that holds DVS statistics in the ISP internal
 * format. Use ia_css_get_dvs_statistics() to translate
 * this to the format used on the host (DVS engine).
 * */
struct ia_css_isp_dvs_statistics {
	ia_css_ptr hor_proj;
	ia_css_ptr ver_proj;
	uint32_t   hor_size;
	uint32_t   ver_size;
	uint32_t   exp_id;   /**< see ia_css_event_public.h for more detail */
	ia_css_ptr data_ptr; /* base pointer containing all memory */
	uint32_t   size;     /* size of allocated memory in data_ptr */
};

/** Structure that holds SKC DVS statistics in the ISP internal
 * format. Use ia_css_dvs_statistics_get() to translate this to
 * the format used on the host.
 * */
struct ia_css_isp_skc_dvs_statistics;


#define SIZE_OF_IA_CSS_ISP_DVS_STATISTICS_STRUCT			\
	((3 * SIZE_OF_IA_CSS_PTR) +					\
	 (4 * sizeof(uint32_t)))

/* Map with host-side pointers to ISP-format statistics.
 * These pointers can either be copies of ISP data or memory mapped
 * ISP pointers.
 * All of the data behind these pointers is allocatd contiguously, the
 * allocated pointer is stored in the data_ptr field. The other fields
 * point into this one block of data.
 */
struct ia_css_isp_dvs_statistics_map {
	void    *data_ptr;
	int32_t *hor_proj;
	int32_t *ver_proj;
	uint32_t size;		 /* total size in bytes */
	uint32_t data_allocated; /* indicate whether data was allocated */
};

union ia_css_dvs_statistics_isp {
	struct ia_css_isp_dvs_statistics *p_dvs_statistics_isp;
	struct ia_css_isp_skc_dvs_statistics *p_skc_dvs_statistics_isp;
};

union ia_css_dvs_statistics_host {
	struct ia_css_dvs_statistics *p_dvs_statistics_host;
	struct ia_css_dvs2_statistics *p_dvs2_statistics_host;
	struct ia_css_skc_dvs_statistics *p_skc_dvs_statistics_host;
};

/** @brief Copy DVS statistics from an ISP buffer to a host buffer.
 * @param[in]	host_stats Host buffer
 * @param[in]	isp_stats ISP buffer
 * @return	error value if temporary memory cannot be allocated
 *
 * This may include a translation step as well depending
 * on the ISP version.
 * Always use this function, never copy the buffer directly.
 * Note that this function uses the mem_load function from the CSS
 * environment struct.
 * In certain environments this may be slow. In those cases it is
 * advised to map the ISP memory into a host-side pointer and use
 * the ia_css_translate_dvs_statistics() function instead.
 */
enum ia_css_err
ia_css_get_dvs_statistics(struct ia_css_dvs_statistics *host_stats,
			  const struct ia_css_isp_dvs_statistics *isp_stats);

/** @brief Translate DVS statistics from ISP format to host format
 * @param[in]	host_stats Host buffer
 * @param[in]	isp_stats ISP buffer
 * @return	None
 *
 * This function translates the dvs statistics from the ISP-internal
 * format to the format used by the DVS library on the CPU.
 * This function takes a host-side pointer as input. This can either
 * point to a copy of the data or be a memory mapped pointer to the
 * ISP memory pages.
 */
void
ia_css_translate_dvs_statistics(
		struct ia_css_dvs_statistics *host_stats,
		const struct ia_css_isp_dvs_statistics_map *isp_stats);

/** @brief Copy DVS 2.0 statistics from an ISP buffer to a host buffer.
 * @param[in]	host_stats Host buffer
 * @param[in]	isp_stats ISP buffer
 * @return	error value if temporary memory cannot be allocated
 *
 * This may include a translation step as well depending
 * on the ISP version.
 * Always use this function, never copy the buffer directly.
 * Note that this function uses the mem_load function from the CSS
 * environment struct.
 * In certain environments this may be slow. In those cases it is
 * advised to map the ISP memory into a host-side pointer and use
 * the ia_css_translate_dvs2_statistics() function instead.
 */
enum ia_css_err
ia_css_get_dvs2_statistics(struct ia_css_dvs2_statistics *host_stats,
			   const struct ia_css_isp_dvs_statistics *isp_stats);

/** @brief Translate DVS2 statistics from ISP format to host format
 * @param[in]	host_stats Host buffer
 * @param[in]	isp_stats ISP buffer
 * @return		None
 *
 * This function translates the dvs2 statistics from the ISP-internal
 * format to the format used by the DVS2 library on the CPU.
 * This function takes a host-side pointer as input. This can either
 * point to a copy of the data or be a memory mapped pointer to the
 * ISP memory pages.
 */
void
ia_css_translate_dvs2_statistics(
		struct ia_css_dvs2_statistics	   *host_stats,
		const struct ia_css_isp_dvs_statistics_map *isp_stats);

/** @brief Copy DVS statistics from an ISP buffer to a host buffer.
 * @param[in] type - DVS statistics type
 * @param[in] host_stats Host buffer
 * @param[in] isp_stats ISP buffer
 * @return None
 */
void
ia_css_dvs_statistics_get(enum dvs_statistics_type type,
			  union ia_css_dvs_statistics_host  *host_stats,
			  const union ia_css_dvs_statistics_isp *isp_stats);

/** @brief Allocate the DVS statistics memory on the ISP
 * @param[in]	grid The grid.
 * @return	Pointer to the allocated DVS statistics buffer on the ISP
*/
struct ia_css_isp_dvs_statistics *
ia_css_isp_dvs_statistics_allocate(const struct ia_css_dvs_grid_info *grid);

/** @brief Free the DVS statistics memory on the ISP
 * @param[in]	me Pointer to the DVS statistics buffer on the ISP.
 * @return	None
*/
void
ia_css_isp_dvs_statistics_free(struct ia_css_isp_dvs_statistics *me);

/** @brief Allocate the DVS 2.0 statistics memory
 * @param[in]	grid The grid.
 * @return	Pointer to the allocated DVS statistics buffer on the ISP
*/
struct ia_css_isp_dvs_statistics *
ia_css_isp_dvs2_statistics_allocate(const struct ia_css_dvs_grid_info *grid);

/** @brief Free the DVS 2.0 statistics memory
 * @param[in]	me Pointer to the DVS statistics buffer on the ISP.
 * @return	None
*/
void
ia_css_isp_dvs2_statistics_free(struct ia_css_isp_dvs_statistics *me);

/** @brief Allocate the DVS statistics memory on the host
 * @param[in]	grid The grid.
 * @return	Pointer to the allocated DVS statistics buffer on the host
*/
struct ia_css_dvs_statistics *
ia_css_dvs_statistics_allocate(const struct ia_css_dvs_grid_info *grid);

/** @brief Free the DVS statistics memory on the host
 * @param[in]	me Pointer to the DVS statistics buffer on the host.
 * @return	None
*/
void
ia_css_dvs_statistics_free(struct ia_css_dvs_statistics *me);

/** @brief Allocate the DVS coefficients memory
 * @param[in]	grid The grid.
 * @return	Pointer to the allocated DVS coefficients buffer
*/
struct ia_css_dvs_coefficients *
ia_css_dvs_coefficients_allocate(const struct ia_css_dvs_grid_info *grid);

/** @brief Free the DVS coefficients memory
 * @param[in]	me Pointer to the DVS coefficients buffer.
 * @return	None
 */
void
ia_css_dvs_coefficients_free(struct ia_css_dvs_coefficients *me);

/** @brief Allocate the DVS 2.0 statistics memory on the host
 * @param[in]	grid The grid.
 * @return	Pointer to the allocated DVS 2.0 statistics buffer on the host
 */
struct ia_css_dvs2_statistics *
ia_css_dvs2_statistics_allocate(const struct ia_css_dvs_grid_info *grid);

/** @brief Free the DVS 2.0 statistics memory
 * @param[in]	me Pointer to the DVS 2.0 statistics buffer on the host.
 * @return	None
*/
void
ia_css_dvs2_statistics_free(struct ia_css_dvs2_statistics *me);

/** @brief Allocate the DVS 2.0 coefficients memory
 * @param[in]	grid The grid.
 * @return	Pointer to the allocated DVS 2.0 coefficients buffer
*/
struct ia_css_dvs2_coefficients *
ia_css_dvs2_coefficients_allocate(const struct ia_css_dvs_grid_info *grid);

/** @brief Free the DVS 2.0 coefficients memory
 * @param[in]	me Pointer to the DVS 2.0 coefficients buffer.
 * @return	None
*/
void
ia_css_dvs2_coefficients_free(struct ia_css_dvs2_coefficients *me);

/** @brief Allocate the DVS 2.0 6-axis config memory
 * @param[in]	stream The stream.
 * @return	Pointer to the allocated DVS 6axis configuration buffer
*/
struct ia_css_dvs_6axis_config *
ia_css_dvs2_6axis_config_allocate(const struct ia_css_stream *stream);

/** @brief Free the DVS 2.0 6-axis config memory
 * @param[in]	dvs_6axis_config Pointer to the DVS 6axis configuration buffer
 * @return	None
 */
void
ia_css_dvs2_6axis_config_free(struct ia_css_dvs_6axis_config *dvs_6axis_config);

/** @brief Allocate a dvs statistics map structure
 * @param[in]	isp_stats pointer to ISP dvs statistis struct
 * @param[in]	data_ptr  host-side pointer to ISP dvs statistics.
 * @return	Pointer to the allocated dvs statistics map
 *
 * This function allocates the ISP dvs statistics map structure
 * and uses the data_ptr as base pointer to set the appropriate
 * pointers to all relevant subsets of the dvs statistics (dmem,
 * vmem, hmem).
 * If the data_ptr is NULL, this function will allocate the host-side
 * memory. This information is stored in the struct and used in the
 * ia_css_isp_dvs_statistics_map_free() function to determine whether
 * the memory should be freed or not.
 * Note that this function does not allocate or map any ISP
 * memory.
*/
struct ia_css_isp_dvs_statistics_map *
ia_css_isp_dvs_statistics_map_allocate(
	const struct ia_css_isp_dvs_statistics *isp_stats,
	void *data_ptr);

/** @brief Free the dvs statistics map
 * @param[in]	me Pointer to the dvs statistics map
 * @return	None
 *
 * This function frees the map struct. If the data_ptr inside it
 * was allocated inside ia_css_isp_dvs_statistics_map_allocate(), it
 * will be freed in this function. Otherwise it will not be freed.
 */
void
ia_css_isp_dvs_statistics_map_free(struct ia_css_isp_dvs_statistics_map *me);

/** @brief Allocate memory for the SKC DVS statistics on the ISP
 * @return		Pointer to the allocated ACC DVS statistics buffer on the ISP
*/
struct ia_css_isp_skc_dvs_statistics *ia_css_skc_dvs_statistics_allocate(void);

#endif /*  __IA_CSS_DVS_H */