Home | History | Annotate | Line # | Download | only in include
intr.h revision 1.31
      1  1.31    dyoung /*	$NetBSD: intr.h,v 1.31 2008/01/21 02:56:14 dyoung Exp $	*/
      2   1.1      fvdl 
      3   1.1      fvdl /*-
      4  1.26      yamt  * Copyright (c) 1998, 2001, 2006, 2007 The NetBSD Foundation, Inc.
      5   1.1      fvdl  * All rights reserved.
      6   1.1      fvdl  *
      7   1.1      fvdl  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1      fvdl  * by Charles M. Hannum, and by Jason R. Thorpe.
      9   1.1      fvdl  *
     10   1.1      fvdl  * Redistribution and use in source and binary forms, with or without
     11   1.1      fvdl  * modification, are permitted provided that the following conditions
     12   1.1      fvdl  * are met:
     13   1.1      fvdl  * 1. Redistributions of source code must retain the above copyright
     14   1.1      fvdl  *    notice, this list of conditions and the following disclaimer.
     15   1.1      fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1      fvdl  *    notice, this list of conditions and the following disclaimer in the
     17   1.1      fvdl  *    documentation and/or other materials provided with the distribution.
     18   1.1      fvdl  * 3. All advertising materials mentioning features or use of this software
     19   1.1      fvdl  *    must display the following acknowledgement:
     20   1.1      fvdl  *        This product includes software developed by the NetBSD
     21   1.1      fvdl  *        Foundation, Inc. and its contributors.
     22   1.1      fvdl  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1      fvdl  *    contributors may be used to endorse or promote products derived
     24   1.1      fvdl  *    from this software without specific prior written permission.
     25   1.1      fvdl  *
     26   1.1      fvdl  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1      fvdl  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1      fvdl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1      fvdl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1      fvdl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1      fvdl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1      fvdl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1      fvdl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1      fvdl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1      fvdl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1      fvdl  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1      fvdl  */
     38   1.1      fvdl 
     39   1.1      fvdl #ifndef _X86_INTR_H_
     40   1.1      fvdl #define _X86_INTR_H_
     41   1.1      fvdl 
     42  1.29        ad #define	__HAVE_FAST_SOFTINTS
     43  1.29        ad 
     44   1.1      fvdl #include <machine/intrdefs.h>
     45   1.1      fvdl 
     46   1.1      fvdl #ifndef _LOCORE
     47   1.1      fvdl #include <machine/pic.h>
     48   1.1      fvdl 
     49   1.1      fvdl /*
     50   1.1      fvdl  * Struct describing an interrupt source for a CPU. struct cpu_info
     51   1.1      fvdl  * has an array of MAX_INTR_SOURCES of these. The index in the array
     52   1.1      fvdl  * is equal to the stub number of the stubcode as present in vector.s
     53   1.1      fvdl  *
     54   1.1      fvdl  * The primary CPU's array of interrupt sources has its first 16
     55   1.1      fvdl  * entries reserved for legacy ISA irq handlers. This means that
     56   1.1      fvdl  * they have a 1:1 mapping for arrayindex:irq_num. This is not
     57   1.1      fvdl  * true for interrupts that come in through IO APICs, to find
     58   1.1      fvdl  * their source, go through ci->ci_isources[index].is_pic
     59   1.1      fvdl  *
     60   1.1      fvdl  * It's possible to always maintain a 1:1 mapping, but that means
     61   1.1      fvdl  * limiting the total number of interrupt sources to MAX_INTR_SOURCES
     62   1.1      fvdl  * (32), instead of 32 per CPU. It also would mean that having multiple
     63   1.1      fvdl  * IO APICs which deliver interrupts from an equal pin number would
     64   1.1      fvdl  * overlap if they were to be sent to the same CPU.
     65   1.1      fvdl  */
     66   1.1      fvdl 
     67   1.1      fvdl struct intrstub {
     68   1.1      fvdl 	void *ist_entry;
     69   1.1      fvdl 	void *ist_recurse;
     70   1.1      fvdl 	void *ist_resume;
     71   1.1      fvdl };
     72   1.1      fvdl 
     73   1.1      fvdl struct intrsource {
     74   1.1      fvdl 	int is_maxlevel;		/* max. IPL for this source */
     75   1.1      fvdl 	int is_pin;			/* IRQ for legacy; pin for IO APIC */
     76   1.1      fvdl 	struct intrhand *is_handlers;	/* handler chain */
     77   1.1      fvdl 	struct pic *is_pic;		/* originating PIC */
     78   1.1      fvdl 	void *is_recurse;		/* entry for spllower */
     79   1.1      fvdl 	void *is_resume;		/* entry for doreti */
     80  1.29        ad 	lwp_t *is_lwp;			/* for soft interrupts */
     81   1.1      fvdl 	struct evcnt is_evcnt;		/* interrupt counter */
     82   1.1      fvdl 	int is_flags;			/* see below */
     83   1.1      fvdl 	int is_type;			/* level, edge */
     84   1.1      fvdl 	int is_idtvec;
     85   1.1      fvdl 	int is_minlevel;
     86  1.29        ad 	char is_evname[32];		/* event counter name */
     87   1.1      fvdl };
     88   1.1      fvdl 
     89   1.1      fvdl #define IS_LEGACY	0x0001		/* legacy ISA irq source */
     90   1.1      fvdl #define IS_IPI		0x0002
     91   1.1      fvdl #define IS_LOG		0x0004
     92   1.1      fvdl 
     93   1.1      fvdl /*
     94   1.1      fvdl  * Interrupt handler chains.  *_intr_establish() insert a handler into
     95   1.1      fvdl  * the list.  The handler is called with its (single) argument.
     96   1.1      fvdl  */
     97   1.1      fvdl 
     98   1.1      fvdl struct intrhand {
     99   1.1      fvdl 	int	(*ih_fun)(void *);
    100   1.1      fvdl 	void	*ih_arg;
    101   1.1      fvdl 	int	ih_level;
    102  1.14      yamt 	int	(*ih_realfun)(void *);
    103  1.14      yamt 	void	*ih_realarg;
    104   1.1      fvdl 	struct	intrhand *ih_next;
    105   1.1      fvdl 	int	ih_pin;
    106   1.1      fvdl 	int	ih_slot;
    107   1.1      fvdl 	struct cpu_info *ih_cpu;
    108   1.1      fvdl };
    109   1.1      fvdl 
    110   1.1      fvdl #define IMASK(ci,level) (ci)->ci_imask[(level)]
    111   1.1      fvdl #define IUNMASK(ci,level) (ci)->ci_iunmask[(level)]
    112   1.1      fvdl 
    113  1.26      yamt void Xspllower(int);
    114  1.26      yamt void spllower(int);
    115  1.26      yamt int splraise(int);
    116  1.26      yamt void softintr(int);
    117   1.1      fvdl 
    118   1.1      fvdl /*
    119   1.1      fvdl  * Convert spl level to local APIC level
    120   1.1      fvdl  */
    121  1.26      yamt 
    122   1.1      fvdl #define APIC_LEVEL(l)   ((l) << 4)
    123   1.1      fvdl 
    124   1.1      fvdl /*
    125  1.26      yamt  * Miscellaneous
    126   1.1      fvdl  */
    127   1.1      fvdl 
    128   1.1      fvdl #define SPL_ASSERT_BELOW(x) KDASSERT(curcpu()->ci_ilevel < (x))
    129   1.1      fvdl #define	spl0()		spllower(IPL_NONE)
    130   1.1      fvdl #define	splx(x)		spllower(x)
    131   1.1      fvdl 
    132  1.23        ad typedef uint8_t ipl_t;
    133  1.22      yamt typedef struct {
    134  1.22      yamt 	ipl_t _ipl;
    135  1.22      yamt } ipl_cookie_t;
    136  1.22      yamt 
    137  1.22      yamt static inline ipl_cookie_t
    138  1.22      yamt makeiplcookie(ipl_t ipl)
    139  1.22      yamt {
    140  1.22      yamt 
    141  1.22      yamt 	return (ipl_cookie_t){._ipl = ipl};
    142  1.22      yamt }
    143  1.22      yamt 
    144  1.22      yamt static inline int
    145  1.22      yamt splraiseipl(ipl_cookie_t icookie)
    146  1.22      yamt {
    147  1.22      yamt 
    148  1.22      yamt 	return splraise(icookie._ipl);
    149  1.22      yamt }
    150  1.22      yamt 
    151  1.18      yamt #include <sys/spl.h>
    152  1.18      yamt 
    153   1.1      fvdl /*
    154   1.1      fvdl  * Stub declarations.
    155   1.1      fvdl  */
    156   1.1      fvdl 
    157  1.29        ad void Xsoftintr(void);
    158   1.1      fvdl 
    159   1.1      fvdl extern struct intrstub i8259_stubs[];
    160   1.2      fvdl extern struct intrstub ioapic_edge_stubs[];
    161   1.2      fvdl extern struct intrstub ioapic_level_stubs[];
    162   1.1      fvdl 
    163   1.1      fvdl struct cpu_info;
    164   1.1      fvdl 
    165  1.10      fvdl struct pcibus_attach_args;
    166  1.10      fvdl 
    167   1.1      fvdl void intr_default_setup(void);
    168  1.31    dyoung void *nmi_establish(int (*)(void *), void *);
    169  1.31    dyoung bool nmi_disestablish(void *);
    170  1.31    dyoung int nmi_dispatch(void);
    171   1.1      fvdl int x86_nmi(void);
    172   1.1      fvdl void intr_calculatemasks(struct cpu_info *);
    173   1.1      fvdl int intr_allocate_slot_cpu(struct cpu_info *, struct pic *, int, int *);
    174   1.1      fvdl int intr_allocate_slot(struct pic *, int, int, int, struct cpu_info **, int *,
    175   1.1      fvdl 		       int *);
    176   1.1      fvdl void *intr_establish(int, struct pic *, int, int, int, int (*)(void *), void *);
    177   1.1      fvdl void intr_disestablish(struct intrhand *);
    178  1.10      fvdl void intr_add_pcibus(struct pcibus_attach_args *);
    179   1.7      fvdl const char *intr_string(int);
    180   1.1      fvdl void cpu_intr_init(struct cpu_info *);
    181  1.10      fvdl int intr_find_mpmapping(int, int, int *);
    182  1.21  christos struct pic *intr_findpic(int);
    183   1.1      fvdl #ifdef INTRDEBUG
    184   1.1      fvdl void intr_printconfig(void);
    185   1.1      fvdl #endif
    186   1.1      fvdl 
    187   1.1      fvdl int x86_send_ipi(struct cpu_info *, int);
    188   1.1      fvdl void x86_broadcast_ipi(int);
    189   1.1      fvdl void x86_multicast_ipi(int, int);
    190   1.1      fvdl void x86_ipi_handler(void);
    191   1.1      fvdl 
    192   1.1      fvdl extern void (*ipifunc[X86_NIPI])(struct cpu_info *);
    193   1.1      fvdl 
    194   1.1      fvdl #endif /* !_LOCORE */
    195   1.1      fvdl 
    196   1.1      fvdl #endif /* !_X86_INTR_H_ */
    197