Media: Wave5: Fix plane size mismatch
[platform/kernel/linux-starfive.git] / drivers / media / platform / chips-media / wave5 / wave5-vpuapi.h
1 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
2 /*
3  * Wave5 series multi-standard codec IP - helper definitions
4  *
5  * Copyright (C) 2021 CHIPS&MEDIA INC
6  */
7
8 #ifndef VPUAPI_H_INCLUDED
9 #define VPUAPI_H_INCLUDED
10
11 #include <linux/kfifo.h>
12 #include <linux/idr.h>
13 #include <media/v4l2-device.h>
14 #include <media/v4l2-mem2mem.h>
15 #include <media/v4l2-ctrls.h>
16 #include "wave5-vpuerror.h"
17 #include "wave5-vpuconfig.h"
18 #include "wave5-vdi.h"
19
20 enum product_id {
21         PRODUCT_ID_521,
22         PRODUCT_ID_511,
23         PRODUCT_ID_517,
24         PRODUCT_ID_NONE,
25 };
26
27 struct vpu_attr;
28
29 enum vpu_instance_type {
30         VPU_INST_TYPE_DEC = 0,
31         VPU_INST_TYPE_ENC = 1
32 };
33
34 enum vpu_instance_state {
35         VPU_INST_STATE_NONE = 0,
36         VPU_INST_STATE_OPEN = 1,
37         VPU_INST_STATE_INIT_SEQ = 2,
38         VPU_INST_STATE_PIC_RUN = 3,
39         VPU_INST_STATE_STOP = 4
40 };
41
42 #define WAVE5_MAX_FBS 32
43
44 #define MAX_REG_FRAME (WAVE5_MAX_FBS * 2)
45
46 #define WAVE5_DEC_HEVC_BUF_SIZE(_w, _h) (DIV_ROUND_UP(_w, 64) * DIV_ROUND_UP(_h, 64) * 256 + 64)
47 #define WAVE5_DEC_AVC_BUF_SIZE(_w, _h) ((((ALIGN(_w, 256) / 16) * (ALIGN(_h, 16) / 16)) + 16) * 80)
48 #define WAVE5_DEC_VP9_BUF_SIZE(_w, _h) (((ALIGN(_w, 64) * ALIGN(_h, 64)) >> 2))
49 #define WAVE5_DEC_AVS2_BUF_SIZE(_w, _h) (((ALIGN(_w, 64) * ALIGN(_h, 64)) >> 5))
50 // AV1 BUF SIZE : MFMV + segment ID + CDF probs table + film grain param Y+ film graim param C
51 #define WAVE5_DEC_AV1_BUF_SZ_1(_w, _h)  \
52         (((ALIGN(_w, 64) / 64) * (ALIGN(_h, 64) / 64) * 512) + 41984 + 8192 + 4864)
53 #define WAVE5_DEC_AV1_BUF_SZ_2(_w1, _w2, _h)    \
54         (((ALIGN(_w1, 64) / 64) * 256 + (ALIGN(_w2, 256) / 64) * 128) * (ALIGN(_h, 64) / 64))
55
56 #define WAVE5_FBC_LUMA_TABLE_SIZE(_w, _h) (ALIGN(_h, 64) * ALIGN(_w, 256) / 32)
57 #define WAVE5_FBC_CHROMA_TABLE_SIZE(_w, _h) (ALIGN((_h), 64) * ALIGN((_w) / 2, 256) / 32)
58 #define WAVE5_ENC_AVC_BUF_SIZE(_w, _h) (ALIGN(_w, 64) * ALIGN(_h, 64) / 32)
59 #define WAVE5_ENC_HEVC_BUF_SIZE(_w, _h) (ALIGN(_w, 64) / 64 * ALIGN(_h, 64) / 64 * 128)
60
61 /*
62  * common struct and definition
63  */
64 enum cod_std {
65         STD_AVC = 0,
66         STD_VC1 = 1,
67         STD_MPEG2 = 2,
68         STD_MPEG4 = 3,
69         STD_H263 = 4,
70         STD_DIV3 = 5,
71         STD_RV = 6,
72         STD_AVS = 7,
73         STD_THO = 9,
74         STD_VP3 = 10,
75         STD_VP8 = 11,
76         STD_HEVC = 12,
77         STD_VP9 = 13,
78         STD_AVS2 = 14,
79         STD_AV1 = 16,
80         STD_MAX
81 };
82
83 enum wave_std {
84         W_HEVC_DEC = 0x00,
85         W_HEVC_ENC = 0x01,
86         W_AVC_DEC = 0x02,
87         W_AVC_ENC = 0x03,
88         W_VP9_DEC = 0x16,
89         W_AVS2_DEC = 0x18,
90         W_AV1_DEC = 0x1A,
91         STD_UNKNOWN = 0xFF
92 };
93
94 enum SET_PARAM_OPTION {
95         OPT_COMMON = 0, /* SET_PARAM command option for encoding sequence */
96         OPT_CUSTOM_GOP = 1, /* SET_PARAM command option for setting custom GOP */
97         OPT_CUSTOM_HEADER = 2, /* SET_PARAM command option for setting custom VPS/SPS/PPS */
98         OPT_VUI = 3, /* SET_PARAM command option for encoding VUI */
99         OPT_CHANGE_PARAM = 0x10,
100 };
101
102 enum DEC_PIC_HDR_OPTION {
103         INIT_SEQ_NORMAL = 0x01,
104         INIT_SEQ_W_THUMBNAIL = 0x11,
105 };
106
107 enum DEC_PIC_OPTION {
108         DEC_PIC_NORMAL = 0x00, /* it is normal mode of DEC_PIC command */
109         DEC_PIC_W_THUMBNAIL = 0x10, /* thumbnail mode (skip non-IRAP without reference reg) */
110         SKIP_NON_IRAP = 0x11, /* it skips to decode non-IRAP pictures */
111         SKIP_NON_REF_PIC = 0x13
112 };
113
114 /************************************************************************/
115 /* PROFILE & LEVEL */
116 /************************************************************************/
117 /* HEVC */
118 #define HEVC_PROFILE_MAIN 1
119 #define HEVC_PROFILE_MAIN10 2
120 #define HEVC_PROFILE_STILLPICTURE 3
121 #define HEVC_PROFILE_MAIN10_STILLPICTURE 2
122
123 /* H.264 profile for encoder*/
124 #define H264_PROFILE_BP 1
125 #define H264_PROFILE_MP 2
126 #define H264_PROFILE_EXTENDED 3
127 #define H264_PROFILE_HP 4
128 #define H264_PROFILE_HIGH10 5
129 #define H264_PROFILE_HIGH422 6
130 #define H264_PROFILE_HIGH444 7
131
132 /************************************************************************/
133 /* error codes */
134 /************************************************************************/
135
136 /************************************************************************/
137 /* utility macros */
138 /************************************************************************/
139
140 /* bit_alloc_mode */
141 #define BIT_ALLOC_MODE_FIXED_RATIO              2
142
143 /* bit_rate */
144 #define MAX_BIT_RATE                            700000000
145
146 /* decoding_refresh_type */
147 #define DEC_REFRESH_TYPE_NON_IRAP               0
148 #define DEC_REFRESH_TYPE_CRA                    1
149 #define DEC_REFRESH_TYPE_IDR                    2
150
151 /* depend_slice_mode */
152 #define DEPEND_SLICE_MODE_RECOMMENDED           1
153 #define DEPEND_SLICE_MODE_BOOST                 2
154 #define DEPEND_SLICE_MODE_FAST                  3
155
156 /* hvs_max_delta_qp */
157 #define MAX_HVS_MAX_DELTA_QP                    51
158
159 /* intra_refresh_mode */
160 #define REFRESH_MODE_CTU_ROWS                   1
161 #define REFRESH_MODE_CTU_COLUMNS                2
162 #define REFRESH_MODE_CTU_STEP_SIZE              3
163 #define REFRESH_MODE_CTUS                       4
164
165 /* intra_mb_refresh_mode */
166 #define REFRESH_MB_MODE_NONE                    0
167 #define REFRESH_MB_MODE_CTU_ROWS                1
168 #define REFRESH_MB_MODE_CTU_COLUMNS             2
169 #define REFRESH_MB_MODE_CTU_STEP_SIZE           3
170
171 /* intra_qp */
172 #define MAX_INTRA_QP                            63
173
174 /* nr_inter_weight_* */
175 #define MAX_INTER_WEIGHT                        31
176
177 /* nr_intra_weight_* */
178 #define MAX_INTRA_WEIGHT                        31
179
180 /* nr_noise_sigma_* */
181 #define MAX_NOISE_SIGMA                         255
182
183 /* bitstream_buffer_size */
184 #define MIN_BITSTREAM_BUFFER_SIZE               1024
185 #define MIN_BITSTREAM_BUFFER_SIZE_WAVE521       (1024 * 64)
186
187 /* vbv_buffer_size */
188 #define MIN_VBV_BUFFER_SIZE                     10
189 #define MAX_VBV_BUFFER_SIZE                     3000
190
191 /* Bitstream buffer option: Explicit End
192  * When set to 1 the VPU assumes that the bitstream has at least one frame and
193  * will read until the end of the bitstream buffer.
194  * When set to 0 the VPU will not read the last few bytes.
195  * This option can be set anytime but cannot be cleared during processing.
196  * It can be set to force finish decoding even though there is not enough
197  * bitstream data for a full frame.
198  */
199 #define BS_EXPLICIT_END_MODE_ON                 1
200
201 #define BUFFER_MARGIN                           4096
202
203 /************************************************************************/
204 /* */
205 /************************************************************************/
206 /**
207  * \brief parameters of DEC_SET_SEQ_CHANGE_MASK
208  */
209 #define SEQ_CHANGE_ENABLE_PROFILE BIT(5)
210 #define SEQ_CHANGE_CHROMA_FORMAT_IDC BIT(15) /* AV1 */
211 #define SEQ_CHANGE_ENABLE_SIZE BIT(16)
212 #define SEQ_CHANGE_INTER_RES_CHANGE BIT(17) /* VP9 */
213 #define SEQ_CHANGE_ENABLE_BITDEPTH BIT(18)
214 #define SEQ_CHANGE_ENABLE_DPB_COUNT BIT(19)
215
216 #define SEQ_CHANGE_ENABLE_ALL_VP9 (SEQ_CHANGE_ENABLE_PROFILE | \
217                 SEQ_CHANGE_ENABLE_SIZE | \
218                 SEQ_CHANGE_INTER_RES_CHANGE | \
219                 SEQ_CHANGE_ENABLE_BITDEPTH | \
220                 SEQ_CHANGE_ENABLE_DPB_COUNT)
221
222 #define SEQ_CHANGE_ENABLE_ALL_HEVC (SEQ_CHANGE_ENABLE_PROFILE | \
223                 SEQ_CHANGE_ENABLE_SIZE | \
224                 SEQ_CHANGE_ENABLE_BITDEPTH | \
225                 SEQ_CHANGE_ENABLE_DPB_COUNT)
226
227 #define SEQ_CHANGE_ENABLE_ALL_AVS2 (SEQ_CHANGE_ENABLE_PROFILE | \
228                 SEQ_CHANGE_ENABLE_SIZE | \
229                 SEQ_CHANGE_ENABLE_BITDEPTH | \
230                 SEQ_CHANGE_ENABLE_DPB_COUNT)
231
232 #define SEQ_CHANGE_ENABLE_ALL_AVC (SEQ_CHANGE_ENABLE_SIZE | \
233                 SEQ_CHANGE_ENABLE_BITDEPTH | \
234                 SEQ_CHANGE_ENABLE_DPB_COUNT)
235
236 #define SEQ_CHANGE_ENABLE_ALL_AV1 (SEQ_CHANGE_ENABLE_PROFILE | \
237                 SEQ_CHANGE_CHROMA_FORMAT_IDC | \
238                 SEQ_CHANGE_ENABLE_SIZE | \
239                 SEQ_CHANGE_ENABLE_BITDEPTH | \
240                 SEQ_CHANGE_ENABLE_DPB_COUNT)
241
242 #define DISPLAY_IDX_FLAG_SEQ_END -1
243 #define DISPLAY_IDX_FLAG_NO_FB -3
244 #define DECODED_IDX_FLAG_NO_FB -1
245 #define DECODED_IDX_FLAG_SKIP -2
246
247 #define RECON_IDX_FLAG_ENC_END -1
248 #define RECON_IDX_FLAG_ENC_DELAY -2
249 #define RECON_IDX_FLAG_HEADER_ONLY -3
250 #define RECON_IDX_FLAG_CHANGE_PARAM -4
251
252 enum codec_command {
253         ENABLE_ROTATION,
254         ENABLE_MIRRORING,
255         SET_MIRROR_DIRECTION,
256         SET_ROTATION_ANGLE,
257         ENABLE_DEC_THUMBNAIL_MODE,
258         DEC_GET_QUEUE_STATUS,
259         ENC_GET_QUEUE_STATUS,
260         DEC_RESET_FRAMEBUF_INFO,
261         DEC_GET_SEQ_INFO,
262 };
263
264 enum error_conceal_mode {
265         ERROR_CONCEAL_MODE_OFF = 0, /* conceal off */
266         ERROR_CONCEAL_MODE_INTRA_ONLY = 1, /* intra conceal in intra-picture, inter-picture */
267         ERROR_CONCEAL_MODE_INTRA_INTER = 2
268 };
269
270 enum error_conceal_unit {
271         ERROR_CONCEAL_UNIT_PICTURE = 0, /* picture-level error conceal */
272         ERROR_CONCEAL_UNIT_SLICE_TILE = 1, /* slice/tile-level error conceal */
273         ERROR_CONCEAL_UNIT_BLOCK_ROW = 2, /* block-row-level error conceal */
274         ERROR_CONCEAL_UNIT_BLOCK = 3 /* block-level conceal */
275 };
276
277 enum cb_cr_order {
278         CBCR_ORDER_NORMAL,
279         CBCR_ORDER_REVERSED
280 };
281
282 enum mirror_direction {
283         MIRDIR_NONE, /* no mirroring */
284         MIRDIR_VER, /* vertical mirroring */
285         MIRDIR_HOR, /* horizontal mirroring */
286         MIRDIR_HOR_VER /* horizontal and vertical mirroring */
287 };
288
289 enum frame_buffer_format {
290         FORMAT_ERR = -1,
291         FORMAT_420 = 0, /* 8bit */
292         FORMAT_422, /* 8bit */
293         FORMAT_224, /* 8bit */
294         FORMAT_444, /* 8bit */
295         FORMAT_400, /* 8bit */
296
297         /* little endian perspective */
298         /* | addr 0 | addr 1 | */
299         FORMAT_420_P10_16BIT_MSB = 5, /* lsb |000000xx|xxxxxxxx | msb */
300         FORMAT_420_P10_16BIT_LSB, /* lsb |xxxxxxx |xx000000 | msb */
301         FORMAT_420_P10_32BIT_MSB, /* lsb |00xxxxxxxxxxxxxxxxxxxxxxxxxxx| msb */
302         FORMAT_420_P10_32BIT_LSB, /* lsb |xxxxxxxxxxxxxxxxxxxxxxxxxxx00| msb */
303
304         /* 4:2:2 packed format */
305         /* little endian perspective */
306         /* | addr 0 | addr 1 | */
307         FORMAT_422_P10_16BIT_MSB, /* lsb |000000xx |xxxxxxxx | msb */
308         FORMAT_422_P10_16BIT_LSB, /* lsb |xxxxxxxx |xx000000 | msb */
309         FORMAT_422_P10_32BIT_MSB, /* lsb |00xxxxxxxxxxxxxxxxxxxxxxxxxxx| msb */
310         FORMAT_422_P10_32BIT_LSB, /* lsb |xxxxxxxxxxxxxxxxxxxxxxxxxxx00| msb */
311
312         FORMAT_YUYV, /* 8bit packed format : Y0U0Y1V0 Y2U1Y3V1 ... */
313         FORMAT_YUYV_P10_16BIT_MSB,
314         FORMAT_YUYV_P10_16BIT_LSB,
315         FORMAT_YUYV_P10_32BIT_MSB,
316         FORMAT_YUYV_P10_32BIT_LSB,
317
318         FORMAT_YVYU, /* 8bit packed format : Y0V0Y1U0 Y2V1Y3U1 ... */
319         FORMAT_YVYU_P10_16BIT_MSB,
320         FORMAT_YVYU_P10_16BIT_LSB,
321         FORMAT_YVYU_P10_32BIT_MSB,
322         FORMAT_YVYU_P10_32BIT_LSB,
323
324         FORMAT_UYVY, /* 8bit packed format : U0Y0V0Y1 U1Y2V1Y3 ... */
325         FORMAT_UYVY_P10_16BIT_MSB,
326         FORMAT_UYVY_P10_16BIT_LSB,
327         FORMAT_UYVY_P10_32BIT_MSB,
328         FORMAT_UYVY_P10_32BIT_LSB,
329
330         FORMAT_VYUY, /* 8bit packed format : V0Y0U0Y1 V1Y2U1Y3 ... */
331         FORMAT_VYUY_P10_16BIT_MSB,
332         FORMAT_VYUY_P10_16BIT_LSB,
333         FORMAT_VYUY_P10_32BIT_MSB,
334         FORMAT_VYUY_P10_32BIT_LSB,
335
336         FORMAT_MAX,
337 };
338
339 enum packed_format_num {
340         NOT_PACKED = 0,
341         PACKED_YUYV,
342         PACKED_YVYU,
343         PACKED_UYVY,
344         PACKED_VYUY,
345 };
346
347 enum wave5_interrupt_bit {
348         INT_WAVE5_INIT_VPU = 0,
349         INT_WAVE5_WAKEUP_VPU = 1,
350         INT_WAVE5_SLEEP_VPU = 2,
351         INT_WAVE5_CREATE_INSTANCE = 3,
352         INT_WAVE5_FLUSH_INSTANCE = 4,
353         INT_WAVE5_DESTROY_INSTANCE = 5,
354         INT_WAVE5_INIT_SEQ = 6,
355         INT_WAVE5_SET_FRAMEBUF = 7,
356         INT_WAVE5_DEC_PIC = 8,
357         INT_WAVE5_ENC_PIC = 8,
358         INT_WAVE5_ENC_SET_PARAM = 9,
359         INT_WAVE5_DEC_QUERY = 14,
360         INT_WAVE5_BSBUF_EMPTY = 15,
361         INT_WAVE5_BSBUF_FULL = 15,
362 };
363
364 enum pic_type {
365         PIC_TYPE_I = 0, /* I picture */
366         PIC_TYPE_KEY = 0, /* KEY frame for AV1*/
367         PIC_TYPE_P = 1, /* P picture */
368         PIC_TYPE_INTER = 1, /* inter frame for AV1*/
369         PIC_TYPE_B = 2, /* B picture (except VC1) */
370         PIC_TYPE_REPEAT = 2, /* repeat frame (VP9 only) */
371         PIC_TYPE_AV1_INTRA = 2, /* intra only frame (AV1 only) */
372         PIC_TYPE_VC1_BI = 2, /* VC1 BI picture (VC1 only) */
373         PIC_TYPE_VC1_B = 3, /* VC1 B picture (VC1 only) */
374         PIC_TYPE_D = 3,
375         PIC_TYPE_S = 3,
376         PIC_TYPE_AVS2_F = 3, /* F picture in AVS2 */
377         PIC_TYPE_AV1_SWITCH = 3, /* switch frame (AV1 only) */
378         PIC_TYPE_VC1_P_SKIP = 4, /* VC1 P skip picture (VC1 only) */
379         PIC_TYPE_MP4_P_SKIP_NOT_CODED = 4, /* not coded P picture in MPEG4 packed mode */
380         PIC_TYPE_AVS2_S = 4, /* S picture in AVS2 */
381         PIC_TYPE_IDR = 5, /* H.264/H.265 IDR picture */
382         PIC_TYPE_AVS2_G = 5, /* G picture in AVS2 */
383         PIC_TYPE_AVS2_GB = 6, /* GB picture in AVS2 */
384         PIC_TYPE_MAX /* no meaning */
385 };
386
387 enum bit_stream_mode {
388         BS_MODE_INTERRUPT,
389         BS_MODE_RESERVED, /* reserved for the future */
390         BS_MODE_PIC_END,
391 };
392
393 enum sw_reset_mode {
394         SW_RESET_SAFETY,
395         SW_RESET_FORCE,
396         SW_RESET_ON_BOOT
397 };
398
399 enum tiled_map_type {
400         LINEAR_FRAME_MAP = 0, /* linear frame map type */
401         COMPRESSED_FRAME_MAP = 17, /* compressed frame map type*/
402 };
403
404 enum temporal_id_mode {
405         TEMPORAL_ID_MODE_ABSOLUTE,
406         TEMPORAL_ID_MODE_RELATIVE,
407 };
408
409 struct vpu_attr {
410         u32 product_id; /* the product ID */
411         char product_name[8]; /* the product name in ascii code */
412         u32 product_version; /* the product version number */
413         u32 fw_version; /* the F/W version */
414         u32 customer_id; /* customer ID number */
415         u32 support_decoders; /* bitmask: see <<vpuapi_h_cod_std>> */
416         u32 support_encoders; /* bitmask: see <<vpuapi_h_cod_std>> */
417         u32 support_endian_mask; /* A variable of supported endian mode in product */
418         u32 support_bitstream_mode;
419         u32 support_backbone: 1;
420         u32 support_avc10bit_enc: 1;
421         u32 support_hevc10bit_enc: 1;
422         u32 support_dual_core: 1; /* this indicates whether a product has two vcores */
423         u32 support_vcore_backbone: 1;
424         u32 support_vcpu_backbone: 1;
425 };
426
427 struct frame_buffer {
428         dma_addr_t buf_y;
429         dma_addr_t buf_cb;
430         dma_addr_t buf_cr;
431         unsigned int buf_y_size;
432         unsigned int buf_cb_size;
433         unsigned int buf_cr_size;
434         unsigned int endian;
435         enum tiled_map_type map_type;
436         unsigned int stride; /* A horizontal stride for given frame buffer */
437         unsigned int width; /* A width for given frame buffer */
438         unsigned int height; /* A height for given frame buffer */
439         size_t size; /* A size for given frame buffer */
440         unsigned int sequence_no;
441         bool update_fb_info;
442 };
443
444 struct vpu_rect {
445         unsigned int left; /* horizontal pixel offset from left edge */
446         unsigned int top; /* vertical pixel offset from top edge */
447         unsigned int right; /* horizontal pixel offset from right edge */
448         unsigned int bottom; /* vertical pixel offset from bottom edge */
449 };
450
451 /*
452  * decode struct and definition
453  */
454
455 struct dec_open_param {
456         dma_addr_t bitstream_buffer;
457         size_t bitstream_buffer_size;
458         enum cb_cr_order cbcr_order;
459         unsigned int frame_endian;
460         unsigned int stream_endian;
461         enum bit_stream_mode bitstream_mode;
462         u32 av1_format;
463         enum error_conceal_unit error_conceal_unit;
464         enum error_conceal_mode error_conceal_mode;
465         u32 pri_ext_addr;
466         u32 pri_axprot;
467         u32 pri_axcache;
468         u32 enable_non_ref_fbc_write: 1;
469 };
470
471 struct dec_initial_info {
472         u32 pic_width;
473         u32 pic_height;
474         s32 f_rate_numerator; /* the numerator part of frame rate fraction */
475         s32 f_rate_denominator; /* the denominator part of frame rate fraction */
476         u64 ns_per_frame;
477         struct vpu_rect pic_crop_rect;
478         u32 min_frame_buffer_count; /* between 1 to 16 */
479         u32 frame_buf_delay;
480
481         u32 max_temporal_layers; /* it indicates the max number of temporal sub-layers */
482         u32 profile;
483         u32 level;
484         u32 tier;
485         bool is_ext_sar;
486         u32 aspect_rate_info;
487         u32 bit_rate;
488         u32 user_data_header;
489         u32 user_data_size;
490         bool user_data_buf_full;
491         u32 chroma_format_idc;/* A chroma format indicator */
492         u32 luma_bitdepth; /* A bit-depth of luma sample */
493         u32 chroma_bitdepth; /* A bit-depth of chroma sample */
494         u32 seq_init_err_reason;
495         u32 warn_info;
496         dma_addr_t rd_ptr; /* A read pointer of bitstream buffer */
497         dma_addr_t wr_ptr; /* A write pointer of bitstream buffer */
498         u32 sequence_no;
499         u32 output_bit_depth;
500         u32 vlc_buf_size; /* the size of vlc buffer */
501         u32 param_buf_size; /* the size of param buffer */
502 };
503
504 #define WAVE_SKIPMODE_WAVE_NONE 0
505 #define WAVE_SKIPMODE_NON_IRAP 1
506 #define WAVE_SKIPMODE_NON_REF 2
507
508 struct dec_param {
509         u32 skipframe_mode: 2;
510         u32 cra_as_bla_flag: 1;
511         u32 disable_film_grain: 1;
512 };
513
514 struct avs2_info {
515         s32 decoded_poi;
516         int display_poi;
517 };
518
519 struct dec_output_info {
520         /**
521          * this is a frame buffer index for the picture to be displayed at the moment among
522          * frame buffers which are registered using vpu_dec_register_frame_buffer(). frame
523          * data to be displayed are stored into the frame buffer with this index
524          * when there is no display delay, this index is always
525          * the same with index_frame_decoded, however, if display delay does exist for display
526          * reordering in AVC
527          * or B-frames in VC1), this index might be different with index_frame_decoded.
528          * by checking this index, HOST application can easily know whether sequence decoding
529          * has been finished or not.
530          *
531          * -3(0xFFFD) or -2(0xFFFE) : it is when a display output cannot be given due to picture
532          * reordering or skip option
533          * -1(0xFFFF) : it is when there is no more output for display at the end of sequence
534          * decoding
535          */
536         s32 index_frame_display;
537         /**
538          * this is a frame buffer index of decoded picture among frame buffers which were
539          * registered using vpu_dec_register_frame_buffer(). the currently decoded frame is stored
540          * into the frame buffer specified by
541          * this index.
542          *
543          * -2 : it indicates that no decoded output is generated because decoder meets EOS
544          * (end of sequence) or skip
545          * -1 : it indicates that decoder fails to decode a picture because there is no available
546          * frame buffer
547          */
548         s32 index_frame_decoded;
549         s32 index_frame_decoded_for_tiled;
550         u32 nal_type;
551         unsigned int pic_type;
552         struct vpu_rect rc_display;
553         unsigned int disp_pic_width;
554         unsigned int disp_pic_height;
555         struct vpu_rect rc_decoded;
556         u32 dec_pic_width;
557         u32 dec_pic_height;
558         struct avs2_info avs2_info;
559         s32 decoded_poc;
560         int temporal_id; /* A temporal ID of the picture */
561         dma_addr_t rd_ptr; /* A stream buffer read pointer for the current decoder instance */
562         dma_addr_t wr_ptr; /* A stream buffer write pointer for the current decoder instance */
563         struct frame_buffer disp_frame;
564         u32 frame_display_flag; /* it reports a frame buffer flag to be displayed */
565         /**
566          * this variable reports that sequence has been changed while H.264/AVC stream decoding.
567          * if it is 1, HOST application can get the new sequence information by calling
568          * vpu_dec_get_initial_info() or wave5_vpu_dec_issue_seq_init().
569          *
570          * for H.265/HEVC decoder, each bit has a different meaning as follows.
571          *
572          * sequence_changed[5] : it indicates that the profile_idc has been changed
573          * sequence_changed[16] : it indicates that the resolution has been changed
574          * sequence_changed[19] : it indicates that the required number of frame buffer has
575          * been changed.
576          */
577         unsigned int frame_cycle; /* reports the number of cycles for processing a frame */
578         u32 sequence_no;
579
580         u32 dec_host_cmd_tick; /* tick of DEC_PIC command for the picture */
581         u32 dec_decode_end_tick; /* end tick of decoding slices of the picture */
582
583         u32 sequence_changed;
584 };
585
586 struct queue_status_info {
587         u32 instance_queue_count;
588         u32 report_queue_count;
589 };
590
591 /*
592  * encode struct and definition
593  */
594
595 #define MAX_NUM_TEMPORAL_LAYER 7
596 #define MAX_NUM_SPATIAL_LAYER 3
597 #define MAX_GOP_NUM 8
598
599 struct custom_gop_pic_param {
600         u32 pic_type; /* A picture type of nth picture in the custom GOP */
601         u32 poc_offset; /* A POC of nth picture in the custom GOP */
602         u32 pic_qp; /* A quantization parameter of nth picture in the custom GOP */
603         u32 use_multi_ref_p; /* use multiref pic for P picture. valid only if PIC_TYPE is P */
604         u32 ref_poc_l0; /* A POC of reference L0 of nth picture in the custom GOP */
605         u32 ref_poc_l1; /* A POC of reference L1 of nth picture in the custom GOP */
606         s32 temporal_id; /* A temporal ID of nth picture in the custom GOP */
607 };
608
609 struct custom_gop_param {
610         u32 custom_gop_size; /* the size of custom GOP (0~8) */
611         struct custom_gop_pic_param pic_param[MAX_GOP_NUM];
612 };
613
614 struct wave_custom_map_opt {
615         u32 roi_avg_qp; /* it sets an average QP of ROI map */
616         u32 addr_custom_map;
617         u32 custom_roi_map_enable: 1; /* it enables ROI map */
618         u32 custom_lambda_map_enable: 1; /* it enables custom lambda map */
619         u32 custom_mode_map_enable: 1;
620         u32 custom_coef_drop_enable: 1;
621 };
622
623 struct enc_wave_param {
624         /*
625          * A profile indicator (HEVC only)
626          *
627          * 0 : the firmware determines a profile according to internalbitdepth
628          * 1 : main profile
629          * 2 : main10 profile
630          * 3 : main still picture profile
631          * in AVC encoder, a profile cannot be set by host application. the firmware decides it
632          * based on internalbitdepth. it is HIGH profile for bitdepth of 8 and HIGH10 profile for
633          * bitdepth of 10.
634          */
635         u32 profile;
636         u32 level; /* A level indicator (level * 10) */
637         u32 internal_bit_depth: 4; /* 8/10 */
638         u32 gop_preset_idx: 4; /* 0 - 9 */
639         u32 decoding_refresh_type: 2; /* 0=non-IRAP, 1=CRA, 2=IDR */
640         u32 intra_qp; /* A quantization parameter of intra picture */
641         u32 intra_period; /* A period of intra picture in GOP size */
642         u32 forced_idr_header_enable: 2;
643         u32 conf_win_top; /* A top offset of conformance window */
644         u32 conf_win_bot; /* A bottom offset of conformance window */
645         u32 conf_win_left; /* A left offset of conformance window */
646         u32 conf_win_right; /* A right offset of conformance window */
647         u32 independ_slice_mode_arg;
648         u32 depend_slice_mode_arg;
649         u32 intra_refresh_mode: 3;
650         /*
651          * it specifies an intra CTU refresh interval. depending on intra_refresh_mode,
652          * it can mean one of the following.
653          *
654          * the number of consecutive CTU rows for intra_ctu_refresh_mode of 1
655          * the number of consecutive CTU columns for intra_ctu_refresh_mode of 2
656          * A step size in CTU for intra_ctu_refresh_mode of 3
657          * the number of intra ct_us to be encoded in a picture for intra_ctu_refresh_mode of 4
658          */
659         u32 intra_refresh_arg;
660         /*
661          * 0 : custom setting
662          * 1 : recommended encoder parameters (slow encoding speed, highest picture quality)
663          * 2 : boost mode (normal encoding speed, moderate picture quality)
664          * 3 : fast mode (fast encoding speed, low picture quality)
665          */
666         u32 depend_slice_mode : 2;
667         u32 use_recommend_enc_param: 2;
668         u32 max_num_merge: 2;
669         u32 scaling_list_enable: 2;
670         u32 bit_alloc_mode: 2; /* 0=ref-pic-priority, 1=uniform, 2=fixed_bit_ratio */
671         s32 beta_offset_div2: 4; /* it sets beta_offset_div2 for deblocking filter */
672         s32 tc_offset_div2: 4; /* it sets tc_offset_div3 for deblocking filter */
673         u32 hvs_qp_scale: 4; /* QP scaling factor for CU QP adjust if hvs_qp_scale_enable is 1 */
674         u32 hvs_max_delta_qp; /* A maximum delta QP for HVS */
675         /*
676          * A fixed bit ratio (1 ~ 255) for each picture of GOP's bit
677          * allocation
678          *
679          * N = 0 ~ (MAX_GOP_SIZE - 1)
680          * MAX_GOP_SIZE = 8
681          *
682          * for instance when MAX_GOP_SIZE is 3, fixed_bit_ratio0, fixed_bit_ratio1, and
683          * fixed_bit_ratio2 can be set as 2, 1, and 1 respectively for
684          * the fixed bit ratio 2:1:1. this is only valid when bit_alloc_mode is 2.
685          */
686         u8 fixed_bit_ratio[MAX_GOP_NUM];
687         struct custom_gop_param gop_param; /* <<vpuapi_h_custom_gop_param>> */
688         u32 num_units_in_tick;
689         u32 time_scale;
690         u32 num_ticks_poc_diff_one;
691         s32 chroma_cb_qp_offset; /* the value of chroma(cb) QP offset */
692         s32 chroma_cr_qp_offset; /* the value of chroma(cr) QP offset */
693         s32 initial_rc_qp;
694         u32 nr_intra_weight_y;
695         u32 nr_intra_weight_cb; /* A weight to cb noise level for intra picture (0 ~ 31) */
696         u32 nr_intra_weight_cr; /* A weight to cr noise level for intra picture (0 ~ 31) */
697         u32 nr_inter_weight_y;
698         u32 nr_inter_weight_cb; /* A weight to cb noise level for inter picture (0 ~ 31) */
699         u32 nr_inter_weight_cr; /* A weight to cr noise level for inter picture (0 ~ 31) */
700         u32 nr_noise_sigma_y; /* Y noise standard deviation if nr_noise_est_enable is 0 */
701         u32 nr_noise_sigma_cb;/* cb noise standard deviation if nr_noise_est_enable is 0 */
702         u32 nr_noise_sigma_cr;/* cr noise standard deviation if nr_noise_est_enable is 0 */
703         u32 bg_thr_diff;
704         u32 bg_thr_mean_diff;
705         u32 bg_lambda_qp;
706         u32 bg_delta_qp;
707         u32 pu04_delta_rate: 8; /* added to the total cost of 4x4 blocks */
708         u32 pu08_delta_rate: 8; /* added to the total cost of 8x8 blocks */
709         u32 pu16_delta_rate: 8; /* added to the total cost of 16x16 blocks */
710         u32 pu32_delta_rate: 8; /* added to the total cost of 32x32 blocks */
711         u32 pu04_intra_planar_delta_rate: 8;
712         u32 pu04_intra_dc_delta_rate: 8;
713         u32 pu04_intra_angle_delta_rate: 8;
714         u32 pu08_intra_planar_delta_rate: 8;
715         u32 pu08_intra_dc_delta_rate: 8;
716         u32 pu08_intra_angle_delta_rate: 8;
717         u32 pu16_intra_planar_delta_rate: 8;
718         u32 pu16_intra_dc_delta_rate: 8;
719         u32 pu16_intra_angle_delta_rate: 8;
720         u32 pu32_intra_planar_delta_rate: 8;
721         u32 pu32_intra_dc_delta_rate: 8;
722         u32 pu32_intra_angle_delta_rate: 8;
723         u32 cu08_intra_delta_rate: 8;
724         u32 cu08_inter_delta_rate: 8;
725         u32 cu08_merge_delta_rate: 8;
726         u32 cu16_intra_delta_rate: 8;
727         u32 cu16_inter_delta_rate: 8;
728         u32 cu16_merge_delta_rate: 8;
729         u32 cu32_intra_delta_rate: 8;
730         u32 cu32_inter_delta_rate: 8;
731         u32 cu32_merge_delta_rate: 8;
732         u32 coef_clear_disable: 8;
733         u32 min_qp_i; /* A minimum QP of I picture for rate control */
734         u32 max_qp_i; /* A maximum QP of I picture for rate control */
735         u32 min_qp_p; /* A minimum QP of P picture for rate control */
736         u32 max_qp_p; /* A maximum QP of P picture for rate control */
737         u32 min_qp_b; /* A minimum QP of B picture for rate control */
738         u32 max_qp_b; /* A maximum QP of B picture for rate control */
739         u32 custom_lambda_addr; /* it specifies the address of custom lambda map */
740         u32 user_scaling_list_addr; /* it specifies the address of user scaling list file */
741         u32 avc_idr_period;/* A period of IDR picture (0 ~ 1024). 0 - implies an infinite period */
742         u32 avc_slice_arg;      /* the number of MB for a slice when avc_slice_mode is set with 1 */
743         u32 intra_mb_refresh_mode: 2; /* 0=none, 1=row, 2=column, 3=step-size-in-mb */
744         /**
745          * it specifies an intra MB refresh interval. depending on intra_mb_refresh_mode,
746          * it can mean one of the following.
747          *
748          * the number of consecutive MB rows for intra_mb_refresh_mode of 1
749          * the number of consecutive MB columns for intra_mb_refresh_mode of 2
750          * A step size in MB for intra_mb_refresh_mode of 3
751          */
752         u32 intra_mb_refresh_arg;
753         u32 rc_weight_param;
754         u32 rc_weight_buf;
755
756         /* flags */
757         u32 en_still_picture: 1; /* still picture profile */
758         u32 tier: 1; /* 0=main, 1=high */
759         u32 independ_slice_mode : 1; /* 0=no-multi-slice, 1=slice-in-ctu-number*/
760         u32 avc_slice_mode: 1; /* 0=none, 1=slice-in-mb-number */
761         u32 entropy_coding_mode: 1; /* 0=CAVLC, 1=CABAC */
762         u32 lossless_enable: 1; /* enables lossless coding */
763         u32 const_intra_pred_flag: 1; /* enables constrained intra prediction */
764         u32 tmvp_enable: 1; /* enables temporal motion vector prediction */
765         u32 wpp_enable: 1;
766         u32 disable_deblk: 1; /* it disables in-loop deblocking filtering */
767         u32 lf_cross_slice_boundary_enable: 1;
768         u32 skip_intra_trans: 1;
769         u32 sao_enable: 1; /* it enables SAO (sample adaptive offset) */
770         u32 intra_nx_n_enable: 1; /* it enables intra nx_n p_us */
771         u32 cu_level_rc_enable: 1; /* it enable CU level rate control */
772         u32 hvs_qp_enable: 1; /* enable CU QP adjustment for subjective quality enhancement */
773         u32 roi_enable: 1; /* it enables ROI map. NOTE: it is valid when rate control is on */
774         u32 nr_y_enable: 1; /* it enables noise reduction algorithm to Y component */
775         u32 nr_noise_est_enable: 1;
776         u32 nr_cb_enable: 1; /* it enables noise reduction algorithm to cb component */
777         u32 nr_cr_enable: 1; /* it enables noise reduction algorithm to cr component */
778         u32 use_long_term: 1; /* it enables long-term reference function */
779         u32 monochrome_enable: 1; /* it enables monochrom encoding mode */
780         u32 strong_intra_smooth_enable: 1; /* it enables strong intra smoothing */
781         u32 weight_pred_enable: 1; /* it enables to use weighted prediction*/
782         u32 bg_detect_enable: 1; /* it enables background detection */
783         u32 custom_lambda_enable: 1; /* it enables custom lambda table */
784         u32 custom_md_enable: 1; /* it enables custom mode decision */
785         u32 rdo_skip: 1; /* it skips RDO(rate distortion optimization) */
786         u32 lambda_scaling_enable: 1; /* it enables lambda scaling using custom GOP */
787         u32 transform8x8_enable: 1; /* it enables 8x8 intra prediction and 8x8 transform */
788         u32 mb_level_rc_enable: 1; /* it enables MB-level rate control */
789         u32 s2fme_disable: 1; /* it disables s2me_fme (only for AVC encoder) */
790 };
791
792 struct enc_sub_frame_sync_config {
793         u32 sub_frame_sync_mode; /* 0=wire-based, 1=register-based */
794         u32 sub_frame_sync_on;
795 };
796
797 struct enc_open_param {
798         dma_addr_t bitstream_buffer;
799         unsigned int bitstream_buffer_size;
800         u32 pic_width; /* the width of a picture to be encoded in unit of sample */
801         u32 pic_height; /* the height of a picture to be encoded in unit of sample */
802         u32 frame_rate_info;/* desired fps */
803         u32 vbv_buffer_size;
804         u32 bit_rate; /* target bitrate in bps */
805         struct enc_wave_param wave_param;
806         enum cb_cr_order cbcr_order;
807         unsigned int stream_endian;
808         unsigned int source_endian;
809         enum packed_format_num packed_format; /* <<vpuapi_h_packed_format_num>> */
810         enum frame_buffer_format src_format;
811         /* enum frame_buffer_format output_format; not used yet */
812         u32 enc_hrd_rbsp_in_vps; /* it encodes the HRD syntax rbsp into VPS */
813         u32 hrd_rbsp_data_size; /* the bit size of the HRD rbsp data */
814         u32 hrd_rbsp_data_addr; /* the address of the HRD rbsp data */
815         u32 encode_vui_rbsp;
816         u32 vui_rbsp_data_size; /* the bit size of the VUI rbsp data */
817         u32 vui_rbsp_data_addr; /* the address of the VUI rbsp data */
818         u32 pri_ext_addr;
819         u32 pri_axprot;
820         u32 pri_axcache;
821         bool ring_buffer_enable;
822         bool line_buf_int_en;
823         bool enable_pts; /* an enable flag to report PTS(presentation timestamp) */
824         u32 rc_enable : 1; /* rate control */
825         u32 enable_non_ref_fbc_write: 1;
826         u32 sub_frame_sync_enable: 1;
827         u32 sub_frame_sync_mode: 1;
828 };
829
830 struct enc_initial_info {
831         u32 min_frame_buffer_count; /* minimum number of frame buffer */
832         u32 min_src_frame_count; /* minimum number of source buffer */
833         u32 max_latency_pictures; /* maximum number of picture latency */
834         u32 seq_init_err_reason; /* error information */
835         u32 warn_info; /* warn information */
836         u32 vlc_buf_size; /* the size of task buffer */
837         u32 param_buf_size; /* the size of task buffer */
838 };
839
840 struct enc_code_opt {
841         u32 implicit_header_encode: 1;
842         u32 encode_vcl: 1; /* A flag to encode VCL nal unit explicitly */
843         u32 encode_vps: 1; /* A flag to encode VPS nal unit explicitly */
844         u32 encode_sps: 1; /* A flag to encode SPS nal unit explicitly */
845         u32 encode_pps: 1; /* A flag to encode PPS nal unit explicitly */
846         u32 encode_aud: 1; /* A flag to encode AUD nal unit explicitly */
847         u32 encode_eos: 1;
848         u32 encode_eob: 1;
849         u32 encode_vui: 1; /* A flag to encode VUI nal unit explicitly */
850 };
851
852 struct enc_param {
853         struct frame_buffer *source_frame;
854         u32 pic_stream_buffer_addr;
855         u64 pic_stream_buffer_size;
856         u32 force_pic_qp_i;
857         u32 force_pic_qp_p;
858         u32 force_pic_qp_b;
859         u32 force_pic_type: 2;
860         u32 src_idx; /* A source frame buffer index */
861         struct enc_code_opt code_option;
862         u32 use_cur_src_as_longterm_pic;
863         u32 use_longterm_ref;
864         u64 pts; /* the presentation timestamp (PTS) of input source */
865         struct wave_custom_map_opt custom_map_opt;
866         u32 wp_pix_sigma_y; /* pixel variance of Y component for weighted prediction */
867         u32 wp_pix_sigma_cb; /* pixel variance of cb component for weighted prediction */
868         u32 wp_pix_sigma_cr; /* pixel variance of cr component for weighted prediction */
869         u32 wp_pix_mean_y; /* pixel mean value of Y component for weighted prediction */
870         u32 wp_pix_mean_cb; /* pixel mean value of cb component for weighted prediction */
871         u32 wp_pix_mean_cr; /* pixel mean value of cr component for weighted prediction */
872         bool src_end_flag;
873         u32 skip_picture: 1;
874         u32 force_pic_qp_enable: 1; /* flag used to force picture quantization parameter */
875         u32 force_pic_type_enable: 1; /* A flag to use a force picture type */
876         u32 force_all_ctu_coef_drop_enable: 1; /* forces all coefficients to be zero after TQ */
877 };
878
879 struct enc_output_info {
880         u32 bitstream_buffer;
881         u32 bitstream_size; /* the byte size of encoded bitstream */
882         u32 pic_type: 2; /* <<vpuapi_h_pic_type>> */
883         s32 recon_frame_index;
884         dma_addr_t rd_ptr;
885         dma_addr_t wr_ptr;
886         u32 enc_pic_byte; /* the number of encoded picture bytes */
887         s32 enc_src_idx; /* the source buffer index of the currently encoded picture */
888         u32 enc_vcl_nut;
889         u32 error_reason; /* the error reason of the currently encoded picture */
890         u32 warn_info; /* the warning information of the currently encoded picture */
891         unsigned int frame_cycle; /* param for reporting the cycle number of encoding one frame*/
892         u64 pts;
893         u32 enc_host_cmd_tick; /* tick of ENC_PIC command for the picture */
894         u32 enc_encode_end_tick; /* end tick of encoding slices of the picture */
895 };
896
897 enum ENC_PIC_CODE_OPTION {
898         CODEOPT_ENC_HEADER_IMPLICIT = BIT(0),
899         CODEOPT_ENC_VCL = BIT(1), /* A flag to encode VCL nal unit explicitly */
900 };
901
902 enum GOP_PRESET_IDX {
903         PRESET_IDX_CUSTOM_GOP = 0, /* user defined GOP structure */
904         PRESET_IDX_ALL_I = 1, /* all intra, gopsize = 1 */
905         PRESET_IDX_IPP = 2, /* consecutive P, cyclic gopsize = 1 */
906         PRESET_IDX_IBBB = 3, /* consecutive B, cyclic gopsize = 1 */
907         PRESET_IDX_IBPBP = 4, /* gopsize = 2 */
908         PRESET_IDX_IBBBP = 5, /* gopsize = 4 */
909         PRESET_IDX_IPPPP = 6, /* consecutive P, cyclic gopsize = 4 */
910         PRESET_IDX_IBBBB = 7, /* consecutive B, cyclic gopsize = 4 */
911         PRESET_IDX_RA_IB = 8, /* random access, cyclic gopsize = 8 */
912         PRESET_IDX_IPP_SINGLE = 9, /* consecutive P, cyclic gopsize = 1, with single ref */
913 };
914
915 struct sec_axi_info {
916         struct {
917                 u32 use_ip_enable;
918                 u32 use_bit_enable;
919                 u32 use_lf_row_enable: 1;
920                 u32 use_enc_rdo_enable: 1;
921                 u32 use_enc_lf_enable: 1;
922         } wave;
923         unsigned int buf_size;
924         dma_addr_t buf_base;
925 };
926
927 struct dec_info {
928         struct dec_open_param open_param;
929         struct dec_initial_info initial_info;
930         struct dec_initial_info new_seq_info; /* temporal new sequence information */
931         u32 stream_wr_ptr;
932         u32 stream_rd_ptr;
933         u32 frame_display_flag;
934         dma_addr_t stream_buf_start_addr;
935         dma_addr_t stream_buf_end_addr;
936         u32 stream_buf_size;
937         struct vpu_buf vb_mv[MAX_REG_FRAME];
938         struct vpu_buf vb_fbc_y_tbl[MAX_REG_FRAME];
939         struct vpu_buf vb_fbc_c_tbl[MAX_REG_FRAME];
940         unsigned int num_of_decoding_fbs;
941         unsigned int num_of_display_fbs;
942         unsigned int stride;
943         enum mirror_direction mirror_direction;
944         unsigned int rotation_angle;
945         struct frame_buffer rotator_output;
946         unsigned int rotator_stride;
947         struct sec_axi_info sec_axi_info;
948         dma_addr_t user_data_buf_addr;
949         u32 user_data_enable;
950         u32 user_data_buf_size;
951         struct vpu_buf vb_work;
952         struct vpu_buf vb_task;
953         struct dec_output_info dec_out_info[WAVE5_MAX_FBS];
954         u32 seq_change_mask;
955         enum temporal_id_mode temp_id_select_mode;
956         u32 target_temp_id;
957         u32 target_spatial_id;
958         u32 instance_queue_count;
959         u32 report_queue_count;
960         u32 cycle_per_tick;
961         u32 product_code;
962         u32 vlc_buf_size;
963         u32 param_buf_size;
964         bool rotation_enable;
965         bool mirror_enable;
966         bool dering_enable;
967         bool initial_info_obtained;
968         bool reorder_enable;
969         bool thumbnail_mode;
970         bool first_cycle_check;
971         u32 stream_endflag: 1;
972 };
973
974 struct enc_info {
975         struct enc_open_param open_param;
976         struct enc_initial_info initial_info;
977         u32 stream_rd_ptr;
978         u32 stream_wr_ptr;
979         dma_addr_t stream_buf_start_addr;
980         dma_addr_t stream_buf_end_addr;
981         u32 stream_buf_size;
982         unsigned int num_frame_buffers;
983         unsigned int stride;
984         bool rotation_enable;
985         bool mirror_enable;
986         enum mirror_direction mirror_direction;
987         unsigned int rotation_angle;
988         bool initial_info_obtained;
989         bool ring_buffer_enable;
990         struct sec_axi_info sec_axi_info;
991         struct enc_sub_frame_sync_config sub_frame_sync_config;
992         bool line_buf_int_en;
993         struct vpu_buf vb_work;
994         struct vpu_buf vb_mv; /* col_mv buffer */
995         struct vpu_buf vb_fbc_y_tbl; /* FBC luma table buffer */
996         struct vpu_buf vb_fbc_c_tbl; /* FBC chroma table buffer */
997         struct vpu_buf vb_sub_sam_buf; /* sub-sampled buffer for ME */
998         struct vpu_buf vb_task;
999         u64 cur_pts; /* current timestamp in 90_k_hz */
1000         u64 pts_map[32]; /* PTS mapped with source frame index */
1001         u32 instance_queue_count;
1002         u32 report_queue_count;
1003         bool first_cycle_check;
1004         u32 cycle_per_tick;
1005         u32 product_code;
1006         u32 vlc_buf_size;
1007         u32 param_buf_size;
1008 };
1009
1010 struct vpu_device {
1011         struct device *dev;
1012         struct v4l2_device v4l2_dev;
1013         struct list_head instances;
1014         struct video_device *video_dev_dec;
1015         struct video_device *video_dev_enc;
1016         struct mutex dev_lock; /* the lock for the src,dst v4l2 queues */
1017         struct mutex hw_lock; /* lock hw configurations */
1018         int irq;
1019         enum product_id  product;
1020         struct vpu_attr  attr;
1021         struct vpu_buf common_mem;
1022         u32 last_performance_cycles;
1023         struct dma_vpu_buf sram_buf;
1024         void __iomem *vdb_register;
1025         u32 product_code;
1026         struct ida inst_ida;
1027         struct clk_bulk_data *clks;
1028         struct reset_control *resets;
1029         int num_clks;
1030 };
1031
1032 struct vpu_instance;
1033
1034 struct vpu_instance_ops {
1035         void (*start_process)(struct vpu_instance *inst);
1036         void (*stop_process)(struct vpu_instance *inst);
1037         void (*finish_process)(struct vpu_instance *inst);
1038 };
1039
1040 struct vpu_instance {
1041         struct list_head list;
1042         struct v4l2_fh v4l2_fh;
1043         struct v4l2_ctrl_handler v4l2_ctrl_hdl;
1044         struct vpu_device *dev;
1045         struct v4l2_m2m_dev *v4l2_m2m_dev;
1046         struct kfifo irq_status;
1047         struct completion irq_done;
1048
1049         struct v4l2_pix_format_mplane src_fmt;
1050         struct v4l2_pix_format_mplane dst_fmt;
1051         enum v4l2_colorspace colorspace;
1052         enum v4l2_xfer_func xfer_func;
1053         enum v4l2_ycbcr_encoding ycbcr_enc;
1054         enum v4l2_quantization quantization;
1055         enum v4l2_hsv_encoding hsv_enc;
1056
1057         enum vpu_instance_state state;
1058         enum vpu_instance_type type;
1059         const struct vpu_instance_ops *ops;
1060         struct vpu_rect crop_rect;
1061
1062         enum wave_std            std;
1063         s32                      id;
1064         union {
1065                 struct enc_info enc_info;
1066                 struct dec_info dec_info;
1067         } *codec_info;
1068         struct frame_buffer frame_buf[MAX_REG_FRAME];
1069         struct vpu_buf frame_vbuf[MAX_REG_FRAME];
1070         u32 min_dst_buf_count;
1071         u32 dst_buf_count;
1072         u32 queued_src_buf_num;
1073         u32 queued_dst_buf_num;
1074         u32 conf_win_width;
1075         u32 conf_win_height;
1076         u64 timestamp;
1077         u64 timestamp_cnt;
1078         bool cbcr_interleave;
1079         bool nv21;
1080         bool eos;
1081
1082         struct vpu_buf bitstream_vbuf;
1083         bool thumbnail_mode;
1084
1085         unsigned int min_src_buf_count;
1086         unsigned int src_buf_count;
1087         unsigned int rot_angle;
1088         unsigned int mirror_direction;
1089         unsigned int bit_depth;
1090         unsigned int frame_rate;
1091         unsigned int vbv_buf_size;
1092         unsigned int rc_mode;
1093         unsigned int rc_enable;
1094         unsigned int bit_rate;
1095         struct enc_wave_param enc_param;
1096 };
1097
1098 void wave5_vdi_write_register(struct vpu_device *vpu_dev, u32 addr, u32 data);
1099 u32 wave5_vdi_readl(struct vpu_device *vpu_dev, u32 addr);
1100 int wave5_vdi_clear_memory(struct vpu_device *vpu_dev, struct vpu_buf *vb);
1101 int wave5_vdi_allocate_dma_memory(struct vpu_device *vpu_dev, struct vpu_buf *vb);
1102 int wave5_vdi_write_memory(struct vpu_device *vpu_dev, struct vpu_buf *vb, size_t offset,
1103                            u8 *data, size_t len, unsigned int endian);
1104 unsigned int wave5_vdi_convert_endian(struct vpu_device *vpu_dev, unsigned int endian);
1105 void wave5_vdi_free_dma_memory(struct vpu_device *vpu_dev, struct vpu_buf *vb);
1106
1107 int wave5_vpu_init_with_bitcode(struct device *dev, u8 *bitcode, size_t size);
1108 void wave5_vpu_clear_interrupt_ex(struct vpu_instance *inst, u32 intr_flag);
1109 int wave5_vpu_get_version_info(struct device *dev, u32 *revision, unsigned int *product_id);
1110 int wave5_vpu_dec_open(struct vpu_instance *inst, struct dec_open_param *open_param);
1111 int wave5_vpu_dec_close(struct vpu_instance *inst, u32 *fail_res);
1112 int wave5_vpu_dec_issue_seq_init(struct vpu_instance *inst);
1113 int wave5_vpu_dec_complete_seq_init(struct vpu_instance *inst, struct dec_initial_info *info);
1114 int wave5_vpu_dec_register_frame_buffer_ex(struct vpu_instance *inst, int num_of_decoding_fbs,
1115                                            int num_of_display_fbs, int stride, int height,
1116                                            int map_type);
1117 int wave5_vpu_dec_start_one_frame(struct vpu_instance *inst, struct dec_param *param,
1118                                   u32 *res_fail);
1119 int wave5_vpu_dec_get_output_info(struct vpu_instance *inst, struct dec_output_info *info);
1120 int wave5_vpu_dec_set_rd_ptr(struct vpu_instance *inst, dma_addr_t addr, int update_wr_ptr);
1121 int wave5_vpu_dec_give_command(struct vpu_instance *inst, enum codec_command cmd, void *parameter);
1122 int wave5_vpu_dec_get_bitstream_buffer(struct vpu_instance *inst, dma_addr_t *prd_ptr,
1123                                        dma_addr_t *pwr_ptr, size_t *size);
1124 int wave5_vpu_dec_update_bitstream_buffer(struct vpu_instance *inst, size_t size);
1125 int wave5_vpu_dec_clr_disp_flag(struct vpu_instance *inst, int index);
1126 int wave5_vpu_dec_set_disp_flag(struct vpu_instance *inst, int index);
1127
1128 int wave5_vpu_enc_open(struct vpu_instance *inst, struct enc_open_param *open_param);
1129 int wave5_vpu_enc_close(struct vpu_instance *inst, u32 *fail_res);
1130 int wave5_vpu_enc_issue_seq_init(struct vpu_instance *inst);
1131 int wave5_vpu_enc_complete_seq_init(struct vpu_instance *inst, struct enc_initial_info *info);
1132 int wave5_vpu_enc_register_frame_buffer(struct vpu_instance *inst, unsigned int num,
1133                                         unsigned int stride, int height,
1134                                         enum tiled_map_type map_type);
1135 int wave5_vpu_enc_start_one_frame(struct vpu_instance *inst, struct enc_param *param,
1136                                   u32 *fail_res);
1137 int wave5_vpu_enc_get_output_info(struct vpu_instance *inst, struct enc_output_info *info);
1138 int wave5_vpu_enc_give_command(struct vpu_instance *inst, enum codec_command cmd, void *parameter);
1139
1140 #endif