/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
/*
 * Copyright (c) 2023 MediaTek Inc.
 */

#ifndef _DRV_GOP_H_
#define _DRV_GOP_H_

#ifdef __cplusplus
extern "C"
{
#endif
#if defined(MSOS_TYPE_LINUX_KERNEL)
#include "autoconf.h"
#endif
#include "MsCommon.h"

#if defined(MSOS_TYPE_LINUX)
#include <sys/types.h>
#include <unistd.h>
#elif defined(MSOS_TYPE_LINUX_KERNEL)
#define getpid() pInstance
#else
#define getpid() 0UL
#define MsOS_GetOSThreadID(args...) (-1)
#endif

#include "apiGOP.h"

#define GETPIDTYPE ptrdiff_t

#if (defined ANDROID) && (defined TV_OS)
#include <cutils/log.h>
#define printf LOGD
#ifndef LOGD // android 4.1 rename LOGx to ALOGx
#define LOGD ALOGD
#endif
#endif

#ifdef  MSOS_TYPE_LINUX
#include <assert.h>
#include <unistd.h>
#define APIGOP_ASSERT(_bool, pri)  if (!(_bool)) {printf("\nAssert in %s,%d\n", __FUNCTION__, __LINE__); {pri;}; MsOS_DelayTask(100); assert(0);}
#else
#define APIGOP_ASSERT(_bool, pri)  if (!(_bool)) {printf("\nAssert in %s,%d\n", __FUNCTION__, __LINE__); {pri;};};
#endif

#if defined(CONFIG_API_GOP) || defined(CONFIG_API_GOP_MODULE)
#else
#define CONFIG_GOP_POOL_ARRANGE
#define CONFIG_GOP_GWIN_MISC
#define CONFIG_GOP_2ND_PAL
#define CONFIG_GOP_BG
#define CONFIG_GOP_FADE
#define CONFIG_GOP_YUV_SWAP
#define CONFIG_GOP_CONTRAST
#define CONFIG_GOP_GOP_VE_CAPTURE
#define CONFIG_GOP_SCROLL
#define CONFIG_GOP_TEST_PATTERN
#define CONFIG_GOP_VE_CAPTURE
#endif
//-------------------------------------------------------------------------------------------------
//  Driver Capability
//-------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------
//  Customize Define
//-------------------------------------------------------------------------------------------------
#define CUS_SETTING               0UL
#ifdef CONFIG_GOP_UTOPIA10
#ifdef INSTANT_PRIVATE
#undef INSTANT_PRIVATE
#endif
#else
#define INSTANT_PRIVATE           1UL
#endif
#if CUS_SETTING
#define WINFB_INSHARED            1UL
#define POOL_INSHARED             1UL
#define CURSOR_SUPPORT            1UL
#define MUTEX_LOCK_ENABLE         0UL
#define ENABLE_GOP0_RBLK_MIRROR   FALSE
#ifndef DRV_MAX_GWIN_FB_SUPPORT
#define DRV_MAX_GWIN_FB_SUPPORT   0xFFFEUL
#endif
#define GFLIP_ENABLE              FALSE
#define BOOTLOGO_PATCH            TRUE
#define GOP_PIXEL_ALIGN           FALSE
#define GOP_SW_SCROLL             TRUE
#define GOP_3D_TYPE_SEL           E_DRV_3D_DUP_FULL
#define GOP_VSYNC_WAIT_BYSLEEP    FALSE

#else  //mstar default
#define WINFB_INSHARED            1UL
#define POOL_INSHARED             0UL
#define CURSOR_SUPPORT            0UL
#define MUTEX_LOCK_ENABLE         0UL
#define ENABLE_GOP0_RBLK_MIRROR   TRUE
#ifndef DRV_MAX_GWIN_FB_SUPPORT
#define DRV_MAX_GWIN_FB_SUPPORT   32UL
#endif

#ifdef CONFIG_GOP_DISABLE_GFLIP
#define GFLIP_ENABLE              FALSE
#else
#define GFLIP_ENABLE              TRUE
#endif
#define BOOTLOGO_PATCH            FALSE
#define GOP_PIXEL_ALIGN           FALSE
#define GOP_SW_SCROLL             FALSE
#define GOP_3D_TYPE_SEL           E_DRV_3D_DUP_HALF
#define GOP_VSYNC_WAIT_BYSLEEP    TRUE
#endif


#ifdef  MSOS_TYPE_NOS
#define GOP_LOCK_SUPPORT                0UL
#define GOP_XC_LOCK_SUPPORT             0UL
#define GOP_XC_SEMPHORE_PROTECT         0UL
#else
#define GOP_LOCK_SUPPORT                MUTEX_LOCK_ENABLE
#define GOP_XC_LOCK_SUPPORT             MUTEX_LOCK_ENABLE
#ifdef UTOPIA_V2  //XC
#define GOP_XC_SEMPHORE_PROTECT         1UL
#else
#define GOP_XC_SEMPHORE_PROTECT         0UL
#endif

#endif
#define GOP_XC_LOCK_DEBUG               0UL

#ifdef GOP_UTOPIA2K
    #define GOPDRIVER_BASE              KERNEL_MODE
#else
    #define GOPDRIVER_BASE              0UL
#endif
//-------------------------------------------------------------------------------------------------
//  Macro and Define
//-------------------------------------------------------------------------------------------------
#define UNUSED( var )                   (void)(var)

#define GOP_8K_WIDTH	(7680)
#define GOP_8K_HEIGHT	(4320)
#define GOP_5K_WIDTH    (5120)
#define GOP_5K_HEIGHT   (2160)
#define GOP_4K_WIDTH	(3840)
#define GOP_4K_HEIGHT	(2160)
#define GOP_SCALING_2TIMES	(0x80000)

#define MAX_GOP_INFO_COUNT      6
#define INVAILD_GOP_NUM                 0xFFUL
#define INVALID_GWIN_ID                 0xFFUL
#define GWIN_OSD_DEFAULT                (MS_U8)g_pGOPCtxLocal->pGopChipProperty->TotalGwinNum
#define INVALID_POOL_NEXT_FBID          0xFFFFFFFFUL
#define FB_FMT_AS_DEFAULT               0xFFFFUL
#define INVALID_CLIENT_PID              0x00UL //Invalid PID
#define INVALID_GOP_MUX_VAL             0xFFFFUL

#define MIU_0                           0UL
#define MIU_1                           1UL

#define GOP_STRETCH_WIDTH_UNIT          2UL    // 2-pixel
#define GOP_OUTVALID_DEFAULT (0xFFFF)

#define GOP_STRETCH_TABLE_NUM           50UL
#define GOP_VSTRETCH_TABLE_NUM          32UL
#define GOP_REG_MAX                     128UL


#define SHARED_GWIN_MAX_COUNT           32UL
#define SHARED_GOP_MAX_COUNT            8UL
#define MAX_GOP_SW_SCROLLNUM            16UL
#define MAX_MUX_NUMBER_SUPPORT          MAX_GOP_MUX

#define HAS_BIT(flag, bit)              ((flag) &  (1<<bit))
#define SET_BIT(flag, bit)              ((flag) |= (1<<bit))
#define RESET_BIT(flag, bit)            ((flag) &= (~(1<<bit)))

#define GOP_MIU_CLIENT_OC9              0x9UL
#define INVALID_BPP                     0xFFFFUL

#define GOP_FMT_RGB555_BLINK       0x0UL
#define GOP_FMT_RGB565             0x1UL
#define GOP_FMT_ARGB4444           0x2UL
#define GOP_FMT_FaBaFgBg2266       0x3UL
#define GOP_FMT_I8                 0x4UL
#define GOP_FMT_ARGB8888           0x5UL
#define GOP_FMT_ARGB1555           0x6UL
#define GOP_FMT_ABGR8888           0x7UL
#define GOP_FMT_ARGB1555_DST       0x8UL
#define GOP_FMT_YUV422             0x9UL
#define GOP_FMT_RGBA5551           10UL
#define GOP_FMT_RGBA4444           11UL
#define GOP_FMT_RGBA8888           12UL
#define GOP_FMT_BGR565             17UL
#define GOP_FMT_ABGR4444           18UL
#define GOP_FMT_ABGR1555           22UL
#define GOP_FMT_BGRA5551           26UL
#define GOP_FMT_BGRA4444           27UL
#define GOP_FMT_BGRA8888           28UL
#define GOP_FMT_GENERIC            0xFFFFUL

#ifndef PAGE_SIZE
#define PAGE_SIZE                  4096UL
#endif
#define PER_BYTE_BITS              8UL
#define TLB_PER_ENTRY_SIZE         4UL
#define PER_MIU_TLB_ENTRY_COUNT    8UL
#define ADDRESSING_8BYTE_UNIT      8UL

///GOP_PALETTE_ENTRY_NUM
#define GOP_PALETTE_ENTRY_NUM_MAX   256UL

#define BRIGHTNESS_OFFSET          0x400UL

#define GOP_MAX_SUPPORT_DEFAULT      (6)
#define GOP_INTERMIU_SEL_NUM         (8)
#define GOP_CFD_CSC_OUTPUT_NUM       (10)
#define GOP_CFD_BRI_OUTPUT_NUM       (3)
#define MAX_ML_CMD                   (100)

#define GOP_OUTPUTCOLOR_INVALID (-1)

#define GOP_CAPS_OFFSET_GOPNUM_MSK BMASK(2:0)
#define GOP_CAPS_OFFSET_VOP_PATHSEL	(5)
#define GOP_CAPS_OFFSET_GOP0_AFBC	(6)
#define GOP_CAPS_OFFSET_GOP0_CSC	(12)
#define GOP_CAPS_OFFSET_GOP0_H2TAP	(18)
#define GOP_CAPS_OFFSET_GOP0_HDUPLICATE	(19)
#define GOP_CAPS_OFFSET_GOP0_H4TAP	(21)
#define GOP_CAPS_OFFSET_GOP0_VSCALE_MODE_MSK BMASK(27:23)
#define GOP_CAPS_OFFSET_GOP0_VBILINEAR	(25)
#define GOP_CAPS_OFFSET_GOP0_V4TAP	(26)

#define GOP_CAPS_OFFSET_GOP_AFBC_COMMON	(0)
#define GOP_CAPS_OFFSET_GOP_H4TAP_COMMON	(15)
#define GOP_CAPS_OFFSET_GOP_H2TAP_COMMON	(12)
#define GOP_CAPS_OFFSET_GOP_HDUPLICATE_COMMON	(13)
#define GOP_CAPS_OFFSET_GOP_VSCALE_MODE_MSK_COMMON BMASK(21:17)
#define GOP_CAPS_OFFSET_GOP_V4TAP_COMMON	(20)
#define GOP_CAPS_OFFSET_GOP_VBILINEAR_COMMON	(19)

#define GOP_CAPS_MAJOR_IPVERSION_OFFSET_MSK BMASK(15:8)
#define GOP_CAPS_MAJOR_IPVERSION_OFFSET_SHT	8
#define GOP_CAPS_MINOR_IPVERSION_OFFSET_MSK	BMASK(7:0)

#define GOP_M6_SERIES_MAJOR	(1)
#define GOP_M6L_SERIES_MINOR	(1)
#define GOP_M6_E3_SERIES_MINOR	(2)
#define GOP_M6L_E3_SERIES_MINOR	(3)

#define GOP_MOKONA_SERIES_MAJOR	(2)

#define GOP_MOKA_SERIES_MAJOR	(3)
#define GOP_MOKA_SERIES_MINOR	(0)

#define H4TAP55_C0	(0x9A)
#define H4TAP55_C1	(0x33)
#define H4TAP55_C2	(0x90)
#define H4TAP55_C3	(0x19)
#define H4TAP55_C4	(0x03)
#define H4TAP55_C5	(0x54)
#define H4TAP55_C6	(0x76)
#define H4TAP55_C7	(0x0A)

#define H4TAP65_C0	(0xAC)
#define H4TAP65_C1	(0x2A)
#define H4TAP65_C2	(0xA0)
#define H4TAP65_C3	(0x10)
#define H4TAP65_C4	(0x0)
#define H4TAP65_C5	(0x50)
#define H4TAP65_C6	(0x7C)
#define H4TAP65_C7	(0x04)

#define H4TAP75_C0	(0xB0)
#define H4TAP75_C1	(0x28)
#define H4TAP75_C2	(0xAF)
#define H4TAP75_C3	(0x07)
#define H4TAP75_C4	(0x1F3)
#define H4TAP75_C5	(0x57)
#define H4TAP75_C6	(0x8A)
#define H4TAP75_C7	(0x1F6)

#define H4TAP85_C0	(0xDC)
#define H4TAP85_C1	(0x12)
#define H4TAP85_C2	(0xC2)
#define H4TAP85_C3	(0x1FE)
#define H4TAP85_C4	(0x1FE)
#define H4TAP85_C5	(0x42)
#define H4TAP85_C6	(0x85)
#define H4TAP85_C7	(0x1FB)

#define H4TAP95_C0	(0xF4)
#define H4TAP95_C1	(0x06)
#define H4TAP95_C2	(0xD5)
#define H4TAP95_C3	(0x1F5)
#define H4TAP95_C4	(0x1FD)
#define H4TAP95_C5	(0x39)
#define H4TAP95_C6	(0x89)
#define H4TAP95_C7	(0x1F7)

#define H4TAP105_C0	(0x110)
#define H4TAP105_C1	(0x1F8)
#define H4TAP105_C2	(0xE9)
#define H4TAP105_C3	(0x1E4)
#define H4TAP105_C4	(0x1FC)
#define H4TAP105_C5	(0x37)
#define H4TAP105_C6	(0x93)
#define H4TAP105_C7	(0x1ED)
//-------------------------------------------------------------------------------------------------
//  Type and Structure
//-------------------------------------------------------------------------------------------------
/// Define GOP driver/hal layer return code, this enum should sync with E_GOP_API_Result
typedef enum
{
    GOP_FAIL                        = 0,
    GOP_SUCCESS                     = 1,
    GOP_NON_ALIGN_ADDRESS           ,
    GOP_NON_ALIGN_PITCH             ,
    GOP_DEPEND_NOAVAIL              ,
    GOP_MUTEX_OBTAIN_FAIL           ,
    GOP_MUTEX_OBTAINED              ,

    GOP_INVALID_BUFF_INFO          ,
    GOP_INVALID_PARAMETERS,
    GOP_FUN_NOT_SUPPORTED,
    GOP_ENUM_NOT_SUPPORTED,
    GOP_CRT_GWIN_FAIL               = 0xFE,
    GOP_CRT_GWIN_NOAVAIL            = 0xFF,
} GOP_Result;


/// Define GWIN color format.
typedef enum
{
    /// Color format RGB555 and Blink.
    E_DRV_GOP_COLOR_RGB555_BLINK    =E_MS_FMT_1ABFgBg12355,
    /// Color format RGB565.
    E_DRV_GOP_COLOR_RGB565          =E_MS_FMT_RGB565,
    /// Color format ARGB4444.
    E_DRV_GOP_COLOR_ARGB4444        =E_MS_FMT_ARGB4444,
    /// Color format alpha blink.
    E_DRV_GOP_COLOR_2266            =E_MS_FMT_FaBaFgBg2266,
    /// Color format I8 (256-entry palette).
    E_DRV_GOP_COLOR_I8              =E_MS_FMT_I8,
    /// Color format ARGB8888.
    E_DRV_GOP_COLOR_ARGB8888        =E_MS_FMT_ARGB8888,
    /// Color format ARGB1555.
    E_DRV_GOP_COLOR_ARGB1555        =E_MS_FMT_ARGB1555,
    /// Color format ARGB8888.  - Andriod format
    E_DRV_GOP_COLOR_ABGR8888        =E_MS_FMT_ABGR8888,
    /// Color format RGB555/YUV422.
    E_DRV_GOP_COLOR_RGB555YUV422    =E_MS_FMT_ARGB1555_DST,
    /// Color format YUV422.
    E_DRV_GOP_COLOR_YUV422          =E_MS_FMT_YUV422,
    /// Color format RGBA5551.  - Andriod format
    E_DRV_GOP_COLOR_RGBA5551        =E_MS_FMT_RGBA5551,
    /// Color format RGBA4444.  - Andriod format
    E_DRV_GOP_COLOR_RGBA4444        =E_MS_FMT_RGBA4444,
    /// Color format RGBA8888.    - Andriod Format
    E_DRV_GOP_COLOR_RGBA8888        =E_MS_FMT_RGBA8888,
    /// Color format BGR565.    - Andriod Format
    E_DRV_GOP_COLOR_BGR565          =E_MS_FMT_BGR565,
    /// Color format ABGR4444.    - Andriod Format
    E_DRV_GOP_COLOR_ABGR4444        =E_MS_FMT_ABGR4444,
    /// Color format AYUV8888.    - Andriod Format
    E_DRV_GOP_COLOR_AYUV8888        =E_MS_FMT_AYUV8888,
    /// Color format ABGR1555.    - Andriod Format
    E_DRV_GOP_COLOR_ABGR1555        =E_MS_FMT_ABGR1555,
    /// Color format BGRA5551.    - Andriod Format
    E_DRV_GOP_COLOR_BGRA5551        =E_MS_FMT_BGRA5551,
    /// Color format BGRA4444.    - Andriod Format
    E_DRV_GOP_COLOR_BGRA4444        =E_MS_FMT_BGRA4444,
    /// Color format BGRA8888.    - Andriod Format
    E_DRV_GOP_COLOR_BGRA8888        =E_MS_FMT_BGRA8888,

    /// Invalid color format.
    E_DRV_GOP_COLOR_INVALID         =E_MS_FMT_GENERIC
} DRV_GOPColorType;

typedef enum
{
    DRV_VALID_6BITS             =   0,
    DRV_VALID_8BITS             =   1,
    DRV_NONE_SETTING            =   2,
} DRV_GOP_CONSALPHA_BITS;

typedef enum
{
    E_DRV_3D_NONE               =   0, ///3D type: Not support
    E_DRV_3D_DUP_HALF           =   1, ///3D type: Support, but SW need expand GWIN and StretchWin
    E_DRV_3D_DUP_FULL           =   2, ///3D type: Support, and HW automatically expand GWIN and StretchWin
} EN_DRV_GOP_3D_TYPE;

/// Define Mux
typedef enum
{
    ///Select gop output to mux0
    E_GOP_MUX0 = 0,
    /// Select gop output to mux1
    E_GOP_MUX1 = 1,
    /// Select gop output to mux2
    E_GOP_MUX2 = 2,
    /// Select gop output to mux3
    E_GOP_MUX3 = 3,
    /// Select gop output to mux4
    E_GOP_MUX4 = 4,
    ///Select gop output to IP0
    E_GOP_IP0_MUX,
    /// Select gop output to IP1
    E_GOP_IP1_MUX,
    /// Select gop output to vop0
    E_GOP_VOP0_MUX,
    /// Select gop output to vop1
    E_GOP_VOP1_MUX,
    /// Select gop output to FRC mux0
    E_GOP_FRC_MUX0,
    /// Select gop output to FRC mux1
    E_GOP_FRC_MUX1,
    /// Select gop output to FRC mux2
    E_GOP_FRC_MUX2,
    /// Select gop output to FRC mux3
    E_GOP_FRC_MUX3,
    /// Select gop output to BYPASS mux
    E_GOP_BYPASS_MUX0,
    /// Select gop output to IP0_SUB
    E_GOP_IP0_SUB_MUX,
    /// Select gop output to VOP0_SUB
    E_GOP_VOP0_SUB_MUX,
    /// Select gop output to OP1
    E_GOP_OP1_MUX,
    /// Select gop output to DIP
    E_GOP_DIP_MUX,
    /// Select gop output to DIP
    E_GOP_GS_MUX,
    /// Select gop output to Mix layer0
    E_GOP_Mix_MUX0,
    /// Select gop output to Mix layer1
    E_GOP_Mix_MUX1,
    /// Select gop output to VE0
    E_GOP_VE0_MUX,
    /// Select gop output to VE1
    E_GOP_VE1_MUX,

    ///Select gop output to dual rate op mux0
    E_GOP_DUALRATE_OP_MUX0,
    ///Select gop output to dual rate op mux1
    E_GOP_DUALRATE_OP_MUX1,
    ///Select gop output to dual rate op mux2
    E_GOP_DUALRATE_OP_MUX2,

    MAX_GOP_MUX_SUPPORT,
    E_GOP_MUX_INVAILD,
} Gop_MuxSel;

/// Define GOP destination displayplane type
typedef enum
{
    E_DRV_GOP_DST_IP0       =   0,
    E_DRV_GOP_DST_IP0_SUB   =   1,
    E_DRV_GOP_DST_MIXER2VE  =   2,
    E_DRV_GOP_DST_OP0       =   3,
    E_DRV_GOP_DST_VOP       =   4,
    E_DRV_GOP_DST_IP1       =   5,
    E_DRV_GOP_DST_IP1_SUB   =   6,
    E_DRV_GOP_DST_MIXER2OP  =   7,
    E_DRV_GOP_DST_VOP_SUB   =   8,
    E_DRV_GOP_DST_FRC       =   9,
    E_DRV_GOP_DST_VE        =   10,
    E_DRV_GOP_DST_BYPASS    =   11,
    E_DRV_GOP_DST_OP1       =   12,
    E_DRV_GOP_DST_MIXER2OP1 =  13,
    E_DRV_GOP_DST_DIP       =   14,
    E_DRV_GOP_DST_GOPScaling  = 15,
    E_DRV_GOP_DST_OP_DUAL_RATE   = 16,
    MAX_DRV_GOP_DST_SUPPORT ,
    E_DRV_GOP_DST_INVALID  ,
} DRV_GOPDstType;

typedef enum
{
    E_DRV_BRI_SIGNBIT   =   0,
    E_DRV_BRI_2SCOMPLEMENT  =   1,
    E_DRV_BRI_MAX   =   2,
} EN_DRV_GOP_BRIG_INFO;

/// Define GOP chip property for different chip characteristic.
typedef struct __attribute__((packed))
{
    MS_BOOL bSetHSyncInverse;
    MS_BOOL bGop1GPalette;
    MS_BOOL bSetHPipeOfst;
    MS_BOOL bNeedCheckMVOP;
    MS_BOOL bNeedSetMUX1ToIP0;
    MS_BOOL bNeedSetMUX3ToIP0;
    MS_BOOL bNewMux;
    MS_BOOL bNewPalette;
    MS_BOOL bNewBwReg;
    MS_BOOL bGop2VStretch;
    MS_BOOL bIgnoreIPHPD;
    MS_BOOL bIgnoreIP1HPD;
    MS_BOOL bIgnoreVEHPD;
    MS_BOOL bhastilemode;
    MS_BOOL bInitNotEnableGOPToSC;
    MS_BOOL bXCDirrectBankSupport;
    MS_BOOL bTstPatternAlpha;
    MS_BOOL bFRCSupport;
    MS_BOOL bGOPMixerToVE;
    MS_BOOL bBnkForceWrite;
    MS_BOOL bPixelModeSupport;
    MS_BOOL bDWINSupport;
    MS_BOOL bScalingDownSupport;
    MS_BOOL b2Pto1PSupport;
    MS_BOOL bTLBSupport[GOP_MAX_SUPPORT_DEFAULT];
    MS_BOOL bInternalMIUSelect[GOP_INTERMIU_SEL_NUM];
    MS_BOOL bAFBC_Support[GOP_MAX_SUPPORT_DEFAULT];

    MS_BOOL bAutoAdjustMirrorHSize;
    MS_BOOL bGOPWithVscale[GOP_MAX_SUPPORT_DEFAULT];
    MS_BOOL bGOPWithScaleDown[GOP_MAX_SUPPORT_DEFAULT];

    MS_U16  GOP_TestPattern_Vaild;
    MS_U16 DwinVer;
    MS_S16 GOP_PD;
    MS_U16 GOP_IP_PD;
    MS_U16 GOP_MVOP_PD;
    MS_U16 GOP_VE_PD;
    MS_U16 GOP_OP1_PD;
    MS_U16 GOP_MIXER_PD;
    MS_U16 GOP_NonVS_PD_Offset;
    MS_U16 GOP_NonVS_DualOpPD_Offset;
    MS_U16 GOP_VE_V_Offset;
    MS_U16 GOP_HDR_OP_PD;
    MS_U16 GOP_DUAL_OP_PD;

    MS_U16 GOP_MUX_Delta;
    MS_U16 GOP_Mux_Offset[GOP_MAX_SUPPORT_DEFAULT];
    MS_U16 GOP_Zorder_Mux_Offset[GOP_MAX_SUPPORT_DEFAULT];
    Gop_MuxSel GOP_MapLayer2Mux[GOP_MAX_SUPPORT_DEFAULT];
    Gop_MuxSel GOP_MapLayer2DualOpMux[GOP_MAX_SUPPORT_DEFAULT];
    MS_U16 GOP_Mux_FRC_offset;
    MS_U16 GOP_DualRateMux_Offset[GOP_MAX_SUPPORT_DEFAULT];
    MS_U16 GOP_REF_POSITION_X;

    MS_U16 WordUnit;
    MS_U16 TotalGwinNum;
    DRV_GOP_CONSALPHA_BITS Default_ConsAlpha_bits;
    EN_DRV_GOP_3D_TYPE enGOP3DType;
    MS_BOOL bOpInterlace;

    MS_BOOL bAFBCMIUSelDoubleBuffer;
    MS_BOOL bAFBC_Merge_GOP_Trig;
    MS_BOOL bGOPVscalePipeDelay[GOP_MAX_SUPPORT_DEFAULT];
    MS_BOOL bGOPNeedSplitMode4DualRate[GOP_MAX_SUPPORT_DEFAULT];
    MS_BOOL bOPHandShakeModeSupport;
    MS_BOOL bOPMuxDoubleBuffer;
    MS_BOOL bGOPAutoClkGating;
    MS_BOOL bH4tap256Phase;
    MS_BOOL bV4tap256Phase;
    MS_BOOL bSupportMixerSDR2HDR;
    MS_BOOL bSupporBrightness3Chan;
    MS_BOOL bSupportContrast;
    MS_BOOL bSupportV4tap[GOP_MAX_SUPPORT_DEFAULT];
    MS_BOOL bSupportV_BiLinear[GOP_MAX_SUPPORT_DEFAULT];
    MS_BOOL bSupportVOPPathSel;
    MS_U16 u16BefRGB3DLupPDOffset;
    MS_U16 u16BefPQGammaPDOffset;
    MS_U16 u16AftPQGammaPDOffset;
    EN_DRV_GOP_BRIG_INFO enBrightnessInfo;
    MS_BOOL bSupportCSCTuning;
    MS_BOOL bSupportXC2DMenuLoad;
    MS_BOOL bSupportH6Tap_8Phase[GOP_MAX_SUPPORT_DEFAULT];
    MS_BOOL bSupportHDuplicate[GOP_MAX_SUPPORT_DEFAULT];
    MS_BOOL bSupportH4Tap_256Phase[GOP_MAX_SUPPORT_DEFAULT];
    MS_BOOL bAutoDetectVersion_1_0[SHARED_GOP_MAX_COUNT];
    MS_BOOL bUse3x3MartixCSC;
    MS_BOOL bAutoDetectVersion_2_0[SHARED_GOP_MAX_COUNT];
    MS_BOOL bSupportV2tap_16Phase[GOP_MAX_SUPPORT_DEFAULT];
    MS_BOOL b120HzDstOP;
    MS_BOOL bSupportTwoLineBuffer[GOP_MAX_SUPPORT_DEFAULT];
    MS_BOOL bSupportTrigBit;
    MS_BOOL bSupportCSCDoubleBuffer;
	MS_U16 TotalGOPNum;
}GOP_CHIP_PROPERTY;

/// GOP0 gwin priority
typedef struct DLL_PACKED
{
    MS_U8 u81stGwin;
    MS_U8 u82stGwin;
    MS_U8 u83stGwin;
    MS_U8 u84stGwin;
}GOP0_GwinPri;

// GOP0/GOP1 gwin priority
typedef struct DLL_PACKED
{
    GOP0_GwinPri Gop0_GwinPri;
    MS_U8 Gop1_1stGwin  :1;
}GOP_GwinPriority;

/// GWIN Information
typedef struct DLL_PACKED
{
    MS_U16 u16DispVPixelStart;      //!< unit: pix
    MS_U16 u16DispVPixelEnd;        //!< unit: pix
    MS_U16 u16DispHPixelStart;      //!< unit: pix
    MS_U16 u16DispHPixelEnd;        //!< unit: pix
    MS_PHY u64DRAMRBlkStart;        //!< unit: Byte
    MS_U16 u16RBlkHPixSize;     //!< unit: pix
    MS_U16 u16RBlkVPixSize;     //!< unit: pix
    MS_U16 u16RBlkHRblkSize;       //!< unit: Byte
    MS_U16 u16WinX;             //!< unit: pix
    MS_U16 u16WinY;             //!< unit: pix
    MS_U32 u32scrX;             //!< unit: pix
    MS_U32 u32scrY;             //!< unit: pix
    DRV_GOPColorType clrType;       //!< color format of the buffer
} DRV_GOP_GWIN_INFO;

/// Dump Window Information
typedef struct DLL_PACKED
{
    MS_U16 u16VPixelStart;      //!< unit: pix
    MS_U16 u16VPixelEnd;        //!< unit: pix
    MS_U16 u16HPixelStart;      //!< unit: pix
    MS_U16 u16HPixelEnd;        //!< unit: pix
    MS_PHY u64TFDRAMAddr;       //!< unit: Byte
    MS_PHY u64BFDRAMAddr;       //!< unit: Byte
    MS_U16 u16DRAMJumpLen;      //!< unit: Byte
    MS_U8 u8fmt;                //!< DWIN format: 0 UV7Y8, 1 UV8Y8, 2 ARGB8888, 3 RGB565
} DRV_GOP_DWIN_INFO;

/// DWIN propert
typedef struct DLL_PACKED
{
    MS_U16 u16x;           ///< x
    MS_U16 u16y;           ///< y
    MS_U16 u16w;           ///< width
    MS_U16 u16h;           ///< height
    MS_PHY u64fbaddr0;     ///< Top field DRAM address
    MS_PHY u64fbaddr1;     ///< Bottom field DRAM address
    MS_U16 u16fbw;         ///< Number of bytes per horizontal line
} DRV_GOP_DwinProperty;

typedef union DLL_PACKED
{
    MS_U8 u8DWinIntInfo;
    struct DLL_PACKED
    {
        MS_U8 bDWinIntWADR:1;
        MS_U8 bDWinIntPROG:1;
        MS_U8 bDWinIntTF:1;
        MS_U8 bDWinIntBF:1;
        MS_U8 bDWinIntVS:1;
        MS_U8 reserved:3;
    }sDwinIntInfo;
} DRV_GOP_DWinIntInfo;

/// Frame buffer attributes for GWIN
typedef struct DLL_PACKED
{
    MS_U8 gWinId;          ///< id
    MS_U8 enable:1;        ///< 4bits enable
    MS_U8 allocated:1;    ///< 4bits

    MS_U16 x0;                 ///< MS_U16
    MS_U16 y0;                 ///< MS_U16
    MS_U16 x1;                 ///< MS_U16
    MS_U16 y1;                 ///< MS_U16
    MS_U16 width;                 ///< MS_U16
    MS_U16 height;                 ///< MS_U16
    MS_U16 pitch;                    ///< MS_U16
    MS_U16 fbFmt;                 ///< MS_U16

    MS_PHY phyAddr;                     ///< MS_U32
    MS_U32 size;                     ///< MS_U32

    MS_U8 next;                 ///< MS_U8
    MS_U8 prev;                  ///< MS_U8
    MS_U8 string;               //store which AP use this FB
    //MS_U8 flag;                ///< bit 0:scroll
    MS_U16 s_x;                ///< MS_U16
    MS_U16 s_y;                ///< MS_U16
    MS_U16 dispWidth;          ///< MS_U16
    MS_U16 dispHeight;         ///< MS_U16
} DRV_Gwin_FB_Attr;

/// OC Info
typedef struct DLL_PACKED
{
    MS_PHY u64GOP_OC_DRAM_RBLK;         ///Bytes
    MS_PHY u64GOP_OC_ADDRPROTECT_STR;   ///Bytes
    MS_PHY u64GOP_OC_ADDRPROTECT_END;   ///Bytes
    MS_U32 u32GOP_OC_FETCH;
    MS_U16 u16GOP_OC_HSIZE;
    MS_U16 u16GOP_OC_VSIZE;
    MS_BOOL bGOP_OC_MIUID;
    MS_U8 u8GOP_OC_BANK_MODE;
} DRV_GOP_OC_INFO;

/// GWIN output color domain
typedef enum
{
    DRV_GOPOUT_RGB,     ///< 0: output color RGB
    DRV_GOPOUT_YUV,     ///< 1: output color YUV
} GOP_OupputColor;

/// Transparent color format
typedef enum
{
    DRV_GOPTRANSCLR_FMT0,   //!< RGB mode transparent color
    DRV_GOPTRANSCLR_FMT1,   //!< index mode transparent color
    DRV_GOPTRANSCLR_FMT2,   //!< ARGB 8888 transparent color
    DRV_GOPTRANSCLR_FMT3,   //!< YUV mode transparent color
} GOP_TransClrFmt;

/// Define Scaler GOP IP setting.
typedef enum
{
    MS_DRV_IP0_SEL_GOP0,
    MS_DRV_IP0_SEL_GOP1,
    MS_DRV_IP0_SEL_GOP2,
    MS_DRV_NIP_SEL_GOP0,
    MS_DRV_NIP_SEL_GOP1,
    MS_DRV_NIP_SEL_GOP2,
    MS_DRV_MVOP_SEL,
    MS_DRV_SUBMVOP_SEL,
    MS_DRV_IP1_SEL,
    MS_DRV_SUBIP0_SEL,
    MS_DRV_SC1OP_SEL,
    MS_DRV_DIP_SEL,
}MS_IPSEL_GOP;

typedef enum
{
    E_DRV_MIXER_DST_IP       =   0,
    E_DRV_MIXER_DST_MIXER    =   1,
    E_DRV_MIXER_DST_OP       =   2,
    E_DRV_MIXER_DST_VE       =   3,
    E_DRV_MIXER_DST_OP1      =   4,
    MAX_DRV_MIXER_DST_SUPPORT      ,
    E_DRV_MIXER_DST_INVALID   =   0xFF,
} DRV_MixerDstType;

/// Define GOP H-Stretch mode.
typedef enum
{
    E_DRV_GOP_HSTRCH_6TAPE = 0,
    E_DRV_GOP_HSTRCH_DUPLICATE = 1,
    E_DRV_GOP_HSTRCH_6TAPE_LINEAR  = 2,
    E_DRV_GOP_HSTRCH_6TAPE_NEAREST = 3,
    E_DRV_GOP_HSTRCH_6TAPE_GAIN0   = 4,
    E_DRV_GOP_HSTRCH_6TAPE_GAIN1   = 5,
    E_DRV_GOP_HSTRCH_6TAPE_GAIN2   = 6,
    E_DRV_GOP_HSTRCH_6TAPE_GAIN3   = 7,
    E_DRV_GOP_HSTRCH_6TAPE_GAIN4   = 8,
    E_DRV_GOP_HSTRCH_6TAPE_GAIN5   = 9,
    E_DRV_GOP_HSTRCH_4TAPE         = 0xA,
    E_DRV_GOP_HSTRCH_2TAPE         = 0xB,
    E_DRV_GOP_HSTRCH_NEW4TAP_45    = 0xC,
    E_DRV_GOP_HSTRCH_NEW4TAP_50    = 0xD,
    E_DRV_GOP_HSTRCH_NEW4TAP_55    = 0xE,
    E_DRV_GOP_HSTRCH_NEW4TAP_65    = 0xF,
    E_DRV_GOP_HSTRCH_NEW4TAP_75    = 0x10,
    E_DRV_GOP_HSTRCH_NEW4TAP_85    = 0x11,
    E_DRV_GOP_HSTRCH_NEW4TAP_95    = 0x12,
    E_DRV_GOP_HSTRCH_NEW4TAP_105   = 0x13,
    E_DRV_GOP_HSTRCH_NEW4TAP_100   = 0x14,
    E_DRV_GOP_HSTRCH_NEW4TAP_105_GAIN22 = 0x15,
    E_DRV_GOP_HSTRCH_NEW4TAP_105_GAIN31 = 0x16,
    E_DRV_GOP_HSTRCH_NEW4TAP_105_GAIN16 = 0x17,
    E_DRV_GOP_HSTRCH_NEW4TAP_105_GAIN17 = 0x18,
    MAX_GOP_HSTRETCH_MODE_SUPPORT,
} DRV_GOPStrchHMode;

/// Define GOP V-Stretch mode.
typedef enum
{
    E_DRV_GOP_VSTRCH_LINEAR = 0,
    E_DRV_GOP_VSTRCH_DUPLICATE = 1,
    E_DRV_GOP_VSTRCH_NEAREST = 2,
    E_DRV_GOP_VSTRCH_LINEAR_GAIN0 = 3,
    E_DRV_GOP_VSTRCH_LINEAR_GAIN1 = 4,
    E_DRV_GOP_VSTRCH_LINEAR_GAIN2 = 5,
    E_DRV_GOP_VSTRCH_4TAP = 6,
    E_DRV_GOP_HSTRCH_V4TAP_100   = 7,
    E_DRV_GOP_VSTRCH_V4TAP_105_GAIN22 = 8,
    E_DRV_GOP_VSTRCH_V4TAP_105_GAIN31 = 9,
    E_DRV_GOP_VSTRCH_V4TAP_105_GAIN16 = 0xA,
    E_DRV_GOP_VSTRCH_V4TAP_105_GAIN17 = 0xB,
    MAX_GOP_VSTRETCH_MODE_SUPPORT,
} DRV_GOPStrchVMode;

/// Define GOP Transparent color Stretch mode.
typedef enum
{
    E_DRV_GOP_TRANSPCOLOR_STRCH_DUPLICATE = 0,
    E_DRV_GOP_TRANSPCOLOR_STRCH_ASNORMAL = 1,
    MAX_GOP_TRANSPCOLOR_STRETCH_MODE_SUPPORT,
} DRV_GOPSTRCH_TRANSPCOLORMODE;

/// Define palette read type.
typedef enum
{
    /// Palette access from GOP0 RIU
    E_DRV_GOP_PAL_GOP_RIU    = 0,
    /// Palette access from GOP0 REGDMA
    E_DRV_GOP_PAL_GOP_REGDMA  = 1,
    /// Palette access from GOP1 RIU
    E_DRV_GOP1_PAL_GOP_RIU    = 2,
    /// Palette access from GOP1 REGDMA
    E_DRV_GOP1_PAL_GOP_REGDMA  = 3,
} DRV_GopPalReadType;

/// Scroll direction
typedef enum
{
    GOP_DRV_SCROLL_NONE = 0,
    GOP_DRV_SCROLL_UP,      // bottom to top
    GOP_DRV_SCROLL_DOWN,    // top to bottom
    GOP_DRV_SCROLL_LEFT,            //right to left
    GOP_DRV_SCROLL_RIGHT,   //left to right
    GOP_DRV_SCROLL_SW,          // Scroll by sw
    GOP_DRV_SCROLL_KERNEL,      // Scroll by sw on kernel
    GOP_DRV_SCROLL_MAX,
} E_GOP_SCROLL_TYPE;

/// DWIN capture data source
typedef enum
{
    GOPDWIN_DATA_SRC_SCALAR,    //!< scaler output
    GOPDWIN_DATA_SRC_EXTRGB,        //!< External, RGB, YUV(pass R2Y)
    GOPDWIN_DATA_SRC_VOP,       //!< DVB VOP (MVOP)
    GOPDWIN_DATA_SRC_MAX
} EN_GOP_DWIN_DATA_SRC;

/// DWIN scan mode
typedef enum
{
    GOPDWIN_SCAN_MODE_PROGRESSIVE,  ///< Progressive scan
    GOPDWIN_SCAN_MODE_INTERLACE,  ///< Interlace scan
    GOPDWIN_SCAN_MODE_MAX
} EN_GOP_DWIN_SCAN_TYPE;

/// DWIN source selection
typedef enum
{
    /// DWIN OP source
    GOP_DRV_DWIN_SRC_OP = 0,
    /// DWIN MVOP source
    GOP_DRV_DWIN_SRC_MVOP = 1,
    /// DWIN IP source
    GOP_DRV_DWIN_SRC_IP = 2,
    /// DWIN OP1 source
    GOP_DRV_DWIN_SRC_OP1 =3,
    /// DWIN SUB MVOP source
    GOP_DRV_DWIN_SRC_SUBMVOP =4,
    /// DWIN GOPScaling source
    GOP_DRV_DWIN_SRC_GOPScaling =5,
    GOP_DRV_DWIN_SRC_MAX = 6
}DRV_GOP_DWIN_SRC_SEL;

/// DWIN source data format
typedef enum
{
    GOPDWIN_DATA_FMT_UV7Y8 = 0,     //!< CrYCb domain
    GOPDWIN_DATA_FMT_UV8Y8,         //!< CrYCb domain
    GOPDWIN_DATA_FMT_ARGB8888,      //!< RGB domain (CSC bypass)
    GOPDWIN_DATA_FMT_RGB565,        //!< RGB domain (CSC bypass)
    GOPDWIN_DATA_FMT_MAX
} DRV_GOP_DWIN_DATA_FMT;

/// Define palette color format.
typedef enum
{
    /// Palette color format is RGB888.
    E_DRV_GOP_PAL_ARGB8888    = 0,
    /// Invalid palette color format.
    E_DRV_GOP_PAL_INVALID
} DRV_GopPalType;

/// Define GOP gwin fade in/out.
typedef enum
{
    /// GOP gwin fade in.
    E_DRV_GOP_GWIN_FADE_IN,
    /// GOP gwin fade out.
    E_DRV_GOP_GWIN_FADE_OUT,
    /// GOP gwin fade unknow type.
    E_DRV_GOP_GWIN_FADE_UNKNOWN,
} DRV_GOP_FADE_TYPE;

//----------------------------------------------------------------------------
// GOP Reg Page Form
//----------------------------------------------------------------------------
typedef enum
{
    E_GOP_REG_FORM_4G   = 0x0000,
    E_GOP_REG_FORM_T21G = 0x0001,
    E_GOP_REG_FORM_2G   = 0x0002,
    E_GOP_REG_FORM_T81G = 0x0003,
    E_GOP_REG_FORM_U42G = 0x0004,
    E_GOP_REG_FORM_NONE = 0x000F,
    E_GOP_REG_FORM_MASK = 0x000F,
}   E_GOP_REG_FORM;

typedef enum
{
    E_GOPD_FIFO_DEPTH_64   = 0x0000,
    E_GOPD_FIFO_DEPTH_128  = 0x0010,
    E_GOPD_FIFO_DEPTH_256  = 0x0020,
    E_GOPD_FIFO_DEPTH_MASK = 0x00F0,
}   E_GOPD_FIFO_DEPTH;

// GOP palette type
typedef enum
{
    E_GOP_PAL_SIZE_NONE = 0x0000,
    E_GOP_PAL_SIZE_256  = 0x0100,
    E_GOP_PAL_SIZE_64   = 0x0200,
    E_GOP_PAL_SIZE_MASK = 0x0F00,
}   E_GOP_PAL_SIZE;

/// GOP VE timing type
typedef enum
{
    E_GOP_VE_NTSC ,
    E_GOP_VE_PAL,
    E_GOP_VE_TIMEING_MAX,
}E_GOP_VE_TIMINGTYPE;

/// GOP MIXER timing type
typedef enum
{
    E_GOP_NTSC ,
    E_GOP_PAL,
    E_GOP_CUSTOM,
    E_GOP_CUSTOM_OP,
    E_GOP_MIXER_TIMEING_MAX,
}E_GOP_MIXER_TIMINGTYPE;

/// video timing mirror type
typedef enum
{
    E_GOP_VIDEOTIMING_MIRROR_BYSCALER,
    E_GOP_VIDEOTIMING_MIRROR_BYMVOP,
    E_GOP_VIDEOTIMING_MIRROR_MAX,
}E_GOP_VIDEOTIMING_MIRRORTYPE;


/// Define GOP burst length.
typedef enum
{
    /// burst length: long
    E_GOP_BURSTLEN_LONG,
    /// burst length: middle
    E_GOP_BURSTLEN_MIDDLE,
    /// burst length: short
    E_GOP_BURSTLEN_SHORT,
} EN_GOP_BURST_LEN;

/// Define GOP G3D DATA FORMAT.
typedef enum
{
    /// E_GOP_TILE_DATA_16BPP. 16 BPP DATA FOR TILE MODE
    E_DRV_GOP_TILE_DATA_16BPP    = 0,
    /// E_GOP_TILE_DATA_16BPP. 32 BPP DATA FOR TILE MODE
    E_DRV_GOP_TILE_DATA_32BPP    = 1,
} E_GOP_TILE_DATA_TYPE;

/// Define GOP MIU SEL
typedef enum
{
    /// E_DRV_GOP_SEL_MIU0. gop access miu 0
    E_DRV_GOP_SEL_MIU0    = 0,
    /// E_GOP_SEL_MIU1. gop access miu1
    E_DRV_GOP_SEL_MIU1    = 1,
    /// E_GOP_SEL_MIU2. gop access miu2
    E_DRV_GOP_SEL_MIU2    = 2,
    /// E_GOP_SEL_MIU3. gop access miu3
    E_DRV_GOP_SEL_MIU3    = 3,
} E_DRV_GOP_SEL_TYPE;

/// Define GOP PINPON Mode
typedef enum
{
    /// E_DRV_GOP_PINPON_G3D. gop set g3d pinpon
    E_DRV_GOP_PINPON_G3D    = 0,
    /// E_DRV_GOP_PINPON_VE. gop set ve pinpon
    E_DRV_GOP_PINPON_VE     = 1,
    /// E_DRV_GOP_PINPON_DWIN. gop set dwin pinpon
    E_DRV_GOP_PINPON_DWIN   = 2,
    /// E_DRV_GOP_PINPON_DIP. gop set dwin pinpon
    E_DRV_GOP_PINPON_DIP   = 3,
    /// E_DRV_GOP_PINPON_DWIN0. gop set dwin pinpon
    E_DRV_GOP_PINPON_DWIN0   = 4,
    /// E_DRV_GOP_PINPON_DWIN1. gop set dwin pinpon
    E_DRV_GOP_PINPON_DWIN1   = 5,

} E_DRV_GOP_PINPON_MODE;



/// Define the entry of palette.
typedef union DLL_PACKED
{
    /// ARGB888
    struct DLL_PACKED
    {
        MS_U8 u8A;
        MS_U8 u8R;
        MS_U8 u8G;
        MS_U8 u8B;
    } RGB;
    /// 32-bit direct access.
    MS_U8 u8Data[4];
} DRV_GopPaletteEntry;

typedef enum
{
   GOP_WINFB_POOL_NULL = 0,
   GOP_WINFB_POOL1 = 1,
   GOP_WINFB_POOL2= 2
}GOP_FBPOOL_ID;

typedef enum
{
    E_DRV_GOP_AFBC_SPILT            =0x1,
    E_DRV_GOP_AFBC_YUV_TRANSFER	    =0x2,
    E_DRV_GOP_AFBC_ARGB8888         =0x4,
    E_DRV_GOP_AFBC_RGB565           =0x8,
    E_DRV_GOP_AFBC_RGB888           =0x10,
    E_DRV_GOP_AFBC_MAX,
}EN_DRV_GOP_AFBC_CNTL;

/// Define GOP FB string.
typedef enum
{
    E_DRV_GOP_FB_NULL,
    /// OSD frame buffer.
    E_DRV_GOP_FB_OSD,
    /// Mute frame buffer.
    E_DRV_GOP_FB_MUTE,
    /// subtitle frame buffer.
    E_DRV_GOP_FB_SUBTITLE,
    /// teltext frame buffer.
    E_DRV_GOP_FB_TELTEXT,
    /// MHEG5 frame buffer.
    E_DRV_GOP_FB_MHEG5,
    /// CC frame buffer.
    E_DRV_GOP_FB_CLOSEDCAPTION,
    /// AFBC frame buffer.
    E_DRV_GOP_FB_AFBC_SPLT_YUVTRNSFER_ARGB8888 = 0x100,
    E_DRV_GOP_FB_AFBC_NONSPLT_YUVTRS_ARGB8888,
    E_DRV_GOP_FB_AFBC_SPLT_NONYUVTRS_ARGB8888,
    E_DRV_GOP_FB_AFBC_NONSPLT_NONYUVTRS_ARGB8888,
    E_DRV_GOP_FB_AFBC_V1P2_ARGB8888,   //v1.2
    E_DRV_GOP_FB_AFBC_V1P2_RGB565,     //v1.2
    E_DRV_GOP_FB_AFBC_V1P2_RGB888,     //v1.2
} EN_DRV_FRAMEBUFFER_STRING;

/// Frame buffer attributes for GWIN
typedef struct __attribute__((packed))
{
    MS_PHY addr;                     ///< MS_U64  /*For 32/64 share memory align*/
    MS_U32 size;                     ///< MS_U32
    MS_U32 nextFBIdInPool;           ///next winId in same pool

    MS_U16 x0;                 ///< MS_U16
    MS_U16 y0;                 ///< MS_U16
    MS_U16 x1;                 ///< MS_U16
    MS_U16 y1;                 ///< MS_U16
    MS_U16 width;                 ///< MS_U16
    MS_U16 height;                 ///< MS_U16
    MS_U16 pitch;                     ///< MS_U16
    MS_U16 fbFmt;                 ///< MS_U16

    MS_U16 s_x;                ///< MS_U16
    MS_U16 s_y;                ///< MS_U16
    MS_U16 dispWidth;          ///< MS_U16
    MS_U16 dispHeight;         ///< MS_U16

    GOP_FBPOOL_ID poolId;

    MS_U8 gWinId;
    MS_U8 string;               ///store which AP use this FB
    MS_U8 enable:1;
    MS_U8 in_use:1;
    MS_U32 u32GOPClientId;     ///<<store Client ID of using this FB
    MS_U8 obtain;
    EN_DRV_FRAMEBUFFER_STRING FBString;
} GOP_WinFB_INFO;

typedef struct __attribute__((packed))
{
   MS_U32 PalSWArray[GOP_PALETTE_ENTRY_NUM_MAX];
}GOP_Palette_INFO;

typedef struct __attribute__((packed))
{
   GOP_FBPOOL_ID poolId;
   MS_PHY GWinFB_Pool_BaseAddr;
   MS_U32 u32GWinFB_Pool_MemLen;
   MS_U32 u32FirstFBIdInPool;
}GOP_FB_POOL;

typedef struct __attribute__((packed))
{
    MS_U32 u32GOPClientId;
    MS_U32 u32CurFBId;
    MS_U16 u16SharedCnt;
    MS_BOOL bIsShared;
}GWIN_MAP;

typedef struct DLL_PACKED
{
    MS_PHY u64NonMirrorFBAdr;
    MS_U16 u16NonMirrorHStr;
    MS_U16 u16NonMirrorHEnd;
    MS_U16 u16NonMirrorVStr;
    MS_U16 u16NonMirrorVEnd;
    MS_U16 u16NonMirrorGOP0WinX;
    MS_U16 u16NonMirrorGOP0WinY;
}GOP_GwinMirror_Info;

///the GOP MIXER timing info
typedef struct DLL_PACKED
{
    MS_U32 hstart;
    MS_U32 hend;
    MS_U32 vstart;
    MS_U32 vend;
    MS_U32 htotal;
    MS_U32 hsyncdelay;
}GOP_DRV_MixerTiming;

///GOP Ignore init value
typedef enum
{
    E_DRV_GOP_MUX_IGNORE              =   0x0001,
    E_DRV_GOP_GWIN_IGNORE             =   0x0002,
    E_DRV_GOP_STRETCHWIN_IGNORE       =   0x0004,
    E_DRV_GOP_PALETTE_IGNORE          =   0x0008,
    E_DRV_GOP_SET_DST_OP_IGNORE       =   0x0010,
    E_DRV_GOP_ENABLE_TRANSCLR_IGNORE  =   0x0020,
    E_DRV_GOP_BOOTLOGO_VEOSDEN_IGNORE =   0x0040,
    E_DRV_GOP_ALL_IGNORE              =   0xFFFF,
    E_DRV_GOP_IGNORE_DISABLE          =   0x0000,
} DRV_GOP_IGNOREINIT;

///the GOP config
typedef struct DLL_PACKED
{
  DRV_GOP_IGNOREINIT eGopIgnoreInit;
}GOP_Config;

typedef struct __attribute__((packed))
{
        MS_U32 u32ClientIdAllocator;
        MS_U32 u32LstGOPClientId;
        MS_U16 u16PnlWidth[SHARED_GOP_MAX_COUNT];
        MS_U16 u16PnlHeight[SHARED_GOP_MAX_COUNT];
        MS_U16 u16PnlHStr[SHARED_GOP_MAX_COUNT];
        MS_BOOL bHMirror;
        MS_BOOL bVMirror;
        MS_BOOL b16TileMode[SHARED_GOP_MAX_COUNT];
        MS_BOOL b32TileMode[SHARED_GOP_MAX_COUNT];
        MS_U16  ScrollBufNum;
        MS_U16  ScrollBufIdx;
        MS_U32  ScrollBuffer[MAX_GOP_SW_SCROLLNUM];

        GWIN_MAP gwinMap[SHARED_GWIN_MAX_COUNT];

        GOP_FB_POOL fbPool1;
        GOP_FB_POOL fbPool2;
        GOP_FBPOOL_ID fb_currentPoolId;

        MS_S32 s32OutputColorType[SHARED_GOP_MAX_COUNT];
        MS_BOOL bGopHasInitialized[SHARED_GOP_MAX_COUNT];
        MS_BOOL bGWINEnable[SHARED_GWIN_MAX_COUNT];
#if WINFB_INSHARED
        GOP_WinFB_INFO winFB[DRV_MAX_GWIN_FB_SUPPORT+1];
#endif
        MS_U8 GOP_StereoMode[SHARED_GOP_MAX_COUNT];
        MS_U16 u16APIStretchWidth[SHARED_GOP_MAX_COUNT]; //Store API set stretch win width(May Not sync with HW register in GOP 3D SBS mode)
        MS_U16 u16APIStretchHeight[SHARED_GOP_MAX_COUNT];
        MS_U8 GOP_TestPatternMode;
        MS_BOOL bGOP3DLRSwitch[SHARED_GOP_MAX_COUNT]; //GOP 3D L/R Switch flag
        MS_U16 u16HScaleSrc[SHARED_GOP_MAX_COUNT];
        MS_U16 u16HScaleDst[SHARED_GOP_MAX_COUNT];
        MS_U16 u16VScaleDst[SHARED_GOP_MAX_COUNT];
        MS_BOOL bPixelMode[SHARED_GOP_MAX_COUNT];
        MS_BOOL bInitShared;
        MS_BOOL bDummyInit;//TRUE: the gop init's input parameter is NULL when SHM is firstly initialized
        MS_BOOL bEnableVsyncIntFlip;
        MS_S32 s32GOPLockTid;
        MS_U32  GOPLockPid;
        MS_BOOL bTLB[SHARED_GOP_MAX_COUNT];
        MS_PHY  u64TLBAddress[SHARED_GOP_MAX_COUNT];
        GOP_Palette_INFO GOPPaletteInfo[SHARED_GOP_MAX_COUNT];
#ifdef CONFIG_MSTAR_SRAMPD
        MS_BOOL bGOPPowerDown[SHARED_GOP_MAX_COUNT];
#endif
        MS_PHY phyGOPRegdmaAdr;
        MS_U32 u32GOPRegdmaLen;
        MS_S32 s32GOPStretchWinHOffset;
        MS_S32 s32GOPStretchWinVOffset;
        MS_U16 u16OrgOPmuxInfo;
        MS_U16 u16OrgOSDBInfo[SHARED_GOP_MAX_COUNT];
        ST_GOP_CSC_PARAM stCSCParam[SHARED_GOP_MAX_COUNT];
        ST_GOP_CSC_TABLE stCSCTable[SHARED_GOP_MAX_COUNT];
        MS_S32 s32PixelShiftPDOffset;
} MS_GOP_CTX_SHARED;

typedef struct DLL_PACKED
{
    MS_GOP_CTX_SHARED *pGOPCtxShared;//pointer to shared context paramemetrs;
    GOP_CHIP_PROPERTY *pGopChipProperty;
    DRV_GOP_CONSALPHA_BITS *pGopConsAlphaBits;
    GOP_Config sGOPConfig;  //GOP configs set for special cases
    MS_U32 u32GOPClientId;
#if GOP_LOCK_SUPPORT
    MS_S32      s32GOPMutex;
    MS_S32      s32GOPLock;
    MS_S32      s32GOPMutexCnt;
#endif
#if GOP_XC_LOCK_SUPPORT
    MS_S32      s32GOPXC_Mutex;
    MS_S32      s32GOPXC_Lock;
    MS_S32      s32GOPXC_MutexCnt;
#endif
    //for local GWIN memory pool

#if WINFB_INSHARED
    //GOP_WinFB_INFO winFB[MAX_GWIN_FB_SUPPORT+1]; //move to MS_GOP_CTX_SHARED
#else
    GOP_WinFB_INFO winFB[DRV_MAX_GWIN_FB_SUPPORT+1];
#endif
    MS_U8 current_winId;


    MS_BOOL Gwin_H_Dup, Gwin_V_Dup;
    MS_U16 u16GOP_HMirrorRBLK_Adr;   //Consider 16Gwins totally
    MS_U16 u16GOP_VMirrorRBLK_Adr;   //Consider 16Gwins totally
    MS_U16 u16GOP_HMirror_HPos;      //Consider 16Gwins totally
    MS_U16 u16GOP_VMirror_VPos;      //Consider 16Gwins totally

    GOP_GwinMirror_Info sMirrorInfo[SHARED_GWIN_MAX_COUNT];
    MS_U8 MS_MuxGop[MAX_GOP_MUX_SUPPORT];
    MS_U8 u8ChgIpMuxGop;
    MS_BOOL IsChgMux;
    MS_BOOL IsClkClosed;
    MS_BOOL bUpdateRegOnce[SHARED_GOP_MAX_COUNT];
#ifdef CONFIG_GOP_TEST_PATTERN
    MS_U16 GOPBnk[SHARED_GOP_MAX_COUNT][GOP_REG_MAX];
    MS_U16 GWINBnk[SHARED_GOP_MAX_COUNT][GOP_REG_MAX];
    MS_U16 GOPStBnk[SHARED_GOP_MAX_COUNT][GOP_REG_MAX];
#endif
    MS_U16 GOP_FramePacking_Gap;
    MS_U16 u16GOPGWinMiddle[SHARED_GOP_MAX_COUNT];

    MS_BOOL bInitFWR;
}MS_GOP_CTX_LOCAL;

typedef struct DLL_PACKED
{
    MS_BOOL bEnable; //InOut
    MS_U8   u8FrameCount; //Out, value range: 0~3
    MS_U8   u8Result; //Out
}MS_DRVGOP_VECAPTURESTATE, *PMS_DRVGOP_VECAPTURESTATE;


//3D OSD mode type
typedef enum
{
    E_DRV_GOP_3D_DISABLE ,
    E_DRV_GOP_3D_SWITH_BY_FRAME,
    E_DRV_GOP_3D_SIDE_BY_SYDE,
    E_DRV_GOP_3D_TOP_BOTTOM,
    E_DRV_GOP_3D_LINE_ALTERNATIVE,
    E_DRV_GOP_3D_LINE_FRAMEPACKING,
}EN_DRV_GOP_3D_MODE;

typedef enum
{
    E_DRV_GOP_Deldirect_Front ,
    E_DRV_GOP_Deldirect_Back,
}E_DRV_GOP_DelDirect;


typedef enum
{
    E_DRV_GOP_MAIN_WINDOW=0,          ///< main window if with PIP or without PIP
    E_DRV_GOP_SUB_WINDOW=1,           ///< sub window if PIP
    E_DRV_GOP_MAX_WINDOW              /// The max support window
}E_DRV_GOP_SCALER_WIN;

typedef enum
{
    E_DRV_GOP_RBLKAddr,
    E_DRV_GOP_DRAMVstr,
    E_DRV_GOP_RBLKSize,
    E_DRV_GOP_ScrollHVStopAddr,
    E_DRV_GOP_RBLK3DAddr
}E_DRV_GOP_AddrType;


///Dwin Capability of IC
typedef struct DLL_PACKED
{
    MS_BOOL bSupportWindowDECapture; //TRUE: Support it; FALSE:Not support, should use FrameDE to capture video
    MS_BOOL bSupportOSDCapture;      //TRUE: Support it; FALSE:Not support
}DRV_GOP_DWIN_CAP, *PDRV_GOP_DWIN_CAP;

///GOP MUX Caps
typedef struct DLL_PACKED
{
    MS_U8 u8MuxNumber;
    MS_U8 *pu8MuxProrityArray;
    MS_BOOL bNewMux;
    MS_BOOL bNeedSetMUX1ToIP0;
    MS_BOOL bNeedSetMUX3ToIP0;
}ST_DRV_GOP_MUX_CAP, *PST_DRV_GOP_MUX_CAP;

///GOP MUX Caps
typedef struct
{
    MS_U8 u8MuxNumber;
    MS_U8 pu8MuxProrityArray[MAX_GOP_INFO_COUNT];
    MS_BOOL bNewMux;
    MS_BOOL bNeedSetMUX1ToIP0;
    MS_BOOL bNeedSetMUX3ToIP0;
}ST_DRV_GOP_MUX_CAP_EX, *PST_DRV_GOP_MUX_CAP_EX;

typedef enum
{
    E_DRV_GOP_BNK_WRITE =0,    //restore the bank register
    E_DRV_GOP_BNK_READ,        //back the bank register
}E_DRV_GOP_BNK_STATUS;

typedef enum
{
    E_DRV_GOP_GPU_TILE_LINEAR =0,
    E_DRV_GOP_GPU_TILE_DIP8X,
    E_DRV_GOP_GPU_TILE_DIP16X,
    E_DRV_GOP_GPU_TILE_GPU,
}EN_DRV_GOP_GPU_TILE_MODE;

typedef enum
{
    EN_GOP_CROP_DISABLE = 0,
    EN_GOP_CROP_ENABLE = 1,
} EN_GOP_CROP_CTL;

///  Test Pattern
typedef struct DLL_PACKED
{
    /// TSTClr_en
    MS_BOOL bTSTClr_En;
    /// TSTClr_Alpha_En
    MS_BOOL bTSTClr_Alpha_En;

    ///TSTClr_Alpha
    MS_U8 u8TSTClr_Alpha;
    /// R_stc
    MS_U8 u8R_stc;
    /// G_stc.
    MS_U8 u8G_stc;
    /// B_stc.
    MS_U8 u8B_stc;

    /// TSTClr_hdup
    MS_U8 u8TSTClr_Hdup;
    /// TSTClr_vdup.
    MS_U8 u8TSTClr_Vdup;

    /// H_R_inc.
    MS_U8 u8HR_inc;
    /// H_R_inc_signz
    MS_BOOL u8HR_inc_signz;
    /// H_G_inc.
    MS_U8 u8HG_inc;
    /// H_G_inc_signz
    MS_BOOL u8HG_inc_signz;
    /// H_B_inc.
    MS_U8 u8HB_inc;
    /// H_B_inc_signz
    MS_BOOL u8HB_inc_signz;
    /// H_R_step
    MS_U8 u8HR_step;
    /// H_G_stepc
    MS_U8 u8HG_step;
    /// H_B_step.
    MS_U8 u8HB_step;

    /// V_R_inc.
    MS_U8 u8VR_inc;
    /// V_R_inc_signz
    MS_BOOL u8VR_inc_signz;
    /// V_G_inc.
    MS_U8 u8VG_inc;
    /// V_G_inc_signz
    MS_BOOL u8VG_inc_signz;
    /// V_B_inc.
    MS_U8 u8VB_inc;
    /// V_B_inc_signz
    MS_BOOL u8VB_inc_signz;
    /// V_R_step
    MS_U8 u8VR_step;
    /// V_G_step
    MS_U8 u8VG_step;
    /// V_B_step.
    MS_U8 u8VB_step;
} DRV_GOP_TSTPATTERN;


typedef struct DLL_PACKED
{
    MS_U8 GOP0;
    MS_U8 GOP1;
    MS_U8 GOP2;
    MS_U8 GOP3;
    MS_U8 GOP4;
    MS_U8 GOP5;
    MS_U8 DWIN;
    MS_U8 MIXER;
}GOP_TYPE_DEF;

typedef struct DLL_PACKED
{
    MS_PHY u64Addr;
    MS_U16 u16Pitch;
    MS_U16 u16Fmt;
}DRV_GOP_CBFmtInfo;

typedef struct DLL_PACKED
{
    MS_U16 Matrix[3][3];
}DRV_GOP_R2Y_Matrix;

typedef struct DLL_PACKED
{
    MS_PHY u64DRAMAddr;       //!< unit: Byte
    MS_U16 u16HPixelStart;      //!< unit: pix
    MS_U16 u16HPixelEnd;        //!< unit: pix
    MS_U16 u16VPixelStart;      //!< unit: pix
    MS_U16 u16VPixelEnd;        //!< unit: pix
    MS_U16 u16Pitch;            //!< unit: Byte
    MS_U8  u8Fmt;
    MS_BOOL bHMirror;
    MS_BOOL bVMirror;
}DRV_GOP_AFBC_Info;

typedef enum
{
    E_DRV_GOP_MWIN_SET_COLORKEY,
    E_DRV_GOP_MWIN_SET_FRAMECOLOR,
    E_DRV_GOP_MIWIN_GET_COLORKEY,
    E_DRV_GOP_MWIN_GET_FRAMECOLOR,
}E_DRV_GOP_MWIN_COLORKEY_MODE;

typedef struct __attribute__((packed))
{
    MS_BOOL enable;
    MS_U8 u8WinIndex;
    MS_U8 u8WinAlpha;
    MS_U8 u8BoarderWidth;
    MS_U8 u8BoarderAlpha;
    MS_U8 u8BoarderY_G;
    MS_U8 u8BoarderCr_R;
    MS_U8 u8BoarderCb_B;
    MS_U16 u16WinHstart;
    MS_U16 u16WinHend;
    MS_U16 u16WinVstart;
    MS_U16 u16WinVend;
}DRV_GOP_MULTIWIN_COLORKEY_Info, *PDRV_GOP_MULTIWIN_COLORKEY_Info;

typedef struct __attribute__((packed))
{
    MS_U8 u8frameAlpha;
    MS_U8 u8frameY_G;
    MS_U8 u8frameCr_R;
    MS_U8 u8frameCb_B;
}DRV_GOP_MULTIWIN_FRAMECOLOR, *PDRV_GOP_MULTIWIN_FRAMECOLOR;

typedef enum
{
    E_DRV_GOP_SDR2HDR_OFF,
    E_DRV_GOP_SDR2HDR_HDR10,
}EN_DRV_GOP_SDR2HDR;

// scaler mirror mode
typedef enum
{
    E_DRV_GOP_XC_MIRROR_NORMAL,
    E_DRV_GOP_XC_MIRROR_H_ONLY,
    E_DRV_GOP_XC_MIRROR_V_ONLY,
    E_DRV_GOP_XC_MIRROR_HV,
    E_DRV_GOP_XC_MIRROR_MAX,
} EN_DRV_GOP_XC_MIRRORMODE;

typedef enum
{
    E_DRV_GOP_VOPPATH_DEF                = 0x0, /// Select osd blending position at last
    E_DRV_GOP_VOPPATH_BEF_RGB3DLOOKUP    = 0x1, /// Select osd blending position before RGB 3D LookUP
    E_DRV_GOP_VOPPATH_BEF_PQGAMMA        = 0x2, /// Select osd blending position before gamma table
    E_DRV_GOP_VOPPATH_AFT_PQGAMMA        = 0x3, /// Select osd blending position after gamma table
    E_DRV_GOP_VOPPATH_AFT_LD             = 0x4, /// Select osd blending position after LD
    E_DRV_GOP_VOPPATH_MAX,
}EN_DRV_GOP_VOP_PATH;

typedef struct DLL_PACKED
{
    MS_U32 u32CSCAddr[GOP_CFD_CSC_OUTPUT_NUM];
    MS_U16 u16CSCValue[GOP_CFD_CSC_OUTPUT_NUM];
    MS_U16 u16CSCMask[GOP_CFD_CSC_OUTPUT_NUM];
    MS_U16 u16CSCClient[GOP_CFD_CSC_OUTPUT_NUM];
    MS_U8 u8CSCAdlData[GOP_CFD_CSC_OUTPUT_NUM];
    //CFD Output Brightness
    MS_U32 u32BriAddr[GOP_CFD_BRI_OUTPUT_NUM];
    MS_U16 u16BriValue[GOP_CFD_BRI_OUTPUT_NUM];
    MS_U16 u16BriMask[GOP_CFD_BRI_OUTPUT_NUM];
    MS_U16 u16BriClient[GOP_CFD_BRI_OUTPUT_NUM];
    MS_U8 u8BriAdlData[GOP_CFD_BRI_OUTPUT_NUM];
}ST_DRV_GOP_CFD_OUTPUT;

typedef struct DLL_PACKED
{
    /// Reg Bank (IN)
    MS_U32 u32Bank;
    /// Reg Address (IN)
    MS_U32 u32Addr;
    /// Reg Data (IN)
    MS_U16 u16Data;
    ///Reg Mask (IN)
    MS_U16 u16Mask;
}ST_MENULOAD_REGISTER;

typedef enum
{
    E_DRV_GOP_FORCEWRITE,
    E_DRV_GOP_BNKFORCEWRITE,
    E_DRV_GOP_WITHVSYNC,
    E_DRV_GOP_WITHSYNC_MULTIGOPUPDATED,
} E_DRV_GOPTriggerMode;
//-------------------------------------------------------------------------------------------------
//  Function and Variable
//-------------------------------------------------------------------------------------------------

//======================================================================================
//  GOP Common utility
//======================================================================================
MS_U8 MDrv_DumpGopByGwinId(MS_GOP_CTX_LOCAL*pGOPCtx,MS_U32 GwinID);
void* MDrv_GOP_GetShareMemory(MS_BOOL *pbNeedInitShared);
GOP_Result MDrv_GOP_Sel(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOPNum);
MS_GOP_CTX_LOCAL*  Drv_GOP_Init_Context(void* pInstance,MS_BOOL *pbNeedInitShared);
void MDrv_GOP_Init(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOPNum, MS_PHY u64GOP_REGDMABASE, MS_U32 u32GOP_RegdmaLen, MS_BOOL bEnableVsyncIntFlip);
void MDrv_GOP_PerClientInit(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOPNum, MS_PHY u64GOP_REGDMABASE, MS_U32 u32GOP_RegdmaLen, MS_BOOL bEnableVsyncIntFlip);
void MDrv_GOP_SetGOPEnable2SC(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 gopNum, MS_BOOL bEnable);
void MDrv_GOP_SetIPSel2SC(MS_GOP_CTX_LOCAL*pGOPCtx, MS_IPSEL_GOP ipSelGop);
void MDrv_GOP_SetClkForCapture(MS_GOP_CTX_LOCAL*pGOPCtx, DRV_GOP_DWIN_SRC_SEL enSrcSel);
void MDrv_GOP_SetVOPNBL(MS_GOP_CTX_LOCAL*pGOPCtx,MS_BOOL bEnable);
void MDrv_GOP_GWIN_UpdateReg(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOP);
void MDrv_GOP_GWIN_UpdateRegWithSync(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOP, MS_BOOL bSync);
void MDrv_GOP_GWIN_UpdateRegWithMaskSync(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U16 u16GopMask, MS_BOOL bSync);
void MDrv_GOP_TriggerRegWriteIn(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOP, MS_BOOL bForceWriteIn, MS_BOOL bSync);
void MDrv_GOP_Restore_Ctx(MS_GOP_CTX_LOCAL*pGOPCtx);
MS_BOOL MDrv_GetAFBCCapsSupport(MS_GOP_CTX_LOCAL*pGOPCtx);
MS_U8 MDrv_GOP_Get(MS_GOP_CTX_LOCAL*pGOPCtx);
MS_U8 MDrv_GOP_GetGwinNum(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GopNum);
MS_U8 MDrv_GetMaxMuxOPNum(void);
MS_BOOL MDrv_GOP_SetIOMapBase(MS_GOP_CTX_LOCAL*pGOPCtx);
GOP_Result MDrv_GOP_SetGOPClk(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 gopNum, DRV_GOPDstType eDstType);
GOP_Result MDrv_GOP_SetGOPHighPri(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOPNum);
MS_U8 MDrv_GOP_GetWordUnit(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOPNum);
MS_U16 MDrv_GOP_GetGOPACK(MS_GOP_CTX_LOCAL *pGOPCtx, MS_U8 enGopType);
MS_U8 MDrv_GOP_GetMaxGOPNum(MS_GOP_CTX_LOCAL*pGOPCtx);
MS_U8 MDrv_GOP_GetMaxMuxSel(MS_GOP_CTX_LOCAL*pGOPCtx);
MS_U8 MDrv_GOP_SelGwinIdByGOP(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOP, MS_U8 u8GWinIdx);
GOP_Result MDrv_GOP_SetClock(MS_GOP_CTX_LOCAL*pGOPCtx,MS_BOOL bEnable);
GOP_Result MDrv_GOP_ConvertAPIAddr2HAL(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8Gwinid, MS_PHY* u64ApiAdr);
MS_PHY MDrv_GOP_GetMIULen(MS_GOP_CTX_LOCAL*pGOPCtx);
MS_U16 MDrv_GOP_GetHPipeOfst(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOP_num, DRV_GOPDstType GopDst);
GOP_Result MDrv_GOP_MIXER_SetOutputTiming(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U32 u32mode, GOP_DRV_MixerTiming *pTM);
GOP_Result MDrv_GOP_MIXER_EnableVfilter(MS_GOP_CTX_LOCAL*pGOPCtx, MS_BOOL bEnable);
MS_U32 MDrv_GOP_GetRegForm(MS_GOP_CTX_LOCAL *pGOPCtx, MS_U8 u8gop, MS_U8 u8gwin);
GOP_Result MDrv_GOP_SetGOPBrightness(MS_GOP_CTX_LOCAL*pGOPCtx,MS_U8 u8GOP,MS_U16 u16BriVal,MS_BOOL bMSB);
GOP_Result MDrv_GOP_GetGOPBrightness(MS_GOP_CTX_LOCAL*pGOPCtx,MS_U8 u8GOP,MS_U16* u16BriVal,MS_BOOL* bMSB);
GOP_Result MDrv_GOP_Set_PINPON(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOPNum,MS_BOOL bEn,E_DRV_GOP_PINPON_MODE pinpon_mode);
GOP_Result MDrv_GOP_SetUVSwap(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOPNum,MS_BOOL bEn);
GOP_Result MDrv_GOP_SetYCSwap(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOPNum,MS_BOOL bEn);
GOP_Result MDrv_GOP_SetGOPContrast(MS_GOP_CTX_LOCAL* pGOPCtx, MS_U8 u8GOP, MS_U16 u16YContrast, MS_U16 u16UContrast, MS_U16 u16VContrast);
GOP_Result MDrv_GOP_GetGOPContrast(MS_GOP_CTX_LOCAL* pGOPCtx, MS_U8 u8GOP, MS_U32* u32YContrast, MS_U32* u32UContrast, MS_U32* u32VContrast);
GOP_Result MDrv_GOP_Set3D_LR_FrameExchange(MS_GOP_CTX_LOCAL* pGOPCtx, MS_U8 u8GOP);
GOP_Result MDrv_GOP_Set_VE_MUX(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 gopNum, MS_BOOL bEn);
MS_BOOL MDrv_GOP_GetGOPEnum(MS_GOP_CTX_LOCAL*pGOPCtx, GOP_TYPE_DEF* GOP_TYPE);
GOP_Result MDrv_GOP_GWIN_PowerState(void* pInstance, MS_U32 u32PowerState, void* pModule);
#ifdef CONFIG_GOP_AFBC_FEATURE
GOP_Result MDrv_GOP_AFBC_Core_Reset(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOP);
GOP_Result MDrv_GOP_AFBC_Core_Enable(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOP, MS_BOOL bEna);
#endif
GOP_Result MDrv_GOP_GWIN_AFBCMode(MS_GOP_CTX_LOCAL*pGOPCtx, MS_BOOL u8GOP, MS_BOOL bEnable, MS_U8 eCTL);
GOP_Result MDrv_GOP_GWIN_AFBCSetWindow(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOP, DRV_GOP_AFBC_Info* pinfo, MS_BOOL bChangePitch);
GOP_Result MDrv_GOP_SetDbgLevel(EN_GOP_DEBUG_LEVEL level);
GOP_Result MDrv_GOP_VOP_Path_Sel(MS_GOP_CTX_LOCAL* pGOPCtx,EN_GOP_VOP_PATH_MODE enGOPPath);
GOP_Result MDrv_GOP_CSC_Tuning(MS_GOP_CTX_LOCAL* pGOPCtx,MS_U32 u32GOPNum,ST_GOP_CSC_PARAM *pstCSCParam);
GOP_Result MDrv_GOP_SetCSCCtrl(MS_GOP_CTX_LOCAL* pGOPCtx,MS_U32 u32GOPNum,ST_GOP_CSC_TABLE *pstCSCParam);
GOP_Result MDrv_GOP_GetOsdNonTransCnt(MS_GOP_CTX_LOCAL*pstGOPCtx, MS_U32* pu32Count);
//======================================================================================
//  GOP GWIN Setting
//======================================================================================
void MDrv_GOP_GWIN_EnableProgressive(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOPNum, MS_BOOL bEnable);
MS_BOOL MDrv_GOP_GWIN_IsProgressive(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOPNum);
void MDrv_GOP_GWIN_SetForceWrite(MS_GOP_CTX_LOCAL*pGOPCtx, MS_BOOL bEnable);
void MDrv_GOP_GWIN_SetBnkForceWrite(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOP, MS_BOOL bEnable);
void MDrv_GOP_GWIN_ForceWrite_Update(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOP, MS_BOOL bEnable);
MS_BOOL MDrv_GOP_GWIN_IsForceWrite(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOP);
void MDrv_GOP_GWIN_OutputColor(MS_GOP_CTX_LOCAL*pGOPCtx,MS_U8 u8GOP, GOP_OupputColor type);
void MDrv_GOP_GWIN_SetTransClr_8888(MS_GOP_CTX_LOCAL*pGOPCtx,MS_U8 u8GOP, MS_U32 clr, MS_U32 mask);
void MDrv_GOP_GWIN_SetTransClr_YUV(MS_GOP_CTX_LOCAL*pGOPCtx,MS_U8 u8GOP, MS_U32 clr, MS_U32 mask);
void MDrv_GOP_GWIN_EnableTransClr(MS_GOP_CTX_LOCAL*pGOPCtx,MS_U8 u8GOP, GOP_TransClrFmt fmt, MS_BOOL bEnable);
void MDrv_GOP_GWIN_SetAlphaInverse(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8gopNum, MS_BOOL bEnable);
GOP_Result MDrv_GOP_GWIN_GetDstPlane(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOPNum, DRV_GOPDstType *pGopDst);
void MDrv_GOP_GWIN_SetBlending(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8win, MS_BOOL bEnable, MS_U8 u8coef);
void MDrv_GOP_GWIN_SetWinFmt(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8win, DRV_GOPColorType clrtype);
void MDrv_GOP_GWIN_EnableGwin(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8win, MS_BOOL bEnable);
void MDrv_GOP_GWIN_IsGWINEnabled(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8win, MS_BOOL* pbEnable );
void MDrv_GOP_GWIN_EnableHMirror(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOPNum, MS_BOOL bEnable);
void MDrv_GOP_GWIN_EnableVMirror(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOPNum, MS_BOOL bEnalbe);
void MDrv_GOP_IsGOPMirrorEnable(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOPNum, MS_BOOL *bHMirror, MS_BOOL *bVMirror);
void MDrv_GOP_GWIN_SetMux(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOPNum, Gop_MuxSel eGopMux);
void MDrv_GOP_MapLayer2Mux(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U32 u32Layer, MS_U8 u8Gopnum, MS_U32 *pu32Mux);
void MDrv_GOP_GWIN_GetMux(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8* u8GOPNum, Gop_MuxSel eGopMux);
void MDrv_GOP_GWIN_SetHSPipe(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOPNum, MS_U16 u16HSPipe);
void MDrv_GOP_SetGOPEnable2Mode1(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 gopNum, MS_BOOL bEnable);
void MDrv_GOP_GetGOPEnable2Mode1(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 gopNum, MS_BOOL *pbEnable);
GOP_Result MDrv_GOP_GWIN_GetGwinInfo(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8win, DRV_GOP_GWIN_INFO* pinfo);
GOP_Result MDrv_GOP_GWIN_SetGwinInfo(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8win, DRV_GOP_GWIN_INFO* pinfo);
GOP_Result MDrv_GOP_GWIN_SetDstPlane(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOPNum, DRV_GOPDstType eDstType,MS_BOOL bOnlyCheck);
GOP_Result MDrv_GOP_GWIN_GetGwinNewAlphaModeEnable(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8win, MS_BOOL* bEnable);
GOP_Result MDrv_GOP_GWIN_SetNewAlphaMode(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8win, MS_BOOL bEnable);
MS_U16 MDrv_GOP_GetBPP(MS_GOP_CTX_LOCAL*pGOPCtx, DRV_GOPColorType fbFmt);
E_GOP_VIDEOTIMING_MIRRORTYPE Mdrv_GOP_GetVideoTimingMirrorType(MS_GOP_CTX_LOCAL* pGOPCtx, MS_BOOL bHorizontal);
GOP_Result MDrv_GOP_GWIN_DeleteWinHVSize(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOP, MS_U16 u16HSize, MS_U16 u16VSize);
void MDrv_GOP_SelfFirstHs(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8Gop, MS_BOOL bEnable);

//======================================================================================
//  GOP Stretch Window Setting
//======================================================================================
void MDrv_GOP_GWIN_SetStretchWin(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOP, MS_U16 x, MS_U16 y, MS_U16 width, MS_U16 height);
void MDrv_GOP_GWIN_SetHTotal(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOP, MS_U16 width);
void MDrv_GOP_GWIN_Get_StretchWin(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOP, MS_U16 *x, MS_U16 *y, MS_U16 *width, MS_U16 *height);
void MDrv_GOP_GWIN_Set_HSCALE(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOP, MS_BOOL bEnable, MS_U16 src, MS_U16 dst) ;
void MDrv_GOP_GWIN_Set_VSCALE(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOP, MS_BOOL bEnable, MS_U16 src, MS_U16 dst) ;
void MDrv_GOP_GWIN_Set_HStretchMode(MS_GOP_CTX_LOCAL*pGOPCtx,MS_U8 u8GOP, DRV_GOPStrchHMode HStrchMode);
void MDrv_GOP_GWIN_Set_VStretchMode(MS_GOP_CTX_LOCAL*pGOPCtx,MS_U8 u8GOP, DRV_GOPStrchVMode VStrchMode);
void MDrv_GOP_GWIN_Load_HStretchModeTable(MS_GOP_CTX_LOCAL*pGOPCtx,MS_U8 u8GOP , DRV_GOPStrchHMode HStrchMode);
void MDrv_GOP_GWIN_Load_VStretchModeTable(MS_GOP_CTX_LOCAL*pGOPCtx,MS_U8 u8GOP, DRV_GOPStrchVMode VStrchMode);

//======================================================================================
//  GOP GWIN H/V Scroll
//======================================================================================
void MDrv_GOP_GWIN_SetScrollRate(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8rate);
void MDrv_GOP_GWIN_SetHScroll(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8win, E_GOP_SCROLL_TYPE type, MS_U32 offset, MS_BOOL bEnable);
void MDrv_GOP_GWIN_SetVScroll(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8win, E_GOP_SCROLL_TYPE type, MS_U32 offset, MS_BOOL bEnable);
void MDrv_GOP_GWIN_Scroll_EnableAutoStop(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8win, MS_BOOL bEnable);
MS_BOOL MDrv_GOP_GWIN_Scroll_AutoStop_HSet(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8win, MS_U32 u32AutoHStopOffset);
MS_BOOL MDrv_GOP_GWIN_Scroll_AutoStop_VSet(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8win, MS_U32 u32AutoVStopOffset);
//======================================================================================
//  GOP OC
//======================================================================================
GOP_Result MDrv_GOP_OC_SetOCEn(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8GOPNum, MS_BOOL bOCEn);
GOP_Result MDrv_GOP_OC_SetOCInfo(MS_GOP_CTX_LOCAL*pGOPCtx, DRV_GOP_OC_INFO* OCinfo);

//======================================================================================
//  GOP GPU Tile
//======================================================================================
GOP_Result MDrv_GOP_GWIN_SetGPUTileMode(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8win, EN_DRV_GOP_GPU_TILE_MODE mode);

MS_BOOL MDrv_GOP_GWIN_BeginDraw(void);
MS_BOOL MDrv_GOP_GWIN_EndDraw(void);
void MDrv_GOP_GWIN_Interrupt(MS_GOP_CTX_LOCAL*pGOPCtx,MS_U8 u8Gop,MS_BOOL bEable);
GOP_Result MDrv_GOP_AutoDectBuf(MS_GOP_CTX_LOCAL*pstGOPCtx, ST_GOP_AUTO_DETECT_BUF_INFO* pstAutoDectInfo);

//======================================================================================
//  GOP HDR
//======================================================================================
GOP_Result MDrv_GOP_IsHDREnabled(MS_GOP_CTX_LOCAL*pGOPCtx, MS_BOOL* pbHDREnable);
GOP_Result MDrv_GOP_SetGOPMixerValid(MS_GOP_CTX_LOCAL*pGOPCtx, MS_U8 u8Gop, MS_BOOL bEnable);

GOP_Result MDrv_GOP_GWIN_Trigger_MUX(MS_GOP_CTX_LOCAL* pstGOPCtx);
GOP_Result MDrv_GOP_ByPassMode(MS_GOP_CTX_LOCAL* pstGOPCtx, MS_U32 u32GOPIdx, MS_BOOL bEnable);

#ifdef __cplusplus
}
#endif


#endif // _DRV_TEMP_H_
