From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web08.3122.1627401014803601224 for ; Tue, 27 Jul 2021 08:50:15 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=Ugsdg9yF; spf=permerror, err=parse error for token &{10 18 %{ir}.%{v}.%{d}.spf.has.pphosted.com}: invalid domain name (domain: hpe.com, ip: 148.163.143.35, mailfrom: prvs=084293f174=abner.chang@hpe.com) 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 16RFm1sa014604; Tue, 27 Jul 2021 15:50:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pps0720; bh=kvsbwtgKePkiPqKmD7JKnHfHsotlHWCPRp0xCqzATSg=; b=Ugsdg9yFqZbTTOgSSvSh6T7zBeEUZifRBq0CKa8zCbczyoSCSw+SEqAuQvT7eKcKTjXw Djxj3ynMtH8nKnNKRT+CpBPgE5hFCDszKKSCQbltHjvMUNSLHeUlEGer4PtHl2Of3voX hQidpXcit2WY6Z47GY/fWK8PFhOCnb98c9PVWItx140tkEHOuHLDNUnhDSuYofbEkfhw 35pTF5riHSX3zdk1D+kbtE15PG/ypWIL0ESZRQzDwhdINauyE9rzpjE2+wSeLeRCnIQ6 ggMTAj2oH+Am0q7w/u3WrlvDGNQbdNNKUUDZ17ZuR8Mj8DJUKlOvxQ3szYR8lPNQUX6S xA== Received: from g9t5008.houston.hpe.com (g9t5008.houston.hpe.com [15.241.48.72]) by mx0b-002e3701.pphosted.com with ESMTP id 3a236dgj3a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Jul 2021 15:50:02 +0000 Received: from g9t2301.houston.hpecorp.net (g9t2301.houston.hpecorp.net [16.220.97.129]) by g9t5008.houston.hpe.com (Postfix) with ESMTP id DCD5A4F; Tue, 27 Jul 2021 15:49:59 +0000 (UTC) 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 06B1348; Tue, 27 Jul 2021 15:49:58 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: Nickle Wang , Liming Gao Subject: [staging/edk2-redfish-client RedfishFeatureCore PATCH 2/3] RedfishClientPkg/RedfishFeatureCoreDxe: Redfish Feature Core DXE driver Date: Tue, 27 Jul 2021 22:54:41 +0800 Message-Id: <20210727145442.22840-3-abner.chang@hpe.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210727145442.22840-1-abner.chang@hpe.com> References: <20210727145442.22840-1-abner.chang@hpe.com> X-Proofpoint-ORIG-GUID: gAr2ZwSX83nt-zSj2oq_ax8qVUThbt36 X-Proofpoint-GUID: gAr2ZwSX83nt-zSj2oq_ax8qVUThbt36 X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-07-27_10:2021-07-27,2021-07-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 spamscore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 priorityscore=1501 clxscore=1015 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2107270095 EDKII Redfish Feature Core DXE driver provides the protocol interface to the auto-generated Redfish feature driver to register itself for the Redfish resource URI it manages. Refer to the Readme.md for the details. Signed-off-by: Abner Chang Cc: Nickle Wang Cc: Liming Gao --- RedfishClientPkg/RedfishClientPkg.dec | 13 +- .../RedfishClientComponents.dsc.inc | 2 + RedfishClientPkg/RedfishClient.fdf.inc | 1 + .../RedfishFeatureCoreDxe.inf | 49 +++ .../Include/Protocol/EdkIIRedfishFeature.h | 116 ++++++ .../RedfishFeatureCoreDxe.h | 43 ++ .../RedfishFeatureCoreDxe.c | 382 ++++++++++++++++++ RedfishClientPkg/Readme.md | 36 ++ 8 files changed, 641 insertions(+), 1 deletion(-) create mode 100644 RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.inf create mode 100644 RedfishClientPkg/Include/Protocol/EdkIIRedfishFeature.h create mode 100644 RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.h create mode 100644 RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.c diff --git a/RedfishClientPkg/RedfishClientPkg.dec b/RedfishClientPkg/RedfishClientPkg.dec index 4038a47bd5..6da0468e65 100644 --- a/RedfishClientPkg/RedfishClientPkg.dec +++ b/RedfishClientPkg/RedfishClientPkg.dec @@ -15,10 +15,21 @@ [Includes] Include - [LibraryClasses] [Protocols] + ## Include/Protocol/EdkIIRedfishFeature.h + gEdkIIRedfishFeatureProtocolGuid = { 0x785CC694, 0x4930, 0xEFBF, { 0x2A, 0xCB, 0xA4, 0xB6, 0xA1, 0xCC, 0xAA, 0x34 } } [Guids] gEfiRedfishClientPkgTokenSpaceGuid = { 0x8c444dae, 0x728b, 0x48ee, { 0x9e, 0x19, 0x8f, 0x0a, 0x3d, 0x4e, 0x9c, 0xc8 } } + +[PcdsFixedAtBuild] + gEfiRedfishClientPkgTokenSpaceGuid.PcdMaxRedfishSchemaStringSize|32|UINT32|0x10000001 + gEfiRedfishClientPkgTokenSpaceGuid.PcdMaxRedfishSchemaVersionSize|8|UINT32|0x10000002 + # + # gEfiEventReadyToBootGuid is the default event to startup Redfish feature drivers. + # { 0x7CE88FB3, 0x4BD7, 0x4679, { 0x87, 0xA8, 0xA8, 0xD8, 0xDE, 0xE5, 0x0D, 0x2B }} + # + gEfiRedfishClientPkgTokenSpaceGuid.PcdEdkIIRedfishFeatureDriverStartupEventGuid|{0xB3, 0x8F, 0xE8, 0x7C, 0xD7, 0x4B, 0x79, 0x46, 0x87, 0xA8, 0xA8, 0xD8, 0xDE, 0xE5, 0x0D, 0x2B}|VOID*|0x10000003 + diff --git a/RedfishClientPkg/RedfishClientComponents.dsc.inc b/RedfishClientPkg/RedfishClientComponents.dsc.inc index 0648fa9d54..e4e2619bfb 100644 --- a/RedfishClientPkg/RedfishClientComponents.dsc.inc +++ b/RedfishClientPkg/RedfishClientComponents.dsc.inc @@ -13,4 +13,6 @@ ## !if $(REDFISH_CLIENT) == TRUE + RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.inf !endif + diff --git a/RedfishClientPkg/RedfishClient.fdf.inc b/RedfishClientPkg/RedfishClient.fdf.inc index 4f0714004e..d4c5874787 100644 --- a/RedfishClientPkg/RedfishClient.fdf.inc +++ b/RedfishClientPkg/RedfishClient.fdf.inc @@ -11,4 +11,5 @@ # ## !if $(REDFISH_CLIENT) == TRUE + INF RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.inf !endif diff --git a/RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.inf b/RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.inf new file mode 100644 index 0000000000..5a2cd7fecc --- /dev/null +++ b/RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.inf @@ -0,0 +1,49 @@ +## @file +# RedfishFeatureCoreDxe is the DXE driver which provides +# EdkIIRedfishFeatureCoreProtocol to EDK2 Redfish Feature +# drivers for the registration. +# +# (C) Copyright 2021 Hewlett Packard Enterprise Development LP
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001000b + BASE_NAME = RedfishFeatureCoreDxe + FILE_GUID = 1E01A624-4161-F1F1-25BC-D28E77420D8E + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = RedfishFeatureCoreEntryPoint + +# +# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64 RISCV64 +# + +[Sources] + RedfishFeatureCoreDxe.c + RedfishFeatureCoreDxe.h + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + RedfishClientPkg/RedfishClientPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + PrintLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiLib + +[Protocols] + gEdkIIRedfishFeatureProtocolGuid ## BY_START + +[Pcd] + gEfiRedfishClientPkgTokenSpaceGuid.PcdEdkIIRedfishFeatureDriverStartupEventGuid + +[Depex] + TRUE diff --git a/RedfishClientPkg/Include/Protocol/EdkIIRedfishFeature.h b/RedfishClientPkg/Include/Protocol/EdkIIRedfishFeature.h new file mode 100644 index 0000000000..036622128d --- /dev/null +++ b/RedfishClientPkg/Include/Protocol/EdkIIRedfishFeature.h @@ -0,0 +1,116 @@ +/** @file + This file defines the EDKII_REDFISH_FEATURE_PROTOCOL interface. + + (C) Copyright 2021 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef EDKII_REDFISH_FEATURE_H_ +#define EDKII_REDFISH_FEATURE_H_ + +typedef struct _EDKII_REDFISH_FEATURE_PROTOCOL EDKII_REDFISH_FEATURE_PROTOCOL; + +#define EDKII_REDFISH_FEATURE_PROTOCOL_GUID \ + { \ + 0x785CC694, 0x4930, 0xEFBF, { 0x2A, 0xCB, 0xA4, 0xB6, 0xA1, 0xCC, 0xAA, 0x34 } \ + } + +typedef enum { + CallbackActionNone = 0, ///< Invalid action + CallbackActionStartOperation, ///< Start the operations on Redfish resource + CallbackActionMax +} FEATURE_CALLBACK_ACTION; + +typedef enum { + InformationTypeNone = 0, ///< Invalid information. + InformationTypeCollectionMemberUri, ///< URI to the new created collection member. + InformationTypeMax +} FEATURE_RETURNED_INFORMATION_TYPE; + +typedef struct { + FEATURE_RETURNED_INFORMATION_TYPE Type; +} FEATURE_RETURNED_INFORMATION; + +/** + The callback function provided by Redfish Feature driver. + + @param[in] This Pointer to EDKII_REDFISH_FEATURE_PROTOCOL instance. + @param[in] FeatureAction The action Redfish feature driver should take. + @param[in] Context The context of Redfish feature driver. + @param[in,out] InformationReturned The pointer to retrive the pointer to + FEATURE_RETURNED_INFOMATION. The memory block of this + information should be freed by caller. + + @retval EFI_SUCCESS Redfish feature driver callback is executed successfully. + @retval Others Some errors happened. + +**/ +typedef +EFI_STATUS +(EFIAPI *REDFISH_FEATURE_CALLBACK) ( + IN EDKII_REDFISH_FEATURE_PROTOCOL *This, + IN FEATURE_CALLBACK_ACTION FeatureAction, + IN VOID *Context, + IN OUT FEATURE_RETURNED_INFORMATION **InformationReturned +); +/** + The registration function for the Redfish Feature driver. + + @param[in] This Pointer to EDKII_REDFISH_FEATURE_PROTOCOL instance. + @param[in] FeatureManagedUri The URI represents the hierarchy path of the Redfish + resource in the entire Redfish data model that managed + by Redfish feature driver . Each node in the hierarchy + path is the property name defined in the schema of the + resource. + @param[in] Callback Callback routine associated with this registration that + provided by Redfish feature driver to execute the action + on Redfish resource which is managed by this Redfish + feature driver. + @param[in] Context The context of the registering feature driver. The pointer + to the conext is delivered through callback function. + @retval EFI_SUCCESS Redfish feature driver is registered successfully. + @retval Others Some error happened. + +**/ +typedef +EFI_STATUS +(EFIAPI *REDFISH_FEATURE_REGISTER) ( + IN EDKII_REDFISH_FEATURE_PROTOCOL *This, + IN EFI_STRING FeatureManagedUri, + IN REDFISH_FEATURE_CALLBACK Callback, + IN VOID *Context +); + +/** + The unregistration function for the Redfish Feature driver. + + @param[in] This Pointer to EDKII_REDFISH_FEATURE_PROTOCOL instance. + @param[in] FeatureManagedUri The URI represents the hierarchy path of the Redfish + resource in the entire Redfish data model that managed + by Redfish feature driver . Each node in the hierarchy + path is the property name defined in the schema of the + resource. + @param[in] Context The context used for the previous feature driver + registration. + @retval EFI_SUCCESS Redfish feature driver is registered successfully. + @retval Others Some error happened. + +**/ +typedef +EFI_STATUS +(EFIAPI *REDFISH_FEATURE_UNREGISTER) ( + IN EDKII_REDFISH_FEATURE_PROTOCOL *This, + IN EFI_STRING FeatureManagedUri, + IN VOID *Context +); + +struct _EDKII_REDFISH_FEATURE_PROTOCOL { + REDFISH_FEATURE_REGISTER Register; + REDFISH_FEATURE_UNREGISTER Unregister; +}; + +extern EFI_GUID gEdkIIRedfishFeatureProtocolGuid; + +#endif diff --git a/RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.h b/RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.h new file mode 100644 index 0000000000..7b1778b038 --- /dev/null +++ b/RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.h @@ -0,0 +1,43 @@ +/** @file + Definitions of RedfishFeatureCoreDxe + + (C) Copyright 2021 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ +#ifndef EDKII_REDFISH_FEATURE_CORE_DXE_H_ +#define EDKII_REDFISH_FEATURE_CORE_DXE_H_ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#define MaxNodeNameLength 64 +#define NodeSeperator L'/' +#define NodeIsCollectionLeftBracket '{' +#define NodeIsCollectionRightBracket '}' + +typedef struct _REDFISH_FEATURE_INTERNAL_DATA REDFISH_FEATURE_INTERNAL_DATA; +struct _REDFISH_FEATURE_INTERNAL_DATA { + REDFISH_FEATURE_INTERNAL_DATA *SiblingList; ///< Next same level in hierarchy of resource URI. + REDFISH_FEATURE_INTERNAL_DATA *ChildList; ///< Next level in hierarchy of resource URI. + EFI_STRING NodeName; ///< Name of the node in hierarchy of resource URI. + REDFISH_FEATURE_CALLBACK Callback; ///< Callback function of Redfish feature driver. + VOID *Context; ///< Context of feature driver. + FEATURE_RETURNED_INFORMATION *ReturnedInformation; ///< Information returned from Redfish feature driver. + UINT32 Flags; +}; +#define REDFISH_FEATURE_INTERNAL_DATA_IS_COLLECTION 0x00000001 + +typedef struct { + EDKII_REDFISH_FEATURE_PROTOCOL *This; + FEATURE_CALLBACK_ACTION Action; +} REDFISH_FEATURE_STARTUP_CONTEXT; +#endif diff --git a/RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.c b/RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.c new file mode 100644 index 0000000000..e5dcc3de8e --- /dev/null +++ b/RedfishClientPkg/RedfishFeatureCoreDxe/RedfishFeatureCoreDxe.c @@ -0,0 +1,382 @@ +/** @file + RedfishFeatureCoreDxe produces EdkIIRedfishFeatureCoreProtocol + for EDK2 Redfish Feature driver registration. + + (C) Copyright 2021 Hewlett Packard Enterprise Development LP
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +EFI_EVENT mEdkIIRedfishFeatureDriverStartupEvent; +REDFISH_FEATURE_STARTUP_CONTEXT mFeatureDriverStartupContext; +REDFISH_FEATURE_INTERNAL_DATA *ResourceUriNodeList; + +/** + Startup child feature drivers and it's sibing feature drivers. + + @param[in] HeadList Head list of this feature driver + @param[in] ThisFeatureDriverList This feature driver list. + @param[in] StartupContext Start up information + +**/ +VOID +StartUpFeatureDriver ( + IN REDFISH_FEATURE_INTERNAL_DATA *ThisFeatureDriverList, + IN REDFISH_FEATURE_STARTUP_CONTEXT *StartupContext +) +{ + EFI_STATUS Status; + REDFISH_FEATURE_INTERNAL_DATA *ThisList; + + ThisList = ThisFeatureDriverList; + while (TRUE) { + if (ThisList->Callback != NULL) { + Status = ThisList->Callback( + StartupContext->This, + StartupContext->Action, + ThisList->Context, + &ThisList->ReturnedInformation + ); + if (EFI_ERROR (Status)) { + DEBUG((DEBUG_ERROR, "%a: Callback to EDK2 Redfish feature driver fail.", __FUNCTION__)); + } + } + if (ThisList->ChildList != NULL) { + StartUpFeatureDriver (ThisList->ChildList, StartupContext); + } + // + // Check sibling Redfish feature driver. + // + if (ThisList->SiblingList == NULL) { + break; + } + // + // Go next sibling Redfish feature driver. + // + ThisList = ThisList->SiblingList; + }; +} + +/** + Callback routine when mEdkIIRedfishFeatureDriverStartupEvent + is signaled. + + @param[in] Event Event whose notification function is being invoked. + @param[in] Context The pointer to the notification function's context, + which is implementation-dependent. + +**/ +VOID +RedfishFeatureDriverStartup( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + REDFISH_FEATURE_STARTUP_CONTEXT *StartupContext; + + StartupContext = (REDFISH_FEATURE_STARTUP_CONTEXT *)Context; + // + // Invoke EDK2 Redfish feature driver callback to start up + // the Redfish operations. + // + if (ResourceUriNodeList == NULL) { + return; + } + // + // Invoke the callback by the hierarchy level + // + StartUpFeatureDriver (ResourceUriNodeList, StartupContext); +} + +/** + Create new internal data instance. + + @param[in,out] PtrToNewInternalData Pointer to receive new instance of + REDFISH_FEATURE_INTERNAL_DATA. + @param[in] NodeName Name of URI node. + + @retval EFI_SUCCESS New entry is inserted successfully. + @retval EFI_INVALID_PARAMETER Improper given parameters. + @retval EFI_OUT_OF_RESOURCES Lack of memory for the internal data structure. + +**/ +EFI_STATUS +NewInternalInstance ( + IN OUT REDFISH_FEATURE_INTERNAL_DATA **PtrToNewInternalData, + IN EFI_STRING NodeName + ) +{ + REDFISH_FEATURE_INTERNAL_DATA *NewInternalData; + + if (PtrToNewInternalData == NULL || NodeName == NULL) { + DEBUG((DEBUG_ERROR, "%a: Inproper given parameters\n", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + *PtrToNewInternalData = NULL; + NewInternalData = AllocateZeroPool (sizeof (REDFISH_FEATURE_INTERNAL_DATA)); + if (NewInternalData == NULL) { + DEBUG((DEBUG_ERROR, "%a: No memory for REDFISH_FEATURE_INTERNAL_DATA\n", __FUNCTION__)); + return EFI_OUT_OF_RESOURCES; + } + NewInternalData->NodeName = AllocateZeroPool (StrSize (NodeName)); + StrnCpyS (NewInternalData->NodeName, StrSize (NodeName), (CONST CHAR16 *)NodeName, StrLen (NodeName)); + NewInternalData->SiblingList = NULL; + NewInternalData->ChildList = NULL; + if (NodeName[0] == (UINT16)NodeIsCollectionLeftBracket && + NodeName [StrLen (NodeName) - 1] == (UINT16)NodeIsCollectionRightBracket) { + NewInternalData->Flags |= REDFISH_FEATURE_INTERNAL_DATA_IS_COLLECTION; + } + *PtrToNewInternalData = NewInternalData; + return EFI_SUCCESS; +} + +/** + Insert the URI node into internal data structure + + @param[in] HeadEntryToInsert The head entry to start the searching. + @param[in] NodeName Name of URI node. + @param[in] NextNodeEntry Pointer to receive the pointer of next head + entry for inserting the follow up nodes. + The returned LIST_ENTRY is the address of + ChildList link list. + @retval EFI_SUCCESS New entry is inserted successfully. + @retval EFI_INVALID_PARAMETER Improper given parameters. + @retval EFI_OUT_OF_RESOURCES Lack of memory for the internal data structure. + +**/ +EFI_STATUS +InsertRedfishFeatureUriNode ( + IN REDFISH_FEATURE_INTERNAL_DATA *HeadEntryToInsert, + IN EFI_STRING NodeName, + IN OUT REDFISH_FEATURE_INTERNAL_DATA **NextNodeEntry + ) +{ + EFI_STATUS Status; + REDFISH_FEATURE_INTERNAL_DATA *NewInternalData; + REDFISH_FEATURE_INTERNAL_DATA *ThisInternalData; + REDFISH_FEATURE_INTERNAL_DATA *SiblingList; + + if (NodeName == NULL) { + DEBUG((DEBUG_ERROR, "%a: Node name is NULL.\n", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + if (NextNodeEntry == NULL) { + DEBUG((DEBUG_ERROR, "%a: NextNodeEntry can't be NULL.\n", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + if (HeadEntryToInsert == NULL || HeadEntryToInsert->ChildList == NULL) { + Status = NewInternalInstance (&NewInternalData, NodeName); + if (EFI_ERROR (Status)) { + return Status; + } + if (HeadEntryToInsert == NULL) { + ResourceUriNodeList = NewInternalData; + } else { + HeadEntryToInsert->ChildList = NewInternalData; + } + *NextNodeEntry = NewInternalData; + return EFI_SUCCESS; + } + // + // Go through sibling list to find the entry. + // + ThisInternalData = HeadEntryToInsert; + SiblingList = ThisInternalData->SiblingList; + while (TRUE) { + if (StrCmp((CONST CHAR16 *)ThisInternalData->NodeName, (CONST CHAR16 *)NodeName) == 0) { + *NextNodeEntry = ThisInternalData->ChildList; + return EFI_SUCCESS; + } + // + // If sibing exist? + // + if (SiblingList == NULL) { + Status = NewInternalInstance (&NewInternalData, NodeName); + if (EFI_ERROR (Status)) { + return Status; + } + ThisInternalData->SiblingList = NewInternalData; + *NextNodeEntry = NewInternalData->ChildList; + return EFI_SUCCESS; + } + SiblingList = SiblingList->SiblingList; + }; + return EFI_SUCCESS; +} + +/** + The registration function for the Redfish Feature driver. + + @param[in] This Pointer to EDKII_REDFISH_FEATURE_PROTOCOL instance. + @param[in] FeatureManagedUri The URI represents the hierarchy path of the Redfish + resource in the entire Redfish data model that managed + by Redfish feature driver . Each node in the hierarchy + path is the property name defined in the schema of the + resource. + e.g. "ServiceRoot/" - Managed by ServiceRoot feature driver + "ServiceRoot/Systems[]/" - Managed by ComputerSystemCollection feature driver + "ServiceRoot/Systems[1]/" - Managed by ComputerSystem feature driver + "ServiceRoot/Systems[2]/Bios/" - Managed by Bios feature driver + @param[in] Callback Callback routine associated with this registration that + provided by Redfish feature driver to execute the action + on Redfish resource which is managed by this Redfish + feature driver. + @param[in] Context The context of the registering feature driver. The pointer + to the conext is delivered through callback function. + @retval EFI_SUCCESS Redfish feature driver is registered successfully. + @retval EFI_SUCCESS Redfish feature driver is registered successfully. + @retval EFI_INVALID_PARAMETER Improper given parameters or fail to register + feature driver. + @retval EFI_OUT_OF_RESOURCES Lack of memory for the internal data structure. + @retval Others Some error happened. + +**/ +EFI_STATUS +EFIAPI +RedfishFeatureRegister ( + IN EDKII_REDFISH_FEATURE_PROTOCOL *This, + IN EFI_STRING FeatureManagedUri, + IN REDFISH_FEATURE_CALLBACK Callback, + IN VOID *Context +) +{ + CHAR16 NodeName [MaxNodeNameLength]; + EFI_STATUS Status; + UINTN Index; + UINTN AnchorIndex; + UINTN UriLength; + REDFISH_FEATURE_INTERNAL_DATA *ThisUriNode; + + if (FeatureManagedUri == NULL || Callback == NULL) { + DEBUG((DEBUG_ERROR, "%a: The given parameter is invalid\n", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + // + // Walk through URI which managed by this EDK2 Redfish feature driver. + // + UriLength = StrLen (FeatureManagedUri) + 1; // Add one NULL for the last node. + Index = 0; + AnchorIndex = 0; + ThisUriNode = ResourceUriNodeList; + do { + if ((Index - AnchorIndex + 1) >= MaxNodeNameLength) { // Increase one for the NULL terminator + DEBUG((DEBUG_ERROR, "%a: the length of node name is >= MaxNodeNameLength\n", __FUNCTION__)); + ASSERT (FALSE); + } + NodeName[Index - AnchorIndex] = *(FeatureManagedUri + Index); + if (NodeName [Index - AnchorIndex] == NodeSeperator || NodeName [Index - AnchorIndex] == (CHAR16)0) { + NodeName [Index - AnchorIndex] = 0; + AnchorIndex = Index + 1; + // + // Insert node + // + if (StrLen(NodeName) != 0) { + Status = InsertRedfishFeatureUriNode(ThisUriNode, NodeName, &ThisUriNode); + if (EFI_ERROR (Status)) { + return Status; + } + } + } + Index ++; + } while ((Index < UriLength)); + + if (ThisUriNode == NULL) { + // + // No URI node was created + // + DEBUG((DEBUG_ERROR, "%a: No URI node is added\n", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + // + // Add feature driver info to internal data instance. + // + ThisUriNode->Callback = Callback; + ThisUriNode->Context = Context; + return EFI_SUCCESS; +} + +/** + The unregistration function for the Redfish Feature driver. + + @param[in] This Pointer to EDKII_REDFISH_FEATURE_PROTOCOL instance. + @param[in] FeatureManagedUri The URI represents the hierarchy path of the Redfish + resource in the entire Redfish data model that managed + by Redfish feature driver . Each node in the hierarchy + path is the property name defined in the schema of the + resource. + @param[in] Context The context used for the previous feature driver + registration. + @retval EFI_SUCCESS Redfish feature driver is registered successfully. + @retval Others Some error happened. + +**/ +EFI_STATUS +RedfishFeatureUnregister ( + IN EDKII_REDFISH_FEATURE_PROTOCOL *This, + IN EFI_STRING FeatureManagedUri, + IN VOID *Context +) +{ + return EFI_UNSUPPORTED; +} + +EDKII_REDFISH_FEATURE_PROTOCOL mRedfishFeatureProtocol = { + RedfishFeatureRegister, + RedfishFeatureUnregister +}; + +/** + Main entry for this driver. + + @param ImageHandle Image handle this driver. + @param SystemTable Pointer to SystemTable. + + @retval EFI_SUCESS This function always complete successfully. + +**/ +EFI_STATUS +EFIAPI +RedfishFeatureCoreEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + EFI_GUID *EventGuid; + + Handle = NULL; + ResourceUriNodeList = NULL; + EventGuid = (EFI_GUID *)PcdGetPtr (PcdEdkIIRedfishFeatureDriverStartupEventGuid); + + ZeroMem ((VOID *)&mFeatureDriverStartupContext, sizeof (REDFISH_FEATURE_STARTUP_CONTEXT)); + mFeatureDriverStartupContext.This = &mRedfishFeatureProtocol; + + Status = gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + RedfishFeatureDriverStartup, + (CONST VOID *)&mFeatureDriverStartupContext, + EventGuid, + &mEdkIIRedfishFeatureDriverStartupEvent + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Install the RedfishCredentialProtocol onto Handle. + // + Status = gBS->InstallMultipleProtocolInterfaces ( + &Handle, + &gEdkIIRedfishFeatureProtocolGuid, + &mRedfishFeatureProtocol, + NULL + ); + return Status; +} diff --git a/RedfishClientPkg/Readme.md b/RedfishClientPkg/Readme.md index 9e56fb9039..18a27633cf 100644 --- a/RedfishClientPkg/Readme.md +++ b/RedfishClientPkg/Readme.md @@ -119,6 +119,42 @@ struct _EDKII_REDFISH_PLATFORM_CONFIG_PROTOCOL { For those Non-EDK2 HII-based platform configuration formats, the driver instance can provide its own implementation to get or set the platform configurations. +### EDKII Redfish Feature Core DXE Driver ***[[12]](#[0])*** +EDKII Redfish Feature Core DXE driver provides the protocol interface to +the auto-generated Redfish feature driver to register itself for the +Redfish resource URI it manages. + +```C +struct _EDKII_REDFISH_FEATURE_PROTOCOL { + REDFISH_FEATURE_REGISTER Register; + REDFISH_FEATURE_UNREGISTER Unregister; +}; +``` + +Redfish Feature Core DXE driver records the +URI according to the URI hierarchy, and then it starts up the Redfish +feature drivers based on the hierarchy when the particular event +***[[11]](#[0])*** is triggered. This makes sure the upper-level Redfish +resource is built up before the lower-level resource. For example, +ComputerSystem resource must be ready before the Memory resource managed +by MemoryCollection because the Memory resource is part of ComputerSystem +resource. + +### Start-Up Event to Trigger EDKII Redfish Feature Core ***[[11]](#[0])*** +This is an EFI event for triggering EDKII Redfish Feature Core to travel +URIs in the database and execute the callback that registered by Redfish feature +drivers. The event GUID is defined in below PCD and is default set to +**gEfiEventReadyToBootGuid**. + +```C +PcdEdkIIRedfishFeatureDriverStartupEventGuid +``` + +This PCD can be overridden to any events based on the platform +implementation. EDKII Redfish Feature Core can be triggered earlier, +for example before the BDS or in the early DXE phase if the platform provides +the EFI REST EX protocol which is available before the BDS phase. + ### EDK2 HII VFR Form ***[[8]](#[0])*** According to **UEFI spec 2.9 section 35.6 Form Browser Protocol**, **EFI_HII_REST_STYLE_FORMSET_GUID** is used on HII form to indicate that HII -- 2.17.1