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
This commit is contained in:
Andrew Turner 2020-07-28 09:29:56 +00:00
parent 24e337bec5
commit 22b33ca4b2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=363636
5 changed files with 108 additions and 43 deletions

View file

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

View file

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

80
sys/dev/smc/if_smc_acpi.c Normal file
View file

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

View file

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

View file

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