Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp4763242rwl; Wed, 28 Dec 2022 08:28:43 -0800 (PST) X-Google-Smtp-Source: AMrXdXsG7AAn2eZkz1KIEtsTn2DndfwrV41jO+b9AesCZcSdTdmNVypFF+prcpdolDLrd9y/sLFY X-Received: by 2002:a17:903:130d:b0:192:6be6:7d2b with SMTP id iy13-20020a170903130d00b001926be67d2bmr17780334plb.33.1672244922948; Wed, 28 Dec 2022 08:28:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672244922; cv=none; d=google.com; s=arc-20160816; b=Nvf9y6n/UlIRdx5W3IJA9qYF0BBCc+oxwDsi8JY/ulrriG56CtIBiSn0G63bUuRALD QvIxmOlyWguFaK7u6leRhljE99NEk5LslcU8pMC84XKCxtpjbwCCdKvtsGqyT//3PP+z MlPwnuulodNgzPXdfKbJLBdLKV3upAJOsernz0pQyDxt7Z5KCcw2CgobL/pV91maGrtw mrUOzp4bMf9QVDwGmeKzIDgi46m59Xp5qxA+/JxMuMyl/Ochltt2fPhbliNkPvOWT2ND vVmeB/KgQ1RfMTs6Re1ALQepx6u1l9WIDgrZor3vgzLMlacuCAC13G35+bytM3IWq/Gx JIfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=tNPPicb71bW2Kkv83J5nMmqaOBqEDoEyAGBVtrD7K44=; b=mbAsbSIx0PywSp46klVUf3RJz3N5akIStD8E5JhKizumfTiu7iCkFljarl9vwDT+dt Y3HisfFnxaVZKLM0pbEB6pHxenak2lbc4BhiwsVQwxuPtbS1gYjeC8sTcPGvS+GHQqFf CAitheEHgBSphTn+ikuWXUw3EKjugg4AATGNYBYpwvNrLcoC7WWNp3eGNEOuCPunJcqx UU2dmIVd7BmY0gOL9JEBkF+NF6KIHgO5lLrqcJ/2yF7FGgJ32kOuGU8jTPLY7ya/oyxC eIpRPWu+MkESd3VOIa+oRfpO7wF3cVwHjqaGoJ727xPXRC8saIDkVX97g0FURclde3VV rBGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sholland.org header.s=fm3 header.b=TbueCSE7; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=MfOiLrfl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sholland.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t70-20020a638149000000b004429ecbda9fsi12401430pgd.39.2022.12.28.08.28.33; Wed, 28 Dec 2022 08:28:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sholland.org header.s=fm3 header.b=TbueCSE7; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=MfOiLrfl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sholland.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234653AbiL1QXM (ORCPT + 63 others); Wed, 28 Dec 2022 11:23:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234590AbiL1QV2 (ORCPT ); Wed, 28 Dec 2022 11:21:28 -0500 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15E3B1A05B for ; Wed, 28 Dec 2022 08:19:24 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 8055B5C016A; Wed, 28 Dec 2022 11:19:23 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Wed, 28 Dec 2022 11:19:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1672244363; x=1672330763; bh=tN PPicb71bW2Kkv83J5nMmqaOBqEDoEyAGBVtrD7K44=; b=TbueCSE7mAQv23DvP8 mOfeGFH9G7YmfvOdXAlRalPfIY3bGsWjSkDSsuf45D5MfOy3vQclW1fA8Sdzq8W9 TWhrkcdUMxTtIMVs77QBREbkEWed3JWmiL+FyTmC3z7NqXbw08QKffLoxctuOFW5 QYZLFmCTTz/PSaPKgf03sq3zZV1ur5hGT0Oju/O8hFPLG1uUxbkT1s/MonzJFtPy bwnC8Mdvko3nMCWThcew6/JnivB8rzr/WLm36HlfIeGpHHLDgMflUbL2kH68hpeH DycAfD06Nu5RPde6eUjq7AEn3xhNXdnEDrQufRl4saGzKrEic5eP+hWJe2eJGHgJ tAwA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1672244363; x=1672330763; bh=tNPPicb71bW2K kv83J5nMmqaOBqEDoEyAGBVtrD7K44=; b=MfOiLrflpldJKncXeb5+CfhFO4VoZ XZE7QF/FtBEaP8SCQkECtHij1BsQMDoZBoP2YkK758J4lCdub9ZLU6eOr/leODO2 MihTCIVx7n7M+k3X/Z9gGMkiTsZiA7YTdBL5fG+8Vd0q3u2bYgBwOELAltvHYY6T wE6nEQ8Ug7IhHqrmGnY6PfeOLbsGzqYwQ+SXIKDdmPngQwWkMMciFGr4VdFl3uX1 nhijrEgL4O6OlaRIIUsYfjzbN57Oc55WZBBR7An1vZrOj3LZbT/Wt9zCCF+u3BK9 eWwVd0fqry43TLsyR84rD6YW2d17gRF8EktbulbeHbSxaFbqPyGvFDCkA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedriedvgdekkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpedukeetueduhedtleetvefguddvvdejhfefudelgfduveeggeehgfdu feeitdevteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 28 Dec 2022 11:19:22 -0500 (EST) From: Samuel Holland To: Palmer Dabbelt , Dmitry Osipenko , "Rafael J . Wysocki" Cc: Samuel Holland , Albert Ou , Anup Patel , Atish Patra , Geert Uytterhoeven , Heiko Stuebner , Kai-Heng Feng , Luis Chamberlain , "Paul E. McKenney" , Paul Walmsley , Petr Mladek , YueHaibing , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, tangmeng Subject: [PATCH 3/3] riscv: sbi: Switch to the sys-off handler API Date: Wed, 28 Dec 2022 10:19:15 -0600 Message-Id: <20221228161915.13194-4-samuel@sholland.org> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20221228161915.13194-1-samuel@sholland.org> References: <20221228161915.13194-1-samuel@sholland.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Any other poweroff handlers registered at the default priority will run before the legacy pm_power_off() function. Register the SBI poweroff handler with the correct priority to ensure it runs first. Signed-off-by: Samuel Holland --- arch/riscv/include/asm/sbi.h | 1 - arch/riscv/kernel/sbi.c | 52 +++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 4ca7fbacff42..2915a3ddf7c6 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -267,7 +267,6 @@ long sbi_get_mvendorid(void); long sbi_get_marchid(void); long sbi_get_mimpid(void); void sbi_set_timer(uint64_t stime_value); -void sbi_shutdown(void); void sbi_clear_ipi(void); int sbi_send_ipi(const struct cpumask *cpu_mask); int sbi_remote_fence_i(const struct cpumask *cpu_mask); diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c index 1196c12299f6..9574851eae6e 100644 --- a/arch/riscv/kernel/sbi.c +++ b/arch/riscv/kernel/sbi.c @@ -7,7 +7,6 @@ #include #include -#include #include #include #include @@ -120,15 +119,16 @@ int sbi_console_getchar(void) EXPORT_SYMBOL(sbi_console_getchar); /** - * sbi_shutdown() - Remove all the harts from executing supervisor code. + * __sbi_shutdown_v01() - Remove all the harts from executing supervisor code. * - * Return: None + * Return: NOTIFY_DONE */ -void sbi_shutdown(void) +static int __sbi_shutdown_v01(struct sys_off_data *data) { sbi_ecall(SBI_EXT_0_1_SHUTDOWN, 0, 0, 0, 0, 0, 0, 0); + + return NOTIFY_DONE; } -EXPORT_SYMBOL(sbi_shutdown); /** * sbi_clear_ipi() - Clear any pending IPIs for the calling hart. @@ -204,11 +204,6 @@ static int __sbi_rfence_v01(int fid, const struct cpumask *cpu_mask, return result; } - -static void sbi_set_power_off(void) -{ - pm_power_off = sbi_shutdown; -} #else static void __sbi_warn_unsupported(const char *extension) { @@ -216,6 +211,13 @@ static void __sbi_warn_unsupported(const char *extension) extension, sbi_major_version(), sbi_minor_version()); } +static int __sbi_shutdown_v01(struct sys_off_data *data) +{ + __sbi_warn_unsupported("Shutdown"); + + return NOTIFY_DONE; +} + static void __sbi_set_timer_v01(uint64_t stime_value) { __sbi_warn_unsupported("Timer"); @@ -236,8 +238,6 @@ static int __sbi_rfence_v01(int fid, const struct cpumask *cpu_mask, return 0; } - -static void sbi_set_power_off(void) {} #endif /* CONFIG_RISCV_SBI_V01 */ static void __sbi_set_timer_v02(uint64_t stime_value) @@ -574,10 +574,12 @@ static int sbi_srst_reboot(struct notifier_block *this, static struct notifier_block sbi_srst_reboot_nb; -static void sbi_srst_power_off(void) +static int sbi_srst_power_off(struct sys_off_data *data) { sbi_srst_reset(SBI_SRST_RESET_TYPE_SHUTDOWN, SBI_SRST_RESET_REASON_NONE); + + return NOTIFY_DONE; } /** @@ -657,7 +659,6 @@ void __init sbi_init(void) { int ret; - sbi_set_power_off(); ret = sbi_get_spec_version(); if (ret > 0) sbi_spec_version = ret; @@ -686,19 +687,26 @@ void __init sbi_init(void) } else { __sbi_rfence = __sbi_rfence_v01; } - if ((sbi_spec_version >= sbi_mk_version(0, 3)) && - (sbi_probe_extension(SBI_EXT_SRST) > 0)) { - pr_info("SBI SRST extension detected\n"); - pm_power_off = sbi_srst_power_off; - sbi_srst_reboot_nb.notifier_call = sbi_srst_reboot; - sbi_srst_reboot_nb.priority = 192; - register_restart_handler(&sbi_srst_reboot_nb); - } } else { __sbi_set_timer = __sbi_set_timer_v01; __sbi_send_ipi = __sbi_send_ipi_v01; __sbi_rfence = __sbi_rfence_v01; } + if ((sbi_spec_version >= sbi_mk_version(0, 3)) && + (sbi_probe_extension(SBI_EXT_SRST) > 0)) { + pr_info("SBI SRST extension detected\n"); + sbi_srst_reboot_nb.notifier_call = sbi_srst_reboot; + sbi_srst_reboot_nb.priority = 192; + register_restart_handler(&sbi_srst_reboot_nb); + register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, + SYS_OFF_PRIO_FIRMWARE, + sbi_srst_power_off, NULL); + } else { + register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, + SYS_OFF_PRIO_FIRMWARE, + __sbi_shutdown_v01, NULL); + } + riscv_set_ipi_ops(&sbi_ipi_ops); } -- 2.37.4