diff options
author | Andrew Turner <andrew@FreeBSD.org> | 2020-07-28 09:29:56 +0000 |
---|---|---|
committer | Andrew Turner <andrew@FreeBSD.org> | 2020-07-28 09:29:56 +0000 |
commit | 22b33ca4b22e960dab4724b61ca137b078cf3069 (patch) | |
tree | ac32384ee0be774f267b41e737d96af2e8c84442 | |
parent | 24e337bec5a5b3bc6e7eba6cda818ef5a8b7c625 (diff) | |
download | src-22b33ca4b22e960dab4724b61ca137b078cf3069.tar.gz src-22b33ca4b22e960dab4724b61ca137b078cf3069.zip |
Add an ACPI attachment for if_smc
This is needed by some of the Arm simulators as they implement a smc based
network interface, but use ACPI rather than FDT.
Sponsored by: Innovate UK
Notes
Notes:
svn path=/head/; revision=363636
-rw-r--r-- | sys/conf/files | 1 | ||||
-rw-r--r-- | sys/dev/smc/if_smc.c | 23 | ||||
-rw-r--r-- | sys/dev/smc/if_smc_acpi.c | 80 | ||||
-rw-r--r-- | sys/dev/smc/if_smc_fdt.c | 45 | ||||
-rw-r--r-- | sys/dev/smc/if_smcvar.h | 2 |
5 files changed, 108 insertions, 43 deletions
diff --git a/sys/conf/files b/sys/conf/files index dd9b4bfa8581..59ef9368419e 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -3029,6 +3029,7 @@ dev/smbus/smbconf.c optional smbus dev/smbus/smbus.c optional smbus dev/smbus/smbus_if.m optional smbus dev/smc/if_smc.c optional smc +dev/smc/if_smc_acpi.c optional smc acpi dev/smc/if_smc_fdt.c optional smc fdt dev/snp/snp.c optional snp dev/sound/clone.c optional sound diff --git a/sys/dev/smc/if_smc.c b/sys/dev/smc/if_smc.c index d3f911d8327c..627787eab641 100644 --- a/sys/dev/smc/if_smc.c +++ b/sys/dev/smc/if_smc.c @@ -80,6 +80,8 @@ __FBSDID("$FreeBSD$"); #include <dev/mii/mii_bitbang.h> #include <dev/mii/miivar.h> +#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 @@ smc_detach(device_t dev) 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) { diff --git a/sys/dev/smc/if_smc_acpi.c b/sys/dev/smc/if_smc_acpi.c new file mode 100644 index 000000000000..74f591493167 --- /dev/null +++ b/sys/dev/smc/if_smc_acpi.c @@ -0,0 +1,80 @@ +/*- + * 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 + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/param.h> +#include <sys/bus.h> +#include <sys/kernel.h> +#include <sys/module.h> +#include <sys/socket.h> +#include <sys/systm.h> +#include <sys/taskqueue.h> + +#include <net/if.h> + +#include <dev/smc/if_smcvar.h> + +#include <contrib/dev/acpica/include/acpi.h> +#include <dev/acpica/acpivar.h> + +static int smc_acpi_probe(device_t); + +static int +smc_acpi_probe(device_t dev) +{ + struct smc_softc *sc; + ACPI_HANDLE h; + + if ((h = acpi_get_handle(dev)) == NULL) + return (ENXIO); + + if (!acpi_MatchHid(h, "LNRO0003")) + return (ENXIO); + + sc = device_get_softc(dev); + sc->smc_usemem = 1; + + return (smc_probe(dev)); +} + +static device_method_t smc_acpi_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, smc_acpi_probe), + { 0, 0 } +}; + +DEFINE_CLASS_1(smc, smc_acpi_driver, smc_acpi_methods, + sizeof(struct smc_softc), smc_driver); + +extern devclass_t smc_devclass; + +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); diff --git a/sys/dev/smc/if_smc_fdt.c b/sys/dev/smc/if_smc_fdt.c index baca0bd6113e..2c63b9f94d49 100644 --- a/sys/dev/smc/if_smc_fdt.c +++ b/sys/dev/smc/if_smc_fdt.c @@ -35,29 +35,16 @@ __FBSDID("$FreeBSD$"); #include <sys/systm.h> #include <sys/taskqueue.h> -#include <machine/bus.h> -#include <machine/resource.h> - -#include <net/ethernet.h> #include <net/if.h> -#include <net/if_arp.h> -#include <net/if_media.h> #include <dev/smc/if_smcvar.h> -#include <dev/mii/mii.h> -#include <dev/mii/miivar.h> - #include <dev/fdt/fdt_common.h> #include <dev/ofw/openfirm.h> #include <dev/ofw/ofw_bus.h> #include <dev/ofw/ofw_bus_subr.h> -#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 @@ smc_fdt_probe(device_t dev) 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); diff --git a/sys/dev/smc/if_smcvar.h b/sys/dev/smc/if_smcvar.h index a58eb0df0374..8de30706a0a5 100644 --- a/sys/dev/smc/if_smcvar.h +++ b/sys/dev/smc/if_smcvar.h @@ -68,6 +68,8 @@ struct smc_softc { void *smc_read_arg; }; +DECLARE_CLASS(smc_driver); + int smc_probe(device_t); int smc_attach(device_t); int smc_detach(device_t); |