1 /*
2 * Copyright (c) 2018 Synopsys, Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 #include <errno.h>
7 #include <zephyr/kernel.h>
8 #include <zephyr/arch/cpu.h>
9 #include <zephyr/types.h>
10 #include <zephyr/toolchain.h>
11
12 #include <zephyr/arch/arc/v2/secureshield/arc_secure.h>
13
14 #define IRQ_PRIO_MASK (0xffff << ARC_N_IRQ_START_LEVEL)
15 /*
16 * @brief read secure auxiliary regs on behalf of normal mode
17 *
18 * @param aux_reg address of aux reg
19 *
20 * Some aux regs require secure privilege, this function implements
21 * an secure service to access secure aux regs. Check should be done
22 * to decide whether the access is valid.
23 */
arc_s_aux_read(uint32_t aux_reg)24 static int32_t arc_s_aux_read(uint32_t aux_reg)
25 {
26 return -1;
27 }
28
29 /*
30 * @brief write secure auxiliary regs on behalf of normal mode
31 *
32 * @param aux_reg address of aux reg
33 * @param val, the val to write
34 *
35 * Some aux regs require secure privilege, this function implements
36 * an secure service to access secure aux regs. Check should be done
37 * to decide whether the access is valid.
38 */
arc_s_aux_write(uint32_t aux_reg,uint32_t val)39 static int32_t arc_s_aux_write(uint32_t aux_reg, uint32_t val)
40 {
41 if (aux_reg == _ARC_V2_AUX_IRQ_ACT) {
42 /* 0 -> CONFIG_NUM_IRQ_PRIO_LEVELS allocated to secure world
43 * left prio levels allocated to normal world
44 */
45 val &= IRQ_PRIO_MASK;
46 z_arc_v2_aux_reg_write(_ARC_V2_AUX_IRQ_ACT, val |
47 (z_arc_v2_aux_reg_read(_ARC_V2_AUX_IRQ_ACT) &
48 (~IRQ_PRIO_MASK)));
49
50 return 0;
51 }
52
53 return -1;
54 }
55
56 /*
57 * @brief allocate interrupt for normal world
58 *
59 * @param intno, the interrupt to be allocated to normal world
60 *
61 * By default, most interrupts are configured to be secure in initialization.
62 * If normal world wants to use an interrupt, through this secure service to
63 * apply one. Necessary check should be done to decide whether the apply is
64 * valid
65 */
arc_s_irq_alloc(uint32_t intno)66 static int32_t arc_s_irq_alloc(uint32_t intno)
67 {
68 z_arc_v2_irq_uinit_secure_set(intno, 0);
69 return 0;
70 }
71
72
73 /*
74 * \todo, to access MPU from normal mode, secure mpu service should be
75 * created. In the secure mpu service, the parameters should be checked
76 * (e.g., not overwrite the mpu regions for secure world)that operations
77 * are valid
78 */
79
80
81 /*
82 * \todo, how to add secure service easily
83 */
84 const _arc_s_call_handler_t arc_s_call_table[ARC_S_CALL_LIMIT] = {
85 [ARC_S_CALL_AUX_READ] = (_arc_s_call_handler_t)arc_s_aux_read,
86 [ARC_S_CALL_AUX_WRITE] = (_arc_s_call_handler_t)arc_s_aux_write,
87 [ARC_S_CALL_IRQ_ALLOC] = (_arc_s_call_handler_t)arc_s_irq_alloc,
88 };
89