From f33d39c832959e1fb890433467f6b9bb29850df5 Mon Sep 17 00:00:00 2001 From: isiora Date: Wed, 7 Mar 2018 11:44:49 +0000 Subject: New tssi interface. git-svn-id: https://svn.code.sf.net/p/chibios/svn2/trunk@11608 110e8d01-0319-4d1e-a829-52ad28d1bb01 --- demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smc.S | 42 ------ .../ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.c | 67 --------- .../ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.h | 88 ------------ .../ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/tsclient.c | 105 ++++++++++++++ .../ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/tsclient.h | 157 +++++++++++++++++++++ 5 files changed, 262 insertions(+), 197 deletions(-) delete mode 100644 demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smc.S delete mode 100644 demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.c delete mode 100644 demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.h create mode 100644 demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/tsclient.c create mode 100644 demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/tsclient.h (limited to 'demos/ATSAMA5D2') diff --git a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smc.S b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smc.S deleted file mode 100644 index 8452dc190..000000000 --- a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smc.S +++ /dev/null @@ -1,42 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio. - - This file is part of ChibiOS. - - ChibiOS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file smcclient.S - * @brief SMC client module code. - * - * @addtogroup SMC - * @{ - */ - .section .text - .code 32 - .balign 4 -/* - * r0 smc_service_t handle - * r1 smc_params_area_t data - * r2 size_t size - * - * r0 msg_t result - */ - .global smcInvoke -smcInvoke: - smc #0 - bx lr -/** @} */ - diff --git a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.c b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.c deleted file mode 100644 index ef85a452b..000000000 --- a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio. - - This file is part of ChibiOS. - - ChibiOS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file smcclient.c - * @brief SMC client module code. - * - * @addtogroup SMC - * @{ - */ - -#include "ch.h" -#include "smcclient.h" - -msg_t smcInvoke(smc_service_t handle, smc_params_area_t data, - size_t size); -/*===========================================================================*/ -/* Module local definitions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ -msg_t smcInvokeService(smc_service_t handle, smc_params_area_t data, - size_t size) -{ - msg_t result; - - result = smcInvoke(handle, data, size); - while (result == SMC_SVC_INTR) - result = smcInvoke(SMC_HND_REENTER, 0, 0); - return result; -} - -/** @} */ diff --git a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.h b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.h deleted file mode 100644 index 06a5e3631..000000000 --- a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/smcclient.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. - - This file is part of ChibiOS. - - ChibiOS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file smcclient.h - * @brief smc Module macros and structures. - * - * @addtogroup SMC - * @{ - */ - -#ifndef SMCCLIENT_H -#define SMCCLIENT_H - -/*===========================================================================*/ -/* Module constants. */ -/*===========================================================================*/ -/* - * Service registry errors - */ -#define SMC_SVC_OK MSG_OK /* No error */ -#define SMC_SVC_INTR (msg_t)-1 /* Service interrupted */ -#define SMC_SVC_NOENT (msg_t)-2 /* No existent service */ -#define SMC_SVC_INVALID (msg_t)-3 /* Invalid service parameter(s) */ -#define SMC_SVC_BADH (msg_t)-4 /* Invalid service handle */ -#define SMC_SVC_EXIST (msg_t)-5 /* Service already exists */ - -/* - * Special service handles - */ -#define SMC_HND_TRAMP ((smc_service_t *)0) /* Trampoline */ -#define SMC_HND_DISCOVERY ((smc_service_t *)1) /* Discovery */ -#define SMC_HND_REENTER ((smc_service_t *)2) /* Reentering a service */ - -/*===========================================================================*/ -/* Module pre-compile time settings. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Derived constants and error checks. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module data structures and types. */ -/*===========================================================================*/ -typedef uint8_t * smc_params_area_t; -typedef void * smc_service_t; - -/*===========================================================================*/ -/* Module macros. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -#ifdef __cplusplus -extern "C" { -#endif -msg_t smcInvokeService(smc_service_t handle, smc_params_area_t data, - size_t size); -#ifdef __cplusplus -} -#endif - -/*===========================================================================*/ -/* Module inline functions. */ -/*===========================================================================*/ - -#endif /* SMCCLIENT_H */ - -/** @} */ diff --git a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/tsclient.c b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/tsclient.c new file mode 100644 index 000000000..b9dba0e66 --- /dev/null +++ b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/tsclient.c @@ -0,0 +1,105 @@ +/* + ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file tsclient.c + * @brief TSSI client module code. + * + * @addtogroup TSSI + * @{ + */ + +#include "ch.h" +#include "tsclient.h" + +/*===========================================================================*/ +/* Module local definitions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + +/* + * @brief Yields all the idle time to secure world. + * @note see CH_CFG_IDLE_LOOP_HOOK in chconf.h + * + * @notapi + */ +void tsIdle(void) { + (void)tsInvoke1(TS_HND_IDLE, 0, 0, TS_GRANTED_TIMESLICE * 10); +} + +/** + * @brief Call a service via smc instruction. + * + * @param[in] handle The handle of the service to invoke. + * The handle is obtained by an invoke to discovery + * service. + * @param[inout] svc_data Service request data, often a reference to a more + * complex structure. + * @param[in] svc_datalen Size of the svc_data memory area. + * @param[in] svc_nsec_time The time slice that will be yielded to the lower + * prio NSEC threads, whenever the service call is + * interrupted, in microseconds. + * This avoids the starvation of lower NSEC thread due + * to continue polling of the called service status. + * 0 means no time slice is yielded. + * + * @return The service status. The value depends on the service. + * + * @retval SMC_SVC_OK generic success value. + * @retval SMC_SVC_BUSY the service has a pending request. + * @retval SMC_SVC_INVALID bad parameters. + * @retval SMC_SVC_NOENT no such service. + * @retval SMC_SVC_BADH bad handle. + * + * @api + */ +msg_t tsInvokeService(ts_service_t handle, ts_params_area_t data, + size_t size, sysinterval_t svc_nsec_time) +{ + int64_t result; + + result = tsInvoke1(handle, data, size, TS_GRANTED_TIMESLICE); + while ((msg_t)result == SMC_SVC_INTR) { + if (svc_nsec_time != 0) + chThdSleepMicroseconds(svc_nsec_time); + result = tsInvoke1(handle, data, size, TS_GRANTED_TIMESLICE); + } + return (msg_t)result; +} + +/** @} */ diff --git a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/tsclient.h b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/tsclient.h new file mode 100644 index 000000000..6389bdb01 --- /dev/null +++ b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-NSEC/tsclient.h @@ -0,0 +1,157 @@ +/* + ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. + + This file is part of ChibiOS. + + ChibiOS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file tsclient.h + * @brief TSSI client module macros and structures. + * + * @addtogroup TSSI + * @{ + */ + +#ifndef TSCLIENT_H +#define TSCLIENT_H + +/*===========================================================================*/ +/* Module constants. */ +/*===========================================================================*/ + +/* Service registry errors as returned by smc.*/ +#define SMC_SVC_OK MSG_OK /* No error.*/ +#define SMC_SVC_INTR (msg_t)-1 /* Service interrupted ( == MSG_TIMEOUT).*/ +#define SMC_SVC_NOENT (msg_t)-2 /* No existent service.*/ +#define SMC_SVC_INVALID (msg_t)-3 /* Invalid service parameter(s).*/ +#define SMC_SVC_BADH (msg_t)-4 /* Invalid service handle.*/ +#define SMC_SVC_EXIST (msg_t)-5 /* Service already exists.*/ +#define SMC_SVC_NHND (msg_t)-6 /* No more services.*/ +#define SMC_SVC_BUSY (msg_t)-7 /* Service busy.*/ + +/* Special trusted service handles.*/ +#define TS_HND_DISCOVERY ((ts_service_t *)1) /* Discovery service handle.*/ +#define TS_HND_STQRY ((ts_service_t *)2) /* Query status service handle.*/ +#define TS_HND_IDLE ((ts_service_t *)3) /* Idle service handle.*/ + +/*===========================================================================*/ +/* Module pre-compile time settings. */ +/*===========================================================================*/ + +#define TS_GRANTED_TIMESLICE 1000 /* Microseconds.*/ + +#define TS_CHECK_EVENT_HOOK(f) { \ + (void)f; \ +} + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module data structures and types. */ +/*===========================================================================*/ + +typedef uint8_t * ts_params_area_t; +typedef void * ts_service_t; + +/*===========================================================================*/ +/* Module macros. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + +/** + * @brief Call a service via smc instruction. + * @note see tsInvoke1() + * + * @notapi + */ +static inline int64_t tsInvoke0(ts_service_t handle, ts_params_area_t data, + size_t size, sysinterval_t yieldtime) { + register int64_t result asm("r0"); + + register int32_t r0 asm("r0") = (int32_t) handle; + register int32_t r1 asm("r1") = (int32_t) data; + register int32_t r2 asm("r2") = (int32_t) size; + register int32_t r3 asm("r3") = (int32_t) yieldtime; + + __asm volatile ("smc #0" : "=r" (result) : "r" (r0), "r" (r1), "r" (r2), + "r" (r3) : "memory"); + return result; +} + +/** + * @brief Call a service via smc instruction. + * @details call a given service via smc and evaluate the eventflags mask + * returned by the secure world. The flags mask is checked by a + * macro, TS_CHECK_EVENT_HOOK, supplied by the user. + * + * @param[in] handle The handle of the service to invoke. + * The handle is obtained by an invoke to discovery + * service. + * @param[inout] svc_data Service request data, often a reference to a more + * complex structure. + * @param[in] svc_datalen Size of the svc_data memory area. + * @param[in] yieldtime The time yield to SEC service to run, in microsec. + * + * @return A 64bit value. It is the OR of the 32bit service + * status combined with a 32bit event mask (in the + * hi-word). + * The retval values are returned in the lower word + * as 32bit int. + * @retval SMC_SVC_OK generic success value. + * @retval SMC_SVC_INTR call interrupted. + * @retval SMC_SVC_BUSY the service has a pending request. + * @retval SMC_SVC_INVALID bad parameters. + * @retval SMC_SVC_NOENT no such service. + * @retval SMC_SVC_BADH bad handle. + * + * @api + */ +static inline int64_t tsInvoke1(ts_service_t handle, ts_params_area_t data, + size_t size, sysinterval_t timeslice) { + int64_t result; + eventflags_t f; + + result = tsInvoke0(handle, data, size, timeslice); + f = (eventflags_t)(result >> 32); + TS_CHECK_EVENT_HOOK(f); + return result; +} + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif +msg_t tsInvokeService(ts_service_t handle, ts_params_area_t data, + size_t size, sysinterval_t svc_nsec_time); +#ifdef __cplusplus +} +#endif + +/*===========================================================================*/ +/* Module inline functions. */ +/*===========================================================================*/ + +#endif /* TSCLIENT_H */ + +/** @} */ -- cgit v1.2.3