Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Jan 2024 22:02:47 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 25d378703a1b - stable/14 - aarch64 nexus: Use bus_generic_rman_*_resource
Message-ID:  <202401032202.403M2l5t072717@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=25d378703a1b5349784e9d77fbbb8b6cf6f430c5

commit 25d378703a1b5349784e9d77fbbb8b6cf6f430c5
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2023-11-24 17:28:19 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2024-01-03 20:48:28 +0000

    aarch64 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/D42741
    
    (cherry picked from commit 658501d25930bcf24839f3308ee1da971145c018)
---
 sys/arm64/arm64/nexus.c | 123 +++++++++++++++---------------------------------
 1 file changed, 37 insertions(+), 86 deletions(-)

diff --git a/sys/arm64/arm64/nexus.c b/sys/arm64/arm64/nexus.c
index 5bd9b15dde2c..f97bf635446e 100644
--- a/sys/arm64/arm64/nexus.c
+++ b/sys/arm64/arm64/nexus.c
@@ -106,12 +106,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;
 
 #ifdef SMP
@@ -133,12 +132,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_adjust_resource,	bus_generic_rman_adjust_resource),
 	DEVMETHOD(bus_alloc_resource,	nexus_alloc_resource),
 	DEVMETHOD(bus_deactivate_resource, nexus_deactivate_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_release_resource,	nexus_release_resource),
+	DEVMETHOD(bus_release_resource,	bus_generic_rman_release_resource),
 	DEVMETHOD(bus_set_resource,	bus_generic_rl_set_resource),
 	DEVMETHOD(bus_unmap_resource,	nexus_unmap_resource),
 #ifdef SMP
@@ -213,6 +213,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.
@@ -222,10 +237,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
@@ -244,70 +256,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)
-			return (error);
-	}
-	return (rman_release_resource(res));
+	return (bus_generic_rman_alloc_resource(bus, child, type, rid, start,
+	    end, count, flags));
 }
 
 static int
@@ -415,8 +365,10 @@ nexus_activate_resource_flags(device_t bus, device_t child, int type, int rid,
 			rman_deactivate_resource(r);
 			return (err);
 		}
+		return (0);
+	default:
+		return (EINVAL);
 	}
-	return (0);
 }
 
 static int
@@ -438,23 +390,22 @@ 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_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);
 	}
-
-	return (rman_deactivate_resource(r));
 }
 
 static int



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202401032202.403M2l5t072717>