public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Simon Wang (SW-GPU)" <simowang@nvidia.com>
To: "devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: Nickle Wang <nicklew@nvidia.com>,
	Nick Ramirez <nramirez@nvidia.com>,
	"abner.chang@amd.com" <Abner.Chang@amd.com>,
	Igor Miroshnichenko <igormir@nvidia.com>
Subject: [edk2-staging][PATCH] edk2-staging/RedfishClientPkg: Add Redfish.Settings support
Date: Fri, 9 Dec 2022 06:39:48 +0000	[thread overview]
Message-ID: <DS0PR12MB65836331E1890CCE02176B0AAF1C9@DS0PR12MB6583.namprd12.prod.outlook.com> (raw)
In-Reply-To: <20221209063413.31912-1-simowang@nvidia.com>

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


       reply	other threads:[~2022-12-09  6:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20221209063413.31912-1-simowang@nvidia.com>
2022-12-09  6:39 ` Simon Wang (SW-GPU) [this message]
2022-12-12  4:52   ` [edk2-staging][PATCH] edk2-staging/RedfishClientPkg: Add Redfish.Settings support Chang, Abner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DS0PR12MB65836331E1890CCE02176B0AAF1C9@DS0PR12MB6583.namprd12.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox