From patchwork Mon Mar 1 11:58:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12109557 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-21.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,MSGID_FROM_MTA_HEADER, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70A17C433E0 for ; Mon, 1 Mar 2021 11:59:27 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DB71E64DBD for ; Mon, 1 Mar 2021 11:59:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB71E64DBD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=j7e5qFnLgamtMVp3L9iYL4kVtQtl0a3vXpyWJK2J64k=; b=dSgpg9N5TPOdxWzRTKOzQwILJ9 8Vp/qZt8Voq2wQnf0upSYswDkuKTDUeGDaPv39THQB1hWwODjM1TMkCm/E5p4UFN/Cpn5I3oMhOUi d9HnK7iN9t0+X3Lhm2bLdw/ih2Aa3Srh6JgVHVXat4W6c+ylMs13f3kWFRxW18sfbn+TuTuZioae3 5cntEisBQHOgjaCEfAWSJt/K4wGqmRQ8ITun0xp0XqPhuKBIbEYjP5IHbnoT8Nmxp+8WJDiUj9Fon PgSRq2HZuYm2SpdzYgl/RTwwam9fQ3eZKWeKA2wQcmHsm9fWUszuQrqFnnX8Hpu7GJGgSoluzOS4P lvvvAhVQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lGhCh-0001un-47; Mon, 01 Mar 2021 11:59:11 +0000 Received: from esa1.hgst.iphmx.com ([68.232.141.245]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lGhCc-0001uF-QT for linux-riscv@lists.infradead.org; Mon, 01 Mar 2021 11:59:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1614599946; x=1646135946; h=from:to:cc:subject:date:message-id: content-transfer-encoding:mime-version; bh=MmOfVbyBMNouM0u0R5TqshV/taZnLCuuS7KZ80fyvsQ=; b=iTwticxrOa8s+dgoEsgAJfKBRTkj+vJAFs3BEASbATSHnHSn+9qllJYN CdU4zv3TF2AFho7A0R8PgyuVzqhid4Dci63brIT7JBmupnoWWpNdL8g0s w8OsdKwKtGiCz9CQ2tSMHc3udksEt1paC7B+4mmw7EEZrApDyhpue8o6q Fu4rfe+qGxCJC+JjDn8FELh7v2CW2zLmqsDI7DHgDgyXIh1ViWaSEDyl/ YukdQp0TinadjuMIYvOf+t7ejQLvDCZsZ8BSxaRB4oZX9EB2wDyyl69jb FIzbgu3Ve/RkP8uUV8yLSP37VPwUZBsX4VFxp0lLyeAVoGgW60NSyavwQ w==; IronPort-SDR: TqZ63/8i48z26AJOWZPWQ4q9dHhj+aNXaZNff7UgImjJArvrJBy0YLxOsu9kdRKYTWJsyUsIhm A/jzdBUXQOMGW7nzm5LUHhyqLPZmZCG3kgKm0biWESpc1p9z+iPvCAZcjiCDwUz6uhA4ikeWbD 72RraVVXzs5B9S31E88hlxnsrXtMOipmm0wXOB7zyVTTHpmvaCUkdyUDFNPSxjXP/aIjRlcbet R8FDeZ79BoI/3+4PaKqzGxU0gHnft3BLR3nF0S00V7SJVgxtAY5RueV6HbMHTurw/7FXf6onBF Rrw= X-IronPort-AV: E=Sophos;i="5.81,215,1610380800"; d="scan'208";a="271656927" Received: from mail-bn7nam10lp2102.outbound.protection.outlook.com (HELO NAM10-BN7-obe.outbound.protection.outlook.com) ([104.47.70.102]) by ob1.hgst.iphmx.com with ESMTP; 01 Mar 2021 19:59:02 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BgIVVUPzEv2EDPkMlvX+WVC2sVdZfrq8aEGDGlOLw+aw0mYgfU2wGf15tzz713KiLlu8ui2B+5ZdqvQZT8aQsiidB3L3IDbWekMz94MHNb5dBL/E1JdYFsXwaBc6IqbxWt24demE5cJ/mk/fYiNRG+kwbgufNdDQW8+Ep7mFekDWXuImlxltM8mn43TgIyWFaPu9ph8GjxcYkhAB10Dk8o6PJMDc9d9u6PLBxUwIZryMGNQZx0f303bJK0Ws2BbIQtZvbG2d8NMgC5VorzMLQzso79IL6enydz0ZOaEjx09XV/D7otRJ1iW79hy8KGiYYD8Oe5MzEVYTu1bSufBi1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iGxkxvvXkkIvji7ApwCtffWmhzeE5KjyCaZYElDEak0=; b=UABiYNowf7tkPshk8nzTKNnNqhinAfCg/n4o8PIKt0MaSo7UzKkqe9SQjhWY0G4m2SdKr09eay3a4MI2Evaixkp967kVrw0SegMHUr09M5s/kf6zBNV0SbDantPsWm2+RyjiTSlmPwGMfHi0eac+4klKLGZwiwQrxj8WbkNmO3E5m2UIa/YBck8xCOzRKyL72dVE8XUUJpE8LqFpBYkX0gjEGuwWIrJV98+4lcc/eeWmj0ejYaPWgudB6dbJiTMykqWVjfoU+0c48AtrgHmQQJ89bdFU7sh5tUwB/y4zo13MY2qixu0nZZvtIuDjG7misbk/Tm8F5KakcbC8KUcXvg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iGxkxvvXkkIvji7ApwCtffWmhzeE5KjyCaZYElDEak0=; b=FULwKc+CwF0wNhUGUbEymSCX1/RZ5DYU20qi9fDqL5QR7gP5YpOvC5r0ZTW196K0HhlGLz6mZSVAaowHW8n/jcW4576ptqajnmQ4EZw5sYhB1Le+FDNFiNpozFWzvUK2fi2g3Qg79N8hUc+p8iKA2mKVUGKgM+YnXBXikv4NapE= Authentication-Results: dabbelt.com; dkim=none (message not signed) header.d=none;dabbelt.com; dmarc=none action=none header.from=wdc.com; Received: from DM6PR04MB6201.namprd04.prod.outlook.com (2603:10b6:5:127::32) by DM6PR04MB5835.namprd04.prod.outlook.com (2603:10b6:5:163::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19; Mon, 1 Mar 2021 11:58:59 +0000 Received: from DM6PR04MB6201.namprd04.prod.outlook.com ([fe80::38c0:cc46:192b:1868]) by DM6PR04MB6201.namprd04.prod.outlook.com ([fe80::38c0:cc46:192b:1868%7]) with mapi id 15.20.3890.028; Mon, 1 Mar 2021 11:58:59 +0000 From: Anup Patel To: Palmer Dabbelt , Palmer Dabbelt , Paul Walmsley , Albert Ou Subject: [PATCH v4] RISC-V: Use SBI SRST extension when available Date: Mon, 1 Mar 2021 17:28:33 +0530 Message-Id: <20210301115833.382364-1-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 X-Originating-IP: [122.171.192.176] X-ClientProxiedBy: MAXPR01CA0079.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:49::21) To DM6PR04MB6201.namprd04.prod.outlook.com (2603:10b6:5:127::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wdc.com (122.171.192.176) by MAXPR01CA0079.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:49::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19 via Frontend Transport; Mon, 1 Mar 2021 11:58:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d34d5cd8-e7c6-4209-bd62-08d8dca965d6 X-MS-TrafficTypeDiagnostic: DM6PR04MB5835: X-MS-Exchange-MinimumUrlDomainAge: github.com#4892 X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:3968; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AuSChSA5aF3l7luwbakoZotNdx16lcRVgf2visLZENmuwQWbbKRZQc3PB7IeRTh57vRNeXl7YyvwxF5lsep9Ot0a8rmfzENj8isW8Ru3C4T9cCnUbkwguHEKBvvCaPI+5YYD1kozmbkEJoUKUudzjXehB+zVAAU7nnuw7oYCk17QsHq36MVPeSK2SqBzXaDxqaUPeb75me6DWPxYtbWuhjNH/qkw7NlnyxK9zb53/zkLiMjC42acYwxc9HNG/oCtHHlvY/ay9HUtEhgQJBpo0nLm+5R/IDit1mpcqjCe4tO5s311jk6mE/9AgwUGXuPg1Hfv01jHj4vO8AsXRxJJLoi8VFGEI0y524pGhNkXm1D3LGqFETHQqcmwt3NoDuWN480ln7LdQffx6ky6cl+xVfl2TiOWDNOKPNZLS2DJdJWbt57IINsJi/9R9DjUkP/OnKnuumR8DbFnf59p4GGirKdjjwNxLAbXcTzlRQr1ti+mR47dSUIIjiCGjlq148VcxLNwCf7xbFmJFbUAu65DfZ9BXst/qlHI9QbELBKm0R45T/Tl9GOVouH7a+fVQab/6V9QYmbN+VHr0FDlXc+nOp+qlt9px8ETVDzQvq8XTuM= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR04MB6201.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(39860400002)(346002)(396003)(136003)(366004)(110136005)(478600001)(8936002)(54906003)(8676002)(5660300002)(316002)(36756003)(52116002)(966005)(83380400001)(26005)(16526019)(86362001)(44832011)(186003)(7696005)(956004)(4326008)(1076003)(55016002)(2616005)(66556008)(6666004)(66946007)(66476007)(2906002)(8886007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: c5wCc/x3rrQbK9/X19ReP6ApZGLIrOceNXzhWgybl/5mPetZ/eah+Nn4zisKb5NUFUq4cjeR5FaXNBLHyIduyoFXMFDO3DhW5XlP6EN6reRAM9C95zPh/If/+YWD9s7z4irgoD4Pu++lvo+6JzHcETjFDMgNaU8j5QrffCRIsYOpaAbsGkMBUVeT3P/j3/yCQCMPnJsPHp7YwE6VhlGMOE707+z7Q5trYb63QI+mD6LQ0iHTk8mFWTeDVIHRzXo0UjelcXPIylWYXoq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rg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: d34d5cd8-e7c6-4209-bd62-08d8dca965d6 X-MS-Exchange-CrossTenant-AuthSource: DM6PR04MB6201.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2021 11:58:59.1079 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: idCp7LXoVPRmtJbbwNU7OL/xSwTV9F0zk9j0a5DtD9x9bJnMNW7yQ2LIzisBejl3qqipmiA7QaKEqSyfXj0y6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR04MB5835 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210301_065907_199853_95F2CB5A X-CRM114-Status: GOOD ( 17.07 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , Anup Patel , linux-kernel@vger.kernel.org, Atish Patra , Alistair Francis , linux-riscv@lists.infradead.org Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The SBI SRST extension provides a standard way to poweroff and reboot the system irrespective to whether Linux RISC-V S-mode is running natively (HS-mode) or inside Guest/VM (VS-mode). The SBI SRST extension is available in latest SBI v0.3-draft specification at: https://github.com/riscv/riscv-sbi-doc. This patch extends Linux RISC-V SBI implementation to detect and use SBI SRST extension. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- arch/riscv/include/asm/sbi.h | 16 ++++++++++++++ arch/riscv/kernel/sbi.c | 41 +++++++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 99895d9c3bdd..8add0209c9c7 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -27,6 +27,7 @@ enum sbi_ext_id { SBI_EXT_IPI = 0x735049, SBI_EXT_RFENCE = 0x52464E43, SBI_EXT_HSM = 0x48534D, + SBI_EXT_SRST = 0x53525354, }; enum sbi_ext_base_fid { @@ -70,6 +71,21 @@ enum sbi_hsm_hart_status { SBI_HSM_HART_STATUS_STOP_PENDING, }; +enum sbi_ext_srst_fid { + SBI_EXT_SRST_RESET = 0, +}; + +enum sbi_srst_reset_type { + SBI_SRST_RESET_TYPE_SHUTDOWN = 0, + SBI_SRST_RESET_TYPE_COLD_REBOOT, + SBI_SRST_RESET_TYPE_WARM_REBOOT, +}; + +enum sbi_srst_reset_reason { + SBI_SRST_RESET_REASON_NONE = 0, + SBI_SRST_RESET_REASON_SYS_FAILURE, +}; + #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 f4a7db3d309e..49155588e56c 100644 --- a/arch/riscv/kernel/sbi.c +++ b/arch/riscv/kernel/sbi.c @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -501,6 +502,32 @@ int sbi_remote_hfence_vvma_asid(const unsigned long *hart_mask, } EXPORT_SYMBOL(sbi_remote_hfence_vvma_asid); +static void sbi_srst_reset(unsigned long type, unsigned long reason) +{ + sbi_ecall(SBI_EXT_SRST, SBI_EXT_SRST_RESET, type, reason, + 0, 0, 0, 0); + pr_warn("%s: type=0x%lx reason=0x%lx failed\n", + __func__, type, reason); +} + +static int sbi_srst_reboot(struct notifier_block *this, + unsigned long mode, void *cmd) +{ + sbi_srst_reset((mode == REBOOT_WARM || mode == REBOOT_SOFT) ? + SBI_SRST_RESET_TYPE_WARM_REBOOT : + SBI_SRST_RESET_TYPE_COLD_REBOOT, + SBI_SRST_RESET_REASON_NONE); + return NOTIFY_DONE; +} + +static struct notifier_block sbi_srst_reboot_nb; + +static void sbi_srst_power_off(void) +{ + sbi_srst_reset(SBI_SRST_RESET_TYPE_SHUTDOWN, + SBI_SRST_RESET_REASON_NONE); +} + /** * sbi_probe_extension() - Check if an SBI extension ID is supported or not. * @extid: The extension ID to be probed. @@ -577,22 +604,30 @@ void __init sbi_init(void) sbi_get_firmware_id(), sbi_get_firmware_version()); if (sbi_probe_extension(SBI_EXT_TIME) > 0) { __sbi_set_timer = __sbi_set_timer_v02; - pr_info("SBI v0.2 TIME extension detected\n"); + pr_info("SBI TIME extension detected\n"); } else { __sbi_set_timer = __sbi_set_timer_v01; } if (sbi_probe_extension(SBI_EXT_IPI) > 0) { __sbi_send_ipi = __sbi_send_ipi_v02; - pr_info("SBI v0.2 IPI extension detected\n"); + pr_info("SBI IPI extension detected\n"); } else { __sbi_send_ipi = __sbi_send_ipi_v01; } if (sbi_probe_extension(SBI_EXT_RFENCE) > 0) { __sbi_rfence = __sbi_rfence_v02; - pr_info("SBI v0.2 RFENCE extension detected\n"); + pr_info("SBI RFENCE extension detected\n"); } else { __sbi_rfence = __sbi_rfence_v01; } + if (sbi_probe_extension(SBI_EXT_SRST) > 0 && + sbi_minor_version() >= 3) { + 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;