From nobody Mon Mar 3 16:57:05 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 4Z64jZ2XMVz5pnRs; Mon, 03 Mar 2025 16:57:06 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Z64jY2x1gz46Lb; Mon, 03 Mar 2025 16:57:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1741021025; 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=9qp9c9IYCPiijEJT/wQepaRuAlUR38c6GmkQ8Wzoaxc=; b=fxvu7ijKkJjHp/A47GCWsCCdTjiQVTSyZweN9RIGYAyG8YxHD4fRkAMnwbfw6J8o2hx3sK HUFIA1YnP91Tb1oBkdg7+URgqFAaYVVOKHvHhRcXMXM9pn62C9zFJ07d0WrOOYbw05sjwh DcCVUzio9gX6uILlS+7twMXlroeoG8H7/hBrXkoKLl8xQobOgGor2gW4bpmritAhcNGAev rPR7XyuSuJv7HsB0V8gUDq3f1fIsecMSMNJZWZRUc3SDq2sXA1D2uum1Tpifs9qWNbZBaK 6V8xYK+931gpSQYDR8Cv+RG8sf/DIZ1b9jCdHUcCMuK5kosE80m4IO1+6khcNw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1741021025; a=rsa-sha256; cv=none; b=W+NRAS1jz8o9E0e3BEw1jqgYCo9HUqbjS9kF/VCqj71A52r/o0suwqZ7RmROzVXgFgwJnk eAvbvQ1vx4PluM7G4cplw2qFV3hbV85fXo85boVOAhqMmIV+f/XVXWMygrMP4d0tHSpiHL RVlyHv//tsHPlGaRO3wayc36exJK+7bXGFaLAHuyU4wXZe8W7LcHXNGSHZwfBl/gx8kS0J ntApgnMTeqeymKfrjtbPfJKvab3AaQFlzCCur41Y8jyJfxXHQq6NBokzxK6nSMPmVRNu4V Z5cwMa/TcmvgS1MNmAnRKiwRG5imUtKgEmcKBrlgMOJEkHDKGrPnJ+gjc+9HoA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1741021025; 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=9qp9c9IYCPiijEJT/wQepaRuAlUR38c6GmkQ8Wzoaxc=; b=BtJyqKpM3wrq+drqxh4bX2w37R/bZBJm8p+Z30mIZw1nu0szu1u9q4S898w+Xsp2aoAiqF XwmhpJ2dxVXU8B2gOLNo5BKB9lkekYEOeeBq7sA+l1Fo4OYfE3eh1KhKtb5jEjbBT7Cz50 fuMGFGDXlzuwDpm6je/AJ0IhWg5ys0puyW2Od0xk6pVJ37/yYnOd3nFtGF+JjnP2Wa49L7 gINBddyS9FDqwGS4SCJSw+7fr9D+GD6ok3vdNkV3ev9IrGzVhCM9fEj7wixncJZ6oN0ClT NUsC64MVxzzIYTuIM36q1cSwVHOCDrIiogauawqCN0iPD4A6iEiqko5ora3+QA== 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 4Z64jY1hwzzwZd; Mon, 03 Mar 2025 16:57:05 +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 523Gv5YA083909; Mon, 3 Mar 2025 16:57:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 523Gv5Nj083906; Mon, 3 Mar 2025 16:57:05 GMT (envelope-from git) Date: Mon, 3 Mar 2025 16:57:05 GMT Message-Id: <202503031657.523Gv5Nj083906@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 858f3ef5a0cb - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 858f3ef5a0cb66b9f8c7ac5df7de9b0851fe57ce Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=858f3ef5a0cb66b9f8c7ac5df7de9b0851fe57ce commit 858f3ef5a0cb66b9f8c7ac5df7de9b0851fe57ce Author: John Baldwin AuthorDate: 2025-02-05 19:44:57 +0000 Commit: John Baldwin CommitDate: 2025-03-03 16:56:21 +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 (cherry picked from commit d7fa71dfedd6db18ded3971c6f42b3699b5627d7) --- 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 b4adf70ae2aa..6a8f9a9f5622 100644 --- a/share/man/man9/Makefile +++ b/share/man/man9/Makefile @@ -1043,6 +1043,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