From nobody Wed Apr 24 20:19:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+73312+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+73312+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=hpe.com ARC-Seal: i=1; a=rsa-sha256; t=1616741193; cv=none; d=zohomail.com; s=zohoarc; b=Smr6NBAbYFH7s/6qZRinMznS5TBhhKHbWHnayPCcgOY07caPq+UWCaJ8N+eF07MdCNXQjmpf1x+l20vjDqF4QGj9xtLRSrFHKW6llYB0z+sWv+3nSatdEH7kGIUHO0Q5qqM1FMARlBKyccGClB+q3NtKYSI2NMmyQ17pga/5DQ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616741193; h=Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=9RkMibTfgTGDpkcNh0X8bMIOrTUNFHDMPX73vRlN82E=; b=Ru+2E0ahO59UoBEgyEc6qcIPJSenDDyBrNtHoXm6l6new8driXaVRwtBcBMYHhr9uaH/XXdPLypD6/3GceF8uM2fCaWsUjY5bxBg/qXsomxwjzm3I4NkueEJHagjEg/T2cJLEY0fLh0X6oyfLDvTLyL/9riZpisg/BHCxnv9kz0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+73312+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1616741193966233.6535023266024; Thu, 25 Mar 2021 23:46:33 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id zPmiYY1788612xNObzzos2jL; Thu, 25 Mar 2021 23:46:33 -0700 X-Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web10.9109.1616741192344556378 for ; Thu, 25 Mar 2021 23:46:32 -0700 X-Received: from pps.filterd (m0150244.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 12Q6iime030059 for ; Fri, 26 Mar 2021 06:46:31 GMT X-Received: from g4t3426.houston.hpe.com (g4t3426.houston.hpe.com [15.241.140.75]) by mx0b-002e3701.pphosted.com with ESMTP id 37h138umeu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 26 Mar 2021 06:46:30 +0000 X-Received: from g9t2301.houston.hpecorp.net (g9t2301.houston.hpecorp.net [16.220.97.129]) by g4t3426.houston.hpe.com (Postfix) with ESMTP id 9E7AF59 for ; Fri, 26 Mar 2021 06:46:30 +0000 (UTC) X-Received: from abner-virtual-machine.asiapacific.hpqcorp.net (abner-virtual-machine.asiapacific.hpqcorp.net [15.119.210.153]) by g9t2301.houston.hpecorp.net (Postfix) with ESMTP id B03E54F; Fri, 26 Mar 2021 06:46:29 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: Nickle Wang Subject: [edk2-devel] [PATCH] RedfishPkg/RedfishConfigHandler: EDKII RedfishConfigHandler Protocol Date: Fri, 26 Mar 2021 13:55:20 +0800 Message-Id: <20210326055520.23823-1-abner.chang@hpe.com> X-Proofpoint-ORIG-GUID: NXwPc2NtYQ1onnwR9hVLljftm3zXx-Td X-Proofpoint-GUID: NXwPc2NtYQ1onnwR9hVLljftm3zXx-Td X-HPE-SCL: -1 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abner.chang@hpe.com X-Gm-Message-State: fblhnEYSzSOKZG7uilf6PTJ3x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1616741193; bh=XaDhIqJCTRokirtGUcIxnT2CTe8e6NrxahN1pga2K7E=; h=Cc:Date:From:Reply-To:Subject:To; b=Ln97V+AE+EHqH36BfInQImLfgblgN4vNoAtl6P/vbdjQXhij2TKH7oW/A6DmMYxjE16 L2ZLDTNgsGHkq4t/GXC/YVxktIgXvlTNKbKfusGTXcCy0rse81BZ633wugtJXQYj0fpGd WUkh/EQ1jthJrCwtYTYni6wMGWWDi4EY8ws= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The driver is used to manage EDK2 Redfish Configuration Handler Protocol installed by EDK2 Redfish feature drivers. This is the EDK2 Redfish client driver written based on the EDK2 Redfish foundation to initialize EDK2 Redfish feature drivers. EDK2 Redfish feature drivers are used to provision/consume/update the firmware owns Redfish properties during system power on initialization. RedfishConfigHandlerCommon.c has the common code for the driver instances used in different EDK2 boot phases or used by different driver models in the future contribution. Signed-off-by: Jiaxin Wu Signed-off-by: Siyuan Fu Signed-off-by: Fan Wang Signed-off-by: Abner Chang Cc: Nickle Wang Reviewed-by: Nickle Wang --- RedfishPkg/RedfishComponents.dsc.inc | 3 +- RedfishPkg/Redfish.fdf.inc | 3 +- .../RedfishConfigHandlerDriver.inf | 60 ++ .../RedfishConfigHandlerCommon.h | 101 +++ .../RedfishConfigHandlerDriver.h | 159 +++++ .../RedfishConfigHandlerCommon.c | 265 ++++++++ .../RedfishConfigHandlerDriver.c | 587 ++++++++++++++++++ 7 files changed, 1176 insertions(+), 2 deletions(-) create mode 100644 RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDri= ver.inf create mode 100644 RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCom= mon.h create mode 100644 RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDri= ver.h create mode 100644 RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCom= mon.c create mode 100644 RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDri= ver.c diff --git a/RedfishPkg/RedfishComponents.dsc.inc b/RedfishPkg/RedfishCompo= nents.dsc.inc index 08f1d3bc32..d0116f065c 100644 --- a/RedfishPkg/RedfishComponents.dsc.inc +++ b/RedfishPkg/RedfishComponents.dsc.inc @@ -6,7 +6,7 @@ # of EDKII Redfish drivers according to the value of flags described in # "RedfishDefines.dsc.inc". # -# (C) Copyright 2020 Hewlett Packard Enterprise Development LP
+# (C) Copyright 2021 Hewlett Packard Enterprise Development LP
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -17,4 +17,5 @@ RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterfaceDxe.inf RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf RedfishPkg/RedfishCredentialDxe/RedfishCredentialDxe.inf + RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.inf !endif diff --git a/RedfishPkg/Redfish.fdf.inc b/RedfishPkg/Redfish.fdf.inc index a64fd119a9..9673246b3f 100644 --- a/RedfishPkg/Redfish.fdf.inc +++ b/RedfishPkg/Redfish.fdf.inc @@ -5,7 +5,7 @@ # by using "!include RedfishPkg/RedfisLibs.fdf.inc" to specify the module = instances # to be built in the firmware volume. # -# (C) Copyright 2020 Hewlett Packard Enterprise Development LP
+# (C) Copyright 2021 Hewlett Packard Enterprise Development LP
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -15,4 +15,5 @@ INF RedfishPkg/RedfishHostInterfaceDxe/RedfishHostInterfaceDxe.inf INF RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf INF RedfishPkg/RedfishCredentialDxe/RedfishCredentialDxe.inf + INF RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.inf !endif diff --git a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.inf= b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.inf new file mode 100644 index 0000000000..def91c7531 --- /dev/null +++ b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.inf @@ -0,0 +1,60 @@ +## @file +# INF file for the UEFI driver model Redfish Configuration Handler +# Driver. +# +# Copyright (c) 2019, Intel Corporation. All rights reserved.
+# (C) Copyright 2021 Hewlett Packard Enterprise Development LP
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001000b + BASE_NAME =3D RedfishConfigHandlerDriver + FILE_GUID =3D 6e881000-5749-11e8-9bf0-8cdcd426c973 + MODULE_TYPE =3D UEFI_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D RedfishConfigHandlerDriverEntryPoint + UNLOAD_IMAGE =3D RedfishConfigHandlerDriverUnload + +# +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 RISCV64 +# + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + NetworkPkg/NetworkPkg.dec + RedfishPkg/RedfishPkg.dec + +[Sources] + RedfishConfigHandlerDriver.h + RedfishConfigHandlerDriver.c + RedfishConfigHandlerCommon.h + RedfishConfigHandlerCommon.c + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + UefiLib + MemoryAllocationLib + NetLib + UefiBootServicesTableLib + UefiDriverEntryPoint + +[Protocols] + gEfiRedfishDiscoverProtocolGuid ## CONSUMES + gEfiRestExServiceBindingProtocolGuid + gEfiRestExProtocolGuid ## CONSUMES + gEdkIIRedfishCredentialProtocolGuid ## CONSUMES + gEdkIIRedfishConfigHandlerProtocolGuid ## CONSUMES + +[Guids] + gEfiEventExitBootServicesGuid ## CONSUMES ## Event + gEfiEndOfDxeEventGroupGuid ## CONSUMES ## Event + +[Depex] + TRUE + diff --git a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.h b= /RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.h new file mode 100644 index 0000000000..5e46c42219 --- /dev/null +++ b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.h @@ -0,0 +1,101 @@ +/** @file + Common Header file for Redfish Configuration Handler UEFI driver + and DXE driver. + + (C) Copyright 2021 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef EFI_REDFISH_CONFIG_HANDLER_COMMON_H_ +#define EFI_REDFISH_CONFIG_HANDLER_COMMON_H_ + +#include + +// +// Libraries +// +#include +#include +#include +#include +#include +#include +#include +#include + +// +// Consumed Protocols +// +#include +#include + +// +// Driver Version +// +#define REDFISH_CONFIG_VERSION 0x00000001 + +/// +/// Internal structure used by Redfish Config DXE driver. +/// +typedef struct { + UINT32 CallerId; ///< Caller ID used to indicate Redfish Config = Handler + ///< has been initiated + EFI_HANDLE Image; ///< Image handle of Redfish Config Driver + EFI_EVENT Event; ///< Event for the notification of EFI_REDFISH_= CONFIG_HANDLER_PROTOCOL + REDFISH_CONFIG_SERVICE_INFORMATION RedfishServiceInfo; /// Redfish Servi= ce information discovered +} REDFISH_CONFIG_DRIVER_DATA; + +/** + Common code of unloading image for both UEFI/DXE Redfish Configuration d= rivers. + + @param[in] ImageHandle Handle that identifies the image to be unl= oaded. + + @retval EFI_SUCCESS The image has been unloaded. + +**/ +EFI_STATUS +RedfishConfigDriverCommonUnload ( + IN EFI_HANDLE ImageHandle + ); + +/** + This is the common code for Redfish configuration UEFI and DXE driver + initialization. + + @param[in] ImageHandle The firmware allocated handle for the UEFI= image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The operation completed successfully. + @retval Others An unexpected error occurred. +**/ +EFI_STATUS +RedfishConfigCommonInit ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + +/** + This is the common code to stop EDK2 Redfish feature driver. + + @retval EFI_SUCCESS All EDK2 Redfish feature drivers are + stopped. + @retval Others An unexpected error occurred. +**/ +EFI_STATUS +RedfishConfigCommonStop ( + VOID +); + +/** + Callback function executed when a Redfish Config Handler Protocol is ins= talled + by EDK2 Redfish Feature Drivers. + +**/ +VOID +RedfishConfigHandlerInitialization ( + VOID + ); + +#endif diff --git a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.h b= /RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.h new file mode 100644 index 0000000000..58202c41e2 --- /dev/null +++ b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.h @@ -0,0 +1,159 @@ +/** @file + Header file of Redfish Configuration Handler UEFI driver. + + Copyright (c) 2019, Intel Corporation. All rights reserved.
+ (C) Copyright 2021 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef EFI_REDFISH_CONFIG_HANDLER_DRIVER_H_ +#define EFI_REDFISH_CONFIG_HANDLER_DRIVER_H_ + +#include "RedfishConfigHandlerCommon.h" + +// +// UEFI Driver Model Protocols +// + +#include +#include +#include + +// +// Protocol instances +// +extern EFI_DRIVER_BINDING_PROTOCOL gRedfishConfigDriverBinding; + +extern REDFISH_CONFIG_DRIVER_DATA gRedfishConfigData; +extern EDKII_REDFISH_CREDENTIAL_PROTOCOL *gCredential; +extern EFI_EVENT gEndOfDxeEvent; +extern EFI_EVENT gExitBootServiceEvent; + +/** + Tests to see if this driver supports a given controller. If a child devi= ce is provided, + it further tests to see if this driver supports creating a handle for th= e specified child device. + + This function checks to see if the driver specified by This supports the= device specified by + ControllerHandle. Drivers will typically use the device path attached to + ControllerHandle and/or the services from the bus I/O abstraction attach= ed to + ControllerHandle to determine if the driver supports ControllerHandle. T= his function + may be called many times during platform initialization. In order to red= uce boot times, the tests + performed by this function must be very small, and take as little time a= s possible to execute. This + function must not change the state of any hardware devices, and this fun= ction must be aware that the + device specified by ControllerHandle may already be managed by the same = driver or a + different driver. This function must match its calls to AllocatePages() = with FreePages(), + AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol(). + Because ControllerHandle may have been previously started by the same dr= iver, if a protocol is + already in the opened state, then it must not be closed with CloseProtoc= ol(). This is required + to guarantee the state of ControllerHandle is not modified by this funct= ion. + + @param[in] This A pointer to the EFI_DRIVER_BINDING_PRO= TOCOL instance. + @param[in] ControllerHandle The handle of the controller to test. T= his handle + must support a protocol interface that = supplies + an I/O abstraction to the driver. + @param[in] RemainingDevicePath A pointer to the remaining portion of a= device path. This + parameter is ignored by device drivers,= and is optional for bus + drivers. For bus drivers, if this param= eter is not NULL, then + the bus driver must determine if the bu= s controller specified + by ControllerHandle and the child contr= oller specified + by RemainingDevicePath are both support= ed by this + bus driver. + + @retval EFI_SUCCESS The device specified by ControllerHandl= e and + RemainingDevicePath is supported by the= driver specified by This. + @retval EFI_ALREADY_STARTED The device specified by ControllerHandl= e and + RemainingDevicePath is already being ma= naged by the driver + specified by This. + @retval EFI_ACCESS_DENIED The device specified by ControllerHandl= e and + RemainingDevicePath is already being ma= naged by a different + driver or an application that requires = exclusive access. + Currently not implemented. + @retval EFI_UNSUPPORTED The device specified by ControllerHandl= e and + RemainingDevicePath is not supported by= the driver specified by This. +**/ +EFI_STATUS +EFIAPI +RedfishConfigDriverBindingSupported ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL + ); + +/** + Starts a device controller or a bus controller. + + The Start() function is designed to be invoked from the EFI boot service= ConnectController(). + As a result, much of the error checking on the parameters to Start() has= been moved into this + common boot service. It is legal to call Start() from other locations, + but the following calling restrictions must be followed, or the system b= ehavior will not be deterministic. + 1. ControllerHandle must be a valid EFI_HANDLE. + 2. If RemainingDevicePath is not NULL, then it must be a pointer to a na= turally aligned + EFI_DEVICE_PATH_PROTOCOL. + 3. Prior to calling Start(), the Supported() function for the driver spe= cified by This must + have been called with the same calling parameters, and Supported() mu= st have returned EFI_SUCCESS. + + @param[in] This A pointer to the EFI_DRIVER_BINDING_PRO= TOCOL instance. + @param[in] ControllerHandle The handle of the controller to start. = This handle + must support a protocol interface that = supplies + an I/O abstraction to the driver. + @param[in] RemainingDevicePath A pointer to the remaining portion of a= device path. This + parameter is ignored by device drivers,= and is optional for bus + drivers. For a bus driver, if this para= meter is NULL, then handles + for all the children of Controller are = created by this driver. + If this parameter is not NULL and the f= irst Device Path Node is + not the End of Device Path Node, then o= nly the handle for the + child device specified by the first Dev= ice Path Node of + RemainingDevicePath is created by this = driver. + If the first Device Path Node of Remain= ingDevicePath is + the End of Device Path Node, no child h= andle is created by this + driver. + + @retval EFI_SUCCESS The driver is started. + @retval EFI_ALREADY_STARTED The driver was already started. + +**/ +EFI_STATUS +EFIAPI +RedfishConfigDriverBindingStart ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL + ); + +/** + Stops a device controller or a bus controller. + + The Stop() function is designed to be invoked from the EFI boot service = DisconnectController(). + As a result, much of the error checking on the parameters to Stop() has = been moved + into this common boot service. It is legal to call Stop() from other loc= ations, + but the following calling restrictions must be followed, or the system b= ehavior will not be deterministic. + 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previo= us call to this + same driver's Start() function. + 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a= valid + EFI_HANDLE. In addition, all of these handles must have been created = in this driver's + Start() function, and the Start() function must have called OpenProto= col() on + ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONT= ROLLER. + + @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOC= OL instance. + @param[in] ControllerHandle A handle to the device being stopped. The = handle must + support a bus specific I/O protocol for th= e driver + to use to stop the device. + @param[in] NumberOfChildren The number of child device handles in Chil= dHandleBuffer. + @param[in] ChildHandleBuffer An array of child handles to be freed. May= be NULL + if NumberOfChildren is 0. + + @retval EFI_SUCCESS The device was stopped. + @retval EFI_DEVICE_ERROR The device could not be stopped due to a d= evice error. + +**/ +EFI_STATUS +EFIAPI +RedfishConfigDriverBindingStop ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN UINTN NumberOfChildren, + IN EFI_HANDLE *ChildHandleBuffer OPTIONAL + ); +#endif diff --git a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c b= /RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c new file mode 100644 index 0000000000..ff465d9ff3 --- /dev/null +++ b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerCommon.c @@ -0,0 +1,265 @@ +/** @file + The common code of EDKII Redfish Configuration Handler driver. + + (C) Copyright 2021 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "RedfishConfigHandlerCommon.h" + +REDFISH_CONFIG_DRIVER_DATA gRedfishConfigData; // Only one Redfish se= rvice supproted + // on platform for the= BIOS + // Redfish configurati= on. +EFI_EVENT gEndOfDxeEvent =3D NULL; +EFI_EVENT gExitBootServiceEvent =3D NULL; +EDKII_REDFISH_CREDENTIAL_PROTOCOL *gCredential =3D NULL; + +/** + Callback function executed when the EndOfDxe event group is signaled. + + @param[in] Event Event whose notification function is being invoked. + @param[out] Context Pointer to the Context buffer. + +**/ +VOID +EFIAPI +RedfishConfigOnEndOfDxe ( + IN EFI_EVENT Event, + OUT VOID *Context + ) +{ + EFI_STATUS Status; + + Status =3D gCredential->StopService (gCredential, ServiceStopTypeSecureB= ootDisabled); + if (EFI_ERROR(Status) && Status !=3D EFI_UNSUPPORTED) { + DEBUG ((DEBUG_ERROR, "Redfish credential protocol faied to stop servic= e on EndOfDxe: %r", Status)); + } + + // + // Close event, so it will not be invoked again. + // + gBS->CloseEvent (gEndOfDxeEvent); + gEndOfDxeEvent =3D NULL; +} + +/** + Callback function executed when the ExitBootService event group is signa= led. + + @param[in] Event Event whose notification function is being invoked. + @param[out] Context Pointer to the Context buffer + +**/ +VOID +EFIAPI +RedfishConfigOnExitBootService ( + IN EFI_EVENT Event, + OUT VOID *Context + ) +{ + EFI_STATUS Status; + + Status =3D gCredential->StopService (gCredential, ServiceStopTypeExitBoo= tService); + if (EFI_ERROR(Status) && Status !=3D EFI_UNSUPPORTED) { + DEBUG ((DEBUG_ERROR, "Redfish credential protocol faied to stop servic= e on ExitBootService: %r", Status)); + } +} + +/** + Unloads an image. + + @param[in] ImageHandle Handle that identifies the image to be unl= oaded. + + @retval EFI_SUCCESS The image has been unloaded. + +**/ +EFI_STATUS +RedfishConfigDriverCommonUnload ( + IN EFI_HANDLE ImageHandle + ) +{ + if (gEndOfDxeEvent !=3D NULL) { + gBS->CloseEvent (gEndOfDxeEvent); + gEndOfDxeEvent =3D NULL; + } + + if (gExitBootServiceEvent !=3D NULL) { + gBS->CloseEvent (gExitBootServiceEvent); + gExitBootServiceEvent =3D NULL; + } + + if (gRedfishConfigData.Event !=3D NULL) { + gBS->CloseEvent (gRedfishConfigData.Event); + gRedfishConfigData.Event =3D NULL; + } + + return EFI_SUCCESS; +} + +/** + This is the common code for Redfish configuration UEFI and DXE driver + initialization. + + @param[in] ImageHandle The firmware allocated handle for the UEFI= image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The operation completed successfully. + @retval Others An unexpected error occurred. +**/ +EFI_STATUS +RedfishConfigCommonInit ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + // + // Locate Redfish Credential Protocol to get credential for + // accessing to Redfish service. + // + Status =3D gBS->LocateProtocol (&gEdkIIRedfishCredentialProtocolGuid, NU= LL, (VOID **) &gCredential); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: No Redfish Credential Protocol is installed o= n system.", __FUNCTION__)); + return Status; + } + // + // Create EndOfDxe Event. + // + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + RedfishConfigOnEndOfDxe, + NULL, + &gEfiEndOfDxeEventGroupGuid, + &gEndOfDxeEvent + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Fail to register End Of DXE event.", __FUNCT= ION__)); + return Status; + } + // + // Create Exit Boot Service event. + // + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + RedfishConfigOnExitBootService, + NULL, + &gEfiEventExitBootServicesGuid, + &gExitBootServiceEvent + ); + if (EFI_ERROR (Status)) { + gBS->CloseEvent (gEndOfDxeEvent); + gEndOfDxeEvent =3D NULL; + DEBUG ((DEBUG_ERROR, "%a: Fail to register Exit Boot Service event.", = __FUNCTION__)); + return Status; + } + return EFI_SUCCESS; +} +/** + This is the common code to stop EDK2 Redfish feature driver. + + @retval EFI_SUCCESS All EDK2 Redfish feature drivers are + stopped. + @retval Others An unexpected error occurred. +**/ +EFI_STATUS +RedfishConfigCommonStop ( + VOID +) +{ + EFI_STATUS Status; + EFI_HANDLE *HandleBuffer; + UINTN NumberOfHandles; + UINTN Index; + EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler; + + Status =3D gBS->LocateHandleBuffer ( + ByProtocol, + &gEdkIIRedfishConfigHandlerProtocolGuid, + NULL, + &NumberOfHandles, + &HandleBuffer + ); + if (EFI_ERROR (Status) && Status !=3D EFI_NOT_FOUND) { + return Status; + } + + Status =3D EFI_SUCCESS; + for (Index =3D 0; Index < NumberOfHandles; Index++) { + Status =3D gBS->HandleProtocol ( + HandleBuffer[Index], + &gEdkIIRedfishConfigHandlerProtocolGuid, + (VOID**) &ConfigHandler + ); + ASSERT_EFI_ERROR (Status); + + Status =3D ConfigHandler->Stop (ConfigHandler); + if (EFI_ERROR (Status) && Status !=3D EFI_UNSUPPORTED) { + DEBUG ((DEBUG_ERROR, "ERROR: Failed to stop Redfish config handler %= p.\n", ConfigHandler)); + break; + } + } + return Status; +} +/** + Callback function executed when a Redfish Config Handler Protocol is ins= talled + by EDK2 Redfish Feature Drivers. + +**/ +VOID +RedfishConfigHandlerInitialization ( + VOID + ) +{ + EFI_STATUS Status; + EFI_HANDLE *HandleBuffer; + UINTN NumberOfHandles; + EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL *ConfigHandler; + UINTN Index; + UINT32 Id; + + Status =3D gBS->LocateHandleBuffer ( + ByProtocol, + &gEdkIIRedfishConfigHandlerProtocolGuid, + NULL, + &NumberOfHandles, + &HandleBuffer + ); + if (EFI_ERROR (Status)) { + return; + } + + for (Index =3D 0; Index < NumberOfHandles; Index++) { + Status =3D gBS->HandleProtocol ( + HandleBuffer [Index], + &gEfiCallerIdGuid, + (VOID **) &Id + ); + if (!EFI_ERROR (Status)) { + continue; + } + + Status =3D gBS->HandleProtocol ( + HandleBuffer [Index], + &gEdkIIRedfishConfigHandlerProtocolGuid, + (VOID**) &ConfigHandler + ); + ASSERT_EFI_ERROR (Status); + Status =3D ConfigHandler->Init (ConfigHandler, &gRedfishConfigData.Red= fishServiceInfo); + if (EFI_ERROR (Status) && Status !=3D EFI_ALREADY_STARTED) { + DEBUG ((DEBUG_ERROR, "ERROR: Failed to init Redfish config handler %= p.\n", ConfigHandler)); + } + // + // Install caller ID to indicate Redfish Configure Handler is initiali= zed. + // + Status =3D gBS->InstallProtocolInterface ( + &HandleBuffer [Index], + &gEfiCallerIdGuid, + EFI_NATIVE_INTERFACE, + (VOID *)&gRedfishConfigData.CallerId + ); + ASSERT_EFI_ERROR (Status); + } +} diff --git a/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.c b= /RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.c new file mode 100644 index 0000000000..51378dff4f --- /dev/null +++ b/RedfishPkg/RedfishConfigHandler/RedfishConfigHandlerDriver.c @@ -0,0 +1,587 @@ +/** @file + The UEFI driver model driver which is responsible for locating the + Redfish service through Redfish host interface and executing EDKII + Redfish feature drivers. + + Copyright (c) 2019, Intel Corporation. All rights reserved.
+ (C) Copyright 2021 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "RedfishConfigHandlerDriver.h" + +EFI_EVENT gEfiRedfishDiscoverProtocolEvent =3D NULL; + +// +// Variables for using RFI Redfish Discover Protocol +// +VOID *gEfiRedfishDiscoverRegistration; +EFI_HANDLE gEfiRedfishDiscoverControllerHandle =3D N= ULL; +EFI_REDFISH_DISCOVER_PROTOCOL *gEfiRedfishDiscoverProtocol =3D NULL; +BOOLEAN gRedfishDiscoverActivated =3D FALSE; +BOOLEAN gRedfishServiceDiscovered =3D FALSE; +// +// Network interfaces discovered by EFI Redfish Discover Protocol. +// +UINTN gNumberOfNetworkInterfaces; +EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *gNetworkInterfaceInstances =3D NU= LL; +EFI_REDFISH_DISCOVERED_TOKEN *gRedfishDiscoveredToken =3D NULL; + +/// +/// Driver Binding Protocol instance +/// +EFI_DRIVER_BINDING_PROTOCOL gRedfishConfigDriverBinding =3D { + RedfishConfigDriverBindingSupported, + RedfishConfigDriverBindingStart, + RedfishConfigDriverBindingStop, + REDFISH_CONFIG_VERSION, + NULL, + NULL +}; + +/** + Stop acquiring Redfish service. + +**/ +VOID +RedfishConfigStopRedfishDiscovery ( + VOID +) +{ + if (gRedfishDiscoverActivated) { + // + // No more EFI Discover Protocol. + // + if (gEfiRedfishDiscoverProtocolEvent !=3D NULL) { + gBS->CloseEvent (gEfiRedfishDiscoverProtocolEvent); + } + // + // Stop Redfish service discovery. + // + gEfiRedfishDiscoverProtocol->AbortAcquireRedfishService ( + gEfiRedfishDiscoverProtocol, + gNetworkInterfaceInstances + ); + gEfiRedfishDiscoverControllerHandle =3D NULL; + gEfiRedfishDiscoverProtocol =3D NULL; + gRedfishDiscoverActivated =3D FALSE; + gRedfishServiceDiscovered =3D FALSE; + } +} + +/** + Callback function executed when a Redfish Config Handler Protocol is ins= talled. + + @param[in] Event Event whose notification function is being invoked. + @param[in] Context Pointer to the REDFISH_CONFIG_DRIVER_DATA buffer. + +**/ +VOID +EFIAPI +RedfishConfigHandlerInstalledCallback ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + if (!gRedfishDiscoverActivated) { + // + // No Redfish service is discovered yet. + // + return; + } + + RedfishConfigHandlerInitialization (); +} + +/** + Tests to see if this driver supports a given controller. If a child devi= ce is provided, + it further tests to see if this driver supports creating a handle for th= e specified child device. + + This function checks to see if the driver specified by This supports the= device specified by + ControllerHandle. Drivers will typically use the device path attached to + ControllerHandle and/or the services from the bus I/O abstraction attach= ed to + ControllerHandle to determine if the driver supports ControllerHandle. T= his function + may be called many times during platform initialization. In order to red= uce boot times, the tests + performed by this function must be very small, and take as little time a= s possible to execute. This + function must not change the state of any hardware devices, and this fun= ction must be aware that the + device specified by ControllerHandle may already be managed by the same = driver or a + different driver. This function must match its calls to AllocatePages() = with FreePages(), + AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol(). + Because ControllerHandle may have been previously started by the same dr= iver, if a protocol is + already in the opened state, then it must not be closed with CloseProtoc= ol(). This is required + to guarantee the state of ControllerHandle is not modified by this funct= ion. + + @param[in] This A pointer to the EFI_DRIVER_BINDING_PRO= TOCOL instance. + @param[in] ControllerHandle The handle of the controller to test. T= his handle + must support a protocol interface that = supplies + an I/O abstraction to the driver. + @param[in] RemainingDevicePath A pointer to the remaining portion of a= device path. This + parameter is ignored by device drivers,= and is optional for bus + drivers. For bus drivers, if this param= eter is not NULL, then + the bus driver must determine if the bu= s controller specified + by ControllerHandle and the child contr= oller specified + by RemainingDevicePath are both support= ed by this + bus driver. + + @retval EFI_SUCCESS The device specified by ControllerHandl= e and + RemainingDevicePath is supported by the= driver specified by This. + @retval EFI_UNSUPPORTED The device specified by ControllerHandl= e and + RemainingDevicePath is not supported by= the driver specified by This. +**/ +EFI_STATUS +EFIAPI +RedfishConfigDriverBindingSupported ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL + ) +{ + EFI_REST_EX_PROTOCOL *RestEx; + EFI_STATUS Status; + EFI_HANDLE ChildHandle; + + ChildHandle =3D NULL; + + // + // Check if REST EX is ready. This just makes sure + // the network stack is brought up. + // + Status =3D NetLibCreateServiceChild ( + ControllerHandle, + This->ImageHandle, + &gEfiRestExServiceBindingProtocolGuid, + &ChildHandle + ); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } + + // + // Test if REST EX protocol is ready. + // + Status =3D gBS->OpenProtocol( + ChildHandle, + &gEfiRestExProtocolGuid, + (VOID**) &RestEx, + This->DriverBindingHandle, + ControllerHandle, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + Status =3D EFI_UNSUPPORTED; + } + NetLibDestroyServiceChild ( + ControllerHandle, + This->ImageHandle, + &gEfiRestExServiceBindingProtocolGuid, + ChildHandle + ); + return Status; +} + +/** + Starts a device controller or a bus controller. + + The Start() function is designed to be invoked from the EFI boot service= ConnectController(). + As a result, much of the error checking on the parameters to Start() has= been moved into this + common boot service. It is legal to call Start() from other locations, + but the following calling restrictions must be followed, or the system b= ehavior will not be deterministic. + 1. ControllerHandle must be a valid EFI_HANDLE. + 2. If RemainingDevicePath is not NULL, then it must be a pointer to a na= turally aligned + EFI_DEVICE_PATH_PROTOCOL. + 3. Prior to calling Start(), the Supported() function for the driver spe= cified by This must + have been called with the same calling parameters, and Supported() mu= st have returned EFI_SUCCESS. + + @param[in] This A pointer to the EFI_DRIVER_BINDING_PRO= TOCOL instance. + @param[in] ControllerHandle The handle of the controller to start. = This handle + must support a protocol interface that = supplies + an I/O abstraction to the driver. + @param[in] RemainingDevicePath A pointer to the remaining portion of a= device path. This + parameter is ignored by device drivers,= and is optional for bus + drivers. For a bus driver, if this para= meter is NULL, then handles + for all the children of Controller are = created by this driver. + If this parameter is not NULL and the f= irst Device Path Node is + not the End of Device Path Node, then o= nly the handle for the + child device specified by the first Dev= ice Path Node of + RemainingDevicePath is created by this = driver. + If the first Device Path Node of Remain= ingDevicePath is + the End of Device Path Node, no child h= andle is created by this + driver. + + @retval EFI_SUCCESS The driver is started. + @retval EFI_ALREADY_STARTED The driver was already started. + +**/ +EFI_STATUS +EFIAPI +RedfishConfigDriverBindingStart ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL + ) +{ + VOID *ConfigHandlerRegistration; + + if (gRedfishConfigData.Event !=3D NULL) { + return EFI_ALREADY_STARTED; + } + + gRedfishConfigData.Event =3D EfiCreateProtocolNotifyEvent ( + &gEdkIIRedfishConfigHandlerProtocolGuid, + TPL_CALLBACK, + RedfishConfigHandlerInstalledCallback, + (VOID *)&gRedfishConfigData, + &ConfigHandlerRegistration + ); + return EFI_SUCCESS; +} + +/** + Stops a device controller or a bus controller. + + The Stop() function is designed to be invoked from the EFI boot service = DisconnectController(). + As a result, much of the error checking on the parameters to Stop() has = been moved + into this common boot service. It is legal to call Stop() from other loc= ations, + but the following calling restrictions must be followed, or the system b= ehavior will not be deterministic. + 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previo= us call to this + same driver's Start() function. + 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a= valid + EFI_HANDLE. In addition, all of these handles must have been created = in this driver's + Start() function, and the Start() function must have called OpenProto= col() on + ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONT= ROLLER. + + @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOC= OL instance. + @param[in] ControllerHandle A handle to the device being stopped. The = handle must + support a bus specific I/O protocol for th= e driver + to use to stop the device. + @param[in] NumberOfChildren The number of child device handles in Chil= dHandleBuffer. + @param[in] ChildHandleBuffer An array of child handles to be freed. May= be NULL + if NumberOfChildren is 0. + + @retval EFI_SUCCESS The device was stopped. + @retval EFI_DEVICE_ERROR The device could not be stopped due to a d= evice error. + +**/ +EFI_STATUS +EFIAPI +RedfishConfigDriverBindingStop ( + IN EFI_DRIVER_BINDING_PROTOCOL *This, + IN EFI_HANDLE ControllerHandle, + IN UINTN NumberOfChildren, + IN EFI_HANDLE *ChildHandleBuffer OPTIONAL + ) +{ + EFI_STATUS Status; + + if (ControllerHandle =3D=3D gEfiRedfishDiscoverControllerHandle) { + RedfishConfigStopRedfishDiscovery (); + } + gBS->CloseProtocol ( + ControllerHandle, + &gEfiRedfishDiscoverProtocolGuid, + gRedfishConfigData.Image, + gRedfishConfigData.Image + ); + + Status =3D RedfishConfigCommonStop (); + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; + } + + if (gRedfishConfigData.Event !=3D NULL) { + gBS->CloseEvent (gRedfishConfigData.Event); + gRedfishConfigData.Event =3D NULL; + } + return EFI_SUCCESS; +} + +/** + Callback function when Redfish service is discovered. + + @param[in] Event Event whose notification function is being invoked. + @param[out] Context Pointer to the Context buffer + +**/ +VOID +EFIAPI +RedfishServiceDiscoveredCallback ( + IN EFI_EVENT Event, + OUT VOID *Context + ) +{ + EFI_REDFISH_DISCOVERED_TOKEN *RedfishDiscoveredToken; + EFI_REDFISH_DISCOVERED_INSTANCE *RedfishInstance; + + if (gRedfishServiceDiscovered) { + // + // Only support one Redfish service on platform. + // + return; + } + + RedfishDiscoveredToken =3D (EFI_REDFISH_DISCOVERED_TOKEN *)Context; + RedfishInstance =3D RedfishDiscoveredToken->DiscoverList.RedfishInstance= s; + // + // Only pick up the first found Redfish service. + // + if (RedfishInstance->Status =3D=3D EFI_SUCCESS) { + gRedfishConfigData.RedfishServiceInfo.RedfishServiceRestExHandle =3D R= edfishInstance->Information.RedfishRestExHandle; + gRedfishConfigData.RedfishServiceInfo.RedfishServiceVersion =3D R= edfishInstance->Information.RedfishVersion; + gRedfishConfigData.RedfishServiceInfo.RedfishServiceLocation =3D R= edfishInstance->Information.Location; + gRedfishConfigData.RedfishServiceInfo.RedfishServiceUuid =3D R= edfishInstance->Information.Uuid; + gRedfishConfigData.RedfishServiceInfo.RedfishServiceOs =3D R= edfishInstance->Information.Os; + gRedfishConfigData.RedfishServiceInfo.RedfishServiceOsVersion =3D R= edfishInstance->Information.OsVersion; + gRedfishConfigData.RedfishServiceInfo.RedfishServiceProduct =3D R= edfishInstance->Information.Product; + gRedfishConfigData.RedfishServiceInfo.RedfishServiceProductVer =3D R= edfishInstance->Information.ProductVer; + gRedfishConfigData.RedfishServiceInfo.RedfishServiceUseHttps =3D R= edfishInstance->Information.UseHttps; + gRedfishServiceDiscovered =3D TRUE; + } + + // + // Invoke RedfishConfigHandlerInstalledCallback to execute + // the initialization of Redfish Configure Handler instance. + // + RedfishConfigHandlerInstalledCallback (gRedfishConfigData.Event, &gRedfi= shConfigData); +} + +/** + Callback function executed when the EFI_REDFISH_DISCOVER_PROTOCOL + protocol interface is installed. + + @param[in] Event Event whose notification function is being invoked. + @param[out] Context Pointer to the Context buffer + +**/ +VOID +EFIAPI +RedfishDiscoverProtocolInstalled ( + IN EFI_EVENT Event, + OUT VOID *Context + ) +{ + EFI_STATUS Status; + UINTN BufferSize; + EFI_HANDLE HandleBuffer; + UINTN NetworkInterfaceIndex; + EFI_REDFISH_DISCOVER_NETWORK_INTERFACE *ThisNetworkInterface; + EFI_REDFISH_DISCOVERED_TOKEN *ThisRedfishDiscoveredToken; + + DEBUG((DEBUG_INFO, "%a: New network interface is installed on system by = EFI Redfish discover driver.\n", __FUNCTION__)); + + BufferSize =3D sizeof (EFI_HANDLE); + Status =3D gBS->LocateHandle ( + ByRegisterNotify, + NULL, + gEfiRedfishDiscoverRegistration, + &BufferSize, + &HandleBuffer + ); + if (EFI_ERROR (Status)) { + DEBUG((DEBUG_ERROR, "%a: Can't locate handle with EFI_REDFISH_DISCOVER= _PROTOCOL installed.\n", __FUNCTION__)); + } + gRedfishDiscoverActivated =3D TRUE; + if (gEfiRedfishDiscoverProtocol =3D=3D NULL) { + gEfiRedfishDiscoverControllerHandle =3D HandleBuffer; + // + // First time to open EFI_REDFISH_DISCOVER_PROTOCOL. + // + Status =3D gBS->OpenProtocol( + gEfiRedfishDiscoverControllerHandle, + &gEfiRedfishDiscoverProtocolGuid, + (VOID **)&gEfiRedfishDiscoverProtocol, + gRedfishConfigData.Image, + gRedfishConfigData.Image, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); + if (EFI_ERROR (Status)) { + gEfiRedfishDiscoverProtocol =3D NULL; + gRedfishDiscoverActivated =3D FALSE; + DEBUG((DEBUG_ERROR, "%a: Can't locate EFI_REDFISH_DISCOVER_PROTOCOL.= \n", __FUNCTION__)); + return; + } + } + // + // Check the new found network interface. + // + if (gNetworkInterfaceInstances !=3D NULL) { + FreePool (gNetworkInterfaceInstances); + } + Status =3D gEfiRedfishDiscoverProtocol->GetNetworkInterfaceList( + gEfiRedfishDiscoverProtocol, + gRedfishConfigData.Image, + &gNumberOfNetworkInterfaces, + &gNetworkInterfaceInstances + ); + if (EFI_ERROR (Status) || gNumberOfNetworkInterfaces =3D=3D 0) { + DEBUG((DEBUG_ERROR, "%a: No network interfaces found on the handle.\n"= , __FUNCTION__)); + return; + } + + gRedfishDiscoveredToken =3D AllocateZeroPool (gNumberOfNetworkInterfaces= * sizeof (EFI_REDFISH_DISCOVERED_TOKEN)); + if (gRedfishDiscoveredToken =3D=3D NULL) { + DEBUG((DEBUG_ERROR, "%a: Not enough memory for EFI_REDFISH_DISCOVERED_= TOKEN.\n", __FUNCTION__)); + return; + } + + ThisNetworkInterface =3D gNetworkInterfaceInstances; + ThisRedfishDiscoveredToken =3D gRedfishDiscoveredToken; + // + // Loop to discover Redfish service on each network interface. + // + for (NetworkInterfaceIndex =3D 0; NetworkInterfaceIndex < gNumberOfNetwo= rkInterfaces; NetworkInterfaceIndex ++) { + // + // Initial this Redfish Discovered Token + // + Status =3D gBS->CreateEvent ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + RedfishServiceDiscoveredCallback, + (VOID *)ThisRedfishDiscoveredToken, + &ThisRedfishDiscoveredToken->Event + ); + if (EFI_ERROR (Status)) { + DEBUG((DEBUG_ERROR, "%a: Failed to create event for Redfish discover= ed token.\n", __FUNCTION__)); + goto ErrorReturn; + } + ThisRedfishDiscoveredToken->Signature =3D REDFISH_DISCOVER_TOKEN_SIGNA= TURE; + ThisRedfishDiscoveredToken->DiscoverList.NumberOfServiceFound =3D 0; + ThisRedfishDiscoveredToken->DiscoverList.RedfishInstances =3D NULL; + // + // Acquire for Redfish service which is reported by + // Redfish Host Interface. + // + Status =3D gEfiRedfishDiscoverProtocol->AcquireRedfishService( + gEfiRedfishDiscoverProtocol, + gRedfishConfigData.Image, + ThisNetworkInterface, + EFI_REDFISH_DISCOVER_HOST_INT= ERFACE, + ThisRedfishDiscoveredToken + ); + ThisNetworkInterface ++; + ThisRedfishDiscoveredToken ++; + } + if (EFI_ERROR (Status)) { + DEBUG((DEBUG_ERROR, "%a: Acquire Redfish service fail.\n", __FUNCTION_= _)); + goto ErrorReturn; + } + return; + +ErrorReturn: + if (gRedfishDiscoveredToken !=3D NULL) { + FreePool(gRedfishDiscoveredToken); + } +} + +/** + Unloads an image. + + @param[in] ImageHandle Handle that identifies the image to be unl= oaded. + + @retval EFI_SUCCESS The image has been unloaded. + +**/ +EFI_STATUS +EFIAPI +RedfishConfigHandlerDriverUnload ( + IN EFI_HANDLE ImageHandle + ) +{ + EFI_REDFISH_DISCOVERED_TOKEN *ThisRedfishDiscoveredToken; + UINTN NumberOfNetworkInterfacesIndex; + + RedfishConfigDriverCommonUnload (ImageHandle); + + RedfishConfigStopRedfishDiscovery (); + if (gRedfishDiscoveredToken !=3D NULL) { + ThisRedfishDiscoveredToken =3D gRedfishDiscoveredToken; + for (NumberOfNetworkInterfacesIndex =3D 0; NumberOfNetworkInterfacesIn= dex < gNumberOfNetworkInterfaces; NumberOfNetworkInterfacesIndex ++) { + if (ThisRedfishDiscoveredToken->Event !=3D NULL) { + gBS->CloseEvent (ThisRedfishDiscoveredToken->Event); + } + FreePool (ThisRedfishDiscoveredToken); + ThisRedfishDiscoveredToken ++; + } + gRedfishDiscoveredToken =3D NULL; + } + return EFI_SUCCESS; +} + +/** + This is the declaration of an EFI image entry point. This entry point is + the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers includ= ing + both device drivers and bus drivers. + + @param[in] ImageHandle The firmware allocated handle for the UEFI= image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The operation completed successfully. + @retval Others An unexpected error occurred. +**/ +EFI_STATUS +EFIAPI +RedfishConfigHandlerDriverEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + ZeroMem ((VOID *)&gRedfishConfigData, sizeof (REDFISH_CONFIG_DRIVER_DATA= )); + gRedfishConfigData.Image =3D ImageHandle; + // + // Register event for EFI_REDFISH_DISCOVER_PROTOCOL protocol install + // notification. + // + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + RedfishDiscoverProtocolInstalled, + NULL, + &gEfiRedfishDiscoverProtocolGuid, + &gEfiRedfishDiscoverProtocolEvent + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Fail to create event for the installation of= EFI_REDFISH_DISCOVER_PROTOCOL.", __FUNCTION__)); + return Status; + } + Status =3D gBS->RegisterProtocolNotify ( + &gEfiRedfishDiscoverProtocolGuid, + gEfiRedfishDiscoverProtocolEvent, + &gEfiRedfishDiscoverRegistration + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Fail to register event for the installation = of EFI_REDFISH_DISCOVER_PROTOCOL.", __FUNCTION__)); + return Status; + } + + Status =3D RedfishConfigCommonInit (ImageHandle, SystemTable); + if (EFI_ERROR (Status)) { + gBS->CloseEvent (gEfiRedfishDiscoverProtocolEvent); + gEfiRedfishDiscoverProtocolEvent =3D NULL; + return Status; + } + + // + // Install UEFI Driver Model protocol(s). + // + Status =3D EfiLibInstallDriverBinding ( + ImageHandle, + SystemTable, + &gRedfishConfigDriverBinding, + ImageHandle + ); + if (EFI_ERROR (Status)) { + gBS->CloseEvent (gEndOfDxeEvent); + gEndOfDxeEvent =3D NULL; + gBS->CloseEvent (gExitBootServiceEvent); + gExitBootServiceEvent =3D NULL; + gBS->CloseEvent (gEfiRedfishDiscoverProtocolEvent); + gEfiRedfishDiscoverProtocolEvent =3D NULL; + DEBUG ((DEBUG_ERROR, "%a: Fail to install EFI Binding Protocol of EFI = Redfish Config driver.", __FUNCTION__)); + return Status; + } + return Status; +} + --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#73312): https://edk2.groups.io/g/devel/message/73312 Mute This Topic: https://groups.io/mt/81622326/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-