From patchwork Fri Sep 21 22:47:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hilman X-Patchwork-Id: 1493681 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 EA909DF28C for ; Fri, 21 Sep 2012 22:49:16 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TFC0d-0000yP-On; Fri, 21 Sep 2012 22:47:43 +0000 Received: from mail-pb0-f49.google.com ([209.85.160.49]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TFC0b-0000yB-6d for linux-arm-kernel@lists.infradead.org; Fri, 21 Sep 2012 22:47:41 +0000 Received: by pbbrq8 with SMTP id rq8so8892688pbb.36 for ; Fri, 21 Sep 2012 15:47:37 -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:x-gm-message-state; bh=XS48Qo5mYIVYXf1NAb9fCeH/RVpivTB66h3YPjRyJr8=; b=gJDqwMZ5PhSANbdzkokSzon0fN0tgTzftOzUHbgU9QHtVqkEWqHNTqOoTVTfbzVXN5 9FDBl2dCatACNnG+oChuil8CmkKn5IyQWMLcZpUGIbCBuxskLEMTVsV9g7QxbczA0WZ5 +5l01PcWn07M2/TyGVRpF4SDiAqQ/tpW0SeehdDy4DPbYXr93RAHb9ZAB5z+F/Zdmu7D I0mMAErIRSAhRp3n2Bpb5Xs0yrJk/980uODetjviQQp1MYlkVpmJHosfcQE9oPoJdoHs W5p/4SUxJnUsxlFwQvpeJ0TEdRaaaoY5pJawTxCjxW0SHreS3pf7qG2n8aQYp3ZX7WKi ClKg== Received: by 10.68.193.196 with SMTP id hq4mr19466131pbc.32.1348267656719; Fri, 21 Sep 2012 15:47:36 -0700 (PDT) Received: from localhost (c-24-19-7-36.hsd1.wa.comcast.net. [24.19.7.36]) by mx.google.com with ESMTPS id vf8sm5732138pbc.27.2012.09.21.15.47.35 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 21 Sep 2012 15:47:36 -0700 (PDT) From: Kevin Hilman To: "Rafael J. Wysocki" , linux-pm@vger.kernel.org Subject: [PATCH v2] PM / Runtime: let rpm_resume() succeed if RPM_ACTIVE, even when disabled Date: Fri, 21 Sep 2012 15:47:34 -0700 Message-Id: <1348267654-30697-1-git-send-email-khilman@deeprootsystems.com> X-Mailer: git-send-email 1.7.9.2 X-Gm-Message-State: ALoCoQmlBGsrWDpdVkCgjp1cmz33Y+lZZ9HOV6XsyfbP4kUjJSBrnAPdJlnPoq/gME0gEPYCgz5I 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 [209.85.160.49 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 DECEASED_NO_ML Dead not via mailing list Cc: Nishanth Menon , Grygorii Strashko , Alan Stern , Santosh Shilimkar , linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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 From: Kevin Hilman There are several drivers where the return value of pm_runtime_get_sync() is used to decide whether or not it is safe to access hardware and that don't provide .suspend() callbacks for system suspend (but may use late/noirq callbacks.) If such a driver happens to call pm_runtime_get_sync() during system suspend, after the core has disabled runtime PM, it will get the error code and will decide that the hardware should not be accessed, although this may be a wrong conclusion, depending on the state of the device when runtime PM was disabled. Drivers might work around this problem by using a test like: ret = pm_runtime_get_sync(dev); if (!ret || (ret == -EACCES && driver_private_data(dev)->suspended)) { /* access hardware */ } where driver_private_data(dev)->suspended is a flag set by the driver's .suspend() method (that would have to be added for this purpose). However, that potentially would need to be done by multiple drivers which means quite a lot of duplicated code and bloat. To avoid that we can use the observation that the core sets dev->power.is_suspended before disabling runtime PM and use that instead of the driver's private flag. Still, potentially many drivers would need to repeat that same check in quite a few places, so it's better to let the core do it. Then we can be a bit smarter and check whether or not runtime PM was disabled by the core only (disable_depth == 1) or by someone else in addition to the core (disable_depth > 1). In the former case rpm_resume() can return 1 if the runtime PM status is RPM_ACTIVE, because it means the device was active when the core disabled runtime PM. In the latter case it should still return -EACCES, because it isn't clear why runtime PM has been disabled. Tested on AM3730/Beagle-xM where a wakeup IRQ firing during the late suspend phase triggers runtime PM activity in the I2C driver since the wakeup IRQ is on an I2C-connected PMIC. Cc: Rafael J. Wysocki Cc: Alan Stern Signed-off-by: Kevin Hilman --- v2: - major changelog rewrite, based largely on input from Rafael - add check for disable_depth == 1 and move to separate if statement, both suggested by Alan Stern drivers/base/power/runtime.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 7d9c1cb..d43856b 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -509,6 +509,9 @@ static int rpm_resume(struct device *dev, int rpmflags) repeat: if (dev->power.runtime_error) retval = -EINVAL; + else if (dev->power.disable_depth == 1 && dev->power.is_suspended + && dev->power.runtime_status == RPM_ACTIVE) + retval = 1; else if (dev->power.disable_depth > 0) retval = -EACCES; if (retval)