#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/eventhandler.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/random.h>
#include <dev/psci/psci.h>
#include <dev/psci/smccc.h>
#include <machine/cpu_feat.h>
#define ERRATA_HIGHER_EL_MITIGATION 3
#define ERRATA_NOT_AFFECTED 2
#define ERRATA_AFFECTED 1
#define EM_VERSION SMCCC_FUNC_ID(SMCCC_FAST_CALL, \
SMCCC_32BIT_CALL, SMCCC_STD_SECURE_SERVICE_CALLS, 0xf0u)
#define EM_VERSION_MIN 0x10000L
#define EM_FEATURES SMCCC_FUNC_ID(SMCCC_FAST_CALL, \
SMCCC_32BIT_CALL, SMCCC_STD_SECURE_SERVICE_CALLS, 0xf1u)
#define EM_CPU_ERRATUM_FEATURES SMCCC_FUNC_ID(SMCCC_FAST_CALL, \
SMCCC_32BIT_CALL, SMCCC_STD_SECURE_SERVICE_CALLS, 0xf2u)
static device_identify_t errata_identify;
static device_probe_t errata_probe;
static device_attach_t errata_attach;
static cpu_feat_errata errata_cpu_feat_errata_check(const struct cpu_feat *,
u_int);
static void
errata_identify(driver_t *driver, device_t parent)
{
int32_t version;
if (smccc_arch_features(EM_VERSION) != SMCCC_RET_SUCCESS)
return;
version = psci_call(EM_VERSION, 0, 0, 0);
if (version < EM_VERSION_MIN)
return;
if (BUS_ADD_CHILD(parent, 0, "errata", DEVICE_UNIT_ANY) == NULL)
device_printf(parent, "add errata child failed\n");
}
static int
errata_probe(device_t dev)
{
device_set_desc(dev, "Arm SMCCC Errata Management");
return (BUS_PROBE_NOWILDCARD);
}
static int
errata_attach(device_t dev)
{
if (arm_smccc_invoke(EM_FEATURES, EM_CPU_ERRATUM_FEATURES, NULL) < 0) {
device_printf(dev,
"EM_CPU_ERRATUM_FEATURES is not implemented\n");
return (ENXIO);
}
cpu_feat_register_errata_check(errata_cpu_feat_errata_check);
return (0);
}
static cpu_feat_errata
errata_cpu_feat_errata_check(const struct cpu_feat *feat __unused, u_int errata_id)
{
struct arm_smccc_res res;
switch(arm_smccc_invoke(EM_CPU_ERRATUM_FEATURES, errata_id, 0, &res)) {
default:
return (ERRATA_UNKNOWN);
case ERRATA_NOT_AFFECTED:
return (ERRATA_NONE);
case ERRATA_AFFECTED:
return (ERRATA_AFFECTED);
case ERRATA_HIGHER_EL_MITIGATION:
return (ERRATA_FW_MITIGAION);
}
}
static device_method_t errata_methods[] = {
DEVMETHOD(device_identify, errata_identify),
DEVMETHOD(device_probe, errata_probe),
DEVMETHOD(device_attach, errata_attach),
DEVMETHOD_END
};
static driver_t errata_driver = {
"errata",
errata_methods,
0
};
DRIVER_MODULE(errata, smccc, errata_driver, 0, 0);