From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.41]) by mx.groups.io with SMTP id smtpd.web08.21053.1665850411463132790 for ; Sat, 15 Oct 2022 09:13:31 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=K934mSIx; 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.236.41, mailfrom: abner.chang@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H6RwHr3x2dpDt6st7jFhIr7eJK7r+9g3Wm/Sw3TYAo2t+5HVl+4sPWgt2YqQQ6qrSTTkWXiSCHU6LGD+oJEfeM6MADPxvHy1ar9WGLFUhUraRMohvX3fpMr4TWkPKYS66cmRuRs2yyOpexib0P/ZkJnqmcomM84CuPgOmeXpyVGbLjXp287QxTFJ8vDUtmxSA+ZDFrqCfwyDI5Pnc3obtDhEn2ddbIXvWtm6hdhkXbFlSnkyuzKXgj6zdk1qF5tYWTzD8QhTw8+qXI6/87ms+yGBFr5dz0JEcoBq8X0C0q/bmK+agcLgEVYh5K7rA/Ik6qyh7JG2tBlh6OY6ayqsKA== 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=FWOMOs02pp48MdxLI0UcyVvB+uqM7HsJpaEaUYhI1iY=; b=lv9g1KizcSYbjGbpyPeSwVQSqjzmXj2rS8SBALvu1rmlvtd/beLKZ8NdpeuXmo66gI+U3wQhLH5zAhFHYLx58zOu3ajZu1IoomQ+YopQjfCDOo/vhFn0sdD7GexLjGgqI75X/xFfBOpTHd/yyC1Xlpwy4HXk8YcZFgazrvxz/MXGtgPliK5J9oJvwr86KbQoFsvBK/3sF/UKX8+hjVdxyrAcFIk68qlPbdVnyfqeRf3zS6ZZ0mwS8dJyRGO17IH0cNt3pguslCEn9hwwPpjX/p2OC8DRGOCF/a6Yd/E49r992wZdDDkkGARtTDpdTdRiiEp834oVqg7GJ/ijpingRQ== 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=FWOMOs02pp48MdxLI0UcyVvB+uqM7HsJpaEaUYhI1iY=; b=K934mSIxsTDb88LVOBNE0TwdARKxivihjKC47Ek8xB8NPFBfwUeYD1YbPMoQabr+11Np71mpTqVoF9J7dwmyQgTZR9NMJdffGb++TVcxHGnK2XzwHrhy44isWdvA8G4csCt+a8dNM3VxL/a/QC9k4FAlHMY8t6SXOftZxfv2mfY= Received: from MN2PR12MB3966.namprd12.prod.outlook.com (2603:10b6:208:165::18) by CY5PR12MB6203.namprd12.prod.outlook.com (2603:10b6:930:24::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.26; Sat, 15 Oct 2022 16:13:28 +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 16:13:27 +0000 From: "Chang, Abner" To: "devel@edk2.groups.io" , "sunilvl@ventanamicro.com" CC: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Daniel Schaefer Subject: Re: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V4 12/34] OvmfPkg/PlatformPei: Add support for RISC-V Thread-Topic: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V4 12/34] OvmfPkg/PlatformPei: Add support for RISC-V Thread-Index: AQHY3+0MH39VDvNUgUO4tMwOlYH4UK4Pn62w Date: Sat, 15 Oct 2022 16:13:27 +0000 Message-ID: References: <20221014164836.1513036-1-sunilvl@ventanamicro.com> <20221014164836.1513036-13-sunilvl@ventanamicro.com> In-Reply-To: <20221014164836.1513036-13-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-15T16:13:25Z; 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=a03a9867-c3ba-44db-a696-21b0a9121c76; 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_|CY5PR12MB6203:EE_ x-ms-office365-filtering-correlation-id: 162f1333-1a62-4e36-6513-08daaec831ce x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: obiWHTgeTKJPNKtezTM4jckra22e7LY1YmMm1Xa0baohklnxV0WcIU69Aw6pyoPvd/45+xfkA9ogL63+brEEVsS+pb6sVeFXiP4aDn8GuB4YoZTu+q0WV/+MAyBInrgNLQ8EgdUCKHt70n4rPHTTg8zqnLcEwJ5OAb9TMjpvgiefZreWElw4M1ExNX4muzWwyAbH6mwXbAjontxRByT7Po16hILxoQpJ29IQcBRmI41HdFHmTU8/vMvAyfmyP1uMy+JBNDoBhKwtiz5YGlyq2Vofahq/Zp+edq9DloPfyiMLPBuFc0Z+ZDhpzrPsYDFkWTZC54G7KApTjrwOcitZvMP7U+gb1wL57F/jAvm4do8PXpwBx78hLUbKxXV5eEt+iMXnjHSQetgKQKS104RaFBY6Cb8wSDXkwORPRmeS3X/38cHxyKk8NT0Be9lDGhyZUQhrU6koLrdXuARxQPKD5jZbSIazMl5nvjODLBRpFHC9TfUnHlW1WIwxQAyxrQclaRQIgwhR+s2rK4KZxGJ9xfpPdoo8LE2dBHcwJhDBFkKYtvUFXFPXZpHcsBsvKINzfpOSeh72iITANCkoDZCiMdANIpm9kD0ckgU6v6goVmRvTOXmChdX9ZCAh1Bjnx8qOdZnOJthsc2o+De6MnhrCTWmRB0UX3P2GRuVC6HF0gL5/j83rhRyLDgMYPYf1jnKxYpvQI4GcRnpvAf36X8YKWhjZfYa7McCo3Edn6nnej4RQMWbspxLILCDa19Ehbyt2wkgu1ZGfpfw0obmXg43D3nU4ttfMuqJ7amit/Oc6Sb+BCiJoKMhY8gOLd2jaJZu5wPEYcaAWDZ4HIBlLAtqMA== 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)(396003)(366004)(451199015)(6506007)(7696005)(5660300002)(52536014)(86362001)(76116006)(30864003)(41300700001)(64756008)(316002)(110136005)(66446008)(66556008)(66946007)(4326008)(8676002)(478600001)(38070700005)(966005)(33656002)(54906003)(8936002)(45080400002)(2906002)(38100700002)(26005)(71200400001)(55016003)(122000001)(9686003)(66476007)(53546011)(186003)(83380400001)(19627235002)(66899015)(559001)(579004);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?kfp4AoEcqN7IFDsjWTGaRVImuX9iZR+a4QwirBOQrpVZWWtIks5aISb8QIJ+?= =?us-ascii?Q?rmr0gT3fFVAvGKuw9pLWS29kfHvwgAi8bcLWpEf7mwulGaY06BvDRiF7xyPh?= =?us-ascii?Q?0j0L+8PRFu6uftjPjXsMCmBAuiwwMzIZWwUfeHXDN0ms6lvyF3OMj06DgkEK?= =?us-ascii?Q?vvHkdwWutKKu09bHhgBb2+Y/wqo8Tx8Xl9AtBvXGjxWj8oQjtye19L1ukomq?= =?us-ascii?Q?cL7SZqevId4yOFglkWYSRgXlwF9VzaE90ut4QXZNxe2ynCmMyVjAwR9ZNBhq?= =?us-ascii?Q?9qWZpDa7NsDY4y2BT/nJyRO7i+M7mFGVRDc53qx6FPIkcbV26G5aKeEUeFXb?= =?us-ascii?Q?FNSBcwmnYnSCests8b7H96T8TOKFics4m7gN3RadZ+3rOqlqkoA7JsWZ9bk/?= =?us-ascii?Q?v6klBgAOy+yuTZtKG/i3E9FWXZCfyoTcuZjWN9Yl/WaA8cabgnmmPfVVEm8y?= =?us-ascii?Q?7uJWlmNmd0vhD6IitEqc3jAcFyzE+lPKL56s/r6N0d8Z8Ayf23UWtCpXFGDX?= =?us-ascii?Q?uZoDAJenUwMngIvRMq+/iTjhJ1fAeWnAiyHzqIv6uUW+gsqLghrJ+mivI4oN?= =?us-ascii?Q?zts3LWc4PZR4hQZnv+r5LDt3Lg5RYtiVhzyTixFMNbfi7vMHptzfpg8bUhbF?= =?us-ascii?Q?uhKVAn6c13CbHV8PidJG3UNlWUeBt90hRuGRxLYIVITShOqHAm6DwSNgOSaf?= =?us-ascii?Q?8/m6Yl+RnVS4oCETvAa2Rlk5WEqydcr4HhqCb7RObIBaQo/h4JXru+ndWPTe?= =?us-ascii?Q?41u6zmuWkPY00tmt2kWhqVhUIMDmGyxvnBjieJgiP/Xrx/4awO5UKoHOhO0W?= =?us-ascii?Q?7XNC+ytjrNsl3frOWMMEnP/4S8YClyFiTRCqwTGD2ITfSjVzmpUZmd3ITBCe?= =?us-ascii?Q?ObrclX05qoJubhiguzO2BqPX5jFMLMo58o+GA5TIVkVbpXbRfK7WwJqDbkZk?= =?us-ascii?Q?d0sw9Vb2jYnRsximH1njfpUcoGVUHibm1ZFqe0Go6EbakuKa8+wYvVp3QASL?= =?us-ascii?Q?EixWXtKmsrI5Q1ChWwKW0Q+EYUc91NAuz2TdaZFufCgQIjslXG0NxTs3yRuz?= =?us-ascii?Q?DcuX1BzDbMQ1qXAeKZvj4zX0fztrI0WKP+Lj3czd+Xvk4CaQE88w+qXLO+BM?= =?us-ascii?Q?Zk+zc0ORW9Y7WvhThWWxpuLpvnKwDoFhZWUZwh8YAU776H2an5yjvpDOccVC?= =?us-ascii?Q?qK5yZs4Xm1CG6kUnZoBEhGuMTM8pPaJeGh4GPxpdQv82lnmw0axI5sUXRZ+W?= =?us-ascii?Q?RkKLGjqo//RLAq/LJC6MmeyiK8U7hnKFoPekzfY4Pj0wYRKrnVDzavFyCpaM?= =?us-ascii?Q?nhJgLkAhUOWZX7WQ8cnNh/xKD0Vk3JRXNEP4SDFw3MkU0vV08s6lqkKLs/IV?= =?us-ascii?Q?q3x5nKySus9o0DQcKKsfcT9i6yaK44a1omKdRgvCMnbzqAO1WgCbG5N6CiZ6?= =?us-ascii?Q?iWNlJaRu7Enb8C60gYh7JX91OxfAkU49We+InR5Yr9iSEntlESw2JJmc4HcN?= =?us-ascii?Q?pao3aTgIviWT/opr1iY0OWuVu8fXj9gjqCzVV8MtVVa5WWyP7vtlYI9CCEou?= =?us-ascii?Q?K6orGpMsEU8cl3w2VzqDl8cyBBwFsdsu9AOr/Lr9?= 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: 162f1333-1a62-4e36-6513-08daaec831ce X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Oct 2022 16:13:27.8023 (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: 2j9N7ZPci2VvgxTrti97eiNQTMztpIcRrZZXEp/z4eWOmj7Eu5PsOKwQ3AgW03Lh9wE4x2yEUHxM2PhTDz/gZw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6203 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable [AMD Official Use Only - General] Acked-by: Abner Chang However, this one has the dependency with 11/34. > -----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 ; Daniel Schaefer > Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V4 12/34] > OvmfPkg/PlatformPei: Add support 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%7C662b4bb7c3d84c49a42608daae042cf8%7C3dd89 > 61fe4884e608e11a82d994e183d%7C0%7C0%7C638013630213202640%7CUnkn > own%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik > 1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=3DiJgba94hHBMT4 > 8Z90bBpSh7wNuJtGQbtRgjk0mOyVlk%3D&reserved=3D0 >=20 > This is mostly copied from > edk2-platforms/Platform/RISC-V/PlatformPkg/Universal/Pei/PlatformPei >=20 > Cc: Ard Biesheuvel > Cc: Jiewen Yao > Cc: Jordan Justen > Cc: Gerd Hoffmann > Cc: Daniel Schaefer > Signed-off-by: Sunil V L > --- > OvmfPkg/PlatformPei/PlatformPei.inf | 9 + > OvmfPkg/PlatformPei/RiscV64/Platform.h | 97 +++++ > OvmfPkg/PlatformPei/RiscV64/Fv.c | 81 +++++ > OvmfPkg/PlatformPei/RiscV64/MemDetect.c | 212 +++++++++++ > OvmfPkg/PlatformPei/RiscV64/Platform.c | 372 ++++++++++++++++++++ > 5 files changed, 771 insertions(+) >=20 > diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf > b/OvmfPkg/PlatformPei/PlatformPei.inf > index c637f621cb1f..5d873c34ca67 100644 > --- a/OvmfPkg/PlatformPei/PlatformPei.inf > +++ b/OvmfPkg/PlatformPei/PlatformPei.inf > @@ -33,6 +33,12 @@ [Sources.IA32, Sources.X64] > Ia32X64/Platform.h > Ia32X64/IntelTdx.c >=20 > +[Sources.RISCV64] > + RiscV64/Fv.c > + RiscV64/MemDetect.c > + RiscV64/Platform.c > + RiscV64/Platform.h > + > [Packages] > EmbeddedPkg/EmbeddedPkg.dec > MdePkg/MdePkg.dec > @@ -68,6 +74,9 @@ [LibraryClasses.IA32, LibraryClasses.X64] > QemuFwCfgSimpleParserLib > MemEncryptSevLib >=20 > +[LibraryClasses.RISCV64] > + RiscVSbiLib > + > [Pcd] > gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase > gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvSize > diff --git a/OvmfPkg/PlatformPei/RiscV64/Platform.h > b/OvmfPkg/PlatformPei/RiscV64/Platform.h > new file mode 100644 > index 000000000000..6c23c722a360 > --- /dev/null > +++ b/OvmfPkg/PlatformPei/RiscV64/Platform.h > @@ -0,0 +1,97 @@ > +/** @file > + Platform PEI module include file. > + > + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All > + rights reserved.
Copyright (c) 2006 - 2014, Intel Corporation. > + All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#ifndef PLATFORM_PEI_H_INCLUDED_ > +#define PLATFORM_PEI_H_INCLUDED_ > + > +VOID > +AddIoMemoryBaseSizeHob ( > + EFI_PHYSICAL_ADDRESS MemoryBase, > + UINT64 MemorySize > + ); > + > +VOID > +AddIoMemoryRangeHob ( > + EFI_PHYSICAL_ADDRESS MemoryBase, > + EFI_PHYSICAL_ADDRESS MemoryLimit > + ); > + > +VOID > +AddMemoryBaseSizeHob ( > + EFI_PHYSICAL_ADDRESS MemoryBase, > + UINT64 MemorySize > + ); > + > +VOID > +AddMemoryRangeHob ( > + EFI_PHYSICAL_ADDRESS MemoryBase, > + EFI_PHYSICAL_ADDRESS MemoryLimit > + ); > + > +VOID > +AddUntestedMemoryBaseSizeHob ( > + EFI_PHYSICAL_ADDRESS MemoryBase, > + UINT64 MemorySize > + ); > + > +VOID > +AddReservedMemoryBaseSizeHob ( > + EFI_PHYSICAL_ADDRESS MemoryBase, > + UINT64 MemorySize > + ); > + > +VOID > +AddUntestedMemoryRangeHob ( > + EFI_PHYSICAL_ADDRESS MemoryBase, > + EFI_PHYSICAL_ADDRESS MemoryLimit > + ); > + > +VOID > +AddressWidthInitialization ( > + VOID > + ); > + > +EFI_STATUS > +PublishPeiMemory ( > + VOID > + ); > + > +UINT32 > +GetSystemMemorySizeBelow4gb ( > + VOID > + ); > + > +VOID > +InitializeRamRegions ( > + VOID > + ); > + > +EFI_STATUS > +PeiFvInitialization ( > + VOID > + ); > + > +EFI_STATUS > +InitializeXen ( > + VOID > + ); > + > +/** > + Build processor and platform information for the U5 platform > + > + @return EFI_SUCCESS Status. > + > +**/ > +EFI_STATUS > +BuildRiscVSmbiosHobs ( > + VOID > + ); > + > +#endif // _PLATFORM_PEI_H_INCLUDED_ > diff --git a/OvmfPkg/PlatformPei/RiscV64/Fv.c > b/OvmfPkg/PlatformPei/RiscV64/Fv.c > new file mode 100644 > index 000000000000..ff99c1432935 > --- /dev/null > +++ b/OvmfPkg/PlatformPei/RiscV64/Fv.c > @@ -0,0 +1,81 @@ > +/** @file > + Build FV related hobs for platform. > + > + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All > + rights reserved.
Copyright (c) 2006 - 2013, Intel Corporation. > + All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include "PiPei.h" > +#include "Platform.h" > +#include > +#include > +#include > +#include > + > +/** > + Publish PEI & DXE (Decompressed) Memory based FVs to let PEI > + and DXE know about them. > + > + @retval EFI_SUCCESS Platform PEI FVs were initialized successfully. > + > +**/ > +EFI_STATUS > +PeiFvInitialization ( > + VOID > + ) > +{ > + DEBUG ((DEBUG_INFO, "Platform PEI Firmware Volume > +Initialization\n")); > + > + // Create a memory allocation HOB for the DXE FV. > + // > + // If "secure" S3 is needed, then SEC will decompress both PEI and > + DXE // firmware volumes at S3 resume too, hence we need to keep away > + the OS from // DXEFV as well. Otherwise we only need to keep away DXE > + itself from the // DXEFV area. > + // > + BuildMemoryAllocationHob ( > + PcdGet32 (PcdOvmfPeiMemFvBase), > + PcdGet32 (PcdOvmfPeiMemFvSize), > + EfiBootServicesData > + ); > + > + // > + // Let DXE know about the DXE FV > + // > + BuildFvHob (PcdGet32 (PcdOvmfDxeMemFvBase), PcdGet32 > + (PcdOvmfDxeMemFvSize)); DEBUG (( > + DEBUG_INFO, > + "Platform builds DXE FV at %x, size %x.\n", > + PcdGet32 (PcdOvmfDxeMemFvBase), > + PcdGet32 (PcdOvmfDxeMemFvSize) > + )); > + > + // Create a memory allocation HOB for the DXE FV. > + // > + // If "secure" S3 is needed, then SEC will decompress both PEI and > + DXE // firmware volumes at S3 resume too, hence we need to keep away > + the OS from // DXEFV as well. Otherwise we only need to keep away DXE > + itself from the // DXEFV area. > + // > + BuildMemoryAllocationHob ( > + PcdGet32 (PcdOvmfDxeMemFvBase), > + PcdGet32 (PcdOvmfDxeMemFvSize), > + EfiBootServicesData > + ); > + > + // > + // Let PEI know about the DXE FV so it can find the DXE Core // > + PeiServicesInstallFvInfoPpi ( > + NULL, > + (VOID *)(UINTN)PcdGet32 (PcdOvmfDxeMemFvBase), > + PcdGet32 (PcdOvmfDxeMemFvSize), > + NULL, > + NULL > + ); > + > + return EFI_SUCCESS; > +} > diff --git a/OvmfPkg/PlatformPei/RiscV64/MemDetect.c > b/OvmfPkg/PlatformPei/RiscV64/MemDetect.c > new file mode 100644 > index 000000000000..eb9d24581f8d > --- /dev/null > +++ b/OvmfPkg/PlatformPei/RiscV64/MemDetect.c > @@ -0,0 +1,212 @@ > +/** @file > + Memory Detection for Virtual Machines. > + > + Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All > + rights reserved.
Copyright (c) 2006 - 2014, Intel Corporation. > + All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +Module Name: > + > + MemDetect.c > + > +**/ > + > +// > +// The package level header files this module uses // #include > + > + > +// > +// The Library classes this module consumes // #include > + #include #include > + #include #include > + #include #include > + > +#include > + > +#include > + > +#include > + > +#include "Platform.h" > + > +STATIC EFI_PHYSICAL_ADDRESS SystemMemoryBase; > +STATIC UINT64 SystemMemorySize; > +STATIC EFI_PHYSICAL_ADDRESS MmodeResvBase; > +STATIC UINT64 MmodeResvSize; > + > +/** > + Publish PEI core memory. > + > + @return EFI_SUCCESS The PEIM initialized successfully. > + > +**/ > +EFI_STATUS > +PublishPeiMemory ( > + VOID > + ) > +{ > + EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext; > + EFI_PHYSICAL_ADDRESS MemoryBase; > + CONST UINT64 *RegProp; > + CONST CHAR8 *Type; > + EFI_STATUS Status; > + UINT64 CurBase, CurSize; > + UINT64 NewBase =3D 0, NewSize =3D 0; > + UINT64 MemorySize; > + INT32 Node, Prev; > + INT32 Len; > + VOID *FdtPointer; > + > + FirmwareContext =3D NULL; > + GetFirmwareContextPointer (&FirmwareContext); > + > + if (FirmwareContext =3D=3D NULL) { > + DEBUG ((DEBUG_ERROR, "%a: Firmware Context is NULL\n", > __FUNCTION__)); > + return EFI_UNSUPPORTED; > + } > + > + FdtPointer =3D (VOID *)FirmwareContext->FlattenedDeviceTree; > + if (FdtPointer =3D=3D NULL) { > + DEBUG ((DEBUG_ERROR, "%a: Invalid FDT pointer\n", __FUNCTION__)); > + return EFI_UNSUPPORTED; > + } > + > + // Look for the lowest memory node > + for (Prev =3D 0; ; Prev =3D Node) { > + Node =3D fdt_next_node (FdtPointer, Prev, NULL); > + if (Node < 0) { > + break; > + } > + > + // Check for memory node > + Type =3D fdt_getprop (FdtPointer, Node, "device_type", &Len); > + if (Type && (AsciiStrnCmp (Type, "memory", Len) =3D=3D 0)) { > + // Get the 'reg' property of this node. For now, we will assume > + // two 8 byte quantities for base and size, respectively. > + RegProp =3D fdt_getprop (FdtPointer, Node, "reg", &Len); > + if ((RegProp !=3D 0) && (Len =3D=3D (2 * sizeof (UINT64)))) { > + CurBase =3D fdt64_to_cpu (ReadUnaligned64 (RegProp)); > + CurSize =3D fdt64_to_cpu (ReadUnaligned64 (RegProp + 1)); > + > + DEBUG (( > + DEBUG_INFO, > + "%a: System RAM @ 0x%lx - 0x%lx\n", > + __FUNCTION__, > + CurBase, > + CurBase + CurSize - 1 > + )); > + > + if ((NewBase > CurBase) || (NewBase =3D=3D 0)) { > + NewBase =3D CurBase; > + NewSize =3D CurSize; > + } > + } else { > + DEBUG (( > + DEBUG_ERROR, > + "%a: Failed to parse FDT memory node\n", > + __FUNCTION__ > + )); > + } > + } > + } > + > + SystemMemoryBase =3D NewBase; > + SystemMemorySize =3D NewSize; > + > + /* try to locate the reserved memory opensbi node */ Node =3D > + fdt_path_offset (FdtPointer, "/reserved-memory/mmode_resv0"); if > + (Node >=3D 0) { > + RegProp =3D fdt_getprop (FdtPointer, Node, "reg", &Len); > + if ((RegProp !=3D 0) && (Len =3D=3D (2 * sizeof (UINT64)))) { > + NewBase =3D fdt64_to_cpu (ReadUnaligned64 (RegProp)); > + NewSize =3D fdt64_to_cpu (ReadUnaligned64 (RegProp + 1)); > + DEBUG (( > + DEBUG_INFO, > + "%a: M-mode Base =3D 0x%lx, M-mode Size =3D 0x%lx\n", > + __FUNCTION__, > + NewBase, > + NewSize > + )); > + MmodeResvBase =3D NewBase; > + MmodeResvSize =3D NewSize; > + } > + } > + > + DEBUG (( > + DEBUG_INFO, > + "%a: SystemMemoryBase:0x%x SystemMemorySize:%x\n", > + __FUNCTION__, > + SystemMemoryBase, > + SystemMemorySize > + )); > + > + // > + // Initial 16MB needs to be reserved > + // > + MemoryBase =3D SystemMemoryBase + SIZE_16MB; MemorySize =3D > + SystemMemorySize - SIZE_16MB; > + > + // > + // Publish this memory to the PEI Core // Status =3D > + PublishSystemMemory (MemoryBase, MemorySize); ASSERT_EFI_ERROR > + (Status); > + > + return Status; > +} > + > +/** > + Publish system RAM and reserve memory regions. > + > +**/ > +VOID > +InitializeRamRegions ( > + VOID > + ) > +{ > + /* > + * M-mode FW can be loaded anywhere in memory but should not overlap > + * with the EDK2. This can happen if some other boot code loads the > + * M-mode firmware. > + * > + * The M-mode firmware memory should be marked as reserved memory > + * so that OS doesn't use it. > + */ > + DEBUG (( > + DEBUG_INFO, > + "%a: M-mode FW Memory Start:0x%lx End:0x%lx\n", > + __FUNCTION__, > + MmodeResvBase, > + MmodeResvBase + MmodeResvSize > + )); > + AddReservedMemoryBaseSizeHob (MmodeResvBase, MmodeResvSize); > + > + if (MmodeResvBase > SystemMemoryBase) { > + DEBUG (( > + DEBUG_INFO, > + "%a: Free Memory Start:0x%lx End:0x%lx\n", > + __FUNCTION__, > + SystemMemoryBase, > + MmodeResvBase > + )); > + AddMemoryRangeHob (SystemMemoryBase, MmodeResvBase); } > + > + DEBUG (( > + DEBUG_INFO, > + "%a: Free Memory Start:0x%lx End:0x%lx\n", > + __FUNCTION__, > + MmodeResvBase + MmodeResvSize, > + SystemMemoryBase + SystemMemorySize > + )); > + AddMemoryRangeHob ( > + MmodeResvBase + MmodeResvSize, > + SystemMemoryBase + SystemMemorySize > + ); > +} > diff --git a/OvmfPkg/PlatformPei/RiscV64/Platform.c > b/OvmfPkg/PlatformPei/RiscV64/Platform.c > new file mode 100644 > index 000000000000..45a2f44d9cca > --- /dev/null > +++ b/OvmfPkg/PlatformPei/RiscV64/Platform.c > @@ -0,0 +1,372 @@ > +/** @file > + Platform PEI driver > + > + Copyright (c) 2019-2022, Hewlett Packard Enterprise Development LP. > + All rights reserved.
Copyright (c) 2006 - 2014, Intel > + Corporation. All rights reserved.
Copyright (c) 2011, Andrei > + Warkentin > + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +// > +// The package level header files this module uses // #include > + > + > +// > +// The Library classes this module consumes // #include > + #include #include > + #include #include > + #include #include > + #include #include > + > +#include > +#include #include > > +#include > + > +#include "Platform.h" > + > +EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] =3D > { > + { EfiACPIMemoryNVS, 0x004 }, > + { EfiACPIReclaimMemory, 0x008 }, > + { EfiReservedMemoryType, 0x004 }, > + { EfiRuntimeServicesData, 0x024 }, > + { EfiRuntimeServicesCode, 0x030 }, > + { EfiBootServicesCode, 0x180 }, > + { EfiBootServicesData, 0xF00 }, > + { EfiMaxMemoryType, 0x000 } > +}; > + > +EFI_PEI_PPI_DESCRIPTOR mPpiBootMode[] =3D { > + { > + EFI_PEI_PPI_DESCRIPTOR_PPI | > EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, > + &gEfiPeiMasterBootModePpiGuid, > + NULL > + } > +}; > + > +STATIC EFI_BOOT_MODE mBootMode =3D > BOOT_WITH_FULL_CONFIGURATION; > + > +/** > + Build memory map I/O range resource HOB using the > + base address and size. > + > + @param MemoryBase Memory map I/O base. > + @param MemorySize Memory map I/O size. > + > +**/ > +VOID > +AddIoMemoryBaseSizeHob ( > + EFI_PHYSICAL_ADDRESS MemoryBase, > + UINT64 MemorySize > + ) > +{ > + BuildResourceDescriptorHob ( > + EFI_RESOURCE_MEMORY_MAPPED_IO, > + EFI_RESOURCE_ATTRIBUTE_PRESENT | > + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | > + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | > + EFI_RESOURCE_ATTRIBUTE_TESTED, > + MemoryBase, > + MemorySize > + ); > +} > + > +/** > + Build reserved memory range resource HOB. > + > + @param MemoryBase Reserved memory range base address. > + @param MemorySize Reserved memory range size. > + > +**/ > +VOID > +AddReservedMemoryBaseSizeHob ( > + EFI_PHYSICAL_ADDRESS MemoryBase, > + UINT64 MemorySize > + ) > +{ > + BuildResourceDescriptorHob ( > + EFI_RESOURCE_MEMORY_RESERVED, > + EFI_RESOURCE_ATTRIBUTE_PRESENT | > + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | > + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | > + EFI_RESOURCE_ATTRIBUTE_TESTED, > + MemoryBase, > + MemorySize > + ); > +} > + > +/** > + Build memory map I/O resource using the base address > + and the top address of memory range. > + > + @param MemoryBase Memory map I/O range base address. > + @param MemoryLimit The top address of memory map I/O range > + > +**/ > +VOID > +AddIoMemoryRangeHob ( > + EFI_PHYSICAL_ADDRESS MemoryBase, > + EFI_PHYSICAL_ADDRESS MemoryLimit > + ) > +{ > + AddIoMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - > +MemoryBase)); } > + > +/** > + Create memory range resource HOB using the memory base > + address and size. > + > + @param MemoryBase Memory range base address. > + @param MemorySize Memory range size. > + > +**/ > +VOID > +AddMemoryBaseSizeHob ( > + EFI_PHYSICAL_ADDRESS MemoryBase, > + UINT64 MemorySize > + ) > +{ > + BuildResourceDescriptorHob ( > + EFI_RESOURCE_SYSTEM_MEMORY, > + EFI_RESOURCE_ATTRIBUTE_PRESENT | > + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | > + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | > + EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | > + EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | > + EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE | > + EFI_RESOURCE_ATTRIBUTE_TESTED, > + MemoryBase, > + MemorySize > + ); > +} > + > +/** > + Create memory range resource HOB using memory base > + address and top address of the memory range. > + > + @param MemoryBase Memory range base address. > + @param MemoryLimit Memory range size. > + > +**/ > +VOID > +AddMemoryRangeHob ( > + EFI_PHYSICAL_ADDRESS MemoryBase, > + EFI_PHYSICAL_ADDRESS MemoryLimit > + ) > +{ > + AddMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit - > +MemoryBase)); } > + > +/** > + Create untested memory range resource HOB using memory base > + address and top address of the memory range. > + > + @param MemoryBase Memory range base address. > + @param MemorySize Memory range size. > + > +**/ > +VOID > +AddUntestedMemoryBaseSizeHob ( > + EFI_PHYSICAL_ADDRESS MemoryBase, > + UINT64 MemorySize > + ) > +{ > + BuildResourceDescriptorHob ( > + EFI_RESOURCE_SYSTEM_MEMORY, > + EFI_RESOURCE_ATTRIBUTE_PRESENT | > + EFI_RESOURCE_ATTRIBUTE_INITIALIZED | > + EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | > + EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | > + EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | > + EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE, > + MemoryBase, > + MemorySize > + ); > +} > + > +/** > + Create untested memory range resource HOB using memory base > + address and top address of the memory range. > + > + @param MemoryBase Memory range base address. > + @param MemoryLimit Memory range size. > + > +**/ > +VOID > +AddUntestedMemoryRangeHob ( > + EFI_PHYSICAL_ADDRESS MemoryBase, > + EFI_PHYSICAL_ADDRESS MemoryLimit > + ) > +{ > + AddUntestedMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit > - > +MemoryBase)); } > + > +/** > + Add PCI resource. > + > +**/ > +VOID > +AddPciResource ( > + VOID > + ) > +{ > + // > + // Platform-specific > + // > +} > + > +/** > + Platform memory map initialization. > + > +**/ > +VOID > +MemMapInitialization ( > + VOID > + ) > +{ > + // > + // Create Memory Type Information HOB > + // > + BuildGuidDataHob ( > + &gEfiMemoryTypeInformationGuid, > + mDefaultMemoryTypeInformation, > + sizeof (mDefaultMemoryTypeInformation) > + ); > + > + // > + // Add PCI IO Port space available for PCI resource allocations. > + // > + AddPciResource (); > +} > + > +/** > + Platform misc initialization. > + > +**/ > +VOID > +MiscInitialization ( > + VOID > + ) > +{ > + // > + // Build the CPU HOB with guest RAM size dependent address width and > +16-bits > + // of IO space. (Side note: unlike other HOBs, the CPU HOB is needed > +during > + // S3 resume as well, so we build it unconditionally.) > + // > + // TODO: Determine this dynamically from the platform > + // setting or the HART configuration. > + // > + BuildCpuHob (56, 32); > +} > + > +/** > + Check if system returns from S3. > + > + @return BOOLEAN TRUE, system returned from S3 > + FALSE, system is not returned from S3 > + > +**/ > +BOOLEAN > +CheckResumeFromS3 ( > + VOID > + ) > +{ > + // > + // Platform implementation-specific > + // > + return FALSE; > +} > + > +/** > + Platform boot mode initialization. > + > +**/ > +VOID > +BootModeInitialization ( > + VOID > + ) > +{ > + EFI_STATUS Status; > + > + if (CheckResumeFromS3 ()) { > + DEBUG ((DEBUG_INFO, "This is wake from S3\n")); } else { > + DEBUG ((DEBUG_INFO, "This is normal boot\n")); } > + > + Status =3D PeiServicesSetBootMode (mBootMode); ASSERT_EFI_ERROR > + (Status); > + > + Status =3D PeiServicesInstallPpi (mPpiBootMode); > + ASSERT_EFI_ERROR (Status); > +} > + > +/** > + Build processor information for U54 Coreplex processor. > + > + @return EFI_SUCCESS Status. > + > +**/ > +EFI_STATUS > +BuildCoreInformationHob ( > + VOID > + ) > +{ > + // return BuildRiscVSmbiosHobs (); > + return EFI_SUCCESS; > +} > + > +/** > + Perform Platform PEI initialization. > + > + @param FileHandle Handle of the file being invoked. > + @param PeiServices Describes the list of possible PEI Services. > + > + @return EFI_SUCCESS The PEIM initialized successfully. > + > +**/ > +EFI_STATUS > +EFIAPI > +InitializePlatform ( > + IN EFI_PEI_FILE_HANDLE FileHandle, > + IN CONST EFI_PEI_SERVICES **PeiServices > + ) > +{ > + EFI_STATUS Status; > + > + DEBUG ((DEBUG_INFO, "Platform PEIM Loaded\n")); Status =3D > + PlatformPeim (); if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "PlatformPeim failed\n")); > + ASSERT (FALSE); > + } > + > + BootModeInitialization (); > + DEBUG ((DEBUG_INFO, "Platform BOOT mode initiated.\n")); > + PublishPeiMemory (); DEBUG ((DEBUG_INFO, "PEI memory > published.\n")); > + InitializeRamRegions (); DEBUG ((DEBUG_INFO, "Platform RAM regions > + initiated.\n")); > + > + if (mBootMode !=3D BOOT_ON_S3_RESUME) { > + PeiFvInitialization (); > + MemMapInitialization (); > + } > + > + MiscInitialization (); > + Status =3D BuildCoreInformationHob (); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Fail to build processor information HOB.\n")); > + ASSERT (FALSE); > + } > + > + return EFI_SUCCESS; > +} > -- > 2.38.0 >=20 >=20 >=20 >=20 >=20