intr.h revision 1.15
11.15Stsutsui/*	$NetBSD: intr.h,v 1.15 2007/02/10 13:08:30 tsutsui Exp $	*/
21.1Stsutsui
31.1Stsutsui/*
41.1Stsutsui *
51.1Stsutsui * Copyright (c) 1998 NetBSD Foundation, Inc.
61.1Stsutsui * All rights reserved.
71.1Stsutsui *
81.1Stsutsui * This code is derived from software contributed to The NetBSD Foundation
91.1Stsutsui * by Minoura Makoto and Jason R. Thorpe.
101.1Stsutsui *
111.1Stsutsui * Redistribution and use in source and binary forms, with or without
121.1Stsutsui * modification, are permitted provided that the following conditions
131.1Stsutsui * are met:
141.1Stsutsui * 1. Redistributions of source code must retain the above copyright
151.1Stsutsui *    notice, this list of conditions and the following disclaimer.
161.1Stsutsui * 2. Redistributions in binary form must reproduce the above copyright
171.1Stsutsui *    notice, this list of conditions and the following disclaimer in the
181.1Stsutsui *    documentation and/or other materials provided with the distribution.
191.1Stsutsui * 3. All advertising materials mentioning features or use of this software
201.1Stsutsui *    must display the following acknowledgement:
211.1Stsutsui *      This product includes software developed by The NetBSD Foundation
221.1Stsutsui *	Inc. and its contributers.
231.1Stsutsui * 4. The name of the author may not be used to endorse or promote products
241.1Stsutsui *    derived from this software without specific prior written permission.
251.1Stsutsui *
261.1Stsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
271.1Stsutsui * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
281.1Stsutsui * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
291.1Stsutsui * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
301.1Stsutsui * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
311.1Stsutsui * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
321.1Stsutsui * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
331.1Stsutsui * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
341.1Stsutsui * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
351.1Stsutsui * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
361.1Stsutsui */
371.1Stsutsui
381.1Stsutsui#ifndef _NEWS68K_INTR_H_
391.1Stsutsui#define	_NEWS68K_INTR_H_
401.1Stsutsui
411.14Stsutsui#include <sys/device.h>
421.14Stsutsui#include <sys/queue.h>
431.1Stsutsui#include <machine/psl.h>
441.5Stsutsui#include <m68k/asm_single.h>
451.1Stsutsui
461.1Stsutsui#ifdef _KERNEL
471.13Syamt#define	IPL_NONE	0
481.14Stsutsui#define	IPL_SOFTCLOCK	1
491.14Stsutsui#define	IPL_SOFTNET	2
501.14Stsutsui#define	IPL_SOFTSERIAL	3
511.14Stsutsui#define	IPL_SOFT	4
521.14Stsutsui#define	IPL_BIO		5
531.14Stsutsui#define	IPL_NET		6
541.14Stsutsui#define	IPL_TTY		7
551.14Stsutsui#define	IPL_VM		8
561.14Stsutsui#define	IPL_SERIAL	9
571.14Stsutsui#define	IPL_CLOCK	10
581.13Syamt#define	IPL_STATCLOCK	IPL_CLOCK
591.14Stsutsui#define	IPL_HIGH	11
601.14Stsutsui#define	IPL_SCHED	IPL_HIGH
611.14Stsutsui#define	IPL_LOCK	IPL_HIGH
621.14Stsutsui#define	NIPL		12
631.14Stsutsui
641.14Stsutsui#define	SI_SOFTSERIAL	0
651.14Stsutsui#define	SI_SOFTNET	1
661.14Stsutsui#define	SI_SOFTCLOCK	2
671.14Stsutsui#define	SI_SOFT		3
681.14Stsutsui
691.14Stsutsui#define	SI_NQUEUES	4
701.14Stsutsui
711.14Stsutsui#define	SI_QUEUENAMES {							\
721.14Stsutsui	"serial",							\
731.14Stsutsui	"net",								\
741.14Stsutsui	"clock",							\
751.14Stsutsui	"misc",								\
761.14Stsutsui}
771.13Syamt
781.13Syamttypedef int ipl_t;
791.13Syamttypedef struct {
801.14Stsutsui	ipl_t _psl;
811.13Syamt} ipl_cookie_t;
821.13Syamt
831.14Stsutsuiipl_cookie_t makeiplcookie(ipl_t);
841.13Syamt
851.13Syamtstatic inline int
861.13Syamtsplraiseipl(ipl_cookie_t icookie)
871.13Syamt{
881.13Syamt
891.14Stsutsui	return _splraise(icookie._psl);
901.13Syamt}
911.13Syamt
921.12Sperrystatic __inline void
931.9Stsutsuisplx(int sr)
941.9Stsutsui{
951.9Stsutsui
961.11Sperry	__asm volatile("movw %0,%%sr" : : "di" (sr));
971.9Stsutsui}
981.1Stsutsui
991.1Stsutsui/*
1001.14Stsutsui * news68k can handle software interrupts by its own hardware
1011.14Stsutsui * so has no need to check for any simulated interrupts, etc.
1021.14Stsutsui */
1031.14Stsutsui#define	spl0()		_spl0()
1041.14Stsutsui
1051.14Stsutsui#define	spllowersoftclock()	spl2()
1061.14Stsutsui#define	splsoft()	splraise2()
1071.14Stsutsui#define	splsoftclock()	splsoft()
1081.14Stsutsui#define	splsoftnet()	splsoft()
1091.14Stsutsui#define	splsoftserial()	splsoft()
1101.14Stsutsui#define	splbio()	splraise4()
1111.14Stsutsui#define	splnet()	splraise4()
1121.14Stsutsui#define	spltty()	splraise5()
1131.14Stsutsui#define	splvm()		splraise5()
1141.14Stsutsui#define	splserial()	splraise5()
1151.14Stsutsui#define	splclock()	splraise6()
1161.14Stsutsui#define	splstatclock()	splclock()
1171.14Stsutsui#define	splhigh()	spl7()
1181.14Stsutsui#define	splsched()	spl7()
1191.14Stsutsui#define	spllock()	spl7()
1201.14Stsutsui
1211.14Stsutsui/*
1221.1Stsutsui * simulated software interrupt register
1231.1Stsutsui */
1241.14Stsutsui#define SOFTINTR_IPL	2
1251.15Stsutsuiextern volatile uint8_t *ctrl_int2;
1261.1Stsutsui
1271.15Stsutsui#define	setsoft(x)		(x = 0)
1281.15Stsutsui#define	softintr_assert()	(*ctrl_int2 = 0xff)
1291.15Stsutsui#define	softintr_clear()	(*ctrl_int2 = 0)
1301.14Stsutsui
1311.14Stsutsuistruct news68k_soft_intrhand {
1321.14Stsutsui	LIST_ENTRY(news68k_soft_intrhand) sih_q;
1331.14Stsutsui	struct news68k_soft_intr *sih_intrhead;
1341.14Stsutsui	void (*sih_fn)(void *);
1351.14Stsutsui	void *sih_arg;
1361.14Stsutsui	volatile int sih_pending;
1371.14Stsutsui};
1381.14Stsutsui
1391.14Stsutsuistruct news68k_soft_intr {
1401.14Stsutsui	LIST_HEAD(, news68k_soft_intrhand) nsi_q;
1411.14Stsutsui	struct evcnt nsi_evcnt;
1421.14Stsutsui	volatile unsigned char nsi_ssir;
1431.14Stsutsui};
1441.14Stsutsui
1451.14Stsutsuivoid *softintr_establish(int, void (*)(void *), void *);
1461.14Stsutsuivoid softintr_disestablish(void *);
1471.14Stsutsuivoid softintr_init(void);
1481.14Stsutsuivoid softintr_dispatch(void);
1491.14Stsutsui
1501.14Stsutsui#define	softintr_schedule(arg)					\
1511.14Stsutsui	do {							\
1521.14Stsutsui		struct news68k_soft_intrhand *__sih = (arg);	\
1531.14Stsutsui		__sih->sih_pending = 1;				\
1541.14Stsutsui		setsoft(__sih->sih_intrhead->nsi_ssir);		\
1551.14Stsutsui		softintr_assert();				\
1561.14Stsutsui	} while (/*CONSTCOND*/ 0)
1571.14Stsutsui
1581.14Stsutsui/* XXX For legacy software interrupts */
1591.14Stsutsuiextern struct news68k_soft_intrhand *softnet_intrhand;
1601.14Stsutsui
1611.14Stsutsui#define	setsoftnet()	softintr_schedule(softnet_intrhand)
1621.1Stsutsui
1631.1Stsutsui#endif /* _KERNEL */
1641.1Stsutsui
1651.1Stsutsui#endif /* _NEWS68K_INTR_H_ */
166