From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web11.3875.1685427711444344273 for ; Mon, 29 May 2023 23:21:52 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=j5TQL3NV; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: ray.ni@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685427711; x=1716963711; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=7v3lfOe9OIaHXvodXjM1boWnte8hyjix3QNmUhLb7bo=; b=j5TQL3NVaaKYsYogrmNkSEaDEQtRtWV8LKOSykDyuL15r3YknFGn2zSm FaG0rM47l/oFoXIXuj+8fJrRi3Q+ANOmZuRm8Ah0PPnxDD5ObbpB25iCc nrZaFY1Hh0HrN0714TmWNWkK+P+dU8KoCUeVMUSZjS/sdM8rhpXThr5kL eaUOt9hdZIspzTMbdf2K0Ht8MxtPsMdA2NeUj/gxEPJGivqbcpluAr1Ti zMxJtZXlhEI+LzIDLlCyR8M5aezrVR6fRFn+tkcRenTcl4eJFUJZOmNFD o5ilZ0ODovh7/+mou1N1ptKjfK6UDP/mPETEhfuq4Q/1OUoSVAnQOVXAB Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="418312493" X-IronPort-AV: E=Sophos;i="6.00,203,1681196400"; d="scan'208";a="418312493" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 May 2023 23:21:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="952989145" X-IronPort-AV: E=Sophos;i="6.00,203,1681196400"; d="scan'208";a="952989145" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by fmsmga006.fm.intel.com with ESMTP; 29 May 2023 23:21:45 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 29 May 2023 23:21:44 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 29 May 2023 23:21:44 -0700 Received: from ORSEDG602.ED.cps.intel.com (10.7.248.7) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Mon, 29 May 2023 23:21:44 -0700 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.173) by edgegateway.intel.com (134.134.137.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.23; Mon, 29 May 2023 23:21:43 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DLThV57Ogcl0jtO2v1R/JLp1BFngsP30txPhw++sIp9YThrioDBlF2Vv01f23BgQLxt3yxZhVmz32yOWD8hthMAg89rzRE+EFxCVyK2nEAhki0sb9TIkmfGKN9rMTzVtB0kDV6TVYmsUbUbc/ZbGpyJ1hi7xerNzOBhHys6fwhs2E/Y0h11dO6rXpfLqFc2RrNxUJiGqWPekWvRbWqyCZRzIy8wij2XCGnTZDcncXclwZOjdoIQfLv2K8B9WvOQKPTgrgWoHtNlvbiSI33jHToU3eJfn8t+IGLKQfDeS+sWiZZVmZ62qswRdzQ+pWMiW7TtUiD0p3KifjLEieJUb1A== 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=AlTw6GFmkA4HYLBIx8JJ/78HpxDwuuZl5ZA4i2E/pYw=; b=DC7RcxuauVc2cfxcWMsJ4WVLNvgxsa1kLt218kkKLFS1vyvAn1w70xWoius+XuRyZrwby+M4ARzLgM6qGz812C05FIzvhOXk60/CnEIGR/zVdp4x4rvm1irrF+wfpqxzzbMU/WInnZj8z6zn0S7/JhfedvvdfTsb4++uqdDAfc12/V3nv4BC18CBcZy7OP1tL+xkB5NU7a3LJTs+8urEhUMAH6w3u2E2um7jz3UZ1ezlsaG4vFIWMqJFFjdBpklghQKvAS4n9aR8DZbz9qDy6x4wc4nb2KgDZeyvgHFkR5Rrmnjq5aogZ2M/JfkBxfHmWJDc+EhYo/WLykquZQj+qw== 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 MN6PR11MB8244.namprd11.prod.outlook.com (2603:10b6:208:470::14) by PH7PR11MB6979.namprd11.prod.outlook.com (2603:10b6:510:207::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.22; Tue, 30 May 2023 06:21:34 +0000 Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::892b:b8e6:bab7:635d]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::892b:b8e6:bab7:635d%5]) with mapi id 15.20.6433.018; Tue, 30 May 2023 06:21:33 +0000 From: "Ni, Ray" To: Ard Biesheuvel , "devel@edk2.groups.io" CC: "Yao, Jiewen" , Gerd Hoffmann , Taylor Beebe , Oliver Smith-Denny , "Bi, Dandan" , "Gao, Liming" , "Kinney, Michael D" , Leif Lindholm , Michael Kubacki Subject: Re: [RFC PATCH 05/11] MdeModulePkg/DxeCore: Use memory mapped FV protocol to avoid image copy Thread-Topic: [RFC PATCH 05/11] MdeModulePkg/DxeCore: Use memory mapped FV protocol to avoid image copy Thread-Index: AQHZkhbRcWfmpFxJ5k+ZOqPoaXAwbq9yV02Q Date: Tue, 30 May 2023 06:21:33 +0000 Message-ID: References: <20230529101705.2476949-1-ardb@kernel.org> <20230529101705.2476949-6-ardb@kernel.org> In-Reply-To: <20230529101705.2476949-6-ardb@kernel.org> 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: MN6PR11MB8244:EE_|PH7PR11MB6979:EE_ x-ms-office365-filtering-correlation-id: cc7bd04b-832d-4f4c-b9f3-08db60d61d36 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: D84LdKo7fwsTQLTVynnUCd+7X4fl7P2Tf14lxPrSkGEx/nJp9NAPHG0ZDOW0kmw+8IBCVy8LRMm56J1qtBewooglxshVsTim1DMyeLNyXMTiURLXwq+P/8/JbcOia6IIqjBXwXNSN11lKXQV9hZ1B+wJXCTNnucwxWlfUI8Rhi3+Nm3DlZSgvxTuODjosjJ4GnLzrspZcZcmjcg/VAixX8X7pmuHcyt04ZMR1aw4eSfidAuGR9IcWL7Yn2Datjkp4aRcQp4U07KnZd2W5GM8VSpYpZ0MuVYZIOkRpPFOX42bvN0HcbJKiLBVEkk/U6ZaTTTFjUhEpnjhXeEPzj5c4uoth+9Ya5iV9mfjLGczmfWof2qT49MDWb9XK3c4poytPrgakAcC5eT1U08nVTjQY4YW50CLpE81O8J0Oy5aUN7LiiFQfvxXH4DB8kNnAhhCsN7t50bUsfxoFoi0KTsg15WIqkXzfnDHwkbgEEin3PtkHvsKggCdyxutMAdI3XI8lOWU1kJxSYKZy8XTvCw6ikgGNC8eIM1oTyWMpr4A5/Ad674wWrZ4anxEJZsvktyLP4FomreV3DdB4nnD8hyEiMT71jw6Q7RDbty1RHCHmHc2/6JgRzxgAZl17Nn7YyCK x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN6PR11MB8244.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(376002)(366004)(396003)(136003)(346002)(451199021)(122000001)(38100700002)(41300700001)(316002)(38070700005)(82960400001)(4326008)(33656002)(71200400001)(86362001)(2906002)(7696005)(8676002)(8936002)(52536014)(76116006)(66946007)(64756008)(66476007)(66556008)(53546011)(66446008)(54906003)(9686003)(110136005)(6506007)(19627235002)(26005)(83380400001)(478600001)(186003)(5660300002)(55016003);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?IHiuTjPTEOuIwhHPv+CpfGY6r/R3SDWkhf4ApE+f/yWoJ0s8ebkyJG4xMS7W?= =?us-ascii?Q?T0UX5nDmaAKexjpXir2ud2N1ZAMCMogQkq1XylYSXMrRHwtG3NfiZP7AFmmc?= =?us-ascii?Q?H9QDTbj+dp+Q4OgF6LDwg9HmLYxMjFH8yfrrggB6IxTWD2I2lppS5ePQGULl?= =?us-ascii?Q?hRmW/EkSQG0xmMj9esN5b/k4StXPiV/khGdyAdIQn6fC6Xzyu5ZSj8X5qHbU?= =?us-ascii?Q?HuteBGbG7j+bckLxsK0HUJ9zPGHowm+wAWCqVFZW7dK0hISZTS02vMDs4UU1?= =?us-ascii?Q?KB69wsW6hpFl3SCvE+JjQYjvc2v/Wjra6uiX7h8jLAQsZRcPnw4OU6o7ATFS?= =?us-ascii?Q?ur4hZci91Hpa6lwxhir8HARQsoZrqkdO0dQFQYuLtRQGxyl9NrhDnpsPgW0P?= =?us-ascii?Q?/6y3/nIoz5pRiSxRaseT0KHqr19a0u6Ojgzpt1pxlGXeBNFTHEElCmky9bn4?= =?us-ascii?Q?qIYu/iSgvt+ycq83ub7cXzBGBIyFr0BrFpKsZK5nN77B8B+int5xJPlqHJzH?= =?us-ascii?Q?Tvdjxfbi49Dh/K5XZ6J6FH7qpPuxuDr/sdSUxLsZtdQG77xLcZI9kVTO7/7s?= =?us-ascii?Q?cnAGje1cW5jqkvKhDwGkmMcw/jdLeFs28ZChqEKcAD91R70JmXiRntRjot4f?= =?us-ascii?Q?K24fSWLUZaDcXqPGK9/2bkK9Lb0AlIdavP9ZPebRiD4Uheub1zKjstud6a+Y?= =?us-ascii?Q?e3kuev8qC/QI62jL4Sqyy/z5sU1GxCJNIIZnY4XhdqtzduHKrCSuzKlvkRJi?= =?us-ascii?Q?3c/2bYpcYZq17CLazQw48cuwVY38XP03bwmu5iQLccqxUQjF5/ylfiEwC60y?= =?us-ascii?Q?HU/3lTYPEVCbmEckmfduhQzLN800ThLAHKJQVzVGXNTgDJrNsePFs0HBrAIc?= =?us-ascii?Q?jXmB/wJv0dkeFaG93JFQE3sM7xovPovbaBR5NoUvg14psxMWwj6hxXEVqsvv?= =?us-ascii?Q?6YtC5qIZ53gtAexTZn6ZsOLFaKcJHfbv4Tjly/HBGBRi4hehf6uha7nHxvIB?= =?us-ascii?Q?E9TngBiTceCHzwM8ovcdW54w7nqpQ+R7UesZgSr/R8S/NRNnV5J5rAMLnq4x?= =?us-ascii?Q?DoxFC/PSNVri5WInUf/PpBADPu405NYS+NsdDx646AMrNr2RNYd9mYmCcpF7?= =?us-ascii?Q?7qcjmj2aBhQLhzvd8M28CEusXz46XGRrLYgfJjTk0GLsGiSxRx/QGiWu8ehN?= =?us-ascii?Q?nFQOReJELSw9ooqXj2Zy5X7YTL0Vl1ZoWhOIx8pmp8eX+rsTlsI5Js2Ewztf?= =?us-ascii?Q?Qrt09GBhwKcB5TSPeTemYrSRCzRxVUtneJyiIouxvR/6oxb7R2N+iW6MHkqd?= =?us-ascii?Q?0GZ5yr4fdzj5slYjEZoEU7Thi4e5Zhkbof6xhdrMD3QAKrMQXG0C8SCdqHvt?= =?us-ascii?Q?myA5Fn0L4KJy5h3RGsDomDc54vqUEskctnnjuUdNankSeWlKRmmQVTur8Zs/?= =?us-ascii?Q?1UeB1kMytJa6ca6yQ0gqJzOyzLN2AHuo3EmnuucI4zsXv07P4dNdjNbfyx7f?= =?us-ascii?Q?zLHlaYSsBAb0I9X4jNJBkz4GdLXa9S4V9CfHYG+bI7o97z86D/VDQ/uTFTzf?= =?us-ascii?Q?Kqanw4KqEiI6w69W96Q=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN6PR11MB8244.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: cc7bd04b-832d-4f4c-b9f3-08db60d61d36 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 May 2023 06:21:33.1864 (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: P5UfcxcdtqYPPkiqtmeMxXxdfXRA9iRyu5lJ9fq6xVNFB4s5Wj3+d7CMm7dBIBpkCIVjcwFKOAxSTJmo8ZBOVg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR11MB6979 Return-Path: ray.ni@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable GetFileBufferByFilePath() always returns a copy of file buffer even when th= e file is in a memory-mapped device. So, your patch adds a new implementation (abstracted through the new MM FV = protocol) that can directly return the file location in the MMIO device. Several comments: 1. I am not sure if any negative impact due to this change. For example: ol= d logic reads the MMIO device but doesn't execute in the MMIO device. Does = MMIO device always support execution in place? 2. If the MMFV protocol is only produced by DxeCore and consumed by DxeCore= , can we just implement a local function instead? The challenge might be ho= w to pass the FV_DEVICE instance to the local function. Can we "handle" the= "FirmwareVolume2" protocol from the Handle first and use CR_FROM_THIS() ma= cro to retrieve the FV_DEVICE pointer? This helps to not add the MMFV proto= col, letting the change a pure DxeCore internal thing. Thanks, Ray > -----Original Message----- > From: Ard Biesheuvel > Sent: Monday, May 29, 2023 6:17 PM > To: devel@edk2.groups.io > Cc: Ard Biesheuvel ; Ni, Ray ; Yao, Ji= ewen > ; Gerd Hoffmann ; Taylor Beebe > ; Oliver Smith-Denny ; Bi, Dandan > ; Gao, Liming ; Kinney, > Michael D ; Leif Lindholm > ; Michael Kubacki > Subject: [RFC PATCH 05/11] MdeModulePkg/DxeCore: Use memory mapped FV > protocol to avoid image copy >=20 > Use the memory mapped FV protocol to obtain the existing location in > memory and the size of an image being loaded from a firmware volume. > This removes the need to do a memcopy of the file data. >=20 > Signed-off-by: Ard Biesheuvel > --- > MdeModulePkg/Core/Dxe/DxeMain.h | 1 + > MdeModulePkg/Core/Dxe/DxeMain.inf | 3 + > MdeModulePkg/Core/Dxe/Image/Image.c | 111 +++++++++++++++++--= - > MdeModulePkg/Include/Protocol/MemoryMappedFv.h | 59 +++++++++++ > MdeModulePkg/MdeModulePkg.dec | 3 + > 5 files changed, 163 insertions(+), 14 deletions(-) >=20 > diff --git a/MdeModulePkg/Core/Dxe/DxeMain.h > b/MdeModulePkg/Core/Dxe/DxeMain.h > index 43daa037be441150..a695b457c79b65bb 100644 > --- a/MdeModulePkg/Core/Dxe/DxeMain.h > +++ b/MdeModulePkg/Core/Dxe/DxeMain.h > @@ -45,6 +45,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > #include >=20 > #include >=20 > #include >=20 > +#include >=20 > #include >=20 > #include >=20 > #include >=20 > diff --git a/MdeModulePkg/Core/Dxe/DxeMain.inf > b/MdeModulePkg/Core/Dxe/DxeMain.inf > index 35d5bf0dee6f7f3f..a7175cb364b9b5de 100644 > --- a/MdeModulePkg/Core/Dxe/DxeMain.inf > +++ b/MdeModulePkg/Core/Dxe/DxeMain.inf > @@ -153,6 +153,9 @@ [Protocols] > gEfiLoadedImageDevicePathProtocolGuid ## PRODUCES >=20 > gEfiHiiPackageListProtocolGuid ## SOMETIMES_PRODUCES >=20 > gEfiSmmBase2ProtocolGuid ## SOMETIMES_CONSUMES >=20 > + ## PRODUCES >=20 > + ## CONSUMES >=20 > + gEdkiiMemoryMappedFvProtocolGuid >=20 > gEdkiiPeCoffImageEmulatorProtocolGuid ## SOMETIMES_CONSUMES >=20 >=20 >=20 > # Arch Protocols >=20 > diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c > b/MdeModulePkg/Core/Dxe/Image/Image.c > index f30e369370a09609..3dfab4829b3ca17f 100644 > --- a/MdeModulePkg/Core/Dxe/Image/Image.c > +++ b/MdeModulePkg/Core/Dxe/Image/Image.c > @@ -1043,6 +1043,76 @@ CoreUnloadAndCloseImage ( > CoreFreePool (Image); >=20 > } >=20 >=20 >=20 > +/** >=20 > + Get the image file data and size directly from a memory mapped FV >=20 > + >=20 > + If FilePath is NULL, then NULL is returned. >=20 > + If FileSize is NULL, then NULL is returned. >=20 > + If AuthenticationStatus is NULL, then NULL is returned. >=20 > + >=20 > + @param[in] FvHandle The firmware volume handle >=20 > + @param[in] FilePath The pointer to the device path o= f the file >=20 > + that is abstracted to the file b= uffer. >=20 > + @param[out] FileSize The pointer to the size of the a= bstracted >=20 > + file buffer. >=20 > + @param[out] AuthenticationStatus Pointer to the authentication st= atus. >=20 > + >=20 > + @retval NULL FilePath is NULL, or FileSize is NULL, or Authenticatio= nStatus >=20 > + is NULL, or the file is not memory mapped >=20 > + @retval other The abstracted file buffer. >=20 > +**/ >=20 > +STATIC >=20 > +VOID * >=20 > +GetFileFromMemoryMappedFv ( >=20 > + IN EFI_HANDLE FvHandle, >=20 > + IN CONST EFI_DEVICE_PATH_PROTOCOL *FilePath, >=20 > + OUT UINTN *FileSize, >=20 > + OUT UINT32 *AuthenticationStatus >=20 > + ) >=20 > +{ >=20 > + EDKII_MEMORY_MAPPED_FV_PROTOCOL *MemMappedFv; >=20 > + CONST EFI_GUID *NameGuid; >=20 > + EFI_PHYSICAL_ADDRESS Address; >=20 > + EFI_STATUS Status; >=20 > + >=20 > + if ((FilePath =3D=3D NULL) || >=20 > + (FileSize =3D=3D NULL) || >=20 > + (AuthenticationStatus =3D=3D NULL)) >=20 > + { >=20 > + return NULL; >=20 > + } >=20 > + >=20 > + NameGuid =3D EfiGetNameGuidFromFwVolDevicePathNode ( >=20 > + (CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)FilePath); >=20 > + if (NameGuid =3D=3D NULL) { >=20 > + return NULL; >=20 > + } >=20 > + >=20 > + Status =3D gBS->HandleProtocol ( >=20 > + FvHandle, >=20 > + &gEdkiiMemoryMappedFvProtocolGuid, >=20 > + (VOID **)&MemMappedFv >=20 > + ); >=20 > + if (EFI_ERROR (Status)) { >=20 > + ASSERT (Status =3D=3D EFI_UNSUPPORTED); >=20 > + return NULL; >=20 > + } >=20 > + >=20 > + Status =3D MemMappedFv->GetLocationAndSize ( >=20 > + MemMappedFv, >=20 > + NameGuid, >=20 > + EFI_SECTION_PE32, >=20 > + &Address, >=20 > + FileSize, >=20 > + AuthenticationStatus >=20 > + ); >=20 > + if (EFI_ERROR (Status) || (Address > (MAX_ADDRESS - *FileSize))) { >=20 > + return NULL; >=20 > + } >=20 > + >=20 > + return (VOID *)(UINTN)Address; >=20 > +} >=20 > + >=20 > /** >=20 > Loads an EFI image into memory and returns a handle to the image. >=20 >=20 >=20 > @@ -1164,6 +1234,16 @@ CoreLoadImageCommon ( > Status =3D CoreLocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, > &HandleFilePath, &DeviceHandle); >=20 > if (!EFI_ERROR (Status)) { >=20 > ImageIsFromFv =3D TRUE; >=20 > + >=20 > + // >=20 > + // If possible, use the memory mapped file image directly, rather = than > copying it into a buffer >=20 > + // >=20 > + FHand.Source =3D GetFileFromMemoryMappedFv ( >=20 > + DeviceHandle, >=20 > + HandleFilePath, >=20 > + &FHand.SourceSize, >=20 > + &AuthenticationStatus >=20 > + ); >=20 > } else { >=20 > HandleFilePath =3D FilePath; >=20 > Status =3D CoreLocateDevicePath (&gEfiSimpleFileSystemProt= ocolGuid, > &HandleFilePath, &DeviceHandle); >=20 > @@ -1187,21 +1267,24 @@ CoreLoadImageCommon ( > // >=20 > // Get the source file buffer by its device path. >=20 > // >=20 > - FHand.Source =3D GetFileBufferByFilePath ( >=20 > - BootPolicy, >=20 > - FilePath, >=20 > - &FHand.SourceSize, >=20 > - &AuthenticationStatus >=20 > - ); >=20 > if (FHand.Source =3D=3D NULL) { >=20 > - Status =3D EFI_NOT_FOUND; >=20 > - } else { >=20 > - FHand.FreeBuffer =3D TRUE; >=20 > - if (ImageIsFromLoadFile) { >=20 > - // >=20 > - // LoadFile () may cause the device path of the Handle be update= d. >=20 > - // >=20 > - OriginalFilePath =3D AppendDevicePath (DevicePathFromHandle > (DeviceHandle), Node); >=20 > + FHand.Source =3D GetFileBufferByFilePath ( >=20 > + BootPolicy, >=20 > + FilePath, >=20 > + &FHand.SourceSize, >=20 > + &AuthenticationStatus >=20 > + ); >=20 > + >=20 > + if (FHand.Source =3D=3D NULL) { >=20 > + Status =3D EFI_NOT_FOUND; >=20 > + } else { >=20 > + FHand.FreeBuffer =3D TRUE; >=20 > + if (ImageIsFromLoadFile) { >=20 > + // >=20 > + // LoadFile () may cause the device path of the Handle be upda= ted. >=20 > + // >=20 > + OriginalFilePath =3D AppendDevicePath (DevicePathFromHandle > (DeviceHandle), Node); >=20 > + } >=20 > } >=20 > } >=20 > } >=20 > diff --git a/MdeModulePkg/Include/Protocol/MemoryMappedFv.h > b/MdeModulePkg/Include/Protocol/MemoryMappedFv.h > new file mode 100644 > index 0000000000000000..821009122113a658 > --- /dev/null > +++ b/MdeModulePkg/Include/Protocol/MemoryMappedFv.h > @@ -0,0 +1,59 @@ > +/** @file >=20 > + Protocol to obtain information about files in memory mapped firmware > volumes >=20 > + >=20 > + Copyright (c) 2023, Google LLC. All rights reserved.
>=20 > + >=20 > + SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > + >=20 > +**/ >=20 > + >=20 > +#ifndef EDKII_MEMORY_MAPPED_FV_H_ >=20 > +#define EDKII_MEMORY_MAPPED_FV_H_ >=20 > + >=20 > +#define EDKII_MEMORY_MAPPED_FV_PROTOCOL_GUID \ >=20 > + { 0xb9bfa973, 0x5384, 0x441e, { 0xa4, 0xe7, 0x20, 0xe6, 0x5d, 0xaf, 0x= 2e, > 0x0f } } >=20 > + >=20 > +typedef struct _EDKII_MEMORY_MAPPED_FV_PROTOCOL > EDKII_MEMORY_MAPPED_FV_PROTOCOL; >=20 > + >=20 > +// >=20 > +// Function Prototypes >=20 > +// >=20 > + >=20 > +/** >=20 > + Get the physical address and size of a file's section in a memory mapp= ed FV >=20 > + >=20 > + @param[in] This The protocol pointer >=20 > + @param[in] NameGuid The name GUID of the file >=20 > + @param[in] SectionType The file section from which to retrieve addr= ess and > size >=20 > + @param[out] FileAddress The physical address of the file >=20 > + @param[out] FileSize The size of the file >=20 > + @param[out] AuthStatus The authentication status associated with th= e file >=20 > + >=20 > + @retval EFI_SUCCESS Information about the file was retrieve= d > successfully. >=20 > + @retval EFI_INVALID_PARAMETER FileAddress was NULL, FileSize was NULL= , > AuthStatus >=20 > + was NULL. >=20 > + @retval EFI_NOT_FOUND No section of the specified type could = be > located in >=20 > + the specified file. >=20 > + >=20 > +**/ >=20 > +typedef >=20 > +EFI_STATUS >=20 > +(EFIAPI *GET_LOCATION_AND_SIZE)( >=20 > + IN EDKII_MEMORY_MAPPED_FV_PROTOCOL *This, >=20 > + IN CONST EFI_GUID *NameGuid, >=20 > + IN EFI_SECTION_TYPE SectionType, >=20 > + OUT EFI_PHYSICAL_ADDRESS *FileAddress, >=20 > + OUT UINTN *FileSize, >=20 > + OUT UINT32 *AuthStatus >=20 > + ); >=20 > + >=20 > +// >=20 > +// Protocol interface structure >=20 > +// >=20 > +struct _EDKII_MEMORY_MAPPED_FV_PROTOCOL { >=20 > + GET_LOCATION_AND_SIZE GetLocationAndSize; >=20 > +}; >=20 > + >=20 > +extern EFI_GUID gEdkiiMemoryMappedFvProtocolGuid; >=20 > + >=20 > +#endif >=20 > diff --git a/MdeModulePkg/MdeModulePkg.dec > b/MdeModulePkg/MdeModulePkg.dec > index d65dae18aa81e569..2d72ac733d82195e 100644 > --- a/MdeModulePkg/MdeModulePkg.dec > +++ b/MdeModulePkg/MdeModulePkg.dec > @@ -679,6 +679,9 @@ [Protocols] > ## Include/Protocol/PlatformBootManager.h >=20 > gEdkiiPlatformBootManagerProtocolGuid =3D { 0xaa17add4, 0x756c, 0x460d= , > { 0x94, 0xb8, 0x43, 0x88, 0xd7, 0xfb, 0x3e, 0x59 } } >=20 >=20 >=20 > + ## Include/Protocol/MemoryMappedFv.h >=20 > + gEdkiiMemoryMappedFvProtocolGuid =3D { 0xb9bfa973, 0x5384, 0x441e, { 0= xa4, > 0xe7, 0x20, 0xe6, 0x5d, 0xaf, 0x2e, 0x0f } } >=20 > + >=20 > # >=20 > # [Error.gEfiMdeModulePkgTokenSpaceGuid] >=20 > # 0x80000001 | Invalid value provided. >=20 > -- > 2.39.2