public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Chang, Abner" <abner.chang@amd.com>
To: Nickle Wang <nicklew@nvidia.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: Igor Kulchytskyy <igork@ami.com>, Nick Ramirez <nramirez@nvidia.com>
Subject: Re: [edk2-staging][PATCH 2/3] edk2-staging/RedfishClientPkg: Add Redfish Resource Addendum Library
Date: Mon, 12 Dec 2022 03:15:42 +0000	[thread overview]
Message-ID: <MN2PR12MB3966CC81BFF4A477E8F373C0EAE29@MN2PR12MB3966.namprd12.prod.outlook.com> (raw)
In-Reply-To: <20221207144100.354-1-nicklew@nvidia.com>

[AMD Official Use Only - General]



> -----Original Message-----
> From: Nickle Wang <nicklew@nvidia.com>
> Sent: Wednesday, December 7, 2022 10:41 PM
> To: devel@edk2.groups.io
> Cc: Chang, Abner <Abner.Chang@amd.com>; Igor Kulchytskyy
> <igork@ami.com>; Nick Ramirez <nramirez@nvidia.com>
> Subject: [edk2-staging][PATCH 2/3] edk2-staging/RedfishClientPkg: Add
> Redfish Resource Addendum Library
> 
> Caution: This message originated from an External Source. Use proper
> caution when opening attachments, clicking links, or responding.
> 
> 
> Implement RedfishAddendumLib to support Redfish Resource Addendum
> Protocol.
> Feature driver calls this library to get addendum data before providing data
> to Redfish service.
> 
> Signed-off-by: Nickle Wang <nicklew@nvidia.com>
> Cc: Abner Chang <abner.chang@amd.com>
> Cc: Igor Kulchytskyy <igork@ami.com>
> Cc: Nick Ramirez <nramirez@nvidia.com>
> ---
>  .../Include/Library/RedfishAddendumLib.h      |  63 +++++
>  .../RedfishAddendumLib/RedfishAddendumLib.c   | 258
> ++++++++++++++++++
>  .../RedfishAddendumLib/RedfishAddendumLib.inf |  40 +++
>  RedfishClientPkg/RedfishClientLibs.dsc.inc    |   2 +
>  4 files changed, 363 insertions(+)
>  create mode 100644
> RedfishClientPkg/Include/Library/RedfishAddendumLib.h
>  create mode 100644
> RedfishClientPkg/Library/RedfishAddendumLib/RedfishAddendumLib.c
>  create mode 100644
> RedfishClientPkg/Library/RedfishAddendumLib/RedfishAddendumLib.inf
> 
> diff --git a/RedfishClientPkg/Include/Library/RedfishAddendumLib.h
> b/RedfishClientPkg/Include/Library/RedfishAddendumLib.h
> new file mode 100644
> index 0000000000..4215257820
> --- /dev/null
> +++ b/RedfishClientPkg/Include/Library/RedfishAddendumLib.h
> @@ -0,0 +1,63 @@
> +/** @file
> +  This file defines the Redfish event library interface.
> +
> +  (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef REDFISH_ADDENDUM_LIB_H_
> +#define REDFISH_ADDENDUM_LIB_H_
> +
> +#include <Uefi.h>
> +#include <Library/JsonLib.h>
> +#include <Protocol/EdkIIRedfishResourceAddendumProtocol.h>
> +
> +/**
> +  Provising redfish resource with with addendum data in given schema.
> +
> +  @param[in]   Uri              Uri of input resource.
> +  @param[in]   Schema           Redfish schema string.
> +  @param[in]   Version          Schema version string.
> +  @param[in]   JsonText         Input resource in JSON format string.
> +  @param[out]  JsonWithAddendum The input resource with addendum
> value attached.
> +
> +  @retval EFI_SUCCESS              Addendum data is attached.
> +  @retval EFI_UNSUPPORTED          No addendum data is required in given
> schema.
> +  @retval Others                   Some error happened.
> +
> +**/
> +EFI_STATUS
> +RedfishGetAddendumData (
> +  IN     EFI_STRING  Uri,
> +  IN     CHAR8       *Schema,
> +  IN     CHAR8       *Version,
> +  IN     CHAR8       *JsonText,
> +  OUT    CHAR8       **JsonWithAddendum
> +  );
> +
> +/**
> +  Provising redfish OEM resource with given schema information.
> +
> +  @param[in]   Uri             Uri of input resource.
> +  @param[in]   Schema          Redfish schema string.
> +  @param[in]   Version         Schema version string.
> +  @param[in]   JsonText        Input resource in JSON format string.
> +  @param[out]  JsonWithOem     The input resource with OEM value
> attached.
> +
> +  @retval EFI_SUCCESS              OEM data is attached.
> +  @retval EFI_UNSUPPORTED          No OEM data is required in given schema.
> +  @retval Others                   Some error happened.
> +
> +**/
> +EFI_STATUS
> +RedfishGetOemData (
> +  IN  EFI_STRING  Uri,
> +  IN  CHAR8       *Schema,
> +  IN  CHAR8       *Version,
> +  IN  CHAR8       *JsonText,
> +  OUT CHAR8       **JsonWithOem
> +  );
> +
> +#endif
> diff --git
> a/RedfishClientPkg/Library/RedfishAddendumLib/RedfishAddendumLib.c
> b/RedfishClientPkg/Library/RedfishAddendumLib/RedfishAddendumLib.c
> new file mode 100644
> index 0000000000..4154d01e5a
> --- /dev/null
> +++
> b/RedfishClientPkg/Library/RedfishAddendumLib/RedfishAddendumLib.c
> @@ -0,0 +1,258 @@
> +/** @file
> +  Redfish event library to deliver Redfish specific event.
> +
> +  (C) Copyright 2022 Hewlett Packard Enterprise Development LP<BR>
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Uefi.h>
> +#include <RedfishBase.h>
> +
> +#include <Library/UefiLib.h>
> +#include <Library/BaseLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +#include <Library/MemoryAllocationLib.h> #include
> +<Library/RedfishAddendumLib.h>
> +
> +/**
> +
> +  Convert Unicode string to ASCII string. It's call responsibility to release
> returned buffer.
> +
> +  @param[in]  UnicodeStr      Unicode string to convert.
> +
> +  @retval     CHAR8 *         ASCII string returned.
> +  @retval     NULL            Errors occur.
> +
> +**/
> +CHAR8 *
> +UnicodeToAscii (
> +  IN EFI_STRING  UnicodeStr
> +  )
> +{
> +  CHAR8       *AsciiStr;
> +  UINTN       AsciiStrSize;
> +  EFI_STATUS  Status;
> +
> +  if (IS_EMPTY_STRING (UnicodeStr)) {
> +    return NULL;
> +  }
> +
> +  AsciiStrSize = StrLen (UnicodeStr) + 1;
> +  AsciiStr     = AllocatePool (AsciiStrSize);
> +  if (AsciiStr == NULL) {
> +    return NULL;
> +  }
> +
> +  Status = UnicodeStrToAsciiStrS (UnicodeStr, AsciiStr, AsciiStrSize);
> + if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "UnicodeStrToAsciiStrS failed: %r\n", Status));
> +    FreePool (AsciiStr);
> +    return NULL;
> +  }
> +
> +  return AsciiStr;
> +}
Please check if UnicodeStrToAsciiStrS(); works for you.

> +
> +/**
> +  Provising redfish resource with with addendum data in given schema.
> +
> +  @param[in]   Uri              Uri of input resource.
> +  @param[in]   Schema           Redfish schema string.
> +  @param[in]   Version          Schema version string.
> +  @param[in]   JsonText         Input resource in JSON format string.
> +  @param[out]  JsonWithAddendum The input resource with addendum
> value attached.
Please add "The return  value must be freed by the caller using FreePool()."

> +
> +  @retval EFI_SUCCESS              Addendum data is attached.
> +  @retval EFI_UNSUPPORTED          No addendum data is required in given
> schema.
> +  @retval Others                   Some error happened.
> +
> +**/
> +EFI_STATUS
> +RedfishGetAddendumData (
> +  IN     EFI_STRING  Uri,
> +  IN     CHAR8       *Schema,
> +  IN     CHAR8       *Version,
> +  IN     CHAR8       *JsonText,
> +  OUT    CHAR8       **JsonWithAddendum
> +  )
> +{
> +  REDFISH_RESOURCE_SCHEMA_INFO              SchemaInfo;
> +  EDKII_JSON_VALUE                          JsonValue;
> +  EFI_STATUS                                Status;
> +  EFI_HANDLE                                *HandleBuffer;
> +  UINTN                                     NumberOfHandles;
> +  UINTN                                     Index;
> +  EDKII_REDFISH_RESOURCE_ADDENDUM_PROTOCOL  *Protocol;
> +
> +  if (IS_EMPTY_STRING (Uri) || IS_EMPTY_STRING (Schema) ||
> IS_EMPTY_STRING (Version) || IS_EMPTY_STRING (JsonText) ||
> (JsonWithAddendum == NULL)) {
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  *JsonWithAddendum  = NULL;
> +  SchemaInfo.Uri     = UnicodeToAscii (Uri);
> +  SchemaInfo.Schema  = Schema;
> +  SchemaInfo.Version = Version;
> +  NumberOfHandles    = 0;
> +  HandleBuffer       = NULL;
> +
> +  JsonValue = JsonLoadString (JsonText, 0, NULL);  if ((JsonValue ==
> + NULL) || !JsonValueIsObject (JsonValue)) {
> +    return EFI_OUT_OF_RESOURCES;
> +  }
> +
> +  Status = gBS->LocateHandleBuffer (
> +                  ByProtocol,
> +                  &gEdkIIRedfishResourceAddendumProtocolGuid,
> +                  NULL,
> +                  &NumberOfHandles,
> +                  &HandleBuffer
> +                  );
> +  if (EFI_ERROR (Status)) {
> +    goto ON_RELEASE;
> +  }
> +
> +  for (Index = 0; Index < NumberOfHandles; Index++) {
> +    Status = gBS->HandleProtocol (
> +                    HandleBuffer[Index],
> +                    &gEdkIIRedfishResourceAddendumProtocolGuid,
> +                    (VOID **)&Protocol
> +                    );
> +    if (EFI_ERROR (Status)) {
> +      continue;
> +    }
> +
> +    Status = Protocol->ProvisioningCallback (Protocol, &SchemaInfo,
> JsonValue);
> +    if (!EFI_ERROR (Status)) {
> +      *JsonWithAddendum = JsonDumpString (JsonValue,
> EDKII_JSON_COMPACT);
> +      break;
> +    }
> +  }
> +
> +ON_RELEASE:
> +
> +  if (HandleBuffer != NULL) {
> +    FreePool (HandleBuffer);
> +  }
> +
> +  if (JsonValue != NULL) {
> +    JsonValueFree (JsonValue);
> +  }
> +
> +  if (SchemaInfo.Uri != NULL) {
> +    FreePool (SchemaInfo.Uri);
> +  }
> +
> +  return Status;
> +}
> +
> +/**
> +  Provising redfish OEM resource with given schema information.
> +
> +  @param[in]   Uri             Uri of input resource.
> +  @param[in]   Schema          Redfish schema string.
> +  @param[in]   Version         Schema version string.
> +  @param[in]   JsonText        Input resource in JSON format string.
> +  @param[out]  JsonWithOem     The input resource with OEM value
> attached.
> +
> +  @retval EFI_SUCCESS              OEM data is attached.
> +  @retval EFI_UNSUPPORTED          No OEM data is required in given schema.
> +  @retval Others                   Some error happened.
> +
> +**/
> +EFI_STATUS
> +RedfishGetOemData (
> +  IN  EFI_STRING  Uri,
> +  IN  CHAR8       *Schema,
> +  IN  CHAR8       *Version,
> +  IN  CHAR8       *JsonText,
> +  OUT CHAR8       **JsonWithOem
> +  )
> +{
> +  REDFISH_RESOURCE_SCHEMA_INFO              SchemaInfo;
> +  EDKII_JSON_VALUE                          JsonValue;
> +  EDKII_JSON_VALUE                          JsonValueWithOem;
The naming of JsonValueWithOem is a little bit confused. How about just naming it as JsonValueOem?  Which is a JSON new object inserted with OEM resource by OEM callback.

> +  EFI_STATUS                                Status;
> +  EFI_HANDLE                                *HandleBuffer;
> +  UINTN                                     NumberOfHandles;
> +  UINTN                                     Index;
> +  EDKII_REDFISH_RESOURCE_ADDENDUM_PROTOCOL  *Protocol;
> +
> +  if (IS_EMPTY_STRING (Uri) || IS_EMPTY_STRING (Schema) ||
> IS_EMPTY_STRING (Version) || IS_EMPTY_STRING (JsonText) ||
> (JsonWithOem == NULL)) {
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  *JsonWithOem       = NULL;
> +  SchemaInfo.Uri     = UnicodeToAscii (Uri);
> +  SchemaInfo.Schema  = Schema;
> +  SchemaInfo.Version = Version;
> +  JsonValue          = NULL;
> +  JsonValueWithOem   = NULL;
> +  NumberOfHandles    = 0;
> +  HandleBuffer       = NULL;
> +
> +  JsonValue = JsonLoadString (JsonText, 0, NULL);  if ((JsonValue ==
> + NULL) || !JsonValueIsObject (JsonValue)) {
> +    return EFI_OUT_OF_RESOURCES;
> +  }
> +
> +  JsonValueWithOem = JsonValueInitObject ();  if ((JsonValueWithOem ==
> + NULL) || !JsonValueIsObject (JsonValueWithOem)) {
> +    Status = EFI_OUT_OF_RESOURCES;
> +    goto ON_RELEASE;
> +  }
> +
> +  Status = gBS->LocateHandleBuffer (
> +                  ByProtocol,
> +                  &gEdkIIRedfishResourceAddendumProtocolGuid,
> +                  NULL,
> +                  &NumberOfHandles,
> +                  &HandleBuffer
> +                  );
> +  if (EFI_ERROR (Status)) {
> +    goto ON_RELEASE;
> +  }
> +
> +  for (Index = 0; Index < NumberOfHandles; Index++) {
> +    Status = gBS->HandleProtocol (
> +                    HandleBuffer[Index],
> +                    &gEdkIIRedfishResourceAddendumProtocolGuid,
> +                    (VOID **)&Protocol
> +                    );
> +    if (EFI_ERROR (Status)) {
> +      continue;
> +    }
> +
> +    Status = Protocol->OemCallback (Protocol, &SchemaInfo,
> JsonValueWithOem);
> +    if (!EFI_ERROR (Status)) {
> +      Status = JsonObjectSetValue (JsonValue, "Oem", JsonValueWithOem);
> +      if (!EFI_ERROR (Status)) {
> +        *JsonWithOem = JsonDumpString (JsonValue, EDKII_JSON_COMPACT);
> +      }
> +
> +      break;
> +    }
> +  }
> +
> +ON_RELEASE:
> +
> +  if (HandleBuffer != NULL) {
> +    FreePool (HandleBuffer);
> +  }
> +
> +  if (JsonValue != NULL) {
> +    JsonValueFree (JsonValue);
> +  }
> +
> +  if (JsonValueWithOem != NULL) {
> +    JsonValueFree (JsonValueWithOem);
> +  }
> +
> +  if (SchemaInfo.Uri != NULL) {
> +    FreePool (SchemaInfo.Uri);
> +  }
> +
> +  return Status;
> +}
> diff --git
> a/RedfishClientPkg/Library/RedfishAddendumLib/RedfishAddendumLib.inf
> b/RedfishClientPkg/Library/RedfishAddendumLib/RedfishAddendumLib.inf
> new file mode 100644
> index 0000000000..7b9ef6114f
> --- /dev/null
> +++
> b/RedfishClientPkg/Library/RedfishAddendumLib/RedfishAddendumLib.inf
> @@ -0,0 +1,40 @@
> +## @file
> +#
> +#  Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights
> reserved.
> +#
> +#  SPDX-License-Identifier: BSD-2-Clause-Patent # ##
> +
> +[Defines]
> +  INF_VERSION                    = 0x00010006
> +  BASE_NAME                      = RedfishAddendumLib
> +  FILE_GUID                      = 7B227D39-746D-4247-8291-27B0FA79A7AF
> +  MODULE_TYPE                    = DXE_DRIVER
> +  VERSION_STRING                 = 1.0
> +  LIBRARY_CLASS                  = RedfishAddendumLib| DXE_DRIVER
> UEFI_DRIVER
> +
> +#
> +#  VALID_ARCHITECTURES           = IA32 X64 EBC
> +#
> +
> +[Sources]
> +  RedfishAddendumLib.c
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +  RedfishPkg/RedfishPkg.dec
> +  RedfishClientPkg/RedfishClientPkg.dec
> +
> +[LibraryClasses]
> +  BaseLib
> +  DebugLib
> +  UefiBootServicesTableLib
> +  MemoryAllocationLib
> +  UefiLib
> +  JsonLib
> +
> +[Protocols]
> +  gEdkIIRedfishResourceAddendumProtocolGuid   ## CONSUMED ##
> +
> diff --git a/RedfishClientPkg/RedfishClientLibs.dsc.inc
> b/RedfishClientPkg/RedfishClientLibs.dsc.inc
> index fe0c4b0885..6ce50e1980 100644
> --- a/RedfishClientPkg/RedfishClientLibs.dsc.inc
> +++ b/RedfishClientPkg/RedfishClientLibs.dsc.inc
> @@ -6,6 +6,7 @@
>  # of EDKII network library classes.
>  #
>  # (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP<BR>
> +# Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights
> reserved.
>  #
>  #    SPDX-License-Identifier: BSD-2-Clause-Patent
>  #
> @@ -37,3 +38,4 @@
> 
> EdkIIRedfishResourceConfigLib|RedfishClientPkg/Library/EdkIIRedfishResou
> rceConfigLib/EdkIIRedfishResourceConfigLib.inf
> 
> RedfishEventLib|RedfishClientPkg/Library/RedfishEventLib/RedfishEventLib.i
> nf
> 
> RedfishVersionLib|RedfishClientPkg/Library/RedfishVersionLib/RedfishVersi
> onLib.inf
> +
> +
> RedfishAddendumLib|RedfishClientPkg/Library/RedfishAddendumLib/Redfi
Also add the library to [Components] section in RedfishClientPkg.dsc.

Abner

> sh
> + AddendumLib.inf
> --
> 2.38.1.windows.1

      reply	other threads:[~2022-12-12  3:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-07 14:41 [edk2-staging][PATCH 2/3] edk2-staging/RedfishClientPkg: Add Redfish Resource Addendum Library Nickle Wang
2022-12-12  3:15 ` Chang, Abner [this message]

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=MN2PR12MB3966CC81BFF4A477E8F373C0EAE29@MN2PR12MB3966.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