From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4D37F81D5B for ; Tue, 8 Nov 2016 06:11:58 -0800 (PST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 08 Nov 2016 06:12:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,462,1473145200"; d="scan'208";a="1201391" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by orsmga002.jf.intel.com with ESMTP; 08 Nov 2016 06:12:01 -0800 Received: from fmsmsx158.amr.corp.intel.com (10.18.116.75) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 8 Nov 2016 06:12:00 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by fmsmsx158.amr.corp.intel.com (10.18.116.75) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 8 Nov 2016 06:12:00 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.206]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.209]) with mapi id 14.03.0248.002; Tue, 8 Nov 2016 22:11:57 +0800 From: "Zhang, Chao B" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" CC: "Gao, Liming" Thread-Topic: [PATCH v2 2/9] MdeModulePkg/UefiBootManager: Add EfiBootManagerDispatchDeferredImages Thread-Index: AQHSObvPPBoQYg/1vESjlw3O/Phn3qDPIHTA Date: Tue, 8 Nov 2016 14:11:57 +0000 Message-ID: References: <20161108122928.53984-1-ruiyu.ni@intel.com> <20161108122928.53984-3-ruiyu.ni@intel.com> In-Reply-To: <20161108122928.53984-3-ruiyu.ni@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_IC x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMDJkZGZiNWEtOGQ0My00NjFhLThjYWUtN2MxYTExMDVkM2E0IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6IkN0UXRoZXNqS0hUNUZwNEtQNnphR2ViZ3lSSlpXdkdRcndNRFUxU1J0ZTg9In0= x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v2 2/9] MdeModulePkg/UefiBootManager: Add EfiBootManagerDispatchDeferredImages X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Nov 2016 14:11:58 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Chao Zhang Thanks & Best regards Chao Zhang -----Original Message----- From: Ni, Ruiyu=20 Sent: Tuesday, November 08, 2016 8:29 PM To: edk2-devel@lists.01.org Cc: Gao, Liming; Zhang, Chao B Subject: [PATCH v2 2/9] MdeModulePkg/UefiBootManager: Add EfiBootManagerDis= patchDeferredImages The API dispatches the deferred images that are returned from all DeferredImageLoad instances. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Liming Gao Cc: Chao B Zhang --- MdeModulePkg/Include/Library/UefiBootManagerLib.h | 13 +++ MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c | 113 +++++++++++++++++= ++++ .../Library/UefiBootManagerLib/InternalBm.h | 1 + .../UefiBootManagerLib/UefiBootManagerLib.inf | 1 + 4 files changed, 128 insertions(+) diff --git a/MdeModulePkg/Include/Library/UefiBootManagerLib.h b/MdeModuleP= kg/Include/Library/UefiBootManagerLib.h index e333ffd..97ac1f2 100644 --- a/MdeModulePkg/Include/Library/UefiBootManagerLib.h +++ b/MdeModulePkg/Include/Library/UefiBootManagerLib.h @@ -777,4 +777,17 @@ EfiBootManagerIsValidLoadOptionVariableName ( OUT UINT16 *OptionNumber OPTIONAL ); =20 + +/** + Dispatch the deferred images that are returned from all DeferredImageLoa= d instances. + + @retval EFI_SUCCESS At least one deferred image is loaded successf= ully and started. + @retval EFI_NOT_FOUND There is no deferred image. + @retval EFI_ACCESS_DENIED There are deferred images but all of them are = failed to load. +**/ +EFI_STATUS +EFIAPI +EfiBootManagerDispatchDeferredImages ( + VOID + ); #endif diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c b/MdeModulePk= g/Library/UefiBootManagerLib/BmMisc.c index 2a60f06..09e4211 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c @@ -417,3 +417,116 @@ BmCharToUint ( return (UINTN) -1; } =20 +/** + Dispatch the deferred images that are returned from all DeferredImageLoa= d instances. + + @retval EFI_SUCCESS At least one deferred image is loaded successf= ully and started. + @retval EFI_NOT_FOUND There is no deferred image. + @retval EFI_ACCESS_DENIED There are deferred images but all of them are = failed to load. +**/ +EFI_STATUS +EFIAPI +EfiBootManagerDispatchDeferredImages ( + VOID + ) +{ + EFI_STATUS Status; + EFI_DEFERRED_IMAGE_LOAD_PROTOCOL *DeferredImage; + UINTN HandleCount; + EFI_HANDLE *Handles; + UINTN Index; + UINTN ImageIndex; + EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath; + VOID *Image; + UINTN ImageSize; + BOOLEAN BootOption; + EFI_HANDLE ImageHandle; + UINTN ExitDataSize; + CHAR16 *ExitData; + UINTN ImageCount; + UINTN LoadCount; + + // + // Find all the deferred image load protocols. + // + HandleCount =3D 0; + Handles =3D NULL; + Status =3D gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiDeferredImageLoadProtocolGuid, + NULL, + &HandleCount, + &Handles + ); + if (EFI_ERROR (Status)) { + return EFI_NOT_FOUND; + } + + ImageCount =3D 0; + LoadCount =3D 0; + for (Index =3D 0; Index < HandleCount; Index++) { + Status =3D gBS->HandleProtocol (Handles[Index], &gEfiDeferredImageLoad= ProtocolGuid, (VOID **) &DeferredImage); + if (EFI_ERROR (Status)) { + continue; + } + + for (ImageIndex =3D 0; ;ImageIndex++) { + // + // Load all the deferred images in this protocol instance. + // + Status =3D DeferredImage->GetImageInfo ( + DeferredImage, + ImageIndex, + &ImageDevicePath, + (VOID **) &Image, + &ImageSize, + &BootOption + ); + if (EFI_ERROR (Status)) { + break; + } + ImageCount++; + // + // Load and start the image. + // + Status =3D gBS->LoadImage ( + BootOption, + gImageHandle, + ImageDevicePath, + NULL, + 0, + &ImageHandle + ); + if (!EFI_ERROR (Status)) { + LoadCount++; + // + // Before calling the image, enable the Watchdog Timer for + // a 5 Minute period + // + gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL); + Status =3D gBS->StartImage (ImageHandle, &ExitDataSize, &ExitData)= ; + if (ExitData !=3D NULL) { + FreePool (ExitData); + } + + // + // Clear the Watchdog Timer after the image returns. + // + gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL); + } + } + } + if (Handles !=3D NULL) { + FreePool (Handles); + } + + if (ImageCount =3D=3D 0) { + return EFI_NOT_FOUND; + } else { + if (LoadCount =3D=3D 0) { + return EFI_ACCESS_DENIED; + } else { + return EFI_SUCCESS; + } + } +} diff --git a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h b/MdeModu= lePkg/Library/UefiBootManagerLib/InternalBm.h index cb719e9..444d4a5 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h +++ b/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h @@ -44,6 +44,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER= EXPRESS OR IMPLIED. #include #include #include +#include =20 #include #include diff --git a/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf= b/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf index 8c3fd7f..bb7c00d 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf +++ b/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf @@ -109,6 +109,7 @@ [Protocols] gEfiDriverHealthProtocolGuid ## SOMETIMES_CONSUMES gEfiFormBrowser2ProtocolGuid ## SOMETIMES_CONSUMES gEfiRamDiskProtocolGuid ## SOMETIMES_CONSUMES + gEfiDeferredImageLoadProtocolGuid ## CONSUMES =20 [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange = ## SOMETIMES_CONSUMES --=20 2.9.0.windows.1