Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 1 | /* |
Raghu Krishnamurthy | 669bf40 | 2022-07-25 14:44:33 -0700 | [diff] [blame] | 2 | * Copyright (c) 2014-2022, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 7 | #ifndef INTERRUPT_MGMT_H |
| 8 | #define INTERRUPT_MGMT_H |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 9 | |
| 10 | #include <arch.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | #include <lib/utils_def.h> |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 12 | |
| 13 | /******************************************************************************* |
| 14 | * Constants for the types of interrupts recognised by the IM framework |
| 15 | ******************************************************************************/ |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 16 | #define INTR_TYPE_S_EL1 U(0) |
| 17 | #define INTR_TYPE_EL3 U(1) |
| 18 | #define INTR_TYPE_NS U(2) |
| 19 | #define MAX_INTR_TYPES U(3) |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 20 | #define INTR_TYPE_INVAL MAX_INTR_TYPES |
Jeenu Viswambharan | dce70b3 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 21 | |
| 22 | /* Interrupt routing modes */ |
| 23 | #define INTR_ROUTING_MODE_PE 0 |
| 24 | #define INTR_ROUTING_MODE_ANY 1 |
| 25 | |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 26 | /* |
| 27 | * Constant passed to the interrupt handler in the 'id' field when the |
| 28 | * framework does not read the gic registers to determine the interrupt id. |
| 29 | */ |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 30 | #define INTR_ID_UNAVAILABLE U(0xFFFFFFFF) |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 31 | |
| 32 | |
| 33 | /******************************************************************************* |
| 34 | * Mask for _both_ the routing model bits in the 'flags' parameter and |
| 35 | * constants to define the valid routing models for each supported interrupt |
| 36 | * type |
| 37 | ******************************************************************************/ |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 38 | #define INTR_RM_FLAGS_SHIFT U(0x0) |
| 39 | #define INTR_RM_FLAGS_MASK U(0x3) |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 40 | /* Routed to EL3 from NS. Taken to S-EL1 from Secure */ |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 41 | #define INTR_SEL1_VALID_RM0 U(0x2) |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 42 | /* Routed to EL3 from NS and Secure */ |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 43 | #define INTR_SEL1_VALID_RM1 U(0x3) |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 44 | /* Routed to EL1/EL2 from NS and to S-EL1 from Secure */ |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 45 | #define INTR_NS_VALID_RM0 U(0x0) |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 46 | /* Routed to EL1/EL2 from NS and to EL3 from Secure */ |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 47 | #define INTR_NS_VALID_RM1 U(0x1) |
Soby Mathew | 58e32d1 | 2015-11-23 13:58:45 +0000 | [diff] [blame] | 48 | /* Routed to EL3 from NS. Taken to S-EL1 from Secure and handed over to EL3 */ |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 49 | #define INTR_EL3_VALID_RM0 U(0x2) |
Soby Mathew | 58e32d1 | 2015-11-23 13:58:45 +0000 | [diff] [blame] | 50 | /* Routed to EL3 from NS and Secure */ |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 51 | #define INTR_EL3_VALID_RM1 U(0x3) |
Soby Mathew | 47903c0 | 2015-01-13 15:48:26 +0000 | [diff] [blame] | 52 | /* This is the default routing model */ |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 53 | #define INTR_DEFAULT_RM U(0x0) |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 54 | |
| 55 | /******************************************************************************* |
| 56 | * Constants for the _individual_ routing model bits in the 'flags' field for |
| 57 | * each interrupt type and mask to validate the 'flags' parameter while |
| 58 | * registering an interrupt handler |
| 59 | ******************************************************************************/ |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 60 | #define INTR_TYPE_FLAGS_MASK U(0xFFFFFFFC) |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 61 | |
| 62 | #define INTR_RM_FROM_SEC_SHIFT SECURE /* BIT[0] */ |
| 63 | #define INTR_RM_FROM_NS_SHIFT NON_SECURE /* BIT[1] */ |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 64 | #define INTR_RM_FROM_FLAG_MASK U(1) |
Jeenu Viswambharan | 837cc9c | 2018-08-02 10:14:12 +0100 | [diff] [blame] | 65 | #define get_interrupt_rm_flag(flag, ss) \ |
| 66 | ((((flag) >> INTR_RM_FLAGS_SHIFT) >> (ss)) & INTR_RM_FROM_FLAG_MASK) |
| 67 | #define set_interrupt_rm_flag(flag, ss) ((flag) |= U(1) << (ss)) |
| 68 | #define clr_interrupt_rm_flag(flag, ss) ((flag) &= ~(U(1) << (ss))) |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 69 | |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 70 | /******************************************************************************* |
| 71 | * Macros to set the 'flags' parameter passed to an interrupt type handler. Only |
| 72 | * the flag to indicate the security state when the exception was generated is |
| 73 | * supported. |
| 74 | ******************************************************************************/ |
Varun Wadekar | c6a11f6 | 2017-05-25 18:04:48 -0700 | [diff] [blame] | 75 | #define INTR_SRC_SS_FLAG_SHIFT U(0) /* BIT[0] */ |
| 76 | #define INTR_SRC_SS_FLAG_MASK U(1) |
Jeenu Viswambharan | 32ceef5 | 2018-08-02 10:14:12 +0100 | [diff] [blame] | 77 | #define set_interrupt_src_ss(flag, val) ((flag) |= (val) << INTR_SRC_SS_FLAG_SHIFT) |
| 78 | #define clr_interrupt_src_ss(flag) ((flag) &= ~(U(1) << INTR_SRC_SS_FLAG_SHIFT)) |
| 79 | #define get_interrupt_src_ss(flag) (((flag) >> INTR_SRC_SS_FLAG_SHIFT) & \ |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 80 | INTR_SRC_SS_FLAG_MASK) |
| 81 | |
Julius Werner | 53456fc | 2019-07-09 13:49:11 -0700 | [diff] [blame] | 82 | #ifndef __ASSEMBLER__ |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 83 | |
Antonio Nino Diaz | e0b757d | 2018-08-24 16:30:29 +0100 | [diff] [blame] | 84 | #include <errno.h> |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 85 | #include <stdint.h> |
| 86 | |
Antonio Nino Diaz | e0b757d | 2018-08-24 16:30:29 +0100 | [diff] [blame] | 87 | /******************************************************************************* |
| 88 | * Helpers to validate the routing model bits in the 'flags' for a type |
| 89 | * of interrupt. If the model does not match one of the valid masks |
| 90 | * -EINVAL is returned. |
| 91 | ******************************************************************************/ |
| 92 | static inline int32_t validate_sel1_interrupt_rm(uint32_t x) |
| 93 | { |
| 94 | if ((x == INTR_SEL1_VALID_RM0) || (x == INTR_SEL1_VALID_RM1)) |
| 95 | return 0; |
| 96 | |
| 97 | return -EINVAL; |
| 98 | } |
| 99 | |
| 100 | static inline int32_t validate_ns_interrupt_rm(uint32_t x) |
| 101 | { |
| 102 | if ((x == INTR_NS_VALID_RM0) || (x == INTR_NS_VALID_RM1)) |
| 103 | return 0; |
| 104 | |
| 105 | return -EINVAL; |
| 106 | } |
| 107 | |
| 108 | static inline int32_t validate_el3_interrupt_rm(uint32_t x) |
| 109 | { |
Marco Felsch | fb13a23 | 2022-09-21 17:37:01 +0200 | [diff] [blame] | 110 | #if EL3_EXCEPTION_HANDLING && !(defined(SPD_spmd) && (SPMD_SPM_AT_SEL2 == 1)) |
Antonio Nino Diaz | e0b757d | 2018-08-24 16:30:29 +0100 | [diff] [blame] | 111 | /* |
| 112 | * With EL3 exception handling, EL3 interrupts are always routed to EL3 |
Raghu Krishnamurthy | 669bf40 | 2022-07-25 14:44:33 -0700 | [diff] [blame] | 113 | * from both Secure and Non-secure, when the SPMC does not live in S-EL2. |
| 114 | * Therefore INTR_EL3_VALID_RM1 is the only valid routing model. |
Antonio Nino Diaz | e0b757d | 2018-08-24 16:30:29 +0100 | [diff] [blame] | 115 | */ |
| 116 | if (x == INTR_EL3_VALID_RM1) |
| 117 | return 0; |
| 118 | #else |
Raghu Krishnamurthy | 669bf40 | 2022-07-25 14:44:33 -0700 | [diff] [blame] | 119 | /* |
| 120 | * When EL3_EXCEPTION_HANDLING is not defined both routing modes are |
| 121 | * valid. This is the most common case. The exception to this rule is |
| 122 | * when EL3_EXCEPTION_HANDLING is defined but also when the SPMC lives |
| 123 | * at S-EL2. In this case, Group0 Interrupts are trapped to the SPMC |
| 124 | * when running in S-EL0 and S-EL1. The SPMC may handle the interrupt |
| 125 | * itself, delegate it to an SP or forward to EL3 for handling. |
| 126 | */ |
Antonio Nino Diaz | e0b757d | 2018-08-24 16:30:29 +0100 | [diff] [blame] | 127 | if ((x == INTR_EL3_VALID_RM0) || (x == INTR_EL3_VALID_RM1)) |
| 128 | return 0; |
| 129 | #endif |
| 130 | |
| 131 | return -EINVAL; |
| 132 | } |
| 133 | |
| 134 | /******************************************************************************* |
| 135 | * Prototype for defining a handler for an interrupt type |
| 136 | ******************************************************************************/ |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 137 | typedef uint64_t (*interrupt_type_handler_t)(uint32_t id, |
| 138 | uint32_t flags, |
| 139 | void *handle, |
| 140 | void *cookie); |
| 141 | |
| 142 | /******************************************************************************* |
| 143 | * Function & variable prototypes |
| 144 | ******************************************************************************/ |
Louis Mayencourt | 1c819c3 | 2020-01-24 13:30:28 +0000 | [diff] [blame] | 145 | u_register_t get_scr_el3_from_routing_model(uint32_t security_state); |
Dan Handley | a17fefa | 2014-05-14 12:38:32 +0100 | [diff] [blame] | 146 | int32_t set_routing_model(uint32_t type, uint32_t flags); |
| 147 | int32_t register_interrupt_type_handler(uint32_t type, |
| 148 | interrupt_type_handler_t handler, |
| 149 | uint32_t flags); |
Roberto Vargas | 777dd43 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 150 | interrupt_type_handler_t get_interrupt_type_handler(uint32_t type); |
Soby Mathew | 47903c0 | 2015-01-13 15:48:26 +0000 | [diff] [blame] | 151 | int disable_intr_rm_local(uint32_t type, uint32_t security_state); |
| 152 | int enable_intr_rm_local(uint32_t type, uint32_t security_state); |
Achin Gupta | 191e86e | 2014-05-09 10:03:15 +0100 | [diff] [blame] | 153 | |
Julius Werner | 53456fc | 2019-07-09 13:49:11 -0700 | [diff] [blame] | 154 | #endif /*__ASSEMBLER__*/ |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 155 | #endif /* INTERRUPT_MGMT_H */ |