/**
 * @file   tlapi_secdrv.h
 * @brief  Header file for API to call driver
 *
 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
 *
 * This software is proprietary of Samsung Electronics.
 * No part of this software, either material or conceptual may be copied
 * or distributed, transmitted, transcribed, stored in a retrieval system
 * or translated into any human or computer language in any form by any means,
 * electronic, mechanical, manual or otherwise, or disclosed to third parties
 * without the express written permission of Samsung Electronics.
 */

#ifndef __TLAPI_SECDRV_H__
#define __TLAPI_SECDRV_H__

#include "TlApi/TlApiCommon.h"
#include "TlApi/TlApiError.h"
#include "secdrv_hw_hal.h"

/**
 * Initialize Secure driver for DRM playback.
 *
 * @secMem : the pointer of secure region data
 * @check_num : the number for secure regions
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : secure driver is initialized successfully.
 *	@E_TLAPI_UNMAPPED_BUFFER : Failed to initialize due to map the address.
 *	@E_TLAPI_INVALID_PARAMETER : Invalid Secmem data.
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSecInitialization(struct secMem_t *secmem,
							int chunk_num);

/**
 * Finalize Secure driver for DRM playback.
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : Always successfully.
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSecFinalization(void);

/**
 * Initialize SSS driver for clock, tzpc
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : secure driver is initialized successfully.
 *	@E_TLAPI_DRV_UNKNOWN : Failed to initialize SSS driver.
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSecSssInit(void);

/**
 * Run SSS driver for decrypting the contents
 *
 * @secSss : the pointer of SSS configuration data
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : secure driver is operated successfully.
 *	@E_TLAPI_INVALIED_PARAMETER : Invalid SSS input data
 *	@E_TLAPI_DRV_UNKNOWN : Failed SSS decryption
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiAddrCheck(struct secSss_t *secSss);

/**
 * Finalize SSS driver for clock, tzpc
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : secure driver is finalized successfully.
 *	@E_TLAPI_DRV_UNKNOWN : Failed to finalized SSS driver.
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSecSssExit(void);

/**
 * Protect the content path with TZASC, TZPC, SYSMMU
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : The content path is protected successfully.
 *	@E_TLAPI_DRV_UNKNOWN : Failed to protect the content path.
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSecStartContentPathProtection(uint32_t cp_mask);

/**
 * Unprotect the content path with TZASC, TZPC, SYSMMU
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : The content path is unprotected successfully.
 *	@E_TLAPI_DRV_UNKNOWN : Failed to unprotect the content path.
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSecStopContentPathProtection(uint32_t cp_mask);

/**
 * Load the MFC F/W binary to secure region
 *
 * @secMfcFw : the Pointer for MFC FW binary address and length
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : The MFC F/W binary is loaded successfully.
 *	@E_TLAPI_DRV_UNKNOWN : Failed to load MFC F/W binary.
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSecLoadMfcFW(struct secMfcFw_t *secMfcFw);

/**
 * Check whether the content path is protected or not.
 *
 * @hdmi_check : the pointer for hdmi status (return value)
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : There is no malicious attack
 *	@E_TLAPI_DRV_UNKNOWN : Failed to decryption due to malicious attack.
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiProtectionCheck(uint32_t *hdmi_check);

/**
 * Initialize G2D driver
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : G2D driver initialization is successful.
 *	@E_TLAPI_DRV_UNKNOWN : Failed to initialize G2D driver.
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSecG2DInit(void);

/**
 * Execute G2D Blit
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : G2D Blit is successful.
 *	@E_TLAPI_DRV_UNKNOWN : Failed to blit G2D.
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSecG2DBlit(struct secBlit_t *secblit);

/**
 * Terminate G2D driver
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : G2D driver termination is successful.
 *	@E_TLAPI_DRV_UNKNOWN : Failed to terminate G2D driver.
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSecG2DExit(void);

/**
 * Get OEM FLAG value
 *
 * @addr : the pointer for getting OEM flag value
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : Get OEM flag value successfully
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSecGetOemFlag(uint32_t *addr);

/**
 * Get HDCP2 FLAG value
 *
 * @addr : the pointer for getting HDCP2 flag value
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : Get HDCP2 flag value successfully
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSecGetHdcp2Flag(uint32_t *addr);

/**
 * Set HDCP2 FLAG value
 *
 * @value : the value for setting HDCP2 flag value
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : Set HDCP2 flag value successfully
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSecSetHdcp2Flag(uint32_t value);

/**
 * Set MFC magic key
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : Set MFC magic key successfully
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSecMfcMagicKey(void);

/**
 * Set MFC magic key for HDCP
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : Set MFC magic key for HDCP successfully
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSecMfcMagicKeyHdcp(void);

/**
 * Get HDCP BKSV value
 *
 * @addr : the pointer for getting BKSV value
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : Get BKSV value successfully
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSecHdcpBksv(uint8_t *hdcp_bksv);

/**
 * Get RTC time value
 *
 * @secRtc : the pointer to get RTC timer
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : Get RTC value successfully
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiGetSecureRTCtime(struct secRtc_t *secRtc);

/**
 * Set RTC time value
 *
 * @secRtc : the pointer to set RTC timer
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : Set RTC value successfully
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSetSecureRTCtime(struct secRtc_t *secRtc);

/**
 * Phys2Phys Memcpy
 *
 * @secMemcpy: the pointer for src, dst, len to memcpy
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : Memcpy phys2phys is successfully
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiPhys2PhysMemcpy(struct secMemcpy_t *secMemcpy);

/**
 * Virt2Phys Memcpy
 *
 * @secMemcpy: the pointer for src, dst, len to memcpy
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : Memcpy virt2phys is successfully
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiVirt2PhysMemcpy(struct secMemcpy_t *secMemcpy);

/**
 * Phys2Virt Memcpy
 *
 * @secMemcpy: the pointer for src, dst, len to memcpy
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : Memcpy phys2virt is successfully
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiPhys2VirtMemcpy(struct secMemcpy_t *secMemcpy);

/**
 * Run generic cipher for ecrypting/decrypting the contents
 *
 * @secCipher : The pointer of Generic Cipher configuration data
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : Secure driver is operated successfully.
 *	@E_TLAPI_INVALIED_PARAMETER : Invalid SSS input data
 *	@E_TLAPI_DRV_UNKNOWN : Failed SSS encryption/decryption
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSecGenericCipher(struct secCipher_t *secCipher);

/**
 * Get RTC tick time value
 *
 * @secRtcTick : the pointer of RTC Tick value configuration data
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : Get RTC Tick value successfully
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiGetSecureRTCTicktime(struct secRtcTick_t *secRtcTick);

/**
 * Set RTC tick time value
 *
 * @secRtcTick : the pointer of RTC Tick value configuration data
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : Set RTC Tick value successfully
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiSetSecureRTCTicktime(struct secRtcTick_t *secRtcTick);

/**
 * Get maximum and current HDCP version
 *
 * @SecureHDCPVer : the pointer of maximum and current HDCP version
 *
 * @return : tlApiResult_t
 *	@TLAPI_OK : Get RTC Tick value successfully
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiGetHDCPVersion(struct secHDCPVer_t *SecureHDCPVer);

#if defined(CONFIG_SRPMB)
/**
 * Write RPMB data
 *
 * @partition : The partition name in RPMB
 *	The RPMB partition is divided into 8 for multi users
 *	Each partition size is 512KB
 *	It can be 1,2,3,4,5,6,7,8
 * @address : The start address of RPMB for write
 *	The start address is '0' each partition
 *	The data size is 256byte per address '1'
 * @*data : The virtual address of input data
 * @blk_num : The block number of input data length in bytes
 *	The data size is 256byte per block '1'
 *	This value must be less than '256' (32KB at once write)
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiRpmbWrite(
	uint32_t partition,
	uint32_t address,
	uint8_t *data,
	uint32_t blk_num);

/**
 * Read RPMB data
 *
 * @partition : The partition name in RPMB
 *	The RPMB partition is divided into 8 for multi users
 *	Each partition size is 512KB
 *	It can be 1,2,3,4,5,6,7,8
 * @address : The start address of RPMB for write
 *	The start address is '0' each partition
 *	The data size is 256byte per address '1'
 * @blk_num : The block number of input data length in bytes
 *	The data size is 256byte per block '1'
 *	This value must be less than '256' (32KB at once write)
 * @*output_data : The virtual address of output buffer
 *	in read RPMB data
 */
_TLAPI_EXTERN_C tlApiResult_t tlApiRpmbRead(
	uint32_t partition,
	uint32_t address,
	uint32_t blk_num,
	uint8_t *output_data);
#endif /* srpmb */
#endif /* __TLAPI_SECDRV_H__ */
