1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
<table class="head">
<tr>
<td class="head-ltitle">BUS_SETUP_INTR(9)</td>
<td class="head-vol">Kernel Developer's Manual</td>
<td class="head-rtitle">BUS_SETUP_INTR(9)</td>
</tr>
</table>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp"><code class="Nm">BUS_SETUP_INTR</code>,
<code class="Nm">bus_setup_intr</code>,
<code class="Nm">BUS_TEARDOWN_INTR</code>,
<code class="Nm">bus_teardown_intr</code> — <span class="Nd">create,
attach and teardown an interrupt handler</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
<p class="Pp"><code class="In">#include
<<a class="In">sys/param.h</a>></code>
<br/>
<code class="In">#include <<a class="In">sys/bus.h</a>></code></p>
<p class="Pp"><var class="Ft">int</var>
<br/>
<code class="Fn">BUS_SETUP_INTR</code>(<var class="Fa">device_t dev</var>,
<var class="Fa">device_t child</var>, <var class="Fa">struct resource
*irq</var>, <var class="Fa">int flags</var>, <var class="Fa">driver_filter_t
*filter</var>, <var class="Fa">driver_intr_t *ithread</var>,
<var class="Fa">void *arg</var>, <var class="Fa">void **cookiep</var>);</p>
<p class="Pp"><var class="Ft">int</var>
<br/>
<code class="Fn">bus_setup_intr</code>(<var class="Fa">device_t dev</var>,
<var class="Fa">struct resource *r</var>, <var class="Fa">int flags</var>,
<var class="Fa">driver_filter_t filter</var>, <var class="Fa">driver_intr_t
ithread</var>, <var class="Fa">void *arg</var>, <var class="Fa">void
**cookiep</var>);</p>
<p class="Pp"><var class="Ft">int</var>
<br/>
<code class="Fn">BUS_TEARDOWN_INTR</code>(<var class="Fa">device_t dev</var>,
<var class="Fa">device_t child</var>, <var class="Fa">struct resource
*irq</var>, <var class="Fa">void *cookiep</var>);</p>
<p class="Pp"><var class="Ft">int</var>
<br/>
<code class="Fn">bus_teardown_intr</code>(<var class="Fa" style="white-space: nowrap;">device_t
dev</var>, <var class="Fa" style="white-space: nowrap;">struct resource
*r</var>, <var class="Fa" style="white-space: nowrap;">void
*cookiep</var>);</p>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
<p class="Pp">The
<a class="permalink" href="#BUS_SETUP_INTR"><code class="Fn" id="BUS_SETUP_INTR">BUS_SETUP_INTR</code></a>()
method will create and attach an interrupt handler to an interrupt
previously allocated by the resource manager's
<a class="Xr">BUS_ALLOC_RESOURCE(9)</a> method. The
<var class="Fa">flags</var> are found in
<code class="In"><<a class="In">sys/bus.h</a>></code>, and give the
broad category of interrupt. The <var class="Fa">flags</var> also tell the
interrupt handlers about certain device driver characteristics.
<code class="Dv">INTR_EXCL</code> marks the handler as being an exclusive
handler for this interrupt. <code class="Dv">INTR_MPSAFE</code> tells the
scheduler that the interrupt handler is well behaved in a preemptive
environment (``SMP safe''), and does not need to be protected by the ``Giant
Lock'' mutex. <code class="Dv">INTR_ENTROPY</code> marks the interrupt as
being a good source of entropy - this may be used by the entropy device
<span class="Pa">/dev/random</span>.</p>
<p class="Pp">To define a time-critical handler that will not execute any
potentially blocking operation, use the <var class="Fa">filter</var>
argument. See the <a class="Sx" href="#Filter_Routines">Filter Routines</a>
section below for information on writing a filter. Otherwise, use the
<var class="Fa">ithread</var> argument. The defined handler will be called
with the value <var class="Fa">arg</var> as its only argument. See the
<a class="Sx" href="#ithread_Routines">ithread Routines</a> section below
for more information on writing an interrupt handler.</p>
<p class="Pp" id="BUS_SETUP_INTR~2">The <var class="Fa">cookiep</var> argument
is a pointer to a <var class="Vt">void *</var> that
<a class="permalink" href="#BUS_SETUP_INTR~2"><code class="Fn">BUS_SETUP_INTR</code></a>()
will write a cookie for the parent bus' use to if it is successful in
establishing an interrupt. Driver writers may assume that this cookie will
be non-zero. The nexus driver will write 0 on failure to
<var class="Fa">cookiep</var>.</p>
<p class="Pp" id="BUS_TEARDOWN_INTR">The interrupt handler will be detached by
<a class="permalink" href="#BUS_TEARDOWN_INTR"><code class="Fn">BUS_TEARDOWN_INTR</code></a>().
The cookie needs to be passed to <code class="Fn">BUS_TEARDOWN_INTR</code>()
in order to tear down the correct interrupt handler. Once
<code class="Fn">BUS_TEARDOWN_INTR</code>() returns, it is guaranteed that
the interrupt function is not active and will no longer be called.</p>
<p class="Pp">Mutexes are not allowed to be held across calls to these
functions.</p>
<section class="Ss">
<h2 class="Ss" id="Filter_Routines"><a class="permalink" href="#Filter_Routines">Filter
Routines</a></h2>
<p class="Pp">A filter runs in primary interrupt context. In this context,
normal mutexes cannot be used. Only the spin lock version of these can be
used (specified by passing <code class="Dv">MTX_SPIN</code> to
<a class="permalink" href="#mtx_init"><code class="Fn" id="mtx_init">mtx_init</code></a>()
when initializing the mutex). <a class="Xr">wakeup(9)</a> and similar
routines can be called. Atomic operations from
<span class="Pa">machine/atomic</span> may be used. Reads and writes to
hardware through <a class="Xr">bus_space(9)</a> may be used. PCI
configuration registers may be read and written. All other kernel interfaces
cannot be used.</p>
<p class="Pp">In this restricted environment, care must be taken to account for
all races. A careful analysis of races should be done as well. It is
generally cheaper to take an extra interrupt, for example, than to protect
variables with spinlocks. Read, modify, write cycles of hardware registers
need to be carefully analyzed if other threads are accessing the same
registers.</p>
<p class="Pp">Generally, a filter routine will use one of two strategies. The
first strategy is to simply mask the interrupt in hardware and allow the
<code class="Dv">ithread</code> routine to read the state from the hardware
and then reenable interrupts. The <code class="Dv">ithread</code> also
acknowledges the interrupt before re-enabling the interrupt source in
hardware. Most PCI hardware can mask its interrupt source.</p>
<p class="Pp">The second common approach is to use a filter with multiple
<a class="Xr">taskqueue(9)</a> tasks. In this case, the filter acknowledges
the interrupts and queues the work to the appropriate taskqueue. Where one
has to multiplex different kinds of interrupt sources, like a network card's
transmit and receive paths, this can reduce lock contention and increase
performance.</p>
<p class="Pp">You should not <a class="Xr">malloc(9)</a> from inside a filter.
You may not call anything that uses a normal mutex. Witness may complain
about these.</p>
</section>
<section class="Ss">
<h2 class="Ss" id="ithread_Routines"><a class="permalink" href="#ithread_Routines">ithread
Routines</a></h2>
<p class="Pp">You can do whatever you want in an ithread routine, except sleep.
Care must be taken not to sleep in an ithread. In addition, one should
minimize lock contention in an ithread routine because contested locks
ripple over to all other ithread routines on that interrupt.</p>
</section>
<section class="Ss">
<h2 class="Ss" id="Sleeping"><a class="permalink" href="#Sleeping">Sleeping</a></h2>
<p class="Pp">Sleeping is voluntarily giving up control of your thread. All the
sleep routine found in <a class="Xr">msleep(9)</a> sleep. Waiting for a
condition variable described in <a class="Xr">condvar(9)</a> is sleeping.
Calling any function that does any of these things is sleeping.</p>
</section>
</section>
<section class="Sh">
<h1 class="Sh" id="RETURN_VALUES"><a class="permalink" href="#RETURN_VALUES">RETURN
VALUES</a></h1>
<p class="Pp">Zero is returned on success, otherwise an appropriate error is
returned.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
ALSO</a></h1>
<p class="Pp"><a class="Xr">random(4)</a>, <a class="Xr">device(9)</a>,
<a class="Xr">driver(9)</a>, <a class="Xr">locking(9)</a></p>
</section>
<section class="Sh">
<h1 class="Sh" id="AUTHORS"><a class="permalink" href="#AUTHORS">AUTHORS</a></h1>
<p class="Pp">This manual page was written by <span class="An">Jeroen Ruigrok
van der Werven</span>
<<a class="Mt" href="mailto:asmodai@FreeBSD.org">asmodai@FreeBSD.org</a>>
based on the manual pages for <code class="Fn">BUS_CREATE_INTR</code>() and
<code class="Fn">BUS_CONNECT_INTR</code>() written by <span class="An">Doug
Rabson</span>
<<a class="Mt" href="mailto:dfr@FreeBSD.org">dfr@FreeBSD.org</a>>.</p>
</section>
</div>
<table class="foot">
<tr>
<td class="foot-date">November 3, 2010</td>
<td class="foot-os">FreeBSD 15.0</td>
</tr>
</table>
|