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: 10338411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6F83A603B5 for ; Thu, 12 Apr 2018 11:32:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F27D2621E for ; Thu, 12 Apr 2018 11:32:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 418AF287E5; Thu, 12 Apr 2018 11:32:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 905C9287E2 for ; Thu, 12 Apr 2018 11:32:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=alFMs1pZB+RLBXsPYrpsrzfjxkX/v/jfBBt203ivbEA=; b=iGG2lKeUyh5Z2xnO2O1Xc1jHQI ZrNlEOHzh5dRGgp4mPydffPH0jeV4DKtyKf1NsCfoCbdTSP/KdATHxqVKqZySezqPlO1QWGFegzUh qTxS9ZsJci0u4QYxSAeDVp6r3iKNGmojhuGvBdXKI7/GbjWG+D4JORctpoFVISZLiVI5OSFl4g0T2 hFjA78Ar2Xn3hsvktATuue0pcjab6s6EaN1dYnp6ZWZV+aG4zpuH2jbgGZOilTz9P5CWvGXJrkH/p DRlx3YfZsHTjKGdYyj+wdkf2uz79f7aYlpUwwQaVHjnitX4O2lwrDk95KDxdaMMzFJUCi4RmAprIS LNnSljaA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f6aSm-0002VF-Im; Thu, 12 Apr 2018 11:32:24 +0000 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f6aCK-0006Mj-2S for linux-arm-kernel@lists.infradead.org; Thu, 12 Apr 2018 11:15:26 +0000 Received: by mail-lf0-x241.google.com with SMTP id v207-v6so7114513lfa.10 for ; Thu, 12 Apr 2018 04:15:13 -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; 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=uacTebf9Q2YRP35KEVIAzMjFH2ZA4qigWAT938AFvi/wiUnbCvPjOhKu1OdRLOAEml 5i4FQGS916k2pJpozbMgFL16D3DOxbbjGyl1gqcHHIJAxsgEOJ1gQ3P81T13jBsTeLuz Gth/F24CZyL/ajaKf1kwj74MySZWnT8p9gabpp8KT+2kjClCv8/eB1mwsp3e8txBvj9a E87mEuI+SxYII8bpM5+3ZVSwGoKjtO+BV5RbDOv4WZsaiUNybMw9PRMkHtmrptO8hCQU +JvhbSV+4xjVhpLRHul4Xs0r9wlL7+v4SNLGvmNO6V6yNlG9JHUUCwtb7wgTiHtFBmIp ftuA== X-Gm-Message-State: ALQs6tAMyw4JBCDJ2qg+Gx2tLNTfqtP4MKEGKGbAnx/YmjSKzm4+G068 N7eaVAIeKNJ13W643BBRRatR2Q== 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) 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180412_041524_215627_68C73951 X-CRM114-Status: GOOD ( 18.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ulf Hansson , Vincent Guittot , Juri Lelli , Geert Uytterhoeven , Kevin Hilman , Stephen Boyd , linux-arm-msm@vger.kernel.org, Daniel Lezcano , linux-kernel@vger.kernel.org, Lina Iyer , Rob Herring , linux-arm-kernel@lists.infradead.org, Thomas Gleixner , Lina Iyer MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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; }