1 /* $NetBSD: intr.h,v 1.38 2009/03/27 16:09:24 dyoung Exp $ */
4 * Copyright (c) 1998, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum, and by Jason R. Thorpe.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
35 #define __HAVE_FAST_SOFTINTS
36 #define __HAVE_PREEMPTION
39 #include <sys/types.h>
44 #include <sys/evcnt.h>
45 #include <machine/intrdefs.h>
48 #include <machine/pic.h>
51 * Struct describing an interrupt source for a CPU. struct cpu_info
52 * has an array of MAX_INTR_SOURCES of these. The index in the array
53 * is equal to the stub number of the stubcode as present in vector.s
55 * The primary CPU's array of interrupt sources has its first 16
56 * entries reserved for legacy ISA irq handlers. This means that
57 * they have a 1:1 mapping for arrayindex:irq_num. This is not
58 * true for interrupts that come in through IO APICs, to find
59 * their source, go through ci->ci_isources[index].is_pic
61 * It's possible to always maintain a 1:1 mapping, but that means
62 * limiting the total number of interrupt sources to MAX_INTR_SOURCES
63 * (32), instead of 32 per CPU. It also would mean that having multiple
64 * IO APICs which deliver interrupts from an equal pin number would
65 * overlap if they were to be sent to the same CPU.
75 int is_maxlevel
; /* max. IPL for this source */
76 int is_pin
; /* IRQ for legacy; pin for IO APIC */
77 struct intrhand
*is_handlers
; /* handler chain */
78 struct pic
*is_pic
; /* originating PIC */
79 void *is_recurse
; /* entry for spllower */
80 void *is_resume
; /* entry for doreti */
81 lwp_t
*is_lwp
; /* for soft interrupts */
82 struct evcnt is_evcnt
; /* interrupt counter */
83 int is_flags
; /* see below */
84 int is_type
; /* level, edge */
87 char is_evname
[32]; /* event counter name */
90 #define IS_LEGACY 0x0001 /* legacy ISA irq source */
95 * Interrupt handler chains. *_intr_establish() insert a handler into
96 * the list. The handler is called with its (single) argument.
100 int (*ih_fun
)(void *);
103 int (*ih_realfun
)(void *);
105 struct intrhand
*ih_next
;
106 struct intrhand
**ih_prevp
;
109 struct cpu_info
*ih_cpu
;
112 #define IMASK(ci,level) (ci)->ci_imask[(level)]
113 #define IUNMASK(ci,level) (ci)->ci_iunmask[(level)]
121 * Convert spl level to local APIC level
124 #define APIC_LEVEL(l) ((l) << 4)
130 #define SPL_ASSERT_BELOW(x) KDASSERT(curcpu()->ci_ilevel < (x))
131 #define spl0() spllower(IPL_NONE)
132 #define splx(x) spllower(x)
134 typedef uint8_t ipl_t
;
139 static inline ipl_cookie_t
140 makeiplcookie(ipl_t ipl
)
143 return (ipl_cookie_t
){._ipl
= ipl
};
147 splraiseipl(ipl_cookie_t icookie
)
150 return splraise(icookie
._ipl
);
159 void Xsoftintr(void);
160 void Xpreemptrecurse(void);
161 void Xpreemptresume(void);
163 extern struct intrstub i8259_stubs
[];
164 extern struct intrstub ioapic_edge_stubs
[];
165 extern struct intrstub ioapic_level_stubs
[];
169 struct pcibus_attach_args
;
171 void intr_default_setup(void);
173 void *intr_establish(int, struct pic
*, int, int, int, int (*)(void *), void *, bool);
174 void intr_disestablish(struct intrhand
*);
175 void intr_add_pcibus(struct pcibus_attach_args
*);
176 const char *intr_string(int);
177 void cpu_intr_init(struct cpu_info
*);
178 int intr_find_mpmapping(int, int, int *);
179 struct pic
*intr_findpic(int);
180 void intr_printconfig(void);
182 int x86_send_ipi(struct cpu_info
*, int);
183 void x86_broadcast_ipi(int);
184 void x86_multicast_ipi(int, int);
185 void x86_ipi_handler(void);
187 extern void (*ipifunc
[X86_NIPI
])(struct cpu_info
*);
189 #endif /* !_LOCORE */
191 #endif /* !_X86_INTR_H_ */