From patchwork Wed Aug 15 10:02:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean Pihet X-Patchwork-Id: 1325161 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id ECCB8DFFED for ; Wed, 15 Aug 2012 10:06:35 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T1aRo-0006Yn-Vc; Wed, 15 Aug 2012 10:03:33 +0000 Received: from mail-we0-f177.google.com ([74.125.82.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T1aRX-0006Uo-DB for linux-arm-kernel@lists.infradead.org; Wed, 15 Aug 2012 10:03:16 +0000 Received: by weyr3 with SMTP id r3so962134wey.36 for ; Wed, 15 Aug 2012 03:03:13 -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=qXKzuPLojjJmgKsIpQfNIRvbXrqVRcuK8Ux1O5HGCj8=; b=MZAkB6o78UClCnWBP/YfZpYnbPdYiC+eefwRTNg3Ooy450JVSgb3nX20QH+GWorkn1 x9jZzPzlSD8Fuh0mGb2yHdZkqccGERLbrs9cLSmvuNqb17pBRhA/BRQ+WBl00mt2T0Ud +HtiVDVCYmHcvM7/qU0aDQZF18NZcDzL6y/gc+cWRNCXg51twKO5GHNT7grQW/UXQzcY 8XOc47f8v+sN51AkGmNKhkns2bWtjFLUqGvayQBt7gjFPW1IQ0cujJpy+wTITvtg2YOb Nfi6F37/oiAyMtzk0cGprjmsKp9glMX9ILG2uy4Lgg13LaEcUDD5DZt9AipMdsnClSPr G/sQ== Received: by 10.216.241.198 with SMTP id g48mr9375697wer.156.1345024993006; Wed, 15 Aug 2012 03:03:13 -0700 (PDT) Received: from localhost.localdomain (49.68-66-87.adsl-dyn.isp.belgacom.be. [87.66.68.49]) by mx.google.com with ESMTPS id q4sm27679093wix.9.2012.08.15.03.03.12 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 15 Aug 2012 03:03:12 -0700 (PDT) From: Jean Pihet To: linux-omap@vger.kernel.org, paul@pwsan.com, linux-arm-kernel@lists.infradead.org, khilman@ti.com, Rajendra Nayak , Santosh Shilimkar , Nishanth Menon Subject: [PATCH 3/8] ARM: OMAP2+: PM: add a lock to protect the powerdomains next state Date: Wed, 15 Aug 2012 12:02:43 +0200 Message-Id: <1345024968-28951-4-git-send-email-j-pihet@ti.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1345024968-28951-1-git-send-email-j-pihet@ti.com> References: <1345024968-28951-1-git-send-email-j-pihet@ti.com> X-Gm-Message-State: ALoCoQmtC5uEOZcAQMV99nmKkTY+rYRoiphcRb287gVc6Bya6LJON2GHSu37Di9pZiPN8v2awqsQ 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.177 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_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 pwrdm_set_next_fpwrst and pwrdm_read_next_fpwrst 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 mutex with a spinlock] Signed-off-by: Jean Pihet Reported-by: Ambresh K --- arch/arm/mach-omap2/powerdomain.c | 36 +++++++++++++++++++++++++++++++----- arch/arm/mach-omap2/powerdomain.h | 3 +++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/arch/arm/mach-omap2/powerdomain.c b/arch/arm/mach-omap2/powerdomain.c index 3a1f56c..a8f7a81 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 */ @@ -601,6 +602,22 @@ 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. + */ +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); +} + +/** * pwrdm_get_achievable_fpwrst() - Provide achievable functional state * @pwrdm: struct powerdomain * to set * @fpwrst: minimum functional state we would like to hit @@ -670,6 +687,7 @@ int pwrdm_set_next_fpwrst(struct powerdomain *pwrdm, int sleep_switch = -1, ret = 0, hwsup = 0; int new_fpwrst, next_fpwrst, pwrst, logic; u8 curr_pwrst; + unsigned long flags; if (!pwrdm || IS_ERR(pwrdm)) { pr_debug("%s: invalid params: pwrdm=%p\n", __func__, pwrdm); @@ -678,13 +696,15 @@ int pwrdm_set_next_fpwrst(struct powerdomain *pwrdm, pr_debug("%s(%s, fpwrst=%0x)\n", __func__, pwrdm->name, fpwrst); + spin_lock_irqsave(&pwrdm->lock, flags); + new_fpwrst = pwrdm_get_achievable_fpwrst(pwrdm, fpwrst); pwrst = pwrdm_fpwrst_to_pwrst(pwrdm, new_fpwrst); logic = pwrdm_fpwrst_to_logic_pwrst(pwrdm, new_fpwrst); - next_fpwrst = pwrdm_read_next_fpwrst(pwrdm); + next_fpwrst = _pwrdm_read_next_fpwrst(pwrdm); if (new_fpwrst == next_fpwrst) - return ret; + goto out; curr_pwrst = pwrdm_read_pwrst(pwrdm); if (curr_pwrst < PWRDM_POWER_ON) { @@ -732,6 +752,8 @@ int pwrdm_set_next_fpwrst(struct powerdomain *pwrdm, break; } +out: + spin_unlock_irqrestore(&pwrdm->lock, flags); return ret; } @@ -801,10 +823,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 45c449d..23b9da9 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;