Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 44F47C433F5 for ; Mon, 21 Feb 2022 20:02:38 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D1145830EA; Mon, 21 Feb 2022 21:02:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1645473755; bh=M5WbEcJLhPs8Brlsjn9c+ZM9FnQ33Ezc+1/31emNKdo=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=S4Bisq2QmYvIjF/Q7cKBdhcQ1384lRF55HIJ3Y1Ez5BftfpdE336MnMOyU6A0YvPN TMDnp0QZ9ALyGaGOTUeSKMTP00FZtEsLiz33zwEUWcDOPGf5LD1wwDhDOJ/S0FCOu7 CGMJtvBTkJzKq9kKESlKftqkaNtRXZTh+5GHg3L+VzcgnY18RG3Zoa7SlzTlJxgf1b o7T9qsg3sG7MREcjbRm3ADHSSUJSX52yKJLx5CTBb5uDD8KY0DOc6Cigl8KEMchEp5 AqMjrlqi8IEUcF9RV0eEGXeB4BG6nAYUpI+CFMAytnT42SjDcDifw3xZnx9wSfISp+ 37eG2vz4RD5AA== Received: from [127.0.0.1] (p578adb1c.dip0.t-ipconnect.de [87.138.219.28]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 636DB802DB; Mon, 21 Feb 2022 21:02:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1645473752; bh=M5WbEcJLhPs8Brlsjn9c+ZM9FnQ33Ezc+1/31emNKdo=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=fzVS7c25Iakvs7+n7wnnhmuCnt66NRQWTYBrskgwAuBPz5paHT9kln5TNY3aC+8H+ WCI4j3MpPKHXgMY2N0trHkfdDtY1RRXp0B8rqPZUHugBoRhrj0YBQwTSqO/vCUSaQ1 eBm6f3KVKM/atYU55ovggz/R3fHjbAFjszlb59HxdZxsNKdLVQv+7FYiw4BVZkHzBh lY1GXNU8/CUT13/GRLP8gx78ORL7B5eDN3zT12BOuTWmznfphHjld7zvLlM1myCF9F UxGo3d09QzdHi/YT9tutfnS/y9WCiKH8HsNl0kgyrc7B5+Zos58dnE4YhHi2WgyJdo u/FbZLt5fTSEA== Message-ID: <5a799057-4a80-0dbf-e6f8-d837260a2001@denx.de> Date: Mon, 21 Feb 2022 21:02:31 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.0 Subject: Re: [PATCH] stm32mp: psci: Implement PSCI system suspend and DRAM SSR Content-Language: en-US To: Patrick DELAUNAY , u-boot@lists.denx.de Cc: Patrice Chotard References: <20220202115256.445701-1-marex@denx.de> <69d750db-a5ec-8fdd-f64e-280a2cbbdf8c@foss.st.com> From: Marek Vasut In-Reply-To: <69d750db-a5ec-8fdd-f64e-280a2cbbdf8c@foss.st.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean On 2/10/22 20:20, Patrick DELAUNAY wrote: [...] >> +    writel(RCC_MP_CIFR_WKUPF, STM32_RCC_BASE + RCC_MP_CIFR); >> +    setbits_le32(STM32_RCC_BASE + RCC_MP_CIER, RCC_MP_CIFR_WKUPF); >> + >> +    setbits_le32(STM32_PWR_BASE + PWR_MPUCR, >> +             PWR_MPUCR_CSSF | PWR_MPUCR_CSTDBYDIS | PWR_MPUCR_PDDS); >> + >> +    psci_v7_flush_dcache_all(); >> +    ddr_sr_mode_ssr(); > > => here SSR is forced in DDR self refresh entry, > >       it was normal in TF-A which manage ASR and HSR mode are managed > >       but that seens strange for SPL as only SSR mode is correclty > managed (DDR_PWRCTL = 0x0) > >       previous mode is not restored after in this code The ASR should be restored if it was enabled before, indeed. >       => I think the  ddr_sr_mode_ssr() can be done in DDR driver > >     as it is done in TF-A driver = ./drivers/st/ddr/stm32mp1_ram.c There is no trace of STM32MP1 ASR/SSR/HSR implementation in ATF : $ git grep -i [ash]sr drivers/st/ddr/stm32mp1_ram.c gives no results in a1f02f4f3 ("Merge "docs(changelog): generate changelog" into integration") or 8d9c1b3ca ("Merge changes from topic "st-format-signedness" into integration"). So back to U-Boot ... The secure part has no access to DM structures, so no, it is better to keep all the bits and pieces of the PSCI in one place. It also makes the PSCI code self-contained and easy to understand, as it should be. As for the various modes: - ASR is Automatic SR, that's handled by the controller automatically even at runtime, and it is enabled in separate patch (ram: stm32mp1: Unconditionally enable ASR) - SSR is Software SR, that's what's implemented here and that's where the system software puts the DRAM into SR - HSR is Hardware SR, what exactly is this useful for ? It seems ASR is recommended for runtime power saving and SSR for suspend power saving. So what is HSR for ? > static int stm32mp1_ddr_setup(void) > { > > ..... > > >     /* >      * Initialization sequence has configured DDR registers with settings. >      * The Self Refresh (SR) mode corresponding to these settings has now >      * to be set. >      */ >     ddr_set_sr_mode(ddr_read_sr_mode()); > >  ..... > > } > > => same can be done at the end of  DDr driver in SPL: > >      drivers/ram/stm32mp1/stm32mp1_ddr.c::stm32mp1_ddr_init() > > > void stm32mp1_ddr_init(struct ddr_info *priv, >                const struct stm32mp1_ddr_config *config) > { > > .... > /* 12. set back registers in step 8 to the orginal values if desidered */ >     stm32mp1_refresh_restore(priv->ctl, config->c_reg.rfshctl3, >                  config->c_reg.pwrctl); > > +   /* Force the Self Refresh (SR) mode = SSR for SPL, HSR or ASR are > not supported */ > > +   ddr_sr_mode_ssr(); > >     /* enable uMCTL2 AXI port 0 and 1 */ > ..... > > } > > > Then the call of ddr_sr_mode_ssr() can be removed here. > > > see also ./drivers/clk/clk_stm32mp1.c::stm32mp1_clktree() > > => Software Self-Refresh mode (SSR) during DDR initilialization SSR does cut off DRAM access, ASR does not, I think you have those two confused, no ? You can enable ASR in the DDR driver (see ram: stm32mp1: Unconditionally enable ASR), but you must only enable/disable SSR on entry/exit from CStop, i.e. here in this PSCI callback. >> +    ddr_sw_self_refresh_in(); >> +    setbits_le32(STM32_PWR_BASE + PWR_CR3, PWR_CR3_DDRSREN); >> +    writel(0x3, STM32_RCC_BASE + RCC_MP_SREQSETR); >> + >> +    /* Zzz, enter stop mode */ >> +    asm volatile( >> +        "wfi\n" >> +        "isb\n" >> +        "dsb\n"); > > are you sure of the instruction order ? > >     in TF-A, stm32_pwr_down_wfi_load() => the order is dsb / isb / wfi > > and you can be replaced by ARM function = arch/arm/include/asm/system.h This function also does not exist in either source, sorry. >     /* >      * Synchronize on memory accesses and instruction flow before the WFI >      * instruction. >      */ >     dsb(); >     isb(); >     wfi(); I think it does make more sense to do ISB/DSB before the WFI, yes. >> + >> +    writel(0x3, STM32_RCC_BASE + RCC_MP_SREQCLRR); >> +    ddr_sw_self_refresh_exit(); >> + >> +    writel(SYSCFG_CMPCR_MPUEN, STM32_SYSCFG_BASE + SYSCFG_CMPENSETR); >> +    clrbits_le32(STM32_SYSCFG_BASE + SYSCFG_CMPCR, >> SYSCFG_CMPCR_SW_CTRL); >> +} > > > I also need to test this patch on ST boards... I will send V2 soon.