xref: /openbsd-src/sys/arch/powerpc/include/intr.h (revision 43003dfe3ad45d1698bed8a37f2b0f5b14f20d4f)
1 /*	$OpenBSD: intr.h,v 1.43 2009/10/01 20:19:19 kettenis Exp $ */
2 
3 /*
4  * Copyright (c) 1997 Per Fogelstrom, Opsycon AB and RTMX Inc, USA.
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  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *	This product includes software developed under OpenBSD by
17  *	Per Fogelstrom, Opsycon AB, Sweden for RTMX Inc, North Carolina USA.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  */
34 
35 #ifndef _POWERPC_INTR_H_
36 #define _POWERPC_INTR_H_
37 
38 #define	IPL_NONE	0
39 #define	IPL_BIO		1
40 #define	IPL_AUDIO	IPL_BIO /* XXX - was defined this val in audio_if.h */
41 #define	IPL_NET		2
42 #define	IPL_TTY		3
43 #define	IPL_VM		4
44 #define	IPL_CLOCK	5
45 #define	IPL_HIGH	6
46 #define	IPL_NUM		7
47 
48 #define	IST_NONE	0
49 #define	IST_PULSE	1
50 #define	IST_EDGE	2
51 #define	IST_LEVEL	3
52 
53 #if defined(_KERNEL) && !defined(_LOCORE)
54 
55 #include <sys/evcount.h>
56 #include <machine/atomic.h>
57 
58 #define PPC_NIRQ	66
59 #define PPC_CLK_IRQ	64
60 #define PPC_STAT_IRQ	65
61 
62 int	splraise(int);
63 int	spllower(int);
64 void	splx(int);
65 
66 
67 void do_pending_int(void);
68 
69 extern int imask[IPL_NUM];
70 
71 /* SPL asserts */
72 #define	splassert(wantipl)	/* nothing */
73 #define	splsoftassert(wantipl)	/* nothing */
74 
75 #define SINTBIT(q)	(31 - (q))
76 #define SINTMASK(q)	(1 << SINTBIT(q))
77 
78 #define	SPL_CLOCKMASK	SINTMASK(SI_NQUEUES)
79 
80 /* Soft interrupt masks. */
81 
82 #define	IPL_SOFTCLOCK	0
83 #define	IPL_SOFTNET	1
84 #define	IPL_SOFTTTY	2
85 
86 #define	SI_SOFTCLOCK	0	/* for IPL_SOFTCLOCK */
87 #define	SI_SOFTNET	1	/* for IPL_SOFTNET */
88 #define	SI_SOFTTTY	2	/* for IPL_SOFTTY */
89 
90 #define	SINT_ALLMASK	(SINTMASK(SI_SOFTCLOCK) | \
91 			 SINTMASK(SI_SOFTNET) | SINTMASK(SI_SOFTTTY))
92 #define	SI_NQUEUES	3
93 
94 #include <machine/mutex.h>
95 #include <sys/queue.h>
96 
97 struct soft_intrhand {
98 	TAILQ_ENTRY(soft_intrhand) sih_list;
99 	void	(*sih_func)(void *);
100 	void	*sih_arg;
101 	struct soft_intrq *sih_siq;
102 	int	sih_pending;
103 };
104 
105 struct soft_intrq {
106 	TAILQ_HEAD(, soft_intrhand) siq_list;
107 	int siq_si;
108 	struct mutex siq_mtx;
109 };
110 
111 void	 softintr_disestablish(void *);
112 void	 softintr_dispatch(int);
113 void	*softintr_establish(int, void (*)(void *), void *);
114 void	 softintr_init(void);
115 void	 softintr_schedule(void *);
116 
117 /* XXX For legacy software interrupts. */
118 extern struct soft_intrhand *softnet_intrhand;
119 
120 #define	setsoftnet()	softintr_schedule(softnet_intrhand)
121 
122 #define	SINT_CLOCK	SINTMASK(SI_SOFTCLOCK)
123 #define	SINT_NET	SINTMASK(SI_SOFTNET)
124 #define	SINT_TTY	SINTMASK(SI_SOFTTTY)
125 
126 #define splbio()	splraise(imask[IPL_BIO])
127 #define splnet()	splraise(imask[IPL_NET])
128 #define spltty()	splraise(imask[IPL_TTY])
129 #define splaudio()	splraise(imask[IPL_AUDIO])
130 #define splclock()	splraise(imask[IPL_CLOCK])
131 #define splvm()		splraise(imask[IPL_VM])
132 #define splsched()	splhigh()
133 #define spllock()	splhigh()
134 #define splstatclock()	splhigh()
135 #define	splsoftclock()	splraise(SINT_CLOCK)
136 #define	splsoftnet()	splraise(SINT_NET|SINT_CLOCK)
137 #define	splsofttty()	splraise(SINT_TTY|SINT_NET|SINT_CLOCK)
138 
139 #define	splhigh()	splraise(0xffffffff)
140 #define	spl0()		spllower(0)
141 
142 /*
143  *	Interrupt control struct used to control the ICU setup.
144  */
145 
146 struct intrhand {
147 	struct intrhand	*ih_next;
148 	int		(*ih_fun)(void *);
149 	void		*ih_arg;
150 	struct evcount	ih_count;
151 	int		ih_level;
152 	int		ih_irq;
153 	const char	*ih_what;
154 };
155 extern int ppc_configed_intr_cnt;
156 #define MAX_PRECONF_INTR 16
157 extern struct intrhand ppc_configed_intr[MAX_PRECONF_INTR];
158 void softnet(int isr);
159 
160 #define PPC_IPI_NOP		0
161 #define PPC_IPI_DDB		1
162 
163 void ppc_send_ipi(struct cpu_info *, int);
164 
165 #endif /* _LOCORE */
166 #endif /* _POWERPC_INTR_H_ */
167