interrupt.h revision 139825
1139825Simp/*-
226156Sse * Copyright (c) 1997, Stefan Esser <se@freebsd.org>
326156Sse * All rights reserved.
426156Sse *
526156Sse * Redistribution and use in source and binary forms, with or without
626156Sse * modification, are permitted provided that the following conditions
726156Sse * are met:
826156Sse * 1. Redistributions of source code must retain the above copyright
926156Sse *    notice unmodified, this list of conditions, and the following
1026156Sse *    disclaimer.
1126156Sse * 2. Redistributions in binary form must reproduce the above copyright
1226156Sse *    notice, this list of conditions and the following disclaimer in the
1326156Sse *    documentation and/or other materials provided with the distribution.
1426156Sse *
1526156Sse * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1626156Sse * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1726156Sse * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1826156Sse * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1926156Sse * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2026156Sse * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2126156Sse * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2226156Sse * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2326156Sse * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2426156Sse * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2526156Sse *
2650477Speter * $FreeBSD: head/sys/sys/interrupt.h 139825 2005-01-07 02:29:27Z imp $
2726156Sse */
2826156Sse
2945897Speter#ifndef _SYS_INTERRUPT_H_
3045897Speter#define _SYS_INTERRUPT_H_
3126380Sdfr
3276771Sjhb#include <sys/_lock.h>
3376771Sjhb#include <sys/_mutex.h>
3476771Sjhb
3565822Sjhb/*
3665822Sjhb * Describe a hardware interrupt handler.
3765822Sjhb *
3865822Sjhb * Multiple interrupt handlers for a specific vector can be chained
3972237Sjhb * together.
4065822Sjhb */
4183045Sobrienstruct intrhand {
4272237Sjhb	driver_intr_t	*ih_handler;	/* Handler function. */
4372237Sjhb	void		*ih_argument;	/* Argument to pass to handler. */
4472237Sjhb	int		 ih_flags;
4572237Sjhb	const char	*ih_name;	/* Name of handler. */
4672237Sjhb	struct ithd	*ih_ithread;	/* Ithread we are connected to. */
4772237Sjhb	int		 ih_need;	/* Needs service. */
4872237Sjhb	TAILQ_ENTRY(intrhand) ih_next;	/* Next handler for this vector. */
4972237Sjhb	u_char		 ih_pri;	/* Priority of this handler. */
5072237Sjhb};
5165822Sjhb
5272237Sjhb/* Interrupt handle flags kept in ih_flags */
5372237Sjhb#define	IH_FAST		0x00000001	/* Fast interrupt. */
5472237Sjhb#define	IH_EXCLUSIVE	0x00000002	/* Exclusive interrupt. */
5572237Sjhb#define	IH_ENTROPY	0x00000004	/* Device is a good entropy source. */
5672839Sjhb#define	IH_DEAD		0x00000008	/* Handler should be removed. */
5772237Sjhb#define	IH_MPSAFE	0x80000000	/* Handler does not need Giant. */
5872237Sjhb
5972237Sjhb/*
6072237Sjhb * Describe an interrupt thread.  There is one of these per interrupt vector.
6172237Sjhb * Note that this actually describes an interrupt source.  There may or may
6272237Sjhb * not be an actual kernel thread attached to a given source.
6372237Sjhb */
6483045Sobrienstruct ithd {
6576771Sjhb	struct	mtx it_lock;
6683366Sjulian	struct	thread *it_td;		/* Interrupt process. */
6772237Sjhb	LIST_ENTRY(ithd) it_list;	/* All interrupt threads. */
6872237Sjhb	TAILQ_HEAD(, intrhand) it_handlers; /* Interrupt handlers. */
6972237Sjhb	struct	ithd *it_interrupted;	/* Who we interrupted. */
70122840Speter	void	(*it_disable)(uintptr_t); /* Enable interrupt source. */
71122840Speter	void	(*it_enable)(uintptr_t); /* Disable interrupt source. */
7272237Sjhb	void	*it_md;			/* Hook for MD interrupt code. */
7372237Sjhb	int	it_flags;		/* Interrupt-specific flags. */
7472237Sjhb	int	it_need;		/* Needs service. */
75122840Speter	uintptr_t it_vector;
7672237Sjhb	char	it_name[MAXCOMLEN + 1];
7765822Sjhb};
7865822Sjhb
7972237Sjhb/* Interrupt thread flags kept in it_flags */
8072237Sjhb#define	IT_SOFT		0x000001	/* Software interrupt. */
8172237Sjhb#define	IT_ENTROPY	0x000002	/* Interrupt is an entropy source. */
8272237Sjhb#define	IT_DEAD		0x000004	/* Thread is waiting to exit. */
8372237Sjhb
8472237Sjhb/* Flags to pass to sched_swi. */
8588900Sjhb#define	SWI_DELAY	0x2
8638244Sbde
8776057Sjhb/*
88131244Sjhb * Software interrupt numbers in priority order.  The priority determines
89131244Sjhb * the priority of the corresponding interrupt thread.
9076057Sjhb */
9176057Sjhb#define	SWI_TTY		0
9276057Sjhb#define	SWI_NET		1
93136134Sscottl#define	SWI_CAMBIO	2
94136134Sscottl#define	SWI_VM		3
95136134Sscottl#define	SWI_CLOCK	4
96136134Sscottl#define	SWI_TQ_FAST	5
97131244Sjhb#define	SWI_TQ		6
98119789Ssam#define	SWI_TQ_GIANT	6
9976057Sjhb
10072237Sjhbextern struct	ithd *tty_ithd;
10172237Sjhbextern struct	ithd *clk_ithd;
10272237Sjhbextern void	*net_ih;
10372237Sjhbextern void	*softclock_ih;
10472237Sjhbextern void	*vm_ih;
10566698Sjhb
10677582Stmm/* Counts and names for statistics (defined in MD code). */
10777582Stmmextern u_long 	eintrcnt[];	/* end of intrcnt[] */
10877582Stmmextern char 	eintrnames[];	/* end of intrnames[] */
10977582Stmmextern u_long 	intrcnt[];	/* counts for for each device and stray */
11077582Stmmextern char 	intrnames[];	/* string table containing device names */
11177582Stmm
112121482Sjhb#ifdef DDB
113121482Sjhbvoid	db_dump_ithread(struct ithd *ithd, int handlers);
114121482Sjhb#endif
115122840Speterint	ithread_create(struct ithd **ithread, uintptr_t vector, int flags,
116122840Speter	    void (*disable)(uintptr_t), void (*enable)(uintptr_t),
117122840Speter	    const char *fmt, ...) __printflike(6, 7);
11892719Salfredint	ithread_destroy(struct ithd *ithread);
11992719Salfredu_char	ithread_priority(enum intr_type flags);
12092719Salfredint	ithread_add_handler(struct ithd *ithread, const char *name,
12172237Sjhb	    driver_intr_t handler, void *arg, u_char pri, enum intr_type flags,
12292719Salfred	    void **cookiep);
12392719Salfredint	ithread_remove_handler(void *cookie);
124131481Sjhbint	ithread_schedule(struct ithd *ithread);
12592719Salfredint     swi_add(struct ithd **ithdp, const char *name,
12672237Sjhb	    driver_intr_t handler, void *arg, int pri, enum intr_type flags,
12792719Salfred	    void **cookiep);
12892719Salfredvoid	swi_sched(void *cookie, int flags);
12938244Sbde
13038244Sbde#endif
131