Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.16.10.1
      1  1.16.10.1    matt /*	$NetBSD: intr.h,v 1.16.10.1 2007/11/06 23:24:04 matt 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 #ifndef _XEN_INTR_H_
     41        1.1      cl #define	_XEN_INTR_H_
     42        1.1      cl 
     43        1.3  bouyer #include <machine/intrdefs.h>
     44  1.16.10.1    matt #include <machine/xen.h>
     45  1.16.10.1    matt #include <machine/hypervisor.h>
     46  1.16.10.1    matt #include <machine/evtchn.h>
     47        1.1      cl 
     48        1.1      cl #ifndef _LOCORE
     49        1.3  bouyer #include <machine/cpu.h>
     50        1.3  bouyer #include <machine/pic.h>
     51        1.3  bouyer 
     52       1.10  bouyer #include "opt_xen.h"
     53       1.10  bouyer 
     54        1.3  bouyer /*
     55        1.3  bouyer  * Struct describing an event channel.
     56        1.3  bouyer  */
     57        1.3  bouyer 
     58        1.3  bouyer struct evtsource {
     59        1.3  bouyer 	int ev_maxlevel;		/* max. IPL for this source */
     60        1.3  bouyer 	u_int32_t ev_imask;		/* interrupt mask */
     61        1.3  bouyer 	struct intrhand *ev_handlers;	/* handler chain */
     62        1.3  bouyer 	struct evcnt ev_evcnt;		/* interrupt counter */
     63        1.3  bouyer 	char ev_evname[32];		/* event counter name */
     64        1.3  bouyer };
     65        1.3  bouyer 
     66        1.3  bouyer /*
     67        1.3  bouyer  * Structure describing an interrupt level. struct cpu_info has an array of
     68        1.3  bouyer  * IPL_MAX of theses. The index in the array is equal to the stub number of
     69        1.3  bouyer  * the stubcode as present in vector.s
     70        1.3  bouyer  */
     71        1.3  bouyer 
     72        1.3  bouyer struct intrstub {
     73        1.3  bouyer #if 0
     74        1.3  bouyer 	void *ist_entry;
     75        1.3  bouyer #endif
     76        1.3  bouyer 	void *ist_recurse;
     77        1.3  bouyer 	void *ist_resume;
     78        1.3  bouyer };
     79        1.3  bouyer 
     80       1.11  dogcow #ifdef XEN3
     81       1.11  dogcow /* for x86 compatibility */
     82       1.11  dogcow extern struct intrstub i8259_stubs[];
     83       1.12  bouyer extern struct intrstub ioapic_edge_stubs[];
     84       1.12  bouyer extern struct intrstub ioapic_level_stubs[];
     85       1.11  dogcow #endif
     86       1.11  dogcow 
     87        1.3  bouyer struct iplsource {
     88        1.3  bouyer 	struct intrhand *ipl_handlers;   /* handler chain */
     89        1.3  bouyer 	void *ipl_recurse;               /* entry for spllower */
     90        1.3  bouyer 	void *ipl_resume;                /* entry for doreti */
     91        1.3  bouyer 	u_int32_t ipl_evt_mask1;	/* pending events for this IPL */
     92        1.3  bouyer 	u_int32_t ipl_evt_mask2[NR_EVENT_CHANNELS];
     93        1.3  bouyer };
     94        1.3  bouyer 
     95        1.3  bouyer 
     96        1.3  bouyer 
     97        1.3  bouyer /*
     98        1.3  bouyer  * Interrupt handler chains. These are linked in both the evtsource and
     99        1.3  bouyer  * the iplsource.
    100        1.3  bouyer  * The handler is called with its (single) argument.
    101        1.3  bouyer  */
    102        1.3  bouyer 
    103        1.3  bouyer struct intrhand {
    104        1.3  bouyer 	int	(*ih_fun)(void *);
    105        1.3  bouyer 	void	*ih_arg;
    106        1.3  bouyer 	int	ih_level;
    107        1.3  bouyer 	struct	intrhand *ih_ipl_next;
    108        1.3  bouyer 	struct	intrhand *ih_evt_next;
    109        1.3  bouyer 	struct cpu_info *ih_cpu;
    110        1.3  bouyer };
    111        1.1      cl 
    112       1.12  bouyer struct xen_intr_handle {
    113       1.12  bouyer 	int pirq; /* also contains the  APIC_INT_* flags if NIOAPIC > 0 */
    114       1.12  bouyer 	int evtch;
    115       1.12  bouyer };
    116        1.1      cl 
    117        1.1      cl extern struct intrstub xenev_stubs[];
    118        1.1      cl 
    119        1.3  bouyer #define IUNMASK(ci,level) (ci)->ci_iunmask[(level)]
    120        1.3  bouyer 
    121        1.3  bouyer extern void Xspllower(int);
    122        1.3  bouyer 
    123       1.16    yamt int splraise(int);
    124       1.16    yamt void spllower(int);
    125       1.16    yamt void softintr(int);
    126        1.3  bouyer 
    127        1.3  bouyer #define SPL_ASSERT_BELOW(x) KDASSERT(curcpu()->ci_ilevel < (x))
    128        1.3  bouyer 
    129        1.3  bouyer /*
    130        1.3  bouyer  * Software interrupt masks
    131        1.3  bouyer  */
    132        1.3  bouyer #define splsoftxenevt()	splraise(IPL_SOFTXENEVT)
    133        1.3  bouyer 
    134        1.3  bouyer /*
    135        1.3  bouyer  * Miscellaneous
    136        1.3  bouyer  */
    137        1.3  bouyer #define	spl0()		spllower(IPL_NONE)
    138        1.3  bouyer #define	splx(x)		spllower(x)
    139        1.3  bouyer 
    140       1.14      ad typedef uint8_t ipl_t;
    141       1.13    yamt typedef struct {
    142       1.13    yamt 	ipl_t _ipl;
    143       1.13    yamt } ipl_cookie_t;
    144       1.13    yamt 
    145       1.13    yamt static inline ipl_cookie_t
    146       1.13    yamt makeiplcookie(ipl_t ipl)
    147       1.13    yamt {
    148       1.13    yamt 
    149       1.13    yamt 	return (ipl_cookie_t){._ipl = ipl};
    150       1.13    yamt }
    151       1.13    yamt 
    152       1.13    yamt static inline int
    153       1.13    yamt splraiseipl(ipl_cookie_t icookie)
    154       1.13    yamt {
    155       1.13    yamt 
    156       1.13    yamt 	return splraise(icookie._ipl);
    157       1.13    yamt }
    158       1.13    yamt 
    159        1.6    yamt #include <sys/spl.h>
    160        1.6    yamt 
    161        1.3  bouyer /*
    162        1.3  bouyer  * XXX
    163        1.3  bouyer  */
    164        1.3  bouyer #define	setsoftnet()	softintr(SIR_NET)
    165        1.3  bouyer 
    166        1.3  bouyer /*
    167        1.3  bouyer  * Stub declarations.
    168        1.3  bouyer  */
    169        1.3  bouyer 
    170        1.3  bouyer extern void Xsoftclock(void);
    171        1.3  bouyer extern void Xsoftnet(void);
    172        1.3  bouyer extern void Xsoftserial(void);
    173        1.3  bouyer extern void Xsoftxenevt(void);
    174        1.3  bouyer 
    175        1.3  bouyer struct cpu_info;
    176        1.3  bouyer 
    177        1.3  bouyer extern char idt_allocmap[];
    178        1.3  bouyer 
    179        1.3  bouyer struct pcibus_attach_args;
    180        1.1      cl 
    181        1.3  bouyer void intr_default_setup(void);
    182        1.3  bouyer int x86_nmi(void);
    183        1.3  bouyer void intr_calculatemasks(struct evtsource *);
    184       1.10  bouyer 
    185        1.3  bouyer void *intr_establish(int, struct pic *, int, int, int, int (*)(void *), void *);
    186        1.3  bouyer void intr_disestablish(struct intrhand *);
    187        1.3  bouyer const char *intr_string(int);
    188        1.3  bouyer void cpu_intr_init(struct cpu_info *);
    189       1.12  bouyer int xen_intr_map(int *, int);
    190        1.3  bouyer #ifdef INTRDEBUG
    191        1.3  bouyer void intr_printconfig(void);
    192        1.2    yamt #endif
    193       1.12  bouyer int intr_find_mpmapping(int, int, struct xen_intr_handle *);
    194       1.12  bouyer struct pic *intr_findpic(int);
    195       1.12  bouyer void intr_add_pcibus(struct pcibus_attach_args *);
    196       1.10  bouyer 
    197        1.3  bouyer #endif /* !_LOCORE */
    198        1.3  bouyer 
    199        1.3  bouyer /*
    200        1.3  bouyer  * Generic software interrupt support.
    201        1.3  bouyer  */
    202        1.3  bouyer 
    203        1.3  bouyer #define	X86_SOFTINTR_SOFTCLOCK		0
    204        1.3  bouyer #define	X86_SOFTINTR_SOFTNET		1
    205        1.3  bouyer #define	X86_SOFTINTR_SOFTSERIAL		2
    206        1.3  bouyer #define	X86_NSOFTINTR			3
    207        1.3  bouyer 
    208        1.3  bouyer #ifndef _LOCORE
    209        1.3  bouyer #include <sys/queue.h>
    210        1.3  bouyer 
    211        1.3  bouyer struct x86_soft_intrhand {
    212        1.3  bouyer 	TAILQ_ENTRY(x86_soft_intrhand)
    213        1.3  bouyer 		sih_q;
    214        1.3  bouyer 	struct x86_soft_intr *sih_intrhead;
    215        1.3  bouyer 	void	(*sih_fn)(void *);
    216        1.3  bouyer 	void	*sih_arg;
    217        1.3  bouyer 	int	sih_pending;
    218        1.3  bouyer };
    219        1.3  bouyer 
    220        1.3  bouyer struct x86_soft_intr {
    221        1.3  bouyer 	TAILQ_HEAD(, x86_soft_intrhand)
    222        1.3  bouyer 		softintr_q;
    223        1.3  bouyer 	int softintr_ssir;
    224        1.3  bouyer 	struct simplelock softintr_slock;
    225        1.3  bouyer };
    226        1.3  bouyer 
    227        1.3  bouyer #define	x86_softintr_lock(si, s)					\
    228        1.3  bouyer do {									\
    229        1.3  bouyer 	(s) = splhigh();						\
    230        1.3  bouyer 	simple_lock(&si->softintr_slock);				\
    231        1.3  bouyer } while (/*CONSTCOND*/ 0)
    232        1.3  bouyer 
    233        1.3  bouyer #define	x86_softintr_unlock(si, s)					\
    234        1.3  bouyer do {									\
    235        1.3  bouyer 	simple_unlock(&si->softintr_slock);				\
    236        1.3  bouyer 	splx((s));							\
    237        1.3  bouyer } while (/*CONSTCOND*/ 0)
    238        1.3  bouyer 
    239        1.3  bouyer void	*softintr_establish(int, void (*)(void *), void *);
    240        1.3  bouyer void	softintr_disestablish(void *);
    241        1.3  bouyer void	softintr_init(void);
    242        1.3  bouyer void	softintr_dispatch(int);
    243       1.16    yamt void	softintr_schedule(void *);
    244        1.3  bouyer 
    245        1.3  bouyer #endif /* _LOCORE */
    246        1.3  bouyer 
    247        1.1      cl #endif /* _XEN_INTR_H_ */
    248