From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web11.57382.1675699436265568553 for ; Mon, 06 Feb 2023 08:03:56 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=i/iYIGaS; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: andrei.warkentin@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1675699436; x=1707235436; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=4cN2INprwRt6rZAmzUViiRL9RLCGyDUTEF3m9t1bTUM=; b=i/iYIGaSGoRYDD5Jfplh+fN+BcdNNTVpHXgJMy+Gw7ZL26z4h8C5r6Y2 mAUGTSzry0ojsN+MdYgGeOZxGkYx61Hq5xQG9w5pVUw0nlyLQol2jKOgh 2TcYUZkIsjzlq2O9EdFU+iitO16WHHwX72PDRhvOCkF//0i8muhlRSevm /k4MRmaEwLgTXLtdrsue4T0nWrNv05rSWdvt9S+HwliyUx7C+MW+dQdQ2 kINXIHrLJZNYJYHpx/FsUPQq05GPiCslNq4pMnQeSzY49Zp63qZbu/m0o TKIedVfErS8kXhvYjywTmdozfLgswchE3xpPxe8FzCyUJI6P9tn+vIsUa g==; X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="308883954" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="308883954" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2023 08:03:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10613"; a="840399711" X-IronPort-AV: E=Sophos;i="5.97,276,1669104000"; d="scan'208";a="840399711" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga005.jf.intel.com with ESMTP; 06 Feb 2023 08:03:29 -0800 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Mon, 6 Feb 2023 08:03:28 -0800 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Mon, 6 Feb 2023 08:03:28 -0800 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16 via Frontend Transport; Mon, 6 Feb 2023 08:03:28 -0800 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.176) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.16; Mon, 6 Feb 2023 08:03:28 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gi261WHwgt4Bk+SQLK/GO0UCeqM39YIDHrqWfLXpwSVIqo98tqi6+qdT2W5jQJAMnygNoFduOc7S75mgvS0zEffzPt1OsxQDmqA1mGkUnAKIvwapxJ5gXfRniemYZ2yw20hXj4oAs/nFfgCLfjNYCfyFqbfAQMLfkrOV364+M1x+us5jMIm0TVhq7W6lOzqhkBgoQ6lY2SmYDvdacpPq6pesLF+vKcz6Xmf0Wa2sffMlYWcz5oQL7JyC0qRwyjPRiIEDF03PZg8jia45ArwX+2mHFAZiCNVvdP0zbWl8RVfrTR75EPdskpXcRb+8WTbaJuuyLZgFDKzQuZa20rSd7A== 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=/poGU1Vf8uXp/nuaqfvB9ViZ815okeOFWQKnAlLkgcM=; b=jsV2/7H7/1vFtCa/0ifP1HuIuxrLGHLKsxRwRTWgWY1Hi/HBW8hcYfiNW1nMLUUA4/HRSiUK1uWAJr75wTI7bMY/HfPD2JVPuzIreELFbbfBVpe9FAqtXFGuLRjgo527v0bZ2w8P70xbLsKDmDKKy/W01y/yA41MGvkYp2+YfrQ/Yj7sO9cSAZDprKW4K7ts7xDQirmZ7kOZyaRkP9qSCRuW0cHqBTG3cfmm13Lc3tTdS5KIvjFVROkGWYXqcHIqLjPXeMLMirPiTh3XKbre1nBeYYz8fojSTQSHabcdr5kVho1dn+qEsdCrE+uuzExCRsqVr0D7e97dbx9tGu1Rhg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from PH8PR11MB6856.namprd11.prod.outlook.com (2603:10b6:510:22b::7) by CH3PR11MB7252.namprd11.prod.outlook.com (2603:10b6:610:144::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.34; Mon, 6 Feb 2023 16:03:25 +0000 Received: from PH8PR11MB6856.namprd11.prod.outlook.com ([fe80::9dba:633a:320c:87b]) by PH8PR11MB6856.namprd11.prod.outlook.com ([fe80::9dba:633a:320c:87b%5]) with mapi id 15.20.6064.032; Mon, 6 Feb 2023 16:03:25 +0000 From: "Andrei Warkentin" To: "devel@edk2.groups.io" , "sunilvl@ventanamicro.com" CC: Ard Biesheuvel , "Yao, Jiewen" , "Justen, Jordan L" , "Gerd Hoffmann" , Abner Chang Subject: Re: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V7 18/20] OvmfPkg/RiscVVirt: Add SEC module Thread-Topic: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V7 18/20] OvmfPkg/RiscVVirt: Add SEC module Thread-Index: AQHZM011sod8Ot+VmECHK9nKBKHZya7CIndg Date: Mon, 6 Feb 2023 16:03:25 +0000 Message-ID: References: <20230128191807.2080547-1-sunilvl@ventanamicro.com> <20230128191807.2080547-19-sunilvl@ventanamicro.com> In-Reply-To: <20230128191807.2080547-19-sunilvl@ventanamicro.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PH8PR11MB6856:EE_|CH3PR11MB7252:EE_ x-ms-office365-filtering-correlation-id: 10cf8bf3-13eb-46ee-3599-08db085baddb x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: RvZoNl8xzuSOU5GYaJ1ngracg+smorhCHvsNoB13a8DplKqUHXpMIi5qDFdud4nMhOmZq4MbtOjGRYLVNRVjtx/75/wWYjJTBFZUHC4z7bEC8J4Oxxwf5ijtn0LQgk2YOmMyg0wogYbE61U21b9gmjCmwhIgWf6+Ba81jSTyz4CPjISo1uWzQCKJIGmtnm0IUhuWu+mfgk7Ub9Zb0PmmU0VSH0AaHsqhiXVyKKl0gPzSJ8RSVqEjyLd29qPdmif/LpFVxSb8IRImrcJHEKvaUnPUEMhcD/W1aTjChWHN7RiHZPBdeuQSBnG3IqIb3SPVsOJG+yzLQRD+OJ2q1RTOU2/4U+w5vCcj4Ta+j4v1eJ03TmbmbtmOXeSlBgVJI3IEv/KHEr0wftAmlgEZm6UU+8YX9Da9ZA3dD8zyx87TnRhfp3eeq0IPi3RuJ/p1mT2NOKhPceLOLuCDuvpsKKzbaHnKPd8EYnGDYeCQryo4wB5xctEMNWwT+NZmS7jTOz20UgQmXEKiZMFKTCgcxN1lEeroJBOVxht6J/hY/UbPPvZWRZZlnaiGXt+jGXKqsk726vNblfmssDOLpD8wF8U4V8kn9dMaxu3JRYyC2lJGn2EAVAX9SYdmO17l6/PAMnyR0VMpGpBt/CL1Vv7oLkveOXybsUf8cUJLfebA8FkrZylwPpL6WVnX36fFlrRDXnS5fXCRX1d42eSowdhsH/2jQTnlcYmOcxJMgKCryyTnhKRory3QHIqY3nL+XaahlAP29bjKunrP0Nhl2RoVcXWC/Q== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR11MB6856.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(396003)(136003)(39860400002)(346002)(366004)(376002)(451199018)(66899018)(316002)(110136005)(33656002)(54906003)(26005)(86362001)(55016003)(7696005)(71200400001)(186003)(30864003)(6506007)(64756008)(2906002)(66476007)(66556008)(4326008)(8936002)(8676002)(5660300002)(41300700001)(9686003)(53546011)(966005)(478600001)(66446008)(82960400001)(76116006)(66946007)(38100700002)(38070700005)(52536014)(83380400001)(122000001)(579004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?5mmTMPPE5VRPvH7uJczokQMok49b0SZDPVOhMnRFeNQHEce7JrPepZRg4ZR5?= =?us-ascii?Q?KWkloI2MYYXG/3CV0fXub98zktiCuc7//l/06Ly2xwdEOj33CGPsPfII3BXe?= =?us-ascii?Q?onqEa0WpjqzvaoajimWGhs5Q3OUQKn36vk+QI7OecY3QwDqeQM1PH0NL+0OZ?= =?us-ascii?Q?A63qTg6gpUh6ElwF7CU+Ilp+75MhwnrmA4S2lg/ujr3RMlVujQcCASssYm6O?= =?us-ascii?Q?paW/J44eU35jePC6IC+dkxO3rftT62yf3Pel45J3ApkpqXZRRYFvXMa6JmHn?= =?us-ascii?Q?+Svj4l5NsGu3ct/kKixtRTiu2SBWBTHeUHTDtO9hvStg1DS16CPSmWE+vgN2?= =?us-ascii?Q?RTZ3rA8yRVuk/yg1wqAp2Zd/TL0wOv84eNy2oQ8WZocDqn7+bDeviJL1494D?= =?us-ascii?Q?SA0aAy+i3eVvKisFxotXe3sFa4CP1oMMg2+LuGNbtfqWK93+klpGCP7IWUbZ?= =?us-ascii?Q?/+oRYKdxSuxjehYIgvU1IKUchiMDA/EXqRVB6tTpfOLlMTOzo7mWMpOWeCOu?= =?us-ascii?Q?8uODNY2fzEz55nrLNnRTI3BeCpbIyGs+uFXUzLsGB5apbXBQD/Ru1wFrq2c8?= =?us-ascii?Q?p2bOJkkqxkA+AM/RZPQrowaPhBT5NDzfb1pdOIMB/5AFiEJ4mF8s6yrZIb/W?= =?us-ascii?Q?rbbVdtWGXD9tvqplLNaVbrucJ9/XVP8rpgfikJGdUX3civ7VptIJnbyrtTv0?= =?us-ascii?Q?uUn32xTZnsp/hKCtkASzPGvUpCZDchkAWTwxaF5QMdhZKsn0cJ3ZazRP1IaE?= =?us-ascii?Q?quDoFHYmrH/7bv3tKnpn0FDWMiRQjT2mruHQNU9SnF23SmRruGopF3p/KCND?= =?us-ascii?Q?L5U7BFTsp/Y2ny4yip2PQF7a4l2oM5FsdEZmRzym1idDN4qhje5FWaseERQ6?= =?us-ascii?Q?31etI5yof/STCUsaAInzwW8H0BVZ+yFvXlIOMnIQ3X5Dq2oOaetB1cZMdcRB?= =?us-ascii?Q?LWLwHUNWdGZ5m4hpiwQhJ/ZMBFFf/wMJ/UfIm2oJCSch4qaDOmm6hqeFAGhL?= =?us-ascii?Q?fetSGq3x7v9puhIAEkoSGwGB1UCaZmihkYam8IUNTCx+ILIh6Ej9+9VxjiUP?= =?us-ascii?Q?Z5HcDIHICKlZCLuBN5wnx9BRC2qi1Sjw5D2AIF+lB+hyQZyEJkxSzXoPh8Zf?= =?us-ascii?Q?ZJaBH6wmDApXhfQQHIqLV23PlgL3/ARa8mDf46FmNV13PHHDkACEAynd84eK?= =?us-ascii?Q?3AqwI5BcEpBFvEgpiV9+ph5wdA/1zz75EpfdEcmvXv0tD+Tv2UsV2Nbya/Vf?= =?us-ascii?Q?f/Rp3ACvZVYdrsMps9zbMsxDiVSraBQ1ob6BD+XizO9jB1TJAHTrNAYr4gBI?= =?us-ascii?Q?1YI1imVls6WFYhgLPzw6EOY70yfjw+/O0qA+hZUXw+bVgIKJSciwHjGn9zNw?= =?us-ascii?Q?UFESAeMAe1YmfvF7+fQA0Bm9oJknVcEShPNoIY4fG1ajQI0FMQEO6i64gvCN?= =?us-ascii?Q?w8KKIk9Q0wW7ro2cYqnb9HkRmUftkL6exXKCiVDdZUSGCazl4yGP4SSHqPeQ?= =?us-ascii?Q?lKq9d2S3FadmGhaEepZq/sZe187f45aHGaDWW+trOlfPmf4P1q957srMKcut?= =?us-ascii?Q?WjD8jmoK2oKPu+A87PGu5KXHpJst8suMSEJN7AKbThUdO/9ug/RMslsYdRPx?= =?us-ascii?Q?Pg=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH8PR11MB6856.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 10cf8bf3-13eb-46ee-3599-08db085baddb X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Feb 2023 16:03:25.4615 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: n4Q28aarmbhPQ3NEPui1wKYG9rEXyMWVEtzusbtqivSFGfrMg09GHIsTaiN8Gdbtp6S0Mt5ekORxW4bveqUbHZn0PmWVlDBP5umUxS6DEgM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR11MB7252 Return-Path: andrei.warkentin@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Andrei Warkentin -----Original Message----- From: devel@edk2.groups.io On Behalf Of Sunil V L Sent: Saturday, January 28, 2023 1:18 PM To: devel@edk2.groups.io Cc: Ard Biesheuvel ; Yao, Jiewen ; Justen, Jordan L ; Gerd Hoffmann ; Abner Chang Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V7 18/20] OvmfPkg= /RiscVVirt: Add SEC module Add the SEC module for RISC-V Qemu virt machine support. It uses the PEI less design. Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Signed-off-by: Sunil V L Acked-by: Abner Chang --- OvmfPkg/RiscVVirt/Sec/SecMain.inf | 66 +++++ OvmfPkg/RiscVVirt/Sec/SecMain.h | 102 ++++++++ OvmfPkg/RiscVVirt/Sec/Cpu.c | 33 +++ OvmfPkg/RiscVVirt/Sec/Memory.c | 263 ++++++++++++++++++++ OvmfPkg/RiscVVirt/Sec/Platform.c | 84 +++++++ OvmfPkg/RiscVVirt/Sec/SecMain.c | 104 ++++++++ OvmfPkg/RiscVVirt/Sec/SecEntry.S | 21 ++ 7 files changed, 673 insertions(+) diff --git a/OvmfPkg/RiscVVirt/Sec/SecMain.inf b/OvmfPkg/RiscVVirt/Sec/SecM= ain.inf new file mode 100644 index 000000000000..aed35d3af596 --- /dev/null +++ b/OvmfPkg/RiscVVirt/Sec/SecMain.inf @@ -0,0 +1,66 @@ +## @file +# SEC Driver for RISC-V +# +# Copyright (c) 2022, Ventana Micro Systems Inc. All rights=20 +reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # ## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D SecMainRiscV64 + FILE_GUID =3D 16740C0A-AA84-4F62-A06D-AE328057AE07 + MODULE_TYPE =3D SEC + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D SecMain + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D RISCV64 +# + +[Sources] + SecEntry.S + SecMain.c + SecMain.h + Cpu.c + Memory.c + Platform.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + OvmfPkg/OvmfPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + PcdLib + IoLib + PeCoffLib + LzmaDecompressLib + RiscVSbiLib + PrePiLib + FdtLib + MemoryAllocationLib + HobLib + +[Ppis] + gEfiTemporaryRamSupportPpiGuid # PPI ALWAYS_PRODUCED + gEfiTemporaryRamDonePpiGuid ## PRODUCES + +[Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress + +[Guids] + gFdtHobGuid diff --git a/OvmfPkg/RiscVVirt/Sec/SecMain.h b/OvmfPkg/RiscVVirt/Sec/SecMai= n.h new file mode 100644 index 000000000000..83a8058efe40 --- /dev/null +++ b/OvmfPkg/RiscVVirt/Sec/SecMain.h @@ -0,0 +1,102 @@ +/** @file + Master header file for SecCore. + + Copyright (c) 2022, Ventana Micro Systems Inc. All rights=20 + 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=20 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + 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 us= e. + @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=20 +of the module's + dependent libraries. This function must be called by the SEC Core=20 +once a stack has + been established. + +**/ +VOID +EFIAPI +ProcessLibraryConstructorList ( + VOID + ); + +/** + Perform Platform PEIM initialization. + + @return EFI_SUCCESS The platform initialized successfully. + @retval Others - As the error code indicates + +**/ +EFI_STATUS +EFIAPI +PlatformPeimInitialization ( + VOID + ); + +/** + Perform Memory PEIM initialization. + + @return EFI_SUCCESS The platform initialized successfully. + @retval Others - As the error code indicates + +**/ +EFI_STATUS +EFIAPI +MemoryPeimInitialization ( + VOID + ); + +/** + Perform CPU PEIM initialization. + + @return EFI_SUCCESS The platform initialized successfully. + @retval Others - As the error code indicates + +**/ +EFI_STATUS +EFIAPI +CpuPeimInitialization ( + VOID + ); + +#endif diff --git a/OvmfPkg/RiscVVirt/Sec/Cpu.c b/OvmfPkg/RiscVVirt/Sec/Cpu.c new = file mode 100644 index 000000000000..2c16df697e37 --- /dev/null +++ b/OvmfPkg/RiscVVirt/Sec/Cpu.c @@ -0,0 +1,33 @@ +/** @file +The library call to pass the device tree to DXE via HOB. + +Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All=20 +rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +// +//// The package level header files this module uses //// #include=20 + + +#include +#include + +/** + Cpu Peim initialization. + +**/ +EFI_STATUS +CpuPeimInitialization ( + VOID + ) +{ + // + // for MMU type >=3D sv39 + // + BuildCpuHob (56, 32); + + return EFI_SUCCESS; +} diff --git a/OvmfPkg/RiscVVirt/Sec/Memory.c b/OvmfPkg/RiscVVirt/Sec/Memory.= c new file mode 100644 index 000000000000..70935b07b56b --- /dev/null +++ b/OvmfPkg/RiscVVirt/Sec/Memory.c @@ -0,0 +1,263 @@ +/** @file + Memory Detection for Virtual Machines. + + Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All=20 + rights reserved.
Copyright (c) 2006 - 2014, Intel Corporation.=20 + All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +Module Name: + + MemDetect.c + +**/ + +// +// The package level header files this module uses // #include=20 + + +// +// The Library classes this module consumes // #include=20 + #include #include=20 + #include #include=20 + #include #include=20 + +#include +#include +#include +#include +#include + +VOID +BuildMemoryTypeInformationHob ( + VOID + ); + +/** + Build reserved memory range resource HOB. + + @param MemoryBase Reserved memory range base address. + @param MemorySize Reserved memory range size. + +**/ +STATIC +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 + ); +} + +/** + Create memory range resource HOB using the memory base + address and size. + + @param MemoryBase Memory range base address. + @param MemorySize Memory range size. + +**/ +STATIC +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. + +**/ +STATIC +VOID +AddMemoryRangeHob ( + EFI_PHYSICAL_ADDRESS MemoryBase, + EFI_PHYSICAL_ADDRESS MemoryLimit + ) +{ + AddMemoryBaseSizeHob (MemoryBase, (UINT64)(MemoryLimit -=20 +MemoryBase)); } + +/** + Configure MMU +**/ +STATIC +VOID +InitMmu ( + ) +{ + // + // Set supervisor translation mode to Bare mode + // + RiscVSetSupervisorAddressTranslationRegister ((UINT64)SATP_MODE_OFF=20 +<< 60); + DEBUG ((DEBUG_INFO, "%a: Set Supervisor address mode to bare-metal=20 +mode.\n", __FUNCTION__)); } + +/** + Publish system RAM and reserve memory regions. + +**/ +STATIC +VOID +InitializeRamRegions ( + EFI_PHYSICAL_ADDRESS SystemMemoryBase, + UINT64 SystemMemorySize, + EFI_PHYSICAL_ADDRESS MmodeResvBase, + UINT64 MmodeResvSize + ) +{ + /* + * 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) { + AddMemoryRangeHob (SystemMemoryBase, MmodeResvBase); } + + AddMemoryRangeHob ( + MmodeResvBase + MmodeResvSize, + SystemMemoryBase + SystemMemorySize + ); +} + +/** + Initialize memory hob based on the DTB information. + + @return EFI_SUCCESS The memory hob added successfully. + +**/ +EFI_STATUS +MemoryPeimInitialization ( + VOID + ) +{ + EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext; + CONST UINT64 *RegProp; + CONST CHAR8 *Type; + UINT64 CurBase, CurSize; + INT32 Node, Prev; + INT32 Len; + VOID *FdtPointer; + EFI_PHYSICAL_ADDRESS MmodeResvBase; + UINT64 MmodeResvSize; + + 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; + } + + /* try to locate the reserved memory opensbi node */ Node =3D=20 + fdt_path_offset (FdtPointer, "/reserved-memory/mmode_resv0"); if=20 + (Node >=3D 0) { + RegProp =3D fdt_getprop (FdtPointer, Node, "reg", &Len); + if ((RegProp !=3D 0) && (Len =3D=3D (2 * sizeof (UINT64)))) { + MmodeResvBase =3D fdt64_to_cpu (ReadUnaligned64 (RegProp)); + MmodeResvSize =3D fdt64_to_cpu (ReadUnaligned64 (RegProp + 1)); + } + } + + // 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 ((MmodeResvBase >=3D CurBase) && ((MmodeResvBase + MmodeResvSiz= e) <=3D (CurBase + CurSize))) { + InitializeRamRegions ( + CurBase, + CurSize, + MmodeResvBase, + MmodeResvSize + ); + } else { + AddMemoryBaseSizeHob (CurBase, CurSize); + } + } else { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to parse FDT memory node\n", + __FUNCTION__ + )); + } + } + } + + InitMmu (); + + BuildMemoryTypeInformationHob (); + + return EFI_SUCCESS; +} diff --git a/OvmfPkg/RiscVVirt/Sec/Platform.c b/OvmfPkg/RiscVVirt/Sec/Platf= orm.c new file mode 100644 index 000000000000..e8fd126cf800 --- /dev/null +++ b/OvmfPkg/RiscVVirt/Sec/Platform.c @@ -0,0 +1,84 @@ +/** @file +The library call to pass the device tree to DXE via HOB. + +Copyright (c) 2021, Hewlett Packard Enterprise Development LP. All=20 +rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +// +//// The package level header files this module uses //// #include=20 + + +#include +#include +#include #include=20 + #include #include=20 + #include #include=20 + + +/** + @retval EFI_SUCCESS The address of FDT is passed in HOB. + EFI_UNSUPPORTED Can't locate FDT. +**/ +EFI_STATUS +EFIAPI +PlatformPeimInitialization ( + VOID + ) +{ + EFI_RISCV_FIRMWARE_CONTEXT *FirmwareContext; + VOID *FdtPointer; + VOID *Base; + VOID *NewBase; + UINTN FdtSize; + UINTN FdtPages; + UINT64 *FdtHobData; + + 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; + } + + DEBUG ((DEBUG_INFO, "%a: Build FDT HOB - FDT at address: 0x%x \n",=20 + __FUNCTION__, FdtPointer)); Base =3D FdtPointer; if (fdt_check_header= =20 + (Base) !=3D 0) { + DEBUG ((DEBUG_ERROR, "%a: Corrupted DTB\n", __FUNCTION__)); + return EFI_UNSUPPORTED; + } + + FdtSize =3D fdt_totalsize (Base); + FdtPages =3D EFI_SIZE_TO_PAGES (FdtSize); NewBase =3D AllocatePages=20 + (FdtPages); if (NewBase =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Could not allocate memory for DTB\n", __FUNC= TION__)); + return EFI_UNSUPPORTED; + } + + fdt_open_into (Base, NewBase, EFI_PAGES_TO_SIZE (FdtPages)); + + FdtHobData =3D BuildGuidHob (&gFdtHobGuid, sizeof *FdtHobData); if=20 + (FdtHobData =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: Could not build FDT Hob\n", __FUNCTION__)); + return EFI_UNSUPPORTED; + } + + *FdtHobData =3D (UINTN)NewBase; + + BuildFvHob (PcdGet32 (PcdOvmfDxeMemFvBase), PcdGet32=20 + (PcdOvmfDxeMemFvSize)); + + return EFI_SUCCESS; +} diff --git a/OvmfPkg/RiscVVirt/Sec/SecMain.c b/OvmfPkg/RiscVVirt/Sec/SecMai= n.c new file mode 100644 index 000000000000..054e49ef0c1e --- /dev/null +++ b/OvmfPkg/RiscVVirt/Sec/SecMain.c @@ -0,0 +1,104 @@ +/** @file + RISC-V SEC phase module for Qemu Virt. + + Copyright (c) 2008 - 2015, Intel Corporation. All rights=20 + reserved.
Copyright (c) 2022, Ventana Micro Systems Inc. All=20 + rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "SecMain.h" + +STATIC +EFI_STATUS +EFIAPI +SecInitializePlatform ( + VOID + ) +{ + EFI_STATUS Status; + + MemoryPeimInitialization (); + + CpuPeimInitialization (); + + // Set the Boot Mode + SetBootMode (BOOT_WITH_FULL_CONFIGURATION); + + Status =3D PlatformPeimInitialization (); ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} + +/** + + Entry point to the C language phase of SEC. After the SEC assembly =20 + code has initialized some temporary memory and set up the stack, the=20 + control is transferred to this function. + + + @param[in] BootHartId Hardware thread ID of boot hart. + @param[in] DeviceTreeAddress Pointer to Device Tree (DTB) **/ VOID=20 +NORETURN EFIAPI SecStartup ( + IN UINTN BootHartId, + IN VOID *DeviceTreeAddress + ) +{ + EFI_HOB_HANDOFF_INFO_TABLE *HobList; + EFI_RISCV_FIRMWARE_CONTEXT FirmwareContext; + EFI_STATUS Status; + UINT64 UefiMemoryBase; + UINT64 StackBase; + + // + // Report Status Code to indicate entering SEC core // DEBUG (( + DEBUG_INFO, + "%a() BootHartId: 0x%x, DeviceTreeAddress=3D0x%x\n", + __FUNCTION__, + BootHartId, + DeviceTreeAddress + )); + + FirmwareContext.BootHartId =3D BootHartId; + FirmwareContext.FlattenedDeviceTree =3D (UINT64)DeviceTreeAddress; =20 + SetFirmwareContextPointer (&FirmwareContext); + + StackBase =3D (UINT64)FixedPcdGet32 (PcdOvmfSecPeiTempRamBase); + UefiMemoryBase =3D StackBase + FixedPcdGet32=20 + (PcdOvmfSecPeiTempRamSize) - SIZE_32MB; + + // Declare the PI/UEFI memory region + HobList =3D HobConstructor ( + (VOID *)UefiMemoryBase, + SIZE_32MB, + (VOID *)UefiMemoryBase, + (VOID *)StackBase // The top of the UEFI Memory is reserved = for the stacks + ); + PrePeiSetHobList (HobList); + + SecInitializePlatform (); + + // + // Process all libraries constructor function linked to SecMain. + // + ProcessLibraryConstructorList (); + + // Assume the FV that contains the SEC (our code) also contains a compre= ssed FV. + Status =3D DecompressFirstFv (); + ASSERT_EFI_ERROR (Status); + + // Load the DXE Core and transfer control to it + Status =3D LoadDxeCoreFromFv (NULL, 0); + ASSERT_EFI_ERROR (Status); + // + // Should not come here. + // + UNREACHABLE (); +} diff --git a/OvmfPkg/RiscVVirt/Sec/SecEntry.S b/OvmfPkg/RiscVVirt/Sec/SecEn= try.S new file mode 100644 index 000000000000..e919a3cb0e80 --- /dev/null +++ b/OvmfPkg/RiscVVirt/Sec/SecEntry.S @@ -0,0 +1,21 @@ +/* + 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