From nobody Thu Feb 27 16:55:53 2025 X-Original-To: dev-commits-src-branches@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 4Z3ct15rpKz59J61; Thu, 27 Feb 2025 16:55:53 +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 4Z3ct15GbMz46Gf; Thu, 27 Feb 2025 16:55:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1740675353; 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=JlL8ipzl4X9KKNfPHq0Lip2lRTPr3I2PAj8HIFugKeo=; b=sh0cCDxGeZQJ83Scmq2sA74XX2f1NvFLB+jpI16Q1RqnltZdnPi2jXzNJZhKYuxU+oN5xB 0Gzgoq3YagjOvArgbS9tggzN3Bn+ulq+hjBVKfqVrcceClDjE8SKtBBqKTICYVw7sej4Ar aIrla68CldtbY4WspgqhA5ei2Umd4f4E/PYClU+DK0I5OV+gdi+jLherdady/kHq+zAVvJ 6qTrq/kEGFkNzt+/8UXewvcpx6Tlu3DxN1zj3CYUlHmB5Y2aC5EeBG+Zfjo89Pu9cdySAo dIPoUTzxrhi9DLcaUyHEHz37fL4q2KuAPL/izGGmKfktWiXcS8qGZdh+f9FVnw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1740675353; a=rsa-sha256; cv=none; b=AAI5l+yyJEkm8OybkXNZh548ki7qF9xq9C82/HSKTYrgImo+CHxAjSpSazn3VDwUgyLyVT KXcjiwOV9JqnwCCuZMYjBI6d4V/G6nWWE+1V0QeATNcaBk+5TQGOg5BQ31F7Y9vY5iio7E 6jeHPQ/WmPgbeGKJuWWOFKh7ZcFjHFZgd9xgRPNR8jQgqMqLznLr7bexzFv/uuVyrzZzls EsdqcGB+cjsG9tHkeFMSA5uhvapGWXGLagU/MbKE9pGiH0db+++zk+B7jrHwBLMxgodWJn ty2TghVbqX5d04w85w9ofdpGu4jsshycKE+o7a9qey0qYSGU76o05RyUi3/iOw== 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=1740675353; 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=JlL8ipzl4X9KKNfPHq0Lip2lRTPr3I2PAj8HIFugKeo=; b=i2x8Ei5q/UAYgx+1/LRI9QxRpdXGIfhKINnHEAJUW+Sz1EgR8eOT0FiNxu/47T/IzQBert 8r0HbH8pxGgZNmMUL+9S8zE+BXL7YodPlRLaHOWd78IUiq+UOhrBrGqGIdqdL4adKoG/TO IrbvoLggUNl7MQoyCpAyPiXSjvGLgCBqlNgsv7NGjOmrKzTfpSJV7tVzbD11W5UmDGIrbl kvl7mqsDHG7MYYu7AWUZc2gpt9JNmoIdpHGS3IpITMnbRuhDzf0jsG44xdNNtmHH9gQueE XTAWLkp8Ep9RMYfiiJF95Q+OUWY23EYfj8s8bA8tFMHN6BEXs6aJ8zimfx+1uA== 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 4Z3ct14ZRpzrkC; Thu, 27 Feb 2025 16:55:53 +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 51RGtrdR016987; Thu, 27 Feb 2025 16:55:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 51RGtrBn016984; Thu, 27 Feb 2025 16:55:53 GMT (envelope-from git) Date: Thu, 27 Feb 2025 16:55:53 GMT Message-Id: <202502271655.51RGtrBn016984@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: 4aed8b3b613c - stable/14 - new-bus: Add bus_(identify|attach|detach)_children List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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: 4aed8b3b613c5e1499336e4d7ec7e9a3ac3d9a12 Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=4aed8b3b613c5e1499336e4d7ec7e9a3ac3d9a12 commit 4aed8b3b613c5e1499336e4d7ec7e9a3ac3d9a12 Author: John Baldwin AuthorDate: 2024-12-06 22:25:04 +0000 Commit: John Baldwin CommitDate: 2025-02-27 15:19:24 +0000 new-bus: Add bus_(identify|attach|detach)_children These correspond to the current implementations of bus_generic_(probe|attach|detach) but with more accurate names and semantics. The intention is to deprecate bus_generic_(probe|attach) and reimplement bus_generic_detach in a future commit. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D47673 (cherry picked from commit 46297859a74563dde6fc5bff9f9ecded9fb61ba6) bus_generic_(probe|attach|detach) will not be changed in stable/14, but providing the new APIs in stable/14 permits drivers to use the new APIs. --- sys/kern/subr_bus.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++----- sys/sys/bus.h | 4 ++++ sys/sys/param.h | 2 +- 3 files changed, 65 insertions(+), 6 deletions(-) diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 5d1a13c08892..b71a46edc544 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -3401,6 +3401,22 @@ bus_generic_add_child(device_t dev, u_int order, const char *name, int unit) */ int bus_generic_probe(device_t dev) +{ + bus_identify_children(dev); + return (0); +} + +/** + * @brief Ask drivers to add child devices of the given device. + * + * This function allows drivers for child devices of a bus to identify + * child devices and add them as children of the given device. NB: + * The driver for @param dev must implement the BUS_ADD_CHILD method. + * + * @param dev the parent device + */ +void +bus_identify_children(device_t dev) { devclass_t dc = dev->devclass; driverlink_t dl; @@ -3419,8 +3435,6 @@ bus_generic_probe(device_t dev) continue; DEVICE_IDENTIFY(dl->driver, dev); } - - return (0); } /** @@ -3432,14 +3446,29 @@ bus_generic_probe(device_t dev) */ int bus_generic_attach(device_t dev) +{ + bus_attach_children(dev); + return (0); +} + +/** + * @brief Probe and attach all children of the given device + * + * This function attempts to attach a device driver to each unattached + * child of the given device using device_probe_and_attach(). If an + * individual child fails to attach this function continues attaching + * other children. + * + * @param dev the parent device + */ +void +bus_attach_children(device_t dev) { device_t child; TAILQ_FOREACH(child, &dev->children, link) { device_probe_and_attach(child); } - - return (0); } /** @@ -3453,7 +3482,7 @@ int bus_delayed_attach_children(device_t dev) { /* Probe and attach the bus children when interrupts are available */ - config_intrhook_oneshot((ich_func_t)bus_generic_attach, dev); + config_intrhook_oneshot((ich_func_t)bus_attach_children, dev); return (0); } @@ -3467,6 +3496,32 @@ bus_delayed_attach_children(device_t dev) */ int bus_generic_detach(device_t dev) +{ + int error; + + error = bus_detach_children(dev); + if (error != 0) + return (error); + + return (0); +} + +/** + * @brief Detach drivers from all children of a device + * + * This function attempts to detach a device driver from each attached + * child of the given device using device_detach(). If an individual + * child fails to detach this function stops and returns an error. + * NB: Children that were successfully detached are not re-attached if + * an error occurs. + * + * @param dev the parent device + * + * @retval 0 success + * @retval non-zero a device would not detach + */ +int +bus_detach_children(device_t dev) { device_t child; int error; diff --git a/sys/sys/bus.h b/sys/sys/bus.h index c1391c4a7284..91a54b93a1db 100644 --- a/sys/sys/bus.h +++ b/sys/sys/bus.h @@ -597,8 +597,12 @@ void bus_delete_resource(device_t dev, int type, int rid); int bus_child_present(device_t child); int bus_child_pnpinfo(device_t child, struct sbuf *sb); int bus_child_location(device_t child, struct sbuf *sb); + +void bus_attach_children(device_t dev); +int bus_detach_children(device_t dev); void bus_enumerate_hinted_children(device_t bus); int bus_delayed_attach_children(device_t bus); +void bus_identify_children(device_t dev); static __inline struct resource * bus_alloc_resource_any(device_t dev, int type, int *rid, u_int flags) diff --git a/sys/sys/param.h b/sys/sys/param.h index 0e91a65170df..914433bace0e 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -75,7 +75,7 @@ * cannot include sys/param.h and should only be updated here. */ #undef __FreeBSD_version -#define __FreeBSD_version 1402502 +#define __FreeBSD_version 1402503 /* * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,