From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.67]) by mx.groups.io with SMTP id smtpd.web10.8143.1665671069060879170 for ; Thu, 13 Oct 2022 07:24:29 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=vzlKn2ux; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.223.67, mailfrom: abner.chang@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oT4eZF0Cx03JKqvg9YppMREP8w73/chg8JncwQDixd1WLJAbJfQeEEbT31R8bMSGUOYZGlCTqOZ5h/18apzFVXFKJuudPXjgv27LCcAfmcJ5HZS6k7c55X4G9/TzkUWockH2Xj2MflQWqzpd27iPu3akaXgoZIHfSHApEQ2F07RTAKCkoWx42l1aa6aaw5s0gfXRjDI7MV4aVphVzFX6mnWYTIllj+IAtPWKF3LvjgPWHmwPuuObS67y3o1xnIjbgBKDeRuCjhByMRb7fCVd9kOUUcZErxDGY3lngF0ISVMd+1+w569sZIAwXCEAyo0T9SDbCdRzUOAAo+UG3ATPsg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IUh0DtEofqjmADEobjwYmSuXEn2+I60C6nQdi+Fx1LI=; b=Ozqijp8yneS9+NRsHAuAHD3jBVzhKli0hd33z4LeDusRYXtRN8xwDQ+4VXTc1zl/TehfNUoqAx06mDeJtTbqtVQaKMyBEbJ/ihEiQuWVUNpm1M+73SdZZTrlUPOLaD+91N0TafRHXXYY4CJ0Iraody/zpqqd00+TsozjTip9igLydVb1JRH+GgnNzjxToy/tSEOFi0tgTfZ1YtmOeI9la+qlm9kN0zu1zsf5ivw+iyHOzkuoEHBFU06zLfVBDmmM5GdbavsLPpuT9wtQZx6ApOkoG25HWZ41v89WnWRpcFFm5HzCYp8e2c2yyLuMiTEYVRzPlhEbWeaPZ+bPRI4yOw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IUh0DtEofqjmADEobjwYmSuXEn2+I60C6nQdi+Fx1LI=; b=vzlKn2ux8Q+LS29ne9vaj762NTpc8F+pVdQdNWToiR7Cj8h9CTdJsuSDHpcOdKgAoecXG3q+BA9t1VdAXxozm4xLWwTzjdjqEjT1XReieavm71pngy80KLrd6n/JytBdreBWPHXMgUdUWS05HTz6CqPS6xHRgP1cpQM0bzCDGeE= Received: from MN2PR12MB3966.namprd12.prod.outlook.com (2603:10b6:208:165::18) by SA0PR12MB4576.namprd12.prod.outlook.com (2603:10b6:806:93::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.26; Thu, 13 Oct 2022 14:24:27 +0000 Received: from MN2PR12MB3966.namprd12.prod.outlook.com ([fe80::dd29:6efb:1027:cfb2]) by MN2PR12MB3966.namprd12.prod.outlook.com ([fe80::dd29:6efb:1027:cfb2%5]) with mapi id 15.20.5723.026; Thu, 13 Oct 2022 14:24:27 +0000 From: "Chang, Abner" To: "devel@edk2.groups.io" , "sunilvl@ventanamicro.com" CC: Michael D Kinney , Liming Gao , Zhiguang Liu Subject: Re: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 04/34] MdePkg: Add BaseRiscVSbiLib Library for RISC-V Thread-Topic: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 04/34] MdePkg: Add BaseRiscVSbiLib Library for RISC-V Thread-Index: AQHY3uqH4olQca7sW0+SC44bxKnoY64MYK0Q Date: Thu, 13 Oct 2022 14:24:27 +0000 Message-ID: References: <20221013095829.1454581-1-sunilvl@ventanamicro.com> <20221013095829.1454581-5-sunilvl@ventanamicro.com> In-Reply-To: <20221013095829.1454581-5-sunilvl@ventanamicro.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Enabled=true; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_SetDate=2022-10-13T14:24:24Z; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Method=Standard; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Name=General; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_SiteId=3dd8961f-e488-4e60-8e11-a82d994e183d; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_ActionId=11d8541c-1e62-4bfd-b692-12557ef33e89; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_ContentBits=1 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN2PR12MB3966:EE_|SA0PR12MB4576:EE_ x-ms-office365-filtering-correlation-id: 73b69328-1a15-4559-508c-08daad26a261 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: nbXKkkdvFfYiKMHc3kWsg85a/hupYSNHoJHxfem8ep3iradkesgAFn/sI3qe+eg2iUWF3O52zqO+K3CDpMFe9RkdFrWQ/OHAmbzslK3d2P8FANtFUyVRWkWEELAINazfxy+UwLhd4i08/xjRqQGffv0rn1SUEe5oXO3RJILDBFU8jh2iNAiHTnatrPC/eJ/K1p+3I9q0kfE44GvsTMA2EugpTYMkTlo2Lo+IkcRsfLxeMpb4tGbwaPfGdjmteJoTmW0IsSfmU5RB4mWeZunMY2rZyibABlundXoCecpZ9PHgEU3EDSCEjHewAhGLpza8+rEcUK+fKFCBh0K6LdAQXt1I2xTcIa4TQo5s+ggOuE/now9XP8ywjqnWfdHFp4XoZ0fKMvW71FTng25p65cdTsYQET3OmiVaAmZAY+snY934e/ditp6mVmwLgm90csOtzw5jtH3/ehpsPMI0iXqurHFtmb+Ju63ZlH75QC3Yw0DHKIyYI2WRqBy4inD0OUAPHPxWJJFFb0ZsUZRjAVuGqp0IYjU5WR605zZJtaBCRLZfILhW9cLlCSBb4io80pfUlc29X6KUC2WM8lNsshOf3Y5IrK0q0No1mwS59sU1VSM+2o5r6vd09Hdjh/IVgXyQGRqAzmYedG6nSJVmVCtXsiPmCYJOs6r8Tt7dpKTVf50o0GcDLCdg4dRioeEWmvD4+yKgyRhkF7AxBjrW3mblukr5Ldf7ChhOhj2D9TIwVXH11uxAClyuJxIBYeroGffIoe0ttDyaxBvjm7xeVSeEQp5/4TVX/xrzVAhlcVewckek3UzQ+jFnqJ+9mNWvyLCoRxyxyV9PGFNBByfg9AShSA== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB3966.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(396003)(346002)(366004)(136003)(39860400002)(451199015)(7696005)(6506007)(26005)(9686003)(478600001)(45080400002)(53546011)(966005)(38100700002)(122000001)(55016003)(86362001)(33656002)(38070700005)(83380400001)(186003)(5660300002)(71200400001)(30864003)(52536014)(8936002)(66899015)(2906002)(66556008)(66946007)(76116006)(4326008)(8676002)(64756008)(66446008)(54906003)(110136005)(66476007)(316002)(41300700001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?CzA0MJ2zOqXylrvqrjzl2nAjVqnSb8ekrgQ3TV7qz6zldkkMCmYz+3OZ1+no?= =?us-ascii?Q?kSyUak7lqYysg/ach0O3H53Bty4JkOxxa65KNRn9+m+J/A6VTUB3KHRKaf3M?= =?us-ascii?Q?u7P8PNL6G4W2UBz+Ewktpqc94so6LbHQWejAHJWBBvBhEdXcXpY1JNVyMMRx?= =?us-ascii?Q?7+ttDCqKkenkxqC0kbWVUqtsk5c6mmUa8f5OKqgSCf0U5o0o5PfuZj0BQrWg?= =?us-ascii?Q?E7Byu//xoH03sXHbSdRlUTRK06v1IgR5JxJkz3LoPUNa4xesbdE6ar9C4VTy?= =?us-ascii?Q?16vI+BdT0S1vCuP5we2FXQzaVCmBHiY9ZWi7TqHmL/Tu+E7OWUTz+HZwwQ+/?= =?us-ascii?Q?k/qzxckn2gGbClg+tqSHJJyFIjjthVoyQ6IBC1ZOkAhqB5Ottfvg62fbgi20?= =?us-ascii?Q?kHJZGSastKmcCzdw5g13jcUZwQzSKLPZpwsh3IAgzkOEUIEnM+KKiXb6EnAu?= =?us-ascii?Q?SyTDANEh8Jb4bp0v/t+sOQFyM7mNSaSbmQ/KkhirN3kPDkkx970l54rqmLTR?= =?us-ascii?Q?RYXhRkkf9HXZo0aA5ardkOJoxcaDgIb1pF1E7vYCy1iG0H0yXmQokWfInQdg?= =?us-ascii?Q?f/x9wSPO0lWj3jSnjc36u6eUVy0iARimwGWq9LLMt0YxsxAsoVFqcUC+i/dp?= =?us-ascii?Q?dY5CoxiYY1huY4oepaUczSI7tn+pfOqeRS5Cv5TF8igzPEywBvhZk9ZkVC1J?= =?us-ascii?Q?d071i+S1qti2hrhErSKEi4VE4XQmwXwRvwjWikuqOYNLXfbXzBD5OA+FFpyW?= =?us-ascii?Q?KeeEuMNEJFuOy/Iel8XYJbEi7JtS6TtWG0xPwg99QCtbBb7qZ0ijTuMV4FRs?= =?us-ascii?Q?OIqofUWQcFdHk0y7NwN0vp2Gm//lu+SRQFakyBilWAU2kXZlL7fVVL7c0NSI?= =?us-ascii?Q?aiPMh6kK/76ND4hG8sy/2kMnT5Rz5f25M61pH1FghO0Z/aMTiQGiju2+SzRQ?= =?us-ascii?Q?SRrlM7FYhvaBVl63/7OWZ6NKdz12XECz7jEKvjpPFxhyjETYPlUMN+60TdSS?= =?us-ascii?Q?L52D6cNtg6VItL1cZs7NJttq68xlPcX1l/xI5o+ut07gt1hLZZklM32VC97q?= =?us-ascii?Q?hQ8ZY7ED3mCaYTpDik++5AuOz6uDdH8PZG02xeSEDAdAkgutv2b9fzEv/ggi?= =?us-ascii?Q?0gD6uvwwBRCmxcXQ4UwyhIUNw7dUVTPpEyTthCt1d3LYBWYgZRYIf5oiIO+g?= =?us-ascii?Q?DNHCpmpeg7AEHphCpaGaZcxf0iZZjQ1CbMsru9B4d4oAfeyL4xdXkRkQk9Px?= =?us-ascii?Q?UNeQRLsYWGzBnwEMjxfE1gq490mLKD4IidAheYJTEDFNHy1FL5/qdAIJ/eNP?= =?us-ascii?Q?Y4OjGhg9Zzmgw5scgFVrhy7vK/V0h7pp5uEZQvyp1jncy1q/3sQpb820BdTw?= =?us-ascii?Q?1PSYlZT9dRRIT3o82ku0uZUYxE8RT9Beo4x7cgrQIx9EwfppFwdSPh8zrY0V?= =?us-ascii?Q?kveAL7P8BDagMRIQh8DkPz/2q1410rFTk1yEYd3z7wyLZQaAziBIcYV6aQaq?= =?us-ascii?Q?tTYD9RQ8GFeFaGySsalGOkYKm8nzmvDETrpnOfKpcQ1d9OGcV6TuNIhSTY6D?= =?us-ascii?Q?baRCyMQ/I96pQXLaIpE=3D?= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB3966.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 73b69328-1a15-4559-508c-08daad26a261 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Oct 2022 14:24:27.0683 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: D4diY6ExZG/pPWa8RdqZdKZy5gQYXFaB3uTzaAQEQHCpG34UZvMXxgkdQUZPPLyPksxlp0/4+09rr9dgFjH3Eg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4576 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable [AMD Official Use Only - General] I have no problem with these source files. Those are already verified on ed= k2-platform. Acked-by: Abner Chang > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Sunil V L > via groups.io > Sent: Thursday, October 13, 2022 5:58 PM > To: devel@edk2.groups.io > Cc: Michael D Kinney ; Liming Gao > ; Zhiguang Liu > Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V3 04/34] > MdePkg: Add BaseRiscVSbiLib Library for RISC-V >=20 > Caution: This message originated from an External Source. Use proper > caution when opening attachments, clicking links, or responding. >=20 >=20 > REF: > https://nam11.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fbugz > illa.tianocore.org%2Fshow_bug.cgi%3Fid%3D4076&data=3D05%7C01%7Ca > bner.chang%40amd.com%7Cfd6b6a96550a4e2bb93108daad01a788%7C3dd89 > 61fe4884e608e11a82d994e183d%7C0%7C0%7C638012519876960817%7CUnkn > own%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik > 1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=3DZhtBOz4KYaE% > 2F9YEhZhU0HXGHnlBM5aCBMpv4%2BUtHWOk%3D&reserved=3D0 >=20 > This library is required to make SBI ecalls from the S-mode EDK2. >=20 > Cc: Michael D Kinney > Cc: Liming Gao > Cc: Zhiguang Liu > Signed-off-by: Sunil V L > --- > MdePkg/MdePkg.dec | 4 + > MdePkg/MdePkg.dsc | 3 + > .../BaseRiscVSbiLib/BaseRiscVSbiLib.inf | 25 ++ > MdePkg/Include/Library/BaseRiscVSbiLib.h | 127 ++++++++++ > .../Library/BaseRiscVSbiLib/BaseRiscVSbiLib.c | 227 ++++++++++++++++++ > 5 files changed, 386 insertions(+) > create mode 100644 MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf > create mode 100644 MdePkg/Include/Library/BaseRiscVSbiLib.h > create mode 100644 MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.c >=20 > diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index > 8f1bcfdc3e97..1762068ffad7 100644 > --- a/MdePkg/MdePkg.dec > +++ b/MdePkg/MdePkg.dec > @@ -307,6 +307,10 @@ [LibraryClasses.IA32, LibraryClasses.X64] > ## @libraryclass Provides function to support TDX processing. > TdxLib|Include/Library/TdxLib.h >=20 > +[LibraryClasses.RISCV64] > + ## @libraryclass Provides function to make ecalls to SBI > + BaseRiscVSbiLib|Include/Library/BaseRiscVSbiLib.h > + > [Guids] > # > # GUID defined in UEFI2.1/UEFI2.0/EFI1.1 diff --git a/MdePkg/MdePkg.ds= c > b/MdePkg/MdePkg.dsc index cc1ac196a931..fd08122f441d 100644 > --- a/MdePkg/MdePkg.dsc > +++ b/MdePkg/MdePkg.dsc > @@ -188,4 +188,7 @@ [Components.ARM, Components.AARCH64] > MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicArmVirt.inf > MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf >=20 > +[Components.RISCV64] > + MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf > + > [BuildOptions] > diff --git a/MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf > b/MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf > new file mode 100644 > index 000000000000..d03132bf01c1 > --- /dev/null > +++ b/MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.inf > @@ -0,0 +1,25 @@ > +## @file > +# RISC-V Library to call SBI ecalls > +# > +# Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All > +rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent > +# ## > + > +[Defines] > + INF_VERSION =3D 0x0001001b > + BASE_NAME =3D BaseRiscVSbiLib > + FILE_GUID =3D D742CF3D-E600-4009-8FB5-318073008508 > + MODULE_TYPE =3D BASE > + VERSION_STRING =3D 1.0 > + LIBRARY_CLASS =3D RiscVSbiLib > + > +[Sources] > + BaseRiscVSbiLib.c > + > +[Packages] > + MdePkg/MdePkg.dec > + > +[LibraryClasses] > + BaseLib > diff --git a/MdePkg/Include/Library/BaseRiscVSbiLib.h > b/MdePkg/Include/Library/BaseRiscVSbiLib.h > new file mode 100644 > index 000000000000..e9886187526a > --- /dev/null > +++ b/MdePkg/Include/Library/BaseRiscVSbiLib.h > @@ -0,0 +1,127 @@ > +/** @file > + Library to call the RISC-V SBI ecalls > + > + Copyright (c) 2021-2022, Hewlett Packard Development LP. All rights > + reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > + @par Glossary: > + - Hart - Hardware Thread, similar to a CPU core > + > + Currently, EDK2 needs to call SBI only to set the time and to do syste= m > reset. > + > +**/ > + > +#ifndef RISCV_SBI_LIB_H_ > +#define RISCV_SBI_LIB_H_ > + > +#include > + > +/* SBI Extension IDs */ > +#define SBI_EXT_TIME 0x54494D45 > +#define SBI_EXT_SRST 0x53525354 > + > +/* SBI function IDs for TIME extension*/ #define > SBI_EXT_TIME_SET_TIMER > +0x0 > + > +/* 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_SRST_RESET_TYPE_LAST > SBI_SRST_RESET_TYPE_WARM_REBOOT > + > +#define SBI_SRST_RESET_REASON_NONE 0x0 > +#define SBI_SRST_RESET_REASON_SYSFAIL 0x1 > + > +/* SBI return error codes */ > +#define SBI_SUCCESS 0 > +#define SBI_ERR_FAILED -1 > +#define SBI_ERR_NOT_SUPPORTED -2 > +#define SBI_ERR_INVALID_PARAM -3 > +#define SBI_ERR_DENIED -4 > +#define SBI_ERR_INVALID_ADDRESS -5 > +#define SBI_ERR_ALREADY_AVAILABLE -6 > +#define SBI_ERR_ALREADY_STARTED -7 > +#define SBI_ERR_ALREADY_STOPPED -8 > + > +#define SBI_LAST_ERR SBI_ERR_ALREADY_STOPPED > + > +typedef struct { > + UINT64 BootHartId; > + VOID *PeiServiceTable; // PEI Service table > + UINT64 FlattenedDeviceTree; // Pointer to Flattened Device tree > +} EFI_RISCV_FIRMWARE_CONTEXT; > + > +// > +// EDK2 OpenSBI firmware extension return status. > +// > +typedef struct { > + UINTN Error; ///< SBI status code > + UINTN Value; ///< Value returned > +} SBI_RET; > + > +VOID > +EFIAPI > +SbiSetTimer ( > + IN UINT64 Time > + ); > + > +EFI_STATUS > +EFIAPI > +SbiSystemReset ( > + IN UINTN ResetType, > + IN UINTN ResetReason > + ); > + > +/** > + Get firmware context of the calling hart. > + > + @param[out] FirmwareContext The firmware context pointer. > +**/ > +VOID > +EFIAPI > +GetFirmwareContext ( > + OUT EFI_RISCV_FIRMWARE_CONTEXT **FirmwareContext > + ); > + > +/** > + Set firmware context of the calling hart. > + > + @param[in] FirmwareContext The firmware context pointer. > +**/ > +VOID > +EFIAPI > +SetFirmwareContext ( > + IN EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext > + ); > + > +/** > + Get pointer to OpenSBI Firmware Context > + > + Get the pointer of firmware context. > + > + @param FirmwareContextPtr Pointer to retrieve pointer to the > + Firmware Context. > +**/ > +VOID > +EFIAPI > +GetFirmwareContextPointer ( > + IN OUT EFI_RISCV_FIRMWARE_CONTEXT **FirmwareContextPtr > + ); > + > +/** > + Set pointer to OpenSBI Firmware Context > + > + Set the pointer of firmware context. > + > + @param FirmwareContextPtr Pointer to Firmware Context. > +**/ > +VOID > +EFIAPI > +SetFirmwareContextPointer ( > + IN EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContextPtr > + ); > + > +#endif > diff --git a/MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.c > b/MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.c > new file mode 100644 > index 000000000000..5db95a008069 > --- /dev/null > +++ b/MdePkg/Library/BaseRiscVSbiLib/BaseRiscVSbiLib.c > @@ -0,0 +1,227 @@ > +/** @file > + Instance of the SBI ecall library. > + > + It allows calling an SBI function via an ecall from S-Mode. > + > + Copyright (c) 2021-2022, Hewlett Packard Development LP. All rights > + reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > +#include > +#include > +#include > + > +// > +// Maximum arguments for SBI ecall > +// It's possible to pass more but no SBI call uses more as of SBI 0.2. > +// The additional arguments would have to be passed on the stack > +instead of as // registers, like it's done now. > +// > +#define SBI_CALL_MAX_ARGS 6 > + > +/** > + Call SBI call using ecall instruction. > + > + Asserts when NumArgs exceeds SBI_CALL_MAX_ARGS. > + > + @param[in] ExtId SBI extension ID. > + @param[in] FuncId SBI function ID. > + @param[in] NumArgs Number of arguments to pass to the ecall. > + @param[in] ... Argument list for the ecall. > + > + @retval Returns SBI_RET structure with value and error code. > + > +**/ > +STATIC > +SBI_RET > +EFIAPI > +SbiCall ( > + IN UINTN ExtId, > + IN UINTN FuncId, > + IN UINTN NumArgs, > + ... > + ) > +{ > + UINTN I; > + SBI_RET Ret; > + UINTN Args[SBI_CALL_MAX_ARGS]; > + VA_LIST ArgList; > + > + VA_START (ArgList, NumArgs); > + > + ASSERT (NumArgs <=3D SBI_CALL_MAX_ARGS); > + > + for (I =3D 0; I < SBI_CALL_MAX_ARGS; I++) { > + if (I < NumArgs) { > + Args[I] =3D VA_ARG (ArgList, UINTN); > + } else { > + // Default to 0 for all arguments that are not given > + Args[I] =3D 0; > + } > + } > + > + VA_END (ArgList); > + > + register UINTN a0 asm ("a0") =3D Args[0]; register UINTN a1 asm > + ("a1") =3D Args[1]; register UINTN a2 asm ("a2") =3D Args[2]; regist= er > + UINTN a3 asm ("a3") =3D Args[3]; register UINTN a4 asm ("a4") =3D > + Args[4]; register UINTN a5 asm ("a5") =3D Args[5]; register UINTN a= 6 > + asm ("a6") =3D (UINTN)(FuncId); register UINTN a7 asm ("a7") =3D > + (UINTN)(ExtId); > + > + asm volatile ("ecall" \ > + : "+r" (a0), "+r" (a1) \ > + : "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), "r" (a7) \ > + : "memory"); \ > + Ret.Error =3D a0; > + Ret.Value =3D a1; > + return Ret; > +} > + > +/** > + Translate SBI error code to EFI status. > + > + @param[in] SbiError SBI error code > + @retval EFI_STATUS > +**/ > +STATIC > +EFI_STATUS > +EFIAPI > +TranslateError ( > + IN UINTN SbiError > + ) > +{ > + switch (SbiError) { > + case SBI_SUCCESS: > + return EFI_SUCCESS; > + case SBI_ERR_FAILED: > + return EFI_DEVICE_ERROR; > + break; > + case SBI_ERR_NOT_SUPPORTED: > + return EFI_UNSUPPORTED; > + break; > + case SBI_ERR_INVALID_PARAM: > + return EFI_INVALID_PARAMETER; > + break; > + case SBI_ERR_DENIED: > + return EFI_ACCESS_DENIED; > + break; > + case SBI_ERR_INVALID_ADDRESS: > + return EFI_LOAD_ERROR; > + break; > + case SBI_ERR_ALREADY_AVAILABLE: > + return EFI_ALREADY_STARTED; > + break; > + default: > + // > + // Reaches here only if SBI has defined a new error type > + // > + ASSERT (FALSE); > + return EFI_UNSUPPORTED; > + break; > + } > +} > + > +/** > + Clear pending timer interrupt bit and set timer for next event after T= ime. > + > + To clear the timer without scheduling a timer event, set Time to a > + practically infinite value or mask the timer interrupt by clearing sie.= STIE. > + > + @param[in] Time The time offset to the next scheduled= timer > interrupt. > +**/ > +VOID > +EFIAPI > +SbiSetTimer ( > + IN UINT64 Time > + ) > +{ > + SbiCall (SBI_EXT_TIME, SBI_EXT_TIME_SET_TIMER, 1, Time); } > + > +EFI_STATUS > +EFIAPI > +SbiSystemReset ( > + IN UINTN ResetType, > + IN UINTN ResetReason > + ) > +{ > + SBI_RET Ret; > + > + Ret =3D SbiCall ( > + SBI_EXT_SRST, > + SBI_EXT_SRST_RESET, > + 2, > + ResetType, > + ResetReason > + ); > + > + return TranslateError (Ret.Error); > +} > + > +/** > + Get firmware context of the calling hart. > + > + @param[out] FirmwareContext The firmware context pointer. > + @retval EFI_SUCCESS The operation succeeds. > +**/ > +VOID > +EFIAPI > +GetFirmwareContext ( > + OUT EFI_RISCV_FIRMWARE_CONTEXT **FirmwareContext > + ) > +{ > + *FirmwareContext =3D (EFI_RISCV_FIRMWARE_CONTEXT > +*)RiscVGetSupervisorScratch (); } > + > +/** > + Set firmware context of the calling hart. > + > + @param[in] FirmwareContext The firmware context pointer. > +**/ > +VOID > +EFIAPI > +SetFirmwareContext ( > + IN EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext > + ) > +{ > + RiscVSetSupervisorScratch ((UINT64)FirmwareContext); } > + > +/** > + Get pointer to OpenSBI Firmware Context > + > + Get the pointer of firmware context through OpenSBI FW Extension SBI. > + > + @param FirmwareContextPtr Pointer to retrieve pointer to the > + Firmware Context. > +**/ > +VOID > +EFIAPI > +GetFirmwareContextPointer ( > + IN OUT EFI_RISCV_FIRMWARE_CONTEXT **FirmwareContextPtr > + ) > +{ > + GetFirmwareContext (FirmwareContextPtr); } > + > +/** > + Set the pointer to OpenSBI Firmware Context > + > + Set the pointer of firmware context through OpenSBI FW Extension SBI. > + > + @param FirmwareContextPtr Pointer to Firmware Context. > +**/ > +VOID > +EFIAPI > +SetFirmwareContextPointer ( > + IN EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContextPtr > + ) > +{ > + SetFirmwareContext (FirmwareContextPtr); } > -- > 2.25.1 >=20 >=20 >=20 >=20 >=20