xref: /aosp_15_r20/external/arm-trusted-firmware/include/bl31/interrupt_mgmt.h (revision 54fd6939e177f8ff529b10183254802c76df6d08)
1*54fd6939SJiyong Park /*
2*54fd6939SJiyong Park  * Copyright (c) 2014-2020, ARM Limited and Contributors. All rights reserved.
3*54fd6939SJiyong Park  *
4*54fd6939SJiyong Park  * SPDX-License-Identifier: BSD-3-Clause
5*54fd6939SJiyong Park  */
6*54fd6939SJiyong Park 
7*54fd6939SJiyong Park #ifndef INTERRUPT_MGMT_H
8*54fd6939SJiyong Park #define INTERRUPT_MGMT_H
9*54fd6939SJiyong Park 
10*54fd6939SJiyong Park #include <arch.h>
11*54fd6939SJiyong Park #include <lib/utils_def.h>
12*54fd6939SJiyong Park 
13*54fd6939SJiyong Park /*******************************************************************************
14*54fd6939SJiyong Park  * Constants for the types of interrupts recognised by the IM framework
15*54fd6939SJiyong Park  ******************************************************************************/
16*54fd6939SJiyong Park #define INTR_TYPE_S_EL1			U(0)
17*54fd6939SJiyong Park #define INTR_TYPE_EL3			U(1)
18*54fd6939SJiyong Park #define INTR_TYPE_NS			U(2)
19*54fd6939SJiyong Park #define MAX_INTR_TYPES			U(3)
20*54fd6939SJiyong Park #define INTR_TYPE_INVAL			MAX_INTR_TYPES
21*54fd6939SJiyong Park 
22*54fd6939SJiyong Park /* Interrupt routing modes */
23*54fd6939SJiyong Park #define INTR_ROUTING_MODE_PE		0
24*54fd6939SJiyong Park #define INTR_ROUTING_MODE_ANY		1
25*54fd6939SJiyong Park 
26*54fd6939SJiyong Park /*
27*54fd6939SJiyong Park  * Constant passed to the interrupt handler in the 'id' field when the
28*54fd6939SJiyong Park  * framework does not read the gic registers to determine the interrupt id.
29*54fd6939SJiyong Park  */
30*54fd6939SJiyong Park #define INTR_ID_UNAVAILABLE		U(0xFFFFFFFF)
31*54fd6939SJiyong Park 
32*54fd6939SJiyong Park 
33*54fd6939SJiyong Park /*******************************************************************************
34*54fd6939SJiyong Park  * Mask for _both_ the routing model bits in the 'flags' parameter and
35*54fd6939SJiyong Park  * constants to define the valid routing models for each supported interrupt
36*54fd6939SJiyong Park  * type
37*54fd6939SJiyong Park  ******************************************************************************/
38*54fd6939SJiyong Park #define INTR_RM_FLAGS_SHIFT		U(0x0)
39*54fd6939SJiyong Park #define INTR_RM_FLAGS_MASK		U(0x3)
40*54fd6939SJiyong Park /* Routed to EL3 from NS. Taken to S-EL1 from Secure */
41*54fd6939SJiyong Park #define INTR_SEL1_VALID_RM0		U(0x2)
42*54fd6939SJiyong Park /* Routed to EL3 from NS and Secure */
43*54fd6939SJiyong Park #define INTR_SEL1_VALID_RM1		U(0x3)
44*54fd6939SJiyong Park /* Routed to EL1/EL2 from NS and to S-EL1 from Secure */
45*54fd6939SJiyong Park #define INTR_NS_VALID_RM0		U(0x0)
46*54fd6939SJiyong Park /* Routed to EL1/EL2 from NS and to EL3 from Secure */
47*54fd6939SJiyong Park #define INTR_NS_VALID_RM1		U(0x1)
48*54fd6939SJiyong Park /* Routed to EL3 from NS. Taken to S-EL1 from Secure and handed over to EL3 */
49*54fd6939SJiyong Park #define INTR_EL3_VALID_RM0		U(0x2)
50*54fd6939SJiyong Park /* Routed to EL3 from NS and Secure */
51*54fd6939SJiyong Park #define INTR_EL3_VALID_RM1		U(0x3)
52*54fd6939SJiyong Park /* This is the default routing model */
53*54fd6939SJiyong Park #define INTR_DEFAULT_RM			U(0x0)
54*54fd6939SJiyong Park 
55*54fd6939SJiyong Park /*******************************************************************************
56*54fd6939SJiyong Park  * Constants for the _individual_ routing model bits in the 'flags' field for
57*54fd6939SJiyong Park  * each interrupt type and mask to validate the 'flags' parameter while
58*54fd6939SJiyong Park  * registering an interrupt handler
59*54fd6939SJiyong Park  ******************************************************************************/
60*54fd6939SJiyong Park #define INTR_TYPE_FLAGS_MASK		U(0xFFFFFFFC)
61*54fd6939SJiyong Park 
62*54fd6939SJiyong Park #define INTR_RM_FROM_SEC_SHIFT		SECURE		/* BIT[0] */
63*54fd6939SJiyong Park #define INTR_RM_FROM_NS_SHIFT		NON_SECURE	/* BIT[1] */
64*54fd6939SJiyong Park #define INTR_RM_FROM_FLAG_MASK		U(1)
65*54fd6939SJiyong Park #define get_interrupt_rm_flag(flag, ss) \
66*54fd6939SJiyong Park 	((((flag) >> INTR_RM_FLAGS_SHIFT) >> (ss)) & INTR_RM_FROM_FLAG_MASK)
67*54fd6939SJiyong Park #define set_interrupt_rm_flag(flag, ss)	((flag) |= U(1) << (ss))
68*54fd6939SJiyong Park #define clr_interrupt_rm_flag(flag, ss)	((flag) &= ~(U(1) << (ss)))
69*54fd6939SJiyong Park 
70*54fd6939SJiyong Park /*******************************************************************************
71*54fd6939SJiyong Park  * Macros to set the 'flags' parameter passed to an interrupt type handler. Only
72*54fd6939SJiyong Park  * the flag to indicate the security state when the exception was generated is
73*54fd6939SJiyong Park  * supported.
74*54fd6939SJiyong Park  ******************************************************************************/
75*54fd6939SJiyong Park #define INTR_SRC_SS_FLAG_SHIFT		U(0)		/* BIT[0] */
76*54fd6939SJiyong Park #define INTR_SRC_SS_FLAG_MASK		U(1)
77*54fd6939SJiyong Park #define set_interrupt_src_ss(flag, val)	((flag) |= (val) << INTR_SRC_SS_FLAG_SHIFT)
78*54fd6939SJiyong Park #define clr_interrupt_src_ss(flag)	((flag) &= ~(U(1) << INTR_SRC_SS_FLAG_SHIFT))
79*54fd6939SJiyong Park #define get_interrupt_src_ss(flag)	(((flag) >> INTR_SRC_SS_FLAG_SHIFT) & \
80*54fd6939SJiyong Park 					 INTR_SRC_SS_FLAG_MASK)
81*54fd6939SJiyong Park 
82*54fd6939SJiyong Park #ifndef __ASSEMBLER__
83*54fd6939SJiyong Park 
84*54fd6939SJiyong Park #include <errno.h>
85*54fd6939SJiyong Park #include <stdint.h>
86*54fd6939SJiyong Park 
87*54fd6939SJiyong Park /*******************************************************************************
88*54fd6939SJiyong Park  * Helpers to validate the routing model bits in the 'flags' for a type
89*54fd6939SJiyong Park  * of interrupt. If the model does not match one of the valid masks
90*54fd6939SJiyong Park  * -EINVAL is returned.
91*54fd6939SJiyong Park  ******************************************************************************/
validate_sel1_interrupt_rm(uint32_t x)92*54fd6939SJiyong Park static inline int32_t validate_sel1_interrupt_rm(uint32_t x)
93*54fd6939SJiyong Park {
94*54fd6939SJiyong Park 	if ((x == INTR_SEL1_VALID_RM0) || (x == INTR_SEL1_VALID_RM1))
95*54fd6939SJiyong Park 		return 0;
96*54fd6939SJiyong Park 
97*54fd6939SJiyong Park 	return -EINVAL;
98*54fd6939SJiyong Park }
99*54fd6939SJiyong Park 
validate_ns_interrupt_rm(uint32_t x)100*54fd6939SJiyong Park static inline int32_t validate_ns_interrupt_rm(uint32_t x)
101*54fd6939SJiyong Park {
102*54fd6939SJiyong Park 	if ((x == INTR_NS_VALID_RM0) || (x == INTR_NS_VALID_RM1))
103*54fd6939SJiyong Park 		return 0;
104*54fd6939SJiyong Park 
105*54fd6939SJiyong Park 	return -EINVAL;
106*54fd6939SJiyong Park }
107*54fd6939SJiyong Park 
validate_el3_interrupt_rm(uint32_t x)108*54fd6939SJiyong Park static inline int32_t validate_el3_interrupt_rm(uint32_t x)
109*54fd6939SJiyong Park {
110*54fd6939SJiyong Park #if EL3_EXCEPTION_HANDLING
111*54fd6939SJiyong Park 	/*
112*54fd6939SJiyong Park 	 * With EL3 exception handling, EL3 interrupts are always routed to EL3
113*54fd6939SJiyong Park 	 * from both Secure and Non-secure, and therefore INTR_EL3_VALID_RM1 is
114*54fd6939SJiyong Park 	 * the only valid routing model.
115*54fd6939SJiyong Park 	 */
116*54fd6939SJiyong Park 	if (x == INTR_EL3_VALID_RM1)
117*54fd6939SJiyong Park 		return 0;
118*54fd6939SJiyong Park #else
119*54fd6939SJiyong Park 	if ((x == INTR_EL3_VALID_RM0) || (x == INTR_EL3_VALID_RM1))
120*54fd6939SJiyong Park 		return 0;
121*54fd6939SJiyong Park #endif
122*54fd6939SJiyong Park 
123*54fd6939SJiyong Park 	return -EINVAL;
124*54fd6939SJiyong Park }
125*54fd6939SJiyong Park 
126*54fd6939SJiyong Park /*******************************************************************************
127*54fd6939SJiyong Park  * Prototype for defining a handler for an interrupt type
128*54fd6939SJiyong Park  ******************************************************************************/
129*54fd6939SJiyong Park typedef uint64_t (*interrupt_type_handler_t)(uint32_t id,
130*54fd6939SJiyong Park 					     uint32_t flags,
131*54fd6939SJiyong Park 					     void *handle,
132*54fd6939SJiyong Park 					     void *cookie);
133*54fd6939SJiyong Park 
134*54fd6939SJiyong Park /*******************************************************************************
135*54fd6939SJiyong Park  * Function & variable prototypes
136*54fd6939SJiyong Park  ******************************************************************************/
137*54fd6939SJiyong Park u_register_t get_scr_el3_from_routing_model(uint32_t security_state);
138*54fd6939SJiyong Park int32_t set_routing_model(uint32_t type, uint32_t flags);
139*54fd6939SJiyong Park int32_t register_interrupt_type_handler(uint32_t type,
140*54fd6939SJiyong Park 					interrupt_type_handler_t handler,
141*54fd6939SJiyong Park 					uint32_t flags);
142*54fd6939SJiyong Park interrupt_type_handler_t get_interrupt_type_handler(uint32_t type);
143*54fd6939SJiyong Park int disable_intr_rm_local(uint32_t type, uint32_t security_state);
144*54fd6939SJiyong Park int enable_intr_rm_local(uint32_t type, uint32_t security_state);
145*54fd6939SJiyong Park 
146*54fd6939SJiyong Park #endif /*__ASSEMBLER__*/
147*54fd6939SJiyong Park #endif /* INTERRUPT_MGMT_H */
148