Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp956628lqh; Fri, 29 Mar 2024 02:30:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUIOYiqYuzG4ZvHMPZviQOE3nOwv/CrpP3hkkPyEIg06WyZ5XFJLDY583vHcV3gvwryBw6ZFY0wtX6SHtV8xcS6LakcSU1yLUBm4Xscew== X-Google-Smtp-Source: AGHT+IEQ/DeNv3MNFy05o/9e39g8aQWjfImcU7FGjbV+9yJnzVnJnqm6x627R1Y+Dd44/LlExple X-Received: by 2002:a05:6a00:230c:b0:6ea:c501:b264 with SMTP id h12-20020a056a00230c00b006eac501b264mr1742061pfh.18.1711704629121; Fri, 29 Mar 2024 02:30:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711704629; cv=pass; d=google.com; s=arc-20160816; b=J+XRBpMuWAhgYTHxv809JDqG9URLBdAlw9/bYZhN50meQbM6akr4reJJuW9mtXmnsd 9BWyVpdS/ogVzw5ye8u7O5zRgGe/gH9CPf4EKBZ53Cubm32XKLc7ppmyqu1wluepxkAF HDuqbv8n1A7ZwVvuhk/cKwT2JnV9ZUec9KQKa+pAOMKs6f+dBL8bSD+pGTtfZcbUt0s0 ab3QHFop+QnecYUYhgHqDI0LHHV9/6tVfzBWAEd1qKDu9lKJyx16aBS1oiSzDUJU6u1/ 83hmi3tHuBg3EUYowbRVBciheOdUdQU/ai3CEU2YUjSJ+o/q2ZHJIa6Oa0cNqAJx/b/X ctFg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=W2BJOQ9wxa5k0Z60PWQjy0KWSd8OFBHkeE+vEvJtEEk=; fh=ZJ9PeAcRW54Z4kv2ak0qF6CY0PknFWNsEGEH46J3jVc=; b=XNu/epde6QNs3oHexBviXCmod18PdFc6voDHPSDo96aRd4K5Oiwx7d2z6VK4Ndwusy bHHE7JQ5sXd7k9A5BvE8rsguPGkDXxA6Eb64b/GleAGtOu0jcGLYza1m8yW6T5oChA8s 9UxhyV8mSPVsTi1+Upgpn5IynIUlys/TjeWkGiHM+9qfYQdzV884Sgi1b6q6fEmhS2FV 4QpDe0el90x+nqloE/3/Qr3s5spgimk5TKgcjyOK4iXS6TbNxe+P/i54kVPDMnKcdwpu vNXCocoy0bXzXnsa3RTgIPrXd/4AEgbPmUTRBHEhWk3v3ZPXpOzn1WN8p/Ym59mkep6g 5U9Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=iL5W1W8H; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-124338-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124338-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d20-20020a056a00199400b006eae6e1252fsi1301634pfl.234.2024.03.29.02.30.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 02:30:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124338-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=iL5W1W8H; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-124338-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124338-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C5C38285A3E for ; Fri, 29 Mar 2024 09:30:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B0D1D69E0D; Fri, 29 Mar 2024 09:28:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="iL5W1W8H" Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E80F69DEE for ; Fri, 29 Mar 2024 09:28:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711704485; cv=none; b=b/5kCG1kflxEBXsjy1zdTZoYXrwZvgrbevBgS67HA7SJYH6aaMZvPxi+7kxeP3dY7T061pdIUJd4EKkfnPWJxt7YP84S11iZRvVcdHI4CgRtkop3pGtV836eGB3zmobhG/t8hFv2QzDBHUR0+pBJ/SQI5J4jxXJ1R3wda9hETHY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711704485; c=relaxed/simple; bh=CV2JPbXziG2CSHm4cLDaE9gjUQ7JZv4SP9wDAVQhAuk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SHfAL6R0uiBuW8kGErAHHmjflXkkdFB0ArUrOEWSIGN3O+v//mE9H5nIhuCOQIwf040o5MX+oUIShYAzYAO4qUjoNb8SnhLkh75jhyh5EZ6t3G2vv4vT+OlAeM3YH3rlgXRoON/i0XoIPK34iWJr6NFXi6uRJ34XQqfZjxVHmmk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=iL5W1W8H; arc=none smtp.client-ip=209.85.210.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-6e6fb9a494aso1580565b3a.0 for ; Fri, 29 Mar 2024 02:28:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711704482; x=1712309282; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=W2BJOQ9wxa5k0Z60PWQjy0KWSd8OFBHkeE+vEvJtEEk=; b=iL5W1W8HpY43VjvnsAI/T5ubmyHaDFyhfwCn57dVpP3KsB+wrajKxQcvQu57nPaCTl Cuvdx/UTbJOi1AP5K1mly0Euj8cs29yYogB+ZN7zfxAuPH7cA8rp4AFY7PSAlhP/9coK IIzzzCIe09J2K2ttTc1qfBhTgF8QSyc2wo5YodyHv28EEt/IWyx7SE0Fl5TsF1IamAKT D8t20Zr7U0+g4xg7FoVhKO9UCSqI5Ndcj/uLafNogFMaYN+FrO6CVXPBg9pai2tLw76h FbuW1mbHK/7cq5507pkpKAOEUhgu7nofzn6oxg8s9PpErUVhxZJESRwGsQU0vRqlGMVs LU9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711704482; x=1712309282; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W2BJOQ9wxa5k0Z60PWQjy0KWSd8OFBHkeE+vEvJtEEk=; b=fkw+OOIuMwNFiG9ShzSCoOnj/lFThKlkM1SmfkADb6fKh5v0upTU5Qo3XJSsRQaoMa wdgA2/PAjqFebODmmc48zOQdWVaYCeI5MuIvsL5HCrF8xonMV9AYdRCJ6DCg1JjqF+vy K19fJD4cSCRnIJAH+kl5BKrTFk3PuRdLwu3K6Nr+38Chi9DzG1pGFgKK8wvlcIFYqF3/ yEbON1OselJ+s2uyj8g7IxToZ1CZPnWaz42zjHGE6hIBREba/bQASPOTSUvDU0nMyTlp c57cVIQvNcQNPiPNBGY6WpZ9NYFvbQ4Wcd3eAgTnrhCdSZieej+AgDwCWQD90c6SCpRq t3GQ== X-Forwarded-Encrypted: i=1; AJvYcCVUg3teHXdbG2//x7w1kUJ2gZ/Z4H4zbeTUAgZaWFW6nlwucU9Xw/fqKZbkcEi7mtJ0+rz5zHMmkhyp92g4PEiavdst/2EZKk5LyelN X-Gm-Message-State: AOJu0YyZNN2q++rz9AkuAD8sVRXu4f0UCd5NQyJW1wtrtXfblk4ANGHS dAvjGki/VFmsK132EJdqW/Ra6fcVcXZXBnirNRb1FMurRcVwa/mtFXrRPurPQZM= X-Received: by 2002:a05:6a20:89a4:b0:1a3:ae18:f1e4 with SMTP id h36-20020a056a2089a400b001a3ae18f1e4mr1227195pzg.34.1711704481705; Fri, 29 Mar 2024 02:28:01 -0700 (PDT) Received: from [127.0.1.1] (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id cv17-20020a17090afd1100b002a02f8d350fsm2628830pjb.53.2024.03.29.02.27.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 02:28:01 -0700 (PDT) From: Max Hsu Date: Fri, 29 Mar 2024 17:26:22 +0800 Subject: [PATCH RFC 06/11] riscv: suspend: add Smstateen CSRs save/restore Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240329-dev-maxh-lin-452-6-9-v1-6-1534f93b94a7@sifive.com> References: <20240329-dev-maxh-lin-452-6-9-v1-0-1534f93b94a7@sifive.com> In-Reply-To: <20240329-dev-maxh-lin-452-6-9-v1-0-1534f93b94a7@sifive.com> To: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , "Rafael J. Wysocki" , Pavel Machek , Anup Patel , Atish Patra , Paolo Bonzini , Shuah Khan Cc: Palmer Dabbelt , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, Max Hsu X-Mailer: b4 0.13.0 From Smstateen extension: the values of the [h/s]stateen CSRs will be lost when entering a non-retentive idle state. Therefore, these CSRs values need to be restored to ensure that the corresponding functionality remains enabled. Signed-off-by: Max Hsu --- arch/riscv/include/asm/suspend.h | 6 ++++++ arch/riscv/kernel/suspend.c | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/arch/riscv/include/asm/suspend.h b/arch/riscv/include/asm/suspend.h index 4718096fa5e3..2ecace073869 100644 --- a/arch/riscv/include/asm/suspend.h +++ b/arch/riscv/include/asm/suspend.h @@ -17,6 +17,12 @@ struct suspend_context { unsigned long envcfg; unsigned long tvec; unsigned long ie; +#if __riscv_xlen < 64 + unsigned long hstateen0h; +#endif + unsigned long hstateen0; + unsigned long sstateen0; + #ifdef CONFIG_MMU unsigned long satp; #endif diff --git a/arch/riscv/kernel/suspend.c b/arch/riscv/kernel/suspend.c index 8a327b485b90..a086da222872 100644 --- a/arch/riscv/kernel/suspend.c +++ b/arch/riscv/kernel/suspend.c @@ -19,6 +19,15 @@ void suspend_save_csrs(struct suspend_context *context) context->envcfg = csr_read(CSR_ENVCFG); context->tvec = csr_read(CSR_TVEC); context->ie = csr_read(CSR_IE); + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SMSTATEEN)) { + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_h)) { +#if __riscv_xlen < 64 + context->hstateen0h = csr_read(CSR_HSTATEEN0H); +#endif + context->hstateen0 = csr_read(CSR_HSTATEEN0); + } + context->sstateen0 = csr_read(CSR_SSTATEEN0); + } /* * No need to save/restore IP CSR (i.e. MIP or SIP) because: @@ -42,6 +51,15 @@ void suspend_restore_csrs(struct suspend_context *context) csr_write(CSR_ENVCFG, context->envcfg); csr_write(CSR_TVEC, context->tvec); csr_write(CSR_IE, context->ie); + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_SMSTATEEN)) { + if (riscv_has_extension_unlikely(RISCV_ISA_EXT_h)) { +#if __riscv_xlen < 64 + csr_write(CSR_HSTATEEN0H, context->hstateen0h); +#endif + csr_write(CSR_HSTATEEN0, context->hstateen0); + } + csr_write(CSR_SSTATEEN0, context->sstateen0); + } #ifdef CONFIG_MMU csr_write(CSR_SATP, context->satp); -- 2.43.2