diff --git a/sys/dev/cpufreq/cpufreq_dt.c b/sys/dev/cpufreq/cpufreq_dt.c index 0633184fe618..061345f1bfca 100644 --- a/sys/dev/cpufreq/cpufreq_dt.c +++ b/sys/dev/cpufreq/cpufreq_dt.c @@ -446,7 +446,7 @@ cpufreq_dt_attach(device_t dev) struct cpufreq_dt_softc *sc; phandle_t node; phandle_t cnode, opp, copp; - int cpu; + int cpu, ncpu; uint64_t freq; int rv = 0; enum opp_version version; @@ -454,6 +454,14 @@ cpufreq_dt_attach(device_t dev) sc = device_get_softc(dev); sc->dev = dev; node = ofw_bus_get_node(device_get_parent(dev)); + cpu = device_get_unit(device_get_parent(dev)); + + if (TUNABLE_INT_FETCH("hw.ncpu", &ncpu)) { + if (cpu >= ncpu) { + device_printf(dev, "Not attaching as cpu is not present\n"); + return (ENXIO); + } + } if (regulator_get_by_ofw_property(dev, node, "cpu-supply", &sc->reg) != 0) { @@ -496,7 +504,6 @@ cpufreq_dt_attach(device_t dev) * Find all CPUs that share the same opp table */ CPU_ZERO(&sc->cpus); - cpu = device_get_unit(device_get_parent(dev)); for (cnode = node; cnode > 0; cnode = OF_peer(cnode), cpu++) { copp = -1; if (version == OPP_V1)