/**
 * @file   secdrv_hw_hal.h
 * @brief  Header file for driver structure
 *
 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
 */

#ifndef __SECDRV_HW_HAL_H__
#define __SECDRV_HW_HAL_H__

#include "sec_g2d_4x.h"
#include "error.h"

#define MAXIMUM_DATA_LENGTH	1024
#define MAX_NAME_LENGTH		20

#if defined(CONFIG_UNI)
#define SB23_MAX_RSA_KEY	(2048 / 8)
#endif

struct secMem_t {
	int index;
	uint8_t name[MAX_NAME_LENGTH];
	uint32_t base;
	uint32_t size;
};

struct secMfcFw_t {
	uint8_t	*addr;
	uint32_t len;
};

enum aesMode_t {
	ECB_MODE,
	CBC_MODE,
	CBC_CTS_MODE,
	CTR_MODE,
};

enum cipherMode_t {
	ENCRYPT,
	DECRYPT,
	ENCRYPT_DECRYPT,
};

enum cipherAlgorithm_t {
	AES_CBC_128_NO_PADDING = 0,
	AES_CTR_128_NO_PADDING = 1,
};

enum contentMode_t {
	VIDEO,
	AUDIO,
};

enum flag_lists {
	OEM_FLAG,
	HDCP2_FLAG,
	PLAYREADY_FLAG,
	NUM_FLAGS,
};

enum subsample_flags {
	NO_FIRST_LAST = 0,
	FIRST_SUB_SAMPLE = 1,
	LAST_SUB_SAMPLE = 2,
	BOTH_FIRST_LAST = 3,
};

struct secSss_t {
	uint32_t *key;
	uint32_t key_len;
	uint32_t *iv;
	uint32_t iv_len;
	uint8_t	*input;
	uint32_t input_len;
	uint8_t	*output;
	uint32_t block_offset;
	uint32_t *output_len;
	uint32_t cbc_iv_flag;
	enum aesMode_t mode;
	enum cipherMode_t cipher_mode;
	enum contentMode_t content_mode;
};

struct secCipher_t {
	uint32_t *key;
	uint32_t key_len;
	uint32_t *iv;
	uint32_t iv_len;
	uint8_t	*input;
	uint32_t input_len;
	uint8_t	*output;
	uint32_t output_len;
	size_t block_offset;
	enum cipherAlgorithm_t cipher_algo;
	enum cipherMode_t cipher_mode;
	enum subsample_flags subsample_flags;
};

struct secBlit_t {
	enum blit_op op;
	struct fimg2d_param param;
	struct fimg2d_image src;
	struct fimg2d_image msk;
	struct fimg2d_image tmp;
	struct fimg2d_image dst;
	enum blit_sync sync;
	unsigned int seq_no;
};

struct secFlag_t {
	uint32_t *addr;
	uint32_t value;
};

struct secRtc_t {
	uint32_t tm_sec;
	uint32_t tm_min;
	uint32_t tm_hour;
	uint32_t tm_mday;
	uint32_t tm_mon;
	uint32_t tm_year;
};

struct secRtcTick_t {
	bool tick_enable;
	uint32_t tick_cnt_val;
};

struct secMemcpy_t {
	uint8_t *dst;
	uint8_t *src;
	uint32_t len;
};

struct secDrm_ctx_t {
	uint32_t chunk_num;
	struct secMem_t *secMem;
	struct secMfcFw_t *secMfcFw;
	struct secSss_t *secSss;
	struct secBlit_t *secBlit;
	struct secFlag_t secFlag[NUM_FLAGS];
	struct secRtc_t *secRtc;
	struct secMemcpy_t *secMemcpy;
	uint8_t *hdcp_bksv;
	uint32_t cp_mask;
	struct secCipher_t *secCipher;
	struct secRtcTick_t *secRtcTick;
};

#if defined(CONFIG_UNI)
struct SB23_RSAPubKey {
	int		rsa_n_Len;
	unsigned char	rsa_n[SB23_MAX_RSA_KEY];
	int		rsa_e_Len;
	unsigned char	rsa_e[4];
};

struct secCp_t {
	uint32_t mem_base;
	uint32_t mem_size;
	uint32_t target_base;
	uint32_t target_size;
	uint32_t firm_magic;
	struct SB23_RSAPubKey rsa_pubkey;
};
#endif

#endif /* __SECDRV_HW_HAL_H__ */

