Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.3
      1  1.3  bouyer /*	$NetBSD: intr.h,v 1.3 2005/04/16 22:49:37 bouyer Exp $	*/
      2  1.3  bouyer /*	NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp	*/
      3  1.3  bouyer 
      4  1.3  bouyer /*-
      5  1.3  bouyer  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
      6  1.3  bouyer  * All rights reserved.
      7  1.3  bouyer  *
      8  1.3  bouyer  * This code is derived from software contributed to The NetBSD Foundation
      9  1.3  bouyer  * by Charles M. Hannum, and by Jason R. Thorpe.
     10  1.3  bouyer  *
     11  1.3  bouyer  * Redistribution and use in source and binary forms, with or without
     12  1.3  bouyer  * modification, are permitted provided that the following conditions
     13  1.3  bouyer  * are met:
     14  1.3  bouyer  * 1. Redistributions of source code must retain the above copyright
     15  1.3  bouyer  *    notice, this list of conditions and the following disclaimer.
     16  1.3  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.3  bouyer  *    notice, this list of conditions and the following disclaimer in the
     18  1.3  bouyer  *    documentation and/or other materials provided with the distribution.
     19  1.3  bouyer  * 3. All advertising materials mentioning features or use of this software
     20  1.3  bouyer  *    must display the following acknowledgement:
     21  1.3  bouyer  *        This product includes software developed by the NetBSD
     22  1.3  bouyer  *        Foundation, Inc. and its contributors.
     23  1.3  bouyer  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.3  bouyer  *    contributors may be used to endorse or promote products derived
     25  1.3  bouyer  *    from this software without specific prior written permission.
     26  1.3  bouyer  *
     27  1.3  bouyer  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.3  bouyer  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.3  bouyer  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.3  bouyer  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.3  bouyer  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.3  bouyer  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.3  bouyer  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.3  bouyer  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.3  bouyer  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.3  bouyer  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.3  bouyer  * POSSIBILITY OF SUCH DAMAGE.
     38  1.3  bouyer  */
     39  1.1      cl 
     40  1.1      cl 
     41  1.1      cl #ifndef _XEN_INTR_H_
     42  1.1      cl #define	_XEN_INTR_H_
     43  1.1      cl 
     44  1.3  bouyer #include <machine/intrdefs.h>
     45  1.1      cl 
     46  1.1      cl #ifndef _LOCORE
     47  1.3  bouyer #include <machine/cpu.h>
     48  1.3  bouyer #include <machine/pic.h>
     49  1.3  bouyer 
     50  1.3  bouyer /*
     51  1.3  bouyer  * Struct describing an event channel.
     52  1.3  bouyer  */
     53  1.3  bouyer 
     54  1.3  bouyer struct evtsource {
     55  1.3  bouyer 	int ev_maxlevel;		/* max. IPL for this source */
     56  1.3  bouyer 	u_int32_t ev_imask;		/* interrupt mask */
     57  1.3  bouyer 	struct intrhand *ev_handlers;	/* handler chain */
     58  1.3  bouyer 	struct evcnt ev_evcnt;		/* interrupt counter */
     59  1.3  bouyer 	char ev_evname[32];		/* event counter name */
     60  1.3  bouyer };
     61  1.3  bouyer 
     62  1.3  bouyer /*
     63  1.3  bouyer  * Structure describing an interrupt level. struct cpu_info has an array of
     64  1.3  bouyer  * IPL_MAX of theses. The index in the array is equal to the stub number of
     65  1.3  bouyer  * the stubcode as present in vector.s
     66  1.3  bouyer  */
     67  1.3  bouyer 
     68  1.3  bouyer struct intrstub {
     69  1.3  bouyer #if 0
     70  1.3  bouyer 	void *ist_entry;
     71  1.3  bouyer #endif
     72  1.3  bouyer 	void *ist_recurse;
     73  1.3  bouyer 	void *ist_resume;
     74  1.3  bouyer };
     75  1.3  bouyer 
     76  1.3  bouyer struct iplsource {
     77  1.3  bouyer 	struct intrhand *ipl_handlers;   /* handler chain */
     78  1.3  bouyer 	void *ipl_recurse;               /* entry for spllower */
     79  1.3  bouyer 	void *ipl_resume;                /* entry for doreti */
     80  1.3  bouyer 	u_int32_t ipl_evt_mask1;	/* pending events for this IPL */
     81  1.3  bouyer 	u_int32_t ipl_evt_mask2[NR_EVENT_CHANNELS];
     82  1.3  bouyer };
     83  1.3  bouyer 
     84  1.3  bouyer 
     85  1.3  bouyer 
     86  1.3  bouyer /*
     87  1.3  bouyer  * Interrupt handler chains. These are linked in both the evtsource and
     88  1.3  bouyer  * the iplsource.
     89  1.3  bouyer  * The handler is called with its (single) argument.
     90  1.3  bouyer  */
     91  1.3  bouyer 
     92  1.3  bouyer struct intrhand {
     93  1.3  bouyer 	int	(*ih_fun)(void *);
     94  1.3  bouyer 	void	*ih_arg;
     95  1.3  bouyer 	int	ih_level;
     96  1.3  bouyer 	struct	intrhand *ih_ipl_next;
     97  1.3  bouyer 	struct	intrhand *ih_evt_next;
     98  1.3  bouyer 	struct cpu_info *ih_cpu;
     99  1.3  bouyer };
    100  1.1      cl 
    101  1.1      cl 
    102  1.1      cl extern struct intrstub xenev_stubs[];
    103  1.1      cl 
    104  1.3  bouyer #define IUNMASK(ci,level) (ci)->ci_iunmask[(level)]
    105  1.3  bouyer 
    106  1.3  bouyer extern void Xspllower(int);
    107  1.3  bouyer 
    108  1.3  bouyer static __inline int splraise(int);
    109  1.3  bouyer static __inline void spllower(int);
    110  1.3  bouyer static __inline void softintr(int);
    111  1.3  bouyer 
    112  1.3  bouyer /*
    113  1.3  bouyer  * Add a mask to cpl, and return the old value of cpl.
    114  1.3  bouyer  */
    115  1.3  bouyer static __inline int
    116  1.3  bouyer splraise(int nlevel)
    117  1.3  bouyer {
    118  1.3  bouyer 	int olevel;
    119  1.3  bouyer 	struct cpu_info *ci = curcpu();
    120  1.3  bouyer 
    121  1.3  bouyer 	olevel = ci->ci_ilevel;
    122  1.3  bouyer 	if (nlevel > olevel)
    123  1.3  bouyer 		ci->ci_ilevel = nlevel;
    124  1.3  bouyer 	__insn_barrier();
    125  1.3  bouyer 	return (olevel);
    126  1.3  bouyer }
    127  1.3  bouyer 
    128  1.3  bouyer /*
    129  1.3  bouyer  * Restore a value to cpl (unmasking interrupts).  If any unmasked
    130  1.3  bouyer  * interrupts are pending, call Xspllower() to process them.
    131  1.3  bouyer  */
    132  1.3  bouyer static __inline void
    133  1.3  bouyer spllower(int nlevel)
    134  1.3  bouyer {
    135  1.3  bouyer 	struct cpu_info *ci = curcpu();
    136  1.3  bouyer 	u_int32_t imask;
    137  1.3  bouyer 	u_long psl;
    138  1.3  bouyer 
    139  1.3  bouyer 	__insn_barrier();
    140  1.3  bouyer 
    141  1.3  bouyer 	imask = IUNMASK(ci, nlevel);
    142  1.3  bouyer 	psl = read_psl();
    143  1.3  bouyer 	disable_intr();
    144  1.3  bouyer 	if (ci->ci_ipending & imask) {
    145  1.3  bouyer 		Xspllower(nlevel);
    146  1.3  bouyer 		/* Xspllower does enable_intr() */
    147  1.3  bouyer 	} else {
    148  1.3  bouyer 		ci->ci_ilevel = nlevel;
    149  1.3  bouyer 		write_psl(psl);
    150  1.3  bouyer 	}
    151  1.3  bouyer }
    152  1.3  bouyer 
    153  1.3  bouyer /*
    154  1.3  bouyer  * Hardware interrupt masks
    155  1.3  bouyer  */
    156  1.3  bouyer #define	splbio()	splraise(IPL_BIO)
    157  1.3  bouyer #define	splnet()	splraise(IPL_NET)
    158  1.3  bouyer #define	spltty()	splraise(IPL_TTY)
    159  1.3  bouyer #define	splaudio()	splraise(IPL_AUDIO)
    160  1.3  bouyer #define	splclock()	splraise(IPL_CLOCK)
    161  1.3  bouyer #define	splstatclock()	splclock()
    162  1.3  bouyer #define	splserial()	splraise(IPL_SERIAL)
    163  1.3  bouyer 
    164  1.3  bouyer #define spllpt()	spltty()
    165  1.3  bouyer 
    166  1.3  bouyer #define SPL_ASSERT_BELOW(x) KDASSERT(curcpu()->ci_ilevel < (x))
    167  1.3  bouyer #define	spllpt()	spltty()
    168  1.3  bouyer 
    169  1.3  bouyer /*
    170  1.3  bouyer  * Software interrupt masks
    171  1.3  bouyer  *
    172  1.3  bouyer  * NOTE: spllowersoftclock() is used by hardclock() to lower the priority from
    173  1.3  bouyer  * clock to softclock before it calls softclock().
    174  1.3  bouyer  */
    175  1.3  bouyer #define	spllowersoftclock() spllower(IPL_SOFTCLOCK)
    176  1.3  bouyer 
    177  1.3  bouyer #define	splsoftclock()	splraise(IPL_SOFTCLOCK)
    178  1.3  bouyer #define	splsoftnet()	splraise(IPL_SOFTNET)
    179  1.3  bouyer #define	splsoftserial()	splraise(IPL_SOFTSERIAL)
    180  1.3  bouyer #define splsoftxenevt()	splraise(IPL_SOFTXENEVT)
    181  1.3  bouyer 
    182  1.3  bouyer /*
    183  1.3  bouyer  * Miscellaneous
    184  1.3  bouyer  */
    185  1.3  bouyer #define	splvm()		splraise(IPL_VM)
    186  1.3  bouyer #define	splhigh()	splraise(IPL_HIGH)
    187  1.3  bouyer #define	spl0()		spllower(IPL_NONE)
    188  1.3  bouyer #define	splsched()	splraise(IPL_SCHED)
    189  1.3  bouyer #define spllock() 	splhigh()
    190  1.3  bouyer #ifndef MULTIPROCESSOR
    191  1.3  bouyer #define splipi() 	splhigh()
    192  1.3  bouyer #endif
    193  1.3  bouyer #define	splx(x)		spllower(x)
    194  1.3  bouyer 
    195  1.3  bouyer /*
    196  1.3  bouyer  * Software interrupt registration
    197  1.3  bouyer  *
    198  1.3  bouyer  * We hand-code this to ensure that it's atomic.
    199  1.3  bouyer  *
    200  1.3  bouyer  * XXX always scheduled on the current CPU.
    201  1.3  bouyer  */
    202  1.3  bouyer static __inline void
    203  1.3  bouyer softintr(int sir)
    204  1.3  bouyer {
    205  1.3  bouyer 	struct cpu_info *ci = curcpu();
    206  1.3  bouyer 
    207  1.3  bouyer 	__asm __volatile("lock ; orl %1, %0" :
    208  1.3  bouyer 	    "=m"(ci->ci_ipending) : "ir" (1 << sir));
    209  1.3  bouyer }
    210  1.3  bouyer 
    211  1.3  bouyer /*
    212  1.3  bouyer  * XXX
    213  1.3  bouyer  */
    214  1.3  bouyer #define	setsoftnet()	softintr(SIR_NET)
    215  1.3  bouyer 
    216  1.3  bouyer /*
    217  1.3  bouyer  * Stub declarations.
    218  1.3  bouyer  */
    219  1.3  bouyer 
    220  1.3  bouyer extern void Xsoftclock(void);
    221  1.3  bouyer extern void Xsoftnet(void);
    222  1.3  bouyer extern void Xsoftserial(void);
    223  1.3  bouyer extern void Xsoftxenevt(void);
    224  1.3  bouyer 
    225  1.3  bouyer struct cpu_info;
    226  1.3  bouyer 
    227  1.3  bouyer extern char idt_allocmap[];
    228  1.3  bouyer 
    229  1.3  bouyer struct pcibus_attach_args;
    230  1.1      cl 
    231  1.3  bouyer void intr_default_setup(void);
    232  1.3  bouyer int x86_nmi(void);
    233  1.3  bouyer void intr_calculatemasks(struct evtsource *);
    234  1.3  bouyer void *intr_establish(int, struct pic *, int, int, int, int (*)(void *), void *);
    235  1.3  bouyer void intr_disestablish(struct intrhand *);
    236  1.3  bouyer const char *intr_string(int);
    237  1.3  bouyer void cpu_intr_init(struct cpu_info *);
    238  1.3  bouyer #ifdef INTRDEBUG
    239  1.3  bouyer void intr_printconfig(void);
    240  1.2    yamt #endif
    241  1.2    yamt 
    242  1.3  bouyer #endif /* !_LOCORE */
    243  1.3  bouyer 
    244  1.3  bouyer /*
    245  1.3  bouyer  * Generic software interrupt support.
    246  1.3  bouyer  */
    247  1.3  bouyer 
    248  1.3  bouyer #define	X86_SOFTINTR_SOFTCLOCK		0
    249  1.3  bouyer #define	X86_SOFTINTR_SOFTNET		1
    250  1.3  bouyer #define	X86_SOFTINTR_SOFTSERIAL		2
    251  1.3  bouyer #define	X86_NSOFTINTR			3
    252  1.3  bouyer 
    253  1.3  bouyer #ifndef _LOCORE
    254  1.3  bouyer #include <sys/queue.h>
    255  1.3  bouyer 
    256  1.3  bouyer struct x86_soft_intrhand {
    257  1.3  bouyer 	TAILQ_ENTRY(x86_soft_intrhand)
    258  1.3  bouyer 		sih_q;
    259  1.3  bouyer 	struct x86_soft_intr *sih_intrhead;
    260  1.3  bouyer 	void	(*sih_fn)(void *);
    261  1.3  bouyer 	void	*sih_arg;
    262  1.3  bouyer 	int	sih_pending;
    263  1.3  bouyer };
    264  1.3  bouyer 
    265  1.3  bouyer struct x86_soft_intr {
    266  1.3  bouyer 	TAILQ_HEAD(, x86_soft_intrhand)
    267  1.3  bouyer 		softintr_q;
    268  1.3  bouyer 	int softintr_ssir;
    269  1.3  bouyer 	struct simplelock softintr_slock;
    270  1.3  bouyer };
    271  1.3  bouyer 
    272  1.3  bouyer #define	x86_softintr_lock(si, s)					\
    273  1.3  bouyer do {									\
    274  1.3  bouyer 	(s) = splhigh();						\
    275  1.3  bouyer 	simple_lock(&si->softintr_slock);				\
    276  1.3  bouyer } while (/*CONSTCOND*/ 0)
    277  1.3  bouyer 
    278  1.3  bouyer #define	x86_softintr_unlock(si, s)					\
    279  1.3  bouyer do {									\
    280  1.3  bouyer 	simple_unlock(&si->softintr_slock);				\
    281  1.3  bouyer 	splx((s));							\
    282  1.3  bouyer } while (/*CONSTCOND*/ 0)
    283  1.3  bouyer 
    284  1.3  bouyer void	*softintr_establish(int, void (*)(void *), void *);
    285  1.3  bouyer void	softintr_disestablish(void *);
    286  1.3  bouyer void	softintr_init(void);
    287  1.3  bouyer void	softintr_dispatch(int);
    288  1.3  bouyer 
    289  1.3  bouyer #define	softintr_schedule(arg)						\
    290  1.3  bouyer do {									\
    291  1.3  bouyer 	struct x86_soft_intrhand *__sih = (arg);			\
    292  1.3  bouyer 	struct x86_soft_intr *__si = __sih->sih_intrhead;		\
    293  1.3  bouyer 	int __s;							\
    294  1.3  bouyer 									\
    295  1.3  bouyer 	x86_softintr_lock(__si, __s);					\
    296  1.3  bouyer 	if (__sih->sih_pending == 0) {					\
    297  1.3  bouyer 		TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q);	\
    298  1.3  bouyer 		__sih->sih_pending = 1;					\
    299  1.3  bouyer 		softintr(__si->softintr_ssir);				\
    300  1.3  bouyer 	}								\
    301  1.3  bouyer 	x86_softintr_unlock(__si, __s);					\
    302  1.3  bouyer } while (/*CONSTCOND*/ 0)
    303  1.3  bouyer #endif /* _LOCORE */
    304  1.3  bouyer 
    305  1.1      cl #endif /* _XEN_INTR_H_ */
    306