From patchwork Wed Dec 28 16:19:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13083039 X-Patchwork-Delegate: palmer@dabbelt.com 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 43EE5C4167B for ; Wed, 28 Dec 2022 16:19:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7Ra54IbvBQbpe76W8IyJw3SwqKR/qmViShu5Dfwi3HQ=; b=kLAZkzLdNc7Scy +LaYQaBCVXOm6Vu4PRHszljJM8qD517o2JD+jzApjg4Xy4Aw7kJUT2ngG+le7XDrOentMCbBjxcIU mpbVle5jvopx0WwBhUveGTFSuf5/Qx8AiVq1kvjaZg76CXCBJ4yLQEXtoJX7jd9gVebFOGfEpj16Z zsirJWWpvsZGWh6OW6ogKzsHLvUzc6tpCekkYjY4VAfi0mu0Dw76810pcK3iFA6uetTB6NUv/sK/C 9VAjvJNCBxWfF2DeFgERFHX3cdfzHg9eXZu2+QAby10OW3YCM4RmRGWzDC3VgczI6MhaX4GsMygaV goA1soF4eiZyX5I796wQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pAZ9W-006J1z-L9; Wed, 28 Dec 2022 16:19:38 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pAZ9I-006Iog-6o for linux-riscv@lists.infradead.org; Wed, 28 Dec 2022 16:19:27 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 85F6D5C018E; Wed, 28 Dec 2022 11:19:20 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 28 Dec 2022 11:19:20 -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=1672244360; x=1672330760; bh=+U 8N0UmTlYd9YC+LHaZbBbMVD4CfYomec3Duaw8K1K0=; b=zr7fbQXW2nEGBaEc4T INBtGnH6KEP1UgaieU+aZQgiU7aex0jvJZ0hgkFNPQgPnGSGz+BS0aRbXoHxRiT4 6H4yZd4xNTWGevCjZAZI6VU1kZpJdCpqYl2w4409kmFiqPGz8BM/SxKDmUQTqcaJ yVoXJyocG2vIcB8uwuobV8E/tHIkFFDkFQSW+IPlb90zDVUquNiGSUUFeDesMf9B 2YzihJ/Q6yBVKk6oJD+U/89eg4X/mQLNYxsUPf5sZAhBIYcCcojHxGxJuQD6JJPU qLuT6uOM6fSzkL+B021ISwz3y/ey4FRgx/EKS2uiaC009Pqo6zgH0JgQUpyogB4U 3Q8A== 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=1672244360; x=1672330760; bh=+U8N0UmTlYd9Y C+LHaZbBbMVD4CfYomec3Duaw8K1K0=; b=LHKENN4HaAl9eTzGJzlvlQQpxNiLw iL6iM4q8xbb93azfif+ouJbTwpUljNqJKRjm4A/vC8brr0ZuAxt8ShwIWx82v+zq IyZ7s9L+YoBix7xe3GSigT0lOs/kN+nSuN4Xl9ElTA4MQco4MtwjwbrzRHlfxaIk PH5BgqZP8fWpQ0AhynLvv6xEV5bm7A7ON7moOTSnAMFF9bSX721CQdBwMS55TmU4 Ya04Rq8J3mCLr3I4znNAahnK+TXBMqKIQprlphidStUGpfop7F8fkulJUY9fKEoQ NBNlM1qDxAr4Q6tv1/mU3No71LrlJHkF3AKsZceWe9ptexc5zc5n98NDw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedriedvgdeklecutefuodetggdotefrodftvf 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:19 -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 1/3] kernel/reboot: Use the static sys-off handler for any priority Date: Wed, 28 Dec 2022 10:19:13 -0600 Message-Id: <20221228161915.13194-2-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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221228_081924_444772_23DB3784 X-CRM114-Status: GOOD ( 13.91 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org commit 587b9bfe0668 ("kernel/reboot: Use static handler for register_platform_power_off()") addded a statically-allocated handler so register_sys_off_handler() could be called before the slab allocator is available. That behavior was limited to the SYS_OFF_PRIO_PLATFORM priority. However, it is also required for handlers such as PSCI on ARM and SBI on RISC-V, which should be registered at SYS_OFF_PRIO_FIRMWARE. Currently, this call stack crashes: start_kernel() setup_arch() psci_dt_init() psci_0_2_init() register_sys_off_handler() kmem_cache_alloc() Generalize the code to use the statically-allocated handler for the first registration, regardless of priority. Check .sys_off_cb for conflicts instead of .cb_data; some callbacks (e.g. firmware drivers) do not need any per-instance data, so .cb_data could be NULL. Reviewed-by: Dmitry Osipenko Signed-off-by: Samuel Holland --- kernel/reboot.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/kernel/reboot.c b/kernel/reboot.c index 3bba88c7ffc6..38c18d4f0a36 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -327,7 +327,7 @@ static int sys_off_notify(struct notifier_block *nb, return handler->sys_off_cb(&data); } -static struct sys_off_handler platform_sys_off_handler; +static struct sys_off_handler early_sys_off_handler; static struct sys_off_handler *alloc_sys_off_handler(int priority) { @@ -338,10 +338,8 @@ static struct sys_off_handler *alloc_sys_off_handler(int priority) * Platforms like m68k can't allocate sys_off handler dynamically * at the early boot time because memory allocator isn't available yet. */ - if (priority == SYS_OFF_PRIO_PLATFORM) { - handler = &platform_sys_off_handler; - if (handler->cb_data) - return ERR_PTR(-EBUSY); + if (!early_sys_off_handler.sys_off_cb) { + handler = &early_sys_off_handler; } else { if (system_state > SYSTEM_RUNNING) flags = GFP_ATOMIC; @@ -358,7 +356,7 @@ static struct sys_off_handler *alloc_sys_off_handler(int priority) static void free_sys_off_handler(struct sys_off_handler *handler) { - if (handler == &platform_sys_off_handler) + if (handler == &early_sys_off_handler) memset(handler, 0, sizeof(*handler)); else kfree(handler); From patchwork Wed Dec 28 16:19:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13083037 X-Patchwork-Delegate: palmer@dabbelt.com 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 60506C4167B for ; Wed, 28 Dec 2022 16:19:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YjXdI26v8I2XXWgfnW3bNc/Fo+1IhQ4B8yl4A9QGDFg=; b=EXnl2sMt9YCZXR 6cQpe+zrg1oNuvldANDsIxugmJy2430K255d//9UIU1NoFhHPK6yXVbhLGXadueQArDlpTvDCtFkR F44M1ZLxv/F/sbKBYOM/owlIfZqsrKmceKUYN6S02C3T+C2pE7XYYtijuP8+fWpACliAU5C3pLNij Og1CDFcfSgT0jy2ApU7n5QT/wah3X2pqrUm0qIp1LpaCYF2Fskhi/3CxsBi8UIDlYFelmoMcxghwK 6nXGWkw+hA9PgeMp23D8c476o/DZ4AoFd305SWJE5w+gPlE9NC+SK7tehTiT1hVTNZISFo0ZSPOTG LP8/Cg6TZr365dbO7d4A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pAZ9M-006Iv3-C1; Wed, 28 Dec 2022 16:19:28 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pAZ9I-006IpV-6l for linux-riscv@lists.infradead.org; Wed, 28 Dec 2022 16:19:25 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id EBBFE5C018A; Wed, 28 Dec 2022 11:19:21 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 28 Dec 2022 11:19:21 -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=1672244361; x=1672330761; bh=ES stYnp5wyCE49c6/wy64Qn4j/wTNxpyUZDW8WgeRUg=; b=KGPw76T8n9MIoY9Oog 5UaC3+g6MNNikDTuxkQ4OAuqigX6iTB3WI4R4Sk2uXqOKSqCGlnxKQAoO1BjwqNN he8M+zq2JjzvpS0ot0vIfuvCpwG2LzU7uB5W8xpL5Gctu51tYHgkXEdtA1QzOKQm OiNjf2Aqz3+GAccv3ggUvuItBTG3r47dxR+6HRJfaTWKtmGIq6TEQrQUGiY8BJdx 3Uj6zgyEF4ONDf6EdlUW4BoUD/VKO2pPNzpVdupP6TgL0pBdkX7AnOD9YdwmKsjM MGcqjK9iCpxA+QzbzBKp+ZkcuytmmHnQ3CHL2vTKf/2zaC+gAAmgPcj16asE1nTx daPg== 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=1672244361; x=1672330761; bh=ESstYnp5wyCE4 9c6/wy64Qn4j/wTNxpyUZDW8WgeRUg=; b=HmXYANKpWMSa6HeXX9i9y1m493z9A HUeDYwPYYbRqMVqN5vrsMkn7f03KMMc0/NRYQKzIKuXx2tFPFTczPkvCgP2CMBWN Rj3bZDhT/zn6JnqMW1OR2HeQh0NTLMBxcUEreyZsXOseWS/srZGbIpOEV9xXm9K4 /rE7uvzfg33XRbit+JUF3L8kYDN163hqwxuVvFDIcxnu1Td3c6bw843Am2khLZMY Rf30Bb7vk7KFGFdn/KqFW1fKjV0qfP9lehYVcFXpd9YxMLmbP+6Xl2yTgIFxWCKS mZcdr2antmAc6VhECZkiCn9bVphwwgtX9UmCWfQMStTYm0Um+IbNf9dKg== 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:20 -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 2/3] riscv: sbi: Share the code for unsupported extension warnings Date: Wed, 28 Dec 2022 10:19:14 -0600 Message-Id: <20221228161915.13194-3-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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221228_081924_360026_8C651BA6 X-CRM114-Status: UNSURE ( 9.85 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org This reduces the code size by sharing most of the code and the format string across all affected extensions. Signed-off-by: Samuel Holland Reviewed-by: Geert Uytterhoeven --- arch/riscv/kernel/sbi.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c index 5c87db8fdff2..1196c12299f6 100644 --- a/arch/riscv/kernel/sbi.c +++ b/arch/riscv/kernel/sbi.c @@ -210,16 +210,20 @@ static void sbi_set_power_off(void) pm_power_off = sbi_shutdown; } #else +static void __sbi_warn_unsupported(const char *extension) +{ + pr_warn("%s extension is not available in SBI v%lu.%lu\n", + extension, sbi_major_version(), sbi_minor_version()); +} + static void __sbi_set_timer_v01(uint64_t stime_value) { - pr_warn("Timer extension is not available in SBI v%lu.%lu\n", - sbi_major_version(), sbi_minor_version()); + __sbi_warn_unsupported("Timer"); } static int __sbi_send_ipi_v01(const struct cpumask *cpu_mask) { - pr_warn("IPI extension is not available in SBI v%lu.%lu\n", - sbi_major_version(), sbi_minor_version()); + __sbi_warn_unsupported("IPI"); return 0; } @@ -228,8 +232,7 @@ static int __sbi_rfence_v01(int fid, const struct cpumask *cpu_mask, unsigned long start, unsigned long size, unsigned long arg4, unsigned long arg5) { - pr_warn("remote fence extension is not available in SBI v%lu.%lu\n", - sbi_major_version(), sbi_minor_version()); + __sbi_warn_unsupported("Remote fence"); return 0; } From patchwork Wed Dec 28 16:19:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13083040 X-Patchwork-Delegate: palmer@dabbelt.com 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 33800C4167B for ; Wed, 28 Dec 2022 16:19:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/PnufoeMAReyM66dr8/krY9exVl9NoCPJaHipqCAwQ4=; b=bKS6o8Xr+BiGJ7 QMTFf6IxPeM9k19vwS/zZt2gi0Ycu6WRhR3DnJQxCn78TtQ0FOVbOGkvaACueFP6fI/lUIhK8yFhF wQql83e004zZX/nsdZkeHn+HC5fLXjprfjHqdAigI1rbDN+++GsV/uCQiGpTeHfJLgO/DzIuLbDNq 1l8Ae5ynUwBz+ItYvSDl3gY7oDK8yKfGzV1YRzHQy9iiPDw9SDnHHaL0QiU3X4A7rnd3x1W5lU85L M7V5zuZfgBF/AieJbQQwvWiRNANFwDNVYaW+D4hhXKeXaK5rSd/OPPt+f4jU4zBQ9GWfYNTOKQKqe sgNjL1g4garUxtR2DnkQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pAZ9Y-006J3a-Qn; Wed, 28 Dec 2022 16:19:40 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pAZ9I-006Iqc-6m for linux-riscv@lists.infradead.org; Wed, 28 Dec 2022 16:19:27 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221228_081924_416133_EB74AFFC X-CRM114-Status: GOOD ( 14.13 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.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); }