intr.h revision 1.2
11.2Sis/*	$NetBSD: intr.h,v 1.2 1998/07/18 21:27:27 is Exp $	*/
21.1Stsubai/*	$OpenBSD: intr.h,v 1.1 1997/10/13 10:53:45 pefo Exp $ */
31.1Stsubai
41.1Stsubai/*
51.1Stsubai * Copyright (c) 1996, 1997 Charles M. Hannum.  All rights reserved.
61.1Stsubai *
71.1Stsubai * Redistribution and use in source and binary forms, with or without
81.1Stsubai * modification, are permitted provided that the following conditions
91.1Stsubai * are met:
101.1Stsubai * 1. Redistributions of source code must retain the above copyright
111.1Stsubai *    notice, this list of conditions and the following disclaimer.
121.1Stsubai * 2. Redistributions in binary form must reproduce the above copyright
131.1Stsubai *    notice, this list of conditions and the following disclaimer in the
141.1Stsubai *    documentation and/or other materials provided with the distribution.
151.1Stsubai * 3. All advertising materials mentioning features or use of this software
161.1Stsubai *    must display the following acknowledgement:
171.1Stsubai *	This product includes software developed by Charles M. Hannum.
181.1Stsubai * 4. The name of the author may not be used to endorse or promote products
191.1Stsubai *    derived from this software without specific prior written permission.
201.1Stsubai *
211.1Stsubai * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
221.1Stsubai * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
231.1Stsubai * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
241.1Stsubai * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
251.1Stsubai * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
261.1Stsubai * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
271.1Stsubai * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
281.1Stsubai * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
291.1Stsubai * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
301.1Stsubai * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
311.1Stsubai */
321.1Stsubai
331.1Stsubai#ifndef _POWERMAC_INTR_H_
341.1Stsubai#define _POWERMAC_INTR_H_
351.1Stsubai
361.1Stsubai/* Interrupt priority `levels'. */
371.1Stsubai#define	IPL_NONE	9	/* nothing */
381.1Stsubai#define	IPL_SOFTCLOCK	8	/* timeouts */
391.1Stsubai#define	IPL_SOFTNET	7	/* protocol stacks */
401.1Stsubai#define	IPL_BIO		6	/* block I/O */
411.1Stsubai#define	IPL_NET		5	/* network */
421.1Stsubai#define	IPL_SOFTSERIAL	4	/* serial */
431.1Stsubai#define	IPL_TTY		3	/* terminal */
441.1Stsubai#define	IPL_IMP		3	/* memory allocation */
451.1Stsubai#define	IPL_AUDIO	2	/* audio */
461.1Stsubai#define	IPL_CLOCK	1	/* clock */
471.1Stsubai#define	IPL_HIGH	1	/* everything */
481.1Stsubai#define	IPL_SERIAL	0	/* serial */
491.1Stsubai#define	NIPL		10
501.1Stsubai
511.1Stsubai/* Interrupt sharing types. */
521.1Stsubai#define	IST_NONE	0	/* none */
531.1Stsubai#define	IST_PULSE	1	/* pulsed */
541.1Stsubai#define	IST_EDGE	2	/* edge-triggered */
551.1Stsubai#define	IST_LEVEL	3	/* level-triggered */
561.1Stsubai
571.1Stsubai#ifndef _LOCORE
581.1Stsubai
591.1Stsubai/*
601.1Stsubai * Interrupt handler chains.  intr_establish() inserts a handler into
611.1Stsubai * the list.  The handler is called with its (single) argument.
621.1Stsubai */
631.1Stsubaistruct intrhand {
641.1Stsubai	int	(*ih_fun) __P((void *));
651.1Stsubai	void	*ih_arg;
661.1Stsubai	u_long	ih_count;
671.1Stsubai	struct	intrhand *ih_next;
681.1Stsubai	int	ih_level;
691.1Stsubai	int	ih_irq;
701.1Stsubai};
711.1Stsubai
721.1Stsubaivoid setsoftclock __P((void));
731.1Stsubaivoid clearsoftclock __P((void));
741.1Stsubaiint  splsoftclock __P((void));
751.1Stsubaivoid setsoftnet   __P((void));
761.1Stsubaivoid clearsoftnet __P((void));
771.1Stsubaiint  splsoftnet   __P((void));
781.1Stsubai
791.1Stsubaivoid do_pending_int __P((void));
801.1Stsubai
811.1Stsubaistatic __inline int splraise __P((int));
821.1Stsubaistatic __inline int spllower __P((int));
831.1Stsubaistatic __inline void splx __P((int));
841.1Stsubaistatic __inline void softintr __P((int));
851.1Stsubai
861.1Stsubaiextern volatile int cpl, ipending, astpending, tickspending;
871.1Stsubaiextern int imask[];
881.1Stsubai
891.1Stsubai/*
901.1Stsubai *  Reorder protection in the following inline functions is
911.1Stsubai * achived with the "eieio" instruction which the assembler
921.1Stsubai * seems to detect and then doen't move instructions past....
931.1Stsubai */
941.1Stsubaistatic __inline int
951.1Stsubaisplraise(ncpl)
961.1Stsubai	int ncpl;
971.1Stsubai{
981.1Stsubai	int ocpl;
991.1Stsubai
1001.1Stsubai	__asm__ volatile("sync; eieio\n");	/* don't reorder.... */
1011.1Stsubai	ocpl = cpl;
1021.1Stsubai	cpl = ocpl | ncpl;
1031.1Stsubai	__asm__ volatile("sync; eieio\n");	/* reorder protect */
1041.1Stsubai	return (ocpl);
1051.1Stsubai}
1061.1Stsubai
1071.1Stsubaistatic __inline void
1081.1Stsubaisplx(ncpl)
1091.1Stsubai	int ncpl;
1101.1Stsubai{
1111.1Stsubai
1121.1Stsubai	__asm__ volatile("sync; eieio\n");	/* reorder protect */
1131.1Stsubai	cpl = ncpl;
1141.1Stsubai	if (ipending & ~ncpl)
1151.1Stsubai		do_pending_int();
1161.1Stsubai	__asm__ volatile("sync; eieio\n");	/* reorder protect */
1171.1Stsubai}
1181.1Stsubai
1191.1Stsubaistatic __inline int
1201.1Stsubaispllower(ncpl)
1211.1Stsubai	int ncpl;
1221.1Stsubai{
1231.1Stsubai	int ocpl;
1241.1Stsubai
1251.1Stsubai	__asm__ volatile("sync; eieio\n");	/* reorder protect */
1261.1Stsubai	ocpl = cpl;
1271.1Stsubai	cpl = ncpl;
1281.1Stsubai	if (ipending & ~ncpl)
1291.1Stsubai		do_pending_int();
1301.1Stsubai	__asm__ volatile("sync; eieio\n");	/* reorder protect */
1311.1Stsubai	return (ocpl);
1321.1Stsubai}
1331.1Stsubai
1341.1Stsubai/* Following code should be implemented with lwarx/stwcx to avoid
1351.1Stsubai * the disable/enable. i need to read the manual once more.... */
1361.1Stsubaistatic __inline void
1371.1Stsubaisoftintr(ipl)
1381.1Stsubai	int ipl;
1391.1Stsubai{
1401.1Stsubai	int msrsave;
1411.1Stsubai
1421.1Stsubai	__asm__ volatile("mfmsr %0" : "=r"(msrsave));
1431.1Stsubai	__asm__ volatile("mtmsr %0" :: "r"(msrsave & ~PSL_EE));
1441.1Stsubai	ipending |= 1 << ipl;
1451.1Stsubai	__asm__ volatile("mtmsr %0" :: "r"(msrsave));
1461.1Stsubai}
1471.1Stsubai
1481.1Stsubai#define	ICU_LEN		32
1491.1Stsubai
1501.1Stsubai/* Soft interrupt masks. */
1511.1Stsubai#define SIR_CLOCK	28
1521.1Stsubai#define SIR_NET		29
1531.1Stsubai#define SIR_SERIAL	30
1541.1Stsubai#define SPL_CLOCK	31
1551.1Stsubai
1561.1Stsubai/*
1571.1Stsubai * Hardware interrupt masks
1581.1Stsubai */
1591.1Stsubai#define splbio()	splraise(imask[IPL_BIO])
1601.1Stsubai#define splnet()	splraise(imask[IPL_NET])
1611.1Stsubai#define spltty()	splraise(imask[IPL_TTY])
1621.1Stsubai#define	splaudio()	splraise(imask[IPL_AUDIO])
1631.1Stsubai#define splclock()	splraise(imask[IPL_CLOCK])
1641.1Stsubai#define splstatclock()	splclock()
1651.1Stsubai#define	splserial()	splraise(imask[IPL_SERIAL])
1661.2Sis
1671.2Sis#define spllpt()	spltty()
1681.1Stsubai
1691.1Stsubai/*
1701.1Stsubai * Software interrupt masks
1711.1Stsubai *
1721.1Stsubai * NOTE: splsoftclock() is used by hardclock() to lower the priority from
1731.1Stsubai * clock to softclock before it calls softclock().
1741.1Stsubai */
1751.1Stsubai#define	splsoftclock()	spllower(imask[IPL_SOFTCLOCK])
1761.1Stsubai#define	splsoftnet()	splraise(imask[IPL_SOFTNET])
1771.1Stsubai#define	splsoftserial()	splraise(imask[IPL_SOFTSERIAL])
1781.1Stsubai
1791.1Stsubai/*
1801.1Stsubai * Miscellaneous
1811.1Stsubai */
1821.1Stsubai#define splimp()	splraise(imask[IPL_IMP])
1831.1Stsubai#define	splhigh()	splraise(imask[IPL_HIGH])
1841.1Stsubai#define	spl0()		spllower(0)
1851.1Stsubai
1861.1Stsubai#define	setsoftclock()	softintr(SIR_CLOCK)
1871.1Stsubai#define	setsoftnet()	softintr(SIR_NET)
1881.1Stsubai#define	setsoftserial()	softintr(SIR_SERIAL)
1891.1Stsubai
1901.1Stsubai#endif /* !_LOCORE */
1911.1Stsubai
1921.1Stsubai#endif /* !_POWERMAC_INTR_H_ */
193