intr.h revision 1.5
11.5Stsutsui/*	$NetBSD: intr.h,v 1.5 2007/06/17 06:04:29 tsutsui Exp $	*/
21.1Such
31.1Such/*-
41.1Such * Copyright (c) 2001 The NetBSD Foundation, Inc.
51.1Such * All rights reserved.
61.1Such *
71.1Such * This code is derived from software contributed to The NetBSD Foundation
81.1Such * by Jason R. Thorpe, UCHIYAMA Yasushi.
91.1Such *
101.1Such * Redistribution and use in source and binary forms, with or without
111.1Such * modification, are permitted provided that the following conditions
121.1Such * are met:
131.1Such * 1. Redistributions of source code must retain the above copyright
141.1Such *    notice, this list of conditions and the following disclaimer.
151.1Such * 2. Redistributions in binary form must reproduce the above copyright
161.1Such *    notice, this list of conditions and the following disclaimer in the
171.1Such *    documentation and/or other materials provided with the distribution.
181.1Such * 3. All advertising materials mentioning features or use of this software
191.1Such *    must display the following acknowledgement:
201.1Such *	This product includes software developed by the NetBSD
211.1Such *	Foundation, Inc. and its contributors.
221.1Such * 4. Neither the name of The NetBSD Foundation nor the names of its
231.1Such *    contributors may be used to endorse or promote products derived
241.1Such *    from this software without specific prior written permission.
251.1Such *
261.1Such * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.1Such * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.1Such * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.1Such * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.1Such * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.1Such * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.1Such * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.1Such * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.1Such * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.1Such * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.1Such * POSSIBILITY OF SUCH DAMAGE.
371.1Such */
381.1Such
391.1Such#ifndef _PLAYSTATION2_INTR_H_
401.1Such#define _PLAYSTATION2_INTR_H_
411.1Such#ifdef _KERNEL
421.1Such
431.1Such#include <sys/device.h>
441.1Such#include <sys/lock.h>
451.1Such#include <sys/queue.h>
461.5Stsutsui#include <mips/locore.h>
471.1Such
481.1Such/* Interrupt sharing types. */
491.1Such#define	IST_NONE		0	/* none */
501.1Such#define	IST_PULSE		1	/* pulsed */
511.1Such#define	IST_EDGE		2	/* edge-triggered */
521.1Such#define	IST_LEVEL		3	/* level-triggered */
531.1Such
541.1Such/* Interrupt priority levels */
551.1Such#define	IPL_NONE		0	/* nothing */
561.1Such
571.1Such#define IPL_SOFT		1	/* generic */
581.1Such#define	IPL_SOFTCLOCK		2	/* timeouts */
591.1Such#define	IPL_SOFTNET		3	/* protocol stacks */
601.1Such#define IPL_SOFTSERIAL		4	/* serial */
611.1Such
621.1Such#define	IPL_BIO			5	/* block I/O */
631.1Such#define	IPL_NET			6	/* network */
641.1Such#define	IPL_TTY			7	/* terminal */
651.1Such#define	IPL_SERIAL		7	/* serial */
661.1Such#define	IPL_CLOCK		8	/* clock */
671.1Such#define	IPL_HIGH		8	/* everything */
681.1Such
691.1Such#define	_IPL_NSOFT	4
701.1Such#define	_IPL_N		9
711.1Such#define	IPL_SOFTNAMES {							\
721.1Such	"misc",								\
731.1Such	"clock",							\
741.1Such	"net",								\
751.1Such	"serial",							\
761.1Such}
771.1Such
781.1Such/*
791.1Such * Hardware interrupt masks
801.1Such */
811.1Suchextern u_int32_t __icu_mask[_IPL_N];
821.1Such
831.1Such#define	splbio()		splraise(__icu_mask[IPL_BIO])
841.1Such#define	splnet()		splraise(__icu_mask[IPL_NET])
851.1Such#define	spltty()		splraise(__icu_mask[IPL_TTY])
861.1Such#define	splserial()		splraise(__icu_mask[IPL_SERIAL])
871.1Such#define	splclock()		splraise(__icu_mask[IPL_CLOCK])
881.1Such
891.1Such#define	splstatclock()		splclock()
901.1Such#define splvm()			spltty()
911.1Such
921.1Such/*
931.1Such * Software interrupt masks
941.1Such */
951.1Such#define splsoft()		splraise(__icu_mask[IPL_SOFT])
961.1Such#define	splsoftclock()		splraise(__icu_mask[IPL_SOFTCLOCK])
971.1Such#define	splsoftnet()		splraise(__icu_mask[IPL_SOFTNET])
981.1Such#define	splsoftserial()		splraise(__icu_mask[IPL_SOFTSERIAL])
991.1Such
1001.1Suchvoid	spllowersofthigh(void);
1011.1Such
1021.1Such/*
1031.1Such * Miscellaneous
1041.1Such */
1051.1Such#define	splx(s)			splset(s)
1061.1Such#define	splhigh()		splraise(__icu_mask[IPL_HIGH])
1071.1Such#define	splsched()		splhigh()
1081.1Such#define	spllock()		splhigh()
1091.1Such
1101.1Such/*
1111.1Such * software simulated interrupt
1121.1Such */
1131.1Suchstruct playstation2_soft_intrhand {
1141.1Such	TAILQ_ENTRY(playstation2_soft_intrhand) sih_q;
1151.1Such	struct playstation2_soft_intr *sih_intrhead;
1161.1Such	void	(*sih_fn)(void *);
1171.1Such	void	*sih_arg;
1181.1Such	int	sih_pending;
1191.1Such};
1201.1Such
1211.1Suchstruct playstation2_soft_intr {
1221.1Such	TAILQ_HEAD(, playstation2_soft_intrhand) softintr_q;
1231.1Such	struct evcnt softintr_evcnt;
1241.1Such	struct simplelock softintr_slock;
1251.1Such	unsigned long softintr_ipl;
1261.1Such};
1271.1Such
1281.1Such#define	softintr_schedule(arg)						\
1291.1Suchdo {									\
1301.1Such	struct playstation2_soft_intrhand *__sih = (arg);		\
1311.1Such	struct playstation2_soft_intr *__si = __sih->sih_intrhead;	\
1321.1Such	int __s;							\
1331.1Such									\
1341.1Such	__s = _intr_suspend();						\
1351.1Such	simple_lock(&__si->softintr_slock);				\
1361.1Such	if (__sih->sih_pending == 0) {					\
1371.1Such		TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q);	\
1381.1Such		__sih->sih_pending = 1;					\
1391.1Such		setsoft(__si->softintr_ipl);				\
1401.1Such	}								\
1411.1Such	simple_unlock(&__si->softintr_slock);				\
1421.1Such	_intr_resume(__s);						\
1431.1Such} while (0)
1441.1Such
1451.1Suchvoid *softintr_establish(int, void (*)(void *), void *);
1461.1Suchvoid softintr_disestablish(void *);
1471.1Suchvoid setsoft(int);
1481.1Such
1491.1Such/* XXX For legacy software interrupts. */
1501.1Suchextern struct playstation2_soft_intrhand *softnet_intrhand;
1511.1Such
1521.1Such#define	setsoftnet()	softintr_schedule(softnet_intrhand)
1531.1Such
1541.5Stsutsuiint splraise(int);
1551.5Stsutsuivoid splset(int);
1561.5Stsutsuivoid spl0(void);
1571.3Such
1581.3Such/* R5900 EI/DI instruction */
1591.5Stsutsuiint _intr_suspend(void);
1601.5Stsutsuivoid _intr_resume(int);
1611.1Such
1621.1Such#endif /* _KERNEL */
1631.1Such#endif /* _PLAYSTATION2_INTR_H_ */
164