xref: /optee_os/core/include/kernel/interrupt.h (revision 5b25c76ac40f830867e3d60800120ffd7874e8dc)
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 };
18 
19 struct itr_ops {
20 	void (*add)(struct itr_chip *chip, size_t it, uint32_t flags);
21 	void (*enable)(struct itr_chip *chip, size_t it);
22 	void (*disable)(struct itr_chip *chip, size_t it);
23 	void (*raise_pi)(struct itr_chip *chip, size_t it);
24 	void (*raise_sgi)(struct itr_chip *chip, size_t it,
25 		uint8_t cpu_mask);
26 	void (*set_affinity)(struct itr_chip *chip, size_t it,
27 		uint8_t cpu_mask);
28 };
29 
30 enum itr_return {
31 	ITRR_NONE,
32 	ITRR_HANDLED,
33 };
34 
35 struct itr_handler {
36 	size_t it;
37 	uint32_t flags;
38 	enum itr_return (*handler)(struct itr_handler *h);
39 	void *data;
40 	SLIST_ENTRY(itr_handler) link;
41 };
42 
43 void itr_init(struct itr_chip *data);
44 void itr_handle(size_t it);
45 
46 void itr_add(struct itr_handler *handler);
47 void itr_enable(size_t it);
48 void itr_disable(size_t it);
49 /* raise the Peripheral Interrupt corresponding to the interrupt ID */
50 void itr_raise_pi(size_t it);
51 /*
52  * raise the Software Generated Interrupt corresponding to the interrupt ID,
53  * the cpu_mask represents which cpu interface to forward.
54  */
55 void itr_raise_sgi(size_t it, uint8_t cpu_mask);
56 /*
57  * let corresponding interrupt forward to the cpu interface
58  * according to the cpu_mask.
59  */
60 void itr_set_affinity(size_t it, uint8_t cpu_mask);
61 
62 /*
63  * __weak overridable function which is called when a secure interrupt is
64  * received. The default function calls panic() immediately, platforms which
65  * expects to receive secure interrupts should override this function.
66  */
67 void itr_core_handler(void);
68 
69 #endif /*__KERNEL_INTERRUPT_H*/
70