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: 248866 Delivered-To: patches@linaro.org Received: by 2002:a92:5b9c:0:0:0:0:0 with SMTP id c28csp4296057ilg; Tue, 1 Sep 2020 07:29:10 -0700 (PDT) X-Received: by 2002:a2e:854c:: with SMTP id u12mr759605ljj.120.1598970550327; Tue, 01 Sep 2020 07:29:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598970550; cv=none; d=google.com; s=arc-20160816; b=LFX25DDxki8It/A5msmTRb61HCGySItQY6n2bNnoO/VDMP8a5IlC6IgjWyfg93dlzb SXmf7DJwYqlqzsRLlxYxjcw3Yii0pr9cSPIngoFwwKzt//+aFDLFCLFM7Mtsv90qTZT1 haiHydf5l3RDMbz4AvqLwubwxPuw0PjWtkYiPUMVuHJ8ARRFnhxQx+FQAJ9M57KGUjdn TszUGTqyHbVvjyZRBZZdDk6qxJQjFyFsSk/XfK+w4+3ErRv73s/mVHTvA1XPn8dUgOpW /oPcAInHTQKIDgPttBtmEb/PfE5TmU38uNeH9Dk3Cfwi/iKkN1s0WJrvfpQq0u5ZwiPW kCHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=G8BpIdoUWarD6YsNR5keyc/R3LV3nr8+EDPnN27oa5w=; b=tq0dmiCXKplaQ0LelL68iOEvbJM0Mvbl21lHBaN+l58oePMvGCxFUiXb7qHaK+WvJD MtOKNVQ344xS3lGrk26nSeH+MYEAwsuA+oDtU358pPDnU6YnA6H9t6g4kseR2wSATC9v 7SafsAZYA6VJG7xGFe5G7cHtXZnjMClqjPSQXuhwzLbzl1K8M3CdP49yV2TurGwArbjI F5DzuC91scATi9y/imxnrTRz31T+MFaMHS8XD25r+L7ugstL/NjyjVNMA0KingrWVKnp rGGSPr6pE6Il3D1MQhCcYFMd5+DFRS86FurPsUXcXIvK2Yr2qYtvffDd1qMAOCaR0MuJ HqWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OTEkxGHM; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id t16sor435499lfe.39.2020.09.01.07.29.10 for (Google Transport Security); Tue, 01 Sep 2020 07:29:10 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OTEkxGHM; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=Gc/f03eQtLecNNWwh14CvfuuDdWPn95ewNvR3kcfkVSyNHZLhkBfSLYF7VXbBT+mbJ pssuiazWzPysa7/hZZ2Eh7ud6EAbsTbe+ranjYwEjK5I1/a99bv+s1XC1vMBgpJRX05H W0IKW1XoebAkOjJyRjbxBqm+Y4FFdVktD0BR33gcTLD2wXi/IMK0HuIUZsMU7CeN19RW F55brY82cZukF/hDawGPLUmZ9n1EJaS7LUBmx0RX8Bvtz7oe5Hh9JaT4bB8lXfhKtEuN GbATdvbOiIOvEQxDjkl10Ur2TyfZG5SgkJd9ukCuTVVTw2tBMWLE4O+tr32pXsrGcl9t GmzQ== X-Gm-Message-State: AOAM530b2XaYbPTm66kMnTlP8XGNpGZWPlNQK4OiufiuVR9R+J9GYqzx xkeFWmggwPD790BCxfrJTRX+PW69qKMvdksDqo8= 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) Return-Path: 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 Cc: "Rafael J . Wysocki" , Daniel Lezcano , Mark Rutland , Lina Iyer , Lukasz Luba , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Benjamin Gaignard , Ulf Hansson , linux-arm-kernel@lists.infradead.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 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(-) -- 2.25.1 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; }