From patchwork Sat Sep 26 06:53:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1371707 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=DCMbcGMG; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=qKOQdew3; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=jIPG/rvL; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Byzyr20Nbz9sRf for ; Sat, 26 Sep 2020 16:53:56 +1000 (AEST) 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=imQ8kyYq9N8kriRgqj+KylyI4hRvneyQ2BO4PieJN9k=; b=DCMbcGMGyXcnnoolyMlGhOYkMl LIpLTEsPqIffE9FXwzooB74SbHBOkzjF8nRKlX8VCVtvSBga8aw/q2Ldrw05U8D30GzukTFU7Or2V 7CBkVUw8Me4iNFIlaslNvMMnRAjEafq1wjphooJ30hDUmFPvJRohgMwPcnL7aYQpak5UTHUbVz0PZ RqF30K0NsiiGNhN8hqCkjAmO91fJuYkBwybtSLvy0MLuVQHkF4ym2POMl48fZITxlOKh1+ugRMPpa HcmQ96/XDvr9ICu8sZXXLkTDP0dgFdkkCt7xZihTHTTNF9WbS7qmHL5/V9j1mcqAoTMEUo6AABg9i 5KsS/QPA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kM45f-0005x7-4b; Sat, 26 Sep 2020 06:53:51 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kM45d-0005wS-0L for opensbi@lists.infradead.org; Sat, 26 Sep 2020 06:53:50 +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=1601103229; x=1632639229; h=from:to:cc:subject:date:message-id: content-transfer-encoding:mime-version; bh=dBOXjN0MgSDZ+JGVH2VVyJGwJhPJkjgneQsBwLr1M/A=; b=qKOQdew3rI7j+iFYS0h9jXnUoF91WLx/+HPISN2Uv/D9srLDmbW37Cnn q92MGPo9IY7WjNMAt0jpke1xI6D8Pn8YFA/AtF1Bb++iQI1t6iWq261Db Ls3WFUAtR8Da8P70NKyKkXUsE8cDjjxNUOFJPKStXUI40LaJo5JSwT+Gv xxSx55s2NWj0/fzkLBvBUmZO95goqgXzVSJoKm8WKl5Wzg/JMgn56i672 hOjIlbxgCa7EAGlpdwYuUS/jtra3Uvq0rxwPUsCmPczSaAQbf4+RxrFZx UaEj/FZsGJNFtkRFkuiUHUBaeic+46HRMwOKeZwPFuzkZ+1acIjJBybxJ A==; IronPort-SDR: qOCObMQm/BtW5Mw/GvbGE0LOHdijcJfbpRVT17SIT+h+AlArkYLK0/JYn0pVxYCNXOmobVOBuU x9910LPamhrSGw6fnFIyTAdEyYX/ykcK/2K9wLX80OhDW5QLYppQh3Hw9AW3nWo8q7ONEH5Aqg J0UFNqQ8wRA95abfkzCv8b4roAk7kvk/K/Dn7fcGNxGapc30uhiFsN9YEhVO2nVElCRlgPYuVs LZR4450qhcBL/FQWOlvzMI34NWbjSZmdQStkcRYje1jGFNrA4CWXYBbOpToIQBlbuPZIdOJ/+u Cag= X-IronPort-AV: E=Sophos;i="5.77,305,1596470400"; d="scan'208";a="149551695" Received: from mail-dm6nam12lp2174.outbound.protection.outlook.com (HELO NAM12-DM6-obe.outbound.protection.outlook.com) ([104.47.59.174]) by ob1.hgst.iphmx.com with ESMTP; 26 Sep 2020 14:53:48 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IMjFUYu5OECpOcxLV15cfxwsv1i+YI1umAYluRX2UadcLIYdvo5BjPByDtozLBDATLQQ3QoLVCDEHsHGmw5aWAP7Qy1bZdg/oES0ySCcKukWM8iWHzOl1m2NOevpbpf6fXqIZwI11vPwYObkT3WlMPXjB0RfLDNpFaYo4VKqAYUo3GG8kDI+eKooeuskbMu6Kzc9qfLspVUMHJSwJ0I6rSNQ31bXIjMUTqOobbB7yDQOuX3yCNbqeBDhzVjUNXL8hK8IvDseLQB/YHjhkNo8UMbdf/gUuZX3dhUxazHiUChfDbRxLzSg5hkjG3F9tPFsIDeUPge9kSuCDbBbCePYyg== 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=g2jnhs7ov5pckA7pc0gGQNwga8iQNbBVwv+GglakFP4=; b=L+zxGp/T4bGvne1MXsNDa0hReD2TsX6bmO2qR2ohbgPO7nYQonyiBr9elghENfDSQsdgW1ZuDngJmYDgHWnGpDGMantkYhob/0YJI1e5mlMfuri3k20aUwj6O96t1RarEU9QhM2xGMOeCW4fOT87ajCeUNb4mYzcHc2PaUjcw4OoV46KYERyseqK6U4kDjiWs1ix6KnW4lcoRG7JTO5jgh+oz8LD+2wxPCiX8NBVimxzh9/V2GOABz4MxRdFrpFk8HJ5nJXZPkFRTuwoU+0cj+2d3Zjq5U7lx2QJ7w4bP+adi2yZjQqOS5bTRBeIo4yomrr57CxDDurbwJEqT73c3w== 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=g2jnhs7ov5pckA7pc0gGQNwga8iQNbBVwv+GglakFP4=; b=jIPG/rvLh1LFYfqLtUwfURlTaeOp+GizyOQq5bKgoQd7omeeb6pvZXDkk1KNUhr3S+QddHKQ4lWXoTZVXbx/c06aD9/1C0VJDlk8sVhQxjg7bPYOINiokxnvoOnX5yyaOlhOMEgQAOIGo2MFFhRP6DkmdS0HYW3ilwVJbpCt9FM= Authentication-Results: wdc.com; dkim=none (message not signed) header.d=none;wdc.com; dmarc=none action=none header.from=wdc.com; Received: from DM6PR04MB6201.namprd04.prod.outlook.com (2603:10b6:5:127::32) by DM6PR04MB6493.namprd04.prod.outlook.com (2603:10b6:5:1bf::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.23; Sat, 26 Sep 2020 06:53:47 +0000 Received: from DM6PR04MB6201.namprd04.prod.outlook.com ([fe80::607a:44ed:1477:83e]) by DM6PR04MB6201.namprd04.prod.outlook.com ([fe80::607a:44ed:1477:83e%7]) with mapi id 15.20.3391.020; Sat, 26 Sep 2020 06:53:47 +0000 From: Anup Patel To: Atish Patra , Alistair Francis Subject: [RFC PATCH v2] lib: Implement System Reset (SRST) SBI extension Date: Sat, 26 Sep 2020 12:23:21 +0530 Message-Id: <20200926065321.807213-1-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 X-ClientProxiedBy: MA1PR0101CA0072.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:20::34) 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.179.126.16) by MA1PR0101CA0072.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:20::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.20 via Frontend Transport; Sat, 26 Sep 2020 06:53:41 +0000 X-Mailer: git-send-email 2.25.1 X-Originating-IP: [122.179.126.16] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b9b2f2a9-871f-4e2a-5ee3-08d861e8e8ec X-MS-TrafficTypeDiagnostic: DM6PR04MB6493: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:1360; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yq6H/ywRKezqZi5Y5I6nOOZcKK3ylhdsHL+k77E3AI9CZ6F3JW45ixajQQh7WitsyDcJG8LBKIiYC07ZyhOcVGbB/RDDyqPqbgKZVo9biRObwWNWeJMB6Oud7w2W1qpSaI34ZbLV3RQNIRbkEKo3fWWDamSTcKK2GOdOG4JnqwmcHg3pSgdnU9WGrMl74hqHm+NeYcWv4m8c1P7q2SMP4recV7l8Jk3NeTCaTVS3Nylj9TOtJvsmAbHN+zpakfFJDGg7xlbZHEG7L2+e1JJyzyjOkIstQOZJDy6jIXQjDf4HRJ7azfiuX2AVkcLx9dP+iddmfBUQ36BITv6EaHrnzCw1RsrYMPzfNsgp1uGF7uZNLGyNvkKAWXVZkEHliM2GyyGWE7bJpKXcVUrHkpdDcCWflBKHrmK+HNzg1v9bLixOmeQjY31MUdpPpSjC8TuL40RYXQcO90RztXhIpub00w== 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)(366004)(39860400002)(346002)(376002)(136003)(396003)(8886007)(186003)(5660300002)(6636002)(16526019)(1076003)(66556008)(66476007)(44832011)(2906002)(26005)(966005)(4326008)(86362001)(66946007)(2616005)(956004)(8676002)(83380400001)(36756003)(6666004)(110136005)(316002)(8936002)(478600001)(7696005)(52116002)(54906003)(55016002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: sbAVtpQjjSsXE48/a3ExGkWz+TIRGn4CMLos42vnPFHFGJ4GnLcSCu1p1ig0SH/9kYjJg/sUi0UorPdtnoifi+e1lOlIpoyH2yxF4cq8dUWhawJjLVqFTF+YVcwqBVX/NRNQmQJMVme76EETD7Vw7vcFuW6kA0uijCMxRIS9ujpVurk3jFlaXFih7br4pr2TG51ig+LUj2q+JrGDGoHEELfDxg/7MNq82zASeSsB9khTi1TrSj/OitTC0akLWJcPuiMFWp76rnmL/AtGBnhhBbZqtsF5ZI5d+5UUIZBkygl/a4+0MP6ALl1umBRptnB8AWKXdQW/zoMGYCbCIasciQsmE5E/fo8st/tIRUpBDuQxNVCv73tfNxSwWdwBqDaUbUynj436LQm6wxuvgrRH9cCJIJfFn0mIMrAb3MqYFrM9gbsOruym8pHqzopFGs1SmpqfWuqcSQ5zbXGcDjGhrVWNNv47HOZ6KCoQ/owPvQvBLvzR4+JJ8OSgIfldsJ5f6tOX6ma9jK1Zy2BdjhwV0cYGbDkgfh1NM3A0b3AtXOe8sc1P50loQNSYNljjt6aI9tdw3RiJQvBCUW4ROJvxQ+RMWvKPiR6FggWFWXEl4hF7yAd3MPXFy8EPl5OLg8ZhtrT6yYZAQ8nRASERcOxasg== X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9b2f2a9-871f-4e2a-5ee3-08d861e8e8ec X-MS-Exchange-CrossTenant-AuthSource: DM6PR04MB6201.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Sep 2020 06:53:47.2715 (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: kS6LPk35pXBmB00qevbAv2Muw3YwVOTcrYBHljeZfITwzDabbchvECHKbZ8Ew0pslzsFV7uPKslL//gy/fPwBQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR04MB6493 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200926_025349_179036_AF5704EE X-CRM114-Status: GOOD ( 24.41 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.45 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 MSGID_FROM_MTA_HEADER Message-Id was added by a relay X-BeenThere: opensbi@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 , opensbi@lists.infradead.org Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The SBI SRST extension specification is in draft state and available in srbt_v1 branch of: https://github.com/avpatel/riscv-sbi-doc. It allows to S-mode software to request system shutdown, cold reboot, and warm reboot. This patch provides implementation of SBI SRST extension. Signed-off-by: Anup Patel --- Changes since v1: - Updated patch as-per latest SBI SRST extension draft spec where we have only one SBI call with "reset_type" parameter --- include/sbi/sbi_ecall.h | 1 + include/sbi/sbi_ecall_interface.h | 8 ++++++ lib/sbi/objects.mk | 1 + lib/sbi/sbi_ecall.c | 3 ++ lib/sbi/sbi_ecall_srst.c | 48 +++++++++++++++++++++++++++++++ 5 files changed, 61 insertions(+) create mode 100644 lib/sbi/sbi_ecall_srst.c diff --git a/include/sbi/sbi_ecall.h b/include/sbi/sbi_ecall.h index 3273ba6..1ef86e2 100644 --- a/include/sbi/sbi_ecall.h +++ b/include/sbi/sbi_ecall.h @@ -37,6 +37,7 @@ extern struct sbi_ecall_extension ecall_rfence; extern struct sbi_ecall_extension ecall_ipi; extern struct sbi_ecall_extension ecall_vendor; extern struct sbi_ecall_extension ecall_hsm; +extern struct sbi_ecall_extension ecall_srst; u16 sbi_ecall_version_major(void); diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h index af30500..d9c2519 100644 --- a/include/sbi/sbi_ecall_interface.h +++ b/include/sbi/sbi_ecall_interface.h @@ -27,6 +27,7 @@ #define SBI_EXT_IPI 0x735049 #define SBI_EXT_RFENCE 0x52464E43 #define SBI_EXT_HSM 0x48534D +#define SBI_EXT_SRST 0x53525354 /* SBI function IDs for BASE extension*/ #define SBI_EXT_BASE_GET_SPEC_VERSION 0x0 @@ -62,6 +63,13 @@ #define SBI_HSM_HART_STATUS_START_PENDING 0x2 #define SBI_HSM_HART_STATUS_STOP_PENDING 0x3 +/* SBI function IDs for SRST extension */ +#define SBI_EXT_SRST_RESET 0x0 + +#define SBI_SRST_RESET_TYPE_SHUTDOWN 0x0 +#define SBI_SRST_RESET_TYPE_COLD_REBOOT 0x1 +#define SBI_SRST_RESET_TYPE_WARM_REBOOT 0x2 + #define SBI_SPEC_VERSION_MAJOR_OFFSET 24 #define SBI_SPEC_VERSION_MAJOR_MASK 0x7f #define SBI_SPEC_VERSION_MINOR_MASK 0xffffff diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk index fa808a0..6ec1154 100644 --- a/lib/sbi/objects.mk +++ b/lib/sbi/objects.mk @@ -20,6 +20,7 @@ libsbi-objs-y += sbi_ecall_base.o libsbi-objs-y += sbi_ecall_hsm.o libsbi-objs-y += sbi_ecall_legacy.o libsbi-objs-y += sbi_ecall_replace.o +libsbi-objs-y += sbi_ecall_srst.o libsbi-objs-y += sbi_ecall_vendor.o libsbi-objs-y += sbi_emulate_csr.o libsbi-objs-y += sbi_fifo.o diff --git a/lib/sbi/sbi_ecall.c b/lib/sbi/sbi_ecall.c index 64c9933..6d41cff 100644 --- a/lib/sbi/sbi_ecall.c +++ b/lib/sbi/sbi_ecall.c @@ -167,6 +167,9 @@ int sbi_ecall_init(void) if (ret) return ret; ret = sbi_ecall_register_extension(&ecall_hsm); + if (ret) + return ret; + ret = sbi_ecall_register_extension(&ecall_srst); if (ret) return ret; ret = sbi_ecall_register_extension(&ecall_legacy); diff --git a/lib/sbi/sbi_ecall_srst.c b/lib/sbi/sbi_ecall_srst.c new file mode 100644 index 0000000..64c228f --- /dev/null +++ b/lib/sbi/sbi_ecall_srst.c @@ -0,0 +1,48 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2020 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel + */ + +#include +#include +#include +#include +#include + +static int sbi_ecall_srst_handler(unsigned long extid, unsigned long funcid, + unsigned long *args, unsigned long *out_val, + struct sbi_trap_info *out_trap) +{ + int ret = 0; + + if (funcid == SBI_EXT_SRST_RESET) { + switch (args[0]) { + case SBI_SRST_RESET_TYPE_SHUTDOWN: + sbi_system_reset(SBI_PLATFORM_RESET_SHUTDOWN); + break; + case SBI_SRST_RESET_TYPE_COLD_REBOOT: + sbi_system_reset(SBI_PLATFORM_RESET_COLD); + break; + case SBI_SRST_RESET_TYPE_WARM_REBOOT: + sbi_system_reset(SBI_PLATFORM_RESET_WARM); + break; + default: + ret = SBI_EINVAL; + break; + }; + } else { + ret = SBI_ENOTSUPP; + } + + return ret; +} + +struct sbi_ecall_extension ecall_srst = { + .extid_start = SBI_EXT_SRST, + .extid_end = SBI_EXT_SRST, + .handle = sbi_ecall_srst_handler, +};