13cdbaee3SMitchell Horne.\" Copyright (c) 2001 John H. Baldwin <jhb@FreeBSD.org> 22af741fcSMitchell Horne.\" Copyright (c) 2006 Tom Rhodes <trhodes@FreeBSD.org> 32af741fcSMitchell Horne.\" Copyright (c) 2021 Mitchell Horne <mhorne@FreeBSD.org> 42af741fcSMitchell Horne.\" Copyright (c) 2022 The FreeBSD Foundation 52af741fcSMitchell Horne.\" 62af741fcSMitchell Horne.\" Portions of this documentation were written by Mitchell Horne 72af741fcSMitchell Horne.\" under sponsorship from the FreeBSD Foundation. 83cdbaee3SMitchell Horne.\" 93cdbaee3SMitchell Horne.\" Redistribution and use in source and binary forms, with or without 103cdbaee3SMitchell Horne.\" modification, are permitted provided that the following conditions 113cdbaee3SMitchell Horne.\" are met: 123cdbaee3SMitchell Horne.\" 1. Redistributions of source code must retain the above copyright 133cdbaee3SMitchell Horne.\" notice, this list of conditions and the following disclaimer. 143cdbaee3SMitchell Horne.\" 2. Redistributions in binary form must reproduce the above copyright 153cdbaee3SMitchell Horne.\" notice, this list of conditions and the following disclaimer in the 163cdbaee3SMitchell Horne.\" documentation and/or other materials provided with the distribution. 173cdbaee3SMitchell Horne.\" 183cdbaee3SMitchell Horne.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 193cdbaee3SMitchell Horne.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 203cdbaee3SMitchell Horne.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 213cdbaee3SMitchell Horne.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 223cdbaee3SMitchell Horne.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 233cdbaee3SMitchell Horne.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 243cdbaee3SMitchell Horne.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 253cdbaee3SMitchell Horne.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 263cdbaee3SMitchell Horne.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 273cdbaee3SMitchell Horne.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 283cdbaee3SMitchell Horne.\" SUCH DAMAGE. 293cdbaee3SMitchell Horne.\" 30*0863dc10SAndrew Turner.Dd January 24, 2025 313cdbaee3SMitchell Horne.Dt INTR_EVENT 9 323cdbaee3SMitchell Horne.Os 333cdbaee3SMitchell Horne.Sh NAME 343cdbaee3SMitchell Horne.Nm intr_event_add_handler , 353cdbaee3SMitchell Horne.Nm intr_event_create , 363cdbaee3SMitchell Horne.Nm intr_event_destroy , 37a4532c4cSMitchell Horne.Nm intr_event_handle , 383cdbaee3SMitchell Horne.Nm intr_event_remove_handler , 393cdbaee3SMitchell Horne.Nm intr_priority 403cdbaee3SMitchell Horne.Nd "kernel interrupt handler and thread API" 413cdbaee3SMitchell Horne.Sh SYNOPSIS 423cdbaee3SMitchell Horne.In sys/param.h 433cdbaee3SMitchell Horne.In sys/bus.h 443cdbaee3SMitchell Horne.In sys/interrupt.h 453cdbaee3SMitchell Horne.Ft int 463cdbaee3SMitchell Horne.Fo intr_event_add_handler 473cdbaee3SMitchell Horne.Fa "struct intr_event *ie" 483cdbaee3SMitchell Horne.Fa "const char *name" 493cdbaee3SMitchell Horne.Fa "driver_filter_t filter" 503cdbaee3SMitchell Horne.Fa "driver_intr_t handler" 513cdbaee3SMitchell Horne.Fa "void *arg" 523cdbaee3SMitchell Horne.Fa "u_char pri" 533cdbaee3SMitchell Horne.Fa "enum intr_type flags" 543cdbaee3SMitchell Horne.Fa "void **cookiep" 553cdbaee3SMitchell Horne.Fc 563cdbaee3SMitchell Horne.Ft int 573cdbaee3SMitchell Horne.Fo intr_event_create 583cdbaee3SMitchell Horne.Fa "struct intr_event **event" 593cdbaee3SMitchell Horne.Fa "void *source" 603cdbaee3SMitchell Horne.Fa "int flags" 613cdbaee3SMitchell Horne.Fa "int irq" 623cdbaee3SMitchell Horne.Fa "void (*pre_ithread)(void *)" 633cdbaee3SMitchell Horne.Fa "void (*post_ithread)(void *)" 643cdbaee3SMitchell Horne.Fa "void (*post_filter)(void *)" 653cdbaee3SMitchell Horne.Fa "int (*assign_cpu)(void *, int)" 663cdbaee3SMitchell Horne.Fa "const char *fmt" 673cdbaee3SMitchell Horne.Fa "..." 683cdbaee3SMitchell Horne.Fc 693cdbaee3SMitchell Horne.Ft int 703cdbaee3SMitchell Horne.Fn intr_event_destroy "struct intr_event *ie" 713cdbaee3SMitchell Horne.Ft int 72334fc46fSMitchell Horne.Fn intr_event_handle "struct intr_event *ie" "struct trapframe *frame" 73334fc46fSMitchell Horne.Ft int 743cdbaee3SMitchell Horne.Fn intr_event_remove_handler "void *cookie" 753cdbaee3SMitchell Horne.Ft u_char 763cdbaee3SMitchell Horne.Fn intr_priority "enum intr_type flags" 773cdbaee3SMitchell Horne.Sh DESCRIPTION 78dfc91493SMitchell HorneThe interrupt event API provides methods to manage the registration and 79dfc91493SMitchell Horneexecution of interrupt handlers and their associated thread contexts. 803cdbaee3SMitchell Horne.Pp 81dfc91493SMitchell HorneEach interrupt event in the system corresponds to a single hardware or software 82dfc91493SMitchell Horneinterrupt source. 83dfc91493SMitchell HorneEach interrupt event maintains a list of interrupt handlers, sorted by 84dfc91493SMitchell Hornepriority, which will be invoked when handling the event. 85dfc91493SMitchell HorneAn interrupt event will typically, but not always, have an associated 86dfc91493SMitchell Horne.Xr kthread 9 , 87dfc91493SMitchell Horneknown as the interrupt thread. 88dfc91493SMitchell HorneFinally, each event contains optional callback functions which will be 89dfc91493SMitchell Horneinvoked before and after the handler functions themselves. 90dfc91493SMitchell Horne.Pp 91dfc91493SMitchell HorneAn interrupt handler contains two distinct handler functions: 92dfc91493SMitchell Hornethe 93dfc91493SMitchell Horne.Em filter 94dfc91493SMitchell Horneand the thread 95dfc91493SMitchell Horne.Em handler . 96dfc91493SMitchell HorneThe 97dfc91493SMitchell Horne.Em filter 98dfc91493SMitchell Hornefunction is run from interrupt context and is intended to perform quick 99dfc91493SMitchell Hornehandling such as acknowledging or masking a hardware interrupt, 100dfc91493SMitchell Horneand queueing work for the ensuing thread 101dfc91493SMitchell Horne.Em handler . 102dfc91493SMitchell HorneBoth functions are optional; each interrupt handler may choose to register a 103dfc91493SMitchell Hornefilter, a thread handler, or both. 104dfc91493SMitchell HorneEach interrupt handler also consists of a name, 105dfc91493SMitchell Hornea set of flags, 106dfc91493SMitchell Horneand an opaque argument which will be passed to both the 107dfc91493SMitchell Horne.Em filter 108dfc91493SMitchell Horneand 109dfc91493SMitchell Horne.Em handler 110dfc91493SMitchell Hornefunctions. 111dfc91493SMitchell Horne.Ss Handler Constraints 112dfc91493SMitchell HorneThe 113dfc91493SMitchell Horne.Em filter 114dfc91493SMitchell Hornefunction is executed inside a 115dfc91493SMitchell Horne.Xr critical 9 116dfc91493SMitchell Hornesection. 117dfc91493SMitchell HorneTherefore, filters may not yield the CPU for any reason, and may only use spin 118dfc91493SMitchell Hornelocks to access shared data. 119dfc91493SMitchell HorneAllocating memory within a filter is not permitted. 120dfc91493SMitchell Horne.Pp 121dfc91493SMitchell HorneThe 122dfc91493SMitchell Horne.Em handler 123dfc91493SMitchell Hornefunction executes from the context of the associated interrupt kernel thread. 124dfc91493SMitchell HorneSleeping is not permitted, but the interrupt thread may be preempted by higher 125dfc91493SMitchell Hornepriority threads. 126dfc91493SMitchell HorneThus, threaded handler functions may obtain non-sleepable locks, as described 127dfc91493SMitchell Hornein 128dfc91493SMitchell Horne.Xr locking 9 . 129dfc91493SMitchell HorneAny memory or zone allocations in an interrupt thread must specify the 130dfc91493SMitchell Horne.Dv M_NOWAIT 131dfc91493SMitchell Horneflag, and any allocation errors must be handled. 132dfc91493SMitchell Horne.Pp 133dfc91493SMitchell HorneThe exception to these constraints is software interrupt threads, which are 134dfc91493SMitchell Horneallowed to sleep but should be allocated and scheduled using the 135dfc91493SMitchell Horne.Xr swi 9 136dfc91493SMitchell Horneinterface. 137dfc91493SMitchell Horne.Ss Function Descriptions 1383cdbaee3SMitchell HorneThe 1393cdbaee3SMitchell Horne.Fn intr_event_create 140cb9425e2SMitchell Hornefunction creates a new interrupt event. 141cb9425e2SMitchell HorneThe 142cb9425e2SMitchell Horne.Fa event 143cb9425e2SMitchell Horneargument points to a 144cb9425e2SMitchell Horne.Vt struct intr_event 145cb9425e2SMitchell Hornepointer that will reference the newly created event upon success. 1463cdbaee3SMitchell HorneThe 1473cdbaee3SMitchell Horne.Fa source 148cb9425e2SMitchell Horneargument is an opaque pointer which will be passed to the 149cb9425e2SMitchell Horne.Fa pre_ithread , 150cb9425e2SMitchell Horne.Fa post_ithread , 151cb9425e2SMitchell Horneand 152cb9425e2SMitchell Horne.Fa post_filter 153cb9425e2SMitchell Hornecallbacks. 1543cdbaee3SMitchell HorneThe 1553cdbaee3SMitchell Horne.Fa flags 1563cdbaee3SMitchell Horneargument is a mask of properties of this thread. 1573cdbaee3SMitchell HorneThe only valid flag currently for 1583cdbaee3SMitchell Horne.Fn intr_event_create 1593cdbaee3SMitchell Horneis 1603cdbaee3SMitchell Horne.Dv IE_SOFT 1613cdbaee3SMitchell Horneto specify that this interrupt thread is a software interrupt. 1623cdbaee3SMitchell HorneThe 1633cdbaee3SMitchell Horne.Fa enable 1643cdbaee3SMitchell Horneand 1653cdbaee3SMitchell Horne.Fa disable 1663cdbaee3SMitchell Hornearguments specify optional functions used to enable and disable this 1673cdbaee3SMitchell Horneinterrupt thread's interrupt source. 168cb9425e2SMitchell HorneThe 169cb9425e2SMitchell Horne.Fa irq 170cb9425e2SMitchell Horneargument is the unique interrupt vector number corresponding to the event. 171cb9425e2SMitchell HorneThe 172cb9425e2SMitchell Horne.Fa pre_ithread , 173cb9425e2SMitchell Horne.Fa post_ithread , 174cb9425e2SMitchell Horneand 175cb9425e2SMitchell Horne.Fa post_filter 176cb9425e2SMitchell Hornearguments are callback functions that are invoked at different 177cb9425e2SMitchell Hornepoints while handling an interrupt. 178cb9425e2SMitchell HorneThis is described in more detail in the 179cb9425e2SMitchell Horne.Sx Handler Callbacks 180cb9425e2SMitchell Hornesection, below. 181cb9425e2SMitchell HorneThey may be 182cb9425e2SMitchell Horne.Va NULL 183cb9425e2SMitchell Horneto specify no callback. 184cb9425e2SMitchell HorneThe 185cb9425e2SMitchell Horne.Fa assign_cpu 186cb9425e2SMitchell Horneargument points to a callback function that will be invoked when binding 187cb9425e2SMitchell Hornean interrupt to a particular CPU. 188cb9425e2SMitchell HorneIt may be 189cb9425e2SMitchell Horne.Va NULL 190cb9425e2SMitchell Horneif binding is unsupported. 191cb9425e2SMitchell HorneThe 192cb9425e2SMitchell Horneremaining arguments form a 1933cdbaee3SMitchell Horne.Xr printf 9 1943cdbaee3SMitchell Horneargument list that is used to build the base name of the new interrupt thread. 1953cdbaee3SMitchell HorneThe full name of an interrupt thread is formed by concatenating the base 1963cdbaee3SMitchell Hornename of the interrupt thread with the names of all of its interrupt handlers. 1973cdbaee3SMitchell Horne.Pp 1983cdbaee3SMitchell HorneThe 1993cdbaee3SMitchell Horne.Fn intr_event_destroy 200cb9425e2SMitchell Hornefunction destroys a previously created interrupt event by releasing its 201cb9425e2SMitchell Horneresources. 202cb9425e2SMitchell Horne.\" The following is not true (yet): 203cb9425e2SMitchell Horne.\"and arranging for the backing kernel thread to terminate. 204cb9425e2SMitchell HorneAn interrupt event can only be destroyed if it has no handlers remaining. 2053cdbaee3SMitchell Horne.Pp 2063cdbaee3SMitchell HorneThe 2073cdbaee3SMitchell Horne.Fn intr_event_add_handler 208cb9425e2SMitchell Hornefunction adds a new handler to an existing interrupt event specified by 209cb9425e2SMitchell Horne.Fa ie . 2103cdbaee3SMitchell HorneThe 2113cdbaee3SMitchell Horne.Fa name 2123cdbaee3SMitchell Horneargument specifies a name for this handler. 2133cdbaee3SMitchell HorneThe 214cb9425e2SMitchell Horne.Fa filter 215cb9425e2SMitchell Horneargument provide the filter function to execute. 216cb9425e2SMitchell HorneThe 2173cdbaee3SMitchell Horne.Fa handler 218cb9425e2SMitchell Horneargument provides the handler function to be executed from the 219cb9425e2SMitchell Horneevent's interrupt thread. 220cb9425e2SMitchell HorneThe 2213cdbaee3SMitchell Horne.Fa arg 222cb9425e2SMitchell Horneargument will be passed to the 223cb9425e2SMitchell Horne.Fa filter 224cb9425e2SMitchell Horneand 225cb9425e2SMitchell Horne.Fa handler 226cb9425e2SMitchell Hornefunctions when they are invoked. 2273cdbaee3SMitchell HorneThe 2283cdbaee3SMitchell Horne.Fa pri 229cb9425e2SMitchell Horneargument specifies the priority of this handler, 230cb9425e2SMitchell Hornecorresponding to the values defined in 231cb9425e2SMitchell Horne.In sys/priority.h . 232cb9425e2SMitchell HorneIt determines the order this handler is called relative to the other handlers 2332c346617SGordon Berglingfor this event, as well as the scheduling priority of the backing kernel 234cb9425e2SMitchell Hornethread. 2353cdbaee3SMitchell Horne.Fa flags 2363cdbaee3SMitchell Horneargument can be used to specify properties of this handler as defined in 2373cdbaee3SMitchell Horne.In sys/bus.h . 2383cdbaee3SMitchell HorneIf 2393cdbaee3SMitchell Horne.Fa cookiep 2403cdbaee3SMitchell Horneis not 2413cdbaee3SMitchell Horne.Dv NULL , 2423cdbaee3SMitchell Hornethen it will be assigned a cookie that can be used later to remove this 2433cdbaee3SMitchell Hornehandler. 2443cdbaee3SMitchell Horne.Pp 2453cdbaee3SMitchell HorneThe 246334fc46fSMitchell Horne.Fn intr_event_handle 247334fc46fSMitchell Hornefunction is the main entry point into the interrupt handling code. 248334fc46fSMitchell HorneIt must be called from an interrupt context. 249334fc46fSMitchell HorneThe function will execute all filter handlers associated with the interrupt 250334fc46fSMitchell Horneevent 251334fc46fSMitchell Horne.Fa ie , 252334fc46fSMitchell Horneand schedule the associated interrupt thread to run, if applicable. 253334fc46fSMitchell HorneThe 254334fc46fSMitchell Horne.Fa frame 255334fc46fSMitchell Horneargument is used to pass a pointer to the 256334fc46fSMitchell Horne.Vt struct trapframe 257334fc46fSMitchell Hornecontaining the machine state at the time of the interrupt. 258334fc46fSMitchell HorneThe main body of this function runs within a 259334fc46fSMitchell Horne.Xr critical 9 260334fc46fSMitchell Hornesection. 261334fc46fSMitchell Horne.Pp 262334fc46fSMitchell HorneThe 2633cdbaee3SMitchell Horne.Fn intr_event_remove_handler 264cb9425e2SMitchell Hornefunction removes an interrupt handler from the interrupt event specified by 265cb9425e2SMitchell Horne.Fa ie . 2663cdbaee3SMitchell HorneThe 2673cdbaee3SMitchell Horne.Fa cookie 268cb9425e2SMitchell Horneargument, obtained from 269cb9425e2SMitchell Horne.Fn intr_event_add_handler , 270cb9425e2SMitchell Horneidentifies the handler to remove. 2713cdbaee3SMitchell Horne.Pp 2723cdbaee3SMitchell HorneThe 2733cdbaee3SMitchell Horne.Fn intr_priority 2743cdbaee3SMitchell Hornefunction translates the 2753cdbaee3SMitchell Horne.Dv INTR_TYPE_* 2763cdbaee3SMitchell Horneinterrupt flags into interrupt thread scheduling priorities. 2773cdbaee3SMitchell Horne.Pp 2783cdbaee3SMitchell HorneThe interrupt flags not related to the type of a particular interrupt 2793cdbaee3SMitchell Horne.Pq Dv INTR_TYPE_* 2803cdbaee3SMitchell Hornecan be used to specify additional properties of both hardware and software 2813cdbaee3SMitchell Horneinterrupt handlers. 2823cdbaee3SMitchell HorneThe 2833cdbaee3SMitchell Horne.Dv INTR_EXCL 2843cdbaee3SMitchell Horneflag specifies that this handler cannot share an interrupt thread with 2853cdbaee3SMitchell Horneanother handler. 2863cdbaee3SMitchell HorneThe 2873cdbaee3SMitchell Horne.Dv INTR_MPSAFE 2883cdbaee3SMitchell Horneflag specifies that this handler is MP safe in that it does not need the 2893cdbaee3SMitchell HorneGiant mutex to be held while it is executed. 2903cdbaee3SMitchell HorneThe 2913cdbaee3SMitchell Horne.Dv INTR_ENTROPY 2923cdbaee3SMitchell Horneflag specifies that the interrupt source this handler is tied to is a good 2933cdbaee3SMitchell Hornesource of entropy, and thus that entropy should be gathered when an interrupt 2943cdbaee3SMitchell Hornefrom the handler's source triggers. 2953cdbaee3SMitchell HornePresently, the 2963cdbaee3SMitchell Horne.Dv INTR_ENTROPY 2973cdbaee3SMitchell Horneflag is not valid for software interrupt handlers. 298*0863dc10SAndrew TurnerThe 299*0863dc10SAndrew Turner.Dv INTR_SLEEPABLE 300*0863dc10SAndrew Turnerflag specifies that the interrupt ithread may sleep. 301*0863dc10SAndrew TurnerPresently, the 302*0863dc10SAndrew Turner.Dv INTR_SLEEPABLE 303*0863dc10SAndrew Turnerflag requires the 304*0863dc10SAndrew Turner.Dv INTR_EXCL 305*0863dc10SAndrew Turnerflag to be set. 306cb9425e2SMitchell Horne.Ss Handler Callbacks 307cb9425e2SMitchell HorneEach 308cb9425e2SMitchell Horne.Vt struct intr_event 309cb9425e2SMitchell Horneis assigned three optional callback functions when it is created: 310cb9425e2SMitchell Horne.Fa pre_ithread , 311cb9425e2SMitchell Horne.Fa post_ithread , 312cb9425e2SMitchell Horneand 313cb9425e2SMitchell Horne.Fa post_filter . 314cb9425e2SMitchell HorneThese callbacks are intended to be defined by the interrupt controller driver, 315cb9425e2SMitchell Horneto allow for actions such as masking and unmasking hardware interrupt signals. 316cb9425e2SMitchell Horne.Pp 317cb9425e2SMitchell HorneWhen an interrupt is triggered, all filters are run to determine if any 318cb9425e2SMitchell Hornethreaded interrupt handlers should be scheduled for execution by the associated 319cb9425e2SMitchell Horneinterrupt thread. If no threaded handlers are scheduled, the 320cb9425e2SMitchell Horne.Fa post_filter 321cb9425e2SMitchell Hornecallback is invoked which should acknowledge the interrupt and permit it to 322cb9425e2SMitchell Hornetrigger in the future. 323cb9425e2SMitchell HorneIf any threaded handlers are scheduled, the 324cb9425e2SMitchell Horne.Fa pre_ithread 325cb9425e2SMitchell Hornecallback is invoked instead. 326cb9425e2SMitchell HorneThis handler should acknowledge the interrupt, but it should also ensure that 327cb9425e2SMitchell Hornethe interrupt will not fire continuously until after the threaded handlers have 328cb9425e2SMitchell Horneexecuted. 329cb9425e2SMitchell HorneTypically this callback masks level-triggered interrupts in an interrupt 330cb9425e2SMitchell Hornecontroller while leaving edge-triggered interrupts alone. 331cb9425e2SMitchell HorneOnce all threaded handlers have executed, 332cb9425e2SMitchell Hornethe 333cb9425e2SMitchell Horne.Fa post_ithread 334cb9425e2SMitchell Hornecallback is invoked from the interrupt thread to enable future interrupts. 335cb9425e2SMitchell HorneTypically this callback unmasks level-triggered interrupts in an interrupt 336cb9425e2SMitchell Hornecontroller. 3373cdbaee3SMitchell Horne.Sh RETURN VALUES 3383cdbaee3SMitchell HorneThe 3393cdbaee3SMitchell Horne.Fn intr_event_add_handler , 3403cdbaee3SMitchell Horne.Fn intr_event_create , 3413cdbaee3SMitchell Horne.Fn intr_event_destroy , 342334fc46fSMitchell Horne.Fn intr_event_handle , 3433cdbaee3SMitchell Horneand 3443cdbaee3SMitchell Horne.Fn intr_event_remove_handler 3453cdbaee3SMitchell Hornefunctions return zero on success and non-zero on failure. 3463cdbaee3SMitchell HorneThe 3473cdbaee3SMitchell Horne.Fn intr_priority 3483cdbaee3SMitchell Hornefunction returns a process priority corresponding to the passed in interrupt 3493cdbaee3SMitchell Horneflags. 3503cdbaee3SMitchell Horne.Sh EXAMPLES 3513cdbaee3SMitchell HorneThe 3520cec1648SMitchell Horne.Xr swi_add 9 3533cdbaee3SMitchell Hornefunction demonstrates the use of 3543cdbaee3SMitchell Horne.Fn intr_event_create 3553cdbaee3SMitchell Horneand 3563cdbaee3SMitchell Horne.Fn intr_event_add_handler . 3573cdbaee3SMitchell Horne.Bd -literal -offset indent 3583cdbaee3SMitchell Horneint 3590cec1648SMitchell Horneswi_add(struct intr_event **eventp, const char *name, driver_intr_t handler, 3603cdbaee3SMitchell Horne void *arg, int pri, enum intr_type flags, void **cookiep) 3613cdbaee3SMitchell Horne{ 3620cec1648SMitchell Horne struct intr_event *ie; 3630cec1648SMitchell Horne int error = 0; 3643cdbaee3SMitchell Horne 3653cdbaee3SMitchell Horne if (flags & INTR_ENTROPY) 3663cdbaee3SMitchell Horne return (EINVAL); 3673cdbaee3SMitchell Horne 3680cec1648SMitchell Horne ie = (eventp != NULL) ? *eventp : NULL; 3693cdbaee3SMitchell Horne 3700cec1648SMitchell Horne if (ie != NULL) { 3710cec1648SMitchell Horne if (!(ie->ie_flags & IE_SOFT)) 3723cdbaee3SMitchell Horne return (EINVAL); 3733cdbaee3SMitchell Horne } else { 3740cec1648SMitchell Horne error = intr_event_create(&ie, NULL, IE_SOFT, 0, 3750cec1648SMitchell Horne NULL, NULL, NULL, swi_assign_cpu, "swi%d:", pri); 3763cdbaee3SMitchell Horne if (error) 3773cdbaee3SMitchell Horne return (error); 3780cec1648SMitchell Horne if (eventp != NULL) 3790cec1648SMitchell Horne *eventp = ie; 3803cdbaee3SMitchell Horne } 3810cec1648SMitchell Horne if (handler != NULL) { 3820cec1648SMitchell Horne error = intr_event_add_handler(ie, name, NULL, handler, arg, 3830cec1648SMitchell Horne PI_SWI(pri), flags, cookiep); 3840cec1648SMitchell Horne } 3850cec1648SMitchell Horne return (error); 3863cdbaee3SMitchell Horne} 3873cdbaee3SMitchell Horne.Ed 3883cdbaee3SMitchell Horne.Sh ERRORS 3893cdbaee3SMitchell HorneThe 3903cdbaee3SMitchell Horne.Fn intr_event_add_handler 3913cdbaee3SMitchell Hornefunction will fail if: 3923cdbaee3SMitchell Horne.Bl -tag -width Er 3933cdbaee3SMitchell Horne.It Bq Er EINVAL 3943cdbaee3SMitchell HorneThe 3953cdbaee3SMitchell Horne.Fa ie 3963cdbaee3SMitchell Horneor 3973cdbaee3SMitchell Horne.Fa name 3983cdbaee3SMitchell Hornearguments are 3993cdbaee3SMitchell Horne.Dv NULL . 4003cdbaee3SMitchell Horne.It Bq Er EINVAL 4013cdbaee3SMitchell HorneThe 4023cdbaee3SMitchell Horne.Fa handler 4033cdbaee3SMitchell Horneand 4043cdbaee3SMitchell Horne.Fa filter 4053cdbaee3SMitchell Hornearguments are both 4063cdbaee3SMitchell Horne.Dv NULL . 4073cdbaee3SMitchell Horne.It Bq Er EINVAL 4083cdbaee3SMitchell HorneThe 4093cdbaee3SMitchell Horne.Dv IH_EXCLUSIVE 4103cdbaee3SMitchell Horneflag is specified and the interrupt thread 4113cdbaee3SMitchell Horne.Fa ie 4123cdbaee3SMitchell Hornealready has at least one handler, or the interrupt thread 4133cdbaee3SMitchell Horne.Fa ie 4143cdbaee3SMitchell Hornealready has an exclusive handler. 4153cdbaee3SMitchell Horne.El 4163cdbaee3SMitchell Horne.Pp 4173cdbaee3SMitchell HorneThe 4183cdbaee3SMitchell Horne.Fn intr_event_create 4193cdbaee3SMitchell Hornefunction will fail if: 4203cdbaee3SMitchell Horne.Bl -tag -width Er 4213cdbaee3SMitchell Horne.It Bq Er EINVAL 4223cdbaee3SMitchell HorneA flag other than 4233cdbaee3SMitchell Horne.Dv IE_SOFT 4243cdbaee3SMitchell Hornewas specified in the 4253cdbaee3SMitchell Horne.Fa flags 4263cdbaee3SMitchell Horneparameter. 4273cdbaee3SMitchell Horne.El 4283cdbaee3SMitchell Horne.Pp 4293cdbaee3SMitchell HorneThe 4303cdbaee3SMitchell Horne.Fn intr_event_destroy 4313cdbaee3SMitchell Hornefunction will fail if: 4323cdbaee3SMitchell Horne.Bl -tag -width Er 4333cdbaee3SMitchell Horne.It Bq Er EINVAL 4343cdbaee3SMitchell HorneThe 4353cdbaee3SMitchell Horne.Fa ie 4363cdbaee3SMitchell Horneargument is 4373cdbaee3SMitchell Horne.Dv NULL . 4383cdbaee3SMitchell Horne.It Bq Er EBUSY 4393cdbaee3SMitchell HorneThe interrupt event pointed to by 4403cdbaee3SMitchell Horne.Fa ie 4413cdbaee3SMitchell Hornehas at least one handler which has not been removed with 4423cdbaee3SMitchell Horne.Fn intr_event_remove_handler . 4433cdbaee3SMitchell Horne.El 4443cdbaee3SMitchell Horne.Pp 4453cdbaee3SMitchell HorneThe 446334fc46fSMitchell Horne.Fn intr_event_handle 447334fc46fSMitchell Hornefunction will fail if: 448334fc46fSMitchell Horne.Bl -tag -width Er 449334fc46fSMitchell Horne.It Bq Er EINVAL 450334fc46fSMitchell HorneThe 451334fc46fSMitchell Horne.Fa ie 452334fc46fSMitchell Horneargument is 453334fc46fSMitchell Horne.Dv NULL . 454334fc46fSMitchell Horne.It Bq Er EINVAL 455334fc46fSMitchell HorneThere are no interrupt handlers assigned to 456334fc46fSMitchell Horne.Fa ie . 457334fc46fSMitchell Horne.It Bq Er EINVAL 458334fc46fSMitchell HorneThe interrupt was not acknowledged by any filter and has no associated thread 459334fc46fSMitchell Hornehandler. 460334fc46fSMitchell Horne.El 461334fc46fSMitchell Horne.Pp 462334fc46fSMitchell HorneThe 4633cdbaee3SMitchell Horne.Fn intr_event_remove_handler 4643cdbaee3SMitchell Hornefunction will fail if: 4653cdbaee3SMitchell Horne.Bl -tag -width Er 4663cdbaee3SMitchell Horne.It Bq Er EINVAL 4673cdbaee3SMitchell HorneThe 4683cdbaee3SMitchell Horne.Fa cookie 4693cdbaee3SMitchell Horneargument is 4703cdbaee3SMitchell Horne.Dv NULL . 4713cdbaee3SMitchell Horne.El 4723cdbaee3SMitchell Horne.Sh SEE ALSO 473334fc46fSMitchell Horne.Xr critical 9 , 4743cdbaee3SMitchell Horne.Xr kthread 9 , 475dfc91493SMitchell Horne.Xr locking 9 , 4763cdbaee3SMitchell Horne.Xr malloc 9 , 4773cdbaee3SMitchell Horne.Xr swi 9 , 4783cdbaee3SMitchell Horne.Xr uma 9 4793cdbaee3SMitchell Horne.Sh HISTORY 4803cdbaee3SMitchell HorneInterrupt threads and their corresponding API first appeared in 4813cdbaee3SMitchell Horne.Fx 5.0 . 482