aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/media/atomisp/pci/isp/kernels/sdis/sdis_2/ia_css_sdis2.host.c
blob: f608740e8340dc21a2628da29acb18074f5928e7 (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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
// SPDX-License-Identifier: GPL-2.0
/*
 * 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.
 */

#include "hmm.h"

#include <assert_support.h>
#include "ia_css_debug.h"
#include "ia_css_sdis2.host.h"

const struct ia_css_dvs2_coefficients default_sdis2_config = {
	.grid = { 0, 0, 0, 0, 0, 0, 0, 0 },
	.hor_coefs = { NULL, NULL, NULL, NULL },
	.ver_coefs = { NULL, NULL, NULL, NULL },
};

static void
fill_row(short *private, const short *public, unsigned int width,
	 unsigned int padding)
{
	memcpy(private, public, width * sizeof(short));
	memset(&private[width], 0, padding * sizeof(short));
}

void ia_css_sdis2_horicoef_vmem_encode(
    struct sh_css_isp_sdis_hori_coef_tbl *to,
    const struct ia_css_dvs2_coefficients *from,
    unsigned int size)
{
	unsigned int aligned_width = from->grid.aligned_width *
				     from->grid.bqs_per_grid_cell;
	unsigned int width         = from->grid.num_hor_coefs;
	int      padding       = aligned_width - width;
	unsigned int stride        = size / IA_CSS_DVS2_NUM_COEF_TYPES / sizeof(short);
	unsigned int total_bytes   = aligned_width * IA_CSS_DVS2_NUM_COEF_TYPES *
				     sizeof(short);
	short   *private       = (short *)to;

	/* Copy the table, add padding */
	assert(padding >= 0);
	assert(total_bytes <= size);
	assert(size % (IA_CSS_DVS2_NUM_COEF_TYPES * ISP_VEC_NELEMS * sizeof(
			   short)) == 0);
	fill_row(&private[0 * stride], from->hor_coefs.odd_real,  width, padding);
	fill_row(&private[1 * stride], from->hor_coefs.odd_imag,  width, padding);
	fill_row(&private[2 * stride], from->hor_coefs.even_real, width, padding);
	fill_row(&private[3 * stride], from->hor_coefs.even_imag, width, padding);
}

void ia_css_sdis2_vertcoef_vmem_encode(
    struct sh_css_isp_sdis_vert_coef_tbl *to,
    const struct ia_css_dvs2_coefficients *from,
    unsigned int size)
{
	unsigned int aligned_height = from->grid.aligned_height *
				      from->grid.bqs_per_grid_cell;
	unsigned int height         = from->grid.num_ver_coefs;
	int      padding        = aligned_height - height;
	unsigned int stride         = size / IA_CSS_DVS2_NUM_COEF_TYPES / sizeof(short);
	unsigned int total_bytes    = aligned_height * IA_CSS_DVS2_NUM_COEF_TYPES *
				      sizeof(short);
	short   *private        = (short *)to;

	/* Copy the table, add padding */
	assert(padding >= 0);
	assert(total_bytes <= size);
	assert(size % (IA_CSS_DVS2_NUM_COEF_TYPES * ISP_VEC_NELEMS * sizeof(
			   short)) == 0);
	fill_row(&private[0 * stride], from->ver_coefs.odd_real,  height, padding);
	fill_row(&private[1 * stride], from->ver_coefs.odd_imag,  height, padding);
	fill_row(&private[2 * stride], from->ver_coefs.even_real, height, padding);
	fill_row(&private[3 * stride], from->ver_coefs.even_imag, height, padding);
}

void ia_css_sdis2_horiproj_encode(
    struct sh_css_isp_sdis_hori_proj_tbl *to,
    const struct ia_css_dvs2_coefficients *from,
    unsigned int size)
{
	(void)to;
	(void)from;
	(void)size;
}

void ia_css_sdis2_vertproj_encode(
    struct sh_css_isp_sdis_vert_proj_tbl *to,
    const struct ia_css_dvs2_coefficients *from,
    unsigned int size)
{
	(void)to;
	(void)from;
	(void)size;
}

void ia_css_get_isp_dvs2_coefficients(
    struct ia_css_stream *stream,
    short *hor_coefs_odd_real,
    short *hor_coefs_odd_imag,
    short *hor_coefs_even_real,
    short *hor_coefs_even_imag,
    short *ver_coefs_odd_real,
    short *ver_coefs_odd_imag,
    short *ver_coefs_even_real,
    short *ver_coefs_even_imag)
{
	struct ia_css_isp_parameters *params;
	unsigned int hor_num_3a, ver_num_3a;
	struct ia_css_binary *dvs_binary;

	IA_CSS_ENTER("void");

	assert(stream);
	assert(hor_coefs_odd_real);
	assert(hor_coefs_odd_imag);
	assert(hor_coefs_even_real);
	assert(hor_coefs_even_imag);
	assert(ver_coefs_odd_real);
	assert(ver_coefs_odd_imag);
	assert(ver_coefs_even_real);
	assert(ver_coefs_even_imag);

	params = stream->isp_params_configs;

	/* Only video pipe supports DVS */
	dvs_binary = ia_css_stream_get_dvs_binary(stream);
	if (!dvs_binary)
		return;

	hor_num_3a  = dvs_binary->dis.coef.dim.width;
	ver_num_3a  = dvs_binary->dis.coef.dim.height;

	memcpy(hor_coefs_odd_real,  params->dvs2_coefs.hor_coefs.odd_real,
	       hor_num_3a * sizeof(short));
	memcpy(hor_coefs_odd_imag,  params->dvs2_coefs.hor_coefs.odd_imag,
	       hor_num_3a * sizeof(short));
	memcpy(hor_coefs_even_real, params->dvs2_coefs.hor_coefs.even_real,
	       hor_num_3a * sizeof(short));
	memcpy(hor_coefs_even_imag, params->dvs2_coefs.hor_coefs.even_imag,
	       hor_num_3a * sizeof(short));
	memcpy(ver_coefs_odd_real,  params->dvs2_coefs.ver_coefs.odd_real,
	       ver_num_3a * sizeof(short));
	memcpy(ver_coefs_odd_imag,  params->dvs2_coefs.ver_coefs.odd_imag,
	       ver_num_3a * sizeof(short));
	memcpy(ver_coefs_even_real, params->dvs2_coefs.ver_coefs.even_real,
	       ver_num_3a * sizeof(short));
	memcpy(ver_coefs_even_imag, params->dvs2_coefs.ver_coefs.even_imag,
	       ver_num_3a * sizeof(short));

	IA_CSS_LEAVE("void");
}

void ia_css_sdis2_clear_coefficients(
    struct ia_css_dvs2_coefficients *dvs2_coefs)
{
	dvs2_coefs->hor_coefs.odd_real  = NULL;
	dvs2_coefs->hor_coefs.odd_imag  = NULL;
	dvs2_coefs->hor_coefs.even_real = NULL;
	dvs2_coefs->hor_coefs.even_imag = NULL;
	dvs2_coefs->ver_coefs.odd_real  = NULL;
	dvs2_coefs->ver_coefs.odd_imag  = NULL;
	dvs2_coefs->ver_coefs.even_real = NULL;
	dvs2_coefs->ver_coefs.even_imag = NULL;
}

int
ia_css_get_dvs2_statistics(
    struct ia_css_dvs2_statistics          *host_stats,
    const struct ia_css_isp_dvs_statistics *isp_stats) {
	struct ia_css_isp_dvs_statistics_map *map;
	int ret = 0;

	IA_CSS_ENTER("host_stats=%p, isp_stats=%p", host_stats, isp_stats);

	assert(host_stats);
	assert(isp_stats);

	map = ia_css_isp_dvs_statistics_map_allocate(isp_stats, NULL);
	if (map)
	{
		hmm_load(isp_stats->data_ptr, map->data_ptr, isp_stats->size);
		ia_css_translate_dvs2_statistics(host_stats, map);
		ia_css_isp_dvs_statistics_map_free(map);
	} else
	{
		IA_CSS_ERROR("out of memory");
		ret = -ENOMEM;
	}

	IA_CSS_LEAVE_ERR(ret);
	return ret;
}

void
ia_css_translate_dvs2_statistics(
    struct ia_css_dvs2_statistics		   *host_stats,
    const struct ia_css_isp_dvs_statistics_map *isp_stats)
{
	unsigned int size_bytes, table_width, table_size, height;
	unsigned int src_offset = 0, dst_offset = 0;
	s32 *htemp_ptr, *vtemp_ptr;

	assert(host_stats);
	assert(host_stats->hor_prod.odd_real);
	assert(host_stats->hor_prod.odd_imag);
	assert(host_stats->hor_prod.even_real);
	assert(host_stats->hor_prod.even_imag);
	assert(host_stats->ver_prod.odd_real);
	assert(host_stats->ver_prod.odd_imag);
	assert(host_stats->ver_prod.even_real);
	assert(host_stats->ver_prod.even_imag);
	assert(isp_stats);
	assert(isp_stats->hor_proj);
	assert(isp_stats->ver_proj);

	IA_CSS_ENTER("hor_coefs.odd_real=%p, hor_coefs.odd_imag=%p, hor_coefs.even_real=%p, hor_coefs.even_imag=%p, ver_coefs.odd_real=%p, ver_coefs.odd_imag=%p, ver_coefs.even_real=%p, ver_coefs.even_imag=%p, haddr=%p, vaddr=%p",
		     host_stats->hor_prod.odd_real, host_stats->hor_prod.odd_imag,
		     host_stats->hor_prod.even_real, host_stats->hor_prod.even_imag,
		     host_stats->ver_prod.odd_real, host_stats->ver_prod.odd_imag,
		     host_stats->ver_prod.even_real, host_stats->ver_prod.even_imag,
		     isp_stats->hor_proj, isp_stats->ver_proj);

	/* Host side: reflecting the true width in bytes */
	size_bytes = host_stats->grid.aligned_width * sizeof(*htemp_ptr);

	/* DDR side: need to be aligned to the system bus width */
	/* statistics table width in terms of 32-bit words*/
	table_width = CEIL_MUL(size_bytes,
			       HIVE_ISP_DDR_WORD_BYTES) / sizeof(*htemp_ptr);
	table_size = table_width * host_stats->grid.aligned_height;

	htemp_ptr = isp_stats->hor_proj; /* horizontal stats */
	vtemp_ptr = isp_stats->ver_proj; /* vertical stats */
	for (height = 0; height < host_stats->grid.aligned_height; height++) {
		/* hor stats */
		memcpy(host_stats->hor_prod.odd_real + dst_offset,
		       &htemp_ptr[0 * table_size + src_offset], size_bytes);
		memcpy(host_stats->hor_prod.odd_imag + dst_offset,
		       &htemp_ptr[1 * table_size + src_offset], size_bytes);
		memcpy(host_stats->hor_prod.even_real + dst_offset,
		       &htemp_ptr[2 * table_size + src_offset], size_bytes);
		memcpy(host_stats->hor_prod.even_imag + dst_offset,
		       &htemp_ptr[3 * table_size + src_offset], size_bytes);

		/* ver stats */
		memcpy(host_stats->ver_prod.odd_real + dst_offset,
		       &vtemp_ptr[0 * table_size + src_offset], size_bytes);
		memcpy(host_stats->ver_prod.odd_imag + dst_offset,
		       &vtemp_ptr[1 * table_size + src_offset], size_bytes);
		memcpy(host_stats->ver_prod.even_real + dst_offset,
		       &vtemp_ptr[2 * table_size + src_offset], size_bytes);
		memcpy(host_stats->ver_prod.even_imag + dst_offset,
		       &vtemp_ptr[3 * table_size + src_offset], size_bytes);

		src_offset += table_width; /* aligned table width */
		dst_offset += host_stats->grid.aligned_width;
	}

	IA_CSS_LEAVE("void");
}

struct ia_css_isp_dvs_statistics *
ia_css_isp_dvs2_statistics_allocate(
    const struct ia_css_dvs_grid_info *grid)
{
	struct ia_css_isp_dvs_statistics *me;
	int size;

	assert(grid);

	IA_CSS_ENTER("grid=%p", grid);

	if (!grid->enable)
		return NULL;

	me = kvcalloc(1, sizeof(*me), GFP_KERNEL);
	if (!me)
		goto err;

	/* on ISP 2 SDIS DMA model, every row of projection table width must be
	   aligned to HIVE_ISP_DDR_WORD_BYTES
	*/
	size = CEIL_MUL(sizeof(int) * grid->aligned_width, HIVE_ISP_DDR_WORD_BYTES)
	       * grid->aligned_height * IA_CSS_DVS2_NUM_COEF_TYPES;

	me->size = 2 * size;
	me->data_ptr = hmm_alloc(me->size, HMM_BO_PRIVATE, 0, NULL, 0);
	if (me->data_ptr == mmgr_NULL)
		goto err;
	me->hor_proj = me->data_ptr;
	me->hor_size = size;
	me->ver_proj = me->data_ptr + size;
	me->ver_size = size;

	IA_CSS_LEAVE("return=%p", me);
	return me;
err:
	ia_css_isp_dvs2_statistics_free(me);
	IA_CSS_LEAVE("return=%p", NULL);

	return NULL;
}

void
ia_css_isp_dvs2_statistics_free(struct ia_css_isp_dvs_statistics *me)
{
	if (me) {
		hmm_free(me->data_ptr);
		kvfree(me);
	}
}

void ia_css_sdis2_horicoef_debug_dtrace(
    const struct ia_css_dvs2_coefficients *config, unsigned int level)
{
	(void)config;
	(void)level;
}

void ia_css_sdis2_vertcoef_debug_dtrace(
    const struct ia_css_dvs2_coefficients *config, unsigned int level)
{
	(void)config;
	(void)level;
}

void ia_css_sdis2_horiproj_debug_dtrace(
    const struct ia_css_dvs2_coefficients *config, unsigned int level)
{
	(void)config;
	(void)level;
}

void ia_css_sdis2_vertproj_debug_dtrace(
    const struct ia_css_dvs2_coefficients *config, unsigned int level)
{
	(void)config;
	(void)level;
}