//<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-2009 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.c
/// @brief  MIU Driver Interface
/// @author MStar Semiconductor Inc.
///////////////////////////////////////////////////////////////////////////////////////////////////

//-------------------------------------------------------------------------------------------------
// Include Files
//-------------------------------------------------------------------------------------------------
#ifdef MSOS_TYPE_LINUX_KERNEL
#include <linux/string.h>
#include <linux/slab.h>
#else
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#endif
#include "MsCommon.h"
#include "MsVersion.h"
#include "MsTypes.h"
#include "drvMIU.h"
#include "drvMIU_private.h"
#include "halMIU.h"
#include "drvMMIO.h"
#include "MsOS.h"
#include "utopia.h"
#include "utopia_dapi.h"
//#include <assert.h>
#include "ULog.h"

//-------------------------------------------------------------------------------------------------
// Global Variables
//-------------------------------------------------------------------------------------------------
MS_U32 u32MIUDbgLevel = E_MIU_DBGLV_ERROR;

//-------------------------------------------------------------------------------------------------
// Local Defines
//-------------------------------------------------------------------------------------------------
#define TAG_MIU "MIU"
//-------------------------------------------------------------------------------------------------
// Macros
//-------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------
// Local Variables
//-------------------------------------------------------------------------------------------------
static MSIF_Version _drv_miu_version = {
    .DDI = { MIU_DRV_VERSION },
};

MS_U8 MIU0_request_mask_count[MIU_CLIENT_MAX];
MS_U8 MIU1_request_mask_count[MIU_CLIENT_MAX];

void* pInstantMIU = NULL;
void* pAttributeMIU = NULL;

//-------------------------------------------------------------------------------------------------
// Local Function Prototypes
//-------------------------------------------------------------------------------------------------
MS_BOOL MDrv_MIU_Exit(void);

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function  \b Name: MDrv_MIU_SetIOMapBase
/// @brief \b Function  \b Description: set MIU I/O Map base address
/// @param None         \b IN :
/// @param None         \b OUT :
/// @param MS_BOOL      \b RET
/// @param None         \b GLOBAL :
////////////////////////////////////////////////////////////////////////////////
MS_BOOL MDrv_MIU_SetIOMapBase(void)
{
    MS_VIRT virtMMIOBaseAdr = 0;
    MS_PHY u32NonPMBankSize = 0;

    if( !MDrv_MMIO_GetBASE(&virtMMIOBaseAdr, &u32NonPMBankSize, MS_MODULE_MIU))
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "Get IOMap MS_MODULE_MIU failure\n");
        MS_ASSERT(0);
        return FALSE;
    }
    HAL_MIU_SetIOMapBase(virtMMIOBaseAdr);

    if( !MDrv_MMIO_GetBASE(&virtMMIOBaseAdr, &u32NonPMBankSize, MS_MODULE_PM))
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "Get IOMap MS_MODULE_PM failure\n");
        MS_ASSERT(0);
        return FALSE;
    }
    HAL_MIU_SetPMIOMapBase(virtMMIOBaseAdr);

    if( !MDrv_MMIO_GetBASE(&virtMMIOBaseAdr, &u32NonPMBankSize, MS_MODULE_EXTRIU))
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "Get IOMap MS_MODULE_EXTRIU failure\n");
        return TRUE;
    }
    HAL_MIU_SetExtIOMapBase(virtMMIOBaseAdr);

    return TRUE;
}

// UTOPIA remove so dummy code
#ifndef CONFIG_UTOPIAXP_REMOVE_IMPL
////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function  \b Name: _MDrv_MIU_Init
/// @brief \b Function  \b Description: set MIU I/O Map base address and parse occupied resource to software structure
/// @param None         \b IN :
/// @param None         \b OUT :
/// @param MS_BOOL      \b RET
/// @param None         \b GLOBAL :
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_Init(void)
{
    if( MDrv_MIU_SetIOMapBase() == FALSE)
        return FALSE;

    if( HAL_MIU_ParseOccupiedResource() == FALSE)
        return FALSE;

    return TRUE;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_Protect()
/// @brief \b Function \b Description:  Enable/Disable MIU Protection mode
/// @param u8Blockx        \b IN     : MIU Block to protect (0 ~ 3)
/// @param *pu8ProtectId   \b IN     : Allow specified client IDs to write
/// @param phy64Start      \b IN     : Starting address
/// @param phy64End        \b IN     : End address
/// @param bSetFlag        \b IN     : Disable or Enable MIU protection
///                                      - -Disable(0)
///                                      - -Enable(1)
/// @param <OUT>           \b None    :
/// @param <RET>           \b None    :
/// @param <GLOBAL>        \b None    :
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_Protect(
                          MS_U8    u8Blockx,
                          MS_U8    *pu8ProtectId,
                          MS_PHY phy64Start,
                          MS_PHY phy64End,
                          MS_BOOL  bSetFlag
                         )
{
    MS_BOOL Result;

    Result = HAL_MIU_Protect(u8Blockx, pu8ProtectId, phy64Start, phy64End, bSetFlag);

    if(Result == TRUE)
    {
        return TRUE;
    }
    else
    {
       //MS_ASSERT(0);
       return FALSE;
    }
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_ProtectEx()
/// @brief \b Function \b Description:  Enable/Disable MIU Protection mode
/// @param u8Blockx        \b IN     : MIU Block to protect (0 ~ 3)
/// @param *pu8ProtectId   \b IN     : Allow specified client IDs to write
/// @param phy64Start      \b IN     : Starting address
/// @param phy64End        \b IN     : End address
/// @param bSetFlag        \b IN     : Disable or Enable MIU protection
///                                      - -Disable(0)
///                                      - -Enable(1)
/// @param <OUT>           \b None    :
/// @param <RET>           \b None    :
/// @param <GLOBAL>        \b None    :
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_ProtectEx(
                          MS_U8    u8Blockx,
                          MS_U32    *pu32ProtectId,
                          MS_PHY phy64Start,
                          MS_PHY phy64End,
                          MS_BOOL  bSetFlag
                         )
{
    MS_BOOL Result;

    Result = HAL_MIU_ProtectEx(u8Blockx, pu32ProtectId, phy64Start, phy64End, bSetFlag);

    if(Result == TRUE)
    {
        return TRUE;
    }
    else
    {
       //MS_ASSERT(0);
       return FALSE;
    }
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function    \b Name: MDrv_MIU_ProtectAlign()
/// @brief \b Function    \b Description:  Get the page shift for MIU protect
/// @param <*u32PageShift>\b IN: Page shift
/// @param <RET>          \b OUT: None
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_ProtectAlign(MS_U32 *u32PageShift)
{
    *u32PageShift = HAL_MIU_ProtectAlign();

    if(*u32PageShift > 0)
        return TRUE;
    else
        return FALSE;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function  \b Name: _MDrv_MIU_GetProtectInfo()
/// @brief \b Function  \b Description:  This function for querying client ID info
/// @param u8MiuDev     \b IN   : select MIU0 or MIU1
/// @param eClientID    \b IN   : Client ID
/// @param pInfo        \b OUT  : Client Info
/// @param None \b RET:   0: Fail 1: Ok
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_GetProtectInfo(MS_U8 u8MiuDev, MIU_PortectInfo *pInfo)
{
    MS_U32 ret;
    ret = HAL_MIU_GetProtectInfo(u8MiuDev, pInfo);

    //if(pInfo->bHit)
    //{
    //    if(MsOS_GetKattribute("miuprot")==1)
    //        MS_ASSERT(0);
    //}

    return ret;
}

void _MDrv_MIU_PrintProtectInfo(void)
{
    HAL_MIU_PrintMIUProtectInfo();
}

void _MDrv_MIU_PrintMIUProtectInfo(void)
{
    HAL_MIU_PrintMIUProtectInfo();
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_SwitchMIU()
/// @brief \b Function \b Description:  This function for switch miu
///
/// @param u8MiuID        \b IN     : select MIU0 or MIU1
/// @param None \b RET:
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_SelMIU(eMIUClientID eClientID, eMIU_SelType eType)
{
    return HAL_MIU_SelMIU(eType, eClientID);;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_Mask_Req_OPM_R()
/// @brief \b Function \b Description:
/// @param None  \b IN   :
/// @param None  \b OUT  :
/// @param None  \b RET  :
///////////////////////////////////////////////////////////////////////////////
void _MDrv_MIU_Mask_Req_OPM_R(MS_U8 u8Mask, MS_U8 u8Miu)
{
    HAL_MIU_Mask_Req_OPM_R(u8Mask, u8Miu);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_Mask_Req_DNRB_R()
/// @brief \b Function \b Description:
/// @param None  \b IN   :
/// @param None  \b OUT  :
/// @param None  \b RET  :
///////////////////////////////////////////////////////////////////////////////
void _MDrv_MIU_Mask_Req_DNRB_R(MS_U8 u8Mask, MS_U8 u8Miu)
{
    HAL_MIU_Mask_Req_DNRB_R( u8Mask,  u8Miu);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_Mask_Req_DNRB_W()
/// @brief \b Function \b Description:
/// @param None  \b IN   :
/// @param None  \b OUT  :
/// @param None  \b RET  :
///////////////////////////////////////////////////////////////////////////////
void _MDrv_MIU_Mask_Req_DNRB_W(MS_U8 u8Mask, MS_U8 u8Miu)
{
    HAL_MIU_Mask_Req_DNRB_W( u8Mask,  u8Miu);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_Mask_Req_DNRB_RW()
/// @brief \b Function \b Description:
/// @param None  \b IN   :
/// @param None  \b OUT  :
/// @param None  \b RET  :
///////////////////////////////////////////////////////////////////////////////
void _MDrv_MIU_Mask_Req_DNRB_RW(MS_U8 u8Mask, MS_U8 u8Miu)
{
   HAL_MIU_Mask_Req_DNRB_RW( u8Mask,  u8Miu);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_Mask_Req_SC_RW()
/// @brief \b Function \b Description:
/// @param None  \b IN   :
/// @param None  \b OUT  :
/// @param None  \b RET  :
///////////////////////////////////////////////////////////////////////////////
void _MDrv_MIU_Mask_Req_SC_RW(MS_U8 u8Mask, MS_U8 u8Miu)
{
    HAL_MIU_Mask_Req_SC_RW( u8Mask,  u8Miu);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_Mask_Req_MVOP_R()
/// @brief \b Function \b Description:
/// @param None  \b IN   :
/// @param None  \b OUT  :
/// @param None  \b RET  :
///////////////////////////////////////////////////////////////////////////////
void _MDrv_MIU_Mask_Req_MVOP_R(MS_U8 u8Mask, MS_U8 u8Miu)
{
    HAL_MIU_Mask_Req_MVOP_R( u8Mask,  u8Miu);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_Mask_Req_MVD_R()
/// @brief \b Function \b Description:
/// @param None  \b IN   :
/// @param None  \b OUT  :
/// @param None  \b RET  :
///////////////////////////////////////////////////////////////////////////////
void _MDrv_MIU_Mask_Req_MVD_R(MS_U8 u8Mask, MS_U8 u8Miu)
{
    HAL_MIU_Mask_Req_MVD_R( u8Mask,  u8Miu);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_Mask_Req_MVD_W()
/// @brief \b Function \b Description:
/// @param None  \b IN   :
/// @param None  \b OUT  :
/// @param None  \b RET  :
///////////////////////////////////////////////////////////////////////////////
void _MDrv_MIU_Mask_Req_MVD_W(MS_U8 u8Mask, MS_U8 u8Miu)
{
    HAL_MIU_Mask_Req_MVD_W( u8Mask,  u8Miu);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_Mask_Req_MVD_RW()
/// @brief \b Function \b Description:
/// @param None  \b IN   :
/// @param None  \b OUT  :
/// @param None  \b RET  :
///////////////////////////////////////////////////////////////////////////////
void _MDrv_MIU_Mask_Req_MVD_RW(MS_U8 u8Mask, MS_U8 u8Miu)
{
    HAL_MIU_Mask_Req_MVD_RW( u8Mask,  u8Miu);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_Mask_Req_AUDIO_RW()
/// @brief \b Function \b Description:
/// @param None  \b IN   :
/// @param None  \b OUT  :
/// @param None  \b RET  :
///////////////////////////////////////////////////////////////////////////////
void _MDrv_MIU_Mask_Req_AUDIO_RW(MS_U8 u8Mask, MS_U8 u8Miu)
{
    HAL_MIU_Mask_Req_AUDIO_RW( u8Mask,  u8Miu);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_MaskReq()
/// @brief \b Function \b Description: Mask MIU request
/// @param u8Miu        \b IN   : 0: MIU0 1:MIU1
/// @param eClientID    \b IN   : Client ID
/// @param None         \b OUT  :
/// @param None         \b RET  :
///////////////////////////////////////////////////////////////////////////////
void _MDrv_MIU_MaskReq(MS_U8 u8Miu, eMIUClientID eClientID)
{
    HAL_MIU_MaskReq(u8Miu, eClientID);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_UnMaskReq()
/// @brief \b Function \b Description: Unmak MIU request
/// @param u8Miu        \b IN   : 0: MIU0 1:MIU1
/// @param eClientID    \b IN   : Client ID
/// @param None         \b OUT  :
/// @param None         \b RET  :
///////////////////////////////////////////////////////////////////////////////
void _MDrv_MIU_UnMaskReq(MS_U8 u8Miu, eMIUClientID eClientID)
{
    HAL_MIU_UnMaskReq(u8Miu, eClientID);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function  \b Name: _MDrv_MIU_SetHPriorityMask()
/// @brief \b Function  \b Description:  Set miu high priority mask
/// @param u8MiuDev     \b IN   : select MIU0 or MIU1
/// @param eClientID    \b IN   : Client ID
/// @param pInfo        \b OUT  : Client Info
/// @param None \b RET:   0: Fail 1: Ok
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_SetHPriorityMask(MS_U8 u8MiuDev, eMIUClientID eClientID, MS_BOOL bMask)
{
    return HAL_MIU_SetHPriorityMask(u8MiuDev, eClientID, bMask);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function  \b Name: _MDrv_MIU_SetGroupPriority()
/// @brief \b Function  \b Description:  This function for querying client ID info
/// @param u8MiuDev     \b IN   : select MIU0 or MIU1
/// @param eClientID    \b IN   : Client ID
/// @param pInfo        \b OUT  : Client Info
/// @param None \b RET:   0: Fail 1: Ok
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_SetGroupPriority(MS_U8 u8MiuDev, MIU_GroupPriority sPriority)
{
    return HAL_MIU_SetGroupPriority(u8MiuDev, sPriority);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: MDrv_MIU_Dram_Size()
/// @brief \b Function \b Description:  Write the DRAM size reg for MIU protect
/// @param MiuID        \b IN     : MIU ID
/// @param DramSize     \b IN     : Specified Dram size for MIU protect
/// @param <OUT>           \b None    :
/// @param <RET>           \b None    :
/// @param <GLOBAL>        \b None    :
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_Dram_Size(MS_U8 MiuID, MS_U8 DramSize)
{
    return HAL_MIU_Dram_Size(MiuID, DramSize);
}

MS_BOOL _MDrv_MIU_GetDramType(MIU_ID eMiu, MIU_DDR_TYPE* pType)
{
    return HAL_MIU_GetDramType(eMiu, pType);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: MDrv_MIU_IsSupportMIU1()
/// @brief \b Function \b Description:  This function for checking if support miu1
///
/// @param None \b RET:   TRUE: Support miu1 FALSE: no miu1
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_IsSupportMIU1(void)
{
      return HAL_MIU_IsInitMiu1();
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_Set_BW_Monitor()
/// @brief \b Function \b Description :  MIU Bandwidth monitor id set
/// @param u8MiuDev        \b IN      :  MIU Block to protect (0 ~ 3)
/// @param pBWInfo         \b IN      :  bandwidth information
///
/// @param <OUT>           \b None    :
/// @param <RET>           \b None    :
/// @param <GLOBAL>        \b None    :
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_Set_BW_Monitor(MS_U8 u8MiuDev, MIU_BandwidthMonitorInfo *pBWInfo)
{
    if(!HAL_MIU_Set_BW_Monitor(u8MiuDev, pBWInfo))
        return FALSE;
    else
        return TRUE;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_Del_BW_Monitor()
/// @brief \b Function \b Description :  MIU Bandwidth monitor id delete
/// @param u8MiuDev        \b IN      :  MIU Block to protect (0 ~ 3)
/// @param pBWInfo         \b IN      :  bandwidth information
///
/// @param <OUT>           \b None    :
/// @param <RET>           \b None    :
/// @param <GLOBAL>        \b None    :
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_Del_BW_Monitor(MS_U8 u8MiuDev, MIU_BandwidthMonitorInfo *pBWInfo)
{
    if(!HAL_MIU_Del_BW_Monitor(u8MiuDev, pBWInfo))
        return FALSE;
    else
        return TRUE;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_Query_BW_Monitor()
/// @brief \b Function \b Description :  Query MIU Bandwidth monitor id
/// @param u8MiuDev        \b IN      :  MIU Block to protect (0 ~ 3)
/// @param pBWInfo         \b IN      :  bandwidth information
///
/// @param <OUT>           \b None    :
/// @param <RET>           \b None    :
/// @param <GLOBAL>        \b None    :
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_Query_BW_Monitor(MS_U8 u8MiuDev, MIU_BandwidthMonitorInfo *pBWInfo)
{
    if(!HAL_MIU_Query_BW_Monitor(u8MiuDev, pBWInfo))
        return FALSE;
    else
        return TRUE;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_Get_BW()
/// @brief \b Function \b Description :  Get MIU Bandwidth info
/// @param u8MiuDev        \b IN      :  MIU Block to protect (0 ~ 3)
/// @param pBWInfo         \b IN      :  bandwidth information
///
/// @param <OUT>           \b None    :
/// @param <RET>           \b None    :
/// @param <GLOBAL>        \b None    :
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_Get_BW(MS_U8 u8MiuDev, MIU_BandwidthMonitorInfo *pBWInfo)
{
    if(!HAL_MIU_Get_BW(u8MiuDev, pBWInfo))
        return FALSE;
    else
        return TRUE;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_Get_BW()
/// @brief \b Function \b Description :  Get MIU Bandwidth info
/// @param u8MiuDev        \b IN      :  MIU Block to protect (0 ~ 3)
/// @param pBWInfo         \b IN      :  bandwidth information
///
/// @param <OUT>           \b None    :
/// @param <RET>           \b None    :
/// @param <GLOBAL>        \b None    :
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_Get_BW_All(MS_U8 u8MiuDev, MIU_BandwidthMonitorInfo *pBWInfo)
{
    if(!HAL_MIU_Get_BW_All(u8MiuDev, pBWInfo))
        return FALSE;
    else
        return TRUE;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_Reset_All_BW_Monitor()
/// @brief \b Function \b Description :  Reset MIU Bandwidth info
/// @param u8MiuDev        \b IN      :  MIU Block to protect (0 ~ 3)
///
/// @param <OUT>           \b None    :
/// @param <RET>           \b None    :
/// @param <GLOBAL>        \b None    :
////////////////////////////////////////////////////////////////////////////////

MS_BOOL _MDrv_MIU_Reset_All_BW_Monitor(MS_U8 u8MiuDev)
{
    if(!HAL_MIU_Reset_All_BW_Monitor(u8MiuDev))
        return FALSE;
    else
        return TRUE;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_Start_BW_Monitor()
/// @brief \b Function \b Description :  Reset MIU Bandwidth info
/// @param u8MiuDev        \b IN      :  MIU Block to protect (0 ~ 3)
///
/// @param <OUT>           \b None    :
/// @param <RET>           \b None    :
/// @param <GLOBAL>        \b None    :
////////////////////////////////////////////////////////////////////////////////

MS_BOOL _MDrv_MIU_Start_BW_Monitor(MS_U8 u8MiuDev)
{
    if(!HAL_MIU_Start_BW_Monitor(u8MiuDev))
        return FALSE;
    else
        return TRUE;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_ConfigHWAttr()
/// @brief \b Function \b Description :  HW Attribute for MIU Setting
/// @param u8MiuDev        \b IN      :  MIU Block to protect (0 ~ 3)
/// @param eAttrType       \b IN      :  Type of HW Attribute
/// @param u16Value        \b IN      :  Setting Values
/// @param u16Length       \b IN      :  Length of Setting Value
///
/// @param <OUT>           \b None    :
/// @param <RET>           \b None    :
/// @param <GLOBAL>        \b None    :
////////////////////////////////////////////////////////////////////////////////

MS_BOOL _MDrv_MIU_ConfigHWAttr(MS_U8 u8MiuDev, eMIU_ATTR_TYPE eAttrType, MS_U16 *u16Value, MS_U16 u16Length)
{
    if(!HAL_MIU_ConfigHWAttr(u8MiuDev, eAttrType, u16Value, u16Length))
        return FALSE;
    else
        return TRUE;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_SetSsc()
/// @brief \b Function \b Description: _MDrv_MIU_SetSsc, @Step & Span
/// @param u16Fmodulation   \b IN : 20KHz ~ 40KHz (Input Value = 20 ~ 40)
/// @param u16FDeviation    \b IN  : under 0.1% ~ 3% (Input Value = 1 ~ 30)
/// @param bEnable          \b IN    :
/// @param None             \b OUT  :
/// @param None             \b RET  :
/// @param None             \b GLOBAL :
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_SetSsc(MS_U16 u16Fmodulation,
                        MS_U16 u16FDeviation,
                        MS_BOOL bEnable)
{
    return HAL_MIU_SetSsc(0, u16Fmodulation, u16FDeviation, bEnable);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_SetSscValue()
/// @brief \b Function \b Description: _MDrv_MIU_SetSscValue, @Step & Span
/// @param u8Miu            \b IN   : 0: MIU0 1:MIU1
/// @param u16Fmodulation   \b IN   : 20KHz ~ 40KHz (Input Value = 20 ~ 40)
/// @param u16FDeviation    \b IN   : under 0.1% ~ 3% (Input Value = 1 ~ 30)
/// @param bEnable          \b IN   :
/// @param None             \b OUT  :
/// @param None             \b RET  :
/// @param None             \b GLOBAL :
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_SetSscValue(MS_U8 u8MiuDev,
                             MS_U16 u16Fmodulation,
                             MS_U16 u16FDeviation,
                             MS_BOOL bEnable)
{
    return HAL_MIU_SetSsc(u8MiuDev, u16Fmodulation, u16FDeviation, bEnable);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_SetClientUtilization()
/// @brief \b Function \b Description:_MDrv_MIU_SetClientUtilization, @eMIU & eClientID
/// @param eMIU             \b IN   : 0: MIU0 1:MIU1
/// @param eClientID        \b IN   : MIU Client ID
/// @param BOOL             \b OUT  :
/// @param None             \b RET  : TRUE or FAlSE
/// @param None             \b GLOBAL :
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_SetClientUtilization(MIU_ID eMIU, eMIUClientID eClientID)
{
    return HAL_MIU_SetClientLoading(eMIU, eClientID);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_GetClientUtilization()
/// @brief \b Function \b Description:_MDrv_MIU_GetClientUtilization, @eMIU & u32BWUtilization
/// @param eMIU             \b IN   : 0: MIU0 1:MIU1
/// @param u32BWUtilization \b OUT  : BW utilization value( millage rate )
/// @param None             \b RET  : TRUE or FAlSE
/// @param None             \b GLOBAL :
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_GetClientUtilization(MIU_ID eMIU, MS_U32 *u32BWUtilization)
{
    return HAL_MIU_GetClientLoading(eMIU, u32BWUtilization);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_SetClientEfficiency()
/// @brief \b Function \b Description:_MDrv_MIU_SetClientEfficiency, @eMIU & eClientID
/// @param eMIU             \b IN   : 0: MIU0 1:MIU1
/// @param eClientID        \b IN   : MIU Client ID
/// @param BOOL             \b OUT  :
/// @param None             \b RET  : TRUE or FAlSE
/// @param None             \b GLOBAL :
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_SetClientEfficiency(MIU_ID eMIU, eMIUClientID eClientID)
{
    return HAL_MIU_SetClientEfficiency(eMIU, eClientID);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: _MDrv_MIU_GetClientEfficiency()
/// @brief \b Function \b Description:_MDrv_MIU_GetClientEfficiency, @eMIU & u32BWUtilization
/// @param eMIU             \b IN   : 0: MIU0 1:MIU1
/// @param u32BWUtilization \b OUT  : BW efficiency value( millage rate )
/// @param None             \b RET  : TRUE or FAlSE
/// @param None             \b GLOBAL :
////////////////////////////////////////////////////////////////////////////////
MS_BOOL _MDrv_MIU_GetClientEfficiency(MIU_ID eMIU, MS_U32 *u32BWEfficiency)
{
    return HAL_MIU_GetClientEfficiency(eMIU, u32BWEfficiency);
}

MS_BOOL _MDrv_MIU_SetBWValue(MS_U32 u32ClientID, MIU_BW_TYPE eBWInfoType)
{
    return HAL_MIU_SetBWValue(u32ClientID, eBWInfoType);
}

MS_BOOL _MDrv_MIU_GetBWValue(MS_U32 u32ClientID, MIU_BW_TYPE eBWInfoType, MIU_UMA_Mode *eUMAMode, MIU_BWValue *BWValue)
{
    return HAL_MIU_GetBWValue(u32ClientID, eBWInfoType, eUMAMode, BWValue);
}

MS_BOOL _MDrv_MIU_GetMIUInfo(MIU_ID eMiu, MIU_Info* stMIUInfo)
{
    return HAL_MIU_GetMIUInfo(eMiu, stMIUInfo);
}

MS_BOOL _MDrv_MIU_SetCPUHPriority(MIU_HPri_Scope eScope, MS_U64 u64Start, MS_U64 u64End, MS_BOOL bEnable)
{
    return HAL_MIU_SetCPUHPriority(eScope, u64Start, u64End, bEnable);
}
#endif

// UTOPIA 2k ARCHITECTURE
#ifndef UTOPIAXP_REMOVE_WRAPPER
MS_BOOL MDrv_MIU_Init(void)
{
    if(NULL == pInstantMIU)
    {
        if(UtopiaOpen(MODULE_MIU, &pInstantMIU, 0, pAttributeMIU) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "MIU UtopiaOpen fail, maybe already initialized\n");
            return FALSE;
        }
    }

    if(UtopiaIoctl(pInstantMIU, MDrv_CMD_MIU_Init,(void*)NULL) != UTOPIA_STATUS_SUCCESS)
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_Init fail\n");
        return FALSE;
    }

    return TRUE;
    //return _MDrv_MIU_Init();
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function  \b Name: MDrv_MIU_Exit
/// @brief \b Function  \b Description: Exit MIU driver
/// @return             \b 0: Fail 1: OK
////////////////////////////////////////////////////////////////////////////////
MS_BOOL MDrv_MIU_Exit(void)
{
    if (pInstantMIU == NULL)
    {
        MIU_DEBUG_DBG(u32MIUDbgLevel, "MIU is not be initialized\n");
        return TRUE;
    }

    if(UtopiaClose(pInstantMIU) != UTOPIA_STATUS_SUCCESS)
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "close MIU fail\n");
        pInstantMIU = NULL;
        return FALSE;
    }

    pInstantMIU = NULL;

    return TRUE;
}

MS_BOOL MDrv_MIU_Protect( MS_U8 u8Blockx, MS_U8 *pu8ProtectId, MS_PHY phy64Start, MS_PHY phy64End, MS_BOOL bSetFlag )
{
    PMIU_PROTECT pMIUProtect;
    MS_BOOL bRet = TRUE;

    if (NULL != pInstantMIU)
    {
        pMIUProtect = (PMIU_PROTECT)malloc(sizeof(MIU_PROTECT));
        if (pMIUProtect == NULL)
            return FALSE;
        pMIUProtect->u8Blockx = u8Blockx;
        pMIUProtect->pu8ProtectId = pu8ProtectId;
        pMIUProtect->phy64Start = phy64Start;
        pMIUProtect->phy64End = phy64End;
        pMIUProtect->bSetFlag = bSetFlag;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_Protect,(void*)pMIUProtect) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_Protect fail\n");
            bRet = FALSE;
        }
        else
        {
            bRet = TRUE;
        }
        free(pMIUProtect);
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
        bRet = FALSE;
    }

    return bRet;
}

MS_BOOL MDrv_MIU_ProtectEx( MS_U8 u8Blockx, MS_U32 *pu32ProtectId, MS_PHY phy64Start, MS_PHY phy64End, MS_BOOL bSetFlag )
{
    PMIU_PROTECTEx pMIUProtect;

    if (NULL != pInstantMIU)
    {
        pMIUProtect = (PMIU_PROTECTEx)malloc(sizeof(MIU_PROTECTEx));
        if (pMIUProtect == NULL)
            return FALSE;
        pMIUProtect->u8Blockx = u8Blockx;
        pMIUProtect->pu32ProtectId = pu32ProtectId;
        pMIUProtect->phy64Start = phy64Start;
        pMIUProtect->phy64End = phy64End;
        pMIUProtect->bSetFlag = bSetFlag;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_ProtectEx,(void*)pMIUProtect) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_Protect fail\n");
            free(pMIUProtect);
            return FALSE;
        }
        free(pMIUProtect);
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
        return FALSE;
    }
    return TRUE;
}

MS_BOOL MDrv_MIU_ProtectAlign(MS_U32 *u32PageShift)
{
    PMIU_PROTECT_ALIGN pMIUProtectAlign = NULL;
    MS_BOOL bRet;

    if (NULL != pInstantMIU)
    {
        pMIUProtectAlign = (PMIU_PROTECT_ALIGN)malloc(sizeof(MIU_PROTECT_ALIGN));
        if(pMIUProtectAlign == NULL)
            return FALSE;
        pMIUProtectAlign->u32PageShift = u32PageShift;
        pMIUProtectAlign->bRet = FALSE;
        if(UtopiaIoctl(pInstantMIU, MDrv_CMD_MIU_ProtectAlign,(void*)pMIUProtectAlign) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_ProtectAlign fail\n");
            bRet = FALSE;
        }
        else
        {
            bRet = pMIUProtectAlign->bRet;
        }

        free(pMIUProtectAlign);
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
        bRet = FALSE;
    }

    return bRet;
}

MS_BOOL MDrv_MIU_GetProtectInfo(MS_U8 u8MiuDev, MIU_PortectInfo *pInfo)
{
    PMIU_GETPROTECTINFO pMIUGetProtectInfo;
    MS_BOOL bRet = TRUE;

    if (NULL != pInstantMIU)
    {
        pMIUGetProtectInfo = (PMIU_GETPROTECTINFO)malloc(sizeof(MIU_GETPROTECTINFO));
        if (pMIUGetProtectInfo == NULL)
            return FALSE;
        pMIUGetProtectInfo->u8MiuDev = u8MiuDev;
        pMIUGetProtectInfo->pInfo = pInfo;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_GetProtectInfo,(void*)pMIUGetProtectInfo) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_GetProtectInfo fail\n");
            bRet = FALSE;
        }
        else
        {
            bRet = TRUE;
        }
        free(pMIUGetProtectInfo);
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
        bRet = FALSE;
    }

    return bRet;
}

void  MDrv_MIU_PrintMIUProtectInfo(void)
{
    if (NULL != pInstantMIU)
    {
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_PrintProtectInfo,(void*)NULL) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_MIU_SetHPriorityMask fail\n");
            return;
        }
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
    }
    return;
}

MS_BOOL MDrv_MIU_SelMIU(eMIUClientID eClientID, eMIU_SelType eType)
{
    PMIU_SELMIU pMIUSelMIU;
    MS_BOOL bRet = TRUE;
    if (NULL != pInstantMIU)
    {
        pMIUSelMIU = (PMIU_SELMIU)malloc(sizeof(MIU_SELMIU));
        if (pMIUSelMIU == NULL)
            return FALSE;
        pMIUSelMIU->eClientID = eClientID;
        pMIUSelMIU->eType = eType;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_SelMIU,(void*)pMIUSelMIU) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_SelMIU fail\n");
            bRet = FALSE;
        }
        else
        {
            bRet = TRUE;
        }

        free(pMIUSelMIU);
    }
    else
    {
        MIU_DEBUG_DBG(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
        bRet = FALSE;
    }

    return bRet;
}

void _MDrv_MIU_MaskReqUtopia20IOCtrl(eMIUIoctlCmd eMIUIOCmd, MS_U8 u8Mask, MS_U8 u8Miu)
{
    PMIU_MIU_MASK pMIUMask;
    if (NULL != pInstantMIU)
    {
        pMIUMask = (PMIU_MIU_MASK)malloc(sizeof(MIU_MIU_MASK));
        if (pMIUMask == NULL)
            return;
        pMIUMask->u8Mask = u8Mask;
        pMIUMask->u8Miu = u8Miu;
        if(UtopiaIoctl(pInstantMIU,eMIUIOCmd,(void*)pMIUMask) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_Mask_Req fail in IP %d\n",eMIUIOCmd);
            free(pMIUMask);
            return;
        }
        free(pMIUMask);
    }
}

void MDrv_MIU_Mask_Req_OPM_R(MS_U8 u8Mask, MS_U8 u8Miu)
{
    // utopia20 flow code
    _MDrv_MIU_MaskReqUtopia20IOCtrl(MDrv_CMD_MIU_Mask_Req_OPM_R, u8Mask, u8Miu);
}

void MDrv_MIU_Mask_Req_DNRB_R(MS_U8 u8Mask, MS_U8 u8Miu)
{
    _MDrv_MIU_MaskReqUtopia20IOCtrl(MDrv_CMD_MIU_Mask_Req_DNRB_R, u8Mask, u8Miu);
}

void MDrv_MIU_Mask_Req_DNRB_W(MS_U8 u8Mask, MS_U8 u8Miu)
{
    _MDrv_MIU_MaskReqUtopia20IOCtrl(MDrv_CMD_MIU_Mask_Req_DNRB_W, u8Mask, u8Miu);
}

void MDrv_MIU_Mask_Req_DNRB_RW(MS_U8 u8Mask, MS_U8 u8Miu)
{
    _MDrv_MIU_MaskReqUtopia20IOCtrl(MDrv_CMD_MIU_Mask_Req_DNRB_RW, u8Mask, u8Miu);
}

void MDrv_MIU_Mask_Req_SC_RW(MS_U8 u8Mask, MS_U8 u8Miu)
{
    _MDrv_MIU_MaskReqUtopia20IOCtrl(MDrv_CMD_MIU_Mask_Req_SC_RW, u8Mask, u8Miu);
}

void MDrv_MIU_Mask_Req_MVOP_R(MS_U8 u8Mask, MS_U8 u8Miu)
{
    _MDrv_MIU_MaskReqUtopia20IOCtrl(MDrv_CMD_MIU_Mask_Req_MVOP_R, u8Mask, u8Miu);
}

void MDrv_MIU_Mask_Req_MVD_R(MS_U8 u8Mask, MS_U8 u8Miu)
{
    _MDrv_MIU_MaskReqUtopia20IOCtrl(MDrv_CMD_MIU_Mask_Req_MVD_R, u8Mask, u8Miu);
}

void MDrv_MIU_Mask_Req_MVD_W(MS_U8 u8Mask, MS_U8 u8Miu)
{
    _MDrv_MIU_MaskReqUtopia20IOCtrl(MDrv_CMD_MIU_Mask_Req_MVD_W, u8Mask, u8Miu);
}

void MDrv_MIU_Mask_Req_MVD_RW(MS_U8 u8Mask, MS_U8 u8Miu)
{
    _MDrv_MIU_MaskReqUtopia20IOCtrl(MDrv_CMD_MIU_Mask_Req_MVD_RW, u8Mask, u8Miu);
}

void MDrv_MIU_Mask_Req_AUDIO_RW(MS_U8 u8Mask, MS_U8 u8Miu)
{
    _MDrv_MIU_MaskReqUtopia20IOCtrl(MDrv_CMD_MIU_Mask_Req_AUDIO_RW, u8Mask, u8Miu);
}

void  MDrv_MIU_MaskReq(MS_U8 u8Miu, eMIUClientID eClientID)
{
    PMIU_MIUREQ_MASK pMIUMaskReq;

    if (NULL != pInstantMIU)
    {
        pMIUMaskReq = (PMIU_MIUREQ_MASK)malloc(sizeof(MIU_MIUREQ_MASK));
        if (pMIUMaskReq == NULL)
            return;
        pMIUMaskReq->u8Miu = u8Miu;
        pMIUMaskReq->eClientID = eClientID;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_Mask_Req,(void*)pMIUMaskReq) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_MIU_MaskReq fail\n");
            free(pMIUMaskReq);
            return;
        }
        free(pMIUMaskReq);
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
    }
}

void MDrv_MIU_UnMaskReq(MS_U8 u8Miu, eMIUClientID eClientID)
{
    PMIU_MIUREQ_MASK pMIUMaskReq;

    if (NULL != pInstantMIU)
    {
        pMIUMaskReq = (PMIU_MIUREQ_MASK)malloc(sizeof(MIU_MIUREQ_MASK));
        if (pMIUMaskReq == NULL)
            return;
        pMIUMaskReq->u8Miu = u8Miu;
        pMIUMaskReq->eClientID = eClientID;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_UnMask_Req,(void*)pMIUMaskReq) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_UnMask_Req fail\n");
            free(pMIUMaskReq);
            return;
        }
        free(pMIUMaskReq);
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
    }
}

MS_BOOL MDrv_MIU_SetHPriorityMask(MS_U8 u8MiuDev, eMIUClientID eClientID, MS_BOOL bMask)
{
    PMIU_SETHIGHPRIORITY pMIUSetHighPri;

    if (NULL != pInstantMIU)
    {
        pMIUSetHighPri = (PMIU_SETHIGHPRIORITY)malloc(sizeof(MIU_SETHIGHPRIORITY));
        if (pMIUSetHighPri == NULL)
            return FALSE;
        pMIUSetHighPri->u8MiuDev = u8MiuDev;
        pMIUSetHighPri->eClientID = eClientID;
        pMIUSetHighPri->bMask = bMask;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_SetHighPriority,(void*)pMIUSetHighPri) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_SetHighPriority fail\n");
            free(pMIUSetHighPri);
            return FALSE;
        }
        free(pMIUSetHighPri);
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
    }
    return TRUE;
}

MS_BOOL MDrv_MIU_SetGroupPriority(MS_U8 u8MiuDev, MIU_GroupPriority sPriority)
{
    PMIU_SETGROUPPRIORITY pMIUSetGroupPri;

    if (NULL != pInstantMIU)
    {
        pMIUSetGroupPri = (PMIU_SETGROUPPRIORITY)malloc(sizeof(MIU_SETGROUPPRIORITY));
        if (pMIUSetGroupPri == NULL)
            return FALSE;
        pMIUSetGroupPri->u8MiuDev = u8MiuDev;
        pMIUSetGroupPri->sPriority = sPriority;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_SetGroupPriority,(void*)pMIUSetGroupPri) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_SetGroupPriority fail\n");
            free(pMIUSetGroupPri);
            return FALSE;
        }
        free(pMIUSetGroupPri);
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
    }
    return TRUE;
}

MS_BOOL MDrv_MIU_Dram_Size(MS_U8 u8MiuDev, MS_U8 DramSize)
{
    PMIU_DRAM_SIZE pMIUDramSize = NULL;
    MS_BOOL bRet;

    if (NULL != pInstantMIU)
    {
        pMIUDramSize = (PMIU_DRAM_SIZE)malloc(sizeof(MIU_DRAM_SIZE));
        if (pMIUDramSize == NULL)
            return FALSE;
        pMIUDramSize->u8MiuDev = u8MiuDev;
        pMIUDramSize->DramSize = DramSize;
        pMIUDramSize->bRet = FALSE;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_Dram_Size,(void*)pMIUDramSize) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_Dram_Size fail\n");
            bRet = FALSE;
        }
        else
        {
            bRet = pMIUDramSize->bRet;
        }

        free(pMIUDramSize);
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
        bRet = FALSE;
    }

    return bRet;
}

MS_BOOL MDrv_MIU_GetDramType(MIU_ID eMiu, MIU_DDR_TYPE* pType)
{
    MIU_GETDRAMTYPE args;
    MS_BOOL bRet = TRUE;

    if (NULL != pInstantMIU)
    {
        args.eMiu = eMiu;
        args.pType = pType;

        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_GetDramType,(void*)&args) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_DBG(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_GetDramType fail\n");
            bRet = FALSE;
        }
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
        bRet = FALSE;
    }

    return bRet;
}

MS_BOOL MDrv_MIU_IsSupportMIU1(void)
{
    MS_BOOL bRet = TRUE;
    if(NULL != pInstantMIU)
    {
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_IsSupportMIU1,(void*)NULL) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_DBG(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_IsSupportMIU1 fail\n");
            bRet = FALSE;
        }
        else
        {
            bRet = TRUE;
        }
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
        bRet = FALSE;
    }
    return bRet;
}

MS_BOOL MDrv_MIU_Set_BW_Monitor(MS_U8 u8MiuDev, MIU_BandwidthMonitorInfo *pBWInfo)
{
    MS_BOOL bRet = TRUE;
    MIU_BWMONITOR SetBWMonitor;
    if (NULL != pInstantMIU)
    {
        SetBWMonitor.u8MiuDev = u8MiuDev;
        SetBWMonitor.pBWInfo = pBWInfo;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_SetBWMonitor,(void*)&SetBWMonitor) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_SetBWMonitor fail\n");
            bRet = FALSE;
        }
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
        bRet = FALSE;
    }
    return bRet;
}

MS_BOOL MDrv_MIU_Del_BW_Monitor(MS_U8 u8MiuDev, MIU_BandwidthMonitorInfo *pBWInfo)
{
    MS_BOOL bRet = TRUE;
    MIU_BWMONITOR SetBWMonitor;
    if (NULL != pInstantMIU)
    {
        SetBWMonitor.u8MiuDev = u8MiuDev;
        SetBWMonitor.pBWInfo = pBWInfo;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_DelBWMonitor,(void*)&SetBWMonitor) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_DelBWMonitor fail\n");
            bRet = FALSE;
        }
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
        bRet = FALSE;
    }
    return bRet;
}

MS_BOOL MDrv_MIU_Query_BW_Monitor(MS_U8 u8MiuDev, MIU_BandwidthMonitorInfo *pBWInfo)
{
    MS_BOOL bRet = TRUE;
    MIU_BWMONITOR SetBWMonitor;
    if (NULL != pInstantMIU)
    {
        SetBWMonitor.u8MiuDev = u8MiuDev;
        SetBWMonitor.pBWInfo = pBWInfo;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_QueryBWMonitor,(void*)&SetBWMonitor) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_QueryBWMonitor fail\n");
            bRet = FALSE;
        }
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
        bRet = FALSE;
    }
    return bRet;
}

MS_BOOL MDrv_MIU_Get_BW(MS_U8 u8MiuDev, MIU_BandwidthMonitorInfo *pBWInfo)
{
    MS_BOOL bRet = TRUE;
    MIU_BWMONITOR SetBWMonitor;
    if (NULL != pInstantMIU)
    {
        SetBWMonitor.u8MiuDev = u8MiuDev;
        SetBWMonitor.pBWInfo = pBWInfo;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_GetBW,(void*)&SetBWMonitor) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_DBG(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_GetBW fail\n");
            bRet = FALSE;
        }
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
        bRet = FALSE;
    }
    return bRet;
}

MS_BOOL MDrv_MIU_Get_BW_All(MS_U8 u8MiuDev, MIU_BandwidthMonitorInfo *pBWInfo)
{
    MS_BOOL bRet = TRUE;
    MIU_BWMONITOR SetBWMonitor;
    if (NULL != pInstantMIU)
    {
        SetBWMonitor.u8MiuDev = u8MiuDev;
        SetBWMonitor.pBWInfo = pBWInfo;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_GetBWAll,(void*)&SetBWMonitor) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_DBG(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_GetBWAll fail\n");
            bRet = FALSE;
        }
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
        bRet = FALSE;
    }
    return bRet;
}

MS_BOOL MDrv_MIU_Reset_All_BW_Monitor(MS_U8 u8MiuDev)
{
    MS_BOOL bRet = TRUE;
    MIU_BWMONITOR SetBWMonitor;
    if (NULL != pInstantMIU)
    {
        SetBWMonitor.u8MiuDev = u8MiuDev;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_ResetAllBWMonitor,(void*)&SetBWMonitor) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_ResetAllBWMonitor fail\n");
            bRet = FALSE;
        }
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
        bRet = FALSE;
    }
    return bRet;
}

MS_BOOL MDrv_MIU_Start_BW_Monitor(MS_U8 u8MiuDev)
{
    MS_BOOL bRet = TRUE;
    MIU_BWMONITOR SetBWMonitor;
    if (NULL != pInstantMIU)
    {
        SetBWMonitor.u8MiuDev = u8MiuDev;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_StartBWMonitor,(void*)&SetBWMonitor) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_StartBWMonitor fail\n");
            bRet = FALSE;
        }
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
        bRet = FALSE;
    }
    return bRet;
}

MS_BOOL MDrv_MIU_ConfigHWAttr(MS_U8 u8MiuDev, eMIU_ATTR_TYPE eAttrType, MS_U16 *u16Value, MS_U16 u16Length)
{
    MS_BOOL bRet = TRUE;
    MIU_ConfigHWAttr MIUConfigHWAttr;
    memset(&MIUConfigHWAttr,0,sizeof(MIU_ConfigHWAttr));

    if (NULL != pInstantMIU)
    {
        MIUConfigHWAttr.u8MiuDev = u8MiuDev;
        MIUConfigHWAttr.eAttrType = eAttrType;
        MIUConfigHWAttr.u16Value = u16Value;
        MIUConfigHWAttr.u16Length = u16Length;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_ConfigHWAttr,(void*)&MIUConfigHWAttr) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_ConfigHWAttr fail\n");
            bRet = FALSE;
        }
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
        bRet = FALSE;
    }
    return bRet;
}

MS_BOOL MDrv_MIU_SetSsc(MS_U16 u16Fmodulation, MS_U16 u16FDeviation,MS_BOOL bEnable)
{
    PMIU_SET_SSC pMIUSetSsc;
    MS_BOOL bRet = TRUE;

    if (NULL != pInstantMIU)
    {
        pMIUSetSsc = (PMIU_SET_SSC)malloc(sizeof(MIU_SET_SSC));
        if (pMIUSetSsc == NULL)
            return FALSE;
        pMIUSetSsc->u16Fmodulation = u16Fmodulation;
        pMIUSetSsc->u16FDeviation = u16FDeviation;
        pMIUSetSsc->bEnable = bEnable;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_SetSsc,(void*)pMIUSetSsc) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_SetSsc fail\n");
            bRet = FALSE;
        }
        else
        {
            bRet = TRUE;
        }
        free(pMIUSetSsc);
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
    }

    return bRet;
}

MS_BOOL MDrv_MIU_SetSscValue(MS_U8 u8MiuDev, MS_U16 u16Fmodulation, MS_U16 u16FDeviation, MS_BOOL bEnable)
{
    PMIU_SET_SSCVALUE pMIUSetSscValue;
    MS_BOOL bRet = TRUE;

    if (NULL != pInstantMIU)
    {
        pMIUSetSscValue = (PMIU_SET_SSCVALUE)malloc(sizeof(MIU_SET_SSCVALUE));
        if (pMIUSetSscValue == NULL)
            return FALSE;
        pMIUSetSscValue->u8MiuDev = u8MiuDev;
        pMIUSetSscValue->u16Fmodulation = u16Fmodulation;
        pMIUSetSscValue->u16FDeviation = u16FDeviation;
        pMIUSetSscValue->bEnable = bEnable;
        if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_SetSscValue,(void*)pMIUSetSscValue) != UTOPIA_STATUS_SUCCESS)
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "Ioctl MDrv_CMD_MIU_SetSscValue fail\n");
            bRet = FALSE;
        }
        else
        {
            bRet = TRUE;
        }
        free(pMIUSetSscValue);
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
        bRet = FALSE;
    }

    return bRet;
}

MS_BOOL MDrv_MIU_SetClientUtilization(MIU_ID eMIU, eMIUClientID eClientID)
{
    MS_BOOL bRet = TRUE;
    MIU_BWUTILIZATION setUtil;
    setUtil.u8MiuDev = eMIU;
    setUtil.eClientID = eClientID;
    if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_SetClientUtilization,(void*)&setUtil) != UTOPIA_STATUS_SUCCESS)
    {
        ULOGE(TAG_MIU, "Ioctl MDrv_CMD_MIU_SetClientUtilization fail\n");
        bRet = FALSE;
    }
    return bRet;
//    return HAL_MIU_SetClientLoading(eMIU, eClientID);
}

MS_BOOL MDrv_MIU_GetClientUtilization(MIU_ID eMIU, MS_U32 *u32BWUtilization)
{

    MS_BOOL bRet = TRUE;
    MIU_BWUTILIZATION getUtil;
    getUtil.u8MiuDev = eMIU;
    getUtil.pu32BWUtilization = u32BWUtilization;
    if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_GetClientUtilization,(void*)&getUtil) != UTOPIA_STATUS_SUCCESS)
    {
        ULOGE(TAG_MIU, "Ioctl MDrv_CMD_MIU_SetClientUtilization fail\n");
        bRet = FALSE;
    }
    return bRet;

//    return HAL_MIU_GetClientLoading(eMIU, u32BWUtilization);
}

MS_BOOL MDrv_MIU_SetClientEfficiency(MIU_ID eMIU, eMIUClientID eClientID)
{
    MS_BOOL bRet = TRUE;
    MIU_BWEFFICIENCY setEffi;
    setEffi.u8MiuDev = eMIU;
    setEffi.eClientID = eClientID;
    if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_SetClientEfficiency,(void*)&setEffi) != UTOPIA_STATUS_SUCCESS)
    {
        ULOGE(TAG_MIU, "Ioctl MDrv_CMD_MIU_SetClientUtilization fail\n");
        bRet = FALSE;
    }
    return bRet;

//    return HAL_MIU_SetClientEfficiency(eMIU, eClientID);
}

MS_BOOL MDrv_MIU_GetClientEfficiency(MIU_ID eMIU, MS_U32 *u32BWEfficiency)
{
    MS_BOOL bRet = TRUE;
    MIU_BWEFFICIENCY getEffi;
    getEffi.u8MiuDev = eMIU;
    getEffi.pu32BWEfficiency = u32BWEfficiency;
    if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_GetClientEfficiency,(void*)&getEffi) != UTOPIA_STATUS_SUCCESS)
    {
        ULOGE(TAG_MIU, "Ioctl MDrv_CMD_MIU_SetClientUtilization fail\n");
        bRet = FALSE;
    }
    return bRet;

//    return HAL_MIU_GetClientEfficiency(eMIU, u32BWEfficiency);
}

MS_BOOL MDrv_MIU_SetBWValue(MS_U32 u32ClientID, MIU_BW_TYPE eBWInfoType)
{
    MS_BOOL bRet = TRUE;
    MIU_SETGETBW setMIUBW;
    setMIUBW.u32ClientID = u32ClientID;
    setMIUBW.eBWINfoType = eBWInfoType;
    if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_SetBWValue,(void*)&setMIUBW) != UTOPIA_STATUS_SUCCESS)
    {
        ULOGE(TAG_MIU, "Ioctl MDrv_CMD_MIU_SetBWValue fail\n");
        bRet = FALSE;
    }
    return bRet;
}

MS_BOOL MDrv_MIU_GetBWValue(MS_U32 u32ClientID, MIU_BW_TYPE eBWInfoType, MIU_UMA_Mode *eUMAMode, MIU_BWValue *BWValue)
{
    MS_BOOL bRet = TRUE;
    MIU_SETGETBW getMIUBW;
    getMIUBW.u32ClientID = u32ClientID;
    getMIUBW.eBWINfoType = eBWInfoType;
    getMIUBW.peUMAMode = eUMAMode;
    getMIUBW.pBWValue = BWValue;
    if(UtopiaIoctl(pInstantMIU,MDrv_CMD_MIU_GetBWValue,(void*)&getMIUBW) != UTOPIA_STATUS_SUCCESS)
    {
        ULOGE(TAG_MIU, "Ioctl MDrv_CMD_MIU_GetBWValue fail\n");
        bRet = FALSE;
    }
    return bRet;
}

MS_BOOL MDrv_MIU_GetMIUInfo(MIU_ID eMiu, MIU_Info* stMIUInfo)
{
    MS_BOOL bRet = TRUE;
    MIU_GETINFO getMIUInfo;
    if( stMIUInfo == NULL )
    {
        ULOGE(TAG_MIU, "stMIUInfo is NULL\n");
        return FALSE;
    }
    getMIUInfo.eMiu = eMiu;
    getMIUInfo.pstMIUInfo = stMIUInfo;
    if(UtopiaIoctl(pInstantMIU, MDrv_CMD_MIU_GetMIUInfo, (void*)&getMIUInfo) != UTOPIA_STATUS_SUCCESS)
    {
        ULOGE(TAG_MIU, "Ioctl MDrv_CMD_MIU_GetMIUInfo fail\n");
        bRet = FALSE;
    }
    return bRet;
}

MS_BOOL MDrv_MIU_SetCPUHPriority(MIU_HPri_Scope eScope, MS_U64 u64Start, MS_U64 u64End, MS_BOOL bEnable)
{
    MS_BOOL bRet = TRUE;
    PMIU_SETCPUHPRI pMIUSetCPUHPri;

    if (NULL != pInstantMIU)
    {
        pMIUSetCPUHPri = (PMIU_SETCPUHPRI)malloc(sizeof(MIU_SETCPUHPRI));
        if(pMIUSetCPUHPri == NULL)
            return FALSE;
        pMIUSetCPUHPri->eScope = eScope;
        pMIUSetCPUHPri->u64Start = u64Start;
        pMIUSetCPUHPri->u64End = u64End;
        pMIUSetCPUHPri->bEnable = bEnable;
        if(UtopiaIoctl(pInstantMIU, MDrv_CMD_MIU_SetCPUHPriority, (void*)pMIUSetCPUHPri) != UTOPIA_STATUS_SUCCESS)
        {
            ULOGE(TAG_MIU, "Ioctl MDrv_CMD_MIU_SetCPUHPriority fail\n");
            bRet = FALSE;
        }
        free(pMIUSetCPUHPri);
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "NULL pInstantMIU, MIU Utopia not Open yet\n");
        bRet = FALSE;
    }
    return bRet;
}

#endif
// UTOPIA 2k ARCHITECTURE

// NON UTOPIA 2k ARCHITECTURE
////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: MDrv_MIU_GetDefaultClientID_KernelProtect()
/// @brief \b Function \b Description:  Get default client id array pointer for protect kernel
/// @param <RET>           \b     : The pointer of Array of client IDs
////////////////////////////////////////////////////////////////////////////////
MS_U8* MDrv_MIU_GetDefaultClientID_KernelProtect(void)
{
    return HAL_MIU_GetDefaultClientID_KernelProtect();
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: MDrv_MIU_Dram_ReadSize()
/// @brief \b Function \b Description:  Read the DRAM size
/// @param MiuID        \b IN     : MIU ID
/// @param DramSize     \b IN     :  Dram size for MIU protect
/// @param <OUT>           \b None    :
/// @param <RET>           \b None    :
/// @param <GLOBAL>        \b None    :
////////////////////////////////////////////////////////////////////////////////
MS_BOOL MDrv_MIU_Dram_ReadSize(MS_U8 MiuID, MIU_DDR_SIZE *pDramSize)
{
    return HAL_MIU_Dram_ReadSize(MiuID, pDramSize);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: MDrv_MIU_GetBusWidth()
/// @brief \b Function \b Description:  This function for querying data bus width
///
/// @param None \b RET:   0: not support or 64 or 128 bits
////////////////////////////////////////////////////////////////////////////////
MS_U16 MDrv_MIU_GetBusWidth(void)
{
    return HAL_MIU_IsI64Mode();
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: MDrv_MIU_ClinetNumber()
/// @brief \b Function \b Description:  Get the number of clients for specific MIU block
/// @param DramSize     \b IN     : MIU Block to protect (0 ~ 3)
/// @param <OUT>           \b None    :
/// @param <RET>           \b None    :
/// @param <GLOBAL>        \b None    :
////////////////////////////////////////////////////////////////////////////////
MS_U8 MDrv_MIU_ClinetNumber(MS_U8 u8Blockx)
{
    return HAL_MIU_ClinetNumber(u8Blockx);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function  \b Name: MDrv_MIU_GetClientWidth
/// @brief \b Function  \b Description: Get MIU client bus width
/// @param u8MiuDev     \b IN   : select MIU0 or MIU1
/// @param eClientID    \b IN   : client ID
/// @param pClientWidth \b IN   : client bus width
/// @return             \b 0 : Fail  1: OK
////////////////////////////////////////////////////////////////////////////////
MS_BOOL MDrv_MIU_GetClientWidth(MS_U8 u8MiuDevi, eMIUClientID eClientID, eMIU_ClientWidth *pClientWidth)
{
    return HAL_MIU_GetClientWidth(u8MiuDevi, eClientID, pClientWidth);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function  \b Name: MDrv_MIU_GetClientInfo()
/// @brief \b Function  \b Description:  This function for querying client ID info
/// @param u8MiuDev     \b IN   : select MIU0 or MIU1
/// @param eClientID    \b IN   : Client ID
/// @param pInfo        \b OUT  : Client Info
/// @param None \b RET:   0: Fail 1: Ok
////////////////////////////////////////////////////////////////////////////////
MS_BOOL MDrv_MIU_GetClientInfo(MS_U8 u8MiuDev, eMIUClientID eClientID, MIU_ClientInfo *pInfo)
{
    MS_S16 sVal;
    if (!pInfo)
        return FALSE;

    sVal = HAL_MIU_GetClientInfo(u8MiuDev, eClientID);
    if (sVal < 0)
        return FALSE;
    pInfo->u8BitPos = (MS_U8)MIU_GET_CLIENT_POS(sVal);
    pInfo->u8Gp = (MS_U8)MIU_GET_CLIENT_GROUP(sVal);
    return TRUE;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: MDrv_MIU_InitCounter()
/// @brief \b Function \b Description:  This function clear all request mask counter of
///                                     MIU driver
/// @param None \b IN:
/// @param None \b RET:
////////////////////////////////////////////////////////////////////////////////
void MDrv_MIU_InitCounter(void)
{
    MS_U8 i;

    for(i=0;i<MIU_CLIENT_MAX;i++)
    {
        MIU0_request_mask_count[i]=0;
        MIU1_request_mask_count[i]=0;
    }
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function \b Name: MDrv_MIU_SwitchMIU()
/// @brief \b Function \b Description:  This function for switch miu
///
/// @param u8MiuID        \b IN     : select MIU0 or MIU1
/// @param None \b RET:
////////////////////////////////////////////////////////////////////////////////
void MDrv_MIU_SwitchMIU(MS_U8 u8MiuID)
{
    HAL_MIU_VOP_SwitchMIU(u8MiuID);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function  \b Name: MDrv_MIU_GetLibVer
/// @brief \b Function  \b Description: Show the MIU driver version
/// @param ppVersion    \b Out: Library version string
/// @return             \b 0: Fail 1: Ok
////////////////////////////////////////////////////////////////////////////////
MS_BOOL MDrv_MIU_GetLibVer(const MSIF_Version **ppVersion)
{
    if (!ppVersion)
        return FALSE;

    *ppVersion = &_drv_miu_version;
    return TRUE;
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function  \b Name: MDrv_MIU_EnableScramble
/// @brief \b Function  \b Description: Enable MIU Scramble
/// @param bEnable      \b In: Enable MIU Scramble
/// @return             \b 0: Fail 1: Ok
////////////////////////////////////////////////////////////////////////////////
MS_BOOL MDrv_MIU_EnableScramble(MS_BOOL bEnable)
{
    return HAL_MIU_EnableScramble(bEnable);
}

////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function  \b Name: MDrv_MIU_IsScrambleEnabled
/// @brief \b Function  \b Description: Check if the MIU Scramble enabled
/// @return             \b 0: Disabled 1: Enabled
////////////////////////////////////////////////////////////////////////////////
MS_BOOL MDrv_MIU_IsScrambleEnabled(void)
{
    return HAL_MIU_IsScrambleEnabled();
}

#ifdef _MIU_INTERNEL_USE
////////////////////////////////////////////////////////////////////////////////
/// @brief \b Function  \b Name: MDrv_MIU_GetLoading
/// @brief \b Function  \b Description: Get the percentage of MIU loading
/// @param u8MiuDev     \b IN   : select MIU0 or MIU1
/// @param *Loading     \b IN   : percentage of MIU loading
/// @return             \b 0: Fail 1: OK
////////////////////////////////////////////////////////////////////////////////
MS_BOOL MDrv_MIU_GetLoading(MS_U8 u8MiuDev, MS_U32 *u32Loading)
{
    HAL_MIU_SetLoadingRequest(u8MiuDev);

    MsOS_DelayTask(1000);

    HAL_MIU_GetLoadingRequest(u8MiuDev, u32Loading);

    return TRUE;
}
#endif

MS_BOOL MDrv_MIU_SetDbgLevel(MIU_DBGLV eDBGLV)
{
    switch(eDBGLV)
    {
        case E_MIU_DBGLV_NONE:
            MIU_DEBUG_PRI(u32MIUDbgLevel, "MIU SET DEBUG LEVEL : CAN NOT CLOSE ALL DEBUG LOG\n");
            MIU_DEBUG_PRI(u32MIUDbgLevel, "MIU SET DEBUG LEVEL E_MIU_DBGLV_ERROR\n");
            u32MIUDbgLevel = E_MIU_DBGLV_ERROR;
            break;
        case E_MIU_DBGLV_ERROR:
            MIU_DEBUG_PRI(u32MIUDbgLevel, "MIU SET DEBUG LEVEL E_MIU_DBGLV_ERROR\n");
            u32MIUDbgLevel = E_MIU_DBGLV_ERROR;
            break;
        case E_MIU_DBGLV_DEBUG:
            MIU_DEBUG_PRI(u32MIUDbgLevel, "MIU SET DEBUG LEVEL E_MIU_DBGLV_DEBUG\n");
            u32MIUDbgLevel = E_MIU_DBGLV_DEBUG;
            break;
        case E_MIU_DBGLV_INFO:
            MIU_DEBUG_PRI(u32MIUDbgLevel, "MIU SET DEBUG LEVEL E_MIU_DBGLV_INFO\n");
            u32MIUDbgLevel = E_MIU_DBGLV_INFO;
            break;
        case E_MIU_DBGLV_ALL:
            MIU_DEBUG_PRI(u32MIUDbgLevel, "MIU SET DEBUG LEVEL E_MIU_DBGLV_ALL\n");
            u32MIUDbgLevel = E_MIU_DBGLV_ALL;
            break;
        default:
            MIU_DEBUG_ERR(u32MIUDbgLevel, "MIU SET DEBUG LEVEL : Error Debug Level Enum\n");
            return FALSE;
    }
    return TRUE;
}

MS_U32 MDrv_MIU_GetModuleClient(MIU_ID eMiu, MIU_IP_Module eMiuModule, MS_U32 **u32ModuleClient)
{
    return HAL_MIU_GetModuleClient(eMiu, eMiuModule, u32ModuleClient);
}

// NON UTOPIA 2k ARCHITECTURE

MS_U32 MDrv_MIU_SetPowerState(EN_POWER_MODE u16PowerState)
{
    static EN_POWER_MODE u16PreMIUPowerState = E_POWER_MECHANICAL;
    MS_U32 u32Return = UTOPIA_STATUS_FAIL;

    // Only do things in Kernel Mode
    if(!MsOS_KernelMode(MODULE_MIU,FALSE))
    {
        MIU_DEBUG_DBG(u32MIUDbgLevel, "Do Nothing: %d\n",u16PowerState);
        return UTOPIA_STATUS_SUCCESS;//Do nothing
    }

    if (u16PowerState == E_POWER_SUSPEND)
    {
        u16PreMIUPowerState = u16PowerState;
        u32Return = UTOPIA_STATUS_SUCCESS;//SUSPEND_OK;
    }
    else if (u16PowerState == E_POWER_RESUME)
    {
        if (u16PreMIUPowerState == E_POWER_SUSPEND)
        {
            MDrv_MIU_Init();

            u16PreMIUPowerState = u16PowerState;
            u32Return = UTOPIA_STATUS_SUCCESS;//RESUME_OK;
        }
        else
        {
            MIU_DEBUG_ERR(u32MIUDbgLevel, "It is not suspended yet. We shouldn't resume\n");
            u32Return = UTOPIA_STATUS_FAIL;//SUSPEND_FAILED;
        }
    }
    else
    {
        MIU_DEBUG_ERR(u32MIUDbgLevel, "Do Nothing: %d\n", u16PowerState);
        u32Return = UTOPIA_STATUS_FAIL;
    }

    return u32Return;// for success
}

MS_BOOL MDrv_MIU_GetSWClientInfo(MIU_ID eMIU, MS_U64 *pu64HWClientID, MS_U32 u32HWClientIDNumber)
{
    return HAL_MIU_GetSWClientInfo(eMIU, pu64HWClientID, u32HWClientIDNumber);
}

#ifdef CONFIG_UTOPIA_PROC_DBG_SUPPORT
static char *strMIUSetPara[] = {
/*0  Information*/              "info",
/*1  MIU device*/               "miu=",
/*2  Protect block*/            "blk=",
/*3  Protect start address*/    "saddr=",
/*4  Protect end address*/      "eaddr=",
/*5  Enable(1) or Disable(0)*/  "attr=",
/*6  MIU client group*/         "g=",
/*7  BW count*/                 "c=",
/*8  BW IP module*/             "m=",
/*9  BW advance information*/   "adv=",
/*10 BWTime of BW Monitor ARB3.0 update frequency*/ "t=",
/*11 BW Monitor ARB3.0 monitor channel*/            "ch=",
/*12 MIU log level*/            "dbg="};

// adv option BIT present
// v2:
//  BIT 0: Show IP's ID BW value(avg)
//  BIT 1: Show each count result
// v3:
//  BIT 0: Show module use which monitor
//  BIT 1: Show BW raw data, BW and Occupy
//  BIT 2: Show each monitor result(AVG and MAX)
//  BIT 3: Show each monitor of each count result
//  BIT 4: Enable Monitor AREA
//  BIT15: Show IPs' ID of each module

static char *strMIUSetArray[] = {
/*0*/   "cid=0x"};

static MS_U32 u32MIUSetValue[sizeof(strMIUSetPara)/sizeof(strMIUSetPara[0])] = {0};
#define ParaNum_MIUProtect (6)
#define ParaNum_MIUMask (2)
#define CmdCnt (MIU_MAX_PROTECT_ID+ParaNum_MIUProtect)
#define StringSize (256)
#define MIU_MAX_Module (E_MIU_MODULE_DISPLAY+1)
static MS_U64 str2num[CmdCnt] = {0};
static char pIPModuleName[StringSize+1];
static char pIPModuleNames[MIU_MAX_Module][StringSize+1];
static MS_U32 *u32MIUModuleClient;
static MS_U32 u32BWMonitorSingleIDs[MIU_MAX_BW_MONITOR_GP_CLIENT_NUMBER_ALL];
static MS_U32 u32AllClient[1] = {0x0};
static MS_BOOL bSetBWMonChannel;
static MS_U64 u64HWClientID[1] = {0x0};

static MS_BOOL MDrv_MIU_GetChipInfo(MIU_ChipInfoHandle *pu32ChipInfo)
{
    return HAL_MIU_GetChipInfo(pu32ChipInfo);
}

static void MDrv_MIU_PROCPrintHelp(MDBCMD_CMDLINE_PARAMETER *paraCmdLine, EN_MIU_MDBCMDLINE eMdbCmdLine)
{
    switch(eMdbCmdLine)
    {
    /* Help */
        case MIU_MDBCMDLINE_HELP:
            MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU echo help---------\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"MIU ProcFS options:\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"echo miu_protect info > /proc/utopia_mdb/miu\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"echo miu_select info > /proc/utopia_mdb/miu\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"echo miu_mask info > /proc/utopia_mdb/miu\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"echo miu_BW status info > /proc/utopia_mdb/miu\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"echo miu_BW v1 info > /proc/utopia_mdb/miu\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"echo miu_BW v2 info > /proc/utopia_mdb/miu\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"echo miu_BW v3 info > /proc/utopia_mdb/miu\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"echo ddr_phase err_check info > /proc/utopia_mdb/miu\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"echo ddr_phase dram_size info > /proc/utopia_mdb/miu\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"echo ddr_phase dram_clock info > /proc/utopia_mdb/miu\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"echo dbg_level info > /proc/utopia_mdb/miu\n");
            break;
        case MIU_MDBCMDLINE_MIU_PROTECT:
            MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU Protect help---------\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"Usage: echo miu_protect [OPTIONS] > /proc/utopia_mdb/miu\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"*: Necessary. #: Optional. $: Choose one.\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"blk(*)\tblock  Select which protect block want to use\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"saddr(*)\tstart address  Set protect start address, need to be 4k alignment\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"eaddr(*)\tend address    Set protect end address, need to be 4k alignment\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"attr(*)\tattribute   1: enable protect block to protect write. 0: disable protect block\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"cid(#)\tclient id  Set client id for which can access protect block\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"---------------------------------------\n\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"$echo miu_protect > /proc/utopia_mdb/miu can show protect status\n");
            break;
        case MIU_MDBCMDLINE_MIU_SELECT:
            MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU Select help---------\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"(Show information only)\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"Usage: echo miu_select [OPTIONS] > /proc/utopia_mdb/miu\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"*: Necessary. #: Optional. $: Choose one.\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"g(*)\tgroup  Select which MIU client group want to show select information\n");
            break;
        case MIU_MDBCMDLINE_MIU_MASK:
            MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU Mask help---------\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"Usage: echo miu_mask [OPTIONS] > /proc/utopia_mdb/miu\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"*: Necessary. #: Optional. $: Choose one.\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"Show mask information\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"m(*)\tmiu  Select which MIU device want to show mask information\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"g(*)\tgroup  Select which MIU client group want to show mask information\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"Set mask\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"m(*)\tmiu  Select which MIU device want to show mask information\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"attr(*)\tattribute  1: mask client ID. 0: Unmask client ID.\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"cid(*)\tclient id  client id you want to mask, 0x0~0xFF, only one client id in one time\n");
            break;
        case MIU_MDBCMDLINE_MIU_BANDWIDTH_BANKINFO:
            MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU Bandwidth info. help---------\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"---------Not Yet Support---------\n");
            break;
        case MIU_MDBCMDLINE_MIU_BANDWIDTH_LOADING:
            MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU Bandwidth Monitor ARB1.0/2.0 help---------\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"Usage: echo miu_BW v2 [OPTIONS] > /proc/utopia_mdb/miu\n\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"Monitor Bandwidth\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"*: Necessary. #: Optional. $: Choose one.\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\tc(*)    COUNT     The number of times of monitoring, the result will be averaged by this count.\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\tm(*)    MODULE    Module name. Use up to 1 monitors at a time.\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t\tSupport Module : ALL CPU GPU XC MVOP MEMC GOP OD HDR\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t\t                 AUDIO AUDIOEN AUDIODE VDEC VDECR2\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t\t                 GE DIP VE MFDEC BIST\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\tadv(#)  ADVANCE   advance option\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t\tBIT 0(1)  : Show IP's ID BW value(avg)\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t\tBIT 1(2)  : Show each count result\n");
            break;
        case MIU_MDBCMDLINE_MIU_BW_MONITOR_ARB3:
            MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU Bandwidth Monitor ARB3.0 help---------\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"Usage: echo miu_BW v3 [OPTIONS] > /proc/utopia_mdb/miu\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"Monitor Bandwidth\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"*: Necessary. #: Optional. $: Choose one.\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\tc(*)    COUNT     The number of times of monitoring, the result will be averaged by this count.\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\tm(*$)   MODULE    Module name(Occupancy monitor quantity). Use up to 8 monitors at a time.\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t\tSupport Module : ALL(1) CPU(1) GPU(1) XC(2) MVOP(1) MEMC(2) GOP(1) OD(1) HDR(1)\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t\t                 AUDIO(2) AUDIOEN(1) AUDIODE(1) VDEC(2) VDECR2(1)\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t\t                 GE(1) DIP(1) VE(1) MFDEC(1) BIST(1)\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\tcid(*$) CLIENT_ID Client id\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t\tSupport Client ID : 0x00 - 0xFF. Up to 8 at a time.\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\tch(#)   CHANNEL   Select monitor channel. Monitor all channels without value.\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\tt(#)    TIME      Monitoring unit(ms)\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\tadv(#)  ADVANCE   advance option\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t\tBIT 0(1)  : Show module use which monitor\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t\tBIT 1(2)  : Show BW raw data, BW and Occupy\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t\tBIT 2(4)  : Show each monitor result(AVG and MAX)\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t\tBIT 3(8)  : Show each monitor of each count result\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t\tBIT 4(16) : Enable Monitor AREA\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t\tBIT 5(32) : Monitor all module in all channel\n");
            break;
        case MIU_MDBCMDLINE_MIU_DDR_PHASE_ERR_CHECK:
            MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU DDR phase error check help---------\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"Usage: echo ddr_phase err_check > /proc/utopia_mdb/miu\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"Show DRAM sboot error check value\n\n");
            break;
        case MIU_MDBCMDLINE_MIU_DRAMSIZE:
            MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU DDR phase dram size help---------\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"Usage: echo ddr_phase dram_size > /proc/utopia_mdb/miu\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"Show DRAM size\n\n");
            break;
        case MIU_MDBCMDLINE_MIU_DRAMCLOCK:
            MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU DDR phase dram clock help---------\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"Usage: echo ddr_phase dram_clock > /proc/utopia_mdb/miu\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"Show DRAM clock\n\n");
            break;
        case MIU_MDBCMDLINE_MIU_SET_DBG_LEVEL:
            MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU set debug level help---------\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"Usage: echo dbg_level [OPTIONS] > /proc/utopia_mdb/miu\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"*: Necessary. #: Optional. $: Choose one.\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\tdbg(*)    DEBUGLOG    set UTPA debug log level\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t          0: E_MIU_DBGLV_NONE\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t          1: E_MIU_DBGLV_ERROR\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t          2: E_MIU_DBGLV_DEBUG\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t          3: E_MIU_DBGLV_INFO\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"\t          4: E_MIU_DBGLV_ALL\n");
            break;
        default:
            MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU---------\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"No have this cmd!\nPlease use 'echo help > /proc/utopia_mdb/miu' get cmdline!\n");
            break;
    }
    return;
}

static void MDrv_MIU_PROCPrintProtectInfo(MDBCMD_CMDLINE_PARAMETER *paraCmdLine, MIU_ChipInfoHandle *pChipInfo)
{
    MS_U32 u32MIUdevce, u32MIUProtectId, u32MIUProtectBlock;
    MS_U8 u8BlockGroup = 0;
    MIU_ProtectInfoHandle *pProtectInfo;
    pProtectInfo = (MIU_ProtectInfoHandle*)malloc(sizeof(MIU_ProtectInfoHandle));
    if(pProtectInfo == NULL)
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"[PROC ERROR][malloc fail]\n");
        return;
    }
    memset(pProtectInfo,0,sizeof(MIU_ProtectInfoHandle));
    for( u32MIUdevce = 0; u32MIUdevce < MIU_MAX_DEVICE; u32MIUdevce++)
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU%d protect Info---------\n", u32MIUdevce);
        if(HAL_MIU_MDBGetProtectInfo((MIU_ID)u32MIUdevce, pProtectInfo) == FALSE)
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"Not Suppurt MIU%d!\n", u32MIUdevce);
            free(pProtectInfo);
            return;
        }
        for ( u32MIUProtectBlock = 0; u32MIUProtectBlock < MIU_MAX_PROTECT_BLOCK; u32MIUProtectBlock ++)
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"\nProtect block [%d]\n", u32MIUProtectBlock);
            MdbPrint(paraCmdLine->u64ReqHdl,"Protect Enable[%d]\n", (pProtectInfo->ProtectAttribute >> u32MIUProtectBlock & BIT0));
            MdbPrint(paraCmdLine->u64ReqHdl,"Protect ragne [0x%lx - 0x%lx]\n", (unsigned int)(long)(pProtectInfo->ProtectAddrStart[u32MIUProtectBlock]<<MIU_PAGE_SHIFT), (unsigned int)(long)((pProtectInfo->ProtectAddrEnd[u32MIUProtectBlock]+1)<<MIU_PAGE_SHIFT));
            MdbPrint(paraCmdLine->u64ReqHdl,"Enable Access ID:\n");
            if(pChipInfo->Protect_Version == 2)
                u8BlockGroup = pProtectInfo->ProtectBlockGroup[u32MIUProtectBlock];
            for( u32MIUProtectId = 0; u32MIUProtectId < MIU_MAX_PROTECT_ID ; u32MIUProtectId++)
            {
                if(pProtectInfo->WhiteListEnable[u32MIUProtectBlock][u32MIUProtectId] == 1)
                {
                    MS_U8 u8BlockGroup = pProtectInfo->ProtectBlockGroup[u32MIUProtectBlock];
                    MdbPrint(paraCmdLine->u64ReqHdl,"ID:0x%02X\n", (MS_U16)pProtectInfo->WhiteList[(MIU_MAX_PROTECT_ID * u8BlockGroup + u32MIUProtectId)]);
                }
            }
        }
        MdbPrint(paraCmdLine->u64ReqHdl,"\nProtect hit info\n");
        if(pProtectInfo->HitPortectInfo.bHit == TRUE)
        {
            if(pChipInfo->Protect_Version == 0)
            {
                if(pProtectInfo->HitPortectInfo.u8Block == 0x6)
                {
                    MdbPrint(paraCmdLine->u64ReqHdl,"Read over DRAM bound\n");
                }
                else if (pProtectInfo->HitPortectInfo.u8Block == 0x7)
                {
                    MdbPrint(paraCmdLine->u64ReqHdl,"Write over DRAM bound\n");
                }
                else
                {
                    MdbPrint(paraCmdLine->u64ReqHdl,"hit protect block:[%x]\n",pProtectInfo->HitPortectInfo.u8Block);
                }
            }
            else if(pChipInfo->Protect_Version == 1 || pChipInfo->Protect_Version == 2)
            {
                if(pProtectInfo->HitPortectInfo.u8Block == 0xE)
                {
                    MdbPrint(paraCmdLine->u64ReqHdl,"Write over DRAM bound\n");
                }
                else if (pProtectInfo->HitPortectInfo.u8Block == 0xF)
                {
                    MdbPrint(paraCmdLine->u64ReqHdl,"Read over DRAM bound\n");
                }
                else
                {
                    MdbPrint(paraCmdLine->u64ReqHdl,"hit protect block:[%x]\n",pProtectInfo->HitPortectInfo.u8Block);
                }

            }
            MdbPrint(paraCmdLine->u64ReqHdl,"hit Client ID:0x%x\n",((pProtectInfo->HitPortectInfo.u8Group<<4)||pProtectInfo->HitPortectInfo.u8ClientID));
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"No MIU protect hit\n");
        }
    }
    free(pProtectInfo);
    return;
}

static void MDrv_MIU_PROCSetProtect(MDBCMD_CMDLINE_PARAMETER *paraCmdLine, MIU_ChipInfoHandle *pChipInfo, MS_U32 u32Num)
{
    MS_U8 *pu8ClientID;
    MS_U32 *pu32ClientID;
    MS_U32 u32MIUProtectId;

    //set miu protect
    if(u32Num >= MIU_MAX_PROTECT_ID)
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"[PROC ERROR][Too much client ID]\n");
        return;
    }
    HAL_MIU_GetSWClientInfo((MIU_ID)u32MIUSetValue[1],str2num, u32Num);
    if( pChipInfo->SWSupport_MIUProtectEx == 0x0)
    {
        pu8ClientID = (MS_U8*)malloc(MIU_MAX_PROTECT_ID * sizeof(MS_U8));
        if(pu8ClientID == NULL)
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"[PROC ERROR][malloc fail]\n");
            return;
        }
        memset(pu8ClientID,0,MIU_MAX_PROTECT_ID * sizeof(MS_U8));
        for( u32MIUProtectId = 0; u32MIUProtectId < MIU_MAX_PROTECT_ID; u32MIUProtectId++)
            pu8ClientID[u32MIUProtectId] = (MS_U8)str2num[u32MIUProtectId];
        if(u32MIUSetValue[5] == 0)
        {
            u32MIUSetValue[3] = 0x0;
            u32MIUSetValue[4] = 0x2000;
        }
        if( MDrv_MIU_Protect(u32MIUSetValue[2],pu8ClientID,(MS_U32)u32MIUSetValue[3], (MS_U32)u32MIUSetValue[4], (MS_BOOL)u32MIUSetValue[5])==FALSE)
            MdbPrint(paraCmdLine->u64ReqHdl,"MDrv_MIU_Protect FLASE\n");
        free(pu8ClientID);
    }
    else if( pChipInfo->SWSupport_MIUProtectEx == 0x1)
    {
        pu32ClientID = (MS_U32*)malloc(MIU_MAX_PROTECT_ID * sizeof(MS_U32));
        if(pu32ClientID == NULL)
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"[PROC ERROR][malloc fail]\n");
            return;
        }
        memset(pu32ClientID,0,MIU_MAX_PROTECT_ID * sizeof(MS_U32));
        for( u32MIUProtectId = 0; u32MIUProtectId < MIU_MAX_PROTECT_ID; u32MIUProtectId++)
            pu32ClientID[u32MIUProtectId] = (MS_U32)str2num[u32MIUProtectId];
        if(u32MIUSetValue[5] == 0)
        {
            u32MIUSetValue[3] = 0x0;
            u32MIUSetValue[4] = 0x2000;
        }
        if( MDrv_MIU_ProtectEx(u32MIUSetValue[2],pu32ClientID,(MS_PHY)u32MIUSetValue[3], (MS_PHY)u32MIUSetValue[4], (MS_BOOL)u32MIUSetValue[5])==FALSE)
            MdbPrint(paraCmdLine->u64ReqHdl,"MDrv_MIU_ProtectEx FLASE\n");
        free(pu32ClientID);
    }
    return;
}

static void MDrv_MIU_PROCPrintMIUSelct(MDBCMD_CMDLINE_PARAMETER *paraCmdLine, MIU_ChipInfoHandle *pChipInfo)
{
    MS_U32 u32MIUGroupClient;
    MS_U32 *pu32SelectInfo;
    if( pChipInfo->HWSupport_MIUSelect == 0x0)
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU select not support this chip---------\n");
        return;
    }
    if(u32MIUSetValue[6] > MIU_MAX_GROUP)
        return;

    pu32SelectInfo = (MS_U32*)malloc(MIU_MAX_DEVICE * sizeof(MS_U32));
    if(pu32SelectInfo == NULL)
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"[PROC ERROR][malloc fail]\n");
        return;
    }
    memset(pu32SelectInfo,0,MIU_MAX_DEVICE * sizeof(MS_U32));
    HAL_MIU_GetSelectInfo(u32MIUSetValue[6], pu32SelectInfo);
    MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU select Info---------\n");
    switch(MIU_MAX_DEVICE)
    {
        case 3:
            MdbPrint(paraCmdLine->u64ReqHdl,"ID\tMIU0\tMIU1\tMIU2\n");
            for ( u32MIUGroupClient = 0; u32MIUGroupClient < MIU_MAX_GP_CLIENT; u32MIUGroupClient++)
            {
                MdbPrint(paraCmdLine->u64ReqHdl,"No%d\t0x%x\t0x%x\t0x%x\n",u32MIUGroupClient,pu32SelectInfo[0] >> u32MIUGroupClient & BIT0, pu32SelectInfo[1] >> u32MIUGroupClient & BIT0, pu32SelectInfo[2] >> u32MIUGroupClient & BIT0);
            }
            break;
        case 2:
            MdbPrint(paraCmdLine->u64ReqHdl,"ID\tMIU0\tMIU1\n");
            for ( u32MIUGroupClient = 0; u32MIUGroupClient < MIU_MAX_GP_CLIENT; u32MIUGroupClient++)
            {
                MdbPrint(paraCmdLine->u64ReqHdl,"No%d\t0x%x\t0x%x\n", u32MIUGroupClient, pu32SelectInfo[0] >> u32MIUGroupClient & BIT0, pu32SelectInfo[1] >> u32MIUGroupClient & BIT0);
            }
            break;
        case 1:
            MdbPrint(paraCmdLine->u64ReqHdl,"ID\tMIU0\n");
            for ( u32MIUGroupClient = 0; u32MIUGroupClient < MIU_MAX_GP_CLIENT; u32MIUGroupClient++)
            {
                MdbPrint(paraCmdLine->u64ReqHdl,"No%d\t0x%x\n", u32MIUGroupClient, pu32SelectInfo[0] >> u32MIUGroupClient & BIT0);
            }
            break;
        default:
            break;
    }
    free(pu32SelectInfo);
    return;
}

static void MDrv_MIU_PROCMIUMask(MDBCMD_CMDLINE_PARAMETER *paraCmdLine, MS_U8 u8flag_foundlist)
{
    MS_U32 u32MIUGroupClient;
    MS_U32 u32Val = 0x0;
    if(u32MIUSetValue[1] > MIU_MAX_DEVICE)
        return;
    if(u8flag_foundlist == 0x1)
    {
//        MdbPrint(paraCmdLine->u64ReqHdl,"u64HWClientID=0x%x\n", u64HWClientID[0]);
        if( HAL_MIU_GetSWClientInfo((MIU_ID)u32MIUSetValue[1], u64HWClientID, 1) == FALSE)
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"Some thing wrong whith ID:0x%x\n", u64HWClientID[0]);
            return;
        }
//        MdbPrint(paraCmdLine->u64ReqHdl,"HAL_MIU_GetSWClientInfo:u64HWClientID=0x%x\n", u64HWClientID[0]);
        if(u32MIUSetValue[5] == 0x0)
        {
            MDrv_MIU_UnMaskReq((MS_U8)u32MIUSetValue[1],(eMIUClientID)u64HWClientID[0]);
            MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU SET unmask---------\n");
        }
        else if(u32MIUSetValue[5] == 0x1)
        {
            MDrv_MIU_MaskReq((MS_U8)u32MIUSetValue[1], (eMIUClientID)u64HWClientID[0]);
            MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU SET mask---------\n");
        }
    }
    //show info
    if(u32MIUSetValue[6] > MIU_MAX_GROUP)
        return;
    if( HAL_MIU_GetMaskInfo((MIU_ID)u32MIUSetValue[1], u32MIUSetValue[6], &u32Val) == FALSE)
        return;
    MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU mask Info---------\n");
    MdbPrint(paraCmdLine->u64ReqHdl,"ID\tMask\n");
    for ( u32MIUGroupClient = 0; u32MIUGroupClient < MIU_MAX_GP_CLIENT; u32MIUGroupClient++)
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"No%d\t0x%x\n", u32MIUGroupClient, u32Val >> u32MIUGroupClient &BIT0);
    }
    return;
}

static void MDrv_MIU_PROCPrintBandwidthBankInfo(MDBCMD_CMDLINE_PARAMETER *paraCmdLine, MIU_ChipInfoHandle *pChipInfo)
{
    MS_U32 u32Block;
    MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU Bandwidth Info---------\n");
    MdbPrint(paraCmdLine->u64ReqHdl,"---------Not Yet Support---------\n");
    return;
}

static MS_BOOL MDrv_MIU_GetClientLoading(MS_U32 u32ClientID, MIU_UMA_Mode *peUmaMode, MIU_BWValue *pstBWValue, MIU_BWValue *pstBWEffi, MIU_BWValue *pstBWUtil)
{
    MIU_UMA_Mode eUMAMode = E_MIU_NONUMA;
    MIU_BWValue BWValueEffi;
    MIU_BWValue BWValueUtil;

    memset(&BWValueEffi,0,sizeof(BWValueEffi));
    memset(&BWValueUtil,0,sizeof(BWValueUtil));

    if(MDrv_MIU_SetBWValue(u32ClientID, E_BW_TYPE_IMMED_UTIL) == FALSE)
        return FALSE;
    MsOS_DelayTask(10);
    if(MDrv_MIU_GetBWValue(u32ClientID, E_BW_TYPE_IMMED_UTIL, &eUMAMode, &BWValueUtil) == FALSE)
        return FALSE;

    if(MDrv_MIU_SetBWValue(u32ClientID, E_BW_TYPE_IMMED_EFFI) == FALSE)
        return FALSE;
    MsOS_DelayTask(300);
    if(MDrv_MIU_GetBWValue(u32ClientID, E_BW_TYPE_IMMED_EFFI, &eUMAMode, &BWValueEffi) == FALSE)
        return FALSE;

    *peUmaMode = eUMAMode;
    if( BWValueEffi.u32MIU0BWValue == 0x0 || BWValueEffi.u32MIU1BWValue == 0x0 || BWValueEffi.u32MIU2BWValue == 0x0 || BWValueEffi.u32UMATotal == 0x0 || BWValueEffi.u32UMATail == 0x0)
    {
        return TRUE;
    }

    pstBWEffi->u32MIU0BWValue += (MS_U32)BWValueEffi.u32MIU0BWValue;
    pstBWEffi->u32MIU1BWValue += (MS_U32)BWValueEffi.u32MIU1BWValue;
    pstBWEffi->u32MIU2BWValue += (MS_U32)BWValueEffi.u32MIU2BWValue;
    pstBWEffi->u32UMATotal += (MS_U32)BWValueEffi.u32UMATotal;
    pstBWEffi->u32UMATail += (MS_U32)BWValueEffi.u32UMATail;

    pstBWUtil->u32MIU0BWValue += (MS_U32)BWValueUtil.u32MIU0BWValue;
    pstBWUtil->u32MIU1BWValue += (MS_U32)BWValueUtil.u32MIU1BWValue;
    pstBWUtil->u32MIU2BWValue += (MS_U32)BWValueUtil.u32MIU2BWValue;
    pstBWUtil->u32UMATotal += (MS_U32)BWValueUtil.u32UMATotal;
    pstBWUtil->u32UMATail += (MS_U32)BWValueUtil.u32UMATail;

    pstBWValue->u32MIU0BWValue =(MS_U32)((BWValueUtil.u32MIU0BWValue*10000)/BWValueEffi.u32MIU0BWValue);
    pstBWValue->u32MIU1BWValue =(MS_U32)((BWValueUtil.u32MIU1BWValue*10000)/BWValueEffi.u32MIU1BWValue);
    pstBWValue->u32MIU2BWValue =(MS_U32)((BWValueUtil.u32MIU2BWValue*10000)/BWValueEffi.u32MIU2BWValue);
    pstBWValue->u32UMATotal =(MS_U32)((BWValueUtil.u32UMATotal*10000)/BWValueEffi.u32UMATotal);
    pstBWValue->u32UMATail =(MS_U32)((BWValueUtil.u32UMATail*10000)/BWValueEffi.u32UMATail);
    return TRUE;
}

static void MDrv_MIU_PROCSetBWLoading(MDBCMD_CMDLINE_PARAMETER *paraCmdLine)
{
    MS_U32 u32tmpCount, u32IPNumber, u32IPCount;
    MS_BOOL bMonitorAll = FALSE;
    MIU_IP_Module IpModule = E_MIU_MODULE_CPU;
    MIU_UMA_Mode UmaMode = E_MIU_NONUMA;

    // pBWTmpUsage : Tmp for get IP Usage
    MIU_BWValue *pBWTmpUsage;
    // pBWTotalUsage : Usage of total module in each count round
    MIU_BWValue *pBWTotalUsage;
    // pBWAvgUsage : Average of Usage of module per count round
    MIU_BWValue *pBWAvgUsage;
    // pBWMaxUsage : Maximum of Usage of module in all count round
    MIU_BWValue *pBWMaxUsage;
    // pBWIPAvgEffi : Average of Effi of all IP in module per count round
    MIU_BWValue *pBWIPAvgEffi;
    MIU_BWValue *pBWAvgEffi;
    MIU_BWValue *pBWIPAvgUtil;
    MIU_BWValue *pBWAvgUtil;

    if(u32MIUSetValue[7] == 0)
    {
        MdbPrint(paraCmdLine->u64ReqHdl, "Wrong MIU Count parameter ( ex: c=5 ) \n");
        return;
    }
    if(pIPModuleName[0] == 0)
    {
        MdbPrint(paraCmdLine->u64ReqHdl, "Wrong MIU IP_Module parameter ( ex: m=CPU ) \n");
        return;
    }

    MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU Bandwidth Loading Info---------\n");
    if(strcmp(pIPModuleName, "CPU") == 0)
    {
        IpModule = E_MIU_MODULE_CPU;
    }
    else if(strcmp(pIPModuleName, "GPU") == 0)
    {
        IpModule = E_MIU_MODULE_GPU;
    }
    else if(strcmp(pIPModuleName, "XC") == 0)
    {
        IpModule = E_MIU_MODULE_XC;
    }
    else if(strcmp(pIPModuleName, "MVOP") == 0)
    {
        IpModule = E_MIU_MODULE_MVOP;
    }
    else if(strcmp(pIPModuleName, "MEMC") == 0)
    {
        IpModule = E_MIU_MODULE_MEMC;
    }
    else if(strcmp(pIPModuleName, "GOP") == 0)
    {
        IpModule = E_MIU_MODULE_GOP;
    }
    else if(strcmp(pIPModuleName, "OD") == 0)
    {
        IpModule = E_MIU_MODULE_OD;
    }
    else if(strcmp(pIPModuleName, "HDR") == 0)
    {
        IpModule = E_MIU_MODULE_HDR;
    }
    else if(strcmp(pIPModuleName, "AUDIO") == 0)
    {
        IpModule = E_MIU_MODULE_AUDIO;
    }
    else if(strcmp(pIPModuleName, "VDEC") == 0)
    {
        IpModule = E_MIU_MODULE_VDEC;
    }
    else if(strcmp(pIPModuleName, "GE") == 0)
    {
        IpModule = E_MIU_MODULE_GE;
    }
    else if(strcmp(pIPModuleName, "VDECR2") == 0)
    {
        IpModule = E_MIU_MODULE_VDEC_R2;
    }
    else if(strcmp(pIPModuleName, "DIP") == 0)
    {
        IpModule = E_MIU_MODULE_DIP;
    }
    else if(strcmp(pIPModuleName, "VE") == 0)
    {
        IpModule = E_MIU_MODULE_VE;
    }
    else if(strcmp(pIPModuleName, "MFDEC") == 0)
    {
        IpModule = E_MIU_MODULE_MFDEC;
    }
    else if(strcmp(pIPModuleName, "BIST") == 0)
    {
        IpModule = E_MIU_MODULE_BIST;
    }
    else if(strcmp(pIPModuleName, "AUDIOEN") == 0)
    {
        IpModule = E_MIU_MODULE_AUDIO_EN;
    }
    else if(strcmp(pIPModuleName, "AUDIODE") == 0)
    {
        IpModule = E_MIU_MODULE_AUDIO_DE;
    }
    else if(strcmp(pIPModuleName, "DISPLAY") == 0)
    {
        IpModule = E_MIU_MODULE_DISPLAY;
    }
    else if(strcmp(pIPModuleName, "ALL") == 0)
    {
        bMonitorAll = TRUE;
    }
    else
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"Not Support [%s] Module\n", pIPModuleName);
        return;
    }

    if( bMonitorAll == TRUE)
    {
        u32IPNumber = 1;
        u32MIUModuleClient = &u32AllClient[0];
    }
    else
    {
        u32IPNumber = MDrv_MIU_GetModuleClient((MIU_ID)0, IpModule, &u32MIUModuleClient);
        if( u32IPNumber == 0)
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"Get MDrv_MIU_GetModuleClient IP number = 0\n");
            return;
        }
    }

    pBWTmpUsage = (MIU_BWValue*)malloc(sizeof(MIU_BWValue));
    pBWTotalUsage = (MIU_BWValue*)malloc(sizeof(MIU_BWValue));
    pBWAvgUsage = (MIU_BWValue*)malloc(sizeof(MIU_BWValue));
    pBWMaxUsage = (MIU_BWValue*)malloc(sizeof(MIU_BWValue));
    pBWIPAvgEffi = (MIU_BWValue*)malloc((sizeof(MIU_BWValue)*u32IPNumber));
    pBWAvgEffi = (MIU_BWValue*)malloc(sizeof(MIU_BWValue));
    pBWIPAvgUtil = (MIU_BWValue*)malloc(sizeof(MIU_BWValue)*u32IPNumber);
    pBWAvgUtil = (MIU_BWValue*)malloc(sizeof(MIU_BWValue));

    if(pBWTmpUsage == NULL || pBWTotalUsage == NULL || pBWAvgUsage == NULL || pBWMaxUsage == NULL || pBWIPAvgEffi == NULL || pBWAvgEffi == NULL || pBWIPAvgUtil == NULL || pBWAvgUtil == NULL)
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"[PROC ERROR][malloc fail]\n");
        free(pBWTmpUsage);
        free(pBWTotalUsage);
        free(pBWAvgUsage);
        free(pBWMaxUsage);
        free(pBWIPAvgEffi);
        free(pBWAvgEffi);
        free(pBWIPAvgUtil);
        free(pBWAvgUtil);
        return;
    }
    memset(pBWTmpUsage,0,sizeof(MIU_BWValue));
    memset(pBWAvgUsage,0,sizeof(MIU_BWValue));
    memset(pBWMaxUsage,0,sizeof(MIU_BWValue));
    memset(pBWIPAvgEffi,0,(sizeof(MIU_BWValue)*u32IPNumber));
    memset(pBWAvgEffi,0,sizeof(MIU_BWValue));
    memset(pBWIPAvgUtil,0,sizeof(MIU_BWValue)*u32IPNumber);
    memset(pBWAvgUtil,0,sizeof(MIU_BWValue));

    for(u32tmpCount = 0; u32tmpCount < u32MIUSetValue[7]; u32tmpCount++)
    {
        memset(pBWTotalUsage,0,sizeof(MIU_BWValue));
        for(u32IPCount = 0; u32IPCount < u32IPNumber; u32IPCount++)
        {
//            MdbPrint(paraCmdLine->u64ReqHdl, "ClientID:0x%x\n", u32MIUModuleClient[u32IPCount]);
            MDrv_MIU_GetClientLoading(u32MIUModuleClient[u32IPCount], &UmaMode, pBWTmpUsage, &pBWIPAvgEffi[u32IPCount], &pBWIPAvgUtil[u32IPCount]);
            pBWTotalUsage->u32MIU0BWValue += pBWTmpUsage->u32MIU0BWValue;
            pBWTotalUsage->u32MIU1BWValue += pBWTmpUsage->u32MIU1BWValue;
            pBWTotalUsage->u32MIU2BWValue += pBWTmpUsage->u32MIU2BWValue;
            pBWTotalUsage->u32UMATotal += pBWTmpUsage->u32UMATotal;
            pBWTotalUsage->u32UMATail += pBWTmpUsage->u32UMATail;
        }
        pBWMaxUsage->u32MIU0BWValue = (pBWTotalUsage->u32MIU0BWValue > pBWMaxUsage->u32MIU0BWValue) ? pBWTotalUsage->u32MIU0BWValue : pBWMaxUsage->u32MIU0BWValue;
        pBWMaxUsage->u32MIU1BWValue = (pBWTotalUsage->u32MIU1BWValue > pBWMaxUsage->u32MIU1BWValue) ? pBWTotalUsage->u32MIU1BWValue : pBWMaxUsage->u32MIU1BWValue;
        pBWMaxUsage->u32MIU2BWValue = (pBWTotalUsage->u32MIU2BWValue > pBWMaxUsage->u32MIU2BWValue) ? pBWTotalUsage->u32MIU2BWValue : pBWMaxUsage->u32MIU2BWValue;
        pBWMaxUsage->u32UMATotal = (pBWTotalUsage->u32UMATotal > pBWMaxUsage->u32UMATotal) ? pBWTotalUsage->u32UMATotal : pBWMaxUsage->u32UMATotal;
        pBWMaxUsage->u32UMATail = (pBWTotalUsage->u32UMATail > pBWMaxUsage->u32UMATail) ? pBWTotalUsage->u32UMATail : pBWMaxUsage->u32UMATail;
        pBWAvgUsage->u32MIU0BWValue += pBWTotalUsage->u32MIU0BWValue;
        pBWAvgUsage->u32MIU1BWValue += pBWTotalUsage->u32MIU1BWValue;
        pBWAvgUsage->u32MIU2BWValue += pBWTotalUsage->u32MIU2BWValue;
        pBWAvgUsage->u32UMATotal += pBWTotalUsage->u32UMATotal;
        pBWAvgUsage->u32UMATail += pBWTotalUsage->u32UMATail;

        if( (u32MIUSetValue[9] & (0x1<<1)) > 0)
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"MIU0 %s Usage:%d.%02d%s\n", pIPModuleName, (int)(pBWTotalUsage->u32MIU0BWValue/100), (int)(pBWTotalUsage->u32MIU0BWValue%100), "%" );
            if(MIU_MAX_CHANNEL >= 2)
            {
                MdbPrint(paraCmdLine->u64ReqHdl,"MIU1 %s Usage:%d.%02d%s\n", pIPModuleName, (int)(pBWTotalUsage->u32MIU1BWValue/100), (int)(pBWTotalUsage->u32MIU1BWValue%100), "%");
            }
            if(MIU_MAX_CHANNEL >= 3)
            {
                MdbPrint(paraCmdLine->u64ReqHdl,"MIU2 %s Usage:%d.%02d%s\n", pIPModuleName, (int)(pBWTotalUsage->u32MIU2BWValue/100), (int)(pBWTotalUsage->u32MIU2BWValue%100), "%");
            }

            if( UmaMode == E_MIU_SYMUMA)
            {
                MdbPrint(paraCmdLine->u64ReqHdl,"Symmetry_UMA %s Total_Usage:%d.%02d%s\n", pIPModuleName, (int)(pBWTotalUsage->u32UMATotal/100), (int)(pBWTotalUsage->u32UMATotal%100), "%");
            }
            else if(UmaMode == E_MIU_ASYMUMA)
            {
                MdbPrint(paraCmdLine->u64ReqHdl,"Asymmetry_UMA %s Total_Usage:%d.%02d%s, Tail_Usage:%d.%02d%s\n", pIPModuleName, (int)(pBWTotalUsage->u32UMATotal/100), (int)(pBWTotalUsage->u32UMATotal%100), "%", (int)(pBWTotalUsage->u32UMATail/100), (int)(pBWTotalUsage->u32UMATail%100), "%");
            }
            MdbPrint(paraCmdLine->u64ReqHdl,"---------------------------------------------\n");
        }
    }

    for(u32IPCount = 0; u32IPCount < u32IPNumber; u32IPCount++)
    {
        pBWAvgUtil->u32MIU0BWValue += pBWIPAvgUtil[u32IPCount].u32MIU0BWValue;
        pBWAvgUtil->u32MIU1BWValue += pBWIPAvgUtil[u32IPCount].u32MIU1BWValue;
        pBWAvgUtil->u32MIU2BWValue += pBWIPAvgUtil[u32IPCount].u32MIU2BWValue;
        pBWAvgUtil->u32UMATotal += pBWIPAvgUtil[u32IPCount].u32UMATotal;
        pBWAvgUtil->u32UMATail += pBWIPAvgUtil[u32IPCount].u32UMATail;
    }
    //MdbPrint(paraCmdLine->u64ReqHdl, "MIU0 USAGE:%d\n", (int)(pBWAvgUsage->u32MIU0BWValue));
    //MdbPrint(paraCmdLine->u64ReqHdl, "MIU1 USAGE:%d\n", (int)(pBWAvgUsage->u32MIU1BWValue));

    pBWAvgEffi->u32MIU0BWValue = (pBWAvgUtil->u32MIU0BWValue*10000) / pBWAvgUsage->u32MIU0BWValue;
    pBWAvgEffi->u32MIU1BWValue = (pBWAvgUtil->u32MIU1BWValue*10000) / pBWAvgUsage->u32MIU1BWValue;
    pBWAvgEffi->u32MIU2BWValue = (pBWAvgUtil->u32MIU2BWValue*10000) / pBWAvgUsage->u32MIU2BWValue;
    pBWAvgEffi->u32UMATotal = (pBWAvgUtil->u32UMATotal*10000) / pBWAvgUsage->u32UMATotal;
    pBWAvgEffi->u32UMATail = (pBWAvgUtil->u32UMATail*10000) / pBWAvgUsage->u32UMATail;

    pBWAvgUsage->u32MIU0BWValue = pBWAvgUsage->u32MIU0BWValue/u32MIUSetValue[7];
    pBWAvgUsage->u32MIU1BWValue = pBWAvgUsage->u32MIU1BWValue/u32MIUSetValue[7];
    pBWAvgUsage->u32MIU2BWValue = pBWAvgUsage->u32MIU2BWValue/u32MIUSetValue[7];
    pBWAvgUsage->u32UMATotal = pBWAvgUsage->u32UMATotal/u32MIUSetValue[7];
    pBWAvgUsage->u32UMATail = pBWAvgUsage->u32UMATail/u32MIUSetValue[7];
    pBWAvgUtil->u32MIU0BWValue = pBWAvgUtil->u32MIU0BWValue/u32MIUSetValue[7];
    pBWAvgUtil->u32MIU1BWValue = pBWAvgUtil->u32MIU1BWValue/u32MIUSetValue[7];
    pBWAvgUtil->u32MIU2BWValue = pBWAvgUtil->u32MIU2BWValue/u32MIUSetValue[7];
    pBWAvgUtil->u32UMATotal = pBWAvgUtil->u32UMATotal/u32MIUSetValue[7];
    pBWAvgUtil->u32UMATail = pBWAvgUtil->u32UMATail/u32MIUSetValue[7];

    MdbPrint(paraCmdLine->u64ReqHdl,"MIU0 %s AVG_Usage:%d.%02d%s MAX_Usage:%d.%02d%s AVG_Effi:%d.%d%s AVG_Util:%d.%d%s\n", pIPModuleName, (int)(pBWAvgUsage->u32MIU0BWValue/100), (int)(pBWAvgUsage->u32MIU0BWValue%100), "%", (int)(pBWMaxUsage->u32MIU0BWValue/100), (int)(pBWMaxUsage->u32MIU0BWValue%100), "%", (int)(pBWAvgEffi->u32MIU0BWValue/10), (int)(pBWAvgEffi->u32MIU0BWValue%10), "%", (int)(pBWAvgUtil->u32MIU0BWValue/10), (int)(pBWAvgUtil->u32MIU0BWValue%10), "%");
    if(MIU_MAX_CHANNEL >= 2)
        MdbPrint(paraCmdLine->u64ReqHdl,"MIU1 %s AVG_Usage:%d.%02d%s MAX_Usage:%d.%02d%s AVG_Effi:%d.%d%s AVG_Util:%d.%d%s\n", pIPModuleName, (int)(pBWAvgUsage->u32MIU1BWValue/100), (int)(pBWAvgUsage->u32MIU1BWValue%100), "%", (int)(pBWMaxUsage->u32MIU1BWValue/100), (int)(pBWMaxUsage->u32MIU1BWValue%100), "%", (int)(pBWAvgEffi->u32MIU1BWValue/10), (int)(pBWAvgEffi->u32MIU1BWValue%10), "%", (int)(pBWAvgUtil->u32MIU1BWValue/10), (int)(pBWAvgUtil->u32MIU1BWValue%10), "%");
    if(MIU_MAX_CHANNEL >= 3)
        MdbPrint(paraCmdLine->u64ReqHdl,"MIU2 %s AVG_Usage:AVG:%d.%02d%s MAX_Usage:%d.%02d%s AVG_Effi:%d.%d%s AVG_Util:%d.%d%s\n", pIPModuleName, (int)(pBWAvgUsage->u32MIU2BWValue/100), (int)(pBWAvgUsage->u32MIU2BWValue%100), "%", (int)(pBWMaxUsage->u32MIU2BWValue/100), (int)(pBWMaxUsage->u32MIU2BWValue%100), "%", (int)(pBWAvgEffi->u32MIU2BWValue/10), (int)(pBWAvgEffi->u32MIU2BWValue%10), "%", (int)(pBWAvgUtil->u32MIU2BWValue), (int)(pBWAvgUtil->u32MIU2BWValue%10), "%");

    if( UmaMode == E_MIU_SYMUMA)
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"Symmetry_UMA %s Total_AVG_Usage:%d.%02d%s Total_MAX_Usage:%d.%02d%s\n", pIPModuleName, (int)(pBWAvgUsage->u32UMATotal/100), (int)(pBWAvgUsage->u32UMATotal%100), "%", (int)(pBWMaxUsage->u32UMATotal/100), (int)(pBWMaxUsage->u32UMATotal%100), "%");
    }
    else if(UmaMode == E_MIU_ASYMUMA)
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"Asymmetry_UMA %s Total_AVG_Usage:%d.%02d%s Total_MAX_Usage:%d.%02d%s, Tail_AVG_Usage:%d.%02d%s Tail_MAX_Usage:%d.%02d%s\n", pIPModuleName, (int)(pBWAvgUsage->u32UMATotal/100), (int)(pBWAvgUsage->u32UMATotal%100), "%", (int)(pBWMaxUsage->u32UMATotal/100), (int)(pBWMaxUsage->u32UMATotal%100), "%", (int)(pBWAvgUsage->u32UMATail/100), (int)(pBWAvgUsage->u32UMATail%100), "%", (int)(pBWMaxUsage->u32UMATail/100), (int)(pBWMaxUsage->u32UMATail%100), "%");
    }

    if( (u32MIUSetValue[9] & (0x1<<0)) > 0)
    {
        for(u32IPCount = 0; u32IPCount < u32IPNumber; u32IPCount++)
        {
            pBWIPAvgUtil[u32IPCount].u32MIU0BWValue = pBWIPAvgUtil[u32IPCount].u32MIU0BWValue / u32MIUSetValue[7];
            pBWIPAvgUtil[u32IPCount].u32MIU1BWValue = pBWIPAvgUtil[u32IPCount].u32MIU1BWValue / u32MIUSetValue[7];
            pBWIPAvgUtil[u32IPCount].u32MIU2BWValue = pBWIPAvgUtil[u32IPCount].u32MIU2BWValue / u32MIUSetValue[7];
            pBWIPAvgUtil[u32IPCount].u32UMATotal = pBWIPAvgUtil[u32IPCount].u32UMATotal / u32MIUSetValue[7];
            pBWIPAvgUtil[u32IPCount].u32UMATail = pBWIPAvgUtil[u32IPCount].u32UMATail / u32MIUSetValue[7];
            pBWIPAvgEffi[u32IPCount].u32MIU0BWValue = pBWIPAvgEffi[u32IPCount].u32MIU0BWValue / u32MIUSetValue[7];
            pBWIPAvgEffi[u32IPCount].u32MIU1BWValue = pBWIPAvgEffi[u32IPCount].u32MIU1BWValue / u32MIUSetValue[7];
            pBWIPAvgEffi[u32IPCount].u32MIU2BWValue = pBWIPAvgEffi[u32IPCount].u32MIU2BWValue / u32MIUSetValue[7];
            pBWIPAvgEffi[u32IPCount].u32UMATotal = pBWIPAvgEffi[u32IPCount].u32UMATotal / u32MIUSetValue[7];
            pBWIPAvgEffi[u32IPCount].u32UMATail = pBWIPAvgEffi[u32IPCount].u32UMATail / u32MIUSetValue[7];
            MdbPrint(paraCmdLine->u64ReqHdl, "ClientID:0x%x, MIU0 Effi:%d.%d%s Util:%d.%d%s\n", u32MIUModuleClient[u32IPCount], (int)(pBWIPAvgEffi[u32IPCount].u32MIU0BWValue/10), (int)(pBWIPAvgEffi[u32IPCount].u32MIU0BWValue%10), "%", (int)(pBWIPAvgUtil[u32IPCount].u32MIU0BWValue/10), (int)(pBWIPAvgUtil[u32IPCount].u32MIU0BWValue%10), "%");
            if(MIU_MAX_CHANNEL >= 2)
                MdbPrint(paraCmdLine->u64ReqHdl, "ClientID:0x%x, MIU1 Effi:%d.%d%s Util:%d.%d%s\n", u32MIUModuleClient[u32IPCount], (int)(pBWIPAvgEffi[u32IPCount].u32MIU1BWValue/10), (int)(pBWIPAvgEffi[u32IPCount].u32MIU1BWValue%10), "%", (int)(pBWIPAvgUtil[u32IPCount].u32MIU1BWValue/10), (int)(pBWIPAvgUtil[u32IPCount].u32MIU1BWValue%10), "%");
            if(MIU_MAX_CHANNEL >= 3)
                MdbPrint(paraCmdLine->u64ReqHdl, "ClientID:0x%x, MIU2 Effi:%d.%d%s Util:%d.%d%s\n", u32MIUModuleClient[u32IPCount], (int)(pBWIPAvgEffi[u32IPCount].u32MIU2BWValue/10), (int)(pBWIPAvgEffi[u32IPCount].u32MIU2BWValue%10), "%", (int)(pBWIPAvgUtil[u32IPCount].u32MIU2BWValue/10), (int)(pBWIPAvgUtil[u32IPCount].u32MIU2BWValue%10), "%");

        }
    }

    free(pBWTmpUsage);
    free(pBWTotalUsage);
    free(pBWAvgUsage);
    free(pBWMaxUsage);
    free(pBWIPAvgEffi);
    free(pBWAvgEffi);
    free(pBWIPAvgUtil);
    free(pBWAvgUtil);

    return;
}

static MS_S32 MDrv_MIU_PROCGetModuleEnum(MDBCMD_CMDLINE_PARAMETER *paraCmdLine, char *pch)
{
    if(strcmp(pch, "CPU") == 0)
    {
        return E_MIU_MODULE_CPU;
    }
    else if(strcmp(pch, "GPU") == 0)
    {
        return E_MIU_MODULE_GPU;
    }
    else if(strcmp(pch, "XC") == 0)
    {
        return E_MIU_MODULE_XC;
    }
    else if(strcmp(pch, "MVOP") == 0)
    {
        return E_MIU_MODULE_MVOP;
    }
    else if(strcmp(pch, "MEMC") == 0)
    {
        return E_MIU_MODULE_MEMC;
    }
    else if(strcmp(pch, "GOP") == 0)
    {
        return E_MIU_MODULE_GOP;
    }
    else if(strcmp(pch, "OD") == 0)
    {
        return E_MIU_MODULE_OD;
    }
    else if(strcmp(pch, "HDR") == 0)
    {
        return E_MIU_MODULE_HDR;
    }
    else if(strcmp(pch, "AUDIO") == 0)
    {
        return E_MIU_MODULE_AUDIO;
    }
    else if(strcmp(pch, "VDEC") == 0)
    {
        return E_MIU_MODULE_VDEC;
    }
    else if(strcmp(pch, "GE") == 0)
    {
        return E_MIU_MODULE_GE;
    }
    else if(strcmp(pch, "VDECR2") == 0)
    {
        return E_MIU_MODULE_VDEC_R2;
    }
    else if(strcmp(pch, "DIP") == 0)
    {
        return E_MIU_MODULE_DIP;
    }
    else if(strcmp(pch, "VE") == 0)
    {
        return E_MIU_MODULE_VE;
    }
    else if(strcmp(pch, "MFDEC") == 0)
    {
        return E_MIU_MODULE_MFDEC;
    }
    else if(strcmp(pch, "BIST") == 0)
    {
        return E_MIU_MODULE_BIST;
    }
    else if(strcmp(pch, "AUDIOEN") == 0)
    {
        return E_MIU_MODULE_AUDIO_EN;
    }
    else if(strcmp(pch, "AUDIODE") == 0)
    {
        return E_MIU_MODULE_AUDIO_DE;
    }
    else if(strcmp(pIPModuleName, "DISPLAY") == 0)
    {
        return E_MIU_MODULE_DISPLAY;
    }
    else if(strcmp(pch, "ALL") == 0)
    {
        return 0xFF;
    }
    else
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"Not Support [%s] Module\n", pch);
        return -1;
    }
}

static void MDrv_MIU_PROCBWMonitor(MDBCMD_CMDLINE_PARAMETER *paraCmdLine, MIU_ChipInfoHandle *pChipInfo)
{
    char *pch;
    char *pch_cut;
    MS_U32 u32tmp, u32tmp1, u32tmp2;
    MS_U32 u32AllBWModuleIP = 0x0;
    MS_U32 u32useMonitorNum = 0;
    MS_U32 u32ModuleNumber = 0;
    MS_U32 u32BWMonitorSingleIDsNumber = 0;
    MS_U32 u32MonitorCount = 0;
    MS_U32 u32ModuleGroup = 0;
    MS_U32 u32ChannelNormalize = 1;
    MS_U32 u32tmpImmdUsage = 0;
    MS_U32 u32tmpMaxUsage = 0;
    MS_U32 u32tmpImmdUtil = 0;
    MS_U32 u32tmpMaxUtil = 0;
    MS_U32 u32tmpImmdEffi = 0;
    MS_U32 u32tmpMinEffi = 0;
    MS_U64 u64tmpImmdOccupancy = 0;
    MS_U64 u64tmpMaxOccupancy = 0;
    MS_U64 u64tmpImmdBW = 0;
    MS_U64 u64tmpMaxBW = 0;
    MS_U64 u64tmpBWMBResult = 0;
    MS_U64 u64tmpBWMBResult1 = 0;

    MS_BOOL *pbMonitorAll;
    MS_U32 *pu32IPNumber;
    MS_U32 *pu32ModuleEnum;
    MS_S32 s32ModuleEnum;
    MS_U32 **pu32ModuleIP;
    MS_U64 *pu64BWClientId;
    MIU_BandwidthMonitorInfo *pBWINFO;
    MIU_BandwidthMonitorInfo *pGetAllBWINFO;
    MIU_BandwidthMonitorInfo *pAvgBWINFO;
    MIU_BandwidthMonitorInfo *pMaxBWINFO;
    MIU_BWRawData *pAvgBWRawData;
    MIU_Info* stMIU0Info;
    MIU_Info* stMIU1Info;
    MS_U32 u32MIUChannel = E_MIU_CHANNEL_ALL;
    MS_U32 u32MIUDevice = 0xFF;

//u32ModuleNumber total module number
//pIPModuleNames[x] module name
//pu32ModuleEnum[x] module enum
//pu32IPNumber[x] module total IP number
//pu32ModuleIP[x][y] module IP enum
//pbMonitorAll[x] module is All or not

    if( pChipInfo->BW_Version < 0x3)
    {
        MdbPrint(paraCmdLine->u64ReqHdl, "Not Support BW Monitor ARB 3.0 \n");
        return;
    }

    if(u32MIUSetValue[7] == 0)
    {
        MdbPrint(paraCmdLine->u64ReqHdl, "Wrong MIU Count parameter ( ex: c=5 ) \n");
        return;
    }
    if(pIPModuleName[0] == 0 && u32BWMonitorSingleIDs[0] == 0xFF)
    {
        MdbPrint(paraCmdLine->u64ReqHdl, "Wrong MIU IP_Module parameter ( ex: m=CPU ) \n");
        return;
    }
//    MdbPrint(paraCmdLine->u64ReqHdl,"[count][%d]\n",u32MIUSetValue[7]);
//    MdbPrint(paraCmdLine->u64ReqHdl,"[time(ms)][%d]\n",u32MIUSetValue[10]);
//    MdbPrint(paraCmdLine->u64ReqHdl,"[channel][%d][%d]\n",bSetBWMonChannel, u32MIUSetValue[11]);
//    MdbPrint(paraCmdLine->u64ReqHdl,"[adv][%d]\n",u32MIUSetValue[9]);
//    MdbPrint(paraCmdLine->u64ReqHdl,"[pIPModuleName][%s]\n",pIPModuleName);

    for(u32tmp = 0; u32tmp < MIU_MAX_BW_MONITOR_GROUP_NUMBER; u32tmp++)
    {
        if(u32BWMonitorSingleIDs[u32tmp] != 0xFF)
        {
            u32BWMonitorSingleIDsNumber++;
        }
    }

    if( u32BWMonitorSingleIDs[0] == 0xFF)
    {
        pch = pIPModuleName;
        while( (pch_cut = strsep(&pch,",")) != NULL )
        {
            strncpy(pIPModuleNames[u32ModuleNumber], pch_cut, StringSize);
//            MdbPrint(paraCmdLine->u64ReqHdl,"[pIPModuleName][%s]\n",pIPModuleNames[u32ModuleNumber]);
            u32ModuleNumber +=1;
        }
    }
    else
    {
        u32ModuleNumber = u32BWMonitorSingleIDsNumber;
    }
//    MdbPrint(paraCmdLine->u64ReqHdl,"[u32ModuleNumber][%d]\n", u32ModuleNumber);
    pbMonitorAll = (MS_BOOL*)malloc(u32ModuleNumber * sizeof(MS_BOOL));
    pu32ModuleEnum = (MS_U32*)malloc(u32ModuleNumber * sizeof(MS_U32));
    pu32IPNumber = (MS_U32*)malloc(u32ModuleNumber * sizeof(MS_U32));
    pu32ModuleIP = (MS_U32**)malloc(u32ModuleNumber * sizeof(MS_U32*));

    if(pbMonitorAll == NULL || pu32ModuleEnum == NULL || pu32IPNumber == NULL || pu32ModuleIP == NULL)
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"[PROC ERROR][malloc fail]\n");
        free(pbMonitorAll);
        free(pu32ModuleEnum);
        free(pu32IPNumber);
        free(pu32ModuleIP);
        return;
    }

    memset(pbMonitorAll,0,(u32ModuleNumber * sizeof(MS_BOOL)));
    memset(pu32ModuleEnum,0,(u32ModuleNumber * sizeof(MS_U32)));
    memset(pu32IPNumber,0,(u32ModuleNumber * sizeof(MS_U32)));
    memset(pu32ModuleIP,0,(u32ModuleNumber * sizeof(MS_U32*)));

//    MdbPrint(paraCmdLine->u64ReqHdl,"-----get module data -----\n");

    if(u32BWMonitorSingleIDs[0] == 0xFF)
    {
        for(u32tmp = 0; u32tmp < u32ModuleNumber; u32tmp++)
        {
            if( (u32MIUSetValue[9] & (0x1<<15)) > 0)
                MdbPrint(paraCmdLine->u64ReqHdl,"[Module Name][%s]\n",pIPModuleNames[u32tmp]);
            s32ModuleEnum = MDrv_MIU_PROCGetModuleEnum(paraCmdLine, pIPModuleNames[u32tmp]);
            if(s32ModuleEnum < 0)
            {
                free(pbMonitorAll);
                free(pu32ModuleEnum);
                free(pu32IPNumber);
                free(pu32ModuleIP);
                return;
            }
            pu32ModuleEnum[u32tmp] = (MS_U32)s32ModuleEnum;
            if(pu32ModuleEnum[u32tmp] == 0xFF)
                pbMonitorAll[u32tmp] = TRUE;
            else
                pbMonitorAll[u32tmp] = FALSE;
    //        MdbPrint(paraCmdLine->u64ReqHdl,"[pu32ModuleEnum][%d]\n", pu32ModuleEnum[u32tmp]);

            if(pbMonitorAll[u32tmp] == TRUE)
            {
                pu32IPNumber[u32tmp] = 1;
                pu32ModuleIP[u32tmp] = (MS_U32*)malloc(sizeof(MS_U32));
                *pu32ModuleIP[u32tmp] = u32AllBWModuleIP;
            }
            else
            {
                pu32IPNumber[u32tmp] = MDrv_MIU_GetModuleClient((MIU_ID)0, (MIU_IP_Module)pu32ModuleEnum[u32tmp], &pu32ModuleIP[u32tmp]);
            }
    //        MdbPrint(paraCmdLine->u64ReqHdl,"[pu32IPNumber][%d]\n", pu32IPNumber[u32tmp]);
#if 0
    // Not check null IP, and by pass
            if( pu32IPNumber[u32tmp] == 0)
            {
                free(pbMonitorAll);
                free(pu32ModuleEnum);
                free(pu32IPNumber);
                free(pu32ModuleIP);
                return;
            }
#endif
            if( (u32MIUSetValue[9] & (0x1<<15)) > 0)
            {
                for(u32tmp1 = 0; u32tmp1 < pu32IPNumber[u32tmp]; u32tmp1++)
                {
                    MdbPrint(paraCmdLine->u64ReqHdl,"[IP][0x%x]\n", pu32ModuleIP[u32tmp][u32tmp1]);
                }
            }
        }
    }
    else
    {
        for(u32tmp = 0; u32tmp < u32ModuleNumber; u32tmp++)
        {
            snprintf(pIPModuleNames[u32tmp],4,"%X",u32BWMonitorSingleIDs[u32tmp]);
            pu32IPNumber[u32tmp] = 1;
            pu32ModuleIP[u32tmp] = (MS_U32*)malloc(sizeof(MS_U32));
            *pu32ModuleIP[u32tmp] = u32BWMonitorSingleIDs[u32tmp];
            if(u32BWMonitorSingleIDs[u32tmp] == 0x0)
            {
                pbMonitorAll[u32tmp] = TRUE;
            }
            else
            {
                pbMonitorAll[u32tmp] = FALSE;
            }
            if( (u32MIUSetValue[9] & (0x1<<15)) > 0)
            {
                MdbPrint(paraCmdLine->u64ReqHdl,"[Module Name][%s]\n",pIPModuleNames[u32tmp]);
                for(u32tmp1 = 0; u32tmp1 < pu32IPNumber[u32tmp]; u32tmp1++)
                {
                    MdbPrint(paraCmdLine->u64ReqHdl,"[IP][0x%x]\n", pu32ModuleIP[u32tmp][u32tmp1]);
                }
            }
        }
    }

//Check if can fill in all BW monitor
    for(u32tmp = 0; u32tmp < u32ModuleNumber; u32tmp++)
        u32useMonitorNum += ((pu32IPNumber[u32tmp]%8 == 0)?pu32IPNumber[u32tmp]/8:(pu32IPNumber[u32tmp]/8)+1);

    if(u32useMonitorNum > MIU_MAX_BW_MONITOR_GROUP_NUMBER)
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"Too Much Module, can only support %d Monitor\n", MIU_MAX_BW_MONITOR_GROUP_NUMBER);
        free(pbMonitorAll);
        free(pu32ModuleEnum);
        free(pu32IPNumber);
        free(pu32ModuleIP);
        return;
    }

    pBWINFO = (MIU_BandwidthMonitorInfo*)malloc(sizeof(MIU_BandwidthMonitorInfo));
    pu64BWClientId = (MS_U64*)malloc(MIU_MAX_BW_MONITOR_GP_CLIENT_NUMBER * sizeof(MS_U64));
    stMIU0Info = (MIU_Info*)malloc(sizeof(MIU_Info));
    stMIU1Info = (MIU_Info*)malloc(sizeof(MIU_Info));
    if(pBWINFO == NULL || pu64BWClientId == NULL || stMIU0Info == NULL || stMIU1Info == NULL)
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"[PROC ERROR][malloc fail]\n");
        free(pbMonitorAll);
        free(pu32ModuleEnum);
        free(pu32IPNumber);
        free(pu32ModuleIP);
        free(pBWINFO);
        free(pu64BWClientId);
        free(stMIU0Info);
        free(stMIU1Info);
        return;
    }

    MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU Set Bandwidth Monitor ARB3.0 (V1.0)---------\n");

//Reset all BW Monitor
    MDrv_MIU_Reset_All_BW_Monitor(E_MIU_0);

//Set Bandwidth Monitor
    memset(pBWINFO,0,sizeof(MIU_BandwidthMonitorInfo));
    memset(stMIU0Info,0,sizeof(MIU_Info));
    memset(stMIU1Info,0,sizeof(MIU_Info));

    if(bSetBWMonChannel == TRUE)
    {
        if(u32MIUSetValue[11] == 1)
        {
            u32MIUChannel = E_MIU_CHANNEL_1;
            u32MIUDevice = E_MIU_1;
        }
        else
        {
            u32MIUChannel = E_MIU_CHANNEL_0;
            u32MIUDevice = E_MIU_0;
        }
        MDrv_MIU_GetMIUInfo((MIU_ID)u32MIUDevice, stMIU0Info);
        u32ChannelNormalize = 1;
    }
    else
    {
        MDrv_MIU_GetMIUInfo(E_MIU_0, stMIU0Info);
        if(MDrv_MIU_GetMIUInfo(E_MIU_1, stMIU1Info) == FALSE)
        {
            u32ChannelNormalize = 1;
        }
        else
        {
            u32ChannelNormalize = 2;
        }
    }

    for(u32tmp = 0; u32tmp < u32ModuleNumber; u32tmp++)
    {
        if(pu32IPNumber[u32tmp] == 0)
            continue;
        for(u32tmp1 = 0; u32tmp1 < ( ((pu32IPNumber[u32tmp]-1) / MIU_MAX_BW_MONITOR_GP_CLIENT_NUMBER)+1) ; u32tmp1++)
        {
            memset(pu64BWClientId,0,MIU_MAX_BW_MONITOR_GP_CLIENT_NUMBER * sizeof(MS_U64));
            for(u32tmp2 = 0; u32tmp2 < MIU_MAX_BW_MONITOR_GP_CLIENT_NUMBER; u32tmp2++)
            {
                pu64BWClientId[u32tmp2] = MIU_CLIENT_DUMMY;
            }
            if(u32BWMonitorSingleIDs[0] != 0xFF)
            {
                if(pu32ModuleIP[u32tmp][0] != 0xFF)
                {
                    pu64BWClientId[0] = pu32ModuleIP[u32tmp][0];
                    if( HAL_MIU_GetSWClientInfo(E_MIU_0, pu64BWClientId, ( pu32IPNumber[u32tmp] % MIU_MAX_BW_MONITOR_GP_CLIENT_NUMBER)) == FALSE)
                    {
                        free(pbMonitorAll);
                        free(pu32ModuleEnum);
                        free(pu32IPNumber);
                        free(pu32ModuleIP);
                        free(pBWINFO);
                        free(pu64BWClientId);
                        return;
                    }
                }
            }
            else
            {
                if( u32tmp1 == (pu32IPNumber[u32tmp] / MIU_MAX_BW_MONITOR_GP_CLIENT_NUMBER) )
                {
                    for(u32tmp2 = 0; u32tmp2 < ( pu32IPNumber[u32tmp] % MIU_MAX_BW_MONITOR_GP_CLIENT_NUMBER); u32tmp2++)
                    {
                        pu64BWClientId[u32tmp2] = (MS_U64)pu32ModuleIP[u32tmp][(u32tmp1 * MIU_MAX_BW_MONITOR_GP_CLIENT_NUMBER) + u32tmp2];
                    }
                    HAL_MIU_GetSWClientInfo(E_MIU_0, pu64BWClientId, ( pu32IPNumber[u32tmp] % MIU_MAX_BW_MONITOR_GP_CLIENT_NUMBER));
                }
                else
                {
                    for(u32tmp2 = 0; u32tmp2 < MIU_MAX_BW_MONITOR_GP_CLIENT_NUMBER; u32tmp2++)
                    {
                        pu64BWClientId[u32tmp2] = (MS_U64)pu32ModuleIP[u32tmp][(u32tmp1 * MIU_MAX_BW_MONITOR_GP_CLIENT_NUMBER) + u32tmp2];
                    }
                    HAL_MIU_GetSWClientInfo(E_MIU_0, pu64BWClientId, MIU_MAX_BW_MONITOR_GP_CLIENT_NUMBER);
                }
            }
//            for(u32tmp2 = 0; u32tmp2 < MIU_MAX_BW_MONITOR_GP_CLIENT_NUMBER; u32tmp2++)
//            {
//                MdbPrint(paraCmdLine->u64ReqHdl,"[IP][%x]\n", pu64BWClientId[u32tmp2]);
//            }
            pBWINFO->u32MonitorIndex = u32MonitorCount;
            pBWINFO->bMonitorAllMIU = pbMonitorAll[u32tmp];
            //default 65ms
            pBWINFO->stSamplingFrequency.u32UpdateFrequencyValue = u32MIUSetValue[10]!=0?u32MIUSetValue[10]:32;
            for( u32tmp2 = 0; u32tmp2 < MIU_MAX_BW_MONITOR_GP_CLIENT_NUMBER; u32tmp2++)
            {
                pBWINFO->u32MonitorId[u32tmp2] = (eMIUClientID)pu64BWClientId[u32tmp2];
//                MdbPrint(paraCmdLine->u64ReqHdl,"[inIP][%x]\n", pBWINFO->u32MonitorId[u32tmp2]);
            }

            if( (u32MIUSetValue[9] & (0x1<<4)) > 0)
            {
                pBWINFO->bMonitorAreaEn = TRUE;
            }
            else
            {
                pBWINFO->bMonitorAreaEn = FALSE;
            }
            if( MDrv_MIU_Set_BW_Monitor((MIU_Channel)u32MIUChannel, pBWINFO) == FALSE )
            {
                MdbPrint(paraCmdLine->u64ReqHdl,"MDrv_MIU_Set_BW_Monitor FALSE\n");
                free(pbMonitorAll);
                free(pu32ModuleEnum);
                free(pu32IPNumber);
                free(pu32ModuleIP);
                free(pBWINFO);
                free(pu64BWClientId);
                return;
            }
//            else
//                MdbPrint(paraCmdLine->u64ReqHdl,"Set Success, In MIU:%d, Get Bandwidth index:%d\n", E_MIU_0, pBWINFO->u32MonitorIndex);

            u32MonitorCount++;
        }
    }
//Get Bandwidth Monitor Utilization
//for loop get value
    pGetAllBWINFO = (MIU_BandwidthMonitorInfo *)malloc(MIU_MAX_BW_MONITOR_GROUP_NUMBER * sizeof(MIU_BandwidthMonitorInfo));
    pAvgBWINFO = (MIU_BandwidthMonitorInfo *)malloc(MIU_MAX_BW_MONITOR_GROUP_NUMBER * sizeof(MIU_BandwidthMonitorInfo));
    pMaxBWINFO = (MIU_BandwidthMonitorInfo *)malloc(MIU_MAX_BW_MONITOR_GROUP_NUMBER * sizeof(MIU_BandwidthMonitorInfo));
    pAvgBWRawData = (MIU_BWRawData*)malloc(MIU_MAX_BW_MONITOR_GROUP_NUMBER * sizeof(MIU_BWRawData));
    if(pGetAllBWINFO == NULL || pAvgBWINFO == NULL || pMaxBWINFO == NULL)
    {
        free(pbMonitorAll);
        free(pu32ModuleEnum);
        free(pu32IPNumber);
        free(pu32ModuleIP);
        free(pBWINFO);
        free(pu64BWClientId);
        free(pGetAllBWINFO);
        free(pAvgBWINFO);
        free(pMaxBWINFO);
        free(pAvgBWRawData);
        free(stMIU0Info);
        free(stMIU1Info);
        return;
    }
    memset(pGetAllBWINFO,0,(MIU_MAX_BW_MONITOR_GROUP_NUMBER * sizeof(MIU_BandwidthMonitorInfo)));
    memset(pAvgBWINFO,0,(MIU_MAX_BW_MONITOR_GROUP_NUMBER * sizeof(MIU_BandwidthMonitorInfo)));
    memset(pMaxBWINFO,0,(MIU_MAX_BW_MONITOR_GROUP_NUMBER * sizeof(MIU_BandwidthMonitorInfo)));
    memset(pAvgBWRawData,0,(MIU_MAX_BW_MONITOR_GROUP_NUMBER * sizeof(MIU_BWRawData)));

//StartBW Monitor
    MDrv_MIU_Start_BW_Monitor(E_MIU_0);

    for(u32tmp = 0; u32tmp < u32MIUSetValue[7]; u32tmp++)
    {
        if( (u32MIUSetValue[9] & (0x1<<3)) > 0)
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"Count[%d]\n",u32tmp);
        }

        //delay time(ms)
        MsOS_DelayTask(pBWINFO->stSamplingFrequency.u32UpdateFrequencyValue);
        if(MDrv_MIU_Get_BW_All( (MIU_Channel)u32MIUChannel, pGetAllBWINFO) == TRUE)
        {
            for(u32tmp1 = 0; u32tmp1 < MIU_MAX_BW_MONITOR_GROUP_NUMBER; u32tmp1++)
            {
                pAvgBWINFO[u32tmp1].u32MonitorIndex = pGetAllBWINFO[u32tmp1].u32MonitorIndex;
                pMaxBWINFO[u32tmp1].u32MonitorIndex = pGetAllBWINFO[u32tmp1].u32MonitorIndex;
                if( (u32MIUSetValue[9] & (0x1<<3)) > 0)
                {
                    MdbPrint(paraCmdLine->u64ReqHdl,"Monitor index:%d\n", pGetAllBWINFO[u32tmp1].u32MonitorIndex);
                    MdbPrint(paraCmdLine->u64ReqHdl,\
                    "ImmdEffi:%u MinEffi:%u ImmdUtil:%u MaxUtil:%u ImmdUsage:%u MaxUsage:%u ImmdOCU:%llu MaxOCU:%llu ImmdBW:%llu MaxBW:%llu\n", \
                    pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateEfficiency, pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMinEfficiency,\
                    pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateUtilization/u32ChannelNormalize,\
                    pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxUtilization/u32ChannelNormalize,\
                    pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateUsage/u32ChannelNormalize,\
                    pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxUsage/u32ChannelNormalize,\
                    pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateOccupancy, pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxOccupancy,\
                    pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateBW, pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxBW);
                }

                pAvgBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateEfficiency += pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateEfficiency;
                pAvgBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMinEfficiency += pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMinEfficiency;
                pAvgBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateUtilization += pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateUtilization;
                pAvgBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxUtilization += pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxUtilization;
                pAvgBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxUsage += pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxUsage;
                pAvgBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateUsage += pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateUsage;
                pAvgBWRawData[u32tmp1].u64ReportImmediateOccupancy += (MS_U64)pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateOccupancy;
                pAvgBWRawData[u32tmp1].u64ReportMaxOccupancy += (MS_U64)pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxOccupancy;
                pAvgBWRawData[u32tmp1].u64ReportImmediateBW += (MS_U64)pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateBW;
                pAvgBWRawData[u32tmp1].u64ReportMaxBW += (MS_U64)pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxBW;

                pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateEfficiency = (pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateEfficiency > pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateEfficiency)?pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateEfficiency:pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateEfficiency;
                pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMinEfficiency = (pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMinEfficiency > pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMinEfficiency)?pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMinEfficiency:pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMinEfficiency;
                pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateUtilization = (pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateUtilization > pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateUtilization)?pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateUtilization:pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateUtilization;
                pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxUtilization = (pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxUtilization > pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxUtilization)?pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxUtilization:pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxUtilization;
                pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateOccupancy = (pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateOccupancy > pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateOccupancy)?pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateOccupancy:pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateOccupancy;
                pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxOccupancy = (pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxOccupancy > pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxOccupancy)?pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxOccupancy:pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxOccupancy;
                pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateUsage = (pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateUsage > pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateUsage)?pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateUsage:pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateUsage;
                pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxUsage = (pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxUsage > pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxUsage)?pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxUsage:pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxUsage;
                pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateBW = (pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateBW > pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateBW)?pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateBW:pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportImmediateBW;
                pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxBW = (pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxBW > pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxBW)?pGetAllBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxBW:pMaxBWINFO[u32tmp1].stCurrentBandwidth.u32ReportMaxBW;
            }
        }
    }
    for(u32tmp = 0; u32tmp < MIU_MAX_BW_MONITOR_GROUP_NUMBER; u32tmp++)
    {
        pAvgBWINFO[u32tmp].stCurrentBandwidth.u32ReportImmediateEfficiency = pAvgBWINFO[u32tmp].stCurrentBandwidth.u32ReportImmediateEfficiency / u32MIUSetValue[7];
        pAvgBWINFO[u32tmp].stCurrentBandwidth.u32ReportMinEfficiency = pAvgBWINFO[u32tmp].stCurrentBandwidth.u32ReportMinEfficiency / u32MIUSetValue[7];
        pAvgBWINFO[u32tmp].stCurrentBandwidth.u32ReportImmediateUtilization = pAvgBWINFO[u32tmp].stCurrentBandwidth.u32ReportImmediateUtilization / u32MIUSetValue[7];
        pAvgBWINFO[u32tmp].stCurrentBandwidth.u32ReportMaxUtilization = pAvgBWINFO[u32tmp].stCurrentBandwidth.u32ReportMaxUtilization / u32MIUSetValue[7];
        pAvgBWINFO[u32tmp].stCurrentBandwidth.u32ReportImmediateUsage = pAvgBWINFO[u32tmp].stCurrentBandwidth.u32ReportImmediateUsage / u32MIUSetValue[7];
        pAvgBWINFO[u32tmp].stCurrentBandwidth.u32ReportMaxUsage = pAvgBWINFO[u32tmp].stCurrentBandwidth.u32ReportMaxUsage / u32MIUSetValue[7];
        pAvgBWRawData[u32tmp].u64ReportImmediateOccupancy = pAvgBWRawData[u32tmp].u64ReportImmediateOccupancy / u32MIUSetValue[7];
        pAvgBWRawData[u32tmp].u64ReportMaxOccupancy = pAvgBWRawData[u32tmp].u64ReportMaxOccupancy / u32MIUSetValue[7];
        pAvgBWRawData[u32tmp].u64ReportImmediateBW = pAvgBWRawData[u32tmp].u64ReportImmediateBW / u32MIUSetValue[7];
        pAvgBWRawData[u32tmp].u64ReportMaxBW = pAvgBWRawData[u32tmp].u64ReportMaxBW/ u32MIUSetValue[7];
    }
    if( (u32MIUSetValue[9] & (0x1<<2)) > 0)
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"EVERY BW MONITOR VALUE(AVG/MAX of ALL COUNT)\n");
        for(u32tmp = 0; u32tmp < MIU_MAX_BW_MONITOR_GROUP_NUMBER; u32tmp++)
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"**********************\n");
            MdbPrint(paraCmdLine->u64ReqHdl,"Monitor index:%d\n", pAvgBWINFO[u32tmp].u32MonitorIndex);

            MdbPrint(paraCmdLine->u64ReqHdl,\
            "AVG ImmdEffi:%u MinEffi:%u ImmdUtil:%u MaxUtil:%u ImmdUsage:%u MaxUsage: %u ImmdOCU:%llu MaxOCU:%llu ImmdBW:%llu MaxBW:%llu\n", \
            pAvgBWINFO[u32tmp].stCurrentBandwidth.u32ReportImmediateEfficiency, pAvgBWINFO[u32tmp].stCurrentBandwidth.u32ReportMinEfficiency,\
            pAvgBWINFO[u32tmp].stCurrentBandwidth.u32ReportImmediateUtilization/u32ChannelNormalize,\
            pAvgBWINFO[u32tmp].stCurrentBandwidth.u32ReportMaxUtilization/u32ChannelNormalize,\
            pAvgBWINFO[u32tmp].stCurrentBandwidth.u32ReportImmediateUsage/u32ChannelNormalize,\
            pAvgBWINFO[u32tmp].stCurrentBandwidth.u32ReportMaxUsage/u32ChannelNormalize,\
            pAvgBWRawData[u32tmp].u64ReportImmediateOccupancy, pAvgBWRawData[u32tmp].u64ReportMaxOccupancy,\
            pAvgBWRawData[u32tmp].u64ReportImmediateBW, pAvgBWRawData[u32tmp].u64ReportMaxBW);

            MdbPrint(paraCmdLine->u64ReqHdl,\
            "MAX ImmdEffi:%u MinEffi:%u ImmdUtil:%u MaxUtil:%u ImmdUsage:%u MaxUsage: %u ImmdOCU:%llu MaxOCU:%llu ImmdBW:%llu MaxBW:%llu\n", \
            pMaxBWINFO[u32tmp].stCurrentBandwidth.u32ReportImmediateEfficiency,\
            pMaxBWINFO[u32tmp].stCurrentBandwidth.u32ReportMinEfficiency,\
            pMaxBWINFO[u32tmp].stCurrentBandwidth.u32ReportImmediateUtilization/u32ChannelNormalize,\
            pMaxBWINFO[u32tmp].stCurrentBandwidth.u32ReportMaxUtilization/u32ChannelNormalize,\
            pMaxBWINFO[u32tmp].stCurrentBandwidth.u32ReportImmediateUsage/u32ChannelNormalize,\
            pMaxBWINFO[u32tmp].stCurrentBandwidth.u32ReportMaxUsage/u32ChannelNormalize,\
            pMaxBWINFO[u32tmp].stCurrentBandwidth.u32ReportImmediateOccupancy, pMaxBWINFO[u32tmp].stCurrentBandwidth.u32ReportMaxOccupancy,\
            pMaxBWINFO[u32tmp].stCurrentBandwidth.u32ReportImmediateBW, pMaxBWINFO[u32tmp].stCurrentBandwidth.u32ReportMaxBW);
        }
    }

    for(u32tmp = 0; u32tmp < u32ModuleNumber; u32tmp++)
    {
        u32tmpImmdUsage = 0;
        u32tmpMaxUsage = 0;
        u32tmpImmdUtil = 0;
        u32tmpMaxUtil = 0;
        u32tmpImmdEffi = 0;
        u32tmpMinEffi = 0;
        u64tmpImmdOccupancy = 0;
        u64tmpMaxOccupancy = 0;
        u64tmpImmdBW = 0;
        u64tmpMaxBW = 0;

        if(pu32IPNumber[u32tmp] == 0)
            continue;
        for(u32tmp1 = 0; u32tmp1 < ( ((pu32IPNumber[u32tmp]-1) / MIU_MAX_BW_MONITOR_GP_CLIENT_NUMBER)+1) ; u32tmp1++)
        {
            u32tmpImmdUtil += pAvgBWINFO[u32ModuleGroup].stCurrentBandwidth.u32ReportImmediateUtilization;
            u32tmpMaxUtil += pAvgBWINFO[u32ModuleGroup].stCurrentBandwidth.u32ReportMaxUtilization;
            u32tmpImmdUsage += pAvgBWINFO[u32ModuleGroup].stCurrentBandwidth.u32ReportImmediateUsage;
            u32tmpMaxUsage += pAvgBWINFO[u32ModuleGroup].stCurrentBandwidth.u32ReportMaxUsage;
            u64tmpImmdOccupancy += pAvgBWRawData[u32ModuleGroup].u64ReportImmediateOccupancy;
            u64tmpMaxOccupancy += pAvgBWRawData[u32ModuleGroup].u64ReportMaxOccupancy;
            u64tmpImmdBW += pAvgBWRawData[u32ModuleGroup].u64ReportImmediateBW;
            u64tmpMaxBW += pAvgBWRawData[u32ModuleGroup].u64ReportMaxBW;
            u32ModuleGroup++;
        }

        if(u64tmpImmdOccupancy == 0)
            u32tmpImmdEffi = 0;
        else
        {
            u64tmpBWMBResult = ((u64tmpImmdBW * 10000) / u64tmpImmdOccupancy);
            u32tmpImmdEffi = (MS_U32)(u64tmpBWMBResult);
        }
        if(u64tmpMaxOccupancy == 0)
            u32tmpMinEffi = 0;
        else
        {

            u64tmpBWMBResult = ((u64tmpImmdBW * 10000) / u64tmpMaxOccupancy);
            u32tmpMinEffi = (MS_U32)(u64tmpBWMBResult);
        }
        u32tmpImmdUsage = u32tmpImmdUsage / u32ChannelNormalize;
        u32tmpMaxUsage = u32tmpMaxUsage / u32ChannelNormalize;
        u32tmpImmdUtil = u32tmpImmdUtil / u32ChannelNormalize;
        u32tmpMaxUtil = u32tmpMaxUtil / u32ChannelNormalize;

        if( (u32MIUSetValue[9] & (0x1<<1)) > 0 && (u32MIUSetValue[9] & (0x1<<1)) > 0 )
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"Ch%x %s AVG_Usage:%u MAX_Usage:%u AVG_Effi:%u AVG_Util:%u MIN_Effi:%u MAX_Util:%u ImmdOCU:%llu MaxOCU:%llu ImmdBW:%llu MaxBW:%llu\n", \
                                            u32MIUDevice, pIPModuleNames[u32tmp], u32tmpImmdUsage, u32tmpMaxUsage,\
                                            u32tmpImmdEffi, u32tmpImmdUtil, u32tmpMinEffi, u32tmpMaxUtil,\
                                            u64tmpImmdOccupancy, u64tmpMaxOccupancy, u64tmpImmdBW, u64tmpMaxBW);
        }
        else if( (u32MIUSetValue[9] & (0x1<<0)) > 0 )
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"Ch%x %s AVG_Usage:%u MAX_Usage:%u AVG_Effi:%u AVG_Util:%u MIN_Effi:%u MAX_Util:%u\n", \
                                            u32MIUDevice, pIPModuleNames[u32tmp], u32tmpImmdUsage, u32tmpMaxUsage,\
                                            u32tmpImmdEffi, u32tmpImmdUtil, u32tmpMinEffi, u32tmpMaxUtil);
        }
        else if( (u32MIUSetValue[9] & (0x1<<1)) > 0 )
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"Ch%x %s AVG_Usage:%u MAX_Usage:%u ImmdOCU:%llu MaxOCU:%llu ImmdBW:%llu MaxBW:%llu\n", \
                                            u32MIUDevice, pIPModuleNames[u32tmp], u32tmpImmdUsage, u32tmpMaxUsage,\
                                            u64tmpImmdOccupancy, u64tmpMaxOccupancy, u64tmpImmdBW, u64tmpMaxBW);
        }
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"Ch%x %s AVG_Usage:%u MAX_Usage:%u\n", u32MIUDevice, pIPModuleNames[u32tmp], u32tmpImmdUsage, u32tmpMaxUsage);
        }
    }

    free(pbMonitorAll);
    free(pu32ModuleEnum);
    free(pu32IPNumber);
    free(pu32ModuleIP);
    free(pBWINFO);
    free(pu64BWClientId);
    free(pGetAllBWINFO);
    free(pAvgBWINFO);
    free(pMaxBWINFO);
    free(pAvgBWRawData);
    free(stMIU0Info);
    free(stMIU1Info);
    return;
}

static void MDrv_MIU_PROCBWMonitor_All(MDBCMD_CMDLINE_PARAMETER *paraCmdLine, MIU_ChipInfoHandle *pChipInfo)
{
    char *ptemp;
    ptemp = (char*)malloc(StringSize*sizeof(char));
    ptemp = "ALL,CPU,GPU,GOP,OD,GE,DIP,VE";
    strncpy(pIPModuleName, ptemp, StringSize);
    bSetBWMonChannel = FALSE;
    MDrv_MIU_PROCBWMonitor(paraCmdLine, pChipInfo);
    strncpy(pIPModuleName, ptemp, StringSize);
    bSetBWMonChannel = TRUE;
    u32MIUSetValue[11] = 0;
    MDrv_MIU_PROCBWMonitor(paraCmdLine, pChipInfo);
    strncpy(pIPModuleName, ptemp, StringSize);
    u32MIUSetValue[11] = 1;
    MDrv_MIU_PROCBWMonitor(paraCmdLine, pChipInfo);

    ptemp = "VDEC,VDECR2,MVOP,MFDEC,HDR";
    strncpy(pIPModuleName, ptemp, StringSize);
    bSetBWMonChannel = FALSE;
    MDrv_MIU_PROCBWMonitor(paraCmdLine, pChipInfo);
    strncpy(pIPModuleName, ptemp, StringSize);
    bSetBWMonChannel = TRUE;
    u32MIUSetValue[11] = 0;
    MDrv_MIU_PROCBWMonitor(paraCmdLine, pChipInfo);
    strncpy(pIPModuleName, ptemp, StringSize);
    u32MIUSetValue[11] = 1;
    MDrv_MIU_PROCBWMonitor(paraCmdLine, pChipInfo);

    ptemp = "XC,MEMC,AUDIO,AUDIOEN,AUDIODE";
    strncpy(pIPModuleName, ptemp, StringSize);
    bSetBWMonChannel = FALSE;
    MDrv_MIU_PROCBWMonitor(paraCmdLine, pChipInfo);
    strncpy(pIPModuleName, ptemp, StringSize);
    bSetBWMonChannel = TRUE;
    u32MIUSetValue[11] = 0;
    MDrv_MIU_PROCBWMonitor(paraCmdLine, pChipInfo);
    strncpy(pIPModuleName, ptemp, StringSize);
    u32MIUSetValue[11] = 1;
    MDrv_MIU_PROCBWMonitor(paraCmdLine, pChipInfo);

    return;
}

static void MDrv_MIU_PROCDDRPhaseErrorCheck(MDBCMD_CMDLINE_PARAMETER *paraCmdLine)
{
    MdbPrint(paraCmdLine->u64ReqHdl,"--------- MTK DDR Phase Error Check ---------\n");
    MIU_Info* stMIUInfo;
    stMIUInfo = (MIU_Info*)malloc(sizeof(MIU_Info));
    if( stMIUInfo == NULL )
    {
        return;
    }

    MDrv_MIU_GetMIUInfo((MIU_ID)u32MIUSetValue[1], stMIUInfo);
    MdbPrint(paraCmdLine->u64ReqHdl,"DDR Phase Error Check Number:%d\n",stMIUInfo->u32MIUDDRPhaseErrorCheck);
    return;
}

static void MDrv_MIU_GetDramSize_String(MIU_DDR_SIZE eDramSize, char *pDramSizeString)
{
    switch(eDramSize)
    {
        case E_MIU_DDR_512MB:
            strcpy(pDramSizeString,"512");
            break;
        case E_MIU_DDR_1024MB:
            strcpy(pDramSizeString,"1024");
            break;
        case E_MIU_DDR_2048MB:
            strcpy(pDramSizeString,"2048");
            break;
        case E_MIU_DDR_4096MB:
            strcpy(pDramSizeString,"4096");
            break;
        case E_MIU_DDR_8192MB:
            strcpy(pDramSizeString,"8192");
            break;
        default:
            break;
    }
    return;
}

static void MDrv_MIU_PROCPrintDramSize(MDBCMD_CMDLINE_PARAMETER *paraCmdLine, MIU_ChipInfoHandle *pChipInfo)
{
    MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU DRAM Size Info---------\n");
    if(pChipInfo->DRAMSize_Version == 1)
    {
        MIU_ID eMIU = E_MIU_0;
        MS_U64 u64DramSize;
        u64DramSize = HAL_MIU_MDBGetDramSize(eMIU);
        //MB unit
        u64DramSize = (u64DramSize >> 20);
        MdbPrint(paraCmdLine->u64ReqHdl,"MIU0 size[%d]MB\n", (unsigned int)u64DramSize);
    }
    else if(pChipInfo->DRAMSize_Version == 0)
    {
        char *pDramSizeString;
        MIU_DDR_SIZE DramSize1 = E_MIU_DDR_32MB;
        pDramSizeString = (char*)malloc(20*sizeof(char));
        if(pDramSizeString == NULL)
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"[PROC ERROR][malloc fail]\n");
            return;
        }
        memset(pDramSizeString,0,20*sizeof(char));
        if( MDrv_MIU_Dram_ReadSize(E_MIU_0, &DramSize1) == FALSE )
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"Not Support MIU0!\n");
            free(pDramSizeString);
            return;
        }
        MDrv_MIU_GetDramSize_String(DramSize1, pDramSizeString);
        MdbPrint(paraCmdLine->u64ReqHdl,"MIU0 size[%s]MB\n",pDramSizeString);
        if( MDrv_MIU_Dram_ReadSize(E_MIU_1, &DramSize1) == FALSE )
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"Not Support MIU1!\n");
            free(pDramSizeString);
            return;
        }
        MDrv_MIU_GetDramSize_String(DramSize1, pDramSizeString);
        MdbPrint(paraCmdLine->u64ReqHdl,"MIU1 size[%s]MB\n",pDramSizeString);
        free(pDramSizeString);
    }
    return;
}

static void MDrv_MIU_PROCPrintDramClock(MDBCMD_CMDLINE_PARAMETER *paraCmdLine)
{
    MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK DDR Phase DRAM Clock ---------\n");
    MIU_Info* stMIUInfo;
    stMIUInfo = (MIU_Info*)malloc(sizeof(MIU_Info));
    if( stMIUInfo == NULL )
    {
        return;
    }
    if(MDrv_MIU_GetMIUInfo(E_MIU_0, stMIUInfo) == TRUE)
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"MIU0 clock[%d] width[%d]\n", stMIUInfo->u32MIUDramFreq, stMIUInfo->u32MIUDramBus);
    }
    if(MDrv_MIU_GetMIUInfo(E_MIU_1, stMIUInfo) == TRUE)
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"MIU1 clock[%d] width[%d]\n", stMIUInfo->u32MIUDramFreq, stMIUInfo->u32MIUDramBus);
    }
    return;
}

static void MDrv_MIU_PROCSetDebugLevel(MDBCMD_CMDLINE_PARAMETER *paraCmdLine)
{
    MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU SET DEBUG LEVEL---------\n");
    switch(u32MIUSetValue[12])
    {
        case E_MIU_DBGLV_NONE:
            u32MIUDbgLevel = E_MIU_DBGLV_NONE;
            MdbPrint(paraCmdLine->u64ReqHdl, "MIU SET DEBUG LEVEL E_MIU_DBGLV_NONE\n");
            break;
        case E_MIU_DBGLV_ERROR:
            u32MIUDbgLevel = E_MIU_DBGLV_ERROR;
            MdbPrint(paraCmdLine->u64ReqHdl, "MIU SET DEBUG LEVEL E_MIU_DBGLV_ERROR\n");
            break;
        case E_MIU_DBGLV_DEBUG:
            u32MIUDbgLevel = E_MIU_DBGLV_DEBUG;
            MdbPrint(paraCmdLine->u64ReqHdl, "MIU SET DEBUG LEVEL E_MIU_DBGLV_DEBUG\n");
            break;
        case E_MIU_DBGLV_INFO:
            u32MIUDbgLevel = E_MIU_DBGLV_INFO;
            MdbPrint(paraCmdLine->u64ReqHdl, "MIU SET DEBUG LEVEL E_MIU_DBGLV_INFO\n");
            break;
        case E_MIU_DBGLV_ALL:
            u32MIUDbgLevel = E_MIU_DBGLV_ALL;
            MdbPrint(paraCmdLine->u64ReqHdl, "MIU SET DEBUG LEVEL E_MIU_DBGLV_ALL\n");
            break;
        default:
            MdbPrint(paraCmdLine->u64ReqHdl, "UNKNOWN DEBUG LEVEL!!\n");
            break;
    }
    return;
}

static void Reset_str2num(void)
{
    MS_U32 i = 0;
    for(i = 0; i < CmdCnt; i++)
        str2num[i] = 0;
}
static MS_U32 atoi_mtk(char *s, MS_U32 b, MS_U8 u8base)
{
    MS_U32 sum = 0;
    MS_U32 i = 0;
//    printf("S's size: %d\n", (int)sizeof(s));
    if(u8base == 16)
    {
        for(i = 0;s[i] != '\0';i++)
        {
            if((s[i]=='A') || s[i]=='a')
            {
                sum = sum*16+10;
                str2num[b] = str2num[b]*16+10;
            }
            else if((s[i]=='B') || (s[i]=='b'))
            {
                sum = sum*16+11;
                str2num[b] = str2num[b]*16+11;
            }
            else if((s[i]=='C') || (s[i]=='c'))
            {
                sum = sum*16+12;
                str2num[b] = str2num[b]*16+12;
            }
            else if((s[i]=='D') || s[i]=='d')
            {
                sum = sum*16+13;
                str2num[b] = str2num[b]*16+13;
            }
            else if((s[i]=='E') || s[i]=='e')
            {
                sum = sum*16+14;
                str2num[b] = str2num[b]*16+14;
            }
            else if((s[i]=='F') || s[i]=='f')
            {
                sum = sum*16+15;
                str2num[b] = str2num[b]*16+15;
            }
            else if ((s[i]==' ') || s[i]==',' || s[i]== '\n')
            {
                b++;
                if (b > CmdCnt-1)
                    break;
            }
            else
            {
                if( s[i]=='0' && s[i+1]=='x' )
                    i += 1;
                else
                {
                    sum = sum * 16 + s[i] - '0';
                    str2num[b] = str2num[b] * 16 + s[i] - '0';
                }
            }
        }
    }
    else if(u8base == 10)
    {
        for(i = 0;s[i] != '\0';i++)
        {
            if ((s[i]==' ') || s[i]==',' || s[i]== '\n')
            {
                b++;
                if (b > CmdCnt-1)
                    break;
            }
            else
            {
                sum = sum*10+s[i]-'0';
                str2num[b] = str2num[b]*10+s[i]-'0';
            }
        }
    }
//    MIU_DEBUG_PRI(u32MIUDbgLevel, "b=%d\n", (int)b);
    b++;
    return b;
};

static MS_U32 MDrv_MIU_SetProcStringtoValue(MDBCMD_CMDLINE_PARAMETER *paraCmdLine, char *ptemp, MS_U32 index)
{
    if( index == 14)
        return 1;
    else if( index == 15 )
    {
        if( strstr(ptemp, "immd_effi") != NULL )
            return E_MONITOR_REPORT_IMMED_EFFI;
        else if( strstr(ptemp, "min_effi") != NULL )
            return E_MONITOR_REPORT_MIN_EFFI;
        else if( strstr(ptemp, "immd_util") != NULL )
            return E_MONITOR_REPORT_IMMED_UTIL;
        else if( strstr(ptemp, "max_util") != NULL )
            return E_MONITOR_REPORT_MAX_UTIL;
        else if( strstr(ptemp, "immd_occu") != NULL )
            return E_MONITOR_REPORT_IMMED_OCCU;
        else if( strstr(ptemp, "max_occu") != NULL )
            return E_MONITOR_REPORT_MAX_OCCU;
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"Not Support %s, default report_immd_effi\n", ptemp);
            return E_MONITOR_REPORT_IMMED_EFFI;
        }
    }
    else if( index == 16 )
    {
        if( strstr(ptemp, "1") != NULL )
            return E_MONITOR_FREQUENCY_1;
        else if( strstr(ptemp, "2") != NULL )
            return E_MONITOR_FREQUENCY_2;
        else if( strstr(ptemp, "3") != NULL )
            return E_MONITOR_FREQUENCY_3;
        else if( strstr(ptemp, "4") != NULL )
            return E_MONITOR_FREQUENCY_4;
        else if( strstr(ptemp, "5") != NULL )
            return E_MONITOR_FREQUENCY_5;
        else if( strstr(ptemp, "6") != NULL )
            return E_MONITOR_FREQUENCY_6;
        else if( strstr(ptemp, "7") != NULL )
            return E_MONITOR_FREQUENCY_7;
        else if( strstr(ptemp, "8") != NULL )
            return E_MONITOR_FREQUENCY_8;
        else if( strstr(ptemp, "9") != NULL )
            return E_MONITOR_FREQUENCY_9;
        else
        {
            MdbPrint(paraCmdLine->u64ReqHdl,"Not Support %s, default frequency1\n", ptemp);
            return E_MONITOR_FREQUENCY_1;
        }
    }
    return 0;
}

MS_BOOL MDrv_MIU_MdbCmdLine(MDBCMD_CMDLINE_PARAMETER *paraCmdLine, EN_MIU_MDBCMDLINE eMdbCmdLine)
{
    //Get parameters
    char *ptemp;
    char *delim = " ";
    char *pch;
    char *pStringCmdLine;
    MS_U8 u8flag_foundlist = 0x0;
    MS_BOOL bSetProtect = FALSE;
    MS_U8 u8flag_help = 0x0;
    MS_U32 index, array_index;
    MS_U32 u32Num = 0x0;
    bSetBWMonChannel = FALSE;

    MIU_ChipInfoHandle *pChipInfo;

    ptemp = (char*)malloc(StringSize*sizeof(char));
    pChipInfo = (MIU_ChipInfoHandle*)malloc(sizeof(MIU_ChipInfoHandle));
    pStringCmdLine = (char*)malloc(StringSize*sizeof(char));

    if(ptemp == NULL || pChipInfo == NULL || pStringCmdLine == NULL)
    {
        MdbPrint(paraCmdLine->u64ReqHdl,"[PROC ERROR][malloc fail]\n");
        free(ptemp);
        free(pChipInfo);
        free(pStringCmdLine);
        return false;
    }

    memset(ptemp,0,StringSize*sizeof(char));
    memset(pChipInfo,0,sizeof(MIU_ChipInfoHandle));
    memset(pStringCmdLine,0,StringSize*sizeof(char));
    memset(&u32MIUSetValue,0,sizeof(u32MIUSetValue));

    pChipInfo->ArbStruct_Version = 0x0;
    pChipInfo->Protect_Version = 0x0;
    pChipInfo->HWSupport_MIUSelect = 0x0;
    pChipInfo->SWSupport_MIUProtectEx = 0x0;
    pChipInfo->BW_Version = 0x0;
    pChipInfo->DRAMSize_Version = 0x0;

    for( index = 0; index < MIU_MAX_BW_MONITOR_GP_CLIENT_NUMBER_ALL; index++)
        u32BWMonitorSingleIDs[index] = 0xFF;
    u64HWClientID[0] = 0;
    pIPModuleName[0] = 0;

    MDrv_MIU_Init();

    strncpy(pStringCmdLine, paraCmdLine->pcCmdLine, StringSize);
    pStringCmdLine[StringSize-1] = '\0';
    if(pStringCmdLine[strlen(pStringCmdLine)-1] == '\n')
        pStringCmdLine[strlen(pStringCmdLine)-1] = '\0';
    //MdbPrint(paraCmdLine->u64ReqHdl,"[Origin string][%s]\n",pStringCmdLine);
    pch = strsep(&pStringCmdLine, delim);
    while( pch != NULL)
    {
        //MdbPrint(paraCmdLine->u64ReqHdl,"[Cut String][%s]\n", pch);
        //for one value
        for( index = 0x0; index < (sizeof(strMIUSetPara)/sizeof(strMIUSetPara[0])); index++)
        {
            if((strstr(pch, strMIUSetPara[index]) != NULL) && (strlen(pch+strlen(strMIUSetPara[index]))<=StringSize))
            {
                strncpy(ptemp, pch+strlen(strMIUSetPara[index]), StringSize);
                ptemp[StringSize-1] = '\0';
                //MdbPrint(paraCmdLine->u64ReqHdl,"[ptemp][%s]\n", ptemp);
                Reset_str2num();
                if(index == 0)
                {
                    u8flag_help = 1;
                }
                else if(index == 8)
                {
                    strncpy(pIPModuleName, ptemp, StringSize);
                }
                else
                {
                    if( index == 3 || index == 4 || index == 6)
                        u32Num = (MS_U32)atoi_mtk(ptemp, 0x0, 16);
                    else
                        u32Num = (MS_U32)atoi_mtk(ptemp, 0, 10);

                    if(index == 11)
                        bSetBWMonChannel = TRUE;

                    if(index == 2)
                        bSetProtect = TRUE;

                    u32MIUSetValue[index] = (MS_U32) str2num[0];
                }

//                u32MIUSetValue[index] = *(pch+strlen(strMIUSetPara[index])) - '0';
//                MdbPrint(paraCmdLine->u64ReqHdl,"u32MIUSetValue[%d] = 0x%x\n", index, u32MIUSetValue[index]);
            }
        }
        //for list
        for( index = 0x0; index < (sizeof(strMIUSetArray)/sizeof(strMIUSetArray[0])); index++)
        {
            if(strstr(pch, strMIUSetArray[index]) != NULL && (strlen(pch+(strlen(strMIUSetPara[index])-1))<=StringSize))
            {
                strncpy(ptemp, pch+strlen(strMIUSetArray[index]), StringSize);
                ptemp[StringSize-1] = '\0';
                Reset_str2num();
                u32Num = (MS_U32)atoi_mtk(ptemp, 0x0, 16);
//                MdbPrint(paraCmdLine->u64ReqHdl,"u32Num=%d, str2num[0] = 0x%x, str2num[1] = 0x%x\n",(unsigned int)u32Num, (unsigned int)str2num[0], (unsigned int)str2num[1]);

                if(eMdbCmdLine == MIU_MDBCMDLINE_MIU_MASK)
                {
                    u64HWClientID[0] = str2num[0];
                }
                else if(eMdbCmdLine == MIU_MDBCMDLINE_MIU_BW_MONITOR_ARB3)
                {
                    for(array_index = 0; array_index < u32Num; array_index++)
                    {
                        if( array_index == MIU_MAX_BW_MONITOR_GP_CLIENT_NUMBER_ALL)
                            break;
                        u32BWMonitorSingleIDs[array_index] = (MS_U32)str2num[array_index];
                    }
                }
                u8flag_foundlist = 0x1;
            }
        }
        pch = strsep(&pStringCmdLine, delim);
    }
    free(ptemp);
    free(pStringCmdLine);

    MDrv_MIU_GetChipInfo(pChipInfo);

    if(u8flag_help == 1)
        MDrv_MIU_PROCPrintHelp(paraCmdLine, eMdbCmdLine);
    else
    {
        switch(eMdbCmdLine)
        {
        /* Help */
            case MIU_MDBCMDLINE_HELP:
                MDrv_MIU_PROCPrintHelp(paraCmdLine, eMdbCmdLine);
                break;
        /* Protect */
            case MIU_MDBCMDLINE_MIU_PROTECT:
                if(bSetProtect == TRUE)
                    MDrv_MIU_PROCSetProtect(paraCmdLine, pChipInfo, u32Num);
                else
                    MDrv_MIU_PROCPrintProtectInfo(paraCmdLine, pChipInfo);
                break;
        /* Select */
            case MIU_MDBCMDLINE_MIU_SELECT:
                MDrv_MIU_PROCPrintMIUSelct(paraCmdLine, pChipInfo);
                break;
        /* Mask */
            case MIU_MDBCMDLINE_MIU_MASK:
                MDrv_MIU_PROCMIUMask(paraCmdLine, u8flag_foundlist);
                break;
        /* Bandwidth */
        /* Information */
            case MIU_MDBCMDLINE_MIU_BANDWIDTH_BANKINFO:
                MDrv_MIU_PROCPrintBandwidthBankInfo(paraCmdLine, pChipInfo);
                break;
        /* ARB1&2 */
            case MIU_MDBCMDLINE_MIU_BANDWIDTH_LOADING:
                MDrv_MIU_PROCSetBWLoading(paraCmdLine);
                break;
        /* ARB3 */
            case MIU_MDBCMDLINE_MIU_BW_MONITOR_ARB3:
                if( (u32MIUSetValue[9] & (0x1<<5)) > 0)
                    MDrv_MIU_PROCBWMonitor_All(paraCmdLine, pChipInfo);
                else
                    MDrv_MIU_PROCBWMonitor(paraCmdLine, pChipInfo);
                break;
        /* DDR Phase */
        /* Error Check*/
            case MIU_MDBCMDLINE_MIU_DDR_PHASE_ERR_CHECK:
                MDrv_MIU_PROCDDRPhaseErrorCheck(paraCmdLine);
                break;
            case MIU_MDBCMDLINE_MIU_DRAMSIZE:
                MDrv_MIU_PROCPrintDramSize(paraCmdLine, pChipInfo);
                break;
            case MIU_MDBCMDLINE_MIU_DRAMCLOCK:
                MDrv_MIU_PROCPrintDramClock(paraCmdLine);
                break;
        /* Log Level */
            case MIU_MDBCMDLINE_MIU_SET_DBG_LEVEL:
                MDrv_MIU_PROCSetDebugLevel(paraCmdLine);
                break;
        //END
            default:
                MdbPrint(paraCmdLine->u64ReqHdl,"---------MTK MIU---------\n");
                MdbPrint(paraCmdLine->u64ReqHdl,"No have this cmd!\nPlease use 'echo help > /proc/utopia_mdb/miu' get cmdline!\n");
                free(pChipInfo);
                return FALSE;
        }
    }
    free(pChipInfo);
    return TRUE;
}
#endif  // #ifdef CONFIG_UTOPIA_PROC_DBG_SUPPORT

#ifdef MSOS_TYPE_LINUX_KERNEL
#ifndef CONFIG_UTOPIA_EXPORT_ALL_SYMBOL
EXPORT_SYMBOL(MDrv_MIU_Set_BW_Monitor);
EXPORT_SYMBOL(MDrv_MIU_Get_BW);
#endif
#endif  // #ifdef MSOS_TYPE_LINUX_KERNEL
