xref: /openbsd-src/sys/arch/octeon/include/intr.h (revision c992d008a2a019c41cdbaf3d0bc25b11c7416233)
1*c992d008Svisa /*	$OpenBSD: intr.h,v 1.22 2019/09/05 05:31:38 visa Exp $ */
2c6b2ceb4Ssyuu 
3c6b2ceb4Ssyuu /*
4c6b2ceb4Ssyuu  * Copyright (c) 2001-2004 Opsycon AB  (www.opsycon.se / www.opsycon.com)
5c6b2ceb4Ssyuu  *
6c6b2ceb4Ssyuu  * Redistribution and use in source and binary forms, with or without
7c6b2ceb4Ssyuu  * modification, are permitted provided that the following conditions
8c6b2ceb4Ssyuu  * are met:
9c6b2ceb4Ssyuu  * 1. Redistributions of source code must retain the above copyright
10c6b2ceb4Ssyuu  *    notice, this list of conditions and the following disclaimer.
11c6b2ceb4Ssyuu  * 2. Redistributions in binary form must reproduce the above copyright
12c6b2ceb4Ssyuu  *    notice, this list of conditions and the following disclaimer in the
13c6b2ceb4Ssyuu  *    documentation and/or other materials provided with the distribution.
14c6b2ceb4Ssyuu  *
15c6b2ceb4Ssyuu  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16c6b2ceb4Ssyuu  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17c6b2ceb4Ssyuu  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18c6b2ceb4Ssyuu  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19c6b2ceb4Ssyuu  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20c6b2ceb4Ssyuu  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21c6b2ceb4Ssyuu  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22c6b2ceb4Ssyuu  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23c6b2ceb4Ssyuu  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24c6b2ceb4Ssyuu  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25c6b2ceb4Ssyuu  * SUCH DAMAGE.
26c6b2ceb4Ssyuu  *
27c6b2ceb4Ssyuu  */
28c6b2ceb4Ssyuu 
29c6b2ceb4Ssyuu #ifndef _MACHINE_INTR_H_
30c6b2ceb4Ssyuu #define _MACHINE_INTR_H_
31c6b2ceb4Ssyuu 
32c6b2ceb4Ssyuu /*
33c6b2ceb4Ssyuu  * The interrupt level ipl is a logical level; per-platform interrupt
34c6b2ceb4Ssyuu  * code will turn it into the appropriate hardware interrupt masks
35c6b2ceb4Ssyuu  * values.
36c6b2ceb4Ssyuu  *
37c6b2ceb4Ssyuu  * Interrupt sources on the CPU are kept enabled regardless of the
38c6b2ceb4Ssyuu  * current ipl value; individual hardware sources interrupting while
39c6b2ceb4Ssyuu  * logically masked are masked on the fly, remembered as pending, and
40c6b2ceb4Ssyuu  * unmasked at the first splx() opportunity.
41c6b2ceb4Ssyuu  *
42c6b2ceb4Ssyuu  * An exception to this rule is the clock interrupt. Clock interrupts
43c6b2ceb4Ssyuu  * are always allowed to happen, but will (of course!) not be serviced
44c6b2ceb4Ssyuu  * if logically masked.  The reason for this is that clocks usually sit on
45c6b2ceb4Ssyuu  * INT5 and cannot be easily masked if external hardware masking is used.
46c6b2ceb4Ssyuu  */
47c6b2ceb4Ssyuu 
48c6b2ceb4Ssyuu /* Interrupt priority `levels'; not mutually exclusive. */
49c6b2ceb4Ssyuu #define	IPL_NONE	0	/* nothing */
50c6b2ceb4Ssyuu #define	IPL_SOFTINT	1	/* soft interrupts */
51ba0d7474Svisa #define	IPL_SOFTCLOCK	1	/* soft clock interrupts */
52ba0d7474Svisa #define	IPL_SOFTNET	2	/* soft network interrupts */
53ba0d7474Svisa #define	IPL_SOFTTTY	3	/* soft terminal interrupts */
54ba0d7474Svisa #define	IPL_SOFTHIGH	IPL_SOFTTTY	/* highest level of soft interrupts */
55ba0d7474Svisa #define	IPL_BIO		4	/* block I/O */
56c6b2ceb4Ssyuu #define	IPL_AUDIO	IPL_BIO
57ba0d7474Svisa #define	IPL_NET		5	/* network */
58ba0d7474Svisa #define	IPL_TTY		6	/* terminal */
59ba0d7474Svisa #define	IPL_VM		7	/* memory allocation */
60ba0d7474Svisa #define	IPL_CLOCK	8	/* clock */
61c6b2ceb4Ssyuu #define	IPL_SCHED	IPL_CLOCK
62ba0d7474Svisa #define	IPL_HIGH	9	/* everything */
63ba0d7474Svisa #define	IPL_IPI		10	/* interprocessor interrupt */
64ba0d7474Svisa #define	NIPLS		11	/* number of levels */
65c6b2ceb4Ssyuu 
66706f15edSdlg #define IPL_MPFLOOR	IPL_TTY
67706f15edSdlg 
68ee8a2a3cSkettenis /* Interrupt priority 'flags'. */
6911b47dfeSvisa #define	IPL_MPSAFE	0x100
70ee8a2a3cSkettenis 
71c6b2ceb4Ssyuu /* Interrupt sharing types. */
72c6b2ceb4Ssyuu #define	IST_NONE	0	/* none */
73c6b2ceb4Ssyuu #define	IST_PULSE	1	/* pulsed */
74c6b2ceb4Ssyuu #define	IST_EDGE	2	/* edge-triggered */
75c6b2ceb4Ssyuu #define	IST_LEVEL	3	/* level-triggered */
76c6b2ceb4Ssyuu 
77c6b2ceb4Ssyuu #define	SINTBIT(q)	(q)
78c6b2ceb4Ssyuu #define	SINTMASK(q)	(1 << SINTBIT(q))
79c6b2ceb4Ssyuu 
80c6b2ceb4Ssyuu /* Soft interrupt masks. */
81c6b2ceb4Ssyuu 
82ba0d7474Svisa #define	SI_SOFTCLOCK	0	/* for IPL_SOFTCLOCK */
83ba0d7474Svisa #define	SI_SOFTNET	1	/* for IPL_SOFTNET */
84ba0d7474Svisa #define	SI_SOFTTTY	2	/* for IPL_SOFTTTY */
85c6b2ceb4Ssyuu 
86ba0d7474Svisa #define	SI_NQUEUES	3
87c6b2ceb4Ssyuu 
88c6b2ceb4Ssyuu #ifndef _LOCORE
89c6b2ceb4Ssyuu 
9065976d5fSmpi #include <sys/mutex.h>
91c6b2ceb4Ssyuu #include <sys/queue.h>
92c6b2ceb4Ssyuu 
93c6b2ceb4Ssyuu struct soft_intrhand {
94c6b2ceb4Ssyuu 	TAILQ_ENTRY(soft_intrhand) sih_list;
95c6b2ceb4Ssyuu 	void	(*sih_func)(void *);
96c6b2ceb4Ssyuu 	void	*sih_arg;
97c6b2ceb4Ssyuu 	struct soft_intrq *sih_siq;
98c6b2ceb4Ssyuu 	int	sih_pending;
99c6b2ceb4Ssyuu };
100c6b2ceb4Ssyuu 
101c6b2ceb4Ssyuu struct soft_intrq {
102c6b2ceb4Ssyuu 	TAILQ_HEAD(, soft_intrhand) siq_list;
103c6b2ceb4Ssyuu 	int siq_si;
104c6b2ceb4Ssyuu 	struct mutex siq_mtx;
105c6b2ceb4Ssyuu };
106c6b2ceb4Ssyuu 
107c6b2ceb4Ssyuu void	 softintr_disestablish(void *);
108c6b2ceb4Ssyuu void	 softintr_dispatch(int);
109c6b2ceb4Ssyuu void	*softintr_establish(int, void (*)(void *), void *);
110c6b2ceb4Ssyuu void	 softintr_init(void);
111c6b2ceb4Ssyuu void	 softintr_schedule(void *);
112c6b2ceb4Ssyuu 
113c6b2ceb4Ssyuu #define splbio()	splraise(IPL_BIO)
114c6b2ceb4Ssyuu #define splnet()	splraise(IPL_NET)
115c6b2ceb4Ssyuu #define spltty()	splraise(IPL_TTY)
116c6b2ceb4Ssyuu #define splaudio()	splraise(IPL_AUDIO)
117c6b2ceb4Ssyuu #define splvm()		splraise(IPL_VM)
118c6b2ceb4Ssyuu #define splclock()	splraise(IPL_CLOCK)
119c6b2ceb4Ssyuu #define splsched()	splraise(IPL_SCHED)
120c6b2ceb4Ssyuu #define splhigh()	splraise(IPL_HIGH)
121c6b2ceb4Ssyuu 
122ba0d7474Svisa #define splsoftclock()	splraise(IPL_SOFTCLOCK)
123ba0d7474Svisa #define splsoftnet()	splraise(IPL_SOFTNET)
124c6b2ceb4Ssyuu #define splstatclock()	splhigh()
125c6b2ceb4Ssyuu 
126c6b2ceb4Ssyuu #define spl0()		spllower(0)
127c6b2ceb4Ssyuu 
128c6b2ceb4Ssyuu void	splinit(void);
129c6b2ceb4Ssyuu 
130*c992d008Svisa #ifdef DIAGNOSTIC
131*c992d008Svisa /*
132*c992d008Svisa  * Although this function is implemented in MI code, it must be in this MD
133*c992d008Svisa  * header because we don't want this header to include MI includes.
134*c992d008Svisa  */
135*c992d008Svisa void splassert_fail(int, int, const char *);
136*c992d008Svisa extern int splassert_ctl;
137*c992d008Svisa void splassert_check(int, const char *);
138*c992d008Svisa #define	splassert(__wantipl) do {				\
139*c992d008Svisa 	if (splassert_ctl > 0) {				\
140*c992d008Svisa 		splassert_check(__wantipl, __func__);		\
141*c992d008Svisa 	}							\
142*c992d008Svisa } while (0)
143*c992d008Svisa #define	splsoftassert(wantipl)	splassert(wantipl)
144*c992d008Svisa #else
145c6b2ceb4Ssyuu #define	splassert(X)
146c6b2ceb4Ssyuu #define	splsoftassert(X)
147*c992d008Svisa #endif
148c6b2ceb4Ssyuu 
149aff9d062Svisa void	register_splx_handler(void (*)(int));
150c6b2ceb4Ssyuu int	splraise(int);
151c6b2ceb4Ssyuu void	splx(int);
152c6b2ceb4Ssyuu int	spllower(int);
153c6b2ceb4Ssyuu 
15427262a1bSkettenis void	intr_barrier(void *);
15527262a1bSkettenis 
156c6b2ceb4Ssyuu /*
157c6b2ceb4Ssyuu  * Low level interrupt dispatcher registration data.
158c6b2ceb4Ssyuu  */
159c6b2ceb4Ssyuu 
160c6b2ceb4Ssyuu /* Schedule priorities for base interrupts (CPU) */
161c6b2ceb4Ssyuu #define	INTPRI_IPI	0
162c6b2ceb4Ssyuu #define	INTPRI_CLOCK	1
163c6b2ceb4Ssyuu /* other values are system-specific */
164c6b2ceb4Ssyuu 
165c6b2ceb4Ssyuu #define NLOWINT	16		/* Number of low level registrations possible */
166c6b2ceb4Ssyuu 
167c6b2ceb4Ssyuu extern uint32_t idle_mask;
168c6b2ceb4Ssyuu 
169b43ebd13Smpi struct trapframe;
170b43ebd13Smpi void	set_intr(int, uint32_t, uint32_t(*)(uint32_t, struct trapframe *));
171c6b2ceb4Ssyuu 
172c6b2ceb4Ssyuu uint32_t updateimask(uint32_t);
173c6b2ceb4Ssyuu void	dosoftint(void);
174c6b2ceb4Ssyuu 
17589182934Svisa struct intr_controller {
17689182934Svisa 	void	  *ic_cookie;
17789182934Svisa 	void	 (*ic_init)(void);
17889182934Svisa 	void	*(*ic_establish)(int, int, int (*)(void *), void *,
17989182934Svisa 		    const char *);
18089182934Svisa 	void	*(*ic_establish_fdt_idx)(void *, int, int, int,
18189182934Svisa 		    int (*)(void *), void *, const char *);
18289182934Svisa 	void	 (*ic_disestablish)(void *);
1830dd6b0daSvisa 	void	 (*ic_intr_barrier)(void *);
18489182934Svisa 
18589182934Svisa #ifdef MULTIPROCESSOR
18689182934Svisa 	int	 (*ic_ipi_establish)(int (*)(void *), cpuid_t);
18789182934Svisa 	void	 (*ic_ipi_set)(cpuid_t);
18889182934Svisa 	void	 (*ic_ipi_clear)(cpuid_t);
18989182934Svisa #endif /* MULTIPROCESSOR */
19089182934Svisa 
19189182934Svisa 	int	   ic_node;
19289182934Svisa 	int	   ic_phandle;
19389182934Svisa 	LIST_ENTRY(intr_controller) ic_list;
19489182934Svisa };
19589182934Svisa 
196c6b2ceb4Ssyuu #ifdef MULTIPROCESSOR
197c6b2ceb4Ssyuu #define ENABLEIPI() updateimask(~CR_INT_1) /* enable IPI interrupt level */
198c6b2ceb4Ssyuu #endif
19989182934Svisa 
20061e15267Ssyuu void   *octeon_intr_establish(int, int, int (*)(void *),
20161e15267Ssyuu 	    void *, const char *);
20261e15267Ssyuu void	octeon_intr_disestablish(void *);
20361e15267Ssyuu void	octeon_intr_init(void);
20489182934Svisa void	octeon_intr_register(struct intr_controller *);
205c6b2ceb4Ssyuu 
206e6dd8ec3Svisa void	*octeon_intr_establish_fdt(int, int, int (*)(void *),
207e6dd8ec3Svisa 	    void *, const char *);
208e6dd8ec3Svisa void	*octeon_intr_establish_fdt_idx(int, int, int, int (*)(void *),
209e6dd8ec3Svisa 	    void *, const char *);
210e6dd8ec3Svisa void	 octeon_intr_disestablish_fdt(void *);
211e6dd8ec3Svisa 
212c6b2ceb4Ssyuu #endif /* _LOCORE */
213c6b2ceb4Ssyuu 
214c6b2ceb4Ssyuu #endif /* _MACHINE_INTR_H_ */
215