intr_machdep.h revision 151658
1193323Sed/*-
2193323Sed * Copyright (c) 2003 John Baldwin <jhb@FreeBSD.org>
3193323Sed * All rights reserved.
4193323Sed *
5193323Sed * Redistribution and use in source and binary forms, with or without
6193323Sed * modification, are permitted provided that the following conditions
7193323Sed * are met:
8193323Sed * 1. Redistributions of source code must retain the above copyright
9193323Sed *    notice, this list of conditions and the following disclaimer.
10193323Sed * 2. Redistributions in binary form must reproduce the above copyright
11193323Sed *    notice, this list of conditions and the following disclaimer in the
12193323Sed *    documentation and/or other materials provided with the distribution.
13193323Sed *
14193323Sed * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15193323Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16193323Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17193323Sed * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18193323Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19193323Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20193323Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21193323Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22193323Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23193323Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24193323Sed * SUCH DAMAGE.
25193323Sed *
26207618Srdivacky * $FreeBSD: head/sys/amd64/include/intr_machdep.h 151658 2005-10-25 19:48:48Z jhb $
27193323Sed */
28198892Srdivacky
29193323Sed#ifndef __MACHINE_INTR_MACHDEP_H__
30198892Srdivacky#define	__MACHINE_INTR_MACHDEP_H__
31218893Sdim
32193323Sed#ifdef _KERNEL
33193323Sed
34218893Sdim/* With I/O APIC's we can have up to 191 interrupts. */
35193323Sed#define	NUM_IO_INTS	191
36198090Srdivacky#define	INTRCNT_COUNT	(1 + NUM_IO_INTS * 2)
37193323Sed
38207618Srdivacky#ifndef LOCORE
39193323Sed
40193323Sedtypedef void inthand_t(u_int cs, u_int ef, u_int esp, u_int ss);
41198090Srdivacky
42193323Sed#define	IDTVEC(name)	__CONCAT(X,name)
43193323Sed
44218893Sdimstruct intsrc;
45218893Sdim
46218893Sdim/*
47218893Sdim * Methods that a PIC provides to mask/unmask a given interrupt source,
48218893Sdim * "turn on" the interrupt on the CPU side by setting up an IDT entry, and
49218893Sdim * return the vector associated with this source.
50218893Sdim */
51218893Sdimstruct pic {
52207618Srdivacky	void (*pic_enable_source)(struct intsrc *);
53207618Srdivacky	void (*pic_disable_source)(struct intsrc *, int);
54193323Sed	void (*pic_eoi_source)(struct intsrc *);
55193323Sed	void (*pic_enable_intr)(struct intsrc *);
56198892Srdivacky	int (*pic_vector)(struct intsrc *);
57207618Srdivacky	int (*pic_source_pending)(struct intsrc *);
58207618Srdivacky	void (*pic_suspend)(struct intsrc *);
59193323Sed	void (*pic_resume)(struct intsrc *);
60193323Sed	int (*pic_config_intr)(struct intsrc *, enum intr_trigger,
61218893Sdim	    enum intr_polarity);
62198090Srdivacky};
63207618Srdivacky
64218893Sdim/* Flags for pic_disable_source() */
65218893Sdimenum {
66193323Sed	PIC_EOI,
67193323Sed	PIC_NO_EOI,
68198090Srdivacky};
69207618Srdivacky
70193323Sed/*
71193323Sed * An interrupt source.  The upper-layer code uses the PIC methods to
72193323Sed * control a given source.  The lower-layer PIC drivers can store additional
73193323Sed * private data in a given interrupt source such as an interrupt pin number
74210299Sed * or an I/O APIC pointer.
75193323Sed */
76193323Sedstruct intsrc {
77193323Sed	struct pic *is_pic;
78207618Srdivacky	struct intr_event *is_event;
79207618Srdivacky	u_long *is_count;
80218893Sdim	u_long *is_straycount;
81218893Sdim	u_int is_index;
82218893Sdim};
83218893Sdim
84218893Sdimstruct intrframe;
85218893Sdim
86218893Sdimextern struct mtx icu_lock;
87218893Sdimextern int elcr_found;
88218893Sdim
89218893Sdim/* XXX: The elcr_* prototypes probably belong somewhere else. */
90218893Sdimint	elcr_probe(void);
91212904Sdimenum intr_trigger elcr_read_trigger(u_int irq);
92198892Srdivackyvoid	elcr_resume(void);
93207618Srdivackyvoid	elcr_write_trigger(u_int irq, enum intr_trigger trigger);
94193323Sedint	intr_add_handler(const char *name, int vector, driver_intr_t handler,
95193323Sed    void *arg, enum intr_type flags, void **cookiep);
96207618Srdivackyint	intr_config_intr(int vector, enum intr_trigger trig,
97218893Sdim    enum intr_polarity pol);
98218893Sdimvoid	intr_execute_handlers(struct intsrc *isrc, struct intrframe *iframe);
99218893Sdimstruct intsrc *intr_lookup_source(int vector);
100193323Sedint	intr_register_source(struct intsrc *isrc);
101207618Srdivackyint	intr_remove_handler(void *cookie);
102218893Sdimvoid	intr_resume(void);
103218893Sdimvoid	intr_suspend(void);
104218893Sdimvoid	intrcnt_add(const char *name, u_long **countp);
105207618Srdivacky
106193323Sed#endif	/* !LOCORE */
107193323Sed#endif	/* _KERNEL */
108193323Sed#endif	/* !__MACHINE_INTR_MACHDEP_H__ */
109193323Sed