intr_machdep.h revision 163219
1121982Sjhb/*-
2121982Sjhb * Copyright (c) 2003 John Baldwin <jhb@FreeBSD.org>
3121982Sjhb * All rights reserved.
4121982Sjhb *
5121982Sjhb * Redistribution and use in source and binary forms, with or without
6121982Sjhb * modification, are permitted provided that the following conditions
7121982Sjhb * are met:
8121982Sjhb * 1. Redistributions of source code must retain the above copyright
9121982Sjhb *    notice, this list of conditions and the following disclaimer.
10121982Sjhb * 2. Redistributions in binary form must reproduce the above copyright
11121982Sjhb *    notice, this list of conditions and the following disclaimer in the
12121982Sjhb *    documentation and/or other materials provided with the distribution.
13121982Sjhb *
14121982Sjhb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15121982Sjhb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16121982Sjhb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17121982Sjhb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18121982Sjhb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19121982Sjhb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20121982Sjhb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21121982Sjhb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22121982Sjhb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23121982Sjhb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24121982Sjhb * SUCH DAMAGE.
25121982Sjhb *
26121982Sjhb * $FreeBSD: head/sys/amd64/include/intr_machdep.h 163219 2006-10-10 23:23:12Z jhb $
27121982Sjhb */
28121982Sjhb
29121982Sjhb#ifndef __MACHINE_INTR_MACHDEP_H__
30121982Sjhb#define	__MACHINE_INTR_MACHDEP_H__
31121982Sjhb
32121982Sjhb#ifdef _KERNEL
33121982Sjhb
34151979Sjhb/*
35151979Sjhb * The maximum number of I/O interrupts we allow.  This number is rather
36151979Sjhb * arbitrary as it is just the maximum IRQ resource value.  The interrupt
37151979Sjhb * source for a given IRQ maps that I/O interrupt to device interrupt
38151979Sjhb * source whether it be a pin on an interrupt controller or an MSI interrupt.
39151979Sjhb * The 16 ISA IRQs are assigned fixed IDT vectors, but all other device
40151979Sjhb * interrupts allocate IDT vectors on demand.  Currently we have 191 IDT
41151979Sjhb * vectors available for device interrupts.  On many systems with I/O APICs,
42151979Sjhb * a lot of the IRQs are not used, so this number can be much larger than
43151979Sjhb * 191 and still be safe since only interrupt sources in actual use will
44151979Sjhb * allocate IDT vectors.
45151979Sjhb *
46151979Sjhb * For now we stick with 255 as ISA IRQs and PCI intline IRQs only allow
47151979Sjhb * for IRQs in the range 0 - 254.  When MSI support is added this number
48151979Sjhb * will likely increase.
49151979Sjhb */
50151979Sjhb#define	NUM_IO_INTS	255
51121982Sjhb
52151979Sjhb/*
53151979Sjhb * - 1 ??? dummy counter.
54151979Sjhb * - 2 counters for each I/O interrupt.
55151979Sjhb * - 1 counter for each CPU for lapic timer.
56151979Sjhb * - 7 counters for each CPU for IPI counters for SMP.
57151979Sjhb */
58151979Sjhb#ifdef SMP
59163212Sjhb#define	INTRCNT_COUNT	(1 + NUM_IO_INTS * 2 + (1 + 7) * MAXCPU)
60163212Sjhb#else
61151979Sjhb#define	INTRCNT_COUNT	(1 + NUM_IO_INTS * 2 + 1)
62151979Sjhb#endif
63151979Sjhb
64121982Sjhb#ifndef LOCORE
65121982Sjhb
66121982Sjhbtypedef void inthand_t(u_int cs, u_int ef, u_int esp, u_int ss);
67121982Sjhb
68121982Sjhb#define	IDTVEC(name)	__CONCAT(X,name)
69121982Sjhb
70121982Sjhbstruct intsrc;
71121982Sjhb
72121982Sjhb/*
73121982Sjhb * Methods that a PIC provides to mask/unmask a given interrupt source,
74121982Sjhb * "turn on" the interrupt on the CPU side by setting up an IDT entry, and
75121982Sjhb * return the vector associated with this source.
76121982Sjhb */
77121982Sjhbstruct pic {
78121982Sjhb	void (*pic_enable_source)(struct intsrc *);
79133907Speter	void (*pic_disable_source)(struct intsrc *, int);
80121982Sjhb	void (*pic_eoi_source)(struct intsrc *);
81121982Sjhb	void (*pic_enable_intr)(struct intsrc *);
82121982Sjhb	int (*pic_vector)(struct intsrc *);
83121982Sjhb	int (*pic_source_pending)(struct intsrc *);
84163219Sjhb	void (*pic_suspend)(struct pic *);
85163219Sjhb	void (*pic_resume)(struct pic *);
86129284Speter	int (*pic_config_intr)(struct intsrc *, enum intr_trigger,
87129284Speter	    enum intr_polarity);
88156124Sjhb	void (*pic_assign_cpu)(struct intsrc *, u_int apic_id);
89163219Sjhb	STAILQ_ENTRY(pic) pics;
90121982Sjhb};
91121982Sjhb
92133907Speter/* Flags for pic_disable_source() */
93133907Speterenum {
94133907Speter	PIC_EOI,
95133907Speter	PIC_NO_EOI,
96133907Speter};
97133907Speter
98121982Sjhb/*
99121982Sjhb * An interrupt source.  The upper-layer code uses the PIC methods to
100121982Sjhb * control a given source.  The lower-layer PIC drivers can store additional
101121982Sjhb * private data in a given interrupt source such as an interrupt pin number
102121982Sjhb * or an I/O APIC pointer.
103121982Sjhb */
104121982Sjhbstruct intsrc {
105121982Sjhb	struct pic *is_pic;
106151658Sjhb	struct intr_event *is_event;
107121982Sjhb	u_long *is_count;
108121982Sjhb	u_long *is_straycount;
109121982Sjhb	u_int is_index;
110156124Sjhb	u_int is_enabled:1;
111121982Sjhb};
112121982Sjhb
113153241Sjhbstruct trapframe;
114121982Sjhb
115121982Sjhbextern struct mtx icu_lock;
116140555Speterextern int elcr_found;
117121982Sjhb
118163219Sjhb#ifndef DEV_ATPIC
119163219Sjhbvoid	atpic_reset(void);
120163219Sjhb#endif
121129284Speter/* XXX: The elcr_* prototypes probably belong somewhere else. */
122129284Speterint	elcr_probe(void);
123129284Speterenum intr_trigger elcr_read_trigger(u_int irq);
124129284Spetervoid	elcr_resume(void);
125129284Spetervoid	elcr_write_trigger(u_int irq, enum intr_trigger trigger);
126156124Sjhb#ifdef SMP
127156124Sjhbvoid	intr_add_cpu(u_int apic_id);
128156124Sjhb#else
129156124Sjhb#define	intr_add_cpu(apic_id)
130156124Sjhb#endif
131121982Sjhbint	intr_add_handler(const char *name, int vector, driver_intr_t handler,
132121982Sjhb    void *arg, enum intr_type flags, void **cookiep);
133129284Speterint	intr_config_intr(int vector, enum intr_trigger trig,
134129284Speter    enum intr_polarity pol);
135153241Sjhbvoid	intr_execute_handlers(struct intsrc *isrc, struct trapframe *frame);
136121982Sjhbstruct intsrc *intr_lookup_source(int vector);
137163219Sjhbint	intr_register_pic(struct pic *pic);
138121982Sjhbint	intr_register_source(struct intsrc *isrc);
139121982Sjhbint	intr_remove_handler(void *cookie);
140121982Sjhbvoid	intr_resume(void);
141121982Sjhbvoid	intr_suspend(void);
142140555Spetervoid	intrcnt_add(const char *name, u_long **countp);
143121982Sjhb
144121982Sjhb#endif	/* !LOCORE */
145121982Sjhb#endif	/* _KERNEL */
146121982Sjhb#endif	/* !__MACHINE_INTR_MACHDEP_H__ */
147