
/*
 * =====================================================================================
 *
 *       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"
#include "TlApiDrTima.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;

        HDM_LOG("%s: policy is 0x%x, command is 0x%x", __func__, policy, command);

        SetHdmPolicy_t HdmPolicyParam;
        HdmPolicyParam.r1 = HDM_MAGIC;
        HdmPolicyParam.r2 = command;
        HdmPolicyParam.r3 = policy;
        HdmPolicyParam.ret_val = ~0;

        HDM_LOG_DEBUG("before TEES_El2if() HdmPolicyParam.r1 = %x, HdmPolicyParam.r2 = %d, HdmPolicyParam.r3 = %d\n", HdmPolicyParam.r1, HdmPolicyParam.r2, HdmPolicyParam.r3);
        if (0 != (ret = tlApiTimaDriverSetHdmPolicy(&HdmPolicyParam))) {
            HDM_LOG_DEBUG(TAG "after TEES_El2if() ret = %d\n", ret);
            return (ret);
        }
        HDM_LOG_DEBUG(TAG "after HdmPolicyParam.ret_val = %d\n", HdmPolicyParam.ret_val);

        return HdmPolicyParam.ret_val;
}
