cpufreq_dt: Do not attach the device if the cpu isn't present

If we boot with hw.ncpu=X (available on arm and arm64 at least) we
shouldn't attach the cpufreq driver as cf_set_method will try to get
the cpuid and it doesn't exists.
This solves cpufreq panicing on RockChip RK3399 when booting with
hw.ncpu=4

MFC after:	1 week
This commit is contained in:
Emmanuel Vadot 2019-12-03 22:08:54 +00:00
parent 357145a0ce
commit 4b23e1e53a

View File

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