From: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> To: linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org Cc: devicetree@vger.kernel.org, Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>, Mark Rutland <mark.rutland@arm.com>, Sudeep Holla <sudeep.holla@arm.com>, Catalin Marinas <catalin.marinas@arm.com>, Charles Garcia Tobin <Charles.Garcia-Tobin@arm.com>, Nicolas Pitre <nico@linaro.org>, Rob Herring <robh+dt@kernel.org>, Grant Likely <grant.likely@linaro.org>, Peter De Schrijver <pdeschrijver@nvidia.com>, Santosh Shilimkar <santosh.shilimkar@ti.com>, Daniel Lezcano <daniel.lezcano@linaro.org>, Amit Kucheria <amit.kucheria@linaro.org>, Vincent Guittot <vincent.guittot@linaro.org>, Antti Miettinen <ananaza@iki.fi>, Stephen Boyd <sboyd@codeaurora.org>, Kevin Hilman <khilman@linaro.org>, Sebastian Capella <sebcape@gmail.com>, Tomasz Figa <t.figa@samsung.com>, Mark Brown <broonie@kernel.org>, Paul Walmsley <paul@pwsan.com>, Chander Kashyap <k.chander@samsung.com>, Geoff Subject: [PATCH v7 3/8] drivers: cpuidle: implement DT based idle states infrastructure Date: Wed, 13 Aug 2014 16:52:02 +0100 [thread overview] Message-ID: <1407945127-27554-4-git-send-email-lorenzo.pieralisi@arm.com> (raw) In-Reply-To: <1407945127-27554-1-git-send-email-lorenzo.pieralisi@arm.com> On most common ARM systems, the low-power states a CPU can be put into are not discoverable in HW and require device tree bindings to describe power down suspend operations and idle states parameters. In order to enable DT based idle states and configure idle drivers, this patch implements the bulk infrastructure required to parse the device tree idle states bindings and initialize the corresponding CPUidle driver states data. The parsing API accepts a start index that defines the first idle state that should be initialized by the parsing code in order to give new and legacy driver flexibility over which states should be parsed using the new DT mechanism. The idle states list is obtained from the first cpu in the driver cpumask, which implicitly means the parsing code expects idle states (and related list of phandles) to be the same for all CPUs in the CPUidle driver mask. The kernel does not check this assumption, it must be enforced by the bootloader to ensure correct system behaviour. Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> --- drivers/cpuidle/Kconfig | 3 + drivers/cpuidle/Makefile | 1 + drivers/cpuidle/dt_idle_states.c | 140 +++++++++++++++++++++++++++++++++++++++ drivers/cpuidle/dt_idle_states.h | 5 ++ 4 files changed, 149 insertions(+) create mode 100644 drivers/cpuidle/dt_idle_states.c create mode 100644 drivers/cpuidle/dt_idle_states.h diff --git a/drivers/cpuidle/Kconfig b/drivers/cpuidle/Kconfig index 32748c3..8deb934 100644 --- a/drivers/cpuidle/Kconfig +++ b/drivers/cpuidle/Kconfig @@ -25,6 +25,9 @@ config CPU_IDLE_GOV_MENU bool "Menu governor (for tickless system)" default y +config DT_IDLE_STATES + bool + menu "ARM CPU Idle Drivers" depends on ARM source "drivers/cpuidle/Kconfig.arm" diff --git a/drivers/cpuidle/Makefile b/drivers/cpuidle/Makefile index 11edb31..002b653 100644 --- a/drivers/cpuidle/Makefile +++ b/drivers/cpuidle/Makefile @@ -4,6 +4,7 @@ obj-y += cpuidle.o driver.o governor.o sysfs.o governors/ obj-$(CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED) += coupled.o +obj-$(CONFIG_DT_IDLE_STATES) += dt_idle_states.o ################################################################################## # ARM SoC drivers diff --git a/drivers/cpuidle/dt_idle_states.c b/drivers/cpuidle/dt_idle_states.c new file mode 100644 index 0000000..207f8f7 --- /dev/null +++ b/drivers/cpuidle/dt_idle_states.c @@ -0,0 +1,140 @@ +/* + * DT idle states parsing code. + * + * Copyright (C) 2014 ARM Ltd. + * Author: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#define pr_fmt(fmt) "DT idle-states: " fmt + +#include <linux/cpuidle.h> +#include <linux/cpumask.h> +#include <linux/errno.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_device.h> + +#include "dt_idle_states.h" + +static int init_state_node(struct cpuidle_state *idle_state, + struct device_node *state_node) +{ + int err; + + err = of_property_read_u32(state_node, "wakeup-latency-us", + &idle_state->exit_latency); + if (err) { + u32 entry_latency, exit_latency; + + err = of_property_read_u32(state_node, "entry-latency-us", + &entry_latency); + if (err) { + pr_debug(" * %s missing entry-latency-us property\n", + state_node->full_name); + return -EINVAL; + } + + err = of_property_read_u32(state_node, "exit-latency-us", + &exit_latency); + if (err) { + pr_debug(" * %s missing exit-latency-us property\n", + state_node->full_name); + return -EINVAL; + } + /* + * If wakeup-latency-us is missing, default to entry+exit + * latencies as defined in idle states bindings + */ + idle_state->exit_latency = entry_latency + exit_latency; + } + + err = of_property_read_u32(state_node, "min-residency-us", + &idle_state->target_residency); + if (err) { + pr_debug(" * %s missing min-residency-us property\n", + state_node->full_name); + return -EINVAL; + } + + idle_state->flags = CPUIDLE_FLAG_TIME_VALID; + if (of_property_read_bool(state_node, "local-timer-stop")) + idle_state->flags |= CPUIDLE_FLAG_TIMER_STOP; + /* + * TODO: + * replace with kstrdup and pointer assignment when name + * and desc become string pointers + */ + strncpy(idle_state->name, state_node->name, CPUIDLE_NAME_LEN - 1); + strncpy(idle_state->desc, state_node->name, CPUIDLE_DESC_LEN - 1); + return 0; +} + +/** + * dt_init_idle_driver() - Parse the DT idle states and initialize the + * idle driver states array + * @drv: Pointer to CPU idle driver to be initialized + * @start_idx: First idle state index to be initialized + * + * If DT idle states are detected and are valid the state count and states + * array entries in the cpuidle driver are initialized accordingly starting + * from index start_idx. + * + * Return: number of valid DT idle states parsed, <0 on failure + */ +int dt_init_idle_driver(struct cpuidle_driver *drv, unsigned int start_idx) +{ + struct cpuidle_state *idle_state; + struct device_node *state_node, *cpu_node; + int i; + unsigned int state_idx = start_idx; + + if (state_idx >= CPUIDLE_STATE_MAX) + return -EINVAL; + /* + * We get the idle states for the first logical cpu in the + * driver mask. The kernel does not check idle states on all + * cpus in the driver mask, they are assumed to be the same + * by default. + */ + cpu_node = of_cpu_device_node_get(cpumask_first(drv->cpumask)); + + for (i = 0; ; i++) { + int err; + + state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i); + if (!state_node) + break; + + if (state_idx == CPUIDLE_STATE_MAX) { + pr_warn("State index reached static CPU idle driver states array size\n"); + break; + } + + idle_state = &drv->states[state_idx++]; + err = init_state_node(idle_state, state_node); + if (err) { + pr_err("Parsing idle state node %s failed with err %d\n", + state_node->full_name, err); + return err; + } + } + /* + * Update the driver state count only if some valid DT idle states + * were detected + */ + if (i) + drv->state_count = state_idx; + + /* + * Return the number of present and valid DT idle states, which can + * also be 0 on platforms with missing DT idle states or legacy DT + * configuration predating the DT idle states bindings. + */ + return i; +} +EXPORT_SYMBOL_GPL(dt_init_idle_driver); diff --git a/drivers/cpuidle/dt_idle_states.h b/drivers/cpuidle/dt_idle_states.h new file mode 100644 index 0000000..728c37c --- /dev/null +++ b/drivers/cpuidle/dt_idle_states.h @@ -0,0 +1,5 @@ +#ifndef __DT_IDLE_STATES +#define __DT_IDLE_STATES + +int dt_init_idle_driver(struct cpuidle_driver *drv, unsigned int start_idx); +#endif -- 1.9.1
WARNING: multiple messages have this Message-ID (diff)
From: lorenzo.pieralisi@arm.com (Lorenzo Pieralisi) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v7 3/8] drivers: cpuidle: implement DT based idle states infrastructure Date: Wed, 13 Aug 2014 16:52:02 +0100 [thread overview] Message-ID: <1407945127-27554-4-git-send-email-lorenzo.pieralisi@arm.com> (raw) In-Reply-To: <1407945127-27554-1-git-send-email-lorenzo.pieralisi@arm.com> On most common ARM systems, the low-power states a CPU can be put into are not discoverable in HW and require device tree bindings to describe power down suspend operations and idle states parameters. In order to enable DT based idle states and configure idle drivers, this patch implements the bulk infrastructure required to parse the device tree idle states bindings and initialize the corresponding CPUidle driver states data. The parsing API accepts a start index that defines the first idle state that should be initialized by the parsing code in order to give new and legacy driver flexibility over which states should be parsed using the new DT mechanism. The idle states list is obtained from the first cpu in the driver cpumask, which implicitly means the parsing code expects idle states (and related list of phandles) to be the same for all CPUs in the CPUidle driver mask. The kernel does not check this assumption, it must be enforced by the bootloader to ensure correct system behaviour. Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> --- drivers/cpuidle/Kconfig | 3 + drivers/cpuidle/Makefile | 1 + drivers/cpuidle/dt_idle_states.c | 140 +++++++++++++++++++++++++++++++++++++++ drivers/cpuidle/dt_idle_states.h | 5 ++ 4 files changed, 149 insertions(+) create mode 100644 drivers/cpuidle/dt_idle_states.c create mode 100644 drivers/cpuidle/dt_idle_states.h diff --git a/drivers/cpuidle/Kconfig b/drivers/cpuidle/Kconfig index 32748c3..8deb934 100644 --- a/drivers/cpuidle/Kconfig +++ b/drivers/cpuidle/Kconfig @@ -25,6 +25,9 @@ config CPU_IDLE_GOV_MENU bool "Menu governor (for tickless system)" default y +config DT_IDLE_STATES + bool + menu "ARM CPU Idle Drivers" depends on ARM source "drivers/cpuidle/Kconfig.arm" diff --git a/drivers/cpuidle/Makefile b/drivers/cpuidle/Makefile index 11edb31..002b653 100644 --- a/drivers/cpuidle/Makefile +++ b/drivers/cpuidle/Makefile @@ -4,6 +4,7 @@ obj-y += cpuidle.o driver.o governor.o sysfs.o governors/ obj-$(CONFIG_ARCH_NEEDS_CPU_IDLE_COUPLED) += coupled.o +obj-$(CONFIG_DT_IDLE_STATES) += dt_idle_states.o ################################################################################## # ARM SoC drivers diff --git a/drivers/cpuidle/dt_idle_states.c b/drivers/cpuidle/dt_idle_states.c new file mode 100644 index 0000000..207f8f7 --- /dev/null +++ b/drivers/cpuidle/dt_idle_states.c @@ -0,0 +1,140 @@ +/* + * DT idle states parsing code. + * + * Copyright (C) 2014 ARM Ltd. + * Author: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#define pr_fmt(fmt) "DT idle-states: " fmt + +#include <linux/cpuidle.h> +#include <linux/cpumask.h> +#include <linux/errno.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_device.h> + +#include "dt_idle_states.h" + +static int init_state_node(struct cpuidle_state *idle_state, + struct device_node *state_node) +{ + int err; + + err = of_property_read_u32(state_node, "wakeup-latency-us", + &idle_state->exit_latency); + if (err) { + u32 entry_latency, exit_latency; + + err = of_property_read_u32(state_node, "entry-latency-us", + &entry_latency); + if (err) { + pr_debug(" * %s missing entry-latency-us property\n", + state_node->full_name); + return -EINVAL; + } + + err = of_property_read_u32(state_node, "exit-latency-us", + &exit_latency); + if (err) { + pr_debug(" * %s missing exit-latency-us property\n", + state_node->full_name); + return -EINVAL; + } + /* + * If wakeup-latency-us is missing, default to entry+exit + * latencies as defined in idle states bindings + */ + idle_state->exit_latency = entry_latency + exit_latency; + } + + err = of_property_read_u32(state_node, "min-residency-us", + &idle_state->target_residency); + if (err) { + pr_debug(" * %s missing min-residency-us property\n", + state_node->full_name); + return -EINVAL; + } + + idle_state->flags = CPUIDLE_FLAG_TIME_VALID; + if (of_property_read_bool(state_node, "local-timer-stop")) + idle_state->flags |= CPUIDLE_FLAG_TIMER_STOP; + /* + * TODO: + * replace with kstrdup and pointer assignment when name + * and desc become string pointers + */ + strncpy(idle_state->name, state_node->name, CPUIDLE_NAME_LEN - 1); + strncpy(idle_state->desc, state_node->name, CPUIDLE_DESC_LEN - 1); + return 0; +} + +/** + * dt_init_idle_driver() - Parse the DT idle states and initialize the + * idle driver states array + * @drv: Pointer to CPU idle driver to be initialized + * @start_idx: First idle state index to be initialized + * + * If DT idle states are detected and are valid the state count and states + * array entries in the cpuidle driver are initialized accordingly starting + * from index start_idx. + * + * Return: number of valid DT idle states parsed, <0 on failure + */ +int dt_init_idle_driver(struct cpuidle_driver *drv, unsigned int start_idx) +{ + struct cpuidle_state *idle_state; + struct device_node *state_node, *cpu_node; + int i; + unsigned int state_idx = start_idx; + + if (state_idx >= CPUIDLE_STATE_MAX) + return -EINVAL; + /* + * We get the idle states for the first logical cpu in the + * driver mask. The kernel does not check idle states on all + * cpus in the driver mask, they are assumed to be the same + * by default. + */ + cpu_node = of_cpu_device_node_get(cpumask_first(drv->cpumask)); + + for (i = 0; ; i++) { + int err; + + state_node = of_parse_phandle(cpu_node, "cpu-idle-states", i); + if (!state_node) + break; + + if (state_idx == CPUIDLE_STATE_MAX) { + pr_warn("State index reached static CPU idle driver states array size\n"); + break; + } + + idle_state = &drv->states[state_idx++]; + err = init_state_node(idle_state, state_node); + if (err) { + pr_err("Parsing idle state node %s failed with err %d\n", + state_node->full_name, err); + return err; + } + } + /* + * Update the driver state count only if some valid DT idle states + * were detected + */ + if (i) + drv->state_count = state_idx; + + /* + * Return the number of present and valid DT idle states, which can + * also be 0 on platforms with missing DT idle states or legacy DT + * configuration predating the DT idle states bindings. + */ + return i; +} +EXPORT_SYMBOL_GPL(dt_init_idle_driver); diff --git a/drivers/cpuidle/dt_idle_states.h b/drivers/cpuidle/dt_idle_states.h new file mode 100644 index 0000000..728c37c --- /dev/null +++ b/drivers/cpuidle/dt_idle_states.h @@ -0,0 +1,5 @@ +#ifndef __DT_IDLE_STATES +#define __DT_IDLE_STATES + +int dt_init_idle_driver(struct cpuidle_driver *drv, unsigned int start_idx); +#endif -- 1.9.1
next prev parent reply other threads:[~2014-08-13 15:52 UTC|newest] Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-08-13 15:51 [PATCH v7 0/8] ARM generic idle states Lorenzo Pieralisi 2014-08-13 15:51 ` Lorenzo Pieralisi 2014-08-13 15:52 ` [PATCH v7 1/8] arm64: kernel: refactor the CPU suspend API for retention states Lorenzo Pieralisi 2014-08-13 15:52 ` Lorenzo Pieralisi 2014-08-18 7:47 ` Hanjun Guo 2014-08-18 7:47 ` Hanjun Guo 2014-08-18 14:20 ` Catalin Marinas 2014-08-18 14:20 ` Catalin Marinas 2014-08-13 15:52 ` [PATCH v7 2/8] Documentation: arm: define DT idle states bindings Lorenzo Pieralisi 2014-08-13 15:52 ` Lorenzo Pieralisi [not found] ` <1407945127-27554-3-git-send-email-lorenzo.pieralisi-5wv7dgnIgG8@public.gmane.org> 2014-08-13 19:25 ` Lina Iyer 2014-08-13 19:25 ` Lina Iyer 2014-08-13 22:11 ` Lorenzo Pieralisi 2014-08-13 22:11 ` Lorenzo Pieralisi 2014-08-15 17:20 ` Lina Iyer 2014-08-15 17:20 ` Lina Iyer 2014-08-15 17:51 ` Lorenzo Pieralisi 2014-08-15 17:51 ` Lorenzo Pieralisi 2014-08-18 14:20 ` Catalin Marinas 2014-08-18 14:20 ` Catalin Marinas 2014-08-13 15:52 ` Lorenzo Pieralisi [this message] 2014-08-13 15:52 ` [PATCH v7 3/8] drivers: cpuidle: implement DT based idle states infrastructure Lorenzo Pieralisi 2014-08-13 16:31 ` Nicolas Pitre 2014-08-13 16:31 ` Nicolas Pitre 2014-08-13 17:04 ` Lorenzo Pieralisi 2014-08-13 17:04 ` Lorenzo Pieralisi 2014-08-13 17:29 ` Nicolas Pitre 2014-08-13 17:29 ` Nicolas Pitre 2014-08-14 11:29 ` Lorenzo Pieralisi 2014-08-14 11:29 ` Lorenzo Pieralisi 2014-08-14 15:47 ` Nicolas Pitre 2014-08-14 15:47 ` Nicolas Pitre 2014-08-14 16:02 ` Lorenzo Pieralisi 2014-08-14 16:02 ` Lorenzo Pieralisi 2014-08-18 14:21 ` Catalin Marinas 2014-08-18 14:21 ` Catalin Marinas 2014-08-13 15:52 ` [PATCH v7 4/8] arm64: kernel: introduce cpu_init_idle CPU operation Lorenzo Pieralisi 2014-08-13 15:52 ` Lorenzo Pieralisi 2014-08-18 14:21 ` Catalin Marinas 2014-08-18 14:21 ` Catalin Marinas [not found] ` <1407945127-27554-1-git-send-email-lorenzo.pieralisi-5wv7dgnIgG8@public.gmane.org> 2014-08-13 15:52 ` [PATCH v7 5/8] arm64: add PSCI CPU_SUSPEND based cpu_suspend support Lorenzo Pieralisi 2014-08-13 15:52 ` Lorenzo Pieralisi 2014-08-18 14:21 ` Catalin Marinas 2014-08-18 14:21 ` Catalin Marinas 2014-08-13 15:52 ` [PATCH v7 6/8] drivers: cpuidle: CPU idle ARM64 driver Lorenzo Pieralisi 2014-08-13 15:52 ` Lorenzo Pieralisi 2014-08-18 14:21 ` Catalin Marinas 2014-08-18 14:21 ` Catalin Marinas 2014-08-18 22:30 ` Lorenzo Pieralisi 2014-08-18 22:30 ` Lorenzo Pieralisi 2014-08-18 14:21 ` Catalin Marinas 2014-08-18 14:21 ` Catalin Marinas 2014-08-18 22:25 ` Lorenzo Pieralisi 2014-08-18 22:25 ` Lorenzo Pieralisi 2014-08-13 15:52 ` [PATCH v7 7/8] drivers: cpuidle: initialize big.LITTLE driver through DT Lorenzo Pieralisi 2014-08-13 15:52 ` Lorenzo Pieralisi 2014-08-18 14:21 ` Catalin Marinas 2014-08-18 14:21 ` Catalin Marinas 2014-08-13 15:52 ` [PATCH v7 8/8] drivers: cpuidle: initialize Exynos " Lorenzo Pieralisi 2014-08-13 15:52 ` Lorenzo Pieralisi 2014-08-15 21:12 ` Lina Iyer 2014-08-15 21:12 ` Lina Iyer 2014-08-15 21:40 ` Lorenzo Pieralisi 2014-08-15 21:40 ` Lorenzo Pieralisi 2014-08-15 21:45 ` Lina Iyer 2014-08-15 21:45 ` Lina Iyer 2014-08-15 21:52 ` Lorenzo Pieralisi 2014-08-15 21:52 ` Lorenzo Pieralisi 2014-08-18 14:22 ` Catalin Marinas 2014-08-18 14:22 ` Catalin Marinas
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1407945127-27554-4-git-send-email-lorenzo.pieralisi@arm.com \ --to=lorenzo.pieralisi@arm.com \ --cc=Charles.Garcia-Tobin@arm.com \ --cc=amit.kucheria@linaro.org \ --cc=ananaza@iki.fi \ --cc=broonie@kernel.org \ --cc=catalin.marinas@arm.com \ --cc=daniel.lezcano@linaro.org \ --cc=devicetree@vger.kernel.org \ --cc=grant.likely@linaro.org \ --cc=k.chander@samsung.com \ --cc=khilman@linaro.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-pm@vger.kernel.org \ --cc=mark.rutland@arm.com \ --cc=nico@linaro.org \ --cc=paul@pwsan.com \ --cc=pdeschrijver@nvidia.com \ --cc=robh+dt@kernel.org \ --cc=santosh.shilimkar@ti.com \ --cc=sboyd@codeaurora.org \ --cc=sebcape@gmail.com \ --cc=sudeep.holla@arm.com \ --cc=t.figa@samsung.com \ --cc=vincent.guittot@linaro.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.