tizen 2.3.1 release
[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
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
319         int out_img_width;      /* [OUT] width  of YUV420 frame */
320         int out_img_height;     /* [OUT] height of YUV420 frame */
321         int out_buf_width;      /* [OUT] width  of YUV420 frame */
322         int out_buf_height;     /* [OUT] height of YUV420 frame */
323
324         int out_disp_pic_frame_type;             /* [OUT] display picture frame type information */
325 #ifdef CONFIG_SLP
326         SSBSIP_MFC_MEMORY_TYPE memory_type;     /* [OUT] memory type */
327 #endif
328 };
329
330 struct mfc_basic_config {
331         int values[4];
332 };
333
334 struct mfc_frame_packing {
335         int             available;
336         unsigned int    arrangement_id;
337         int             arrangement_cancel_flag;
338         unsigned char   arrangement_type;
339         int             quincunx_sampling_flag;
340         unsigned char   content_interpretation_type;
341         int             spatial_flipping_flag;
342         int             frame0_flipped_flag;
343         int             field_views_flag;
344         int             current_frame_is_frame0_flag;
345         unsigned char   frame0_grid_pos_x;
346         unsigned char   frame0_grid_pos_y;
347         unsigned char   frame1_grid_pos_x;
348         unsigned char   frame1_grid_pos_y;
349 };
350
351 union _mfc_config_arg {
352         struct mfc_basic_config basic;
353         struct mfc_frame_packing frame_packing;
354 };
355
356 struct mfc_config_arg {
357         int type;
358         union _mfc_config_arg args;
359 };
360
361 struct mfc_get_real_addr_arg {
362         unsigned int key;
363         unsigned int addr;
364 };
365
366 struct mfc_buf_alloc_arg {
367         enum inst_type type;
368         int size;
369         /*
370         unsigned int mapped;
371         */
372         unsigned int align;
373
374         unsigned int addr;
375         /*
376         unsigned int phys;
377         */
378 #if defined(CONFIG_VIDEO_MFC_VCM_UMP)
379         /* FIMXE: invalid secure id == -1 */
380         unsigned int secure_id;
381 #elif defined(CONFIG_S5P_VMEM)
382         unsigned int cookie;
383 #else
384         unsigned int offset;
385 #endif
386 };
387
388 struct mfc_buf_free_arg {
389         unsigned int addr;
390 };
391
392
393 /* RMVME */
394 struct mfc_mem_alloc_arg {
395         enum inst_type type;
396         int buff_size;
397         SSBIP_MFC_BUFFER_TYPE buf_cache_type;
398         unsigned int mapped_addr;
399 #if defined(CONFIG_VIDEO_MFC_VCM_UMP)
400         unsigned int secure_id;
401 #elif defined(CONFIG_S5P_VMEM)
402         unsigned int cookie;
403 #else
404         unsigned int offset;
405 #endif
406 };
407
408 struct mfc_mem_free_arg {
409         unsigned int key;
410 };
411 /* RMVME */
412
413 union mfc_args {
414         /*
415         struct mfc_enc_init_arg enc_init;
416
417         struct mfc_enc_init_mpeg4_arg enc_init_mpeg4;
418         struct mfc_enc_init_mpeg4_arg enc_init_h263;
419         struct mfc_enc_init_h264_arg enc_init_h264;
420         */
421         struct mfc_enc_init_arg enc_init;
422         struct mfc_enc_exe_arg enc_exe;
423
424         struct mfc_dec_init_arg dec_init;
425         struct mfc_dec_exe_arg dec_exe;
426
427         struct mfc_config_arg config;
428
429         struct mfc_buf_alloc_arg buf_alloc;
430         struct mfc_buf_free_arg buf_free;
431         struct mfc_get_real_addr_arg real_addr;
432
433         /* RMVME */
434         struct mfc_mem_alloc_arg mem_alloc;
435         struct mfc_mem_free_arg mem_free;
436         /* RMVME */
437 #ifdef CONFIG_SLP
438         SSBSIP_MFC_MEMORY_TYPE memory_type;
439 #endif
440 };
441
442 struct mfc_common_args {
443         enum mfc_ret_code ret_code;     /* [OUT] error code */
444         union mfc_args args;
445 };
446
447 struct mfc_enc_vui_info {
448         int aspect_ratio_idc;
449 };
450
451 struct mfc_dec_fimv1_info {
452         int width;
453         int height;
454 };
455
456 struct mfc_enc_hier_p_qp {
457         int t0_frame_qp;
458         int t2_frame_qp;
459         int t3_frame_qp;
460 };
461
462 struct mfc_enc_set_config {
463         int enable;
464         int number;
465 };
466
467 typedef struct
468 {
469         int magic;
470         int hMFC;
471         int hVMEM;
472         int width;
473         int height;
474         int sizeStrmBuf;
475         struct mfc_frame_buf_arg sizeFrmBuf;
476         int displayStatus;
477         int inter_buff_status;
478         unsigned int virFreeStrmAddr;
479         unsigned int phyStrmBuf;
480         unsigned int virStrmBuf;
481         unsigned int virMvRefYC;
482         struct mfc_frame_buf_arg phyFrmBuf;
483         struct mfc_frame_buf_arg virFrmBuf;
484         unsigned int mapped_addr;
485         unsigned int mapped_size;
486         struct mfc_common_args MfcArg;
487         SSBSIP_MFC_CODEC_TYPE codecType;
488         SSBSIP_MFC_DEC_OUTPUT_INFO decOutInfo;
489         unsigned int inframetag;
490         unsigned int outframetagtop;
491         unsigned int outframetagbottom;
492         unsigned int immediatelydisp;
493         unsigned int encodedHeaderSize;
494         int encodedDataSize;
495         unsigned int encodedframeType;
496         struct mfc_frame_buf_arg encodedphyFrmBuf;
497
498         unsigned int dec_crc;
499         unsigned int dec_pixelcache;
500         unsigned int dec_slice;
501         unsigned int dec_numextradpb;
502         unsigned int dec_packedPB_detect;
503
504         int input_cookie;
505         int input_secure_id;
506         int input_size;
507
508         unsigned int encode_cnt;
509         int enc_frame_map;
510 } _MFCLIB;
511
512 #define ENC_PROFILE_LEVEL(profile, level)      ((profile) | ((level) << 8))
513 #define ENC_RC_QBOUND(min_qp, max_qp)          ((min_qp) | ((max_qp) << 8))
514
515 #endif /* __MFC_INTERFACE_H */