Skip to content

Commit cca3920

Browse files
Wayne Renioannisg
authored andcommitted
arch: arc: add initial support of ARC TEE
* it's based on ARC SecureShield * add basic secure service in arch/arc/core/secureshield * necesssary changes in arch level * thread switch * irq/exception handling * initialization * add secure time support Signed-off-by: Wayne Ren <[email protected]>
1 parent ee92cf4 commit cca3920

File tree

25 files changed

+880
-122
lines changed

25 files changed

+880
-122
lines changed

arch/arc/Kconfig

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,6 @@ config CODE_DENSITY
177177
help
178178
Enable code density option to get better code density
179179

180-
config ARC_HAS_SECURE
181-
bool
182-
# a hidden option
183-
help
184-
This option is enabled when ARC core supports secure mode
185-
186180
config ARC_HAS_ACCL_REGS
187181
bool "Reg Pair ACCL:ACCH (FPU and/or MPY > 6)"
188182
default y if FLOAT
@@ -191,6 +185,60 @@ config ARC_HAS_ACCL_REGS
191185
(also referred to as r58:r59). These can also be used by gcc as GPR so
192186
kernel needs to save/restore per process
193187

188+
config ARC_HAS_SECURE
189+
bool "ARC has SecureShield"
190+
select CPU_HAS_TEE
191+
select ARCH_HAS_TRUSTED_EXECUTION
192+
help
193+
This option is enabled when ARC core supports secure mode
194+
195+
config SJLI_TABLE_SIZE
196+
int "SJLI table size"
197+
depends on ARC_SECURE_FIRMWARE
198+
default 8
199+
help
200+
The size of sjli (Secure Jump and Link Indexed) table. The
201+
code in normal mode call secure services in secure mode through
202+
sjli instruction.
203+
204+
config ARC_SECURE_FIRMWARE
205+
prompt "Generate Secure Firmware"
206+
bool
207+
depends on ARC_HAS_SECURE
208+
default y if TRUSTED_EXECUTION_SECURE
209+
help
210+
This option indicates that we are building a Zephyr image that
211+
is intended to execute in secure mode. The option is only
212+
applicable to ARC processors that implement the SecureShield.
213+
214+
This option enables Zephyr to include code that executes in
215+
secure mode, as well as to exclude code that is designed to
216+
execute only in normal mode.
217+
218+
Code executing in secure mode has access to both the secure
219+
and normal resources of the ARC processors.
220+
221+
config ARC_NORMAL_FIRMWARE
222+
prompt "Generate Normal Firmware"
223+
bool
224+
depends on !ARC_SECURE_FIRMWARE
225+
depends on ARC_HAS_SECURE
226+
default y if TRUSTED_EXECUTION_NONSECURE
227+
help
228+
This option indicates that we are building a Zephyr image that
229+
is intended to execute in normal mode. Execution of this
230+
image is triggered by secure firmware that executes in secure
231+
mode. The option is only applicable to ARC processors that
232+
implement the SecureShield.
233+
234+
This option enables Zephyr to include code that executes in
235+
normal mode only, as well as to exclude code that is
236+
designed to execute only in secure mode.
237+
238+
Code executing in normal mode has no access to secure
239+
resources of the ARC processors, and, therefore, it shall avoid
240+
accessing them.
241+
194242
menu "ARC MPU Options"
195243
depends on CPU_HAS_MPU
196244

arch/arc/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ zephyr_library_sources_ifdef(CONFIG_ARC_FIRQ fast_irq.S)
2424

2525
zephyr_library_sources_if_kconfig(irq_offload.c)
2626
add_subdirectory_ifdef(CONFIG_ARC_CORE_MPU mpu)
27+
add_subdirectory_ifdef(CONFIG_ARC_SECURE_FIRMWARE secureshield)
2728
zephyr_library_sources_ifdef(CONFIG_USERSPACE userspace.S)
2829
zephyr_library_sources_ifdef(CONFIG_ARC_CONNECT arc_connect.c)
2930
zephyr_library_sources_ifdef(CONFIG_SMP arc_smp.c)

arch/arc/core/fast_irq.S

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@ SECTION_FUNC(TEXT, _firq_enter)
5353
* This has already been done by _isr_wrapper.
5454
*/
5555
#ifdef CONFIG_ARC_STACK_CHECKING
56-
#ifdef CONFIG_ARC_HAS_SECURE
56+
#ifdef CONFIG_ARC_SECURE_FIRMWARE
5757
lr r2, [_ARC_V2_SEC_STAT]
5858
bclr r2, r2, _ARC_V2_SEC_STAT_SSC_BIT
59-
/* sflag r2 */
60-
/* sflag instruction is not supported in current ARC GNU */
61-
.long 0x00bf302f
59+
sflag r2
6260
#else
6361
/* disable stack checking */
6462
lr r2, [_ARC_V2_STATUS32]

arch/arc/core/fault_s.S

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ _exc_entry:
8181
_create_irq_stack_frame
8282

8383
#ifdef CONFIG_ARC_HAS_SECURE
84+
/* ERSEC_STAT is IOW/RAZ in normal mode */
8485
lr r0,[_ARC_V2_ERSEC_STAT]
8586
st_s r0, [sp, ___isf_t_sec_stat_OFFSET]
8687
#endif
@@ -121,7 +122,7 @@ _exc_return:
121122
st_s r2, [r1, _kernel_offset_to_current]
122123
#endif
123124

124-
#ifdef CONFIG_ARC_HAS_SECURE
125+
#ifdef CONFIG_ARC_SECURE_FIRMWARE
125126
/*
126127
* sync up the ERSEC_STAT.ERM and SEC_STAT.IRM.
127128
* use a fake interrupt return to simulate an exception turn.
@@ -130,11 +131,9 @@ _exc_return:
130131
*/
131132
lr r3,[_ARC_V2_ERSEC_STAT]
132133
btst r3, 31
133-
bset.nz r3, r3, 3
134-
bclr.z r3, r3, 3
135-
/* sflag r3 */
136-
/* sflag instruction is not supported in current ARC GNU */
137-
.long 0x00ff302f
134+
bset.nz r3, r3, _ARC_V2_SEC_STAT_IRM_BIT
135+
bclr.z r3, r3, _ARC_V2_SEC_STAT_IRM_BIT
136+
sflag r3
138137
#endif
139138
/* clear AE bit to forget this was an exception, and go to
140139
* register bank0 (if exception is raised in firq with 2 reg
@@ -155,8 +154,23 @@ _exc_return:
155154
* raise exception again. The ignored interrupts will be re-triggered
156155
* if not cleared, or re-triggered by interrupt sources, or just missed
157156
*/
158-
mov r3,(1 << (CONFIG_NUM_IRQ_PRIO_LEVELS - 1)) /* use lowest */
157+
158+
#ifdef CONFIG_ARC_SECURE_FIRMWARE
159+
mov r3, (1 << (ARC_N_IRQ_START_LEVEL - 1))
160+
#else
161+
mov r3, (1 << (CONFIG_NUM_IRQ_PRIO_LEVELS - 1))
162+
#endif
163+
164+
#ifdef CONFIG_ARC_NORMAL_FIRMWARE
165+
push r2
166+
mov r0, _ARC_V2_AUX_IRQ_ACT
167+
mov r1, r3
168+
mov r6, ARC_S_CALL_AUX_WRITE
169+
sjli SJLI_CALL_ARC_SECURE
170+
pop r2
171+
#else
159172
sr r3, [_ARC_V2_AUX_IRQ_ACT]
173+
#endif
160174

161175
#if defined(CONFIG_ARC_FIRQ) && CONFIG_RGF_NUM_BANKS != 1
162176
mov r2, ilink
@@ -191,7 +205,7 @@ SECTION_SUBSEC_FUNC(TEXT,__fault,__ev_trap)
191205
mov r6, K_SYSCALL_BAD
192206

193207
valid_syscall_id:
194-
#ifdef CONFIG_ARC_HAS_SECURE
208+
#ifdef CONFIG_ARC_SECURE_FIRMWARE
195209
lr ilink, [_ARC_V2_ERSEC_STAT]
196210
push ilink
197211
#endif
@@ -268,17 +282,8 @@ exc_nest_handle:
268282
/* check if the current thread needs to be rescheduled */
269283
ld_s r0, [r1, _kernel_offset_to_ready_q_cache]
270284
breq r0, r2, _exc_return_from_irqoffload_trap
271-
272-
_save_callee_saved_regs
273-
274-
st _CAUSE_RIRQ, [r2, _thread_offset_to_relinquish_cause]
275-
/* note: Ok to use _CAUSE_RIRQ since everything is saved */
276-
277-
ld_s r2, [r1, _kernel_offset_to_ready_q_cache]
278-
st_s r2, [r1, _kernel_offset_to_current]
279285
#endif
280-
281-
#ifdef CONFIG_ARC_HAS_SECURE
286+
#ifdef CONFIG_ARC_SECURE_FIRMWARE
282287
/*
283288
* sync up the ERSEC_STAT.ERM and SEC_STAT.IRM.
284289
* use a fake interrupt return to simulate an exception turn.
@@ -287,21 +292,42 @@ exc_nest_handle:
287292
*/
288293
lr r3,[_ARC_V2_ERSEC_STAT]
289294
btst r3, 31
290-
bset.nz r3, r3, 3
291-
bclr.z r3, r3, 3
292-
/* sflag r3 */
293-
/* sflag instruction is not supported in current ARC GNU */
294-
.long 0x00ff302f
295+
bset.nz r3, r3, _ARC_V2_SEC_STAT_IRM_BIT
296+
bclr.z r3, r3, _ARC_V2_SEC_STAT_IRM_BIT
297+
sflag r3
295298
#endif
299+
300+
_save_callee_saved_regs
301+
302+
st _CAUSE_RIRQ, [r2, _thread_offset_to_relinquish_cause]
303+
/* note: Ok to use _CAUSE_RIRQ since everything is saved */
304+
305+
ld_s r2, [r1, _kernel_offset_to_ready_q_cache]
306+
st_s r2, [r1, _kernel_offset_to_current]
307+
296308
/* clear AE bit to forget this was an exception */
297309
lr r3, [_ARC_V2_STATUS32]
298310
and r3,r3,(~_ARC_V2_STATUS32_AE)
299311
kflag r3
300312
/* pretend lowest priority interrupt happened to use common handler */
301313
lr r3, [_ARC_V2_AUX_IRQ_ACT]
302-
or r3,r3,(1<<(CONFIG_NUM_IRQ_PRIO_LEVELS-1)) /* use lowest */
303-
sr r3, [_ARC_V2_AUX_IRQ_ACT]
304314

315+
#ifdef CONFIG_ARC_SECURE_FIRMWARE
316+
or r3, r3, (1 << (ARC_N_IRQ_START_LEVEL - 1))
317+
#else
318+
or r3, r3, (1 << (CONFIG_NUM_IRQ_PRIO_LEVELS - 1))
319+
#endif
320+
321+
#ifdef CONFIG_ARC_NORMAL_FIRMWARE
322+
push_s r2
323+
mov r0, _ARC_V2_AUX_IRQ_ACT
324+
mov r1, r3
325+
mov r6, ARC_S_CALL_AUX_WRITE
326+
sjli SJLI_CALL_ARC_SECURE
327+
pop_s r2
328+
#else
329+
sr r3, [_ARC_V2_AUX_IRQ_ACT]
330+
#endif
305331
/* Assumption: r2 has current thread */
306332
b _rirq_common_interrupt_swap
307333
#endif

arch/arc/core/irq_manage.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ void z_irq_priority_set(unsigned int irq, unsigned int prio, u32_t flags)
8383

8484
__ASSERT(prio < CONFIG_NUM_IRQ_PRIO_LEVELS,
8585
"invalid priority %d for irq %d", prio, irq);
86+
/* 0 -> CONFIG_NUM_IRQ_PRIO_LEVELS allocted to secure world
87+
* left prio levels allocated to normal world
88+
*/
89+
#if defined(CONFIG_ARC_SECURE_FIRMWARE)
90+
prio = prio < ARC_N_IRQ_START_LEVEL ?
91+
prio : (ARC_N_IRQ_START_LEVEL - 1);
92+
#elif defined(CONFIG_ARC_NORMAL_FIRMWARE)
93+
prio = prio < ARC_N_IRQ_START_LEVEL ?
94+
ARC_N_IRQ_START_LEVEL : prio;
95+
#endif
8696
z_arc_v2_irq_unit_prio_set(irq, prio);
8797
irq_unlock(key);
8898
}

0 commit comments

Comments
 (0)