From patchwork Wed Sep 12 09:55:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 1441861 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (unknown [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id D8370DF28C for ; Wed, 12 Sep 2012 10:06:18 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TBjgG-0006mn-Gj; Wed, 12 Sep 2012 09:56:24 +0000 Received: from mail-wg0-f41.google.com ([74.125.82.41]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TBjfk-0006g9-K1 for linux-arm-kernel@lists.infradead.org; Wed, 12 Sep 2012 09:55:56 +0000 Received: by wgbds1 with SMTP id ds1so2536621wgb.0 for ; Wed, 12 Sep 2012 02:55:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=W5ebzHboJ2ETH36ck87z1GZgaWgyaUXRAUGf32Zuxhc=; b=SjPTP8AZxepIdfqNpPWapHLS4Vyyo0kXF+5FWFcVC+vBUrjeqro2XeMhUtRxa2dGrL nEeif5T0u1ZDAnhZm5WL8JENs1Cr8Lt550aQz27vMQid6AIjd5JceR6x2d/KOkBS8zoJ L5JvaWKjLY7L2hucRBfJLIxEKjNVY8MQN6ZSLZjJPFY5gKfha3p9CFkeRgSpPxfvHFnc gQRhzcAoaC5Qv4MIiurHhx2z7yoyXqSyhWwfqrmBatfyUavo290fhnPFBOfFMYYyUku5 LvtTxSG3xon+jyuzp6UthYtle7aWsVuUtmKJkvgM8LB3iZn24CSvm5FBF5ZrFSfJgmG+ 910Q== Received: by 10.180.106.137 with SMTP id gu9mr31524419wib.20.1347443750435; Wed, 12 Sep 2012 02:55:50 -0700 (PDT) Received: from localhost.localdomain (52.60-66-87.adsl-dyn.isp.belgacom.be. [87.66.60.52]) by mx.google.com with ESMTPS id w7sm7312997wiz.0.2012.09.12.02.55.49 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 12 Sep 2012 02:55:50 -0700 (PDT) From: Jean Pihet To: linux-omap@vger.kernel.org, paul@pwsan.com, linux-arm-kernel@lists.infradead.org, khilman@ti.com, Benoit Cousson , Santosh Shilimkar , Nishanth Menon , Rajendra Nayak Subject: [PATCH 2/7] ARM: OMAP2+: PM: add a lock to protect the powerdomains next state Date: Wed, 12 Sep 2012 11:55:27 +0200 Message-Id: <1347443732-7411-3-git-send-email-j-pihet@ti.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1347443732-7411-1-git-send-email-j-pihet@ti.com> References: <1347443732-7411-1-git-send-email-j-pihet@ti.com> X-Gm-Message-State: ALoCoQncqCAtoc1Up3g005UzRiI8+ZiHkJ3Fk83PW+3p6Sn3MlPa5gJRXaobiDjflFvA3j2PsLXB X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.41 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Jean Pihet X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org pwrdm_set_fpwrst, pwrdm_set_next_fpwrst and pwrdm_read_next_fpwrst are intented to be the only API to program and request the next state of a power domain. This patch protects the power domain next state settings and structs from concurrent accesses by the use of a lock. A spinlock is used since the API functions can be called from atomic context (.i.e) either from cpuidle path or suspend path. [ambresh@ti.com: reported the atomic context issue and suggested to replace the initial mutex with a spinlock] Signed-off-by: Jean Pihet Reported-by: Ambresh K --- arch/arm/mach-omap2/powerdomain.c | 40 ++++++++++++++++++++++++++++++++---- arch/arm/mach-omap2/powerdomain.h | 3 ++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/arch/arm/mach-omap2/powerdomain.c b/arch/arm/mach-omap2/powerdomain.c index 18c21fa..f4b219f 100644 --- a/arch/arm/mach-omap2/powerdomain.c +++ b/arch/arm/mach-omap2/powerdomain.c @@ -102,6 +102,7 @@ static int _pwrdm_register(struct powerdomain *pwrdm) INIT_LIST_HEAD(&pwrdm->voltdm_node); voltdm_add_pwrdm(voltdm, pwrdm); + spin_lock_init(&pwrdm->lock); list_add(&pwrdm->node, &pwrdm_list); /* Initialize the powerdomain's state counter */ @@ -394,6 +395,22 @@ static int _pwrdm_pwrst_to_fpwrst(struct powerdomain *pwrdm, u8 pwrst, u8 logic) } +/** + * _pwrdm_read_next_fpwrst - get next powerdomain functional power state + * @pwrdm: struct powerdomain * to get power state + * + * Return the powerdomain @pwrdm's next functional power state. + * Returns -EINVAL if the powerdomain pointer is null or returns + * the next power state upon success. + */ +static int _pwrdm_read_next_fpwrst(struct powerdomain *pwrdm) +{ + int next_pwrst = pwrdm_read_next_pwrst(pwrdm); + int next_logic = pwrdm_read_logic_retst(pwrdm); + + return _pwrdm_pwrst_to_fpwrst(pwrdm, next_pwrst, next_logic); +} + /* Public functions */ /** @@ -677,6 +694,7 @@ int pwrdm_set_fpwrst(struct powerdomain *pwrdm, enum pwrdm_func_state fpwrst) int pwrst = _pwrdm_fpwrst_to_pwrst(pwrdm, fpwrst); int logic = _pwrdm_fpwrst_to_logic_pwrst(pwrdm, fpwrst); int sleep_switch = -1, ret = 0, hwsup = 0; + unsigned long flags; if (!pwrdm || IS_ERR(pwrdm) || (pwrst < 0) || (logic < 0)) { pr_debug("%s: invalid params: pwrdm=%p, fpwrst=%0x\n", @@ -687,9 +705,11 @@ int pwrdm_set_fpwrst(struct powerdomain *pwrdm, enum pwrdm_func_state fpwrst) pr_debug("%s: set fpwrst %0x to pwrdm %s\n", __func__, fpwrst, pwrdm->name); - next_fpwrst = pwrdm_read_next_fpwrst(pwrdm); + spin_lock_irqsave(&pwrdm->lock, flags); + + next_fpwrst = _pwrdm_read_next_fpwrst(pwrdm); if (next_fpwrst == fpwrst) - return ret; + goto out; curr_pwrst = pwrdm_read_pwrst(pwrdm); if (curr_pwrst < PWRDM_POWER_ON) { @@ -725,6 +745,8 @@ int pwrdm_set_fpwrst(struct powerdomain *pwrdm, enum pwrdm_func_state fpwrst) break; } +out: + spin_unlock_irqrestore(&pwrdm->lock, flags); return ret; } @@ -741,6 +763,7 @@ int pwrdm_set_next_fpwrst(struct powerdomain *pwrdm, int pwrst = _pwrdm_fpwrst_to_pwrst(pwrdm, fpwrst); int logic = _pwrdm_fpwrst_to_logic_pwrst(pwrdm, fpwrst); int ret = 0; + unsigned long flags; if (!pwrdm || IS_ERR(pwrdm) || (pwrst < 0) || (logic < 0)) { pr_debug("%s: invalid params: pwrdm=%p, fpwrst=%0x\n", @@ -751,6 +774,8 @@ int pwrdm_set_next_fpwrst(struct powerdomain *pwrdm, pr_debug("%s: set fpwrst %0x to pwrdm %s\n", __func__, fpwrst, pwrdm->name); + spin_lock_irqsave(&pwrdm->lock, flags); + ret = pwrdm_set_logic_retst(pwrdm, logic); if (ret) pr_err("%s: unable to set logic state %0x of powerdomain: %s\n", @@ -761,6 +786,7 @@ int pwrdm_set_next_fpwrst(struct powerdomain *pwrdm, pr_err("%s: unable to set power state %0x of powerdomain: %s\n", __func__, pwrst, pwrdm->name); + spin_unlock_irqrestore(&pwrdm->lock, flags); return ret; }; @@ -837,10 +863,14 @@ int pwrdm_read_next_pwrst(struct powerdomain *pwrdm) */ int pwrdm_read_next_fpwrst(struct powerdomain *pwrdm) { - int next_pwrst = pwrdm_read_next_pwrst(pwrdm); - int next_logic = pwrdm_read_logic_retst(pwrdm); + int ret; + unsigned long flags; - return _pwrdm_pwrst_to_fpwrst(pwrdm, next_pwrst, next_logic); + spin_lock_irqsave(&pwrdm->lock, flags); + ret = _pwrdm_read_next_fpwrst(pwrdm); + spin_unlock_irqrestore(&pwrdm->lock, flags); + + return ret; } /** diff --git a/arch/arm/mach-omap2/powerdomain.h b/arch/arm/mach-omap2/powerdomain.h index aa5de4f..c3dc363 100644 --- a/arch/arm/mach-omap2/powerdomain.h +++ b/arch/arm/mach-omap2/powerdomain.h @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -109,6 +110,7 @@ struct powerdomain; * @pwrdm_clkdms: Clockdomains in this powerdomain * @node: list_head linking all powerdomains * @voltdm_node: list_head linking all powerdomains in a voltagedomain + * @lock: powerdomain next state registers protection lock * @pwrstctrl_offs: (AM33XX only) XXX_PWRSTCTRL reg offset from prcm_offs * @pwrstst_offs: (AM33XX only) XXX_PWRSTST reg offset from prcm_offs * @logicretstate_mask: (AM33XX only) mask for logic retention bitfield @@ -142,6 +144,7 @@ struct powerdomain { struct clockdomain *pwrdm_clkdms[PWRDM_MAX_CLKDMS]; struct list_head node; struct list_head voltdm_node; + spinlock_t lock; int state; unsigned state_counter[PWRDM_MAX_PWRSTS]; unsigned ret_logic_off_counter;