ofw: Convert simplebus to device_get_softc_class().

Stop embedding struct simplebus_softc as the first member of subclass
softcs. Use device_get_softc_class() to locate the simplebus portion of
the device softc

MFC after:	2 months
Differential Revision:	https://reviews.freebsd.org/D59837
This commit is contained in:
Michal Meloun committed 2026-09-26 10:30:42 +02:00
1 parent 12c3004129
commit e2d42b0e6c
37 files changed
+139 -289

No files matched your search

+9 -4
View File
@@ -46,7 +46,7 @@
#include <arm/broadcom/bcm2835/bcm2835_vcbus.h>
struct bcm2835_firmware_softc {
struct simplebus_softc sc;
device_t dev;
phandle_t sc_mbox;
};
@@ -81,6 +81,7 @@ bcm2835_firmware_attach(device_t dev)
int rv;
sc = device_get_softc(dev);
sc->dev = dev;
node = ofw_bus_get_node(dev);
rv = OF_getencprop(node, "mboxes", &mbox, sizeof(mbox));
@@ -101,8 +102,12 @@ bcm2835_firmware_attach(device_t dev)
"Firmware revision");
/* The firmwaare doesn't have a ranges property */
sc->sc.flags |= SB_FLAG_NO_RANGES;
return (simplebus_attach(dev));
rv = simplebus_attach_impl(dev, SB_FLAG_NO_RANGES, 0);
if (rv != 0)
return (rv);
bus_attach_children(dev);
return (0);
}
int
@@ -151,7 +156,7 @@ sysctl_bcm2835_firmware_get_revision(SYSCTL_HANDLER_ARGS)
uint32_t rev;
int err;
if (bcm2835_firmware_property(sc->sc.dev,
if (bcm2835_firmware_property(sc->dev,
BCM2835_MBOX_TAG_FIRMWARE_REVISION, &rev, sizeof(rev)) != 0)
return (ENXIO);
+1 -2
View File
@@ -88,7 +88,6 @@ struct client_info {
};
struct host1x_softc {
struct simplebus_softc simplebus_sc; /* must be first */
device_t dev;
struct sx lock;
int attach_done;
@@ -514,7 +513,7 @@ host1x_new_pass(device_t dev)
goto fail;
}
simplebus_init(dev, 0);
simplebus_attach_impl(dev, SB_FLAG_NO_RANGES, 0);
for (node = OF_child(node); node > 0; node = OF_peer(node))
simplebus_add_device(dev, node, 0, NULL, -1, NULL);
+4 -19
View File
@@ -67,7 +67,6 @@ static device_attach_t am335x_pwmss_attach;
static device_detach_t am335x_pwmss_detach;
struct am335x_pwmss_softc {
struct simplebus_softc sc_simplebus;
device_t sc_dev;
struct syscon *syscon;
};
@@ -101,7 +100,7 @@ am335x_pwmss_attach(device_t dev)
struct am335x_pwmss_softc *sc;
uint32_t reg, id;
uint64_t rev_address;
phandle_t node, opp_table;
phandle_t opp_table;
sc = device_get_softc(dev);
sc->sc_dev = dev;
@@ -140,23 +139,9 @@ am335x_pwmss_attach(device_t dev)
reg |= (1 << id);
SYSCON_WRITE_4(sc->syscon, SCM_PWMSS_CTRL, reg);
node = ofw_bus_get_node(dev);
if (node == -1)
return (ENXIO);
simplebus_init(dev, node);
/*
* Allow devices to identify.
*/
bus_identify_children(dev);
/*
* Now walk the OFW tree and attach top-level devices.
*/
for (node = OF_child(node); node > 0; node = OF_peer(node))
simplebus_add_device(dev, node, 0, NULL, -1, NULL);
error = simplebus_attach_impl(dev, SB_FLAG_NO_RANGES, 0);
if (error != 0)
return (error);
bus_attach_children(dev);
return (0);
+3 -14
View File
@@ -55,7 +55,6 @@ static struct ofw_compat_data compat_data[] = {
};
struct ti_omap4_cm_softc {
struct simplebus_softc sc;
device_t dev;
};
@@ -101,19 +100,9 @@ ti_omap4_cm_attach(device_t dev)
sc->dev = dev;
node = ofw_bus_get_node(dev);
simplebus_init(dev, node);
if (simplebus_fill_ranges(node, &sc->sc) < 0) {
device_printf(dev, "could not get ranges\n");
return (ENXIO);
}
bus_identify_children(sc->dev);
for (child = OF_child(node); child > 0; child = OF_peer(child)) {
cdev = simplebus_add_device(dev, child, 0, NULL, -1, NULL);
if (cdev != NULL)
device_probe_and_attach(cdev);
}
rv = simplebus_attach_impl(dev, SB_FLAG_NO_RANGES, node);
if (rv != 0)
return (rv);
bus_attach_children(dev);
return (0);
+6 -7
View File
@@ -63,7 +63,6 @@
#endif
struct ti_prcm_softc {
struct simplebus_softc sc_simplebus;
device_t dev;
struct resource * mem_res;
bus_space_tag_t bst;
@@ -135,6 +134,7 @@ static int
ti_prcm_attach(device_t dev)
{
struct ti_prcm_softc *sc;
struct simplebus__softc *sb_sc;
phandle_t node, child;
int rid;
@@ -144,20 +144,19 @@ ti_prcm_attach(device_t dev)
node = ofw_bus_get_node(sc->dev);
simplebus_init(sc->dev, node);
if (simplebus_fill_ranges(node, &sc->sc_simplebus) < 0) {
if (simplebus_fill_ranges(node, sb_sc) < 0) {
device_printf(sc->dev, "could not get ranges\n");
return (ENXIO);
}
if (sc->sc_simplebus.nranges == 0) {
if (sb_sc->nranges == 0) {
device_printf(sc->dev, "nranges == 0\n");
return (ENXIO);
}
sc->mem_res = bus_alloc_resource(sc->dev, SYS_RES_MEMORY, &rid,
sc->sc_simplebus.ranges[0].host,
(sc->sc_simplebus.ranges[0].host +
sc->sc_simplebus.ranges[0].size - 1),
sc->sc_simplebus.ranges[0].size,
sb_sc->ranges[0].host,
(sb_sc->ranges[0].host + sb_sc->ranges[0].size - 1),
sb_sc->ranges[0].size,
RF_ACTIVE | RF_SHAREABLE);
if (sc->mem_res == NULL) {
+4 -13
View File
@@ -82,7 +82,6 @@ static struct ofw_compat_data compat_data[] = {
};
struct ti_scm_softc {
struct simplebus_softc sc;
device_t dev;
};
@@ -108,24 +107,16 @@ static int
ti_scm_attach(device_t dev)
{
struct ti_scm_softc *sc;
device_t cdev;
phandle_t node, child;
int rv
sc = device_get_softc(dev);
sc->dev = dev;
node = ofw_bus_get_node(dev);
simplebus_init(dev, node);
if (simplebus_fill_ranges(node, &sc->sc) < 0) {
device_printf(dev, "could not get ranges\n");
return (ENXIO);
}
for (child = OF_child(node); child > 0; child = OF_peer(child)) {
cdev = simplebus_add_device(dev, child, 0, NULL, -1, NULL);
if (cdev != NULL)
device_probe_and_attach(cdev);
}
rv = simplebus_attach_impl(dev, 0, node);
if (rv != 0)
return (rv);
bus_attach_children(dev);
return (0);
+4 -7
View File
@@ -60,7 +60,6 @@
MALLOC_DECLARE(M_SYSCON);
struct ti_scm_syscon_softc {
struct simplebus_softc sc_simplebus;
device_t dev;
struct syscon * syscon;
struct resource * res[1];
@@ -160,6 +159,7 @@ ti_scm_syscon_attach(device_t dev)
{
struct ti_scm_syscon_softc *sc;
phandle_t node, child;
int rv;
sc = device_get_softc(dev);
sc->dev = dev;
@@ -183,12 +183,9 @@ ti_scm_syscon_attach(device_t dev)
return (ENXIO);
}
simplebus_init(sc->dev, node);
bus_identify_children(sc->dev);
for (child = OF_child(node); child != 0; child = OF_peer(child)) {
simplebus_add_device(sc->dev, child, 0, NULL, -1, NULL);
}
rv = simplebus_attach_impl(sc->dev, SB_FLAG_NO_RANGES, node);
if (rv != 0)
return (rv);
bus_attach_children(sc->dev);
return (0);
-1
View File
@@ -129,7 +129,6 @@ struct clk_list {
};
struct ti_sysc_softc {
struct simplebus_softc sc;
bool attach_done;
device_t dev;
+3 -2
View File
@@ -90,7 +90,6 @@ struct brcm_mdio_ofw_devinfo {
};
struct brcm_iproc_mdio_softc {
struct simplebus_softc sbus;
device_t dev;
struct resource * reg_base;
uint32_t clock_rate;
@@ -300,12 +299,14 @@ static int
brcm_iproc_mdio_attach(device_t dev)
{
struct brcm_iproc_mdio_softc *sc;
struct simplebus_softc *sb_sc;
phandle_t node, parent;
struct brcm_mdio_ofw_devinfo *di;
int rid;
device_t child;
sc = device_get_softc(dev);
sb_sc = device_get_softc_class(dev, &simplebus_driver);
sc->dev = dev;
/* Allocate memory resources */
@@ -337,7 +338,7 @@ brcm_iproc_mdio_attach(device_t dev)
/* Initialize and populate resource list. */
resource_list_init(&di->di_rl);
ofw_bus_reg_to_rl(dev, node, sc->sbus.acells, sc->sbus.scells,
ofw_bus_reg_to_rl(dev, node, sb_sc->acells, sb_sc->scells,
&di->di_rl);
ofw_bus_intr_to_rl(dev, node, &di->di_rl, NULL);
@@ -45,7 +45,6 @@ MALLOC_DEFINE(M_BRCM_IPROC_NEXUS, "Broadcom IPROC MDIO NEXUS",
"Broadcom IPROC MDIO NEXUS dynamic memory");
struct brcm_mdionexus_softc {
struct simplebus_softc simplebus_sc;
uint32_t mux_id;
};
@@ -198,7 +197,7 @@ brcm_mdionexus_ofw_bus_attach(device_t dev)
parent = ofw_bus_get_node(dev);
simplebus_init(dev, parent);
sc = (struct simplebus_softc *)device_get_softc(dev);
sc = device_get_softc_class(dev, &simplebus_driver);
/* Iterate through all bus subordinates */
for (node = OF_child(parent); node > 0; node = OF_peer(node)) {
-1
View File
@@ -103,7 +103,6 @@ struct rk_pinctrl_conf {
};
struct rk_pinctrl_softc {
struct simplebus_softc simplebus_sc;
device_t dev;
struct syscon *grf;
struct syscon *pmu;
+3 -12
View File
@@ -50,7 +50,6 @@
#define CCU_SIZE 0x400
struct aw_ccu_softc {
struct simplebus_softc sc;
bus_space_tag_t bst;
bus_space_handle_t bsh;
struct mtx mtx;
@@ -187,14 +186,9 @@ static int
aw_ccu_attach(device_t dev)
{
struct aw_ccu_softc *sc;
phandle_t node, child;
device_t cdev;
int error;
sc = device_get_softc(dev);
node = ofw_bus_get_node(dev);
simplebus_init(dev, node);
sc->flags = aw_ccu_search_compatible()->ocd_data;
@@ -213,12 +207,9 @@ aw_ccu_attach(device_t dev)
mtx_init(&sc->mtx, device_get_nameunit(dev), NULL, MTX_DEF);
/* Attach child devices */
for (child = OF_child(node); child > 0; child = OF_peer(child)) {
cdev = simplebus_add_device(dev, child, 0, NULL, -1, NULL);
if (cdev != NULL)
device_probe_and_attach(cdev);
}
error = simplebus_attach_impl(dev, SB_FLAG_NO_RANGES, 0);
if (error != 0)
return (error);
bus_attach_children(dev);
return (0);
+5 -15
View File
@@ -35,10 +35,6 @@
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_bus_subr.h>
struct ofw_clkbus_softc {
struct simplebus_softc simplebus_sc;
};
static int
ofw_clkbus_probe(device_t dev)
{
@@ -57,17 +53,11 @@ ofw_clkbus_probe(device_t dev)
static int
ofw_clkbus_attach(device_t dev)
{
phandle_t node, child;
device_t cdev;
int rv;
node = ofw_bus_get_node(dev);
simplebus_init(dev, node);
for (child = OF_child(node); child > 0; child = OF_peer(child)) {
cdev = simplebus_add_device(dev, child, 0, NULL, -1, NULL);
if (cdev != NULL)
device_probe_and_attach(cdev);
}
rv = simplebus_attach_impl(dev, SB_FLAG_NO_RANGES, 0);
if (rv != 0)
return (rv);
bus_attach_children(dev);
return (0);
@@ -82,7 +72,7 @@ static device_method_t ofw_clkbus_methods[] = {
};
DEFINE_CLASS_1(ofw_clkbus, ofw_clkbus_driver, ofw_clkbus_methods,
sizeof(struct ofw_clkbus_softc), simplebus_driver);
0, simplebus_driver);
EARLY_DRIVER_MODULE(ofw_clkbus, simplebus, ofw_clkbus_driver, 0, 0,
BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);
MODULE_VERSION(ofw_clkbus, 1);
+5 -3
View File
@@ -54,7 +54,6 @@
#define DA9063_IIC_PAGE_CON_REG_PAGE_SHIFT 1
struct da9063_iic_softc {
struct simplebus_softc simplebus_sc;
device_t dev;
struct mtx mtx;
uint8_t page;
@@ -219,9 +218,12 @@ da9063_iic_attach(device_t dev)
DA9063_PAGE_CON_REG_PAGE_MASK) >> DA9063_IIC_PAGE_CON_REG_PAGE_SHIFT;
mtx_init(&sc->mtx, device_get_nameunit(sc->dev), NULL, MTX_DEF);
sc->simplebus_sc.flags |= SB_FLAG_NO_RANGES;
error = simplebus_attach_impl(dev, SB_FLAG_NO_RANGES, 0);
if (error != 0)
return (error);
return (simplebus_attach(dev));
bus_attach_children(dev);
return (0);
}
static int
+19 -15
View File
@@ -161,13 +161,15 @@ int
fman_activate_resource(device_t bus, device_t child, struct resource *res)
{
struct fman_softc *sc;
struct simplebus_softc *sb_sc;
bus_space_tag_t bt;
bus_space_handle_t bh;
int i, rv;
sc = device_get_softc(bus);
sb_sc = device_get_softc_class(bus, &simplebus_driver);
if (rman_get_type(res) != SYS_RES_IRQ) {
for (i = 0; i < sc->sc_base.nranges; i++) {
for (i = 0; i < sb_sc->nranges; i++) {
if (rman_is_region_manager(res, &sc->rman) != 0) {
bt = rman_get_bustag(sc->mem_res);
rv = bus_space_subregion(bt,
@@ -224,6 +226,7 @@ fman_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 fman_softc *sc;
struct simplebus_softc *sb_sc;
struct resource_list *rl;
struct resource_list_entry *rle = NULL;
struct resource *res;
@@ -232,6 +235,7 @@ fman_alloc_resource(device_t bus, device_t child, int type, int rid,
isdefault = RMAN_IS_DEFAULT_RANGE(start, end);
passthrough = (device_get_parent(child) != bus);
sc = device_get_softc(bus);
sb_sc = device_get_softc_class(bus, &simplebus_driver);
rl = BUS_GET_RESOURCE_LIST(bus, child);
switch (type) {
case SYS_RES_MEMORY:
@@ -252,9 +256,9 @@ fman_alloc_resource(device_t bus, device_t child, int type, int rid,
res = NULL;
/* Map fman ranges to nexus ranges. */
for (i = 0; i < sc->sc_base.nranges; i++) {
if (start >= sc->sc_base.ranges[i].bus && end <
sc->sc_base.ranges[i].bus + sc->sc_base.ranges[i].size) {
for (i = 0; i < sb_sc->nranges; i++) {
if (start >= sb_sc->ranges[i].bus && end <
sb_sc->ranges[i].bus + sb_sc->ranges[i].size) {
start += rman_get_start(sc->mem_res);
end += rman_get_start(sc->mem_res);
res = rman_reserve_resource(&sc->rman, start,
@@ -366,14 +370,14 @@ fman_fill_soc_params(struct fman_softc *sc)
sc->total_fifo_size = 295 * 1024;
break;
default:
device_printf(sc->sc_base.dev,
device_printf(sc->dev,
"Unsupported FManv3 revision: %d\n",
sc->sc_revision_minor);
break;
}
break;
default:
device_printf(sc->sc_base.dev,
device_printf(sc->dev,
"Unsupported FMan version: %d\n", sc->sc_revision_major);
break;
}
@@ -403,12 +407,12 @@ fman_reset(struct fman_softc *sc)
#define DEVDISR2_FMAN1 0xfcc00000
#define DEVDISR2_FMAN2 0x000fcc00
node = ofw_bus_get_node(device_get_parent(sc->sc_base.dev));
node = ofw_bus_get_node(device_get_parent(sc->dev));
node = fdt_find_compatible(node, "fsl,qoriq-device-config-2.0",
false);
if (node == 0) {
device_printf(sc->sc_base.dev,
device_printf(sc->dev,
"missing device-config node in FDT. Cannot reset FMAN");
return (0);
}
@@ -487,7 +491,7 @@ fman_dma_init(struct fman_softc *sc)
sc->dma_cam_num_entries * DMA_CAM_SIZE, DMA_CAM_ALIGN, 0, 0,
VMEM_ADDR_MIN, VMEM_ADDR_MAX, M_BESTFIT | M_WAITOK, &addr);
if (err != 0)
device_printf(sc->sc_base.dev,
device_printf(sc->dev,
"failed to allocate DMA buffer\n");
reg = addr;
bus_write_4(sc->mem_res, FMDM_EBCR, reg);
@@ -593,7 +597,7 @@ fman_init(struct fman_softc *sc)
sc->sc_revision_minor = fman_get_revision_minor(sc);
if (bootverbose)
device_printf(sc->sc_base.dev, "Hardware version: %d.%d.\n",
device_printf(sc->dev, "Hardware version: %d.%d.\n",
sc->sc_revision_major, sc->sc_revision_minor);
fman_fill_soc_params(sc);
@@ -649,7 +653,7 @@ fman_init_muram(struct fman_softc *sc)
u_long base, size;
phandle_t node;
node = ofw_bus_get_node(sc->sc_base.dev);
node = ofw_bus_get_node(sc->dev);
for (node = OF_child(node); node != 0; node = OF_peer(node)) {
char compat[255];
@@ -659,11 +663,11 @@ fman_init_muram(struct fman_softc *sc)
break;
}
if (node == 0) {
device_printf(sc->sc_base.dev, "no muram node\n");
device_printf(sc->dev, "no muram node\n");
return (ENXIO);
}
if (fdt_regsize(node, &base, &size) != 0) {
device_printf(sc->sc_base.dev, "failed to get muram reg\n");
device_printf(sc->dev, "failed to get muram reg\n");
return (ENXIO);
}
sc->muram_vmem = vmem_create("MURAM",
@@ -681,7 +685,7 @@ fman_attach(device_t dev)
phandle_t node;
sc = device_get_softc(dev);
sc->sc_base.dev = dev;
sc->dev = dev;
cell = 0;
node = ofw_bus_get_node(dev);
@@ -729,7 +733,7 @@ fman_attach(device_t dev)
sc->rman.rm_type = RMAN_ARRAY;
sc->rman.rm_descr = "FMan range";
rman_init_from_resource(&sc->rman, sc->mem_res);
simplebus_attach_impl(sc->sc_base.dev);
simplebus_attach_impl(sc->dev, 0, 0);
if (fman_init_muram(sc) != 0)
goto err;
+1 -1
View File
@@ -63,7 +63,7 @@
* FMan driver instance data.
*/
struct fman_softc {
struct simplebus_softc sc_base;
device_t dev;
struct resource *mem_res;
struct resource *irq_res;
struct resource *err_irq_res;
+2 -4
View File
@@ -87,16 +87,14 @@ fman_fdt_probe(device_t dev)
uint32_t
fman_get_clock(struct fman_softc *sc)
{
device_t dev;
phandle_t node;
pcell_t fman_clock;
dev = sc->sc_base.dev;
node = ofw_bus_get_node(dev);
node = ofw_bus_get_node(sc->dev);
if ((OF_getprop(node, "clock-frequency", &fman_clock,
sizeof(fman_clock)) <= 0) || (fman_clock == 0)) {
device_printf(dev,
device_printf(sc->dev,
"could not acquire correct frequency from DTS\n");
return (0);
+3 -3
View File
@@ -145,12 +145,12 @@ kg_ar_write(struct fman_softc *sc, uint32_t ar)
DELAY(1);
}
if ((ar & FMKG_AR_GO) != 0) {
device_printf(sc->sc_base.dev,
device_printf(sc->dev,
"fman_kg: AR stuck busy (0x%08x)\n", ar);
return (ETIMEDOUT);
}
if ((ar & FMKG_AR_ERR) != 0) {
device_printf(sc->sc_base.dev,
device_printf(sc->dev,
"fman_kg: AR reported error (0x%08x)\n", ar);
return (EIO);
}
@@ -212,7 +212,7 @@ kg_program_scheme(struct fman_softc *sc, uint8_t scheme_id,
error = kg_ar_write(sc, FMKG_AR_GO |
(scheme_id << FMKG_AR_NUM_SHIFT) | FMKG_AR_SCM_WSEL_UPDCNT);
if (error != 0)
device_printf(sc->sc_base.dev,
device_printf(sc->dev,
"fman_kg: scheme %u program failed\n", scheme_id);
return (error);
}
+2 -2
View File
@@ -396,7 +396,7 @@ static device_method_t dpaa2_mc_fdt_methods[] = {
DEVMETHOD_END
};
DEFINE_CLASS_1(dpaa2_mc, dpaa2_mc_fdt_driver, dpaa2_mc_fdt_methods,
sizeof(struct dpaa2_mc_softc), dpaa2_mc_driver);
DEFINE_CLASS_2(dpaa2_mc, dpaa2_mc_fdt_driver, dpaa2_mc_fdt_methods,
sizeof(struct dpaa2_mc_softc), dpaa2_mc_driver, simplebus_driver);
DRIVER_MODULE(dpaa2_mc, simplebus, dpaa2_mc_fdt_driver, 0, 0);
+2 -7
View File
@@ -160,12 +160,7 @@ MODULE_DEPEND(memacphy_fdt, miibus, 1, 1, 1);
/* -------------------------------------------------------------------------- */
/*
* Order in this softc is important; memac_mdio_fdt_attach() calls
* simplebus_init() which expects sb_sc at the beginning.
*/
struct memac_mdio_softc_fdt {
struct simplebus_softc sb_sc; /* Must stay first. */
struct memac_mdio_softc_common scc;
};
@@ -294,8 +289,8 @@ static device_method_t memac_mdio_fdt_methods[] = {
DEVMETHOD_END
};
DEFINE_CLASS_0(memac_mdio_fdt, memac_mdio_fdt_driver, memac_mdio_fdt_methods,
sizeof(struct memac_mdio_softc_fdt));
DEFINE_CLASS_1(memac_mdio_fdt, memac_mdio_fdt_driver, memac_mdio_fdt_methods,
sizeof(struct memac_mdio_softc_fdt), simplebus_driver);
EARLY_DRIVER_MODULE(memac_mdio_fdt, simplebus, memac_mdio_fdt_driver, 0, 0,
BUS_PASS_SUPPORTDEV);
+5 -33
View File
@@ -152,7 +152,6 @@ simple_mfd_syscon_unlock(device_t dev)
static int
simple_mfd_probe(device_t dev)
{
if (!ofw_bus_status_okay(dev))
return (ENXIO);
if (!ofw_bus_is_compatible(dev, "simple-mfd"))
@@ -167,43 +166,16 @@ static int
simple_mfd_attach(device_t dev)
{
struct simple_mfd_softc *sc;
phandle_t node, child;
int rid;
int rid, rv;
sc = device_get_softc(dev);
node = ofw_bus_get_node(dev);
sc->dev = dev;
rid = 0;
/* Parse address-cells and size-cells from the parent node as a fallback */
if (OF_getencprop(node, "#address-cells", &sc->sc.acells,
sizeof(sc->sc.acells)) == -1) {
if (OF_getencprop(OF_parent(node), "#address-cells", &sc->sc.acells,
sizeof(sc->sc.acells)) == -1) {
sc->sc.acells = 2;
}
}
if (OF_getencprop(node, "#size-cells", &sc->sc.scells,
sizeof(sc->sc.scells)) == -1) {
if (OF_getencprop(OF_parent(node), "#size-cells", &sc->sc.scells,
sizeof(sc->sc.scells)) == -1) {
sc->sc.scells = 1;
}
}
/* If the node has a ranges prop, parse it so children mapping will be done correctly */
if (OF_hasprop(node, "ranges")) {
if (simplebus_fill_ranges(node, &sc->sc) < 0) {
device_printf(dev, "could not get ranges\n");
return (ENXIO);
}
}
/* Attach child devices */
for (child = OF_child(node); child > 0; child = OF_peer(child)) {
(void)simple_mfd_add_device(dev, child, 0, NULL, -1, NULL);
}
rv = simplebus_attach_impl(dev, SB_FLAG_NO_RANGES, 0);
if (rv != 0)
return (rv);
if (ofw_bus_is_compatible(dev, "syscon")) {
sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
@@ -255,7 +227,7 @@ simple_mfd_setup_dinfo(device_t dev, phandle_t node,
struct simplebus_softc *sc;
struct simplebus_devinfo *ndi;
sc = device_get_softc(dev);
sc = device_get_softc_class(dev, &simplebus_driver);
if (di == NULL)
ndi = malloc(sizeof(*ndi), M_DEVBUF, M_WAITOK | M_ZERO);
else
-1
View File
@@ -30,7 +30,6 @@
#include <dev/fdt/simplebus.h>
struct simple_mfd_softc {
struct simplebus_softc sc;
device_t dev;
struct syscon *syscon;
struct resource *mem_res;
+15 -10
View File
@@ -34,6 +34,8 @@
#include <sys/kernel.h>
#include <sys/rman.h>
#include <machine/bus.h>
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
@@ -178,13 +180,16 @@ simplebus_probe(device_t dev)
}
int
simplebus_attach_impl(device_t dev)
simplebus_attach_impl(device_t dev, int flags, phandle_t node)
{
struct simplebus_softc *sc;
phandle_t node;
sc = device_get_softc(dev);
simplebus_init(dev, 0);
if (node == 0)
node = ofw_bus_get_node(dev);
sc = device_get_softc_class(dev, &simplebus_driver);
sc->flags |=flags;
simplebus_init(dev, node);
if ((sc->flags & SB_FLAG_NO_RANGES) == 0 &&
simplebus_fill_ranges(sc->node, sc) < 0) {
device_printf(dev, "could not get ranges\n");
@@ -207,7 +212,7 @@ simplebus_attach(device_t dev)
{
int rv;
rv = simplebus_attach_impl(dev);
rv = simplebus_attach_impl(dev, 0, 0);
if (rv != 0)
return (rv);
@@ -225,7 +230,7 @@ simplebus_detach(device_t dev)
if (rv != 0)
return (rv);
sc = device_get_softc(dev);
sc = device_get_softc_class(dev, &simplebus_driver);
if (sc->ranges != NULL)
free(sc->ranges, M_DEVBUF);
@@ -236,8 +241,7 @@ void
simplebus_init(device_t dev, phandle_t node)
{
struct simplebus_softc *sc;
sc = device_get_softc(dev);
sc = device_get_softc_class(dev, &simplebus_driver);
if (node == 0)
node = ofw_bus_get_node(dev);
sc->dev = dev;
@@ -250,6 +254,7 @@ simplebus_init(device_t dev, phandle_t node)
OF_getencprop(node, "#address-cells", &sc->acells, sizeof(sc->acells));
sc->scells = 1;
OF_getencprop(node, "#size-cells", &sc->scells, sizeof(sc->scells));
}
int
@@ -308,7 +313,7 @@ simplebus_setup_dinfo(device_t dev, phandle_t node,
struct simplebus_softc *sc;
struct simplebus_devinfo *ndi;
sc = device_get_softc(dev);
sc = device_get_softc_class(dev, &simplebus_driver);
if (di == NULL)
ndi = malloc(sizeof(*ndi), M_DEVBUF, M_WAITOK | M_ZERO);
else
@@ -468,7 +473,7 @@ simplebus_alloc_resource(device_t bus, device_t child, int type, int rid,
struct resource_list_entry *rle;
int j;
sc = device_get_softc(bus);
sc = device_get_softc_class(bus, &simplebus_driver);
/*
* Request for the default allocation with a given rid: use resource
+1 -1
View File
@@ -65,7 +65,7 @@ int simplebus_fill_ranges(phandle_t node,
struct simplebus_softc *sc);
int simplebus_attach(device_t dev);
int simplebus_attach_impl(device_t dev);
int simplebus_attach_impl(device_t dev, int flags, phandle_t node);
int simplebus_detach(device_t dev);
#endif /* _FDT_SIMPLEBUS_H */
-1
View File
@@ -61,7 +61,6 @@ struct scmi_transport_desc {
struct scmi_transport;
struct scmi_softc {
struct simplebus_softc simplebus_sc;
device_t dev;
struct mtx mtx;
struct scmi_transport_desc trs_desc;
@@ -88,7 +88,6 @@ enum {
typedef int (*zynqmp_callfn_t)(register_t, register_t, register_t, uint32_t *payload);
struct zynqmp_firmware_softc {
struct simplebus_softc sc;
device_t dev;
zynqmp_callfn_t callfn;
};
+4 -13
View File
@@ -46,7 +46,6 @@
#include "dwgpio_if.h"
struct dwgpiobus_softc {
struct simplebus_softc simplebus_sc;
device_t dev;
struct resource *res[1];
};
@@ -76,6 +75,7 @@ dwgpiobus_attach(device_t dev)
{
struct dwgpiobus_softc *sc;
phandle_t node;
int rv;
sc = device_get_softc(dev);
sc->dev = dev;
@@ -89,18 +89,9 @@ dwgpiobus_attach(device_t dev)
return (ENXIO);
}
simplebus_init(dev, node);
/*
* Allow devices to identify.
*/
bus_identify_children(dev);
/*
* Now walk the OFW tree and attach top-level devices.
*/
for (node = OF_child(node); node > 0; node = OF_peer(node))
simplebus_add_device(dev, node, 0, NULL, -1, NULL);
rv = simplebus_attach_impl(dev, SB_FLAG_NO_RANGES, node);
if (rv != 0)
return (rv);
bus_attach_children(dev);
return (0);
+13 -12
View File
@@ -43,7 +43,6 @@
#include <dev/ofw/ofw_bus_subr.h>
struct ofw_firmware_softc {
struct simplebus_softc sc;
device_t dev;
};
@@ -54,7 +53,7 @@ ofw_firmware_setup_dinfo(device_t dev, phandle_t node,
struct simplebus_softc *sc;
struct simplebus_devinfo *ndi;
sc = device_get_softc(dev);
sc = device_get_softc_class(dev, &simplebus_driver);
if (di == NULL)
ndi = malloc(sizeof(*ndi), M_DEVBUF, M_WAITOK | M_ZERO);
else
@@ -122,25 +121,27 @@ static int
ofw_firmware_attach(device_t dev)
{
struct ofw_firmware_softc *sc;
struct simplebus_softc *sb_sc;
phandle_t node, child;
device_t cdev;
sc = device_get_softc(dev);
sb_sc = device_get_softc_class(dev, &simplebus_driver);
sc->dev = dev;
node = ofw_bus_get_node(dev);
if (OF_getencprop(node, "#address-cells", &sc->sc.acells,
sizeof(sc->sc.acells)) == -1) {
if (OF_getencprop(OF_parent(node), "#address-cells", &sc->sc.acells,
sizeof(sc->sc.acells)) == -1) {
sc->sc.acells = 2;
if (OF_getencprop(node, "#address-cells", &sb_sc->acells,
sizeof(sb_sc->acells)) == -1) {
if (OF_getencprop(OF_parent(node), "#address-cells",
&sb_sc->acells, sizeof(sb_sc->acells)) == -1) {
sb_sc->acells = 2;
}
}
if (OF_getencprop(node, "#size-cells", &sc->sc.scells,
sizeof(sc->sc.scells)) == -1) {
if (OF_getencprop(OF_parent(node), "#size-cells", &sc->sc.scells,
sizeof(sc->sc.scells)) == -1) {
sc->sc.scells = 1;
if (OF_getencprop(node, "#size-cells", &sb_sc->scells,
sizeof(sb_sc->scells)) == -1) {
if (OF_getencprop(OF_parent(node), "#size-cells",
&sb_sc->scells, sizeof(sb_sc->scells)) == -1) {
sb_sc->scells = 1;
}
}
+1 -2
View File
@@ -73,8 +73,7 @@ static device_method_t ofwbus_methods[] = {
DEVMETHOD_END
};
DEFINE_CLASS_1(ofwbus, ofwbus_driver, ofwbus_methods,
sizeof(struct simplebus_softc), simplebus_driver);
DEFINE_CLASS_1(ofwbus, ofwbus_driver, ofwbus_methods, 0, simplebus_driver);
EARLY_DRIVER_MODULE(ofwbus, nexus, ofwbus_driver, 0, 0,
BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);
MODULE_VERSION(ofwbus, 1);
+2 -12
View File
@@ -56,7 +56,6 @@ static struct ofw_compat_data compat_data[] = {
};
struct qcom_dwc3_softc {
struct simplebus_softc sc;
device_t dev;
clk_t clk_core;
clk_t clk_sleep;
@@ -144,18 +143,9 @@ qcom_dwc3_attach(device_t dev)
* Rest is glue code.
*/
simplebus_init(dev, node);
if (simplebus_fill_ranges(node, &sc->sc) < 0) {
device_printf(dev, "could not get ranges\n");
err = simplebus_attach_impl(dev, 0, node);
if (err != 0)
return (ENXIO);
}
for (child = OF_child(node); child > 0; child = OF_peer(child)) {
cdev = simplebus_add_device(dev, child, 0, NULL, -1, NULL);
if (cdev != NULL)
device_probe_and_attach(cdev);
}
bus_attach_children(dev);
return (0);
}
+5 -13
View File
@@ -35,10 +35,6 @@
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_bus_subr.h>
struct ofw_regulator_bus_softc {
struct simplebus_softc simplebus_sc;
};
static int
ofw_regulator_bus_probe(device_t dev)
{
@@ -55,14 +51,11 @@ ofw_regulator_bus_probe(device_t dev)
static int
ofw_regulator_bus_attach(device_t dev)
{
phandle_t node, child;
int rv;
node = ofw_bus_get_node(dev);
simplebus_init(dev, node);
for (child = OF_child(node); child > 0; child = OF_peer(child)) {
simplebus_add_device(dev, child, 0, NULL, -1, NULL);
}
rv = simplebus_attach_impl(dev, SB_FLAG_NO_RANGES, 0);
if (rv != 0)
return (rv);
bus_attach_children(dev);
return (0);
@@ -77,8 +70,7 @@ static device_method_t ofw_regulator_bus_methods[] = {
};
DEFINE_CLASS_1(ofw_regulator_bus, ofw_regulator_bus_driver,
ofw_regulator_bus_methods, sizeof(struct ofw_regulator_bus_softc),
simplebus_driver);
ofw_regulator_bus_methods, 0, simplebus_driver);
EARLY_DRIVER_MODULE(ofw_regulator_bus, simplebus, ofw_regulator_bus_driver,
0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);
MODULE_VERSION(ofw_regulator_bus, 1);
+4 -13
View File
@@ -51,7 +51,6 @@ static struct resource_spec mmio_sram_spec[] = {
};
struct mmio_sram_softc {
struct simplebus_softc simplebus_sc;
struct resource *res[1];
device_t dev;
};
@@ -76,6 +75,7 @@ mmio_sram_attach(device_t dev)
{
struct mmio_sram_softc *sc;
phandle_t node;
int rv;
sc = device_get_softc(dev);
sc->dev = dev;
@@ -89,18 +89,9 @@ mmio_sram_attach(device_t dev)
if (node == -1)
return (ENXIO);
simplebus_init(dev, node);
/*
* Allow devices to identify.
*/
bus_identify_children(dev);
/*
* Now walk the OFW tree and attach top-level devices.
*/
for (node = OF_child(node); node > 0; node = OF_peer(node))
simplebus_add_device(dev, node, 0, NULL, -1, NULL);
rv = simplebus_attach_impl(dev, SB_FLAG_NO_RANGES, node);
if (rv != 0)
return (rv);
bus_attach_children(dev);
return (0);
+1 -1
View File
@@ -185,7 +185,7 @@ syscon_generic_attach(device_t dev)
return (ENXIO);
}
if (ofw_bus_is_compatible(dev, "simple-bus")) {
rv = simplebus_attach_impl(sc->dev);
rv = simplebus_attach_impl(sc->dev, 0, 0);
if (rv != 0) {
device_printf(dev, "Failed to create simplebus\n");
syscon_generic_detach(dev);
-1
View File
@@ -30,7 +30,6 @@
#include <dev/fdt/simplebus.h>
struct syscon_generic_softc {
struct simplebus_softc simplebus;
device_t dev;
struct syscon *syscon;
struct resource *mem_res;
+4 -14
View File
@@ -55,7 +55,6 @@ static struct ofw_compat_data compat_data[] = {
};
struct aw_dwc3_softc {
struct simplebus_softc sc;
device_t dev;
clk_t clk_bus;
hwreset_t rst_bus;
@@ -85,8 +84,7 @@ static int
aw_dwc3_attach(device_t dev)
{
struct aw_dwc3_softc *sc;
device_t cdev;
phandle_t node, child;
phandle_t node;
int err;
sc = device_get_softc(dev);
@@ -113,17 +111,9 @@ aw_dwc3_attach(device_t dev)
}
}
simplebus_init(dev, node);
if (simplebus_fill_ranges(node, &sc->sc) < 0) {
device_printf(dev, "could not get ranges\n");
return (ENXIO);
}
for (child = OF_child(node); child > 0; child = OF_peer(child)) {
cdev = simplebus_add_device(dev, child, 0, NULL, -1, NULL);
if (cdev != NULL)
device_probe_and_attach(cdev);
}
err = simplebus_attach_impl(dev, 0, node);
if (err != 0)
return (err);
bus_attach_children(dev);
return (0);
+4 -13
View File
@@ -60,7 +60,6 @@ static struct ofw_compat_data compat_data[] = {
};
struct rk_dwc3_softc {
struct simplebus_softc sc;
device_t dev;
clk_t clk_ref;
clk_t clk_suspend;
@@ -96,8 +95,7 @@ static int
rk_dwc3_attach(device_t dev)
{
struct rk_dwc3_softc *sc;
device_t cdev;
phandle_t node, child;
phandle_t node;
int err;
sc = device_get_softc(dev);
@@ -170,17 +168,10 @@ rk_dwc3_attach(device_t dev)
}
}
simplebus_init(dev, node);
if (simplebus_fill_ranges(node, &sc->sc) < 0) {
device_printf(dev, "could not get ranges\n");
return (ENXIO);
}
for (child = OF_child(node); child > 0; child = OF_peer(child)) {
cdev = simplebus_add_device(dev, child, 0, NULL, -1, NULL);
if (cdev != NULL)
device_probe_and_attach(cdev);
}
err = simplebus_attach_impl(dev, 0, 0);
if (err != 0)
return (err);
bus_attach_children(dev);
return (0);
+3 -14
View File
@@ -56,7 +56,6 @@ static struct ofw_compat_data compat_data[] = {
};
struct xlnx_dwc3_softc {
struct simplebus_softc sc;
device_t dev;
hwreset_t rst_crst;
hwreset_t rst_hibrst;
@@ -87,8 +86,7 @@ static int
xlnx_dwc3_attach(device_t dev)
{
struct xlnx_dwc3_softc *sc;
device_t cdev;
phandle_t node, child;
phandle_t node;
sc = device_get_softc(dev);
sc->dev = dev;
@@ -119,17 +117,8 @@ xlnx_dwc3_attach(device_t dev)
}
}
simplebus_init(dev, node);
if (simplebus_fill_ranges(node, &sc->sc) < 0) {
device_printf(dev, "could not get ranges\n");
return (ENXIO);
}
for (child = OF_child(node); child > 0; child = OF_peer(child)) {
cdev = simplebus_add_device(dev, child, 0, NULL, -1, NULL);
if (cdev != NULL)
device_probe_and_attach(cdev);
}
if (simplebus_attach_impl(dev, 0, node) != 0)
device_printf(dev, "Cannot attach simplebus\n");
bus_attach_children(dev);
return (0);