11bb92983SJerome Forissier /* SPDX-License-Identifier: BSD-2-Clause */
27315b7b4SJens Wiklander /*
3e9f46c74SJens Wiklander * Copyright (c) 2016-2019, Linaro Limited
47315b7b4SJens Wiklander */
57315b7b4SJens Wiklander #ifndef __KERNEL_INTERRUPT_H
67315b7b4SJens Wiklander #define __KERNEL_INTERRUPT_H
77315b7b4SJens Wiklander
8702fe5a7SClément Léger #include <dt-bindings/interrupt-controller/irq.h>
933a0c835SEtienne Carriere #include <kernel/dt_driver.h>
10f932e355SEtienne Carriere #include <mm/core_memprot.h>
117315b7b4SJens Wiklander #include <sys/queue.h>
12f932e355SEtienne Carriere #include <tee_api_types.h>
13f932e355SEtienne Carriere #include <types_ext.h>
141c832d7cSdavidwang #include <util.h>
157315b7b4SJens Wiklander
161c832d7cSdavidwang #define ITRF_TRIGGER_LEVEL BIT(0)
171c832d7cSdavidwang #define ITRF_SHARED BIT(1)
187315b7b4SJens Wiklander
19ec740b9fSJens Wiklander /* Forward the interrupt only to the current CPU */
20ec740b9fSJens Wiklander #define ITR_CPU_MASK_TO_THIS_CPU BIT(31)
21ec740b9fSJens Wiklander /* Forward the interrupt to all CPUs except the current CPU */
22ec740b9fSJens Wiklander #define ITR_CPU_MASK_TO_OTHER_CPUS BIT(30)
23ec740b9fSJens Wiklander
24f932e355SEtienne Carriere struct itr_handler;
25f932e355SEtienne Carriere
26a009881dSEtienne Carriere /*
27a009881dSEtienne Carriere * struct itr_chip - Interrupt controller
28a009881dSEtienne Carriere *
29a009881dSEtienne Carriere * @ops Operation callback functions
30f932e355SEtienne Carriere * @name Controller name, for debug purpose
31f932e355SEtienne Carriere * @handlers Registered handlers list head
32a009881dSEtienne Carriere * @dt_get_irq Device tree node parsing function
33a009881dSEtienne Carriere */
347315b7b4SJens Wiklander struct itr_chip {
357315b7b4SJens Wiklander const struct itr_ops *ops;
36f932e355SEtienne Carriere const char *name;
37f932e355SEtienne Carriere SLIST_HEAD(, itr_handler) handlers;
38702fe5a7SClément Léger /*
39702fe5a7SClément Léger * dt_get_irq - parse a device tree interrupt property
40702fe5a7SClément Léger *
4150cbe7ebSEtienne Carriere * @properties Big-endian interrupt property array from device tree
42702fe5a7SClément Léger * @count number of elements in @properties
43702fe5a7SClément Léger * @type If not NULL, output interrupt type (IRQ_TYPE_* defines)
44702fe5a7SClément Léger * or IRQ_TYPE_NONE if unknown
45702fe5a7SClément Léger * @prio If not NULL, output interrupt priority value or 0 if unknown
46d2c318b6SEtienne Carriere *
47d2c318b6SEtienne Carriere * This handler is required to support dt_get_irq_type_prio() and
48d2c318b6SEtienne Carriere * dt_get_irq() API function for interrupt consumers manually
49d2c318b6SEtienne Carriere * retrieving trigger type and/or priority from the device tree.
50702fe5a7SClément Léger */
51702fe5a7SClément Léger int (*dt_get_irq)(const uint32_t *properties, int count, uint32_t *type,
52702fe5a7SClément Léger uint32_t *prio);
537315b7b4SJens Wiklander };
547315b7b4SJens Wiklander
55a009881dSEtienne Carriere /*
56a009881dSEtienne Carriere * struct itr_ops - Interrupt controller operations
572a50ce7dSEtienne Carriere * @configure Configure an interrupt
58a009881dSEtienne Carriere * @enable Enable an interrupt
59a009881dSEtienne Carriere * @disable Disable an interrupt
60f932e355SEtienne Carriere * @mask Mask an interrupt, may be called from an interrupt context
61f932e355SEtienne Carriere * @unmask Unmask an interrupt, may be called from an interrupt context
62a009881dSEtienne Carriere * @raise_pi Raise per-cpu interrupt or NULL if not applicable
63a009881dSEtienne Carriere * @raise_sgi Raise a SGI or NULL if not applicable to that controller
64a009881dSEtienne Carriere * @set_affinity Set interrupt/cpu affinity or NULL if not applicable
65*990c4711SAntonio Borneo * @set_wake Enable/disable power-management wake-on of an interrupt or NULL
66*990c4711SAntonio Borneo * if not applicable
67f932e355SEtienne Carriere *
68df7874b5SEtienne Carriere * Handlers @enable, @disable, @mask and @unmask are mandated. Handlers
69df7874b5SEtienne Carriere * @mask and @unmask have unpaged memory constraints. These requirements are
70df7874b5SEtienne Carriere * verified by itr_chip_init() and itr_chip_dt_only_init().
71df7874b5SEtienne Carriere *
72df7874b5SEtienne Carriere * Handler @configure is needed for interrupt providers which do not rely on
73df7874b5SEtienne Carriere * DT for consumers interrupt configuration, that is interrupt consumers using
74df7874b5SEtienne Carriere * interrupt_configure() or friends (interrupt_add_handler(),
75df7874b5SEtienne Carriere * interrupt_add_configure_handler(), interrupt_add_handler_with_chip(),
76df7874b5SEtienne Carriere * etc...).
77a009881dSEtienne Carriere */
787315b7b4SJens Wiklander struct itr_ops {
792a50ce7dSEtienne Carriere void (*configure)(struct itr_chip *chip, size_t it, uint32_t type,
80702fe5a7SClément Léger uint32_t prio);
817315b7b4SJens Wiklander void (*enable)(struct itr_chip *chip, size_t it);
827315b7b4SJens Wiklander void (*disable)(struct itr_chip *chip, size_t it);
83f932e355SEtienne Carriere void (*mask)(struct itr_chip *chip, size_t it);
84f932e355SEtienne Carriere void (*unmask)(struct itr_chip *chip, size_t it);
8526ed70ecSGuanchao Liang void (*raise_pi)(struct itr_chip *chip, size_t it);
8626ed70ecSGuanchao Liang void (*raise_sgi)(struct itr_chip *chip, size_t it,
87ec740b9fSJens Wiklander uint32_t cpu_mask);
8826ed70ecSGuanchao Liang void (*set_affinity)(struct itr_chip *chip, size_t it,
8926ed70ecSGuanchao Liang uint8_t cpu_mask);
90*990c4711SAntonio Borneo void (*set_wake)(struct itr_chip *chip, size_t it, bool on);
917315b7b4SJens Wiklander };
927315b7b4SJens Wiklander
9333a0c835SEtienne Carriere /*
9433a0c835SEtienne Carriere * struct itr_desc - Interrupt description
9533a0c835SEtienne Carriere * @chip Interrupt controller reference
9633a0c835SEtienne Carriere * @itr_num Interrupt number
9733a0c835SEtienne Carriere *
9833a0c835SEtienne Carriere * This struct is used for binding interrupt device data between
9933a0c835SEtienne Carriere * drivers when using DT_DRIVERS means. See itr_dt_get_func type
10033a0c835SEtienne Carriere * definition.
10133a0c835SEtienne Carriere */
10233a0c835SEtienne Carriere struct itr_desc {
10333a0c835SEtienne Carriere struct itr_chip *chip;
10433a0c835SEtienne Carriere size_t itr_num;
10533a0c835SEtienne Carriere };
10633a0c835SEtienne Carriere
107a009881dSEtienne Carriere /* Interrupt handler return value */
1087315b7b4SJens Wiklander enum itr_return {
1097315b7b4SJens Wiklander ITRR_NONE,
1107315b7b4SJens Wiklander ITRR_HANDLED,
1117315b7b4SJens Wiklander };
1127315b7b4SJens Wiklander
113a009881dSEtienne Carriere /* Interrupt handler signature */
114acc5dd21SLudovic Barre typedef enum itr_return (*itr_handler_t)(struct itr_handler *h);
115acc5dd21SLudovic Barre
116a009881dSEtienne Carriere /*
117a009881dSEtienne Carriere * struct itr_handler - Interrupt handler reference
118a009881dSEtienne Carriere * @it Interrupt number
119f932e355SEtienne Carriere * @flags Property bit flags (ITRF_*) or 0
120a009881dSEtienne Carriere * @data Private data for that interrupt handler
121f932e355SEtienne Carriere * @chip Interrupt controller chip device
122a009881dSEtienne Carriere * @link Reference in controller handler list
123a009881dSEtienne Carriere */
1247315b7b4SJens Wiklander struct itr_handler {
1257315b7b4SJens Wiklander size_t it;
1267315b7b4SJens Wiklander uint32_t flags;
127acc5dd21SLudovic Barre itr_handler_t handler;
1287315b7b4SJens Wiklander void *data;
129f932e355SEtienne Carriere struct itr_chip *chip;
1307315b7b4SJens Wiklander SLIST_ENTRY(itr_handler) link;
1317315b7b4SJens Wiklander };
1327315b7b4SJens Wiklander
133f932e355SEtienne Carriere #define ITR_HANDLER(_chip, _itr_num, _flags, _fn, _priv) \
134f932e355SEtienne Carriere ((struct itr_handler){ \
135f932e355SEtienne Carriere .chip = (_chip), .it = (_itr_num), .flags = (_flags), \
136f932e355SEtienne Carriere .handler = (_fn), .data = (_priv), \
137f932e355SEtienne Carriere })
138f932e355SEtienne Carriere
139f932e355SEtienne Carriere /*
140df7874b5SEtienne Carriere * Initialise an interrupt controller handle to be used only with the DT
141df7874b5SEtienne Carriere * @chip Interrupt controller
142f932e355SEtienne Carriere */
143df7874b5SEtienne Carriere TEE_Result itr_chip_dt_only_init(struct itr_chip *chip);
144f932e355SEtienne Carriere
145f932e355SEtienne Carriere /*
146f932e355SEtienne Carriere * Initialise an interrupt controller handle
147f932e355SEtienne Carriere * @chip Interrupt controller
148f932e355SEtienne Carriere */
149f932e355SEtienne Carriere TEE_Result itr_chip_init(struct itr_chip *chip);
150f932e355SEtienne Carriere
15101980f3fSEtienne Carriere /*
152a009881dSEtienne Carriere * Initialise main interrupt controller driver
153a009881dSEtienne Carriere * @data Main controller main data reference to register
15401980f3fSEtienne Carriere */
15501980f3fSEtienne Carriere void interrupt_main_init(struct itr_chip *data);
15601980f3fSEtienne Carriere
157e050e0a7SEtienne Carriere /* Retrieve main interrupt controller reference */
158e050e0a7SEtienne Carriere struct itr_chip *interrupt_get_main_chip(void);
159245a552cSJens Wiklander /* Retrieve main interrupt controller reference, or NULL on failure */
160245a552cSJens Wiklander struct itr_chip *interrupt_get_main_chip_may_fail(void);
161e050e0a7SEtienne Carriere
16267729d8dSLudovic Barre #ifdef CFG_DT
16367729d8dSLudovic Barre /*
164702fe5a7SClément Léger * Get the DT interrupt property at @node. In the DT an interrupt property can
165702fe5a7SClément Léger * specify additional information which can be retrieved with @type and @prio.
16667729d8dSLudovic Barre *
16767729d8dSLudovic Barre * @fdt reference to the Device Tree
168702fe5a7SClément Léger * @node is the node offset to read the interrupt property from
169702fe5a7SClément Léger * @type interrupt type (IRQ_TYPE_* defines) if specified by interrupt property
170702fe5a7SClément Léger * or IRQ_TYPE_NONE if not. Can be NULL if not needed
171702fe5a7SClément Léger * @prio interrupt priority if specified by interrupt property or 0 if not. Can
172702fe5a7SClément Léger * be NULL if not needed
17367729d8dSLudovic Barre *
17467729d8dSLudovic Barre * Returns the interrupt number if value >= 0
17567729d8dSLudovic Barre * otherwise DT_INFO_INVALID_INTERRUPT
17667729d8dSLudovic Barre */
177702fe5a7SClément Léger int dt_get_irq_type_prio(const void *fdt, int node, uint32_t *type,
178702fe5a7SClément Léger uint32_t *prio);
179702fe5a7SClément Léger
180702fe5a7SClément Léger /*
181702fe5a7SClément Léger * Get the DT interrupt property at @node
182702fe5a7SClément Léger */
dt_get_irq(const void * fdt,int node)183702fe5a7SClément Léger static inline int dt_get_irq(const void *fdt, int node)
184702fe5a7SClément Léger {
185702fe5a7SClément Léger return dt_get_irq_type_prio(fdt, node, NULL, NULL);
186702fe5a7SClément Léger }
18767729d8dSLudovic Barre #endif
18867729d8dSLudovic Barre
189e9f46c74SJens Wiklander /*
190e9f46c74SJens Wiklander * __weak overridable function which is called when a secure interrupt is
191e9f46c74SJens Wiklander * received. The default function calls panic() immediately, platforms which
192e9f46c74SJens Wiklander * expects to receive secure interrupts should override this function.
193e9f46c74SJens Wiklander */
194358bf47cSEtienne Carriere void interrupt_main_handler(void);
195e9f46c74SJens Wiklander
196f932e355SEtienne Carriere /*
197f932e355SEtienne Carriere * Interrupt controller chip API functions
198f932e355SEtienne Carriere */
199f932e355SEtienne Carriere
200f932e355SEtienne Carriere /*
201f932e355SEtienne Carriere * interrupt_call_handlers() - Call registered handlers for an interrupt
202f932e355SEtienne Carriere * @chip Interrupt controller
203f932e355SEtienne Carriere * @itr_num Interrupt number
204f932e355SEtienne Carriere *
205f932e355SEtienne Carriere * This function is called from an interrupt context by a primary interrupt
206f932e355SEtienne Carriere * handler. This function calls the handlers registered for that interrupt.
207f932e355SEtienne Carriere * If interrupt is not handled, it is masked.
208f932e355SEtienne Carriere */
209f932e355SEtienne Carriere void interrupt_call_handlers(struct itr_chip *chip, size_t itr_num);
210f932e355SEtienne Carriere
211f932e355SEtienne Carriere /*
212f932e355SEtienne Carriere * interrupt_mask() - Mask an interrupt
213f932e355SEtienne Carriere * @chip Interrupt controller
214f932e355SEtienne Carriere * @itr_num Interrupt number
215f932e355SEtienne Carriere *
216f932e355SEtienne Carriere * This function may be called in interrupt context
217f932e355SEtienne Carriere */
interrupt_mask(struct itr_chip * chip,size_t itr_num)218f932e355SEtienne Carriere static inline void interrupt_mask(struct itr_chip *chip, size_t itr_num)
219f932e355SEtienne Carriere {
220f932e355SEtienne Carriere chip->ops->mask(chip, itr_num);
221f932e355SEtienne Carriere }
222f932e355SEtienne Carriere
223f932e355SEtienne Carriere /*
224f932e355SEtienne Carriere * interrupt_unmask() - Unmask an interrupt
225f932e355SEtienne Carriere * @chip Interrupt controller
226f932e355SEtienne Carriere * @itr_num Interrupt number
227f932e355SEtienne Carriere *
228f932e355SEtienne Carriere * This function may be called in interrupt context
229f932e355SEtienne Carriere */
interrupt_unmask(struct itr_chip * chip,size_t itr_num)230f932e355SEtienne Carriere static inline void interrupt_unmask(struct itr_chip *chip, size_t itr_num)
231f932e355SEtienne Carriere {
232f932e355SEtienne Carriere chip->ops->unmask(chip, itr_num);
233f932e355SEtienne Carriere }
234f932e355SEtienne Carriere
235f932e355SEtienne Carriere /*
236f932e355SEtienne Carriere * interrupt_enable() - Enable an interrupt
237f932e355SEtienne Carriere * @chip Interrupt controller
238f932e355SEtienne Carriere * @itr_num Interrupt number
239f932e355SEtienne Carriere */
interrupt_enable(struct itr_chip * chip,size_t itr_num)240f932e355SEtienne Carriere static inline void interrupt_enable(struct itr_chip *chip, size_t itr_num)
241f932e355SEtienne Carriere {
242f932e355SEtienne Carriere chip->ops->enable(chip, itr_num);
243f932e355SEtienne Carriere }
244f932e355SEtienne Carriere
245f932e355SEtienne Carriere /*
246f932e355SEtienne Carriere * interrupt_disable() - Disable an interrupt
247f932e355SEtienne Carriere * @chip Interrupt controller
248f932e355SEtienne Carriere * @itr_num Interrupt number
249f932e355SEtienne Carriere */
interrupt_disable(struct itr_chip * chip,size_t itr_num)250f932e355SEtienne Carriere static inline void interrupt_disable(struct itr_chip *chip, size_t itr_num)
251f932e355SEtienne Carriere {
252f932e355SEtienne Carriere chip->ops->disable(chip, itr_num);
253f932e355SEtienne Carriere }
254f932e355SEtienne Carriere
255f932e355SEtienne Carriere /*
256b2d6db21SEtienne Carriere * interrupt_can_raise_pi() - Return whether controller embeds raise_pi
257b2d6db21SEtienne Carriere * @chip Interrupt controller
258b2d6db21SEtienne Carriere */
interrupt_can_raise_pi(struct itr_chip * chip)259b2d6db21SEtienne Carriere static inline bool interrupt_can_raise_pi(struct itr_chip *chip)
260b2d6db21SEtienne Carriere {
261b2d6db21SEtienne Carriere return chip->ops->raise_pi;
262b2d6db21SEtienne Carriere }
263b2d6db21SEtienne Carriere
264b2d6db21SEtienne Carriere /*
265b2d6db21SEtienne Carriere * interrupt_can_raise_sgi() - Return whether controller embeds raise_sgi
266b2d6db21SEtienne Carriere * @chip Interrupt controller
267b2d6db21SEtienne Carriere */
interrupt_can_raise_sgi(struct itr_chip * chip)268b2d6db21SEtienne Carriere static inline bool interrupt_can_raise_sgi(struct itr_chip *chip)
269b2d6db21SEtienne Carriere {
270b2d6db21SEtienne Carriere return chip->ops->raise_sgi;
271b2d6db21SEtienne Carriere }
272b2d6db21SEtienne Carriere
273b2d6db21SEtienne Carriere /*
274b2d6db21SEtienne Carriere * interrupt_can_set_affinity() - Return whether controller embeds set_affinity
275b2d6db21SEtienne Carriere * @chip Interrupt controller
276b2d6db21SEtienne Carriere */
interrupt_can_set_affinity(struct itr_chip * chip)277b2d6db21SEtienne Carriere static inline bool interrupt_can_set_affinity(struct itr_chip *chip)
278b2d6db21SEtienne Carriere {
279b2d6db21SEtienne Carriere return chip->ops->set_affinity;
280b2d6db21SEtienne Carriere }
281b2d6db21SEtienne Carriere
282b2d6db21SEtienne Carriere /*
283*990c4711SAntonio Borneo * interrupt_can_set_wake() - Return whether controller embeds set_wake
284*990c4711SAntonio Borneo * @chip Interrupt controller
285*990c4711SAntonio Borneo */
interrupt_can_set_wake(struct itr_chip * chip)286*990c4711SAntonio Borneo static inline bool interrupt_can_set_wake(struct itr_chip *chip)
287*990c4711SAntonio Borneo {
288*990c4711SAntonio Borneo return chip->ops->set_wake;
289*990c4711SAntonio Borneo }
290*990c4711SAntonio Borneo
291*990c4711SAntonio Borneo /*
292b2d6db21SEtienne Carriere * interrupt_raise_pi() - Raise a peripheral interrupt of a controller
293b2d6db21SEtienne Carriere * @chip Interrupt controller
294b2d6db21SEtienne Carriere * @itr_num Interrupt number to raise
295b2d6db21SEtienne Carriere */
interrupt_raise_pi(struct itr_chip * chip,size_t itr_num)296b2d6db21SEtienne Carriere static inline void interrupt_raise_pi(struct itr_chip *chip, size_t itr_num)
297b2d6db21SEtienne Carriere {
298b2d6db21SEtienne Carriere assert(interrupt_can_raise_pi(chip));
299b2d6db21SEtienne Carriere chip->ops->raise_pi(chip, itr_num);
300b2d6db21SEtienne Carriere }
301b2d6db21SEtienne Carriere
302b2d6db21SEtienne Carriere /*
303b2d6db21SEtienne Carriere * interrupt_raise_sgi() - Raise a software generiated interrupt of a controller
304b2d6db21SEtienne Carriere * @chip Interrupt controller
305b2d6db21SEtienne Carriere * @itr_num Interrupt number to raise
306ec740b9fSJens Wiklander * @cpu_mask: A bitfield of CPUs to forward the interrupt to, unless
307ec740b9fSJens Wiklander * ITR_CPU_MASK_TO_THIS_CPU or ITR_CPU_MASK_TO_OTHER_CPUS
308ec740b9fSJens Wiklander * (mutually exclusive) are set.
309b2d6db21SEtienne Carriere */
interrupt_raise_sgi(struct itr_chip * chip,size_t itr_num,uint32_t cpu_mask)310b2d6db21SEtienne Carriere static inline void interrupt_raise_sgi(struct itr_chip *chip, size_t itr_num,
311ec740b9fSJens Wiklander uint32_t cpu_mask)
312b2d6db21SEtienne Carriere {
313b2d6db21SEtienne Carriere assert(interrupt_can_raise_sgi(chip));
314b2d6db21SEtienne Carriere chip->ops->raise_sgi(chip, itr_num, cpu_mask);
315b2d6db21SEtienne Carriere }
316b2d6db21SEtienne Carriere
317b2d6db21SEtienne Carriere /*
318b2d6db21SEtienne Carriere * interrupt_set_affinity() - Set CPU affinity for a controller interrupt
319b2d6db21SEtienne Carriere * @chip Interrupt controller
320ae7f9049SEtienne Carriere * @itr_num Interrupt number
321b2d6db21SEtienne Carriere * @cpu_mask Mask of the CPUs targeted by the interrupt
322b2d6db21SEtienne Carriere */
interrupt_set_affinity(struct itr_chip * chip,size_t itr_num,uint8_t cpu_mask)323b2d6db21SEtienne Carriere static inline void interrupt_set_affinity(struct itr_chip *chip, size_t itr_num,
324b2d6db21SEtienne Carriere uint8_t cpu_mask)
325b2d6db21SEtienne Carriere {
326b2d6db21SEtienne Carriere assert(interrupt_can_set_affinity(chip));
327b2d6db21SEtienne Carriere chip->ops->set_affinity(chip, itr_num, cpu_mask);
328b2d6db21SEtienne Carriere }
329b2d6db21SEtienne Carriere
330b2d6db21SEtienne Carriere /*
331*990c4711SAntonio Borneo * interrupt_set_wake() - Enable/disable power-management wake-on of interrupt
332*990c4711SAntonio Borneo * @chip Interrupt controller
333*990c4711SAntonio Borneo * @itr_num Interrupt number
334*990c4711SAntonio Borneo * @on A boolean for enable/disable
335*990c4711SAntonio Borneo */
interrupt_set_wake(struct itr_chip * chip,size_t itr_num,bool on)336*990c4711SAntonio Borneo static inline void interrupt_set_wake(struct itr_chip *chip, size_t itr_num,
337*990c4711SAntonio Borneo bool on)
338*990c4711SAntonio Borneo {
339*990c4711SAntonio Borneo assert(interrupt_can_set_wake(chip));
340*990c4711SAntonio Borneo chip->ops->set_wake(chip, itr_num, on);
341*990c4711SAntonio Borneo }
342*990c4711SAntonio Borneo
343*990c4711SAntonio Borneo /*
344f932e355SEtienne Carriere * interrupt_configure() - Configure an interrupt in an interrupt controller
345f932e355SEtienne Carriere * @chip Interrupt controller
346f932e355SEtienne Carriere * @itr_num Interrupt number
347f932e355SEtienne Carriere * @type Interrupt trigger type (IRQ_TYPE_* defines) or IRQ_TYPE_NONE
348f932e355SEtienne Carriere * @prio Interrupt priority or 0
349f932e355SEtienne Carriere *
350f932e355SEtienne Carriere * Interrupt consumers that get their interrupt from the DT do not need to
351f932e355SEtienne Carriere * call interrupt_configure() since the interrupt configuration has already
352f932e355SEtienne Carriere * been done by interrupt controller based on the DT bidings.
353f932e355SEtienne Carriere */
354f932e355SEtienne Carriere TEE_Result interrupt_configure(struct itr_chip *chip, size_t itr_num,
355f932e355SEtienne Carriere uint32_t type, uint32_t prio);
356f932e355SEtienne Carriere
357f932e355SEtienne Carriere /*
358f932e355SEtienne Carriere * interrupt_add_and_configure_handler() - Register and configure a handler
359f932e355SEtienne Carriere * @hdl Interrupt handler to register
360f932e355SEtienne Carriere * @type Interrupt trigger type (IRQ_TYPE_* defines) or IRQ_TYPE_NONE
361f932e355SEtienne Carriere * @prio Interrupt priority or 0
362f932e355SEtienne Carriere */
363f932e355SEtienne Carriere TEE_Result interrupt_add_configure_handler(struct itr_handler *hdl,
364f932e355SEtienne Carriere uint32_t type, uint32_t prio);
365f932e355SEtienne Carriere
366f932e355SEtienne Carriere /*
367f932e355SEtienne Carriere * interrupt_add_handler() - Register an interrupt handler
368f932e355SEtienne Carriere * @hdl Interrupt handler to register
369f932e355SEtienne Carriere *
370f932e355SEtienne Carriere * This helper function assumes interrupt type is set to IRQ_TYPE_NONE
371f932e355SEtienne Carriere * and interrupt priority to 0.
372f932e355SEtienne Carriere */
interrupt_add_handler(struct itr_handler * hdl)373f932e355SEtienne Carriere static inline TEE_Result interrupt_add_handler(struct itr_handler *hdl)
374f932e355SEtienne Carriere {
375f932e355SEtienne Carriere return interrupt_add_configure_handler(hdl, IRQ_TYPE_NONE, 0);
376f932e355SEtienne Carriere }
377f932e355SEtienne Carriere
378f932e355SEtienne Carriere /*
379e9376d02SEtienne Carriere * interrupt_create_handler() - Allocate/register an interrupt callback handler
38077c4fee6SEtienne Carriere * @itr_chip Interrupt chip obtained from interrupt_dt_get_by_*() or like
38177c4fee6SEtienne Carriere * @itr_num Interrupt number obtained from interrupt_dt_get_by_*() or like
382e9376d02SEtienne Carriere * @callback Callback handler function
383e9376d02SEtienne Carriere * @priv Private dat to pssa to @callback
384e9376d02SEtienne Carriere * @flags INTERRUPT_FLAGS_* or 0
385e9376d02SEtienne Carriere * @out_hdl Output allocated and registered handler or NULL
386e9376d02SEtienne Carriere *
387e9376d02SEtienne Carriere * This function differs from interrupt_add_handler() in that the
388e9376d02SEtienne Carriere * interrupt is not reconfigured. interrupt_create_handler() expects
38977c4fee6SEtienne Carriere * @itr_chip and @itr_num were obtained from a call
39077c4fee6SEtienne Carriere * to interrupt_dt_get_by_index() or interrupt_dt_get_by_name() that
39177c4fee6SEtienne Carriere * are in charge of configuring the interrupt according to its DT property.
392e9376d02SEtienne Carriere */
393e9376d02SEtienne Carriere TEE_Result interrupt_create_handler(struct itr_chip *itr_chip, size_t itr_num,
394e9376d02SEtienne Carriere itr_handler_t callback, void *priv,
395e9376d02SEtienne Carriere uint32_t flags,
396e9376d02SEtienne Carriere struct itr_handler **out_hdl);
397e9376d02SEtienne Carriere
398e9376d02SEtienne Carriere /*
399f932e355SEtienne Carriere * interrupt_add_handler_with_chip() - Register an interrupt handler providing
400f932e355SEtienne Carriere * the interrupt chip reference in specific argument @chip.
401f932e355SEtienne Carriere * @chip Interrupt controller
402f932e355SEtienne Carriere * @h Interrupt handler to register
403f932e355SEtienne Carriere */
interrupt_add_handler_with_chip(struct itr_chip * chip,struct itr_handler * h)404f932e355SEtienne Carriere static inline TEE_Result interrupt_add_handler_with_chip(struct itr_chip *chip,
405f932e355SEtienne Carriere struct itr_handler *h)
406f932e355SEtienne Carriere {
407f932e355SEtienne Carriere h->chip = chip;
408f932e355SEtienne Carriere return interrupt_add_handler(h);
409f932e355SEtienne Carriere }
410f932e355SEtienne Carriere
411f932e355SEtienne Carriere /*
412f932e355SEtienne Carriere * interrupt_remove_handler() - Remove a registered interrupt handler
413f932e355SEtienne Carriere * @hdl Interrupt handler to remove
414f932e355SEtienne Carriere *
415f932e355SEtienne Carriere * This function is the counterpart of interrupt_add_handler().
416f932e355SEtienne Carriere * This function may panic on non-NULL invalid @hdl reference.
417f932e355SEtienne Carriere */
418f932e355SEtienne Carriere void interrupt_remove_handler(struct itr_handler *hdl);
419f932e355SEtienne Carriere
420f932e355SEtienne Carriere /*
4211b5c7ca4SEtienne Carriere * interrupt_alloc_add_conf_handler() - Allocate, configure, register a handler
4221b5c7ca4SEtienne Carriere * @chip Interrupt controller
4231b5c7ca4SEtienne Carriere * @itr_num Interrupt number
4241b5c7ca4SEtienne Carriere * @handler Interrupt handler to register
4251b5c7ca4SEtienne Carriere * @flags Bitmask flag ITRF_*
4261b5c7ca4SEtienne Carriere * @data Private data reference passed to @handler
4271b5c7ca4SEtienne Carriere * @type Interrupt trigger type (IRQ_TYPE_* defines) or IRQ_TYPE_NONE
4281b5c7ca4SEtienne Carriere * @prio Interrupt priority or 0
4291b5c7ca4SEtienne Carriere * @out_hdl NULL or output pointer to allocated struct itr_handler
4301b5c7ca4SEtienne Carriere */
4311b5c7ca4SEtienne Carriere TEE_Result interrupt_alloc_add_conf_handler(struct itr_chip *chip,
4321b5c7ca4SEtienne Carriere size_t it_num,
4331b5c7ca4SEtienne Carriere itr_handler_t handler,
4341b5c7ca4SEtienne Carriere uint32_t flags, void *data,
4351b5c7ca4SEtienne Carriere uint32_t type, uint32_t prio,
4361b5c7ca4SEtienne Carriere struct itr_handler **out_hdl);
4371b5c7ca4SEtienne Carriere
4381b5c7ca4SEtienne Carriere /*
439f932e355SEtienne Carriere * interrupt_alloc_add_handler() - Allocate and register an interrupt handler
440f932e355SEtienne Carriere * @chip Interrupt controller
441f932e355SEtienne Carriere * @itr_num Interrupt number
442f932e355SEtienne Carriere * @handler Interrupt handler to register
443f932e355SEtienne Carriere * @flags Bitmask flag ITRF_*
444f932e355SEtienne Carriere * @data Private data reference passed to @handler
445f932e355SEtienne Carriere * @out_hdl NULL or output pointer to allocated struct itr_handler
446f932e355SEtienne Carriere */
interrupt_alloc_add_handler(struct itr_chip * chip,size_t it_num,itr_handler_t handler,uint32_t flags,void * data,struct itr_handler ** hdl)4471b5c7ca4SEtienne Carriere static inline TEE_Result interrupt_alloc_add_handler(struct itr_chip *chip,
4481b5c7ca4SEtienne Carriere size_t it_num,
4491b5c7ca4SEtienne Carriere itr_handler_t handler,
4501b5c7ca4SEtienne Carriere uint32_t flags,
451f932e355SEtienne Carriere void *data,
4521b5c7ca4SEtienne Carriere struct itr_handler **hdl)
4531b5c7ca4SEtienne Carriere {
4541b5c7ca4SEtienne Carriere return interrupt_alloc_add_conf_handler(chip, it_num, handler, flags,
4551b5c7ca4SEtienne Carriere data, IRQ_TYPE_NONE, 0, hdl);
4561b5c7ca4SEtienne Carriere }
457f932e355SEtienne Carriere
458f932e355SEtienne Carriere /*
459f932e355SEtienne Carriere * interrupt_remove_free_handler() - Remove/free a registered interrupt handler
460f932e355SEtienne Carriere * @hdl Interrupt handler to remove and free
461f932e355SEtienne Carriere *
4621b5c7ca4SEtienne Carriere * This function is the counterpart of interrupt_alloc_add_handler()
4631b5c7ca4SEtienne Carriere * and interrupt_alloc_add_conf_handler().
464f932e355SEtienne Carriere * This function may panic on non-NULL invalid @hdl reference.
465f932e355SEtienne Carriere */
466f932e355SEtienne Carriere void interrupt_remove_free_handler(struct itr_handler *hdl);
46733a0c835SEtienne Carriere
46833a0c835SEtienne Carriere /*
46933a0c835SEtienne Carriere * itr_dt_get_func - Typedef of function to get an interrupt in DT node
47033a0c835SEtienne Carriere *
47133a0c835SEtienne Carriere * @args Reference to phandle arguments
47233a0c835SEtienne Carriere * @data Pointer to data given at interrupt_register_provider() call
47333a0c835SEtienne Carriere * @itr_desc_p Pointer to the struct itr_desc to fill
47433a0c835SEtienne Carriere * Return TEE_SUCCESS in case of success.
47533a0c835SEtienne Carriere * Return TEE_ERROR_DEFER_DRIVER_INIT if controller is not initialized.
47633a0c835SEtienne Carriere * Return another TEE_Result code otherwise.
47733a0c835SEtienne Carriere *
47833a0c835SEtienne Carriere * Upon success, the interrupt is configured and consumer can add a handler
47933a0c835SEtienne Carriere * function to the interrupt. Yet, the interrupt is not enabled until consumer
48033a0c835SEtienne Carriere * calls interrupt_enable().
48133a0c835SEtienne Carriere */
48233a0c835SEtienne Carriere typedef TEE_Result (*itr_dt_get_func)(struct dt_pargs *args, void *data,
48333a0c835SEtienne Carriere struct itr_desc *itr_desc_p);
48433a0c835SEtienne Carriere
48533a0c835SEtienne Carriere #ifdef CFG_DT
48633a0c835SEtienne Carriere /**
48733a0c835SEtienne Carriere * interrupt_register_provider() - Register an interrupt provider
48833a0c835SEtienne Carriere *
48933a0c835SEtienne Carriere * @fdt Device tree to work on
49033a0c835SEtienne Carriere * @node Node offset of the interrupt controller in the DT
49133a0c835SEtienne Carriere * @dt_get_itr Callback to match the devicetree interrupt reference with
49233a0c835SEtienne Carriere * @data Data which will be passed to the get_dt_its callback
49333a0c835SEtienne Carriere */
49433a0c835SEtienne Carriere TEE_Result interrupt_register_provider(const void *fdt, int node,
49533a0c835SEtienne Carriere itr_dt_get_func dt_get_itr, void *data);
49633a0c835SEtienne Carriere
49733a0c835SEtienne Carriere /**
49833a0c835SEtienne Carriere * interrupt_dt_get_by_index() - Get an interrupt from DT by interrupt index
49933a0c835SEtienne Carriere *
50033a0c835SEtienne Carriere * Interrupt index (@index) refers to the index of the target interrupt to be
50133a0c835SEtienne Carriere * retrieved as DT binding property "interrupts" may define several
50233a0c835SEtienne Carriere * interrupts.
50333a0c835SEtienne Carriere *
50433a0c835SEtienne Carriere * @fdt Device tree to work on
50533a0c835SEtienne Carriere * @node Node offset of the subnode containing interrupt(s) references
5062e6b9fc5SEtienne Carriere * @index Index in "interrupts" or "interrupts-extended" property list
50733a0c835SEtienne Carriere * @chip Output interrupt controller reference upon success
50833a0c835SEtienne Carriere * @itr_num Output interrupt number upon success
50933a0c835SEtienne Carriere *
51033a0c835SEtienne Carriere * Return TEE_SUCCESS in case of success
51133a0c835SEtienne Carriere * Return TEE_ERROR_DEFER_DRIVER_INIT if interrupt driver is not yet initialized
51233a0c835SEtienne Carriere * Return TEE_ERROR_ITEM_NOT_FOUND if the DT does not reference target interrupt
51333a0c835SEtienne Carriere * Return any other TEE_Result compliant code in case of error
51433a0c835SEtienne Carriere */
51533a0c835SEtienne Carriere TEE_Result interrupt_dt_get_by_index(const void *fdt, int node,
51633a0c835SEtienne Carriere unsigned int index, struct itr_chip **chip,
51733a0c835SEtienne Carriere size_t *itr_num);
51833a0c835SEtienne Carriere
51933a0c835SEtienne Carriere /**
52033a0c835SEtienne Carriere * interrupt_dt_get_by_name() - Get an interrupt from DT by interrupt name
52133a0c835SEtienne Carriere *
52233a0c835SEtienne Carriere * @fdt Device tree to work on
52333a0c835SEtienne Carriere * @node Node offset of the subnode containing interrupt(s) references
52433a0c835SEtienne Carriere * @name Name identifier used in "interrupt-names" property
52533a0c835SEtienne Carriere * @chip Output interrupt controller reference upon success
52633a0c835SEtienne Carriere * @itr_num Output interrupt number upon success
52733a0c835SEtienne Carriere *
52833a0c835SEtienne Carriere * Return TEE_SUCCESS in case of success
52933a0c835SEtienne Carriere * Return TEE_ERROR_DEFER_DRIVER_INIT if interrupt driver is not yet initialized
53033a0c835SEtienne Carriere * Return TEE_ERROR_ITEM_NOT_FOUND if the DT does not reference target interrupt
53133a0c835SEtienne Carriere * Return any other TEE_Result compliant code in case of error
53233a0c835SEtienne Carriere */
53333a0c835SEtienne Carriere TEE_Result interrupt_dt_get_by_name(const void *fdt, int node, const char *name,
53433a0c835SEtienne Carriere struct itr_chip **chip, size_t *itr_num);
53533a0c835SEtienne Carriere #else
interrupt_register_provider(const void * dt __unused,int node __unused,itr_dt_get_func f __unused,void * data __unused)53633a0c835SEtienne Carriere static inline TEE_Result interrupt_register_provider(const void *dt __unused,
53733a0c835SEtienne Carriere int node __unused,
53833a0c835SEtienne Carriere itr_dt_get_func f __unused,
53933a0c835SEtienne Carriere void *data __unused)
54033a0c835SEtienne Carriere {
54133a0c835SEtienne Carriere return TEE_ERROR_NOT_IMPLEMENTED;
54233a0c835SEtienne Carriere }
54333a0c835SEtienne Carriere
interrupt_dt_get_by_index(const void * fdt __unused,int node __unused,unsigned int index __unused,struct itr_chip ** c __unused,size_t * itr_num __unused)54433a0c835SEtienne Carriere static inline TEE_Result interrupt_dt_get_by_index(const void *fdt __unused,
54533a0c835SEtienne Carriere int node __unused,
54633a0c835SEtienne Carriere unsigned int index __unused,
54733a0c835SEtienne Carriere struct itr_chip **c __unused,
54833a0c835SEtienne Carriere size_t *itr_num __unused)
54933a0c835SEtienne Carriere {
55033a0c835SEtienne Carriere return TEE_ERROR_NOT_IMPLEMENTED;
55133a0c835SEtienne Carriere }
55233a0c835SEtienne Carriere
interrupt_dt_get_by_name(const void * fdt __unused,int node __unused,const char * name __unused,struct itr_chip ** ch __unused,size_t * itr_num __unused)55333a0c835SEtienne Carriere static inline TEE_Result interrupt_dt_get_by_name(const void *fdt __unused,
55433a0c835SEtienne Carriere int node __unused,
55533a0c835SEtienne Carriere const char *name __unused,
55633a0c835SEtienne Carriere struct itr_chip **ch __unused,
55733a0c835SEtienne Carriere size_t *itr_num __unused)
55833a0c835SEtienne Carriere {
55933a0c835SEtienne Carriere return TEE_ERROR_NOT_IMPLEMENTED;
56033a0c835SEtienne Carriere }
56133a0c835SEtienne Carriere #endif /*CFG_DT*/
56233a0c835SEtienne Carriere
56333a0c835SEtienne Carriere /*
56433a0c835SEtienne Carriere * Helper function for when caller retrieves the first interrupt defined
5652e6b9fc5SEtienne Carriere * in "interrupts" or "interrupts-extended" DT binding property list.
56633a0c835SEtienne Carriere */
interrupt_dt_get(const void * fdt,int node,struct itr_chip ** chip,size_t * itr_num)56733a0c835SEtienne Carriere static inline TEE_Result interrupt_dt_get(const void *fdt, int node,
56833a0c835SEtienne Carriere struct itr_chip **chip,
56933a0c835SEtienne Carriere size_t *itr_num)
57033a0c835SEtienne Carriere {
57133a0c835SEtienne Carriere return interrupt_dt_get_by_index(fdt, node, 0, chip, itr_num);
57233a0c835SEtienne Carriere }
5737315b7b4SJens Wiklander #endif /*__KERNEL_INTERRUPT_H*/
574