Skip to content

Commit

Permalink
kboot: Remove disabled CPU cores from /cpus/cpu-map
Browse files Browse the repository at this point in the history
Required for cpufreq on M1 Pro with disabled performance cores.

Signed-off-by: Janne Grunau <j@jannau.net>
  • Loading branch information
jannau committed Feb 15, 2022
1 parent a8a93a3 commit 55b48fd
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/kboot.c
Expand Up @@ -204,6 +204,32 @@ static int dt_set_memory(void)
return 0;
}

static int dt_fix_cpu_cluters(uint32_t phandle)
{
int cpumap = fdt_path_offset(dt, "/cpus/cpu-map");
if (cpumap < 0)
bail("FDT: /cpus/cpu-map node not found in devtree\n");

int cluster;
for (cluster = fdt_first_subnode(dt, cpumap); cluster >= 0;) {
int node;
for (node = fdt_first_subnode(dt, cluster); node >= 0;) {
int next = fdt_next_subnode(dt, node);
const fdt32_t *core = fdt_getprop(dt, node, "cpu", NULL);

if (phandle == fdt32_ld(core)) {
printf("FDT: removing inactive /cpus/cpu-map/%s/%s\n",
fdt_get_name(dt, cluster, NULL), fdt_get_name(dt, node, NULL));
fdt_nop_node(dt, node);
}
node = next;
}
cluster = fdt_next_subnode(dt, cluster);
}

return 0;
}

static int dt_set_cpus(void)
{
int cpus = fdt_path_offset(dt, "/cpus");
Expand All @@ -227,6 +253,11 @@ static int dt_set_cpus(void)

if (!smp_is_alive(cpu)) {
printf("FDT: CPU %d is not alive, disabling...\n", cpu);
// find and remove from cpu-map
uint32_t phandle = fdt_get_phandle(dt, node);
if (phandle != 0)
dt_fix_cpu_cluters(phandle);

int next = fdt_next_subnode(dt, node);
fdt_nop_node(dt, node);
cpu++;
Expand Down

0 comments on commit 55b48fd

Please sign in to comment.