From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.69]) by mx.groups.io with SMTP id smtpd.web08.20816.1665849006385524703 for ; Sat, 15 Oct 2022 08:50:06 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=aguCocEU; 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.92.69, mailfrom: abner.chang@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H15PyE+tC44ksUY2G4HYL6SKP0UNiEgYxly/7uO4tCRIqOSnQQNtGlQH2T06MdjYK7g4o8BHNPuw2PR9u9PXzUOulT+3VjJNmr5OTbn7fxLsU0dYUKuXt25Mi4PUlt5AF7nFSFGdOFL7LCDk6swdcRT3jtB7LKR6n8puzLb461ICQ5OSoVZN/5575BBKHYRha7N7C+SUPBJrHR//Bk3st0/Mhy62U0yw0AYhj74me6yXTaxQV8ANUK1gS/cPkgatae9kazdHDkBVaRVz3ILSNoTosTieMAvUsM1aDOAmxldcMVdGk3a3xGw8iFPqip0uert2iIU6tB2xpF2mGgOBSA== 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=uweBybIK/mnfGi0P1g3tr3IHScOddTO9tWG/79HzHtM=; b=XMAuxbj85wWikdHCjXbkhp8XpsgBsiHAxEUdcWlue31z9nPrIKMbGB93MbMoPAioUU/EL4KoqdN7S4KegyNqyoHHuOHskv9w1TRgDYiBUu4sHZkH/HEWPFJsibjJpPTB4McZyEzc6QbEDGR8kRxlxiBH23Xg3CfEABXzodkBM0JPp1H++wBzcVndi4XxJ44wwWeYDIreQU8+fQLgSo6TWEhX7qX0eOMBVVRnlwx8sNUMdQABfe6BW69bCIoqRPd4FNkTZyKs5JZwFH5j9mfa92jQwf8Kcujwk8bhhWulKFk0Iy3P48fjiQJlF4/sMGful7/tUwECG9tVFhM1u2h41g== 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=uweBybIK/mnfGi0P1g3tr3IHScOddTO9tWG/79HzHtM=; b=aguCocEUWuENpFI1GxyaO+rplqgQAFPbbHo/tqXMxT4goWZtSXZVAS7RIj3zgJk3zatEkD8rd16E1kbRzO+NMxFRiFGivaUClDHEzASDmGBZy/TKkxZHLOPNgGySJzwKrtBXB8uHK78pn20J787SqyT5jc3aMZmN+rfdYMJP7ro= Received: from MN2PR12MB3966.namprd12.prod.outlook.com (2603:10b6:208:165::18) by BY5PR12MB4950.namprd12.prod.outlook.com (2603:10b6:a03:1d9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.30; Sat, 15 Oct 2022 15:50:02 +0000 Received: from MN2PR12MB3966.namprd12.prod.outlook.com ([fe80::2eab:b851:827c:1d88]) by MN2PR12MB3966.namprd12.prod.outlook.com ([fe80::2eab:b851:827c:1d88%3]) with mapi id 15.20.5723.030; Sat, 15 Oct 2022 15:50:02 +0000 From: "Chang, Abner" To: "devel@edk2.groups.io" , "sunilvl@ventanamicro.com" CC: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann , "Singh, Brijesh" , Erdem Aktas , James Bottomley , Min Xu , "Lendacky, Thomas" , Daniel Schaefer Subject: Re: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V4 10/34] OvmfPkg/Sec: Add RISC-V support Thread-Topic: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V4 10/34] OvmfPkg/Sec: Add RISC-V support Thread-Index: AQHY3+z9gH9eEatOzk2KHOKFja6LAK4PmCsw Date: Sat, 15 Oct 2022 15:50:02 +0000 Message-ID: References: <20221014164836.1513036-1-sunilvl@ventanamicro.com> <20221014164836.1513036-11-sunilvl@ventanamicro.com> In-Reply-To: <20221014164836.1513036-11-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-15T15:49:58Z; 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=7fba0dcb-0ea9-4bb0-934f-3b15adc145d1; 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_|BY5PR12MB4950:EE_ x-ms-office365-filtering-correlation-id: ff1dc9dc-1389-4733-8efc-08daaec4ec3d x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: DIYKMy41tXsvGUa7jA3t6bbAG7d7aJ949pC3cAoi4x+BtXKolgUEWEIS1OLdhnvTau5M3BK6207UGWrODFzfnxOj2pY/ismVI8CFr/udgm4uNMa92eUuF562fZqPpkzxjgK6jfHkte2nBHl+udBoBNN4M4kQFE4qnz244XRifh5rpvusz8ka8GePZ3E0e7nM/OvkVtHKKnINNCxnTJNIemORMHVoeQBenhGu32+CRIvGufd3mxaZAPmDGOiyM87xusj6E+iCtAv8vopVG4HvNV5o0KJpHCX24KtUZFxHRWa03suy1jfzC16Fg/W1wOwp+IB/9e9XFDPrExigRmyJrsWZRsyfqFPANHQXH2fz9RS6uultOjWyr+PhpGZDhjVE/acYI5IjWyJPVC4lVKemqlvIKKPZmVFZjXSc3WYfjnC3H9qW95lp0UxOHao0Yg+ssVc02sB7aKv5MIUC5yHXWEoUlfwkFz3IGkuj2iffDGR7YlThTXCAv3nFZNidJ5Bscc0HNqZY+gui040yoqQ0IoKatoROViEMYR+/SBv2Icdb4Ueb+6lRy9N8duz0T+Hk5tIX+/qPsLM4t1k9bUa9S/YYZsAFso/zuyE7D4DK+aqrY3+dqYq8dWrKkGz/2nzlKMk81WbIS9TNEmcrqZgbD/aozs2XW/igzz/P7iVu8ZlQN3ZWtGI54pwFLGkUH27ng9BT96zLK8XztVKmKkbD8YKxS7lk1mpLVz2JYckNcq8M6IiREiYB8NEtzrWE7XCVBk/RV//Hqald1nsrayCWTiJ7P+We0ni3mjRswxXQmNMaEgtDcA6yyDysrmo2vfjX6+PJtE21B6V9rhgsb8ICDw== 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)(39850400004)(396003)(346002)(376002)(366004)(136003)(451199015)(5660300002)(19627235002)(30864003)(316002)(76116006)(66946007)(66899015)(54906003)(110136005)(64756008)(66446008)(66476007)(66556008)(4326008)(8676002)(7696005)(41300700001)(9686003)(53546011)(26005)(6506007)(8936002)(2906002)(52536014)(966005)(71200400001)(7416002)(186003)(83380400001)(38070700005)(45080400002)(38100700002)(478600001)(122000001)(86362001)(55016003)(33656002)(579004)(559001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?6WnoOG2j02KepXwVi6D7FT69f5ptHoBN/6Kp+SC87jpAqAPRULcxTrqqR26k?= =?us-ascii?Q?11s/efQ2FOO6JA32rOnNNJyoi+o5qHBq3jIiWZDz/EcIqQWY9hCHNFrrI0SG?= =?us-ascii?Q?72LJGoW9H+ZC2s/6mZ2hRFU2eIo/QRXXBqX8LpesbVZKZmym+A86ame7rgNo?= =?us-ascii?Q?TK6ymyjQf7ZOG2ua/CKmDXijYNI2jn87+u6FF3zWZN4gBwj9sTrpskZzlro0?= =?us-ascii?Q?HU3V9LVvHjGdjwmgRSilrCldXQD235L6JVnOloYr0+abBhTtOPxmxnyfw9nS?= =?us-ascii?Q?ynLie9u1qyDS7ARDe7pHa6hTf97AuppLlBzSJ2q+gGBRnu7O69k7QDsQ6xur?= =?us-ascii?Q?KgKcqE6kK2QVtlE/2Kgik8L4uWG8608oBsixjcG+dQErRqI6Be9T9OHZXSfT?= =?us-ascii?Q?JSCvEvAwIusMBcQY0AJe8/GgGp/ezG5uTBwXnKBJPklLm9/EROZ4US41VgCR?= =?us-ascii?Q?nvn6D9Yuorvv4NHUoMJSgcuigyFKbrlcDYqLwz1HFikP+Ae+t4w2agZ97y1B?= =?us-ascii?Q?TRQ5Z+eOtCFGaFFDjZxZ8KBjOJB7AwbHlk14wYy7iT10GY4RwC3ALvxCdCgB?= =?us-ascii?Q?sLAgje2GzuQ5cb8DIaRr5nrR+iC3rmc8yS3hRND5R8fH9Fm3xRhd3mre96D8?= =?us-ascii?Q?aamx3vU3CfbgbyYcK7dUJHkAbLerEfEl2U5bTcFk2r4YIe9hLHw7bAj2F75h?= =?us-ascii?Q?XQGjFpwD8SB6fWNMTByxGCbYcBNhlGUDsIwL545e0k9Aa/nB1cQS4apmeDDC?= =?us-ascii?Q?nD2eOkdxTsFQ/AI2IyYE09ua4tu/L/aY7wtoNo8YwRPUEg8hdICxnxYW239K?= =?us-ascii?Q?Dbpi2HGclCji1G0ZJ5kgHH7DlMEuMTvpXxn0cgS4yHpaKcj339aW3c419jzq?= =?us-ascii?Q?u3YOJ+ri9laqglDHBSUEAT7OS/rLSoY+Sd8pm4HW96bmBm5Bcbv6YL12IyFe?= =?us-ascii?Q?rXY509GGx6vbUa8g+V1a/pqPFuHIoN7Im0Z9PAwDDkA0xdvLS1eX+UpHwJn0?= =?us-ascii?Q?l1K5G7hFzeetU535enhPyjUX2Q4+2Oex07Qec5nX50+ANybirlPujxfn/zr7?= =?us-ascii?Q?BeIVfzXgUjC4qA9mBlmeZG5VmY3EUdHsz5FpwBc/w3yOcW6zPS+cGX7/Ycrt?= =?us-ascii?Q?o6VsZN7UxHB0GTbaxyAtJlUfwRUEH1XoRkABeJI4ea1kBNCUPcmoI/cpq32R?= =?us-ascii?Q?AcZEOBIzMHWelUIaZwGyv+TDE4lSvHJaJ/sIJXemsOl9YkcWRsdrfKldaZQj?= =?us-ascii?Q?6WjoXAwv0nsV21lX0NjpaTpYhhpMhkPLZisIX5R111qF/44jgtjrDCFVAZEw?= =?us-ascii?Q?eBd7rKJn/KjHvtHWiwyKpve2mtxIxSFaf+RsQwDSNOCPwoyC5yQhYELQWPX6?= =?us-ascii?Q?BFinB34Wp51FYc70YZ6hTIGjwVtQV/blOIMP3WeD+RqM0TT47NoiHNmHgLTW?= =?us-ascii?Q?TEKs2Nyle1Rcvn+TdyRfgJlG27z7NKqTzTlEsIwrNu01T+93hY89XyHVs/+2?= =?us-ascii?Q?1pQrfoLyuZAu5kKqe2TOw4RpP9S9RsX2AHzS9syH8GSy0la5UMvhHyOdDMNE?= =?us-ascii?Q?0Wqh+KgtXyxTYyXjULMHM48mAG+rIdLoInVdRfgE?= 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: ff1dc9dc-1389-4733-8efc-08daaec4ec3d X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Oct 2022 15:50:02.6314 (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: TQrvtjUPeAOITzWFCZNbO3XbSo25LccLLjb4puTH12w+GU9NC+RYXw/HMIubM6tD1EbM+1zLK2lrge0YgL7ZuQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4950 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable [AMD Official Use Only - General] Hi Sunil, this is my comment for both 9/34 and 10/34. The original RISC-V SecCore implementation can be used by RiscVVirt and the= RISC-V platforms under edk2-platform. So my plan back to half year ago was= to have SecCore under UefiCpuPkg, that would be Riscv64SecCore because cur= rent the SecCore under UeficpuPkg is hard to be leveraged. With this, one R= ISC-V SecCore driver can be used by RiscVVirt and RISC-V platforms. Of cour= se we have to move some Pcds to under PCD Riscv64 arch section in UEfiCpuPk= g.dec. Even through having PcdRiscVDbtFvBase(Size) for Riscv64 in UefiCpuPk= g.dec makes sense to me because Device Tree is part of RISC-V processor ini= tialization. Could you please take some time having this change? I think that is doable = and also an ideal implementation for RISC-V. Thanks Abner > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Sunil V L > via groups.io > Sent: Saturday, October 15, 2022 12:48 AM > To: devel@edk2.groups.io > Cc: Ard Biesheuvel ; Jiewen Yao > ; Jordan Justen ; Gerd > Hoffmann ; Singh, Brijesh ; > Erdem Aktas ; James Bottomley > ; Min Xu ; Lendacky, Thomas > ; Daniel Schaefer > Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V4 10/34] > OvmfPkg/Sec: Add RISC-V support >=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%7C531c5e6ae7be49f75fc008daae041e9f%7C3dd896 > 1fe4884e608e11a82d994e183d%7C0%7C0%7C638013629969623115%7CUnkn > own%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik > 1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=3DwfVgOCUv%2BI > KWfjGVItYwRLB8owJ6Q3h2qs4NanLnSAU%3D&reserved=3D0 >=20 > Add the SEC module for RISC-V. EDK2 is launched as the payload for machin= e > mode firmware in RISC-V. >=20 > Cc: Ard Biesheuvel > Cc: Jiewen Yao > Cc: Jordan Justen > Cc: Gerd Hoffmann > Cc: Brijesh Singh > Cc: Erdem Aktas > Cc: James Bottomley > Cc: Min Xu > Cc: Tom Lendacky > Cc: Daniel Schaefer > Signed-off-by: Sunil V L > --- > OvmfPkg/Sec/SecMain.inf | 16 +- > OvmfPkg/Sec/RiscV64/SecMain.h | 65 +++ > OvmfPkg/Sec/RiscV64/SecMain.c | 573 ++++++++++++++++++++ > OvmfPkg/Sec/RiscV64/SecEntry.S | 23 + > 4 files changed, 676 insertions(+), 1 deletion(-) >=20 > diff --git a/OvmfPkg/Sec/SecMain.inf b/OvmfPkg/Sec/SecMain.inf index > a014bcb4cf1a..96fcc464c0d5 100644 > --- a/OvmfPkg/Sec/SecMain.inf > +++ b/OvmfPkg/Sec/SecMain.inf > @@ -18,7 +18,7 @@ [Defines] > # > # The following information is for reference only and not required by th= e > build tools. > # > -# VALID_ARCHITECTURES =3D IA32 X64 EBC > +# VALID_ARCHITECTURES =3D IA32 X64 EBC RISCV64 > # >=20 > [Sources.IA32, Sources.X64] > @@ -34,6 +34,13 @@ [Sources.IA32] > [Sources.X64] > X64/SecEntry.nasm >=20 > +[Sources.RISCV64] > + SecMainCommon.c > + SecMainCommon.h > + RiscV64/SecEntry.S > + RiscV64/SecMain.c > + RiscV64/SecMain.h > + > [Packages] > MdePkg/MdePkg.dec > MdeModulePkg/MdeModulePkg.dec > @@ -61,11 +68,17 @@ [LibraryClasses.IA32, LibraryClasses.X64] > PeiServicesLib > CcProbeLib >=20 > +[LibraryClasses.RISCV64] > + RiscVSbiLib > + > [Ppis] > gEfiTemporaryRamSupportPpiGuid # PPI ALWAYS_PRODUCED > gEfiPeiMpInitLibMpDepPpiGuid > gEfiPeiMpInitLibUpDepPpiGuid >=20 > +[Ppis.RISCV64] > + gEfiTemporaryRamDonePpiGuid ## PRODUCES > + > [Pcd] > gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase > gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase > @@ -88,6 +101,7 @@ [Pcd] > gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupBase > gUefiOvmfPkgTokenSpaceGuid.PcdTdxAcceptPageSize > gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase > + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress >=20 > [FeaturePcd] > gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire > diff --git a/OvmfPkg/Sec/RiscV64/SecMain.h > b/OvmfPkg/Sec/RiscV64/SecMain.h new file mode 100644 index > 000000000000..11e3daa090b5 > --- /dev/null > +++ b/OvmfPkg/Sec/RiscV64/SecMain.h > @@ -0,0 +1,65 @@ > +/** @file > + Master header file for SecCore. > + > + Copyright (c) 2019-2022, Hewlett Packard Enterprise Development LP. > + All rights reserved.
Copyright (c) 2022, Ventana Micro Systems > + Inc. All rights reserved.
> + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#ifndef _SEC_MAIN_H_ > +#define _SEC_MAIN_H_ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include #include > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include #include > + #include > + > +#include "SecMainCommon.h" > + > +/** > + Entry point to the C language phase of SEC. After the SEC assembly > + code has initialized some temporary memory and set up the stack, > + the control is transferred to this function. > + > + @param SizeOfRam Size of the temporary memory available for = use. > + @param TempRamBase Base address of temporary ram > + @param BootFirmwareVolume Base address of the Boot Firmware > Volume. > +**/ > +VOID > +NORETURN > +EFIAPI > +SecStartup ( > + IN UINTN BootHartId, > + IN VOID *DeviceTreeAddress > + ); > + > +/** > + Auto-generated function that calls the library constructors for all > +of the module's > + dependent libraries. This function must be called by the SEC Core > +once a stack has > + been established. > + > +**/ > +VOID > +EFIAPI > +ProcessLibraryConstructorList ( > + VOID > + ); > + > +#endif > diff --git a/OvmfPkg/Sec/RiscV64/SecMain.c > b/OvmfPkg/Sec/RiscV64/SecMain.c new file mode 100644 index > 000000000000..c8c852714a32 > --- /dev/null > +++ b/OvmfPkg/Sec/RiscV64/SecMain.c > @@ -0,0 +1,573 @@ > +/** @file > + RISC-V SEC phase module. > + > + Copyright (c) 2008 - 2015, Intel Corporation. All rights > + reserved.
Copyright (c) 2022, Ventana Micro Systems Inc. All > + rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include "SecMain.h" > + > +EFI_STATUS > +EFIAPI > +TemporaryRamMigration ( > + IN CONST EFI_PEI_SERVICES **PeiServices, > + IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, > + IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, > + IN UINTN CopySize > + ); > + > +EFI_STATUS > +EFIAPI > +TemporaryRamDone ( > + VOID > + ); > + > +STATIC EFI_PEI_TEMPORARY_RAM_SUPPORT_PPI > mTemporaryRamSupportPpi =3D { > + TemporaryRamMigration > +}; > + > +STATIC EFI_PEI_TEMPORARY_RAM_DONE_PPI mTemporaryRamDonePpi =3D > { > + TemporaryRamDone > +}; > + > +STATIC EFI_PEI_PPI_DESCRIPTOR mPrivateDispatchTable[] =3D { > + { > + EFI_PEI_PPI_DESCRIPTOR_PPI, > + &gEfiTemporaryRamSupportPpiGuid, > + &mTemporaryRamSupportPpi > + }, > + { > + (EFI_PEI_PPI_DESCRIPTOR_PPI | > EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), > + &gEfiTemporaryRamDonePpiGuid, > + &mTemporaryRamDonePpi > + }, > +}; > + > +/** Temporary RAM migration function. > + > + This function migrates the data from temporary RAM to permanent > + memory. > + > + @param[in] PeiServices PEI service > + @param[in] TemporaryMemoryBase Temporary memory base address > + @param[in] PermanentMemoryBase Permanent memory base address > + @param[in] CopySize Size to copy > + > +**/ > +EFI_STATUS > +EFIAPI > +TemporaryRamMigration ( > + IN CONST EFI_PEI_SERVICES **PeiServices, > + IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, > + IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, > + IN UINTN CopySize > + ) > +{ > + VOID *OldHeap; > + VOID *NewHeap; > + VOID *OldStack; > + VOID *NewStack; > + EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext; > + > + DEBUG (( > + DEBUG_INFO, > + "%a: Temp Mem Base:0x%Lx, Permanent Mem Base:0x%Lx, > CopySize:0x%Lx\n", > + __FUNCTION__, > + TemporaryMemoryBase, > + PermanentMemoryBase, > + (UINT64)CopySize > + )); > + > + OldHeap =3D (VOID *)(UINTN)TemporaryMemoryBase; NewHeap =3D (VOID > + *)((UINTN)PermanentMemoryBase + (CopySize >> 1)); > + > + OldStack =3D (VOID *)((UINTN)TemporaryMemoryBase + (CopySize >> 1)); > + NewStack =3D (VOID *)(UINTN)PermanentMemoryBase; > + > + CopyMem (NewHeap, OldHeap, CopySize >> 1); // Migrate Heap > + CopyMem (NewStack, OldStack, CopySize >> 1); // Migrate Stack > + > + // > + // Reset firmware context pointer > + // > + GetFirmwareContextPointer (&FirmwareContext); FirmwareContext =3D > + (VOID *)FirmwareContext + (unsigned long)((UINTN)NewStack - > + (UINTN)OldStack); SetFirmwareContextPointer (FirmwareContext); > + > + DEBUG ((DEBUG_INFO, "%a: Firmware Context is relocated to 0x%x\n", > + __FUNCTION__, FirmwareContext)); > + > + register UINTN a0 asm ("a0") =3D (UINTN)((UINTN)NewStack - > + (UINTN)OldStack); > + > + asm volatile ("add sp, sp, a0"::"r"(a0):); > + return EFI_SUCCESS; > +} > + > +/** Temprary RAM done function. > + > +**/ > +EFI_STATUS EFIAPI > +TemporaryRamDone ( > + VOID > + ) > +{ > + DEBUG ((DEBUG_INFO, "%a: 2nd time PEI core, temporary ram done.\n", > +__FUNCTION__)); > + return EFI_SUCCESS; > +} > + > +/** Return platform SEC PPI before PEI Core > + > + @param[in,out] ThisPpiList Pointer to retrieve EFI_PEI_PPI_DESCRIPT= OR. > + > +**/ > +STATIC EFI_STATUS > +GetPlatformPrePeiCorePpiDescriptor ( > + IN OUT EFI_PEI_PPI_DESCRIPTOR **ThisPpiList > + ) > +{ > + *ThisPpiList =3D mPrivateDispatchTable; > + return EFI_SUCCESS; > +} > + > +/** > + Locates the main boot firmware volume. > + > + @param[in,out] BootFv On input, the base of the BootFv > + On output, the decompressed main firmware > + volume > + > + @retval EFI_SUCCESS The main firmware volume was located and > decompressed > + @retval EFI_NOT_FOUND The main firmware volume was not found > + > +**/ > +EFI_STATUS > +FindMainFv ( > + IN OUT EFI_FIRMWARE_VOLUME_HEADER **BootFv > + ) > +{ > + EFI_FIRMWARE_VOLUME_HEADER *Fv; > + UINTN Distance; > + > + ASSERT (((UINTN)*BootFv & EFI_PAGE_MASK) =3D=3D 0); > + > + Fv =3D *BootFv; > + Distance =3D (UINTN)(*BootFv)->FvLength; do { > + Fv =3D (EFI_FIRMWARE_VOLUME_HEADER *)((UINT8 *)Fv + > EFI_PAGE_SIZE); > + Distance +=3D EFI_PAGE_SIZE; > + if (Distance > SIZE_32MB) { > + return EFI_NOT_FOUND; > + } > + > + if (Fv->Signature !=3D EFI_FVH_SIGNATURE) { > + continue; > + } > + > + if ((UINTN)Fv->FvLength < Distance) { > + continue; > + } > + > + *BootFv =3D Fv; > + return EFI_SUCCESS; > + } while (TRUE); > +} > + > +/** > + Locates the compressed main firmware volume and decompresses it. > + > + @param[in,out] Fv On input, the firmware volume to search > + On output, the decompressed BOOT/PEI FV > + > + @retval EFI_SUCCESS The file and section was found > + @retval EFI_NOT_FOUND The file and section was not found > + @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted > + > +**/ > +EFI_STATUS > +DecompressMemFvs ( > + IN OUT EFI_FIRMWARE_VOLUME_HEADER **Fv > + ) > +{ > + EFI_STATUS Status; > + EFI_GUID_DEFINED_SECTION *Section; > + UINT32 OutputBufferSize; > + UINT32 ScratchBufferSize; > + UINT16 SectionAttribute; > + UINT32 AuthenticationStatus; > + VOID *OutputBuffer; > + VOID *ScratchBuffer; > + EFI_COMMON_SECTION_HEADER *FvSection; > + EFI_FIRMWARE_VOLUME_HEADER *PeiMemFv; > + EFI_FIRMWARE_VOLUME_HEADER *DxeMemFv; > + UINT32 FvHeaderSize; > + UINT32 FvSectionSize; > + > + FvSection =3D (EFI_COMMON_SECTION_HEADER *)NULL; > + > + Status =3D FindFfsFileAndSection ( > + *Fv, > + EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE, > + EFI_SECTION_GUID_DEFINED, > + (EFI_COMMON_SECTION_HEADER **)&Section > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Unable to find GUID defined section\n")); > + return Status; > + } > + > + Status =3D ExtractGuidedSectionGetInfo ( > + Section, > + &OutputBufferSize, > + &ScratchBufferSize, > + &SectionAttribute > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Unable to GetInfo for GUIDed section\n")); > + return Status; > + } > + > + OutputBuffer =3D (VOID *)((UINT8 *)(UINTN)PcdGet32 > + (PcdOvmfDxeMemFvBase) + SIZE_1MB); ScratchBuffer =3D ALIGN_POINTER > + ((UINT8 *)OutputBuffer + OutputBufferSize, SIZE_1MB); > + > + Status =3D ExtractGuidedSectionDecode ( > + Section, > + &OutputBuffer, > + ScratchBuffer, > + &AuthenticationStatus > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Error during GUID section decode\n")); > + return Status; > + } > + > + Status =3D FindFfsSectionInstance ( > + OutputBuffer, > + OutputBufferSize, > + EFI_SECTION_FIRMWARE_VOLUME_IMAGE, > + 0, > + &FvSection > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Unable to find PEI FV section\n")); > + return Status; > + } > + > + ASSERT ( > + SECTION_SIZE (FvSection) =3D=3D > + (PcdGet32 (PcdOvmfPeiMemFvSize) + sizeof (*FvSection)) > + ); > + ASSERT (FvSection->Type =3D=3D EFI_SECTION_FIRMWARE_VOLUME_IMAGE); > + > + PeiMemFv =3D (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 > + (PcdOvmfPeiMemFvBase); CopyMem (PeiMemFv, (VOID *)(FvSection + 1), > + PcdGet32 (PcdOvmfPeiMemFvSize)); > + > + if (PeiMemFv->Signature !=3D EFI_FVH_SIGNATURE) { > + DEBUG ((DEBUG_ERROR, "Extracted FV at %p does not have FV header > signature\n", PeiMemFv)); > + CpuDeadLoop (); > + return EFI_VOLUME_CORRUPTED; > + } > + > + Status =3D FindFfsSectionInstance ( > + OutputBuffer, > + OutputBufferSize, > + EFI_SECTION_FIRMWARE_VOLUME_IMAGE, > + 1, > + &FvSection > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Unable to find DXE FV section\n")); > + return Status; > + } > + > + ASSERT (FvSection->Type =3D=3D EFI_SECTION_FIRMWARE_VOLUME_IMAGE); > + > + if (IS_SECTION2 (FvSection)) { > + FvSectionSize =3D SECTION2_SIZE (FvSection); > + FvHeaderSize =3D sizeof (EFI_COMMON_SECTION_HEADER2); } else { > + FvSectionSize =3D SECTION_SIZE (FvSection); > + FvHeaderSize =3D sizeof (EFI_COMMON_SECTION_HEADER); } > + > + ASSERT (FvSectionSize =3D=3D (PcdGet32 (PcdOvmfDxeMemFvSize) + > + FvHeaderSize)); > + > + DxeMemFv =3D (EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 > + (PcdOvmfDxeMemFvBase); CopyMem (DxeMemFv, (VOID > *)((UINTN)FvSection + > + FvHeaderSize), PcdGet32 (PcdOvmfDxeMemFvSize)); > + > + if (DxeMemFv->Signature !=3D EFI_FVH_SIGNATURE) { > + DEBUG ((DEBUG_ERROR, "Extracted FV at %p does not have FV header > signature\n", DxeMemFv)); > + CpuDeadLoop (); > + return EFI_VOLUME_CORRUPTED; > + } > + > + *Fv =3D PeiMemFv; > + return EFI_SUCCESS; > +} > + > +/** > + Locates the PEI Core entry point address > + > + @param[in,out] Fv The firmware volume to search > + @param[out] PeiCoreEntryPoint The entry point of the PEI Core ima= ge > + > + @retval EFI_SUCCESS The file and section was found > + @retval EFI_NOT_FOUND The file and section was not found > + @retval EFI_VOLUME_CORRUPTED The firmware volume was corrupted > + > +**/ > +VOID > +FindPeiCoreImageBase ( > + IN OUT EFI_FIRMWARE_VOLUME_HEADER **BootFv, > + OUT EFI_PHYSICAL_ADDRESS *PeiCoreImageBase > + ) > +{ > + *PeiCoreImageBase =3D 0; > + > + FindMainFv (BootFv); > + > + DecompressMemFvs (BootFv); > + > + FindPeiCoreImageBaseInFv (*BootFv, PeiCoreImageBase); } > + > +/** > + Find core image base. > + > +**/ > +EFI_STATUS > +FindImageBase ( > + IN EFI_FIRMWARE_VOLUME_HEADER *BootFirmwareVolumePtr, > + OUT EFI_PHYSICAL_ADDRESS *SecCoreImageBase > + ) > +{ > + EFI_PHYSICAL_ADDRESS CurrentAddress; > + EFI_PHYSICAL_ADDRESS EndOfFirmwareVolume; > + EFI_FFS_FILE_HEADER *File; > + UINT32 Size; > + EFI_PHYSICAL_ADDRESS EndOfFile; > + EFI_COMMON_SECTION_HEADER *Section; > + EFI_PHYSICAL_ADDRESS EndOfSection; > + > + *SecCoreImageBase =3D 0; > + > + CurrentAddress =3D > (EFI_PHYSICAL_ADDRESS)(UINTN)BootFirmwareVolumePtr; > + EndOfFirmwareVolume =3D CurrentAddress + > + BootFirmwareVolumePtr->FvLength; > + > + // > + // Loop through the FFS files in the Boot Firmware Volume // for > + (EndOfFile =3D CurrentAddress + BootFirmwareVolumePtr->HeaderLength; ; = ) > { > + CurrentAddress =3D (EndOfFile + 7) & 0xfffffffffffffff8ULL; > + if (CurrentAddress > EndOfFirmwareVolume) { > + return EFI_NOT_FOUND; > + } > + > + File =3D (EFI_FFS_FILE_HEADER *)(UINTN)CurrentAddress; > + Size =3D FFS_FILE_SIZE (File); > + if (Size < sizeof (*File)) { > + return EFI_NOT_FOUND; > + } > + > + EndOfFile =3D CurrentAddress + Size; > + if (EndOfFile > EndOfFirmwareVolume) { > + return EFI_NOT_FOUND; > + } > + > + // > + // Look for SEC Core > + // > + if (File->Type !=3D EFI_FV_FILETYPE_SECURITY_CORE) { > + continue; > + } > + > + // > + // Loop through the FFS file sections within the FFS file > + // > + EndOfSection =3D (EFI_PHYSICAL_ADDRESS)(UINTN)(File + 1); > + for ( ; ;) { > + CurrentAddress =3D (EndOfSection + 3) & 0xfffffffffffffffcULL; > + Section =3D (EFI_COMMON_SECTION_HEADER > *)(UINTN)CurrentAddress; > + > + Size =3D SECTION_SIZE (Section); > + if (Size < sizeof (*Section)) { > + return EFI_NOT_FOUND; > + } > + > + EndOfSection =3D CurrentAddress + Size; > + if (EndOfSection > EndOfFile) { > + return EFI_NOT_FOUND; > + } > + > + // > + // Look for executable sections > + // > + if ((Section->Type =3D=3D EFI_SECTION_PE32) || (Section->Type =3D= =3D > EFI_SECTION_TE)) { > + if (File->Type =3D=3D EFI_FV_FILETYPE_SECURITY_CORE) { > + *SecCoreImageBase =3D (PHYSICAL_ADDRESS)(UINTN)(Section + 1); > + } > + > + break; > + } > + } > + > + // > + // SEC Core image found > + // > + if (*SecCoreImageBase !=3D 0) { > + return EFI_SUCCESS; > + } > + } > +} > + > +/* > + Find and return Pei Core entry point. > + > + It also find SEC and PEI Core file debug information. It will report > + them if remote debug is enabled. > + > +**/ > +VOID > +FindAndReportEntryPoints ( > + IN EFI_FIRMWARE_VOLUME_HEADER **BootFirmwareVolumePtr, > + OUT EFI_PEI_CORE_ENTRY_POINT *PeiCoreEntryPoint > + ) > +{ > + EFI_STATUS Status; > + EFI_PHYSICAL_ADDRESS SecCoreImageBase; > + EFI_PHYSICAL_ADDRESS PeiCoreImageBase; > + PE_COFF_LOADER_IMAGE_CONTEXT ImageContext; > + > + // > + // Find SEC Core and PEI Core image base // Status =3D FindImageBase > + (*BootFirmwareVolumePtr, &SecCoreImageBase); ASSERT_EFI_ERROR > + (Status); > + > + FindPeiCoreImageBase (BootFirmwareVolumePtr, &PeiCoreImageBase); > + > + ZeroMem ((VOID *)&ImageContext, sizeof > + (PE_COFF_LOADER_IMAGE_CONTEXT)); // // Report SEC Core debug > + information when remote debug is enabled // > + ImageContext.ImageAddress =3D SecCoreImageBase; > + ImageContext.PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID > *)(UINTN)ImageContext.ImageAddress); > + PeCoffLoaderRelocateImageExtraAction (&ImageContext); > + > + // > + // Report PEI Core debug information when remote debug is enabled // > + ImageContext.ImageAddress =3D > (EFI_PHYSICAL_ADDRESS)(UINTN)PeiCoreImageBase; > + ImageContext.PdbPointer =3D PeCoffLoaderGetPdbPointer ((VOID > *)(UINTN)ImageContext.ImageAddress); > + PeCoffLoaderRelocateImageExtraAction (&ImageContext); > + > + // > + // Find PEI Core entry point > + // > + Status =3D PeCoffLoaderGetEntryPoint ((VOID *)(UINTN)PeiCoreImageBase, > + (VOID **)PeiCoreEntryPoint); if (EFI_ERROR (Status)) { > + *PeiCoreEntryPoint =3D 0; > + } > + > + return; > +} > + > +/** > + > + Entry point to the C language phase of SEC. After the SEC assembly > + code has initialized some temporary memory and set up the stack, the > + control is transferred to this function. > + > + > + @param[in] BootHartId Hardware thread ID of boot hart. > + @param[in] DeviceTreeAddress Pointer to Device Tree (DTB) **/ VOID > +NORETURN EFIAPI SecStartup ( > + IN UINTN BootHartId, > + IN VOID *DeviceTreeAddress > + ) > +{ > + EFI_RISCV_FIRMWARE_CONTEXT FirmwareContext; > + EFI_FIRMWARE_VOLUME_HEADER *BootFv; > + EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint; > + EFI_PEI_PPI_DESCRIPTOR *PpiList; > + EFI_SEC_PEI_HAND_OFF SecCoreData; > + EFI_STATUS Status; > + > + // > + // Report Status Code to indicate entering SEC core // DEBUG (( > + DEBUG_INFO, > + "%a() BootHartId: 0x%x, DeviceTreeAddress=3D0x%x\n", > + __FUNCTION__, > + BootHartId, > + DeviceTreeAddress > + )); > + > + // > + // Process all libraries constructor function linked to SecCore. > + // > + ProcessLibraryConstructorList (); > + > + BootFv =3D (EFI_FIRMWARE_VOLUME_HEADER *)FixedPcdGet32 > + (PcdOvmfFdBaseAddress); > + > + ASSERT (BootFv !=3D NULL); > + SecCoreData.DataSize =3D (UINT16)sizeof (EFI_SEC_PEI_HAN= D_OFF); > + SecCoreData.BootFirmwareVolumeBase =3D BootFv; > + SecCoreData.BootFirmwareVolumeSize =3D (UINTN)BootFv->FvLength; > + SecCoreData.TemporaryRamBase =3D (VOID *)(UINT64)FixedPcdGet32 > (PcdOvmfSecPeiTempRamBase); > + SecCoreData.TemporaryRamSize =3D (UINTN)FixedPcdGet32 > (PcdOvmfSecPeiTempRamSize); > + SecCoreData.PeiTemporaryRamBase =3D SecCoreData.TemporaryRamBase; > + SecCoreData.PeiTemporaryRamSize =3D SecCoreData.TemporaryRamSize > >> 1; > + SecCoreData.StackBase =3D (UINT8 > *)SecCoreData.TemporaryRamBase + (SecCoreData.TemporaryRamSize >> > 1); > + SecCoreData.StackSize =3D SecCoreData.TemporaryRamSize >>= 1; > + > + DEBUG (( > + DEBUG_INFO, > + "%a() BFV Base: 0x%x, BFV Size: 0x%x, TempRAM Base: 0x%x, TempRAM > Size: 0x%x, PeiTempRamBase: 0x%x, PeiTempRamSize: 0x%x, StackBase: > 0x%x, StackSize: 0x%x\n", > + __FUNCTION__, > + SecCoreData.BootFirmwareVolumeBase, > + SecCoreData.BootFirmwareVolumeSize, > + SecCoreData.TemporaryRamBase, > + SecCoreData.TemporaryRamSize, > + SecCoreData.PeiTemporaryRamBase, > + SecCoreData.PeiTemporaryRamSize, > + SecCoreData.StackBase, > + SecCoreData.StackSize > + )); > + > + FindAndReportEntryPoints ( > + &BootFv, > + &PeiCoreEntryPoint > + ); > + if (PeiCoreEntryPoint =3D=3D NULL) { > + CpuDeadLoop (); > + } > + > + SecCoreData.BootFirmwareVolumeBase =3D BootFv; > + SecCoreData.BootFirmwareVolumeSize =3D (UINTN)BootFv->FvLength; > + > + Status =3D GetPlatformPrePeiCorePpiDescriptor (&PpiList); if > + (EFI_ERROR (Status)) { > + PpiList =3D NULL; > + } > + > + FirmwareContext.BootHartId =3D BootHartId; > + FirmwareContext.FlattenedDeviceTree =3D (UINT64)DeviceTreeAddress; > + SetFirmwareContextPointer (&FirmwareContext); > + > + // > + // Transfer the control to the PEI core // ASSERT > + (PeiCoreEntryPoint !=3D NULL); (*PeiCoreEntryPoint)(&SecCoreData, > + PpiList); > + > + // > + // Should not come here. > + // > + UNREACHABLE (); > +} > diff --git a/OvmfPkg/Sec/RiscV64/SecEntry.S > b/OvmfPkg/Sec/RiscV64/SecEntry.S new file mode 100644 index > 000000000000..d201e9f8a608 > --- /dev/null > +++ b/OvmfPkg/Sec/RiscV64/SecEntry.S > @@ -0,0 +1,23 @@ > +/* > + Copyright (c) 2021-2022 , Hewlett Packard Enterprise Development LP. A= ll > rights reserved. > + Copyright (c) 2019 Western Digital Corporation or its affiliates. > + Copyright (c) 2022 Ventana Micro Systems Inc. > + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > + */ > + > +#include "SecMain.h" > + > +.text > +.align 3 > + > +ASM_FUNC (_ModuleEntryPoint) > + /* Use Temp memory as the stack for calling to C code */ > + li a4, FixedPcdGet32 (PcdOvmfSecPeiTempRamBase) > + li a5, FixedPcdGet32 (PcdOvmfSecPeiTempRamSize) > + > + /* Use Temp memory as the stack for calling to C code */ > + add sp, a4, a5 > + > + call SecStartup > -- > 2.38.0 >=20 >=20 >=20 >=20 >=20