From nobody Fri Dec 19 04:33:02 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDB76C001DE for ; Thu, 20 Jul 2023 00:25:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229771AbjGTAZ3 (ORCPT ); Wed, 19 Jul 2023 20:25:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbjGTAZ1 (ORCPT ); Wed, 19 Jul 2023 20:25:27 -0400 Received: from out203-205-221-155.mail.qq.com (out203-205-221-155.mail.qq.com [203.205.221.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE261123 for ; Wed, 19 Jul 2023 17:25:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1689812723; bh=XDRuLIHkJfQQZemCigyLqfDZFz49CdHiP3pF+50Mh4Y=; h=From:To:Cc:Subject:Date; b=aM3mQ7HIau0bNNDGHkZNJ5A+inNsISE5aAmm2BmBcRyl5iLUB8tT4QUKJyyZCm1fV 9uhd8MKDJ4Cts5mYUWjV0M6F6mMJX6RnyEwmcApK/BLVfYvR833b0m4e5ecTbxswZJ BdJ9AzK8RvS28IikHuBrYac9L+YcwYmF0hamScBA= Received: from localhost ([101.224.148.235]) by newxmesmtplogicsvrszc2-0.qq.com (NewEsmtp) with SMTP id 5FB3E47E; Thu, 20 Jul 2023 08:23:59 +0800 X-QQ-mid: xmsmtpt1689812639tblmroxam Message-ID: X-QQ-XMAILINFO: OZZSS56D9fAjyoRLlB1WdJIvKEZ+uXLTVV6mobk6OIzYcsk9NcixTRI+09csj6 A6Yso/kzi3FrJfhROjQ3VF/tdNNQJf0/gMKVus8ZxYR3irBaDnNyINv8rziCQUriDNs3t38ZC31z G9ovwpjDqNp9cp2eR/EeE3zEVziqloAzv3z4bSsh4aprnUjOWJpFFcG4qC/P21cRNX1P+ZiKx+m1 IlxhI2lJc20BuZKnUm6/wFDQnfNhFrH6Aq1RfJQJGMSmH+/5/C9DJVtU61l9xKRlmHvJ0FTvVqyJ ek1ciGmIHfgINhAM2puKYK2ayzTy0QnRVdl3tGMnGp1JXL+hisra5Bh/OAux8w9sK6lEURusk52M rzqtUisrZOIXwqzyjeHXh6V3wJ4IhhAzwQbqoZoFcsNt/WBYECzzOcGGRJF8hjT/GDT6GFCkj3SR +zV71ZPMwBRZdmOLDJq14Ry4Kvh00/Fv1H8bN3eduUH0sEUGaDCKB4xbumOLti8An1OrqyXTi1vf YL/b/4OeSOO1Ri+TCnl6QqgkllPIPYktfM6BVUBVgvw2xyWxeJzyvVdrN0aK682CqWmI0Qj8vvVf alemCeYCVuUbETBDLwCOhv2JYvr5eIEgPIRv8ZR5Hfz733fY01jrKxbWQ7gn0eFjV7KRdzgKOtxI M/yFOeUaX9CRKoeM7OLhZi6VxKsXkrBUPOwYcqqUxmysg+edwrTLmAGI6ZwcsZAMfGzbSmHQrjAk KsVl7BRsxTrfx6oxAT/zOzQxGp1ZtHjuPcxjN49Wiv4xkMIY8ZvqCvQu9zGMyZ/VkBD+cucoJn4N Uc81tG0T473Y13dDXyZWGTqKI0iU3JZnEJ4UExl9GcScjhvVArdnsPx7r2kPcERauwfTqm2zgxyK taoEiAfO1PMlrSd8cqMtbgRbKzJJrK4FYVwzxaiLejsrKiHW7EjxKGofgZI+tz/XeY2lYCeRgqFw rVSG/V7eFueGunGRujUJoaDcPr+bP+qbSm2MEWMexLG77UC1uC9g== X-QQ-XMRINFO: NS+P29fieYNw95Bth2bWPxk= From: Woody Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: Conor Dooley , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Woody Zhang Subject: [PATCH] riscv: add SBI SUSP extension support Date: Thu, 20 Jul 2023 08:23:19 +0800 X-OQ-MSGID: <20230720002318.2543822-1-woodylab@foxmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" RISC-V SBI spec 2.0 [1] introduces System Suspend Extension which can be used to suspend the platform via SBI firmware. This patch can be tested on Qemu with recent OpenSBI with `system-suspend-test` enabled like [2] in DTB. [1] https://github.com/riscv-non-isa/riscv-sbi-doc/blob/master/riscv-sbi.ad= oc [2] https://github.com/woodyzhang666/qemu/commit/e4a5120133c1dc354e6ac437ec= 1f870f6c0f6d05 Signed-off-by: Woody Zhang --- arch/riscv/include/asm/sbi.h | 10 ++++++++++ arch/riscv/kernel/sbi.c | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 5b4a1bf5f439..3b04016da671 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -30,6 +30,7 @@ enum sbi_ext_id { SBI_EXT_HSM =3D 0x48534D, SBI_EXT_SRST =3D 0x53525354, SBI_EXT_PMU =3D 0x504D55, + SBI_EXT_SUSP =3D 0x53555350, =20 /* Experimentals extensions must lie within this range */ SBI_EXT_EXPERIMENTAL_START =3D 0x08000000, @@ -236,6 +237,15 @@ enum sbi_pmu_ctr_type { /* Flags defined for counter stop function */ #define SBI_PMU_STOP_FLAG_RESET (1 << 0) =20 +enum sbi_ext_susp_fid { + SBI_EXT_SUSP_SYSTEM_SUSPEND =3D 0, +}; + +/* SBI suspend sleep types */ +enum sbi_susp_sleep_type { + SBI_SUSP_SLEEP_TYPE_SUSPEND =3D 0x0, +}; + #define SBI_SPEC_VERSION_DEFAULT 0x1 #define SBI_SPEC_VERSION_MAJOR_SHIFT 24 #define SBI_SPEC_VERSION_MAJOR_MASK 0x7f diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c index c672c8ba9a2a..9a68959f9f18 100644 --- a/arch/riscv/kernel/sbi.c +++ b/arch/riscv/kernel/sbi.c @@ -9,8 +9,10 @@ #include #include #include +#include #include #include +#include =20 /* default SBI version is 0.1 */ unsigned long sbi_spec_version __ro_after_init =3D SBI_SPEC_VERSION_DEFAUL= T; @@ -520,6 +522,26 @@ static void sbi_srst_power_off(void) SBI_SRST_RESET_REASON_NONE); } =20 +static int sbi_system_suspend(unsigned long arg, + unsigned long resume_entry, unsigned long context) +{ + struct sbiret ret =3D {0}; + + ret =3D sbi_ecall(SBI_EXT_SUSP, SBI_EXT_SUSP_SYSTEM_SUSPEND, + SBI_SUSP_SLEEP_TYPE_SUSPEND, resume_entry, context, 0, 0, 0); + return ret.error; +} + +static int sbi_system_suspend_enter(suspend_state_t state) +{ + return cpu_suspend(0, sbi_system_suspend); +} + +static const struct platform_suspend_ops sbi_suspend_ops =3D { + .valid =3D suspend_valid_only_mem, + .enter =3D sbi_system_suspend_enter, +}; + /** * sbi_probe_extension() - Check if an SBI extension ID is supported or no= t. * @extid: The extension ID to be probed. @@ -624,6 +646,10 @@ void __init sbi_init(void) sbi_srst_reboot_nb.priority =3D 192; register_restart_handler(&sbi_srst_reboot_nb); } + if (sbi_probe_extension(SBI_EXT_SUSP)) { + pr_info("SBI SUSP extension detected\n"); + suspend_set_ops(&sbi_suspend_ops); + } } else { __sbi_set_timer =3D __sbi_set_timer_v01; __sbi_send_ipi =3D __sbi_send_ipi_v01; --=20 2.39.2