19ebce8e5SJohn Baldwin.\" Copyright (c) 2000-2001 John H. Baldwin <jhb@FreeBSD.org> 2dc4e9f1aSJohn Baldwin.\" 3dc4e9f1aSJohn Baldwin.\" Redistribution and use in source and binary forms, with or without 4dc4e9f1aSJohn Baldwin.\" modification, are permitted provided that the following conditions 5dc4e9f1aSJohn Baldwin.\" are met: 6dc4e9f1aSJohn Baldwin.\" 1. Redistributions of source code must retain the above copyright 7dc4e9f1aSJohn Baldwin.\" notice, this list of conditions and the following disclaimer. 8dc4e9f1aSJohn Baldwin.\" 2. Redistributions in binary form must reproduce the above copyright 9dc4e9f1aSJohn Baldwin.\" notice, this list of conditions and the following disclaimer in the 10dc4e9f1aSJohn Baldwin.\" documentation and/or other materials provided with the distribution. 11dc4e9f1aSJohn Baldwin.\" 12dc4e9f1aSJohn Baldwin.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 13dc4e9f1aSJohn Baldwin.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14dc4e9f1aSJohn Baldwin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15dc4e9f1aSJohn Baldwin.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 16dc4e9f1aSJohn Baldwin.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 17dc4e9f1aSJohn Baldwin.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 18dc4e9f1aSJohn Baldwin.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 19dc4e9f1aSJohn Baldwin.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 20dc4e9f1aSJohn Baldwin.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 21dc4e9f1aSJohn Baldwin.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 22dc4e9f1aSJohn Baldwin.\" SUCH DAMAGE. 23dc4e9f1aSJohn Baldwin.\" 24dc4e9f1aSJohn Baldwin.\" $FreeBSD$ 25dc4e9f1aSJohn Baldwin.\" 26*aba10e13SAlexander Motin.Dd July 25, 2020 27dc4e9f1aSJohn Baldwin.Dt SWI 9 28dc4e9f1aSJohn Baldwin.Os 29dc4e9f1aSJohn Baldwin.Sh NAME 309ebce8e5SJohn Baldwin.Nm swi_add , 31eb55f31bSSergey Kandaurov.Nm swi_remove , 329ebce8e5SJohn Baldwin.Nm swi_sched 33dc4e9f1aSJohn Baldwin.Nd register and schedule software interrupt handlers 34dc4e9f1aSJohn Baldwin.Sh SYNOPSIS 3532eef9aeSRuslan Ermilov.In sys/param.h 3632eef9aeSRuslan Ermilov.In sys/bus.h 3732eef9aeSRuslan Ermilov.In sys/interrupt.h 3852116a1cSSergey Kandaurov.Vt "extern struct intr_event *tty_intr_event" ; 3952116a1cSSergey Kandaurov.Vt "extern struct intr_event *clk_intr_event" ; 409ebce8e5SJohn Baldwin.Vt "extern void *vm_ih" ; 419ebce8e5SJohn Baldwin.Ft int 429ebce8e5SJohn Baldwin.Fo swi_add 434b47ece9SSergey Kandaurov.Fa "struct intr_event **eventp" 44dc4e9f1aSJohn Baldwin.Fa "const char *name" 45dc4e9f1aSJohn Baldwin.Fa "driver_intr_t handler" 46dc4e9f1aSJohn Baldwin.Fa "void *arg" 47dc4e9f1aSJohn Baldwin.Fa "int pri" 489ebce8e5SJohn Baldwin.Fa "enum intr_type flags" 499ebce8e5SJohn Baldwin.Fa "void **cookiep" 50dc4e9f1aSJohn Baldwin.Fc 51eb55f31bSSergey Kandaurov.Ft int 52eb55f31bSSergey Kandaurov.Fn swi_remove "void *cookie" 539ebce8e5SJohn Baldwin.Ft void 5468ca7644SJoseph Koshy.Fn swi_sched "void *cookie" "int flags" 55dc4e9f1aSJohn Baldwin.Sh DESCRIPTION 56dc4e9f1aSJohn BaldwinThese functions are used to register and schedule software interrupt handlers. 57dc4e9f1aSJohn BaldwinSoftware interrupt handlers are attached to a software interrupt thread, just 58dc4e9f1aSJohn Baldwinas hardware interrupt handlers are attached to a hardware interrupt thread. 599ebce8e5SJohn BaldwinMultiple handlers can be attached to the same thread. 60dc4e9f1aSJohn BaldwinSoftware interrupt handlers can be used to queue up less critical processing 61dc4e9f1aSJohn Baldwininside of hardware interrupt handlers so that the work can be done at a later 62dc4e9f1aSJohn Baldwintime. 63dc4e9f1aSJohn BaldwinSoftware interrupt threads are different from other kernel threads in that they 64dc4e9f1aSJohn Baldwinare treated as an interrupt thread. 65dc4e9f1aSJohn BaldwinThis means that time spent executing these threads is counted as interrupt 669ebce8e5SJohn Baldwintime, and that they can be run via a lightweight context switch. 67dc4e9f1aSJohn Baldwin.Pp 68dc4e9f1aSJohn BaldwinThe 699ebce8e5SJohn Baldwin.Fn swi_add 704b47ece9SSergey Kandaurovfunction is used to add a new software interrupt handler to a specified 714b47ece9SSergey Kandaurovinterrupt event. 72dc4e9f1aSJohn BaldwinThe 734b47ece9SSergey Kandaurov.Fa eventp 74dc4e9f1aSJohn Baldwinargument is an optional pointer to a 754b47ece9SSergey Kandaurov.Vt struct intr_event 76dc4e9f1aSJohn Baldwinpointer. 774b47ece9SSergey KandaurovIf this argument points to an existing event that holds a list of 784b47ece9SSergey Kandaurovinterrupt handlers, then this handler will be attached to that event. 794b47ece9SSergey KandaurovOtherwise a new event will be created, and if 804b47ece9SSergey Kandaurov.Fa eventp 81dc4e9f1aSJohn Baldwinis not 82dc4e9f1aSJohn Baldwin.Dv NULL , 83dc4e9f1aSJohn Baldwinthen the pointer at that address to will be modified to point to the 844b47ece9SSergey Kandaurovnewly created event. 85dc4e9f1aSJohn BaldwinThe 869ebce8e5SJohn Baldwin.Fa name 879ebce8e5SJohn Baldwinargument is used to associate a name with a specific handler. 889ebce8e5SJohn BaldwinThis name is appended to the name of the software interrupt thread that this 899ebce8e5SJohn Baldwinhandler is attached to. 909ebce8e5SJohn BaldwinThe 91dc4e9f1aSJohn Baldwin.Fa handler 929ebce8e5SJohn Baldwinargument is the function that will be executed when the handler is scheduled 939ebce8e5SJohn Baldwinto run. 94dc4e9f1aSJohn BaldwinThe 95dc4e9f1aSJohn Baldwin.Fa arg 96dc4e9f1aSJohn Baldwinparameter will be passed in as the only parameter to 97dc4e9f1aSJohn Baldwin.Fa handler 98dc4e9f1aSJohn Baldwinwhen the function is executed. 99dc4e9f1aSJohn BaldwinThe 100dc4e9f1aSJohn Baldwin.Fa pri 1019ebce8e5SJohn Baldwinvalue specifies the priority of this interrupt handler relative to other 1029ebce8e5SJohn Baldwinsoftware interrupt handlers. 1034b47ece9SSergey KandaurovIf an interrupt event is created, then this value is used as the vector, 104dc4e9f1aSJohn Baldwinand the 105dc4e9f1aSJohn Baldwin.Fa flags 106dc4e9f1aSJohn Baldwinargument is used to specify the attributes of a handler such as 107dc4e9f1aSJohn Baldwin.Dv INTR_MPSAFE . 1089ebce8e5SJohn BaldwinThe 10968ca7644SJoseph Koshy.Fa cookiep 1109ebce8e5SJohn Baldwinargument points to a 11179cd39f2SRuslan Ermilov.Vt void * 1129ebce8e5SJohn Baldwincookie. 1139ebce8e5SJohn BaldwinThis cookie will be set to a value that uniquely identifies this handler, 1149ebce8e5SJohn Baldwinand is used to schedule the handler for execution later on. 115dc4e9f1aSJohn Baldwin.Pp 116dc4e9f1aSJohn BaldwinThe 117eb55f31bSSergey Kandaurov.Fn swi_remove 118eb55f31bSSergey Kandaurovfunction is used to teardown an interrupt handler pointed to by the 119eb55f31bSSergey Kandaurov.Fa cookie 120eb55f31bSSergey Kandaurovargument. 121eb55f31bSSergey KandaurovIt detaches the interrupt handler from the associated interrupt event 122eb55f31bSSergey Kandaurovand frees its memory. 123eb55f31bSSergey Kandaurov.Pp 124eb55f31bSSergey KandaurovThe 1259ebce8e5SJohn Baldwin.Fn swi_sched 126dc4e9f1aSJohn Baldwinfunction is used to schedule an interrupt handler and its associated thread to 127dc4e9f1aSJohn Baldwinrun. 128dc4e9f1aSJohn BaldwinThe 1299ebce8e5SJohn Baldwin.Fa cookie 130dc4e9f1aSJohn Baldwinargument specifies which software interrupt handler should be scheduled to run. 131dc4e9f1aSJohn BaldwinThe 132dc4e9f1aSJohn Baldwin.Fa flags 133dc4e9f1aSJohn Baldwinargument specifies how and when the handler should be run and is a mask of one 134dc4e9f1aSJohn Baldwinor more of the following flags: 135*aba10e13SAlexander Motin.Bl -tag -width SWI_FROMNMI 136dc4e9f1aSJohn Baldwin.It Dv SWI_DELAY 137dc4e9f1aSJohn BaldwinSpecifies that the kernel should mark the specified handler as needing to run, 138dc4e9f1aSJohn Baldwinbut the kernel should not schedule the software interrupt thread to run. 139dc4e9f1aSJohn BaldwinInstead, 140dc4e9f1aSJohn Baldwin.Fa handler 141dc4e9f1aSJohn Baldwinwill be executed the next time that the software interrupt thread runs after 142dc4e9f1aSJohn Baldwinbeing scheduled by another event. 143dc4e9f1aSJohn BaldwinAttaching a handler to the clock software interrupt thread and using this flag 144dc4e9f1aSJohn Baldwinwhen scheduling a software interrupt handler can be used to implement the 145a3672eeeSJohn Baldwinfunctionality performed by 146a3672eeeSJohn Baldwin.Fn setdelayed 147a3672eeeSJohn Baldwinin earlier versions of 148a3672eeeSJohn Baldwin.Fx . 149*aba10e13SAlexander Motin.It Dv SWI_FROMNMI 150*aba10e13SAlexander MotinSpecifies that 151*aba10e13SAlexander Motin.Fn swi_sched 152*aba10e13SAlexander Motinis called from NMI context and should be careful about used KPIs. 153*aba10e13SAlexander MotinOn platforms allowing IPI sending from NMI context it immediately wakes 154*aba10e13SAlexander Motin.Va clk_intr_event 155*aba10e13SAlexander Motinvia the IPI, otherwise it works just like SWI_DELAY. 156dc4e9f1aSJohn Baldwin.El 157dc4e9f1aSJohn Baldwin.Pp 158dc4e9f1aSJohn BaldwinThe 15952116a1cSSergey Kandaurov.Va tty_intr_event 160dc4e9f1aSJohn Baldwinand 16152116a1cSSergey Kandaurov.Va clk_intr_event 16252116a1cSSergey Kandaurovvariables contain pointers to the software interrupt handlers for the tty and 163dc4e9f1aSJohn Baldwinclock software interrupts, respectively. 16452116a1cSSergey Kandaurov.Va tty_intr_event 165dc4e9f1aSJohn Baldwinis used to hang tty software interrupt handlers off of the same thread. 16652116a1cSSergey Kandaurov.Va clk_intr_event 167dc4e9f1aSJohn Baldwinis used to hang delayed handlers off of the clock software interrupt thread so 168dc4e9f1aSJohn Baldwinthat the functionality of 169dc4e9f1aSJohn Baldwin.Fn setdelayed 170559ff927SJens Schweikhardtcan be obtained in conjunction with 171dc4e9f1aSJohn Baldwin.Dv SWI_DELAY . 172dc4e9f1aSJohn BaldwinThe 173dc4e9f1aSJohn Baldwin.Va vm_ih 17452116a1cSSergey Kandaurovhandler cookie is used to schedule software interrupt threads to run for the 17552116a1cSSergey KandaurovVM subsystem. 176dc4e9f1aSJohn Baldwin.Sh RETURN VALUES 177dc4e9f1aSJohn BaldwinThe 1789ebce8e5SJohn Baldwin.Fn swi_add 179eb55f31bSSergey Kandaurovand 180eb55f31bSSergey Kandaurov.Fn swi_remove 181eb55f31bSSergey Kandaurovfunctions return zero on success and non-zero on failure. 1829ebce8e5SJohn Baldwin.Sh ERRORS 1839ebce8e5SJohn BaldwinThe 1849ebce8e5SJohn Baldwin.Fn swi_add 1859ebce8e5SJohn Baldwinfunction will fail if: 1869ebce8e5SJohn Baldwin.Bl -tag -width Er 1879ebce8e5SJohn Baldwin.It Bq Er EAGAIN 1889ebce8e5SJohn BaldwinThe system-imposed limit on the total 1899ebce8e5SJohn Baldwinnumber of processes under execution would be exceeded. 1909ebce8e5SJohn BaldwinThe limit is given by the 1919ebce8e5SJohn Baldwin.Xr sysctl 3 1929ebce8e5SJohn BaldwinMIB variable 1939ebce8e5SJohn Baldwin.Dv KERN_MAXPROC . 1949ebce8e5SJohn Baldwin.It Bq Er EINVAL 1959ebce8e5SJohn BaldwinThe 1969ebce8e5SJohn Baldwin.Fa flags 19749fe354aSJohn Baldwinargument specifies 19849fe354aSJohn Baldwin.Dv INTR_ENTROPY . 1999ebce8e5SJohn Baldwin.It Bq Er EINVAL 2009ebce8e5SJohn BaldwinThe 2014b47ece9SSergey Kandaurov.Fa eventp 2029ebce8e5SJohn Baldwinargument points to a hardware interrupt thread. 2039ebce8e5SJohn Baldwin.It Bq Er EINVAL 2049ebce8e5SJohn BaldwinEither of the 2059ebce8e5SJohn Baldwin.Fa name 2069ebce8e5SJohn Baldwinor 2079ebce8e5SJohn Baldwin.Fa handler 2089ebce8e5SJohn Baldwinarguments are 2099ebce8e5SJohn Baldwin.Dv NULL . 2109ebce8e5SJohn Baldwin.It Bq Er EINVAL 2119ebce8e5SJohn BaldwinThe 2129ebce8e5SJohn Baldwin.Dv INTR_EXCL 2134b47ece9SSergey Kandaurovflag is specified and the interrupt event pointed to by 2144b47ece9SSergey Kandaurov.Fa eventp 2154b47ece9SSergey Kandaurovalready has at least one handler, or the interrupt event already has an 2169ebce8e5SJohn Baldwinexclusive handler. 2179ebce8e5SJohn Baldwin.El 218eb55f31bSSergey Kandaurov.Pp 219eb55f31bSSergey KandaurovThe 220eb55f31bSSergey Kandaurov.Fn swi_remove 221eb55f31bSSergey Kandaurovfunction will fail if: 222eb55f31bSSergey Kandaurov.Bl -tag -width Er 223eb55f31bSSergey Kandaurov.It Bq Er EINVAL 224eb55f31bSSergey KandaurovA software interrupt handler pointed to by 225eb55f31bSSergey Kandaurov.Fa cookie 226eb55f31bSSergey Kandaurovis 227eb55f31bSSergey Kandaurov.Dv NULL . 228eb55f31bSSergey Kandaurov.El 229dc4e9f1aSJohn Baldwin.Sh SEE ALSO 2309ebce8e5SJohn Baldwin.Xr ithread 9 , 231dc4e9f1aSJohn Baldwin.Xr taskqueue 9 232dc4e9f1aSJohn Baldwin.Sh HISTORY 233dc4e9f1aSJohn BaldwinThe 2349ebce8e5SJohn Baldwin.Fn swi_add 2359ebce8e5SJohn Baldwinand 2369ebce8e5SJohn Baldwin.Fn swi_sched 237dc4e9f1aSJohn Baldwinfunctions first appeared in 238dc4e9f1aSJohn Baldwin.Fx 5.0 . 2399ebce8e5SJohn BaldwinThey replaced the 2409ebce8e5SJohn Baldwin.Fn register_swi 2419ebce8e5SJohn Baldwinfunction which appeared in 2429ebce8e5SJohn Baldwin.Fx 3.0 2439ebce8e5SJohn Baldwinand the 2449ebce8e5SJohn Baldwin.Fn setsoft* , 2459ebce8e5SJohn Baldwinand 2469ebce8e5SJohn Baldwin.Fn schedsoft* 2479ebce8e5SJohn Baldwinfunctions which date back to at least 2489ebce8e5SJohn Baldwin.Bx 4.4 . 249eb55f31bSSergey KandaurovThe 250eb55f31bSSergey Kandaurov.Fn swi_remove 251eb55f31bSSergey Kandaurovfunction first appeared in 252eb55f31bSSergey Kandaurov.Fx 6.1 . 253dc4e9f1aSJohn Baldwin.Sh BUGS 254dc4e9f1aSJohn BaldwinMost of the global variables described in this manual page should not be 255dc4e9f1aSJohn Baldwinglobal, or at the very least should not be declared in 256fe08efe6SRuslan Ermilov.In sys/interrupt.h . 257