From nobody Wed Feb 5 19:49:47 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Yp9mr1HVTz5mHh9; Wed, 05 Feb 2025 19:49:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Yp9mq5qVFz3v9N; Wed, 05 Feb 2025 19:49:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1738784987; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=U8NnxC6INtoR9l5ebbKPw3boy+1XHcxkGhQGDAJerKw=; b=tSr55Qs+wQDzpY31o6+Af+JfkiZdvSs3yDVcvsV11qQ6pC7z3X1vG0WQaIcClxJWyOaAlH /fsvcqiWvEejoz+qnpxxmfrGhv6ncKk5gcNahiMqPw2GMHjw1RmS0kJxRbbilUZhLTa+s1 PRtiU1jZyTQnwF0ePOfdcPnaDYnCmYL1SDHOhmodY8CF2niuYR0NS+INuDs6LsWtfB9n+E EA45Z7J7T5Eo1riuADTEnnSZZpLQmaZvAuA7RjeJN3Bkjy7qTdtw/vPpWAkxFJ4HZHJZ3/ QKbX+B6VFAqG4foqVLT4O+7TnWuu73HoXZMBmSyhNTkOwPIv9JMYUD+wsWk/vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1738784987; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=U8NnxC6INtoR9l5ebbKPw3boy+1XHcxkGhQGDAJerKw=; b=DAL/+ijl5r9HJp80bi4XjdxRQpB7hvakaF4DM5ReBIp9fM8sMUKHL+e2aLfwBlaWryblaV 4Da3LhFhfiv42mcjeFvc9etkI40NJav+9FZiplkFti+CcLgudhdMi0UM3THUB73WAF2r0m wcdcXF8vgNZvjKt/BPgK0QPt4Ns3nxjObhebGNPYhAfhH/ekvjxSJA82CuUc8N7msL7YcA ls089DQKxaN4ETUFK05a73fyRWo4WldOff23bOwok4yFl6GxgJS9dcAn1HNZbI2ywZqcYz VjMbNgiEQKDMi06GyGS7r+lNTF7tREpjf89qUDyiJmdzIdkIpNdPEkf3kESzOg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1738784987; a=rsa-sha256; cv=none; b=XlbRk9z32j0K4flL/j3C8C1+5ljSwHxREbmhP7J5M50t+8/ItPyQbFs1F4At9WhhDHoGoG iBvpLjfcoCSj0hZpSq8QjTQpAsW+297eSxp7LPTaSPntgl6Rcy6gkC9MknijnkGPkCkMfa QJP+AzncfdiopyGQAc0sZk7YOULvFsd8J48dVexEQVamclrS+z9ENGVs3PGtLi1n0q8T6k jQt/NShu20q6lT3yGI4Z1c8/bqlIWDxEnJFzOGfj1u/jCdEYPIdCny5mZ8Cim+M9nP/mDg x+iCd3U9pQjXye5Jb11o3quACXt4vYBnvMv0wCNSZejjbx12Tal6YfXSIeNBxw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Yp9mq5Gc5z15P5; Wed, 05 Feb 2025 19:49:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 515Jnl3V070250; Wed, 5 Feb 2025 19:49:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 515Jnlps070247; Wed, 5 Feb 2025 19:49:47 GMT (envelope-from git) Date: Wed, 5 Feb 2025 19:49:47 GMT Message-Id: <202502051949.515Jnlps070247@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: d7fa71dfedd6 - main - device_probe_and_attach.9: Document more device functions List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d7fa71dfedd6db18ded3971c6f42b3699b5627d7 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=d7fa71dfedd6db18ded3971c6f42b3699b5627d7 commit d7fa71dfedd6db18ded3971c6f42b3699b5627d7 Author: John Baldwin AuthorDate: 2025-02-05 19:44:57 +0000 Commit: John Baldwin CommitDate: 2025-02-05 19:45:41 +0000 device_probe_and_attach.9: Document more device functions Split out separate descriptions of device_probe and device_attach and include extra details (such as the effect of a disabled hint during device_attach). Reframe device_probe_and_attach as a recommended wrapper function around device_probe and device_attach. While here, add a description of device_detach. Differential Revision: https://reviews.freebsd.org/D48364 --- share/man/man9/Makefile | 3 + share/man/man9/device_probe_and_attach.9 | 128 ++++++++++++++++++++++++++++--- 2 files changed, 120 insertions(+), 11 deletions(-) diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile index 6af9880b8d57..3054e5b3e9bd 100644 --- a/share/man/man9/Makefile +++ b/share/man/man9/Makefile @@ -1044,6 +1044,9 @@ MLINKS+=device_set_desc.9 device_get_desc.9 \ device_set_desc.9 device_set_descf.9 \ device_set_desc.9 device_set_desc_copy.9 MLINKS+=device_set_flags.9 device_get_flags.9 +MLINKS+=device_probe_and_attach.9 device_attach.9 \ + device_probe_and_attach.9 device_detach.9 \ + device_probe_and_attach.9 device_probe.9 MLINKS+=devstat.9 devicestat.9 \ devstat.9 devstat_new_entry.9 \ devstat.9 devstat_end_transaction.9 \ diff --git a/share/man/man9/device_probe_and_attach.9 b/share/man/man9/device_probe_and_attach.9 index 5d5de52cee66..0c438be3a483 100644 --- a/share/man/man9/device_probe_and_attach.9 +++ b/share/man/man9/device_probe_and_attach.9 @@ -26,33 +26,139 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd June 16, 1998 +.Dd February 5, 2025 .Dt DEVICE_PROBE_AND_ATTACH 9 .Os .Sh NAME +.Nm device_attach , +.Nm device_detach , +.Nm device_probe , .Nm device_probe_and_attach -.Nd initialise a device +.Nd manage device's connection to a device driver .Sh SYNOPSIS .In sys/param.h .In sys/bus.h .Ft int +.Fn device_attach "device_t dev" +.Ft int +.Fn device_detach "device_t dev" +.Ft int +.Fn device_probe "device_t dev" +.Ft int .Fn device_probe_and_attach "device_t dev" .Sh DESCRIPTION -This function is called during autoconfiguration to initialise the -devices in the system. -For each device, the +These functions manage the relationship between a device and device drivers. +.Pp +.Fn device_probe +invokes the .Xr DEVICE_PROBE 9 -method of each suitable driver is called and if a probe succeeds, a -description of the device is printed and the +method of each suitable driver and to find the driver with the best match for +.Fa dev . +If a matching driver is found, +.Fa dev +is set to the +.Dv DS_ALIVE +state and zero is returned. +If +.Fa dev +is already attached to a device driver or has been disabled via +.Xr device_disable 9 , +then it will not be probed and -1 is returned. +.Pp +.Fn device_attach +fully attaches a device driver to +.Fa dev . +This function prints a description of the device and invokes the +.Xr DEVICE_ATTACH 9 +method. +If the +.Xr DEVICE_ATTACH 9 +method succeeds, +.Fa dev +is set to the +.Dv DS_ATTACHED +state and zero is returned. +If the .Xr DEVICE_ATTACH 9 -method is called. -If the device is disabled using -.Xr device_disable 9 -then it will not be probed. +method fails, +.Xr BUS_CHILD_DETACHED 9 +is called and an error value is returned. +.Pp +If the device name and unit are disabled by a hint, +.Fn device_attach +disables the device, demotes it to the +.Dv DS_NOTPRESENT +state, +and returns +.Dv ENXIO . +The device retains its device name and unit and can be re-enabled via +.Xr devctl 8 . +.Pp +.Fn device_probe_and_attach +is a wrapper function around +.Fn device_probe +and +.Fn device_attach +that fully initialises a device. +If +.Fa dev +is already attached or disabled, +.Fn device_probe_and_attach +leaves the device unchanged and returns zero. +Otherwise, +.Fn device_probe +is used to identify a device driver for +.Fa dev +and +.Fn device_attach +finalizes attaching the driver to +.Fa dev . +Device drivers should generally use this function to initialize a device +rather than direct calls to +.Fn device_probe +and +.Fn device_attach . +.Pp +.Fn device_detach +detaches the device driver from +.Fa dev . +This function invokes the +.Xr DEVICE_DETACH 9 +method to tear down device driver state for +.Fa dev . +If the method fails, +its error value is returned and +.Fa dev +remains attached. +If the method succeeds, +otherwise, +.Xr BUS_CHILD_DETACHED 9 +is called, +the device is set to the +.Dv DS_NOTPRESENT +state, +and zero is returned. +If a device is busy, +.Fn device_detach +fails with +.Dv EBUSY +and leaving +.Fa dev +unchanged. .Sh RETURN VALUES Zero is returned on success, otherwise an appropriate error is returned. +In addition, +.Fn device_probe +returns -1 if +.Fa dev +is disabled or already attached. .Sh SEE ALSO +.Xr devctl 8 , +.Xr BUS_CHILD_DETACHED 9 , .Xr device 9 , +.Xr DEVICE_ATTACH 9 , +.Xr DEVICE_DETACH 9 , +.Xr DEVICE_PROBE 9 , .Xr driver 9 .Sh AUTHORS This manual page was written by