xref: /openbsd-src/sys/arch/arm64/include/intr.h (revision be691f3bb6417f04a68938fadbcaee2d5795e764)
1 /*	$OpenBSD: intr.h,v 1.18 2021/05/17 17:25:13 kettenis Exp $ */
2 
3 /*
4  * Copyright (c) 2001-2004 Opsycon AB  (www.opsycon.se / www.opsycon.com)
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  */
28 
29 #ifndef	_MACHINE_INTR_H_
30 #define	_MACHINE_INTR_H_
31 
32 /*
33  * The interrupt level ipl is a logical level; per-platform interrupt
34  * code will turn it into the appropriate hardware interrupt masks
35  * values.
36  *
37  * Interrupt sources on the CPU are kept enabled regardless of the
38  * current ipl value; individual hardware sources interrupting while
39  * logically masked are masked on the fly, remembered as pending, and
40  * unmasked at the first splx() opportunity.
41  */
42 #ifdef _KERNEL
43 
44 /* Interrupt priority `levels'; not mutually exclusive. */
45 #define	IPL_NONE	0	/* nothing */
46 #define	IPL_SOFT	1	/* soft interrupts */
47 #define	IPL_SOFTCLOCK	2	/* soft clock interrupts */
48 #define	IPL_SOFTNET	3	/* soft network interrupts */
49 #define	IPL_SOFTTTY	4	/* soft terminal interrupts */
50 #define	IPL_BIO		5	/* block I/O */
51 #define	IPL_NET		6	/* network */
52 #define	IPL_TTY		7	/* terminal */
53 #define	IPL_VM		8	/* memory allocation */
54 #define	IPL_AUDIO	9	/* audio */
55 #define	IPL_CLOCK	10	/* clock */
56 #define	IPL_SCHED	IPL_CLOCK
57 #define	IPL_STATCLOCK	IPL_CLOCK
58 #define	IPL_HIGH	11	/* everything */
59 #define	IPL_IPI		12	/* interprocessor interrupt */
60 #define	NIPL		13	/* number of levels */
61 
62 #define	IPL_MPFLOOR	IPL_TTY
63 /* Interrupt priority 'flags'. */
64 #define	IPL_IRQMASK	0xf	/* priority only */
65 #define	IPL_FLAGMASK	0xf00	/* flags only*/
66 #define	IPL_MPSAFE	0x100	/* 'mpsafe' interrupt, no kernel lock */
67 
68 /* Interrupt sharing types. */
69 #define	IST_NONE	0	/* none */
70 #define	IST_PULSE	1	/* pulsed */
71 #define	IST_EDGE	2	/* edge-triggered */
72 #define	IST_LEVEL	3	/* level-triggered */
73 
74 #define	IST_LEVEL_LOW		IST_LEVEL
75 #define	IST_LEVEL_HIGH		4
76 #define	IST_EDGE_FALLING	IST_EDGE
77 #define	IST_EDGE_RISING		5
78 #define	IST_EDGE_BOTH		6
79 
80 #ifndef _LOCORE
81 #include <sys/device.h>
82 #include <sys/queue.h>
83 
84 int	splraise(int);
85 int	spllower(int);
86 void	splx(int);
87 
88 void	arm_do_pending_intr(int);
89 void	arm_set_intr_handler(int (*)(int), int (*)(int), void (*)(int),
90 	    void (*)(int), void (*)(void *), void (*)(void *));
91 
92 struct machine_intr_handle {
93 	struct interrupt_controller *ih_ic;
94 	void *ih_ih;
95 };
96 
97 struct arm_intr_func {
98 	int (*raise)(int);
99 	int (*lower)(int);
100 	void (*x)(int);
101 	void (*setipl)(int);
102 };
103 
104 extern struct arm_intr_func arm_intr_func;
105 
106 #define	splraise(cpl)		(arm_intr_func.raise(cpl))
107 #define	_splraise(cpl)		(arm_intr_func.raise(cpl))
108 #define	spllower(cpl)		(arm_intr_func.lower(cpl))
109 #define	splx(cpl)		(arm_intr_func.x(cpl))
110 
111 #define	splsoft()	splraise(IPL_SOFT)
112 #define	splsoftclock()	splraise(IPL_SOFTCLOCK)
113 #define	splsoftnet()	splraise(IPL_SOFTNET)
114 #define	splsofttty()	splraise(IPL_SOFTTTY)
115 #define	splbio()	splraise(IPL_BIO)
116 #define	splnet()	splraise(IPL_NET)
117 #define	spltty()	splraise(IPL_TTY)
118 #define	splvm()		splraise(IPL_VM)
119 #define	splaudio()	splraise(IPL_AUDIO)
120 #define	splclock()	splraise(IPL_CLOCK)
121 #define	splsched()	splraise(IPL_SCHED)
122 #define	splstatclock()	splraise(IPL_STATCLOCK)
123 #define	splhigh()	splraise(IPL_HIGH)
124 
125 #define	spl0()		spllower(IPL_NONE)
126 
127 void	 intr_barrier(void *);
128 
129 void	 arm_init_smask(void); /* XXX */
130 extern uint32_t arm_smask[NIPL];
131 
132 #include <machine/softintr.h>
133 
134 /* XXX - this is probably the wrong location for this */
135 void arm_clock_register(void (*)(void), void (*)(u_int), void (*)(int),
136     void (*)(void));
137 
138 struct cpu_info;
139 
140 struct interrupt_controller {
141 	int	ic_node;
142 	void	*ic_cookie;
143 	void	*(*ic_establish)(void *, int *, int, struct cpu_info *,
144 		    int (*)(void *), void *, char *);
145 	void	*(*ic_establish_msi)(void *, uint64_t *, uint64_t *, int,
146 		    struct cpu_info *, int (*)(void *), void *, char *);
147 	void	 (*ic_disestablish)(void *);
148 	void	 (*ic_enable)(void *);
149 	void	 (*ic_disable)(void *);
150 	void	 (*ic_route)(void *, int, struct cpu_info *);
151 	void	 (*ic_cpu_enable)(void);
152 	void	 (*ic_barrier)(void *);
153 
154 	LIST_ENTRY(interrupt_controller) ic_list;
155 	uint32_t ic_phandle;
156 	uint32_t ic_cells;
157 };
158 
159 void	 arm_intr_init_fdt(void);
160 void	 arm_intr_register_fdt(struct interrupt_controller *);
161 void	*arm_intr_establish_fdt(int, int, int (*)(void *),
162 	    void *, char *);
163 void	*arm_intr_establish_fdt_cpu(int, int, struct cpu_info *,
164 	    int (*)(void *), void *, char *);
165 void	*arm_intr_establish_fdt_idx(int, int, int, int (*)(void *),
166 	    void *, char *);
167 void	*arm_intr_establish_fdt_idx_cpu(int, int, int, struct cpu_info *,
168 	    int (*)(void *), void *, char *);
169 void	*arm_intr_establish_fdt_imap(int, int *, int, int, int (*)(void *),
170 	    void *, char *);
171 void	*arm_intr_establish_fdt_imap_cpu(int, int *, int, int,
172 	    struct cpu_info *, int (*)(void *), void *, char *);
173 void	*arm_intr_establish_fdt_msi(int, uint64_t *, uint64_t *, int,
174 	    int (*)(void *), void *, char *);
175 void	*arm_intr_establish_fdt_msi_cpu(int, uint64_t *, uint64_t *, int,
176 	    struct cpu_info *, int (*)(void *), void *, char *);
177 void	 arm_intr_disestablish_fdt(void *);
178 void	 arm_intr_enable(void *);
179 void	 arm_intr_disable(void *);
180 void	 arm_intr_route(void *, int, struct cpu_info *);
181 void	 arm_intr_cpu_enable(void);
182 void	*arm_intr_parent_establish_fdt(void *, int *, int,
183 	    struct cpu_info *ci, int (*)(void *), void *, char *);
184 void	 arm_intr_parent_disestablish_fdt(void *);
185 
186 void	 arm_send_ipi(struct cpu_info *, int);
187 extern void (*intr_send_ipi_func)(struct cpu_info *, int);
188 
189 #define ARM_IPI_NOP	0
190 #define ARM_IPI_DDB	1
191 
192 #ifdef DIAGNOSTIC
193 /*
194  * Although this function is implemented in MI code, it must be in this MD
195  * header because we don't want this header to include MI includes.
196  */
197 void splassert_fail(int, int, const char *);
198 extern int splassert_ctl;
199 void arm_splassert_check(int, const char *);
200 #define splassert(__wantipl) do {				\
201 	if (splassert_ctl > 0) {				\
202 		arm_splassert_check(__wantipl, __func__);	\
203 	}							\
204 } while (0)
205 #define	splsoftassert(wantipl)	splassert(wantipl)
206 #else
207 #define	splassert(wantipl)	do { /* nothing */ } while (0)
208 #define	splsoftassert(wantipl)	do { /* nothing */ } while (0)
209 #endif
210 
211 #endif /* ! _LOCORE */
212 
213 #endif /* _KERNEL */
214 
215 #endif	/* _MACHINE_INTR_H_ */
216 
217