From patchwork Thu Apr 22 11:20:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1469169 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:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) 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=desiato.20200630 header.b=mM6IKxr4; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=BG0JXN0j; 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=mw4zwAXZ; dkim=neutral header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=xxIDWuhO; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (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 4FQw3S5dpHz9sWD for ; Thu, 22 Apr 2021 21:21:24 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=cOgBqTW63c4lAbc5c91J74KsppAXJK142DkT5FdCFkw=; b=mM6IKxr4JptC5nZV87CSne+Xp aHuwLJ+/oEmy4XuY6/l0CNpSeypmUalfHrLqL0FcEg0AOfo2GOXERvzKjNqqIySLNKjXgPZdaZ1LP YcJV2jTkFrT8IIPT3VSGrzHqvCMDNu9FbB67OSXYtb9Ala7OqbY6QFUjLtxgVWnKX1p3oILtwxlNk t0xEIKhDx3Y2oPKw1UJwaZs1+G3Ew+kgn6sjskpywq/yYUbaPXgkw5yI93E57VuwB3u6jB3E650pv GhK6BdLkqFhF9mB71zd9dllENtVe8eym2Kg2FtHdDU+fyvvwBg1KFxjY2aqaBeH5OtZX2SImMeN92 U2VQpZaPg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZXOa-00GZqh-5b; Thu, 22 Apr 2021 11:21:20 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZXOV-00GZpa-EZ for opensbi@desiato.infradead.org; Thu, 22 Apr 2021 11:21:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=5GNRN69NdXf1/A2HhQF4tz4TV8wByJF5kZpk+/FugMg=; b=BG0JXN0jwjtGut+/hDwgGCCZ3s CxxRXkd4+m0s35H5guLBpV3LECOf7hMr6K8t6ETTP7F/UCH7RhCrvL/JQ4bWQTTtRBn0/JFcjFQwk f/xvwzqiX3nsCuJxcJeIWtVmMI8Dd+JRKQzJvfM907nn607iUon1YfHQ+OYxvSP1JMQupDLxRmsEW N3Vq6/dmrqzMmqISEfXppQS/V2KbLhu/x9+/OYIuxlvlMvH+7iN909jwHm8R0okSfLe5I0nFLGUqO Mpu8rdBxUg/PEppXzoS4tPgvDU2CiNUgi8mn5EspYb4IrH4BDqef/wjp6AkXuPbY+xGstyHMMzHOM PZxlxJ2w==; Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZXOQ-00Dbyb-GA for opensbi@lists.infradead.org; Thu, 22 Apr 2021 11:21:14 +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=1619090470; x=1650626470; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=3R7gteFlKVaizOBPLhQmvKSOVTLoCFO6sHqAuIXxbSw=; b=mw4zwAXZWN7ejESU8900BA17S17eqIZx1SKZUgmtplcDiZvJ2YHNUBnD gVJGRz1D5FZeTz2Q6T51OzpWPWdrYd0hkLgLN/EmDRpYyzgGubd/PT3Jp CjMDXiZQ2YDSx4IXqR3vaT7qti7Ap8h0MrON8SBQKNFdOdgwKGy0qJ3kG vZDn0t45QX90GBVkBInn0mlMKTfVRMz77yWP5RGsU+Klo6yybEksvrk3s o63ip3DXQShaOHwETy5dsxLtDCGdZqna51sppGOAikUaYWvyqFTR6m8E1 OLbXP1d1z4qv6gGbLC9me+oLAdxkBwGttDycz2Sa27d3Y4qzmTyfz3ySz A==; IronPort-SDR: oIQRqhRNRF10qfS9urYXhf7jTlVopEBArrFNO/MC9TVZj5W2KUUIG3vuflHKz9XOJQdYAAuPac xffpOsDpqdtozyOoQ99HH4UCuyje48m+IZo9CoxNEllSNka3sasi2bB4x72mxYuMa+NO0IVvob ulhd64j3Acd2o+RSTmqgnnn8FVVX6vBZnRGuuTmil0gzMzsGoT4dogsz0Vj5oedBCdRNF7lYjw 6TzIl0g0J2vDSPu25/mzcD9VRpAH6T/L1p1yjAYK5bKGd9wp6TKT+uHJHI6/96xN7+S8AhvFDi ffY= X-IronPort-AV: E=Sophos;i="5.82,242,1613404800"; d="scan'208";a="166389012" Received: from mail-dm6nam11lp2177.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.177]) by ob1.hgst.iphmx.com with ESMTP; 22 Apr 2021 19:21:10 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kaZ2sIvI5biYesY8uNpXiXoZzYJCy+/f0HiZzQyiYrmsIOngXYDD6pOYlBHxDgE3AJVCyuVvWLt2LL7F/Sq3iMIJMIL+reo+/o7uk8L4CLDrFqv7DlvEpNrrPvcjz7M/l4xLvZP4T42lR3+C9SGrvExp0lnqN1MuUyWTZvNZTHT2+6JfIyTZ+r7P+eheaU92zt3gpD0QXsRtDwZ67sNppERpC7/IPvwEk6K8Hcfd61LbyxKlGh8TbghaeBJ/g9k/ldTtye7vxuE6T+Zn+vTjkm6Q+VZ/GbX/K4bhrlN2junNmdjRmot46PjGhtVyEsJK+5xQpnQLUiTdtPmkHD6EHA== 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=5GNRN69NdXf1/A2HhQF4tz4TV8wByJF5kZpk+/FugMg=; b=QwFdJhP0BguK+Y+04O333HXOjbIm+v8oZ2kEtDc6sj0PW2RwE9k4YahRlQx6OwZxyNE+XgCBuqsRF/IEdwwlVqwMCmiKyHTywpSHGaDRklKSxT4YFLpiMDuINmFT5u+rBpRKFqhy368AiFoNLUgOaqsfJSTkUT0f01uAiJHGWNpsMjmg41mdCX84QQsQNUXhjB3Skx1RJLKVe/lWsxMJuzLdbTIfcxlTbMh+cK6Y8OPwhIBTn6CyUKc05coAMjkQPSJlhKUCuf5GAxB9aWHKFdhhWpqIU4/11D2nglOedA7cM5VY2lZ+hbQl/H5Oc1YG/ZOLKly5CabsxMW/L35T3g== 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=5GNRN69NdXf1/A2HhQF4tz4TV8wByJF5kZpk+/FugMg=; b=xxIDWuhOzWR6vF5G1KM6RzF1kAQNhepLDCh9Yqgd9ZaRFgjkIt/a/W7Opr01VZyRqgemfs6Mu0CjBATms8PP0KckJzj0ueUsJPu/RjfBNyKV5VWOH1QZVrZ+lXHrZ3WBBUeXYpGrFB2+99/iG38tQ+m7d8Wn/f+H5f/pNyMJIO0= 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 DM6PR04MB5755.namprd04.prod.outlook.com (2603:10b6:5:162::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Thu, 22 Apr 2021 11:21:08 +0000 Received: from DM6PR04MB6201.namprd04.prod.outlook.com ([fe80::8159:3e4e:d870:bd18]) by DM6PR04MB6201.namprd04.prod.outlook.com ([fe80::8159:3e4e:d870:bd18%3]) with mapi id 15.20.4042.024; Thu, 22 Apr 2021 11:21:08 +0000 From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 6/7] lib: sbi: Simplify HSM platform operations Date: Thu, 22 Apr 2021 16:50:22 +0530 Message-Id: <20210422112023.670521-7-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210422112023.670521-1-anup.patel@wdc.com> References: <20210422112023.670521-1-anup.patel@wdc.com> X-Originating-IP: [122.171.42.203] X-ClientProxiedBy: MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::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.171.42.203) by MA1PR0101CA0024.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:21::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.22 via Frontend Transport; Thu, 22 Apr 2021 11:21:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 90c454f2-82c4-4a6e-968f-08d90580b9fb X-MS-TrafficTypeDiagnostic: DM6PR04MB5755: 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: l0ldh20kJGeOVTXw6WMJOr9q4hXI3+xq+w5i595MVBBu5wPG7QvD3OFZVLesBU5v2+CIexk9EdXP6/7A1fZtsbO3NDYZqEIACfNKMN8jpZhK00zJigXwaC0/EhVpyFkMGqaj6Rq25S9MpeB39xW/ejJtVaJScPgEkFIx7L4GmChS2Ur7R0A19SLbo41WQPdYBwu2mYNmMgSh5jkP2WaqRrxlEE1owPs2sgnF7H2q8ZvomY+omPA5ft3XHTX6ebKyKfqM5VWUl6mvxO5Qypj6yrwM2kLzjoU7ZXQprP3SVhB3TJKnxkswnssJjgoo5HLvClEEvygqdo2yRBwocMYlLJffAdn4uYAOAnzOfUuwpVNLqRfxa1FukgZqw4Y9h0lDTOskNzLgdI9JKHkWMo9IVXKeNO03MzTMSyphmqz0dB1YhwzlSgSNIVLDCcnIyNneqKnb7klm8iwghJP9aHgWmQJDNaF8ZhiaLaBt+Fv76UOc7idziH6oJ+bpf6KSRyt7ro/u6GM9eMsUSVypXPWot+xlTu+XPOdzMKEgmQay6kbp1igt/zNc/m7j3LBWft2IPXqMWaOa5hnoZn9TID+6i8m+pd92jpL40sv07McLDDNm3y3jx6/WXzsxQmC9BnaN+jBRQhWKolrbBkrTRSNJFIyiLL4D8Zs1OZEZ1DfL7iU= 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)(366004)(396003)(39860400002)(376002)(136003)(55016002)(4326008)(110136005)(86362001)(478600001)(66946007)(6636002)(5660300002)(66556008)(66476007)(38350700002)(1076003)(2906002)(6666004)(26005)(44832011)(8886007)(956004)(30864003)(38100700002)(83380400001)(186003)(2616005)(16526019)(36756003)(52116002)(7696005)(8676002)(54906003)(8936002)(316002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: p7VXuDlqVNh8Sd/XU5d9wNMStrLyDMWAlm0P7IaT5bQz9NoLra/BVoESNd5qHbyKDpfxkJ1HD4VfRpHyg1MzBtsuB0AijR4R7X3SEGO/ABaoZqBuzzVAqAoczvmRqyeDXywYm0Al2fc5VvXGw2WbaOQVn9I0dNkDoFx5R1JeP+JrkqmRhw4Yg1jt1ntRX1VA416bM3J7yFgVu8pZJQt/sOTk0G6wn6z3JFjSG7AOoAQiwvakenrMEPvLSu/bO8Wqb23pqZvrUdF2lky3YBaWHQF+uRAhaDac4hZ4luHvGoZiGk4j/s0VMVkxIorMPto3IFNlzF2Rr+XLqKLssLCZjkl0hbOhSV0wzgFicwTTdDULqM7CbgZlLS4D0IDqoBBN0oC0TINXzexUfoA8+aHC8c3fH26ES4sdY9046VgPlesormQoY5Ae3XppVWhnu9z5A7SqTXHytJvhBiwGkTzCDmoJjrre9elkKPlZjnKJexWw9ZDeWt8xwiiudmncnLA32j83ZQAg1cg0LTCRMXRl7Ipwg4vwVWYa04t1o1yM3bQs8ZpdIOo2TksYUop7ALiRcnpIzCinnTAy4/e+BwyOUnfXND8X1JHJ7milxRPuLX+RpTU1ckMSATedYiVNkKpk9jRElTIJLROy1jEn4f/iZBp4K89dnacCYBOqHJww5Exdwk4ju4RbnHW02hRVEzvYU4IQJLiA4aYsAi/Pk2ReT3UhtrRtY642KCyg0FVR+GWHebGXaayYhffKCnEZU2galAKSSdCF1yCUgX5noCu4KvskJgHpq35RrXqGPiavaZUHBU5DAGdxifrFjDwaCS/z1HNTU+SkXLxFWwEN68DsSRASO+RheXMCqQaNCZjb9lL97zedo54zbHPYTYf7vnWyrMX5bJK97zhAqDW+78NnGADMU6xzOTj3VflPEHhzqKKlGLCC5UI2wfJIvcpF71sHCSsZsOMGRNjLlcSBgDglTkbUVQp/bOKVFeSuof0iV/MM8fvBmwSAKX4DE0S3u2Go/mTAJPKlw32Fbm+coTiYJ/njFmJ74/uI/Nzvy+k4EPHiApGwfbQbUd4Li4FBZcUc/b1Ep9WmH8GhUua4ZtAqF2yWpybtReYeScLddfMDsOZE7K5ZK492GJqL5usVGOyBEfgAst+4BR/nCDb28ZJjGNAWsv4r8BLfoZHHUzm0CIyx5JmKiWMfzN5CQK6AWu2A574xqfw1bKENMjTV7/Lcbyvp1xYElMSfxiVNmVoo8nx2kuRlJEM9KPq4GyZwn2Xaf+eIVh+iGmaPr2nANYlPCU2FHRyp7JkUoNKuLHJXibhku6Z6IZCroV5RHyPXz0BD X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 90c454f2-82c4-4a6e-968f-08d90580b9fb X-MS-Exchange-CrossTenant-AuthSource: DM6PR04MB6201.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2021 11:21:08.5970 (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: 1lusmkSBoBKzad5CMvwsWpmjoSRsJUC3/8vc7HgR/IbXbX0Ps1IP+gqYuY0uW370liZvxXW+P21y8gQYMvT0Aw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR04MB5755 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210422_042110_669927_34C9514C X-CRM114-Status: GOOD ( 24.03 ) X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Instead of having hsm_start(), hsm_stop() and hsm_suspend() callbacks in platform operations, it will be much simpler for HSM driver to directly register these operations as a device to the sbi_hsm im [...] Content analysis details: (-0.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [216.71.154.45 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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.0 MSGID_FROM_MTA_HEADER Message-Id was added by a relay X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Instead of having hsm_start(), hsm_stop() and hsm_suspend() callbacks in platform operations, it will be much simpler for HSM driver to directly register these operations as a device to the sbi_hsm implementation. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- include/sbi/sbi_hsm.h | 31 +++++++++++++ include/sbi/sbi_platform.h | 83 +--------------------------------- lib/sbi/sbi_hsm.c | 68 +++++++++++++++++++++++----- lib/sbi/sbi_platform.c | 6 --- platform/thead/c910/platform.c | 27 ++++++----- platform/thead/c910/platform.h | 3 +- 6 files changed, 105 insertions(+), 113 deletions(-) diff --git a/include/sbi/sbi_hsm.h b/include/sbi/sbi_hsm.h index bf0c1a5..c16e871 100644 --- a/include/sbi/sbi_hsm.h +++ b/include/sbi/sbi_hsm.h @@ -12,9 +12,40 @@ #include +/** Hart state managment device */ +struct sbi_hsm_device { + /** Name of the hart state managment device */ + char name[32]; + + /** Start (or power-up) the given hart */ + int (*hart_start)(u32 hartid, ulong saddr); + + /** + * Stop (or power-down) the current hart from running. This call + * doesn't expect to return if success. + */ + int (*hart_stop)(void); + + /** + * Put the current hart in platform specific suspend (or low-power) + * state. + * + * For successful retentive suspend, the call will return 0 when + * the hart resumes normal execution. + * + * For successful non-retentive suspend, the hart will resume from + * specified resume address + */ + int (*hart_suspend)(u32 suspend_type, ulong raddr); +}; + struct sbi_domain; struct sbi_scratch; +const struct sbi_hsm_device *sbi_hsm_get_device(void); + +void sbi_hsm_set_device(const struct sbi_hsm_device *dev); + int sbi_hsm_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot); void __noreturn sbi_hsm_exit(struct sbi_scratch *scratch); diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 921d39c..f8074d2 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -51,15 +51,11 @@ struct sbi_trap_regs; /** Possible feature flags of a platform */ enum sbi_platform_features { - /** Platform has HART hotplug support */ - SBI_PLATFORM_HAS_HART_HOTPLUG = (1 << 0), /** Platform has fault delegation support */ SBI_PLATFORM_HAS_MFAULTS_DELEGATION = (1 << 1), - /** Platform has custom secondary hart booting support */ - SBI_PLATFORM_HAS_HART_SECONDARY_BOOT = (1 << 2), /** Last index of Platform features*/ - SBI_PLATFORM_HAS_LAST_FEATURE = SBI_PLATFORM_HAS_HART_SECONDARY_BOOT, + SBI_PLATFORM_HAS_LAST_FEATURE = SBI_PLATFORM_HAS_MFAULTS_DELEGATION, }; /** Default feature set for a platform */ @@ -114,19 +110,6 @@ struct sbi_platform_operations { /** Exit platform timer for current HART */ void (*timer_exit)(void); - /** Bringup the given hart */ - int (*hart_start)(u32 hartid, ulong saddr); - /** - * Stop the current hart from running. This call doesn't expect to - * return if success. - */ - int (*hart_stop)(void); - /** - * Put the current hart in platform specific suspend (or low-power) - * state. - */ - int (*hart_suspend)(u32 suspend_type, ulong raddr); - /** platform specific SBI extension implementation probe function */ int (*vendor_ext_check)(long extid); /** platform specific SBI extension implementation provider */ @@ -193,15 +176,9 @@ struct sbi_platform { #define sbi_platform_ops(__p) \ ((const struct sbi_platform_operations *)(__p)->platform_ops_addr) -/** Check whether the platform supports HART hotplug */ -#define sbi_platform_has_hart_hotplug(__p) \ - ((__p)->features & SBI_PLATFORM_HAS_HART_HOTPLUG) /** Check whether the platform supports fault delegation */ #define sbi_platform_has_mfaults_delegation(__p) \ ((__p)->features & SBI_PLATFORM_HAS_MFAULTS_DELEGATION) -/** Check whether the platform supports custom secondary hart booting support */ -#define sbi_platform_has_hart_secondary_boot(__p) \ - ((__p)->features & SBI_PLATFORM_HAS_HART_SECONDARY_BOOT) /** * Get HART index for the given HART @@ -316,64 +293,6 @@ static inline bool sbi_platform_hart_invalid(const struct sbi_platform *plat, return FALSE; } -/** - * Bringup a given hart from previous stage. Platform should implement this - * operation if they support a custom mechanism to start a hart. Otherwise, - * a generic WFI based approach will be used to start/stop a hart in OpenSBI. - * - * @param plat pointer to struct sbi_platform - * @param hartid HART id - * @param saddr M-mode start physical address for the HART - * - * @return 0 if sucessful and negative error code on failure - */ -static inline int sbi_platform_hart_start(const struct sbi_platform *plat, - u32 hartid, ulong saddr) -{ - if (plat && sbi_platform_ops(plat)->hart_start) - return sbi_platform_ops(plat)->hart_start(hartid, saddr); - return SBI_ENOTSUPP; -} - -/** - * Stop the current hart in OpenSBI. - * - * @param plat pointer to struct sbi_platform - * - * @return Negative error code on failure. It doesn't return on success. - */ -static inline int sbi_platform_hart_stop(const struct sbi_platform *plat) -{ - if (plat && sbi_platform_ops(plat)->hart_stop) - return sbi_platform_ops(plat)->hart_stop(); - return SBI_ENOTSUPP; -} - -/** - * Put the current hart in platform specific suspend (or low-power) state. - * - * For successful retentive suspend, the call will return 0 when the hart - * resumes normal execution. - * - * For successful non-retentive suspend, the hart will resume from specified - * resume address - * - * @param plat pointer to struct sbi_platform - * @param suspend_type the type of suspend - * @param raddr physical address where the hart can resume in M-mode after - * non-retantive suspend - * - * @return 0 if successful and negative error code on failure - */ -static inline int sbi_platform_hart_suspend(const struct sbi_platform *plat, - u32 suspend_type, ulong raddr) -{ - if (plat && sbi_platform_ops(plat)->hart_suspend) - return sbi_platform_ops(plat)->hart_suspend(suspend_type, - raddr); - return SBI_ENOTSUPP; -} - /** * Early initialization for current HART * diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c index 64d299b..4662150 100644 --- a/lib/sbi/sbi_hsm.c +++ b/lib/sbi/sbi_hsm.c @@ -21,11 +21,12 @@ #include #include #include -#include +#include #include #include #include +static const struct sbi_hsm_device *hsm_dev = NULL; static unsigned long hart_data_offset; /** Per hart specific data to manage state transition **/ @@ -129,6 +130,54 @@ static void sbi_hsm_hart_wait(struct sbi_scratch *scratch, u32 hartid) */ } +const struct sbi_hsm_device *sbi_hsm_get_device(void) +{ + return hsm_dev; +} + +void sbi_hsm_set_device(const struct sbi_hsm_device *dev) +{ + if (!dev || hsm_dev) + return; + + hsm_dev = dev; +} + +static bool hsm_device_has_hart_hotplug(void) +{ + if (hsm_dev && hsm_dev->hart_start && hsm_dev->hart_stop) + return true; + return false; +} + +static bool hsm_device_has_hart_secondary_boot(void) +{ + if (hsm_dev && hsm_dev->hart_start && !hsm_dev->hart_stop) + return true; + return false; +} + +static int hsm_device_hart_start(u32 hartid, ulong saddr) +{ + if (hsm_dev && hsm_dev->hart_start) + return hsm_dev->hart_start(hartid, saddr); + return SBI_ENOTSUPP; +} + +static int hsm_device_hart_stop(void) +{ + if (hsm_dev && hsm_dev->hart_stop) + return hsm_dev->hart_stop(); + return SBI_ENOTSUPP; +} + +static int hsm_device_hart_suspend(u32 suspend_type, ulong raddr) +{ + if (hsm_dev && hsm_dev->hart_suspend) + return hsm_dev->hart_suspend(suspend_type, raddr); + return SBI_ENOTSUPP; +} + int sbi_hsm_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot) { u32 i; @@ -164,7 +213,6 @@ int sbi_hsm_init(struct sbi_scratch *scratch, u32 hartid, bool cold_boot) void __noreturn sbi_hsm_exit(struct sbi_scratch *scratch) { u32 hstate; - const struct sbi_platform *plat = sbi_platform_ptr(scratch); struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset); void (*jump_warmboot)(void) = (void (*)(void))scratch->warmboot_addr; @@ -174,8 +222,8 @@ void __noreturn sbi_hsm_exit(struct sbi_scratch *scratch) if (hstate != SBI_HSM_STATE_STOP_PENDING) goto fail_exit; - if (sbi_platform_has_hart_hotplug(plat)) { - sbi_platform_hart_stop(plat); + if (hsm_device_has_hart_hotplug()) { + hsm_device_hart_stop(); /* It should never reach here */ goto fail_exit; } @@ -201,7 +249,6 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch, unsigned int hstate; struct sbi_scratch *rscratch; struct sbi_hsm_data *hdata; - const struct sbi_platform *plat = sbi_platform_ptr(scratch); /* For now, we only allow start mode to be S-mode or U-mode. */ if (smode != PRV_S && smode != PRV_U) @@ -233,10 +280,9 @@ int sbi_hsm_hart_start(struct sbi_scratch *scratch, rscratch->next_addr = saddr; rscratch->next_mode = smode; - if (sbi_platform_has_hart_hotplug(plat) || - (sbi_platform_has_hart_secondary_boot(plat) && !init_count)) { - return sbi_platform_hart_start(plat, hartid, - scratch->warmboot_addr); + if (hsm_device_has_hart_hotplug() || + (hsm_device_has_hart_secondary_boot() && !init_count)) { + return hsm_device_hart_start(hartid, scratch->warmboot_addr); } else { sbi_ipi_raw_send(hartid); } @@ -374,7 +420,6 @@ int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type, { int oldstate, ret; const struct sbi_domain *dom = sbi_domain_thishart_ptr(); - const struct sbi_platform *plat = sbi_platform_ptr(scratch); struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset); @@ -420,8 +465,7 @@ int sbi_hsm_hart_suspend(struct sbi_scratch *scratch, u32 suspend_type, hdata->suspend_type = suspend_type; /* Try platform specific suspend */ - ret = sbi_platform_hart_suspend(plat, suspend_type, - scratch->warmboot_addr); + ret = hsm_device_hart_suspend(suspend_type, scratch->warmboot_addr); if (ret == SBI_ENOTSUPP) { /* Try generic implementation of default suspend types */ if (suspend_type == SBI_HSM_SUSPEND_RET_DEFAULT) { diff --git a/lib/sbi/sbi_platform.c b/lib/sbi/sbi_platform.c index e78119a..e8b94a3 100644 --- a/lib/sbi/sbi_platform.c +++ b/lib/sbi/sbi_platform.c @@ -19,15 +19,9 @@ static inline char *sbi_platform_feature_id2string(unsigned long feature) return NULL; switch (feature) { - case SBI_PLATFORM_HAS_HART_HOTPLUG: - fstr = "hotplug"; - break; case SBI_PLATFORM_HAS_MFAULTS_DELEGATION: fstr = "mfdeleg"; break; - case SBI_PLATFORM_HAS_HART_SECONDARY_BOOT: - fstr = "sec_boot"; - break; default: break; } diff --git a/platform/thead/c910/platform.c b/platform/thead/c910/platform.c index 8f8069c..8a9318c 100644 --- a/platform/thead/c910/platform.c +++ b/platform/thead/c910/platform.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -39,6 +40,19 @@ static struct sbi_system_reset_device c910_reset = { .system_reset = c910_system_reset }; +static int c910_hart_start(u32 hartid, ulong saddr) +{ + csr_write(CSR_MRVBR, saddr); + csr_write(CSR_MRMR, csr_read(CSR_MRMR) | (1 << hartid)); + + return 0; +} + +static struct sbi_hsm_device c910_hsm = { + .name = "thead_c910_hsm", + .hart_start = c910_hart_start +}; + static int c910_early_init(bool cold_boot) { if (cold_boot) { @@ -63,6 +77,7 @@ static int c910_early_init(bool cold_boot) c910_regs.clint_base_addr = c910_regs.plic_base_addr + C910_PLIC_CLINT_OFFSET; + sbi_hsm_set_device(&c910_hsm); sbi_system_reset_set_device(&c910_reset); } else { /* Store to other core */ @@ -127,14 +142,6 @@ static int c910_timer_init(bool cold_boot) return clint_warm_timer_init(); } -int c910_hart_start(u32 hartid, ulong saddr) -{ - csr_write(CSR_MRVBR, saddr); - csr_write(CSR_MRMR, csr_read(CSR_MRMR) | (1 << hartid)); - - return 0; -} - const struct sbi_platform_operations platform_ops = { .early_init = c910_early_init, .final_init = c910_final_init, @@ -143,9 +150,7 @@ const struct sbi_platform_operations platform_ops = { .ipi_init = c910_ipi_init, - .timer_init = c910_timer_init, - - .hart_start = c910_hart_start, + .timer_init = c910_timer_init }; const struct sbi_platform platform = { diff --git a/platform/thead/c910/platform.h b/platform/thead/c910/platform.h index 354404e..880cb6b 100644 --- a/platform/thead/c910/platform.h +++ b/platform/thead/c910/platform.h @@ -8,8 +8,7 @@ #define C910_HART_COUNT 16 #define SBI_THEAD_FEATURES \ - (SBI_PLATFORM_HAS_MFAULTS_DELEGATION | \ - SBI_PLATFORM_HAS_HART_SECONDARY_BOOT) + (SBI_PLATFORM_HAS_MFAULTS_DELEGATION) #define CSR_MCOR 0x7c2 #define CSR_MHCR 0x7c1