/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/

/*-----------------------------------------------------------------------------
 *
 * $Author: danning.wang $
 * $Date: 2015/11/04 $
 * $RCSfile: dmx_emu_if.h,v $
 * $Revision: #2 $
 *
 *---------------------------------------------------------------------------*/

/** @file dmx_emu_if.h
 *  Interface of demux emulation driver
 */


#ifndef DMX_EMU_IF_H
#define DMX_EMU_IF_H

//-----------------------------------------------------------------------------
// Include files
//-----------------------------------------------------------------------------

#include "x_lint.h"

LINT_EXT_HEADER_BEGIN

#include "dmx_if.h"
#include "dmx_mm_if.h"
LINT_EXT_HEADER_END


//-----------------------------------------------------------------------------
// Configurations
//-----------------------------------------------------------------------------
;
//-----------------------------------------------------------------------------
// Constant definitions
//-----------------------------------------------------------------------------
typedef enum
{
    FULL_PUSH_MODE = 0,
    HALF_PULL_PUSH_MODE = 1,
    FULL_PULL_MODE = 3
} PUL_MODE_T;

//-----------------------------------------------------------------------------
// Macro definitions
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Prototype  of inter-file functions
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Prototype  of public functions
//-----------------------------------------------------------------------------

//---------------------------------------------------------------------
/// Emulation
//---------------------------------------------------------------------
EXTERN BOOL DMX_EMU_DDI_Init(UINT8 u1TsIndex);

EXTERN BOOL DMX_EMU_DDI_Exit(void);

EXTERN BOOL DMX_EMU_DDI_Transfer0(UINT8 u1Type, UINT8 u1TsIndex,
                                  UINT32 u4Size ,PUL_MODE_T eMode, BOOL fgBypassFramer);

EXTERN BOOL DMX_EMU_DDI_Transfer1(UINT8 u1Type, UINT32 u4Size ,PUL_MODE_T eMode);

EXTERN BOOL DMX_EMU_FramerUnlock_Test(UINT8 u1TsIndex, UINT32 u4Size ,PUL_MODE_T eMode );


EXTERN BOOL DMX_EMU_PVR_ResetTransfer(UINT8 u1TsIndex,BOOL fgBypassFramer, UINT8 u1TsoutIdx, UINT32 u4Size, BOOL fgIntr);
#if defined(CC_DMX_64BIT_MMU)
EXTERN BOOL DMX_EMU_PVR_MMU_64BIT(UINT8 u1TsIndex, UINT8 u1TsoutIdx, UINT8 u1Case, UINT8 u1Mode, UINT32 u4Size, BOOL fgIntr);
#endif
EXTERN BOOL DMX_EMU_PVR_MMU32BIT(UINT8 u1TsIndex,BOOL fgBypassFramer, UINT8 u1TsoutIdx, UINT32 u4Size, BOOL fgIntr);

EXTERN BOOL DMX_EMU_DDI_ResetTransfer(UINT8 u1TsIndex, BOOL fgBypassFramer, UINT32 u4Size, BOOL fgIntr);
/// TS pull mode

EXTERN BOOL DMX_EMU_PullTsTransfer0(UINT8 u1TsIndex, UINT32 u4Size,
                                    UINT16 u2Pid ,PUL_MODE_T eMode, BOOL fgBypassFramer);

EXTERN BOOL DMX_EMU_PullTsTransfer1(UINT8 u1TsIndex, UINT32 u4Size,
                                    UINT16 u2Pid ,PUL_MODE_T eMode);

EXTERN BOOL DMX_EMU_PullTsTransfer3(UINT8 u1TsIndex, UINT32 u4Size,
                                    UINT16 u2Pid ,PUL_MODE_T eMode);


EXTERN BOOL DMX_EMU_PullTsTransfer2(UINT32 u4Size ,PUL_MODE_T eMode);

EXTERN BOOL DMX_EMU_InitPullTsBuffers(UINT8 u1TsIndex);

EXTERN BOOL DMX_EMU_ReleasePullTsBuffers(void);

/// ES pull mode

EXTERN BOOL DMX_EMU_PullEsTransfer0(UINT8 u1TsIndex, UINT32 u4Size,
                                    UINT16 u2Pid ,PUL_MODE_T eMode);

EXTERN BOOL DMX_EMU_PullEsTransfer1(UINT8 u1TsIndex, UINT32 u4Size,
                                    UINT16 u2Pid ,PUL_MODE_T eMode);

// DES emulation

EXTERN BOOL DMX_EMU_Des0(UINT8 u1TsIndex, UINT32 u4Size, UINT16 u2Pid, UINT8 u1Type);

// AES emulation

EXTERN BOOL DMX_EMU_AES_SelfTest(void);

EXTERN BOOL DMX_EMU_AES_SelfTest2(void);

EXTERN BOOL DMX_EMU_AES_SelfTest3(void);

EXTERN BOOL DMX_EMU_AES_SelfTest4(UINT8 u1TsIndex);

EXTERN BOOL DMX_EMU_Aes0(UINT8 u1TsIndex, UINT32 u4Size, UINT16 u2Pid, UINT8 u1Type);

// DRM emulation

EXTERN BOOL DMX_EMU_Drm0(UINT8 u1TsIndex, UINT32 u4Size, UINT16 u2Pid,
                         DMX_DRM_MODE_T eMode);

EXTERN BOOL DMX_EMU_EncryptAes(UINT32 u4DstAddr, UINT32 u4SrcAddr, UINT32 u4Size, DMX_MM_DRM_AES_T* prAES);

EXTERN BOOL DMX_EMU_DrmNdSelfTest(void);

// Pattern Match
EXTERN BOOL DMX_EMU_PM_Transfer(UINT8 u1TsIndex);

// TS_output
EXTERN BOOL DMX_EMU_TSOut_Init(UINT8 u1TsIndex, UINT32 u4Size);
EXTERN BOOL DMX_EMU_TSOut_StressTest(void);

// Multi2 emulation
EXTERN BOOL DMX_EMU_Multi2Test(UINT8 u1TsIndex, UINT8 u1Type);

// DVB decryption
EXTERN BOOL DMX_EMU_DvbMain(UINT8 u1TsIndex, UINT8 u1Type, BOOL fgBypassFramer);

EXTERN BOOL DMX_EMU_SMS4(UINT8 u1TsIndex, UINT32 u4Size, UINT16 u2Pid, UINT8 u1Type);

//IOMMU
EXTERN BOOL DMX_EMU_DDI_IOMMU(UINT8 u1TsIndex, BOOL fgBypassFramer, UINT8 u1Mode);
EXTERN BOOL DMX_EMU_DDI_IOMMU_64BIT(UINT8 u1TsIndex, BOOL fgBypassFramer, UINT8 u1Case, UINT8 u1Mode);

EXTERN BOOL DMX_EMU_DMX_IOMMU(UINT8 u1TsIndex, BOOL fgBypassFramer, UINT8 u1Mode);

EXTERN BOOL DMX_EMU_DMXDDI_IOMMU(UINT8 u1TsIndex, BOOL fgBypassFramer, UINT8 u1Mode);

EXTERN BOOL DMX_EMU_IOMMU_PerformanceTest(UINT8 u1TsIndex, BOOL fgBypassFramer, BOOL fgIommu1, BOOL fgIommu2, BOOL fgIommu3);

EXTERN BOOL DMX_VideoEstest (UINT8 u1TsIdx, PUL_MODE_T eMode, BOOL fgBypassFramer);

EXTERN BOOL DMX_EMU_SecureBuffer_Test (UINT8 u1TsIdx, PUL_MODE_T eMode, BOOL fgBypassFramer);

EXTERN BOOL DMX_TsOut_ToCaOutput(UINT8 u1TsIndex, BOOL fgBypassFramer, UINT8 u1TsoutIdx);

EXTERN BOOL DMX_TsOut_ToFtup(UINT8 u1TsIndex, BOOL fgBypassFramer, UINT8 u1TsoutIdx);

EXTERN BOOL DMX_EMU_FVR_TimestampOnOffTest(UINT8 u1TsIndex, BOOL fgTimeStampOn, UINT8 u1TsOutIdx,UINT8 u1_PlayTsIndex);

EXTERN BOOL DMX_EMU_FVR_TimestampPauseTest(UINT8 u1TsIndex, UINT8 u1TsOutIdx,UINT8 u1_Play_TsIndex);

EXTERN BOOL DMX_EMU_FVR_TimestampErrTest(UINT8 u1TsIndex, UINT8 u1TsOutIdx,UINT8 u1_Play_TsIndex);

EXTERN BOOL DMX_EMU_FVR_TimestampResetTest(UINT8 u1TsIndex, UINT8 u1TsOutIdx,UINT8 u1_Play_TsIndex);


EXTERN BOOL DMX_EMU_DBM_Auto_SwitchTest(UINT8 u1TsOutIdx,  BOOL fgEnable_AutoSwitch);

EXTERN BOOL DMX_EMU_PSICALoopback_Test(UINT8 u1TsIdex, BOOL fgGenPat, DMX_FILTER_MODE_T eMode, UINT8 u1TsOutIdx);

EXTERN BOOL DMX_EMU_PSILoopback_Test(UINT8 u1TsIdex, BOOL fgGenPat, DMX_FILTER_MODE_T eMode,  UINT8 u1TsOutIdx);

EXTERN BOOL DMX_EMU_DDI_Bypass_Test(UINT8 u1TsIndex, BOOL fgRec);

EXTERN BOOL DMX_Emu_130TsTest(BOOL fgExtSync , UINT8 u1Tsindex);

EXTERN BOOL DMX_Emu_Tsout130_TransmitData(BOOL fgExtSync ,UINT8 u1Tsindex,UINT8 u1TsOutIndex);

EXTERN BOOL DMX_EMU_Multi_PacketSize_Test( BOOL fgFramer0Reset, BOOL fgFramer1Reset, UINT8 u1TsoutIdx);

EXTERN BOOL DMX_EMU_FVR_PES_Test(UINT8 u1TsIndex, UINT8 u1Pidx);

EXTERN BOOL DMX_EMU_DDI_TransferTest(UINT8 u1Mode, UINT8 u1TsIndex, BOOL fgBypassFramer);


EXTERN BOOL DMX_EMU_DDI_To_PID_FILTER_Transfer(UINT8 u1TsIndex,BOOL b_match);
EXTERN BOOL DMX_EMU_PVR_Reset_Bypass_Transfer(UINT8 u1TsIndex,BOOL pb_steer_bit9, UINT8 u1TsoutIdx,BOOL fgIntr,UINT32 u4Size);
EXTERN BOOL DMX_EMU_PVR_Reset_PID_FILTER_Transfer(UINT8 u1TsIndex,BOOL pb_steer_bit9, UINT8 u1TsoutIdx,BOOL fgIntr,UINT32 u4Size);

#endif  // DMX_EMU_IF_H

