From patchwork Mon Mar 20 10:19:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 9633685 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BD9B5601E9 for ; Mon, 20 Mar 2017 10:21:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD4FF2780C for ; Mon, 20 Mar 2017 10:21:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A216627F9A; Mon, 20 Mar 2017 10:21:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DA632780C for ; Mon, 20 Mar 2017 10:21:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753170AbdCTKVC (ORCPT ); Mon, 20 Mar 2017 06:21:02 -0400 Received: from mail-lf0-f45.google.com ([209.85.215.45]:35986 "EHLO mail-lf0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753679AbdCTKUX (ORCPT ); Mon, 20 Mar 2017 06:20:23 -0400 Received: by mail-lf0-f45.google.com with SMTP id y193so53267795lfd.3 for ; Mon, 20 Mar 2017 03:19:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8aF1bRw5WP9SnbVdBCFgnc6fPLCNiUqMgzg6h6r4R5Y=; b=XhHrkqi3343PRIfX4jMNNh75IYXh2RbLFIahl1GRV8g8h6AQh18O/cNALbXRLCcUnG kt+O//f+IqvrnfTboMFIsM6wBV21yBBjLts46mdE3oA1NeYiKY7zK0lMf2S2wh97W6/h sKJuicq0ULv+4AGvXBpUSmjgfTi2HPUzJ6Z/w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8aF1bRw5WP9SnbVdBCFgnc6fPLCNiUqMgzg6h6r4R5Y=; b=lVlNLxJNPaehhSinGlWIUpl4cZyD75CkUc2tBuVwLsLTn8/dZentaP/MTWPUmsL7w2 pGyZ1V41RiIjT7CD11VrCw7dcgtLDkpbwHvl07lsTLjXbROoum01KyrBIimwnLonEeov l7QawSMzoACCTf5+qo3njRvKeJ1L8N3SfuQp+mTdMvmLTxZFGXHNuNel9LpYXxp98wQt LAS/9TzA9tEUTvsxmKk2yEeoaAhYPDOcEqCxhsiNmqQSMHXXyWCK/j7x0+VmUT7vrsAD Pm3QFQbOFzg3QyNcbNBBE2zzIgTKvlpfNJuqEWsMbRuB7cbdNOE+cVxObwPpwTdp/3EI fbHg== X-Gm-Message-State: AFeK/H3NehK+R58jFcnUvUZPx690d5OnQahFkQ1O3PbrWDGDG/5kDBOMy8EHTVZQkno9ak3t X-Received: by 10.46.71.138 with SMTP id u132mr8538545lja.43.1490005176202; Mon, 20 Mar 2017 03:19:36 -0700 (PDT) Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id c5sm223825lfk.51.2017.03.20.03.19.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Mar 2017 03:19:35 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Ulf Hansson , linux-pm@vger.kernel.org Cc: Len Brown , Pavel Machek , Kevin Hilman , Geert Uytterhoeven , Lina Iyer , Jon Hunter , Marek Szyprowski , Viresh Kumar Subject: [PATCH 2/4] PM / Domains: Enable users of genpd to specify always on PM domains Date: Mon, 20 Mar 2017 11:19:21 +0100 Message-Id: <1490005163-28633-3-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490005163-28633-1-git-send-email-ulf.hansson@linaro.org> References: <1490005163-28633-1-git-send-email-ulf.hansson@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The current way to implement an always on PM domain consists of returning -EBUSY from the ->power_off() callback. This is a bit different compared to using the always on genpd governor, which prevents the PM domain from being powered off via runtime suspend, but not via system suspend. The approach to return -EBUSY from the ->power_off() callback to support always on PM domains in genpd is suboptimal. That is because it requires genpd to follow the regular execution path of the power off sequence, which ends by invoking the ->power_off() callback. To enable genpd to early abort the power off sequence for always on PM domains, it needs static information about these configurations. Therefore let's add a new genpd configuration flag, GENPD_FLAG_ALWAYS_ON. Users of the new GENPD_FLAG_ALWAYS_ON flag, are by genpd required to make sure the PM domain is powered on before calling pm_genpd_init(). Moreover, users don't need to implement the ->power_off() callback, as genpd doesn't ever invoke it. Signed-off-by: Ulf Hansson Reviewed-by: Viresh Kumar Reviewed-by: Geert Uytterhoeven Reviewed-by: Bartlomiej Zolnierkiewicz --- drivers/base/power/domain.c | 14 ++++++++++++-- include/linux/pm_domain.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 7a8e70d..e63712d 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -123,6 +123,7 @@ static const struct genpd_lock_ops genpd_spin_ops = { #define genpd_status_on(genpd) (genpd->status == GPD_STATE_ACTIVE) #define genpd_is_irq_safe(genpd) (genpd->flags & GENPD_FLAG_IRQ_SAFE) +#define genpd_is_always_on(genpd) (genpd->flags & GENPD_FLAG_ALWAYS_ON) static inline bool irq_safe_dev_in_no_sleep_domain(struct device *dev, struct generic_pm_domain *genpd) @@ -300,7 +301,12 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on, if (!genpd_status_on(genpd) || genpd->prepared_count > 0) return 0; - if (atomic_read(&genpd->sd_count) > 0) + /* + * Abort power off for the PM domain in the following situations: + * (1) The domain is configured as always on. + * (2) When the domain has a subdomain being powered on. + */ + if (genpd_is_always_on(genpd) || atomic_read(&genpd->sd_count) > 0) return -EBUSY; list_for_each_entry(pdd, &genpd->dev_list, list_node) { @@ -752,7 +758,7 @@ static void genpd_sync_power_off(struct generic_pm_domain *genpd, bool use_lock, { struct gpd_link *link; - if (!genpd_status_on(genpd)) + if (!genpd_status_on(genpd) || genpd_is_always_on(genpd)) return; if (genpd->suspended_count != genpd->device_count @@ -1491,6 +1497,10 @@ int pm_genpd_init(struct generic_pm_domain *genpd, genpd->dev_ops.start = pm_clk_resume; } + /* Always-on domains must be powered on at initialization. */ + if (genpd_is_always_on(genpd) && !genpd_status_on(genpd)) + return -EINVAL; + /* Use only one "off" state if there were no states declared */ if (genpd->state_count == 0) { ret = genpd_set_default_power_state(genpd); diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 5339ed5..9b6abe6 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -20,6 +20,7 @@ /* Defines used for the flags field in the struct generic_pm_domain */ #define GENPD_FLAG_PM_CLK (1U << 0) /* PM domain uses PM clk */ #define GENPD_FLAG_IRQ_SAFE (1U << 1) /* PM domain operates in atomic */ +#define GENPD_FLAG_ALWAYS_ON (1U << 2) /* PM domain is always powered on */ enum gpd_status { GPD_STATE_ACTIVE = 0, /* PM domain is active */