14e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park/** @addtogroup FCI
24e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @{
34e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @file
44e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * Declaration of FastCall helper functions.
54e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *
64e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @attention Helper functions are mostly RealView (ARM CC) specific.
74e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *
84e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * Holds the functions for SIQ, YIELD and FastCall for switching to the secure world.
94e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * <!-- Copyright Giesecke & Devrient GmbH 2009-2012 -->
104e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *
114e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * Redistribution and use in source and binary forms, with or without
124e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * modification, are permitted provided that the following conditions
134e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * are met:
144e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * 1. Redistributions of source code must retain the above copyright
154e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *    notice, this list of conditions and the following disclaimer.
164e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * 2. Redistributions in binary form must reproduce the above copyright
174e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *    notice, this list of conditions and the following disclaimer in the
184e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *    documentation and/or other materials provided with the distribution.
194e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * 3. The name of the author may not be used to endorse or promote
204e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *    products derived from this software without specific prior
214e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *    written permission.
224e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *
234e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
244e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
254e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
264e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
274e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
284e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
294e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
304e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
314e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
324e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
334e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
344e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park */
354e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
364e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park#ifndef MCIFCFUNC_H_
374e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park#define MCIFCFUNC_H_
384e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
394e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park#include "mcifc.h"
404e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park/**
414e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * Execute a secure monitor call (SMC).
424e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *
434e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @param mode SMC mode affects the way SMC is handled
444e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *
454e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @attention This function shall not be used directly. Use N_Siq() or Yield() instead.
464e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park */
474e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park__smc(0) void smc(int32_t mode);
484e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
494e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park/**
504e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * N-SIQ switch from NWd to SWd.
514e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * Execution will continue in the SWd. The notification queue will be drained by the MC4 and MC4 system schedules its services.
524e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park */
534e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Parkinline void N_Siq(void) { smc(MC_SMC_N_SIQ); }
544e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
554e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park/**
564e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * Yield switch from NWd to SWd.
574e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * Execution will continue in the SWd without scheduling MC4 services.
584e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park */
594e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Parkinline void Yield(void) { smc(MC_SMC_N_YIELD); }
604e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
614e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park/** Wrapper structure for parameter passing in registers.
624e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *  This structure is used as a "wrapper" return value for functions that
634e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *  return data in the registers r0 to r3. With the RealView compiler such
644e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *  function are declare as:  _value_in_regs reg_r0_r1_r2_r3_t foo()
654e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
664e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park */
674e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Parktypedef struct {
684e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park    uint32_t r0;
694e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park    uint32_t r1;
704e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park    uint32_t r2;
714e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park    uint32_t r3;
724e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park} reg_r0_r1_r2_r3_t;
734e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
744e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park/** Parameterized SMC for FastCalls.
754e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @attention This function shall not be used directly.
764e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park */
774e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park__smc(0) __value_in_regs  reg_r0_r1_r2_r3_t smcFc(
784e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint32_t r0,
794e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint32_t r1,
804e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint32_t r2,
814e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint32_t r3
824e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park);
834e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
844e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park/** FastCall helper function.
854e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @attention This function shall not be used directly.
864e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park */
874e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Parkinline static __value_in_regs reg_r0_r1_r2_r3_t fastCall(
884e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint32_t r0,
894e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint32_t r1,
904e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint32_t r2,
914e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint32_t r3
924e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park) {
934e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park    return smcFc(r0,r1,r2,r3);
944e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park}
954e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
964e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park/**
974e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * Initialize the MobiCore.
984e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * The FcMc4init FastCall shall be used to set up the MCI. The function passes the message buffers used in the MCI to the MC4 system.
994e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * As long as the buffers are not set up the MC4 message passing mechanisms (notifications, MCP commands) are not available.
1004e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * NQ buffer and MCP buffer as well as length calculations are described in the "MobiCore4 Driver Interface Specification".
1014e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * <br> The fastCallInit() will not check the parameters for validity. Instead the MC4 will perform a check on first usage of the parameters.
1024e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *
1034e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @image html DoxyMciBuffer.png "MCI buffer"
1044e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @image latex DoxyMciBuffer.png "MCI buffer" width=12cm
1054e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *
1064e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @param base      Physical start address of the MCI buffer. Must be 4kB aligned.
1074e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @param nqOffset  Offset in bytes  to the beginning of the NQ buffer.
1084e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @param nqLength  Length of the NQ buffer in bytes.
1094e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @param mcpOffset Offset in bytes to the beginning of the MCP buffer.
1104e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @param mcpLength Length of the MCP buffer in bytes
1114e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *
1124e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park */
1134e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Parkinline static uint32_t fastCallInit(
1144e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint8_t *base,
1154e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint32_t  nqOffset,
1164e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint32_t  nqLength,
1174e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint32_t  mcpOffset,
1184e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint32_t  mcpLength
1194e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park) {
1204e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
1214e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park    reg_r0_r1_r2_r3_t ret;
1224e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
1234e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park    ret = fastCall(
1244e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park            MC_FC_INIT,
1254e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park            (uint32_t)base,
1264e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park            ((nqOffset << 16) | (nqLength & 0xFFFF)),
1274e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park            ((mcpOffset << 16) | (mcpLength & 0xFFFF)) );
1284e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
1294e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
1304e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park    return ret.r1;
1314e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park}
1324e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
1334e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
1344e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park/** Get status information about MobiCore.
1354e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * The FcMcGetInfo FastCall provides information about the current state of the MobiCore.
1364e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * In certain states extended information is provided.
1374e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *
1384e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @param extInfoId Extended info word to be obtained.
1394e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @param mc4state Current state of the MobiCore.
1404e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @param extInfo Extended information depending on state.
1414e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park */
1424e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Parkinline static uint32_t fastCallGetInfo(
1434e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint32_t extInfoId,
1444e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint32_t *mc4state,
1454e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint32_t *extInfo
1464e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park) {
1474e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park    reg_r0_r1_r2_r3_t ret;
1484e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
1494e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park    ret = fastCall(MC_FC_INFO,extInfoId,0,0);
1504e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
1514e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park    if (MC_FC_RET_OK == ret.r1)
1524e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park    {
1534e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        *mc4state = ret.r2;
1544e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        *extInfo = ret.r3;
1554e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park    }
1564e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
1574e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park    return ret.r1;
1584e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park}
1594e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
1604e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park/**
1614e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * Power management.
1624e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * The power management FastCall is platform specific.
1634e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park *
1644e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @param param0  platform specific parameter.
1654e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @param param1  platform specific parameter.
1664e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @param param2  platform specific parameter.
1674e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park */
1684e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Parkinline static uint32_t fastCallPower(
1694e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint32_t param0,
1704e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint32_t param1,
1714e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park        uint32_t param2
1724e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park) {
1734e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
1744e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park    reg_r0_r1_r2_r3_t ret;
1754e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
1764e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park    ret = fastCall(
1774e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park            MC_FC_POWER,
1784e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park            param0,
1794e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park            param1,
1804e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park            param2 );
1814e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
1824e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park    return ret.r1;
1834e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park}
1844e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park
1854e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park#endif /* MCIFCFUNC_H_ */
1864e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park/**
1874e9e8c9c0169b40318386436d762c3d73cf4c328DongJin Park * @}*/
188