From patchwork Fri Sep 25 11:27:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1371181 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=tDo/2H8g; 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=Yyf00ms/; 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=iBLlvcjI; 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 4ByV6G3W4dz9sSJ for ; Fri, 25 Sep 2020 21:28:38 +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=EkqxMrmGPjwtVV0+9qW5U2gJGtDi+v/vNkEGf9BeP1c=; b=tDo/2H8geql/udvhpeGtLerwMI 7tpoaDU7TUYiilqxCMR0SigSUMY1Y3c6NVkr5Yq7milfo5S5NzAxsMvwHhypgrYt3Cklb4n9Bi/py bzGXREeC4L3C8FV7NopWeN16QmyU1CUtagEJbwgEEsgMscCoEENVgRKuuro2/zA3+Tnz3O+tN3IHX Ajj0MBr+vwUnZ+DB3s+gOXy/5yTg9QESK0+KW9BaVB6BlcjzO8NpKbjvln84zMnlNMg/ukkMOAh3N nUrR9I172Vw/H6goMIkWfxYqUmWs5b2BaFsI0CFlWgENKFIeGpEjzeGWDX2OKQbhiHXP70CBKfc4p AHkvXWEQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLltw-0003qW-9I; Fri, 25 Sep 2020 11:28:32 +0000 Received: from esa4.hgst.iphmx.com ([216.71.154.42]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kLlts-0003om-F0 for opensbi@lists.infradead.org; Fri, 25 Sep 2020 11:28:30 +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=1601033308; x=1632569308; h=from:to:cc:subject:date:message-id: content-transfer-encoding:mime-version; bh=kgVhYTRm+FlhpIqeP9uLVvMXVGID91/PpgOq20yqXaY=; b=Yyf00ms/pxNJs1sbCN5Dh2bYzW8Gs7pqVAF4KfDx2BBioiu1EuG4SHdi u2SE05yCXLu1SU7XVh7jMMlVJsog6jLZSPYnKg50gV+5l6ipMbqZVgQ0Y o0fG0uD0Wp0DBA41y+x3TpYTI+FXUrlc8lNLRz4Bx3gHhsifc3+8Eyexi llmpklZnaZ0LDw7CaYL4UapDq+z+i+jtNm5esvFkgZ+0XXgkUuDeNY1xN IDkaLo90Zj1dhIVqh+5lVkt5EoK13ebS5rVcCG4pzm2C/uU8+NGXePyB4 kRBNkRWAimh7yZ0mukOgkO0iyaRd3oX2qQd3gwa4aCdHLaI4gkLIbBJ1f Q==; IronPort-SDR: rtA8y6Fj28DquO9aldho1NoNVlVyGNDww5wJ9mgDDIo6rm7COGgMRbcufGYvDL+41fqzzg1Ae8 X9HMin7PSjiJz1eAqLDtHXcmA1X7f6WgfYftdn2QtisY0N5nlY4mIxEhikbgaymV9ZoFBB+xmQ +HLgwOQhAp3rx3vP02HA97pJ3MzKv1CTLS+xxrNDvDEMh9R37LHMmARN7Qbf0vpeWYp6S8cxx5 TtnFVrl7oXLGb0mNh8Hc2Mwmjd1LzFNE7AcVt/UR7GXMxIVZRnwn9WTuCzwedlEZAXUI+6z5t8 a6U= X-IronPort-AV: E=Sophos;i="5.77,301,1596470400"; d="scan'208";a="148192017" Received: from mail-co1nam04lp2059.outbound.protection.outlook.com (HELO NAM04-CO1-obe.outbound.protection.outlook.com) ([104.47.45.59]) by ob1.hgst.iphmx.com with ESMTP; 25 Sep 2020 19:28:25 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nXL+3X8BC2TR5WoYgZ3fMSCm80XW3jtiePSvsVp5GzLkLuMcZxE04k4xoIkIlc9iP4pm8k5AEiZQ99h24Eqk/mkNuUCQUq/zlxosaxncrw+ohhzX57Qu+ItDe7tIf2cxJVgGINs+EUGb4O7+M6iLlGx4MMDI3nmTTuBbeqO0Ioyrs2W4getrIMaLRhJcdd4Holtv5Z1tYw6fnRtzR4KJ3MVmZd8eOz/2jkvOLW7y8Gz4h4kHy6OF40OAS6vw7OWKMpHsgbK1O01KWg6PZM+SQ2u1Us0ThX6FZ0bJXR0khCbCbH04uD2dfjXSYMazz406qknqKXG+LkTvrSchiyhBFg== 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=bnxAL2qgryRhUTiGD7n4XVoiM6aO1PbmZJbalV0fSNw=; b=BPpWdAVOi2sC1RSl/fVWcluzwhRgg1xYOkUWAF8TXQnMdSD3yk1pSUQRzQ+8SBYe+GWkgV+mlDgv8qJZKipDoFmfq4e6lgvn1Yh/GaBuVlhsYSjBaa5+dDiTm6xNGyIGYR10SeRyDswG2OM8hmTxyCfcEdsdpnjDGet3axdRcZWOuMpHtNqCz6jfkisnnFc6I5acNQqJSiFJ0l6cMnocvmjd4vfqmMk7Sq+59Q0RPkHsUCeURzCCHJd78GruyCiknGN4hmZjOMeuJyYKRK/6p69PTCaf3MB43qkEZu5WDVxP47qjwo3WfTJ4QX+EFtzNsuU8uL5n+PqnoyJi8QQuYg== 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=bnxAL2qgryRhUTiGD7n4XVoiM6aO1PbmZJbalV0fSNw=; b=iBLlvcjI3qKtH0sor4qkrsxYVOLrmaGDt27PHwc84PemLEOxBRCURrx8jvssBdSwpMFtEUOoZHZJiWU+avFUBzdHryO4JkgKlBNghnYN6/1G5uf1OSp76BDoXaABFBQbXmMbe2sIuuJQozNHmJ3kzhF6lCUcnHChZO6Wc+IKAYU= 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 DM6PR04MB6778.namprd04.prod.outlook.com (2603:10b6:5:24c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.20; Fri, 25 Sep 2020 11:28:24 +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; Fri, 25 Sep 2020 11:28:23 +0000 From: Anup Patel To: Atish Patra , Alistair Francis Subject: [RFC PATCH] lib: Implement System Reset (SRST) SBI extension Date: Fri, 25 Sep 2020 16:57:54 +0530 Message-Id: <20200925112754.725742-1-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 X-ClientProxiedBy: MA1PR01CA0116.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::32) 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.69.106) by MA1PR01CA0116.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.20 via Frontend Transport; Fri, 25 Sep 2020 11:28:21 +0000 X-Mailer: git-send-email 2.25.1 X-Originating-IP: [122.179.69.106] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e1879ac6-bd19-4c14-6687-08d861461d09 X-MS-TrafficTypeDiagnostic: DM6PR04MB6778: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:901; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5KHbeD6j7v5j+ckpQ4lPVkKC9tx+kePZQjQby2vXqoind/G0we4W7BSZptWb9eMi7Bcyih0SsxUZQ0hfpXgyVoPw/4QsDPE1tJjNm8e8LsRAXFua+BCpnRsFtZH/RSohuQYeViYKPdGCUi486OvRFS8D+RDDrw+47BXvKOhWmE7j7YoxjDtpXHTX9spU+ry651Ksm0y2nlMJF5NJ23KTZy9/jHaKpzyglXGu42OrogheX1ZbawY6yHnS9addBpe4drl3Rn5+kOMivOGF6nDIQSTLMuaLrXjQ7nhPdiqJw23Cfz4ToKnhW0Z0acuSJ2vQM4iToyNKlVvR+OFbgI12juhqNzcECriw8aBMdRd1y6enm1b5YVCPERJpFZplx9f5ZNNhJMxbfAC+XKej1dP0y4g2EeInOjo4PYl6I43D7EdLYwxl0NOEQmfk/R3ZUIA3rLeQSvb0mdqCzG/pGVzBAA== 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)(346002)(136003)(366004)(39860400002)(396003)(376002)(6636002)(6666004)(55016002)(66946007)(86362001)(26005)(1076003)(316002)(4326008)(2616005)(110136005)(44832011)(83380400001)(186003)(956004)(478600001)(966005)(52116002)(7696005)(66476007)(66556008)(16526019)(8886007)(2906002)(5660300002)(8676002)(36756003)(8936002)(54906003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: CQNCmXqZYKJWVRurnkLGRJNmL1MeUXeCozsPdL/xzHIBFNHqr3/Sp+faUaDtgJgO4RI+qMkIRVhkyQZBUOO5oFcOcuztXG4CIe6KpiftqYWoBvNmQecyQX18cq+vRZ1YspYpBZuQzMXXtuE2V9+iiLrxeD32iFpWP34tnhm7NF0i8iWG5OWvYEVzQqZytGGKiRPwKfQu5C+ndua7FEu9WMpNXwzZIGBexfnmMEUezRNi+PhPuHh/pacSNo6F0FuLBYN/j400CGD5bkO3smjpK2SRQpcSFsz8rObEF8hd2AyH2/SYLr06R/pzonR3Dbi7HkjgQlbldHvOUiy4G8Iwg6R6tm84w0XHzdgrXRINdqYFOJp6RxvcldCFd1lMjDIiAN0M3pihnhm2iD5dG7B94zuhjtMzEfVN9UOWx/Y84OlWA+8rNwCY2LOSrK8zqGZAsBjJFc9UitJzAuGMO24XtUsHrrtitXGVBQy4Q8Ylk0QjzKUGuOONTadXgRQjfeZLN+Y7CsvFfgKtv11y85C1cRUx7uri2M20z8VTLsfPw2EO9XA3kOScTH7mmqBpBgp1CBLQFXEdQ20pSEb1te8n3awTmzU8X25tS5QMeO6d0K04FmW1++8/4YnfFJaCdTSrWmC8/P7Bha1/oEDjNhiW7g== X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: e1879ac6-bd19-4c14-6687-08d861461d09 X-MS-Exchange-CrossTenant-AuthSource: DM6PR04MB6201.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Sep 2020 11:28:23.7904 (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: MgrNPoNx1PiwfALrA4Mv7E4BxqrBbJtD6yiTEBK+jqvyCHFBRAQXILcF6o51OV4eay/gVvXjDgRQTOJ2aaNG2g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR04MB6778 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200925_072828_792077_17759641 X-CRM114-Status: GOOD ( 22.19 ) 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.42 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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.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 --- include/sbi/sbi_ecall.h | 1 + include/sbi/sbi_ecall_interface.h | 6 +++++ lib/sbi/objects.mk | 1 + lib/sbi/sbi_ecall.c | 3 +++ lib/sbi/sbi_ecall_srst.c | 44 +++++++++++++++++++++++++++++++ 5 files changed, 55 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..bdc7d96 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,11 @@ #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_SHUTDOWN 0x0 +#define SBI_EXT_SRST_COLD_REBOOT 0x1 +#define SBI_EXT_SRST_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..a1b4bee --- /dev/null +++ b/lib/sbi/sbi_ecall_srst.c @@ -0,0 +1,44 @@ +/* + * 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; + + switch (funcid) { + case SBI_EXT_SRST_SHUTDOWN: + sbi_system_reset(SBI_PLATFORM_RESET_SHUTDOWN); + break; + case SBI_EXT_SRST_COLD_REBOOT: + sbi_system_reset(SBI_PLATFORM_RESET_COLD); + break; + case SBI_EXT_SRST_WARM_REBOOT: + sbi_system_reset(SBI_PLATFORM_RESET_WARM); + break; + default: + ret = SBI_ENOTSUPP; + break; + }; + + return ret; +} + +struct sbi_ecall_extension ecall_srst = { + .extid_start = SBI_EXT_SRST, + .extid_end = SBI_EXT_SRST, + .handle = sbi_ecall_srst_handler, +};