xref: /optee_os/core/include/kernel/interrupt.h (revision 77bdbf67c42209142ef43129e01113d29d9c62f6)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2016-2019, Linaro Limited
4  */
5 #ifndef __KERNEL_INTERRUPT_H
6 #define __KERNEL_INTERRUPT_H
7 
8 #include <types_ext.h>
9 #include <sys/queue.h>
10 #include <util.h>
11 
12 #define ITRF_TRIGGER_LEVEL	BIT(0)
13 #define ITRF_SHARED			BIT(1)
14 
15 struct itr_chip {
16 	const struct itr_ops *ops;
17 	int (*dt_get_irq)(const uint32_t *properties, int len);
18 };
19 
20 struct itr_ops {
21 	void (*add)(struct itr_chip *chip, size_t it, uint32_t flags);
22 	void (*enable)(struct itr_chip *chip, size_t it);
23 	void (*disable)(struct itr_chip *chip, size_t it);
24 	void (*raise_pi)(struct itr_chip *chip, size_t it);
25 	void (*raise_sgi)(struct itr_chip *chip, size_t it,
26 		uint8_t cpu_mask);
27 	void (*set_affinity)(struct itr_chip *chip, size_t it,
28 		uint8_t cpu_mask);
29 };
30 
31 enum itr_return {
32 	ITRR_NONE,
33 	ITRR_HANDLED,
34 };
35 
36 struct itr_handler;
37 
38 typedef enum itr_return (*itr_handler_t)(struct itr_handler *h);
39 
40 struct itr_handler {
41 	size_t it;
42 	uint32_t flags;
43 	itr_handler_t handler;
44 	void *data;
45 	SLIST_ENTRY(itr_handler) link;
46 };
47 
48 void itr_init(struct itr_chip *data);
49 void itr_handle(size_t it);
50 
51 #ifdef CFG_DT
52 /*
53  * Get the DT interrupt property at @node. In the DT an interrupt
54  *
55  * @fdt reference to the Device Tree
56  * @node is the node offset to read
57  *
58  * Returns the interrupt number if value >= 0
59  * otherwise DT_INFO_INVALID_INTERRUPT
60  */
61 int dt_get_irq(const void *fdt, int node);
62 #endif
63 
64 struct itr_handler *itr_alloc_add(size_t it, itr_handler_t handler,
65 				  uint32_t flags, void *data);
66 void itr_free(struct itr_handler *hdl);
67 void itr_add(struct itr_handler *handler);
68 void itr_enable(size_t it);
69 void itr_disable(size_t it);
70 /* raise the Peripheral Interrupt corresponding to the interrupt ID */
71 void itr_raise_pi(size_t it);
72 /*
73  * raise the Software Generated Interrupt corresponding to the interrupt ID,
74  * the cpu_mask represents which cpu interface to forward.
75  */
76 void itr_raise_sgi(size_t it, uint8_t cpu_mask);
77 /*
78  * let corresponding interrupt forward to the cpu interface
79  * according to the cpu_mask.
80  */
81 void itr_set_affinity(size_t it, uint8_t cpu_mask);
82 
83 /*
84  * __weak overridable function which is called when a secure interrupt is
85  * received. The default function calls panic() immediately, platforms which
86  * expects to receive secure interrupts should override this function.
87  */
88 void itr_core_handler(void);
89 
90 #endif /*__KERNEL_INTERRUPT_H*/
91