2 .\" Copyright (c) 2001 Michael Smith <msmith@FreeBSD.org>
3 .\" All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
14 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .Nm devinfo_handle_to_device ,
34 .Nm devinfo_handle_to_resource ,
35 .Nm devinfo_handle_to_rman ,
36 .Nm devinfo_foreach_device_child ,
37 .Nm devinfo_foreach_device_resource ,
38 .Nm devinfo_foreach_rman_resource ,
39 .Nm devinfo_foreach_rman
40 .Nd device and resource information utility library
46 .Fn devinfo_init "void"
48 .Fn devinfo_free "void"
49 .Ft struct devinfo_dev *
50 .Fn devinfo_handle_to_device "devinfo_handle_t handle"
51 .Ft struct devinfo_res *
52 .Fn devinfo_handle_to_resource "devinfo_handle_t handle"
53 .Ft struct devinfo_rman *
54 .Fn devinfo_handle_to_rman "devinfo_handle_t handle"
56 .Fo devinfo_foreach_device_child
57 .Fa "struct devinfo_dev *parent"
58 .Fa "int \*[lp]*fn\*[rp]\*[lp]struct devinfo_dev *child, void *arg\*[rp]"
62 .Fo devinfo_foreach_device_resource
63 .Fa "struct devinfo_dev *dev"
64 .Fa "int \*[lp]*fn\*[rp]\*[lp]struct devinfo_dev *dev, \:struct devinfo_res *res, void *arg\*[rp]"
68 .Fo devinfo_foreach_rman_resource
69 .Fa "struct devinfo_rman *rman"
70 .Fa "int \*[lp]*fn\*[rp]\*[lp]struct devinfo_res *res, void *arg\*[rp]"
74 .Fo devinfo_foreach_rman
75 .Fa "int \*[lp]*fn\*[rp]\*[lp]struct devinfo_rman *rman, void *arg\*[rp]"
81 library provides access to the kernel's internal device hierarchy
82 and to the I/O resource manager.
85 interface to obtain a snapshot of the kernel's state,
86 which is then made available to the application.
88 Due to the fact that the information may be logically arranged
89 in a number of different fashions,
90 the library does not attempt to impose any structure on the data.
92 Device, resource, and resource manager information is returned in
93 data structures defined in
95 .Bd -literal -offset indent
97 devinfo_handle_t dd_handle; /* device handle */
98 devinfo_handle_t dd_parent; /* parent handle */
99 char *dd_name; /* name of device */
100 char *dd_desc; /* device description */
101 char *dd_drivername; /* name of attached driver */
102 char *dd_pnpinfo; /* pnp info from parent bus */
103 char *dd_location; /* Where bus thinks dev at */
104 uint32_t dd_devflags; /* API flags */
105 uint16_t dd_flags; /* internal dev flags */
106 device_state_t dd_state; /* attachment state of dev */
109 struct devinfo_rman {
110 devinfo_handle_t dm_handle; /* resource manager handle */
111 rman_res_t dm_start; /* resource start */
112 rman_res_t dm_size; /* resource size */
113 char *dm_desc; /* resource description */
117 devinfo_handle_t dr_handle; /* resource handle */
118 devinfo_handle_t dr_rman; /* resource manager handle */
119 devinfo_handle_t dr_device; /* owning device */
120 rman_res_t dr_start; /* region start */
121 rman_res_t dr_size; /* region size */
127 values can be used to look up the correspondingly referenced structures.
130 takes a snapshot of the kernel's internal device and resource state.
132 if after a number of retries a consistent snapshot cannot be obtained.
134 must be called before any other functions can be used.
137 releases the memory associated with the snapshot.
138 Any pointers returned by other functions are invalidated by this,
141 must be called again before using any other functions.
143 .Fn devinfo_handle_to_device ,
144 .Fn devinfo_handle_to_resource
146 .Fn devinfo_handle_to_rman
152 structures respectively based on the
155 These functions can be used to traverse the tree from any node to any
158 .Fn devinfo_handle_to_device
159 is passed the constant
160 .Dv DEVINFO_ROOT_DEVICE
161 it will return the handle to the root of the device tree.
163 .Fn devinfo_foreach_device_child
164 invokes its callback argument
166 on every device which is an immediate child of
170 function is also passed
172 allowing state to be passed to the callback function.
175 returns a nonzero error value the traversal is halted,
177 .Fn devinfo_foreach_device_child
178 returns the error value to its caller.
180 .Fn devinfo_foreach_device_resource
181 invokes its callback argument
183 on every resource which is owned by
187 function is also passed
191 allowing state to be passed to the callback function.
194 returns a nonzero error value the traversal is halted,
196 .Fn devinfo_foreach_device_resource
197 returns the error value to its caller.
199 .Fn devinfo_foreach_rman_resource
200 invokes its callback argument
202 on every resource within the resource manager
206 function is also passed
208 allowing state to be passed to the callback function.
211 returns a nonzero error value the traversal is halted,
213 .Fn devinfo_foreach_rman_resource
214 returns the error value to its caller.
216 .Fn devinfo_foreach_rman
217 invokes its callback argument
219 on every resource manager.
222 function is also passed
224 allowing state to be passed to the callback function.
227 returns a nonzero error value the traversal is halted,
229 .Fn devinfo_foreach_rman
230 returns the error value to its caller.
236 library first appeared in
239 .An Michael Smith Aq Mt msmith@FreeBSD.org
241 This is the first implementation of the library,
242 and the interface is still subject to refinement.
244 The interface does not report device classes or drivers,
245 making it hard to sort by class or driver.