From patchwork Mon Jul 21 16:06:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Pieralisi X-Patchwork-Id: 33993 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f69.google.com (mail-yh0-f69.google.com [209.85.213.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A25E620492 for ; Mon, 21 Jul 2014 16:06:56 +0000 (UTC) Received: by mail-yh0-f69.google.com with SMTP id v1sf24198662yhn.0 for ; Mon, 21 Jul 2014 09:06:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=Bm1HziQlKp79j2+5sx5d6oGeA2NSF+fK3PdKpLvZdK8=; b=gC3Yi9FYcufp+8sdAOgBkwW6ST0tUlB+9RaEDVCXRR83pZSI3LSg3cX88mAKazaP3Z Cv0NOgA8aUKxmKa2rNpmwCb/0Zw+f0UePvUlq3EqnXpR6FCPCWLzJHG7mAMFXP1VjQzF ddbHVyTl7C8RDfwUKrQeaZUwjkfO+5ad659IjRNf8HK1XYebP2DuEtOnQfDE3yWHx0U4 JUoPQC91a5BiJL91wdSGR+Be2/D4dSvHxlpwXpPQI8eRucpYuhbGhW4ZCGIgTUKTieI+ pnlDhuRZR/WbauRH4MaThSJemIqMNUTmEWI82rBlQFk8wtxhtA+TTz3mcSiZGyNV2QyJ /h2Q== X-Gm-Message-State: ALoCoQne730H5bZS/hhRQy23O4WuojhO8nwvEsFayzwxCEDwlV3mThYyB+dNLcQ8wCo0zsGTva7U X-Received: by 10.236.129.2 with SMTP id g2mr11574984yhi.2.1405958816432; Mon, 21 Jul 2014 09:06:56 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.31.101 with SMTP id e92ls1211672qge.37.gmail; Mon, 21 Jul 2014 09:06:56 -0700 (PDT) X-Received: by 10.53.1.231 with SMTP id bj7mr25692501vdd.49.1405958816281; Mon, 21 Jul 2014 09:06:56 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id e5si3974198vcz.37.2014.07.21.09.06.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Jul 2014 09:06:56 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id la4so12466114vcb.37 for ; Mon, 21 Jul 2014 09:06:56 -0700 (PDT) X-Received: by 10.52.244.138 with SMTP id xg10mr26020240vdc.40.1405958816191; Mon, 21 Jul 2014 09:06:56 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp124827vcb; Mon, 21 Jul 2014 09:06:55 -0700 (PDT) X-Received: by 10.70.43.170 with SMTP id x10mr26753676pdl.9.1405958814943; Mon, 21 Jul 2014 09:06:54 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qe5si14693995pac.103.2014.07.21.09.06.54; Mon, 21 Jul 2014 09:06:54 -0700 (PDT) Received-SPF: none (google.com: devicetree-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932543AbaGUQGq (ORCPT + 8 others); Mon, 21 Jul 2014 12:06:46 -0400 Received: from service87.mimecast.com ([91.220.42.44]:41572 "EHLO service87.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932776AbaGUQGl (ORCPT ); Mon, 21 Jul 2014 12:06:41 -0400 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Mon, 21 Jul 2014 17:06:39 +0100 Received: from red-moon.cambridge.arm.com ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 21 Jul 2014 17:06:36 +0100 From: Lorenzo Pieralisi To: linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org Cc: devicetree@vger.kernel.org, Lorenzo Pieralisi , Mark Rutland , Sudeep Holla , Catalin Marinas , Charles Garcia Tobin , Nicolas Pitre , Rob Herring , Grant Likely , Peter De Schrijver , Santosh Shilimkar , Daniel Lezcano , Amit Kucheria , Vincent Guittot , Antti Miettinen , Stephen Boyd , Kevin Hilman , Sebastian Capella , Tomasz Figa , Mark Brown , Paul Walmsley , Chander Kashyap , Geoff Levand , Bartlomiej Zolnierkiewicz Subject: [PATCH v6 2/7] drivers: cpuidle: implement DT based idle states infrastructure Date: Mon, 21 Jul 2014 17:06:21 +0100 Message-Id: <1405958786-17243-3-git-send-email-lorenzo.pieralisi@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1405958786-17243-1-git-send-email-lorenzo.pieralisi@arm.com> References: <1405958786-17243-1-git-send-email-lorenzo.pieralisi@arm.com> X-OriginalArrivalTime: 21 Jul 2014 16:06:36.0477 (UTC) FILETIME=[BF9296D0:01CFA4FD] X-MC-Unique: 114072117063912501 Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lorenzo.pieralisi@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- drivers/cpuidle/Kconfig | 8 +++ drivers/cpuidle/Makefile | 1 + drivers/cpuidle/dt_idle_states.c | 138 +++++++++++++++++++++++++++++++++++++++ drivers/cpuidle/dt_idle_states.h | 5 ++ 4 files changed, 152 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 1b96fb9..414e7a96 100644 --- a/drivers/cpuidle/Kconfig +++ b/drivers/cpuidle/Kconfig @@ -30,6 +30,14 @@ config CPU_IDLE_GOV_MENU bool "Menu governor (for tickless system)" default y +config DT_IDLE_STATES + bool "Idle states DT support" + depends on ARM || ARM64 + help + Allows the CPU idle framework to initialize CPU idle drivers + state data by using DT provided nodes compliant with idle states + device tree bindings. + menu "ARM CPU Idle Drivers" depends on ARM source "drivers/cpuidle/Kconfig.arm" diff --git a/drivers/cpuidle/Makefile b/drivers/cpuidle/Makefile index d8bb1ff..b27a062 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..5413132 --- /dev/null +++ b/drivers/cpuidle/dt_idle_states.c @@ -0,0 +1,138 @@ +/* + * DT idle states parsing code. + * + * Copyright (C) 2014 ARM Ltd. + * Author: Lorenzo Pieralisi + * + * 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 +#include +#include +#include +#include +#include +#include + +#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 + * + * On success the states array in the cpuidle driver contains + * initialized entries in the states array, starting from index start_idx. + * + * Return: + * 0 on success + * <0 on failure + */ +int dt_init_idle_driver(struct cpuidle_driver *drv, unsigned int start_idx) +{ + unsigned int i, state_idx = start_idx; + struct cpuidle_state *idle_state; + struct device_node *state_node, *cpu_node; + + + 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) + return err; + } + + /* + * If no idle states are detected, return an error and let the idle + * driver initialization fail accordingly since initializing a driver + * with simple WFI as an idle state is equivalent to letting the + * kernel run the default idle loop. + */ + if (!i) + return -ENODATA; + + drv->state_count = state_idx; + return 0; +} +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