intr.h revision 1.14
11.339Smartin/*	$NetBSD: intr.h,v 1.14 2003/12/10 01:26:24 jmc Exp $	*/
21.1Smrg
31.98Schs/*-
41.1Smrg * Copyright (c) 1997 The NetBSD Foundation, Inc.
51.98Schs * All rights reserved.
61.1Smrg *
71.1Smrg * This code is derived from software contributed to The NetBSD Foundation
81.1Smrg * by Ignatios Souvatzis.
91.1Smrg *
101.1Smrg * Redistribution and use in source and binary forms, with or without
111.1Smrg * modification, are permitted provided that the following conditions
121.1Smrg * are met:
131.1Smrg * 1. Redistributions of source code must retain the above copyright
141.1Smrg *    notice, this list of conditions and the following disclaimer.
151.1Smrg * 2. Redistributions in binary form must reproduce the above copyright
161.1Smrg *    notice, this list of conditions and the following disclaimer in the
171.1Smrg *    documentation and/or other materials provided with the distribution.
181.1Smrg * 3. All advertising materials mentioning features or use of this software
191.1Smrg *    must display the following acknowledgement:
201.295Schuck *        This product includes software developed by the NetBSD
211.1Smrg *        Foundation, Inc. and its contributors.
221.1Smrg * 4. Neither the name of The NetBSD Foundation nor the names of its
231.1Smrg *    contributors may be used to endorse or promote products derived
241.1Smrg *    from this software without specific prior written permission.
251.1Smrg *
261.1Smrg * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.1Smrg * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.1Smrg * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.1Smrg * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.1Smrg * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.1Smrg * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.1Smrg * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.1Smrg * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.1Smrg * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.1Smrg * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.1Smrg * POSSIBILITY OF SUCH DAMAGE.
371.3Smrg */
381.1Smrg
391.1Smrg/*
401.1Smrg * machine/intr.h for the Amiga port.
411.1Smrg * Currently, only a wrapper, for most of the stuff, around the old
421.98Schs * include files.
431.1Smrg */
441.1Smrg
451.1Smrg#ifndef _MACHINE_INTR_H_
461.1Smrg#define _MACHINE_INTR_H_
471.1Smrg
481.98Schs#ifdef _KERNEL
491.98Schs#include <amiga/amiga/isr.h>
501.98Schs#include <amiga/include/mtpr.h>
511.1Smrg#endif
521.98Schs
531.1Smrg/* ADAM: commented out
541.1Smrg#define IPL_SOFTSERIAL 1
551.1Smrg#define IPL_SOFTNET 1
561.1Smrg*/
571.1Smrg
581.1Smrg#ifdef splaudio
591.1Smrg#undef splaudio
601.1Smrg#define splaudio spl6
611.1Smrg#endif
621.1Smrg
631.1Smrg#define spllpt()	spl6()
641.114Slukem
651.114Slukem/* ADAM: from macppc/intr.h */
661.114Slukem/* Interrupt priority `levels'. */
671.114Slukem#define	IPL_NONE	9	/* nothing */
681.114Slukem#define	IPL_SOFTCLOCK	8	/* timeouts */
691.339Smartin#define	IPL_SOFTNET	7	/* protocol stacks */
701.114Slukem#define	IPL_BIO		6	/* block I/O */
711.21Sjonathan#define	IPL_NET		5	/* network */
721.6Smrg#define	IPL_SOFTSERIAL	4	/* serial */
731.169Spetrov#define	IPL_TTY		3	/* terminal */
741.31Stron#define	IPL_VM		3	/* memory allocation */
751.1Smrg#define	IPL_AUDIO	2	/* audio */
761.1Smrg#define	IPL_CLOCK	1	/* clock */
771.1Smrg#define	IPL_HIGH	1	/* everything */
781.1Smrg#define	IPL_SERIAL	0	/* serial */
791.1Smrg#define	NIPL		10
801.25Sthorpej
811.104Schs/* Interrupt sharing types. */
821.112Sthorpej#define	IST_NONE	0	/* none */
831.109Sthorpej#define	IST_PULSE	1	/* pulsed */
841.335Schristos#define	IST_EDGE	2	/* edge-triggered */
851.244Syamt#define	IST_LEVEL	3	/* level-triggered */
861.248Sad
871.335Schristos#ifndef _LOCORE
881.288Sdrochner
891.288Sdrochner/*
901.290Sdrochner * Interrupt handler chains.  intr_establish() inserts a handler into
911.288Sdrochner * the list.  The handler is called with its (single) argument.
921.1Smrg */
931.1Smrgstruct intrhand {
941.1Smrg	int	(*ih_fun) __P((void *));
951.1Smrg	void	*ih_arg;
961.271Syamt	u_long	ih_count;
971.21Sjonathan	struct	intrhand *ih_next;
981.270Spooka	int	ih_level;
991.21Sjonathan	int	ih_irq;
1001.21Sjonathan};
1011.21Sjonathan
1021.318Smattvoid do_pending_int __P((void));
1031.328Smatt
1041.328Smattstatic __inline int splraise __P((int));
1051.318Smattstatic __inline int spllower __P((int));
1061.318Smattstatic __inline void splx __P((int));
1071.258Sadstatic __inline void softintr __P((int));
1081.207Syamt
1091.207Syamtextern volatile int cpl, ipending, astpending, tickspending;
1101.207Syamtextern int imask[];
1111.207Syamt
1121.207Syamt/*
1131.207Syamt *  Reorder protection in the following inline functions is
1141.207Syamt * achieved with the "eieio" instruction which the assembler
1151.228Syamt * seems to detect and then doesn't move instructions past....
1161.207Syamt */
1171.207Syamtstatic __inline int
1181.207Syamtsplraise(ncpl)
1191.207Syamt	int ncpl;
1201.207Syamt{
1211.207Syamt	int ocpl;
1221.207Syamt
1231.207Syamt	__asm__ volatile("sync; eieio\n");	/* don't reorder.... */
1241.207Syamt	ocpl = cpl;
1251.207Syamt	cpl = ocpl | ncpl;
1261.207Syamt	__asm__ volatile("sync; eieio\n");	/* reorder protect */
1271.207Syamt	return (ocpl);
1281.207Syamt}
1291.207Syamt
1301.207Syamtstatic __inline void
1311.207Syamtsplx(ncpl)
1321.207Syamt	int ncpl;
1331.207Syamt{
1341.207Syamt	__asm__ volatile("sync; eieio\n");	/* reorder protect */
1351.207Syamt	cpl = ncpl;
1361.263Smatt	if (ipending & ~ncpl)
1371.263Smatt		do_pending_int();
1381.263Smatt	__asm__ volatile("sync; eieio\n");	/* reorder protect */
1391.263Smatt}
1401.169Spetrov
1411.87Senamistatic __inline int
1421.1Smrgspllower(ncpl)
1431.1Smrg	int ncpl;
1441.248Sad{
1451.25Sthorpej	int ocpl;
1461.25Sthorpej
1471.248Sad	__asm__ volatile("sync; eieio\n");	/* reorder protect */
1481.25Sthorpej	ocpl = cpl;
1491.26Sthorpej	cpl = ncpl;
1501.248Sad	if (ipending & ~ncpl)
1511.26Sthorpej		do_pending_int();
1521.26Sthorpej	__asm__ volatile("sync; eieio\n");	/* reorder protect */
1531.248Sad	return (ocpl);
1541.130Sthorpej}
1551.40Sthorpej
1561.40Sthorpej/* Following code should be implemented with lwarx/stwcx to avoid
1571.40Sthorpej * the disable/enable. i need to read the manual once more.... */
1581.40Sthorpejstatic __inline void
1591.40Sthorpejsoftintr(ipl)
1601.40Sthorpej	int ipl;
1611.40Sthorpej{
1621.40Sthorpej	int msrsave;
1631.40Sthorpej
1641.40Sthorpej	__asm__ volatile("mfmsr %0" : "=r"(msrsave));
1651.40Sthorpej	__asm__ volatile("mtmsr %0" :: "r"(msrsave & ~PSL_EE));
1661.288Sdrochner	ipending |= 1 << ipl;
1671.290Sdrochner	__asm__ volatile("mtmsr %0" :: "r"(msrsave));
1681.290Sdrochner}
1691.288Sdrochner
1701.290Sdrochner#define	ICU_LEN		32
1711.290Sdrochner
1721.290Sdrochner/* Soft interrupt masks. */
1731.288Sdrochner/*
1741.290Sdrochner#define SIR_CLOCK	28
1751.288Sdrochner#define SIR_NET		29
1761.288Sdrochner#define SIR_SERIAL	30
1771.25Sthorpej*/
1781.1Smrg#define SPL_CLOCK	31
1791.1Smrg
1801.1Smrg/*
1811.1Smrg * Hardware interrupt masks
1821.194Syamt */
1831.194Syamt#define splbio()	splraise(imask[IPL_BIO])
1841.311Spara#define splnet()	splraise(imask[IPL_NET])
1851.194Syamt#define spltty()	splraise(imask[IPL_TTY])
1861.194Syamt#define	splaudio()	splraise(imask[IPL_AUDIO])
1871.194Syamt#define splclock()	splraise(imask[IPL_CLOCK])
1881.194Syamt#define splstatclock()	splclock()
1891.311Spara#define	splserial()	splraise(imask[IPL_SERIAL])
1901.194Syamt
1911.194Syamt/* ADAM: see above
1921.194Syamt#define spllpt()	spltty()
1931.194Syamt*/
1941.194Syamt
1951.194Syamt/*
1961.194Syamt * Software interrupt masks
1971.194Syamt *
1981.1Smrg * NOTE: splsoftclock() is used by hardclock() to lower the priority from
1991.1Smrg * clock to softclock before it calls softclock().
2001.1Smrg */
2011.1Smrg#define	spllowersoftclock() spllower(imask[IPL_SOFTCLOCK])
2021.10Smrg#define	splsoftclock()	splraise(imask[IPL_SOFTCLOCK])
2031.218Syamt#define	splsoftnet()	splraise(imask[IPL_SOFTNET])
2041.10Smrg#define	splsoftserial()	splraise(imask[IPL_SOFTSERIAL])
2051.10Smrg
2061.10Smrg/*
2071.10Smrg * Miscellaneous
2081.10Smrg */
2091.144Syamt#define splvm()		splraise(imask[IPL_VM])
2101.124Sperry#define	splhigh()	splraise(imask[IPL_HIGH])
2111.10Smrg#define	splsched()	splhigh()
2121.1Smrg#define	spllock()	splhigh()
2131.1Smrg#define	spl0()		spllower(0)
2141.1Smrg
2151.1Smrg/*
2161.1Smrg#define	setsoftnet()	softintr(SIR_NET)
2171.10Smrg#define	setsoftserial()	softintr(SIR_SERIAL)
2181.221Syamt*/
2191.221Syamtextern long intrcnt[];
2201.218Syamt
2211.10Smrg#define CNT_IRQ0	0
2221.10Smrg#define CNT_CLOCK	64
2231.10Smrg#define CNT_SOFTCLOCK	65
2241.144Syamt#define CNT_SOFTNET	66
2251.124Sperry#define CNT_SOFTSERIAL	67
2261.1Smrg
2271.1Smrg#endif /* !_LOCORE */
2281.1Smrg
2291.1Smrg#endif /* !_MACPPC_INTR_H_ */
2301.248Sad