From patchwork Sun Mar 3 17:12:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 10837189 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E7DD014DE for ; Sun, 3 Mar 2019 18:10:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D487729BA7 for ; Sun, 3 Mar 2019 18:10:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C528F29BB0; Sun, 3 Mar 2019 18:10:57 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham 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 3054B29BA7 for ; Sun, 3 Mar 2019 18:10:57 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=LmHBasSi9YET2EX15rSRr/6CEDqfFgjNNLI6kGolkg0=; b=bAIRjMBQfCqv1Y MAEhTsmrTEPPQVt8aj/quD9JnyPAP42ptnA62qLwPK4RiEqQ716OkmynMgoZR1300mRHo2aYfAHwy WYgflJ2BgBQgk+npyJExs/Y5+ofQqip2nSPmfsjX3RBud07U/IhiQYXATHFYTEAQlmty3071isPHF 0KMZry/ok23jju5ouVofU6voscsSsYC380IwgDJGhF/29ouDNP9EjQLL/tzpFKheViod0W20JMGbO ShPNwKhpmW2X2w1/RltQXdLSqjOM95KnbDJ4w2C2E0Fmw3is8NxrwZgq8a+JeMDMOu7PaMMnCiCLL ZpDTYS5w4SgSv4oYhP7A==; 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 1h0VZc-00015O-GX; Sun, 03 Mar 2019 18:10:52 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0VZV-0000yG-Vo for linux-arm-kernel@bombadil.infradead.org; Sun, 03 Mar 2019 18:10:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=S/ZyEhorrdTBL7u6Ya1Op9P6A1v1DuFjJTJQoxPu4VY=; b=XglI4BCxHEu0DEMGujMeeQS1Vk 9Ofvlox7fWEizOvTByTpiq8rNmAcBREfu75p/ZQeIKKQ4VjkyJfWKX9EHQrnpF7wDwpcPbGx6PNHl 1W3kQZCn+CkBHuZiEv+3GZTuG8z7TB1B5k4Y1+ppQ0Q+B+YIHk7w9x3zpMgTQpg1UZdYcuq5GrSyl 4jmmfcBjDVoH9z1Fe4Hu7t8+xwOnAqsOurl+gkO+1Lzwzm1c8t+5YZ7o78o7AFN1/YEzr/3bsRz79 fOvpxOalyUo59PIIjR3bn1xGZtMT9YhVCw6t3Br5GASV8IXG5V/epSoi/FQ2C1xcHmXeUNmiuMuUA pdiarufQ==; Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h0Ugn-0007df-RY for linux-arm-kernel@lists.infradead.org; Sun, 03 Mar 2019 17:14:15 +0000 Received: by mail-pg1-x544.google.com with SMTP id k11so365704pgb.8 for ; Sun, 03 Mar 2019 09:14:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S/ZyEhorrdTBL7u6Ya1Op9P6A1v1DuFjJTJQoxPu4VY=; b=s8ZuZV2/I3zwZe/kEfY/j0eXq+/h3U63yAwipL4Q2dB5hrlOhAw1eXik/Ldl2LGqUN Hi7aUatMPx7iUaTBQ/MrX89hc3L5gxmLnm3lPIIQLz4ZCjwRWzxQqlJdHyD3TJwskRTI iHe+S2oP/xYlQeJwEiOapE6gnOSrP1XMp/404RAePQS8UKUDIjrY5xOMGDkFGWtE1kvF L2jpV24u81Z/1ETwSq402YHgAbSyYArH4RiLOYB9qNmZdyJ/5AD/CmLZ4i95IImsE22J KuwIsC4qbrL4CLC1yhPiHV+vkhN2q7v1nHzoY/7Mi+PGz8dhL69vSKhatyeSMb7lDPfo 7Z1g== 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=S/ZyEhorrdTBL7u6Ya1Op9P6A1v1DuFjJTJQoxPu4VY=; b=ulxHvkgNk+8SslXvIb6cjAVA5vVMs7XpzMUWbj3N/Tc0Ozik44E75cM+kBxy91beig 5DV33EmS4gpXvkPlI71XYu12DqQp02Ggc+46cBd1uloUNuX+n+Vw5LepSLDSCUQMvcxd CjIEhu8STX5OToEFcZEJs5XRgcOoYGo/kdspT7dwdLeWSIcOG0+BcYhohOCXOwdWtkKr 6kPqWOHTcFPBjmNHH4d7mHlqES7ptWLLWeXXp7VHtRhFf6n+mu+zq0vn9Yx3YOnmoJ1a V9xrsGFzAImxm6sAHhUKippyd7hq0AoGe9/wACoPNi7w9+ldoKZB9DTJXVfQFkjTJviW 8yUQ== X-Gm-Message-State: APjAAAVPVAM0IRJY9DpEPxYKDGX8FV5jD3P2B0MRsdYjibwDOEu/lZW9 ETXE+2Q6LlRG/dL5vsm5334= X-Google-Smtp-Source: APXvYqxfLsmRAPRznfkOu8fnFfnK/wUWohnVxn/0K8ORSBztGGzCLcypK9JtpiFfz6FPWuVpZFC/aw== X-Received: by 2002:a63:d49:: with SMTP id 9mr14576916pgn.27.1551633250262; Sun, 03 Mar 2019 09:14:10 -0800 (PST) Received: from localhost.localdomain (ppp91-79-175-49.pppoe.mtu-net.ru. [91.79.175.49]) by smtp.gmail.com with ESMTPSA id e22sm5349412pfi.126.2019.03.03.09.14.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Mar 2019 09:14:09 -0800 (PST) From: Dmitry Osipenko To: Russell King , Thierry Reding , Jonathan Hunter , Robert Yang , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= Subject: [PATCH v9 7/7] ARM: tegra: Add firmware calls required for suspend-resume on Tegra30 Date: Sun, 3 Mar 2019 20:12:14 +0300 Message-Id: <20190303171214.24821-8-digetx@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190303171214.24821-1-digetx@gmail.com> References: <20190303171214.24821-1-digetx@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190303_121413_932172_8D37B14F X-CRM114-Status: GOOD ( 20.27 ) 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: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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 In order to suspend-resume CPU with Trusted Foundations firmware being present on Tegra30, the LP1/LP2 boot vectors and CPU caches need to be set up using the firmware calls and then suspend code shall avoid re-disabling parts that were disabled by the firmware. Tested-by: Robert Yang Tested-by: Michał Mirosław Signed-off-by: Dmitry Osipenko --- arch/arm/mach-tegra/pm.c | 49 +++++++++++++++++++++++++++++ arch/arm/mach-tegra/reset-handler.S | 26 +++++++++++++++ arch/arm/mach-tegra/sleep.S | 14 ++++++--- 3 files changed, 84 insertions(+), 5 deletions(-) diff --git a/arch/arm/mach-tegra/pm.c b/arch/arm/mach-tegra/pm.c index 1ad5719779b0..abf5f88778f4 100644 --- a/arch/arm/mach-tegra/pm.c +++ b/arch/arm/mach-tegra/pm.c @@ -33,11 +33,13 @@ #include #include +#include #include #include #include #include #include +#include #include "iomap.h" #include "pm.h" @@ -159,6 +161,28 @@ int tegra_cpu_do_idle(void) static int tegra_sleep_cpu(unsigned long v2p) { + /* + * L2 cache disabling using kernel API only allowed when all + * secondary CPU's are offline. Cache have to be disabled with + * MMU-on if cache maintenance is done via Trusted Foundations + * firmware. Note that CPUIDLE won't ever enter powergate on Tegra30 + * if any of secondary CPU's is online and this is the LP2-idle + * code-path only for Tegra20/30. + */ + if (trusted_foundations_registered()) + outer_disable(); + + /* + * Note that besides of setting up CPU reset vector this firmware + * call may also do the following, depending on the FW version: + * 1) Disable L2. But this doesn't matter since we already + * disabled the L2. + * 2) Disable D-cache. This need to be taken into account in + * particular by the tegra_disable_clean_inv_dcache() which + * shall avoid the re-disable. + */ + call_firmware_op(prepare_idle, TF_PM_MODE_LP2); + setup_mm_for_reboot(); tegra_sleep_cpu_finish(v2p); @@ -197,6 +221,14 @@ void tegra_idle_lp2_last(void) cpu_suspend(PHYS_OFFSET - PAGE_OFFSET, &tegra_sleep_cpu); + /* + * Resume L2 cache if it wasn't re-enabled early during resume, + * which is the case for Tegra30 that has to re-enable the cache + * via firmware call. In other cases cache is already enabled and + * hence re-enabling is a no-op. This is always a no-op on Tegra114+. + */ + outer_resume(); + restore_cpu_complex(); cpu_cluster_pm_exit(); } @@ -215,6 +247,15 @@ enum tegra_suspend_mode tegra_pm_validate_suspend_mode( static int tegra_sleep_core(unsigned long v2p) { + /* + * Cache have to be disabled with MMU-on if cache maintenance is done + * via Trusted Foundations firmware. This is a no-op on Tegra114+. + */ + if (trusted_foundations_registered()) + outer_disable(); + + call_firmware_op(prepare_idle, TF_PM_MODE_LP1); + setup_mm_for_reboot(); tegra_sleep_core_finish(v2p); @@ -342,6 +383,14 @@ static int tegra_suspend_enter(suspend_state_t state) cpu_suspend(PHYS_OFFSET - PAGE_OFFSET, tegra_sleep_func); + /* + * Resume L2 cache if it wasn't re-enabled early during resume, + * which is the case for Tegra30 that has to re-enable the cache + * via firmware call. In other cases cache is already enabled and + * hence re-enabling is a no-op. + */ + outer_resume(); + switch (mode) { case TEGRA_SUSPEND_LP1: tegra_suspend_exit_lp1(); diff --git a/arch/arm/mach-tegra/reset-handler.S b/arch/arm/mach-tegra/reset-handler.S index 31fb53f9ce13..cd94d7c41fc0 100644 --- a/arch/arm/mach-tegra/reset-handler.S +++ b/arch/arm/mach-tegra/reset-handler.S @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -76,6 +77,7 @@ ENTRY(tegra_resume) orr r1, r1, #1 str r1, [r0] #endif + bl tegra_resume_trusted_foundations #ifdef CONFIG_CACHE_L2X0 /* L2 cache resume & re-enable */ @@ -88,6 +90,30 @@ end_ca9_scu_l2_resume: b cpu_resume ENDPROC(tegra_resume) + +/* + * tegra_resume_trusted_foundations + * + * Trusted Foundations firmware initialization. + * + * Doesn't return if firmware presents. + * Corrupted registers: r1, r2 + */ +ENTRY(tegra_resume_trusted_foundations) + /* Check whether Trusted Foundations firmware presents. */ + mov32 r2, TEGRA_IRAM_BASE + TEGRA_IRAM_RESET_HANDLER_OFFSET + ldr r1, =__tegra_cpu_reset_handler_data_offset + \ + RESET_DATA(TF_PRESENT) + ldr r1, [r2, r1] + cmp r1, #0 + reteq lr + + .arch_extension sec + /* First call after suspend wakes firmware. No arguments required. */ + smc #0 + + b cpu_resume +ENDPROC(tegra_resume_trusted_foundations) #endif .align L1_CACHE_SHIFT diff --git a/arch/arm/mach-tegra/sleep.S b/arch/arm/mach-tegra/sleep.S index 5e3496753df1..1735ded5a812 100644 --- a/arch/arm/mach-tegra/sleep.S +++ b/arch/arm/mach-tegra/sleep.S @@ -49,8 +49,9 @@ ENTRY(tegra_disable_clean_inv_dcache) /* Disable the D-cache */ mrc p15, 0, r2, c1, c0, 0 + tst r2, #CR_C @ see tegra_sleep_cpu() bic r2, r2, #CR_C - mcr p15, 0, r2, c1, c0, 0 + mcrne p15, 0, r2, c1, c0, 0 isb /* Flush the D-cache */ @@ -132,10 +133,13 @@ ENTRY(tegra_shut_off_mmu) #ifdef CONFIG_CACHE_L2X0 /* Disable L2 cache */ check_cpu_part_num 0xc09, r9, r10 - movweq r2, #:lower16:(TEGRA_ARM_PERIF_BASE + 0x3000) - movteq r2, #:upper16:(TEGRA_ARM_PERIF_BASE + 0x3000) - moveq r3, #0 - streq r3, [r2, #L2X0_CTRL] + retne r0 + + mov32 r2, TEGRA_ARM_PERIF_BASE + 0x3000 + ldr r3, [r2, #L2X0_CTRL] + tst r3, #L2X0_CTRL_EN @ see tegra_sleep_cpu() + mov r3, #0 + strne r3, [r2, #L2X0_CTRL] #endif ret r0 ENDPROC(tegra_shut_off_mmu)