RedfishPkg/RestJsonStructureDxe: Refine REST JSON C Structure DXE driver

BZ #: 4711
- Add mode debug messages.
- Remove the references of "Redfish" from this driver.
  As REST JSON C Structure was not designed for Redfish only.
  Any RESTful applications can register the converter and
  provide JSON-C structure conversions through
  EFI_REST_JSON_STRUCTURE_PROTOCOL. Therefore this driver
  shouldn't have a dependency on Redfish package and the
  references of "Redfish" terminology.
- Fix the missing parameter of DEBUG macros used in this
  driver.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Reviewed-by: Nickle Wang <nicklew@nvidia.com>
This commit is contained in:
Abner Chang 2024-02-26 10:28:59 +08:00 committed by mergify[bot]
parent 33c81c25bb
commit 74b5309da9
3 changed files with 96 additions and 6 deletions

View File

@ -4,12 +4,14 @@
Protocol. Protocol.
(C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR> (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
#include <Uefi.h> #include <Uefi.h>
#include <Library/DebugLib.h>
#include <Protocol/RestJsonStructure.h> #include <Protocol/RestJsonStructure.h>
#include "RestJsonStructureInternal.h" #include "RestJsonStructureInternal.h"
@ -72,6 +74,8 @@ RestJsonStructureRegister (
} }
} }
DEBUG ((DEBUG_MANAGEABILITY, "%a: %d REST JSON-C interpreter(s) to register for the name spaces.\n", __func__, NumberOfNS));
Instance = Instance =
(REST_JSON_STRUCTURE_INSTANCE *)AllocateZeroPool (sizeof (REST_JSON_STRUCTURE_INSTANCE) + NumberOfNS * sizeof (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER)); (REST_JSON_STRUCTURE_INSTANCE *)AllocateZeroPool (sizeof (REST_JSON_STRUCTURE_INSTANCE) + NumberOfNS * sizeof (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER));
if (Instance == NULL) { if (Instance == NULL) {
@ -88,6 +92,10 @@ RestJsonStructureRegister (
ThisSupportedInterp = JsonStructureSupported; ThisSupportedInterp = JsonStructureSupported;
for (Index = 0; Index < NumberOfNS; Index++) { for (Index = 0; Index < NumberOfNS; Index++) {
CopyMem ((VOID *)CloneSupportedInterpId, (VOID *)&ThisSupportedInterp->RestResourceInterp, sizeof (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER)); CopyMem ((VOID *)CloneSupportedInterpId, (VOID *)&ThisSupportedInterp->RestResourceInterp, sizeof (EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER));
DEBUG ((DEBUG_MANAGEABILITY, " Resource type : %a\n", ThisSupportedInterp->RestResourceInterp.NameSpace.ResourceTypeName));
DEBUG ((DEBUG_MANAGEABILITY, " Major version : %a\n", ThisSupportedInterp->RestResourceInterp.NameSpace.MajorVersion));
DEBUG ((DEBUG_MANAGEABILITY, " Minor version : %a\n", ThisSupportedInterp->RestResourceInterp.NameSpace.MinorVersion));
DEBUG ((DEBUG_MANAGEABILITY, " Errata version: %a\n\n", ThisSupportedInterp->RestResourceInterp.NameSpace.ErrataVersion));
ThisSupportedInterp = (EFI_REST_JSON_STRUCTURE_SUPPORTED *)ThisSupportedInterp->NextSupportedRsrcInterp.ForwardLink; ThisSupportedInterp = (EFI_REST_JSON_STRUCTURE_SUPPORTED *)ThisSupportedInterp->NextSupportedRsrcInterp.ForwardLink;
CloneSupportedInterpId++; CloneSupportedInterpId++;
} }
@ -125,6 +133,8 @@ InterpreterInstanceToStruct (
EFI_STATUS Status; EFI_STATUS Status;
EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId; EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId;
DEBUG ((DEBUG_MANAGEABILITY, "%a: Entry\n", __func__));
if ((This == NULL) || if ((This == NULL) ||
(InterpreterInstance == NULL) || (InterpreterInstance == NULL) ||
(ResourceRaw == NULL) || (ResourceRaw == NULL) ||
@ -146,9 +156,23 @@ InterpreterInstanceToStruct (
ResourceRaw, ResourceRaw,
RestJSonHeader RestJSonHeader
); );
if (EFI_ERROR (Status)) {
if (Status == EFI_UNSUPPORTED) {
DEBUG ((
DEBUG_MANAGEABILITY,
"%a %a.%a.%a REST JSON to C structure interpreter has no capability to interpret the resource.\n",
InterpreterInstance->SupportedRsrcIndentifier->NameSpace.ResourceTypeName,
InterpreterInstance->SupportedRsrcIndentifier->NameSpace.MajorVersion,
InterpreterInstance->SupportedRsrcIndentifier->NameSpace.MinorVersion,
InterpreterInstance->SupportedRsrcIndentifier->NameSpace.ErrataVersion
));
} else {
DEBUG ((DEBUG_MANAGEABILITY, "REST JsonToStructure returns failure - %r\n", Status));
}
}
} else { } else {
// //
// Check if the namesapce and version is supported by this interpreter. // Check if the namespace and version is supported by this interpreter.
// //
ThisSupportedRsrcTypeId = InterpreterInstance->SupportedRsrcIndentifier; ThisSupportedRsrcTypeId = InterpreterInstance->SupportedRsrcIndentifier;
for (Index = 0; Index < InterpreterInstance->NumberOfNameSpaceToConvert; Index++) { for (Index = 0; Index < InterpreterInstance->NumberOfNameSpaceToConvert; Index++) {
@ -171,6 +195,11 @@ InterpreterInstanceToStruct (
ResourceRaw, ResourceRaw,
RestJSonHeader RestJSonHeader
); );
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_MANAGEABILITY, "Don't check version of this resource type identifier JsonToStructure returns %r\n", Status));
DEBUG ((DEBUG_MANAGEABILITY, " Supported ResourceTypeName = %a\n", ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName));
}
break; break;
} else { } else {
// //
@ -195,6 +224,14 @@ InterpreterInstanceToStruct (
ResourceRaw, ResourceRaw,
RestJSonHeader RestJSonHeader
); );
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_MANAGEABILITY, "Check version of this resource type identifier JsonToStructure returns %r\n", Status));
DEBUG ((DEBUG_MANAGEABILITY, " Supported ResourceTypeName = %a\n", ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName));
DEBUG ((DEBUG_MANAGEABILITY, " Supported MajorVersion = %a\n", ThisSupportedRsrcTypeId->NameSpace.MajorVersion));
DEBUG ((DEBUG_MANAGEABILITY, " Supported MinorVersion = %a\n", ThisSupportedRsrcTypeId->NameSpace.MinorVersion));
DEBUG ((DEBUG_MANAGEABILITY, " Supported ErrataVersion = %a\n", ThisSupportedRsrcTypeId->NameSpace.ErrataVersion));
}
break; break;
} }
} }
@ -232,6 +269,8 @@ InterpreterEfiStructToInstance (
EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId; EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *ThisSupportedRsrcTypeId;
EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier; EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier;
DEBUG ((DEBUG_MANAGEABILITY, "%a: Entry\n", __func__));
if ((This == NULL) || if ((This == NULL) ||
(InterpreterInstance == NULL) || (InterpreterInstance == NULL) ||
(RestJSonHeader == NULL) || (RestJSonHeader == NULL) ||
@ -284,6 +323,14 @@ InterpreterEfiStructToInstance (
RestJSonHeader, RestJSonHeader,
ResourceRaw ResourceRaw
); );
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_MANAGEABILITY, "StructureToJson returns %r\n", Status));
DEBUG ((DEBUG_MANAGEABILITY, " Supported ResourceTypeName = %a\n", ThisSupportedRsrcTypeId->NameSpace.ResourceTypeName));
DEBUG ((DEBUG_MANAGEABILITY, " Supported MajorVersion = %a\n", ThisSupportedRsrcTypeId->NameSpace.MajorVersion));
DEBUG ((DEBUG_MANAGEABILITY, " Supported MinorVersion = %a\n", ThisSupportedRsrcTypeId->NameSpace.MinorVersion));
DEBUG ((DEBUG_MANAGEABILITY, " Supported ErrataVersion = %a\n", ThisSupportedRsrcTypeId->NameSpace.ErrataVersion));
}
break; break;
} }
} }
@ -416,6 +463,35 @@ RestJsonStructureToStruct (
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
if (RsrcTypeIdentifier != NULL) {
DEBUG ((DEBUG_MANAGEABILITY, "%a: Looking for the REST JSON to C Structure converter:\n", __func__));
if (RsrcTypeIdentifier->NameSpace.ResourceTypeName != NULL) {
DEBUG ((DEBUG_MANAGEABILITY, " ResourceType: %a\n", RsrcTypeIdentifier->NameSpace.ResourceTypeName));
} else {
DEBUG ((DEBUG_MANAGEABILITY, " ResourceType: NULL"));
}
if (RsrcTypeIdentifier->NameSpace.MajorVersion != NULL) {
DEBUG ((DEBUG_MANAGEABILITY, " MajorVersion: %a\n", RsrcTypeIdentifier->NameSpace.MajorVersion));
} else {
DEBUG ((DEBUG_MANAGEABILITY, " MajorVersion: NULL"));
}
if (RsrcTypeIdentifier->NameSpace.MinorVersion != NULL) {
DEBUG ((DEBUG_MANAGEABILITY, " MinorVersion: %a\n", RsrcTypeIdentifier->NameSpace.MinorVersion));
} else {
DEBUG ((DEBUG_MANAGEABILITY, " MinorVersion: NULL"));
}
if (RsrcTypeIdentifier->NameSpace.ErrataVersion != NULL) {
DEBUG ((DEBUG_MANAGEABILITY, " ErrataVersion: %a\n", RsrcTypeIdentifier->NameSpace.ErrataVersion));
} else {
DEBUG ((DEBUG_MANAGEABILITY, " ErrataVersion: NULL"));
}
} else {
DEBUG ((DEBUG_MANAGEABILITY, "%a: RsrcTypeIdentifier is given as NULL, go through all of the REST JSON to C structure interpreters.\n", __func__));
}
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList); Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);
while (TRUE) { while (TRUE) {
@ -427,10 +503,12 @@ RestJsonStructureToStruct (
JsonStructure JsonStructure
); );
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
DEBUG ((DEBUG_MANAGEABILITY, "%a: REST JSON to C structure is interpreted successfully.\n", __func__));
break; break;
} }
if (IsNodeAtEnd (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) { if (IsNodeAtEnd (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
DEBUG ((DEBUG_ERROR, "%a: No REST JSON to C structure interpreter found.\n", __func__));
Status = EFI_UNSUPPORTED; Status = EFI_UNSUPPORTED;
break; break;
} }
@ -483,6 +561,7 @@ RestJsonStructureDestroyStruct (
} }
if (IsNodeAtEnd (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) { if (IsNodeAtEnd (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
DEBUG ((DEBUG_ERROR, "%a: No REST JSON to C structure interpreter found.\n", __func__));
Status = EFI_UNSUPPORTED; Status = EFI_UNSUPPORTED;
break; break;
} }
@ -512,8 +591,9 @@ RestJsonStructureToJson (
OUT CHAR8 **ResourceRaw OUT CHAR8 **ResourceRaw
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
REST_JSON_STRUCTURE_INSTANCE *Instance; REST_JSON_STRUCTURE_INSTANCE *Instance;
EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *RsrcTypeIdentifier;
if ((This == NULL) || (RestJSonHeader == NULL) || (ResourceRaw == NULL)) { if ((This == NULL) || (RestJSonHeader == NULL) || (ResourceRaw == NULL)) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
@ -523,6 +603,13 @@ RestJsonStructureToJson (
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
RsrcTypeIdentifier = &RestJSonHeader->JsonRsrcIdentifier;
DEBUG ((DEBUG_MANAGEABILITY, "Looking for the REST C Structure to JSON resource converter:\n"));
DEBUG ((DEBUG_MANAGEABILITY, " ResourceType : %a\n", RsrcTypeIdentifier->NameSpace.ResourceTypeName));
DEBUG ((DEBUG_MANAGEABILITY, " MajorVersion : %a\n", RsrcTypeIdentifier->NameSpace.MajorVersion));
DEBUG ((DEBUG_MANAGEABILITY, " MinorVersion : %a\n", RsrcTypeIdentifier->NameSpace.MinorVersion));
DEBUG ((DEBUG_MANAGEABILITY, " ErrataVersion: %a\n", RsrcTypeIdentifier->NameSpace.ErrataVersion));
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList); Instance = (REST_JSON_STRUCTURE_INSTANCE *)GetFirstNode (&mRestJsonStructureList);
while (TRUE) { while (TRUE) {
@ -537,6 +624,7 @@ RestJsonStructureToJson (
} }
if (IsNodeAtEnd (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) { if (IsNodeAtEnd (&mRestJsonStructureList, &Instance->NextRestJsonStructureInstance)) {
DEBUG ((DEBUG_ERROR, "%a: No REST C structure to JSON interpreter found.\n", __func__));
Status = EFI_UNSUPPORTED; Status = EFI_UNSUPPORTED;
break; break;
} }
@ -587,7 +675,7 @@ RestJsonStructureEntryPoint (
} }
/** /**
This is the unload handle for Redfish discover module. This is the unload handle for REST JSON to C structure module.
Disconnect the driver specified by ImageHandle from all the devices in the handle database. Disconnect the driver specified by ImageHandle from all the devices in the handle database.
Uninstall all the protocols installed in the driver entry point. Uninstall all the protocols installed in the driver entry point.

View File

@ -2,6 +2,7 @@
# Implementation of EFI REST JSON Structure Protocol. # Implementation of EFI REST JSON Structure Protocol.
# #
# (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR> # (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent # SPDX-License-Identifier: BSD-2-Clause-Patent
## ##
@ -17,7 +18,6 @@
[Packages] [Packages]
MdePkg/MdePkg.dec MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec MdeModulePkg/MdeModulePkg.dec
RedfishPkg/RedfishPkg.dec
[Sources] [Sources]
RestJsonStructureDxe.c RestJsonStructureDxe.c
@ -26,6 +26,7 @@
[LibraryClasses] [LibraryClasses]
BaseLib BaseLib
BaseMemoryLib BaseMemoryLib
DebugLib
MemoryAllocationLib MemoryAllocationLib
UefiBootServicesTableLib UefiBootServicesTableLib
UefiDriverEntryPoint UefiDriverEntryPoint

View File

@ -3,6 +3,7 @@
Protocol. Protocol.
(C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR> (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>
Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
@ -25,7 +26,7 @@
typedef struct _REST_JSON_STRUCTURE_INSTANCE { typedef struct _REST_JSON_STRUCTURE_INSTANCE {
LIST_ENTRY NextRestJsonStructureInstance; ///< Next convertor instance LIST_ENTRY NextRestJsonStructureInstance; ///< Next convertor instance
UINTN NumberOfNameSpaceToConvert; ///< Number of resource type this convertor supports. UINTN NumberOfNameSpaceToConvert; ///< Number of resource type this convertor supports.
EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *SupportedRsrcIndentifier; ///< The resource type linklist EFI_REST_JSON_RESOURCE_TYPE_IDENTIFIER *SupportedRsrcIndentifier; ///< The supported resource type array.
EFI_REST_JSON_STRUCTURE_TO_STRUCTURE JsonToStructure; ///< JSON to C structure function EFI_REST_JSON_STRUCTURE_TO_STRUCTURE JsonToStructure; ///< JSON to C structure function
EFI_REST_JSON_STRUCTURE_TO_JSON StructureToJson; ///< C structure to JSON function EFI_REST_JSON_STRUCTURE_TO_JSON StructureToJson; ///< C structure to JSON function
EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE DestroyStructure; ///< Destory C struture function. EFI_REST_JSON_STRUCTURE_DESTORY_STRUCTURE DestroyStructure; ///< Destory C struture function.