Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.5
      1  1.5  mycroft /*	$NetBSD: intr.h,v 1.5 1996/05/13 06:11:28 mycroft Exp $	*/
      2  1.1  mycroft 
      3  1.1  mycroft /*
      4  1.1  mycroft  * Copyright (c) 1996 Charles M. Hannum.  All rights reserved.
      5  1.1  mycroft  *
      6  1.1  mycroft  * Redistribution and use in source and binary forms, with or without
      7  1.1  mycroft  * modification, are permitted provided that the following conditions
      8  1.1  mycroft  * are met:
      9  1.1  mycroft  * 1. Redistributions of source code must retain the above copyright
     10  1.1  mycroft  *    notice, this list of conditions and the following disclaimer.
     11  1.1  mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  mycroft  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  mycroft  *    documentation and/or other materials provided with the distribution.
     14  1.1  mycroft  * 3. All advertising materials mentioning features or use of this software
     15  1.1  mycroft  *    must display the following acknowledgement:
     16  1.1  mycroft  *	This product includes software developed by Charles M. Hannum.
     17  1.1  mycroft  * 4. The name of the author may not be used to endorse or promote products
     18  1.1  mycroft  *    derived from this software without specific prior written permission.
     19  1.1  mycroft  *
     20  1.1  mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.1  mycroft  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.1  mycroft  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.1  mycroft  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.1  mycroft  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.1  mycroft  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.1  mycroft  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.1  mycroft  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.1  mycroft  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.1  mycroft  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.1  mycroft  */
     31  1.1  mycroft 
     32  1.4  mycroft #ifndef _I386_INTR_H_
     33  1.4  mycroft #define _I386_INTR_H_
     34  1.4  mycroft 
     35  1.1  mycroft /* Interrupt priority `levels'; not mutually exclusive. */
     36  1.1  mycroft #define	IPL_BIO		0	/* block I/O */
     37  1.1  mycroft #define	IPL_NET		1	/* network */
     38  1.1  mycroft #define	IPL_TTY		2	/* terminal */
     39  1.1  mycroft #define	IPL_CLOCK	3	/* clock */
     40  1.1  mycroft #define	IPL_IMP		4	/* memory allocation */
     41  1.2  mycroft #define	IPL_NONE	5	/* nothing */
     42  1.2  mycroft #define	IPL_HIGH	6	/* everything */
     43  1.1  mycroft 
     44  1.1  mycroft /* Interrupt sharing types. */
     45  1.1  mycroft #define	IST_NONE	0	/* none */
     46  1.1  mycroft #define	IST_PULSE	1	/* pulsed */
     47  1.1  mycroft #define	IST_EDGE	2	/* edge-triggered */
     48  1.1  mycroft #define	IST_LEVEL	3	/* level-triggered */
     49  1.3  mycroft 
     50  1.3  mycroft /* Soft interrupt masks. */
     51  1.3  mycroft #define	SIR_CLOCK	31
     52  1.3  mycroft #define	SIR_CLOCKMASK	((1 << SIR_CLOCK))
     53  1.3  mycroft #define	SIR_NET		30
     54  1.3  mycroft #define	SIR_NETMASK	((1 << SIR_NET) | SIR_CLOCKMASK)
     55  1.3  mycroft #define	SIR_TTY		29
     56  1.3  mycroft #define	SIR_TTYMASK	((1 << SIR_TTY) | SIR_CLOCKMASK)
     57  1.3  mycroft #define	SIR_ALLMASK	(SIR_CLOCKMASK | SIR_NETMASK | SIR_TTYMASK)
     58  1.3  mycroft 
     59  1.3  mycroft #ifndef _LOCORE
     60  1.3  mycroft 
     61  1.3  mycroft volatile int cpl, ipending, astpending;
     62  1.5  mycroft int imask[7];
     63  1.3  mycroft 
     64  1.3  mycroft extern void Xspllower __P((void));
     65  1.3  mycroft 
     66  1.3  mycroft static __inline int splraise __P((int));
     67  1.3  mycroft static __inline int spllower __P((int));
     68  1.3  mycroft static __inline void splx __P((int));
     69  1.3  mycroft static __inline void softintr __P((int));
     70  1.3  mycroft 
     71  1.3  mycroft /*
     72  1.3  mycroft  * Add a mask to cpl, and return the old value of cpl.
     73  1.3  mycroft  */
     74  1.3  mycroft static __inline int
     75  1.3  mycroft splraise(ncpl)
     76  1.3  mycroft 	register int ncpl;
     77  1.3  mycroft {
     78  1.3  mycroft 	register int ocpl = cpl;
     79  1.3  mycroft 
     80  1.3  mycroft 	cpl = ocpl | ncpl;
     81  1.3  mycroft 	return (ocpl);
     82  1.3  mycroft }
     83  1.3  mycroft 
     84  1.3  mycroft /*
     85  1.3  mycroft  * Restore a value to cpl (unmasking interrupts).  If any unmasked
     86  1.3  mycroft  * interrupts are pending, call Xspllower() to process them.
     87  1.3  mycroft  */
     88  1.3  mycroft static __inline void
     89  1.3  mycroft splx(ncpl)
     90  1.3  mycroft 	register int ncpl;
     91  1.3  mycroft {
     92  1.3  mycroft 
     93  1.3  mycroft 	cpl = ncpl;
     94  1.3  mycroft 	if (ipending & ~ncpl)
     95  1.3  mycroft 		Xspllower();
     96  1.3  mycroft }
     97  1.3  mycroft 
     98  1.3  mycroft /*
     99  1.3  mycroft  * Same as splx(), but we return the old value of spl, for the
    100  1.3  mycroft  * benefit of some splsoftclock() callers.
    101  1.3  mycroft  */
    102  1.3  mycroft static __inline int
    103  1.3  mycroft spllower(ncpl)
    104  1.3  mycroft 	register int ncpl;
    105  1.3  mycroft {
    106  1.3  mycroft 	register int ocpl = cpl;
    107  1.3  mycroft 
    108  1.3  mycroft 	cpl = ncpl;
    109  1.3  mycroft 	if (ipending & ~ncpl)
    110  1.3  mycroft 		Xspllower();
    111  1.3  mycroft 	return (ocpl);
    112  1.3  mycroft }
    113  1.3  mycroft 
    114  1.3  mycroft /*
    115  1.3  mycroft  * Hardware interrupt masks
    116  1.3  mycroft  */
    117  1.3  mycroft #define	splbio()	splraise(imask[IPL_BIO])
    118  1.3  mycroft #define	splnet()	splraise(imask[IPL_NET])
    119  1.3  mycroft #define	spltty()	splraise(imask[IPL_TTY])
    120  1.3  mycroft #define	splclock()	splraise(imask[IPL_CLOCK])
    121  1.3  mycroft #define	splimp()	splraise(imask[IPL_IMP])
    122  1.3  mycroft #define	splstatclock()	splclock()
    123  1.3  mycroft 
    124  1.3  mycroft /*
    125  1.3  mycroft  * Software interrupt masks
    126  1.3  mycroft  *
    127  1.3  mycroft  * NOTE: splsoftclock() is used by hardclock() to lower the priority from
    128  1.3  mycroft  * clock to softclock before it calls softclock().
    129  1.3  mycroft  */
    130  1.3  mycroft #define	splsoftclock()	spllower(SIR_CLOCKMASK)
    131  1.3  mycroft #define	splsoftnet()	splraise(SIR_NETMASK)
    132  1.3  mycroft #define	splsofttty()	splraise(SIR_TTYMASK)
    133  1.3  mycroft 
    134  1.3  mycroft /*
    135  1.3  mycroft  * Miscellaneous
    136  1.3  mycroft  */
    137  1.3  mycroft #define	splhigh()	splraise(-1)
    138  1.3  mycroft #define	spl0()		spllower(0)
    139  1.3  mycroft 
    140  1.3  mycroft /*
    141  1.3  mycroft  * Software interrupt registration
    142  1.3  mycroft  *
    143  1.3  mycroft  * We hand-code this to ensure that it's atomic.
    144  1.3  mycroft  */
    145  1.3  mycroft static __inline void
    146  1.3  mycroft softintr(mask)
    147  1.3  mycroft 	register int mask;
    148  1.3  mycroft {
    149  1.3  mycroft 
    150  1.3  mycroft 	__asm __volatile("orl %0,_ipending" : : "ir" (mask));
    151  1.3  mycroft }
    152  1.3  mycroft 
    153  1.3  mycroft #define	setsoftast()	(astpending = 1)
    154  1.3  mycroft #define	setsoftclock()	softintr(1 << SIR_CLOCK)
    155  1.3  mycroft #define	setsoftnet()	softintr(1 << SIR_NET)
    156  1.3  mycroft #define	setsofttty()	softintr(1 << SIR_TTY)
    157  1.3  mycroft 
    158  1.3  mycroft #endif /* !_LOCORE */
    159  1.4  mycroft 
    160  1.4  mycroft #endif /* !_I386_INTR_H_ */
    161