From b757e1c633ad67550482bf641c09b6b425b4136d Mon Sep 17 00:00:00 2001 From: isiora Date: Thu, 15 Mar 2018 13:42:14 +0000 Subject: Added TSSI version service. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11772 110e8d01-0319-4d1e-a829-52ad28d1bb01 --- os/common/ports/ARMCAx-TZ/chtssi.c | 36 +++++++++++++++++++++++++----- os/common/ports/ARMCAx-TZ/chtssi.h | 45 +++++++++++++++++--------------------- 2 files changed, 51 insertions(+), 30 deletions(-) (limited to 'os/common/ports/ARMCAx-TZ') diff --git a/os/common/ports/ARMCAx-TZ/chtssi.c b/os/common/ports/ARMCAx-TZ/chtssi.c index 373995331..580a4ebd5 100644 --- a/os/common/ports/ARMCAx-TZ/chtssi.c +++ b/os/common/ports/ARMCAx-TZ/chtssi.c @@ -64,7 +64,8 @@ static event_listener_t tsEventListener; static bool isAddrSpaceValid(uint8_t *addr, size_t size) { - //chEvtBroadcastFlags(); + if (size == 0) + return TRUE; return (bool)((addr - NSEC_MEMORY_START_ADDR) < (NSEC_MEMORY_END_ADDR - NSEC_MEMORY_START_ADDR)) && (bool)((addr + size - NSEC_MEMORY_START_ADDR) < @@ -151,8 +152,14 @@ int64_t smcEntry(ts_state_t *svc_handle, ts_params_area_t svc_data, if (!isAddrSpaceValid(svc_data, svc_datalen)) return LOWORD(SMC_SVC_INVALID); - /* Internal discovery service.*/ - if (svc_handle == TS_HND_DISCOVERY) { + if (svc_handle == TS_HND_VERSION) { + + /* Internal get version service.*/ + return LOWORD(TSSI_VERSION); + } + else if (svc_handle == TS_HND_DISCOVERY) { + + /* Internal discovery service.*/ if (svc_datalen) { *((char *)svc_data + svc_datalen - 1) = '\0'; tssp = findSvcsEntry((char *)svc_data); @@ -160,7 +167,10 @@ int64_t smcEntry(ts_state_t *svc_handle, ts_params_area_t svc_data, if (tssp == NULL) return LOWORD(SMC_SVC_NOENT); return LOWORD((int32_t)tssp); - } else { + } + else { + + /* User service.*/ if (!isHndlValid(svc_handle)) return LOWORD(SMC_SVC_BADH); tssp = svc_handle; @@ -223,6 +233,22 @@ msg_t tssiWaitRequest(ts_state_t *svcp) return r; } +/** + * @brief Check that the specified memory space is a subspace of + * the non secure memory space. + * + * @param[in] addr start address of the memory space. + * @param[in] size size of the memory space. + * + * @return TRUE, if the space is valid. + * + * @api + */ +bool tsIsAddrSpaceValid(void *addr, size_t size) +{ + return isAddrSpaceValid((uint8_t *)addr, size); +} + /** * @brief Initializes the trusted services and jumps in the NSEC world. * @@ -278,7 +304,7 @@ CC_NO_RETURN void tssiInit(void) mtxRegionWrnsech(REGION_2, NOT_SECURE_WRITE)); /* Mark the whole non secure memory region as non executable - by the secure code.*/ + by the secure side.*/ tt = (uint32_t *)(__get_TTBR0() & 0xFFFFC000); for (d = ((uint32_t)NSEC_MEMORY_START_ADDR >> 20); d < ((uint32_t)NSEC_MEMORY_END_ADDR >> 20); d += 1) { diff --git a/os/common/ports/ARMCAx-TZ/chtssi.h b/os/common/ports/ARMCAx-TZ/chtssi.h index 3fbb1497b..198ec8a50 100644 --- a/os/common/ports/ARMCAx-TZ/chtssi.h +++ b/os/common/ports/ARMCAx-TZ/chtssi.h @@ -35,6 +35,10 @@ /* Module constants. */ /*===========================================================================*/ +/* TSSI interface version. This code is returned also at run time by + calling the internal service TS_HND_VERSION.*/ +#define TSSI_VERSION 0x01000000 /* 00 major, 000 minor, 000 build.*/ + /* 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).*/ @@ -42,7 +46,8 @@ #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_NHND (msg_t)-6 /* No more services or + service resources.*/ #define SMC_SVC_BUSY (msg_t)-7 /* Service busy.*/ /* Special trusted service handles.*/ @@ -50,18 +55,11 @@ #define TS_HND_DISCOVERY ((ts_state_t *)1) /* Discovery service handle.*/ #define TS_HND_STQRY ((ts_state_t *)2) /* Query status service handle.*/ #define TS_HND_IDLE ((ts_state_t *)3) /* Idle service handle.*/ - -/* Service states.*/ -#define TS_STATE_READY 0 -#define TS_STATE_PROCESSING 1 -#define TS_STATE_DONE 2 +#define TS_HND_VERSION ((ts_state_t *)4) /* Get version service handle.*/ /* Services events event mask.*/ #define EVT_DAEMON_REQ_ATN EVENT_MASK(0) -/* Service events flags.*/ -#define EVT_DRA_SOCK_PROXY 1 - /*===========================================================================*/ /* Module pre-compile time settings. */ /*===========================================================================*/ @@ -71,24 +69,25 @@ * @{ */ -/* +/** * @brief Max number of services. */ #define TS_MAX_SVCS 64 -/* +/** * @brief Max smc call timeout, in microseconds. */ #define TS_MAX_TMO 10000 -/* +/** * @brief Secure and non secure memory address spaces. */ #define NSEC_MEMORY_START_ADDR ((uint8_t *)0x20000000) #define NSEC_MEMORY_END_ADDR ((uint8_t *)0x27000000) #define SEC_MEMORY_START_ADDR ((uint8_t *)0x27000000) -#define SEC_MEMORY_END_ADDR ((size_t)0x1000000) +#define SEC_MEMORY_SIZE ((size_t)0x1000000) +/** @} */ /*===========================================================================*/ /* Derived constants and error checks. */ @@ -145,22 +144,17 @@ typedef struct tssi_service_state { #define TS_CONF_TABLE_END \ }; -/* +/** * @brief Accessor to the service table entry i. */ #define TS_CONF_TABLE(i) (&ts_configs[i]) -/* +/** * @brief Trusted services base prio. */ #define TS_BASE_PRIO (NORMALPRIO+1) -/* - * @brief Check if service is busy. - */ -#define TS_IS_BUSY(state) (state != TS_STATE_READY) - -/* +/** * @brief Set the service status. * @note The service sets the status at a value representing the status * of the completion of the request. This value is @@ -168,15 +162,15 @@ typedef struct tssi_service_state { */ #define TS_SET_STATUS(svcp, newst) (((ts_state_t *)svcp)->ts_status = newst) -/* - * @brief Get the client shared memory start address. +/** + * @brief Get the pointer to the client shared memory. * @note The client sets the data field at the start address * of a shared memory allocated from the non secure memory space. */ #define TS_GET_DATA(svcp) ((char *)((ts_state_t *)svcp)->ts_datap) -/* - * @brief Get the client shared memory size. +/** + * @brief Get the size of the client shared memory. * @note The client sets the datalen field to the size * of a shared memory allocated from the non secure memory space. */ @@ -198,6 +192,7 @@ extern "C" { CC_NO_RETURN void _ns_trampoline(uint8_t *addr); CC_NO_RETURN void tssiInit(void); msg_t tssiWaitRequest(ts_state_t *svcp); + bool tsIsAddrSpaceValid(void *addr, size_t size); #ifdef __cplusplus } #endif -- cgit v1.2.3