Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.12.10.4
      1  1.12.10.4  sommerfe /*	$NetBSD: intr.h,v 1.12.10.4 2000/08/12 16:13:01 sommerfeld 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.1  sommerfe #define	NIPL		16
     69        1.1   mycroft 
     70        1.1   mycroft /* Interrupt sharing types. */
     71        1.1   mycroft #define	IST_NONE	0	/* none */
     72        1.1   mycroft #define	IST_PULSE	1	/* pulsed */
     73        1.1   mycroft #define	IST_EDGE	2	/* edge-triggered */
     74        1.1   mycroft #define	IST_LEVEL	3	/* level-triggered */
     75        1.3   mycroft 
     76        1.3   mycroft /* Soft interrupt masks. */
     77        1.3   mycroft #define	SIR_CLOCK	31
     78        1.3   mycroft #define	SIR_NET		30
     79        1.6   mycroft #define	SIR_SERIAL	29
     80        1.3   mycroft 
     81  1.12.10.2  sommerfe /* Hack for CLKF_INTR(). */
     82  1.12.10.2  sommerfe #define	IPL_TAGINTR	28
     83  1.12.10.2  sommerfe 
     84        1.3   mycroft #ifndef _LOCORE
     85        1.3   mycroft 
     86  1.12.10.1  sommerfe #ifdef MULTIPROCESSOR
     87  1.12.10.1  sommerfe #include <machine/i82489reg.h>
     88  1.12.10.1  sommerfe #include <machine/i82489var.h>
     89  1.12.10.1  sommerfe #endif
     90  1.12.10.1  sommerfe 
     91  1.12.10.1  sommerfe extern volatile u_int32_t lapic_tpr;
     92  1.12.10.1  sommerfe volatile u_int32_t ipending;
     93  1.12.10.1  sommerfe 
     94  1.12.10.1  sommerfe #ifndef MULTIPROCESSOR
     95  1.12.10.1  sommerfe volatile u_int32_t astpending;
     96  1.12.10.1  sommerfe #endif
     97  1.12.10.1  sommerfe 
     98  1.12.10.1  sommerfe int imasks[NIPL];
     99  1.12.10.1  sommerfe int iunmask[NIPL];
    100  1.12.10.1  sommerfe 
    101  1.12.10.1  sommerfe #define CPSHIFT 4
    102  1.12.10.1  sommerfe #define IMASK(level) imasks[(level)>>CPSHIFT]
    103  1.12.10.1  sommerfe #define IUNMASK(level) iunmask[(level)>>CPSHIFT]
    104        1.3   mycroft 
    105        1.3   mycroft extern void Xspllower __P((void));
    106        1.3   mycroft 
    107        1.3   mycroft static __inline int splraise __P((int));
    108  1.12.10.2  sommerfe static __inline void spllower __P((int));
    109  1.12.10.1  sommerfe static __inline void softintr __P((int, int));
    110        1.3   mycroft 
    111        1.3   mycroft /*
    112        1.3   mycroft  * Add a mask to cpl, and return the old value of cpl.
    113        1.3   mycroft  */
    114        1.3   mycroft static __inline int
    115        1.3   mycroft splraise(ncpl)
    116        1.3   mycroft 	register int ncpl;
    117        1.3   mycroft {
    118  1.12.10.1  sommerfe 	register int ocpl = lapic_tpr;
    119        1.3   mycroft 
    120  1.12.10.1  sommerfe 	if (ncpl > ocpl)
    121  1.12.10.1  sommerfe 		lapic_tpr = ncpl;
    122        1.3   mycroft 	return (ocpl);
    123        1.3   mycroft }
    124        1.3   mycroft 
    125        1.3   mycroft /*
    126        1.3   mycroft  * Restore a value to cpl (unmasking interrupts).  If any unmasked
    127        1.3   mycroft  * interrupts are pending, call Xspllower() to process them.
    128        1.3   mycroft  */
    129        1.3   mycroft static __inline void
    130        1.3   mycroft spllower(ncpl)
    131        1.3   mycroft 	register int ncpl;
    132        1.3   mycroft {
    133  1.12.10.1  sommerfe 	register int cmask;
    134  1.12.10.2  sommerfe 
    135  1.12.10.1  sommerfe 	lapic_tpr = ncpl;
    136  1.12.10.1  sommerfe 	cmask = IUNMASK(ncpl);
    137  1.12.10.1  sommerfe 	if (ipending & cmask)
    138        1.3   mycroft 		Xspllower();
    139        1.3   mycroft }
    140        1.3   mycroft 
    141        1.3   mycroft /*
    142        1.3   mycroft  * Hardware interrupt masks
    143        1.3   mycroft  */
    144  1.12.10.1  sommerfe #define	splbio()	splraise(IPL_BIO)
    145  1.12.10.1  sommerfe #define	splnet()	splraise(IPL_NET)
    146  1.12.10.1  sommerfe #define	spltty()	splraise(IPL_TTY)
    147  1.12.10.1  sommerfe #define	splaudio()	splraise(IPL_AUDIO)
    148  1.12.10.1  sommerfe #define	splclock()	splraise(IPL_CLOCK)
    149        1.7   mycroft #define	splstatclock()	splclock()
    150  1.12.10.1  sommerfe #define	splserial()	splraise(IPL_SERIAL)
    151  1.12.10.4  sommerfe #define spllock() 	splraise(IPL_SERIAL) /* XXX XXX XXX XXX */
    152  1.12.10.4  sommerfe #define splsched()	splraise(IPL_HIGH)
    153        1.8        is 
    154        1.8        is #define spllpt()	spltty()
    155        1.3   mycroft 
    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.1  sommerfe #define	splhigh()	splraise(IPL_HIGH)
    173  1.12.10.1  sommerfe #define	spl0()		spllower(IPL_NONE)
    174  1.12.10.2  sommerfe #define	splx(x)		spllower(x)
    175        1.3   mycroft 
    176        1.3   mycroft /*
    177        1.3   mycroft  * Software interrupt registration
    178        1.3   mycroft  *
    179        1.3   mycroft  * We hand-code this to ensure that it's atomic.
    180        1.3   mycroft  */
    181        1.3   mycroft static __inline void
    182  1.12.10.1  sommerfe softintr(sir, vec)
    183  1.12.10.1  sommerfe 	register int sir;
    184  1.12.10.1  sommerfe 	register int vec;
    185        1.3   mycroft {
    186  1.12.10.1  sommerfe 	__asm __volatile("orl %1, %0" : "=m"(ipending) : "ir" (1 << sir));
    187  1.12.10.1  sommerfe #ifdef MULTIPROCESSOR
    188  1.12.10.1  sommerfe 	i82489_writereg(LAPIC_ICRLO,
    189  1.12.10.1  sommerfe 	    vec | LAPIC_DLMODE_FIXED | LAPIC_LVL_ASSERT | LAPIC_DEST_SELF);
    190  1.12.10.1  sommerfe #endif
    191        1.3   mycroft }
    192        1.3   mycroft 
    193        1.3   mycroft #define	setsoftast()	(astpending = 1)
    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.1  sommerfe #define I386_IPI_HALT		0x00000001
    200  1.12.10.1  sommerfe #define I386_IPI_TLB		0x00000002
    201  1.12.10.3  sommerfe #define I386_IPI_FPSAVE		0x00000004
    202  1.12.10.1  sommerfe 
    203  1.12.10.1  sommerfe /* the following are for debugging.. */
    204  1.12.10.1  sommerfe #define I386_IPI_GMTB		0x00000010
    205  1.12.10.1  sommerfe #define I386_IPI_NYCHI		0x00000020
    206  1.12.10.1  sommerfe 
    207  1.12.10.1  sommerfe #define I386_NIPI		6
    208  1.12.10.1  sommerfe 
    209  1.12.10.3  sommerfe void i386_send_ipi (struct cpu_info *, int);
    210  1.12.10.1  sommerfe void i386_broadcast_ipi (int);
    211  1.12.10.1  sommerfe void i386_ipi_handler (void);
    212        1.3   mycroft 
    213        1.3   mycroft #endif /* !_LOCORE */
    214        1.4   mycroft 
    215        1.4   mycroft #endif /* !_I386_INTR_H_ */
    216