Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.12.10.10
      1  1.12.10.10   thorpej /*	$NetBSD: intr.h,v 1.12.10.10 2001/01/14 23:18:51 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.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 #ifdef MULTIPROCESSOR
     88   1.12.10.1  sommerfe #include <machine/i82489reg.h>
     89   1.12.10.1  sommerfe #include <machine/i82489var.h>
     90   1.12.10.1  sommerfe #endif
     91   1.12.10.1  sommerfe 
     92   1.12.10.1  sommerfe extern volatile u_int32_t lapic_tpr;
     93   1.12.10.1  sommerfe volatile u_int32_t ipending;
     94   1.12.10.1  sommerfe 
     95   1.12.10.1  sommerfe int imasks[NIPL];
     96   1.12.10.1  sommerfe int iunmask[NIPL];
     97   1.12.10.1  sommerfe 
     98   1.12.10.1  sommerfe #define CPSHIFT 4
     99   1.12.10.1  sommerfe #define IMASK(level) imasks[(level)>>CPSHIFT]
    100   1.12.10.1  sommerfe #define IUNMASK(level) iunmask[(level)>>CPSHIFT]
    101         1.3   mycroft 
    102         1.3   mycroft extern void Xspllower __P((void));
    103         1.3   mycroft 
    104         1.3   mycroft static __inline int splraise __P((int));
    105   1.12.10.2  sommerfe static __inline void spllower __P((int));
    106   1.12.10.1  sommerfe static __inline void softintr __P((int, int));
    107         1.3   mycroft 
    108         1.3   mycroft /*
    109         1.3   mycroft  * Add a mask to cpl, and return the old value of cpl.
    110         1.3   mycroft  */
    111         1.3   mycroft static __inline int
    112         1.3   mycroft splraise(ncpl)
    113         1.3   mycroft 	register int ncpl;
    114         1.3   mycroft {
    115   1.12.10.1  sommerfe 	register int ocpl = lapic_tpr;
    116         1.3   mycroft 
    117   1.12.10.1  sommerfe 	if (ncpl > ocpl)
    118   1.12.10.1  sommerfe 		lapic_tpr = ncpl;
    119         1.3   mycroft 	return (ocpl);
    120         1.3   mycroft }
    121         1.3   mycroft 
    122         1.3   mycroft /*
    123         1.3   mycroft  * Restore a value to cpl (unmasking interrupts).  If any unmasked
    124         1.3   mycroft  * interrupts are pending, call Xspllower() to process them.
    125         1.3   mycroft  */
    126         1.3   mycroft static __inline void
    127         1.3   mycroft spllower(ncpl)
    128         1.3   mycroft 	register int ncpl;
    129         1.3   mycroft {
    130   1.12.10.1  sommerfe 	register int cmask;
    131   1.12.10.2  sommerfe 
    132   1.12.10.1  sommerfe 	lapic_tpr = ncpl;
    133   1.12.10.1  sommerfe 	cmask = IUNMASK(ncpl);
    134   1.12.10.1  sommerfe 	if (ipending & cmask)
    135         1.3   mycroft 		Xspllower();
    136         1.3   mycroft }
    137         1.3   mycroft 
    138         1.3   mycroft /*
    139         1.3   mycroft  * Hardware interrupt masks
    140         1.3   mycroft  */
    141   1.12.10.1  sommerfe #define	splbio()	splraise(IPL_BIO)
    142   1.12.10.1  sommerfe #define	splnet()	splraise(IPL_NET)
    143   1.12.10.1  sommerfe #define	spltty()	splraise(IPL_TTY)
    144   1.12.10.1  sommerfe #define	splaudio()	splraise(IPL_AUDIO)
    145   1.12.10.1  sommerfe #define	splclock()	splraise(IPL_CLOCK)
    146         1.7   mycroft #define	splstatclock()	splclock()
    147   1.12.10.1  sommerfe #define	splserial()	splraise(IPL_SERIAL)
    148   1.12.10.4  sommerfe #define spllock() 	splraise(IPL_SERIAL) /* XXX XXX XXX XXX */
    149   1.12.10.4  sommerfe #define splsched()	splraise(IPL_HIGH)
    150   1.12.10.5  sommerfe #define splipi()	splraise(IPL_IPI)
    151         1.8        is 
    152         1.8        is #define spllpt()	spltty()
    153         1.3   mycroft 
    154   1.12.10.5  sommerfe #define SPL_ASSERT_ATMOST(x) KDASSERT(lapic_tpr <= (x))
    155   1.12.10.5  sommerfe 
    156         1.3   mycroft /*
    157         1.3   mycroft  * Software interrupt masks
    158         1.3   mycroft  *
    159         1.3   mycroft  * NOTE: splsoftclock() is used by hardclock() to lower the priority from
    160         1.3   mycroft  * clock to softclock before it calls softclock().
    161         1.3   mycroft  */
    162   1.12.10.1  sommerfe #define	spllowersoftclock() spllower(IPL_SOFTCLOCK)
    163   1.12.10.1  sommerfe 
    164   1.12.10.1  sommerfe #define	splsoftclock()	splraise(IPL_SOFTCLOCK)
    165   1.12.10.1  sommerfe #define	splsoftnet()	splraise(IPL_SOFTNET)
    166   1.12.10.1  sommerfe #define	splsoftserial()	splraise(IPL_SOFTSERIAL)
    167         1.3   mycroft 
    168         1.3   mycroft /*
    169         1.3   mycroft  * Miscellaneous
    170         1.3   mycroft  */
    171   1.12.10.1  sommerfe #define	splimp()	splraise(IPL_IMP)
    172  1.12.10.10   thorpej #define	splvm()		splraise(IPL_IMP)
    173   1.12.10.1  sommerfe #define	splhigh()	splraise(IPL_HIGH)
    174   1.12.10.1  sommerfe #define	spl0()		spllower(IPL_NONE)
    175   1.12.10.2  sommerfe #define	splx(x)		spllower(x)
    176         1.3   mycroft 
    177         1.3   mycroft /*
    178         1.3   mycroft  * Software interrupt registration
    179         1.3   mycroft  *
    180         1.3   mycroft  * We hand-code this to ensure that it's atomic.
    181         1.3   mycroft  */
    182         1.3   mycroft static __inline void
    183   1.12.10.1  sommerfe softintr(sir, vec)
    184   1.12.10.1  sommerfe 	register int sir;
    185   1.12.10.1  sommerfe 	register int vec;
    186         1.3   mycroft {
    187   1.12.10.1  sommerfe 	__asm __volatile("orl %1, %0" : "=m"(ipending) : "ir" (1 << sir));
    188   1.12.10.1  sommerfe #ifdef MULTIPROCESSOR
    189   1.12.10.1  sommerfe 	i82489_writereg(LAPIC_ICRLO,
    190   1.12.10.1  sommerfe 	    vec | LAPIC_DLMODE_FIXED | LAPIC_LVL_ASSERT | LAPIC_DEST_SELF);
    191   1.12.10.1  sommerfe #endif
    192         1.3   mycroft }
    193         1.3   mycroft 
    194   1.12.10.1  sommerfe #define	setsoftclock()	softintr(SIR_CLOCK,IPL_SOFTCLOCK)
    195   1.12.10.1  sommerfe #define	setsoftnet()	softintr(SIR_NET,IPL_SOFTNET)
    196   1.12.10.1  sommerfe #define	setsoftserial()	softintr(SIR_SERIAL,IPL_SOFTSERIAL)
    197   1.12.10.1  sommerfe 
    198   1.12.10.1  sommerfe 
    199   1.12.10.5  sommerfe #define I386_IPI_HALT			0x00000001
    200   1.12.10.5  sommerfe #define I386_IPI_FLUSH_FPU		0x00000002
    201   1.12.10.5  sommerfe #define I386_IPI_SYNCH_FPU		0x00000004
    202   1.12.10.5  sommerfe #define I386_IPI_TLB			0x00000008
    203   1.12.10.8  sommerfe #define I386_IPI_MTRR			0x00000010
    204   1.12.10.1  sommerfe 
    205   1.12.10.8  sommerfe #define I386_NIPI		5
    206   1.12.10.1  sommerfe 
    207   1.12.10.7  sommerfe #ifdef MULTIPROCESSOR
    208   1.12.10.3  sommerfe void i386_send_ipi (struct cpu_info *, int);
    209   1.12.10.1  sommerfe void i386_broadcast_ipi (int);
    210   1.12.10.9   thorpej void i386_multicast_ipi (int, int);
    211   1.12.10.1  sommerfe void i386_ipi_handler (void);
    212   1.12.10.7  sommerfe #endif
    213         1.3   mycroft 
    214         1.3   mycroft #endif /* !_LOCORE */
    215         1.4   mycroft 
    216         1.4   mycroft #endif /* !_I386_INTR_H_ */
    217