From patchwork Mon Jun 15 15:20:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 187944 Delivered-To: patches@linaro.org Received: by 2002:a54:30ca:0:0:0:0:0 with SMTP id e10csp2633402ecs; Mon, 15 Jun 2020 08:21:00 -0700 (PDT) X-Received: by 2002:a2e:7203:: with SMTP id n3mr13351367ljc.231.1592234460256; Mon, 15 Jun 2020 08:21:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592234460; cv=none; d=google.com; s=arc-20160816; b=Ta9ulTeMwA6CRTZRSCVR/OE98PI8v9+SZjMQAfwzOdNduZta6y/WD0UBGyrqWkwXLs pcDShkvhGZU64m2q6T1guUz3dwvHOHK5ftSAvDwy6AVCnP7YIQQlEhoAhpzvf9XQNjti Cit7Q5XzKaeFFKhuRyc/4IJMyTCCyPDB+8mAhnUrc4KVzO6+7yjZkLcDBlRHAnLhe4I3 NznrCmEXfW+FqY3Q+AEMTTvcUbpOK4BdKjA/43Zv8TgGpWlWPCqnWhWr/fL71fb5pr5H jQxI/xLDwgg0vnYIe71ihGca/xnmr15kvYcz4DFK6XaDup9fHcoVYJYErK0SxSr7EmZH 3r6w== 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=zKuQg/V734JQ52Bk2AkHR9NRP89P2pyrqBomz/3R808=; b=k44/dygOoXv8+SVlYmrm4np7VVbY496D6zX3FtvHcjTJbZwE8qenU2I44hTaDkKR+x q9iKD4iyPmjgYeBU28k/6N+ZE6hHgnwuxZLh58DXCOTge8QP77mSNAplklOvms2sZvFo jH/DQdo8drFldHLZ8w0xqOzqQHJmZp/k14aeqPHmdavwNxFMH8lru7EFJdnZamGpwrcG aBxaouulefnZRP75gjIutTmbUzZ/zb/5+el4bP4hHjXQFyKFuKOiAvr4JR0wAIDOKF+5 FMjewcHAoYNT4fXlYp26L8UB+wOhpjGU6pBH4I5bkvn5ksarjslABaro3XLOoQVMFb5M IwkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pvtc1SZF; 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 t5sor7458008ljk.29.2020.06.15.08.21.00 for (Google Transport Security); Mon, 15 Jun 2020 08:21:00 -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=pvtc1SZF; 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=zKuQg/V734JQ52Bk2AkHR9NRP89P2pyrqBomz/3R808=; b=pvtc1SZFZTITynG6EAMVZtWwt6lRnyd/IzhXA/GcyT1APmIZRJjKvOFBulO0VpBUZp bvz9hCSRcYaxOsiDD5aSDarY9I0SBwqIkrusZOPH+r0qm7Hk1ixgsqn2Q+moDrS/ab4s /krAWc9u7RQPETLSw2VMzG/aZJnBTZ0qN88eK/MOdk+a8M8S3zUlzZk3maOnFESycdDA cFFcyXPo2frLFTbVPpZgMoDq4FmRJnXp59Ep1jtKuprRcSTFoXUwq0VNevxw4/AAyS1L O6/InAf3ar6Vt2CXzMxDD06ypaHu3Cpn0U4mwr7m2XWS2HUOuNNOx3u6l5+7Iywn7SUh xEfQ== 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=zKuQg/V734JQ52Bk2AkHR9NRP89P2pyrqBomz/3R808=; b=YJFxx1bQXMbZcAfrjvRXUBMKd0j8SwKwyajCMqB7Q7GihvNVZ3RjVYiHyoXA/SnARI CnPmGf7Kov0eCVrbgrZPG6c6KIaY2UiQnUpWOjogvXji5RqQmWXfYtJkK2XHCG4shjVY YiRZSeo41u/4PrtXkDFvS+NYrrFZKE72Oe++PQ36sEHWlHbucp7QGKkkoHur3jHo8sGy AVHxiY0rZKw7pVH78/bwiDn0pFM0cO7OtVyNvMLOBjqj1iS9UCxpBVBxyWivZIXe1eul r1X5UO7seMBLIqf6gmfsV/G+P16agcWwv9MH97SalaEh1bpm9kme3DrgGAL+ADNf30ec jQaA== X-Gm-Message-State: AOAM530+rg0kD9vpYHoAtxHI9v/DTBWe891YWDt0syg8U7p6E6+sKTK/ XOYu44ujy3d++oxZXaP7ZppqY4bZ X-Google-Smtp-Source: ABdhPJzk+/msjtPy+gK56odrzaAF+uDCn54CXNp4xuAEJt/Zr3zDNx3DSb7724QQbj0z/HWq04YcBg== X-Received: by 2002:a2e:9e86:: with SMTP id f6mr11881801ljk.95.1592234459927; Mon, 15 Jun 2020 08:20:59 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-98-128-181-7.NA.cust.bahnhof.se. [98.128.181.7]) by smtp.gmail.com with ESMTPSA id r13sm507045lfp.80.2020.06.15.08.20.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2020 08:20:58 -0700 (PDT) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Saravana Kannan , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Lina Iyer , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Benjamin Gaignard , Ulf Hansson , linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/5] cpuidle: psci: Fail cpuidle registration if set OSI mode failed Date: Mon, 15 Jun 2020 17:20:50 +0200 Message-Id: <20200615152054.6819-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200615152054.6819-1-ulf.hansson@linaro.org> References: <20200615152054.6819-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Currently we allow the cpuidle driver registration to succeed, even if we failed to enable the OSI mode when the hierarchical DT layout is used. This means running in a degraded mode, by using the available idle states per CPU, while also preventing the domain idle states. Moving forward, this behaviour looks quite questionable to maintain, as complexity seems to grow around it, especially when trying to add support for deferred probe, for example. Therefore, let's make the cpuidle driver registration to fail in this situation, thus relying on the default architectural cpuidle backend for WFI to be used. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci-domain.c | 5 ----- 1 file changed, 5 deletions(-) -- 2.20.1 Reviewed-by: Lina Iyer diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c index 423f03bbeb74..f07786aad673 100644 --- a/drivers/cpuidle/cpuidle-psci-domain.c +++ b/drivers/cpuidle/cpuidle-psci-domain.c @@ -26,7 +26,6 @@ struct psci_pd_provider { }; static LIST_HEAD(psci_pd_providers); -static bool osi_mode_enabled __initdata; static int psci_pd_power_off(struct generic_pm_domain *pd) { @@ -272,7 +271,6 @@ static int __init psci_idle_init_domains(void) goto remove_pd; } - osi_mode_enabled = true; of_node_put(np); pr_info("Initialized CPU PM domain topology\n"); return pd_count; @@ -293,9 +291,6 @@ struct device __init *psci_dt_attach_cpu(int cpu) { struct device *dev; - if (!osi_mode_enabled) - return NULL; - dev = dev_pm_domain_attach_by_name(get_cpu_device(cpu), "psci"); if (IS_ERR_OR_NULL(dev)) return dev; From patchwork Mon Jun 15 15:20:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 187945 Delivered-To: patches@linaro.org Received: by 2002:a54:30ca:0:0:0:0:0 with SMTP id e10csp2633439ecs; Mon, 15 Jun 2020 08:21:02 -0700 (PDT) X-Received: by 2002:ac2:4422:: with SMTP id w2mr4976197lfl.152.1592234462494; Mon, 15 Jun 2020 08:21:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592234462; cv=none; d=google.com; s=arc-20160816; b=DLqc3eLbr09QOx7kTdO7U2uTSvON5H13QgQvRv5cg6IXLX+JV6avKVxi6u3k69kLWV w0RL7QZi72v0m04eQ97DXHKyQK7UTAEV/9UiCTne13iUceg97HLG1l08zHO7cNQ2t60G V9EBHFbuJiquMInoaD9Ip6g8de8ZxC1rywhTy2hX6IKYdY3kHAzUME9Wb/Ntm55dz5yJ LVbHuOQNsX7QGtxDu/Km/6qBOIRrLWgXdJkfyFzuisKG1OxS/ey/DCZxNkNLxCocO+r7 b3Wu01oFrCGBME2NicNqNovljWtfPAH3iKzYgiVswRKwTlnbzc704vdhM48rx4skWqjF WPpg== 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=DIs8KJ98J5MEVUm8Cx49lckO7aev9utr31emHR9iDsU=; b=BHlZztXBrfW7NywW96/Ja5H7DQHEfhheHPyI9bZUkiOT2TXa9IIkt4Bgf/6gcHH2AU Hwi80J/XcoDNVdNKdviPaKhkeWx6XAfmTEVU+r20PoXPut4QGdDYMCYAjejiIwyGlHzE I31tpi10sRu86X3uL7sPw8Hlh97TXE2yemfxlwqT8OLQJr2moxxYy3yVfv7APkPMSvAz ic7zWCQq/qMZEc1jRoktqLeLOBd3T/yqWNGnMR7mVAyKm0X8YUgKltKJrjkhpsuky6xg uemenhdfeofNg2lWqcZ02cIfmO9PqaaZ7pr069pHrbXiysdVJdZHScQ3RZnD1Nzll43o EQKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AFCjTEok; 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 2sor7597897ljv.49.2020.06.15.08.21.02 for (Google Transport Security); Mon, 15 Jun 2020 08:21:02 -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=AFCjTEok; 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=DIs8KJ98J5MEVUm8Cx49lckO7aev9utr31emHR9iDsU=; b=AFCjTEokEP2xEJjuOwKRjcKylvH8VqoJjg4K13+Nzc2pdpekOoxJq2ILU2MRcVImNs fw0AiQaLqsnQ2gh/dp+lH6VuzR2ZW8Z3YxDLV6JpAgSAUcxS17j6Fg2WWO1gT+5tn1K+ OpMC6p9I58kyMkF5MqnOFX6sXvk/XyK/cOnDT0AxqXefKTcCnCM0By+oLxmdbpVwuFwj NCB78ttEpun1Idx9ipUa8FFRwaV2BF/hzdj8WopbHip/FYI0xrHF5WlQg74S50GEaISo RrgzHYjC8v7gNNC7g574np0lSd7/OLgEyRuJSsJC0aaRHuqiVTlvqEoc8neCqvabz0yU LiSg== 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=DIs8KJ98J5MEVUm8Cx49lckO7aev9utr31emHR9iDsU=; b=h7RR9XZGjBWyDH2dkQCC8u7slaipZbHKLWOZGxk3mu6f2S6C/9n56sPVDb/QjijNEi 8k68rTjfOQHoejpkeXSmfrYRSgzaMCpPdLDDfLiOpkV2w9rht6P6zpmpwWiaKDpaTSLK Pn7FT9UOfuWE70dwlo0v8HEE59qIWZyDh2tHa5vjuXN0mtZP1U2mwiF6I7TsYxSECXTc x6F53Sj0GZB4kxvCPfqkkwLbUBv37Z4CH2/2Z4w/OFkWw6pGb55nLD60WwsWQfRN+ltY zzBePB5VsI2PscbD73HNtYENhN4lHqud5mGYOtHr2x2QwGJLvbgN1PG1hfVCfLu1VkIF +3tw== X-Gm-Message-State: AOAM5313Kj+PnEl+SNWM0+RWWqhFo55F4cM6kYOxLLKR8gZWnsn2UGfb kWYJsxq2m33+phkJlK0o+eXG0rW2 X-Google-Smtp-Source: ABdhPJztnoAE7zSNCindBOjSInKfGNIkh6lL/30j/OX2l+3X1MmV/RJDFccwwnB2T2Sc8+tKjSldPQ== X-Received: by 2002:a2e:9b8c:: with SMTP id z12mr12524785lji.257.1592234462069; Mon, 15 Jun 2020 08:21:02 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-98-128-181-7.NA.cust.bahnhof.se. [98.128.181.7]) by smtp.gmail.com with ESMTPSA id r13sm507045lfp.80.2020.06.15.08.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2020 08:21:01 -0700 (PDT) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Saravana Kannan , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Lina Iyer , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Benjamin Gaignard , Ulf Hansson , linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/5] cpuidle: psci: Fix error path via converting to a platform driver Date: Mon, 15 Jun 2020 17:20:51 +0200 Message-Id: <20200615152054.6819-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200615152054.6819-1-ulf.hansson@linaro.org> References: <20200615152054.6819-1-ulf.hansson@linaro.org> MIME-Version: 1.0 The current error paths for the cpuidle-psci driver, may leak memory or possibly leave CPU devices attached to their PM domains. These are quite harmless issues, but still deserves to be taken care of. Although, rather than fixing them by keeping track of allocations that needs to be freed, which tends to become a bit messy, let's convert into a platform driver. In this way, it gets easier to fix the memory leaks as we can rely on the devm_* functions. Moreover, converting to a platform driver also enables support for deferred probe, which subsequent changes takes benefit from. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci-domain.c | 10 +- drivers/cpuidle/cpuidle-psci.c | 141 +++++++++++++++----------- drivers/cpuidle/cpuidle-psci.h | 9 +- 3 files changed, 95 insertions(+), 65 deletions(-) -- 2.20.1 diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c index f07786aad673..e48e578aaa7d 100644 --- a/drivers/cpuidle/cpuidle-psci-domain.c +++ b/drivers/cpuidle/cpuidle-psci-domain.c @@ -287,7 +287,7 @@ static int __init psci_idle_init_domains(void) } subsys_initcall(psci_idle_init_domains); -struct device __init *psci_dt_attach_cpu(int cpu) +struct device *psci_dt_attach_cpu(int cpu) { struct device *dev; @@ -301,3 +301,11 @@ struct device __init *psci_dt_attach_cpu(int cpu) return dev; } + +void psci_dt_detach_cpu(struct device *dev) +{ + if (IS_ERR_OR_NULL(dev)) + return; + + dev_pm_domain_detach(dev, false); +} diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c index 3806f911b61c..74463841805f 100644 --- a/drivers/cpuidle/cpuidle-psci.c +++ b/drivers/cpuidle/cpuidle-psci.c @@ -17,9 +17,11 @@ #include #include #include +#include #include #include #include +#include #include @@ -33,7 +35,7 @@ struct psci_cpuidle_data { static DEFINE_PER_CPU_READ_MOSTLY(struct psci_cpuidle_data, psci_cpuidle_data); static DEFINE_PER_CPU(u32, domain_state); -static bool psci_cpuidle_use_cpuhp __initdata; +static bool psci_cpuidle_use_cpuhp; void psci_set_domain_state(u32 state) { @@ -104,7 +106,7 @@ static int psci_idle_cpuhp_down(unsigned int cpu) return 0; } -static void __init psci_idle_init_cpuhp(void) +static void psci_idle_init_cpuhp(void) { int err; @@ -127,30 +129,13 @@ static int psci_enter_idle_state(struct cpuidle_device *dev, return psci_enter_state(idx, state[idx]); } -static struct cpuidle_driver psci_idle_driver __initdata = { - .name = "psci_idle", - .owner = THIS_MODULE, - /* - * PSCI idle states relies on architectural WFI to - * be represented as state index 0. - */ - .states[0] = { - .enter = psci_enter_idle_state, - .exit_latency = 1, - .target_residency = 1, - .power_usage = UINT_MAX, - .name = "WFI", - .desc = "ARM WFI", - } -}; - -static const struct of_device_id psci_idle_state_match[] __initconst = { +static const struct of_device_id psci_idle_state_match[] = { { .compatible = "arm,idle-state", .data = psci_enter_idle_state }, { }, }; -int __init psci_dt_parse_state_node(struct device_node *np, u32 *state) +int psci_dt_parse_state_node(struct device_node *np, u32 *state) { int err = of_property_read_u32(np, "arm,psci-suspend-param", state); @@ -167,9 +152,9 @@ int __init psci_dt_parse_state_node(struct device_node *np, u32 *state) return 0; } -static int __init psci_dt_cpu_init_topology(struct cpuidle_driver *drv, - struct psci_cpuidle_data *data, - unsigned int state_count, int cpu) +static int psci_dt_cpu_init_topology(struct cpuidle_driver *drv, + struct psci_cpuidle_data *data, + unsigned int state_count, int cpu) { /* Currently limit the hierarchical topology to be used in OSI mode. */ if (!psci_has_osi_support()) @@ -190,9 +175,9 @@ static int __init psci_dt_cpu_init_topology(struct cpuidle_driver *drv, return 0; } -static int __init psci_dt_cpu_init_idle(struct cpuidle_driver *drv, - struct device_node *cpu_node, - unsigned int state_count, int cpu) +static int psci_dt_cpu_init_idle(struct device *dev, struct cpuidle_driver *drv, + struct device_node *cpu_node, + unsigned int state_count, int cpu) { int i, ret = 0; u32 *psci_states; @@ -200,7 +185,8 @@ static int __init psci_dt_cpu_init_idle(struct cpuidle_driver *drv, struct psci_cpuidle_data *data = per_cpu_ptr(&psci_cpuidle_data, cpu); state_count++; /* Add WFI state too */ - psci_states = kcalloc(state_count, sizeof(*psci_states), GFP_KERNEL); + psci_states = devm_kcalloc(dev, state_count, sizeof(*psci_states), + GFP_KERNEL); if (!psci_states) return -ENOMEM; @@ -213,32 +199,26 @@ static int __init psci_dt_cpu_init_idle(struct cpuidle_driver *drv, of_node_put(state_node); if (ret) - goto free_mem; + return ret; pr_debug("psci-power-state %#x index %d\n", psci_states[i], i); } - if (i != state_count) { - ret = -ENODEV; - goto free_mem; - } + if (i != state_count) + return -ENODEV; /* Initialize optional data, used for the hierarchical topology. */ ret = psci_dt_cpu_init_topology(drv, data, state_count, cpu); if (ret < 0) - goto free_mem; + return ret; /* Idle states parsed correctly, store them in the per-cpu struct. */ data->psci_states = psci_states; return 0; - -free_mem: - kfree(psci_states); - return ret; } -static __init int psci_cpu_init_idle(struct cpuidle_driver *drv, - unsigned int cpu, unsigned int state_count) +static int psci_cpu_init_idle(struct device *dev, struct cpuidle_driver *drv, + unsigned int cpu, unsigned int state_count) { struct device_node *cpu_node; int ret; @@ -254,14 +234,22 @@ static __init int psci_cpu_init_idle(struct cpuidle_driver *drv, if (!cpu_node) return -ENODEV; - ret = psci_dt_cpu_init_idle(drv, cpu_node, state_count, cpu); + ret = psci_dt_cpu_init_idle(dev, drv, cpu_node, state_count, cpu); of_node_put(cpu_node); return ret; } -static int __init psci_idle_init_cpu(int cpu) +static void psci_cpu_deinit_idle(int cpu) +{ + struct psci_cpuidle_data *data = per_cpu_ptr(&psci_cpuidle_data, cpu); + + psci_dt_detach_cpu(data->dev); + psci_cpuidle_use_cpuhp = false; +} + +static int psci_idle_init_cpu(struct device *dev, int cpu) { struct cpuidle_driver *drv; struct device_node *cpu_node; @@ -284,17 +272,26 @@ static int __init psci_idle_init_cpu(int cpu) if (ret) return ret; - drv = kmemdup(&psci_idle_driver, sizeof(*drv), GFP_KERNEL); + drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); if (!drv) return -ENOMEM; + drv->name = "psci_idle"; + drv->owner = THIS_MODULE; drv->cpumask = (struct cpumask *)cpumask_of(cpu); /* - * Initialize idle states data, starting at index 1, since - * by default idle state 0 is the quiescent state reached - * by the cpu by executing the wfi instruction. - * + * PSCI idle states relies on architectural WFI to be represented as + * state index 0. + */ + drv->states[0].enter = psci_enter_idle_state; + drv->states[0].exit_latency = 1; + drv->states[0].target_residency = 1; + drv->states[0].power_usage = UINT_MAX; + strcpy(drv->states[0].name, "WFI"); + strcpy(drv->states[0].desc, "ARM WFI"); + + /* * If no DT idle states are detected (ret == 0) let the driver * initialization fail accordingly since there is no reason to * initialize the idle driver if only wfi is supported, the @@ -302,48 +299,45 @@ static int __init psci_idle_init_cpu(int cpu) * on idle entry. */ ret = dt_init_idle_driver(drv, psci_idle_state_match, 1); - if (ret <= 0) { - ret = ret ? : -ENODEV; - goto out_kfree_drv; - } + if (ret <= 0) + return ret ? : -ENODEV; /* * Initialize PSCI idle states. */ - ret = psci_cpu_init_idle(drv, cpu, ret); + ret = psci_cpu_init_idle(dev, drv, cpu, ret); if (ret) { pr_err("CPU %d failed to PSCI idle\n", cpu); - goto out_kfree_drv; + return ret; } ret = cpuidle_register(drv, NULL); if (ret) - goto out_kfree_drv; + goto deinit; cpuidle_cooling_register(drv); return 0; - -out_kfree_drv: - kfree(drv); +deinit: + psci_cpu_deinit_idle(cpu); return ret; } /* - * psci_idle_init - Initializes PSCI cpuidle driver + * psci_idle_probe - Initializes PSCI cpuidle driver * * Initializes PSCI cpuidle driver for all CPUs, if any CPU fails * to register cpuidle driver then rollback to cancel all CPUs * registration. */ -static int __init psci_idle_init(void) +static int psci_cpuidle_probe(struct platform_device *pdev) { int cpu, ret; struct cpuidle_driver *drv; struct cpuidle_device *dev; for_each_possible_cpu(cpu) { - ret = psci_idle_init_cpu(cpu); + ret = psci_idle_init_cpu(&pdev->dev, cpu); if (ret) goto out_fail; } @@ -356,9 +350,34 @@ static int __init psci_idle_init(void) dev = per_cpu(cpuidle_devices, cpu); drv = cpuidle_get_cpu_driver(dev); cpuidle_unregister(drv); - kfree(drv); + psci_cpu_deinit_idle(cpu); } return ret; } + +static struct platform_driver psci_cpuidle_driver = { + .probe = psci_cpuidle_probe, + .driver = { + .name = "psci-cpuidle", + }, +}; + +static int __init psci_idle_init(void) +{ + struct platform_device *pdev; + int ret; + + ret = platform_driver_register(&psci_cpuidle_driver); + if (ret) + return ret; + + pdev = platform_device_register_simple("psci-cpuidle", -1, NULL, 0); + if (IS_ERR(pdev)) { + platform_driver_unregister(&psci_cpuidle_driver); + return PTR_ERR(pdev); + } + + return 0; +} device_initcall(psci_idle_init); diff --git a/drivers/cpuidle/cpuidle-psci.h b/drivers/cpuidle/cpuidle-psci.h index 7299a04dd467..0690d66df829 100644 --- a/drivers/cpuidle/cpuidle-psci.h +++ b/drivers/cpuidle/cpuidle-psci.h @@ -3,15 +3,18 @@ #ifndef __CPUIDLE_PSCI_H #define __CPUIDLE_PSCI_H +struct device; struct device_node; void psci_set_domain_state(u32 state); -int __init psci_dt_parse_state_node(struct device_node *np, u32 *state); +int psci_dt_parse_state_node(struct device_node *np, u32 *state); #ifdef CONFIG_PM_GENERIC_DOMAINS_OF -struct device __init *psci_dt_attach_cpu(int cpu); +struct device *psci_dt_attach_cpu(int cpu); +void psci_dt_detach_cpu(struct device *dev); #else -static inline struct device __init *psci_dt_attach_cpu(int cpu) { return NULL; } +static inline struct device *psci_dt_attach_cpu(int cpu) { return NULL; } +static inline void psci_dt_detach_cpu(struct device *dev) { } #endif #endif /* __CPUIDLE_PSCI_H */ From patchwork Mon Jun 15 15:20:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 187947 Delivered-To: patch@linaro.org Received: by 2002:a54:30ca:0:0:0:0:0 with SMTP id e10csp2633532ecs; Mon, 15 Jun 2020 08:21:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOkZE5GWlMJgER6Emw9xfoguSBieLNGvD3/QOUpPy3psKrbYbvHA8and7B6hhY8P99Q2AZ X-Received: by 2002:a17:906:264a:: with SMTP id i10mr26010080ejc.210.1592234468569; Mon, 15 Jun 2020 08:21:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592234468; cv=none; d=google.com; s=arc-20160816; b=OOfDgH9PFr3MYqaXSqazo1s1pOknPdgYpgqu3wJ00KLDe5N5Q99nnqtItSfbJojYGM 9SEL3cWD/nhXsxoYzjmFR5uKM192moHh8pXh+JoigEuK4JGt8Pm30/8cHVjj7lkETw3h 4NxdRm0bKL+pUB5b4OyjIlBfOnrVnlIdI9w9BRyRuYzvDsNRSK8vFRM01kplwGX2Qb0l r6UL7aUzVeSb7G5Z0BicadcAOVJftFJPcavYFyIEhmm4tu2Bvua8SUT0rG91yNiEA3VZ C+MbK5sEpdCnGADZNeHIMQ44GQvo8+HmL5vCLsBVHGbG06EAFwZl8x7jjT0PcPSpgkvH xq3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1DzsoTjhcIMb9+A4N/cXj76UygN5PXLTTjiX9hXk5EQ=; b=X+SZnzbHHkjLCyGxTFZcH6IwuSeC5pQGkXQM/pcVHhQpLi7rTlNZVcmBhCNdbw0N4x Qfr76qrzH2VXL8uq9L9BW78a5a9nnvJQqaErw01bm74Q76yu4Hoe/+iKIRODZCUlZZPY aLME+KsR1/o2PtsdgPnUBGUSXW+7boL0j+f7s8PCiNqwFGvYZDao4TVSjMV3SkU5JvLd VS3/q+X1th2RL8zSKq7GZGDS1OfB9r+q1JC/jvkpB+Ad+oDlUg6oiHpwmFsyNDx2rplu MIZbsrLbK51fV42LenkVKwpT9Bj/pjjKV1FhqPezu739SZzOytzwcSVOZFF5/EoMaXDb Vvyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="R0/G6JK8"; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n4si9550427ejz.569.2020.06.15.08.21.08; Mon, 15 Jun 2020 08:21:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="R0/G6JK8"; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730276AbgFOPVH (ORCPT + 10 others); Mon, 15 Jun 2020 11:21:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730189AbgFOPVG (ORCPT ); Mon, 15 Jun 2020 11:21:06 -0400 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 165F0C061A0E for ; Mon, 15 Jun 2020 08:21:06 -0700 (PDT) Received: by mail-lj1-x241.google.com with SMTP id a9so19694908ljn.6 for ; Mon, 15 Jun 2020 08:21:06 -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=1DzsoTjhcIMb9+A4N/cXj76UygN5PXLTTjiX9hXk5EQ=; b=R0/G6JK86gTEe2vWg8LbA/u3P1xlSlDzO2cBwJ+jyc0Eyl/SwAQQeoz0nmHzEM9rYG a8C5hk3FatI1oDaBKtXmf3+5kDyy62EmcpnoKxRHDDReh/iU/lkb0M3PLXDf8aINzQh4 QI1dTzd06nIDvJMSyEZdHKFqHbdjdupZB6AUPdAPLN5I0c3AP6Os0XceOiYbeQCb3ilZ y51fAxDJmGo9fXYkYBbpYfTFG7x2KSFGUIUHwflaE6Geg2EOtDrjONRn4up1dxpUweV4 NCX0O91K4uoulbUiz6v+9NZzVzAsyYPHg+B170chZGL7TCwEPmyZFsymoEGalxo25AbC MwhQ== 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=1DzsoTjhcIMb9+A4N/cXj76UygN5PXLTTjiX9hXk5EQ=; b=thXTz71mFZ3XERckR1GiCHhd4719RLJdc7LOGWs6PbObIEB42IgN5hXUn1tB1fdWcT xVtaHai9IMQX37aMH3feP7oHboJtsIwHINwlaaFMpBV5AiTcJEVxxucMqXXZBxzgGwem GMjdJZyhm/oQa/wA+DuNPfTmNDy+ILd5pImmiC4bekkuRwJovytbYj34hRLEo6A+5M0T AlcRBQjLJE9mAbFH9X2VuHhCe6FG9SRIdconyGzzZcQIO+A2G/9BwZ+sU5xkNgv9OERt fFj2Cm2jT4NKIy9XrBj5H+qbh+45KyoCQEZ7oJfvt9nl9wSfQbxOk8H4nlM8VjFP/Ixl Cm8Q== X-Gm-Message-State: AOAM533a0cvo6/tSwljXYDYj7mXN69eWg12Ierlzlaa3o+0kbNlLPwdA iNTecBAtCzizWaeNEQr+hwsFNA== X-Received: by 2002:a2e:7016:: with SMTP id l22mr14031408ljc.284.1592234464325; Mon, 15 Jun 2020 08:21:04 -0700 (PDT) Received: from localhost.localdomain (h-98-128-181-7.NA.cust.bahnhof.se. [98.128.181.7]) by smtp.gmail.com with ESMTPSA id r13sm507045lfp.80.2020.06.15.08.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2020 08:21:03 -0700 (PDT) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Saravana Kannan , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Lina Iyer , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Benjamin Gaignard , Ulf Hansson , linux-arm-kernel@lists.infradead.org Subject: [PATCH 3/5] cpuidle: psci: Split into two separate build objects Date: Mon, 15 Jun 2020 17:20:52 +0200 Message-Id: <20200615152054.6819-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200615152054.6819-1-ulf.hansson@linaro.org> References: <20200615152054.6819-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The combined build object for the PSCI cpuidle driver and the PSCI PM domain, is a bit messy. Therefore let's split it up by adding a new Kconfig ARM_PSCI_CPUIDLE_DOMAIN and convert into two separate objects. Signed-off-by: Ulf Hansson --- drivers/cpuidle/Kconfig.arm | 10 ++++++++++ drivers/cpuidle/Makefile | 5 ++--- drivers/cpuidle/cpuidle-psci.h | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) -- 2.20.1 Reviewed-by: Lina Iyer Reviewed-by: Sudeep Holla diff --git a/drivers/cpuidle/Kconfig.arm b/drivers/cpuidle/Kconfig.arm index 51a7e89085c0..0844fadc4be8 100644 --- a/drivers/cpuidle/Kconfig.arm +++ b/drivers/cpuidle/Kconfig.arm @@ -23,6 +23,16 @@ config ARM_PSCI_CPUIDLE It provides an idle driver that is capable of detecting and managing idle states through the PSCI firmware interface. +config ARM_PSCI_CPUIDLE_DOMAIN + bool "PSCI CPU idle Domain" + depends on ARM_PSCI_CPUIDLE + depends on PM_GENERIC_DOMAINS_OF + default y + help + Select this to enable the PSCI based CPUidle driver to use PM domains, + which is needed to support the hierarchical DT based layout of the + idle states. + config ARM_BIG_LITTLE_CPUIDLE bool "Support for ARM big.LITTLE processors" depends on ARCH_VEXPRESS_TC2_PM || ARCH_EXYNOS || COMPILE_TEST diff --git a/drivers/cpuidle/Makefile b/drivers/cpuidle/Makefile index f07800cbb43f..26bbc5e74123 100644 --- a/drivers/cpuidle/Makefile +++ b/drivers/cpuidle/Makefile @@ -21,9 +21,8 @@ obj-$(CONFIG_ARM_U8500_CPUIDLE) += cpuidle-ux500.o obj-$(CONFIG_ARM_AT91_CPUIDLE) += cpuidle-at91.o obj-$(CONFIG_ARM_EXYNOS_CPUIDLE) += cpuidle-exynos.o obj-$(CONFIG_ARM_CPUIDLE) += cpuidle-arm.o -obj-$(CONFIG_ARM_PSCI_CPUIDLE) += cpuidle_psci.o -cpuidle_psci-y := cpuidle-psci.o -cpuidle_psci-$(CONFIG_PM_GENERIC_DOMAINS_OF) += cpuidle-psci-domain.o +obj-$(CONFIG_ARM_PSCI_CPUIDLE) += cpuidle-psci.o +obj-$(CONFIG_ARM_PSCI_CPUIDLE_DOMAIN) += cpuidle-psci-domain.o obj-$(CONFIG_ARM_TEGRA_CPUIDLE) += cpuidle-tegra.o obj-$(CONFIG_ARM_QCOM_SPM_CPUIDLE) += cpuidle-qcom-spm.o diff --git a/drivers/cpuidle/cpuidle-psci.h b/drivers/cpuidle/cpuidle-psci.h index 0690d66df829..d8e925e84c27 100644 --- a/drivers/cpuidle/cpuidle-psci.h +++ b/drivers/cpuidle/cpuidle-psci.h @@ -9,7 +9,7 @@ struct device_node; void psci_set_domain_state(u32 state); int psci_dt_parse_state_node(struct device_node *np, u32 *state); -#ifdef CONFIG_PM_GENERIC_DOMAINS_OF +#ifdef CONFIG_ARM_PSCI_CPUIDLE_DOMAIN struct device *psci_dt_attach_cpu(int cpu); void psci_dt_detach_cpu(struct device *dev); #else From patchwork Mon Jun 15 15:20:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 187946 Delivered-To: patches@linaro.org Received: by 2002:a54:30ca:0:0:0:0:0 with SMTP id e10csp2633505ecs; Mon, 15 Jun 2020 08:21:06 -0700 (PDT) X-Received: by 2002:a2e:998c:: with SMTP id w12mr14057243lji.143.1592234466672; Mon, 15 Jun 2020 08:21:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592234466; cv=none; d=google.com; s=arc-20160816; b=T34oUtWU3mcWsbsw18Grw6/r0beSjA7Uu543Kj2Q0mMCuH0mpz1f0g+hUhjTIpOBy/ QubcLde4TXjoDev8XneYr5NlrSe5wGglkFRk0ATCFJSn9XldsWU8JTNKpO+uzbw2wpA2 tfPlKyjbWlfwgsdT50TVKVjMzxslZSedxQzbwvzVZYoThe8qXoK921LKzpwf/3d+O3Hv yZAYBGA0b6VmB9aHI63UJ4EV4mxbQAcSxwN8ntejgDNieSMguEK07oe72PwPCVY31uZw oJ968xInCUuek18ONsTx9H3AXTMP8wOybNtUb0JWtXxpizIzpakO8y72pfW5k0ou+fmU zxtQ== 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=GC70gu/KuM6k/D+t12MJpeTyl5aXSJlixkvFE052RDs=; b=y/AeM+7sCr8AanLLi3g1Q/5DEe6fTfCSMZqKxTCS+t6y1mh1Y5RmeoFIWKOC1DIIM/ fqu5bUpGF3Hi3p2/mYMdNmIV8hsiYlYp/tz16pc25CUu+gwbeXPKBb/ru9QJqOZ6rZ6f Rf0Q23PewZqVsyehtyi9yg2ZeK1kNsDrmvSU0ol/IQejRq6fSyd72CH9ucQByrEglXry 6abUeetQoViv+j4un0UXq5V/GjiKSYN7JBmcnw/W04nOLN6Yqju7qpNMDdhLO3x9/URi LEMRDYdQuFjEyJjv+SwRQVUCHCWfLmhl6OZmiqLUx5e1qS5lIt3Sflw+7+Xnys9aH4Vd lUCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JnL0VFDL; 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 o13sor1419671lfc.2.2020.06.15.08.21.06 for (Google Transport Security); Mon, 15 Jun 2020 08:21:06 -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=JnL0VFDL; 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=GC70gu/KuM6k/D+t12MJpeTyl5aXSJlixkvFE052RDs=; b=JnL0VFDLFIILGO0nUCBh6p0+PJ00P5rFYB20L3+wdzaaf8acyU6+crOeQkjOcz8p/E NfwTDioK18cs92dba9RgtWPAcJDK+LIXfIhyOw3QuLi12wdFTNil8MGzDJchWaNQlfaa zFWw+iLfdLh3nXCfCUB0VlxhohW1EzmVJmRdCauuidUUtv7YYIXDeybeVxxORKB5vXnd Udwb7Ru4v7rRwdqK139qq9Jpmu+7RZ+IAxL8B44Pw/JCegI3nsv5BN+j6UFNiQeW24iX QDAOMGAC4aAlcWUSDRxGHPNdDzww078zeUC/8FqlNt7EVD3yO8oehMaZZ0FxB8sN/uAw P9iw== 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=GC70gu/KuM6k/D+t12MJpeTyl5aXSJlixkvFE052RDs=; b=K0VllytcaYqBFc6S178k9vxy6RzGvmkcGBuCWOYzTapGIU18JJMPnd2XyqrpDdsEtX 6SKoe5RAc+27m4PbEFCaiXBl/xhq7S30yF6Wbmj8QTxR6stqoMQXfqS1kiAlHTKpCuri QanKsPTiEb+YG7EYIxeQqRgXoBtObU31K40AxFCxHEaSWd6TSX2mH1PYxildIJWsX6ZJ YUeulxVprrCO4NtmNBEl/9mTsRhkkYKvFpyKHEz0Wt6CeZNELQtp7OeDgKbZHrPNZaif ns3t7KgF4IUpph4yA+9Da6dupboW5sL0OUvF6UO2CrgpZSzr1+oAQvnycZlSsNH0Gnh6 +nsg== X-Gm-Message-State: AOAM531u7rBdBh0H2LvKgEm5n7if6y4fYVcvC1x4WZQQ26VgIi3ISCwA R/I16lGVUqvSi+wdj8XKYhxkqY+b X-Google-Smtp-Source: ABdhPJzuWrj4m6EK3EepgYnbI6CxPwGIQzFsWlLIN5e2ApsKrVZA6GxkeECekZVHmqtxdz1F/MtQnw== X-Received: by 2002:ac2:48a6:: with SMTP id u6mr8375406lfg.49.1592234466371; Mon, 15 Jun 2020 08:21:06 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-98-128-181-7.NA.cust.bahnhof.se. [98.128.181.7]) by smtp.gmail.com with ESMTPSA id r13sm507045lfp.80.2020.06.15.08.21.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2020 08:21:05 -0700 (PDT) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Saravana Kannan , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Lina Iyer , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Benjamin Gaignard , Ulf Hansson , linux-arm-kernel@lists.infradead.org Subject: [PATCH 4/5] cpuidle: psci: Convert PM domain to platform driver Date: Mon, 15 Jun 2020 17:20:53 +0200 Message-Id: <20200615152054.6819-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200615152054.6819-1-ulf.hansson@linaro.org> References: <20200615152054.6819-1-ulf.hansson@linaro.org> MIME-Version: 1.0 To enable support for deferred probing and to allow implementation of the ->sync_state() callback from subsequent changes, let's convert into a platform driver. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci-domain.c | 45 +++++++++++++++++---------- 1 file changed, 28 insertions(+), 17 deletions(-) -- 2.20.1 Reviewed-by: Lina Iyer diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c index e48e578aaa7d..bf527d2bb4b6 100644 --- a/drivers/cpuidle/cpuidle-psci-domain.c +++ b/drivers/cpuidle/cpuidle-psci-domain.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -42,8 +43,8 @@ static int psci_pd_power_off(struct generic_pm_domain *pd) return 0; } -static int __init psci_pd_parse_state_nodes(struct genpd_power_state *states, - int state_count) +static int psci_pd_parse_state_nodes(struct genpd_power_state *states, + int state_count) { int i, ret; u32 psci_state, *psci_state_buf; @@ -72,7 +73,7 @@ static int __init psci_pd_parse_state_nodes(struct genpd_power_state *states, return ret; } -static int __init psci_pd_parse_states(struct device_node *np, +static int psci_pd_parse_states(struct device_node *np, struct genpd_power_state **states, int *state_count) { int ret; @@ -100,7 +101,7 @@ static void psci_pd_free_states(struct genpd_power_state *states, kfree(states); } -static int __init psci_pd_init(struct device_node *np) +static int psci_pd_init(struct device_node *np) { struct generic_pm_domain *pd; struct psci_pd_provider *pd_provider; @@ -167,7 +168,7 @@ static int __init psci_pd_init(struct device_node *np) return ret; } -static void __init psci_pd_remove(void) +static void psci_pd_remove(void) { struct psci_pd_provider *pd_provider, *it; struct generic_pm_domain *genpd; @@ -185,7 +186,7 @@ static void __init psci_pd_remove(void) } } -static int __init psci_pd_init_topology(struct device_node *np, bool add) +static int psci_pd_init_topology(struct device_node *np, bool add) { struct device_node *node; struct of_phandle_args child, parent; @@ -211,24 +212,24 @@ static int __init psci_pd_init_topology(struct device_node *np, bool add) return 0; } -static int __init psci_pd_add_topology(struct device_node *np) +static int psci_pd_add_topology(struct device_node *np) { return psci_pd_init_topology(np, true); } -static void __init psci_pd_remove_topology(struct device_node *np) +static void psci_pd_remove_topology(struct device_node *np) { psci_pd_init_topology(np, false); } -static const struct of_device_id psci_of_match[] __initconst = { +static const struct of_device_id psci_of_match[] = { { .compatible = "arm,psci-1.0" }, {} }; -static int __init psci_idle_init_domains(void) +static int psci_cpuidle_domain_probe(struct platform_device *pdev) { - struct device_node *np = of_find_matching_node(NULL, psci_of_match); + struct device_node *np = pdev->dev.of_node; struct device_node *node; int ret = 0, pd_count = 0; @@ -237,7 +238,7 @@ static int __init psci_idle_init_domains(void) /* Currently limit the hierarchical topology to be used in OSI mode. */ if (!psci_has_osi_support()) - goto out; + return 0; /* * Parse child nodes for the "#power-domain-cells" property and @@ -256,7 +257,7 @@ static int __init psci_idle_init_domains(void) /* Bail out if not using the hierarchical CPU topology. */ if (!pd_count) - goto out; + return 0; /* Link genpd masters/subdomains to model the CPU topology. */ ret = psci_pd_add_topology(np); @@ -271,9 +272,8 @@ static int __init psci_idle_init_domains(void) goto remove_pd; } - of_node_put(np); pr_info("Initialized CPU PM domain topology\n"); - return pd_count; + return 0; put_node: of_node_put(node); @@ -281,10 +281,21 @@ static int __init psci_idle_init_domains(void) if (pd_count) psci_pd_remove(); pr_err("failed to create CPU PM domains ret=%d\n", ret); -out: - of_node_put(np); return ret; } + +static struct platform_driver psci_cpuidle_domain_driver = { + .probe = psci_cpuidle_domain_probe, + .driver = { + .name = "psci-cpuidle-domain", + .of_match_table = psci_of_match, + }, +}; + +static int __init psci_idle_init_domains(void) +{ + return platform_driver_register(&psci_cpuidle_domain_driver); +} subsys_initcall(psci_idle_init_domains); struct device *psci_dt_attach_cpu(int cpu) From patchwork Mon Jun 15 15:20:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 187948 Delivered-To: patch@linaro.org Received: by 2002:a54:30ca:0:0:0:0:0 with SMTP id e10csp2633608ecs; Mon, 15 Jun 2020 08:21:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlInDhC+usOJSTEmzd6QspDX2hfnIzRHPd9Ahg0kHTqNDlKy1YKVkrmg/EPv5NpKc94y8F X-Received: by 2002:a50:f052:: with SMTP id u18mr23749513edl.16.1592234475200; Mon, 15 Jun 2020 08:21:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592234475; cv=none; d=google.com; s=arc-20160816; b=hKtV5J/d/BFhUiB3O4r2lFCsWX/uMHXBbIcXIlISj0hO4cYp9MxUNVnVCB/fBFgriz vkGzexiSJAqahGEmVJPETroz2wvsAuBVfBHtrHGMmvFZupY/kzkVs8xS0srbIL6Xs8At FyIdbvXx5yZbrsC+CWUUdrYcm1v8EmPv4J4d6u9cyGxS29Sy/u/s+xaj6DRGTUkAa557 4qKKK2mOeGAbJxXJ7TKegK3inHxLhCfo3qxzPrgxIFYmbmuGdZmmlpAkDR8cYbqEsKeD 9BJ/fYFvXJqxkQXrj8AJvjJU4o4wBk+WIFoC0OrDS3ZcY+RWQ/4kfViywdAYK/VcXzTC dbpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vhNL1X1q5NcFvN2K8EIYcmkOuXak8nPvZVNGDqJ5u0c=; b=RJTFM8VQXjbAYuvbWUUV8b9S9GftN+qHX7GQ0ym9DOqRpXiCkLhoETLa1s3PTBqBzm DrngGxY3omDHV40MYED3dX4EiGii2MGSjo5CDnXXxsDO+et0niQVxDwNbFiNE6AHCrNZ 6YPWuyHPApcuE8hbGN5rQEHbyndfGCTDlA9vpTGV5w5QAiGuCj+vZcykePrb9bj/Ye8u M4HWObhvnR//VOeLtprv5AGiBnQy067PF29hGgy1WAt1tb3z/BLsKYCiqAG1/CG4tuYH 82OuSFbxpPJ37QjAakPDxrkqZ1RnIy7ADtRylIePSFjsAfa8upZs4vYrnQzUIvVj15ep vcdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OQjdZzsx; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y16si8811298ejw.501.2020.06.15.08.21.15; Mon, 15 Jun 2020 08:21:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=OQjdZzsx; spf=pass (google.com: domain of linux-pm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729825AbgFOPVL (ORCPT + 10 others); Mon, 15 Jun 2020 11:21:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730313AbgFOPVK (ORCPT ); Mon, 15 Jun 2020 11:21:10 -0400 Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC0EBC061A0E for ; Mon, 15 Jun 2020 08:21:09 -0700 (PDT) Received: by mail-lf1-x143.google.com with SMTP id c21so9792171lfb.3 for ; Mon, 15 Jun 2020 08:21:09 -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=vhNL1X1q5NcFvN2K8EIYcmkOuXak8nPvZVNGDqJ5u0c=; b=OQjdZzsxvgkgfaKvQLiV9tJflG/RmsGfS4m0I+TNrGoWmxvcK+jbLmLbY/ExTtyYIY Vg0NakP5xmuAUYG5zcgPGVkCT9VZF1veYdWFoUD5fUgHkfVGaeNHKEJN25AAgTF8V8LQ PgzfhEgTzMOyHpSDNFa2qyo9TypmPVyqxH4getv5l1aDBZQ3JkpJ8cxAiWzEzKFR4E10 49TbJjXKfSkjjPLPMQcqrsoyB/Ois6R99dzAT+FzaGoCQbXGJ1dSBUfaQ4MCqVesCMIo 7R4yEVofwZbDenbjuj6hfTqi7qeLn8Gkf0aQ0W8V+NzNUTtNWCiLwAcU9+i8nBfBxN1i aXPA== 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=vhNL1X1q5NcFvN2K8EIYcmkOuXak8nPvZVNGDqJ5u0c=; b=nWuSrnIWdL9yIAEAcmREyMu6lgstllwP3QSqrKIyrnZFMA9XdGjVbzluS4ZCz8uh0t +fdfG1rA5oHpHV16sE//swsPTJP1UrRYMd5SgItfFoOGXvkVJy73RjP8QceTvu+PgRlp rOUW3K6fic/Ur9P/SFpSaWXvIBJtXm5TibQCzxbCyAu1lpABONWvVK0JNqtb88mILHPO auoZJD8sVQIe4lmC6jJ8uTpl+dq2Q3uuHLeX0iwkAewvRSwl3J1Io4nYsNQSDMY8eVpv tb62ZIj9RNoJyZdxVGvvjs5A182kySdLtgbVaw/0xEENOGywV/NKxSTJaMQhF1c8FHtr or+A== X-Gm-Message-State: AOAM533K0s92qKAsxI5LbZvNyiXhN7qgKLz/eq1y3KncIm9KGIEYRIR8 ZyXWbEJN0Ktkv4L5XPbL4fi7SA== X-Received: by 2002:a19:a44:: with SMTP id 65mr2240250lfk.69.1592234468265; Mon, 15 Jun 2020 08:21:08 -0700 (PDT) Received: from localhost.localdomain (h-98-128-181-7.NA.cust.bahnhof.se. [98.128.181.7]) by smtp.gmail.com with ESMTPSA id r13sm507045lfp.80.2020.06.15.08.21.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2020 08:21:07 -0700 (PDT) From: Ulf Hansson To: Sudeep Holla , Lorenzo Pieralisi , Saravana Kannan , linux-pm@vger.kernel.org Cc: "Rafael J . Wysocki" , Daniel Lezcano , Lina Iyer , Vincent Guittot , Stephen Boyd , Bjorn Andersson , Benjamin Gaignard , Ulf Hansson , linux-arm-kernel@lists.infradead.org Subject: [PATCH 5/5] cpuidle: psci: Prevent domain idlestates until consumers are ready Date: Mon, 15 Jun 2020 17:20:54 +0200 Message-Id: <20200615152054.6819-6-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200615152054.6819-1-ulf.hansson@linaro.org> References: <20200615152054.6819-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Depending on the SoC/platform, additional devices may be part of the PSCI PM domain topology. This is the case with 'qcom,rpmh-rsc' device, for example, even if this is not yet visible in the corresponding DTS-files. Without going into too much details, a device like the 'qcom,rpmh-rsc' may have HW constraints that needs to be obeyed to, before a domain idlestate can be picked. Therefore, let's implement the ->sync_state() callback to receive a notification when all consumers of the PSCI PM domain providers have been attached/probed to it. In this way, we can make sure all constraints from all relevant devices, are taken into account before allowing a domain idlestate to be picked. Signed-off-by: Ulf Hansson --- drivers/cpuidle/cpuidle-psci-domain.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) -- 2.20.1 Acked-by: Saravana Kannan diff --git a/drivers/cpuidle/cpuidle-psci-domain.c b/drivers/cpuidle/cpuidle-psci-domain.c index bf527d2bb4b6..b6e9649ab0da 100644 --- a/drivers/cpuidle/cpuidle-psci-domain.c +++ b/drivers/cpuidle/cpuidle-psci-domain.c @@ -27,6 +27,7 @@ struct psci_pd_provider { }; static LIST_HEAD(psci_pd_providers); +static bool psci_pd_allow_domain_state; static int psci_pd_power_off(struct generic_pm_domain *pd) { @@ -36,6 +37,9 @@ static int psci_pd_power_off(struct generic_pm_domain *pd) if (!state->data) return 0; + if (!psci_pd_allow_domain_state) + return -EBUSY; + /* OSI mode is enabled, set the corresponding domain state. */ pd_state = state->data; psci_set_domain_state(*pd_state); @@ -222,6 +226,15 @@ static void psci_pd_remove_topology(struct device_node *np) psci_pd_init_topology(np, false); } +static void psci_cpuidle_domain_sync_state(struct device *dev) +{ + /* + * All devices have now been attached/probed to the PM domain topology, + * hence it's fine to allow domain states to be picked. + */ + psci_pd_allow_domain_state = true; +} + static const struct of_device_id psci_of_match[] = { { .compatible = "arm,psci-1.0" }, {} @@ -289,6 +302,7 @@ static struct platform_driver psci_cpuidle_domain_driver = { .driver = { .name = "psci-cpuidle-domain", .of_match_table = psci_of_match, + .sync_state = psci_cpuidle_domain_sync_state, }, };