blob: 0ca760efbaa0d6712838d304ccd87c4ac73d78b5 [file] [log] [blame]
Achin Gupta191e86e2014-05-09 10:03:15 +01001/*
Boyan Karatotev93102352024-11-20 14:02:32 +00002 * Copyright (c) 2014-2024, Arm Limited and Contributors. All rights reserved.
Achin Gupta191e86e2014-05-09 10:03:15 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta191e86e2014-05-09 10:03:15 +01005 */
6
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef INTERRUPT_MGMT_H
8#define INTERRUPT_MGMT_H
Achin Gupta191e86e2014-05-09 10:03:15 +01009
10#include <arch.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011#include <lib/utils_def.h>
Achin Gupta191e86e2014-05-09 10:03:15 +010012
13/*******************************************************************************
14 * Constants for the types of interrupts recognised by the IM framework
15 ******************************************************************************/
Varun Wadekarc6a11f62017-05-25 18:04:48 -070016#define INTR_TYPE_S_EL1 U(0)
17#define INTR_TYPE_EL3 U(1)
18#define INTR_TYPE_NS U(2)
Boyan Karatotev93102352024-11-20 14:02:32 +000019#define INTR_TYPE_RL U(3)
20#define MAX_INTR_TYPES U(4)
Achin Gupta191e86e2014-05-09 10:03:15 +010021#define INTR_TYPE_INVAL MAX_INTR_TYPES
Jeenu Viswambharandce70b32017-09-22 08:32:09 +010022
23/* Interrupt routing modes */
24#define INTR_ROUTING_MODE_PE 0
25#define INTR_ROUTING_MODE_ANY 1
26
Achin Gupta191e86e2014-05-09 10:03:15 +010027/*
28 * Constant passed to the interrupt handler in the 'id' field when the
29 * framework does not read the gic registers to determine the interrupt id.
30 */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070031#define INTR_ID_UNAVAILABLE U(0xFFFFFFFF)
Achin Gupta191e86e2014-05-09 10:03:15 +010032
33
34/*******************************************************************************
35 * Mask for _both_ the routing model bits in the 'flags' parameter and
36 * constants to define the valid routing models for each supported interrupt
37 * type
38 ******************************************************************************/
Varun Wadekarc6a11f62017-05-25 18:04:48 -070039#define INTR_RM_FLAGS_SHIFT U(0x0)
40#define INTR_RM_FLAGS_MASK U(0x3)
Achin Gupta191e86e2014-05-09 10:03:15 +010041/* Routed to EL3 from NS. Taken to S-EL1 from Secure */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070042#define INTR_SEL1_VALID_RM0 U(0x2)
Achin Gupta191e86e2014-05-09 10:03:15 +010043/* Routed to EL3 from NS and Secure */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070044#define INTR_SEL1_VALID_RM1 U(0x3)
Achin Gupta191e86e2014-05-09 10:03:15 +010045/* Routed to EL1/EL2 from NS and to S-EL1 from Secure */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070046#define INTR_NS_VALID_RM0 U(0x0)
Achin Gupta191e86e2014-05-09 10:03:15 +010047/* Routed to EL1/EL2 from NS and to EL3 from Secure */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070048#define INTR_NS_VALID_RM1 U(0x1)
Soby Mathew58e32d12015-11-23 13:58:45 +000049/* Routed to EL3 from NS. Taken to S-EL1 from Secure and handed over to EL3 */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070050#define INTR_EL3_VALID_RM0 U(0x2)
Soby Mathew58e32d12015-11-23 13:58:45 +000051/* Routed to EL3 from NS and Secure */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070052#define INTR_EL3_VALID_RM1 U(0x3)
Soby Mathew47903c02015-01-13 15:48:26 +000053/* This is the default routing model */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070054#define INTR_DEFAULT_RM U(0x0)
Achin Gupta191e86e2014-05-09 10:03:15 +010055
56/*******************************************************************************
57 * Constants for the _individual_ routing model bits in the 'flags' field for
58 * each interrupt type and mask to validate the 'flags' parameter while
59 * registering an interrupt handler
60 ******************************************************************************/
Varun Wadekarc6a11f62017-05-25 18:04:48 -070061#define INTR_TYPE_FLAGS_MASK U(0xFFFFFFFC)
Achin Gupta191e86e2014-05-09 10:03:15 +010062
63#define INTR_RM_FROM_SEC_SHIFT SECURE /* BIT[0] */
64#define INTR_RM_FROM_NS_SHIFT NON_SECURE /* BIT[1] */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070065#define INTR_RM_FROM_FLAG_MASK U(1)
Jeenu Viswambharan837cc9c2018-08-02 10:14:12 +010066#define get_interrupt_rm_flag(flag, ss) \
67 ((((flag) >> INTR_RM_FLAGS_SHIFT) >> (ss)) & INTR_RM_FROM_FLAG_MASK)
68#define set_interrupt_rm_flag(flag, ss) ((flag) |= U(1) << (ss))
69#define clr_interrupt_rm_flag(flag, ss) ((flag) &= ~(U(1) << (ss)))
Achin Gupta191e86e2014-05-09 10:03:15 +010070
Achin Gupta191e86e2014-05-09 10:03:15 +010071/*******************************************************************************
72 * Macros to set the 'flags' parameter passed to an interrupt type handler. Only
73 * the flag to indicate the security state when the exception was generated is
74 * supported.
75 ******************************************************************************/
Varun Wadekarc6a11f62017-05-25 18:04:48 -070076#define INTR_SRC_SS_FLAG_SHIFT U(0) /* BIT[0] */
77#define INTR_SRC_SS_FLAG_MASK U(1)
Jeenu Viswambharan32ceef52018-08-02 10:14:12 +010078#define set_interrupt_src_ss(flag, val) ((flag) |= (val) << INTR_SRC_SS_FLAG_SHIFT)
79#define clr_interrupt_src_ss(flag) ((flag) &= ~(U(1) << INTR_SRC_SS_FLAG_SHIFT))
80#define get_interrupt_src_ss(flag) (((flag) >> INTR_SRC_SS_FLAG_SHIFT) & \
Achin Gupta191e86e2014-05-09 10:03:15 +010081 INTR_SRC_SS_FLAG_MASK)
82
Julius Werner53456fc2019-07-09 13:49:11 -070083#ifndef __ASSEMBLER__
Achin Gupta191e86e2014-05-09 10:03:15 +010084
Antonio Nino Diaze0b757d2018-08-24 16:30:29 +010085#include <errno.h>
Maheedhar Bollapallie09e32a2024-04-24 18:05:56 +053086#include <stddef.h>
Jeenu Viswambharanaeb267c2017-09-22 08:32:09 +010087#include <stdint.h>
88
Antonio Nino Diaze0b757d2018-08-24 16:30:29 +010089/*******************************************************************************
90 * Helpers to validate the routing model bits in the 'flags' for a type
91 * of interrupt. If the model does not match one of the valid masks
92 * -EINVAL is returned.
93 ******************************************************************************/
94static inline int32_t validate_sel1_interrupt_rm(uint32_t x)
95{
96 if ((x == INTR_SEL1_VALID_RM0) || (x == INTR_SEL1_VALID_RM1))
97 return 0;
98
99 return -EINVAL;
100}
101
102static inline int32_t validate_ns_interrupt_rm(uint32_t x)
103{
104 if ((x == INTR_NS_VALID_RM0) || (x == INTR_NS_VALID_RM1))
105 return 0;
106
107 return -EINVAL;
108}
109
110static inline int32_t validate_el3_interrupt_rm(uint32_t x)
111{
Manish Pandeya47a61a2023-11-20 12:22:08 +0000112#if EL3_EXCEPTION_HANDLING && SPM_MM
Antonio Nino Diaze0b757d2018-08-24 16:30:29 +0100113 /*
114 * With EL3 exception handling, EL3 interrupts are always routed to EL3
Manish Pandeya47a61a2023-11-20 12:22:08 +0000115 * from Non-secure and from secure only if SPM_MM is present.
Raghu Krishnamurthy669bf402022-07-25 14:44:33 -0700116 * Therefore INTR_EL3_VALID_RM1 is the only valid routing model.
Antonio Nino Diaze0b757d2018-08-24 16:30:29 +0100117 */
118 if (x == INTR_EL3_VALID_RM1)
119 return 0;
120#else
Raghu Krishnamurthy669bf402022-07-25 14:44:33 -0700121 /*
122 * When EL3_EXCEPTION_HANDLING is not defined both routing modes are
123 * valid. This is the most common case. The exception to this rule is
124 * when EL3_EXCEPTION_HANDLING is defined but also when the SPMC lives
125 * at S-EL2. In this case, Group0 Interrupts are trapped to the SPMC
126 * when running in S-EL0 and S-EL1. The SPMC may handle the interrupt
127 * itself, delegate it to an SP or forward to EL3 for handling.
128 */
Antonio Nino Diaze0b757d2018-08-24 16:30:29 +0100129 if ((x == INTR_EL3_VALID_RM0) || (x == INTR_EL3_VALID_RM1))
130 return 0;
131#endif
132
133 return -EINVAL;
134}
135
136/*******************************************************************************
137 * Prototype for defining a handler for an interrupt type
138 ******************************************************************************/
Achin Gupta191e86e2014-05-09 10:03:15 +0100139typedef uint64_t (*interrupt_type_handler_t)(uint32_t id,
140 uint32_t flags,
141 void *handle,
142 void *cookie);
143
144/*******************************************************************************
145 * Function & variable prototypes
146 ******************************************************************************/
Maheedhar Bollapallie09e32a2024-04-24 18:05:56 +0530147u_register_t get_scr_el3_from_routing_model(size_t security_state);
Dan Handleya17fefa2014-05-14 12:38:32 +0100148int32_t set_routing_model(uint32_t type, uint32_t flags);
149int32_t register_interrupt_type_handler(uint32_t type,
150 interrupt_type_handler_t handler,
151 uint32_t flags);
Roberto Vargas777dd432018-02-12 12:36:17 +0000152interrupt_type_handler_t get_interrupt_type_handler(uint32_t type);
Soby Mathew47903c02015-01-13 15:48:26 +0000153int disable_intr_rm_local(uint32_t type, uint32_t security_state);
154int enable_intr_rm_local(uint32_t type, uint32_t security_state);
Achin Gupta191e86e2014-05-09 10:03:15 +0100155
Julius Werner53456fc2019-07-09 13:49:11 -0700156#endif /*__ASSEMBLER__*/
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +0000157#endif /* INTERRUPT_MGMT_H */