//<MStar Software>
//******************************************************************************
// MStar Software
// Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
// All software, firmware and related documentation herein ("MStar Software") are
// intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
// law, including, but not limited to, copyright law and international treaties.
// Any use, modification, reproduction, retransmission, or republication of all
// or part of MStar Software is expressly prohibited, unless prior written
// permission has been granted by MStar.
//
// By accessing, browsing and/or using MStar Software, you acknowledge that you
// have read, understood, and agree, to be bound by below terms ("Terms") and to
// comply with all applicable laws and regulations:
//
// 1. MStar shall retain any and all right, ownership and interest to MStar
//    Software and any modification/derivatives thereof.
//    No right, ownership, or interest to MStar Software and any
//    modification/derivatives thereof is transferred to you under Terms.
//
// 2. You understand that MStar Software might include, incorporate or be
//    supplied together with third party`s software and the use of MStar
//    Software may require additional licenses from third parties.
//    Therefore, you hereby agree it is your sole responsibility to separately
//    obtain any and all third party right and license necessary for your use of
//    such third party`s software.
//
// 3. MStar Software and any modification/derivatives thereof shall be deemed as
//    MStar`s confidential information and you agree to keep MStar`s
//    confidential information in strictest confidence and not disclose to any
//    third party.
//
// 4. MStar Software is provided on an "AS IS" basis without warranties of any
//    kind. Any warranties are hereby expressly disclaimed by MStar, including
//    without limitation, any warranties of merchantability, non-infringement of
//    intellectual property rights, fitness for a particular purpose, error free
//    and in conformity with any international standard.  You agree to waive any
//    claim against MStar for any loss, damage, cost or expense that you may
//    incur related to your use of MStar Software.
//    In no event shall MStar be liable for any direct, indirect, incidental or
//    consequential damages, including without limitation, lost of profit or
//    revenues, lost or damage of data, and unauthorized system use.
//    You agree that this Section 4 shall still apply without being affected
//    even if MStar Software has been modified by MStar in accordance with your
//    request or instruction for your use, except otherwise agreed by both
//    parties in writing.
//
// 5. If requested, MStar may from time to time provide technical supports or
//    services in relation with MStar Software to you for your use of
//    MStar Software in conjunction with your or your customer`s product
//    ("Services").
//    You understand and agree that, except otherwise agreed by both parties in
//    writing, Services are provided on an "AS IS" basis and the warranty
//    disclaimer set forth in Section 4 above shall apply.
//
// 6. Nothing contained herein shall be construed as by implication, estoppels
//    or otherwise:
//    (a) conferring any license or right to use MStar name, trademark, service
//        mark, symbol or any other identification;
//    (b) obligating MStar or any of its affiliates to furnish any person,
//        including without limitation, you and your customers, any assistance
//        of any kind whatsoever, or any information; or
//    (c) conferring any license or right under any intellectual property right.
//
// 7. These terms shall be governed by and construed in accordance with the laws
//    of Taiwan, R.O.C., excluding its conflict of law rules.
//    Any and all dispute arising out hereof or related hereto shall be finally
//    settled by arbitration referred to the Chinese Arbitration Association,
//    Taipei in accordance with the ROC Arbitration Law and the Arbitration
//    Rules of the Association by three (3) arbitrators appointed in accordance
//    with the said Rules.
//    The place of arbitration shall be in Taipei, Taiwan and the language shall
//    be English.
//    The arbitration award shall be final and binding to both parties.
//
//******************************************************************************
//<MStar Software>
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2006-2007 MStar Semiconductor, Inc.
// All rights reserved.
//
// Unless otherwise stipulated in writing, any and all information contained
// herein regardless in any format shall remain the sole proprietary of
// MStar Semiconductor Inc. and be kept in strict confidence
// (ˇ§MStar Confidential Informationˇ¨) by the recipient.
// Any unauthorized act including without limitation unauthorized disclosure,
// copying, use, reproduction, sale, distribution, modification, disassembling,
// reverse engineering and compiling of the contents of MStar Confidential
// Information is unlawful and strictly prohibited. MStar hereby reserves the
// rights to any and all damages, losses, costs and expenses resulting therefrom.
//
////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////
///
/// @file   drvMIU_v2.h
/// @brief  MIU Driver Interface
/// @author MStar Semiconductor Inc.
///////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef _DRV_MIU_V2_H_
#define _DRV_MIU_V2_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include "MsTypes.h"
#include "UFO.h"

//-------------------------------------------------------------------------------------------------
// Defines
//-------------------------------------------------------------------------------------------------
typedef enum _eMIUIoctlCmd
{
    MDrv_CMD_MIU_Init,
    MDrv_CMD_MIU_Mask_Req_OPM_R,
    MDrv_CMD_MIU_Mask_Req_DNRB_R,
    MDrv_CMD_MIU_Mask_Req_DNRB_W,
    MDrv_CMD_MIU_Mask_Req_DNRB_RW,
    MDrv_CMD_MIU_Mask_Req_SC_RW,
    MDrv_CMD_MIU_Mask_Req_MVOP_R,
    MDrv_CMD_MIU_Mask_Req_MVD_R,
    MDrv_CMD_MIU_Mask_Req_MVD_W,
    MDrv_CMD_MIU_Mask_Req_MVD_RW,
    MDrv_CMD_MIU_Mask_Req_AUDIO_RW,
    MDrv_CMD_MIU_Mask_Req,
    MDrv_CMD_MIU_UnMask_Req,
    MDrv_CMD_MIU_GetLoading,
    MDrv_CMD_MIU_SetSsc,
    MDrv_CMD_MIU_SetSscValue,
    MDrv_CMD_MIU_Protect,
    MDrv_CMD_MIU_ProtectEx,
    MDrv_CMD_MIU_SelMIU,
    MDrv_CMD_MIU_GetProtectInfo,
    MDrv_CMD_MIU_SetGroupPriority,
    MDrv_CMD_MIU_SetHighPriority,
    MDrv_CMD_MIU_PrintProtectInfo,
    MDrv_CMD_MIU_Dram_Size,
    MDrv_CMD_MIU_ProtectAlign,
    MDrv_CMD_MIU_GetDramType,
    MDrv_CMD_MIU_IsSupportMIU1,
    MDrv_CMD_MIU_SetBWMonitor,
    MDrv_CMD_MIU_DelBWMonitor,
    MDrv_CMD_MIU_QueryBWMonitor,
    MDrv_CMD_MIU_GetBW,
    MDrv_CMD_MIU_ResetAllBWMonitor,
    MDrv_CMD_MIU_ConfigHWAttr,
    MDrv_CMD_MIU_SetClientUtilization,
    MDrv_CMD_MIU_GetClientUtilization,
    MDrv_CMD_MIU_SetClientEfficiency,
    MDrv_CMD_MIU_GetClientEfficiency,
    MDrv_CMD_MIU_SetBWValue,
    MDrv_CMD_MIU_GetBWValue,
    MDrv_CMD_MIU_GetMIUInfo,
    MDrv_CMD_MIU_GetBWAll,
    MDrv_CMD_MIU_StartBWMonitor,
    MDrv_CMD_MIU_SetCPUHPriority,
}eMIUIoctlCmd;

//-------------------------------------------------------------------------------------------------
// Macros
//-------------------------------------------------------------------------------------------------


//-------------------------------------------------------------------------------------------------
// Type and Structure Declaration
//-------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------
// Extern Global Variabls
//-------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------
// Extern Functions
//-------------------------------------------------------------------------------------------------

//////////////////////////////////////////////////////////////
// below are for utopia20 cmd and parameters structure
// for below cmds
// MDrv_CMD_MIU_Mask_Req_OPM_R,
// MDrv_CMD_MIU_Mask_Req_DNRB_R,
// MDrv_CMD_MIU_Mask_Req_DNRB_W,
// MDrv_CMD_MIU_Mask_Req_DNRB_RW,
// MDrv_CMD_MIU_Mask_Req_SC_RW,
// MDrv_CMD_MIU_Mask_Req_MVOP_R,
// MDrv_CMD_MIU_Mask_Req_MVD_R,
// MDrv_CMD_MIU_Mask_Req_MVD_W,
// MDrv_CMD_MIU_Mask_Req_MVD_RW,
// MDrv_CMD_MIU_Mask_Req_AUDIO_RW,

typedef struct _MIU_RET
{
    MS_BOOL bRet;
}MIU_RET, *PMIU_RET;

typedef struct _MIU_MASK
{
    MS_U8 u8Mask;
    MS_U8 u8Miu;
}MIU_MIU_MASK, *PMIU_MIU_MASK;

// for below cmds MDrv_CMD_MIU_Mask_Req, MDrv_CMD_MIU_UnMask_Req
typedef struct _MIU_MIUREQ_MASK
{
    MS_U8 u8Miu;
    eMIUClientID eClientID;
}MIU_MIUREQ_MASK, *PMIU_MIUREQ_MASK;

// MDrv_MIU_GetLoading,
typedef struct _MIU_GET_LOADING
{
    MS_U8 u8MiuDev;
    MS_U32 *u32Loading;
    MS_BOOL bRet;
}MIU_GET_LOADING, *PMIU_MIU_GET_LOADING;

// for below cmds MDrv_CMD_MIU_SetSsc
typedef struct _MIU_SET_SSC
{
    MS_U16 u16Fmodulation;
    MS_U16 u16FDeviation;
    MS_BOOL bEnable;
    MS_BOOL bRet;
}MIU_SET_SSC, *PMIU_SET_SSC;

// for below cmds MDrv_CMD_MIU_SetSscValue
typedef struct _MIU_SET_SSCVALUE
{
    MS_U8 u8MiuDev;
    MS_U16 u16Fmodulation;
    MS_U16 u16FDeviation;
    MS_BOOL bEnable;
    MS_BOOL bRet;
}MIU_SET_SSCVALUE, *PMIU_SET_SSCVALUE;

// for below cmds MDrv_CMD_MIU_Protect

typedef MS_U8 MIU_PROYECT_ID[16];

#ifdef BIFROST_32BIT_MODE
typedef struct DLL_PACKED _MIU_PROTECT
{
    MS_U8 u8Blockx;
    MS_U8 *pu8ProtectId;
#if defined(UFO_PUBLIC_HEADER_212)||defined(UFO_PUBLIC_HEADER_300)
    MS_U32 u32Start;
    MS_U32 u32End;
#else
    MS_U32 phy64Start;
    MS_U32 phy64End;
#endif
    MS_BOOL bSetFlag;
    MS_BOOL bRet;
}MIU_PROTECT, *PMIU_PROTECT;
#else
typedef struct DLL_PACKED _MIU_PROTECT
{
    MS_U8 u8Blockx;
    MS_U8 *pu8ProtectId;
#if defined(UFO_PUBLIC_HEADER_212)||defined(UFO_PUBLIC_HEADER_300)
    MS_U32 u32Start;
    MS_U32 u32End;
#else
    MS_PHY phy64Start;
    MS_PHY phy64End;
#endif
    MS_BOOL bSetFlag;
    MS_BOOL bRet;
}MIU_PROTECT, *PMIU_PROTECT;
#endif

// for below cmds MDrv_CMD_MIU_ProtectEx
typedef struct DLL_PACKED _MIU_PROTECTEx
{
    MS_U8 u8Blockx;
    MS_U32 *pu32ProtectId;
    MS_PHY phy64Start;
    MS_PHY phy64End;
    MS_BOOL bSetFlag;
}MIU_PROTECTEx, *PMIU_PROTECTEx;

// For HW Setting
typedef struct _MIU_ConfigHWAttr
{
    MS_U8 u8MiuDev;
    eMIU_ATTR_TYPE eAttrType;
    MS_U16 *u16Value;
    MS_U16 u16Length;
    MS_BOOL bRet;
}MIU_ConfigHWAttr, *PMIU_ConfigHWAttr;

// for below cmds MDrv_CMD_MIU_SelMIU
typedef struct _MIU_SELMIU
{
    eMIUClientID eClientID;
    eMIU_SelType eType;
    MS_BOOL bRet;
}MIU_SELMIU, *PMIU_SELMIU;

// for below cmds MDrv_CMD_MIU_GetDramType
typedef struct _MIU_GETDRAMTYPE
{
    MIU_ID eMiu;
    MIU_DDR_TYPE* pType;
}MIU_GETDRAMTYPE, *PMIU_GETDRAMTYPE;

// for below cmds MDrv_CMD_MIU_GetProtectInfo
typedef struct DLL_PACKED _MIU_GETPROTECTINFO
{
    MS_U8 u8MiuDev;
    MIU_PortectInfo *pInfo;
    MS_BOOL bRet;
}MIU_GETPROTECTINFO, *PMIU_GETPROTECTINFO;

// for below cmds MDrv_CMD_MIU_SetGroupPriority
typedef struct _MIU_SETGROUPPRIORITY
{
    MS_U8 u8MiuDev;
    MIU_GroupPriority sPriority;
    MS_BOOL bRet;
}MIU_SETGROUPPRIORITY, *PMIU_SETGROUPPRIORITY;


// for below cmds MDrv_CMD_MIU_SetHighPriority
typedef struct _MIU_SETHIGHPRIORITY
{
    MS_U8 u8MiuDev;
    eMIUClientID eClientID;
    MS_BOOL bMask;
    MS_BOOL bRet;
}MIU_SETHIGHPRIORITY, *PMIU_SETHIGHPRIORITY;

// for below cmds MDrv_CMD_MIU_Dram_Size
typedef struct _MIU_DRAM_SIZE
{
    MS_U8 u8MiuDev;
    MS_U8 DramSize;
    MS_BOOL bRet;
}MIU_DRAM_SIZE, *PMIU_DRAM_SIZE;

// for below cmds MDrv_CMD_MIU_ProtectAlign
typedef struct DLL_PACKED _MIU_PROTECT_ALIGN
{
    MS_U32 *u32PageShift;
    MS_BOOL bRet;
}MIU_PROTECT_ALIGN, *PMIU_PROTECT_ALIGN;

// for below cmds MDrv_CMD_MIU_SetBWMonitor
typedef struct DLL_PACKED _MIU_BWMONITOR
{
    MS_U8 u8MiuDev;
    MIU_BandwidthMonitorInfo *pBWInfo;
    MS_BOOL bRet;
}MIU_BWMONITOR, *PMIU_BWMONITOR;

typedef struct DLL_PACKED _MIU_BWUTILIZATION
{
    MS_U8 u8MiuDev;
    eMIUClientID eClientID;
    MS_U32 *pu32BWUtilization;
}MIU_BWUTILIZATION, *PMIU_BWUTILIZATION;

typedef struct DLL_PACKED _MIU_BWEFFICIENCY
{
    MS_U8 u8MiuDev;
    eMIUClientID eClientID;
    MS_U32 *pu32BWEfficiency;
}MIU_BWEFFICIENCY, *PMIU_BWEFFICIENCY;

typedef struct DLL_PACKED _MIU_SETGETBW
{
    MS_U32 u32ClientID;
    MIU_BW_TYPE eBWINfoType;
    MIU_UMA_Mode *peUMAMode;
    MIU_BWValue *pBWValue;
}MIU_SETGETBW, *PMIU_SETGETBW;

typedef struct DLL_PACKED _MIU_GETINFO
{
    MIU_ID eMiu;
    MIU_Info *pstMIUInfo;
}MIU_GETINFO, *PMIU_GETINFO;

typedef struct DLL_PACKED _MIU_SETCPUHPRI
{
    MIU_HPri_Scope eScope;
    MS_U64 u64Start;
    MS_U64 u64End;
    MS_BOOL bEnable;
}MIU_SETCPUHPRI, *PMIU_SETCPUHPRI;

#ifdef __cplusplus
}
#endif

#endif // _DRV_MIU_V2_H_

