xref: /openbsd/sys/arch/loongson/include/intr.h (revision 891d7ab6)
1 /*	$OpenBSD: intr.h,v 1.3 2010/12/21 14:56:24 claudio 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  * An exception to this rule is the clock interrupt. Clock interrupts
43  * are always allowed to happen, but will (of course!) not be serviced
44  * if logically masked.  The reason for this is that clocks usually sit on
45  * INT5 and cannot be easily masked if external hardware masking is used.
46  */
47 
48 /* Interrupt priority `levels'; not mutually exclusive. */
49 #define	IPL_NONE	0	/* nothing */
50 #define	IPL_SOFTINT	1	/* soft interrupts */
51 #define	IPL_BIO		2	/* block I/O */
52 #define IPL_AUDIO	IPL_BIO
53 #define	IPL_NET		3	/* network */
54 #define	IPL_TTY		4	/* terminal */
55 #define	IPL_VM		5	/* memory allocation */
56 #define	IPL_CLOCK	6	/* clock */
57 #define	IPL_SCHED	7	/* everything */
58 #define	IPL_HIGH	7	/* everything */
59 #define	NIPLS		8	/* Number of levels */
60 
61 /* Interrupt sharing types. */
62 #define	IST_NONE	0	/* none */
63 #define	IST_PULSE	1	/* pulsed */
64 #define	IST_EDGE	2	/* edge-triggered */
65 #define	IST_LEVEL	3	/* level-triggered */
66 
67 #define	SINTBIT(q)	(q)
68 #define	SINTMASK(q)	(1 << SINTBIT(q))
69 
70 /* Soft interrupt masks. */
71 
72 #define	IPL_SOFT	0
73 #define	IPL_SOFTCLOCK	1
74 #define	IPL_SOFTNET	2
75 #define	IPL_SOFTTTY	3
76 
77 #define	SI_SOFT		0	/* for IPL_SOFT */
78 #define	SI_SOFTCLOCK	1	/* for IPL_SOFTCLOCK */
79 #define	SI_SOFTNET	2	/* for IPL_SOFTNET */
80 #define	SI_SOFTTTY	3	/* for IPL_SOFTTTY */
81 
82 #define	SI_NQUEUES	4
83 
84 #ifndef _LOCORE
85 
86 #include <machine/mutex.h>
87 #include <sys/queue.h>
88 
89 struct soft_intrhand {
90 	TAILQ_ENTRY(soft_intrhand) sih_list;
91 	void	(*sih_func)(void *);
92 	void	*sih_arg;
93 	struct soft_intrq *sih_siq;
94 	int	sih_pending;
95 };
96 
97 struct soft_intrq {
98 	TAILQ_HEAD(, soft_intrhand) siq_list;
99 	int siq_si;
100 	struct mutex siq_mtx;
101 };
102 
103 void	 softintr_disestablish(void *);
104 void	 softintr_dispatch(int);
105 void	*softintr_establish(int, void (*)(void *), void *);
106 void	 softintr_init(void);
107 void	 softintr_schedule(void *);
108 
109 #define	splsoft()	splraise(IPL_SOFTINT)
110 #define splbio()	splraise(IPL_BIO)
111 #define splnet()	splraise(IPL_NET)
112 #define spltty()	splraise(IPL_TTY)
113 #define splaudio()	splraise(IPL_AUDIO)
114 #define splclock()	splraise(IPL_CLOCK)
115 #define splvm()		splraise(IPL_VM)
116 #define splhigh()	splraise(IPL_HIGH)
117 
118 #define splsoftclock()	splsoft()
119 #define splsoftnet()	splsoft()
120 #define splstatclock()	splhigh()
121 
122 #define splsched()	splhigh()
123 #define spllock()	splhigh()
124 #define spl0()		spllower(0)
125 
126 void	splinit(void);
127 
128 #define	splassert(X)
129 #define	splsoftassert(X)
130 
131 /* Inlines */
132 static __inline void register_splx_handler(void (*)(int));
133 
134 typedef void (int_f)(int);
135 extern int_f *splx_hand;
136 
137 static __inline void
138 register_splx_handler(void(*handler)(int))
139 {
140 	splx_hand = handler;
141 }
142 
143 int	splraise(int);
144 void	splx(int);
145 int	spllower(int);
146 
147 /*
148  * Interrupt control struct used by interrupt dispatchers
149  * to hold interrupt handler info.
150  */
151 
152 #include <sys/evcount.h>
153 
154 struct intrhand {
155 	struct	intrhand	*ih_next;
156 	int			(*ih_fun)(void *);
157 	void			*ih_arg;
158 	int			 ih_level;
159 	int			 ih_irq;
160 	struct evcount		 ih_count;
161 };
162 
163 /*
164  * Low level interrupt dispatcher registration data.
165  */
166 
167 /* Schedule priorities for base interrupts (CPU) */
168 #define	INTPRI_CLOCK	0
169 /* other values are system-specific */
170 
171 #define NLOWINT	4		/* Number of low level registrations possible */
172 
173 extern uint32_t idle_mask;
174 
175 struct trap_frame;
176 void	set_intr(int, uint32_t, uint32_t(*)(uint32_t, struct trap_frame *));
177 
178 uint32_t updateimask(uint32_t);
179 void	dosoftint(void);
180 
181 #endif /* _LOCORE */
182 
183 #endif /* _MACHINE_INTR_H_ */
184