RedfishPkg/RedfishDebugLib: Introduce Redfish DEBUG macro

Introduce DEBUG_REDFISH macro for the debug message
of edk2 Redfish components.
DEBUG_REDFISH can be used in any edk2 Redfish component
with Redfish DebugCatagory as the first parameter.
Whether the debug message is output or not depends on
the platform setting of PcdRedfishDebugCatagory.

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>
Reviewed-by: Igor Kulchytskyy <igork@ami.com>
This commit is contained in:
Abner Chang 2024-03-18 10:32:44 +08:00 committed by mergify[bot]
parent 29114fc574
commit b0be42516e
4 changed files with 57 additions and 54 deletions

View File

@ -2,6 +2,7 @@
This file defines the Redfish debug library interface. This file defines the Redfish debug library interface.
Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
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
@ -11,28 +12,48 @@
#define REDFISH_DEBUG_LIB_H_ #define REDFISH_DEBUG_LIB_H_
#include <Uefi.h> #include <Uefi.h>
#include <Library/DebugLib.h>
#include <RedfishServiceData.h> #include <RedfishServiceData.h>
#include <Library/HiiUtilityLib.h> #include <Library/HiiUtilityLib.h>
#include <Library/JsonLib.h> #include <Library/JsonLib.h>
#include <Protocol/EdkIIRedfishPlatformConfig.h> #include <Protocol/EdkIIRedfishPlatformConfig.h>
// Used with MdePKg DEBUG macro.
#define DEBUG_REDFISH_NETWORK DEBUG_MANAGEABILITY ///< Debug error level for Redfish networking function #define DEBUG_REDFISH_NETWORK DEBUG_MANAGEABILITY ///< Debug error level for Redfish networking function
#define DEBUG_REDFISH_HOST_INTERFACE DEBUG_MANAGEABILITY ///< Debug error level for Redfish networking function #define DEBUG_REDFISH_HOST_INTERFACE DEBUG_MANAGEABILITY ///< Debug error level for Redfish Host INterface
#define DEBUG_REDFISH_PLATFORM_CONFIG DEBUG_MANAGEABILITY ///< Debug error level for Redfish Platform Configure Driver
//
// Definitions of Redfish debug capability in Redfish component scope, used with DEBUG_REDFISH macro
// For example, Redfish Platform Config Driver
// DEBUG_REDFISH(DEBUG_REDFISH_PLATFORM_CONFIG_DXE, ...)
//
#define DEBUG_REDFISH_COMPONENT_PLATFORM_CONFIG_DXE 0x00000001
#define DEBUG_REDFISH(DebugCategory, ...) \
do { \
if (!DebugPrintEnabled()) { \
break; \
} \
if (!DebugRedfishComponentEnabled (DebugCategory)) { \
break; \
} \
DEBUG ((DEBUG_MANAGEABILITY, ##__VA_ARGS__)); \
} while (FALSE)
/** /**
Debug print the value of StatementValue. Determine whether the Redfish debug category is enabled in
gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDebugCategory.
@param[in] ErrorLevel DEBUG macro error level. @param[in] DebugCategory Redfish debug category.
@param[in] StatementValue The statement value to print.
@retval EFI_SUCCESS StatementValue is printed. @retval TRUE This debug category is enabled.
@retval EFI_INVALID_PARAMETER StatementValue is NULL. @retval FALSE This debug category is disabled..
**/ **/
EFI_STATUS BOOLEAN
DumpHiiStatementValue ( DebugRedfishComponentEnabled (
IN UINTN ErrorLevel, IN UINT64 DebugCategory
IN HII_STATEMENT_VALUE *StatementValue
); );
/** /**

View File

@ -2,6 +2,7 @@
Redfish debug library to debug Redfish application. Redfish debug library to debug Redfish application.
Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
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,55 +26,23 @@
#define REDFISH_PRINT_BUFFER_BYTES_PER_ROW 16 #define REDFISH_PRINT_BUFFER_BYTES_PER_ROW 16
/** /**
Debug print the value of StatementValue. Determine whether the Redfish debug category is enabled in
gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDebugCategory.
@param[in] ErrorLevel DEBUG macro error level. @param[in] RedfishDebugCategory Redfish debug category.
@param[in] StatementValue The statement value to print.
@retval EFI_SUCCESS StatementValue is printed. @retval TRUE This debug category is enabled.
@retval EFI_INVALID_PARAMETER StatementValue is NULL. @retval FALSE This debug category is disabled..
**/ **/
EFI_STATUS BOOLEAN
DumpHiiStatementValue ( DebugRedfishComponentEnabled (
IN UINTN ErrorLevel, IN UINT64 RedfishDebugCategory
IN HII_STATEMENT_VALUE *StatementValue
) )
{ {
if (StatementValue == NULL) { UINT64 DebugCategory;
return EFI_INVALID_PARAMETER;
}
DEBUG ((ErrorLevel, "BufferValueType: 0x%x\n", StatementValue->BufferValueType)); DebugCategory = FixedPcdGet64 (PcdRedfishDebugCategory);
DEBUG ((ErrorLevel, "BufferLen: 0x%x\n", StatementValue->BufferLen)); return ((DebugCategory & RedfishDebugCategory) != 0);
DEBUG ((ErrorLevel, "Buffer: 0x%p\n", StatementValue->Buffer));
DEBUG ((ErrorLevel, "Type: 0x%p\n", StatementValue->Type));
switch (StatementValue->Type) {
case EFI_IFR_TYPE_NUM_SIZE_8:
DEBUG ((ErrorLevel, "Value: 0x%x\n", StatementValue->Value.u8));
break;
case EFI_IFR_TYPE_NUM_SIZE_16:
DEBUG ((ErrorLevel, "Value: 0x%x\n", StatementValue->Value.u16));
break;
case EFI_IFR_TYPE_NUM_SIZE_32:
DEBUG ((ErrorLevel, "Value: 0x%x\n", StatementValue->Value.u32));
break;
case EFI_IFR_TYPE_NUM_SIZE_64:
DEBUG ((ErrorLevel, "Value: 0x%lx\n", StatementValue->Value.u64));
break;
case EFI_IFR_TYPE_BOOLEAN:
DEBUG ((ErrorLevel, "Value: %a\n", (StatementValue->Value.b ? "true" : "false")));
break;
case EFI_IFR_TYPE_STRING:
DEBUG ((ErrorLevel, "Value: 0x%x\n", StatementValue->Value.string));
break;
case EFI_IFR_TYPE_TIME:
case EFI_IFR_TYPE_DATE:
default:
break;
}
return EFI_SUCCESS;
} }
/** /**

View File

@ -2,6 +2,7 @@
# INF file for Redfish debug library. # INF file for Redfish debug library.
# #
# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# 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
# #
@ -35,5 +36,8 @@
RedfishHttpLib RedfishHttpLib
UefiLib UefiLib
[FixedPcd]
gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDebugCategory
[Depex] [Depex]
TRUE TRUE

View File

@ -5,6 +5,7 @@
# (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR> # (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
# Copyright (c) 2023, American Megatrends International LLC. # Copyright (c) 2023, American Megatrends International LLC.
# Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# 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
## ##
@ -184,3 +185,11 @@
gEfiRedfishPkgTokenSpaceGuid.PcdHttpRetryWaitInSecond|1|UINT16|0x00001010 gEfiRedfishPkgTokenSpaceGuid.PcdHttpRetryWaitInSecond|1|UINT16|0x00001010
## This is used to disable Redfish HTTP cache function and every request will be sent to Redfish service. ## This is used to disable Redfish HTTP cache function and every request will be sent to Redfish service.
gEfiRedfishPkgTokenSpaceGuid.PcdHttpCacheDisabled|FALSE|BOOLEAN|0x00001011 gEfiRedfishPkgTokenSpaceGuid.PcdHttpCacheDisabled|FALSE|BOOLEAN|0x00001011
#
# Redfish debug catagories
# To enable the debug message for the entire edk2 Redfish implementation, below PCDs must be set.
# DEBUG_MANAGEABILITY must be set PcdDebugPrintErrorLevel.
#
# 0x0000000000000001 RedfishPlatformConfigDxe driver debug enabled.
#
gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDebugCategory|0|UINT64|0x00001012