[PATCH] [SCHEME 1] Add support for new idle device tree format
From: Akshay Adiga
Date: Wed May 30 2018 - 22:53:23 EST
This patch adds support for new device-tree format for idle state
description.
Previously if a older kernel runs on a newer firmware, it may enable
all available states irrespective of its capability of handling it.
New device tree format adds a compatible flag, so that only kernel
which has the capability to handle the version of stop state will enable
it.
Older kernel will still see stop0 and stop0_lite in older format and we
will depricate it after some time.
Idea is to bump up the version in firmware if we find a bug or
regression in stop states. A fix will be provided in linux which would
now know about the bumped up version of stop states, where as kernel
without fixes would ignore the states.
New idle state device tree format :
power-mgt {
...
ibm,enabled-stop-levels = <0xec000000>;
ibm,cpu-idle-state-psscr-mask = <0x0 0x3003ff 0x0 0x3003ff>;
ibm,cpu-idle-state-latencies-ns = <0x3e8 0x7d0>;
ibm,cpu-idle-state-psscr = <0x0 0x330 0x0 0x300330>;
ibm,cpu-idle-state-flags = <0x100000 0x101000>;
ibm,cpu-idle-state-residency-ns = <0x2710 0x4e20>;
ibm,idle-states {
phandle = <0xff>;
stop4 {
flags = <0x207000>;
compatible = "ibm,cpuidle-state-v1";
psscr-mask = <0x0 0x3003ff>;
handle = <0x102>;
latency-ns = <0x186a0>;
residency-ns = <0x989680>;
psscr = <0x0 0x300374>;
};
...
stop11 {
...
compatible = "ibm,cpuoffline-state-v1";
...
};
};
Signed-off-by: Akshay Adiga <akshay.adiga@xxxxxxxxxxxxxxxxxx>
---
arch/powerpc/platforms/powernv/idle.c | 70 ++++++++++++++++++++++++++++++-----
drivers/cpuidle/cpuidle-powernv.c | 26 ++++++++++++-
2 files changed, 85 insertions(+), 11 deletions(-)
diff --git a/arch/powerpc/platforms/powernv/idle.c b/arch/powerpc/platforms/powernv/idle.c
index 1f12ab1..074381d 100644
--- a/arch/powerpc/platforms/powernv/idle.c
+++ b/arch/powerpc/platforms/powernv/idle.c
@@ -623,17 +623,19 @@ int validate_psscr_val_mask(u64 *psscr_val, u64 *psscr_mask, u32 flags)
* Returns 0 on success
*/
static int __init pnv_power9_idle_init(struct device_node *np, u32 *flags,
- int dt_idle_states)
+ int dt_idle_states, int additional_states)
{
u64 *psscr_val = NULL;
u64 *psscr_mask = NULL;
u32 *residency_ns = NULL;
u64 max_residency_ns = 0;
- int rc = 0, i;
-
- psscr_val = kcalloc(dt_idle_states, sizeof(*psscr_val), GFP_KERNEL);
- psscr_mask = kcalloc(dt_idle_states, sizeof(*psscr_mask), GFP_KERNEL);
- residency_ns = kcalloc(dt_idle_states, sizeof(*residency_ns),
+ int rc = 0, i, orig_dt_idle_states;
+ struct device_node *dt_node;
+ orig_dt_idle_states = dt_idle_states;
+ /* TODO: remove ugliness of using additional_states count*/
+ psscr_val = kcalloc(dt_idle_states+additional_states, sizeof(*psscr_val), GFP_KERNEL);
+ psscr_mask = kcalloc(dt_idle_states+additional_states, sizeof(*psscr_mask), GFP_KERNEL);
+ residency_ns = kcalloc(dt_idle_states+additional_states, sizeof(*residency_ns),
GFP_KERNEL);
if (!psscr_val || !psscr_mask || !residency_ns) {
@@ -664,7 +666,37 @@ static int __init pnv_power9_idle_init(struct device_node *np, u32 *flags,
rc = -1;
goto out;
}
+ for_each_compatible_node( dt_node, NULL, "ibm,cpuoffline-state_v1" ) {
+ printk("Found a state\n");
+ rc = of_property_read_u32(dt_node, "residency-ns" , &(residency_ns[dt_idle_states]));
+ if (rc)
+ printk("error reading residency rc= %d\n",rc);
+ rc = of_property_read_u64(dt_node, "psscr-mask" , &(psscr_mask[dt_idle_states]));
+ if (rc)
+ printk("error reading psscr-mask rc= %d\n",rc);
+ rc = of_property_read_u64(dt_node, "psscr" , &(psscr_val[dt_idle_states]));
+ if (rc)
+ printk("error reading psscr rc= %d\n",rc);
+ dt_idle_states++;
+ }
+ /* Fall back if no cpuoffline state found */
+ if ( orig_dt_idle_states == dt_idle_states) {
+ for_each_compatible_node( dt_node, NULL, "ibm,cpuidle-state_v1" ) {
+ printk("Found a state\n");
+ rc = of_property_read_u32(dt_node, "residency-ns" , &(residency_ns[dt_idle_states]));
+ if (rc)
+ printk("error reading residency rc= %d\n",rc);
+ rc = of_property_read_u64(dt_node, "psscr-mask" , &(psscr_mask[dt_idle_states]));
+ if (rc)
+ printk("error reading psscr-mask rc= %d\n",rc);
+ rc = of_property_read_u64(dt_node, "psscr" , &(psscr_val[dt_idle_states]));
+ if (rc)
+ printk("error reading psscr rc= %d\n",rc);
+ dt_idle_states++;
+ }
+ }
+
/*
* Set pnv_first_deep_stop_state, pnv_deepest_stop_psscr_{val,mask},
* and the pnv_default_stop_{val,mask}.
@@ -740,10 +772,11 @@ static int __init pnv_power9_idle_init(struct device_node *np, u32 *flags,
*/
static void __init pnv_probe_idle_states(void)
{
- struct device_node *np;
+ struct device_node *np,*dt_node;
int dt_idle_states;
u32 *flags = NULL;
- int i;
+ int i,rc;
+ int additional_states=0;
np = of_find_node_by_path("/ibm,opal/power-mgt");
if (!np) {
@@ -765,12 +798,29 @@ static void __init pnv_probe_idle_states(void)
goto out;
}
+
+ for_each_compatible_node( dt_node, NULL, "ibm,cpuidle-state-v1" ) {
+
+ i = dt_idle_states + additional_states;
+ rc = of_property_read_u32(dt_node, "flags" , &(flags[i]));
+ if (rc)
+ printk("error reading flags rc= %d\n",rc);
+ additional_states++;
+ }
+ for_each_compatible_node( dt_node, NULL, "ibm,cpuoffline-state-v1" ) {
+
+ i = dt_idle_states + additional_states;
+ rc = of_property_read_u32(dt_node, "flags" , &(flags[i]));
+ if (rc)
+ printk("error reading flags rc= %d\n",rc);
+ additional_states++;
+ }
if (cpu_has_feature(CPU_FTR_ARCH_300)) {
- if (pnv_power9_idle_init(np, flags, dt_idle_states))
+ if (pnv_power9_idle_init(np, flags, dt_idle_states,additional_states))
goto out;
}
- for (i = 0; i < dt_idle_states; i++)
+ for (i = 0; i < dt_idle_states+additional_states; i++)
supported_cpuidle_states |= flags[i];
out:
diff --git a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c
index 1a8234e..e06181f 100644
--- a/drivers/cpuidle/cpuidle-powernv.c
+++ b/drivers/cpuidle/cpuidle-powernv.c
@@ -241,7 +241,7 @@ static inline int validate_dt_prop_sizes(const char *prop1, int prop1_len,
extern u32 pnv_get_supported_cpuidle_states(void);
static int powernv_add_idle_states(void)
{
- struct device_node *power_mgt;
+ struct device_node *power_mgt,*dt_node;
int nr_idle_states = 1; /* Snooze */
int dt_idle_states, count;
u32 latency_ns[CPUIDLE_STATE_MAX];
@@ -365,6 +365,30 @@ static int powernv_add_idle_states(void)
residency_ns, dt_idle_states);
}
+ /* Support new dt format for idle states */
+ for_each_compatible_node( dt_node, NULL, "ibm,cpuidle-state-v1" ) {
+ printk("Found a state\n");
+ rc = of_property_read_string(dt_node, "name" , &(names[dt_idle_states]));
+ if (rc)
+ printk("error reading names rc= %d\n",rc);
+ rc = of_property_read_u32(dt_node, "residency-ns" , &(residency_ns[dt_idle_states]));
+ if (rc)
+ printk("error reading residency rc= %d\n",rc);
+ rc = of_property_read_u32(dt_node, "latency-ns" , &(latency_ns[dt_idle_states]));
+ if (rc)
+ printk("error reading latency rc= %d\n",rc);
+ rc = of_property_read_u32(dt_node, "flags" , &(flags[dt_idle_states]));
+ if (rc)
+ printk("error reading flags rc= %d\n",rc);
+ rc = of_property_read_u64(dt_node, "psscr-mask" , &(psscr_mask[dt_idle_states]));
+ if (rc)
+ printk("error reading psscr-mask rc= %d\n",rc);
+ rc = of_property_read_u64(dt_node, "psscr" , &(psscr_val[dt_idle_states]));
+ if (rc)
+ printk("error reading psscr rc= %d\n",rc);
+ dt_idle_states++;
+ }
+
for (i = 0; i < dt_idle_states; i++) {
unsigned int exit_latency, target_residency;
bool stops_timebase = false;
--
2.5.5