
/*
 * =====================================================================================
 *
 *       Filename:  hdm_hypervisor.c
 *
 *    Description:  HDM hypervisor manipulation
 *
 *        Version:  1.0
 *        Created:  09/16/2019 15:26:11 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *        Company:  Samsung Electronics
 *        Copyright (c) 2015 by Samsung Electronics, All rights reserved.
 *
 * =====================================================================================
 */

/** Includes */
#include "hdm_hypervisor.h"

/**
 * @brief
 * hypervisor_communication
 * If command is write: Apply command bitmap (device block) on hypervisor.
 * If command is read: policy is useless
 *
 * @param[in] policy - policy device block
 * @param[in] command - read/write operation
 * @return TEE_Result
*/
TEE_Result hypervisor_communication(uint32_t policy, uint32_t command) {
        TEE_Result ret = TEE_SUCCESS;
        struct TEES_El2if_Args attr;


//TODO: remove sdk30
#if defined(SEC_SDK30)

        HDM_LOG("%s: commad is 0x%x", __func__, policy);
        attr.x0 = HDM_MAGIC;
        attr.x1 = 0;
        attr.x2 = policy;

        HDM_LOG_DEBUG("before TEES_El2if() attr.x0 = 0x%lx, attr.x1 = 0x%lx, attr.x2 = 0x%lx\n", attr.x0, attr.x1, attr.x2);
        ret = TEES_El2if(&attr);
        HDM_LOG_DEBUG("after TEES_El2if() ret = %d\n", ret);
        HDM_LOG_DEBUG("after TEES_El2if() attr.x0 = 0x%lx, attr.x1 = 0x%lx, attr.x2 = 0x%lx\n", attr.x0, attr.x1, attr.x2);

#endif

#if defined(SEC_SDK40)

        HDM_LOG("%s: commad is 0x%x", __func__, policy);
        attr.args[0] = HDM_MAGIC;
        attr.args[1] = 0;
        attr.args[2] = policy;

        HDM_LOG_DEBUG("before TEES_El2if() attr.x0 = 0x%lx, attr.x1 = 0x%lx, attr.x2 = 0x%lx\n", attr.args[0], attr.args[1], attr.args[2]);
        ret = TEES_El2if(&attr);
        HDM_LOG_DEBUG("after TEES_El2if() ret = %d\n", ret);
        HDM_LOG_DEBUG("after TEES_El2if() attr.x0 = 0x%lx, attr.x1 = 0x%lx, attr.x2 = 0x%lx\n", attr.args[0], attr.args[1], attr.args[2]);

#endif
        return ret;
}
