public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-staging][PATCH] edk2-staging/RedfishClientPkg: Add Redfish.Settings support
       [not found] <20221209063413.31912-1-simowang@nvidia.com>
@ 2022-12-09  6:39 ` Simon Wang (SW-GPU)
  2022-12-12  4:52   ` Chang, Abner
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Wang (SW-GPU) @ 2022-12-09  6:39 UTC (permalink / raw)
  To: devel@edk2.groups.io
  Cc: Nickle Wang, Nick Ramirez, abner.chang@amd.com,
	Igor Miroshnichenko

BIOS feature driver cannot recognize "@Redfish.Settings", decode it and get pending setting URI. So BIOS feature driver can consume pending setting from correct place.

Signed-off-by: Simon Wang <simowang@nvidia.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Nick Ramirez <nramirez@nvidia.com>
---
 .../Features/Bios/v1_0_9/Dxe/BiosDxe.c        | 214 +++++++++++-------
 1 file changed, 130 insertions(+), 84 deletions(-)

diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
index a478061cde..5e3820fa96 100644
--- a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
+++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
@@ -2,6 +2,7 @@
   Redfish feature driver implementation - Bios
 
   (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP<BR>
+  Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -9,15 +10,15 @@
 
 #include "../Common/BiosCommon.h"
 
-extern REDFISH_RESOURCE_COMMON_PRIVATE *mRedfishResourcePrivate;
+extern REDFISH_RESOURCE_COMMON_PRIVATE  *mRedfishResourcePrivate;
 
 EFI_STATUS
 HandleResource (
-  IN  REDFISH_RESOURCE_COMMON_PRIVATE *Private,
-  IN  EFI_STRING                      Uri
+  IN  REDFISH_RESOURCE_COMMON_PRIVATE  *Private,
+  IN  EFI_STRING                       Uri
   );
 
-EFI_HANDLE medfishResourceConfigProtocolHandle;
+EFI_HANDLE  medfishResourceConfigProtocolHandle;
 
 /**
   Provising redfish resource by given URI.
@@ -33,16 +34,16 @@ EFI_HANDLE medfishResourceConfigProtocolHandle;
 **/
 EFI_STATUS
 RedfishResourceProvisioningResource (
-  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL    *This,
-  IN     EFI_STRING                                Uri,
-  IN     BOOLEAN                                   PostMode
+  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  *This,
+  IN     EFI_STRING                              Uri,
+  IN     BOOLEAN                                 PostMode
   )
 {
-  REDFISH_RESOURCE_COMMON_PRIVATE *Private;
-  EFI_STATUS                      Status;
-  REDFISH_RESPONSE                Response;
+  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
+  EFI_STATUS                       Status;
+  REDFISH_RESPONSE                 Response;
 
-  if (This == NULL || IS_EMPTY_STRING (Uri)) {
+  if ((This == NULL) || IS_EMPTY_STRING (Uri)) {
     return EFI_INVALID_PARAMETER;
   }
 
@@ -60,7 +61,7 @@ RedfishResourceProvisioningResource (
     return Status;
   }
 
-  Private->Uri = Uri;
+  Private->Uri     = Uri;
   Private->Payload = Response.Payload;
   ASSERT (Private->Payload != NULL);
 
@@ -94,16 +95,22 @@ RedfishResourceProvisioningResource (  **/  EFI_STATUS  RedfishResourceConsumeResource (
-  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL    *This,
-  IN     EFI_STRING                                Uri
+  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  *This,
+  IN     EFI_STRING                              Uri
   )
 {
-  REDFISH_RESOURCE_COMMON_PRIVATE *Private;
-  EFI_STATUS                    Status;
-  REDFISH_RESPONSE              Response;
-  CHAR8                         *Etag;
-
-  if (This == NULL || IS_EMPTY_STRING (Uri)) {
+  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
+  EFI_STATUS                       Status;
+  REDFISH_RESPONSE                 Response;
+  REDFISH_RESPONSE                 *ExpectedResponse;
+  REDFISH_RESPONSE                 RedfishSettingsResponse;
+  CHAR8                            *Etag;
+  UINTN                            Index;
+  EDKII_JSON_VALUE                 JsonValue;
+  EFI_STRING                       RedfishSettingsUri;
+  CONST CHAR8                      *RedfishSettingsUriKeys[] = { "@Redfish.Settings", "SettingsObject", "@odata.id" };
+
+  if ((This == NULL) || IS_EMPTY_STRING (Uri)) {
     return EFI_INVALID_PARAMETER;
   }
 
@@ -119,7 +126,37 @@ RedfishResourceConsumeResource (
     return Status;
   }
 
-  Private->Uri = Uri;
+  ExpectedResponse   = &Response;
+  RedfishSettingsUri = NULL;
+  JsonValue          = RedfishJsonInPayload (Response.Payload);
+
+  //
+  // Seeking RedfishSettings URI link.
+  //
+  for (Index = 0; Index < ARRAY_SIZE (RedfishSettingsUriKeys); Index++) {
+    if (JsonValue == NULL) {
+      break;
+    }
+
+    JsonValue = JsonObjectGetValue (JsonValueGetObject (JsonValue), 
+ RedfishSettingsUriKeys[Index]);  }
+
+  if (JsonValue != NULL) {
+    //
+    // Verify RedfishSettings URI link is valid to retrieve resource or not.
+    //
+    RedfishSettingsUri = JsonValueGetUnicodeString (JsonValue);
+
+    Status = GetResourceByUri (Private->RedfishService, RedfishSettingsUri, &RedfishSettingsResponse);
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n", __FUNCTION__, RedfishSettingsUri));
+    } else {
+      Uri              = RedfishSettingsUri;
+      ExpectedResponse = &RedfishSettingsResponse;
+    }
+  }
+
+  Private->Uri     = Uri;
   Private->Payload = Response.Payload;
   ASSERT (Private->Payload != NULL);
 
@@ -129,7 +166,7 @@ RedfishResourceConsumeResource (
   //
   // Find etag in HTTP response header
   //
-  Etag = NULL;
+  Etag   = NULL;
   Status = GetEtagAndLocation (&Response, &Etag, NULL);
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "%a, failed to get ETag from HTTP header\n", __FUNCTION__)); @@ -153,13 +190,23 @@ RedfishResourceConsumeResource (
   // Release resource
   //
   if (Private->Payload != NULL) {
-    RedfishFreeResponse (
-      Response.StatusCode,
-      Response.HeaderCount,
-      Response.Headers,
-      Response.Payload
-      );
-    Private->Payload = NULL;
+    if (Response.Payload != NULL) {
+      RedfishFreeResponse (
+        Response.StatusCode,
+        Response.HeaderCount,
+        Response.Headers,
+        Response.Payload
+        );
+    }
+
+    if (RedfishSettingsResponse.Payload != NULL) {
+      RedfishFreeResponse (
+        RedfishSettingsResponse.StatusCode,
+        RedfishSettingsResponse.HeaderCount,
+        RedfishSettingsResponse.Headers,
+        RedfishSettingsResponse.Payload
+        );
+    }
   }
 
   if (Private->Json != NULL) {
@@ -185,13 +232,13 @@ RedfishResourceConsumeResource (  **/  EFI_STATUS  RedfishResourceGetInfo (
-  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL    *This,
+  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  *This,
   OUT    REDFISH_SCHEMA_INFO                     *Info
   )
 {
-  REDFISH_RESOURCE_COMMON_PRIVATE *Private;
+  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
 
-  if (This == NULL || Info == NULL) {
+  if ((This == NULL) || (Info == NULL)) {
     return EFI_INVALID_PARAMETER;
   }
 
@@ -217,15 +264,15 @@ RedfishResourceGetInfo (  **/  EFI_STATUS  RedfishResourceUpdate (
-  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL    *This,
-  IN     EFI_STRING                                Uri
+  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  *This,
+  IN     EFI_STRING                              Uri
   )
 {
-  REDFISH_RESOURCE_COMMON_PRIVATE *Private;
-  EFI_STATUS                    Status;
-  REDFISH_RESPONSE              Response;
+  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
+  EFI_STATUS                       Status;
+  REDFISH_RESPONSE                 Response;
 
-  if (This == NULL || IS_EMPTY_STRING (Uri)) {
+  if ((This == NULL) || IS_EMPTY_STRING (Uri)) {
     return EFI_INVALID_PARAMETER;
   }
 
@@ -241,7 +288,7 @@ RedfishResourceUpdate (
     return Status;
   }
 
-  Private->Uri = Uri;
+  Private->Uri     = Uri;
   Private->Payload = Response.Payload;
   ASSERT (Private->Payload != NULL);
 
@@ -286,15 +333,15 @@ RedfishResourceUpdate (  **/  EFI_STATUS  RedfishResourceCheck (
-  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL    *This,
-  IN     EFI_STRING                                Uri
+  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  *This,
+  IN     EFI_STRING                              Uri
   )
 {
-  REDFISH_RESOURCE_COMMON_PRIVATE *Private;
-  EFI_STATUS                    Status;
-  REDFISH_RESPONSE              Response;
+  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
+  EFI_STATUS                       Status;
+  REDFISH_RESPONSE                 Response;
 
-  if (This == NULL || IS_EMPTY_STRING (Uri)) {
+  if ((This == NULL) || IS_EMPTY_STRING (Uri)) {
     return EFI_INVALID_PARAMETER;
   }
 
@@ -310,7 +357,7 @@ RedfishResourceCheck (
     return Status;
   }
 
-  Private->Uri = Uri;
+  Private->Uri     = Uri;
   Private->Payload = Response.Payload;
   ASSERT (Private->Payload != NULL);
 
@@ -354,18 +401,17 @@ RedfishResourceCheck (
   @retval Others                   Some error happened.
 
 **/
-
 EFI_STATUS
 RedfishResourceIdentify (
   IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  *This,
   IN     EFI_STRING                              Uri
   )
 {
-  REDFISH_RESOURCE_COMMON_PRIVATE *Private;
-  EFI_STATUS                    Status;
-  REDFISH_RESPONSE              Response;
+  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
+  EFI_STATUS                       Status;
+  REDFISH_RESPONSE                 Response;
 
-  if (This == NULL || IS_EMPTY_STRING (Uri)) {
+  if ((This == NULL) || IS_EMPTY_STRING (Uri)) {
     return EFI_INVALID_PARAMETER;
   }
 
@@ -381,7 +427,7 @@ RedfishResourceIdentify (
     return Status;
   }
 
-  Private->Uri = Uri;
+  Private->Uri     = Uri;
   Private->Payload = Response.Payload;
   ASSERT (Private->Payload != NULL);
 
@@ -392,6 +438,7 @@ RedfishResourceIdentify (
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "%a, identify %s failed: %r\n", __FUNCTION__, Uri, Status));
   }
+
   //
   // Release resource
   //
@@ -413,7 +460,7 @@ RedfishResourceIdentify (
   return Status;
 }
 
-EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL mRedfishResourceConfig = {
+EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  mRedfishResourceConfig = {
   RedfishResourceProvisioningResource,
   RedfishResourceConsumeResource,
   RedfishResourceUpdate,
@@ -441,10 +488,10 @@ EFI_STATUS
 EFIAPI
 RedfishResourceInit (
   IN  EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL  *This,
-  IN  REDFISH_CONFIG_SERVICE_INFORMATION   *RedfishConfigServiceInfo
+  IN  REDFISH_CONFIG_SERVICE_INFORMATION     *RedfishConfigServiceInfo
   )
 {
-  REDFISH_RESOURCE_COMMON_PRIVATE *Private;
+  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
 
   Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_CONFIG_PROTOCOL (This);
 
@@ -468,10 +515,10 @@ RedfishResourceInit (  EFI_STATUS  EFIAPI  RedfishResourceStop (
-  IN  EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL       *This
+  IN  EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL  *This
   )
 {
-  REDFISH_RESOURCE_COMMON_PRIVATE *Private;
+  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
 
   Private = REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_CONFIG_PROTOCOL (This);
 
@@ -493,7 +540,7 @@ RedfishResourceStop (
   return EFI_SUCCESS;
 }
 
-EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL mRedfishConfigHandler = {
+EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL  mRedfishConfigHandler = {
   RedfishResourceInit,
   RedfishResourceStop
 };
@@ -506,10 +553,9 @@ EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL mRedfishConfigHandler = {  **/  VOID  EFIAPI -EfiRestJasonStructureProtocolIsReady
- (
-  IN  EFI_EVENT                             Event,
-  IN  VOID                                  *Context
+EfiRestJasonStructureProtocolIsReady (
+  IN  EFI_EVENT  Event,
+  IN  VOID       *Context
   )
 {
   EFI_STATUS  Status;
@@ -523,10 +569,10 @@ EfiRestJasonStructureProtocolIsReady
   }
 
   Status = gBS->LocateProtocol (
-                 &gEfiRestJsonStructureProtocolGuid,
-                 NULL,
-                 (VOID **)&mRedfishResourcePrivate->JsonStructProtocol
-                 );
+                  &gEfiRestJsonStructureProtocolGuid,
+                  NULL,
+                  (VOID **)&mRedfishResourcePrivate->JsonStructProtocol
+                  );
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "%a, failed to locate gEfiRestJsonStructureProtocolGuid: %r\n", __FUNCTION__, Status));
   }
@@ -550,7 +596,7 @@ RedfishResourceUnload (
   )
 {
   EFI_STATUS                             Status;
-  EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL    *ConfigHandler;
+  EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL  *ConfigHandler;
 
   if (mRedfishResourcePrivate == NULL) {
     return EFI_NOT_READY;
@@ -564,12 +610,12 @@ RedfishResourceUnload (
   Status = gBS->OpenProtocol (
                   ImageHandle,
                   &gEdkIIRedfishConfigHandlerProtocolGuid,
-                  (VOID **) &ConfigHandler,
+                  (VOID **)&ConfigHandler,
                   NULL,
                   NULL,
                   EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
                   );
-  if (EFI_ERROR (Status) || ConfigHandler == NULL) {
+  if (EFI_ERROR (Status) || (ConfigHandler == NULL)) {
     return Status;
   }
 
@@ -612,10 +658,10 @@ RedfishResourceUnload (  EFI_STATUS  EFIAPI  RedfishExternalResourceResourceFeatureCallback (
-  IN     EDKII_REDFISH_FEATURE_PROTOCOL *This,
-  IN     FEATURE_CALLBACK_ACTION        FeatureAction,
-  IN     VOID                           *Context,
-  IN OUT RESOURCE_INFORMATION_EXCHANGE  *InformationExchange
+  IN     EDKII_REDFISH_FEATURE_PROTOCOL  *This,
+  IN     FEATURE_CALLBACK_ACTION         FeatureAction,
+  IN     VOID                            *Context,
+  IN OUT RESOURCE_INFORMATION_EXCHANGE   *InformationExchange
   )
 {
   EFI_STATUS                       Status;
@@ -647,11 +693,12 @@ RedfishExternalResourceResourceFeatureCallback (
   //
   // Create the full URI from Redfish service root.
   //
-  ResourceUri = (EFI_STRING)AllocateZeroPool (MAX_URI_LENGTH * sizeof(CHAR16));
+  ResourceUri = (EFI_STRING)AllocateZeroPool (MAX_URI_LENGTH * sizeof 
+ (CHAR16));
   if (ResourceUri == NULL) {
     DEBUG ((DEBUG_ERROR, "%a, Fail to allocate memory for full URI.\n", __FUNCTION__));
     return EFI_OUT_OF_RESOURCES;
   }
+
   StrCatS (ResourceUri, MAX_URI_LENGTH, Private->RedfishVersion);
   StrCatS (ResourceUri, MAX_URI_LENGTH, InformationExchange->SendInformation.FullUri);
 
@@ -681,10 +728,9 @@ RedfishExternalResourceResourceFeatureCallback (  **/  VOID  EFIAPI -EdkIIRedfishFeatureProtocolIsReady
- (
-  IN  EFI_EVENT                             Event,
-  IN  VOID                                  *Context
+EdkIIRedfishFeatureProtocolIsReady (
+  IN  EFI_EVENT  Event,
+  IN  VOID       *Context
   )
 {
   EFI_STATUS                      Status;
@@ -699,10 +745,10 @@ EdkIIRedfishFeatureProtocolIsReady
   }
 
   Status = gBS->LocateProtocol (
-                 &gEdkIIRedfishFeatureProtocolGuid,
-                 NULL,
-                 (VOID **)&FeatureProtocol
-                 );
+                  &gEdkIIRedfishFeatureProtocolGuid,
+                  NULL,
+                  (VOID **)&FeatureProtocol
+                  );
   if (EFI_ERROR (Status)) {
     DEBUG ((DEBUG_ERROR, "%a, failed to locate gEdkIIRedfishFeatureProtocolGuid: %r\n", __FUNCTION__, Status));
     gBS->CloseEvent (Event);
@@ -744,8 +790,8 @@ RedfishResourceEntryPoint (
   IN EFI_SYSTEM_TABLE  *SystemTable
   )
 {
-  EFI_STATUS               Status;
-  VOID                     *Registration;
+  EFI_STATUS  Status;
+  VOID        *Registration;
 
   if (mRedfishResourcePrivate != NULL) {
     return EFI_ALREADY_STARTED;
--
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [edk2-staging][PATCH] edk2-staging/RedfishClientPkg: Add Redfish.Settings support
  2022-12-09  6:39 ` [edk2-staging][PATCH] edk2-staging/RedfishClientPkg: Add Redfish.Settings support Simon Wang (SW-GPU)
@ 2022-12-12  4:52   ` Chang, Abner
  0 siblings, 0 replies; 2+ messages in thread
From: Chang, Abner @ 2022-12-12  4:52 UTC (permalink / raw)
  To: Simon Wang (SW-GPU), devel@edk2.groups.io
  Cc: Nickle Wang, Nick Ramirez, Igor Miroshnichenko

[AMD Official Use Only - General]

Hi Simon, comments in line.

> -----Original Message-----
> From: Simon Wang (SW-GPU) <simowang@nvidia.com>
> Sent: Friday, December 9, 2022 2:40 PM
> To: devel@edk2.groups.io
> Cc: Nickle Wang <nicklew@nvidia.com>; Nick Ramirez
> <nramirez@nvidia.com>; Chang, Abner <Abner.Chang@amd.com>; Igor
> Miroshnichenko <igormir@nvidia.com>
> Subject: [edk2-staging][PATCH] edk2-staging/RedfishClientPkg: Add
> Redfish.Settings support
> 
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
> 
> 
> BIOS feature driver cannot recognize "@Redfish.Settings", decode it and get
> pending setting URI. So BIOS feature driver can consume pending setting
> from correct place.
> 
> Signed-off-by: Simon Wang <simowang@nvidia.com>
> Cc: Nickle Wang <nicklew@nvidia.com>
> Cc: Abner Chang <abner.chang@amd.com>
> Cc: Igor Kulchytskyy <igork@ami.com>
> Cc: Nick Ramirez <nramirez@nvidia.com>
> ---
>  .../Features/Bios/v1_0_9/Dxe/BiosDxe.c        | 214 +++++++++++-------
>  1 file changed, 130 insertions(+), 84 deletions(-)
> 
> diff --git a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
> b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
> index a478061cde..5e3820fa96 100644
> --- a/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
> +++ b/RedfishClientPkg/Features/Bios/v1_0_9/Dxe/BiosDxe.c
> @@ -2,6 +2,7 @@
>    Redfish feature driver implementation - Bios
> 
>    (C) Copyright 2020-2022 Hewlett Packard Enterprise Development LP<BR>
> +  Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
> 
>    SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> @@ -9,15 +10,15 @@
> 
>  #include "../Common/BiosCommon.h"
> 
> -extern REDFISH_RESOURCE_COMMON_PRIVATE
> *mRedfishResourcePrivate;
> +extern REDFISH_RESOURCE_COMMON_PRIVATE
> *mRedfishResourcePrivate;
Just a note here, move extern declaration to header file when autogen the feature driver. This is compliant with edk2 C coding standard section 5.4.2.1.

> 
>  EFI_STATUS
>  HandleResource (
> -  IN  REDFISH_RESOURCE_COMMON_PRIVATE *Private,
> -  IN  EFI_STRING                      Uri
> +  IN  REDFISH_RESOURCE_COMMON_PRIVATE  *Private,
> +  IN  EFI_STRING                       Uri
>    );
> 
> -EFI_HANDLE medfishResourceConfigProtocolHandle;
> +EFI_HANDLE  medfishResourceConfigProtocolHandle;
> 
>  /**
>    Provising redfish resource by given URI.
> @@ -33,16 +34,16 @@ EFI_HANDLE medfishResourceConfigProtocolHandle;
>  **/
>  EFI_STATUS
>  RedfishResourceProvisioningResource (
> -  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL    *This,
> -  IN     EFI_STRING                                Uri,
> -  IN     BOOLEAN                                   PostMode
> +  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  *This,
> +  IN     EFI_STRING                              Uri,
> +  IN     BOOLEAN                                 PostMode
>    )
>  {
> -  REDFISH_RESOURCE_COMMON_PRIVATE *Private;
> -  EFI_STATUS                      Status;
> -  REDFISH_RESPONSE                Response;
> +  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
> +  EFI_STATUS                       Status;
> +  REDFISH_RESPONSE                 Response;
> 
> -  if (This == NULL || IS_EMPTY_STRING (Uri)) {
> +  if ((This == NULL) || IS_EMPTY_STRING (Uri)) {
>      return EFI_INVALID_PARAMETER;
>    }
> 
> @@ -60,7 +61,7 @@ RedfishResourceProvisioningResource (
>      return Status;
>    }
> 
> -  Private->Uri = Uri;
> +  Private->Uri     = Uri;
>    Private->Payload = Response.Payload;
>    ASSERT (Private->Payload != NULL);
> 
> @@ -94,16 +95,22 @@ RedfishResourceProvisioningResource (  **/
> EFI_STATUS  RedfishResourceConsumeResource (
> -  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL    *This,
> -  IN     EFI_STRING                                Uri
> +  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  *This,
> +  IN     EFI_STRING                              Uri
>    )
>  {
> -  REDFISH_RESOURCE_COMMON_PRIVATE *Private;
> -  EFI_STATUS                    Status;
> -  REDFISH_RESPONSE              Response;
> -  CHAR8                         *Etag;
> -
> -  if (This == NULL || IS_EMPTY_STRING (Uri)) {
> +  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
> +  EFI_STATUS                       Status;
> +  REDFISH_RESPONSE                 Response;
> +  REDFISH_RESPONSE                 *ExpectedResponse;
> +  REDFISH_RESPONSE                 RedfishSettingsResponse;
> +  CHAR8                            *Etag;
> +  UINTN                            Index;
> +  EDKII_JSON_VALUE                 JsonValue;
> +  EFI_STRING                       RedfishSettingsUri;
> +  CONST CHAR8                      *RedfishSettingsUriKeys[] =
> { "@Redfish.Settings", "SettingsObject", "@odata.id" };
> +
> +  if ((This == NULL) || IS_EMPTY_STRING (Uri)) {
>      return EFI_INVALID_PARAMETER;
>    }
> 
> @@ -119,7 +126,37 @@ RedfishResourceConsumeResource (
>      return Status;
>    }
> 
> -  Private->Uri = Uri;
> +  ExpectedResponse   = &Response;
> +  RedfishSettingsUri = NULL;
> +  JsonValue          = RedfishJsonInPayload (Response.Payload);
> +
> +  //
> +  // Seeking RedfishSettings URI link.
> +  //
> +  for (Index = 0; Index < ARRAY_SIZE (RedfishSettingsUriKeys); Index++) {
> +    if (JsonValue == NULL) {
> +      break;
> +    }
> +
> +    JsonValue = JsonObjectGetValue (JsonValueGetObject (JsonValue),
> + RedfishSettingsUriKeys[Index]);  }
> +
> +  if (JsonValue != NULL) {
> +    //
> +    // Verify RedfishSettings URI link is valid to retrieve resource or not.
> +    //
> +    RedfishSettingsUri = JsonValueGetUnicodeString (JsonValue);
> +
> +    Status = GetResourceByUri (Private->RedfishService, RedfishSettingsUri,
> &RedfishSettingsResponse);
> +    if (EFI_ERROR (Status)) {
> +      DEBUG ((DEBUG_ERROR, "%a, get resource from: %s failed\n",
> __FUNCTION__, RedfishSettingsUri));
Can we have a more clear debug message, something like
"@Redfish.Settings exists, however to get resource from %s failed.\n"

Thanks
Abner


> +    } else {
> +      Uri              = RedfishSettingsUri;
> +      ExpectedResponse = &RedfishSettingsResponse;
> +    }
> +  }
> +
> +  Private->Uri     = Uri;
>    Private->Payload = Response.Payload;
>    ASSERT (Private->Payload != NULL);
> 
> @@ -129,7 +166,7 @@ RedfishResourceConsumeResource (
>    //
>    // Find etag in HTTP response header
>    //
> -  Etag = NULL;
> +  Etag   = NULL;
>    Status = GetEtagAndLocation (&Response, &Etag, NULL);
>    if (EFI_ERROR (Status)) {
>      DEBUG ((DEBUG_ERROR, "%a, failed to get ETag from HTTP header\n",
> __FUNCTION__)); @@ -153,13 +190,23 @@
> RedfishResourceConsumeResource (
>    // Release resource
>    //
>    if (Private->Payload != NULL) {
> -    RedfishFreeResponse (
> -      Response.StatusCode,
> -      Response.HeaderCount,
> -      Response.Headers,
> -      Response.Payload
> -      );
> -    Private->Payload = NULL;
> +    if (Response.Payload != NULL) {
> +      RedfishFreeResponse (
> +        Response.StatusCode,
> +        Response.HeaderCount,
> +        Response.Headers,
> +        Response.Payload
> +        );
> +    }
> +
> +    if (RedfishSettingsResponse.Payload != NULL) {
> +      RedfishFreeResponse (
> +        RedfishSettingsResponse.StatusCode,
> +        RedfishSettingsResponse.HeaderCount,
> +        RedfishSettingsResponse.Headers,
> +        RedfishSettingsResponse.Payload
> +        );
> +    }
>    }
> 
>    if (Private->Json != NULL) {
> @@ -185,13 +232,13 @@ RedfishResourceConsumeResource (  **/
> EFI_STATUS  RedfishResourceGetInfo (
> -  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL    *This,
> +  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  *This,
>    OUT    REDFISH_SCHEMA_INFO                     *Info
>    )
>  {
> -  REDFISH_RESOURCE_COMMON_PRIVATE *Private;
> +  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
> 
> -  if (This == NULL || Info == NULL) {
> +  if ((This == NULL) || (Info == NULL)) {
>      return EFI_INVALID_PARAMETER;
>    }
> 
> @@ -217,15 +264,15 @@ RedfishResourceGetInfo (  **/  EFI_STATUS
> RedfishResourceUpdate (
> -  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL    *This,
> -  IN     EFI_STRING                                Uri
> +  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  *This,
> +  IN     EFI_STRING                              Uri
>    )
>  {
> -  REDFISH_RESOURCE_COMMON_PRIVATE *Private;
> -  EFI_STATUS                    Status;
> -  REDFISH_RESPONSE              Response;
> +  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
> +  EFI_STATUS                       Status;
> +  REDFISH_RESPONSE                 Response;
> 
> -  if (This == NULL || IS_EMPTY_STRING (Uri)) {
> +  if ((This == NULL) || IS_EMPTY_STRING (Uri)) {
>      return EFI_INVALID_PARAMETER;
>    }
> 
> @@ -241,7 +288,7 @@ RedfishResourceUpdate (
>      return Status;
>    }
> 
> -  Private->Uri = Uri;
> +  Private->Uri     = Uri;
>    Private->Payload = Response.Payload;
>    ASSERT (Private->Payload != NULL);
> 
> @@ -286,15 +333,15 @@ RedfishResourceUpdate (  **/  EFI_STATUS
> RedfishResourceCheck (
> -  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL    *This,
> -  IN     EFI_STRING                                Uri
> +  IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  *This,
> +  IN     EFI_STRING                              Uri
>    )
>  {
> -  REDFISH_RESOURCE_COMMON_PRIVATE *Private;
> -  EFI_STATUS                    Status;
> -  REDFISH_RESPONSE              Response;
> +  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
> +  EFI_STATUS                       Status;
> +  REDFISH_RESPONSE                 Response;
> 
> -  if (This == NULL || IS_EMPTY_STRING (Uri)) {
> +  if ((This == NULL) || IS_EMPTY_STRING (Uri)) {
>      return EFI_INVALID_PARAMETER;
>    }
> 
> @@ -310,7 +357,7 @@ RedfishResourceCheck (
>      return Status;
>    }
> 
> -  Private->Uri = Uri;
> +  Private->Uri     = Uri;
>    Private->Payload = Response.Payload;
>    ASSERT (Private->Payload != NULL);
> 
> @@ -354,18 +401,17 @@ RedfishResourceCheck (
>    @retval Others                   Some error happened.
> 
>  **/
> -
>  EFI_STATUS
>  RedfishResourceIdentify (
>    IN     EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  *This,
>    IN     EFI_STRING                              Uri
>    )
>  {
> -  REDFISH_RESOURCE_COMMON_PRIVATE *Private;
> -  EFI_STATUS                    Status;
> -  REDFISH_RESPONSE              Response;
> +  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
> +  EFI_STATUS                       Status;
> +  REDFISH_RESPONSE                 Response;
> 
> -  if (This == NULL || IS_EMPTY_STRING (Uri)) {
> +  if ((This == NULL) || IS_EMPTY_STRING (Uri)) {
>      return EFI_INVALID_PARAMETER;
>    }
> 
> @@ -381,7 +427,7 @@ RedfishResourceIdentify (
>      return Status;
>    }
> 
> -  Private->Uri = Uri;
> +  Private->Uri     = Uri;
>    Private->Payload = Response.Payload;
>    ASSERT (Private->Payload != NULL);
> 
> @@ -392,6 +438,7 @@ RedfishResourceIdentify (
>    if (EFI_ERROR (Status)) {
>      DEBUG ((DEBUG_ERROR, "%a, identify %s failed: %r\n", __FUNCTION__,
> Uri, Status));
>    }
> +
>    //
>    // Release resource
>    //
> @@ -413,7 +460,7 @@ RedfishResourceIdentify (
>    return Status;
>  }
> 
> -EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL mRedfishResourceConfig =
> {
> +EDKII_REDFISH_RESOURCE_CONFIG_PROTOCOL  mRedfishResourceConfig
> = {
>    RedfishResourceProvisioningResource,
>    RedfishResourceConsumeResource,
>    RedfishResourceUpdate,
> @@ -441,10 +488,10 @@ EFI_STATUS
>  EFIAPI
>  RedfishResourceInit (
>    IN  EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL  *This,
> -  IN  REDFISH_CONFIG_SERVICE_INFORMATION   *RedfishConfigServiceInfo
> +  IN  REDFISH_CONFIG_SERVICE_INFORMATION
> *RedfishConfigServiceInfo
>    )
>  {
> -  REDFISH_RESOURCE_COMMON_PRIVATE *Private;
> +  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
> 
>    Private =
> REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_CONFIG_PROTOCO
> L (This);
> 
> @@ -468,10 +515,10 @@ RedfishResourceInit (  EFI_STATUS  EFIAPI
> RedfishResourceStop (
> -  IN  EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL       *This
> +  IN  EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL  *This
>    )
>  {
> -  REDFISH_RESOURCE_COMMON_PRIVATE *Private;
> +  REDFISH_RESOURCE_COMMON_PRIVATE  *Private;
> 
>    Private =
> REDFISH_RESOURCE_COMMON_PRIVATE_DATA_FROM_CONFIG_PROTOCO
> L (This);
> 
> @@ -493,7 +540,7 @@ RedfishResourceStop (
>    return EFI_SUCCESS;
>  }
> 
> -EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL mRedfishConfigHandler = {
> +EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL  mRedfishConfigHandler = {
>    RedfishResourceInit,
>    RedfishResourceStop
>  };
> @@ -506,10 +553,9 @@ EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL
> mRedfishConfigHandler = {  **/  VOID  EFIAPI -
> EfiRestJasonStructureProtocolIsReady
> - (
> -  IN  EFI_EVENT                             Event,
> -  IN  VOID                                  *Context
> +EfiRestJasonStructureProtocolIsReady (
> +  IN  EFI_EVENT  Event,
> +  IN  VOID       *Context
>    )
>  {
>    EFI_STATUS  Status;
> @@ -523,10 +569,10 @@ EfiRestJasonStructureProtocolIsReady
>    }
> 
>    Status = gBS->LocateProtocol (
> -                 &gEfiRestJsonStructureProtocolGuid,
> -                 NULL,
> -                 (VOID **)&mRedfishResourcePrivate->JsonStructProtocol
> -                 );
> +                  &gEfiRestJsonStructureProtocolGuid,
> +                  NULL,
> +                  (VOID **)&mRedfishResourcePrivate->JsonStructProtocol
> +                  );
>    if (EFI_ERROR (Status)) {
>      DEBUG ((DEBUG_ERROR, "%a, failed to locate
> gEfiRestJsonStructureProtocolGuid: %r\n", __FUNCTION__, Status));
>    }
> @@ -550,7 +596,7 @@ RedfishResourceUnload (
>    )
>  {
>    EFI_STATUS                             Status;
> -  EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL    *ConfigHandler;
> +  EDKII_REDFISH_CONFIG_HANDLER_PROTOCOL  *ConfigHandler;
> 
>    if (mRedfishResourcePrivate == NULL) {
>      return EFI_NOT_READY;
> @@ -564,12 +610,12 @@ RedfishResourceUnload (
>    Status = gBS->OpenProtocol (
>                    ImageHandle,
>                    &gEdkIIRedfishConfigHandlerProtocolGuid,
> -                  (VOID **) &ConfigHandler,
> +                  (VOID **)&ConfigHandler,
>                    NULL,
>                    NULL,
>                    EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
>                    );
> -  if (EFI_ERROR (Status) || ConfigHandler == NULL) {
> +  if (EFI_ERROR (Status) || (ConfigHandler == NULL)) {
>      return Status;
>    }
> 
> @@ -612,10 +658,10 @@ RedfishResourceUnload (  EFI_STATUS  EFIAPI
> RedfishExternalResourceResourceFeatureCallback (
> -  IN     EDKII_REDFISH_FEATURE_PROTOCOL *This,
> -  IN     FEATURE_CALLBACK_ACTION        FeatureAction,
> -  IN     VOID                           *Context,
> -  IN OUT RESOURCE_INFORMATION_EXCHANGE  *InformationExchange
> +  IN     EDKII_REDFISH_FEATURE_PROTOCOL  *This,
> +  IN     FEATURE_CALLBACK_ACTION         FeatureAction,
> +  IN     VOID                            *Context,
> +  IN OUT RESOURCE_INFORMATION_EXCHANGE   *InformationExchange
>    )
>  {
>    EFI_STATUS                       Status;
> @@ -647,11 +693,12 @@ RedfishExternalResourceResourceFeatureCallback (
>    //
>    // Create the full URI from Redfish service root.
>    //
> -  ResourceUri = (EFI_STRING)AllocateZeroPool (MAX_URI_LENGTH *
> sizeof(CHAR16));
> +  ResourceUri = (EFI_STRING)AllocateZeroPool (MAX_URI_LENGTH * sizeof
> + (CHAR16));
>    if (ResourceUri == NULL) {
>      DEBUG ((DEBUG_ERROR, "%a, Fail to allocate memory for full URI.\n",
> __FUNCTION__));
>      return EFI_OUT_OF_RESOURCES;
>    }
> +
>    StrCatS (ResourceUri, MAX_URI_LENGTH, Private->RedfishVersion);
>    StrCatS (ResourceUri, MAX_URI_LENGTH, InformationExchange-
> >SendInformation.FullUri);
> 
> @@ -681,10 +728,9 @@ RedfishExternalResourceResourceFeatureCallback
> (  **/  VOID  EFIAPI -EdkIIRedfishFeatureProtocolIsReady
> - (
> -  IN  EFI_EVENT                             Event,
> -  IN  VOID                                  *Context
> +EdkIIRedfishFeatureProtocolIsReady (
> +  IN  EFI_EVENT  Event,
> +  IN  VOID       *Context
>    )
>  {
>    EFI_STATUS                      Status;
> @@ -699,10 +745,10 @@ EdkIIRedfishFeatureProtocolIsReady
>    }
> 
>    Status = gBS->LocateProtocol (
> -                 &gEdkIIRedfishFeatureProtocolGuid,
> -                 NULL,
> -                 (VOID **)&FeatureProtocol
> -                 );
> +                  &gEdkIIRedfishFeatureProtocolGuid,
> +                  NULL,
> +                  (VOID **)&FeatureProtocol
> +                  );
>    if (EFI_ERROR (Status)) {
>      DEBUG ((DEBUG_ERROR, "%a, failed to locate
> gEdkIIRedfishFeatureProtocolGuid: %r\n", __FUNCTION__, Status));
>      gBS->CloseEvent (Event);
> @@ -744,8 +790,8 @@ RedfishResourceEntryPoint (
>    IN EFI_SYSTEM_TABLE  *SystemTable
>    )
>  {
> -  EFI_STATUS               Status;
> -  VOID                     *Registration;
> +  EFI_STATUS  Status;
> +  VOID        *Registration;
> 
>    if (mRedfishResourcePrivate != NULL) {
>      return EFI_ALREADY_STARTED;
> --
> 2.17.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-12  4:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20221209063413.31912-1-simowang@nvidia.com>
2022-12-09  6:39 ` [edk2-staging][PATCH] edk2-staging/RedfishClientPkg: Add Redfish.Settings support Simon Wang (SW-GPU)
2022-12-12  4:52   ` Chang, Abner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox