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