Skip to content

Commit 5c4a527

Browse files
committed
refactor(esp_tee): Remove explicit setting of the HP_CPU APM/TEE security mode
1 parent 26fa710 commit 5c4a527

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
lines changed

components/esp_tee/subproject/main/arch/riscv/esp_tee_secure_entry.S

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -15,21 +15,12 @@
1515
.global _sec_world_entry
1616
.type _sec_world_entry, @function
1717
_sec_world_entry:
18-
/* Setup the APM for HP CPU in TEE mode */
19-
li t0, TEE_M0_MODE_CTRL_REG
20-
sw zero, 0(t0) /* APM_LL_SECURE_MODE_TEE = 0 */
21-
2218
/* Disable the U-mode delegation of all interrupts */
2319
csrwi mideleg, 0
2420

2521
/* Jump to the secure service dispatcher */
2622
jal esp_tee_service_dispatcher
2723

28-
/* Setup the APM for HP CPU in REE mode */
29-
li t0, TEE_M0_MODE_CTRL_REG
30-
li t1, 0x1 /* APM_LL_SECURE_MODE_REE = 1 */
31-
sw t1, 0(t0)
32-
3324
/* Enable the U-mode delegation of all interrupts (except the TEE secure interrupt) */
3425
li t0, 0xffffbfff
3526
csrw mideleg, t0

components/esp_tee/subproject/main/arch/riscv/esp_tee_vectors.S

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -177,15 +177,16 @@ _panic_handler:
177177
addi sp, sp, -16
178178
sw t0, 0(sp)
179179

180-
/* Check whether the exception is an M-mode ecall */
180+
/* Read mcause */
181181
csrr t0, mcause
182-
xori t0, t0, ECALL_M_MODE
183-
beqz t0, _machine_ecall
182+
183+
/* Check whether the exception is an M-mode ecall */
184+
li t1, ECALL_M_MODE
185+
beq t0, t1, _machine_ecall
184186

185187
/* Check whether the exception is an U-mode ecall */
186-
csrr t0, mcause
187-
xori t0, t0, ECALL_U_MODE
188-
beqz t0, _user_ecall
188+
li t1, ECALL_U_MODE
189+
beq t0, t1, _user_ecall
189190

190191
/* Restore t0 from the stack */
191192
lw t0, 0(sp)
@@ -250,6 +251,10 @@ _return_from_exception:
250251
_ecall_handler:
251252
/* M-mode ecall handler */
252253
_machine_ecall:
254+
/* Set the privilege mode to transition to after mret to U-mode */
255+
li t0, MSTATUS_MPP
256+
csrc mstatus, t0
257+
253258
/* Check whether this is the first M-mode ecall (see esp_tee_init) and skip context restoration */
254259
lui t0, ESP_TEE_M2U_SWITCH_MAGIC
255260
beq a1, t0, _skip_ctx_restore
@@ -267,15 +272,10 @@ _machine_ecall:
267272
restore_general_regs RV_STK_FRMSZ
268273
csrrw a0, mscratch, zero
269274

270-
/* This point is reached only after the first M-mode ecall, never again (see esp_tee_init) */
271275
_skip_ctx_restore:
272276
/* Copy the ra register to mepc which contains the user app entry point (i.e. call_start_cpu0) */
273277
csrw mepc, ra
274278

275-
/* Set the privilege mode to transition to after mret to U-mode */
276-
li t3, MSTATUS_MPP
277-
csrc mstatus, t3
278-
279279
/* Jump to the REE */
280280
mret
281281

@@ -291,8 +291,8 @@ _user_ecall:
291291
lw t0, 0(sp)
292292
addi sp, sp, 16
293293

294-
/* This point is reached after a secure service call is issued from the REE */
295-
/* Save register context and the mepc */
294+
/* This point is reached when a service call is issued from the REE */
295+
/* Save register context and mepc */
296296
save_general_regs RV_STK_FRMSZ
297297
save_mepc
298298

components/esp_tee/subproject/main/soc/esp32c6/esp_tee_secure_sys_cfg.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ void esp_tee_soc_secure_sys_init(void)
100100

101101
IRAM_ATTR inline void esp_tee_switch_to_ree(uint32_t ree_entry_addr)
102102
{
103-
/* Switch HP_CPU to REE0 mode. */
104-
apm_tee_hal_set_master_secure_mode(HP_APM_CTRL, APM_LL_MASTER_HPCORE, APM_LL_SECURE_MODE_REE0);
105-
106103
/* 2nd argument is used as magic value to detect very first M2U switch */
107104
/* TBD: clean this up and use proper temporary register instead of a1 */
108105
/* Switch to non-secure world and launch App. */

0 commit comments

Comments
 (0)