Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.12.10.1
      1 /*	$NetBSD: intr.h,v 1.12.10.1 2000/02/20 17:41:33 sommerfeld Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Charles M. Hannum.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #ifndef _I386_INTR_H_
     40 #define _I386_INTR_H_
     41 
     42 /*
     43  * Interrupt priority levels.
     44  *
     45  * There are tty, network and disk drivers that use free() at interrupt
     46  * time, so imp > (tty | net | bio).
     47  *
     48  * Since run queues may be manipulated by both the statclock and tty,
     49  * network, and disk drivers, clock > imp.
     50  *
     51  * IPL_HIGH must block everything that can manipulate a run queue.
     52  *
     53  * We need serial drivers to run at the absolute highest priority to
     54  * avoid overruns, so serial > high.
     55  */
     56 #define	IPL_NONE	0x00	/* nothing */
     57 #define	IPL_SOFTCLOCK	0x50	/* timeouts */
     58 #define	IPL_SOFTNET	0x60	/* protocol stacks */
     59 #define	IPL_BIO		0x70	/* block I/O */
     60 #define	IPL_NET		0x80	/* network */
     61 #define	IPL_SOFTSERIAL	0x90	/* serial */
     62 #define	IPL_TTY		0xa0	/* terminal */
     63 #define	IPL_IMP		0xb0	/* memory allocation */
     64 #define	IPL_AUDIO	0xc0	/* audio */
     65 #define	IPL_CLOCK	0xd0	/* clock */
     66 #define	IPL_HIGH	0xd0	/* everything */
     67 #define	IPL_SERIAL	0xe0	/* serial */
     68 #define	NIPL		16
     69 
     70 /* Interrupt sharing types. */
     71 #define	IST_NONE	0	/* none */
     72 #define	IST_PULSE	1	/* pulsed */
     73 #define	IST_EDGE	2	/* edge-triggered */
     74 #define	IST_LEVEL	3	/* level-triggered */
     75 
     76 /* Soft interrupt masks. */
     77 #define	SIR_CLOCK	31
     78 #define	SIR_NET		30
     79 #define	SIR_SERIAL	29
     80 
     81 #ifndef _LOCORE
     82 
     83 #ifdef MULTIPROCESSOR
     84 #include <machine/i82489reg.h>
     85 #include <machine/i82489var.h>
     86 #endif
     87 
     88 extern volatile u_int32_t lapic_tpr;
     89 volatile u_int32_t ipending;
     90 
     91 #ifndef MULTIPROCESSOR
     92 volatile u_int32_t astpending;
     93 #endif
     94 
     95 int imasks[NIPL];
     96 int iunmask[NIPL];
     97 
     98 #define CPSHIFT 4
     99 #define IMASK(level) imasks[(level)>>CPSHIFT]
    100 #define IUNMASK(level) iunmask[(level)>>CPSHIFT]
    101 
    102 extern void Xspllower __P((void));
    103 
    104 static __inline int splraise __P((int));
    105 static __inline int spllower __P((int));
    106 static __inline void splx __P((int));
    107 static __inline void softintr __P((int, int));
    108 
    109 /*
    110  * Add a mask to cpl, and return the old value of cpl.
    111  */
    112 static __inline int
    113 splraise(ncpl)
    114 	register int ncpl;
    115 {
    116 	register int ocpl = lapic_tpr;
    117 
    118 	if (ncpl > ocpl)
    119 		lapic_tpr = ncpl;
    120 	return (ocpl);
    121 }
    122 
    123 /*
    124  * Restore a value to cpl (unmasking interrupts).  If any unmasked
    125  * interrupts are pending, call Xspllower() to process them.
    126  */
    127 static __inline void
    128 splx(ncpl)
    129 	register int ncpl;
    130 {
    131 	register int cmask;
    132 
    133 	lapic_tpr = ncpl;
    134 	cmask = IUNMASK(ncpl);
    135 	if (ipending & cmask)
    136 		Xspllower();
    137 }
    138 
    139 /*
    140  * Same as splx(), but we return the old value of spl, for the
    141  * benefit of some splsoftclock() callers.
    142  */
    143 static __inline int
    144 spllower(ncpl)
    145 	register int ncpl;
    146 {
    147 	register int ocpl = lapic_tpr;
    148 	register int cmask;
    149 
    150 	lapic_tpr = ncpl;
    151 	cmask = IUNMASK(ncpl);
    152 	if (ipending & cmask)
    153 		Xspllower();
    154 	return (ocpl);
    155 }
    156 
    157 /*
    158  * Hardware interrupt masks
    159  */
    160 #define	splbio()	splraise(IPL_BIO)
    161 #define	splnet()	splraise(IPL_NET)
    162 #define	spltty()	splraise(IPL_TTY)
    163 #define	splaudio()	splraise(IPL_AUDIO)
    164 #define	splclock()	splraise(IPL_CLOCK)
    165 #define	splstatclock()	splclock()
    166 #define	splserial()	splraise(IPL_SERIAL)
    167 
    168 #define spllpt()	spltty()
    169 
    170 /*
    171  * Software interrupt masks
    172  *
    173  * NOTE: splsoftclock() is used by hardclock() to lower the priority from
    174  * clock to softclock before it calls softclock().
    175  */
    176 #define	spllowersoftclock() spllower(IPL_SOFTCLOCK)
    177 
    178 #define	splsoftclock()	splraise(IPL_SOFTCLOCK)
    179 #define	splsoftnet()	splraise(IPL_SOFTNET)
    180 #define	splsoftserial()	splraise(IPL_SOFTSERIAL)
    181 
    182 /*
    183  * Miscellaneous
    184  */
    185 #define	splimp()	splraise(IPL_IMP)
    186 #define	splhigh()	splraise(IPL_HIGH)
    187 #define	spl0()		spllower(IPL_NONE)
    188 
    189 /*
    190  * Software interrupt registration
    191  *
    192  * We hand-code this to ensure that it's atomic.
    193  */
    194 static __inline void
    195 softintr(sir, vec)
    196 	register int sir;
    197 	register int vec;
    198 {
    199 	__asm __volatile("orl %1, %0" : "=m"(ipending) : "ir" (1 << sir));
    200 #ifdef MULTIPROCESSOR
    201 	i82489_writereg(LAPIC_ICRLO,
    202 	    vec | LAPIC_DLMODE_FIXED | LAPIC_LVL_ASSERT | LAPIC_DEST_SELF);
    203 #endif
    204 }
    205 
    206 #define	setsoftast()	(astpending = 1)
    207 #define	setsoftclock()	softintr(SIR_CLOCK,IPL_SOFTCLOCK)
    208 #define	setsoftnet()	softintr(SIR_NET,IPL_SOFTNET)
    209 #define	setsoftserial()	softintr(SIR_SERIAL,IPL_SOFTSERIAL)
    210 
    211 
    212 #define I386_IPI_HALT		0x00000001
    213 #define I386_IPI_TLB		0x00000002
    214 
    215 /* the following are for debugging.. */
    216 #define I386_IPI_GMTB		0x00000010
    217 #define I386_IPI_NYCHI		0x00000020
    218 
    219 #define I386_NIPI		6
    220 
    221 void i386_send_ipi (int, int);
    222 void i386_broadcast_ipi (int);
    223 void i386_ipi_handler (void);
    224 
    225 #endif /* !_LOCORE */
    226 
    227 #endif /* !_I386_INTR_H_ */
    228