Lines Matching +full:domain +full:- +full:idle +full:- +full:states

1 // SPDX-License-Identifier: GPL-2.0-only
3 * RISC-V SBI CPU idle driver.
9 #define pr_fmt(fmt) "cpuidle-riscv-sbi: " fmt
33 u32 *states; member
52 data->available = true; in sbi_set_domain_state()
53 data->state = state; in sbi_set_domain_state()
60 return data->state; in sbi_get_domain_state()
67 data->available = false; in sbi_clear_domain_state()
74 return data->available; in sbi_is_domain_state_available()
100 u32 *states = __this_cpu_read(sbi_cpuidle_data.states); in sbi_cpuidle_enter_state() local
101 u32 state = states[idx]; in sbi_cpuidle_enter_state()
115 u32 *states = data->states; in __sbi_enter_domain_idle_state() local
116 struct device *pd_dev = data->dev; in __sbi_enter_domain_idle_state()
122 return -1; in __sbi_enter_domain_idle_state()
135 state = states[idx]; in __sbi_enter_domain_idle_state()
137 ret = sbi_suspend(state) ? -1 : idx; in __sbi_enter_domain_idle_state()
148 /* Clear the domain state to start fresh when back from idle. */ in __sbi_enter_domain_idle_state()
182 /* Clear domain state to start fresh at next online. */ in sbi_cpuidle_cpuhp_down()
205 { .compatible = "riscv,idle-state",
223 int err = of_property_read_u32(np, "riscv,sbi-suspend-param", state); in sbi_dt_parse_state_node()
226 pr_warn("%pOF missing riscv,sbi-suspend-param property\n", np); in sbi_dt_parse_state_node()
232 return -EINVAL; in sbi_dt_parse_state_node()
246 data->dev = dt_idle_attach_cpu(cpu, "sbi"); in sbi_dt_cpu_init_topology()
247 if (IS_ERR_OR_NULL(data->dev)) in sbi_dt_cpu_init_topology()
248 return PTR_ERR_OR_ZERO(data->dev); in sbi_dt_cpu_init_topology()
252 * of a shared state for the domain, assumes the domain states are all in sbi_dt_cpu_init_topology()
253 * deeper states. in sbi_dt_cpu_init_topology()
255 drv->states[state_count - 1].flags |= CPUIDLE_FLAG_RCU_IDLE; in sbi_dt_cpu_init_topology()
256 drv->states[state_count - 1].enter = sbi_enter_domain_idle_state; in sbi_dt_cpu_init_topology()
257 drv->states[state_count - 1].enter_s2idle = in sbi_dt_cpu_init_topology()
271 u32 *states; in sbi_cpuidle_dt_init_states() local
276 return -ENODEV; in sbi_cpuidle_dt_init_states()
278 states = devm_kcalloc(dev, state_count, sizeof(*states), GFP_KERNEL); in sbi_cpuidle_dt_init_states()
279 if (!states) in sbi_cpuidle_dt_init_states()
280 return -ENOMEM; in sbi_cpuidle_dt_init_states()
284 state_node = of_get_cpu_state_node(cpu_node, i - 1); in sbi_cpuidle_dt_init_states()
288 ret = sbi_dt_parse_state_node(state_node, &states[i]); in sbi_cpuidle_dt_init_states()
294 pr_debug("sbi-state %#x index %d\n", states[i], i); in sbi_cpuidle_dt_init_states()
297 return -ENODEV; in sbi_cpuidle_dt_init_states()
304 /* Store states in the per-cpu struct. */ in sbi_cpuidle_dt_init_states()
305 data->states = states; in sbi_cpuidle_dt_init_states()
314 dt_idle_detach_cpu(data->dev); in sbi_cpuidle_deinit_cpu()
326 return -ENOMEM; in sbi_cpuidle_init_cpu()
328 drv->name = "sbi_cpuidle"; in sbi_cpuidle_init_cpu()
329 drv->owner = THIS_MODULE; in sbi_cpuidle_init_cpu()
330 drv->cpumask = (struct cpumask *)cpumask_of(cpu); in sbi_cpuidle_init_cpu()
332 /* RISC-V architectural WFI to be represented as state index 0. */ in sbi_cpuidle_init_cpu()
333 drv->states[0].enter = sbi_cpuidle_enter_state; in sbi_cpuidle_init_cpu()
334 drv->states[0].exit_latency = 1; in sbi_cpuidle_init_cpu()
335 drv->states[0].target_residency = 1; in sbi_cpuidle_init_cpu()
336 drv->states[0].power_usage = UINT_MAX; in sbi_cpuidle_init_cpu()
337 strcpy(drv->states[0].name, "WFI"); in sbi_cpuidle_init_cpu()
338 strcpy(drv->states[0].desc, "RISC-V WFI"); in sbi_cpuidle_init_cpu()
341 * If no DT idle states are detected (ret == 0) let the driver in sbi_cpuidle_init_cpu()
343 * initialize the idle driver if only wfi is supported, the in sbi_cpuidle_init_cpu()
344 * default archictectural back-end already executes wfi in sbi_cpuidle_init_cpu()
345 * on idle entry. in sbi_cpuidle_init_cpu()
349 pr_debug("HART%ld: failed to parse DT idle states\n", in sbi_cpuidle_init_cpu()
351 return ret ? : -ENODEV; in sbi_cpuidle_init_cpu()
355 /* Initialize idle states from DT. */ in sbi_cpuidle_init_cpu()
358 pr_err("HART%ld: failed to init idle states\n", in sbi_cpuidle_init_cpu()
378 * All devices have now been attached/probed to the PM domain in sbi_cpuidle_domain_sync_state()
379 * topology, hence it's fine to allow domain states to be picked. in sbi_cpuidle_domain_sync_state()
388 struct genpd_power_state *state = &pd->states[pd->state_idx]; in sbi_cpuidle_pd_power_off()
391 if (!state->data) in sbi_cpuidle_pd_power_off()
395 return -EBUSY; in sbi_cpuidle_pd_power_off()
397 /* OSI mode is enabled, set the corresponding domain state. */ in sbi_cpuidle_pd_power_off()
398 pd_state = state->data; in sbi_cpuidle_pd_power_off()
416 int ret = -ENOMEM; in sbi_pd_init()
426 pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN; in sbi_pd_init()
430 pd->power_off = sbi_cpuidle_pd_power_off; in sbi_pd_init()
432 pd->flags |= GENPD_FLAG_ALWAYS_ON; in sbi_pd_init()
434 /* Use governor for CPU PM domains if it has some states to manage. */ in sbi_pd_init()
435 pd_gov = pd->states ? &pm_domain_cpu_gov : NULL; in sbi_pd_init()
445 pd_provider->node = of_node_get(np); in sbi_pd_init()
446 list_add(&pd_provider->link, &sbi_pd_providers); in sbi_pd_init()
448 pr_debug("init PM domain %s\n", pd->name); in sbi_pd_init()
458 pr_err("failed to init PM domain ret=%d %pOF\n", ret, np); in sbi_pd_init()
468 of_genpd_del_provider(pd_provider->node); in sbi_pd_remove()
470 genpd = of_genpd_remove_last(pd_provider->node); in sbi_pd_remove()
474 of_node_put(pd_provider->node); in sbi_pd_remove()
475 list_del(&pd_provider->link); in sbi_pd_remove()
486 return -ENODEV; in sbi_genpd_probe()
489 * Parse child nodes for the "#power-domain-cells" property and in sbi_genpd_probe()
490 * initialize a genpd/genpd-of-provider pair when it's found. in sbi_genpd_probe()
493 if (!of_property_present(node, "#power-domain-cells")) in sbi_genpd_probe()
544 of_property_present(np, "power-domains") && in sbi_cpuidle_probe()
545 of_property_present(np, "power-domain-names")) { in sbi_cpuidle_probe()
554 pds_node = of_find_node_by_path("/cpus/power-domains"); in sbi_cpuidle_probe()
562 /* Initialize CPU idle driver for each CPU */ in sbi_cpuidle_probe()
564 ret = sbi_cpuidle_init_cpu(&pdev->dev, cpu); in sbi_cpuidle_probe()
566 pr_debug("HART%ld: idle driver init failed\n", in sbi_cpuidle_probe()
575 pr_info("idle driver registered for all CPUs\n"); in sbi_cpuidle_probe()
580 while (--cpu >= 0) { in sbi_cpuidle_probe()
593 .name = "sbi-cpuidle",
618 pdev = platform_device_register_simple("sbi-cpuidle", in sbi_cpuidle_init()
619 -1, NULL, 0); in sbi_cpuidle_init()