Re: [edk2-devel] [edk2-staging][PATCH v3 13/15] edk2-staging/RedfishClientPkg: Introduce Computer System collection driver

2022-07-27 Thread Chang, Abner via groups.io
[AMD Official Use Only - General]

Reviewed-by: Abner Chang 

> -Original Message-
> From: Nickle Wang 
> Sent: Wednesday, July 27, 2022 9:38 AM
> To: devel@edk2.groups.io
> Cc: Chang, Abner ; Yang, Atom
> ; Nick Ramirez 
> Subject: [edk2-staging][PATCH v3 13/15] edk2-staging/RedfishClientPkg:
> Introduce Computer System collection driver
> 
> [CAUTION: External Email]
> 
> Introduce new feature driver to support Computer System Collection
> schema. Update corresponding FDF and DSC file to enable this feature driver.
> 
> Signed-off-by: Nickle Wang 
> Cc: Abner Chang 
> Cc: Yang Atom 
> Cc: Nick Ramirez 
> ---
>  .../ComputerSystemCollectionDxe.c | 667 ++
>  .../ComputerSystemCollectionDxe.h |  21 +
>  .../ComputerSystemCollectionDxe.inf   |  56 ++
>  RedfishClientPkg/RedfishClient.fdf.inc|   2 +
>  .../RedfishClientComponents.dsc.inc   |   2 +
>  RedfishClientPkg/RedfishClientLibs.dsc.inc|   1 +
>  6 files changed, 749 insertions(+)
>  create mode 100644
> RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSyste
> mCollectionDxe.c
>  create mode 100644
> RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSyste
> mCollectionDxe.h
>  create mode 100644
> RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSyste
> mCollectionDxe.inf
> 
> diff --git
> a/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSyst
> emCollectionDxe.c
> b/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSyst
> emCollectionDxe.c
> new file mode 100644
> index 00..dbf5ab3395
> --- /dev/null
> +++
> b/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSyst
> +++ emCollectionDxe.c
> @@ -0,0 +1,667 @@
> +/** @file
> +
> +  Redfish feature driver implementation - ComputerSystemCollection
> +
> +  (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include "ComputerSystemCollectionDxe.h"
> +
> +REDFISH_COLLECTION_PRIVATE *mRedfishCollectionPrivate = NULL;
> +
> +EFI_STATUS
> +HandleResource (
> +  IN  REDFISH_COLLECTION_PRIVATE *Private,
> +  IN  EFI_STRING Uri
> +  )
> +{
> +  EFI_STATUS  Status;
> +  REDFISH_SCHEMA_INFO SchemaInfo;
> +  EFI_STRING  ConfigLang;
> +  EFI_STRING  ReturnedConfigLang;
> +  UINTN   Index;
> +
> +  if (Private == NULL || IS_EMPTY_STRING (Uri)) {
> +return EFI_INVALID_PARAMETER;
> +  }
> +
> +  //
> +  // Resource match
> +  //
> +
> +  DEBUG ((REDFISH_DEBUG_TRACE, "%a, process resource for: %s\n",
> + __FUNCTION__, Uri));
> +
> +  Status = GetRedfishSchemaInfo (Private->RedfishService,
> + Private->JsonStructProtocol, Uri, );  if (EFI_ERROR (Status)) {
> +DEBUG ((DEBUG_ERROR, "%a, failed to get schema information from: %s
> %r\n", __FUNCTION__, Uri, Status));
> +return Status;
> +  }
> +  //
> +  // Check and see if this is target resource that we want to handle.
> +  // Some resource is handled by other provider so we have to make sure
> this first.
> +  //
> +  DEBUG ((REDFISH_DEBUG_TRACE, "%s Identify for %s\n", __FUNCTION__,
> + Uri));  ConfigLang = RedfishGetConfigLanguage (Uri);  if (ConfigLang
> + == NULL) {
> +Status = EdkIIRedfishResourceConfigIdentify (, Uri, Private-
> >InformationExchange);
> +if (EFI_ERROR (Status)) {
> +  if (Status == EFI_UNSUPPORTED) {
> +DEBUG ((DEBUG_INFO, "%a, \"%s\" is not handled by us\n",
> __FUNCTION__, Uri));
> +return EFI_SUCCESS;
> +  }
> +
> +  DEBUG ((DEBUG_ERROR, "%a, fail to identify resource: \"%s\": %r\n",
> __FUNCTION__, Uri, Status));
> +  return Status;
> +}
> +  } else {
> +DEBUG ((REDFISH_DEBUG_TRACE, "%a, history record found: %s\n",
> __FUNCTION__, ConfigLang));
> +//
> +// Set exchange information
> +//
> +Status = GetArrayIndexFromArrayTypeConfigureLang (ConfigLang,
> , );
> +if (!EFI_ERROR (Status) || Status == EFI_NOT_FOUND) {
> +  Private->InformationExchange->ReturnedInformation.Type =
> InformationTypeCollectionMemberConfigLanguage;
> +  Private->InformationExchange-
> >ReturnedInformation.ConfigureLanguageList.Count = 1;
> +  Private->InformationExchange-
> >ReturnedInformation.ConfigureLanguageList.List =
> +AllocateZeroPool(sizeof
> + (REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG));
> +
> +  if (Private->InformationExchange-
> >ReturnedInformation.ConfigureLanguageList.List == NULL) {
> +DEBUG ((DEBUG_ERROR, "%a, Fail to allocate memory for
> REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG.\n", __FUNCTION__));
> +return EFI_OUT_OF_RESOURCES;
> +  }
> +  Private->InformationExchange-
> >ReturnedInformation.ConfigureLanguageList.List [0].Index = Index;
> +  Private->InformationExchange-
> >ReturnedInformation.ConfigureLanguageList.List 

[edk2-devel] [edk2-staging][PATCH v3 13/15] edk2-staging/RedfishClientPkg: Introduce Computer System collection driver

2022-07-26 Thread Nickle Wang
Introduce new feature driver to support Computer System Collection
schema. Update corresponding FDF and DSC file to enable this feature
driver.

Signed-off-by: Nickle Wang 
Cc: Abner Chang 
Cc: Yang Atom 
Cc: Nick Ramirez 
---
 .../ComputerSystemCollectionDxe.c | 667 ++
 .../ComputerSystemCollectionDxe.h |  21 +
 .../ComputerSystemCollectionDxe.inf   |  56 ++
 RedfishClientPkg/RedfishClient.fdf.inc|   2 +
 .../RedfishClientComponents.dsc.inc   |   2 +
 RedfishClientPkg/RedfishClientLibs.dsc.inc|   1 +
 6 files changed, 749 insertions(+)
 create mode 100644 
RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.c
 create mode 100644 
RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.h
 create mode 100644 
RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.inf

diff --git 
a/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.c
 
b/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.c
new file mode 100644
index 00..dbf5ab3395
--- /dev/null
+++ 
b/RedfishClientPkg/Features/ComputerSystemCollectionDxe/ComputerSystemCollectionDxe.c
@@ -0,0 +1,667 @@
+/** @file
+
+  Redfish feature driver implementation - ComputerSystemCollection
+
+  (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "ComputerSystemCollectionDxe.h"
+
+REDFISH_COLLECTION_PRIVATE *mRedfishCollectionPrivate = NULL;
+
+EFI_STATUS
+HandleResource (
+  IN  REDFISH_COLLECTION_PRIVATE *Private,
+  IN  EFI_STRING Uri
+  )
+{
+  EFI_STATUS  Status;
+  REDFISH_SCHEMA_INFO SchemaInfo;
+  EFI_STRING  ConfigLang;
+  EFI_STRING  ReturnedConfigLang;
+  UINTN   Index;
+
+  if (Private == NULL || IS_EMPTY_STRING (Uri)) {
+return EFI_INVALID_PARAMETER;
+  }
+
+  //
+  // Resource match
+  //
+
+  DEBUG ((REDFISH_DEBUG_TRACE, "%a, process resource for: %s\n", __FUNCTION__, 
Uri));
+
+  Status = GetRedfishSchemaInfo (Private->RedfishService, 
Private->JsonStructProtocol, Uri, );
+  if (EFI_ERROR (Status)) {
+DEBUG ((DEBUG_ERROR, "%a, failed to get schema information from: %s %r\n", 
__FUNCTION__, Uri, Status));
+return Status;
+  }
+  //
+  // Check and see if this is target resource that we want to handle.
+  // Some resource is handled by other provider so we have to make sure this 
first.
+  //
+  DEBUG ((REDFISH_DEBUG_TRACE, "%s Identify for %s\n", __FUNCTION__, Uri));
+  ConfigLang = RedfishGetConfigLanguage (Uri);
+  if (ConfigLang == NULL) {
+Status = EdkIIRedfishResourceConfigIdentify (, Uri, 
Private->InformationExchange);
+if (EFI_ERROR (Status)) {
+  if (Status == EFI_UNSUPPORTED) {
+DEBUG ((DEBUG_INFO, "%a, \"%s\" is not handled by us\n", __FUNCTION__, 
Uri));
+return EFI_SUCCESS;
+  }
+
+  DEBUG ((DEBUG_ERROR, "%a, fail to identify resource: \"%s\": %r\n", 
__FUNCTION__, Uri, Status));
+  return Status;
+}
+  } else {
+DEBUG ((REDFISH_DEBUG_TRACE, "%a, history record found: %s\n", 
__FUNCTION__, ConfigLang));
+//
+// Set exchange information
+//
+Status = GetArrayIndexFromArrayTypeConfigureLang (ConfigLang, 
, );
+if (!EFI_ERROR (Status) || Status == EFI_NOT_FOUND) {
+  Private->InformationExchange->ReturnedInformation.Type = 
InformationTypeCollectionMemberConfigLanguage;
+  
Private->InformationExchange->ReturnedInformation.ConfigureLanguageList.Count = 
1;
+  
Private->InformationExchange->ReturnedInformation.ConfigureLanguageList.List =
+AllocateZeroPool(sizeof (REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG));
+
+  if 
(Private->InformationExchange->ReturnedInformation.ConfigureLanguageList.List 
== NULL) {
+DEBUG ((DEBUG_ERROR, "%a, Fail to allocate memory for 
REDFISH_FEATURE_ARRAY_TYPE_CONFIG_LANG.\n", __FUNCTION__));
+return EFI_OUT_OF_RESOURCES;
+  }
+  
Private->InformationExchange->ReturnedInformation.ConfigureLanguageList.List 
[0].Index = Index;
+  
Private->InformationExchange->ReturnedInformation.ConfigureLanguageList.List 
[0].ConfigureLang =
+  (EFI_STRING)AllocateCopyPool(StrSize(ReturnedConfigLang), (VOID 
*)ReturnedConfigLang);
+} else {
+  DEBUG ((DEBUG_ERROR, "%a, GetArrayIndexFromArrayTypeConfigureLang fail: 
%r\n", __FUNCTION__, Status));
+}
+FreePool (ConfigLang);
+  }
+
+  //
+  // Check and see if target property exist or not even when collection 
memeber exists.
+  // If not, we sill do provision.
+  //
+  DEBUG ((REDFISH_DEBUG_TRACE, "%a Check for %s\n", __FUNCTION__, Uri));
+  Status = EdkIIRedfishResourceConfigCheck (, Uri);
+  if (EFI_ERROR (Status)) {
+//
+// The target property does not exist, do the provision