xref: /freebsd/share/man/man9/device_add_child.9 (revision 29d13f3d06dec06a2fc9636ca8308c0462f80cfc)
1cefd51ecSDoug Rabson.\" -*- nroff -*-
2cefd51ecSDoug Rabson.\"
3cefd51ecSDoug Rabson.\" Copyright (c) 1998 Doug Rabson
4cefd51ecSDoug Rabson.\"
5cefd51ecSDoug Rabson.\" All rights reserved.
6cefd51ecSDoug Rabson.\"
7cefd51ecSDoug Rabson.\" This program is free software.
8cefd51ecSDoug Rabson.\"
9cefd51ecSDoug Rabson.\" Redistribution and use in source and binary forms, with or without
10cefd51ecSDoug Rabson.\" modification, are permitted provided that the following conditions
11cefd51ecSDoug Rabson.\" are met:
12cefd51ecSDoug Rabson.\" 1. Redistributions of source code must retain the above copyright
13cefd51ecSDoug Rabson.\"    notice, this list of conditions and the following disclaimer.
14cefd51ecSDoug Rabson.\" 2. Redistributions in binary form must reproduce the above copyright
15cefd51ecSDoug Rabson.\"    notice, this list of conditions and the following disclaimer in the
16cefd51ecSDoug Rabson.\"    documentation and/or other materials provided with the distribution.
17cefd51ecSDoug Rabson.\"
18cefd51ecSDoug Rabson.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
19cefd51ecSDoug Rabson.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20cefd51ecSDoug Rabson.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21cefd51ecSDoug Rabson.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
22cefd51ecSDoug Rabson.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23cefd51ecSDoug Rabson.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24cefd51ecSDoug Rabson.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25cefd51ecSDoug Rabson.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26cefd51ecSDoug Rabson.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27cefd51ecSDoug Rabson.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28cefd51ecSDoug Rabson.\"
294bc191c3SConrad Meyer.Dd February 11, 2018
30def37e7cSMike Pritchard.Dt DEVICE_ADD_CHILD 9
313d45e180SRuslan Ermilov.Os
32cefd51ecSDoug Rabson.Sh NAME
33cefd51ecSDoug Rabson.Nm device_add_child ,
340d28dd1dSAlexey Zelkin.Nm device_add_child_ordered
35f167d7fbSSheldon Hearn.Nd "add a new device as a child of an existing device"
36cefd51ecSDoug Rabson.Sh SYNOPSIS
3732eef9aeSRuslan Ermilov.In sys/param.h
3832eef9aeSRuslan Ermilov.In sys/bus.h
3931f698b8SBruce Evans.Ft device_t
40238ebf99SMatthew N. Dodd.Fn device_add_child "device_t dev" "const char *name" "int unit"
4131f698b8SBruce Evans.Ft device_t
42238ebf99SMatthew N. Dodd.Fn device_add_child_ordered "device_t dev" "int order" "const char *name" "int unit"
43cefd51ecSDoug Rabson.Sh DESCRIPTION
44cefd51ecSDoug RabsonCreate a new child device of
45cefd51ecSDoug Rabson.Fa dev .
46cefd51ecSDoug RabsonThe
47cefd51ecSDoug Rabson.Fa name
48cefd51ecSDoug Rabsonand
49cefd51ecSDoug Rabson.Fa unit
50cefd51ecSDoug Rabsonarguments specify the name and unit number of the device.
51cefd51ecSDoug RabsonIf the name is unknown then the caller should pass
52cefd51ecSDoug Rabson.Dv NULL .
53cefd51ecSDoug RabsonIf the unit is unknown then the caller should pass
54*29d13f3dSWarner Losh.Dv DEVICE_UNIT_ANY
55cefd51ecSDoug Rabsonand the system will choose the next available unit number.
56cefd51ecSDoug Rabson.Pp
57cefd51ecSDoug RabsonThe name of the device is used to determine which drivers might be
58a0942a60SHiten Pandyaappropriate for the device.
59a0942a60SHiten PandyaIf a name is specified then only drivers of that name are probed.
60cf39dca9SWarner LoshIf no name is given then all drivers for the owning bus are probed.
61cf39dca9SWarner LoshIn any event, only the name of the device is stored so that one may
62cf39dca9SWarner Loshsafely unload/load a driver bound to that name.
63cefd51ecSDoug Rabson.Pp
64db4fcadfSConrad MeyerThis allows buses which can uniquely identify device instances (such
65cefd51ecSDoug Rabsonas PCI) to allow each driver to check each device instance for a
66a0942a60SHiten Pandyamatch.
67db4fcadfSConrad MeyerFor buses which rely on supplied probe hints where only one
68b47668b3SBrian Somersdriver can have a chance of probing the device, the driver name should
69b47668b3SBrian Somersbe specified as the device name.
70cefd51ecSDoug Rabson.Pp
71cefd51ecSDoug RabsonNormally unit numbers will be chosen automatically by the system and a
72cefd51ecSDoug Rabsonunit number of
73*29d13f3dSWarner Losh.Dv DEVICE_UNIT_ANY
74cefd51ecSDoug Rabsonshould be given.
75c64c9b8eSWarner LoshWhen a specific unit number is desired (e.g.,\& for wiring a particular
76cefd51ecSDoug Rabsonpiece of hardware to a pre-configured unit number), that unit should
77a0942a60SHiten Pandyabe passed.
78a0942a60SHiten PandyaIf the specified unit number is already allocated, a new
79cefd51ecSDoug Rabsonunit will be allocated and a diagnostic message printed.
80cefd51ecSDoug Rabson.Pp
81cefd51ecSDoug RabsonIf the devices attached to a bus must be probed in a specific order
82c64c9b8eSWarner Losh(e.g.,\& for the ISA bus some devices are sensitive to failed probe attempts
8386238261SDoug Rabsonof unrelated drivers and therefore must be probed first),
8486238261SDoug Rabsonthe
8586238261SDoug Rabson.Fa order
86cefd51ecSDoug Rabsonargument of
87facc6767SRuslan Ermilov.Fn device_add_child_ordered
8886238261SDoug Rabsonshould be used to specify a partial ordering.
8986238261SDoug RabsonThe new device will be added before any existing device with a greater
9086238261SDoug Rabsonorder.
9186238261SDoug RabsonIf
92facc6767SRuslan Ermilov.Fn device_add_child
9386238261SDoug Rabsonis used, then the new child will be added as if its order was zero.
94cf39dca9SWarner Losh.Pp
95cf39dca9SWarner LoshWhen adding a device in the context of
96cf39dca9SWarner Losh.Xr DEVICE_IDENTIFY 9
97893446feSBrian Somersroutine, the
9801be9cf1SRuslan Ermilov.Xr device_find_child 9
99893446feSBrian Somersroutine should be used to ensure that the device has not already been
100893446feSBrian Somersadded to the tree.
101cf39dca9SWarner LoshBecause the device name and
102bf7f20c2SRuslan Ermilov.Vt devclass_t
103cf39dca9SWarner Loshare associated at probe time (not child addition time), previous
104cf39dca9SWarner Loshinstances of the driver (say in a module that was later unloaded) may
105cf39dca9SWarner Loshhave already added the instance.
106cf39dca9SWarner LoshAuthors of bus drivers must likewise be careful when adding children
107cf39dca9SWarner Loshwhen they are loaded and unloaded to avoid duplication of children
108cf39dca9SWarner Loshdevices.
109788de9d4SWarner Losh.Pp
110c64c9b8eSWarner LoshWhen adding a child to another device node, such as in an identify
111c64c9b8eSWarner Loshroutine, use
112788de9d4SWarner Losh.Xr BUS_ADD_CHILD 9
113788de9d4SWarner Loshinstead of
114f9ea7b6eSChristopher Davidson.Fn device_add_child .
115c64c9b8eSWarner Losh.Xr BUS_ADD_CHILD 9
116c64c9b8eSWarner Loshwill call
117f9ea7b6eSChristopher Davidson.Fn device_add_child
118c64c9b8eSWarner Loshand add the proper bus-specific data to the new child.
119c64c9b8eSWarner Losh.Fn device_add_child
120c64c9b8eSWarner Loshdoes not call
121c64c9b8eSWarner Losh.Xr BUS_ADD_CHILD 9 .
122cefd51ecSDoug Rabson.Sh RETURN VALUES
123cefd51ecSDoug RabsonThe new device if successful, NULL otherwise.
124cefd51ecSDoug Rabson.Sh SEE ALSO
125788de9d4SWarner Losh.Xr BUS_ADD_CHILD 9 ,
12678ad5421SRuslan Ermilov.Xr device 9 ,
1274bc191c3SConrad Meyer.Xr device_delete_child 9 ,
12801be9cf1SRuslan Ermilov.Xr device_find_child 9 ,
129893446feSBrian Somers.Xr DEVICE_IDENTIFY 9
130cefd51ecSDoug Rabson.Sh AUTHORS
13109356c84SHiten PandyaThis manual page was written by
132cefd51ecSDoug Rabson.An Doug Rabson .
133