intr.h revision 1.1
11.1Smatt/*	$NetBSD: intr.h,v 1.1 2003/10/19 03:33:50 matt Exp $	*/
21.1Smatt
31.1Smatt/*-
41.1Smatt * Copyright (c) 1998 The NetBSD Foundation, Inc.
51.1Smatt * All rights reserved.
61.1Smatt *
71.1Smatt * This code is derived from software contributed to The NetBSD Foundation
81.1Smatt * by Charles M. Hannum.
91.1Smatt *
101.1Smatt * Redistribution and use in source and binary forms, with or without
111.1Smatt * modification, are permitted provided that the following conditions
121.1Smatt * are met:
131.1Smatt * 1. Redistributions of source code must retain the above copyright
141.1Smatt *    notice, this list of conditions and the following disclaimer.
151.1Smatt * 2. Redistributions in binary form must reproduce the above copyright
161.1Smatt *    notice, this list of conditions and the following disclaimer in the
171.1Smatt *    documentation and/or other materials provided with the distribution.
181.1Smatt * 3. All advertising materials mentioning features or use of this software
191.1Smatt *    must display the following acknowledgement:
201.1Smatt *        This product includes software developed by the NetBSD
211.1Smatt *        Foundation, Inc. and its contributors.
221.1Smatt * 4. Neither the name of The NetBSD Foundation nor the names of its
231.1Smatt *    contributors may be used to endorse or promote products derived
241.1Smatt *    from this software without specific prior written permission.
251.1Smatt *
261.1Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.1Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.1Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.1Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.1Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.1Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.1Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.1Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.1Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.1Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.1Smatt * POSSIBILITY OF SUCH DAMAGE.
371.1Smatt */
381.1Smatt
391.1Smatt#ifndef _IBMNWS_INTR_H_
401.1Smatt#define _IBMNWS_INTR_H_
411.1Smatt
421.1Smatt/* Interrupt priority `levels'. */
431.1Smatt#define	IPL_NONE	9	/* nothing */
441.1Smatt#define	IPL_SOFTCLOCK	8	/* software clock interrupt */
451.1Smatt#define	IPL_SOFTNET	7	/* software network interrupt */
461.1Smatt#define	IPL_BIO		6	/* block I/O */
471.1Smatt#define	IPL_NET		5	/* network */
481.1Smatt#define	IPL_SOFTSERIAL	4	/* software serial interrupt */
491.1Smatt#define	IPL_TTY		3	/* terminal */
501.1Smatt#define	IPL_IMP		3	/* memory allocation */
511.1Smatt#define	IPL_AUDIO	2	/* audio */
521.1Smatt#define	IPL_CLOCK	1	/* clock */
531.1Smatt#define	IPL_HIGH	1	/* everything */
541.1Smatt#define	IPL_SERIAL	0	/* serial */
551.1Smatt#define	NIPL		10
561.1Smatt
571.1Smatt/* Interrupt sharing types. */
581.1Smatt#define	IST_NONE	0	/* none */
591.1Smatt#define	IST_PULSE	1	/* pulsed */
601.1Smatt#define	IST_EDGE	2	/* edge-triggered */
611.1Smatt#define	IST_LEVEL	3	/* level-triggered */
621.1Smatt
631.1Smatt#ifndef _LOCORE
641.1Smatt
651.1Smatt/*
661.1Smatt * Interrupt handler chains.  intr_establish() inserts a handler into
671.1Smatt * the list.  The handler is called with its (single) argument.
681.1Smatt */
691.1Smattstruct intrhand {
701.1Smatt	int	(*ih_fun)(void *);
711.1Smatt	void	*ih_arg;
721.1Smatt	u_long	ih_count;
731.1Smatt	struct	intrhand *ih_next;
741.1Smatt	int	ih_level;
751.1Smatt	int	ih_irq;
761.1Smatt};
771.1Smatt
781.1Smattvoid do_pending_int(void);
791.1Smatt
801.1Smattvoid init_intr(void);
811.1Smattvoid init_intr_ivr(void);
821.1Smatt
831.1Smattvoid enable_intr(void);
841.1Smattvoid disable_intr(void);
851.1Smatt
861.1Smattvoid *intr_establish(int, int, int, int (*)(void *), void *);
871.1Smattvoid intr_disestablish(void *);
881.1Smatt
891.1Smattvoid softnet(int);
901.1Smattvoid softserial(void);
911.1Smattint isa_intr(void);
921.1Smattvoid isa_intr_mask(int);
931.1Smattvoid isa_intr_clr(int);
941.1Smattvoid isa_setirqstat(int, int, int);
951.1Smatt
961.1Smattstatic __inline int splraise(int);
971.1Smattstatic __inline void spllower(int);
981.1Smattstatic __inline void set_sint(int);
991.1Smatt
1001.1Smattextern volatile int cpl, ipending, astpending, tickspending;
1011.1Smattextern int imen;
1021.1Smattextern int imask[];
1031.1Smattextern long intrcnt[];
1041.1Smattextern unsigned intrcnt2[];
1051.1Smattextern struct intrhand *intrhand[];
1061.1Smattextern int intrtype[];
1071.1Smattextern vaddr_t prep_intr_reg;
1081.1Smatt
1091.1Smatt/*
1101.1Smatt *  Reorder protection in the following inline functions is
1111.1Smatt * achieved with the "eieio" instruction which the assembler
1121.1Smatt * seems to detect and then doesn't move instructions past....
1131.1Smatt */
1141.1Smattstatic __inline int
1151.1Smattsplraise(int newcpl)
1161.1Smatt{
1171.1Smatt	int oldcpl;
1181.1Smatt
1191.1Smatt	__asm__ volatile("sync; eieio\n");	/* don't reorder.... */
1201.1Smatt	oldcpl = cpl;
1211.1Smatt	cpl = oldcpl | newcpl;
1221.1Smatt	__asm__ volatile("sync; eieio\n");	/* reorder protect */
1231.1Smatt	return(oldcpl);
1241.1Smatt}
1251.1Smatt
1261.1Smattstatic __inline void
1271.1Smattspllower(int newcpl)
1281.1Smatt{
1291.1Smatt
1301.1Smatt	__asm__ volatile("sync; eieio\n");	/* reorder protect */
1311.1Smatt	cpl = newcpl;
1321.1Smatt	if(ipending & ~newcpl)
1331.1Smatt		do_pending_int();
1341.1Smatt	__asm__ volatile("sync; eieio\n");	/* reorder protect */
1351.1Smatt}
1361.1Smatt
1371.1Smatt/* Following code should be implemented with lwarx/stwcx to avoid
1381.1Smatt * the disable/enable. i need to read the manual once more.... */
1391.1Smattstatic __inline void
1401.1Smattset_sint(int pending)
1411.1Smatt{
1421.1Smatt	int	msrsave;
1431.1Smatt
1441.1Smatt	__asm__ ("mfmsr %0" : "=r"(msrsave));
1451.1Smatt	__asm__ volatile ("mtmsr %0" :: "r"(msrsave & ~PSL_EE));
1461.1Smatt	ipending |= pending;
1471.1Smatt	__asm__ volatile ("mtmsr %0" :: "r"(msrsave));
1481.1Smatt}
1491.1Smatt
1501.1Smatt#define	ICU_LEN			32
1511.1Smatt#define	IRQ_SLAVE		2
1521.1Smatt#define	LEGAL_IRQ(x)		((x) >= 0 && (x) < ICU_LEN && (x) != IRQ_SLAVE)
1531.1Smatt#define	I8259_INTR_NUM		16
1541.1Smatt
1551.1Smatt#define	PREP_INTR_REG	0xbffff000
1561.1Smatt#define	INTR_VECTOR_REG	0xff0
1571.1Smatt
1581.1Smatt#define	SINT_CLOCK	0x20000000
1591.1Smatt#define	SINT_NET	0x40000000
1601.1Smatt#define	SINT_SERIAL	0x80000000
1611.1Smatt#define	SPL_CLOCK	0x00000001
1621.1Smatt#define	SINT_MASK	(SINT_CLOCK|SINT_NET|SINT_SERIAL)
1631.1Smatt
1641.1Smatt#define	CNT_SINT_NET	29
1651.1Smatt#define	CNT_SINT_CLOCK	30
1661.1Smatt#define	CNT_SINT_SERIAL	31
1671.1Smatt#define	CNT_CLOCK	0
1681.1Smatt
1691.1Smatt#define splbio()	splraise(imask[IPL_BIO])
1701.1Smatt#define splnet()	splraise(imask[IPL_NET])
1711.1Smatt#define spltty()	splraise(imask[IPL_TTY])
1721.1Smatt#define splclock()	splraise(imask[IPL_CLOCK])
1731.1Smatt#define splvm()		splraise(imask[IPL_IMP])
1741.1Smatt#define splaudio()	splraise(imask[IPL_AUDIO])
1751.1Smatt#define	splserial()	splraise(imask[IPL_SERIAL])
1761.1Smatt#define splstatclock()	splclock()
1771.1Smatt#define	spllowersoftclock() spllower(imask[IPL_SOFTCLOCK])
1781.1Smatt#define	splsoftclock()	splraise(imask[IPL_SOFTCLOCK])
1791.1Smatt#define	splsoftnet()	splraise(imask[IPL_SOFTNET])
1801.1Smatt#define	splsoftserial()	splraise(imask[IPL_SOFTSERIAL])
1811.1Smatt
1821.1Smatt#define spllpt()	spltty()
1831.1Smatt
1841.1Smatt#define	setsoftclock()	set_sint(SINT_CLOCK);
1851.1Smatt#define	setsoftnet()	set_sint(SINT_NET);
1861.1Smatt#define	setsoftserial()	set_sint(SINT_SERIAL);
1871.1Smatt
1881.1Smatt#define	splhigh()	splraise(imask[IPL_HIGH])
1891.1Smatt#define	splsched()	splhigh()
1901.1Smatt#define	spllock()	splhigh()
1911.1Smatt#define	splx(x)		spllower(x)
1921.1Smatt#define	spl0()		spllower(0)
1931.1Smatt
1941.1Smatt#define	CLKF_BASEPRI(pri)	((pri) != 0)
1951.1Smatt
1961.1Smatt#endif /* !_LOCORE */
1971.1Smatt
1981.1Smatt#endif /* !_IBMNWS_INTR_H_ */
199