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
This commit is contained in:
Warner Losh 2021-12-09 16:52:44 -07:00
parent 815a0973b2
commit d14bc7230b
8 changed files with 24 additions and 15 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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)

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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)

View File

@ -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.