xref: /utopia/UTPA2-700.0.x/mxlib/include/drv_mfe_st.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2006-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // (uMStar Confidential Informationv) by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94 
95 
96 #ifndef _DRV_MFE_ST_H_
97 #define _DRV_MFE_ST_H_
98 
99 #ifdef __cplusplus
100 extern "C"
101 {
102 #endif
103 
104 
105 #define MFE_SUPPORT_REDUCE_MODE
106 // This version of MFE driver supports "reduce mode" which includes
107 // two flags that can be turned on/off seperately. Refer to
108 // 'enableReduceBW' and 'enableFastMode' in struct PVR_Info below.
109 
110 // MFE driver state
111 typedef enum {
112     MFE_Invalid = 0x00,  // invalid state
113     MFE_Init    = 0x20,  // driver is initialized
114     MFE_Idle    = 0x30,  // driver is idle
115     MFE_Busy    = 0x40,  // driver is busy handling a command
116     MFE_DeInit  = 0x50,  // driver is deinitialized
117     MFE_Error   = 0x60,  // driver is in an error state
118     MFE_ReInit  = 0x70,  // marker for share mem copy of encode info that
119                          //   was used during initialization
120  } MFE_STATE;
121 
122 // MFE clock level
123 typedef enum
124 {
125 MFE_CLK_VERY_SLOW = 0,
126 MFE_CLK_SLOW = 1,
127 MFE_CLK_MEDIUM = 2,
128 MFE_CLK_FAST = 3,
129 } MFE_CLK_LEVEL;
130 
131 // DO NOT USE
132 typedef enum
133 {
134 BITS_INFO_ZERO = 0,
135 BITS_INFO_UNKNOW,
136 BITS_INFO_FRAMEDONE,
137 BITS_INFO_BUFFULL,
138 BITS_INFO_IMG_BUFFULL,
139 } BITS_STATUS_INFO;
140 
141 // OBSOLETE
142 typedef enum
143 {
144 GETBITS_NOT_READY=0,
145 GETBITS_READY=1,
146 } MFE_HW_STATUS;
147 
148 // Progressive or interlaced video
149 typedef enum
150 {
151 PROGRESSIVE = 0,
152 INTERLACE_SPLITED,
153 INTERLACE_NONSPLITED,
154 } MFE_INTERLACE_INFO;
155 
156 // Input data format
157 typedef enum
158 {
159 YUVTILE = 0,         // OBSOLETE
160 MSTTILE = 1,         // YUV420, 16x32 tiled
161 MFE_YUYV = 2,        // YUV422, linear YUYV
162 MFE_YVYU = 3,        // YUV422, linear YVYU
163 MFE_UYVY = 4,        // YUV422, linear UYVY
164 MFE_VYUY = 5,        // YUV422, linear VYUY
165 MFE_EVDTILE = 6,     // YUV420, 32x16 tiled
166 MFE_32x32TILE = 7,   // YUV420, 32x32 tiled
167 MFE_NV12 = 8,        // YUV420SP, planar Y with interleaved uv
168 MFE_NV21 = 9,        // YUV420SP, planar Y with interleaved vu
169 } MFE_COLOR_FORMAT_INFO;
170 
171 #define MAX_OUTBUFFER 10UL
172 
173 // DO NOT USE
174 typedef struct {
175     MS_PHY miuAddress;    //hardware physical
176     MS_VIRT miuPointer;    //need to OR 0xA0000000
177     MS_VIRT virtual_addr;
178     MS_S32 size;
179     BITS_STATUS_INFO status;    // 1: frame_done. 2: buffer full,3: image buffer full.
180     MS_S32 is_more_bits; //1: there are more bitstream packet;  0: this is the last bitstream packet
181     MS_U8  voptype;
182     MS_PHY IVOP_address;
183     MS_S32 stuffing_bytes;     //CABAC stuffing byte
184 } BITSFRAME_INFO;
185 
186 /* Linear memory area descriptor */
187 typedef struct MEMMAP
188 {
189     MS_U8 *miuPointer;  // virtual addr
190     MS_PHY miuAddress;  // physical addr
191     MS_U32 size;        // length
192 } MEMMAP_t;
193 
194 // Input frame descriptor
195 typedef struct MEMMAP_CUR
196 {
197     MEMMAP_t Cur_Y0;    // Lumam compoment of input frame
198     MEMMAP_t Cur_C0;    // Chroma component of input frame
199     MEMMAP_t Cur_Y1;    // OBSOLETE
200     MEMMAP_t Cur_C1;    // OBSOLETE
201 } MEMMAP_CUR_t;
202 
203 // Crop information to be inserted in SPS
204 typedef struct _MFE_CROP_INFO
205 {
206     MS_BOOL crop_en;
207     MS_U32 crop_top;
208     MS_U32 crop_bottom;
209     MS_U32 crop_left;
210     MS_U32 crop_right;
211 } MFE_CROP_INFO_t;
212 
213 // Descriptor on buffer allocated for MFE use
214 typedef struct _MFE_API_INFO
215 {
216     MS_PHY miu_offset;          // miu offset
217     MS_PHY mfe_phy_buf_addr;    // physical address
218     MS_VIRT mfe_vir_buf_ptr;    // virtual address
219     MS_U32 mfe_phy_buf_size;    // buffer size
220     MS_U32 Encode_stop;         // OBSOLETE
221 } MFE_API_INFO_t;
222 
223 // OBSOLETE
224 typedef struct _MFE_ADV_INFO
225 {
226     MS_U32 low_bandwidth_en;
227     MS_U32 input_imi_en;
228     MEMMAP_t imi_buf_addr;
229 } MFE_ADV_INFO_t;
230 
231 // DO NOT USE
232 typedef struct{
233     MS_U32 is_off;
234     MFE_CLK_LEVEL clock_level;
235 } POWERON_t;
236 
237 // SPS/PPS information
238 typedef struct _SPSPPS_INFO
239 {
240     MS_U8* pHeaderSPS;  // pointer to SPS
241     MS_U32 SPSLen;      // SPS size
242     MS_U8* pHeaderPPS;  // pointer to PPS
243     MS_U32 PPSLen;      // PPS size
244 } SPSPPS_INFO_t;
245 
246 // OBSOLETE
247 typedef struct _VOL_INFO
248 {
249     MS_U8* pHeader;
250     MS_U32 Len;
251 } VOL_INFO_t;
252 
253 // Callback function invoked after frame is encoded
254 // bFirst_or_last_byte_of_Frame: 0x00 error state, 0x10 first , 0x01 last at frame, 0x11 one frame
255 typedef void (*StreamCallback)(void *pCtx, MS_S32 s32FrameType, void *pStreamData, MS_U32 u32DataLen, MS_U32 bFirstOrLastByteOfFrame);
256 
257 // Callback function invoked to signal input buffer status
258 typedef void (*CleanCallback)(MS_U32 u32FrameCoded, MS_VIRT u32YUVPlane);
259 
260 // Encode info structure
261 // OBSOLETE fields should be initialized to 0 and not tampered with afterwards.
262 // MADP-layer "simplified" encoder configuration
263 // NOTE: "Advanced" configurations are hidden inside DRV-layer.
264 typedef struct{
265     // MFE-compliant
266     MS_S32 width;                           // frame width
267     MS_S32 height;                          // frame height
268     MS_PHY BitsBuffStart;                   // OBSOLETE
269     MS_U32 BitsBuffSize;                    // OBSOLETE
270     MS_S32 nOutBuffer;                      // OBSOLETE
271     MS_S32 OutBufferSize;                   // OBSOLETE
272     MEMMAP_t InBuffer;                      // OBSOLETE
273     MEMMAP_t BitstreamOutBuffer;            // output buffer descriptor
274     MS_S32 BitstreamOutBufferSize;          // output buffer size
275 
276     // MFE new settings
277     //MFE_COLOR_FORMAT_INFO nColorFormat;
278     MS_S32 nCodecType;                      // Encoder format. MUST be H264_ENC.
279     MS_S32 nDispWidth, nDispHeight;         // Display resolution
280     MS_S32 nBufWidth, nBufHeight;           // Image buffer resolution (aligned to 16 or 32 byte, depends on nCodecType)
281     MFE_INTERLACE_INFO bInterlace;          // Frame mode to encode
282     MFE_COLOR_FORMAT_INFO bColorFormat;     // input data format
283     // GOP
284     MS_S32 nPbetweenI;                      // number of P-frames between I-frames
285     MS_S32 nBbetweenP;                      // OBSOLETE
286     MS_S32 nP_is_infinite;                  // One I-frame followed by infinite number of P-frames
287     // Rate control
288     MS_S32 FrameRatex100;                   // frames per second x 100
289     MS_S32 nBitrate;                        // bits per second
290     MS_S32 m_bFrameMode;                    // Input frame mode. MUST be 1.
291     MS_S32 out_frametag_top;                // frame tag set/retrieved using MFE_ENC_SETCONF_FRAME_TAG/MFE_ENC_GETCONF_FRAME_TAG
292     // Video length
293     MS_S32 nTotalFrames;                    // OBSOLETE
294     MS_S32 TimeIncreamentRes;               // OBSOLETE
295     MS_S32 VopTimeIncreament;               // OBSOLETE
296     //jpeg parameter
297     MS_S32 quality;                         // OBSOLETE
298     MS_S32 fdc_mode;                        // OBSOLETE
299     MS_S32 exif_enable;                     // OBSOLETE
300     MFE_CLK_LEVEL MFEClk;                   // MFE clock level to use
301 
302     MFE_API_INFO_t MfeApiInfo;              // buffer allocated for MFE use
303     MFE_ADV_INFO_t MfeAdvInfo;              // OBSOLETE
304 
305     MS_U32 nDropFlag;                       // OBSOLETE
306     MS_U32 nSkipFlag;                       // OBSOLETE
307     MS_U32 enableVTRateControl;             // OBSOLETE
308     MS_U32 enableSecurityMode;              // security mode
309     MS_U32 enableISR;                       // frame done detection: 1: ISR mode; 0: polling mode
310     MS_U32 enableCABAC;                     // main profile requires CABAC
311 
312     MFE_CROP_INFO_t  MfeCropInfo;
313     MS_U32 enableReduceBW;                  // Memory BW reduced mode
314     MS_U32 enableFastMode;                  // intra mode inly 0~2, drop i16 and disable fme.
315     MFE_STATE mfe_state;                    // driver state
316     void* g_pCustomCtx;
317     StreamCallback g_StreamCallBackFunc;    // pointer to stream callback function
318     CleanCallback g_CleanCallBackFunc;      // pointer to input buffer callback function
319 
320     void* mfe_drvHandle;                    // driver handle for internal use. *** DO NOT MODIFY ***
321 
322     MS_S32 reserved0;                       // 1: cached memory; 0: non-cached memory
323     MS_S32 reserved1;                       // bit[0] 1: enable TLB; 0: disable TLB
324     MS_S32 reserved2;                       // reserved
325     MS_S32 reserved3;                       // reserved
326     MS_S32 reserved4;                       // reserved
327     MS_S32 reserved5;                       // reserved
328 }PVR_Info;
329 
330 #define API_HWCAP_VERSION0 1UL
331 
332 // Hardware capability strcuture
333 typedef struct{
334     MS_U32 u32ApiHW_Version;                // Version of current structure
335     MS_U16 u16ApiHW_Length;                 // Length of this structure
336     MS_BOOL bIsSupportEncoder;              // Support encoder
337     MS_U8 u8MaxEncodeFrame;                 // Max encode frame
338     MS_U16 u16MaxEncodeWidth;               // Max encode width
339     MS_U16 u16MaxEncodeHeight;              // Max encode height
340     MS_BOOL bSupportSubVidWin;              // Support sub video window
341     MS_BOOL bSupportMpeg4;                  // Support MPEG4
342     MS_BOOL bSupportH264;                   // Support H.264
343     /*New Cap add in struct add at the end*/
344 }MFE_HwCapV0;
345 
346 #ifdef __cplusplus
347 }
348 #endif
349 
350 #endif
351