From 20ff1c1a3c65b9dd48e0946ed81b69ad51896eb9 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Mon, 7 Feb 2022 09:04:28 +0000 Subject: [PATCH 01/26] acpi(9): No need to test dv_locators. It is always initialized by config_devalloc before config_devlink makes it visible to device iteration. No need to reach into private autoconf internals. --- sys/dev/acpi/acpi_pci.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/sys/dev/acpi/acpi_pci.c b/sys/dev/acpi/acpi_pci.c index 83a2e152afd8..5fcf91841fcf 100644 --- a/sys/dev/acpi/acpi_pci.c +++ b/sys/dev/acpi/acpi_pci.c @@ -472,9 +472,6 @@ acpi_pcidev_find_dev(struct acpi_devnode *ad) if (pr == NULL || device_is_a(pr, "pci") != true) continue; - if (dv->dv_locators == NULL) /* This should not happen. */ - continue; - pci = device_private(pr); if (pci->sc_bus == ap->ap_bus && From 0527914ab80913e09628204973919f3f7b7e7993 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Mon, 7 Feb 2022 09:07:33 +0000 Subject: [PATCH 02/26] ccd(4): Fix typo in comment. --- sys/dev/ccd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/dev/ccd.c b/sys/dev/ccd.c index 2283bc0346da..089fc23799ee 100644 --- a/sys/dev/ccd.c +++ b/sys/dev/ccd.c @@ -1447,7 +1447,7 @@ ccdioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) disk_detach(&cs->sc_dkdev); bufq_free(cs->sc_bufq); - /* also releases dv_lock */ + /* also releases sc_dvlock */ ccdput(cs); /* Don't break, otherwise cs is read again. */ From a5d7805a2a9e09a9a217a1f138e0191eae60fd74 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Mon, 7 Feb 2022 09:07:57 +0000 Subject: [PATCH 03/26] x86, zaurus: Use device_parent(dev), not dev->dv_parent. Will help to make struct device opaque later. --- sys/arch/x86/x86/x86_autoconf.c | 2 +- sys/arch/zaurus/zaurus/autoconf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/arch/x86/x86/x86_autoconf.c b/sys/arch/x86/x86/x86_autoconf.c index fc548ec352ce..dbfc8ece0cfb 100644 --- a/sys/arch/x86/x86/x86_autoconf.c +++ b/sys/arch/x86/x86/x86_autoconf.c @@ -568,7 +568,7 @@ device_register(device_t dev, void *aux) * only for reading memory module EERPOMs and sensors. */ if (device_is_a(dev, "iic") && - device_is_a(dev->dv_parent, "imcsmb")) { + device_is_a(device_parent(dev), "imcsmb")) { static const char *imcsmb_device_permitlist[] = { "spdmem", "sdtemp", diff --git a/sys/arch/zaurus/zaurus/autoconf.c b/sys/arch/zaurus/zaurus/autoconf.c index fa304b7f5040..948369ba081b 100644 --- a/sys/arch/zaurus/zaurus/autoconf.c +++ b/sys/arch/zaurus/zaurus/autoconf.c @@ -226,7 +226,7 @@ device_register(device_t dev, void *aux) * limited capabilities. */ if (device_is_a(dev, "iic") && - device_is_a(dev->dv_parent, "ziic")) { + device_is_a(device_parent(dev), "ziic")) { (void)prop_dictionary_set_string_nocopy(device_properties(dev), I2C_PROP_INDIRECT_PROBE_STRATEGY, I2C_PROBE_STRATEGY_NONE); } From 0c1e3525d6e250d5540f3881336eced52d2b0b42 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Mon, 7 Feb 2022 09:15:42 +0000 Subject: [PATCH 04/26] sys: Avoid touching struct device::dv_unit directly outside autoconf. Will help to make struct device opaque later. --- sys/arch/arm/imx/imx31_icu.c | 2 +- sys/arch/arm/imx/imx51_tzic.c | 2 +- sys/arch/arm/omap/omapl1x_psc.c | 2 +- sys/arch/arm/omap/omapl1x_timer.c | 2 +- sys/dev/marvell/if_mvxpe.c | 3 ++- sys/dev/marvell/mvxpsec.c | 2 +- sys/dev/spkr.c | 6 ++++-- sys/dev/usb/vhci.c | 2 +- 8 files changed, 12 insertions(+), 9 deletions(-) diff --git a/sys/arch/arm/imx/imx31_icu.c b/sys/arch/arm/imx/imx31_icu.c index 1b55b2361a72..055049fda1c1 100644 --- a/sys/arch/arm/imx/imx31_icu.c +++ b/sys/arch/arm/imx/imx31_icu.c @@ -225,7 +225,7 @@ avic_attach(device_t parent, device_t self, void *aux) int error; KASSERT(ahba->ahba_irqbase != AHBCF_IRQBASE_DEFAULT); - KASSERT(self->dv_unit == 0); + KASSERT(device_unit(self) == 0); if (ahba->ahba_size == AHBCF_SIZE_DEFAULT) ahba->ahba_size = INTC_SIZE; diff --git a/sys/arch/arm/imx/imx51_tzic.c b/sys/arch/arm/imx/imx51_tzic.c index 70db4bbba825..73ccb76b9980 100644 --- a/sys/arch/arm/imx/imx51_tzic.c +++ b/sys/arch/arm/imx/imx51_tzic.c @@ -124,7 +124,7 @@ tzic_attach(device_t parent, device_t self, void *aux) int error; KASSERT(aa->aa_irqbase != AXICF_IRQBASE_DEFAULT); - KASSERT(self->dv_unit == 0); + KASSERT(device_unit(self) == 0); aprint_normal(": TrustZone Interrupt Controller\n"); aprint_naive("\n"); diff --git a/sys/arch/arm/omap/omapl1x_psc.c b/sys/arch/arm/omap/omapl1x_psc.c index de1523d36f13..3c97d96bb129 100644 --- a/sys/arch/arm/omap/omapl1x_psc.c +++ b/sys/arch/arm/omap/omapl1x_psc.c @@ -120,7 +120,7 @@ omapl1xpsc_attach(device_t parent, device_t self, void *aux) sc = device_private(self); sc->sc_iot = tipb->tipb_iot; - sc->sc_unit = self->dv_unit; + sc->sc_unit = device_unit(self); sc->sc_addr = tipb->tipb_addr; sc->sc_size = tipb->tipb_size; diff --git a/sys/arch/arm/omap/omapl1x_timer.c b/sys/arch/arm/omap/omapl1x_timer.c index 31b6192cac36..870e360024d7 100644 --- a/sys/arch/arm/omap/omapl1x_timer.c +++ b/sys/arch/arm/omap/omapl1x_timer.c @@ -436,7 +436,7 @@ omapl1xtimer_attach (device_t parent, device_t self, void *aux) struct omapl1xtmr_softc *sc = device_private(self); struct tipb_attach_args *tipb = aux; - sc->sc_timerno = self->dv_unit; + sc->sc_timerno = device_unit(self); sc->sc_iot = tipb->tipb_iot; sc->sc_intr = tipb->tipb_intr; sc->sc_addr = tipb->tipb_addr; diff --git a/sys/dev/marvell/if_mvxpe.c b/sys/dev/marvell/if_mvxpe.c index 1adbac52b5c6..b858e51960e1 100644 --- a/sys/dev/marvell/if_mvxpe.c +++ b/sys/dev/marvell/if_mvxpe.c @@ -482,7 +482,8 @@ mvxpe_attach(device_t parent, device_t self, void *aux) * we assume phyaddress == MAC unit number here, * but some boards may not. */ - mii_attach(self, mii, 0xffffffff, MII_PHY_ANY, sc->sc_dev->dv_unit, 0); + mii_attach(self, mii, 0xffffffff, MII_PHY_ANY, device_unit(sc->sc_dev), + 0); child = LIST_FIRST(&mii->mii_phys); if (child == NULL) { aprint_error_dev(self, "no PHY found!\n"); diff --git a/sys/dev/marvell/mvxpsec.c b/sys/dev/marvell/mvxpsec.c index c2c4e6372a6b..2c33ba568450 100644 --- a/sys/dev/marvell/mvxpsec.c +++ b/sys/dev/marvell/mvxpsec.c @@ -1036,7 +1036,7 @@ mvxpsec_init_sram(struct mvxpsec_softc *sc) vaddr_t va; int window; - switch (sc->sc_dev->dv_unit) { + switch (device_unit(sc->sc_dev)) { case 0: tag = ARMADAXP_TAG_CRYPT0; break; diff --git a/sys/dev/spkr.c b/sys/dev/spkr.c index 13f6cdcb07e1..31968336e8bc 100644 --- a/sys/dev/spkr.c +++ b/sys/dev/spkr.c @@ -416,7 +416,8 @@ spkr_attach(device_t self, void (*tone)(device_t, u_int, u_int)) struct spkr_softc *sc = device_private(self); #ifdef SPKRDEBUG - aprint_debug("%s: entering for unit %d\n", __func__, self->dv_unit); + aprint_debug("%s: entering for unit %d\n", __func__, + device_unit(self)); #endif /* SPKRDEBUG */ sc->sc_dev = self; sc->sc_tone = tone; @@ -433,7 +434,8 @@ spkr_detach(device_t self, int flags) int rc; #ifdef SPKRDEBUG - aprint_debug("%s: entering for unit %d\n", __func__, self->dv_unit); + aprint_debug("%s: entering for unit %d\n", __func__, + device_unit(self)); #endif /* SPKRDEBUG */ if (sc == NULL) return ENXIO; diff --git a/sys/dev/usb/vhci.c b/sys/dev/usb/vhci.c index 7d4254cc70b5..46c6e5285e95 100644 --- a/sys/dev/usb/vhci.c +++ b/sys/dev/usb/vhci.c @@ -1273,7 +1273,7 @@ vhci_attach(device_t parent, device_t self, void *aux) sc->sc_dev = self; sc->sc_bus.ub_revision = USBREV_2_0; sc->sc_bus.ub_hctype = USBHCTYPE_VHCI; - sc->sc_bus.ub_busnum = self->dv_unit; + sc->sc_bus.ub_busnum = device_unit(self); sc->sc_bus.ub_usedma = false; sc->sc_bus.ub_methods = &vhci_bus_methods; sc->sc_bus.ub_pipesize = sizeof(vhci_pipe_t); From 9279d0417c85aa484605b0858196f68afe8fd010 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Mon, 7 Feb 2022 09:22:54 +0000 Subject: [PATCH 05/26] sys: Avoid touching struct device::dv_cfdata directly outside autoconf. Will help to make struct device opaque later. --- sys/dev/i2c/tsllux.c | 3 +-- sys/dev/isa/wss_isa.c | 12 ++++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/sys/dev/i2c/tsllux.c b/sys/dev/i2c/tsllux.c index e0e453428d78..b5f6c9d4d99d 100644 --- a/sys/dev/i2c/tsllux.c +++ b/sys/dev/i2c/tsllux.c @@ -154,8 +154,7 @@ tsllux_attach(device_t parent, device_t self, void *aux) sc->sc_i2c = ia->ia_tag; sc->sc_addr = ia->ia_addr; - if (self->dv_cfdata != NULL && - self->dv_cfdata->cf_flags & TSLLUX_F_CS_PACKAGE) + if (device_cfdata(self)->cf_flags & TSLLUX_F_CS_PACKAGE) sc->sc_cs_package = true; if (iic_acquire_bus(ia->ia_tag, 0) != 0) { diff --git a/sys/dev/isa/wss_isa.c b/sys/dev/isa/wss_isa.c index f168e15908b1..a86eb0eb17ff 100644 --- a/sys/dev/isa/wss_isa.c +++ b/sys/dev/isa/wss_isa.c @@ -91,7 +91,6 @@ int wss_isa_probe(device_t parent, cfdata_t match, void *aux) { struct isa_attach_args *ia; - struct device probedev; struct wss_softc probesc, *sc; struct ad1848_softc *ac; @@ -106,13 +105,10 @@ wss_isa_probe(device_t parent, cfdata_t match, void *aux) if (ISA_DIRECT_CONFIG(ia)) return 0; - memset(&probedev, 0, sizeof probedev); memset(&probesc, 0, sizeof probesc); sc = &probesc; ac = &sc->sc_ad1848.sc_ad1848; - ac->sc_dev = &probedev; - ac->sc_dev->dv_cfdata = match; - if (wssfind(parent, sc, 1, aux)) { + if (wssfind(parent, match, sc, 1, aux)) { bus_space_unmap(sc->sc_iot, sc->sc_ioh, WSS_CODEC); ad1848_isa_unmap(&sc->sc_ad1848); madunmap(sc); @@ -123,7 +119,7 @@ wss_isa_probe(device_t parent, cfdata_t match, void *aux) } static int -wssfind(device_t parent, struct wss_softc *sc, int probing, +wssfind(device_t parent, cfdata_t match, struct wss_softc *sc, int probing, struct isa_attach_args *ia) { static u_char interrupt_bits[12] = { @@ -135,7 +131,7 @@ wssfind(device_t parent, struct wss_softc *sc, int probing, ac = &sc->sc_ad1848.sc_ad1848; sc->sc_iot = ia->ia_iot; - if (device_cfdata(ac->sc_dev)->cf_flags & 1) + if (match->cf_flags & 1) madprobe(sc, ia->ia_io[0].ir_addr); else sc->mad_chip_type = MAD_NONE; @@ -245,7 +241,7 @@ wss_isa_attach(device_t parent, device_t self, void *aux) ac = &sc->sc_ad1848.sc_ad1848; ac->sc_dev = self; ia = aux; - if (!wssfind(parent, sc, 0, ia)) { + if (!wssfind(parent, device_cfdata(self), sc, 0, ia)) { aprint_error_dev(self, "wssfind failed\n"); return; } From 7fbae9d1b70e47ceb9c28231fbaf45e95d020376 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Mon, 7 Feb 2022 09:36:24 +0000 Subject: [PATCH 06/26] arm/ti: Omit needless dv_private assignment in omap2icu_attach. --- sys/arch/arm/ti/ti_omapintc.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sys/arch/arm/ti/ti_omapintc.c b/sys/arch/arm/ti/ti_omapintc.c index 2503bc16ce85..bcea218fc57d 100644 --- a/sys/arch/arm/ti/ti_omapintc.c +++ b/sys/arch/arm/ti/ti_omapintc.c @@ -260,7 +260,6 @@ omap2icu_attach(device_t parent, device_t self, void *aux) INTC_WRITE(sc, n, INTC_MIR_SET, 0xffffffff); sc->sc_dev = self; - self->dv_private = sc; sc->sc_pic.pic_ops = &omap2icu_picops; sc->sc_pic.pic_maxsources = sc->sc_nbank * 32; From c1d65a6751074d6c82ee42bc28a57392d029a79d Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Mon, 7 Feb 2022 09:37:47 +0000 Subject: [PATCH 07/26] driver(9): New device_set_private. Used to initialize a device_t's private pointer at most once. Only for drivers with zero cfattach size so autoconf doesn't preallocate; KASSERT checks for this mistake. --- sys/kern/subr_device.c | 11 +++++++++++ sys/sys/device.h | 1 + 2 files changed, 12 insertions(+) diff --git a/sys/kern/subr_device.c b/sys/kern/subr_device.c index bc65b1e6ef6a..4657f02f04ea 100644 --- a/sys/kern/subr_device.c +++ b/sys/kern/subr_device.c @@ -278,6 +278,17 @@ device_private(device_t dev) return dev == NULL ? NULL : dev->dv_private; } +void +device_set_private(device_t dev, void *private) +{ + + KASSERTMSG(dev->dv_private == NULL, "device_set_private(%p, %p):" + " device %s already has private set to %p", + dev, private, device_xname(dev), device_private(dev)); + KASSERT(private != NULL); + dev->dv_private = private; +} + prop_dictionary_t device_properties(device_t dev) { diff --git a/sys/sys/device.h b/sys/sys/device.h index f09d5c1675de..96bd9931ec32 100644 --- a/sys/sys/device.h +++ b/sys/sys/device.h @@ -675,6 +675,7 @@ bool device_is_enabled(device_t); bool device_has_power(device_t); int device_locator(device_t, u_int); void *device_private(device_t); +void device_set_private(device_t, void *); prop_dictionary_t device_properties(device_t); void device_set_handle(device_t, devhandle_t); devhandle_t device_handle(device_t); From 185f25059c4f9e6a9a539f08833431f263978005 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Mon, 7 Feb 2022 09:44:35 +0000 Subject: [PATCH 08/26] arm: Use device_set_private for cpuN. For cpu at fdt, nix the fdt softc -- this was leaked and never used for anything. The device's private storage is the cpu_info. --- sys/arch/aarch64/aarch64/cpu.c | 4 ++-- sys/arch/arm/arm32/cpu.c | 4 ++-- sys/arch/arm/fdt/cpu_fdt.c | 11 +---------- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/sys/arch/aarch64/aarch64/cpu.c b/sys/arch/aarch64/aarch64/cpu.c index fa7ec5003caa..254558b0d8ba 100644 --- a/sys/arch/aarch64/aarch64/cpu.c +++ b/sys/arch/aarch64/aarch64/cpu.c @@ -128,7 +128,7 @@ cpu_attach(device_t dv, cpuid_t id) cpu_info[ncpu] = ci; if (cpu_hatched_p(unit) == 0) { ci->ci_dev = dv; - dv->dv_private = ci; + device_set_private(dv, ci); ci->ci_index = -1; aprint_naive(": disabled\n"); @@ -143,7 +143,7 @@ cpu_attach(device_t dv, cpuid_t id) } ci->ci_dev = dv; - dv->dv_private = ci; + device_set_private(dv, ci); ci->ci_kfpu_spl = -1; diff --git a/sys/arch/arm/arm32/cpu.c b/sys/arch/arm/arm32/cpu.c index e5596408cbf9..71e8bcebcd3d 100644 --- a/sys/arch/arm/arm32/cpu.c +++ b/sys/arch/arm/arm32/cpu.c @@ -128,7 +128,7 @@ cpu_attach(device_t dv, cpuid_t id) cpu_info[unit] = ci; if (cpu_hatched_p(unit) == false) { ci->ci_dev = dv; - dv->dv_private = ci; + device_set_private(dv, ci); aprint_naive(": disabled\n"); aprint_normal(": disabled (unresponsive)\n"); return; @@ -141,7 +141,7 @@ cpu_attach(device_t dv, cpuid_t id) } ci->ci_dev = dv; - dv->dv_private = ci; + device_set_private(dv, ci); arm_cpu_do_topology(ci); diff --git a/sys/arch/arm/fdt/cpu_fdt.c b/sys/arch/arm/fdt/cpu_fdt.c index b9dca143b2a9..0235a935b8bc 100644 --- a/sys/arch/arm/fdt/cpu_fdt.c +++ b/sys/arch/arm/fdt/cpu_fdt.c @@ -57,12 +57,7 @@ __KERNEL_RCSID(0, "$NetBSD: cpu_fdt.c,v 1.41 2021/08/30 23:16:17 jmcneill Exp $" static int cpu_fdt_match(device_t, cfdata_t, void *); static void cpu_fdt_attach(device_t, device_t, void *); -struct cpu_fdt_softc { - device_t sc_dev; - int sc_phandle; -}; - -CFATTACH_DECL_NEW(cpu_fdt, sizeof(struct cpu_fdt_softc), +CFATTACH_DECL_NEW(cpu_fdt, 0, cpu_fdt_match, cpu_fdt_attach, NULL, NULL); static int @@ -80,16 +75,12 @@ cpu_fdt_match(device_t parent, cfdata_t cf, void *aux) static void cpu_fdt_attach(device_t parent, device_t self, void *aux) { - struct cpu_fdt_softc * const sc = device_private(self); struct fdt_attach_args * const faa = aux; const int phandle = faa->faa_phandle; bus_addr_t cpuid; const uint32_t *cap_ptr; int len; - sc->sc_dev = self; - sc->sc_phandle = phandle; - cap_ptr = fdtbus_get_prop(phandle, "capacity-dmips-mhz", &len); if (cap_ptr && len == 4) { prop_dictionary_t dict = device_properties(self); From ca9df9b6c08e17e710e40534ddd8a4a4a77bb583 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Mon, 7 Feb 2022 09:46:46 +0000 Subject: [PATCH 09/26] arc: Use device_set_private for cpuN. --- sys/arch/arc/arc/cpu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sys/arch/arc/arc/cpu.c b/sys/arch/arc/arc/cpu.c index c05c418ac06f..6044c1c275e9 100644 --- a/sys/arch/arc/arc/cpu.c +++ b/sys/arch/arc/arc/cpu.c @@ -71,11 +71,10 @@ cpumatch(device_t parent, cfdata_t cf, void *aux) static void cpuattach(device_t parent, device_t self, void *aux) { - struct cpu_info * const ci = curcpu(); ci->ci_dev = self; - self->dv_private = ci; + device_set_private(self, ci); aprint_normal(": "); From 8547a79568aa8d6eda8b902f379a197ca078f013 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Mon, 7 Feb 2022 09:53:24 +0000 Subject: [PATCH 10/26] exyopctl(4): Don't leak a duplicate softc on attach. --- sys/arch/arm/samsung/exynos_pinctrl.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/sys/arch/arm/samsung/exynos_pinctrl.c b/sys/arch/arm/samsung/exynos_pinctrl.c index 9349fbf6dcf6..e88bd3aa5f6c 100644 --- a/sys/arch/arm/samsung/exynos_pinctrl.c +++ b/sys/arch/arm/samsung/exynos_pinctrl.c @@ -41,7 +41,6 @@ __KERNEL_RCSID(1, "$NetBSD: exynos_pinctrl.c,v 1.21 2021/01/27 03:10:19 thorpej #include <sys/device.h> #include <sys/intr.h> #include <sys/systm.h> -#include <sys/kmem.h> #include <sys/gpio.h> #include <dev/gpio/gpiovar.h> @@ -93,8 +92,7 @@ exynos_pinctrl_match(device_t parent, cfdata_t cf, void *aux) static void exynos_pinctrl_attach(device_t parent, device_t self, void *aux) { - struct exynos_pinctrl_softc * const sc - = kmem_zalloc(sizeof(*sc), KM_SLEEP); + struct exynos_pinctrl_softc * const sc = device_private(self); struct fdt_attach_args * const faa = aux; bus_addr_t addr; bus_size_t size; @@ -107,7 +105,6 @@ exynos_pinctrl_attach(device_t parent, device_t self, void *aux) } aprint_normal(" pinctrl @ 0x%08x ", (uint)addr); - self->dv_private = sc; sc->sc_dev = self; sc->sc_bst = faa->faa_bst; sc->sc_epb = of_compatible_lookup(faa->faa_phandle, compat_data)->data; From 16f43a219bbce2531db804f40bdc9cbd101c1c98 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Tue, 8 Feb 2022 14:48:50 +0000 Subject: [PATCH 11/26] arm/samsung: Don't abuse child's dv_private for the parent's uses. dv_private belongs to the device itself, i.e., the child here. This overwrote the child's softc pointer, causing all kinds of havoc; if this worked it was by an amazing accident. --- sys/arch/arm/samsung/exynos_gpio.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/sys/arch/arm/samsung/exynos_gpio.c b/sys/arch/arm/samsung/exynos_gpio.c index df045a50335a..10e54eb9c07b 100644 --- a/sys/arch/arm/samsung/exynos_gpio.c +++ b/sys/arch/arm/samsung/exynos_gpio.c @@ -398,7 +398,6 @@ exynos_gpio_bank_config(struct exynos_pinctrl_softc * parent, bank->bank_sc = sc; bank->bank_dev = config_found(parent->sc_dev, &gba, exynos_gpio_cfprint, CFARGS_NONE); - bank->bank_dev->dv_private = sc; /* read in our initial settings */ bank->bank_cfg.cfg = GPIO_READ(bank, EXYNOS_GPIO_CON); @@ -451,7 +450,14 @@ exynos_gpio_pin_lookup(const char *name) static void * exynos_gpio_fdt_acquire(device_t dev, const void *data, size_t len, int flags) { + device_t parent = device_parent(dev); + struct exynos_pinctrl_softc *sc = device_private(parent); + const struct exynos_pinctrl_banks *epb = sc->sc_epb; + struct exynos_gpio_bank *bank = NULL; struct exynos_gpio_pin *gpin; + u_int n; + + KASSERT(device_is_a(parent, "exyopctl")); if (len != 12) return NULL; @@ -460,8 +466,14 @@ exynos_gpio_fdt_acquire(device_t dev, const void *data, size_t len, int flags) const int pin = be32toh(cells[1]) & 0x0f; const int actlo = be32toh(cells[2]) & 0x01; - struct exynos_gpio_softc *bank_sc = device_private(dev); - struct exynos_gpio_bank * const bank = bank_sc->sc_bank; + for (n = 0; n < epb->epb_nbanks; n++) { + if (epb->epb_banks[n].bank_dev == dev) { + bank = &epb->epb_banks[n]; + break; + } + } + KASSERTMSG(bank != NULL, "no such gpio bank child of %s @ %p: %s @ %p", + device_xname(parent), parent, device_xname(dev), dev); gpin = kmem_alloc(sizeof(*gpin), KM_SLEEP); gpin->pin_sc = bank->bank_sc; From 0ca8092f51808f85bc14cd404fea52c79b80598a Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Tue, 8 Feb 2022 15:28:47 +0000 Subject: [PATCH 12/26] arm: Use device_set_private for various drivers. --- sys/arch/arm/broadcom/bcm53xx_cca.c | 2 +- sys/arch/arm/broadcom/bcm53xx_ccb.c | 2 +- sys/arch/arm/cortex/a9tmr.c | 2 +- sys/arch/arm/cortex/gic.c | 2 +- sys/arch/arm/cortex/gtmr.c | 2 +- sys/arch/arm/gemini/gemini_icu.c | 2 +- sys/arch/arm/omap/omap2_icu.c | 2 +- sys/arch/arm/omap/omap2_prcm.c | 2 +- sys/arch/arm/samsung/mct.c | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sys/arch/arm/broadcom/bcm53xx_cca.c b/sys/arch/arm/broadcom/bcm53xx_cca.c index 2098f4f2496a..45aa46d47d58 100644 --- a/sys/arch/arm/broadcom/bcm53xx_cca.c +++ b/sys/arch/arm/broadcom/bcm53xx_cca.c @@ -154,7 +154,7 @@ bcmcca_mainbus_attach(device_t parent, device_t self, void *aux) struct bcmcca_softc * const sc = &bcmcca_sc; sc->sc_dev = self; - self->dv_private = sc; + device_set_private(self, sc); sc->sc_bst = bcm53xx_ioreg_bst; diff --git a/sys/arch/arm/broadcom/bcm53xx_ccb.c b/sys/arch/arm/broadcom/bcm53xx_ccb.c index af75de7ffdd2..27d17ee8c286 100644 --- a/sys/arch/arm/broadcom/bcm53xx_ccb.c +++ b/sys/arch/arm/broadcom/bcm53xx_ccb.c @@ -168,7 +168,7 @@ bcmccb_mainbus_attach(device_t parent, device_t self, void *aux) struct bcmccb_softc * const sc = &bcmccb_sc; sc->sc_dev = self; - self->dv_private = sc; + device_set_private(self, sc); sc->sc_bst = bcm53xx_ioreg_bst; diff --git a/sys/arch/arm/cortex/a9tmr.c b/sys/arch/arm/cortex/a9tmr.c index 624d52f3070a..1d07c03ae941 100644 --- a/sys/arch/arm/cortex/a9tmr.c +++ b/sys/arch/arm/cortex/a9tmr.c @@ -139,7 +139,7 @@ a9tmr_attach(device_t parent, device_t self, void *aux) } aprint_normal(": %s Global 64-bit Timer (%s)\n", cpu_type, freqbuf); - self->dv_private = sc; + device_set_private(self, sc); sc->sc_dev = self; sc->sc_memt = mpcaa->mpcaa_memt; sc->sc_memh = mpcaa->mpcaa_memh; diff --git a/sys/arch/arm/cortex/gic.c b/sys/arch/arm/cortex/gic.c index 7a75d7a061b8..21f8c890ffc2 100644 --- a/sys/arch/arm/cortex/gic.c +++ b/sys/arch/arm/cortex/gic.c @@ -612,7 +612,7 @@ armgic_attach(device_t parent, device_t self, void *aux) struct mpcore_attach_args * const mpcaa = aux; sc->sc_dev = self; - self->dv_private = sc; + device_set_private(self, sc); sc->sc_memt = mpcaa->mpcaa_memt; /* provided for us */ bus_space_subregion(sc->sc_memt, mpcaa->mpcaa_memh, mpcaa->mpcaa_off1, diff --git a/sys/arch/arm/cortex/gtmr.c b/sys/arch/arm/cortex/gtmr.c index a145e576bcd7..a737308a74b8 100644 --- a/sys/arch/arm/cortex/gtmr.c +++ b/sys/arch/arm/cortex/gtmr.c @@ -139,7 +139,7 @@ gtmr_attach(device_t parent, device_t self, void *aux) aprint_debug_dev(self, "enabling Allwinner A64 timer workaround\n"); } - self->dv_private = sc; + device_set_private(self, sc); sc->sc_dev = self; #ifdef DIAGNOSTIC diff --git a/sys/arch/arm/gemini/gemini_icu.c b/sys/arch/arm/gemini/gemini_icu.c index 343d910695c8..ebac2cb33882 100644 --- a/sys/arch/arm/gemini/gemini_icu.c +++ b/sys/arch/arm/gemini/gemini_icu.c @@ -262,7 +262,7 @@ geminiicu_attach(device_t parent, device_t self, void *aux) INTC_WRITE(sc, GEMINI_ICU_IRQ_TRIGLEVEL, 0xffffffff); sc->sc_dev = self; - self->dv_private = sc; + device_set_private(self, sc); pic_add(&sc->sc_pic, 0); } diff --git a/sys/arch/arm/omap/omap2_icu.c b/sys/arch/arm/omap/omap2_icu.c index a19b6d90438e..6d5ec74dc329 100644 --- a/sys/arch/arm/omap/omap2_icu.c +++ b/sys/arch/arm/omap/omap2_icu.c @@ -207,7 +207,7 @@ omap2icu_attach(device_t parent, device_t self, void *aux) INTC_WRITE(sc, 2, INTC_MIR_SET, 0xffffffff); sc->sc_dev = self; - self->dv_private = sc; + device_set_private(self, sc); pic_add(&sc->sc_pic, 0); } diff --git a/sys/arch/arm/omap/omap2_prcm.c b/sys/arch/arm/omap/omap2_prcm.c index 109d09126601..b7ece398c36e 100644 --- a/sys/arch/arm/omap/omap2_prcm.c +++ b/sys/arch/arm/omap/omap2_prcm.c @@ -82,7 +82,7 @@ prcm_attach(device_t parent, device_t self, void *aux) KASSERT(prcm_sc.sc_dev == NULL); - self->dv_private = &prcm_sc; + device_set_private(self, &prcm_sc); prcm_sc.sc_dev = self; prcm_sc.sc_base = obio->obio_addr; diff --git a/sys/arch/arm/samsung/mct.c b/sys/arch/arm/samsung/mct.c index a8a5d3b47ee9..1413a157c16d 100644 --- a/sys/arch/arm/samsung/mct.c +++ b/sys/arch/arm/samsung/mct.c @@ -252,7 +252,7 @@ mct_attach(device_t parent, device_t self, void *aux) return; } - self->dv_private = sc; + device_set_private(self, sc); sc->sc_dev = self; sc->sc_phandle = faa->faa_phandle; sc->sc_bst = faa->faa_bst; From 9a4b2d2de7918c72a7daeaf5ac51238e6160c47e Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Tue, 8 Feb 2022 15:55:10 +0000 Subject: [PATCH 13/26] mips: Use device_set_private for cpuN on older ports. Specifically, for those that don't use cpu_attach_common of mips_subr.c. --- sys/arch/cobalt/cobalt/cpu.c | 2 +- sys/arch/ews4800mips/ews4800mips/cpu.c | 2 +- sys/arch/hpcmips/hpcmips/cpu.c | 2 +- sys/arch/mipsco/mipsco/cpu.c | 2 +- sys/arch/newsmips/newsmips/cpu.c | 2 +- sys/arch/pmax/pmax/cpu.c | 2 +- sys/arch/sgimips/sgimips/cpu.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sys/arch/cobalt/cobalt/cpu.c b/sys/arch/cobalt/cobalt/cpu.c index 733f36f2b5a1..ce06bd39a5b6 100644 --- a/sys/arch/cobalt/cobalt/cpu.c +++ b/sys/arch/cobalt/cobalt/cpu.c @@ -59,7 +59,7 @@ cpu_attach(device_t parent, device_t self, void *aux) struct cpu_info * const ci = curcpu(); ci->ci_dev = self; - self->dv_private = ci; + device_set_private(self, ci); aprint_normal(": "); cpu_identify(self); diff --git a/sys/arch/ews4800mips/ews4800mips/cpu.c b/sys/arch/ews4800mips/ews4800mips/cpu.c index 6215e044ea85..00952c914805 100644 --- a/sys/arch/ews4800mips/ews4800mips/cpu.c +++ b/sys/arch/ews4800mips/ews4800mips/cpu.c @@ -66,7 +66,7 @@ cpuattach(device_t parent, device_t self, void *aux) struct cpu_info * const ci = curcpu(); ci->ci_dev = self; - self->dv_private = ci; + device_set_private(self, ci); aprint_normal(": "); cpu_attached = 1; diff --git a/sys/arch/hpcmips/hpcmips/cpu.c b/sys/arch/hpcmips/hpcmips/cpu.c index f6ca851d5d21..5458941e8da3 100644 --- a/sys/arch/hpcmips/hpcmips/cpu.c +++ b/sys/arch/hpcmips/hpcmips/cpu.c @@ -93,7 +93,7 @@ cpuattach(device_t parent, device_t self, void *aux) struct cpu_info * const ci = curcpu(); ci->ci_dev = self; - self->dv_private = ci; + device_set_private(self, ci); aprint_normal(": "); diff --git a/sys/arch/mipsco/mipsco/cpu.c b/sys/arch/mipsco/mipsco/cpu.c index d614f3a26618..88a2145885c3 100644 --- a/sys/arch/mipsco/mipsco/cpu.c +++ b/sys/arch/mipsco/mipsco/cpu.c @@ -66,7 +66,7 @@ cpuattach(device_t parent, device_t self, void *aux) struct cpu_info * const ci = curcpu(); ci->ci_dev = self; - self->dv_private = ci; + device_set_private(self, ci); aprint_normal(": "); cpu_identify(self); diff --git a/sys/arch/newsmips/newsmips/cpu.c b/sys/arch/newsmips/newsmips/cpu.c index 22322f6a840e..e5237dcee6a1 100644 --- a/sys/arch/newsmips/newsmips/cpu.c +++ b/sys/arch/newsmips/newsmips/cpu.c @@ -66,7 +66,7 @@ cpuattach(device_t parent, device_t self, void *aux) struct cpu_info * const ci = curcpu(); ci->ci_dev = self; - self->dv_private = ci; + device_set_private(self, ci); aprint_normal(": "); cpu_identify(self); diff --git a/sys/arch/pmax/pmax/cpu.c b/sys/arch/pmax/pmax/cpu.c index bc17e17812a7..c0be9287b0cd 100644 --- a/sys/arch/pmax/pmax/cpu.c +++ b/sys/arch/pmax/pmax/cpu.c @@ -66,7 +66,7 @@ cpuattach(device_t parent, device_t self, void *aux) struct cpu_info * const ci = curcpu(); ci->ci_dev = self; - self->dv_private = ci; + device_set_private(self, ci); aprint_normal(": "); cpu_identify(self); diff --git a/sys/arch/sgimips/sgimips/cpu.c b/sys/arch/sgimips/sgimips/cpu.c index 4d2b926f286e..a0e9fed8f912 100644 --- a/sys/arch/sgimips/sgimips/cpu.c +++ b/sys/arch/sgimips/sgimips/cpu.c @@ -91,7 +91,7 @@ cpu_attach(device_t parent, device_t self, void *aux) struct cpu_info * const ci = curcpu(); ci->ci_dev = self; - self->dv_private = ci; + device_set_private(self, ci); aprint_normal(": "); cpu_identify(self); From e6a4a5646216f19a0fdf68cf4ba028df7f39aeff Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Tue, 8 Feb 2022 16:45:48 +0000 Subject: [PATCH 14/26] mips: Use device_set_private in a few drivers. --- sys/arch/evbmips/gdium/bonito_mainbus.c | 2 +- sys/arch/evbmips/loongson/bonito_mainbus.c | 2 +- sys/arch/mips/sibyte/pci/sbbrz.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sys/arch/evbmips/gdium/bonito_mainbus.c b/sys/arch/evbmips/gdium/bonito_mainbus.c index d67fc3529759..2618aa93d51a 100644 --- a/sys/arch/evbmips/gdium/bonito_mainbus.c +++ b/sys/arch/evbmips/gdium/bonito_mainbus.c @@ -70,7 +70,7 @@ bonito_mainbus_attach(device_t parent, device_t self, void *aux) struct gdium_config * const gc = &gdium_configuration; pcireg_t rev; - self->dv_private = &gc->gc_bonito; + device_set_private(self, &gc->gc_bonito); /* * There is only one PCI controller on a Loongson chip. diff --git a/sys/arch/evbmips/loongson/bonito_mainbus.c b/sys/arch/evbmips/loongson/bonito_mainbus.c index 1330742eede3..9334fc079bc7 100644 --- a/sys/arch/evbmips/loongson/bonito_mainbus.c +++ b/sys/arch/evbmips/loongson/bonito_mainbus.c @@ -73,7 +73,7 @@ bonito_mainbus_attach(device_t parent, device_t self, void *aux) pcireg_t rev; bool compatible; - self->dv_private = __UNCONST(&sys_platform->bonito_config); + device_set_private(self, __UNCONST(&sys_platform->bonito_config)); /* * Loongson 2F processors do not use a real Bonito64 chip but diff --git a/sys/arch/mips/sibyte/pci/sbbrz.c b/sys/arch/mips/sibyte/pci/sbbrz.c index b7213720bc04..92d1b2f90224 100644 --- a/sys/arch/mips/sibyte/pci/sbbrz.c +++ b/sys/arch/mips/sibyte/pci/sbbrz.c @@ -181,7 +181,7 @@ sbbrz_attach(device_t parent, device_t self, void *aux) /* note that we've attached the bridge; can't have two. */ sc->sc_dev = self; - self->dv_private = sc; + device_set_private(self, sc); /* * set up the bridge's info; done once at console init time From f6a4fd8c163707565202cca13cfcd9fb1a41b9a4 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Tue, 8 Feb 2022 16:48:21 +0000 Subject: [PATCH 15/26] powerpc: Use device_set_private for e500 cpuN. --- sys/arch/evbppc/mpc85xx/machdep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/arch/evbppc/mpc85xx/machdep.c b/sys/arch/evbppc/mpc85xx/machdep.c index 658f8a1ef548..86fe0e52e23a 100644 --- a/sys/arch/evbppc/mpc85xx/machdep.c +++ b/sys/arch/evbppc/mpc85xx/machdep.c @@ -1019,7 +1019,7 @@ e500_cpu_attach(device_t self, u_int instance) if (instance > 1) { #if defined(MULTIPROCESSOR) ci->ci_idepth = -1; - self->dv_private = ci; + device_set_private(self, ci); ci->ci_cpuid = instance - (instance > 0); ci->ci_dev = self; @@ -1038,7 +1038,7 @@ e500_cpu_attach(device_t self, u_int instance) #endif } - self->dv_private = ci; + device_set_private(self, ci); ci->ci_cpuid = instance - (instance > 0); ci->ci_dev = self; From 99391c54a93ce87a4966e21c5c87215174266d21 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Tue, 8 Feb 2022 16:50:55 +0000 Subject: [PATCH 16/26] vax: Use device_set_private. --- sys/arch/vax/vax/autoconf.c | 2 +- sys/arch/vax/vax/ka6400.c | 2 +- sys/arch/vax/vax/ka820.c | 4 ++-- sys/arch/vax/vax/ka88.c | 2 +- sys/arch/vax/vax/multicpu.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sys/arch/vax/vax/autoconf.c b/sys/arch/vax/vax/autoconf.c index 4a96a9e88474..b07559ad14fd 100644 --- a/sys/arch/vax/vax/autoconf.c +++ b/sys/arch/vax/vax/autoconf.c @@ -173,7 +173,7 @@ cpu_mainbus_attach(device_t parent, device_t self, void *aux) KASSERT(device_private(self) == NULL); ci = curcpu(); - self->dv_private = ci; + device_set_private(self, ci); ci->ci_dev = self; ci->ci_cpuid = device_unit(self); diff --git a/sys/arch/vax/vax/ka6400.c b/sys/arch/vax/vax/ka6400.c index e904f78de04f..50f7b4d8e360 100644 --- a/sys/arch/vax/vax/ka6400.c +++ b/sys/arch/vax/vax/ka6400.c @@ -146,7 +146,7 @@ ka6400_attach(device_t parent, device_t self, void *aux) mtpr(0, PR_VPSR); /* Can't use vector processor */ ci = curcpu(); - self->dv_private = ci; + device_set_private(self, ci); ci->ci_dev = self; ci->ci_cpuid = device_unit(self); ci->ci_slotid = xa->xa_nodenr; diff --git a/sys/arch/vax/vax/ka820.c b/sys/arch/vax/vax/ka820.c index 72d572d96c09..5a85b4307f36 100644 --- a/sys/arch/vax/vax/ka820.c +++ b/sys/arch/vax/vax/ka820.c @@ -169,8 +169,8 @@ ka820_attach(device_t parent, device_t self, void *aux) #endif ci = curcpu(); - self->dv_private = ci; /* eww. but curcpu() is already too */ - /* entrenched to change */ + device_set_private(self, ci); /* eww. but curcpu() is already too */ + /* entrenched to change */ ci->ci_slotid = ba->ba_nodenr; ci->ci_cpuid = device_unit(self); ci->ci_dev = self; diff --git a/sys/arch/vax/vax/ka88.c b/sys/arch/vax/vax/ka88.c index 400964748f29..592959ed6d28 100644 --- a/sys/arch/vax/vax/ka88.c +++ b/sys/arch/vax/vax/ka88.c @@ -149,7 +149,7 @@ ka88_cpu_attach(device_t parent, device_t self, void *aux) return; } ci = curcpu(); - self->dv_private = ci; + device_set_private(self, ci); ci->ci_dev = self; ci->ci_cpuid = device_unit(self); ci->ci_slotid = na->na_slot; diff --git a/sys/arch/vax/vax/multicpu.c b/sys/arch/vax/vax/multicpu.c index ec91b93eb2e0..9c40292b35b6 100644 --- a/sys/arch/vax/vax/multicpu.c +++ b/sys/arch/vax/vax/multicpu.c @@ -87,7 +87,7 @@ cpu_slavesetup(device_t self, int slotid) KASSERT(device_private(self) == NULL); ci = kmem_zalloc(sizeof(*ci), KM_SLEEP); - self->dv_private = ci; + device_set_private(self, ci); ci->ci_dev = self; ci->ci_slotid = slotid; ci->ci_cpuid = device_unit(self); From 7132222d036a0efacbb94e5f173b2541c3c80f71 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Tue, 8 Feb 2022 20:24:29 +0000 Subject: [PATCH 17/26] playstation2: Somewhat belated device_t/softc split. --- sys/arch/playstation2/dev/emac3.c | 6 +++--- sys/arch/playstation2/dev/emac3var.h | 2 +- sys/arch/playstation2/dev/if_smap.c | 8 +++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/sys/arch/playstation2/dev/emac3.c b/sys/arch/playstation2/dev/emac3.c index 2b734681f10b..b335ef72c832 100644 --- a/sys/arch/playstation2/dev/emac3.c +++ b/sys/arch/playstation2/dev/emac3.c @@ -103,7 +103,7 @@ emac3_init(struct emac3_softc *sc) r = _emac3_reg_read_4(EMAC3_MR1); if (emac3_soft_reset() != 0) { - printf("%s: reset failed.\n", sc->dev.dv_xname); + printf("%s: reset failed.\n", device_xname(sc->dev)); return (1); } @@ -132,7 +132,7 @@ emac3_exit(struct emac3_softc *sc) ; if (retry == 0) - printf("%s: still running.\n", sc->dev.dv_xname); + printf("%s: still running.\n", device_xname(sc->dev)); } int @@ -140,7 +140,7 @@ emac3_reset(struct emac3_softc *sc) { if (emac3_soft_reset() != 0) { - printf("%s: reset failed.\n", sc->dev.dv_xname); + printf("%s: reset failed.\n", device_xname(sc->dev)); return (1); } diff --git a/sys/arch/playstation2/dev/emac3var.h b/sys/arch/playstation2/dev/emac3var.h index e6ecc7b2e498..8bfdac89171d 100644 --- a/sys/arch/playstation2/dev/emac3var.h +++ b/sys/arch/playstation2/dev/emac3var.h @@ -30,7 +30,7 @@ */ struct emac3_softc { - struct device dev; + device_t dev; struct mii_data mii; u_int8_t eaddr[ETHER_ADDR_LEN]; u_int32_t mode1_reg; diff --git a/sys/arch/playstation2/dev/if_smap.c b/sys/arch/playstation2/dev/if_smap.c index e8d23e9f91f8..d367b2bf7701 100644 --- a/sys/arch/playstation2/dev/if_smap.c +++ b/sys/arch/playstation2/dev/if_smap.c @@ -108,7 +108,7 @@ struct smap_softc { krndsource_t rnd_source; }; -#define DEVNAME (sc->emac3.dev.dv_xname) +#define DEVNAME (device_xname(sc->emac3.dev)) #define ROUND4(x) (((x) + 3) & ~3) #define ROUND16(x) (((x) + 15) & ~15) @@ -147,7 +147,7 @@ void smap_attach(struct device *parent, struct device *self, void *aux) { struct spd_attach_args *spa = aux; - struct smap_softc *sc = (void *)self; + struct smap_softc *sc = device_private(self); struct emac3_softc *emac3 = &sc->emac3; struct ifnet *ifp = &sc->ethercom.ec_if; struct mii_data *mii = &emac3->mii; @@ -158,6 +158,8 @@ smap_attach(struct device *parent, struct device *self, void *aux) __sc = sc; #endif + sc->dev = self; + printf(": %s\n", spa->spa_product_name); /* SPD EEPROM */ @@ -219,7 +221,7 @@ smap_attach(struct device *parent, struct device *self, void *aux) mii->mii_statchg = emac3_phy_statchg; sc->ethercom.ec_mii = mii; ifmedia_init(&mii->mii_media, 0, ether_mediachange, ether_mediastatus); - mii_attach(&emac3->dev, mii, 0xffffffff, MII_PHY_ANY, + mii_attach(emac3->dev, mii, 0xffffffff, MII_PHY_ANY, MII_OFFSET_ANY, 0); /* Choose a default media. */ From 1a04249933054142a7e65f9e37f53fd6716236f7 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Tue, 8 Feb 2022 20:26:18 +0000 Subject: [PATCH 18/26] sparc64/vnet(4): device_t/softc split --- sys/arch/sparc64/dev/vnet.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sys/arch/sparc64/dev/vnet.c b/sys/arch/sparc64/dev/vnet.c index bafc00dfe669..bdca4077a1fb 100644 --- a/sys/arch/sparc64/dev/vnet.c +++ b/sys/arch/sparc64/dev/vnet.c @@ -128,7 +128,7 @@ struct vnet_soft_desc { }; struct vnet_softc { - struct device sc_dv; + device_t sc_dv; bus_space_tag_t sc_bustag; bus_dma_tag_t sc_dmatag; @@ -247,6 +247,7 @@ vnet_attach(struct device *parent, struct device *self, void *aux) struct ldc_conn *lc; struct ifnet *ifp; + sc->sc_dv = self; sc->sc_bustag = ca->ca_bustag; sc->sc_dmatag = ca->ca_dmatag; sc->sc_tx_ino = ca->ca_tx_ino; @@ -304,8 +305,10 @@ vnet_attach(struct device *parent, struct device *self, void *aux) /* * Each interface gets its own pool. */ - pool_init(&sc->sc_pool, 2048, 0, 0, 0, sc->sc_dv.dv_xname, NULL, IPL_NET); - + pool_init(&sc->sc_pool, /*size*/2048, /*align*/0, /*align_offset*/0, + /*flags*/0, /*wchan*/device_xname(sc->sc_dv), /*palloc*/NULL, + IPL_NET); + ifp = &sc->sc_ethercom.ec_if; ifp->if_softc = sc; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; @@ -1392,7 +1395,7 @@ vnet_watchdog(struct ifnet *ifp) struct vnet_softc *sc = ifp->if_softc; - printf("%s: watchdog timeout\n", sc->sc_dv.dv_xname); + printf("%s: watchdog timeout\n", device_xname(sc->sc_dv)); } int From 6847d7202e5cbbab3d00c7bb5d8a7f9f6d1e02ce Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Tue, 8 Feb 2022 20:39:49 +0000 Subject: [PATCH 19/26] ts(4): Skip fabricating bogus struct device in tsmatch. Doesn't appear to be used anywhere in tsmatch. Let's not invent bogus autoconf guts here. --- sys/dev/qbus/ts.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/sys/dev/qbus/ts.c b/sys/dev/qbus/ts.c index c0644ed36519..a92d93fea22b 100644 --- a/sys/dev/qbus/ts.c +++ b/sys/dev/qbus/ts.c @@ -215,7 +215,6 @@ const struct cdevsw ts_cdevsw = { int tsmatch(device_t parent, cfdata_t match, void *aux) { - struct device tsdev; struct ts_softc ssc; struct ts_softc *sc = &ssc; struct uba_attach_args *ua = aux; @@ -224,9 +223,7 @@ tsmatch(device_t parent, cfdata_t match, void *aux) sc->sc_iot = ua->ua_iot; sc->sc_ioh = ua->ua_ioh; sc->sc_mapped = 0; - sc->sc_dev = &tsdev; sc->sc_uh = device_private(parent); - strcpy(sc->sc_dev->dv_xname, "ts"); /* Try to reset the device */ for (i = 0; i < 3; i++) { From e257ebb55397bab247695c6de101f7d253ff97b7 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Tue, 8 Feb 2022 20:42:34 +0000 Subject: [PATCH 20/26] evbppc/wdc(4) at obio: Stop fabricating bogus struct device. Nothing uses this. --- sys/arch/evbppc/mpc85xx/wdc_obio.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sys/arch/evbppc/mpc85xx/wdc_obio.c b/sys/arch/evbppc/mpc85xx/wdc_obio.c index 87c9c2054c70..a8f9c09b2296 100644 --- a/sys/arch/evbppc/mpc85xx/wdc_obio.c +++ b/sys/arch/evbppc/mpc85xx/wdc_obio.c @@ -101,7 +101,6 @@ wdc_obio_match(device_t parent, cfdata_t cf, void *aux) struct generic_attach_args * const ga = aux; bus_size_t size = ga->ga_size; struct wdc_regs wdr; - struct device dev; int rv = 0; if (ga->ga_addr == OBIOCF_ADDR_DEFAULT) @@ -112,11 +111,8 @@ wdc_obio_match(device_t parent, cfdata_t cf, void *aux) /* * We need to see if a CF is attached in True-IDE mode */ - memset(&dev, 0, sizeof(dev)); memset(&wdr, 0, sizeof(wdr)); - dev.dv_xname[0] = '?'; - if (wdc_obio_initregmap(&wdr, ga->ga_bst, ga->ga_addr, size)) { wdc_init_shadow_regs(&wdr); rv = wdcprobe(&wdr); From 83655a52839399bab4e4cbc7d3e814e57f34a56c Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Tue, 8 Feb 2022 20:45:48 +0000 Subject: [PATCH 21/26] sys: Fix various abuse of struct device internals. --- share/man/man4/iop.4 | 2 +- sys/arch/arm/ep93xx/epcom.c | 2 +- sys/arch/evbmips/cavium/autoconf.c | 2 +- sys/arch/sgimips/ioc/if_le_oioc.c | 6 ++--- sys/arch/sun3/dev/fbvar.h | 2 +- sys/arch/vax/vsa/lcg.c | 42 +++++++++++++++++++----------- sys/dev/i2c/ihidev.c | 37 +++++++++++++------------- sys/dev/i2c/pcagpio.c | 14 +++++----- sys/dev/pci/xmm7360.c | 16 ++++++------ 9 files changed, 68 insertions(+), 55 deletions(-) diff --git a/share/man/man4/iop.4 b/share/man/man4/iop.4 index 1ce5ff03e4a0..acf713db43f2 100644 --- a/share/man/man4/iop.4 +++ b/share/man/man4/iop.4 @@ -169,7 +169,7 @@ iov_len field from the returned iovec. struct iop_tidmap { u_short it_tid; u_short it_flags; - char it_dvname[sizeof(((struct device *)NULL)->dv_xname)]; + char it_dvname[16]; }; #define IT_CONFIGURED 0x02 /* target configured */ .Ed diff --git a/sys/arch/arm/ep93xx/epcom.c b/sys/arch/arm/ep93xx/epcom.c index ebda4841c9b4..b37c696892a5 100644 --- a/sys/arch/arm/ep93xx/epcom.c +++ b/sys/arch/arm/ep93xx/epcom.c @@ -260,7 +260,7 @@ epcom_attach_subr(struct epcom_softc *sc) if (sc->sc_iot == kgdb_sc.sc_iot && sc->sc_hwbase == kgdb_sc.sc_hwbase) { SET(sc->sc_hwflags, COM_HW_KGDB); - printf("%s: kgdb\n", sc->sc_dev.dv_xname); + device_printf(sc->sc_dev, "kgdb\n"); } #endif diff --git a/sys/arch/evbmips/cavium/autoconf.c b/sys/arch/evbmips/cavium/autoconf.c index d09e6ce029a4..106a8e5910d2 100644 --- a/sys/arch/evbmips/cavium/autoconf.c +++ b/sys/arch/evbmips/cavium/autoconf.c @@ -172,7 +172,7 @@ prop_set_cnmac(device_t dev) pn = prop_number_create_signed(7 - unit); break; case BOARD_TYPE_UBIQUITI_E300: - pn = prop_number_create_signed(4 + dev->dv_unit); + pn = prop_number_create_signed(4 + device_unit(dev)); break; default: pn = prop_number_create_signed(-1); diff --git a/sys/arch/sgimips/ioc/if_le_oioc.c b/sys/arch/sgimips/ioc/if_le_oioc.c index a5a6ec32087f..e339c77c39fc 100644 --- a/sys/arch/sgimips/ioc/if_le_oioc.c +++ b/sys/arch/sgimips/ioc/if_le_oioc.c @@ -88,9 +88,9 @@ __KERNEL_RCSID(0, "$NetBSD: if_le_oioc.c,v 1.5 2015/06/11 08:22:09 matt Exp $"); * bus_space_tag ... * } * - * So, we can cast any three to any other three, plus sc_dev->dv_private points - * back at the top (i.e. to le_softc, am7990_softc and lance_softc). Bloody - * hell! + * So, we can cast any three to any other three, plus + * device_private(sc_dev) points back at the top (i.e. to le_softc, + * am7990_softc and lance_softc). Bloody hell! */ struct le_softc { struct am7990_softc sc_am7990; /* glue to MI code */ diff --git a/sys/arch/sun3/dev/fbvar.h b/sys/arch/sun3/dev/fbvar.h index 50141cd7a3df..50dc4738fa97 100644 --- a/sys/arch/sun3/dev/fbvar.h +++ b/sys/arch/sun3/dev/fbvar.h @@ -53,7 +53,7 @@ struct fbdevice { struct fbtype fb_fbtype; /* see fbio.h */ struct fbdriver *fb_driver; /* pointer to driver */ void *fb_private; /* for fb driver use */ - const char *fb_name; /* i.e. sc_dev->dv_xname */ + const char *fb_name; /* i.e. device_xname(sc_dev) */ void * fb_pixels; /* display RAM */ int fb_linebytes; /* bytes per display line */ diff --git a/sys/arch/vax/vsa/lcg.c b/sys/arch/vax/vsa/lcg.c index 7b5f87bd5ed0..0f8cd8279669 100644 --- a/sys/arch/vax/vsa/lcg.c +++ b/sys/arch/vax/vsa/lcg.c @@ -991,7 +991,8 @@ lcg_init_common(struct device *self, struct vsbus_attach_args *va) if (self != NULL) { regaddr = (long*)vax_map_physmem(LCG_REG_ADDR, (LCG_REG_SIZE/VAX_NBPG)); if (regaddr == 0) { - printf("%s: Couldn't allocate register memory.\n", self->dv_xname); + device_printf(self, + "Couldn't allocate register memory.\n"); return; } } else { @@ -1061,8 +1062,9 @@ lcg_init_common(struct device *self, struct vsbus_attach_args *va) panic("LCG model not supported"); } if (self != NULL) - aprint_normal("%s: framebuffer size %dx%d, depth %d (magic 0x%x)\n", - self->dv_xname, lcg_xsize, lcg_ysize, lcg_depth, magic); + aprint_normal_dev(self, + "framebuffer size %dx%d, depth %d (magic 0x%x)\n", + lcg_xsize, lcg_ysize, lcg_depth, magic); wsfont_init(); cookie = wsfont_find(NULL, 12, 22, 0, WSDISPLAY_FONTORDER_R2L, @@ -1079,8 +1081,9 @@ lcg_init_common(struct device *self, struct vsbus_attach_args *va) lcg_cols = lcg_xsize / lcg_font.fontwidth; lcg_rows = lcg_ysize / lcg_font.fontheight; if (self != NULL) { - aprint_normal("%s: using font %s (%dx%d), ", self->dv_xname, lcg_font.name, - lcg_font.fontwidth, lcg_font.fontheight); + aprint_normal_dev(self, "using font %s (%dx%d), ", + lcg_font.name, + lcg_font.fontwidth, lcg_font.fontheight); aprint_normal("console size: %dx%d\n", lcg_cols, lcg_rows); } lcg_onerow = lcg_xsize * lcg_font.fontheight; @@ -1098,7 +1101,8 @@ lcg_init_common(struct device *self, struct vsbus_attach_args *va) lcgaddr = (void *)vax_map_physmem(va->va_paddr, ((lcg_fb_size + LCG_FONT_STORAGE_SIZE)/VAX_NBPG)); if (lcgaddr == 0) { - printf("%s: unable to allocate framebuffer memory.\n", self->dv_xname); + device_printf(self, + "unable to allocate framebuffer memory.\n"); return; } #ifndef LCG_NO_ACCEL @@ -1120,12 +1124,13 @@ lcg_init_common(struct device *self, struct vsbus_attach_args *va) lutaddr = (void *)vax_map_physmem(LCG_LUT_ADDR, (LCG_LUT_SIZE/VAX_NBPG)); if (lutaddr == 0) { - printf("%s: unable to allocate LUT memory.\n", self->dv_xname); + device_printf(self, + "unable to allocate LUT memory.\n"); return; } fifoaddr = (long*)vax_map_physmem(LCG_FIFO_WIN_ADDR, (LCG_FIFO_WIN_SIZE/VAX_NBPG)); if (regaddr == 0) { - printf("%s: unable to map FIFO window\n", self->dv_xname); + device_printf(self, "unable to map FIFO window\n"); return; } @@ -1133,16 +1138,18 @@ lcg_init_common(struct device *self, struct vsbus_attach_args *va) err = bus_dmamem_alloc(va->va_dmat, LCG_FIFO_SIZE, LCG_FIFO_ALIGN, 0, &seg, 1, &rseg, BUS_DMA_NOWAIT); if (err) { - printf("%s: unable to allocate FIFO memory block, err = %d\n", - self->dv_xname, err); + device_printf(self, + "unable to allocate FIFO memory block, err = %d\n", + err); return; } err = bus_dmamem_map(va->va_dmat, &seg, rseg, LCG_FIFO_SIZE, &fifo_mem_vaddr, BUS_DMA_NOWAIT); if (err) { - printf("%s: unable to map FIFO memory block, err = %d\n", - self->dv_xname, err); + device_printf(self, + "unable to map FIFO memory block, err = %d\n", + err); bus_dmamem_free(va->va_dmat, &seg, rseg); return; } @@ -1150,7 +1157,9 @@ lcg_init_common(struct device *self, struct vsbus_attach_args *va) err = bus_dmamap_create(va->va_dmat, LCG_FIFO_SIZE, rseg, LCG_FIFO_SIZE, 0, BUS_DMA_NOWAIT, &sc->sc_dm); if (err) { - printf("%s: unable to create DMA map, err = %d\n", self->dv_xname, err); + device_printf(self, + "unable to create DMA map, err = %d\n", + err); bus_dmamem_unmap(va->va_dmat, fifo_mem_vaddr, LCG_FIFO_SIZE); bus_dmamem_free(va->va_dmat, &seg, rseg); return; @@ -1159,7 +1168,9 @@ lcg_init_common(struct device *self, struct vsbus_attach_args *va) err = bus_dmamap_load(va->va_dmat, sc->sc_dm, fifo_mem_vaddr, LCG_FIFO_SIZE, NULL, BUS_DMA_NOWAIT); if (err) { - printf("%s: unable to load DMA map, err = %d\n", self->dv_xname, err); + device_printf(self, + "unable to load DMA map, err = %d\n", + err); bus_dmamap_destroy(va->va_dmat, sc->sc_dm); bus_dmamem_unmap(va->va_dmat, fifo_mem_vaddr, LCG_FIFO_SIZE); bus_dmamem_free(va->va_dmat, &seg, rseg); @@ -1288,6 +1299,7 @@ lcg_init_common(struct device *self, struct vsbus_attach_args *va) #ifdef LCG_DEBUG if (self != NULL) - printf("%s: video config register set 0x%08lx\n", video_conf, self->dv_xname); + device_printf(self, "video config register set 0x%08lx\n", + video_conf); #endif } diff --git a/sys/dev/i2c/ihidev.c b/sys/dev/i2c/ihidev.c index 7d0bbc19c9f7..b03e06cea0fd 100644 --- a/sys/dev/i2c/ihidev.c +++ b/sys/dev/i2c/ihidev.c @@ -204,8 +204,8 @@ ihidev_attach(device_t parent, device_t self, void *aux) if (isize > sc->sc_isize) sc->sc_isize = isize; - DPRINTF(("%s: repid %d size %d\n", sc->sc_dev.dv_xname, repid, - repsz)); + DPRINTF(("%s: repid %d size %d\n", + device_xname(sc->sc_dev), repid, repsz)); } sc->sc_ibuf = kmem_zalloc(sc->sc_isize, KM_SLEEP); if (!ihidev_intr_init(sc)) { @@ -334,14 +334,14 @@ ihidev_hid_command(struct ihidev_softc *sc, int hidcmd, void *arg, bool poll) }; DPRINTF(("%s: HID command I2C_HID_CMD_DESCR at 0x%x\n", - sc->sc_dev.dv_xname, htole16(sc->sc_hid_desc_addr))); + device_xname(sc->sc_dev), htole16(sc->sc_hid_desc_addr))); /* 20 00 */ res = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, &cmd, sizeof(cmd), &sc->hid_desc_buf, sizeof(struct i2c_hid_desc), flags); - DPRINTF(("%s: HID descriptor:", sc->sc_dev.dv_xname)); + DPRINTF(("%s: HID descriptor:", device_xname(sc->sc_dev))); for (i = 0; i < sizeof(struct i2c_hid_desc); i++) DPRINTF((" %.2x", sc->hid_desc_buf[i])); DPRINTF(("\n")); @@ -357,7 +357,7 @@ ihidev_hid_command(struct ihidev_softc *sc, int hidcmd, void *arg, bool poll) }; DPRINTF(("%s: HID command I2C_HID_CMD_RESET\n", - sc->sc_dev.dv_xname)); + device_xname(sc->sc_dev))); /* 22 00 00 01 */ res = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, @@ -385,7 +385,7 @@ ihidev_hid_command(struct ihidev_softc *sc, int hidcmd, void *arg, bool poll) uint8_t *tmprep; DPRINTF(("%s: HID command I2C_HID_CMD_GET_REPORT %d " - "(type %d, len %d)\n", sc->sc_dev.dv_xname, report_id, + "(type %d, len %d)\n", device_xname(sc->sc_dev), report_id, rreq->type, rreq->len)); /* @@ -431,7 +431,7 @@ ihidev_hid_command(struct ihidev_softc *sc, int hidcmd, void *arg, bool poll) d = tmprep[0] | tmprep[1] << 8; if (d != report_len) { DPRINTF(("%s: response size %d != expected length %d\n", - sc->sc_dev.dv_xname, d, report_len)); + device_xname(sc->sc_dev), d, report_len)); } if (report_id_len == 2) @@ -441,13 +441,13 @@ ihidev_hid_command(struct ihidev_softc *sc, int hidcmd, void *arg, bool poll) if (d != rreq->id) { DPRINTF(("%s: response report id %d != %d\n", - sc->sc_dev.dv_xname, d, rreq->id)); + device_xname(sc->sc_dev), d, rreq->id)); iic_release_bus(sc->sc_tag, 0); kmem_free(tmprep, report_len); return (1); } - DPRINTF(("%s: response:", sc->sc_dev.dv_xname)); + DPRINTF(("%s: response:", device_xname(sc->sc_dev))); for (i = 0; i < report_len; i++) DPRINTF((" %.2x", tmprep[i])); DPRINTF(("\n")); @@ -475,7 +475,7 @@ ihidev_hid_command(struct ihidev_softc *sc, int hidcmd, void *arg, bool poll) uint8_t *finalcmd; DPRINTF(("%s: HID command I2C_HID_CMD_SET_REPORT %d " - "(type %d, len %d):", sc->sc_dev.dv_xname, report_id, + "(type %d, len %d):", device_xname(sc->sc_dev), report_id, rreq->type, rreq->len)); for (i = 0; i < rreq->len; i++) DPRINTF((" %.2x", ((uint8_t *)rreq->data)[i])); @@ -540,7 +540,7 @@ ihidev_hid_command(struct ihidev_softc *sc, int hidcmd, void *arg, bool poll) }; DPRINTF(("%s: HID command I2C_HID_CMD_SET_POWER(%d)\n", - sc->sc_dev.dv_xname, power)); + device_xname(sc->sc_dev), power)); /* 22 00 00 08 */ res = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_addr, @@ -555,14 +555,15 @@ ihidev_hid_command(struct ihidev_softc *sc, int hidcmd, void *arg, bool poll) }; DPRINTF(("%s: HID command I2C_HID_REPORT_DESCR at 0x%x with " - "size %d\n", sc->sc_dev.dv_xname, cmd[0], + "size %d\n", device_xname(sc->sc_dev), cmd[0], sc->sc_reportlen)); /* 20 00 */ res = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP, sc->sc_addr, &cmd, sizeof(cmd), sc->sc_report, sc->sc_reportlen, flags); - DPRINTF(("%s: HID report descriptor:", sc->sc_dev.dv_xname)); + DPRINTF(("%s: HID report descriptor:", + device_xname(sc->sc_dev))); for (i = 0; i < sc->sc_reportlen; i++) DPRINTF((" %.2x", sc->sc_report[i])); DPRINTF(("\n")); @@ -582,7 +583,7 @@ ihidev_hid_command(struct ihidev_softc *sc, int hidcmd, void *arg, bool poll) static int ihidev_reset(struct ihidev_softc *sc, bool poll) { - DPRINTF(("%s: resetting\n", sc->sc_dev.dv_xname)); + DPRINTF(("%s: resetting\n", device_xname(sc->sc_dev))); if (ihidev_hid_command(sc, I2C_HID_CMD_SET_POWER, &I2C_HID_POWER_ON, poll)) { @@ -795,7 +796,7 @@ ihidev_work(struct work *wk, void *arg) psize = sc->sc_ibuf[0] | sc->sc_ibuf[1] << 8; if (!psize || psize > sc->sc_isize) { DPRINTF(("%s: %s: invalid packet size (%d vs. %d)\n", - sc->sc_dev.dv_xname, __func__, psize, sc->sc_isize)); + device_xname(sc->sc_dev), __func__, psize, sc->sc_isize)); goto out; } @@ -811,7 +812,7 @@ ihidev_work(struct work *wk, void *arg) goto out; } - DPRINTF(("%s: %s: hid input (rep %d):", sc->sc_dev.dv_xname, + DPRINTF(("%s: %s: hid input (rep %d):", device_xname(sc->sc_dev), __func__, rep)); for (i = 0; i < sc->sc_isize; i++) DPRINTF((" %.2x", sc->sc_ibuf[i])); @@ -884,7 +885,7 @@ ihidev_open(struct ihidev *scd) struct ihidev_softc *sc = scd->sc_parent; int error; - DPRINTF(("%s: %s: state=%d refcnt=%d\n", sc->sc_dev.dv_xname, + DPRINTF(("%s: %s: state=%d refcnt=%d\n", device_xname(sc->sc_dev), __func__, scd->sc_state, sc->sc_refcnt)); mutex_enter(&sc->sc_lock); @@ -914,7 +915,7 @@ ihidev_close(struct ihidev *scd) { struct ihidev_softc *sc = scd->sc_parent; - DPRINTF(("%s: %s: state=%d refcnt=%d\n", sc->sc_dev.dv_xname, + DPRINTF(("%s: %s: state=%d refcnt=%d\n", device_xname(sc->sc_dev), __func__, scd->sc_state, sc->sc_refcnt)); mutex_enter(&sc->sc_lock); diff --git a/sys/dev/i2c/pcagpio.c b/sys/dev/i2c/pcagpio.c index 4cf26c05a4dd..519f09eca927 100644 --- a/sys/dev/i2c/pcagpio.c +++ b/sys/dev/i2c/pcagpio.c @@ -172,9 +172,9 @@ pcagpio_attach(device_t parent, device_t self, void *aux) out &= ~sc->sc_dir; in &= sc->sc_dir; - - printdir(sc->sc_dev->dv_xname, in, sc->sc_dir, 'I'); - printdir(sc->sc_dev->dv_xname, out, ~sc->sc_dir, 'O'); + + printdir(device_xname(sc->sc_dev), in, sc->sc_dir, 'I'); + printdir(device_xname(sc->sc_dev), out, ~sc->sc_dir, 'O'); callout_init(&sc->sc_timer, CALLOUT_MPSAFE); callout_reset(&sc->sc_timer, hz*20, pcagpio_timeout, sc); @@ -246,15 +246,15 @@ pcagpio_timeout(void *v) o_in = sc->sc_in; o_out &= ~sc->sc_dir; o_in &= sc->sc_dir; - printdir(sc->sc_dev->dv_xname, o_in, sc->sc_dir, 'I'); - printdir(sc->sc_dev->dv_xname, o_out, ~sc->sc_dir, 'O'); + printdir(device_xname(sc->sc_dev), o_in, sc->sc_dir, 'I'); + printdir(device_xname(sc->sc_dev), o_out, ~sc->sc_dir, 'O'); sc->sc_state = out; sc->sc_dir = dir; sc->sc_in = in; out &= ~sc->sc_dir; in &= sc->sc_dir; - printdir(sc->sc_dev->dv_xname, in, sc->sc_dir, 'I'); - printdir(sc->sc_dev->dv_xname, out, ~sc->sc_dir, 'O'); + printdir(device_xname(sc->sc_dev), in, sc->sc_dir, 'I'); + printdir(device_xname(sc->sc_dev), out, ~sc->sc_dir, 'O'); } callout_reset(&sc->sc_timer, hz*60, pcagpio_timeout, sc); } diff --git a/sys/dev/pci/xmm7360.c b/sys/dev/pci/xmm7360.c index 04bf01188fe6..2e823beab260 100644 --- a/sys/dev/pci/xmm7360.c +++ b/sys/dev/pci/xmm7360.c @@ -143,9 +143,9 @@ typedef void * wait_queue_head_t; /* just address for tsleep() */ #ifdef __OpenBSD__ typedef struct mutex spinlock_t; #define dev_err(devp, fmt, ...) \ - printf("%s: " fmt, (devp)->dv_xname, ##__VA_ARGS__) + printf("%s: " fmt, device_xname(devp), ##__VA_ARGS__) #define dev_info(devp, fmt, ...) \ - printf("%s: " fmt, (devp)->dv_xname, ##__VA_ARGS__) + printf("%s: " fmt, device_xname(devp), ##__VA_ARGS__) #define kzalloc(size, flags) malloc(size, M_DEVBUF, M_WAITOK | M_ZERO) #define kfree(addr) free(addr, M_DEVBUF, 0) #define mutex_init(lock) mtx_init(lock, IPL_TTY) @@ -2220,9 +2220,9 @@ wwanc_attach(struct device *parent, struct device *self, void *aux) /* Device initialized, can establish the interrupt now */ sc->sc_ih = pci_intr_establish(sc->sc_pc, sc->sc_pih, IPL_NET, - wwanc_intr, sc, sc->sc_dev->dv_xname); + wwanc_intr, sc, device_xname(sc->sc_dev)); if (sc->sc_ih == NULL) { - printf("%s: can't establish interrupt\n", self->dv_xname); + device_printf(self, "can't establish interrupt\n"); return; } @@ -2353,8 +2353,8 @@ wwanc_activate(struct device *self, int act) case DVACT_SUSPEND: if (sc->sc_resume) { /* Refuse to suspend if resume still ongoing */ - printf("%s: not suspending, resume still ongoing\n", - self->dv_xname); + device_printf(self, + "not suspending, resume still ongoing\n"); return EBUSY; } @@ -2860,7 +2860,7 @@ dma_alloc_coherent(struct device *self, size_t sz, dma_addr_t *physp, int flags) BUS_DMA_WAITOK); if (error) { panic("%s: bus_dmamem_alloc(%lu) failed %d\n", - self->dv_xname, (unsigned long)sz, error); + device_xname(self), (unsigned long)sz, error); /* NOTREACHED */ } @@ -2871,7 +2871,7 @@ dma_alloc_coherent(struct device *self, size_t sz, dma_addr_t *physp, int flags) BUS_DMA_WAITOK | BUS_DMA_COHERENT); if (error) { panic("%s: bus_dmamem_alloc(%lu) failed %d\n", - self->dv_xname, (unsigned long)sz, error); + device_xname(self), (unsigned long)sz, error); /* NOTREACHED */ } From 6b22b7e9c215c1c07bb859704d7b9b956f98df64 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Tue, 8 Feb 2022 20:47:01 +0000 Subject: [PATCH 22/26] ips(4): device_t/softc split --- sys/dev/pci/ips.c | 57 +++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/sys/dev/pci/ips.c b/sys/dev/pci/ips.c index fb6864b73079..430660518551 100644 --- a/sys/dev/pci/ips.c +++ b/sys/dev/pci/ips.c @@ -419,7 +419,7 @@ struct dmamem { }; struct ips_softc { - struct device sc_dev; + device_t sc_dev; /* SCSI mid-layer connection. */ struct scsipi_adapter sc_adapt; @@ -634,6 +634,7 @@ ips_attach(struct device *parent, struct device *self, void *aux) struct scsipi_channel *chan; char intrbuf[PCI_INTRSTR_LEN]; + sc->sc_dev = self; sc->sc_dmat = pa->pa_dmat; /* Identify chipset */ @@ -738,7 +739,7 @@ ips_attach(struct device *parent, struct device *self, void *aux) } intrstr = pci_intr_string(pa->pa_pc, ih, intrbuf, sizeof(intrbuf)); if (pci_intr_establish_xname(pa->pa_pc, ih, IPL_BIO, ips_intr, sc, - sc->sc_dev.dv_xname) == NULL) { + device_xname(sc->sc_dev)) == NULL) { printf(": can't establish interrupt"); if (intrstr != NULL) printf(" at %s", intrstr); @@ -748,7 +749,7 @@ ips_attach(struct device *parent, struct device *self, void *aux) printf(": %s\n", intrstr); /* Display adapter info */ - printf("%s: ServeRAID", sc->sc_dev.dv_xname); + device_printf(sc->sc_dev, "ServeRAID"); type = htole16(pg5->type); if (type < sizeof(ips_names) / sizeof(ips_names[0]) && ips_names[type]) printf(" %s", ips_names[type]); @@ -822,7 +823,7 @@ ips_attach(struct device *parent, struct device *self, void *aux) #if NBIO > 0 /* Install ioctl handler */ if (bio_register(&sc->sc_dev, ips_ioctl)) - printf("%s: no ioctl support\n", sc->sc_dev.dv_xname); + device_printf(sc->sc_dev, "no ioctl support\n"); #endif return; @@ -854,12 +855,12 @@ ips_scsi_cmd(struct ips_ccb *ccb) int code; DPRINTF(IPS_D_XFER, ("%s: ips_scsi_cmd: xs %p, target %d, " - "opcode 0x%02x, flags 0x%x\n", sc->sc_dev.dv_xname, xs, target, + "opcode 0x%02x, flags 0x%x\n", device_xname(sc->sc_dev), xs, target, xs->cmd->opcode, xs->xs_control)); if (target >= sc->sc_nunits || periph->periph_lun != 0) { DPRINTF(IPS_D_INFO, ("%s: ips_scsi_cmd: invalid params " - "target %d, lun %d\n", sc->sc_dev.dv_xname, + "target %d, lun %d\n", device_xname(sc->sc_dev), target, periph->periph_lun)); xs->error = XS_DRIVER_STUFFUP; ips_ccb_put(sc, ccb); @@ -893,7 +894,7 @@ ips_scsi_cmd(struct ips_ccb *ccb) if (blkno >= htole32(drive->seccnt) || blkno + blkcnt > htole32(drive->seccnt)) { DPRINTF(IPS_D_ERR, ("%s: ips_scsi_cmd: invalid params " - "blkno %u, blkcnt %u\n", sc->sc_dev.dv_xname, + "blkno %u, blkcnt %u\n", device_xname(sc->sc_dev), blkno, blkcnt)); xs->error = XS_DRIVER_STUFFUP; break; @@ -912,7 +913,7 @@ ips_scsi_cmd(struct ips_ccb *ccb) if (ips_load_xs(sc, ccb, xs)) { DPRINTF(IPS_D_ERR, ("%s: ips_scsi_cmd: ips_load_xs " - "failed\n", sc->sc_dev.dv_xname)); + "failed\n", device_xname(sc->sc_dev))); xs->error = XS_DRIVER_STUFFUP; ips_ccb_put(sc, ccb); scsipi_done(xs); @@ -973,7 +974,7 @@ ips_scsi_cmd(struct ips_ccb *ccb) break; default: DPRINTF(IPS_D_INFO, ("%s: unsupported scsi command 0x%02x\n", - sc->sc_dev.dv_xname, xs->cmd->opcode)); + device_xname(sc->sc_dev), xs->cmd->opcode)); xs->error = XS_DRIVER_STUFFUP; } @@ -1044,7 +1045,7 @@ ips_ioctl(device_t dev, u_long cmd, void *data) struct ips_softc *sc = (struct ips_softc *)dev; DPRINTF(IPS_D_INFO, ("%s: ips_ioctl: cmd %lu\n", - sc->sc_dev.dv_xname, cmd)); + device_xname(sc->sc_dev), cmd)); switch (cmd) { case BIOCINQ: @@ -1066,7 +1067,7 @@ ips_ioctl_inq(struct ips_softc *sc, struct bioc_inq *bi) struct ips_conf *conf = &sc->sc_info->conf; int i; - strlcpy(bi->bi_dev, sc->sc_dev.dv_xname, sizeof(bi->bi_dev)); + strlcpy(bi->bi_dev, device_xname(sc->sc_dev), sizeof(bi->bi_dev)); bi->bi_novol = sc->sc_nunits; for (i = 0, bi->bi_nodisk = 0; i < sc->sc_nunits; i++) bi->bi_nodisk += conf->ld[i].chunkcnt; @@ -1144,7 +1145,7 @@ ips_ioctl_vol(struct ips_softc *sc, struct bioc_vol *bv) DPRINTF(IPS_D_INFO, ("%s: ips_ioctl_vol: vid %d, state 0x%02x, " "total %u, done %u, size %llu, level %d, nodisk %d, dev %s\n", - sc->sc_dev.dv_xname, vid, ld->state, total, done, bv->bv_size, + device_xname(sc->sc_dev), vid, ld->state, total, done, bv->bv_size, bv->bv_level, bv->bv_nodisk, bv->bv_dev)); return (0); @@ -1216,7 +1217,7 @@ out: } DPRINTF(IPS_D_INFO, ("%s: ips_ioctl_disk: vid %d, did %d, channel %d, " - "target %d, size %llu, state 0x%02x\n", sc->sc_dev.dv_xname, + "target %d, size %llu, state 0x%02x\n", device_xname(sc->sc_dev), vid, did, bd->bd_channel, bd->bd_target, bd->bd_size, dev->state)); return (0); @@ -1328,7 +1329,7 @@ ips_cmd(struct ips_softc *sc, struct ips_ccb *ccb) DPRINTF(IPS_D_XFER, ("%s: ips_cmd: id 0x%02x, flags 0x%x, xs %p, " "code 0x%02x, drive %d, sgcnt %d, lba %d, sgaddr 0x%08x, " - "seccnt %d\n", sc->sc_dev.dv_xname, ccb->c_id, ccb->c_flags, + "seccnt %d\n", device_xname(sc->sc_dev), ccb->c_id, ccb->c_flags, ccb->c_xfer, cmd->code, cmd->drive, cmd->sgcnt, htole32(cmd->lba), htole32(cmd->sgaddr), htole16(cmd->seccnt))); @@ -1354,7 +1355,7 @@ ips_poll(struct ips_softc *sc, struct ips_ccb *ccb) if (ccb->c_flags & XS_CTL_NOSLEEP) { /* busy-wait */ DPRINTF(IPS_D_XFER, ("%s: ips_poll: busy-wait\n", - sc->sc_dev.dv_xname)); + device_xname(sc->sc_dev))); for (timo = 10000; timo > 0; timo--) { delay(100); @@ -1370,10 +1371,11 @@ ips_poll(struct ips_softc *sc, struct ips_ccb *ccb) timo = tvtohz(&tv); DPRINTF(IPS_D_XFER, ("%s: ips_poll: sleep %d hz\n", - sc->sc_dev.dv_xname, timo)); + device_xname(sc->sc_dev), timo)); tsleep(ccb, PRIBIO + 1, "ipscmd", timo); } - DPRINTF(IPS_D_XFER, ("%s: ips_poll: state %d\n", sc->sc_dev.dv_xname, + DPRINTF(IPS_D_XFER, ("%s: ips_poll: state %d\n", + device_xname(sc->sc_dev), ccb->c_state)); if (ccb->c_state != IPS_CCB_DONE) @@ -1393,7 +1395,7 @@ void ips_done(struct ips_softc *sc, struct ips_ccb *ccb) { DPRINTF(IPS_D_XFER, ("%s: ips_done: id 0x%02x, flags 0x%x, xs %p\n", - sc->sc_dev.dv_xname, ccb->c_id, ccb->c_flags, ccb->c_xfer)); + device_xname(sc->sc_dev), ccb->c_id, ccb->c_flags, ccb->c_xfer)); ccb->c_error = ips_error(sc, ccb); ccb->c_done(sc, ccb); @@ -1488,7 +1490,7 @@ ips_error(struct ips_softc *sc, struct ips_ccb *ccb) DPRINTF(IPS_D_ERR, ("%s: ips_error: stat 0x%02x, estat 0x%02x, " "cmd code 0x%02x, drive %d, sgcnt %d, lba %u, seccnt %d", - sc->sc_dev.dv_xname, ccb->c_stat, ccb->c_estat, cmd->code, + device_xname(sc->sc_dev), ccb->c_stat, ccb->c_estat, cmd->code, cmd->drive, cmd->sgcnt, htole32(cmd->lba), htole16(cmd->seccnt))); if (cmd->code == IPS_CMD_DCDB || cmd->code == IPS_CMD_DCDB_SG) { int i; @@ -1586,7 +1588,7 @@ ips_intr(void *arg) u_int32_t status; int id; - DPRINTF(IPS_D_XFER, ("%s: ips_intr", sc->sc_dev.dv_xname)); + DPRINTF(IPS_D_XFER, ("%s: ips_intr", device_xname(sc->sc_dev))); if (!ips_isintr(sc)) { DPRINTF(IPS_D_XFER, (": not ours\n")); return (0); @@ -1596,12 +1598,12 @@ ips_intr(void *arg) /* Process completed commands */ while ((status = ips_status(sc)) != 0xffffffff) { DPRINTF(IPS_D_XFER, ("%s: ips_intr: status 0x%08x\n", - sc->sc_dev.dv_xname, status)); + device_xname(sc->sc_dev), status)); id = IPS_STAT_ID(status); if (id >= sc->sc_nccbs) { DPRINTF(IPS_D_ERR, ("%s: ips_intr: invalid id %d\n", - sc->sc_dev.dv_xname, id)); + device_xname(sc->sc_dev), id)); continue; } @@ -1609,7 +1611,7 @@ ips_intr(void *arg) if (ccb->c_state != IPS_CCB_QUEUED) { DPRINTF(IPS_D_ERR, ("%s: ips_intr: cmd 0x%02x not " "queued, state %d, status 0x%08x\n", - sc->sc_dev.dv_xname, ccb->c_id, ccb->c_state, + device_xname(sc->sc_dev), ccb->c_id, ccb->c_state, status)); continue; } @@ -1640,7 +1642,7 @@ ips_timeout(void *arg) if (xs) scsi_print_addr(xs->xs_periph); else - printf("%s: ", sc->sc_dev.dv_xname); + printf("%s: ", device_xname(sc->sc_dev)); printf("timeout\n"); /* @@ -1818,7 +1820,7 @@ ips_copperhead_exec(struct ips_softc *sc, struct ips_ccb *ccb) break; } if (timeout < 0) { - printf("%s: semaphore timeout\n", sc->sc_dev.dv_xname); + device_printf(sc->sc_dev, "semaphore timeout\n"); return; } @@ -1853,7 +1855,7 @@ ips_copperhead_status(struct ips_softc *sc) sqhead = bus_space_read_4(sc->sc_iot, sc->sc_ioh, IPS_REG_SQH); DPRINTF(IPS_D_XFER, ("%s: sqhead 0x%08x, sqtail 0x%08x\n", - sc->sc_dev.dv_xname, sqhead, sc->sc_sqtail)); + device_xname(sc->sc_dev), sqhead, sc->sc_sqtail)); sqtail = sc->sc_sqtail + sizeof(u_int32_t); if (sqtail == sc->sc_sqm.dm_paddr + IPS_SQSZ) @@ -1899,7 +1901,8 @@ ips_morpheus_status(struct ips_softc *sc) u_int32_t reg; reg = bus_space_read_4(sc->sc_iot, sc->sc_ioh, IPS_REG_OQP); - DPRINTF(IPS_D_XFER, ("%s: status 0x%08x\n", sc->sc_dev.dv_xname, reg)); + DPRINTF(IPS_D_XFER, ("%s: status 0x%08x\n", device_xname(sc->sc_dev), + reg)); return (reg); } From 691f2c612ca3061f6c8e10353255af9b30115ea9 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Tue, 8 Feb 2022 21:09:09 +0000 Subject: [PATCH 23/26] mips: Carefully use device_set_private for cpuN. But don't do it in cpu_attach_common because the callers aren't set up right -- instead leave a comment about what's wrong, to be dealt with later. --- sys/arch/evbmips/evbmips/cpu.c | 2 +- sys/arch/evbmips/ingenic/cpu.c | 2 +- sys/arch/mips/cavium/octeon_cpunode.c | 2 +- sys/arch/mips/mips/cpu_subr.c | 5 +++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sys/arch/evbmips/evbmips/cpu.c b/sys/arch/evbmips/evbmips/cpu.c index 0e09d41bc180..c031670f1adc 100644 --- a/sys/arch/evbmips/evbmips/cpu.c +++ b/sys/arch/evbmips/evbmips/cpu.c @@ -64,7 +64,7 @@ cpu_attach(device_t parent, device_t self, void *aux) struct cpu_info * const ci = curcpu(); ci->ci_dev = self; - self->dv_private = ci; + device_set_private(self, ci); aprint_normal(": %lu.%02luMHz (hz cycles = %lu, delay divisor = %lu)\n", ci->ci_cpu_freq / 1000000, diff --git a/sys/arch/evbmips/ingenic/cpu.c b/sys/arch/evbmips/ingenic/cpu.c index 5eae1939b3b5..2dc0f11569e5 100644 --- a/sys/arch/evbmips/ingenic/cpu.c +++ b/sys/arch/evbmips/ingenic/cpu.c @@ -113,7 +113,7 @@ cpu_attach(device_t parent, device_t self, void *aux) } ci->ci_dev = self; - self->dv_private = ci; + device_set_private(self, ci); aprint_normal(": %lu.%02luMHz (hz cycles = %lu, delay divisor = %lu)\n", ci->ci_cpu_freq / 1000000, diff --git a/sys/arch/mips/cavium/octeon_cpunode.c b/sys/arch/mips/cavium/octeon_cpunode.c index b3e09ba996ee..6a4fc1ec5073 100644 --- a/sys/arch/mips/cavium/octeon_cpunode.c +++ b/sys/arch/mips/cavium/octeon_cpunode.c @@ -252,7 +252,7 @@ cpu_cpunode_attach_common(device_t self, struct cpu_info *ci) struct cpu_softc * const cpu __diagused = ci->ci_softc; ci->ci_dev = self; - self->dv_private = ci; + device_set_private(self, ci); KASSERTMSG(cpu != NULL, "ci %p index %d", ci, cpu_index(ci)); diff --git a/sys/arch/mips/mips/cpu_subr.c b/sys/arch/mips/mips/cpu_subr.c index 0af5338f79a6..ced26719e572 100644 --- a/sys/arch/mips/mips/cpu_subr.c +++ b/sys/arch/mips/mips/cpu_subr.c @@ -236,6 +236,11 @@ cpu_attach_common(device_t self, struct cpu_info *ci) /* * Cross link cpu_info and its device together + * + * XXX autoconf abuse: Can't use device_set_private here + * because some callers already do so -- and some callers + * (sbmips cpu_attach) already have a softc allocated by + * autoconf. */ ci->ci_dev = self; self->dv_private = ci; From 942b6d06a678aed9db0466f917175b47f2f26da7 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Tue, 8 Feb 2022 21:12:50 +0000 Subject: [PATCH 24/26] veriexec(4): Omit needless device crud in veriexec.c. --- sys/dev/veriexec.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/sys/dev/veriexec.c b/sys/dev/veriexec.c index 767387298cc5..873d0632ee1a 100644 --- a/sys/dev/veriexec.c +++ b/sys/dev/veriexec.c @@ -43,8 +43,7 @@ __KERNEL_RCSID(0, "$NetBSD: veriexec.c,v 1.2 2021/06/21 03:11:05 christos Exp $" #include <sys/proc.h> #include <sys/ioctl.h> -#include <sys/device.h> -#define DEVPORT_DEVICE struct device +#include <sys/device_if.h> #include <prop/proplib.h> @@ -53,10 +52,6 @@ static dev_type_open(veriexecopen); static dev_type_close(veriexecclose); static dev_type_ioctl(veriexecioctl); -struct veriexec_softc { - DEVPORT_DEVICE veriexec_dev; -}; - const struct cdevsw veriexec_cdevsw = { .d_open = veriexecopen, .d_close = veriexecclose, @@ -76,7 +71,7 @@ const struct cdevsw veriexec_cdevsw = { static unsigned int veriexec_dev_usage = 0; void -veriexecattach(DEVPORT_DEVICE *parent, DEVPORT_DEVICE *self, void *aux) +veriexecattach(device_t parent, device_t self, void *aux) { veriexec_dev_usage = 0; } From 36f485f9956eba6f0ce9ccafd828fc3397b4c3db Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Tue, 8 Feb 2022 21:23:22 +0000 Subject: [PATCH 25/26] drvctl(4): Use the public autoconf API, not struct device internals. --- sys/kern/kern_drvctl.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/sys/kern/kern_drvctl.c b/sys/kern/kern_drvctl.c index 8a4156f8a0aa..5ecd3a6cdcb5 100644 --- a/sys/kern/kern_drvctl.c +++ b/sys/kern/kern_drvctl.c @@ -277,7 +277,8 @@ detachdevbyname(const char *devname) * There might be a private notification mechanism, * but better play it safe here. */ - if (d->dv_parent && !d->dv_parent->dv_cfattach->ca_childdetached) { + if (device_parent(d) && + !device_cfattach(device_parent(d))->ca_childdetached) { error = ENOTSUP; goto out; } @@ -314,27 +315,27 @@ rescanbus(const char *busname, const char *ifattr, * must support rescan, and must have something * to attach to */ - if (!d->dv_cfattach->ca_rescan || - !d->dv_cfdriver->cd_attrs) + if (!device_cfattach(d)->ca_rescan || + !device_cfdriver(d)->cd_attrs) return ENODEV; /* rescan all ifattrs if none is specified */ if (!ifattr) { rc = 0; - for (ap = d->dv_cfdriver->cd_attrs; *ap; ap++) { - rc = (*d->dv_cfattach->ca_rescan)(d, (*ap)->ci_name, - locs); + for (ap = device_cfdriver(d)->cd_attrs; *ap; ap++) { + rc = (*device_cfattach(d)->ca_rescan)(d, + (*ap)->ci_name, locs); if (rc) break; } } else { /* check for valid attribute passed */ - for (ap = d->dv_cfdriver->cd_attrs; *ap; ap++) + for (ap = device_cfdriver(d)->cd_attrs; *ap; ap++) if (!strcmp((*ap)->ci_name, ifattr)) break; if (!*ap) return EINVAL; - rc = (*d->dv_cfattach->ca_rescan)(d, ifattr, locs); + rc = (*device_cfattach(d)->ca_rescan)(d, ifattr, locs); } config_deferred(NULL); From 1fbd21189e87994209a6a7a473b31c4f896690ef Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastradh@NetBSD.org> Date: Tue, 8 Feb 2022 21:19:24 +0000 Subject: [PATCH 26/26] sys: Split struct device into a private device_impl.h. Include this only inside autoconf itself, and a few files that abuse autoconf in ways I can't confidently make easy fixes for. --- sys/arch/amiga/amiga/autoconf.c | 1 + sys/arch/amiga/dev/grf_cc.c | 1 + sys/arch/amiga/dev/grf_cl.c | 1 + sys/arch/amiga/dev/grf_cv.c | 1 + sys/arch/amiga/dev/grf_cv3d.c | 1 + sys/arch/amiga/dev/grf_et.c | 1 + sys/arch/amiga/dev/grf_rh.c | 1 + sys/arch/amiga/dev/grf_rt.c | 1 + sys/arch/amiga/dev/grf_ul.c | 1 + sys/arch/amigappc/amigappc/autoconf.c | 1 + sys/arch/arm/iomd/iomdiic.c | 1 + sys/arch/atari/atari/autoconf.c | 1 + sys/arch/atari/dev/ite_cc.c | 1 + sys/arch/atari/dev/ite_et.c | 1 + sys/arch/dreamcast/dev/maple/maple.c | 1 + sys/arch/mips/mips/cpu_subr.c | 1 + sys/ddb/db_autoconf.c | 1 + sys/dev/wscons/wsmux.c | 1 + sys/kern/kern_pmf.c | 1 + sys/kern/subr_autoconf.c | 1 + sys/kern/subr_device.c | 1 + sys/rump/librump/rumpkern/rump.c | 1 + sys/sys/device.h | 69 ++------------------------- 23 files changed, 27 insertions(+), 64 deletions(-) diff --git a/sys/arch/amiga/amiga/autoconf.c b/sys/arch/amiga/amiga/autoconf.c index 3f548fd68bdd..d59e6c7eb7f8 100644 --- a/sys/arch/amiga/amiga/autoconf.c +++ b/sys/arch/amiga/amiga/autoconf.c @@ -39,6 +39,7 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.120 2021/08/07 16:18:41 thorpej Exp $ #include <sys/conf.h> #include <sys/buf.h> #include <sys/device.h> +#include <sys/device_impl.h> /* XXX autoconf abuse */ #include <sys/disklabel.h> #include <sys/disk.h> #include <sys/proc.h> diff --git a/sys/arch/amiga/dev/grf_cc.c b/sys/arch/amiga/dev/grf_cc.c index f12724264900..aecc72ec818f 100644 --- a/sys/arch/amiga/dev/grf_cc.c +++ b/sys/arch/amiga/dev/grf_cc.c @@ -47,6 +47,7 @@ __KERNEL_RCSID(0, "$NetBSD: grf_cc.c,v 1.43 2021/08/07 16:18:41 thorpej Exp $"); #include <sys/ioctl.h> #include <sys/queue.h> #include <sys/device.h> +#include <sys/device_impl.h> /* XXX autoconf abuse */ #include <sys/systm.h> #include <sys/conf.h> #include <machine/cpu.h> diff --git a/sys/arch/amiga/dev/grf_cl.c b/sys/arch/amiga/dev/grf_cl.c index 5f9b129ef4ea..ade94ccd3ee5 100644 --- a/sys/arch/amiga/dev/grf_cl.c +++ b/sys/arch/amiga/dev/grf_cl.c @@ -78,6 +78,7 @@ __KERNEL_RCSID(0, "$NetBSD: grf_cl.c,v 1.54 2021/12/26 16:08:19 andvar Exp $"); #include <sys/errno.h> #include <sys/ioctl.h> #include <sys/device.h> +#include <sys/device_impl.h> /* XXX autoconf abuse */ #include <sys/malloc.h> #include <machine/cpu.h> diff --git a/sys/arch/amiga/dev/grf_cv.c b/sys/arch/amiga/dev/grf_cv.c index 7a3d60e1d63f..373a63fe9438 100644 --- a/sys/arch/amiga/dev/grf_cv.c +++ b/sys/arch/amiga/dev/grf_cv.c @@ -57,6 +57,7 @@ __KERNEL_RCSID(0, "$NetBSD: grf_cv.c,v 1.63 2022/01/01 11:45:37 msaitoh Exp $"); #include <sys/errno.h> #include <sys/ioctl.h> #include <sys/device.h> +#include <sys/device_impl.h> /* XXX autoconf abuse */ #include <sys/malloc.h> #include <sys/systm.h> #include <sys/syslog.h> diff --git a/sys/arch/amiga/dev/grf_cv3d.c b/sys/arch/amiga/dev/grf_cv3d.c index f42ca5ad334e..f7bbd4360d8d 100644 --- a/sys/arch/amiga/dev/grf_cv3d.c +++ b/sys/arch/amiga/dev/grf_cv3d.c @@ -81,6 +81,7 @@ Note: IO Regbase is needed for wakeup of the board otherwise use #include <sys/errno.h> #include <sys/ioctl.h> #include <sys/device.h> +#include <sys/device_impl.h> /* XXX autoconf abuse */ #include <sys/malloc.h> #include <sys/systm.h> #include <sys/bus.h> diff --git a/sys/arch/amiga/dev/grf_et.c b/sys/arch/amiga/dev/grf_et.c index f41f3229435a..2219b99d4b26 100644 --- a/sys/arch/amiga/dev/grf_et.c +++ b/sys/arch/amiga/dev/grf_et.c @@ -69,6 +69,7 @@ __KERNEL_RCSID(0, "$NetBSD: grf_et.c,v 1.39 2021/12/26 16:08:19 andvar Exp $"); #include <sys/errno.h> #include <sys/ioctl.h> #include <sys/device.h> +#include <sys/device_impl.h> /* XXX autoconf abuse */ #include <sys/malloc.h> #include <machine/cpu.h> diff --git a/sys/arch/amiga/dev/grf_rh.c b/sys/arch/amiga/dev/grf_rh.c index 99dbbf5dc2cf..ca67fdf1c5a3 100644 --- a/sys/arch/amiga/dev/grf_rh.c +++ b/sys/arch/amiga/dev/grf_rh.c @@ -50,6 +50,7 @@ __KERNEL_RCSID(0, "$NetBSD: grf_rh.c,v 1.60 2021/08/09 21:13:05 andvar Exp $"); #include <sys/errno.h> #include <sys/ioctl.h> #include <sys/device.h> +#include <sys/device_impl.h> /* XXX autoconf abuse */ #include <sys/malloc.h> #include <machine/cpu.h> #include <amiga/amiga/device.h> diff --git a/sys/arch/amiga/dev/grf_rt.c b/sys/arch/amiga/dev/grf_rt.c index e5b2db788f15..8d7cf71e374c 100644 --- a/sys/arch/amiga/dev/grf_rt.c +++ b/sys/arch/amiga/dev/grf_rt.c @@ -47,6 +47,7 @@ __KERNEL_RCSID(0, "$NetBSD: grf_rt.c,v 1.60 2021/08/07 16:18:41 thorpej Exp $"); #include <sys/errno.h> #include <sys/ioctl.h> #include <sys/device.h> +#include <sys/device_impl.h> /* XXX autoconf abuse */ #include <machine/cpu.h> #include <amiga/amiga/device.h> #include <amiga/dev/zbusvar.h> diff --git a/sys/arch/amiga/dev/grf_ul.c b/sys/arch/amiga/dev/grf_ul.c index 2e9eed2b0164..3cba97c339ac 100644 --- a/sys/arch/amiga/dev/grf_ul.c +++ b/sys/arch/amiga/dev/grf_ul.c @@ -47,6 +47,7 @@ __KERNEL_RCSID(0, "$NetBSD: grf_ul.c,v 1.53 2021/08/07 16:18:41 thorpej Exp $"); #include <sys/errno.h> #include <sys/ioctl.h> #include <sys/device.h> +#include <sys/device_impl.h> /* XXX autoconf abuse */ #include <sys/malloc.h> #include <sys/syslog.h> diff --git a/sys/arch/amigappc/amigappc/autoconf.c b/sys/arch/amigappc/amigappc/autoconf.c index decf6df0677a..c7520f77dab6 100644 --- a/sys/arch/amigappc/amigappc/autoconf.c +++ b/sys/arch/amigappc/amigappc/autoconf.c @@ -39,6 +39,7 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.9 2021/08/07 16:18:42 thorpej Exp $") #include <sys/conf.h> #include <sys/buf.h> #include <sys/device.h> +#include <sys/device_impl.h> /* XXX autoconf abuse */ #include <sys/disklabel.h> #include <sys/disk.h> #include <sys/proc.h> diff --git a/sys/arch/arm/iomd/iomdiic.c b/sys/arch/arm/iomd/iomdiic.c index 483619edb032..9dd8c8a855cd 100644 --- a/sys/arch/arm/iomd/iomdiic.c +++ b/sys/arch/arm/iomd/iomdiic.c @@ -37,6 +37,7 @@ #include <sys/param.h> #include <sys/device.h> +#include <sys/device_impl.h> /* XXX autoconf abuse */ #include <sys/kernel.h> #include <sys/systm.h> #include <sys/mutex.h> diff --git a/sys/arch/atari/atari/autoconf.c b/sys/arch/atari/atari/autoconf.c index 5ed2c9964932..ec1d8ed58c31 100644 --- a/sys/arch/atari/atari/autoconf.c +++ b/sys/arch/atari/atari/autoconf.c @@ -41,6 +41,7 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.71 2021/08/07 16:18:46 thorpej Exp $" #include <sys/conf.h> #include <sys/buf.h> #include <sys/device.h> +#include <sys/device_impl.h> /* XXX autoconf abuse */ #include <sys/disklabel.h> #include <sys/disk.h> #include <sys/kmem.h> diff --git a/sys/arch/atari/dev/ite_cc.c b/sys/arch/atari/dev/ite_cc.c index 7bd1b2f85261..27d45b6f3516 100644 --- a/sys/arch/atari/dev/ite_cc.c +++ b/sys/arch/atari/dev/ite_cc.c @@ -44,6 +44,7 @@ __KERNEL_RCSID(0, "$NetBSD: ite_cc.c,v 1.43 2021/08/07 16:18:46 thorpej Exp $"); #include <sys/termios.h> #include <sys/malloc.h> #include <sys/device.h> +#include <sys/device_impl.h> /* XXX autoconf abuse */ #include <dev/cons.h> #include <machine/cpu.h> #include <atari/atari/device.h> diff --git a/sys/arch/atari/dev/ite_et.c b/sys/arch/atari/dev/ite_et.c index 8841f8253b2b..5ab3944c9fda 100644 --- a/sys/arch/atari/dev/ite_et.c +++ b/sys/arch/atari/dev/ite_et.c @@ -34,6 +34,7 @@ __KERNEL_RCSID(0, "$NetBSD: ite_et.c,v 1.34 2021/08/07 16:18:46 thorpej Exp $"); #include <sys/ioctl.h> #include <sys/malloc.h> #include <sys/device.h> +#include <sys/device_impl.h> /* XXX autoconf abuse */ #include <dev/cons.h> #include <machine/cpu.h> diff --git a/sys/arch/dreamcast/dev/maple/maple.c b/sys/arch/dreamcast/dev/maple/maple.c index 87abe5527c7e..4c1cb97f23bd 100644 --- a/sys/arch/dreamcast/dev/maple/maple.c +++ b/sys/arch/dreamcast/dev/maple/maple.c @@ -66,6 +66,7 @@ __KERNEL_RCSID(0, "$NetBSD: maple.c,v 1.55 2021/08/07 16:18:48 thorpej Exp $"); #include <sys/param.h> #include <sys/device.h> +#include <sys/device_impl.h> /* XXX autoconf abuse */ #include <sys/fcntl.h> #include <sys/kernel.h> #include <sys/kthread.h> diff --git a/sys/arch/mips/mips/cpu_subr.c b/sys/arch/mips/mips/cpu_subr.c index ced26719e572..7cd71287a970 100644 --- a/sys/arch/mips/mips/cpu_subr.c +++ b/sys/arch/mips/mips/cpu_subr.c @@ -42,6 +42,7 @@ __KERNEL_RCSID(0, "$NetBSD: cpu_subr.c,v 1.59 2021/11/16 06:11:52 simonb Exp $") #include <sys/bitops.h> #include <sys/cpu.h> #include <sys/device.h> +#include <sys/device_impl.h> /* XXX autoconf abuse */ #include <sys/idle.h> #include <sys/intr.h> #include <sys/ipi.h> diff --git a/sys/ddb/db_autoconf.c b/sys/ddb/db_autoconf.c index 0a0ca58eb9d6..f894b851cc0b 100644 --- a/sys/ddb/db_autoconf.c +++ b/sys/ddb/db_autoconf.c @@ -35,6 +35,7 @@ __KERNEL_RCSID(0, "$NetBSD: db_autoconf.c,v 1.2 2018/03/05 07:47:21 mlelstv Exp #include <sys/param.h> #include <sys/device.h> +#include <sys/device_impl.h> #include <ddb/ddb.h> diff --git a/sys/dev/wscons/wsmux.c b/sys/dev/wscons/wsmux.c index 890e9b9486fa..cbf11d607d02 100644 --- a/sys/dev/wscons/wsmux.c +++ b/sys/dev/wscons/wsmux.c @@ -63,6 +63,7 @@ __KERNEL_RCSID(0, "$NetBSD: wsmux.c,v 1.65 2021/11/10 16:57:39 msaitoh Exp $"); #include <sys/tty.h> #include <sys/signalvar.h> #include <sys/device.h> +#include <sys/device_impl.h> /* XXX autoconf abuse */ #include "opt_wsdisplay_compat.h" diff --git a/sys/kern/kern_pmf.c b/sys/kern/kern_pmf.c index d47939a5a631..119bd0645df5 100644 --- a/sys/kern/kern_pmf.c +++ b/sys/kern/kern_pmf.c @@ -36,6 +36,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_pmf.c,v 1.47 2021/07/01 22:08:13 blymn Exp $"); #include <sys/callout.h> #include <sys/kernel.h> #include <sys/device.h> +#include <sys/device_impl.h> #include <sys/pmf.h> #include <sys/queue.h> #include <sys/sched.h> diff --git a/sys/kern/subr_autoconf.c b/sys/kern/subr_autoconf.c index f6d443e9f1f6..8760a90cef71 100644 --- a/sys/kern/subr_autoconf.c +++ b/sys/kern/subr_autoconf.c @@ -86,6 +86,7 @@ __KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.291 2021/12/31 14:19:57 riastrad #include <sys/param.h> #include <sys/device.h> +#include <sys/device_impl.h> #include <sys/disklabel.h> #include <sys/conf.h> #include <sys/kauth.h> diff --git a/sys/kern/subr_device.c b/sys/kern/subr_device.c index 4657f02f04ea..e653cfe2b716 100644 --- a/sys/kern/subr_device.c +++ b/sys/kern/subr_device.c @@ -31,6 +31,7 @@ __KERNEL_RCSID(0, "$NetBSD: subr_device.c,v 1.11 2022/01/22 11:58:15 thorpej Exp #include <sys/param.h> #include <sys/device.h> +#include <sys/device_impl.h> #include <sys/systm.h> #include <sys/device_calls.h> diff --git a/sys/rump/librump/rumpkern/rump.c b/sys/rump/librump/rumpkern/rump.c index c36015ed3445..12dff1c95fbd 100644 --- a/sys/rump/librump/rumpkern/rump.c +++ b/sys/rump/librump/rumpkern/rump.c @@ -38,6 +38,7 @@ __KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.353 2021/01/17 22:32:25 chs Exp $"); #include <sys/conf.h> #include <sys/cpu.h> #include <sys/device.h> +#include <sys/device_impl.h> #include <sys/evcnt.h> #include <sys/event.h> #include <sys/exec_elf.h> diff --git a/sys/sys/device.h b/sys/sys/device.h index 96bd9931ec32..6b7ada29decf 100644 --- a/sys/sys/device.h +++ b/sys/sys/device.h @@ -255,72 +255,13 @@ struct devhandle_impl { /* Max size of a device external name (including terminating NUL) */ #define DEVICE_XNAME_SIZE 16 -struct device { - devhandle_t dv_handle; /* this device's handle; - new device_t's get INVALID */ - devclass_t dv_class; /* this device's classification */ - TAILQ_ENTRY(device) dv_list; /* entry on list of all devices */ - cfdata_t dv_cfdata; /* config data that found us - (NULL if pseudo-device) */ - cfdriver_t dv_cfdriver; /* our cfdriver */ - cfattach_t dv_cfattach; /* our cfattach */ - int dv_unit; /* device unit number */ - /* external name (name + unit) */ - char dv_xname[DEVICE_XNAME_SIZE]; - device_t dv_parent; /* pointer to parent device - (NULL if pseudo- or root node) */ - int dv_depth; /* number of parents until root */ - int dv_flags; /* misc. flags; see below */ - void *dv_private; /* this device's private storage */ - int *dv_locators; /* our actual locators (optional) */ - prop_dictionary_t dv_properties;/* properties dictionary */ - struct localcount *dv_localcount;/* reference count */ - - int dv_pending; /* config_pending count */ - TAILQ_ENTRY(device) dv_pending_list; - - struct lwp *dv_attaching; /* thread not yet finished in attach */ - struct lwp *dv_detaching; /* detach lock (config_misc_lock/cv) */ - bool dv_detached; /* config_misc_lock */ - - size_t dv_activity_count; - void (**dv_activity_handlers)(device_t, devactive_t); - - bool (*dv_driver_suspend)(device_t, const pmf_qual_t *); - bool (*dv_driver_resume)(device_t, const pmf_qual_t *); - bool (*dv_driver_shutdown)(device_t, int); - bool (*dv_driver_child_register)(device_t); - - void *dv_bus_private; - bool (*dv_bus_suspend)(device_t, const pmf_qual_t *); - bool (*dv_bus_resume)(device_t, const pmf_qual_t *); - bool (*dv_bus_shutdown)(device_t, int); - void (*dv_bus_deregister)(device_t); - - void *dv_class_private; - bool (*dv_class_suspend)(device_t, const pmf_qual_t *); - bool (*dv_class_resume)(device_t, const pmf_qual_t *); - void (*dv_class_deregister)(device_t); - - devgen_t dv_add_gen, - dv_del_gen; - - struct device_lock dv_lock; - const device_suspensor_t - *dv_bus_suspensors[DEVICE_SUSPENSORS_MAX], - *dv_driver_suspensors[DEVICE_SUSPENSORS_MAX], - *dv_class_suspensors[DEVICE_SUSPENSORS_MAX]; - struct device_garbage dv_garbage; -}; +struct device; -/* dv_flags */ -#define DVF_ACTIVE 0x0001 /* device is activated */ +/* + * struct cfattach::ca_flags (must not overlap with device_impl.h + * struct device::dv_flags for now) + */ #define DVF_PRIV_ALLOC 0x0002 /* device private storage != device */ -#define DVF_POWER_HANDLERS 0x0004 /* device has suspend/resume support */ -#define DVF_CLASS_SUSPENDED 0x0008 /* device class suspend was called */ -#define DVF_DRIVER_SUSPENDED 0x0010 /* device driver suspend was called */ -#define DVF_BUS_SUSPENDED 0x0020 /* device bus suspend was called */ -#define DVF_ATTACH_INPROGRESS 0x0040 /* device attach is in progress */ #define DVF_DETACH_SHUTDOWN 0x0080 /* device detaches safely at shutdown */ #ifdef _KERNEL