xref: /optee_os/core/include/kernel/interrupt.h (revision b1469ba0bfd0371eb52bd50f5c52eeda7a8f5f1e)
1 /*
2  * Copyright (c) 2016, Linaro Limited
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 #ifndef __KERNEL_INTERRUPT_H
28 #define __KERNEL_INTERRUPT_H
29 
30 #include <types_ext.h>
31 #include <sys/queue.h>
32 
33 #define ITRF_TRIGGER_LEVEL	(1 << 0)
34 
35 struct itr_chip {
36 	const struct itr_ops *ops;
37 };
38 
39 struct itr_ops {
40 	void (*add)(struct itr_chip *chip, size_t it, uint32_t flags);
41 	void (*enable)(struct itr_chip *chip, size_t it);
42 	void (*disable)(struct itr_chip *chip, size_t it);
43 	void (*raise_pi)(struct itr_chip *chip, size_t it);
44 	void (*raise_sgi)(struct itr_chip *chip, size_t it,
45 		uint8_t cpu_mask);
46 	void (*set_affinity)(struct itr_chip *chip, size_t it,
47 		uint8_t cpu_mask);
48 };
49 
50 enum itr_return {
51 	ITRR_NONE,
52 	ITRR_HANDLED,
53 };
54 
55 struct itr_handler {
56 	size_t it;
57 	uint32_t flags;
58 	enum itr_return (*handler)(struct itr_handler *h);
59 	void *data;
60 	SLIST_ENTRY(itr_handler) link;
61 };
62 
63 void itr_init(struct itr_chip *data);
64 void itr_handle(size_t it);
65 
66 void itr_add(struct itr_handler *handler);
67 void itr_enable(size_t it);
68 void itr_disable(size_t it);
69 /* raise the Peripheral Interrupt corresponding to the interrupt ID */
70 void itr_raise_pi(size_t it);
71 /*
72  * raise the Software Generated Interrupt corresponding to the interrupt ID,
73  * the cpu_mask represents which cpu interface to forward.
74  */
75 void itr_raise_sgi(size_t it, uint8_t cpu_mask);
76 /*
77  * let corresponding interrupt forward to the cpu interface
78  * according to the cpu_mask.
79  */
80 void itr_set_affinity(size_t it, uint8_t cpu_mask);
81 
82 #endif /*__KERNEL_INTERRUPT_H*/
83