interrupt.h revision 165125
1/*- 2 * Copyright (c) 1997, Stefan Esser <se@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice unmodified, this list of conditions, and the following 10 * disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * 26 * $FreeBSD: head/sys/sys/interrupt.h 165125 2006-12-12 19:20:19Z jhb $ 27 */ 28 29#ifndef _SYS_INTERRUPT_H_ 30#define _SYS_INTERRUPT_H_ 31 32#include <sys/_lock.h> 33#include <sys/_mutex.h> 34 35struct intr_event; 36struct intr_thread; 37 38/* 39 * Describe a hardware interrupt handler. 40 * 41 * Multiple interrupt handlers for a specific event can be chained 42 * together. 43 */ 44struct intr_handler { 45 driver_intr_t *ih_handler; /* Handler function. */ 46 void *ih_argument; /* Argument to pass to handler. */ 47 int ih_flags; 48 const char *ih_name; /* Name of handler. */ 49 struct intr_event *ih_event; /* Event we are connected to. */ 50 int ih_need; /* Needs service. */ 51 TAILQ_ENTRY(intr_handler) ih_next; /* Next handler for this event. */ 52 u_char ih_pri; /* Priority of this handler. */ 53}; 54 55/* Interrupt handle flags kept in ih_flags */ 56#define IH_FAST 0x00000001 /* Fast interrupt. */ 57#define IH_EXCLUSIVE 0x00000002 /* Exclusive interrupt. */ 58#define IH_ENTROPY 0x00000004 /* Device is a good entropy source. */ 59#define IH_DEAD 0x00000008 /* Handler should be removed. */ 60#define IH_MPSAFE 0x80000000 /* Handler does not need Giant. */ 61 62/* 63 * Describe an interrupt event. An event holds a list of handlers. 64 */ 65struct intr_event { 66 TAILQ_ENTRY(intr_event) ie_list; 67 TAILQ_HEAD(, intr_handler) ie_handlers; /* Interrupt handlers. */ 68 char ie_name[MAXCOMLEN]; /* Individual event name. */ 69 char ie_fullname[MAXCOMLEN]; 70 struct mtx ie_lock; 71 void *ie_source; /* Cookie used by MD code. */ 72 struct intr_thread *ie_thread; /* Thread we are connected to. */ 73 void (*ie_enable)(void *); 74 int ie_flags; 75 int ie_count; /* Loop counter. */ 76 int ie_warned; /* Warned about interrupt storm. */ 77}; 78 79/* Interrupt event flags kept in ie_flags. */ 80#define IE_SOFT 0x000001 /* Software interrupt. */ 81#define IE_ENTROPY 0x000002 /* Interrupt is an entropy source. */ 82#define IE_ADDING_THREAD 0x000004 /* Currently building an ithread. */ 83 84/* Flags to pass to sched_swi. */ 85#define SWI_DELAY 0x2 86 87/* 88 * Software interrupt numbers in priority order. The priority determines 89 * the priority of the corresponding interrupt thread. 90 */ 91#define SWI_TTY 0 92#define SWI_NET 1 93#define SWI_CAMBIO 2 94#define SWI_VM 3 95#define SWI_CLOCK 4 96#define SWI_TQ_FAST 5 97#define SWI_TQ 6 98#define SWI_TQ_GIANT 6 99 100extern struct intr_event *tty_intr_event; 101extern struct intr_event *clk_intr_event; 102extern void *softclock_ih; 103extern void *vm_ih; 104 105/* Counts and names for statistics (defined in MD code). */ 106extern u_long eintrcnt[]; /* end of intrcnt[] */ 107extern char eintrnames[]; /* end of intrnames[] */ 108extern u_long intrcnt[]; /* counts for for each device and stray */ 109extern char intrnames[]; /* string table containing device names */ 110 111#ifdef DDB 112void db_dump_intr_event(struct intr_event *ie, int handlers); 113#endif 114u_char intr_priority(enum intr_type flags); 115int intr_event_add_handler(struct intr_event *ie, const char *name, 116 driver_intr_t handler, void *arg, u_char pri, enum intr_type flags, 117 void **cookiep); 118int intr_event_create(struct intr_event **event, void *source, 119 int flags, void (*enable)(void *), const char *fmt, ...) 120 __printflike(5, 6); 121int intr_event_destroy(struct intr_event *ie); 122int intr_event_remove_handler(void *cookie); 123int intr_event_schedule_thread(struct intr_event *ie); 124void *intr_handler_source(void *cookie); 125int swi_add(struct intr_event **eventp, const char *name, 126 driver_intr_t handler, void *arg, int pri, enum intr_type flags, 127 void **cookiep); 128void swi_sched(void *cookie, int flags); 129int swi_remove(void *cookie); 130 131#endif 132