xref: /openbsd/sys/arch/powerpc/include/intr.h (revision 8932bfb7)
1 /*	$OpenBSD: intr.h,v 1.46 2011/01/08 18:10:20 deraadt 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_SCHED	6
46 #define	IPL_HIGH	6
47 #define	IPL_NUM		7
48 
49 #define	IST_NONE	0
50 #define	IST_PULSE	1
51 #define	IST_EDGE	2
52 #define	IST_LEVEL	3
53 
54 #if defined(_KERNEL) && !defined(_LOCORE)
55 
56 #include <sys/evcount.h>
57 #include <machine/atomic.h>
58 
59 #define PPC_NIRQ	66
60 #define PPC_CLK_IRQ	64
61 #define PPC_STAT_IRQ	65
62 
63 int	splraise(int);
64 int	spllower(int);
65 void	splx(int);
66 
67 
68 void do_pending_int(void);
69 
70 extern int cpu_imask[IPL_NUM];
71 
72 /* SPL asserts */
73 #define	splassert(wantipl)	/* nothing */
74 #define	splsoftassert(wantipl)	/* nothing */
75 
76 #define SINTBIT(q)	(31 - (q))
77 #define SINTMASK(q)	(1 << SINTBIT(q))
78 
79 #define	SPL_CLOCKMASK	SINTMASK(SI_NQUEUES)
80 
81 /* Soft interrupt masks. */
82 
83 #define	IPL_SOFTCLOCK	0
84 #define	IPL_SOFTNET	1
85 #define	IPL_SOFTTTY	2
86 
87 #define	SI_SOFTCLOCK	0	/* for IPL_SOFTCLOCK */
88 #define	SI_SOFTNET	1	/* for IPL_SOFTNET */
89 #define	SI_SOFTTTY	2	/* for IPL_SOFTTY */
90 
91 #define	SINT_ALLMASK	(SINTMASK(SI_SOFTCLOCK) | \
92 			 SINTMASK(SI_SOFTNET) | SINTMASK(SI_SOFTTTY))
93 #define	SI_NQUEUES	3
94 
95 #include <machine/mutex.h>
96 #include <sys/queue.h>
97 
98 struct soft_intrhand {
99 	TAILQ_ENTRY(soft_intrhand) sih_list;
100 	void	(*sih_func)(void *);
101 	void	*sih_arg;
102 	struct soft_intrq *sih_siq;
103 	int	sih_pending;
104 };
105 
106 struct soft_intrq {
107 	TAILQ_HEAD(, soft_intrhand) siq_list;
108 	int siq_si;
109 	struct mutex siq_mtx;
110 };
111 
112 void	 softintr_disestablish(void *);
113 void	 softintr_dispatch(int);
114 void	*softintr_establish(int, void (*)(void *), void *);
115 void	 softintr_init(void);
116 void	 softintr_schedule(void *);
117 
118 #define	SINT_CLOCK	SINTMASK(SI_SOFTCLOCK)
119 #define	SINT_NET	SINTMASK(SI_SOFTNET)
120 #define	SINT_TTY	SINTMASK(SI_SOFTTTY)
121 
122 #define splbio()	splraise(cpu_imask[IPL_BIO])
123 #define splnet()	splraise(cpu_imask[IPL_NET])
124 #define spltty()	splraise(cpu_imask[IPL_TTY])
125 #define splaudio()	splraise(cpu_imask[IPL_AUDIO])
126 #define splclock()	splraise(cpu_imask[IPL_CLOCK])
127 #define splvm()		splraise(cpu_imask[IPL_VM])
128 #define splsched()	splhigh()
129 #define spllock()	splhigh()
130 #define splstatclock()	splhigh()
131 #define	splsoftclock()	splraise(SINT_CLOCK)
132 #define	splsoftnet()	splraise(SINT_NET|SINT_CLOCK)
133 #define	splsofttty()	splraise(SINT_TTY|SINT_NET|SINT_CLOCK)
134 
135 #define	splhigh()	splraise(0xffffffff)
136 #define	spl0()		spllower(0)
137 
138 /*
139  *	Interrupt control struct used to control the ICU setup.
140  */
141 
142 struct intrhand {
143 	struct intrhand	*ih_next;
144 	int		(*ih_fun)(void *);
145 	void		*ih_arg;
146 	struct evcount	ih_count;
147 	int		ih_level;
148 	int		ih_irq;
149 	const char	*ih_what;
150 };
151 extern int ppc_configed_intr_cnt;
152 #define MAX_PRECONF_INTR 16
153 extern struct intrhand ppc_configed_intr[MAX_PRECONF_INTR];
154 void softnet(int isr);
155 
156 #define PPC_IPI_NOP		0
157 #define PPC_IPI_DDB		1
158 
159 void ppc_send_ipi(struct cpu_info *, int);
160 
161 #endif /* _LOCORE */
162 #endif /* _POWERPC_INTR_H_ */
163