⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mfcdriver.cpp

📁 6410BSP3
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//
// Copyright (c) Samsung Electronics. Co. LTD.  All rights reserved.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

*/


#include <windows.h>
#include <nkintr.h>
#if (_WIN32_WCE >= 600)
#include <s3c6410_vintr.h>
#define E2E_MFC
#else
#include <oal_intr.h>
#endif
#include <pm.h>
#include <pmplatform.h>


#include "MfcDriver.h"
#include "MfcPwrMgmt.h"
#include "MfcSetClk.h"
#include "MfcDrvParams.h"

#include "MfcConfig.h"

#include "MFC_HW_Init.h"
#include "MFC_Instance.h"
#include "MFC_Inst_Pool.h"
#include "MfcSfr.h"
#include "DataBuf.h"

#include "LogMsg.h"

#include "MfcMutex.h"
#include "MfcIntrNotification.h"
#include "CacheOpr.h"


static HANDLE gMfcIntrEvent;
static HANDLE gMfcIntrThread;

UINT32 g_MfcIrq     = IRQ_MFC;
UINT32 g_MfcSysIntr = SYSINTR_UNDEFINED;

static BOOL InitializeIST();
static LONG _openhandle_count = 0;


extern int MFC_GetConfigParams(MFCInstCtx  *pMfcInst, MFC_ARGS   *args);
extern int MFC_SetConfigParams(MFCInstCtx  *pMfcInst, MFC_ARGS   *args);


typedef struct _MFC_HANDLE
{
    MFCInstCtx  *mfc_inst;

#if (_WIN32_WCE >= 600)
    HANDLE          hUsrProc;    // Used for virtual address conversion (WCE600 or higher)
    unsigned char  *pStrmBuf;    // STRM_BUF pointer (virtual address of Application)
    unsigned char  *pFramBuf;    // FRAM_BUF pointer (virtual address of Application)
#endif

#if (defined(DIVX_ENABLE) && (DIVX_ENABLE == 1))
    unsigned char  *pMV;
    unsigned char  *pMBType;
#endif
} MFC_HANDLE;

static MFC_HANDLE   *gMfcHandlePower = NULL;



BOOL WINAPI
DllEntry(HANDLE hInstDll, DWORD dwReason, LPVOID lpvReserved)
{
    switch ( dwReason )
    {
    case DLL_PROCESS_ATTACH:

        DisableThreadLibraryCalls((HMODULE) hInstDll);
        break;

    }

    return (TRUE);
}

/*
** Function Name : MFC_Init
**
** Function Description : This function initialize MFC.
**                        MFC initailzation contains memory setup, clock configuration, HW initialization, IST initialization.
**                        First, You have to create mutex for mutual exclusive access of MFC.
*/
DWORD
MFC_Init(
    DWORD dwContext
    )
{
    /////////////////////////
    //  1. Mutex Creation  //
    /////////////////////////
    if (MFC_Mutex_Create() == FALSE)
    {
        // No CleanUp
        return FALSE;
    }

    ///////////////////////////
    //  2. MFC Memory Setup  //
    ///////////////////////////
    if (MFC_MemorySetup() == FALSE)
    {
        // CleanUp
        MFC_Mutex_Delete();
        return FALSE;
    }

    /////////////////////////////////////////
    //  3. MFC Clock divider configuration //
    /////////////////////////////////////////
    if (Mfc_Set_ClkDiv(MFC_CLOCK_DIVIDER_RATIO_HALF) == FALSE)
    {
        // CleanUp
        MFC_Mutex_Delete();
        return FALSE;
    }

    ///////////////////////////////////////////////////////
    //  4. IST(Interrupt Service Thread) Initialization  //
    ///////////////////////////////////////////////////////
    if (InitializeIST() == FALSE)
    {
        // CleanUp
        MFC_Mutex_Delete();
        return FALSE;
    }


    // Number of open handle
    _openhandle_count = 0;

    return MFC_INIT_SUCCESS;
}


/*
** Function Name : MFC_Deinit
**
** Function Description : This function de-initialize MFC
**                        In this case, You have to delete mutex only.
*/
BOOL
MFC_Deinit(
    DWORD InitHandle
    )
{
    // CleanUp IST
    if (g_MfcSysIntr != SYSINTR_UNDEFINED)
        InterruptDisable(g_MfcSysIntr);

    DeleteInterruptNotification();

    if (gMfcIntrEvent)
        CloseHandle(gMfcIntrEvent);

    // CleanUp Mutex
    MFC_Mutex_Delete();

    return TRUE;
}


/*
** Function Name : MFC_Open
**
** Function Description : This function open MFC instace and return instance handle.
*/
DWORD
MFC_Open(
    DWORD InitHandle,
    DWORD dwAccess,
    DWORD dwShareMode
    )
{
    MFC_HANDLE   *handle;

    // Mutex Lock
    MFC_Mutex_Lock();

    // Allocate & Clear MFC Handle
    handle = (MFC_HANDLE *) malloc(sizeof(MFC_HANDLE));
    if (!handle)
    {
        RETAILMSG(1, (L"\n[MFC_Open Error] Momory Allocation Fail.\n"));
        MFC_Mutex_Release();
        return 0;
    }
    memset(handle, 0, sizeof(MFC_HANDLE));

    // Increment OpenHandle Count
    InterlockedIncrement(&_openhandle_count);

    //
    if (_openhandle_count == 1) // Handle for Power Control
    {
        // Save Specific Handle for Power Control
        gMfcHandlePower = handle;
        RETAILMSG(1, (L"\n[MFC_Open] Power Manager Handle Opened...\n"));
    }
    else if (_openhandle_count >= 2) // Handle for User Application
    {
        // Create MFC Instance
        handle->mfc_inst = MFCInst_Create();
        if (!handle->mfc_inst)
        {
            RETAILMSG(1, (L"\n[MFC_Open Error] MFC Instance Creattion Fail.\n"));
            InterlockedDecrement(&_openhandle_count);
            free(handle);
            MFC_Mutex_Release();
            return 0;
        }

        if (_openhandle_count == 2) // First Handle for User Application
        {
            // MFC HW Init
            Mfc_Pwr_On();
            Mfc_Clk_On();

            if (MFC_HW_Init() == FALSE)
            {
                Mfc_Clk_Off();
                Mfc_Pwr_Off();
                MFCInst_Delete(handle->mfc_inst);
                InterlockedDecrement(&_openhandle_count);
                MFC_Mutex_Release();
                return 0;
            }
            Mfc_Clk_Off();
        }
    }

    // Mutex Release
    MFC_Mutex_Release();

    return (DWORD) handle;
}


/*
** Function Name : MFC_Close
**
** Function Description : This function close MFC instance.
**                        The instance handle and memory block free here.
*/
BOOL
MFC_Close(
    DWORD OpenHandle
    )
{
    MFC_HANDLE *handle;
    BOOL        ret;

    handle = (MFC_HANDLE *) OpenHandle;
    if (handle == NULL)
        return FALSE;

#if (_WIN32_WCE >= 600)
#ifdef E2E_MFC
{
    if(handle->pStrmBuf)
    {
        ret = VirtualFreeEx(handle->hUsrProc,    // HANDLE hProcess
                          handle->pStrmBuf,
                          0,
                          MEM_RELEASE);
        if (ret == FALSE)
            RETAILMSG(1, (L"\n[MFC_Close] VirtualFreeEx(STRM_BUF) returns FALSE.\n"));
    }

    if(handle->pFramBuf)
    {
        ret = VirtualFreeEx(handle->hUsrProc,    // HANDLE hProcess
                              handle->pFramBuf,
                              0,
                              MEM_RELEASE);
        if (ret == FALSE)
            RETAILMSG(1, (L"\n[MFC_Close] VirtualFreeEx(FRAM_BUF) returns FALSE.\n"));
    }
}
#else
{
    if(handle->pStrmBuf)
    {
        ret = VirtualFreeEx(handle->hUsrProc,    // HANDLE hProcess
                          handle->pStrmBuf,
                          handle->mfc_inst->nStrmBufSize,
                          MEM_DECOMMIT);
        if (ret == FALSE)
            RETAILMSG(1, (L"\n[MFC_Close] VirtualFreeEx(STRM_BUF) returns FALSE.\n"));
    }

    if(handle->pFramBuf)
    {
        ret = VirtualFreeEx(handle->hUsrProc,    // HANDLE hProcess
                              handle->pFramBuf,
                              handle->mfc_inst->nFramBufSize,
                              MEM_DECOMMIT);
        if (ret == FALSE)
            RETAILMSG(1, (L"\n[MFC_Close] VirtualFreeEx(FRAM_BUF) returns FALSE.\n"));
    }
}
#endif
#endif

    if (handle->mfc_inst)
    {
        MFCInst_Delete(handle->mfc_inst);
    }

    free(handle);

    // Decrement OpenHandle Count
    InterlockedDecrement(&_openhandle_count);

    if (_openhandle_count == 1)
    {   // Remain Power Control handle only.
        // MFC is now sw-reset.
        Mfc_Clk_On();
        MfcReset();
        Mfc_Clk_Off();

        // MFC Power Off
        Mfc_Pwr_Off();
    }
    else if (_openhandle_count == 0)
    {
        RETAILMSG(1, (L"\n[MFC_Close] Power Manager Handle closed...\n"));
        gMfcHandlePower = NULL;
    }

    return TRUE;
}

/*
** Function Name : process_MFC_PowerUp
**
** Function Description : This function Power up MFC.
*/
CEDEVICE_POWER_STATE
process_MFC_PowerUp(DWORD OpenHandle)
{
    static CEDEVICE_POWER_STATE   mfc_pwr_state;
    static BOOL                   is_mfc_on = FALSE;

// MOON_PowerManagementOfMultiInstance
    unsigned int            nNumOfInstance = 0;            
// End MOON_PowerManagementOfMultiInstance

    if ( mfc_pwr_state == D4)
    {
        if (is_mfc_on)
        {
// MOON_PowerManagementOfMultiInstance
        // Change Instance State
            for (int inst_no = 0; inst_no < MFC_NUM_INSTANCES_MAX; inst_no++) {
                MFCInstCtx *mfcinst_ctx = MFCInst_GetCtx(inst_no);
                if (mfcinst_ctx) {
                    nNumOfInstance++;
                    // On Power Up, the state of the MFC instance is recovered.
                    MFCInst_PowerOnState(mfcinst_ctx);
                }
            }
               LOG_MSG(LOG_TRACE, "MFC_IOControl", "[MFC IOCTL_POWER_SET] nNumOfInstance = 0x%X \r\n",nNumOfInstance);
        // Change MFC Power
            for (unsigned int nPwrLoof = 0; nPwrLoof < nNumOfInstance; nPwrLoof++)
            Mfc_Pwr_On();

        // Wakeup MFC
            if (is_mfc_on) {
            Mfc_Clk_On();
            MFC_Wakeup();
            Mfc_Clk_Off();

                   LOG_MSG(LOG_TRACE, "MFC_IOControl", "[MFC IOCTL_POWER_SET] POWER UP, handle = 0x%X \r\n",(DWORD) OpenHandle);
            }
        }
    }

    mfc_pwr_state = D0;    // MFC power state is now changed to D0(Power On) state.

    return mfc_pwr_state;
}

/*
** Function Name : process_MFC_PowerDown
**
** Function Description : This function Power down MFC.
*/
CEDEVICE_POWER_STATE
process_MFC_PowerDown(DWORD OpenHandle)
{
    static CEDEVICE_POWER_STATE   mfc_pwr_state;
    static BOOL                   is_mfc_on = FALSE;

// MOON_PowerManagementOfMultiInstance
    unsigned int            nNumOfInstance = 0;            
// End MOON_PowerManagementOfMultiInstance

    if ( mfc_pwr_state == D0)
    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -