intr.h revision 1.24
11.24Syamt/*	$NetBSD: intr.h,v 1.24 2006/12/21 15:55:22 yamt Exp $	*/
21.1Ssakamoto
31.6Smycroft/*-
41.6Smycroft * Copyright (c) 1998 The NetBSD Foundation, Inc.
51.6Smycroft * All rights reserved.
61.6Smycroft *
71.6Smycroft * This code is derived from software contributed to The NetBSD Foundation
81.6Smycroft * by Charles M. Hannum.
91.1Ssakamoto *
101.1Ssakamoto * Redistribution and use in source and binary forms, with or without
111.1Ssakamoto * modification, are permitted provided that the following conditions
121.1Ssakamoto * are met:
131.1Ssakamoto * 1. Redistributions of source code must retain the above copyright
141.1Ssakamoto *    notice, this list of conditions and the following disclaimer.
151.1Ssakamoto * 2. Redistributions in binary form must reproduce the above copyright
161.1Ssakamoto *    notice, this list of conditions and the following disclaimer in the
171.1Ssakamoto *    documentation and/or other materials provided with the distribution.
181.1Ssakamoto * 3. All advertising materials mentioning features or use of this software
191.1Ssakamoto *    must display the following acknowledgement:
201.6Smycroft *        This product includes software developed by the NetBSD
211.6Smycroft *        Foundation, Inc. and its contributors.
221.6Smycroft * 4. Neither the name of The NetBSD Foundation nor the names of its
231.6Smycroft *    contributors may be used to endorse or promote products derived
241.6Smycroft *    from this software without specific prior written permission.
251.1Ssakamoto *
261.6Smycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.6Smycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.6Smycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.6Smycroft * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.6Smycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.6Smycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.6Smycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.6Smycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.6Smycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.6Smycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.6Smycroft * POSSIBILITY OF SUCH DAMAGE.
371.1Ssakamoto */
381.1Ssakamoto
391.1Ssakamoto#ifndef _BEBOX_INTR_H_
401.1Ssakamoto#define _BEBOX_INTR_H_
411.1Ssakamoto
421.1Ssakamoto/* Interrupt priority `levels'. */
431.1Ssakamoto#define	IPL_NONE	9	/* nothing */
441.1Ssakamoto#define	IPL_SOFTCLOCK	8	/* software clock interrupt */
451.1Ssakamoto#define	IPL_SOFTNET	7	/* software network interrupt */
461.1Ssakamoto#define	IPL_BIO		6	/* block I/O */
471.1Ssakamoto#define	IPL_NET		5	/* network */
481.8Sthorpej#define	IPL_SOFTSERIAL	4	/* software serial interrupt */
491.8Sthorpej#define	IPL_TTY		3	/* terminal */
501.24Syamt#define	IPL_LPT		IPL_TTY
511.18Sthorpej#define	IPL_VM		3	/* memory allocation */
521.1Ssakamoto#define	IPL_AUDIO	2	/* audio */
531.1Ssakamoto#define	IPL_CLOCK	1	/* clock */
541.24Syamt#define	IPL_STATCLOCK	IPL_CLOCK
551.8Sthorpej#define	IPL_HIGH	1	/* everything */
561.24Syamt#define	IPL_SCHED	IPL_HIGH
571.24Syamt#define	IPL_LOCK	IPL_HIGH
581.4Ssakamoto#define	IPL_SERIAL	0	/* serial */
591.1Ssakamoto#define	NIPL		10
601.1Ssakamoto
611.1Ssakamoto/* Interrupt sharing types. */
621.1Ssakamoto#define	IST_NONE	0	/* none */
631.1Ssakamoto#define	IST_PULSE	1	/* pulsed */
641.1Ssakamoto#define	IST_EDGE	2	/* edge-triggered */
651.1Ssakamoto#define	IST_LEVEL	3	/* level-triggered */
661.1Ssakamoto
671.1Ssakamoto#ifndef _LOCORE
681.1Ssakamoto
691.19Smatt#define	CLKF_BASEPRI(frame)	((frame)->pri == 0)
701.2Ssakamoto/*
711.2Ssakamoto * Interrupt handler chains.  intr_establish() inserts a handler into
721.2Ssakamoto * the list.  The handler is called with its (single) argument.
731.2Ssakamoto */
741.2Ssakamotostruct intrhand {
751.2Ssakamoto	int	(*ih_fun) __P((void *));
761.2Ssakamoto	void	*ih_arg;
771.2Ssakamoto	u_long	ih_count;
781.2Ssakamoto	struct	intrhand *ih_next;
791.2Ssakamoto	int	ih_level;
801.2Ssakamoto	int	ih_irq;
811.2Ssakamoto};
821.2Ssakamoto
831.2Ssakamotovoid do_pending_int __P((void));
841.14Smatt
851.14Smattvoid ext_intr __P((void));
861.14Smattvoid *intr_establish __P((int, int, int, int (*)(void *), void *));
871.14Smattvoid intr_disestablish __P((void *));
881.14Smattvoid intr_calculatemasks __P((void));
891.14Smattint  isa_intr __P((void));
901.14Smattvoid isa_intr_mask __P((int));
911.14Smattvoid isa_intr_clr __P((int));
921.14Smatt
931.14Smattvoid enable_intr __P((void));
941.14Smattvoid disable_intr __P((void));
951.2Ssakamoto
961.23Sperrystatic __inline int splraise __P((int));
971.23Sperrystatic __inline int spllower __P((int));
981.23Sperrystatic __inline void splx __P((int));
991.23Sperrystatic __inline void set_sint __P((int));
1001.2Ssakamoto
1011.2Ssakamotoextern volatile int cpl, ipending, astpending, tickspending;
1021.2Ssakamotoextern int imask[];
1031.7Ssakamotoextern long intrcnt[];
1041.2Ssakamoto
1051.2Ssakamoto/*
1061.2Ssakamoto *  Reorder protection in the following inline functions is
1071.15Swiz * achieved with the "eieio" instruction which the assembler
1081.16Swiz * seems to detect and then doesn't move instructions past....
1091.2Ssakamoto */
1101.23Sperrystatic __inline int
1111.2Ssakamotosplraise(newcpl)
1121.2Ssakamoto	int newcpl;
1131.2Ssakamoto{
1141.2Ssakamoto	int oldcpl;
1151.2Ssakamoto
1161.22Sperry	__asm volatile("sync; eieio\n");	/* don't reorder.... */
1171.2Ssakamoto	oldcpl = cpl;
1181.2Ssakamoto	cpl = oldcpl | newcpl;
1191.22Sperry	__asm volatile("sync; eieio\n");	/* reorder protect */
1201.2Ssakamoto	return(oldcpl);
1211.2Ssakamoto}
1221.2Ssakamoto
1231.23Sperrystatic __inline void
1241.2Ssakamotosplx(newcpl)
1251.2Ssakamoto	int newcpl;
1261.2Ssakamoto{
1271.22Sperry	__asm volatile("sync; eieio\n");	/* reorder protect */
1281.2Ssakamoto	cpl = newcpl;
1291.2Ssakamoto	if(ipending & ~newcpl)
1301.2Ssakamoto		do_pending_int();
1311.22Sperry	__asm volatile("sync; eieio\n");	/* reorder protect */
1321.2Ssakamoto}
1331.2Ssakamoto
1341.23Sperrystatic __inline int
1351.2Ssakamotospllower(newcpl)
1361.2Ssakamoto	int newcpl;
1371.2Ssakamoto{
1381.2Ssakamoto	int oldcpl;
1391.2Ssakamoto
1401.22Sperry	__asm volatile("sync; eieio\n");	/* reorder protect */
1411.2Ssakamoto	oldcpl = cpl;
1421.2Ssakamoto	cpl = newcpl;
1431.2Ssakamoto	if(ipending & ~newcpl)
1441.2Ssakamoto		do_pending_int();
1451.22Sperry	__asm volatile("sync; eieio\n");	/* reorder protect */
1461.2Ssakamoto	return(oldcpl);
1471.2Ssakamoto}
1481.2Ssakamoto
1491.2Ssakamoto/* Following code should be implemented with lwarx/stwcx to avoid
1501.2Ssakamoto * the disable/enable. i need to read the manual once more.... */
1511.23Sperrystatic __inline void
1521.2Ssakamotoset_sint(pending)
1531.2Ssakamoto	int	pending;
1541.2Ssakamoto{
1551.2Ssakamoto	int	msrsave;
1561.2Ssakamoto
1571.22Sperry	__asm ("mfmsr %0" : "=r"(msrsave));
1581.22Sperry	__asm volatile ("mtmsr %0" :: "r"(msrsave & ~PSL_EE));
1591.2Ssakamoto	ipending |= pending;
1601.22Sperry	__asm volatile ("mtmsr %0" :: "r"(msrsave));
1611.2Ssakamoto}
1621.2Ssakamoto
1631.2Ssakamoto#define	ICU_LEN		32
1641.2Ssakamoto#define	IRQ_SLAVE	2
1651.2Ssakamoto#define	LEGAL_IRQ(x)	((x) >= 0 && (x) < ICU_LEN && (x) != IRQ_SLAVE)
1661.2Ssakamoto
1671.2Ssakamoto#define	MOTHER_BOARD_REG	0x7ffff000
1681.2Ssakamoto#define	CPU0_INT_MASK	0x0f0
1691.2Ssakamoto#define	CPU1_INT_MASK	0x1f0
1701.2Ssakamoto#define	INT_STATE_REG	0x2f0
1711.2Ssakamoto
1721.3Ssakamoto#define	SINT_CLOCK	0x20000000
1731.3Ssakamoto#define	SINT_NET	0x40000000
1741.4Ssakamoto#define	SINT_SERIAL	0x80000000
1751.3Ssakamoto#define	SPL_CLOCK	0x00000001
1761.4Ssakamoto#define	SINT_MASK	(SINT_CLOCK|SINT_NET|SINT_SERIAL)
1771.2Ssakamoto
1781.2Ssakamoto#define	CNT_SINT_NET	29
1791.2Ssakamoto#define	CNT_SINT_CLOCK	30
1801.4Ssakamoto#define	CNT_SINT_SERIAL	31
1811.3Ssakamoto#define	CNT_CLOCK	0
1821.2Ssakamoto
1831.9Sthorpej#define	spllowersoftclock() spllower(imask[IPL_SOFTCLOCK])
1841.2Ssakamoto
1851.2Ssakamoto#define	setsoftclock()	set_sint(SINT_CLOCK);
1861.2Ssakamoto#define	setsoftnet()	set_sint(SINT_NET);
1871.4Ssakamoto#define	setsoftserial()	set_sint(SINT_SERIAL);
1881.2Ssakamoto
1891.2Ssakamoto#define	spl0()		spllower(0)
1901.10Sthorpej
1911.24Syamttypedef int ipl_t;
1921.24Syamttypedef struct {
1931.24Syamt	ipl_t _ipl;
1941.24Syamt} ipl_cookie_t;
1951.24Syamt
1961.24Syamtstatic inline ipl_cookie_t
1971.24Syamtmakeiplcookie(ipl_t ipl)
1981.24Syamt{
1991.24Syamt
2001.24Syamt	return (ipl_cookie_t){._ipl = ipl};
2011.24Syamt}
2021.24Syamt
2031.24Syamtstatic inline int
2041.24Syamtsplraiseipl(ipl_cookie_t icookie)
2051.24Syamt{
2061.24Syamt
2071.24Syamt	return splraise(imask[icookie._ipl]);
2081.24Syamt}
2091.24Syamt
2101.24Syamt#include <sys/spl.h>
2111.1Ssakamoto
2121.1Ssakamoto#endif /* !_LOCORE */
2131.1Ssakamoto
2141.1Ssakamoto#endif /* !_BEBOX_INTR_H_ */
215