/*
 * app_driver.h
 */

#ifndef _APP_DRIVER_H_
#define _APP_DRIVER_H_

#define ICCC_MEM_ADDR_ERROR    0
#define PARAM_FOR_ICCC_SEC_MEM 0

#define ICCC_SECURE_MEM_BASE_ADDR 0x00000000

// .../tima_common/inc/logging.h
#define SVC_ICCCUTIL_ID        0x00070000
#define ICCCUTIL_CREATE_CMD(x) (SVC_ICCCUTIL_ID | x)

// .../tima_common/inc/tima_ioctl.h
struct ioctl_mem_access_data {
    uint32_t phys_addr;
    uint32_t len;
    char* rw_addr;
    int32_t status;
};

// .../tima_common/inc/tima_ioctl.h
#if defined(SUPPORT_ICCC_DRV)
typedef enum {
    ICCCUTIL_SECURE_PHYS_READ      = ICCCUTIL_CREATE_CMD(0x00000041),
    ICCCUTIL_SECURE_PHYS_WRITE     = ICCCUTIL_CREATE_CMD(0x00000042),
} icccutil_cmd_type;
#else
typedef enum {
    ICCCUTIL_DEBUG_LOG_WRITE       = ICCCUTIL_CREATE_CMD(0x00000000),
    ICCCUTIL_DEBUG_LOG_READ        = ICCCUTIL_CREATE_CMD(0x00000001),
    ICCCUTIL_SECURE_LOG_WRITE      = ICCCUTIL_CREATE_CMD(0x00000002),
    ICCCUTIL_SECURE_LOG_READ       = ICCCUTIL_CREATE_CMD(0x00000003),
    ICCCUTIL_SECURE_PHYS_READ      = ICCCUTIL_CREATE_CMD(0x00000041),
    ICCCUTIL_SECURE_PHYS_WRITE     = ICCCUTIL_CREATE_CMD(0x00000042),
    DMV_SRAM_READ_RECOVERY         = ICCCUTIL_CREATE_CMD(0x00000121)
} icccutil_cmd_type;
#endif

#if defined(SUPPORT_ICCC_DRV)
static const char drv_name[] = "/dev/iccc_driver";
#else
static const char drv_name[] = "/dev/tima_driver"; // TEEGRIS 4 - ICCC v4 (TA-to-TA)
#endif

static int drv_fd = -1;

uint32_t get_sec_ICCC_address(int type);
uint32_t Iccc_phys_write(void *offset, uint32_t length, void *data_buf);
uint32_t Iccc_phys_read(void *offset, uint32_t length, void *ret_buf);

#endif // _APP_DRIVER_H_
