From nobody Tue Jun 04 23:52:13 2024 X-Original-To: dev-commits-src-main@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 4Vv6p650RBz5N0D7; Tue, 04 Jun 2024 23:52:14 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Vv6p60sMhz4KNc; Tue, 4 Jun 2024 23:52:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717545134; 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=Nx1tPeYI7IIsXUeCrc0XjYjT+sOqVtY68S9wHpL4PGM=; b=GN2qtHyzEvRa/n2rxyd0hBxo/AKvpi+suS/jQ9c5tLCnqfYks9moYBiY/iMpV7JKbV3MeX W2+nRjbxZfoxLSWXOCYqTIu2BQhfnI2vFonfRXOI12VkOw38SdkQ5FI7X6EuFoDdp1JOw3 GLidipx79I8GC5Se5MaBJEC+AdJ3AiqCowgf81gMgg/gsWOAMqdEMXbGLE//rPtJNxZnAu XPhDK5K9YSL46vYsKgQx260MvejhMe9FYONkTR5EY8jW7SXdatPP3I5XquBhTq5BZvmpxR ryYNL0W39JzQhlWywivConqIW5ek28sPxZ9CKcyMpUOFlkepXJqbhlAV69EK/g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1717545134; a=rsa-sha256; cv=none; b=gW/qCDFZ8258mcnD+4MwhjHi19GZ4vMnSYGkgCd3snbnUhHF4s2iel6L3LlJqSX9K39OYZ w7HqUP+8/LtZ5jMsYsWwgZ0yphg792fWlGiS2W2tKFes5R5wxG5uEiZZS4ZJthKrMuT+vH gBr0klM2ICd/wAnu+1yIMC6seQ0apIY9H7otSqhahZLc2McA2wYfKmyCtGevet1VLwPiyt KRMdsUddoInGW+4AFcLJbaNuYbbun16ZtcFvfSA5MECPDN9CLmHpZYPng7VRbZ041BRfaV jgHM4WKVpaHgRpy0g82uoa7YDczyp+TOxPS1UtOpbBQmFjprHhaDTd7OlaQzww== 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=1717545134; 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=Nx1tPeYI7IIsXUeCrc0XjYjT+sOqVtY68S9wHpL4PGM=; b=xSysNpDfsl24yC9Bh9okOqtb+OcRok/qL9Rzl9BxJ930i28KGhhSE5qsy9Jimq4iYNhd0D 07l4My3MZ3v+k56Qew+zVGTFr38aaCY5yZJcECPd09haJnJ4kpZZ4ggwAFwwfE2f6FYqz0 pySv1Sw47mXkjUnR95U6oh79VIrBx7RqaNfEXEQm4y63cPFDkOabVz3p9kOtzfTE4I4/Sf CX3pDOVXexRI/aKQwWmMQzEweJ9RHzlUn/9xLbYIO10cITgSNk4zn+1VkEydAj/KCA/BBR +Q2jw6cT91UHtmiBOwTODNPobAu/4lp65vZSYU/AkuqpBgUSgi2egK/yCo5EdQ== 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 4Vv6p607nqzfqS; Tue, 4 Jun 2024 23:52:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 454NqDln061277; Tue, 4 Jun 2024 23:52:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 454NqDjx061274; Tue, 4 Jun 2024 23:52:13 GMT (envelope-from git) Date: Tue, 4 Jun 2024 23:52:13 GMT Message-Id: <202406042352.454NqDjx061274@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: 98056127ddfa - main - acpi/pci/vmd: Fix a nit with nested resource mapping requests List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: 98056127ddfa36720bcf46edc09843c867784bcb Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=98056127ddfa36720bcf46edc09843c867784bcb commit 98056127ddfa36720bcf46edc09843c867784bcb Author: John Baldwin AuthorDate: 2024-06-04 23:50:56 +0000 Commit: John Baldwin CommitDate: 2024-06-04 23:51:14 +0000 acpi/pci/vmd: Fix a nit with nested resource mapping requests Some bus drivers use rmans to suballocate resources to child devices. When the driver for a child device requests a mapping for a suballocated resource, the bus driver translates this into a mapping request for a suitable subrange of the original resource the bus driver allocated from its parent. This nested mapping request should look like any other resource mapping request being made by the bus device (i.e. as if the bus device had called bus_map_resource() or bus_alloc_resource() with RF_ACTIVE). I had slightly flubbed this last bit though since the direct use of bus_generic_map/unmap_resource passed up the original child device (second argument to the underlying kobj interface). While this is currently harmless, it is not strictly correct as the resource being mapped is owned by the bus device, not the child and can break for other bus drivers in the future. Instead, use bus_map/unmap_resource for the nested request where the requesting device is now the bus device that owns the parent resource. Reviewed by: imp Fixes: 0e1246e33461 acpi: Cleanup handling of suballocated resources Fixes: b377ff8110e3 pcib: Refine handling of resources allocated from bridge windows Fixes: d79b6b8ec267 pci_host_generic: Don't rewrite resource start address for translation Fixes: d714e73f7895 vmd: Use bus_generic_rman_* for PCI bus and memory resources Differential Revision: https://reviews.freebsd.org/D45433 --- sys/dev/acpica/acpi.c | 17 ++++++++++------- sys/dev/pci/pci_host_generic.c | 16 ++++++++-------- sys/dev/pci/pci_pci.c | 16 +++++++++------- sys/dev/vmd/vmd.c | 9 +++++---- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/sys/dev/acpica/acpi.c b/sys/dev/acpica/acpi.c index ad1af9373fb7..24d7027f165d 100644 --- a/sys/dev/acpica/acpi.c +++ b/sys/dev/acpica/acpi.c @@ -1651,19 +1651,22 @@ acpi_map_resource(device_t bus, device_t child, struct resource *r, args.offset = start - rman_get_start(sysres); args.length = length; - return (bus_generic_map_resource(bus, child, sysres, &args, map)); + return (bus_map_resource(bus, sysres, &args, map)); } static int acpi_unmap_resource(device_t bus, device_t child, struct resource *r, struct resource_map *map) { - if (acpi_is_resource_managed(bus, r)) { - r = acpi_managed_resource(bus, r); - if (r == NULL) - return (ENOENT); - } - return (bus_generic_unmap_resource(bus, child, r, map)); + struct resource *sysres; + + if (!acpi_is_resource_managed(bus, r)) + return (bus_generic_unmap_resource(bus, child, r, map)); + + sysres = acpi_managed_resource(bus, r); + if (sysres == NULL) + return (ENOENT); + return (bus_unmap_resource(bus, sysres, map)); } /* Allocate an IO port or memory resource, given its GAS. */ diff --git a/sys/dev/pci/pci_host_generic.c b/sys/dev/pci/pci_host_generic.c index 82ed51460621..d97a7597df25 100644 --- a/sys/dev/pci/pci_host_generic.c +++ b/sys/dev/pci/pci_host_generic.c @@ -646,7 +646,7 @@ generic_pcie_map_resource(device_t dev, device_t child, struct resource *r, args.offset = start - range->pci_base; args.length = length; - return (bus_generic_map_resource(dev, child, range->res, &args, map)); + return (bus_map_resource(dev, range->res, &args, map)); } static int @@ -664,16 +664,16 @@ generic_pcie_unmap_resource(device_t dev, device_t child, struct resource *r, #endif case SYS_RES_IOPORT: case SYS_RES_MEMORY: - range = generic_pcie_containing_range(dev, type, - rman_get_start(r), rman_get_end(r)); - if (range == NULL || range->res == NULL) - return (ENOENT); - r = range->res; break; default: - break; + return (bus_generic_unmap_resource(dev, child, r, argsp, map)); } - return (bus_generic_unmap_resource(dev, child, r, map)); + + range = generic_pcie_containing_range(dev, type, rman_get_start(r), + rman_get_end(r)); + if (range == NULL || range->res == NULL) + return (ENOENT); + return (bus_unmap_resource(dev, range->res, map)); } static bus_dma_tag_t diff --git a/sys/dev/pci/pci_pci.c b/sys/dev/pci/pci_pci.c index 35062d67050e..40b22c9802c4 100644 --- a/sys/dev/pci/pci_pci.c +++ b/sys/dev/pci/pci_pci.c @@ -2549,7 +2549,7 @@ pcib_map_resource(device_t dev, device_t child, struct resource *r, args.offset = start - rman_get_start(pres); args.length = length; - return (bus_generic_map_resource(dev, child, pres, &args, map)); + return (bus_map_resource(dev, pres, &args, map)); } static int @@ -2558,14 +2558,16 @@ pcib_unmap_resource(device_t dev, device_t child, struct resource *r, { struct pcib_softc *sc = device_get_softc(dev); struct pcib_window *w; + struct resource *pres; w = pcib_get_resource_window(sc, r); - if (w != NULL) { - r = pcib_find_parent_resource(w, r); - if (r == NULL) - return (ENOENT); - } - return (bus_generic_unmap_resource(dev, child, r, map)); + if (w == NULL) + return (bus_generic_unmap_resource(dev, child, r, map)); + + pres = pcib_find_parent_resource(w, r); + if (pres == NULL) + return (ENOENT); + return (bus_unmap_resource(dev, pres, map)); } #else /* diff --git a/sys/dev/vmd/vmd.c b/sys/dev/vmd/vmd.c index b52787fc45d3..d15a545d8d47 100644 --- a/sys/dev/vmd/vmd.c +++ b/sys/dev/vmd/vmd.c @@ -543,7 +543,7 @@ vmd_map_resource(device_t dev, device_t child, struct resource *r, args.offset = start - rman_get_start(pres); args.length = length; - return (bus_generic_map_resource(dev, child, pres, &args, map)); + return (bus_map_resource(dev, pres, &args, map)); } static int @@ -551,11 +551,12 @@ vmd_unmap_resource(device_t dev, device_t child, struct resource *r, struct resource_map *map) { struct vmd_softc *sc = device_get_softc(dev); + struct resource *pres; - r = vmd_find_parent_resource(sc, r); - if (r == NULL) + pres = vmd_find_parent_resource(sc, r); + if (pres == NULL) return (ENOENT); - return (bus_generic_unmap_resource(dev, child, r, map)); + return (bus_unmap_resource(dev, pres, map)); } static int