intr_machdep.h revision 169221
1272399Sganbold/*-
2272399Sganbold * Copyright (c) 2003 John Baldwin <jhb@FreeBSD.org>
3272399Sganbold * All rights reserved.
4272399Sganbold *
5272399Sganbold * Redistribution and use in source and binary forms, with or without
6272399Sganbold * modification, are permitted provided that the following conditions
7272399Sganbold * are met:
8272399Sganbold * 1. Redistributions of source code must retain the above copyright
9272399Sganbold *    notice, this list of conditions and the following disclaimer.
10272399Sganbold * 2. Redistributions in binary form must reproduce the above copyright
11272399Sganbold *    notice, this list of conditions and the following disclaimer in the
12272399Sganbold *    documentation and/or other materials provided with the distribution.
13272399Sganbold *
14272399Sganbold * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15272399Sganbold * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16272399Sganbold * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17272399Sganbold * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18272399Sganbold * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19272399Sganbold * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20272399Sganbold * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21272399Sganbold * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22272399Sganbold * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23272399Sganbold * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24272399Sganbold * SUCH DAMAGE.
25272399Sganbold *
26272399Sganbold * $FreeBSD: head/sys/amd64/include/intr_machdep.h 169221 2007-05-02 17:50:36Z jhb $
27272399Sganbold */
28272399Sganbold
29272399Sganbold#ifndef __MACHINE_INTR_MACHDEP_H__
30272399Sganbold#define	__MACHINE_INTR_MACHDEP_H__
31272399Sganbold
32272399Sganbold#ifdef _KERNEL
33272399Sganbold
34272399Sganbold/*
35272399Sganbold * The maximum number of I/O interrupts we allow.  This number is rather
36272399Sganbold * arbitrary as it is just the maximum IRQ resource value.  The interrupt
37272399Sganbold * source for a given IRQ maps that I/O interrupt to device interrupt
38272399Sganbold * source whether it be a pin on an interrupt controller or an MSI interrupt.
39272399Sganbold * The 16 ISA IRQs are assigned fixed IDT vectors, but all other device
40272399Sganbold * interrupts allocate IDT vectors on demand.  Currently we have 191 IDT
41272399Sganbold * vectors available for device interrupts.  On many systems with I/O APICs,
42272399Sganbold * a lot of the IRQs are not used, so this number can be much larger than
43272399Sganbold * 191 and still be safe since only interrupt sources in actual use will
44272399Sganbold * allocate IDT vectors.
45272399Sganbold *
46272399Sganbold * The first 255 IRQs (0 - 254) are reserved for ISA IRQs and PCI intline IRQs.
47272399Sganbold * IRQ values beyond 256 are used by MSI.  We leave 255 unused to avoid
48272399Sganbold * confusion since 255 is used in PCI to indicate an invalid IRQ.
49272399Sganbold */
50272399Sganbold#define	NUM_MSI_INTS	128
51272399Sganbold#define	FIRST_MSI_INT	256
52272399Sganbold#define	NUM_IO_INTS	(FIRST_MSI_INT + NUM_MSI_INTS)
53272399Sganbold
54272399Sganbold/*
55272399Sganbold * Default base address for MSI messages on x86 platforms.
56272399Sganbold */
57272399Sganbold#define	MSI_INTEL_ADDR_BASE		0xfee00000
58272399Sganbold
59272399Sganbold/*
60272399Sganbold * - 1 ??? dummy counter.
61272399Sganbold * - 2 counters for each I/O interrupt.
62272399Sganbold * - 1 counter for each CPU for lapic timer.
63272399Sganbold * - 7 counters for each CPU for IPI counters for SMP.
64272399Sganbold */
65272399Sganbold#ifdef SMP
66272399Sganbold#define	INTRCNT_COUNT	(1 + NUM_IO_INTS * 2 + (1 + 7) * MAXCPU)
67272399Sganbold#else
68272399Sganbold#define	INTRCNT_COUNT	(1 + NUM_IO_INTS * 2 + 1)
69272399Sganbold#endif
70272399Sganbold
71272399Sganbold#ifndef LOCORE
72272399Sganbold
73272399Sganboldtypedef void inthand_t(u_int cs, u_int ef, u_int esp, u_int ss);
74272399Sganbold
75272399Sganbold#define	IDTVEC(name)	__CONCAT(X,name)
76272399Sganbold
77272399Sganboldstruct intsrc;
78272399Sganbold
79272399Sganbold/*
80272399Sganbold * Methods that a PIC provides to mask/unmask a given interrupt source,
81272399Sganbold * "turn on" the interrupt on the CPU side by setting up an IDT entry, and
82272399Sganbold * return the vector associated with this source.
83272399Sganbold */
84272399Sganboldstruct pic {
85272399Sganbold	void (*pic_enable_source)(struct intsrc *);
86272399Sganbold	void (*pic_disable_source)(struct intsrc *, int);
87272399Sganbold	void (*pic_eoi_source)(struct intsrc *);
88272399Sganbold	void (*pic_enable_intr)(struct intsrc *);
89272399Sganbold	int (*pic_vector)(struct intsrc *);
90272399Sganbold	int (*pic_source_pending)(struct intsrc *);
91272399Sganbold	void (*pic_suspend)(struct pic *);
92272399Sganbold	void (*pic_resume)(struct pic *);
93272399Sganbold	int (*pic_config_intr)(struct intsrc *, enum intr_trigger,
94272399Sganbold	    enum intr_polarity);
95272399Sganbold	void (*pic_assign_cpu)(struct intsrc *, u_int apic_id);
96272399Sganbold	STAILQ_ENTRY(pic) pics;
97272399Sganbold};
98272399Sganbold
99272399Sganbold/* Flags for pic_disable_source() */
100272399Sganboldenum {
101272399Sganbold	PIC_EOI,
102272399Sganbold	PIC_NO_EOI,
103272399Sganbold};
104272399Sganbold
105272399Sganbold/*
106272399Sganbold * An interrupt source.  The upper-layer code uses the PIC methods to
107272399Sganbold * control a given source.  The lower-layer PIC drivers can store additional
108272399Sganbold * private data in a given interrupt source such as an interrupt pin number
109272399Sganbold * or an I/O APIC pointer.
110272399Sganbold */
111272399Sganboldstruct intsrc {
112272399Sganbold	struct pic *is_pic;
113272399Sganbold	struct intr_event *is_event;
114272399Sganbold	u_long *is_count;
115272399Sganbold	u_long *is_straycount;
116272399Sganbold	u_int is_index;
117272399Sganbold	u_int is_enabled:1;
118272399Sganbold};
119272399Sganbold
120272399Sganboldstruct trapframe;
121272399Sganbold
122272399Sganboldextern struct mtx icu_lock;
123272399Sganboldextern int elcr_found;
124272399Sganbold
125272399Sganbold#ifndef DEV_ATPIC
126272399Sganboldvoid	atpic_reset(void);
127272399Sganbold#endif
128272399Sganbold/* XXX: The elcr_* prototypes probably belong somewhere else. */
129272399Sganboldint	elcr_probe(void);
130272399Sganboldenum intr_trigger elcr_read_trigger(u_int irq);
131272399Sganboldvoid	elcr_resume(void);
132272399Sganboldvoid	elcr_write_trigger(u_int irq, enum intr_trigger trigger);
133272399Sganbold#ifdef SMP
134272399Sganboldvoid	intr_add_cpu(u_int cpu);
135272399Sganbold#endif
136272399Sganboldint	intr_add_handler(const char *name, int vector, driver_filter_t filter,
137272399Sganbold			 driver_intr_t handler, void *arg, enum intr_type flags,
138272399Sganbold			 void **cookiep);
139272399Sganboldint	intr_config_intr(int vector, enum intr_trigger trig,
140272399Sganbold    enum intr_polarity pol);
141272399Sganboldvoid	intr_execute_handlers(struct intsrc *isrc, struct trapframe *frame);
142272399Sganboldstruct intsrc *intr_lookup_source(int vector);
143272399Sganboldint	intr_register_pic(struct pic *pic);
144272399Sganboldint	intr_register_source(struct intsrc *isrc);
145272399Sganboldint	intr_remove_handler(void *cookie);
146272399Sganboldvoid	intr_resume(void);
147272399Sganboldvoid	intr_suspend(void);
148272399Sganboldvoid	intrcnt_add(const char *name, u_long **countp);
149272399Sganboldint	msi_alloc(device_t dev, int count, int maxcount, int *irqs, int *newirq,
150272399Sganbold    int *newcount);
151272399Sganboldvoid	msi_init(void);
152272399Sganboldint	msi_map(int irq, uint64_t *addr, uint32_t *data);
153272399Sganboldint	msi_release(int *irqs, int count);
154272399Sganboldint	msix_alloc(device_t dev, int *irq, int *new);
155272399Sganboldint	msix_release(int irq);
156272399Sganbold
157272399Sganbold#endif	/* !LOCORE */
158272399Sganbold#endif	/* _KERNEL */
159272399Sganbold#endif	/* !__MACHINE_INTR_MACHDEP_H__ */
160272399Sganbold