interrupt.h revision 119789
126156Sse/*
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 119789 2003-09-05 23:09:22Z sam $
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. */
7072237Sjhb	void	(*it_disable)(int);	/* Enable interrupt source. */
7172237Sjhb	void	(*it_enable)(int);	/* 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. */
7572237Sjhb	int	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/*
8876057Sjhb * Software interrupt bit numbers in priority order.  The priority only
8976057Sjhb * determines which swi will be dispatched next; a higher priority swi
9076057Sjhb * may be dispatched when a nested h/w interrupt handler returns.
9176057Sjhb */
9276057Sjhb#define	SWI_TTY		0
9376057Sjhb#define	SWI_NET		1
9476057Sjhb#define	SWI_CAMNET	2
9576057Sjhb#define	SWI_CAMBIO	3
9676057Sjhb#define	SWI_VM		4
97119789Ssam#define	SWI_TQ_FAST	5
98119789Ssam#define	SWI_TQ_GIANT	6
99119789Ssam#define	SWI_TQ		7
100119789Ssam#define	SWI_CLOCK	8
10176057Sjhb
10272237Sjhbextern struct	ithd *tty_ithd;
10372237Sjhbextern struct	ithd *clk_ithd;
10472237Sjhbextern void	*net_ih;
10572237Sjhbextern void	*softclock_ih;
10672237Sjhbextern void	*vm_ih;
10766698Sjhb
10877582Stmm/* Counts and names for statistics (defined in MD code). */
10977582Stmmextern u_long 	eintrcnt[];	/* end of intrcnt[] */
11077582Stmmextern char 	eintrnames[];	/* end of intrnames[] */
11177582Stmmextern u_long 	intrcnt[];	/* counts for for each device and stray */
11277582Stmmextern char 	intrnames[];	/* string table containing device names */
11377582Stmm
11492719Salfredint	ithread_create(struct ithd **ithread, int vector, int flags,
11592719Salfred	    void (*disable)(int), void (*enable)(int), const char *fmt, ...)
11672237Sjhb	    __printflike(6, 7);
11792719Salfredint	ithread_destroy(struct ithd *ithread);
11892719Salfredu_char	ithread_priority(enum intr_type flags);
11992719Salfredint	ithread_add_handler(struct ithd *ithread, const char *name,
12072237Sjhb	    driver_intr_t handler, void *arg, u_char pri, enum intr_type flags,
12192719Salfred	    void **cookiep);
12292719Salfredint	ithread_remove_handler(void *cookie);
12392719Salfredint	ithread_schedule(struct ithd *ithread, int do_switch);
12492719Salfredint     swi_add(struct ithd **ithdp, const char *name,
12572237Sjhb	    driver_intr_t handler, void *arg, int pri, enum intr_type flags,
12692719Salfred	    void **cookiep);
12792719Salfredvoid	swi_sched(void *cookie, int flags);
12838244Sbde
12938244Sbde#endif
130