From nobody Thu Feb 27 14:16:40 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 4Z3YLJ3JWVz5qFXt; Thu, 27 Feb 2025 14:16:40 +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 4Z3YLJ1ZN0z3x9N; Thu, 27 Feb 2025 14:16:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1740665800; 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=B0MCZGAK/fh3evAkGMx01yoZdj4k7PUaMez+BetqgDI=; b=Ye0YGc2UB8S+/ETbzcuOuZJRoz+OTi1YQ5ums3mXaruGvlC3LLjTnOVzSbK5qF32AsDv51 weEL2RsP0DOjQeTuPTWDn4luEOf3DvCJj8drEs/ncurHRircDMnQpB1LnMe+7VBAP99AN3 3jzDMuEHSqiOzl2i2YjOXftTTnVDpdLCN2EIY2+XVIZhYsSqjDAD07mz0ogWXvi4KlpPoi +rkC1WivXQhdnDUXxN6kC0MOzro5IuESrLYQ7QtNHQangERZkDArkWcCIzq5H5+lFRjSZf sf8CJ79w+zYlsk/McZys71Vd0u5PSpWSTaJtGQx/5fGj+ekvC4Fv8DeaMO3Z9A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1740665800; a=rsa-sha256; cv=none; b=Lz49TV1timyg2PNSQT/WCc+F+C1fkPaVGyAeIR2/QnsZG/nEICQWzsmb41pk/iLh1W11Lw HvvgaO//Ft8qJM3QMklWz6CQ3lEJXNjF0Bft84x+mvfEAPqLqoNM+I6pkqqh5UgE6EB9oG Qrqv3TEijCJYK84MwvJdDYyGbNnnN1MWSIcZ92hezeVgbVcGp94ZKbCk3nOfjDv9IWFqHI esRGjfcZbC4UJBTTtoUdWxIGfr2qqhkC3tZBc3iq7p9hrjOkBrJyt/1mc6yx3YpBHmG1jN aYRQVnMsdxGnFbn3qdppmopiziB4Oba833ydvsvtONqNQ01vkskXIX4SMr4Pwg== 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=1740665800; 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=B0MCZGAK/fh3evAkGMx01yoZdj4k7PUaMez+BetqgDI=; b=hLitzjRYajV6RLCK4k3H5EtqbtJo9nCpUGYTq5KW63LRhEYsUoAi3Os53kxikYRSV2zSaL SJcghtCeHie1CRAyFjAZOGTUMgPsWkopq6OhXKLKFcdzU7k0fSopd8T1NGkcfJVvvPOkkV 1jOyt9ywtfhyxq6NoFKFMbYp9/pPgHvU3rjPZkJm46Mzb+NuGu/ByNKA6JRPMzMgv/12iU UTbjoiA0bXXdZ0j9YgUK4bST6ro49Pq4v7J0XBZUTUOgf/0DfULPXEb/xv1Yr4aIN/x20p fGfEySktndGgvg2KzfrPFzX4NL0XZAPjEIvf/oreNphF7zaCIMyuXz5BajFokQ== 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 4Z3YLJ17J9zm7K; Thu, 27 Feb 2025 14:16:40 +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 51REGefC015913; Thu, 27 Feb 2025 14:16:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 51REGe8Q015910; Thu, 27 Feb 2025 14:16:40 GMT (envelope-from git) Date: Thu, 27 Feb 2025 14:16:40 GMT Message-Id: <202502271416.51REGe8Q015910@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: a7febc75da2f - stable/14 - arm nexus: Use bus_generic_rman_* 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: a7febc75da2f84c03d991c9c8c4562438803e5e0 Auto-Submitted: auto-generated The branch stable/14 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=a7febc75da2f84c03d991c9c8c4562438803e5e0 commit a7febc75da2f84c03d991c9c8c4562438803e5e0 Author: John Baldwin AuthorDate: 2024-01-23 17:37:13 +0000 Commit: John Baldwin CommitDate: 2025-02-27 13:09:20 +0000 arm nexus: Use bus_generic_rman_* - Implement bus_get_rman pulling bits from nexus_alloc_resource. - Implement bus_map/unmap_resource pulling bits from nexus_activate/deactivate_resource. - Use bus_generic_rman_* for bus_alloc/adjust/activate/deactivate/release_resource except for custom interrupt activate/deactivate logic still in nexus_activate/deactivate_resource. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D43437 (cherry picked from commit faeb273e7a8ec57d87de8d4337598fb11ae305c3) --- sys/arm/arm/nexus.c | 220 +++++++++++++++++++++++----------------------------- 1 file changed, 97 insertions(+), 123 deletions(-) diff --git a/sys/arm/arm/nexus.c b/sys/arm/arm/nexus.c index 108771db6301..0d37aa07f342 100644 --- a/sys/arm/arm/nexus.c +++ b/sys/arm/arm/nexus.c @@ -84,10 +84,10 @@ 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_release_resource_t nexus_release_resource; +static bus_get_rman_t nexus_get_rman; +static bus_map_resource_t nexus_map_resource; +static bus_unmap_resource_t nexus_unmap_resource; #ifdef SMP static bus_bind_intr_t nexus_bind_intr; @@ -120,10 +120,13 @@ 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_alloc_resource, nexus_alloc_resource), + DEVMETHOD(bus_adjust_resource, bus_generic_rman_adjust_resource), + DEVMETHOD(bus_alloc_resource, bus_generic_rman_alloc_resource), DEVMETHOD(bus_deactivate_resource, nexus_deactivate_resource), - DEVMETHOD(bus_release_resource, nexus_release_resource), + DEVMETHOD(bus_get_rman, nexus_get_rman), + DEVMETHOD(bus_map_resource, nexus_map_resource), + DEVMETHOD(bus_release_resource, bus_generic_rman_release_resource), + DEVMETHOD(bus_unmap_resource, nexus_unmap_resource), #ifdef SMP DEVMETHOD(bus_bind_intr, nexus_bind_intr), #endif @@ -217,83 +220,18 @@ nexus_add_child(device_t bus, u_int order, const char *name, int unit) return (child); } -/* - * 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. - */ -static struct resource * -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) +static struct rman * +nexus_get_rman(device_t bus, int type, u_int flags) { - struct resource *rv; - struct rman *rm; - int needactivate = flags & RF_ACTIVE; - - flags &= ~RF_ACTIVE; - switch (type) { case SYS_RES_IRQ: - rm = &irq_rman; - break; - + return (&irq_rman); case SYS_RES_MEMORY: case SYS_RES_IOPORT: - rm = &mem_rman; - break; - + return (&mem_rman); default: return (NULL); } - - rv = rman_reserve_resource(rm, start, end, count, flags, child); - if (rv == NULL) - return (NULL); - - rman_set_rid(rv, *rid); - - 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) - return (error); - } - return (rman_release_resource(res)); } static bus_space_tag_t @@ -372,73 +310,109 @@ nexus_activate_resource(device_t bus, device_t child, int type, int rid, struct resource *r) { int err; - bus_addr_t paddr; - bus_size_t psize; - bus_space_handle_t vaddr; - - if ((err = rman_activate_resource(r)) != 0) - return (err); - /* - * If this is a memory resource, map it into the kernel. - */ - if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) { - paddr = (bus_addr_t)rman_get_start(r); - psize = (bus_size_t)rman_get_size(r); -#ifdef FDT - err = bus_space_map(fdtbus_bs_tag, paddr, psize, 0, &vaddr); - if (err != 0) { - rman_deactivate_resource(r); + switch (type) { + case SYS_RES_MEMORY: + case SYS_RES_IOPORT: + return (bus_generic_rman_activate_resource(bus, child, type, + rid, r)); + case SYS_RES_IRQ: + err = rman_activate_resource(r); + if (err != 0) return (err); - } - rman_set_bustag(r, fdtbus_bs_tag); -#else - vaddr = (bus_space_handle_t)pmap_mapdev((vm_paddr_t)paddr, - (vm_size_t)psize); - if (vaddr == 0) { - rman_deactivate_resource(r); - return (ENOMEM); - } - rman_set_bustag(r, (void *)1); -#endif - rman_set_virtual(r, (void *)vaddr); - rman_set_bushandle(r, vaddr); - return (0); - } else if (type == SYS_RES_IRQ) { err = intr_activate_irq(child, r); if (err != 0) { rman_deactivate_resource(r); return (err); } + return (0); + default: + return (EINVAL); } - return (0); } static int -nexus_deactivate_resource(device_t bus, device_t child, int type, int rid, - struct resource *r) +nexus_map_resource(device_t bus, device_t child, int type, struct resource *r, + struct resource_map_request *argsp, struct resource_map *map) { - bus_size_t psize; - bus_space_handle_t vaddr; + struct resource_map_request args; + rman_res_t length, start; + int error; + + /* Resources must be active to be mapped. */ + if (!(rman_get_flags(r) & RF_ACTIVE)) + return (ENXIO); + + switch (type) { + case SYS_RES_MEMORY: + case SYS_RES_IOPORT: + break; + default: + return (EINVAL); + } - if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) { - psize = (bus_size_t)rman_get_size(r); - vaddr = rman_get_bushandle(r); + resource_init_map_request(&args); + error = resource_validate_map_request(r, argsp, &args, &start, &length); + if (error) + return (error); - if (vaddr != 0) { #ifdef FDT - bus_space_unmap(fdtbus_bs_tag, vaddr, psize); + error = bus_space_map(fdtbus_bs_tag, start, length, 0, + &map->r_bushandle); + if (error) + return (error); + map->r_bustag = fdtbus_bs_tag; + map->r_vaddr = (void *)map->r_bushandle; #else - pmap_unmapdev((void *)vaddr, (vm_size_t)psize); + map->r_vaddr = pmap_mapdev(start, length); + if (map->r_vaddr == NULL) + return (ENOMEM); + map->r_bustag = (void *)1; + map->r_bushandle = (bus_space_handle_t)map->r_vaddr; #endif - rman_set_virtual(r, NULL); - rman_set_bushandle(r, 0); - } - } else if (type == SYS_RES_IRQ) { - intr_deactivate_irq(child, r); + map->r_size = length; + return (0); +} + +static int +nexus_unmap_resource(device_t bus, device_t child, int type, struct resource *r, + struct resource_map *map) +{ + + switch (type) { + case SYS_RES_MEMORY: + case SYS_RES_IOPORT: +#ifdef FDT + bus_space_unmap(map->r_bustag, map->r_bushandle, map->r_size); +#else + pmap_unmapdev(map->r_vaddr, map->r_size); +#endif + return (0); + default: + return (EINVAL); } +} + +static int +nexus_deactivate_resource(device_t bus, device_t child, int type, int rid, + struct resource *r) +{ + int error; - return (rman_deactivate_resource(r)); + switch (type) { + case SYS_RES_MEMORY: + case SYS_RES_IOPORT: + return (bus_generic_rman_deactivate_resource(bus, child, type, + rid, r)); + case SYS_RES_IRQ: + error = rman_deactivate_resource(r); + if (error) + return (error); + intr_deactivate_irq(child, r); + return (0); + default: + return (EINVAL); + } } #ifdef FDT