Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.12.10.13
      1  1.12.10.13  sommerfe /*	$NetBSD: intr.h,v 1.12.10.13 2001/04/30 20:36:38 sommerfeld Exp $	*/
      2         1.1   mycroft 
      3         1.9   mycroft /*-
      4  1.12.10.11  sommerfe  * Copyright (c) 1998, 2001 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.12.10.11  sommerfe  * by Charles M. Hannum, and by Jason R. Thorpe.
      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.12.10.1  sommerfe /*
     43   1.12.10.1  sommerfe  * Interrupt priority levels.
     44   1.12.10.1  sommerfe  *
     45   1.12.10.1  sommerfe  * There are tty, network and disk drivers that use free() at interrupt
     46   1.12.10.1  sommerfe  * time, so imp > (tty | net | bio).
     47   1.12.10.1  sommerfe  *
     48   1.12.10.1  sommerfe  * Since run queues may be manipulated by both the statclock and tty,
     49   1.12.10.1  sommerfe  * network, and disk drivers, clock > imp.
     50   1.12.10.1  sommerfe  *
     51   1.12.10.1  sommerfe  * IPL_HIGH must block everything that can manipulate a run queue.
     52   1.12.10.1  sommerfe  *
     53   1.12.10.1  sommerfe  * We need serial drivers to run at the absolute highest priority to
     54   1.12.10.1  sommerfe  * avoid overruns, so serial > high.
     55   1.12.10.1  sommerfe  */
     56   1.12.10.1  sommerfe #define	IPL_NONE	0x00	/* nothing */
     57   1.12.10.1  sommerfe #define	IPL_SOFTCLOCK	0x50	/* timeouts */
     58   1.12.10.1  sommerfe #define	IPL_SOFTNET	0x60	/* protocol stacks */
     59   1.12.10.1  sommerfe #define	IPL_BIO		0x70	/* block I/O */
     60   1.12.10.1  sommerfe #define	IPL_NET		0x80	/* network */
     61   1.12.10.1  sommerfe #define	IPL_SOFTSERIAL	0x90	/* serial */
     62   1.12.10.1  sommerfe #define	IPL_TTY		0xa0	/* terminal */
     63   1.12.10.1  sommerfe #define	IPL_IMP		0xb0	/* memory allocation */
     64   1.12.10.1  sommerfe #define	IPL_AUDIO	0xc0	/* audio */
     65   1.12.10.1  sommerfe #define	IPL_CLOCK	0xd0	/* clock */
     66   1.12.10.1  sommerfe #define	IPL_HIGH	0xd0	/* everything */
     67   1.12.10.1  sommerfe #define	IPL_SERIAL	0xe0	/* serial */
     68   1.12.10.5  sommerfe #define IPL_IPI		0xe0	/* inter-processor interrupts */
     69   1.12.10.1  sommerfe #define	NIPL		16
     70         1.1   mycroft 
     71         1.1   mycroft /* Interrupt sharing types. */
     72         1.1   mycroft #define	IST_NONE	0	/* none */
     73         1.1   mycroft #define	IST_PULSE	1	/* pulsed */
     74         1.1   mycroft #define	IST_EDGE	2	/* edge-triggered */
     75         1.1   mycroft #define	IST_LEVEL	3	/* level-triggered */
     76         1.3   mycroft 
     77         1.3   mycroft /* Soft interrupt masks. */
     78         1.3   mycroft #define	SIR_CLOCK	31
     79         1.3   mycroft #define	SIR_NET		30
     80         1.6   mycroft #define	SIR_SERIAL	29
     81         1.3   mycroft 
     82   1.12.10.2  sommerfe /* Hack for CLKF_INTR(). */
     83   1.12.10.2  sommerfe #define	IPL_TAGINTR	28
     84   1.12.10.2  sommerfe 
     85         1.3   mycroft #ifndef _LOCORE
     86         1.3   mycroft 
     87   1.12.10.1  sommerfe extern volatile u_int32_t lapic_tpr;
     88   1.12.10.1  sommerfe volatile u_int32_t ipending;
     89   1.12.10.1  sommerfe 
     90   1.12.10.1  sommerfe int imasks[NIPL];
     91   1.12.10.1  sommerfe int iunmask[NIPL];
     92   1.12.10.1  sommerfe 
     93   1.12.10.1  sommerfe #define CPSHIFT 4
     94   1.12.10.1  sommerfe #define IMASK(level) imasks[(level)>>CPSHIFT]
     95   1.12.10.1  sommerfe #define IUNMASK(level) iunmask[(level)>>CPSHIFT]
     96         1.3   mycroft 
     97         1.3   mycroft extern void Xspllower __P((void));
     98         1.3   mycroft 
     99         1.3   mycroft static __inline int splraise __P((int));
    100   1.12.10.2  sommerfe static __inline void spllower __P((int));
    101  1.12.10.11  sommerfe static __inline void softintr __P((int));
    102         1.3   mycroft 
    103         1.3   mycroft /*
    104         1.3   mycroft  * Add a mask to cpl, and return the old value of cpl.
    105         1.3   mycroft  */
    106         1.3   mycroft static __inline int
    107         1.3   mycroft splraise(ncpl)
    108         1.3   mycroft 	register int ncpl;
    109         1.3   mycroft {
    110   1.12.10.1  sommerfe 	register int ocpl = lapic_tpr;
    111         1.3   mycroft 
    112   1.12.10.1  sommerfe 	if (ncpl > ocpl)
    113   1.12.10.1  sommerfe 		lapic_tpr = ncpl;
    114         1.3   mycroft 	return (ocpl);
    115         1.3   mycroft }
    116         1.3   mycroft 
    117         1.3   mycroft /*
    118         1.3   mycroft  * Restore a value to cpl (unmasking interrupts).  If any unmasked
    119         1.3   mycroft  * interrupts are pending, call Xspllower() to process them.
    120         1.3   mycroft  */
    121         1.3   mycroft static __inline void
    122         1.3   mycroft spllower(ncpl)
    123         1.3   mycroft 	register int ncpl;
    124         1.3   mycroft {
    125   1.12.10.1  sommerfe 	register int cmask;
    126   1.12.10.2  sommerfe 
    127   1.12.10.1  sommerfe 	lapic_tpr = ncpl;
    128   1.12.10.1  sommerfe 	cmask = IUNMASK(ncpl);
    129   1.12.10.1  sommerfe 	if (ipending & cmask)
    130         1.3   mycroft 		Xspllower();
    131         1.3   mycroft }
    132         1.3   mycroft 
    133         1.3   mycroft /*
    134         1.3   mycroft  * Hardware interrupt masks
    135         1.3   mycroft  */
    136   1.12.10.1  sommerfe #define	splbio()	splraise(IPL_BIO)
    137   1.12.10.1  sommerfe #define	splnet()	splraise(IPL_NET)
    138   1.12.10.1  sommerfe #define	spltty()	splraise(IPL_TTY)
    139   1.12.10.1  sommerfe #define	splaudio()	splraise(IPL_AUDIO)
    140   1.12.10.1  sommerfe #define	splclock()	splraise(IPL_CLOCK)
    141         1.7   mycroft #define	splstatclock()	splclock()
    142   1.12.10.1  sommerfe #define	splserial()	splraise(IPL_SERIAL)
    143   1.12.10.5  sommerfe #define splipi()	splraise(IPL_IPI)
    144         1.8        is 
    145         1.8        is #define spllpt()	spltty()
    146         1.3   mycroft 
    147   1.12.10.5  sommerfe #define SPL_ASSERT_ATMOST(x) KDASSERT(lapic_tpr <= (x))
    148   1.12.10.5  sommerfe 
    149         1.3   mycroft /*
    150         1.3   mycroft  * Software interrupt masks
    151         1.3   mycroft  *
    152         1.3   mycroft  * NOTE: splsoftclock() is used by hardclock() to lower the priority from
    153         1.3   mycroft  * clock to softclock before it calls softclock().
    154         1.3   mycroft  */
    155   1.12.10.1  sommerfe #define	spllowersoftclock() spllower(IPL_SOFTCLOCK)
    156   1.12.10.1  sommerfe 
    157   1.12.10.1  sommerfe #define	splsoftclock()	splraise(IPL_SOFTCLOCK)
    158   1.12.10.1  sommerfe #define	splsoftnet()	splraise(IPL_SOFTNET)
    159   1.12.10.1  sommerfe #define	splsoftserial()	splraise(IPL_SOFTSERIAL)
    160         1.3   mycroft 
    161         1.3   mycroft /*
    162         1.3   mycroft  * Miscellaneous
    163         1.3   mycroft  */
    164  1.12.10.10   thorpej #define	splvm()		splraise(IPL_IMP)
    165   1.12.10.1  sommerfe #define	splhigh()	splraise(IPL_HIGH)
    166   1.12.10.1  sommerfe #define	spl0()		spllower(IPL_NONE)
    167  1.12.10.11  sommerfe #define	splsched()	splhigh()
    168  1.12.10.11  sommerfe #define spllock() 	splraise(IPL_SERIAL) /* XXX XXX XXX XXX */
    169   1.12.10.2  sommerfe #define	splx(x)		spllower(x)
    170         1.3   mycroft 
    171         1.3   mycroft /*
    172         1.3   mycroft  * Software interrupt registration
    173         1.3   mycroft  *
    174         1.3   mycroft  * We hand-code this to ensure that it's atomic.
    175         1.3   mycroft  */
    176         1.3   mycroft static __inline void
    177  1.12.10.11  sommerfe softintr(register int sir)
    178         1.3   mycroft {
    179   1.12.10.1  sommerfe 	__asm __volatile("orl %1, %0" : "=m"(ipending) : "ir" (1 << sir));
    180         1.3   mycroft }
    181         1.3   mycroft 
    182  1.12.10.11  sommerfe #define	setsoftnet()	softintr(SIR_NET)
    183   1.12.10.1  sommerfe 
    184  1.12.10.13  sommerfe /* XXX does ipi goo belong here, or elsewhere? */
    185  1.12.10.13  sommerfe 
    186   1.12.10.5  sommerfe #define I386_IPI_HALT			0x00000001
    187   1.12.10.5  sommerfe #define I386_IPI_FLUSH_FPU		0x00000002
    188   1.12.10.5  sommerfe #define I386_IPI_SYNCH_FPU		0x00000004
    189   1.12.10.5  sommerfe #define I386_IPI_TLB			0x00000008
    190   1.12.10.8  sommerfe #define I386_IPI_MTRR			0x00000010
    191   1.12.10.1  sommerfe 
    192   1.12.10.8  sommerfe #define I386_NIPI		5
    193   1.12.10.1  sommerfe 
    194   1.12.10.7  sommerfe #ifdef MULTIPROCESSOR
    195  1.12.10.13  sommerfe struct cpu_info;
    196  1.12.10.13  sommerfe 
    197   1.12.10.3  sommerfe void i386_send_ipi (struct cpu_info *, int);
    198   1.12.10.1  sommerfe void i386_broadcast_ipi (int);
    199   1.12.10.9   thorpej void i386_multicast_ipi (int, int);
    200   1.12.10.1  sommerfe void i386_ipi_handler (void);
    201   1.12.10.7  sommerfe #endif
    202         1.3   mycroft 
    203         1.3   mycroft #endif /* !_LOCORE */
    204  1.12.10.11  sommerfe 
    205  1.12.10.11  sommerfe /*
    206  1.12.10.11  sommerfe  * Generic software interrupt support.
    207  1.12.10.11  sommerfe  */
    208  1.12.10.11  sommerfe 
    209  1.12.10.11  sommerfe #define	I386_SOFTINTR_SOFTCLOCK		0
    210  1.12.10.11  sommerfe #define	I386_SOFTINTR_SOFTNET		1
    211  1.12.10.11  sommerfe #define	I386_SOFTINTR_SOFTSERIAL	2
    212  1.12.10.11  sommerfe #define	I386_NSOFTINTR			3
    213  1.12.10.11  sommerfe 
    214  1.12.10.11  sommerfe #ifndef _LOCORE
    215  1.12.10.11  sommerfe #include <sys/queue.h>
    216  1.12.10.11  sommerfe 
    217  1.12.10.11  sommerfe struct i386_soft_intrhand {
    218  1.12.10.11  sommerfe 	TAILQ_ENTRY(i386_soft_intrhand)
    219  1.12.10.11  sommerfe 		sih_q;
    220  1.12.10.11  sommerfe 	struct i386_soft_intr *sih_intrhead;
    221  1.12.10.11  sommerfe 	void	(*sih_fn)(void *);
    222  1.12.10.11  sommerfe 	void	*sih_arg;
    223  1.12.10.11  sommerfe 	int	sih_pending;
    224  1.12.10.11  sommerfe };
    225  1.12.10.11  sommerfe 
    226  1.12.10.11  sommerfe struct i386_soft_intr {
    227  1.12.10.11  sommerfe 	TAILQ_HEAD(, i386_soft_intrhand)
    228  1.12.10.11  sommerfe 		softintr_q;
    229  1.12.10.11  sommerfe 	int softintr_ssir;
    230  1.12.10.11  sommerfe };
    231  1.12.10.11  sommerfe 
    232  1.12.10.11  sommerfe #define	i386_softintr_lock(si, s)					\
    233  1.12.10.11  sommerfe do {									\
    234  1.12.10.11  sommerfe 	(s) = splhigh();						\
    235  1.12.10.12  sommerfe } while (/*CONSTCOND*/ 0)
    236  1.12.10.11  sommerfe 
    237  1.12.10.11  sommerfe #define	i386_softintr_unlock(si, s)					\
    238  1.12.10.11  sommerfe do {									\
    239  1.12.10.11  sommerfe 	splx((s));							\
    240  1.12.10.12  sommerfe } while (/*CONSTCOND*/ 0)
    241  1.12.10.11  sommerfe 
    242  1.12.10.11  sommerfe void	*softintr_establish(int, void (*)(void *), void *);
    243  1.12.10.11  sommerfe void	softintr_disestablish(void *);
    244  1.12.10.11  sommerfe void	softintr_init(void);
    245  1.12.10.11  sommerfe void	softintr_dispatch(int);
    246  1.12.10.11  sommerfe 
    247  1.12.10.11  sommerfe #define	softintr_schedule(arg)						\
    248  1.12.10.11  sommerfe do {									\
    249  1.12.10.11  sommerfe 	struct i386_soft_intrhand *__sih = (arg);			\
    250  1.12.10.11  sommerfe 	struct i386_soft_intr *__si = __sih->sih_intrhead;		\
    251  1.12.10.11  sommerfe 	int __s;							\
    252  1.12.10.11  sommerfe 									\
    253  1.12.10.11  sommerfe 	i386_softintr_lock(__si, __s);					\
    254  1.12.10.11  sommerfe 	if (__sih->sih_pending == 0) {					\
    255  1.12.10.11  sommerfe 		TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q);	\
    256  1.12.10.11  sommerfe 		__sih->sih_pending = 1;					\
    257  1.12.10.11  sommerfe 		softintr(__si->softintr_ssir);				\
    258  1.12.10.11  sommerfe 	}								\
    259  1.12.10.11  sommerfe 	i386_softintr_unlock(__si, __s);				\
    260  1.12.10.12  sommerfe } while (/*CONSTCOND*/ 0)
    261  1.12.10.11  sommerfe #endif /* _LOCORE */
    262         1.4   mycroft 
    263         1.4   mycroft #endif /* !_I386_INTR_H_ */
    264