From nobody Wed Jan 03 22:02:50 2024 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 4T53cV4P7dz56npM; Wed, 3 Jan 2024 22:02:50 +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 4T53cV1cF1z4YdC; Wed, 3 Jan 2024 22:02:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704319370; 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=WoTlYICpXW2wFCntt+HoZ7UdWnq+ObleRw4ZCvNyDiM=; b=Pi96il5ujiVOOR0Tdbf+xfOwu2c9X3C2CxwAmQOlCSlvQuRwouOoyKQBTeNOiZkYpVOh8P wLriX4eMFngRyO1+RINamEx8daMa8lXb38yNuXAStJauf9gYDIRfz10xxFRgv535VztY4x zKRvbTZmEGxy170C2vucS8TCIJB9NBdAwt/jmyRrIcttT0KmDh7KInJjKNIZ4KQtDGErD4 11+FI5NL6bQsyS1PuwmsHnYNYrvzrqPicNYyQY+Bzzd1JrrjKp4YvMux5lmsclVodoOrmz SzKcgIi97OqroGRVW+5C2YNOBOiOP00i4tf3gQ1yyTJot9lQVKEP6gyTzWQjbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1704319370; 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=WoTlYICpXW2wFCntt+HoZ7UdWnq+ObleRw4ZCvNyDiM=; b=yzuTFwQzi9x+gAQpRqBaWlU4vSUCDSC4Txy/y8j1XXq8XOZlwAA8xkVvQwAWsxSWVz7U27 nhHtUjSSaXMba34/D3xPyhSCxqDuMPUilv29Iq5h7/vICH7ZBYghg9ElpVEyDhWTVntHM7 KoFfuUikeh5NCwfni/MUKrKe1ljCS19d7u55wdk7Sr8aHKYXTluuW1iwfPv86fZvT1c48s c5kQ1eeWNCmyP8XPvmEk3lREdBxuJhh62NsOwLPNFwn/HeqYpF2MStZH11+aXVdGyQQFak 79QPvGVQqa/qJholr96nZ+glD5mvS+iWvR3/+oQQGUON/67IpcL74wH2RKh4+A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1704319370; a=rsa-sha256; cv=none; b=KpINmo1gDbw//KcVE/WVpThBR7iQg19USJ9gWA4hHONEe3MVSbbWDRlowxMGdTpob5LlH5 BmJ5PjVOOmV5EJVcEn1fWx7U7xBq9fhayUcxwXzv8o2yD0wgKWpEvoBki+GIBUWG7jCPiM FjrunrgCH8HBBvc4xEWVHWJgtAz7qqN/zo2NdHa2s6eJvkMmYcr4OkBo0dRCEFZic3GlOq uvCSP9eJIIJb+WwIzMm6W8wuKm7WIAfFiJjjH/ZhXiX9CqGiqFiDp3tJb21fKxjNg8++rQ taGl6q9Wd+Pya5S/lBKZEauXqXYXQR5D7Bus+lhnnbVm1bFvDya00+YiuBe7tA== 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 4T53cV0jGdz12qn; Wed, 3 Jan 2024 22:02:50 +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 403M2ovq072811; Wed, 3 Jan 2024 22:02:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 403M2of1072808; Wed, 3 Jan 2024 22:02:50 GMT (envelope-from git) Date: Wed, 3 Jan 2024 22:02:50 GMT Message-Id: <202401032202.403M2of1072808@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: c24913c90417 - stable/14 - riscv nexus: Use bus_generic_rman_*_resource 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: 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: c24913c904174374a378ed9c0825f1a38736a379 Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=c24913c904174374a378ed9c0825f1a38736a379 commit c24913c904174374a378ed9c0825f1a38736a379 Author: John Baldwin AuthorDate: 2023-11-24 17:28:28 +0000 Commit: John Baldwin CommitDate: 2024-01-03 20:48:42 +0000 riscv nexus: Use bus_generic_rman_*_resource Custom activate/deactivate_resource methods are still needed to handle IRQ resources. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D42742 (cherry picked from commit f8709c826be977471df5663833f291f43d93d54c) --- sys/riscv/riscv/nexus.c | 158 ++++++++++++++++-------------------------------- 1 file changed, 51 insertions(+), 107 deletions(-) diff --git a/sys/riscv/riscv/nexus.c b/sys/riscv/riscv/nexus.c index d92ad7861ae9..f710e6826c21 100644 --- a/sys/riscv/riscv/nexus.c +++ b/sys/riscv/riscv/nexus.c @@ -81,12 +81,11 @@ static bus_add_child_t nexus_add_child; static bus_print_child_t nexus_print_child; static bus_activate_resource_t nexus_activate_resource; -static bus_adjust_resource_t nexus_adjust_resource; static bus_alloc_resource_t nexus_alloc_resource; static bus_deactivate_resource_t nexus_deactivate_resource; static bus_get_resource_list_t nexus_get_reslist; +static bus_get_rman_t nexus_get_rman; static bus_map_resource_t nexus_map_resource; -static bus_release_resource_t nexus_release_resource; static bus_unmap_resource_t nexus_unmap_resource; static bus_config_intr_t nexus_config_intr; @@ -110,15 +109,16 @@ static device_method_t nexus_methods[] = { DEVMETHOD(bus_add_child, nexus_add_child), DEVMETHOD(bus_print_child, nexus_print_child), DEVMETHOD(bus_activate_resource, nexus_activate_resource), - DEVMETHOD(bus_adjust_resource, nexus_adjust_resource), + DEVMETHOD(bus_adjust_resource, bus_generic_rman_adjust_resource), DEVMETHOD(bus_alloc_resource, nexus_alloc_resource), DEVMETHOD(bus_deactivate_resource, nexus_deactivate_resource), DEVMETHOD(bus_delete_resource, bus_generic_rl_delete_resource), DEVMETHOD(bus_get_resource, bus_generic_rl_get_resource), DEVMETHOD(bus_get_resource_list, nexus_get_reslist), + DEVMETHOD(bus_get_rman, nexus_get_rman), DEVMETHOD(bus_map_resource, nexus_map_resource), DEVMETHOD(bus_set_resource, bus_generic_rl_set_resource), - DEVMETHOD(bus_release_resource, nexus_release_resource), + DEVMETHOD(bus_release_resource, bus_generic_rman_release_resource), DEVMETHOD(bus_unmap_resource, nexus_unmap_resource), DEVMETHOD(bus_config_intr, nexus_config_intr), DEVMETHOD(bus_describe_intr, nexus_describe_intr), @@ -207,6 +207,21 @@ nexus_add_child(device_t bus, u_int order, const char *name, int unit) return (child); } +static struct rman * +nexus_get_rman(device_t bus, int type, u_int flags) +{ + + switch (type) { + case SYS_RES_IRQ: + return (&irq_rman); + case SYS_RES_MEMORY: + case SYS_RES_IOPORT: + return (&mem_rman); + default: + return (NULL); + } +} + /* * Allocate a resource on behalf of child. NB: child is usually going to be a * child of one of our descendants, not a direct child of nexus0. @@ -216,10 +231,7 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags) { struct nexus_device *ndev = DEVTONX(child); - struct resource *rv; struct resource_list_entry *rle; - struct rman *rm; - int needactivate = flags & RF_ACTIVE; /* * If this is an allocation of the "default" range for a given @@ -238,70 +250,8 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid, count = rle->count; } - switch (type) { - case SYS_RES_IRQ: - rm = &irq_rman; - break; - - case SYS_RES_MEMORY: - case SYS_RES_IOPORT: - rm = &mem_rman; - break; - - default: - return (NULL); - } - - rv = rman_reserve_resource(rm, start, end, count, flags, child); - if (rv == NULL) - return (NULL); - - rman_set_rid(rv, *rid); - rman_set_bushandle(rv, rman_get_start(rv)); - - if (needactivate) { - if (bus_activate_resource(child, type, *rid, rv)) { - rman_release_resource(rv); - return (NULL); - } - } - - return (rv); -} - -static int -nexus_adjust_resource(device_t bus __unused, device_t child __unused, int type, - struct resource *r, rman_res_t start, rman_res_t end) -{ - struct rman *rm; - - switch (type) { - case SYS_RES_IRQ: - rm = &irq_rman; - break; - case SYS_RES_MEMORY: - rm = &mem_rman; - break; - default: - return (EINVAL); - } - if (rman_is_region_manager(r, rm) == 0) - return (EINVAL); - return (rman_adjust_resource(r, start, end)); -} - -static int -nexus_release_resource(device_t bus, device_t child, int type, int rid, - struct resource *res) -{ - int error; - - if (rman_get_flags(res) & RF_ACTIVE) { - error = bus_deactivate_resource(child, type, rid, res); - if (error != 0) - return (error); - } - return (rman_release_resource(res)); + return (bus_generic_rman_alloc_resource(bus, child, type, rid, + start, end, count, flags)); } static int @@ -357,37 +307,29 @@ static int nexus_activate_resource(device_t bus, device_t child, int type, int rid, struct resource *r) { - struct resource_map map; - int err; - - if ((err = rman_activate_resource(r)) != 0) - return (err); + int error; - /* - * If this is a memory resource, map it into the kernel. - */ switch (type) { case SYS_RES_IOPORT: case SYS_RES_MEMORY: - if ((rman_get_flags(r) & RF_UNMAPPED) == 0) { - err = nexus_map_resource(bus, child, type, r, NULL, - &map); - if (err != 0) { - rman_deactivate_resource(r); - return (err); - } - - rman_set_mapping(r, &map); - } + error = bus_generic_rman_activate_resource(bus, child, type, + rid, r); break; case SYS_RES_IRQ: - err = intr_activate_irq(child, r); - if (err != 0) { + error = rman_activate_resource(r); + if (error != 0) + return (error); + error = intr_activate_irq(child, r); + if (error != 0) { rman_deactivate_resource(r); - return (err); + return (error); } + break; + default: + error = EINVAL; + break; } - return (0); + return (error); } static struct resource_list * @@ -402,23 +344,25 @@ static int nexus_deactivate_resource(device_t bus, device_t child, int type, int rid, struct resource *r) { - bus_size_t psize; - bus_space_handle_t vaddr; - - if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) { - psize = (bus_size_t)rman_get_size(r); - vaddr = rman_get_bushandle(r); + int error; - if (vaddr != 0) { - bus_space_unmap(&memmap_bus, vaddr, psize); - rman_set_virtual(r, NULL); - rman_set_bushandle(r, 0); - } - } else if (type == SYS_RES_IRQ) { + switch (type) { + case SYS_RES_IOPORT: + case SYS_RES_MEMORY: + error = bus_generic_rman_deactivate_resource(bus, child, type, + rid, r); + break; + case SYS_RES_IRQ: + error = rman_deactivate_resource(r); + if (error != 0) + return (error); intr_deactivate_irq(child, r); + break; + default: + error = EINVAL; + break; } - - return (rman_deactivate_resource(r)); + return (error); } static int