git: d14bc7230ba5 - main - newbus: add bus_topo_assert

From: Warner Losh <imp_at_FreeBSD.org>
Date: Fri, 10 Dec 2021 00:05:12 UTC
The branch main has been updated by imp:

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

commit d14bc7230ba5c26de7d793ae3947e7571dc8fb7c
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2021-12-09 23:52:44 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2021-12-10 00:04:57 +0000

    newbus: add bus_topo_assert
    
    Add bus_topo_assert() and implmement it as GIANT_REQUIRED for the
    moment. This will allow us to change more easily to a newbus-specific
    lock int he future.
    
    Sponsored by:           Netflix
    Reviewed by:            wulf, mav, jhb
    Differential Revision:  https://reviews.freebsd.org/D31833
---
 sys/dev/acpica/acpi.c    |  6 +++---
 sys/dev/bhnd/bhnd.c      |  4 ++--
 sys/dev/bhnd/bhnd_subr.c |  3 +--
 sys/dev/hid/hidbus.c     |  4 ++--
 sys/dev/hid/hmt.c        |  4 ++--
 sys/dev/mii/mii.c        |  2 ++
 sys/kern/subr_bus.c      | 15 +++++++++++----
 sys/sys/bus.h            |  1 +
 8 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/sys/dev/acpica/acpi.c b/sys/dev/acpica/acpi.c
index ce396a835b4f..7066116f19a4 100644
--- a/sys/dev/acpica/acpi.c
+++ b/sys/dev/acpica/acpi.c
@@ -755,7 +755,7 @@ acpi_suspend(device_t dev)
 {
     int error;
 
-    GIANT_REQUIRED;
+    bus_topo_assert();
 
     error = bus_generic_suspend(dev);
     if (error == 0)
@@ -768,7 +768,7 @@ static int
 acpi_resume(device_t dev)
 {
 
-    GIANT_REQUIRED;
+    bus_topo_assert();
 
     acpi_set_power_children(dev, ACPI_STATE_D0);
 
@@ -779,7 +779,7 @@ static int
 acpi_shutdown(device_t dev)
 {
 
-    GIANT_REQUIRED;
+    bus_topo_assert();
 
     /* Allow children to shutdown first. */
     bus_generic_shutdown(dev);
diff --git a/sys/dev/bhnd/bhnd.c b/sys/dev/bhnd/bhnd.c
index 654f42864233..0413970e5665 100644
--- a/sys/dev/bhnd/bhnd.c
+++ b/sys/dev/bhnd/bhnd.c
@@ -374,7 +374,7 @@ bhnd_generic_alloc_pmu(device_t dev, device_t child)
 	u_int				 max_latency;
 	int				 error;
 
-	GIANT_REQUIRED;	/* for newbus */
+	bus_topo_assert();
 
 	if (device_get_parent(child) != dev)
 		return (EINVAL);
@@ -490,7 +490,7 @@ bhnd_generic_release_pmu(device_t dev, device_t child)
 	struct bhnd_resource	*r;
 	device_t		 pmu_dev;
 
-	GIANT_REQUIRED;	/* for newbus */
+	bus_topo_assert();
 
 	sc = device_get_softc(dev);
 
diff --git a/sys/dev/bhnd/bhnd_subr.c b/sys/dev/bhnd/bhnd_subr.c
index 036c3def5817..955e1a197002 100644
--- a/sys/dev/bhnd/bhnd_subr.c
+++ b/sys/dev/bhnd/bhnd_subr.c
@@ -2185,8 +2185,7 @@ bhnd_bus_generic_get_nvram_var(device_t dev, device_t child, const char *name,
 	device_t	nvram;
 	device_t	parent;
 
-        /* Make sure we're holding Giant for newbus */
-	GIANT_REQUIRED;
+	bus_topo_assert();
 
 	/* Look for a directly-attached NVRAM child */
 	if ((nvram = device_find_child(dev, "bhnd_nvram", -1)) != NULL)
diff --git a/sys/dev/hid/hidbus.c b/sys/dev/hid/hidbus.c
index 69f3d3911631..4a3a3e21bf03 100644
--- a/sys/dev/hid/hidbus.c
+++ b/sys/dev/hid/hidbus.c
@@ -544,7 +544,7 @@ hidbus_find_child(device_t bus, int32_t usage)
 	device_t *children, child;
 	int ccount, i;
 
-	GIANT_REQUIRED;
+	bus_topo_assert();
 
 	/* Get a list of all hidbus children */
 	if (device_get_children(bus, &children, &ccount) != 0)
@@ -724,7 +724,7 @@ hid_set_report_descr(device_t dev, const void *data, hid_size_t len)
 	bool is_bus;
 	int error;
 
-	GIANT_REQUIRED;
+	bus_topo_assert();
 
 	is_bus = device_get_devclass(dev) == hidbus_devclass;
 	bus = is_bus ? dev : device_get_parent(dev);
diff --git a/sys/dev/hid/hmt.c b/sys/dev/hid/hmt.c
index dcf360bcffba..42dadfe24256 100644
--- a/sys/dev/hid/hmt.c
+++ b/sys/dev/hid/hmt.c
@@ -869,7 +869,7 @@ hmt_set_input_mode(struct hmt_softc *sc, enum hconf_input_mode mode)
 	device_t hconf;
 	int  err;
 
-	GIANT_REQUIRED;
+	bus_topo_assert();
 
 	/* Find touchpad's configuration TLC */
 	hconf = hidbus_find_child(device_get_parent(sc->dev),
@@ -886,7 +886,7 @@ hmt_set_input_mode(struct hmt_softc *sc, enum hconf_input_mode mode)
 	if (device_get_devclass(hconf) != hconf_devclass)
 		return (ENXIO);
 
-	/* hconf_set_input_mode can drop the Giant while sleeping */
+	/* hconf_set_input_mode can drop the the topo lock while sleeping */
 	device_busy(hconf);
 	err = hconf_set_input_mode(hconf, mode);
 	device_unbusy(hconf);
diff --git a/sys/dev/mii/mii.c b/sys/dev/mii/mii.c
index f5f791171a53..5f782b15a151 100644
--- a/sys/dev/mii/mii.c
+++ b/sys/dev/mii/mii.c
@@ -377,6 +377,8 @@ mii_attach(device_t dev, device_t *miibus, if_t ifp,
 	int bmsr, first, i, nchildren, phymax, phymin, rv;
 	uint32_t phymask;
 
+	bus_topo_assert();
+
 	if (phyloc != MII_PHY_ANY && offloc != MII_OFFSET_ANY) {
 		printf("%s: phyloc and offloc specified\n", __func__);
 		return (EINVAL);
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c
index 2544826e9028..a5d0fc773787 100644
--- a/sys/kern/subr_bus.c
+++ b/sys/kern/subr_bus.c
@@ -867,6 +867,13 @@ static kobj_method_t null_methods[] = {
 
 DEFINE_CLASS(null, null_methods, 0);
 
+void
+bus_topo_assert()
+{
+
+	GIANT_REQUIRED;	
+}
+
 struct mtx *
 bus_topo_mtx(void)
 {
@@ -2102,7 +2109,7 @@ device_probe_child(device_t dev, device_t child)
 	/* We should preserve the devclass (or lack of) set by the bus. */
 	int hasclass = (child->devclass != NULL);
 
-	GIANT_REQUIRED;
+	bus_topo_assert();
 
 	dc = dev->devclass;
 	if (!dc)
@@ -2920,7 +2927,7 @@ device_probe(device_t dev)
 {
 	int error;
 
-	GIANT_REQUIRED;
+	bus_topo_assert();
 
 	if (dev->state >= DS_ALIVE)
 		return (-1);
@@ -2954,7 +2961,7 @@ device_probe_and_attach(device_t dev)
 {
 	int error;
 
-	GIANT_REQUIRED;
+	bus_topo_assert();
 
 	error = device_probe(dev);
 	if (error == -1)
@@ -3052,7 +3059,7 @@ device_detach(device_t dev)
 {
 	int error;
 
-	GIANT_REQUIRED;
+	bus_topo_assert();
 
 	PDEBUG(("%s", DEVICENAME(dev)));
 	if (dev->busy > 0)
diff --git a/sys/sys/bus.h b/sys/sys/bus.h
index f5e31e5a6d00..9996ceeb07f3 100644
--- a/sys/sys/bus.h
+++ b/sys/sys/bus.h
@@ -745,6 +745,7 @@ void	bus_set_pass(int pass);
 void bus_topo_lock(void);
 void bus_topo_unlock(void);
 struct mtx * bus_topo_mtx(void);
+void bus_topo_assert(void);
 
 /**
  * Shorthands for constructing method tables.