From patchwork Thu Nov 29 17:46:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 152440 Delivered-To: patches@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2672422ljp; Thu, 29 Nov 2018 09:47:36 -0800 (PST) X-Received: by 2002:a19:c7c2:: with SMTP id x185mr1695873lff.123.1543513656702; Thu, 29 Nov 2018 09:47:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543513656; cv=none; d=google.com; s=arc-20160816; b=ZFcT8hLrFTs/7p6uV2X/PaFQcRSYyicG1guIg213XfUR0wYOCS5GzAJOsj186JUHDQ gxrnOV7EmAmZBcAOqi/fUJjR35scpTRwDOmgQFz2mfTPEOUx0/tOpZ01kQU0l8psWRtw SWAikILqK07uztg1GGBH0AjnTTR6gQXU5jDbJ19+69ZE4PqReahej41rzmyorOGmFZvC qXwHhzgTLDNtcWPA+DIWZah+d3eShWP4yDL3edaoHUVMSGCnW66k45g/2JXOJAjdypXS gpLHSXHQ2Xkm1ob60ZdjVzCyIVT380/cgykkM1YMblgnLgOVR6gp82ClIVSjsVdAg5+s FI3Q== 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; bh=PgU1c1CxxtqSBW5JefCvIK+xCW7iLG8npYRcb1HuKE4=; b=Xyz46WEY8k/Gj4dzPIvoEd9NO2lulSyGiowce95/NEe51st5xUQr+BO8hZhuDruJhy MqSLjg+tBW+eVYNU2y3q6HazaELdm9i5Oyzrw6ynQCQu02k490Pb3WxuQPikfiE9kb4p 1od8E+dcRDy5KdTiCcBmjc6VcuG8QRv2nsQV6OE08Rrz25SGRBwbk6/4qwElMCMmk+Y0 Aj2Su4H2gOqyV71243r6WDtrIWsDbq9mJLbjgxBoEpQmxFV40Rwfoox4vVP0yqfyMuqW fnLUOsj7NrbyeL4iopKWEl1Sfnkdo7E5X/BVI5HaRttcgyZoTtkPU99Ym3XKRLzaFBm8 hlIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="B/5EWbX/"; 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 r65-v6sor1793358ljb.13.2018.11.29.09.47.36 for (Google Transport Security); Thu, 29 Nov 2018 09:47:36 -0800 (PST) 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="B/5EWbX/"; 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=PgU1c1CxxtqSBW5JefCvIK+xCW7iLG8npYRcb1HuKE4=; b=B/5EWbX/4pIf3Oc3G2zdHEoTEbgIGKaLe3sWcikr1JnH0hv2gk3BnxwQr4TUdob0pS GBHcOVwcErj08YkbJF+3nI8Qeiz3paCDoblCXvk3zQCosYDQzVJJ3Zu2ag+TMhbtAuwy JVyxj/mbnkShjM0JtEpEnU0awLd8+vHoqWDi4= 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=PgU1c1CxxtqSBW5JefCvIK+xCW7iLG8npYRcb1HuKE4=; b=GysI5XqpPZY7ly8wUAYBmdBKgJR8REOpOfXoveRJ2cOUf+EXjF9ms2nVaGbwGfO1xJ VPb7GOmUWE/05xQ5tOKihLjslhOdlGzvn7mnJjvh1quuwwbNNKgzlRhDehyKPJS9GdgM i0+HsBfnc/bXCK7t2ubXb2f5Vmn9UOJ334WU2K5OQ9OcKPTj8CHpdoL8hH7n0D9oNAue gDvE1wXcYVJnVivmkv2DbiHH8Yhi/RqZPeYPKGYYKjTIMvRdFy+5SprwtIVvEezC/q1T Gf4bNyBuMf4/s5nRFFf/eOoeZ0aU8/RinQUMWeUvfeDtyh0XBOuPXJ6bjGucCbDKnS5V B9zA== X-Gm-Message-State: AA+aEWazuxJhdKZy3pPDQljDEHhCMU2B3M7dXfAur9yBDqdXzdoG9rGX jvkBhu6NCgBYZhKepWqRyoK6i9Wm X-Google-Smtp-Source: AFSGD/WczsUHri23WmBiaft8WE6DWc6NG5zksmRIXHH/fM1XFB8rrAvVA/6TldZECosGbxyL5A6+UQ== X-Received: by 2002:a2e:85d3:: with SMTP id h19-v6mr1678736ljj.82.1543513656433; Thu, 29 Nov 2018 09:47:36 -0800 (PST) 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 j76-v6sm393983ljb.12.2018.11.29.09.47.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Nov 2018 09:47:35 -0800 (PST) From: Ulf Hansson To: "Rafael J . Wysocki" , Sudeep Holla , Lorenzo Pieralisi , Mark Rutland , Daniel Lezcano , linux-pm@vger.kernel.org Cc: "Raju P . L . S . S . S . N" , Stephen Boyd , Tony Lindgren , Kevin Hilman , Lina Iyer , Ulf Hansson , Viresh Kumar , Vincent Guittot , Geert Uytterhoeven , linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v10 16/27] drivers: firmware: psci: Prepare to use OS initiated suspend mode Date: Thu, 29 Nov 2018 18:46:49 +0100 Message-Id: <20181129174700.16585-17-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181129174700.16585-1-ulf.hansson@linaro.org> References: <20181129174700.16585-1-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 are created by ORing the bits for PM domain's 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 the variable. Cc: Lina Iyer Co-developed-by: Lina Iyer Signed-off-by: Ulf Hansson --- Changes in v10: - Use __this_cpu_read|write() rather than this_cpu_read|write(). --- drivers/firmware/psci/psci.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index 4f0cbc95e41b..8dbcdecc2ae4 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); } @@ -409,15 +422,17 @@ int psci_cpu_init_idle(struct cpuidle_driver *drv, 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 @@ -425,11 +440,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; }