1.\" Copyright (c) 2000 Jeroen Ruigrok van der Werven 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23.\" SUCH DAMAGE. 24.\" 25.\" $FreeBSD: src/share/man/man9/BUS_SETUP_INTR.9,v 1.20 2007/03/01 14:33:29 ru Exp $ 26.\" $DragonFly: src/share/man/man9/BUS_SETUP_INTR.9,v 1.5 2007/04/08 07:05:25 swildner Exp $ 27.\" 28.Dd April 7, 2007 29.Dt BUS_SETUP_INTR 9 30.Os 31.Sh NAME 32.Nm BUS_SETUP_INTR , 33.Nm bus_setup_intr , 34.Nm BUS_TEARDOWN_INTR , 35.Nm bus_teardown_intr 36.Nd create, attach and teardown an interrupt handler 37.Sh SYNOPSIS 38.In sys/param.h 39.In sys/bus.h 40.Ft int 41.Fo BUS_SETUP_INTR 42.Fa "device_t dev" "device_t child" "struct resource *irq" "int flags" 43.Fa "driver_intr_t *intr" "void *arg" "void **cookiep" 44.Fa "lwkt_serialize_t serializer" 45.Fc 46.Ft int 47.Fo bus_setup_intr 48.Fa "device_t dev" "struct resource *r" "int flags" "driver_intr_t handler" 49.Fa "void *arg" "void **cookiep" "lwkt_serialize_t serializer" 50.Fc 51.Ft int 52.Fo BUS_TEARDOWN_INTR 53.Fa "device_t dev" "device_t child" "struct resource *irq" "void *cookie" 54.Fc 55.Ft int 56.Fn bus_teardown_intr "device_t dev" "struct resource *r" "void *cookie" 57.Sh DESCRIPTION 58The 59.Fn BUS_SETUP_INTR 60method 61will create and attach an interrupt handler to an interrupt 62previously allocated by the resource manager's 63.Xr BUS_ALLOC_RESOURCE 9 64method. 65The defined handler 66will be called with the value 67.Fa arg 68as its only argument. 69.Pp 70The 71.Fa cookiep 72argument is a pointer to a 73.Vt "void *" 74that 75.Fn BUS_SETUP_INTR 76will write a cookie for the parent bus' use to if it is successful in 77establishing an interrupt. 78Driver writers may assume that this cookie will be non-zero. 79The nexus driver will write 0 on failure to 80.Fa cookiep . 81.Pp 82The 83.Fa flags 84are found in 85.In sys/bus.h 86and tell the interrupt handlers about certain 87device driver characteristics and are typically either 88.Li 0 89or 90.Dv INTR_MPSAFE . 91If 92.Dv INTR_MPSAFE 93is specified the kernel is free to call the interrupt handler without 94holding the MP lock. 95.Dv INTR_FAST 96is also sometimes specified and allows the 97interrupt handler to be directly called from the context of the thread 98being interrupted, but is not recommended for most drivers. 99Other interrupt flags exist for special purposes. 100.Pp 101If 102.Fa serializer 103is non-NULL the interrupt handler will be called with the serializer held. 104The serializer replaces the obsolete SPL calls that are no longer relevant on 105SMP systems. 106Driver code can obtain the same serializer to interlock against 107the driver interrupt. 108The serializer also has enablement and disablement 109features which mainline driver code can use to avoid races between interrupt 110disablement and delayed interrupts executing from the device's interrupt 111thread. 112.Pp 113The interrupt handler will be detached by 114.Fn BUS_TEARDOWN_INTR . 115The 116.Fa cookie 117needs to be passed to 118.Fn BUS_TEARDOWN_INTR 119in order to tear down the correct interrupt handler. 120Once 121.Fn BUS_TEARDOWN_INTR 122returns, it is guaranteed that the interrupt function is not active and 123will no longer be called. 124.Pp 125The lowercase versions 126.Fn bus_setup_intr 127and 128.Fn bus_teardown_intr 129are convenience functions to make it easier for drivers to use the 130resource-management functions. 131All they do is hide indirection through the parent's method table, 132making for slightly less wordy code. 133.Sh RETURN VALUES 134Zero is returned on success, 135otherwise an appropriate error is returned. 136.Sh SEE ALSO 137.Xr device 9 , 138.Xr driver 9 , 139.Xr serializer 9 140.Sh AUTHORS 141.An -nosplit 142This manual page was written by 143.An Jeroen Ruigrok van der Werven 144.Aq asmodai@FreeBSD.org 145based on the manual pages for 146.Fn BUS_CREATE_INTR 147and 148.Fn BUS_CONNECT_INTR 149written by 150.An Doug Rabson 151.Aq dfr@FreeBSD.org . 152