|
| 1 | +/* arm_tee_api.h |
| 2 | + * |
| 3 | + * ARM TEE style PSA client veneers for Zephyr integration. |
| 4 | + * |
| 5 | + * Copyright (C) 2025 wolfSSL Inc. |
| 6 | + * |
| 7 | + * This file is part of wolfBoot. |
| 8 | + * |
| 9 | + * wolfBoot is free software; you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU General Public License as published by |
| 11 | + * the Free Software Foundation; either version 3 of the License, or |
| 12 | + * (at your option) any later version. |
| 13 | + */ |
| 14 | + |
| 15 | +#ifndef WOLFBOOT_ARM_TEE_API_H |
| 16 | +#define WOLFBOOT_ARM_TEE_API_H |
| 17 | + |
| 18 | +#include <stddef.h> |
| 19 | +#include <stdint.h> |
| 20 | + |
| 21 | +#ifdef __cplusplus |
| 22 | +extern "C" { |
| 23 | +#endif |
| 24 | + |
| 25 | +/* Provide minimal PSA client types if PSA client headers are unavailable. */ |
| 26 | +#ifndef __PSA_CLIENT_H__ |
| 27 | +typedef int32_t psa_handle_t; |
| 28 | +typedef struct psa_invec { |
| 29 | + const void *base; |
| 30 | + size_t len; |
| 31 | +} psa_invec; |
| 32 | +typedef struct psa_outvec { |
| 33 | + void *base; |
| 34 | + size_t len; |
| 35 | +} psa_outvec; |
| 36 | +#endif |
| 37 | + |
| 38 | +#ifndef PSA_ERROR_INVALID_ARGUMENT |
| 39 | +#define PSA_ERROR_INVALID_ARGUMENT ((int32_t)-132) |
| 40 | +#endif |
| 41 | +#ifndef PSA_ERROR_NOT_SUPPORTED |
| 42 | +#define PSA_ERROR_NOT_SUPPORTED ((int32_t)-138) |
| 43 | +#endif |
| 44 | + |
| 45 | +/* Pack extra args to keep veneers <= 4 args (ARM TEE style). */ |
| 46 | +#define WOLFBOOT_ARM_TEE_TYPE_MASK 0xFFFFUL |
| 47 | +#define WOLFBOOT_ARM_TEE_IN_LEN_OFFSET 24 |
| 48 | +#define WOLFBOOT_ARM_TEE_IN_LEN_MASK (0x7UL << WOLFBOOT_ARM_TEE_IN_LEN_OFFSET) |
| 49 | +#define WOLFBOOT_ARM_TEE_OUT_LEN_OFFSET 16 |
| 50 | +#define WOLFBOOT_ARM_TEE_OUT_LEN_MASK (0x7UL << WOLFBOOT_ARM_TEE_OUT_LEN_OFFSET) |
| 51 | + |
| 52 | +#define WOLFBOOT_ARM_TEE_PARAM_PACK(type, in_len, out_len) \ |
| 53 | + ((((uint32_t)(type)) & WOLFBOOT_ARM_TEE_TYPE_MASK) | \ |
| 54 | + ((((uint32_t)(in_len)) << WOLFBOOT_ARM_TEE_IN_LEN_OFFSET) & \ |
| 55 | + WOLFBOOT_ARM_TEE_IN_LEN_MASK) | \ |
| 56 | + ((((uint32_t)(out_len)) << WOLFBOOT_ARM_TEE_OUT_LEN_OFFSET) & \ |
| 57 | + WOLFBOOT_ARM_TEE_OUT_LEN_MASK)) |
| 58 | + |
| 59 | +#define WOLFBOOT_ARM_TEE_PARAM_UNPACK_TYPE(ctrl_param) \ |
| 60 | + ((int32_t)(int16_t)((ctrl_param) & WOLFBOOT_ARM_TEE_TYPE_MASK)) |
| 61 | +#define WOLFBOOT_ARM_TEE_PARAM_UNPACK_IN_LEN(ctrl_param) \ |
| 62 | + ((size_t)(((ctrl_param) & WOLFBOOT_ARM_TEE_IN_LEN_MASK) >> \ |
| 63 | + WOLFBOOT_ARM_TEE_IN_LEN_OFFSET)) |
| 64 | +#define WOLFBOOT_ARM_TEE_PARAM_UNPACK_OUT_LEN(ctrl_param) \ |
| 65 | + ((size_t)(((ctrl_param) & WOLFBOOT_ARM_TEE_OUT_LEN_MASK) >> \ |
| 66 | + WOLFBOOT_ARM_TEE_OUT_LEN_OFFSET)) |
| 67 | + |
| 68 | +#if defined(__ARM_FEATURE_CMSE) && defined(__GNUC__) |
| 69 | +#define WOLFBOOT_CMSE_NS_ENTRY __attribute__((cmse_nonsecure_entry)) |
| 70 | +#else |
| 71 | +#define WOLFBOOT_CMSE_NS_ENTRY |
| 72 | +#endif |
| 73 | + |
| 74 | +/* Secure-side NSC veneers expected by Zephyr ARM TEE client. */ |
| 75 | +uint32_t WOLFBOOT_CMSE_NS_ENTRY arm_tee_psa_framework_version_veneer(void); |
| 76 | +uint32_t WOLFBOOT_CMSE_NS_ENTRY arm_tee_psa_version_veneer(uint32_t sid); |
| 77 | +psa_handle_t WOLFBOOT_CMSE_NS_ENTRY arm_tee_psa_connect_veneer(uint32_t sid, |
| 78 | + uint32_t version); |
| 79 | +int32_t WOLFBOOT_CMSE_NS_ENTRY arm_tee_psa_call_veneer(psa_handle_t handle, |
| 80 | + uint32_t ctrl_param, |
| 81 | + const psa_invec *in_vec, psa_outvec *out_vec); |
| 82 | +void WOLFBOOT_CMSE_NS_ENTRY arm_tee_psa_close_veneer(psa_handle_t handle); |
| 83 | + |
| 84 | +/* Backing PSA IPC hooks (override in secure code). */ |
| 85 | +uint32_t arm_tee_psa_framework_version(void); |
| 86 | +uint32_t arm_tee_psa_version(uint32_t sid); |
| 87 | +psa_handle_t arm_tee_psa_connect(uint32_t sid, uint32_t version); |
| 88 | +int32_t arm_tee_psa_call(psa_handle_t handle, int32_t type, |
| 89 | + const psa_invec *in_vec, size_t in_len, |
| 90 | + psa_outvec *out_vec, size_t out_len); |
| 91 | +void arm_tee_psa_close(psa_handle_t handle); |
| 92 | + |
| 93 | +#ifdef __cplusplus |
| 94 | +} |
| 95 | +#endif |
| 96 | + |
| 97 | +#endif /* WOLFBOOT_ARM_TEE_API_H */ |
0 commit comments