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.80]) by mx.groups.io with SMTP id smtpd.web08.39697.1666006337003870327 for ; Mon, 17 Oct 2022 04:32:17 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=Rdwp4XrI; 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.80, mailfrom: abner.chang@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hJ+R75NTSvwtqzAuMLhjfwxnpVRYxWgLYWRpFM5xYedDwlmnZjbk63H+Ba+NdiWBkauIHbnDw//WqZnrARE5JKfXeFPE3dl5vF1hiuL3hbxHOx6lxoFh7mKUmSDriDFiajtNnMolYpfRQcKUTYqi6ePCvCHi4DTOKip8x3/xOpdZwCUGIMU5o9v139jsFhKGXOHJfnFF1jcIZihOivoZ5RlVftZdBjsDfvuFVe+KY8rKFbXzjOKpBedUyWoyyHwoqkNDDVcLROPHs/x46ny/z8oHAMZ9krz4pih3YClQsC7sCYIzWoxcGl8EyXByreqUDYKiiaZtenI/qJlcQH/+Iw== 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=Oaiw2Wchgpd5EbQjKOtTSHv8vvI5Zw21juT3ypES0jc=; b=GFAEcZg4v6P3bja1nYMaik1hXEOJP4A5YYi9edvG1r2vl/dLoKZNS99HQDD2W8btEbQ+BIwkHKkwPkj3ksf5aM3NMKumM08VL0+ebieWYmW2ybt4hrgvIpZTFULN7lK0brmZiOgHFRyRp2zGUkUo8gEGGDsJGzgk7H4CAZ2nAIrEvnNJVZyqA8+PdR7EanorzalEXLd2Aj3tbH02iBhs6GFRczJRQL9E6pNIosmfIaODgI1Dyz5ba5gXc0ARYsZW/e5Ir3c/v4jnpJL392FNb+9sViexPwnc7VHAm0EVgGYtykWGCZcfdvkwNUEXD5+g9J/ICoIaAUN16TU5zIVZSA== 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=Oaiw2Wchgpd5EbQjKOtTSHv8vvI5Zw21juT3ypES0jc=; b=Rdwp4XrI/avCXY9VKTJT7xV4fpC84jHW/PRFaBJaNf1edj0qN/Xt8fSORzN9b1ZJ4wXGFQwKin5QtZVCQZozuu7FRWSXmp7T/ZGOCdk4w31Gvaj8m1PNYLcBxInAg19M6FT7YpLDJjp9WJ8BfzYNfWtHXPlnCbEqghGt+8xMplg= Received: from MN2PR12MB3966.namprd12.prod.outlook.com (2603:10b6:208:165::18) by PH7PR12MB5687.namprd12.prod.outlook.com (2603:10b6:510:13e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.26; Mon, 17 Oct 2022 11:32:13 +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.033; Mon, 17 Oct 2022 11:32:13 +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+z9gH9eEatOzk2KHOKFja6LAK4SdxdQ Date: Mon, 17 Oct 2022 11:32:13 +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-17T11:32:10Z; 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=2b746425-fe0b-4384-a480-924552cdb33f; 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_|PH7PR12MB5687:EE_ x-ms-office365-filtering-correlation-id: c9ca2676-d88d-42e5-7019-08dab0333cd1 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 4YH3o7+AepoXWWNeMoEc//d6vxyuuw/f0KeVD0gwX7GLhnozZeK6LACsUNIU86ZqX9XG8QTXsDZpmXQYzrXegIkQom/wlzfuf4XMCeev6b4pNsPC7lcmnSpErZ3w9jaz4H7lVqwUqFRZ5hV8NR7GRhCz9TcTwHXNej8RJ3VMHDrN+jjU+e2IIeLNT9QxfYFK3T7MCL/0Ey+Zlq5BOwp3apj0xYLnhi183e4zKbEk3lwf1gulHlFxn6J9iDIEe04QVxtMRK4pPp9XTBvqjnQB/8nAfVYhOADIheIh3+0xuYT3+4UO+PchZMVV6WnA7neJWP67QHdxaKx2pZRFuzS8ChjXpfkUwc38vdcSv71bm5LSeKkZdaGJhmXNw9S3LyBzKd2rDZvCtPdoqfZKQoLmO7mUHpPfsfYp8Rj2JggGArLU8BxNYQOWCBPqMHmrlX4nd0qHw1t4qfgFZfFd1AbwWmHV96UD6ZReTVzAFM8KO5IK0SgdvFdu8vfSHHNpbW00koVr9fxnzS1HXn88xvVXw3fSDHCHQoDtgpINJgarwJEfy6/F9lWRAnpFN9b8h7wICpCNW2EutivuSS1nCsFJ3DzWRMSO0n6UERA1IeBELIMgMvZYEg0/h8CBS8+1FBPJ+JTJXCOpfri1kankntzD8KCyVcivErD06YLBSUKVQ0uKz2IqpPLDT/15bHR2z83Ft+8II8tV+u3XuHy1xD2lyrFZLbwxRVuEUohvhplCHLq0o7CPYXjnkSvz5pMNjqMzGz3u8JACiDfkB3O25OJwKxoSFznmNq+LKQSN5lygRUh25ESWySyDxD2PS6weiB4nTP5wpaCL8dhZGgTNnEXJrg== 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)(346002)(136003)(39860400002)(366004)(396003)(451199015)(54906003)(110136005)(7416002)(5660300002)(30864003)(19627235002)(45080400002)(66946007)(76116006)(66556008)(316002)(66899015)(64756008)(7696005)(6506007)(53546011)(41300700001)(4326008)(478600001)(9686003)(26005)(8676002)(52536014)(66446008)(966005)(71200400001)(2906002)(186003)(8936002)(66476007)(83380400001)(38070700005)(38100700002)(55016003)(86362001)(33656002)(122000001)(559001)(579004);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?jBWVJ2wwkeP/E6LfvSQk+7KhKgVu/3ZlNW5jx384wnULhjKP966JdbGeBAZb?= =?us-ascii?Q?HXwrIDBZ0FnUjGKcrdtxt/JXo2Go3QuwworIgzVKGfG1f8z1hcPkZS2RxcVH?= =?us-ascii?Q?QifmZR/cAWGaGAF5hiUCqETCWMLBwrpnt1vDJvGHs68AomQQdYA7+MQyDBjY?= =?us-ascii?Q?UiMqFzOSsT1nWmHqRP57sIhPy6QlEo4VyO42uR41fb2H+/cDLhxI2oakn6wJ?= =?us-ascii?Q?diAkzTEg9JglgYkRL0cAG+kG29EkyQm5R9AiS2UL1+/66TtrO/OVntp1RyvQ?= =?us-ascii?Q?3UuiXcN8+EPq5iHc2Sbsf6C7vHw4/hgGLPHXsi53U0rl8gB2tIBW59ncA3St?= =?us-ascii?Q?0us4YfiTjQVHxdKh6nRZrpQUua5Da+kALmjS3tsweGpY2Bpol3Dj+7CpLEt7?= =?us-ascii?Q?jekBmetLuJ9K6tQugZVhTrK4RuXRc3ap+Flxb5HVAZRFb30pN4Xirf0nI3+/?= =?us-ascii?Q?j+UXKuwR2RGL5BK6KtuReCcH41jUF7GImRmSESe3JK4fHnT8XGSF6sxvqpKR?= =?us-ascii?Q?zBWSjBO8tWBkRNnx7rpNSHl/kipCdkJ3iC+d0R8FHLulj1JJJz1lR5zoa9XX?= =?us-ascii?Q?pbh6lir6VTANkCsYmF00nHCtvra7ksaV3NCV792N49CTAcJ+rlE1/nC03Pgv?= =?us-ascii?Q?gay3+XIiIDPI2GeOpHSt+i0YUvOMCtRlgKFGKBZH+jAbJT8Hr3qtCEkVuJFN?= =?us-ascii?Q?B1H+6c/7ICgke/AG+Iz2Dh9ZHUOE6OfF6ePCQAi5T1/qnHEK/Xgl2iJHTI3j?= =?us-ascii?Q?tN1E8Ly4toSLoh0ICi3amBvXR+j78VsTWoipH5ti8V27TU1IfF1zXrZAOt4/?= =?us-ascii?Q?8RB04zib95ecVW4D/osB4/eDAAg3JSPi03scVbDrV1Vr816Xi0FkkO/XvbNb?= =?us-ascii?Q?RgwtdkV1baPNbTRkjfQCr1t0oAfyZFmOtGxeq+hXP3WcHsMpEdmNhd7bpbvv?= =?us-ascii?Q?X20nitjLi+i+epQhov49A9iLVYWxrSNt+PEUzywuunARapr93WluPcCcnYd6?= =?us-ascii?Q?FvXTilKczzq0oc6KZGS30FK4Oa0cKBX3Fxb05CE4JpVQPaxSPOq0r5eKqQjL?= =?us-ascii?Q?rtAWlxI/JxFuq4KH9cooLKI2XZImqrvIP7EwOvXN9R3Y2/DXmzpcsmJpUawN?= =?us-ascii?Q?jTl6LQH9ZnjJn5lO7cZLmER+EuPn+rkt1bmEZxa/xY86X0euAYQmEJyGxccX?= =?us-ascii?Q?aadtvAoWROVvdcTeHDOrPSfkGn+9gsi+CylZMwmmXHhKN+lih6/Gr5Vhc8y+?= =?us-ascii?Q?2DIQKx2R8ttpss+0riDyGWWIFp0iimSc0n8OvFu2t6a0GmYgJ3MQ2ggRPnhT?= =?us-ascii?Q?DU8j0H9ucZzbenXVjgVjY5DNDiJk3wtaXZprI5znhA2WWDpuccsp3X498nUS?= =?us-ascii?Q?7GU9M0S4/Xg6iAYw1DDdpfJLVZtJJR5LWEwqx28endk5ZJe9cNbValQnEGCT?= =?us-ascii?Q?chkgcw0y0o/tqrbjF0rcaJu2CnkYiPWnamWPOMzip3CFNWJW7w0hUgTikKAa?= =?us-ascii?Q?LbrD0Mi8urzbaDWdBJyCft71K30PFLyDQBRdjvB7QmpWvvfgdaOC3cAfn1Fl?= =?us-ascii?Q?Bl0ZFU6M3eeD4k0t/y0oeZ48hEluaYYHckvzvE3+?= 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: c9ca2676-d88d-42e5-7019-08dab0333cd1 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Oct 2022 11:32:13.6057 (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: Y5PMTT+JFL+B7udzO7F1n9E5WcxQfHhkH871VWHjODqPFqdNer0NEZaTRz/05v3N+jg8+sHQrJvqLuzjy/5J+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5687 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable [AMD Official Use Only - General] > -----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. I think you don't need to put HPE copyright for this file. > + 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_ No leading "_" as it mentioned in edk2 C coding standard. > + > +#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 HPE copyright is not necessary for this file. Otherwise, Acked-by: Abner Chang Thanks Abner > 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