intr.h revision 1.17
1/*	$NetBSD: intr.h,v 1.17 2007/03/04 09:59:10 tsutsui Exp $	*/
2
3/*
4 *
5 * Copyright (c) 1998 NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Minoura Makoto and Jason R. Thorpe.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 *    must display the following acknowledgement:
21 *      This product includes software developed by The NetBSD Foundation
22 *	Inc. and its contributers.
23 * 4. The name of the author may not be used to endorse or promote products
24 *    derived from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
27 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef _NEWS68K_INTR_H_
39#define	_NEWS68K_INTR_H_
40
41#include <sys/device.h>
42#include <sys/queue.h>
43#include <machine/psl.h>
44#include <m68k/asm_single.h>
45
46#define	IPL_NONE	0
47#define	IPL_SOFTCLOCK	1
48#define	IPL_SOFTNET	2
49#define	IPL_SOFTSERIAL	3
50#define	IPL_SOFT	4
51#define	IPL_BIO		5
52#define	IPL_NET		6
53#define	IPL_TTY		7
54#define	IPL_VM		8
55#define	IPL_SERIAL	9
56#define	IPL_CLOCK	10
57#define	IPL_STATCLOCK	IPL_CLOCK
58#define	IPL_HIGH	11
59#define	IPL_SCHED	IPL_HIGH
60#define	IPL_LOCK	IPL_HIGH
61#define	NIPL		12
62
63#define	SI_SOFTSERIAL	0
64#define	SI_SOFTNET	1
65#define	SI_SOFTCLOCK	2
66#define	SI_SOFT		3
67
68#define	SI_NQUEUES	4
69
70#define	SI_QUEUENAMES {							\
71	"serial",							\
72	"net",								\
73	"clock",							\
74	"misc",								\
75}
76
77typedef int ipl_t;
78typedef struct {
79	ipl_t _psl;
80} ipl_cookie_t;
81
82ipl_cookie_t makeiplcookie(ipl_t);
83
84static inline int
85splraiseipl(ipl_cookie_t icookie)
86{
87
88	return _splraise(icookie._psl);
89}
90
91static __inline void
92splx(int sr)
93{
94
95	__asm volatile("movw %0,%%sr" : : "di" (sr));
96}
97
98/*
99 * news68k can handle software interrupts by its own hardware
100 * so has no need to check for any simulated interrupts, etc.
101 */
102#define	spl0()		_spl0()
103
104#define	splsoft()	splraise2()
105#define	splsoftclock()	splsoft()
106#define	splsoftnet()	splsoft()
107#define	splsoftserial()	splsoft()
108#define	splbio()	splraise4()
109#define	splnet()	splraise4()
110#define	spltty()	splraise5()
111#define	splvm()		splraise5()
112#define	splserial()	splraise5()
113#define	splclock()	splraise6()
114#define	splstatclock()	splclock()
115#define	splhigh()	spl7()
116#define	splsched()	spl7()
117#define	spllock()	spl7()
118
119/*
120 * simulated software interrupt register
121 */
122#define SOFTINTR_IPL	2
123extern volatile uint8_t *ctrl_int2;
124
125#define	setsoft(x)		(x = 0)
126#define	softintr_assert()	(*ctrl_int2 = 0xff)
127#define	softintr_clear()	(*ctrl_int2 = 0)
128
129struct news68k_soft_intrhand {
130	LIST_ENTRY(news68k_soft_intrhand) sih_q;
131	struct news68k_soft_intr *sih_intrhead;
132	void (*sih_fn)(void *);
133	void *sih_arg;
134	volatile int sih_pending;
135};
136
137struct news68k_soft_intr {
138	LIST_HEAD(, news68k_soft_intrhand) nsi_q;
139	struct evcnt nsi_evcnt;
140	volatile unsigned char nsi_ssir;
141};
142
143void *softintr_establish(int, void (*)(void *), void *);
144void softintr_disestablish(void *);
145void softintr_init(void);
146void softintr_dispatch(void);
147
148#define	softintr_schedule(arg)					\
149	do {							\
150		struct news68k_soft_intrhand *__sih = (arg);	\
151		__sih->sih_pending = 1;				\
152		setsoft(__sih->sih_intrhead->nsi_ssir);		\
153		softintr_assert();				\
154	} while (/*CONSTCOND*/ 0)
155
156/* XXX For legacy software interrupts */
157extern struct news68k_soft_intrhand *softnet_intrhand;
158
159#define	setsoftnet()	softintr_schedule(softnet_intrhand)
160
161#endif /* _NEWS68K_INTR_H_ */
162