From nobody Thu Dec 18 20:48:05 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 4dXN6F2Dhmz6LlJs for ; Thu, 18 Dec 2025 20:48:05 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dXN6F1DKsz3PV8 for ; Thu, 18 Dec 2025 20:48:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1766090885; 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=1aG+Abcj8+YjuBd0wFqtj16dl1jT/speX5cl0ePUSeQ=; b=WAJSk4+8eJFyGAIPJj4R9V8aqcjQDa0ArjegptaXq0aktN3YJ77OylwW/tTde8d96kMR8g vmpS5ti2a9qZgjFOSdIoIRIq7rcm3c1V+rWyNM5+gN1jFSKzMD7Mh5mvTwbPFbAcP47qwv AqVntyXYsZPbrhtWUX1/CfdejP8NStMO1orDSIuWhPK4DtWcyNh0UqcoEMEExWEZX3Hp/s ZiE+nVbVmUlRb73FAnLrrEa5/MgkfhYAvbwI6P3rpJbp3FvkEJ6KVsQ2yB4KuX1g+2Cvaf oWXLFCX4Bgt9MduPONSLEgdsYTdmjvQiW65x79Xtbe+gKKJ6ZxNaBsUU4ZK0gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1766090885; 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=1aG+Abcj8+YjuBd0wFqtj16dl1jT/speX5cl0ePUSeQ=; b=NmRHG8T4gX3AzdInArA4HiqULybMT/mZMoEjz95F9ywLweioD9vk78c6DP1Hd7MFWkaXu3 lZsbKkjrvA+dEI/HDdtY0IprSxRNqEaK9PkXyhovX9/ypQxFNR5BokoH3M8/jLjOT5FZhs 3AIpNodeok9CLv4+pt6PxgXBfdrxHLJVZf/Ar0ryYqOy4qYQgY9q+JWZ7A5ygAUhi0BhVz o5FGG1S94SD59AGaEtlm7BVnJVnEbqJMPYKOBYwrzuXxVrvp9Xuo3CxfUqrBLGa/igEEZa tfr0g7meXidIAIxI+i7C7MiFBCpaJhhPdK4iGY1zsQIewDMS9oH/E0pe1+Gk+g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1766090885; a=rsa-sha256; cv=none; b=IkDtz3lQZCM/DdGNbFRmrz3RI3ZjtpP+pFQkRT1ujLCUKVn/mhjS/PO6ESC2gOygTao9ps u7mJB4fF+XyPzj6qNo11gkFUcNPsfTI/6iydDP1uLA2lE8x/UPvbKKnolYq5Xk5hGn00Xl rAxaisC1EEw7hf3Ao6EU/7vYdpgAi8Xa3C17wHFaV/kKMwzkfeJESqBIX3BzRcI2C1qeQj ZVAyLe1uH7ZECmX71H3F2oQfKkX2Q5vx/K9u/BRf+qc72LwNnNnWW+ctTRzZ/GHvsTochI 88B0PCqlH7a7ht1MEmqMAGJSwqo3DLAH4NNZp8T1khgF20wpym3bd+rBbkjNnA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dXN6F0YNrzv7r for ; Thu, 18 Dec 2025 20:48:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3b4f0 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 18 Dec 2025 20:48:05 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 3fbce8315ee2 - stable/15 - bus_alloc_resource: First step in passing resource IDs by value 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/15 X-Git-Reftype: branch X-Git-Commit: 3fbce8315ee22ef3a3e0fde3c57130e6ad16535f Auto-Submitted: auto-generated Date: Thu, 18 Dec 2025 20:48:05 +0000 Message-Id: <69446885.3b4f0.2bd35ddf@gitrepo.freebsd.org> The branch stable/15 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=3fbce8315ee22ef3a3e0fde3c57130e6ad16535f commit 3fbce8315ee22ef3a3e0fde3c57130e6ad16535f Author: John Baldwin AuthorDate: 2025-10-30 15:14:27 +0000 Commit: John Baldwin CommitDate: 2025-12-18 20:22:05 +0000 bus_alloc_resource: First step in passing resource IDs by value Add wrapper inline functions for bus_alloc_resource* that accept a resource ID by value (instead of a pointer). The rest of the bus resource API (outside of compat shims) does not accept resource IDs as arguments, but instead obtains the resource ID from the resource itself when needed. As such, there is no reason to return any potentially modified resource IDs to the caller. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D53401 (cherry picked from commit 7eb213614b90cde31707a53c4b8ae6acacf2aa0f) --- share/man/man9/bus_alloc_resource.9 | 24 +++++++-------------- sys/kern/subr_bus.c | 2 +- sys/sys/bus.h | 42 +++++++++++++++++++++++++++++++++++++ sys/sys/param.h | 2 +- 4 files changed, 51 insertions(+), 19 deletions(-) diff --git a/share/man/man9/bus_alloc_resource.9 b/share/man/man9/bus_alloc_resource.9 index 27c64c608c70..210abb3074e1 100644 --- a/share/man/man9/bus_alloc_resource.9 +++ b/share/man/man9/bus_alloc_resource.9 @@ -26,7 +26,7 @@ .\" (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 May 20, 2016 +.Dd October 30, 2025 .Dt BUS_ALLOC_RESOURCE 9 .Os .Sh NAME @@ -43,14 +43,14 @@ .In machine/resource.h .Ft struct resource * .Fo bus_alloc_resource -.Fa "device_t dev" "int type" "int *rid" "rman_res_t start" "rman_res_t end" +.Fa "device_t dev" "int type" "int rid" "rman_res_t start" "rman_res_t end" .Fa "rman_res_t count" "u_int flags" .Fc .Ft struct resource * -.Fn bus_alloc_resource_any "device_t dev" "int type" "int *rid" "u_int flags" +.Fn bus_alloc_resource_any "device_t dev" "int type" "int rid" "u_int flags" .Ft struct resource * .Fo bus_alloc_resource_anywhere -.Fa "device_t dev" "int type" "int *rid" "rman_res_t count" "u_int flags" +.Fa "device_t dev" "int type" "int rid" "rman_res_t count" "u_int flags" .Fc .Sh DESCRIPTION This is an easy interface to the resource-management functions. @@ -106,15 +106,13 @@ for I/O memory .El .It .Fa rid -points to a bus specific handle that identifies the resource being allocated. +is a bus specific handle that identifies the resource being allocated. For ISA this is an index into an array of resources that have been setup for this device by either the PnP mechanism, or via the hints mechanism. For PCCARD, this is an index into the array of resources described by the PC Card's CIS entry. For PCI, the offset into PCI config space which has the BAR to use to access the resource. -The bus methods are free to change the RIDs that they are given as a parameter. -You must not depend on the value you gave it earlier. .It .Fa start and @@ -170,20 +168,12 @@ A pointer to is returned on success, a null pointer otherwise. .Sh EXAMPLES This is some example code that allocates a 32 byte I/O port range and an IRQ. -The values of -.Va portid -and -.Va irqid -should be saved in the softc of the device after these calls. .Bd -literal struct resource *portres, *irqres; - int portid, irqid; - portid = 0; - irqid = 0; - portres = bus_alloc_resource(dev, SYS_RES_IOPORT, &portid, + portres = bus_alloc_resource(dev, SYS_RES_IOPORT, 0, 0ul, ~0ul, 32, RF_ACTIVE); - irqres = bus_alloc_resource_any(dev, SYS_RES_IRQ, &irqid, + irqres = bus_alloc_resource_any(dev, SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE); .Ed .Sh SEE ALSO diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index f75345415265..755d7d41899f 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -4651,7 +4651,7 @@ bus_release_resources(device_t dev, const struct resource_spec *rs, * parent of @p dev. */ struct resource * -bus_alloc_resource(device_t dev, int type, int *rid, rman_res_t start, +(bus_alloc_resource)(device_t dev, int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags) { struct resource *res; diff --git a/sys/sys/bus.h b/sys/sys/bus.h index 77250bb1df4c..a0967178830f 100644 --- a/sys/sys/bus.h +++ b/sys/sys/bus.h @@ -600,6 +600,48 @@ bus_alloc_resource_anywhere(device_t dev, int type, int *rid, return (bus_alloc_resource(dev, type, rid, 0, ~0, count, flags)); } +/* Compat shims for bus_alloc_resource API. */ +static __inline struct resource * +bus_alloc_resource_const(device_t dev, int type, int rid, rman_res_t start, + rman_res_t end, rman_res_t count, u_int flags) +{ + return (bus_alloc_resource(dev, type, &rid, start, end, count, flags)); +} + +static __inline struct resource * +bus_alloc_resource_any_const(device_t dev, int type, int rid, u_int flags) +{ + return (bus_alloc_resource(dev, type, &rid, 0, ~0, 1, flags)); +} + +static __inline struct resource * +bus_alloc_resource_anywhere_const(device_t dev, int type, int rid, + rman_res_t count, u_int flags) +{ + return (bus_alloc_resource(dev, type, &rid, 0, ~0, count, flags)); +} + +#define bus_alloc_resource(dev, type, rid, start, end, count, flags) \ + _Generic((rid), \ + int *: bus_alloc_resource, \ + unsigned int *: bus_alloc_resource, \ + default: bus_alloc_resource_const) \ + ((dev), (type), (rid), (start), (end), (count), (flags)) + +#define bus_alloc_resource_any(dev, type, rid, flags) \ + _Generic((rid), \ + int *: bus_alloc_resource_any, \ + unsigned int *: bus_alloc_resource_any, \ + default: bus_alloc_resource_any_const) \ + ((dev), (type), (rid), (flags)) + +#define bus_alloc_resource_anywhere(dev, type, rid, count, flags) \ + _Generic((rid), \ + int *: bus_alloc_resource_anywhere, \ + unsigned int *: bus_alloc_resource_anywhere, \ + default: bus_alloc_resource_anywhere_const) \ + ((dev), (type), (rid), (count), (flags)) + /* Compat shims for simpler bus resource API. */ int bus_adjust_resource_old(device_t child, int type, struct resource *r, rman_res_t start, rman_res_t end); diff --git a/sys/sys/param.h b/sys/sys/param.h index fe7ceeb90e9d..d4afa1be7bc5 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -74,7 +74,7 @@ * cannot include sys/param.h and should only be updated here. */ #undef __FreeBSD_version -#define __FreeBSD_version 1500503 +#define __FreeBSD_version 1500504 /* * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,