Skip to content

Commit 1aad06b

Browse files
authored
Merge pull request #10829 from devran01/feature_trusted-firmware-m_e7efdc6
PSA: TFM import
2 parents 279925b + 98fa63a commit 1aad06b

File tree

24 files changed

+633
-1346
lines changed

24 files changed

+633
-1346
lines changed

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/platform/include/tfm_spm_hal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Arm Limited. All rights reserved.
2+
* Copyright (c) 2018-2019, Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*
@@ -28,7 +28,7 @@
2828
*/
2929
struct tfm_spm_partition_platform_data_t;
3030

31-
#if TFM_LVL != 1
31+
#if defined (TFM_PSA_API) || (TFM_LVL != 1)
3232
/**
3333
* \brief Holds SPM db fields that define the memory regions used by a
3434
* partition.
@@ -147,7 +147,7 @@ uint32_t tfm_spm_hal_get_ns_MSP(void);
147147
uint32_t tfm_spm_hal_get_ns_entry_point(void);
148148

149149

150-
#if TFM_LVL != 1
150+
#if (TFM_LVL != 1) && !defined(TFM_PSA_API)
151151
/**
152152
* \brief Configure the sandbox for a partition.
153153
*

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/include/tfm_spm.h

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ struct tfm_spm_ipc_partition_t {
7575
*/
7676
uint32_t tfm_spm_partition_get_running_partition_id_ext(void);
7777

78+
/**
79+
* \brief Get the current partition mode.
80+
*
81+
* \param[in] partition_idx Index of current partition
82+
*
83+
* \retval TFM_PARTITION_PRIVILEGED_MODE Privileged mode
84+
* \retval TFM_PARTITION_UNPRIVILEGED_MODE Unprivileged mode
85+
*/
86+
uint32_t tfm_spm_partition_get_privileged_mode(uint32_t partition_idx);
87+
7888
/******************** Service handle management functions ********************/
7989

8090
/**
@@ -279,22 +289,38 @@ int32_t tfm_spm_check_client_version(struct tfm_spm_service_t *service,
279289
uint32_t minor_version);
280290

281291
/**
282-
* \brief Check the memory reference is valid.
283-
*
284-
* \param[in] buffer Pointer of memory reference
285-
* \param[in] len Length of memory reference in bytes
286-
* \param[in] ns_caller From non-secure caller
287-
* \param[in] access Type of access specified by the
288-
* \ref tfm_memory_access_e
289-
*
290-
* \retval IPC_SUCCESS Success
291-
* \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
292-
* \retval IPC_ERROR_MEMORY_CHECK Check failed
292+
* \brief Check the memory reference is valid.
293+
*
294+
* \param[in] buffer Pointer of memory reference
295+
* \param[in] len Length of memory reference in bytes
296+
* \param[in] ns_caller From non-secure caller
297+
* \param[in] access Type of access specified by the
298+
* \ref tfm_memory_access_e
299+
* \param[in] privileged Privileged mode or unprivileged mode:
300+
* \ref TFM_PARTITION_UNPRIVILEGED_MODE
301+
* \ref TFM_PARTITION_PRIVILEGED_MODE
302+
*
303+
* \retval IPC_SUCCESS Success
304+
* \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
305+
* \retval IPC_ERROR_MEMORY_CHECK Check failed
293306
*/
294307
int32_t tfm_memory_check(void *buffer, size_t len, int32_t ns_caller,
295-
enum tfm_memory_access_e access);
308+
enum tfm_memory_access_e access,
309+
uint32_t privileged);
296310

297311
/* This function should be called before schedule function */
298312
void tfm_spm_init(void);
299313

314+
/*
315+
* PendSV specified function.
316+
*
317+
* Parameters :
318+
* ctxb - State context storage pointer
319+
*
320+
* Notes:
321+
* This is a staging API. Scheduler should be called in SPM finally and
322+
* this function will be obsoleted later.
323+
*/
324+
void tfm_pendsv_do_schedule(struct tfm_state_context_ext *ctxb);
325+
300326
#endif

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/include/tfm_thread.h

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,19 @@ struct tfm_thrd_ctx *tfm_thrd_curr_thread(void);
177177
*/
178178
struct tfm_thrd_ctx *tfm_thrd_next_thread(void);
179179

180+
/*
181+
* Start scheduler for existing threads
182+
*
183+
* Parameters:
184+
* pth - pointer of the caller context collecting thread
185+
*
186+
* Notes :
187+
* This function should be called only ONCE to start the scheduler.
188+
* Caller needs to provide a thread object to collect current context.
189+
* The usage of the collected context is caller defined.
190+
*/
191+
void tfm_thrd_start_scheduler(struct tfm_thrd_ctx *pth);
192+
180193
/*
181194
* Activate a scheduling action after exception.
182195
*
@@ -201,23 +214,19 @@ void tfm_thrd_context_switch(struct tfm_state_context_ext *ctxb,
201214
struct tfm_thrd_ctx *next);
202215

203216
/*
204-
* Exit current running thread.
217+
* Svcall to exit current running thread.
205218
*
206219
* Notes :
207220
* Remove current thread out of schedulable list.
208221
*/
209-
void tfm_thrd_do_exit(void);
222+
void tfm_svcall_thrd_exit(void);
210223

211224
/*
212-
* PendSV specified function.
213-
*
214-
* Parameters :
215-
* ctxb - State context storage pointer
225+
* Exit current running thread for client.
216226
*
217227
* Notes:
218-
* This is a staging API. Scheduler should be called in SPM finally and
219-
* this function will be obsoleted later.
228+
* Must be called in thread mode.
220229
*/
221-
void tfm_pendsv_do_schedule(struct tfm_state_context_ext *ctxb);
230+
void tfm_thrd_exit(void);
222231

223232
#endif

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/psa_client.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@
1010
#include "tfm_svc.h"
1111
#include "psa_client.h"
1212

13-
__attribute__((naked))
13+
__attribute__((naked, section("SFN")))
1414
uint32_t psa_framework_version(void)
1515
{
1616
__ASM volatile("SVC %0 \n"
1717
"BX LR \n"
1818
: : "I" (TFM_SVC_PSA_FRAMEWORK_VERSION));
1919
}
2020

21-
__attribute__((naked))
21+
__attribute__((naked, section("SFN")))
2222
uint32_t psa_version(uint32_t sid)
2323
{
2424
__ASM volatile("SVC %0 \n"
2525
"BX LR \n"
2626
: : "I" (TFM_SVC_PSA_VERSION));
2727
}
2828

29-
__attribute__((naked))
29+
__attribute__((naked, section("SFN")))
3030
psa_handle_t psa_connect(uint32_t sid, uint32_t minor_version)
3131
{
3232
__ASM volatile("SVC %0 \n"
3333
"BX LR \n"
3434
: : "I" (TFM_SVC_PSA_CONNECT));
3535
}
3636

37-
__attribute__((naked))
37+
__attribute__((naked, section("SFN")))
3838
psa_status_t psa_call(psa_handle_t handle,
3939
const psa_invec *in_vec,
4040
size_t in_len,
@@ -46,7 +46,7 @@ psa_status_t psa_call(psa_handle_t handle,
4646
: : "I" (TFM_SVC_PSA_CALL));
4747
}
4848

49-
__attribute__((naked))
49+
__attribute__((naked, section("SFN")))
5050
void psa_close(psa_handle_t handle)
5151
{
5252
__ASM volatile("SVC %0 \n"

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/psa_service.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "psa_client.h"
1212
#include "psa_service.h"
1313

14-
__attribute__((naked))
14+
__attribute__((naked, section("SFN")))
1515
psa_signal_t psa_wait(psa_signal_t signal_mask, uint32_t timeout)
1616

1717
{
@@ -20,23 +20,23 @@ psa_signal_t psa_wait(psa_signal_t signal_mask, uint32_t timeout)
2020
: : "I" (TFM_SVC_PSA_WAIT));
2121
}
2222

23-
__attribute__((naked))
23+
__attribute__((naked, section("SFN")))
2424
psa_status_t psa_get(psa_signal_t signal, psa_msg_t *msg)
2525
{
2626
__ASM volatile("SVC %0 \n"
2727
"BX LR \n"
2828
: : "I" (TFM_SVC_PSA_GET));
2929
}
3030

31-
__attribute__((naked))
31+
__attribute__((naked, section("SFN")))
3232
void psa_set_rhandle(psa_handle_t msg_handle, void *rhandle)
3333
{
3434
__ASM volatile("SVC %0 \n"
3535
"BX LR \n"
3636
: : "I" (TFM_SVC_PSA_SET_RHANDLE));
3737
}
3838

39-
__attribute__((naked))
39+
__attribute__((naked, section("SFN")))
4040
size_t psa_read(psa_handle_t msg_handle, uint32_t invec_idx,
4141
void *buffer, size_t num_bytes)
4242

@@ -46,15 +46,15 @@ size_t psa_read(psa_handle_t msg_handle, uint32_t invec_idx,
4646
: : "I" (TFM_SVC_PSA_READ));
4747
}
4848

49-
__attribute__((naked))
49+
__attribute__((naked, section("SFN")))
5050
size_t psa_skip(psa_handle_t msg_handle, uint32_t invec_idx, size_t num_bytes)
5151
{
5252
__ASM volatile("SVC %0 \n"
5353
"BX LR \n"
5454
: : "I" (TFM_SVC_PSA_SKIP));
5555
}
5656

57-
__attribute__((naked))
57+
__attribute__((naked, section("SFN")))
5858
void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx,
5959
const void *buffer, size_t num_bytes)
6060
{
@@ -63,31 +63,31 @@ void psa_write(psa_handle_t msg_handle, uint32_t outvec_idx,
6363
: : "I" (TFM_SVC_PSA_WRITE));
6464
}
6565

66-
__attribute__((naked))
66+
__attribute__((naked, section("SFN")))
6767
void psa_reply(psa_handle_t msg_handle, psa_status_t retval)
6868
{
6969
__ASM volatile("SVC %0 \n"
7070
"BX LR \n"
7171
: : "I" (TFM_SVC_PSA_REPLY));
7272
}
7373

74-
__attribute__((naked))
74+
__attribute__((naked, section("SFN")))
7575
void psa_notify(int32_t partition_id)
7676
{
7777
__ASM volatile("SVC %0 \n"
7878
"BX LR \n"
7979
: : "I" (TFM_SVC_PSA_NOTIFY));
8080
}
8181

82-
__attribute__((naked))
82+
__attribute__((naked, section("SFN")))
8383
void psa_clear(void)
8484
{
8585
__ASM volatile("SVC %0 \n"
8686
"BX LR \n"
8787
: : "I" (TFM_SVC_PSA_CLEAR));
8888
}
8989

90-
__attribute__((naked))
90+
__attribute__((naked, section("SFN")))
9191
void psa_eoi(psa_signal_t irq_signal)
9292
{
9393
__ASM volatile("SVC %0 \n"

components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_arch_v8m.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,10 @@
1717

1818
/* This file contains the ARCH code for ARM V8M */
1919

20-
/*
21-
* Thread exit zone.
22-
* This function is set as the return address of thread entry and only
23-
* privileged thread could return here. Un-privileged thread triggers
24-
* fault if it tries to jump here and it gets exit by fault handler.
25-
*
26-
* The reason of putting this function here is for fault handler checking.
27-
* Function address could be checked in fault handler to know it is a REAL
28-
* thread exit or just an exception.
29-
*/
20+
__attribute__((section("SFN")))
3021
static void exit_zone(void)
3122
{
32-
tfm_thrd_do_exit();
23+
tfm_thrd_exit();
3324
}
3425

3526
void tfm_initialize_context(struct tfm_state_context *ctx,

0 commit comments

Comments
 (0)