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

📄 mfc_instance.c

📁 6410BSP3
💻 C
📖 第 1 页 / 共 4 页
字号:
//
// 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 "Mfc.h"
#include "MFC_Instance.h"
#include "MfcMemory.h"
#include "DataBuf.h"
#include "FramBufMgr.h"
#include "LogMsg.h"
#include "MfcConfig.h"
#include "MfcSfr.h"
#include "BitProcBuf.h"
#include "MFC_Inst_Pool.h"
#include "CacheOpr.h"

#ifdef LINUX
#include <asm/io.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <asm/uaccess.h>
#endif


static MFCInstCtx _mfcinst_ctx[MFC_NUM_INSTANCES_MAX];


MFCInstCtx *MFCInst_GetCtx(int inst_no)
{
    if ((inst_no < 0) || (inst_no >= MFC_NUM_INSTANCES_MAX))
        return NULL;

    if (MFCINST_STATE(&(_mfcinst_ctx[inst_no])) >= MFCINST_STATE_CREATED)
        return &(_mfcinst_ctx[inst_no]);
    else
        return NULL;
}



// Filling the pStrmBuf and phyadrStrmBuf variables of the MfcInstCtx structure
// (pStrmBuf and phyadrStrmBuf are the virtual and physical address of STRM_BUF(stream buffer) respectively.)
static void Get_MfcStrmBufAddr(MFCInstCtx *ctx)
{
        ctx->pStrmBuf        = (unsigned char *) ( GetDataBufVirAddr() + (ctx->inst_no * MFC_LINE_BUF_SIZE_PER_INSTANCE) );
        ctx->phyadrStrmBuf    = (PHYADDR_VAL) ( GetDataBufPhyAddr() + (ctx->inst_no * MFC_LINE_BUF_SIZE_PER_INSTANCE) );
        ctx->nStrmBufSize   = MFC_LINE_BUF_SIZE_PER_INSTANCE;

    LOG_MSG(LOG_TRACE, "Get_MfcStrmBufAddr", "ctx->pStrmBuf address 0x%08X\n", ctx->pStrmBuf);
    LOG_MSG(LOG_TRACE, "Get_MfcStrmBufAddr", "ctx->phyadrStrmBuf address 0x%08X\n", ctx->phyadrStrmBuf);
}

// Filling the pFramBuf and phyadrFramBuf variables of the MfcInstCtx structure
// (pFramBuf and phyadrFramBuf are the virtual and physical address of FRAM_BUF(frame buffer) respectively.)
static BOOL Get_MfcFramBufAddr(MFCInstCtx *ctx, int buf_size)
{
    unsigned char    *pInstFramBuf;

    pInstFramBuf    = FramBufMgrCommit(ctx->inst_no, buf_size);
    if (pInstFramBuf == NULL) {
        LOG_MSG(LOG_ERROR, "Get_MfcFramBufAddr", "Frame buffer allocation was failed!\r\n");
        return FALSE;
    }

#ifdef DEBUG
    FramBufMgrPrintCommitInfo();
#endif

    ctx->pFramBuf       = pInstFramBuf;    // virtual address of frame buffer
    ctx->phyadrFramBuf  = S3C6410_BASEADDR_MFC_DATA_BUF + ( (int)pInstFramBuf - (int)GetDataBufVirAddr() );
    ctx->nFramBufSize   = buf_size;

    LOG_MSG(LOG_TRACE, "Get_MfcFramBufAddr", "ctx->inst_no : %d\r\n", ctx->inst_no);
    LOG_MSG(LOG_TRACE, "Get_MfcFramBufAddr", "ctx->pFramBuf : 0x%X\r\n", ctx->pFramBuf);
    LOG_MSG(LOG_TRACE, "Get_MfcFramBufAddr", "ctx->phyadrFramBuf : 0x%X\r\n", ctx->phyadrFramBuf);

    return TRUE;
}


void MFCInst_RingBufAddrCorrection(MFCInstCtx *ctx)
{
    Get_MfcStrmBufAddr(ctx);
}



int MFCInst_GetLineBuf(MFCInstCtx *ctx, unsigned char **ppBuf, int *size)
{
    ////////////////////////////
    ///    STATE checking    ///
    ////////////////////////////
    if (MFCINST_STATE_CHECK(ctx, MFCINST_STATE_DELETED)) {
        LOG_MSG(LOG_ERROR, "MFCInst_GetRingBuf", "MFC instance is deleted.\r\n");
        return MFCINST_ERR_STATE_DELETED;
    }

    *ppBuf = ctx->pStrmBuf;
    *size  = MFC_LINE_BUF_SIZE_PER_INSTANCE;

    return MFCINST_RET_OK;
}

int MFCInst_GetFramBuf(MFCInstCtx *ctx, unsigned char **ppBuf, int *size)
{
    ////////////////////////////
    ///    STATE checking    ///
    ////////////////////////////
    if (MFCINST_STATE_CHECK(ctx, MFCINST_STATE_DELETED)) {
        LOG_MSG(LOG_ERROR, "MFCInst_GetFramBuf", "MFC instance is deleted.\r\n");
        return MFCINST_ERR_STATE_DELETED;
    }
    if (MFCINST_STATE_CHECK(ctx, MFCINST_STATE_CREATED)) {
        LOG_MSG(LOG_ERROR, "MFCInst_GetFramBuf", "MFC instance is not initialized.\r\n");
        return MFCINST_ERR_STATE_CHK;
    }

    if (ctx->pFramBuf == NULL) {
        LOG_MSG(LOG_ERROR, "MFCInst_GetFramBuf", "MFC Frame buffer is not internally allocated yet.\n");
        return MFCINST_ERR_ETC;
    }



    *size  = (ctx->buf_width * ctx->buf_height * 3) >> 1;    // YUV420 frame size

    if (ctx->run_index < 0)    // RET_DEC_PIC_IDX == -3  (No picture to be displayed)
        *ppBuf = NULL;
    else {
        *ppBuf = ctx->pFramBuf + (ctx->run_index) * (*size);
#if (MFC_ROTATE_ENABLE == 1)
        if (ctx->PostRotMode & 0x0010)
            *ppBuf = ctx->pFramBuf + (ctx->frambufCnt) * (*size);
#endif
    }


    return MFCINST_RET_OK;
}

int MFCInst_GetFramBufPhysical(MFCInstCtx *ctx, unsigned char **ppBuf, int *size)
{
    ////////////////////////////
    ///    STATE checking    ///
    ////////////////////////////
    if (MFCINST_STATE_CHECK(ctx, MFCINST_STATE_DELETED)) {
        LOG_MSG(LOG_ERROR, "MFCInst_GetFramBuf", "MFC instance is deleted.\r\n");
        return MFCINST_ERR_STATE_DELETED;
    }
    if (MFCINST_STATE_CHECK(ctx, MFCINST_STATE_CREATED)) {
        LOG_MSG(LOG_ERROR, "MFCInst_GetFramBuf", "MFC instance is not initialized.\r\n");
        return MFCINST_ERR_STATE_CHK;
    }

    if (ctx->pFramBuf == NULL) {
        LOG_MSG(LOG_ERROR, "MFCInst_GetFramBuf", "MFC Frame buffer is not internally allocated yet.\n");
        return MFCINST_ERR_ETC;
    }

#if (defined(DIVX_ENABLE) && (DIVX_ENABLE == 1))
    *size  = (ctx->buf_width* ctx->buf_height* 3) >> 1;    // YUV420 frame size
#else
    *size  = (ctx->width * ctx->height * 3) >> 1;    // YUV420 frame size
#endif

    if (ctx->run_index < 0)    // RET_DEC_PIC_IDX == -3  (No picture to be displayed)
        *ppBuf = NULL;
    else
        *ppBuf = (unsigned char *) ( ctx->phyadrFramBuf + (ctx->run_index) * (*size) );


    return MFCINST_RET_OK;
}

//
// Function Name: MFCInst_GetInstNo
// Description
//      It returns the instance number of the 6410 MFC instance context.
// Parameters
//      ctx[IN]: MFCInstCtx
//
int MFCInst_GetInstNo(MFCInstCtx *ctx)
{
    return ctx->inst_no;
}

//
// Function Name: MFCInst_GetStreamRWPtrs
// Description
//      It returns the virtual address of RD_PTR and WR_PTR.
// Parameters
//      ctx[IN]: MFCInstCtx
//      ppRD_PTR[OUT]: RD_PTR
//      ppWR_PTR[OUT]: WR_PTR
//
BOOL MFCInst_GetStreamRWPtrs(MFCInstCtx *ctx, unsigned char **ppRD_PTR, unsigned char **ppWR_PTR)
{
    S3C6410_MFC_SFR    *mfc_sfr;        // MFC SFR pointer
    int              diff_vir_phy;


    if (MFCINST_STATE(ctx) < MFCINST_STATE_CREATED)
        return FALSE;

    if (MFCINST_STATE_CHECK(ctx, MFCINST_STATE_CREATED)) {
        // If MFCInstCtx is just created and not initialized by MFCInst_Init,
        // then the initial RD_PTR and WR_PTR are the start address of STRM_BUF.
        *ppRD_PTR = ctx->pStrmBuf;
        *ppWR_PTR = ctx->pStrmBuf;
    }
    else {
        // The physical to virtual address conversion of RD_PTR and WR_PTR.
        diff_vir_phy  =  (int) (ctx->pStrmBuf - ctx->phyadrStrmBuf);
        mfc_sfr = (S3C6410_MFC_SFR *) GetMfcSfrVirAddr();
        *ppRD_PTR = (unsigned char *) (diff_vir_phy + mfc_sfr->BIT_STR_BUF_RW_ADDR[ctx->inst_no].BITS_RD_PTR);
        *ppWR_PTR = (unsigned char *) (diff_vir_phy + mfc_sfr->BIT_STR_BUF_RW_ADDR[ctx->inst_no].BITS_WR_PTR);
    }

    return TRUE;
}


unsigned int MFCInst_Set_PostRotate(MFCInstCtx *ctx, unsigned int post_rotmode)
{
    unsigned int old_post_rotmode;

    old_post_rotmode = ctx->PostRotMode;

    if (post_rotmode & 0x0010) {
        ctx->PostRotMode = post_rotmode;
    }
    else
        ctx->PostRotMode = 0;


    return old_post_rotmode;
}


MFCInstCtx *MFCInst_Create(void)
{
    MFCInstCtx *ctx;
    int        inst_no;

    // Occupy the 'inst_no'.
    // If it fails, it returns NULL.
    inst_no = MfcInstPool_Occupy();
    if (inst_no == -1)
        return NULL;


    ctx = &(_mfcinst_ctx[inst_no]);

    Mem_Set(ctx, 0, sizeof(MFCInstCtx));

    ctx->inst_no     = inst_no;
    MFCINST_STATE_TRANSITION(ctx, MFCINST_STATE_CREATED);

    Get_MfcStrmBufAddr(ctx);
    LOG_MSG(LOG_TRACE, "s3c_mfc_open", "state : %d\n", ctx->state_var);


    return ctx;
}


//
// Function Name: MFCInst_Delete
// Description
//      It deletes the 6410 MFC instance.
// Parameters
//      ctx[IN]: MFCInstCtx
//
void MFCInst_Delete(MFCInstCtx *ctx)
{
    ////////////////////////////
    ///    STATE checking    ///
    ////////////////////////////
    if (MFCINST_STATE_CHECK(ctx, MFCINST_STATE_DELETED)) {
        LOG_MSG(LOG_ERROR, "MFCInst_Delete", "MFC instance is already deleted.\r\n");
        return;
    }

    MfcInstPool_Release(ctx->inst_no);
    FramBufMgrFree(ctx->inst_no);

    MFCINST_STATE_TRANSITION(ctx, MFCINST_STATE_DELETED);
}


//
// Function Name: MFCInst_PowerOffState
// Description
//      It turns on the flag indicating 6410 MFC's power-off.
// Parameters
//      ctx[IN]: MFCInstCtx
//
void MFCInst_PowerOffState(MFCInstCtx *ctx)
{
    MFCINST_STATE_PWR_OFF_FLAG_SET(ctx);
}

⌨️ 快捷键说明

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