Initial commit
[kernel/linux-3.0.git] / drivers / media / video / samsung / mfc5x / mfc_interface.h
1 /*
2  * Copyright (c) 2010 Samsung Electronics Co., Ltd.
3  *              http://www.samsung.com/
4  *
5  * Global header for Samsung MFC (Multi Function Codec - FIMV) driver
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * Alternatively, Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23
24 #ifndef __MFC_INTERFACE_H
25 #define __MFC_INTERFACE_H __FILE__
26
27 #include "mfc_errno.h"
28 #include "SsbSipMfcApi.h"
29
30 #define IOCTL_MFC_DEC_INIT              (0x00800001)
31 #define IOCTL_MFC_ENC_INIT              (0x00800002)
32 #define IOCTL_MFC_DEC_EXE               (0x00800003)
33 #define IOCTL_MFC_ENC_EXE               (0x00800004)
34
35 #define IOCTL_MFC_GET_IN_BUF            (0x00800010)
36 #define IOCTL_MFC_FREE_BUF              (0x00800011)
37 #define IOCTL_MFC_GET_REAL_ADDR         (0x00800012)
38 #define IOCTL_MFC_GET_MMAP_SIZE         (0x00800014)
39 #define IOCTL_MFC_SET_IN_BUF            (0x00800018)
40
41 #define IOCTL_MFC_SET_CONFIG            (0x00800101)
42 #define IOCTL_MFC_GET_CONFIG            (0x00800102)
43
44 #define IOCTL_MFC_SET_BUF_CACHE         (0x00800201)
45
46 /* MFC H/W support maximum 32 extra DPB. */
47 #define MFC_MAX_EXTRA_DPB               5
48 #define MFC_MAX_DISP_DELAY              0xF
49
50 #define MFC_LIB_VER_MAJOR               1
51 #define MFC_LIB_VER_MINOR               00
52
53 #define BUF_L_UNIT                      (1024)
54 #define Align(x, alignbyte)             (((x)+(alignbyte)-1)/(alignbyte)*(alignbyte))
55
56
57 enum inst_type {
58     DECODER = 0x1,
59     ENCODER = 0x2,
60 };
61
62 typedef enum {
63     MFC_UNPACKED_PB = 0,
64     MFC_PACKED_PB = 1
65 } mfc_packed_mode;
66
67
68 typedef enum
69 {
70         MFC_USE_NONE = 0x00,
71         MFC_USE_YUV_BUFF = 0x01,
72         MFC_USE_STRM_BUFF = 0x10
73 } s3c_mfc_interbuff_status;
74
75 #ifndef FPS
76 typedef struct
77 {
78         int luma0;      /* per frame (or top field)*/
79         int chroma0;    /* per frame (or top field)*/
80         int luma1;      /* per frame (or bottom field)*/
81         int chroma1;    /* per frame (or bottom field)*/
82 } SSBSIP_MFC_CRC_DATA;
83 #endif
84
85 struct mfc_strm_ref_buf_arg {
86         unsigned int strm_ref_y;
87         unsigned int mv_ref_yc;
88 };
89
90 struct mfc_frame_buf_arg {
91         unsigned int luma;
92         unsigned int chroma;
93 };
94
95
96 struct mfc_enc_init_common_arg {
97         SSBSIP_MFC_CODEC_TYPE in_codec_type;    /* [IN] codec type */
98
99         int in_width;           /* [IN] width of YUV420 frame to be encoded */
100         int in_height;          /* [IN] height of YUV420 frame to be encoded */
101
102         int in_gop_num;         /* [IN] GOP Number (interval of I-frame) */
103         int in_vop_quant;       /* [IN] VOP quant */
104         int in_vop_quant_p;     /* [IN] VOP quant for P frame */
105
106         /* [IN] RC enable */
107         /* [IN] RC enable (0:disable, 1:frame level RC) */
108         int in_rc_fr_en;
109         int in_rc_bitrate;      /* [IN]  RC parameter (bitrate in kbps) */
110
111         int in_rc_qbound_min;   /* [IN]  RC parameter (Q bound Min) */
112         int in_rc_qbound_max;   /* [IN]  RC parameter (Q bound Max) */
113         int in_rc_rpara;        /* [IN]  RC parameter (Reaction Coefficient) */
114
115         /* [IN] Multi-slice mode (0:single, 1:multiple) */
116         int in_ms_mode;
117         /* [IN] Multi-slice size (in num. of mb or byte) */
118         int in_ms_arg;
119
120         int in_mb_refresh;      /* [IN]  Macroblock refresh */
121
122         /* [IN] Enable (1) / Disable (0) padding with the specified values */
123         int in_pad_ctrl_on;
124
125         /* [IN] pad value if pad_ctrl_on is Enable */
126         int in_y_pad_val;
127         int in_cb_pad_val;
128         int in_cr_pad_val;
129
130         /* linear or tiled */
131         int in_frame_map;
132
133         unsigned int in_pixelcache;
134         unsigned int in_mapped_addr;
135
136         struct mfc_strm_ref_buf_arg out_u_addr;
137         struct mfc_strm_ref_buf_arg out_p_addr;
138         struct mfc_strm_ref_buf_arg out_buf_size;
139         unsigned int out_header_size;
140
141 #if SUPPORT_SLICE_ENCODING
142         unsigned int in_output_mode;
143 #endif
144 };
145
146 struct mfc_enc_init_h263_arg {
147         int in_rc_framerate;    /* [IN]  RC parameter (framerate) */
148 };
149
150 struct mfc_enc_init_mpeg4_arg {
151         int in_profile;         /* [IN] profile */
152         int in_level;           /* [IN] level */
153
154         int in_vop_quant_b;     /* [IN] VOP quant for B frame */
155
156         /* [IN] B frame number */
157         int in_bframenum;
158
159         /* [IN] Quarter-pel MC enable (1:enabled, 0:disabled) */
160         int in_quart_pixel;
161
162         int in_TimeIncreamentRes;       /* [IN] VOP time resolution */
163         int in_VopTimeIncreament;       /* [IN] Frame delta */
164 };
165
166 struct mfc_enc_init_h264_arg {
167         int in_profile;         /* [IN] profile */
168         int in_level;           /* [IN] level */
169
170         int in_vop_quant_b;     /* [IN] VOP quant for B frame */
171
172         /* [IN] B frame number */
173         int in_bframenum;
174
175         /* [IN] interlace mode(0:progressive, 1:interlace) */
176         int in_interlace_mode;
177
178         /* [IN]  reference number */
179         int in_reference_num;
180         /* [IN]  reference number of P frame */
181         int in_ref_num_p;
182
183         int in_rc_framerate;    /* [IN]  RC parameter (framerate) */
184         int in_rc_mb_en;        /* [IN] RC enable (0:disable, 1:MB level RC) */
185         /* [IN] MB level rate control dark region adaptive feature */
186         int in_rc_mb_dark_dis;  /* (0:enable, 1:disable) */
187         /* [IN] MB level rate control smooth region adaptive feature */
188         int in_rc_mb_smooth_dis;        /* (0:enable, 1:disable) */
189         /* [IN] MB level rate control static region adaptive feature */
190         int in_rc_mb_static_dis;        /* (0:enable, 1:disable) */
191         /* [IN] MB level rate control activity region adaptive feature */
192         int in_rc_mb_activity_dis;      /* (0:enable, 1:disable) */
193
194         /* [IN]  disable deblocking filter idc */
195         int in_deblock_dis;     /* (0: enable,1: disable, 2:Disable at slice boundary) */
196         /* [IN]  slice alpha c0 offset of deblocking filter */
197         int in_deblock_alpha_c0;
198         /* [IN]  slice beta offset of deblocking filter */
199         int in_deblock_beta;
200
201         /* [IN]  ( 0 : CAVLC, 1 : CABAC ) */
202         int in_symbolmode;
203         /* [IN] (0: only 4x4 transform, 1: allow using 8x8 transform) */
204         int in_transform8x8_mode;
205
206         /* [IN] Inter weighted parameter for mode decision */
207         int in_md_interweight_pps;
208         /* [IN] Intra weighted parameter for mode decision */
209         int in_md_intraweight_pps;
210 };
211
212 struct mfc_enc_init_arg {
213         struct mfc_enc_init_common_arg cmn;
214         union {
215                 struct mfc_enc_init_h264_arg h264;
216                 struct mfc_enc_init_mpeg4_arg mpeg4;
217                 struct mfc_enc_init_h263_arg h263;
218         } codec;
219 };
220
221 struct mfc_enc_exe_arg {
222         SSBSIP_MFC_CODEC_TYPE in_codec_type;    /* [IN] codec type */
223         unsigned int in_Y_addr;   /*[IN]In-buffer addr of Y component */
224         unsigned int in_CbCr_addr;/*[IN]In-buffer addr of CbCr component */
225         unsigned int in_Y_addr_vir;   /*[IN]In-buffer addr of Y component */
226         unsigned int in_CbCr_addr_vir;/*[IN]In-buffer addr of CbCr component */
227         unsigned int in_strm_st;  /*[IN]Out-buffer start addr of encoded strm*/
228         unsigned int in_strm_end; /*[IN]Out-buffer end addr of encoded strm */
229         unsigned int in_frametag;       /* [IN]  unique frame ID */
230
231         unsigned int out_frame_type; /* [OUT] frame type  */
232         int out_encoded_size;        /* [OUT] Length of Encoded video stream */
233         unsigned int out_Y_addr;    /*[OUT]Out-buffer addr of encoded Y component */
234         unsigned int out_CbCr_addr; /*[OUT]Out-buffer addr of encoded CbCr component */
235         unsigned int out_frametag_top;  /* [OUT] unique frame ID of an output frame or top field */
236         unsigned int out_frametag_bottom;/* [OUT] unique frame ID of bottom field */
237
238 #if defined(CONFIG_VIDEO_MFC_VCM_UMP)
239         unsigned int out_y_secure_id;
240         unsigned int out_c_secure_id;
241 #elif defined(CONFIG_S5P_VMEM)
242         unsigned int out_y_cookie;
243         unsigned int out_c_cookie;
244 #endif
245 #ifdef CONFIG_SLP_DMABUF
246         SSBSIP_MFC_MEMORY_TYPE memory_type;     /* [OUT] memory type */
247 #endif
248 };
249
250 struct mfc_dec_init_arg {
251         SSBSIP_MFC_CODEC_TYPE in_codec_type;    /* [IN] codec type */
252         int in_strm_buf;                /* [IN] address of stream buffer */
253         int in_strm_size;               /* [IN] filled size in stream buffer */
254         int in_packed_PB;               /* [IN]  Is packed PB frame or not, 1: packedPB  0: unpacked    */
255
256         unsigned int in_crc;            /* [IN] */
257         unsigned int in_pixelcache;     /* [IN] */
258         unsigned int in_slice;          /* [IN] */
259         unsigned int in_numextradpb;    /* [IN] */
260
261         unsigned int in_mapped_addr;
262
263         int out_frm_width;              /* [OUT] width  of YUV420 frame */
264         int out_frm_height;             /* [OUT] height of YUV420 frame */
265         int out_buf_width;      /* [OUT] width  of YUV420 frame */
266         int out_buf_height;     /* [OUT] height of YUV420 frame */
267
268         int out_dpb_cnt;        /* [OUT] the number of buffers which is nessary during decoding. */
269
270         int out_crop_right_offset;      /* [OUT] crop information for h264 */
271         int out_crop_left_offset;
272         int out_crop_bottom_offset;
273         int out_crop_top_offset;
274 };
275
276 struct mfc_dec_exe_arg {
277         SSBSIP_MFC_CODEC_TYPE in_codec_type;    /* [IN]  codec type */
278         int in_strm_buf;  /* [IN]  the physical address of STRM_BUF */
279         /* [IN]  Size of video stream filled in STRM_BUF */
280         int in_strm_size;
281         /* [IN] the address of dpb FRAME_BUF */
282         struct mfc_frame_buf_arg in_frm_buf;
283         /* [IN] size of dpb FRAME_BUF */
284         struct mfc_frame_buf_arg in_frm_size;
285         /* [IN] Unique frame ID eg. application specific timestamp */
286         unsigned int in_frametag;
287         /* [IN] immdiate Display for seek,thumbnail and one frame */
288         int in_immediately_disp;
289         /* [OUT]  the physical address of display buf */
290         int out_display_Y_addr;
291         /* [OUT]  the physical address of display buf */
292         int out_display_C_addr;
293         int out_display_status;
294         /* [OUT] unique frame ID of an output frame or top field */
295         unsigned int out_frametag_top;
296         /* [OUT] unique frame ID of bottom field */
297         unsigned int out_frametag_bottom;
298         int out_pic_time_top;
299         int out_pic_time_bottom;
300         int out_consumed_byte;
301
302         int out_crop_right_offset;
303         int out_crop_left_offset;
304         int out_crop_bottom_offset;
305         int out_crop_top_offset;
306
307         /* in new driver, each buffer offset must be return to the user */
308         int out_y_offset;
309         int out_c_offset;
310
311 #if defined(CONFIG_VIDEO_MFC_VCM_UMP)
312         unsigned int out_y_secure_id;
313         unsigned int out_c_secure_id;
314 #elif defined(CONFIG_S5P_VMEM)
315         unsigned int out_y_cookie;
316         unsigned int out_c_cookie;
317 #endif
318 #ifdef CONFIG_SLP_DMABUF
319         SSBSIP_MFC_MEMORY_TYPE memory_type;     /* [OUT] memory type */
320 #endif
321         int out_img_width;      /* [OUT] width  of YUV420 frame */
322         int out_img_height;     /* [OUT] height of YUV420 frame */
323         int out_buf_width;      /* [OUT] width  of YUV420 frame */
324         int out_buf_height;     /* [OUT] height of YUV420 frame */
325
326         int out_disp_pic_frame_type;             /* [OUT] display picture frame type information */
327 };
328
329 struct mfc_basic_config {
330         int values[4];
331 };
332
333 struct mfc_frame_packing {
334         int             available;
335         unsigned int    arrangement_id;
336         int             arrangement_cancel_flag;
337         unsigned char   arrangement_type;
338         int             quincunx_sampling_flag;
339         unsigned char   content_interpretation_type;
340         int             spatial_flipping_flag;
341         int             frame0_flipped_flag;
342         int             field_views_flag;
343         int             current_frame_is_frame0_flag;
344         unsigned char   frame0_grid_pos_x;
345         unsigned char   frame0_grid_pos_y;
346         unsigned char   frame1_grid_pos_x;
347         unsigned char   frame1_grid_pos_y;
348 };
349
350 union _mfc_config_arg {
351         struct mfc_basic_config basic;
352         struct mfc_frame_packing frame_packing;
353 };
354
355 struct mfc_config_arg {
356         int type;
357         union _mfc_config_arg args;
358 };
359
360 struct mfc_get_real_addr_arg {
361         unsigned int key;
362         unsigned int addr;
363 };
364
365 struct mfc_buf_alloc_arg {
366         enum inst_type type;
367         int size;
368         /*
369         unsigned int mapped;
370         */
371         unsigned int align;
372
373         unsigned int addr;
374         /*
375         unsigned int phys;
376         */
377 #if defined(CONFIG_VIDEO_MFC_VCM_UMP)
378         /* FIMXE: invalid secure id == -1 */
379         unsigned int secure_id;
380 #elif defined(CONFIG_S5P_VMEM)
381         unsigned int cookie;
382 #else
383         unsigned int offset;
384 #endif
385 };
386
387 struct mfc_buf_free_arg {
388         unsigned int addr;
389 };
390
391
392 /* RMVME */
393 struct mfc_mem_alloc_arg {
394         enum inst_type type;
395         int buff_size;
396         SSBIP_MFC_BUFFER_TYPE buf_cache_type;
397         unsigned int mapped_addr;
398 #if defined(CONFIG_VIDEO_MFC_VCM_UMP)
399         unsigned int secure_id;
400 #elif defined(CONFIG_S5P_VMEM)
401         unsigned int cookie;
402 #else
403         unsigned int offset;
404 #endif
405 };
406
407 struct mfc_mem_free_arg {
408         unsigned int key;
409 };
410 /* RMVME */
411
412 union mfc_args {
413         /*
414         struct mfc_enc_init_arg enc_init;
415
416         struct mfc_enc_init_mpeg4_arg enc_init_mpeg4;
417         struct mfc_enc_init_mpeg4_arg enc_init_h263;
418         struct mfc_enc_init_h264_arg enc_init_h264;
419         */
420         struct mfc_enc_init_arg enc_init;
421         struct mfc_enc_exe_arg enc_exe;
422
423         struct mfc_dec_init_arg dec_init;
424         struct mfc_dec_exe_arg dec_exe;
425
426         struct mfc_config_arg config;
427
428         struct mfc_buf_alloc_arg buf_alloc;
429         struct mfc_buf_free_arg buf_free;
430         struct mfc_get_real_addr_arg real_addr;
431
432         /* RMVME */
433         struct mfc_mem_alloc_arg mem_alloc;
434         struct mfc_mem_free_arg mem_free;
435         /* RMVME */
436 };
437
438 struct mfc_common_args {
439         enum mfc_ret_code ret_code;     /* [OUT] error code */
440         union mfc_args args;
441 };
442
443 struct mfc_enc_vui_info {
444         int aspect_ratio_idc;
445 };
446
447 struct mfc_dec_fimv1_info {
448         int width;
449         int height;
450 };
451
452 struct mfc_enc_hier_p_qp {
453         int t0_frame_qp;
454         int t2_frame_qp;
455         int t3_frame_qp;
456 };
457
458 struct mfc_enc_set_config {
459         int enable;
460         int number;
461 };
462
463 typedef struct
464 {
465         int magic;
466         int hMFC;
467         int hVMEM;
468         int width;
469         int height;
470         int sizeStrmBuf;
471         struct mfc_frame_buf_arg sizeFrmBuf;
472         int displayStatus;
473         int inter_buff_status;
474         unsigned int virFreeStrmAddr;
475         unsigned int phyStrmBuf;
476         unsigned int virStrmBuf;
477         unsigned int virMvRefYC;
478         struct mfc_frame_buf_arg phyFrmBuf;
479         struct mfc_frame_buf_arg virFrmBuf;
480         unsigned int mapped_addr;
481         unsigned int mapped_size;
482         struct mfc_common_args MfcArg;
483         SSBSIP_MFC_CODEC_TYPE codecType;
484         SSBSIP_MFC_DEC_OUTPUT_INFO decOutInfo;
485         unsigned int inframetag;
486         unsigned int outframetagtop;
487         unsigned int outframetagbottom;
488         unsigned int immediatelydisp;
489         unsigned int encodedHeaderSize;
490         int encodedDataSize;
491         unsigned int encodedframeType;
492         struct mfc_frame_buf_arg encodedphyFrmBuf;
493
494         unsigned int dec_crc;
495         unsigned int dec_pixelcache;
496         unsigned int dec_slice;
497         unsigned int dec_numextradpb;
498         unsigned int dec_packedPB_detect;
499
500         int input_cookie;
501         int input_secure_id;
502         int input_size;
503
504         unsigned int encode_cnt;
505         int enc_frame_map;
506 } _MFCLIB;
507
508 #define ENC_PROFILE_LEVEL(profile, level)      ((profile) | ((level) << 8))
509 #define ENC_RC_QBOUND(min_qp, max_qp)          ((min_qp) | ((max_qp) << 8))
510
511 #endif /* __MFC_INTERFACE_H */