Skip to content

Commit bce15c5

Browse files
author
Charley Chu
committed
psoc64: Add TF-M release package
Signed-off-by: Charley Chu <[email protected]>
1 parent d5074a5 commit bce15c5

File tree

17 files changed

+12918
-153
lines changed

17 files changed

+12918
-153
lines changed

features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_DUALCPU/src/platform_ns_mailbox.c

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
#include "cy_ipc_sema.h"
1717

1818
#include "ns_ipc_config.h"
19+
#include "os_wrapper/thread.h"
20+
#include "os_wrapper/semaphore.h"
1921
#include "tfm_ns_mailbox.h"
2022
#include "platform_multicore.h"
21-
#include "cmsis_os2.h"
2223

2324
static uint8_t saved_irq_state = 1;
2425

@@ -54,6 +55,7 @@ int32_t tfm_ns_mailbox_hal_notify_peer(void)
5455

5556
static int32_t mailbox_sema_init(void)
5657
{
58+
#if defined(CY_IPC_DEFAULT_CFG_DISABLE)
5759
/* semaphore data */
5860
static uint32_t tfm_sema __attribute__((section("TFM_SHARED_DATA")));
5961

@@ -62,6 +64,7 @@ static int32_t mailbox_sema_init(void)
6264
&tfm_sema) != CY_IPC_SEMA_SUCCESS) {
6365
return PLATFORM_MAILBOX_INIT_ERROR;
6466
}
67+
#endif
6568
return PLATFORM_MAILBOX_SUCCESS;
6669
}
6770

@@ -116,18 +119,25 @@ int32_t tfm_ns_mailbox_hal_init(struct ns_mailbox_queue_t *queue)
116119
return MAILBOX_SUCCESS;
117120
}
118121

119-
const void *tfm_ns_mailbox_get_task_handle(void)
122+
void * tfm_ns_mailbox_hal_create_semaphore(void)
120123
{
121-
#ifdef TFM_MULTI_CORE_MULTI_CLIENT_CALL
122-
return osThreadGetId();
123-
#else
124-
return NULL;
125-
#endif
124+
return os_wrapper_semaphore_create(1, 0, NULL);
126125
}
127126

128127
void tfm_ns_mailbox_hal_wait_reply(mailbox_msg_handle_t handle)
129128
{
130-
osThreadFlagsWait(handle, osFlagsWaitAll, osWaitForever);
129+
void *sem = tfm_ns_mailbox_get_msg_semaphore(handle);
130+
if (sem != NULL) {
131+
os_wrapper_semaphore_acquire(sem, OS_WRAPPER_WAIT_FOREVER);
132+
}
133+
}
134+
135+
void tfm_ns_mailbox_hal_delete_semaphore(mailbox_msg_handle_t handle)
136+
{
137+
void *sem = tfm_ns_mailbox_get_msg_semaphore(handle);
138+
if (sem != NULL) {
139+
os_wrapper_semaphore_delete(sem);
140+
}
131141
}
132142

133143
static cy_en_ipcsema_status_t mailbox_raw_spin_lock(uint32_t ipc_channel,
@@ -181,10 +191,6 @@ static cy_en_ipcsema_status_t mailbox_raw_spin_lock(uint32_t ipc_channel,
181191
* notification event from secure core. However, it is more
182192
* complex and requires more code and more modifications.
183193
*/
184-
volatile uint32_t count = 1000;
185-
while(count > 0) {
186-
count--;
187-
}
188194
Cy_IPC_Sema_Status(sema_num);
189195
}
190196
}
@@ -279,11 +285,12 @@ static bool mailbox_clear_intr(void)
279285
return true;
280286
}
281287

282-
void cpuss_interrupts_ipc_5_IRQHandler(void)
288+
void tfm_ns_mailbox_ipc_IRQHandler(void)
283289
{
284290
uint32_t magic;
285291
mailbox_msg_handle_t handle;
286-
osThreadId_t task_handle;
292+
void *sem;
293+
uint32_t yield = 0;
287294

288295
if (!mailbox_clear_intr())
289296
return;
@@ -297,13 +304,11 @@ void cpuss_interrupts_ipc_5_IRQHandler(void)
297304
break;
298305
}
299306

300-
task_handle = (osThreadId_t)tfm_ns_mailbox_get_msg_owner(handle);
301-
if (task_handle) {
302-
/* According to the description of CMSIS-RTOS v2 Thread Flags,
303-
* osThreadFlagsSet() can be called inside Interrupt Service
304-
* Routine. */
305-
osThreadFlagsSet(task_handle, handle);
307+
sem = (void *)tfm_ns_mailbox_get_msg_semaphore(handle);
308+
if (sem) {
309+
yield |= os_wrapper_semaphore_release_isr(sem);
306310
}
307311
}
312+
os_wrapper_isr_yield(yield);
308313
}
309314
}

features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_DUALCPU/src/tfm_multi_core_api.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@
55
*
66
*/
77

8+
#include "os_wrapper/semaphore.h"
9+
810
#include "tfm_api.h"
911
#include "tfm_mailbox.h"
1012
#include "tfm_multi_core_api.h"
11-
#include "cmsis_os2.h"
1213

1314
#define MAX_SEMAPHORE_COUNT NUM_MAILBOX_QUEUE_SLOT
1415

15-
static osSemaphoreId_t ns_lock_handle = NULL;
16+
static void *ns_lock_handle = NULL;
1617

1718
__attribute__((weak))
1819
enum tfm_status_e tfm_ns_interface_init(void)
1920
{
20-
osSemaphoreAttr_t sema_attrib = {0};
21-
22-
ns_lock_handle = osSemaphoreNew(MAX_SEMAPHORE_COUNT,
23-
MAX_SEMAPHORE_COUNT,
24-
&sema_attrib);
21+
ns_lock_handle = os_wrapper_semaphore_create(MAX_SEMAPHORE_COUNT,
22+
MAX_SEMAPHORE_COUNT,
23+
NULL);
2524
if (!ns_lock_handle) {
2625
return TFM_ERROR_GENERIC;
2726
}
@@ -36,10 +35,11 @@ int32_t tfm_ns_wait_for_s_cpu_ready(void)
3635

3736
uint32_t tfm_ns_multi_core_lock_acquire(void)
3837
{
39-
return osSemaphoreAcquire(ns_lock_handle, osWaitForever);
38+
return os_wrapper_semaphore_acquire(ns_lock_handle,
39+
OS_WRAPPER_WAIT_FOREVER);
4040
}
4141

4242
uint32_t tfm_ns_multi_core_lock_release(void)
4343
{
44-
return osSemaphoreRelease(ns_lock_handle);
44+
return os_wrapper_semaphore_release(ns_lock_handle);
4545
}

features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_DUALCPU/src/tfm_multi_core_psa_ns_api.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <stdint.h>
99
#include <stdbool.h>
1010

11+
#include "os_wrapper/mutex.h"
12+
1113
#include "psa/client.h"
1214
#include "psa/error.h"
1315
#include "tfm_api.h"
@@ -62,7 +64,7 @@ uint32_t psa_framework_version(void)
6264
uint32_t version;
6365
int32_t ret;
6466

65-
if (tfm_ns_multi_core_lock_acquire() != TFM_SUCCESS) {
67+
if (tfm_ns_multi_core_lock_acquire() != OS_WRAPPER_SUCCESS) {
6668
return PSA_VERSION_NONE;
6769
}
6870

@@ -80,7 +82,7 @@ uint32_t psa_framework_version(void)
8082
version = PSA_VERSION_NONE;
8183
}
8284

83-
if (tfm_ns_multi_core_lock_release() != TFM_SUCCESS) {
85+
if (tfm_ns_multi_core_lock_release() != OS_WRAPPER_SUCCESS) {
8486
return PSA_VERSION_NONE;
8587
}
8688

@@ -96,7 +98,7 @@ uint32_t psa_version(uint32_t sid)
9698

9799
params.psa_version_params.sid = sid;
98100

99-
if (tfm_ns_multi_core_lock_acquire() != TFM_SUCCESS) {
101+
if (tfm_ns_multi_core_lock_acquire() != OS_WRAPPER_SUCCESS) {
100102
return PSA_VERSION_NONE;
101103
}
102104

@@ -114,7 +116,7 @@ uint32_t psa_version(uint32_t sid)
114116
version = PSA_VERSION_NONE;
115117
}
116118

117-
if (tfm_ns_multi_core_lock_release() != TFM_SUCCESS) {
119+
if (tfm_ns_multi_core_lock_release() != OS_WRAPPER_SUCCESS) {
118120
return PSA_VERSION_NONE;
119121
}
120122

@@ -131,7 +133,7 @@ psa_handle_t psa_connect(uint32_t sid, uint32_t version)
131133
params.psa_connect_params.sid = sid;
132134
params.psa_connect_params.version = version;
133135

134-
if (tfm_ns_multi_core_lock_acquire() != TFM_SUCCESS) {
136+
if (tfm_ns_multi_core_lock_acquire() != OS_WRAPPER_SUCCESS) {
135137
return PSA_NULL_HANDLE;
136138
}
137139

@@ -149,7 +151,7 @@ psa_handle_t psa_connect(uint32_t sid, uint32_t version)
149151
psa_handle = PSA_NULL_HANDLE;
150152
}
151153

152-
if (tfm_ns_multi_core_lock_release() != TFM_SUCCESS) {
154+
if (tfm_ns_multi_core_lock_release() != OS_WRAPPER_SUCCESS) {
153155
return PSA_NULL_HANDLE;
154156
}
155157

@@ -172,7 +174,7 @@ psa_status_t psa_call(psa_handle_t handle, int32_t type,
172174
params.psa_call_params.out_vec = out_vec;
173175
params.psa_call_params.out_len = out_len;
174176

175-
if (tfm_ns_multi_core_lock_acquire() != TFM_SUCCESS) {
177+
if (tfm_ns_multi_core_lock_acquire() != OS_WRAPPER_SUCCESS) {
176178
return PSA_ERROR_GENERIC_ERROR;
177179
}
178180

@@ -190,7 +192,7 @@ psa_status_t psa_call(psa_handle_t handle, int32_t type,
190192
status = PSA_INTER_CORE_COMM_ERR;
191193
}
192194

193-
if (tfm_ns_multi_core_lock_release() != TFM_SUCCESS) {
195+
if (tfm_ns_multi_core_lock_release() != OS_WRAPPER_SUCCESS) {
194196
return PSA_ERROR_GENERIC_ERROR;
195197
}
196198

@@ -205,7 +207,7 @@ void psa_close(psa_handle_t handle)
205207

206208
params.psa_close_params.handle = handle;
207209

208-
if (tfm_ns_multi_core_lock_acquire() != TFM_SUCCESS) {
210+
if (tfm_ns_multi_core_lock_acquire() != OS_WRAPPER_SUCCESS) {
209211
return;
210212
}
211213

features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_DUALCPU/src/tfm_ns_mailbox.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ static uint8_t acquire_empty_slot(const struct ns_mailbox_queue_t *queue)
113113
return idx;
114114
}
115115

116-
static void set_msg_owner(uint8_t idx, const void *owner)
116+
static void set_msg_sema_handle(uint8_t idx, void *sem)
117117
{
118118
if (idx < NUM_MAILBOX_QUEUE_SLOT) {
119-
mailbox_queue_ptr->queue[idx].owner = owner;
119+
mailbox_queue_ptr->queue[idx].sem = sem;
120120
}
121121
}
122122

@@ -191,7 +191,7 @@ mailbox_msg_handle_t tfm_ns_mailbox_tx_client_req(uint32_t call_type,
191191
uint8_t idx;
192192
struct mailbox_msg_t *msg_ptr;
193193
mailbox_msg_handle_t handle;
194-
const void *task_handle;
194+
void *sem_handle;
195195

196196
if (!mailbox_queue_ptr) {
197197
return MAILBOX_MSG_NULL_HANDLE;
@@ -218,11 +218,11 @@ mailbox_msg_handle_t tfm_ns_mailbox_tx_client_req(uint32_t call_type,
218218
msg_ptr->client_id = client_id;
219219

220220
/*
221-
* Fetch the current task handle. The task will be woken up according the
222-
* handle value set in the owner field.
221+
* Create a semaphore and store the semaphore handle in mailbx message,
222+
* which will be used to wake up the owner thread.
223223
*/
224-
task_handle = tfm_ns_mailbox_get_task_handle();
225-
set_msg_owner(idx, task_handle);
224+
sem_handle = tfm_ns_mailbox_hal_create_semaphore();
225+
set_msg_sema_handle(idx, sem_handle);
226226

227227
get_mailbox_msg_handle(idx, &handle);
228228

@@ -256,8 +256,9 @@ int32_t tfm_ns_mailbox_rx_client_reply(mailbox_msg_handle_t handle,
256256

257257
*reply = mailbox_queue_ptr->queue[idx].reply.return_val;
258258

259-
/* Clear up the owner field */
260-
set_msg_owner(idx, NULL);
259+
/* Delete the semaphore and remove the semaphore handle */
260+
tfm_ns_mailbox_hal_delete_semaphore(handle);
261+
set_msg_sema_handle(idx, NULL);
261262

262263
tfm_ns_mailbox_hal_enter_critical();
263264
clear_queue_slot_replied(idx);
@@ -337,7 +338,7 @@ mailbox_msg_handle_t tfm_ns_mailbox_fetch_reply_msg_isr(void)
337338
return MAILBOX_MSG_NULL_HANDLE;
338339
}
339340

340-
const void *tfm_ns_mailbox_get_msg_owner(mailbox_msg_handle_t handle)
341+
void *tfm_ns_mailbox_get_msg_semaphore(mailbox_msg_handle_t handle)
341342
{
342343
uint8_t idx;
343344

@@ -346,7 +347,7 @@ const void *tfm_ns_mailbox_get_msg_owner(mailbox_msg_handle_t handle)
346347
}
347348

348349
if (idx < NUM_MAILBOX_QUEUE_SLOT) {
349-
return mailbox_queue_ptr->queue[idx].owner;
350+
return mailbox_queue_ptr->queue[idx].sem;
350351
}
351352

352353
return NULL;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1d1faca481c3
1+
36e356a5

features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/include/psa/initial_attestation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extern "C" {
4646
* attestation service. Used to configure buffers for services that verify the
4747
* produced tokens.
4848
*/
49-
#define PSA_INITIAL_ATTEST_MAX_TOKEN_SIZE (0x400)
49+
#define PSA_INITIAL_ATTEST_MAX_TOKEN_SIZE (0x500)
5050

5151
/**
5252
* The list of fixed claims in the initial attestation token is still evolving,

features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/include/psa_manifest/sid.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019-2020, Arm Limited. All rights reserved.
2+
* Copyright (c) 2019, Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*
@@ -45,8 +45,6 @@ extern "C" {
4545
#define TFM_SP_PLATFORM_SYSTEM_RESET_VERSION (1U)
4646
#define TFM_SP_PLATFORM_IOCTL_SID (0x00000041U)
4747
#define TFM_SP_PLATFORM_IOCTL_VERSION (1U)
48-
#define TFM_SP_PLATFORM_NV_COUNTER_SID (0x00000042U)
49-
#define TFM_SP_PLATFORM_NV_COUNTER_VERSION (1U)
5048

5149
/******** TFM_SP_INITIAL_ATTESTATION ********/
5250
#define TFM_ATTEST_GET_TOKEN_SID (0x00000020U)
@@ -61,6 +59,10 @@ extern "C" {
6159
#define SPM_CORE_TEST_INIT_SUCCESS_VERSION (1U)
6260
#define SPM_CORE_TEST_DIRECT_RECURSION_SID (0x0000F021U)
6361
#define SPM_CORE_TEST_DIRECT_RECURSION_VERSION (1U)
62+
#define SPM_CORE_TEST_MPU_ACCESS_SID (0x0000F022U)
63+
#define SPM_CORE_TEST_MPU_ACCESS_VERSION (1U)
64+
#define SPM_CORE_TEST_MEMORY_PERMISSIONS_SID (0x0000F023U)
65+
#define SPM_CORE_TEST_MEMORY_PERMISSIONS_VERSION (1U)
6466
#define SPM_CORE_TEST_SS_TO_SS_SID (0x0000F024U)
6567
#define SPM_CORE_TEST_SS_TO_SS_VERSION (1U)
6668
#define SPM_CORE_TEST_SS_TO_SS_BUFFER_SID (0x0000F025U)
@@ -130,6 +132,24 @@ extern "C" {
130132
#define TFM_SST_TEST_PREPARE_SID (0x0000F0C0U)
131133
#define TFM_SST_TEST_PREPARE_VERSION (1U)
132134

135+
/******** TFM_SP_PSOC_SERVICE_TEST ********/
136+
#define PSOC_SERVICE_TEST_PSA_INIT_WD_SID (0x00002001U)
137+
#define PSOC_SERVICE_TEST_PSA_INIT_WD_VERSION (1U)
138+
#define PSOC_SERVICE_TEST_PSA_POKE_WD_SID (0x00002002U)
139+
#define PSOC_SERVICE_TEST_PSA_POKE_WD_VERSION (1U)
140+
#define PSOC_SERVICE_TEST_PSA_KILL_WD_SID (0x00002003U)
141+
#define PSOC_SERVICE_TEST_PSA_KILL_WD_VERSION (1U)
142+
#define PSOC_SERVICE_TEST_PSA_WRITE_FLASH_SID (0x00002004U)
143+
#define PSOC_SERVICE_TEST_PSA_WRITE_FLASH_VERSION (1U)
144+
#define PSOC_SERVICE_TEST_PSA_READ_FLASH_SID (0x00002005U)
145+
#define PSOC_SERVICE_TEST_PSA_READ_FLASH_VERSION (1U)
146+
#define PSOC_SERVICE_TEST_PSA_GET_REBOOT_REASON_SID (0x00002006U)
147+
#define PSOC_SERVICE_TEST_PSA_GET_REBOOT_REASON_VERSION (1U)
148+
149+
/******** TFM_PSOC_CLIENT_TEST ********/
150+
#define PSOC_CLIENT_TEST_LVL2_SID (0x00002000U)
151+
#define PSOC_CLIENT_TEST_LVL2_VERSION (1U)
152+
133153
/******** TFM_SP_SECURE_CLIENT_2 ********/
134154
#define TFM_SECURE_CLIENT_2_SID (0x0000F0E0U)
135155
#define TFM_SECURE_CLIENT_2_VERSION (1U)

features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/include/tfm_mailbox.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ struct mailbox_reply_t {
135135
struct ns_mailbox_slot_t {
136136
struct mailbox_msg_t msg;
137137
struct mailbox_reply_t reply;
138-
const void *owner; /* Handle of the owner task of this
138+
void *sem; /* Handle of the semaphore of this
139139
* slot
140140
*/
141141
bool is_woken; /* Indicate that owner task has been

0 commit comments

Comments
 (0)