xref: /freebsd/share/man/man9/DEVICE_IDENTIFY.9 (revision dd21556857e8d40f66bf5ad54754d9d52669ebf7)
1.\" -*- nroff -*-
2.\"
3.\" Copyright (c) 2001 Alexander Langer
4.\"
5.\" All rights reserved.
6.\"
7.\" This program is free software.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
19.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
22.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28.\"
29.Dd January 9, 2025
30.Dt DEVICE_IDENTIFY 9
31.Os
32.Sh NAME
33.Nm DEVICE_IDENTIFY
34.Nd identify new child devices and register them
35.Sh SYNOPSIS
36.In sys/param.h
37.In sys/bus.h
38.Ft void
39.Fn DEVICE_IDENTIFY "driver_t *driver" "device_t parent"
40.Sh DESCRIPTION
41The identify method of a device driver is used to add devices that cannot be
42enumerated by the standard method on a bus device.
43Devices can be enumerated in various ways including accessing non-ambiguous
44device registers and parsing firmware tables.
45Software-only pseudo devices are also often enumerated via identify methods.
46.Pp
47For each newly identified device,
48a new device instance should be created by invoking the
49.Xr BUS_ADD_CHILD 9
50method.
51If the identify method is able to discover other properties about the new
52device, those should also be set.
53For example, device resources should be added to the device by calling
54.Xr bus_set_resource 9
55for each resource.
56.Pp
57An identify method might be invoked multiple times.
58If a device driver is unloaded and loaded,
59the identify method will be called a second time after being reloaded.
60As a result, the identify method should avoid duplicate devices.
61Devices added by identify methods typically use a fixed device name
62in which case
63.Xr device_find_child 9
64can be used to detect existing devices.
65.Sh EXAMPLES
66The following pseudo-code shows an example of a function that
67probes for a piece of hardware and registers it and its resource
68(an I/O port) with the parent bus device.
69.Bd -literal
70void
71foo_identify(driver_t *driver, device_t parent)
72{
73	device_t child;
74
75	retrieve_device_information;
76	if (devices matches one of your supported devices &&
77	    device_get_child(parent, "foo", DEVICE_UNIT_ANY) == NULL) {
78		child = BUS_ADD_CHILD(parent, 0, "foo", DEVICE_UNIT_ANY);
79		bus_set_resource(child, SYS_RES_IOPORT, 0, FOO_IOADDR, 1);
80	}
81}
82.Ed
83.Sh SEE ALSO
84.Xr BUS_ADD_CHILD 9 ,
85.Xr bus_set_resource 9 ,
86.Xr device 9 ,
87.Xr device_find_child 9
88.Sh AUTHORS
89This manual page was written by
90.An Alexander Langer Aq Mt alex@FreeBSD.org .
91