xref: /freebsd/share/man/man9/DEVICE_IDENTIFY.9 (revision 22ea1ec051c15659944bf3922c33ec4025d010ea)
12fccaec6SAlexander Langer.\" -*- nroff -*-
22fccaec6SAlexander Langer.\"
32fccaec6SAlexander Langer.\" Copyright (c) 2001 Alexander Langer
42fccaec6SAlexander Langer.\"
52fccaec6SAlexander Langer.\" All rights reserved.
62fccaec6SAlexander Langer.\"
72fccaec6SAlexander Langer.\" This program is free software.
82fccaec6SAlexander Langer.\"
92fccaec6SAlexander Langer.\" Redistribution and use in source and binary forms, with or without
102fccaec6SAlexander Langer.\" modification, are permitted provided that the following conditions
112fccaec6SAlexander Langer.\" are met:
122fccaec6SAlexander Langer.\" 1. Redistributions of source code must retain the above copyright
132fccaec6SAlexander Langer.\"    notice, this list of conditions and the following disclaimer.
142fccaec6SAlexander Langer.\" 2. Redistributions in binary form must reproduce the above copyright
152fccaec6SAlexander Langer.\"    notice, this list of conditions and the following disclaimer in the
162fccaec6SAlexander Langer.\"    documentation and/or other materials provided with the distribution.
172fccaec6SAlexander Langer.\"
182fccaec6SAlexander Langer.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
192fccaec6SAlexander Langer.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
202fccaec6SAlexander Langer.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
212fccaec6SAlexander Langer.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
222fccaec6SAlexander Langer.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
232fccaec6SAlexander Langer.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242fccaec6SAlexander Langer.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252fccaec6SAlexander Langer.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262fccaec6SAlexander Langer.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
272fccaec6SAlexander Langer.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282fccaec6SAlexander Langer.\"
29db4fcadfSConrad Meyer.Dd January 15, 2017
302fccaec6SAlexander Langer.Dt DEVICE_IDENTIFY 9
312fccaec6SAlexander Langer.Os
322fccaec6SAlexander Langer.Sh NAME
332fccaec6SAlexander Langer.Nm DEVICE_IDENTIFY
342fccaec6SAlexander Langer.Nd identify a device, register it
352fccaec6SAlexander Langer.Sh SYNOPSIS
3632eef9aeSRuslan Ermilov.In sys/param.h
3732eef9aeSRuslan Ermilov.In sys/bus.h
382fccaec6SAlexander Langer.Ft void
392fccaec6SAlexander Langer.Fn DEVICE_IDENTIFY "driver_t *driver" "device_t parent"
402fccaec6SAlexander Langer.Sh DESCRIPTION
41db4fcadfSConrad MeyerThe identify function for a device is only needed for devices on buses
425203edcdSRuslan Ermilovthat cannot identify their children independently, e.g.\& the ISA bus.
43b82af3f5SMike PritchardIt is used to recognize the device (usually done by accessing non-ambiguous
442fccaec6SAlexander Langerregisters in the hardware) and to tell the kernel about it and thus
452fccaec6SAlexander Langercreating a new device instance.
462fccaec6SAlexander Langer.Pp
472fccaec6SAlexander Langer.Xr BUS_ADD_CHILD 9
482fccaec6SAlexander Langeris used to register the device as a child of the bus.
492fccaec6SAlexander LangerThe device's resources (such as IRQ and I/O ports) are registered
502fccaec6SAlexander Langerwith the kernel by calling
512fccaec6SAlexander Langer.Fn bus_set_resource
522fccaec6SAlexander Langerfor each resource (refer to
532fccaec6SAlexander Langer.Xr bus_set_resource 9
542fccaec6SAlexander Langerfor more information).
554eebf565SWarner Losh.Pp
564eebf565SWarner LoshSince the device tree and the device driver tree are disjoint, the
57bf7f20c2SRuslan Ermilov.Fn DEVICE_IDENTIFY
584eebf565SWarner Loshroutine needs to take this into account.
594eebf565SWarner LoshIf you load and unload your device driver that has the identify
604eebf565SWarner Loshroutine, the child node has the potential for adding the same node
61a1013c57SWarner Loshmultiple times unless specific measure are taken to preclude that
62a1013c57SWarner Loshpossibility.
632fccaec6SAlexander Langer.Sh EXAMPLES
642fccaec6SAlexander LangerThe following pseudo-code shows an example of a function that
652fccaec6SAlexander Langerprobes for a piece of hardware and registers it and its resource
662fccaec6SAlexander Langer(an I/O port) with the kernel.
672fccaec6SAlexander Langer.Bd -literal
682fccaec6SAlexander Langervoid
692fccaec6SAlexander Langerfoo_identify(driver_t *driver, device_t parent)
702fccaec6SAlexander Langer{
712fccaec6SAlexander Langer	device_t child;
722fccaec6SAlexander Langer
732fccaec6SAlexander Langer	retrieve_device_information;
74a1013c57SWarner Losh	if (devices matches one of your supported devices &&
75a1013c57SWarner Losh	    not already in device tree) {
76*22ea1ec0SWarner Losh		child = BUS_ADD_CHILD(parent, 0, "foo", DEVICE_UNIT_ANY);
772fccaec6SAlexander Langer		bus_set_resource(child, SYS_RES_IOPORT, 0, FOO_IOADDR, 1);
782fccaec6SAlexander Langer	}
792fccaec6SAlexander Langer}
802fccaec6SAlexander Langer.Ed
812fccaec6SAlexander Langer.Sh SEE ALSO
822fccaec6SAlexander Langer.Xr BUS_ADD_CHILD 9 ,
835521ff5aSRuslan Ermilov.Xr bus_set_resource 9 ,
845521ff5aSRuslan Ermilov.Xr device 9 ,
852fccaec6SAlexander Langer.Xr device_add_child 9 ,
862fccaec6SAlexander Langer.Xr DEVICE_ATTACH 9 ,
872fccaec6SAlexander Langer.Xr DEVICE_DETACH 9 ,
882fccaec6SAlexander Langer.Xr DEVICE_PROBE 9 ,
895521ff5aSRuslan Ermilov.Xr DEVICE_SHUTDOWN 9
902fccaec6SAlexander Langer.Sh AUTHORS
91571dba6eSHiten PandyaThis manual page was written by
928a7314fcSBaptiste Daroussin.An Alexander Langer Aq Mt alex@FreeBSD.org .
93