diff --git a/sys/dev/psci/psci.c b/sys/dev/psci/psci.c --- a/sys/dev/psci/psci.c +++ b/sys/dev/psci/psci.c @@ -71,6 +71,7 @@ struct psci_softc { device_t dev; + device_t smccc_dev; uint32_t psci_version; uint32_t psci_fnids[PSCI_FN_MAX]; @@ -341,11 +342,16 @@ if (psci_init(dev, default_version)) return (ENXIO); + psci_softc = sc; + #ifdef __aarch64__ smccc_init(); -#endif + sc->smccc_dev = device_add_child(dev, "smccc", DEVICE_UNIT_ANY); + if (sc->smccc_dev == NULL) + device_printf(dev, "Unable to add SMCCC device\n"); - psci_softc = sc; + bus_generic_attach(dev); +#endif return (0); } diff --git a/sys/dev/psci/smccc.c b/sys/dev/psci/smccc.c --- a/sys/dev/psci/smccc.c +++ b/sys/dev/psci/smccc.c @@ -34,7 +34,9 @@ #include #include +#include #include +#include #include #include @@ -66,6 +68,32 @@ } } +static int +smccc_probe(device_t dev) +{ + int32_t version; + + /* + * If the version is not implemented then we treat it as SMCCC 1.0 + */ + if (psci_features(SMCCC_VERSION) == PSCI_RETVAL_NOT_SUPPORTED || + (version = arm_smccc_invoke(SMCCC_VERSION, NULL)) <= 0) { + device_set_desc(dev, "ARM SMCCC v1.0"); + return (0); + } + + device_set_descf(dev, "ARM SMCCC v%d.%d", SMCCC_VERSION_MAJOR(version), + SMCCC_VERSION_MINOR(version)); + + return (0); +} + +static int +smccc_attach(device_t dev) +{ + return (bus_generic_attach(dev)); +} + uint32_t smccc_get_version(void) { @@ -107,3 +135,21 @@ ("SMCCC arch workaround 2 called with an invalid SMCCC interface")); return (arm_smccc_invoke(SMCCC_ARCH_WORKAROUND_2, enable, NULL)); } + +static device_method_t smccc_methods[] = { + DEVMETHOD(device_probe, smccc_probe), + DEVMETHOD(device_attach, smccc_attach), + + DEVMETHOD(bus_add_child, bus_generic_add_child), + + DEVMETHOD_END +}; + +static driver_t smccc_driver = { + "smccc", + smccc_methods, + 0, +}; + +EARLY_DRIVER_MODULE(smccc, psci, smccc_driver, 0, 0, + BUS_PASS_CPU + BUS_PASS_ORDER_FIRST);