From nobody Tue Jan 23 17:45:59 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 4TKDyw0BYnz57mxY; Tue, 23 Jan 2024 17:46:00 +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 4TKDyv5hlVz475c; Tue, 23 Jan 2024 17:45:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706031959; 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=8jvQmGHgn33IQfoP7U3nyzVFtrfi+9xbSg4xC5EVo5I=; b=LfGMaEoTESAFDKalV4s2IrQ1sjSO4sVWANjFv5vkfYwjGnwHssiPmtToRBAFdbTJUn4PEJ dkTcYni/0om1+kUhVPlonsbz1yGiKkU651aIyPRlQR5haIJ584/WIyCquPJU91iVANSUlp RSSi/junBhvbLFBX1+58xIgvvjSlln/50YuyFCwpTlA0SXqZrLvmu2jcmy3fUgJMkQtXwL ps/Or5+uCfAKktIi5ex+uvAeZqlv6fUXU3VgckV6lx51v0eA7SUwGppI5HjUMtbMDN2QOX PeJThxC9ZwdM8yo7t2lhAW37VTW+VOYLE5WwZSdA0frv4CWMjLY3zR8bRCxKAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706031959; 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=8jvQmGHgn33IQfoP7U3nyzVFtrfi+9xbSg4xC5EVo5I=; b=mL6IiSf8emjaAkh+G/VNocqH2jJ8JgnTDc4GDZpd1Qt6jKTErAdaxGWWtSrnPVbbksGOfO GwUINEkAXiqYZFHbIhvMJgjDmAp7IUcHjReDY7m61Co3Be5SrTwU0amcpwC59xk8v6kKGG IYCMR2RRu9AZtkURegPZ/nlJr9YktU+8L1yfBFDgFzoy5f6I2hduVSpr4UWYWBa/CdDtM0 g9HSYlBjjHU5HQOPeA8INqHhBYpy0AGt4XIc0ygCqj7kCJ2ML0OjGcBypFfIBpO6YzVJ/b CxY236lHW4yh6rXhv6kZbyFeuV4YorTQgV/krOJHLU5O5HsV4SjuGZAqViT9kw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706031959; a=rsa-sha256; cv=none; b=KvzAT+Cz5rjsGk1zBJabrefRzdyPsEKk6tS7sPph42LzoPwWbm/4PNdo5io7ct6Uwz7gLV 9VKfiV9UvnGz/q0U/xc7fEpES8JcZfMHmFw6eTgTgzmui8Bt5c4ZVM/JqlydKd8OWQugOX EjTSGsQ7yKvfBD+gCAJch0Oj2Vl3h0RSxHGZtrTbCbMOb5GNkIOR2wPkT/uhmHgvWMbOKj hELLKHVCfzEk3+Ci1HyzlpnWJwYb1Jd4U5/N+TY97zCcRznD208q1eKR4/b9PzoDzJYm4b I3m06VdE6ayM77JyxZ8NufMED91l61KCuo+bdJX+4TcoBksg2hRavRimO5vWOA== 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 4TKDyv4ph6zgNP; Tue, 23 Jan 2024 17:45:59 +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 40NHjx5C075958; Tue, 23 Jan 2024 17:45:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40NHjx87075955; Tue, 23 Jan 2024 17:45:59 GMT (envelope-from git) Date: Tue, 23 Jan 2024 17:45:59 GMT Message-Id: <202401231745.40NHjx87075955@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: faeb273e7a8e - main - arm nexus: Use bus_generic_rman_* 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: 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: faeb273e7a8ec57d87de8d4337598fb11ae305c3 Auto-Submitted: auto-generated The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=faeb273e7a8ec57d87de8d4337598fb11ae305c3 commit faeb273e7a8ec57d87de8d4337598fb11ae305c3 Author: John Baldwin AuthorDate: 2024-01-23 17:37:13 +0000 Commit: John Baldwin CommitDate: 2024-01-23 17:37:13 +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 --- 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 196e879fb0db..eb0d1a5b7ded 100644 --- a/sys/arm/arm/nexus.c +++ b/sys/arm/arm/nexus.c @@ -83,10 +83,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; @@ -119,10 +119,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 @@ -216,83 +219,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 @@ -371,73 +309,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