Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 70734a78 authored by Preeti U Murthy's avatar Preeti U Murthy Committed by Rafael J. Wysocki
Browse files

cpuidle: powernv: Avoid endianness conversions while parsing DT



We currently read the information about idle states from the DT
so as to populate the cpuidle table. Use those APIs to read from
the DT that can avoid endianness conversions of the property values
in the cpuidle driver.

Signed-off-by: default avatarPreeti U Murthy <preeti@linux.vnet.ibm.com>
Acked-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 92c83ff5
Loading
Loading
Loading
Loading
+16 −13
Original line number Original line Diff line number Diff line
@@ -159,9 +159,7 @@ static int powernv_add_idle_states(void)
	struct device_node *power_mgt;
	struct device_node *power_mgt;
	int nr_idle_states = 1; /* Snooze */
	int nr_idle_states = 1; /* Snooze */
	int dt_idle_states;
	int dt_idle_states;
	const __be32 *idle_state_flags;
	u32 *latency_ns, *residency_ns, *flags;
	u32 len_flags, flags;
	u32 *latency_ns, *residency_ns;
	int i, rc;
	int i, rc;


	/* Currently we have snooze statically defined */
	/* Currently we have snooze statically defined */
@@ -172,14 +170,19 @@ static int powernv_add_idle_states(void)
		goto out;
		goto out;
	}
	}


	idle_state_flags = of_get_property(power_mgt,
	/* Read values of any property to determine the num of idle states */
				"ibm,cpu-idle-state-flags", &len_flags);
	dt_idle_states = of_property_count_u32_elems(power_mgt, "ibm,cpu-idle-state-flags");
	if (!idle_state_flags) {
	if (dt_idle_states < 0) {
		pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-flags in DT\n");
		pr_warn("cpuidle-powernv: no idle states found in the DT\n");
		goto out;
		goto out;
	}
	}


	dt_idle_states = len_flags / sizeof(u32);
	flags = kzalloc(sizeof(*flags) * dt_idle_states, GFP_KERNEL);
	if (of_property_read_u32_array(power_mgt,
			"ibm,cpu-idle-state-flags", flags, dt_idle_states)) {
		pr_warn("cpuidle-powernv : missing ibm,cpu-idle-state-flags in DT\n");
		goto out_free_flags;
	}


	latency_ns = kzalloc(sizeof(*latency_ns) * dt_idle_states, GFP_KERNEL);
	latency_ns = kzalloc(sizeof(*latency_ns) * dt_idle_states, GFP_KERNEL);
	rc = of_property_read_u32_array(power_mgt,
	rc = of_property_read_u32_array(power_mgt,
@@ -195,21 +198,19 @@ static int powernv_add_idle_states(void)


	for (i = 0; i < dt_idle_states; i++) {
	for (i = 0; i < dt_idle_states; i++) {


		flags = be32_to_cpu(idle_state_flags[i]);

		/*
		/*
		 * Cpuidle accepts exit_latency and target_residency in us.
		 * Cpuidle accepts exit_latency and target_residency in us.
		 * Use default target_residency values if f/w does not expose it.
		 * Use default target_residency values if f/w does not expose it.
		 */
		 */
		if (flags & OPAL_PM_NAP_ENABLED) {
		if (flags[i] & OPAL_PM_NAP_ENABLED) {
			/* Add NAP state */
			/* Add NAP state */
			strcpy(powernv_states[nr_idle_states].name, "Nap");
			strcpy(powernv_states[nr_idle_states].name, "Nap");
			strcpy(powernv_states[nr_idle_states].desc, "Nap");
			strcpy(powernv_states[nr_idle_states].desc, "Nap");
			powernv_states[nr_idle_states].flags = 0;
			powernv_states[nr_idle_states].flags = 0;
			powernv_states[nr_idle_states].target_residency = 100;
			powernv_states[nr_idle_states].target_residency = 100;
			powernv_states[nr_idle_states].enter = &nap_loop;
			powernv_states[nr_idle_states].enter = &nap_loop;
		} else if (flags & OPAL_PM_SLEEP_ENABLED ||
		} else if (flags[i] & OPAL_PM_SLEEP_ENABLED ||
			flags & OPAL_PM_SLEEP_ENABLED_ER1) {
			flags[i] & OPAL_PM_SLEEP_ENABLED_ER1) {
			/* Add FASTSLEEP state */
			/* Add FASTSLEEP state */
			strcpy(powernv_states[nr_idle_states].name, "FastSleep");
			strcpy(powernv_states[nr_idle_states].name, "FastSleep");
			strcpy(powernv_states[nr_idle_states].desc, "FastSleep");
			strcpy(powernv_states[nr_idle_states].desc, "FastSleep");
@@ -232,6 +233,8 @@ static int powernv_add_idle_states(void)
	kfree(residency_ns);
	kfree(residency_ns);
out_free_latency:
out_free_latency:
	kfree(latency_ns);
	kfree(latency_ns);
out_free_flags:
	kfree(flags);
out:
out:
	return nr_idle_states;
	return nr_idle_states;
}
}