1 .\" $NetBSD: deviter.9,v 1.1 2009/11/05 00:20:25 dyoung Exp $
3 .\" Copyright (c) 2009 David Young <dyoung@NetBSD.org>
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following 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.
15 .\" THIS SOFTWARE IS PROVIDED BY David Young ``AS IS'' AND ANY EXPRESS
16 .\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\" ARE DISCLAIMED. IN NO EVENT SHALL David Young BE LIABLE FOR ANY
19 .\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21 .\" GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23 .\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 .\" NetBSD: pmf.9,v 1.12 2009/10/21 16:06:59 snj Exp
29 .\" Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
30 .\" All rights reserved.
32 .\" Redistribution and use in source and binary forms, with or without
33 .\" modification, are permitted provided that the following conditions
35 .\" 1. Redistributions of source code must retain the above copyright
36 .\" notice, this list of conditions and the following disclaimer.
37 .\" 2. Redistributions in binary form must reproduce the above copyright
38 .\" notice, this list of conditions and the following disclaimer in the
39 .\" documentation and/or other materials provided with the distribution.
41 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
42 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
43 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
45 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
46 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
47 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
48 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
49 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
51 .\" POSSIBILITY OF SUCH DAMAGE.
62 .Nd machine-independent device iteration API
66 .Fn deviter_init "deviter_t *di" "deviter_flags_t flags"
68 .Fn deviter_first "deviter_t *di" "deviter_flags_t flags"
70 .Fn deviter_next "deviter_t *di"
72 .Fn deviter_release "deviter_t *di"
74 The machine-independent
76 API lets interrupt handlers running at any priority level and kernel
77 threads iterate over the devices attached to the kernel.
80 it is safe for an interrupt handler or a thread to iterate over
81 devices attached to the kernel while another thread attaches or
84 Kernel subsystems using
86 may make use of the following data types:
87 .Bl -tag -width compact
88 .It Fa deviter_flags_t
89 The kernel can iterate over devices for different purposes and in
91 The following flags affect device iteration:
92 .Bl -item -compact -offset indent
96 .Dv DEVITER_F_SHUTDOWN
98 .Dv DEVITER_F_LEAVES_FIRST
100 .Dv DEVITER_F_ROOT_FIRST
103 This is a device iteration
107 It holds iteration state such as the next device to visit.
110 .Bl -tag -width compact
111 .It Fn deviter_init "di" "flags"
112 Initialize the device iterator,
116 to affect the order of iteration.
118 .Dv DEVITER_F_LEAVES_FIRST
119 to visit each device only after visiting its children (visit the
120 leaves of the device tree, first).
122 .Dv DEVITER_F_ROOT_FIRST
123 to visit each device before visiting its children (visit the root
124 of the device tree, first).
126 .Dv DEVITER_F_LEAVES_FIRST
128 .Dv DEVITER_F_ROOT_FIRST ,
130 returns devices in an arbitrary order.
134 if your purpose for iterating over devices is to modify the device
135 tree by attaching or detaching devices.
137 .Dv DEVITER_F_SHUTDOWN
138 if your purpose for iterating over devices is to detach all of
139 the devices during system shutdown.
140 .Dv DEVITER_F_SHUTDOWN
143 .It Fn deviter_next "di"
148 returns the current device or
150 if there are no more devices.
154 has not been initialized using
158 .It Fn deviter_first "di" "flags"
159 Initialize the iterator
163 Return the first device according to the ordering
168 to the second device, or
171 if there are no devices.
172 This is equivalent to calling
173 .Fn deviter_init "di" "flags"
175 .Fn deviter_next "di" .
176 .It Fn deviter_release "di"
177 Release all resources held by the iterator
179 Every iterator that is initialized with
186 This section describes places within the
188 source tree where actual code implementing
191 All pathnames are relative to
194 Device iteration is implemented within the files
197 .Pa sys/kern/subr_autoconf.c .
206 .An David Young Aq dyoung@NetBSD.org