Index: sys/dev/smc/if_smc.c =================================================================== --- sys/dev/smc/if_smc.c +++ sys/dev/smc/if_smc.c @@ -80,6 +80,8 @@ #include #include +#include "miibus_if.h" + #define SMC_LOCK(sc) mtx_lock(&(sc)->smc_mtx) #define SMC_UNLOCK(sc) mtx_unlock(&(sc)->smc_mtx) #define SMC_ASSERT_LOCKED(sc) mtx_assert(&(sc)->smc_mtx, MA_OWNED) @@ -480,6 +482,27 @@ return (0); } +static device_method_t smc_methods[] = { + /* Device interface */ + DEVMETHOD(device_attach, smc_attach), + DEVMETHOD(device_detach, smc_detach), + + /* MII interface */ + DEVMETHOD(miibus_readreg, smc_miibus_readreg), + DEVMETHOD(miibus_writereg, smc_miibus_writereg), + DEVMETHOD(miibus_statchg, smc_miibus_statchg), + + { 0, 0 } +}; + +driver_t smc_driver = { + "smc", + smc_methods, + sizeof(struct smc_softc), +}; + +DRIVER_MODULE(miibus, smc, miibus_driver, miibus_devclass, 0, 0); + static void smc_start(struct ifnet *ifp) { Index: sys/dev/smc/if_smc_acpi.c =================================================================== --- sys/dev/smc/if_smc_acpi.c +++ sys/dev/smc/if_smc_acpi.c @@ -1,6 +1,7 @@ /*- * Copyright (c) 2008 Benno Rice * All rights reserved. + * Copyright (c) 2020 Andrew Turner * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -35,92 +36,45 @@ #include #include -#include -#include - -#include #include -#include -#include #include -#include -#include - -#include -#include -#include -#include - -#include "miibus_if.h" +#include +#include -static int smc_fdt_probe(device_t); -static int smc_fdt_attach(device_t); -static int smc_fdt_detach(device_t); +static int smc_acpi_probe(device_t); static int -smc_fdt_probe(device_t dev) +smc_acpi_probe(device_t dev) { struct smc_softc *sc; + ACPI_HANDLE h; - if (!ofw_bus_status_okay(dev)) + if ((h = acpi_get_handle(dev)) == NULL) return (ENXIO); - if (ofw_bus_is_compatible(dev, "smsc,lan91c111")) { - sc = device_get_softc(dev); - sc->smc_usemem = 1; - - if (smc_probe(dev) != 0) { - return (ENXIO); - } - - return (0); - } - - return (ENXIO); -} - -static int -smc_fdt_attach(device_t dev) -{ - - return smc_attach(dev); -} - -static int -smc_fdt_detach(device_t dev) -{ + if (!acpi_MatchHid(h, "LNRO0003")) + return (ENXIO); - smc_detach(dev); + sc = device_get_softc(dev); + sc->smc_usemem = 1; - return (0); + return (smc_probe(dev)); } -static device_method_t smc_fdt_methods[] = { +static device_method_t smc_acpi_methods[] = { /* Device interface */ - DEVMETHOD(device_probe, smc_fdt_probe), - DEVMETHOD(device_attach, smc_fdt_attach), - DEVMETHOD(device_detach, smc_fdt_detach), - - /* MII interface */ - DEVMETHOD(miibus_readreg, smc_miibus_readreg), - DEVMETHOD(miibus_writereg, smc_miibus_writereg), - DEVMETHOD(miibus_statchg, smc_miibus_statchg), - + DEVMETHOD(device_probe, smc_acpi_probe), { 0, 0 } }; -static driver_t smc_fdt_driver = { - "smc", - smc_fdt_methods, - sizeof(struct smc_softc), -}; +DEFINE_CLASS_1(smc, smc_acpi_driver, smc_acpi_methods, + sizeof(struct smc_softc), smc_driver); extern devclass_t smc_devclass; -DRIVER_MODULE(smc, simplebus, smc_fdt_driver, smc_devclass, 0, 0); -DRIVER_MODULE(miibus, smc, miibus_driver, miibus_devclass, 0, 0); -MODULE_DEPEND(smc, fdt, 1, 1, 1); +DRIVER_MODULE(smc, acpi, smc_acpi_driver, smc_devclass, 0, 0); +MODULE_DEPEND(smc, acpi, 1, 1, 1); MODULE_DEPEND(smc, ether, 1, 1, 1); MODULE_DEPEND(smc, miibus, 1, 1, 1); Index: sys/dev/smc/if_smc_fdt.c =================================================================== --- sys/dev/smc/if_smc_fdt.c +++ sys/dev/smc/if_smc_fdt.c @@ -35,29 +35,16 @@ #include #include -#include -#include - -#include #include -#include -#include #include -#include -#include - #include #include #include #include -#include "miibus_if.h" - static int smc_fdt_probe(device_t); -static int smc_fdt_attach(device_t); -static int smc_fdt_detach(device_t); static int smc_fdt_probe(device_t dev) @@ -81,46 +68,18 @@ return (ENXIO); } -static int -smc_fdt_attach(device_t dev) -{ - - return smc_attach(dev); -} - -static int -smc_fdt_detach(device_t dev) -{ - - smc_detach(dev); - - return (0); -} - static device_method_t smc_fdt_methods[] = { /* Device interface */ DEVMETHOD(device_probe, smc_fdt_probe), - DEVMETHOD(device_attach, smc_fdt_attach), - DEVMETHOD(device_detach, smc_fdt_detach), - - /* MII interface */ - DEVMETHOD(miibus_readreg, smc_miibus_readreg), - DEVMETHOD(miibus_writereg, smc_miibus_writereg), - DEVMETHOD(miibus_statchg, smc_miibus_statchg), - { 0, 0 } }; -static driver_t smc_fdt_driver = { - "smc", - smc_fdt_methods, - sizeof(struct smc_softc), -}; +DEFINE_CLASS_1(smc, smc_fdt_driver, smc_fdt_methods, + sizeof(struct smc_softc), smc_driver); extern devclass_t smc_devclass; DRIVER_MODULE(smc, simplebus, smc_fdt_driver, smc_devclass, 0, 0); -DRIVER_MODULE(miibus, smc, miibus_driver, miibus_devclass, 0, 0); MODULE_DEPEND(smc, fdt, 1, 1, 1); MODULE_DEPEND(smc, ether, 1, 1, 1); MODULE_DEPEND(smc, miibus, 1, 1, 1); Index: sys/dev/smc/if_smcvar.h =================================================================== --- sys/dev/smc/if_smcvar.h +++ sys/dev/smc/if_smcvar.h @@ -68,6 +68,8 @@ void *smc_read_arg; }; +DECLARE_CLASS(smc_driver); + int smc_probe(device_t); int smc_attach(device_t); int smc_detach(device_t);