From patchwork Tue Sep 1 14:28:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11748387 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D4D6C138A for ; Tue, 1 Sep 2020 14:30:40 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ADCEA20767 for ; Tue, 1 Sep 2020 14:30:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="J1SogTUr"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="WDHB19AG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ADCEA20767 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=gRgKhkmwMLCsjTT9Fm26kCpilKyt9hgrohXmlAl1gbE=; b=J1SogTUrrliU9AbE5oVRUuM4D U/LJ29abd7RkWOuuVTOnexsCQAt3cxE20coN40dONKSzAVwzzajUud9kzTxHv6MlBknWJIsR280j6 5ZB185S3ei2X4Qv9bX2Yt2qfwIgOE4FhYhklCQTiEHZsP3bLnAo2ugn5lxVuewv+yJfSQwDDikBXA wOaM3Xk5CQAWxE2FKVjCZ4JkiW/toTVKjuXngCYS2hHVX6c5Fdhyr5bhfON7PSiib5Mwi508ywH+d gdQ/cEeMxLWPOs0IeFDlICP7GKmQ1KBEtEJ5sXmFhTGFGcNkRjnrb7FxXGlT3Wf0rYF4X19Iwgyk3 TkJL7T+pA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kD7Hc-0003yW-9H; Tue, 01 Sep 2020 14:29:12 +0000 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kD7HZ-0003xf-9H for linux-arm-kernel@lists.infradead.org; Tue, 01 Sep 2020 14:29:10 +0000 Received: by mail-lj1-x243.google.com with SMTP id k25so1766146ljg.9 for ; Tue, 01 Sep 2020 07:29:08 -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 :mime-version:content-transfer-encoding; bh=LTilAKx6uhyrrDCSQGM9DUga+qKc7kxrp8ADcGsaoJo=; b=WDHB19AGJeh66EVd4uru7yOjVuBjxtiQGn+tHoHz1rkFf4LoQ14AJI8XoVMOkqK1y+ tP4yxQX7bkHab4DxtpYpGgaL2Wj7b4sr7vFGIS875JY2yLLMr/+gOFObjVzJ8V5FQV0/ sqtEblQh1nYuMiWsgwjzDQOOf2C7f1lZKdda/US6QBJvCn3uCGsYuXIWdEi14gHxGdXW LOpgn9Zy3O3S3ZJTfxKNMlWHX2My2WRvMuIxhqAVheK1sA+i/kkAy3n9J+qAX4FE32Ml B4Et8qXF96r9/1hws7RdaLIcK8AL5WV3C9/OZroNUOaWitkbW4uLMmzRpSEQchNDGkPl 3ePg== 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:mime-version:content-transfer-encoding; bh=LTilAKx6uhyrrDCSQGM9DUga+qKc7kxrp8ADcGsaoJo=; b=S8xCAIceQjFC7vFGPvidUFGv8tAJVbQAxxG21BoDc/b/NG4EKlqoKUpJ5LBly2qRsr cNpMVTduHx0xiUNt/zf5pyYHnO+BsXWQB0X7a4mTSmJOXaDNFLhXLn0B2kPO1n7Hl6Uf mqupCgfVJgqG7P2MYJhcvGtQB0EY0aqo/MLdRCOhMyqTZZ0tq+Lb0oZIZ684Njt8frxA 98B8orc7bfp0jMEzhT8LY4NoXKfPypnWn/ZtPHpYyuITHijLm1zP7SZ1dP6Mo4Agb+8v 4Q0JGVBv21cgjSqNZK3jv4SnCmT/g+iZbfZsyKDNwjkIDdIOLI/tfr5v1mArGwaVaqKm xlKA== X-Gm-Message-State: AOAM532//ZdTcY5+S36XusQ38RvbVYSokICGuNVZlGj3XyfoJGSGh+Qk ZLwPx27SkG4k1R0RRUyGgUhpyw== X-Google-Smtp-Source: ABdhPJyWQNEbbmEJWXfQWRgICw8JuT0MwqJbc8qwxQ+05+O9Zg1NEAZsOpYK5ll8S0N/aewyZdl5/w== X-Received: by 2002:a05:651c:505:: with SMTP id o5mr755471ljp.306.1598970547217; Tue, 01 Sep 2020 07:29:07 -0700 (PDT) Received: from localhost.localdomain (h-98-128-180-79.NA.cust.bahnhof.se. [98.128.180.79]) by smtp.gmail.com with ESMTPSA id r7sm318313lfn.84.2020.09.01.07.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 07:29:06 -0700 (PDT) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , linux-pm@vger.kernel.org Subject: [PATCH v3 1/2] firmware: psci: Extend psci_set_osi_mode() to allow reset to PC mode Date: Tue, 1 Sep 2020 16:28:58 +0200 Message-Id: <20200901142859.224381-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200901142859.224381-1-ulf.hansson@linaro.org> References: <20200901142859.224381-1-ulf.hansson@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200901_102909_443791_67378B2C X-CRM114-Status: GOOD ( 16.57 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:243 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Ulf Hansson , Vincent Guittot , Benjamin Gaignard , Stephen Boyd , Daniel Lezcano , "Rafael J . Wysocki" , Lina Iyer , Bjorn Andersson , linux-arm-kernel@lists.infradead.org, Lukasz Luba Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The current user (cpuidle-psci) of psci_set_osi_mode() only needs to enable the PSCI OSI mode. Although, as subsequent changes shows, there is a need to be able to reset back into the PSCI PC mode. Therefore, let's extend psci_set_osi_mode() to take a bool as in-parameter, to let the user indicate whether to enable OSI or to switch back to PC mode. Reviewed-by: Sudeep Holla Signed-off-by: Ulf Hansson --- Changes in v3: - Added reviewed-by tag. --- drivers/cpuidle/cpuidle-psci-domain.c | 2 +- drivers/firmware/psci/psci.c | 12 +++++++----- include/linux/psci.h | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c index b6e9649ab0da..b6ab0415f450 100644 --- a/drivers/cpuidle/cpuidle-psci-domain.c +++ b/drivers/cpuidle/cpuidle-psci-domain.c @@ -278,7 +278,7 @@ static int psci_cpuidle_domain_probe(struct platform_device *pdev) goto remove_pd; /* Try to enable OSI mode. */ - ret = psci_set_osi_mode(); + ret = psci_set_osi_mode(true); if (ret) { pr_warn("failed to enable OSI mode: %d\n", ret); psci_pd_remove_topology(np); diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index 92013ecc2d9e..00af99b6f97c 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -151,12 +151,15 @@ static u32 psci_get_version(void) return invoke_psci_fn(PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0); } -int psci_set_osi_mode(void) +int psci_set_osi_mode(bool enable) { + unsigned long suspend_mode; int err; - err = invoke_psci_fn(PSCI_1_0_FN_SET_SUSPEND_MODE, - PSCI_1_0_SUSPEND_MODE_OSI, 0, 0); + suspend_mode = enable ? PSCI_1_0_SUSPEND_MODE_OSI : + PSCI_1_0_SUSPEND_MODE_PC; + + err = invoke_psci_fn(PSCI_1_0_FN_SET_SUSPEND_MODE, suspend_mode, 0, 0); return psci_to_linux_errno(err); } @@ -546,8 +549,7 @@ static int __init psci_1_0_init(struct device_node *np) pr_info("OSI mode supported.\n"); /* Default to PC mode. */ - invoke_psci_fn(PSCI_1_0_FN_SET_SUSPEND_MODE, - PSCI_1_0_SUSPEND_MODE_PC, 0, 0); + psci_set_osi_mode(false); } return 0; diff --git a/include/linux/psci.h b/include/linux/psci.h index 14ad9b9ebcd6..2a1bfb890e58 100644 --- a/include/linux/psci.h +++ b/include/linux/psci.h @@ -18,7 +18,7 @@ bool psci_tos_resident_on(int cpu); int psci_cpu_suspend_enter(u32 state); bool psci_power_state_is_valid(u32 state); -int psci_set_osi_mode(void); +int psci_set_osi_mode(bool enable); bool psci_has_osi_support(void); struct psci_operations { From patchwork Tue Sep 1 14:28:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 11748389 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 38163138A for ; Tue, 1 Sep 2020 14:30:44 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1067420767 for ; Tue, 1 Sep 2020 14:30:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ytwIKqcg"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="OTEkxGHM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1067420767 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=KPz/+xgSPOBXDo3y+FhbS+3BfqvBdfBRrUPlPcASOVw=; b=ytwIKqcgCi3NwzPphlKtAKdIB WP5iaV2FsQOZd+sEF4MlZxDBlvR1BaY4fbS/YNdzmJQU96hIRNqn7mGPDkCz0vwYmn1Iy6W8TclP5 cn0WiAWhp9li+XfM1ezulFsTj5Um9kT2lp5JO47WQdg/DF09V4zHueC6DbBzlnpejXo5wM4jlfCnH 7i4axwFzoglk2lffwc3rWyXzSBIaijlB2xPTXGziuBvj1HHeF/FL7OasqzRSjTiTo8s2We9FdCd+K XEs8mCGv7sEnovWnGI7E1Bq3T4U+9gbOAWvEkX73y87Tgz0f3CVkrIJP2SA1ep/r+RMvKelZ8Tagl T93yfmDeg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kD7Hg-0003zl-DO; Tue, 01 Sep 2020 14:29:16 +0000 Received: from mail-lf1-x144.google.com ([2a00:1450:4864:20::144]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kD7Hb-0003yE-Le for linux-arm-kernel@lists.infradead.org; Tue, 01 Sep 2020 14:29:13 +0000 Received: by mail-lf1-x144.google.com with SMTP id c15so906049lfi.3 for ; Tue, 01 Sep 2020 07:29:11 -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 :mime-version:content-transfer-encoding; bh=G8BpIdoUWarD6YsNR5keyc/R3LV3nr8+EDPnN27oa5w=; b=OTEkxGHMQo6lwO7qWEQS2nyPIV/ZoNJAB8hDU6ChkbgvxwNGtDewDKJtFveHjZzp/i PhZPCdhzh82f/yTaY/0usjl1LHnulS839xOg82DPgxEgo/CgC7TLxL479PBtD2fZhqO7 lI/JnOvhYQjtu3BYAcB1posah3WmMsckT4zi9C0dKjfCYlRXN7hpZ77HGsJlJZjIK6Tm rPxtcJIuobY348SoLcmpP1GydVYZu2iY6w+QxF731AZdgLmbcSKkHfJEvE68M/i2e0eX 3LvLsiYsWQIGGKIodQI6FR7wu6hoGhAFnEU61O1utmljufbDwhM15eKkAiX6GMVRhd8W vbGg== 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:mime-version:content-transfer-encoding; bh=G8BpIdoUWarD6YsNR5keyc/R3LV3nr8+EDPnN27oa5w=; b=g0eKf6Cm6hKqptBfkpOM9MVn98UErdGAWm5NpzDRYAzpbbNLN0g5oCVX4YiU6beKR+ Eaa5+SiZ30wSR6zvqOTPiSb6RLWWxokv+h9BsD6JThQtNdBM4I6ejiTwENNGIg1KCsuI lOsqwjjyex495ZDvqIcIpo2mE1qXAPfS/qL3zQ2gyjp9BjOGHW0r43eLCWLdH/8QX4kR eyNLV+5xEBL9VI4gwbjbNT7VYtzNlMP9ntkFxqoF6aZVGlx3Cu5sTusiqgALp6IYypFr +6BLs4pEMTL2Ln5RLT1IMQyftPQpnPVpsFfixbu2LV6ZoLNaq6+Q0wGnLryGKUc8PVLf YGHA== X-Gm-Message-State: AOAM532zfHvSr3ah2l9MEdV1ocP2C4O6WzMemTPDV8Bfq81rt8663vbn 0vyPw/1ucKlF0wUGw8UrDo2x4g== X-Google-Smtp-Source: ABdhPJyfXiM4Okzd/SRkCrEceXeq0ysdCqTtfeVh0J2LAdPZF7qAOjGHIdlheefSoZzDhHIGzHmNWw== X-Received: by 2002:a05:6512:200e:: with SMTP id a14mr749683lfb.49.1598970549872; Tue, 01 Sep 2020 07:29:09 -0700 (PDT) Received: from localhost.localdomain (h-98-128-180-79.NA.cust.bahnhof.se. [98.128.180.79]) by smtp.gmail.com with ESMTPSA id r7sm318313lfn.84.2020.09.01.07.29.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2020 07:29:08 -0700 (PDT) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , linux-pm@vger.kernel.org Subject: [PATCH v3 2/2] cpuidle: psci: Allow PM domain to be initialized even if no OSI mode Date: Tue, 1 Sep 2020 16:28:59 +0200 Message-Id: <20200901142859.224381-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200901142859.224381-1-ulf.hansson@linaro.org> References: <20200901142859.224381-1-ulf.hansson@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200901_102911_813837_8B28632F X-CRM114-Status: GOOD ( 24.28 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:144 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Ulf Hansson , Vincent Guittot , Benjamin Gaignard , Stephen Boyd , Daniel Lezcano , "Rafael J . Wysocki" , Lina Iyer , Bjorn Andersson , linux-arm-kernel@lists.infradead.org, Lukasz Luba Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org If the PSCI OSI mode isn't supported or fails to be enabled, the PM domain topology with the genpd providers isn't initialized. This is perfectly fine from cpuidle-psci point of view. However, since the PM domain topology in the DTS files is a description of the HW, no matter of whether the PSCI OSI mode is supported or not, other consumers besides the CPUs may rely on it. Therefore, let's always allow the initialization of the PM domain topology to succeed, independently of whether the PSCI OSI mode is supported. Consequentially we need to track if we succeed to enable the OSI mode, as to know when a domain idlestate can be selected. Note that, CPU devices are still not being attached to the PM domain topology, unless the PSCI OSI mode is supported. Acked-by: Sudeep Holla Signed-off-by: Ulf Hansson --- Changes in v3: - Added acked-by tag. - Use GENPD_FLAG_ALWAYS_ON to prevent power off, unless OSI has been successfully enabled. --- drivers/cpuidle/cpuidle-psci-domain.c | 59 ++++++++++++++------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c index b6ab0415f450..4a031c62f92a 100644 --- a/drivers/cpuidle/cpuidle-psci-domain.c +++ b/drivers/cpuidle/cpuidle-psci-domain.c @@ -105,7 +105,7 @@ static void psci_pd_free_states(struct genpd_power_state *states, kfree(states); } -static int psci_pd_init(struct device_node *np) +static int psci_pd_init(struct device_node *np, bool use_osi) { struct generic_pm_domain *pd; struct psci_pd_provider *pd_provider; @@ -135,11 +135,16 @@ static int psci_pd_init(struct device_node *np) pd->free_states = psci_pd_free_states; pd->name = kbasename(pd->name); - pd->power_off = psci_pd_power_off; pd->states = states; pd->state_count = state_count; pd->flags |= GENPD_FLAG_IRQ_SAFE | GENPD_FLAG_CPU_DOMAIN; + /* Allow power off when OSI has been successfully enabled. */ + if (use_osi) + pd->power_off = psci_pd_power_off; + else + pd->flags |= GENPD_FLAG_ALWAYS_ON; + /* Use governor for CPU PM domains if it has some states to manage. */ pd_gov = state_count > 0 ? &pm_domain_cpu_gov : NULL; @@ -190,7 +195,7 @@ static void psci_pd_remove(void) } } -static int psci_pd_init_topology(struct device_node *np, bool add) +static int psci_pd_init_topology(struct device_node *np) { struct device_node *node; struct of_phandle_args child, parent; @@ -203,9 +208,7 @@ static int psci_pd_init_topology(struct device_node *np, bool add) child.np = node; child.args_count = 0; - - ret = add ? of_genpd_add_subdomain(&parent, &child) : - of_genpd_remove_subdomain(&parent, &child); + ret = of_genpd_add_subdomain(&parent, &child); of_node_put(parent.np); if (ret) { of_node_put(node); @@ -216,14 +219,20 @@ static int psci_pd_init_topology(struct device_node *np, bool add) return 0; } -static int psci_pd_add_topology(struct device_node *np) +static bool psci_pd_try_set_osi_mode(void) { - return psci_pd_init_topology(np, true); -} + int ret; -static void psci_pd_remove_topology(struct device_node *np) -{ - psci_pd_init_topology(np, false); + if (!psci_has_osi_support()) + return false; + + ret = psci_set_osi_mode(true); + if (ret) { + pr_warn("failed to enable OSI mode: %d\n", ret); + return false; + } + + return true; } static void psci_cpuidle_domain_sync_state(struct device *dev) @@ -244,14 +253,14 @@ static int psci_cpuidle_domain_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; struct device_node *node; + bool use_osi; int ret = 0, pd_count = 0; if (!np) return -ENODEV; - /* Currently limit the hierarchical topology to be used in OSI mode. */ - if (!psci_has_osi_support()) - return 0; + /* If OSI mode is supported, let's try to enable it. */ + use_osi = psci_pd_try_set_osi_mode(); /* * Parse child nodes for the "#power-domain-cells" property and @@ -261,7 +270,7 @@ static int psci_cpuidle_domain_probe(struct platform_device *pdev) if (!of_find_property(node, "#power-domain-cells", NULL)) continue; - ret = psci_pd_init(node); + ret = psci_pd_init(node, use_osi); if (ret) goto put_node; @@ -270,30 +279,24 @@ static int psci_cpuidle_domain_probe(struct platform_device *pdev) /* Bail out if not using the hierarchical CPU topology. */ if (!pd_count) - return 0; + goto no_pd; /* Link genpd masters/subdomains to model the CPU topology. */ - ret = psci_pd_add_topology(np); + ret = psci_pd_init_topology(np); if (ret) goto remove_pd; - /* Try to enable OSI mode. */ - ret = psci_set_osi_mode(true); - if (ret) { - pr_warn("failed to enable OSI mode: %d\n", ret); - psci_pd_remove_topology(np); - goto remove_pd; - } - pr_info("Initialized CPU PM domain topology\n"); return 0; put_node: of_node_put(node); remove_pd: - if (pd_count) - psci_pd_remove(); + psci_pd_remove(); pr_err("failed to create CPU PM domains ret=%d\n", ret); +no_pd: + if (use_osi) + psci_set_osi_mode(false); return ret; }