intr.h revision 1.5
1/*	$NetBSD: intr.h,v 1.5 2007/06/17 06:04:29 tsutsui Exp $	*/
2
3/*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe, UCHIYAMA Yasushi.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *	This product includes software developed by the NetBSD
21 *	Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 *    contributors may be used to endorse or promote products derived
24 *    from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#ifndef _PLAYSTATION2_INTR_H_
40#define _PLAYSTATION2_INTR_H_
41#ifdef _KERNEL
42
43#include <sys/device.h>
44#include <sys/lock.h>
45#include <sys/queue.h>
46#include <mips/locore.h>
47
48/* Interrupt sharing types. */
49#define	IST_NONE		0	/* none */
50#define	IST_PULSE		1	/* pulsed */
51#define	IST_EDGE		2	/* edge-triggered */
52#define	IST_LEVEL		3	/* level-triggered */
53
54/* Interrupt priority levels */
55#define	IPL_NONE		0	/* nothing */
56
57#define IPL_SOFT		1	/* generic */
58#define	IPL_SOFTCLOCK		2	/* timeouts */
59#define	IPL_SOFTNET		3	/* protocol stacks */
60#define IPL_SOFTSERIAL		4	/* serial */
61
62#define	IPL_BIO			5	/* block I/O */
63#define	IPL_NET			6	/* network */
64#define	IPL_TTY			7	/* terminal */
65#define	IPL_SERIAL		7	/* serial */
66#define	IPL_CLOCK		8	/* clock */
67#define	IPL_HIGH		8	/* everything */
68
69#define	_IPL_NSOFT	4
70#define	_IPL_N		9
71#define	IPL_SOFTNAMES {							\
72	"misc",								\
73	"clock",							\
74	"net",								\
75	"serial",							\
76}
77
78/*
79 * Hardware interrupt masks
80 */
81extern u_int32_t __icu_mask[_IPL_N];
82
83#define	splbio()		splraise(__icu_mask[IPL_BIO])
84#define	splnet()		splraise(__icu_mask[IPL_NET])
85#define	spltty()		splraise(__icu_mask[IPL_TTY])
86#define	splserial()		splraise(__icu_mask[IPL_SERIAL])
87#define	splclock()		splraise(__icu_mask[IPL_CLOCK])
88
89#define	splstatclock()		splclock()
90#define splvm()			spltty()
91
92/*
93 * Software interrupt masks
94 */
95#define splsoft()		splraise(__icu_mask[IPL_SOFT])
96#define	splsoftclock()		splraise(__icu_mask[IPL_SOFTCLOCK])
97#define	splsoftnet()		splraise(__icu_mask[IPL_SOFTNET])
98#define	splsoftserial()		splraise(__icu_mask[IPL_SOFTSERIAL])
99
100void	spllowersofthigh(void);
101
102/*
103 * Miscellaneous
104 */
105#define	splx(s)			splset(s)
106#define	splhigh()		splraise(__icu_mask[IPL_HIGH])
107#define	splsched()		splhigh()
108#define	spllock()		splhigh()
109
110/*
111 * software simulated interrupt
112 */
113struct playstation2_soft_intrhand {
114	TAILQ_ENTRY(playstation2_soft_intrhand) sih_q;
115	struct playstation2_soft_intr *sih_intrhead;
116	void	(*sih_fn)(void *);
117	void	*sih_arg;
118	int	sih_pending;
119};
120
121struct playstation2_soft_intr {
122	TAILQ_HEAD(, playstation2_soft_intrhand) softintr_q;
123	struct evcnt softintr_evcnt;
124	struct simplelock softintr_slock;
125	unsigned long softintr_ipl;
126};
127
128#define	softintr_schedule(arg)						\
129do {									\
130	struct playstation2_soft_intrhand *__sih = (arg);		\
131	struct playstation2_soft_intr *__si = __sih->sih_intrhead;	\
132	int __s;							\
133									\
134	__s = _intr_suspend();						\
135	simple_lock(&__si->softintr_slock);				\
136	if (__sih->sih_pending == 0) {					\
137		TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q);	\
138		__sih->sih_pending = 1;					\
139		setsoft(__si->softintr_ipl);				\
140	}								\
141	simple_unlock(&__si->softintr_slock);				\
142	_intr_resume(__s);						\
143} while (0)
144
145void *softintr_establish(int, void (*)(void *), void *);
146void softintr_disestablish(void *);
147void setsoft(int);
148
149/* XXX For legacy software interrupts. */
150extern struct playstation2_soft_intrhand *softnet_intrhand;
151
152#define	setsoftnet()	softintr_schedule(softnet_intrhand)
153
154int splraise(int);
155void splset(int);
156void spl0(void);
157
158/* R5900 EI/DI instruction */
159int _intr_suspend(void);
160void _intr_resume(int);
161
162#endif /* _KERNEL */
163#endif /* _PLAYSTATION2_INTR_H_ */
164