From patchwork Thu Apr 12 11:14:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 133257 Delivered-To: patches@linaro.org Received: by 10.46.84.29 with SMTP id i29csp1573888ljb; Thu, 12 Apr 2018 04:15:12 -0700 (PDT) X-Received: by 10.46.54.20 with SMTP id d20mr381466lja.114.1523531712131; Thu, 12 Apr 2018 04:15:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523531712; cv=none; d=google.com; s=arc-20160816; b=g5dMmBByLT2AMN9pg2rBHkCorJLWW2kMqpGhxLUhIpMZRy3K9/0mJn2RdCMsUW9QWT R43iq9ybAimBTnh+mrmITM7jyE2doDrWelw1+ZFf3Slz4jKWOwHhwZKqOZivKa5vBi0U XHs/oXTPUWKfx011FZJghM0e1I+NDfcx5CvzKu2x+AZ4sr5arhXeNcuzAuZLsbqeQis0 TA6LhxwjCrAF2jYhvQ1H+38y/OGgzuTXWhljUh28oO2Oc2UrcTdl+/Or0aH85xshV3cG skLagZluE/tUKK0Z1KWlW5JrvDt0I4vdVpubF4uk5cQxbEBQwyIthgp6BnUPlOHY6b1m WUDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=CLZv/6uOiw9vI+wQv3ueZ/LLuTM3aRhla8SPqP5AgTg=; b=KDTwQhYTK0cinf7DaicT654VPyCiL3pff/UxK5s8rGvJHHSsJRRZj25ElDfXVD0sBO XMqKAuJVgjZXxQxPq1Q71NiU6dp3sSqzhbdXWTq21LxB3eZm8aQS9GaZUSXhAD9a512G zEAXVXc55dPu1bQEoc1STCLhydj66N19HIZ9+NLwQsHDgonbPrT9TdG/WgueM8oNJeC4 edGq12j8ApgnH7uUst9PwzYqZWcSPC7+lfwL3U/lDxPhZwMRzDF0YN3jOUGC1kUlr9TH 7m6XMmnoACbj56ef26s3vdMP//FuwJLSm9QbvL9aqNHU2+IEwXPnjG59AYM6+XHjVd0A cKmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G0+Jh59u; 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 p22sor897494ljg.12.2018.04.12.04.15.12 for (Google Transport Security); Thu, 12 Apr 2018 04:15:12 -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=G0+Jh59u; 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; bh=CLZv/6uOiw9vI+wQv3ueZ/LLuTM3aRhla8SPqP5AgTg=; b=G0+Jh59umkwJB698c2RB2If9ZKDrVHtAZJJ9hiEz8/AkLQGSrhuVT+RlUjxhVAOh6L pfxiY4BdeBJK8EOWO9pQzVleBnDliJ0aeIlC6oVBxNaV3x2J8KvyqKOinx3E8G2jIA/R BPpB6lHGYj001AEiAcq9Onb+m07GbhBlSIWMY= 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; bh=CLZv/6uOiw9vI+wQv3ueZ/LLuTM3aRhla8SPqP5AgTg=; b=QEO5KVmqQl6DYN/Iv3phS6Amznlcex4fccbhF4a4e1ZJN9zsJAC7j6nTgaCrG8FWZF V/Ls/P0M1Fu4uYjAl7EQd6MPShe22l/bByFnkVGCBu/4u5Cq6PypTItHfd45FQPa2EGD a4ukYZY1Jxo6BNbUf4lwwo+LkDxMs6IlFeTZluAUqwCPYF1dL0BoY645O736QpZH8EJ9 CmZu7hJFxi9XXoiaqT3zN0ZUvs041AxJYOq315XQoUrs3byWpECHkDDSm2OMMiClZb24 RuYKdLIWff5ZgMbD18YBFhw8JFCsMfrgfkXrebNLhZHdOwkTkHvgBynAbuBh+bmhcvvK rXKg== X-Gm-Message-State: ALQs6tD0isnt7eaRPot9POF/77aGzFy12yu/tGB6wNW0mAX/rRxnKmrV 1kiWWB4vS9irdsTZFYDi4C5X1m6h X-Google-Smtp-Source: AIpwx49a8s23MUX5vh6XozH+RnJhKfmqz1q6V2EcaUj79apwzrfUBotIEY1uyL6zbmdGN3PviPm8hA== X-Received: by 10.46.41.19 with SMTP id u19mr415801lje.62.1523531711875; Thu, 12 Apr 2018 04:15:11 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id r29sm543187lje.72.2018.04.12.04.15.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Apr 2018 04:15:11 -0700 (PDT) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , linux-pm@vger.kernel.org Cc: Kevin Hilman , Lina Iyer , Lina Iyer , Ulf Hansson , Rob Herring , Daniel Lezcano , Thomas Gleixner , Vincent Guittot , Stephen Boyd , Juri Lelli , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 19/26] drivers: firmware: psci: Prepare to use OS initiated suspend mode Date: Thu, 12 Apr 2018 13:14:24 +0200 Message-Id: <1523531671-27491-20-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523531671-27491-1-git-send-email-ulf.hansson@linaro.org> References: <1523531671-27491-1-git-send-email-ulf.hansson@linaro.org> To enable the OS initiated mode, the CPU topology needs to be described using the hierarchical model in DT. When used, the idle state bits for the CPU needs to be created by ORing the bits for CPU's selected idle state with the bits for CPU's PM domain (CPU's cluster) idle state. Let's prepare the PSCI driver to deal with this, via introducing a per CPU variable called domain_state and by adding internal helpers to read/write the value of variable. Cc: Lina Iyer Co-developed-by: Lina Iyer Signed-off-by: Ulf Hansson --- drivers/firmware/psci/psci.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index e8f4f84..40b2b89 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -87,8 +87,19 @@ static u32 psci_function_id[PSCI_FN_MAX]; (PSCI_1_0_EXT_POWER_STATE_ID_MASK | \ PSCI_1_0_EXT_POWER_STATE_TYPE_MASK) +static DEFINE_PER_CPU(u32, domain_state); static u32 psci_cpu_suspend_feature; +static inline u32 psci_get_domain_state(void) +{ + return this_cpu_read(domain_state); +} + +static inline void psci_set_domain_state(u32 state) +{ + this_cpu_write(domain_state, state); +} + static inline bool psci_has_ext_power_state(void) { return psci_cpu_suspend_feature & @@ -187,6 +198,8 @@ static int psci_cpu_on(unsigned long cpuid, unsigned long entry_point) fn = psci_function_id[PSCI_FN_CPU_ON]; err = invoke_psci_fn(fn, cpuid, entry_point, 0); + /* Clear the domain state to start fresh. */ + psci_set_domain_state(0); return psci_to_linux_errno(err); } @@ -408,15 +421,17 @@ int psci_cpu_init_idle(unsigned int cpu) static int psci_suspend_finisher(unsigned long index) { u32 *state = __this_cpu_read(psci_power_state); + u32 composite_state = state[index - 1] | psci_get_domain_state(); - return psci_ops.cpu_suspend(state[index - 1], - __pa_symbol(cpu_resume)); + return psci_ops.cpu_suspend(composite_state, __pa_symbol(cpu_resume)); } int psci_cpu_suspend_enter(unsigned long index) { int ret; u32 *state = __this_cpu_read(psci_power_state); + u32 composite_state = state[index - 1] | psci_get_domain_state(); + /* * idle state index 0 corresponds to wfi, should never be called * from the cpu_suspend operations @@ -424,11 +439,14 @@ int psci_cpu_suspend_enter(unsigned long index) if (WARN_ON_ONCE(!index)) return -EINVAL; - if (!psci_power_state_loses_context(state[index - 1])) - ret = psci_ops.cpu_suspend(state[index - 1], 0); + if (!psci_power_state_loses_context(composite_state)) + ret = psci_ops.cpu_suspend(composite_state, 0); else ret = cpu_suspend(index, psci_suspend_finisher); + /* Clear the domain state to start fresh when back from idle. */ + psci_set_domain_state(0); + return ret; }