intr_machdep.h revision 153241
174462Salfred/*-
274462Salfred * Copyright (c) 2003 John Baldwin <jhb@FreeBSD.org>
3258578Shrs * All rights reserved.
4258578Shrs *
5258578Shrs * Redistribution and use in source and binary forms, with or without
68858Srgrimes * modification, are permitted provided that the following conditions
7258578Shrs * are met:
8258578Shrs * 1. Redistributions of source code must retain the above copyright
9258578Shrs *    notice, this list of conditions and the following disclaimer.
10258578Shrs * 2. Redistributions in binary form must reproduce the above copyright
11258578Shrs *    notice, this list of conditions and the following disclaimer in the
12258578Shrs *    documentation and/or other materials provided with the distribution.
13258578Shrs *
14258578Shrs * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15258578Shrs * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16258578Shrs * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
178858Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18258578Shrs * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19258578Shrs * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20258578Shrs * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21258578Shrs * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22258578Shrs * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23258578Shrs * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24258578Shrs * SUCH DAMAGE.
25258578Shrs *
26258578Shrs * $FreeBSD: head/sys/amd64/include/intr_machdep.h 153241 2005-12-08 18:33:30Z jhb $
27258578Shrs */
28258578Shrs
298858Srgrimes#ifndef __MACHINE_INTR_MACHDEP_H__
301903Swollman#define	__MACHINE_INTR_MACHDEP_H__
311903Swollman
3250473Speter#ifdef _KERNEL
331839Swollman
341839Swollman/*
351839Swollman * The maximum number of I/O interrupts we allow.  This number is rather
361839Swollman * arbitrary as it is just the maximum IRQ resource value.  The interrupt
371839Swollman * source for a given IRQ maps that I/O interrupt to device interrupt
381839Swollman * source whether it be a pin on an interrupt controller or an MSI interrupt.
391839Swollman * The 16 ISA IRQs are assigned fixed IDT vectors, but all other device
401839Swollman * interrupts allocate IDT vectors on demand.  Currently we have 191 IDT
411839Swollman * vectors available for device interrupts.  On many systems with I/O APICs,
4274462Salfred * a lot of the IRQs are not used, so this number can be much larger than
4374462Salfred * 191 and still be safe since only interrupt sources in actual use will
441903Swollman * allocate IDT vectors.
4574462Salfred *
461839Swollman * For now we stick with 255 as ISA IRQs and PCI intline IRQs only allow
471839Swollman * for IRQs in the range 0 - 254.  When MSI support is added this number
481839Swollman * will likely increase.
491839Swollman */
501839Swollman#define	NUM_IO_INTS	255
511839Swollman
521839Swollman/*
531839Swollman * - 1 ??? dummy counter.
541839Swollman * - 2 counters for each I/O interrupt.
551839Swollman * - 1 counter for each CPU for lapic timer.
561839Swollman * - 7 counters for each CPU for IPI counters for SMP.
571839Swollman */
581839Swollman#ifdef SMP
591839Swollman#define	INTRCNT_COUNT	(1 + NUM_IO_INTS * 2 + 1)
601839Swollman#else
611839Swollman#define	INTRCNT_COUNT	(1 + NUM_IO_INTS * 2 + (1 + 7) * MAXCPU)
621839Swollman#endif
631839Swollman
641839Swollman#ifndef LOCORE
651839Swollman
661839Swollmantypedef void inthand_t(u_int cs, u_int ef, u_int esp, u_int ss);
671839Swollman
681839Swollman#define	IDTVEC(name)	__CONCAT(X,name)
691839Swollman
701839Swollmanstruct intsrc;
711839Swollman
721839Swollman/*
731839Swollman * Methods that a PIC provides to mask/unmask a given interrupt source,
741839Swollman * "turn on" the interrupt on the CPU side by setting up an IDT entry, and
751839Swollman * return the vector associated with this source.
761839Swollman */
771839Swollmanstruct pic {
781839Swollman	void (*pic_enable_source)(struct intsrc *);
791839Swollman	void (*pic_disable_source)(struct intsrc *, int);
801839Swollman	void (*pic_eoi_source)(struct intsrc *);
811839Swollman	void (*pic_enable_intr)(struct intsrc *);
821839Swollman	int (*pic_vector)(struct intsrc *);
831839Swollman	int (*pic_source_pending)(struct intsrc *);
841839Swollman	void (*pic_suspend)(struct intsrc *);
851839Swollman	void (*pic_resume)(struct intsrc *);
861839Swollman	int (*pic_config_intr)(struct intsrc *, enum intr_trigger,
871839Swollman	    enum intr_polarity);
881839Swollman};
891839Swollman
901839Swollman/* Flags for pic_disable_source() */
911839Swollmanenum {
9274462Salfred	PIC_EOI,
9374462Salfred	PIC_NO_EOI,
941839Swollman};
951839Swollman
961839Swollman/*
971839Swollman * An interrupt source.  The upper-layer code uses the PIC methods to
981839Swollman * control a given source.  The lower-layer PIC drivers can store additional
991839Swollman * private data in a given interrupt source such as an interrupt pin number
1001839Swollman * or an I/O APIC pointer.
1011839Swollman */
1021839Swollmanstruct intsrc {
1031839Swollman	struct pic *is_pic;
1041839Swollman	struct intr_event *is_event;
1051839Swollman	u_long *is_count;
1061839Swollman	u_long *is_straycount;
1071839Swollman	u_int is_index;
1081839Swollman};
1091839Swollman
1101839Swollmanstruct trapframe;
1111839Swollman
11274462Salfredextern struct mtx icu_lock;
11374462Salfredextern int elcr_found;
1141839Swollman
1151839Swollman/* XXX: The elcr_* prototypes probably belong somewhere else. */
1161839Swollmanint	elcr_probe(void);
1171839Swollmanenum intr_trigger elcr_read_trigger(u_int irq);
1181839Swollmanvoid	elcr_resume(void);
1191839Swollmanvoid	elcr_write_trigger(u_int irq, enum intr_trigger trigger);
1201839Swollmanint	intr_add_handler(const char *name, int vector, driver_intr_t handler,
1211839Swollman    void *arg, enum intr_type flags, void **cookiep);
1221839Swollmanint	intr_config_intr(int vector, enum intr_trigger trig,
1231839Swollman    enum intr_polarity pol);
1241839Swollmanvoid	intr_execute_handlers(struct intsrc *isrc, struct trapframe *frame);
1251839Swollmanstruct intsrc *intr_lookup_source(int vector);
1261839Swollmanint	intr_register_source(struct intsrc *isrc);
1271839Swollmanint	intr_remove_handler(void *cookie);
1281839Swollmanvoid	intr_resume(void);
1291839Swollmanvoid	intr_suspend(void);
1301839Swollmanvoid	intrcnt_add(const char *name, u_long **countp);
1311839Swollman
1321839Swollman#endif	/* !LOCORE */
1331839Swollman#endif	/* _KERNEL */
1341839Swollman#endif	/* !__MACHINE_INTR_MACHDEP_H__ */
1351839Swollman