git: c75d7f769541 - stable/13 - riscv: nexus code tidy-up

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Mon, 17 Apr 2023 17:04:04 UTC
The branch stable/13 has been updated by mhorne:

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

commit c75d7f769541a06a57f84780149a3d599f0ac802
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2023-02-06 15:53:09 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2023-04-17 16:57:35 +0000

    riscv: nexus code tidy-up
    
    Make a pass at the various nexus implementations, fixing some very minor
    style issues, obsolete comments, etc.
    
    The method declaration section has become unwieldy in many respects.
    Attempt to tame it by:
     - Using generated method typedefs
     - Grouping methods roughly by category, and then alphabetically.
    
    Reviewed by:    jhb
    Differential Revision:  https://reviews.freebsd.org/D38495
    
    (cherry picked from commit abe3309e71b94527e937f034dd81ca7d6afdeb67)
---
 sys/riscv/riscv/nexus.c | 89 ++++++++++++++++++++++---------------------------
 1 file changed, 40 insertions(+), 49 deletions(-)

diff --git a/sys/riscv/riscv/nexus.c b/sys/riscv/riscv/nexus.c
index 0333c851af2c..38c11b13aff6 100644
--- a/sys/riscv/riscv/nexus.c
+++ b/sys/riscv/riscv/nexus.c
@@ -76,36 +76,28 @@ struct nexus_device {
 static struct rman mem_rman;
 static struct rman irq_rman;
 
-static device_probe_t nexus_fdt_probe;
-static int nexus_attach(device_t);
-
-static	int nexus_print_child(device_t, device_t);
-static	device_t nexus_add_child(device_t, u_int, const char *, int);
-static	struct resource *nexus_alloc_resource(device_t, device_t, int, int *,
-    rman_res_t, rman_res_t, rman_res_t, u_int);
-static	int nexus_activate_resource(device_t, device_t, int, int,
-    struct resource *);
-static	int nexus_adjust_resource(device_t, device_t, int, struct resource *,
-    rman_res_t, rman_res_t);
-static	int nexus_map_resource(device_t, device_t, int, struct resource *,
-    struct resource_map_request *, struct resource_map *);
-static int nexus_config_intr(device_t dev, int irq, enum intr_trigger trig,
-    enum intr_polarity pol);
-static struct resource_list *nexus_get_reslist(device_t, device_t);
-static	int nexus_set_resource(device_t, device_t, int, int,
-    rman_res_t, rman_res_t);
-static	int nexus_deactivate_resource(device_t, device_t, int, int,
-    struct resource *);
-static	int nexus_release_resource(device_t, device_t, int, int,
-    struct resource *);
-
-static int nexus_setup_intr(device_t dev, device_t child, struct resource *res,
-    int flags, driver_filter_t *filt, driver_intr_t *intr, void *arg, void **cookiep);
-static int nexus_teardown_intr(device_t, device_t, struct resource *, void *);
-static bus_space_tag_t nexus_get_bus_tag(device_t, device_t);
-
-static int nexus_ofw_map_intr(device_t dev, device_t child, phandle_t iparent,
-    int icells, pcell_t *intr);
+static device_probe_t		nexus_fdt_probe;
+static device_attach_t		nexus_attach;
+
+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_map_resource_t	nexus_map_resource;
+static bus_set_resource_t	nexus_set_resource;
+static bus_release_resource_t	nexus_release_resource;
+
+static bus_config_intr_t	nexus_config_intr;
+static bus_setup_intr_t		nexus_setup_intr;
+static bus_teardown_intr_t	nexus_teardown_intr;
+
+static bus_get_bus_tag_t	nexus_get_bus_tag;
+
+static ofw_bus_map_intr_t	nexus_ofw_map_intr;
 
 static device_method_t nexus_methods[] = {
 	/* Device interface */
@@ -116,21 +108,22 @@ static device_method_t nexus_methods[] = {
 	DEVMETHOD(ofw_bus_map_intr,	nexus_ofw_map_intr),
 
 	/* Bus interface */
-	DEVMETHOD(bus_print_child,	nexus_print_child),
 	DEVMETHOD(bus_add_child,	nexus_add_child),
-	DEVMETHOD(bus_alloc_resource,	nexus_alloc_resource),
-	DEVMETHOD(bus_activate_resource,	nexus_activate_resource),
+	DEVMETHOD(bus_print_child,	nexus_print_child),
+	DEVMETHOD(bus_activate_resource, nexus_activate_resource),
 	DEVMETHOD(bus_adjust_resource,	nexus_adjust_resource),
-	DEVMETHOD(bus_map_resource,	nexus_map_resource),
-	DEVMETHOD(bus_config_intr,	nexus_config_intr),
+	DEVMETHOD(bus_alloc_resource,	nexus_alloc_resource),
+	DEVMETHOD(bus_deactivate_resource, nexus_deactivate_resource),
 	DEVMETHOD(bus_get_resource_list, nexus_get_reslist),
+	DEVMETHOD(bus_map_resource,	nexus_map_resource),
 	DEVMETHOD(bus_set_resource,	nexus_set_resource),
-	DEVMETHOD(bus_deactivate_resource,	nexus_deactivate_resource),
 	DEVMETHOD(bus_release_resource,	nexus_release_resource),
+	DEVMETHOD(bus_config_intr,	nexus_config_intr),
 	DEVMETHOD(bus_setup_intr,	nexus_setup_intr),
 	DEVMETHOD(bus_teardown_intr,	nexus_teardown_intr),
 	DEVMETHOD(bus_get_bus_tag,	nexus_get_bus_tag),
-	{ 0, 0 }
+
+	DEVMETHOD_END
 };
 
 static driver_t nexus_fdt_driver = {
@@ -139,6 +132,11 @@ static driver_t nexus_fdt_driver = {
 	1			/* no softc */
 };
 
+static devclass_t nexus_fdt_devclass;
+
+EARLY_DRIVER_MODULE(nexus_fdt, root, nexus_fdt_driver, nexus_fdt_devclass,
+    0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_FIRST);
+
 static int
 nexus_fdt_probe(device_t dev)
 {
@@ -203,7 +201,6 @@ nexus_add_child(device_t bus, u_int order, const char *name, int unit)
 
 	child = device_add_child_ordered(bus, order, name, unit);
 
-	/* should we free this in nexus_child_detached? */
 	device_set_ivars(child, ndev);
 
 	return (child);
@@ -212,7 +209,6 @@ nexus_add_child(device_t bus, u_int order, const char *name, int unit)
 /*
  * 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.
- * (Exceptions include footbridge.)
  */
 static struct resource *
 nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
@@ -232,10 +228,10 @@ nexus_alloc_resource(device_t bus, device_t child, int type, int *rid,
 	 */
 	if (RMAN_IS_DEFAULT_RANGE(start, end) && (count == 1)) {
 		if (device_get_parent(child) != bus || ndev == NULL)
-			return(NULL);
+			return (NULL);
 		rle = resource_list_find(&ndev->nx_resources, type, *rid);
 		if (rle == NULL)
-			return(NULL);
+			return (NULL);
 		start = rle->start;
 		end = rle->end;
 		count = rle->count;
@@ -301,7 +297,7 @@ nexus_release_resource(device_t bus, device_t child, int type, int rid,
 
 	if (rman_get_flags(res) & RF_ACTIVE) {
 		error = bus_deactivate_resource(child, type, rid, res);
-		if (error)
+		if (error != 0)
 			return (error);
 	}
 	return (rman_release_resource(res));
@@ -326,7 +322,7 @@ nexus_setup_intr(device_t dev, device_t child, struct resource *res, int flags,
 
 	/* We depend here on rman_activate_resource() being idempotent. */
 	error = rman_activate_resource(res);
-	if (error)
+	if (error != 0)
 		return (error);
 
 	error = intr_setup_irq(child, res, filt, intr, arg, flags, cookiep);
@@ -403,7 +399,7 @@ nexus_set_resource(device_t dev, device_t child, int type, int rid,
 	/* XXX this should return a success/failure indicator */
 	resource_list_add(rl, type, rid, start, start + count - 1, count);
 
-	return(0);
+	return (0);
 }
 
 static int
@@ -474,11 +470,6 @@ nexus_map_resource(device_t bus, device_t child, int type, struct resource *r,
 	return (0);
 }
 
-static devclass_t nexus_fdt_devclass;
-
-EARLY_DRIVER_MODULE(nexus_fdt, root, nexus_fdt_driver, nexus_fdt_devclass,
-    0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_FIRST);
-
 static int
 nexus_ofw_map_intr(device_t dev, device_t child, phandle_t iparent, int icells,
     pcell_t *intr)