intr.h revision 1.4
11.4Ssakamoto/*	$NetBSD: intr.h,v 1.4 1998/01/12 04:57:13 sakamoto Exp $	*/
21.2Ssakamoto/*	$OpenBSD: intr.h,v 1.1 1997/10/13 10:53:45 pefo Exp $ */
31.1Ssakamoto
41.1Ssakamoto/*
51.1Ssakamoto * Copyright (c) 1996, 1997 Charles M. Hannum.  All rights reserved.
61.1Ssakamoto *
71.1Ssakamoto * Redistribution and use in source and binary forms, with or without
81.1Ssakamoto * modification, are permitted provided that the following conditions
91.1Ssakamoto * are met:
101.1Ssakamoto * 1. Redistributions of source code must retain the above copyright
111.1Ssakamoto *    notice, this list of conditions and the following disclaimer.
121.1Ssakamoto * 2. Redistributions in binary form must reproduce the above copyright
131.1Ssakamoto *    notice, this list of conditions and the following disclaimer in the
141.1Ssakamoto *    documentation and/or other materials provided with the distribution.
151.1Ssakamoto * 3. All advertising materials mentioning features or use of this software
161.1Ssakamoto *    must display the following acknowledgement:
171.1Ssakamoto *	This product includes software developed by Charles M. Hannum.
181.1Ssakamoto * 4. The name of the author may not be used to endorse or promote products
191.1Ssakamoto *    derived from this software without specific prior written permission.
201.1Ssakamoto *
211.1Ssakamoto * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
221.1Ssakamoto * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
231.1Ssakamoto * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
241.1Ssakamoto * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
251.1Ssakamoto * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
261.1Ssakamoto * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
271.1Ssakamoto * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
281.1Ssakamoto * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
291.1Ssakamoto * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
301.1Ssakamoto * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
311.1Ssakamoto */
321.1Ssakamoto
331.1Ssakamoto#ifndef _BEBOX_INTR_H_
341.1Ssakamoto#define _BEBOX_INTR_H_
351.1Ssakamoto
361.1Ssakamoto/* Interrupt priority `levels'. */
371.1Ssakamoto#define	IPL_NONE	9	/* nothing */
381.1Ssakamoto#define	IPL_SOFTCLOCK	8	/* software clock interrupt */
391.1Ssakamoto#define	IPL_SOFTNET	7	/* software network interrupt */
401.1Ssakamoto#define	IPL_BIO		6	/* block I/O */
411.1Ssakamoto#define	IPL_NET		5	/* network */
421.1Ssakamoto#define	IPL_TTY		4	/* terminal */
431.1Ssakamoto#define	IPL_IMP		3	/* memory allocation */
441.1Ssakamoto#define	IPL_AUDIO	2	/* audio */
451.1Ssakamoto#define	IPL_CLOCK	1	/* clock */
461.1Ssakamoto#define	IPL_HIGH	0	/* everything */
471.4Ssakamoto#define	IPL_SERIAL	0	/* serial */
481.1Ssakamoto#define	NIPL		10
491.1Ssakamoto
501.1Ssakamoto/* Interrupt sharing types. */
511.1Ssakamoto#define	IST_NONE	0	/* none */
521.1Ssakamoto#define	IST_PULSE	1	/* pulsed */
531.1Ssakamoto#define	IST_EDGE	2	/* edge-triggered */
541.1Ssakamoto#define	IST_LEVEL	3	/* level-triggered */
551.1Ssakamoto
561.1Ssakamoto#ifndef _LOCORE
571.1Ssakamoto
581.2Ssakamoto/*
591.2Ssakamoto * Interrupt handler chains.  intr_establish() inserts a handler into
601.2Ssakamoto * the list.  The handler is called with its (single) argument.
611.2Ssakamoto */
621.2Ssakamotostruct intrhand {
631.2Ssakamoto	int	(*ih_fun) __P((void *));
641.2Ssakamoto	void	*ih_arg;
651.2Ssakamoto	u_long	ih_count;
661.2Ssakamoto	struct	intrhand *ih_next;
671.2Ssakamoto	int	ih_level;
681.2Ssakamoto	int	ih_irq;
691.2Ssakamoto};
701.2Ssakamoto
711.2Ssakamotovoid setsoftclock __P((void));
721.2Ssakamotovoid clearsoftclock __P((void));
731.2Ssakamotoint  splsoftclock __P((void));
741.2Ssakamotovoid setsoftnet   __P((void));
751.2Ssakamotovoid clearsoftnet __P((void));
761.2Ssakamotoint  splsoftnet   __P((void));
771.2Ssakamoto
781.2Ssakamotovoid do_pending_int __P((void));
791.2Ssakamoto
801.2Ssakamoto
811.2Ssakamotoextern volatile int cpl, ipending, astpending, tickspending;
821.2Ssakamotoextern int imask[];
831.2Ssakamoto
841.2Ssakamoto/*
851.2Ssakamoto *  Reorder protection in the following inline functions is
861.2Ssakamoto * achived with the "eieio" instruction which the assembler
871.2Ssakamoto * seems to detect and then doen't move instructions past....
881.2Ssakamoto */
891.2Ssakamotostatic __inline int
901.2Ssakamotosplraise(newcpl)
911.2Ssakamoto	int newcpl;
921.2Ssakamoto{
931.2Ssakamoto	int oldcpl;
941.2Ssakamoto
951.2Ssakamoto	__asm__ volatile("sync; eieio\n");	/* don't reorder.... */
961.2Ssakamoto	oldcpl = cpl;
971.2Ssakamoto	cpl = oldcpl | newcpl;
981.2Ssakamoto	__asm__ volatile("sync; eieio\n");	/* reorder protect */
991.2Ssakamoto	return(oldcpl);
1001.2Ssakamoto}
1011.2Ssakamoto
1021.2Ssakamotostatic __inline void
1031.2Ssakamotosplx(newcpl)
1041.2Ssakamoto	int newcpl;
1051.2Ssakamoto{
1061.2Ssakamoto	__asm__ volatile("sync; eieio\n");	/* reorder protect */
1071.2Ssakamoto	cpl = newcpl;
1081.2Ssakamoto	if(ipending & ~newcpl)
1091.2Ssakamoto		do_pending_int();
1101.2Ssakamoto	__asm__ volatile("sync; eieio\n");	/* reorder protect */
1111.2Ssakamoto}
1121.2Ssakamoto
1131.2Ssakamotostatic __inline int
1141.2Ssakamotospllower(newcpl)
1151.2Ssakamoto	int newcpl;
1161.2Ssakamoto{
1171.2Ssakamoto	int oldcpl;
1181.2Ssakamoto
1191.2Ssakamoto	__asm__ volatile("sync; eieio\n");	/* reorder protect */
1201.2Ssakamoto	oldcpl = cpl;
1211.2Ssakamoto	cpl = newcpl;
1221.2Ssakamoto	if(ipending & ~newcpl)
1231.2Ssakamoto		do_pending_int();
1241.2Ssakamoto	__asm__ volatile("sync; eieio\n");	/* reorder protect */
1251.2Ssakamoto	return(oldcpl);
1261.2Ssakamoto}
1271.2Ssakamoto
1281.2Ssakamoto/* Following code should be implemented with lwarx/stwcx to avoid
1291.2Ssakamoto * the disable/enable. i need to read the manual once more.... */
1301.2Ssakamotostatic __inline void
1311.2Ssakamotoset_sint(pending)
1321.2Ssakamoto	int	pending;
1331.2Ssakamoto{
1341.2Ssakamoto	int	msrsave;
1351.2Ssakamoto
1361.2Ssakamoto	__asm__ ("mfmsr %0" : "=r"(msrsave));
1371.2Ssakamoto	__asm__ volatile ("mtmsr %0" :: "r"(msrsave & ~PSL_EE));
1381.2Ssakamoto	ipending |= pending;
1391.2Ssakamoto	__asm__ volatile ("mtmsr %0" :: "r"(msrsave));
1401.2Ssakamoto}
1411.2Ssakamoto
1421.2Ssakamoto#define	ICU_LEN		32
1431.2Ssakamoto#define	IRQ_SLAVE	2
1441.2Ssakamoto#define	LEGAL_IRQ(x)	((x) >= 0 && (x) < ICU_LEN && (x) != IRQ_SLAVE)
1451.2Ssakamoto
1461.2Ssakamoto#define	MOTHER_BOARD_REG	0x7ffff000
1471.2Ssakamoto#define	CPU0_INT_MASK	0x0f0
1481.2Ssakamoto#define	CPU1_INT_MASK	0x1f0
1491.2Ssakamoto#define	INT_STATE_REG	0x2f0
1501.2Ssakamoto
1511.3Ssakamoto#define	SINT_CLOCK	0x20000000
1521.3Ssakamoto#define	SINT_NET	0x40000000
1531.4Ssakamoto#define	SINT_SERIAL	0x80000000
1541.3Ssakamoto#define	SPL_CLOCK	0x00000001
1551.4Ssakamoto#define	SINT_MASK	(SINT_CLOCK|SINT_NET|SINT_SERIAL)
1561.2Ssakamoto
1571.2Ssakamoto#define	CNT_SINT_NET	29
1581.2Ssakamoto#define	CNT_SINT_CLOCK	30
1591.4Ssakamoto#define	CNT_SINT_SERIAL	31
1601.3Ssakamoto#define	CNT_CLOCK	0
1611.2Ssakamoto
1621.2Ssakamoto#define splbio()	splraise(imask[IPL_BIO])
1631.2Ssakamoto#define splnet()	splraise(imask[IPL_NET])
1641.2Ssakamoto#define spltty()	splraise(imask[IPL_TTY])
1651.2Ssakamoto#define splclock()	splraise(SPL_CLOCK|SINT_CLOCK|SINT_NET)
1661.2Ssakamoto#define splimp()	splraise(imask[IPL_IMP])
1671.4Ssakamoto#define	splserial()	splraise(imask[IPL_SERIAL])
1681.2Ssakamoto#define splstatclock()	splhigh()
1691.2Ssakamoto#define	splsoftclock()	spllower(SINT_CLOCK)
1701.2Ssakamoto#define	splsoftnet()	splraise(SINT_NET)
1711.4Ssakamoto#define	splsoftserial()	splraise(SINT_SERIAL)
1721.2Ssakamoto
1731.2Ssakamoto#define	setsoftclock()	set_sint(SINT_CLOCK);
1741.2Ssakamoto#define	setsoftnet()	set_sint(SINT_NET);
1751.4Ssakamoto#define	setsoftserial()	set_sint(SINT_SERIAL);
1761.2Ssakamoto
1771.2Ssakamoto#define	splhigh()	splraise(0xffffffff)
1781.2Ssakamoto#define	spl0()		spllower(0)
1791.1Ssakamoto
1801.1Ssakamoto#endif /* !_LOCORE */
1811.1Ssakamoto
1821.1Ssakamoto#endif /* !_BEBOX_INTR_H_ */
183