pax_global_header 0000666 0000000 0000000 00000000064 14165347476 0014533 g ustar 00root root 0000000 0000000 52 comment=c66b702fdd730086ac4577b88baf36b5afa7c910
ipmctl-03.00.00.0423/ 0000775 0000000 0000000 00000000000 14165347476 0013632 5 ustar 00root root 0000000 0000000 ipmctl-03.00.00.0423/.gitattributes 0000664 0000000 0000000 00000000417 14165347476 0016527 0 ustar 00root root 0000000 0000000 *.uni diff=word
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
src/os/** text eol=lf
Dcpmpkg/** text eol=lf
CMakeLists.txt text eol=lf
CMake/** text eol=lf
install/linux/logrotate/** text eol=lf
install/linux/debian/** text eol=lf
ipmctl-03.00.00.0423/CMake/ 0000775 0000000 0000000 00000000000 14165347476 0014612 5 ustar 00root root 0000000 0000000 ipmctl-03.00.00.0423/CMake/Find/ 0000775 0000000 0000000 00000000000 14165347476 0015472 5 ustar 00root root 0000000 0000000 ipmctl-03.00.00.0423/CMake/Find/Findasciidoc.cmake 0000664 0000000 0000000 00000000602 14165347476 0021051 0 ustar 00root root 0000000 0000000 # Copyright (c) 2018, Intel Corporation.
# SPDX-License-Identifier: BSD-3-Clause
# Try to find asciidoc
# Once done this will define
# ASCIIDOC_FOUND - asciidoc found
find_program(ASCIIDOC_BINARY NAMES asciidoc
HINTS ${ASCIIDOC_BINARY_PATH})
find_package_handle_standard_args(asciidoc DEFAULT_MSG
ASCIIDOC_BINARY)
mark_as_advanced(ASCIIDOC_BINARY) ipmctl-03.00.00.0423/CMake/Find/Findasciidoctor.cmake 0000664 0000000 0000000 00000001611 14165347476 0021577 0 ustar 00root root 0000000 0000000 # Copyright (c) 2018, Intel Corporation.
# SPDX-License-Identifier: BSD-3-Clause
# Try to find asciidoctor
# Once done this will define
# ASCIIDOCTOR_FOUND - asciidoctor found
find_program(ASCIIDOCTOR_BINARY NAMES asciidoctor
HINTS ${ASCIIDOCTOR_BINARY_PATH})
# Get the version of asciidoctor
execute_process( COMMAND ${ASCIIDOCTOR_BINARY} --version OUTPUT_VARIABLE stdout_str )
separate_arguments(stdout_str)
if (NOT "" STREQUAL "${stdout_str}")
# Only parse stdout_str if found
# Example output: "Asciidoctor 2.0.10 [https://asciidoctor.org]"
# The argument at position 1 is the version
list(GET stdout_str 1 ASCIIDOCTOR_VERSION)
endif()
find_package_handle_standard_args(asciidoctor
REQUIRED_VARS ASCIIDOCTOR_BINARY
VERSION_VAR ASCIIDOCTOR_VERSION
)
mark_as_advanced(ASCIIDOCTOR_BINARY) ipmctl-03.00.00.0423/CMake/GTest.txt.in 0000664 0000000 0000000 00000000654 14165347476 0017013 0 ustar 00root root 0000000 0000000 cmake_minimum_required(VERSION 2.8.2)
project(googletest-download NONE)
include(ExternalProject)
ExternalProject_Add(googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.8.0
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)
ipmctl-03.00.00.0423/CMake/unit_test.cmake 0000664 0000000 0000000 00000003321 14165347476 0017631 0 ustar 00root root 0000000 0000000 SET(CMAKE_SKIP_BUILD_RPATH FALSE)
# --------------------------------------------------------------------------------------------------
# Google Test and Google Mock
# --------------------------------------------------------------------------------------------------
# Download and unpack googletest at configure time
configure_file(CMake/GTest.txt.in ${CMAKE_BINARY_DIR}/googletest-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download
)
if(result)
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} --build .
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/googletest-download
)
if(result)
message(FATAL_ERROR "Build step for googletest failed: ${result}")
endif()
# Prevent overriding the parent project's compiler/linker
# settings on Windows
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
# Add googletest directly to our build. This defines
# the gtest and gtest_main targets.
add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src
${CMAKE_BINARY_DIR}/googletest-build
EXCLUDE_FROM_ALL
)
# --------------------------------------------------------------------------------------------------
# libipmctl tests
# --------------------------------------------------------------------------------------------------
file(GLOB CORE_TEST_SRC
src/os/nvm_api/unittest/*
)
message(TESTS: ${CORE_TEST_SRC})
add_executable(ipmctl_test ${CORE_TEST_SRC})
target_link_libraries(ipmctl_test
gtest
gtest_main
gmock
ipmctl
)
include_directories(ipmctl_test SYSTEM PUBLIC
src/os/nvm_api
)
ipmctl-03.00.00.0423/CMakeLists.txt 0000664 0000000 0000000 00000066276 14165347476 0016413 0 ustar 00root root 0000000 0000000 # Copyright (c) 2018, Intel Corporation.
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 2.8.12)
message("cmake version: " ${CMAKE_VERSION})
project(ipmctl)
# Enable tests that may be contained in the below subdirectories
enable_testing()
set(CMAKE_VERBOSE_MAKEFILE on)
get_filename_component(ROOT ./ ABSOLUTE)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake/Find")
set(LIBIPMCTL_VERSION_MAJOR 5)
set(LIBIPMCTL_VERSION_MINOR 2)
set(LIBIPMCTL_VERSION_PATCH 0)
set(LIBIPMCTL_VERSION_STRING ${LIBIPMCTL_VERSION_MAJOR}.${LIBIPMCTL_VERSION_MINOR}.${LIBIPMCTL_VERSION_PATCH})
set(IPMCTL_VERSION_MAJOR 03)
set(IPMCTL_VERSION_MINOR 01)
set(IPMCTL_VERSION_PATCH 00)
set(IPMCTL_SPEC_VERSION_MAJOR 3)
set(IPMCTL_SPEC_VERSION_MINOR 03)
set(IPMCTL_DRAFT "")
set(IPMCTL_SPEC_VERSION_STRING ${IPMCTL_SPEC_VERSION_MAJOR}.${IPMCTL_SPEC_VERSION_MINOR}${IPMCTL_DRAFT})
if(BUILDNUM)
set(IPMCTL_VERSION_STRING ${BUILDNUM})
else()
find_package(Git)
if(GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tag --dirty
OUTPUT_VARIABLE IPMCTL_VERSION_STRING
RESULT_VARIABLE GIT_RETURN_CODE
)
# strip leading string in git tag
string(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+)" IPMCTL_VERSION_STRING "${IPMCTL_VERSION_STRING}")
# strip ending newline
string(REGEX REPLACE "\n" "" IPMCTL_VERSION_STRING "${IPMCTL_VERSION_STRING}")
endif()
if(NOT GIT_FOUND OR ${GIT_RETURN_CODE})
set(IPMCTL_VERSION_STRING ${IPMCTL_VERSION_MAJOR}.${IPMCTL_VERSION_MINOR}.${IPMCTL_VERSION_PATCH}.0423)
endif()
endif()
message(VERSION: ${IPMCTL_VERSION_STRING})
if(RELEASE OR CMAKE_BUILD_TYPE STREQUAL "Release")
set(BUILD_TYPE release)
set(CMAKE_BUILD_TYPE Release)
SET(CMAKE_SKIP_BUILD_RPATH TRUE)
else()
set(BUILD_TYPE debug)
set(CMAKE_BUILD_TYPE Debug)
add_definitions(
-DDEBUG_BUILD
)
endif()
message(CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE})
if(BUILD_STATIC)
set(LIB_TYPE STATIC)
else()
set(LIB_TYPE SHARED)
endif()
find_package(PythonInterp REQUIRED)
if(ESX_BUILD)
set(OS_TYPE esx)
set(FILE_PREFIX esx)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "/opt/intel/bin")
else()
## Common packages between Windows and Linux
# Optional packages for documentation
## Unfortunately it sounds like we can't do conditional inclusion
## based on the target selected.
find_package(a2x)
find_package(asciidoctor)
find_package(asciidoc)
if(UNIX)
set(LNX_BUILD 1)
set(OS_TYPE linux)
set(FILE_PREFIX lnx)
find_package(PkgConfig REQUIRED)
pkg_check_modules(NDCTL REQUIRED libndctl>=58.2)
pkg_check_modules(SYSTEMD systemd)
find_package(Threads REQUIRED)
elseif(MSVC)
set(WIN_BUILD 1)
set(OS_TYPE win)
set(FILE_PREFIX win)
endif()
endif()
message(BUILD_TYPE: ${CMAKE_BUILD_TYPE})
message(OS_TYPE: ${OS_TYPE})
message(LIB_TYPE: ${LIB_TYPE})
message(COMPILER: ${CMAKE_C_COMPILER})
message(SYSROOT: ${MY_CMAKE_SYSROOT})
message(TOOLCHAIN: ${CMAKE_TOOLCHAIN_FILE})
set(OUTPUT_DIR ${ROOT}/output/${BUILD_TYPE})
file(MAKE_DIRECTORY ${OUTPUT_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ROOT}/output/${BUILD_TYPE})
set(CMAKE_BINARY_DIR ${OUTPUT_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
if(INTERNAL_MFG)
include(CMake/mfg.cmake)
endif()
#----------------------------------------------------------------------------------------------------
# Project wide defines and flags
#----------------------------------------------------------------------------------------------------
add_definitions(
-DOS_BUILD
-DPCD_CACHE_ENABLED
-D__VERSION_NUMBER__=${IPMCTL_VERSION_STRING}
-DPLAYBACK_RECORD_SUPPORTED
)
# Promote warnings to errors only for release builds
if(MSVC)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /O2 /WX")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /WX")
set(CMAKE_C_FLAGS_DEBUG_ "${CMAKE_C_FLAGS_DEBUG} /Od")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od")
else()
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2 -fno-strict-aliasing -D_FORTIFY_SOURCE=2")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fno-strict-aliasing -D_FORTIFY_SOURCE=2")
if(LNX_BUILD)
#A few warnings yet to resolve under esx
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Werror")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Werror")
endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -ggdb")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -ggdb")
endif()
if(UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_MSABI_VA_FUNCS -std=c99 -Wformat -Wformat-security -D_XOPEN_SOURCE=500 -Wall -Wfatal-errors -MMD -fPIC -fno-strict-aliasing")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wformat -Wformat-security -D_XOPEN_SOURCE=500 -Drestrict=__restrict__ -Wall -Wfatal-errors -MMD -fPIC -fno-strict-aliasing")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z noexecstack -z relro -z now -pie")
elseif(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /GS /DynamicBase /sdl")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GS /DynamicBase /sdl")
set(CMAKE_SHARED_LINKER_FLAGS "/NXCompat")
endif()
if(LNX_BUILD)
if("${CMAKE_INSTALL_DATAROOTDIR}" STREQUAL "/usr/share")
# Workaround for the RPM build cause the %{_datarootdir} is already prefixed
set(INI_INSTALL_FILEPATH "${CMAKE_INSTALL_DATAROOTDIR}")
else()
if("${CMAKE_INSTALL_PREFIX}" STREQUAL "/")
# In case the CMAKE_INSTALL_PREFIX equals "/" for
other than the SYSCONFDIR and LOCALSTATEDIR,
# the value of CMAKE_INSTALL_ is prefixed with usr/ if it is not user-specified as an absolute path.
set(CMAKE_INSTALL_PREFIX "/usr")
message("CMAKE_INSTALL_PREFIX value changed to: ${CMAKE_INSTALL_PREFIX}")
endif()
if(NOT DEFINED CMAKE_INSTALL_DATAROOTDIR)
set(CMAKE_INSTALL_DATAROOTDIR "share")
message("CMAKE_INSTALL_DATAROOTDIR not defined. Creating a new definition with value: ${CMAKE_INSTALL_DATAROOTDIR}")
endif()
set(INI_INSTALL_FILEPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}")
endif()
message("INI_INSTALL_FILEPATH definition create with value: ${INI_INSTALL_FILEPATH}")
add_definitions(
-D_GNU_SOURCE
-D__LINUX__
-DHAVE_C99
-DINI_INSTALL_FILEPATH="${INI_INSTALL_FILEPATH}/ipmctl/"
)
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.9)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong")
endif()
endif()
if(MSVC)
if(VCREDIST_STATIC)
# Force vcredist to be linked static
# Keep this after all other compiler flag setup
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
message("VCREDIST: STATIC")
else()
message("VCREDIST: SHARED")
endif()
endif()
#----------------------------------------------------------------------------------------------------
# OS driver interface library
#----------------------------------------------------------------------------------------------------
if(MSVC)
# setup resource file for file details
string(REGEX REPLACE "[.]" "," IPMCTL_VERSION_COMMA_STRING "${IPMCTL_VERSION_STRING}")
# exe
set (NAME_RC ${CMAKE_PROJECT_NAME})
set (NAME_RC_EXT "${NAME_RC}.exe")
set (VFT_TYPE "VFT_APP")
configure_file(src/os/win/ipmctl.rc.in src/os/win/ipmctl.rc @ONLY)
# lib
set (NAME_RC "lib${CMAKE_PROJECT_NAME}")
set (NAME_RC_EXT "${NAME_RC}.dll")
set (VFT_TYPE "VFT_DLL")
configure_file(src/os/win/ipmctl.rc.in src/os/win/libipmctl.rc @ONLY)
FILE(GLOB OS_INTERFACE_SOURCE_FILES
src/os/os_str.c
src/os/os_common.c
src/os/win/win_scm2_ioctl.c
src/os/win/win_scm2_passthrough.c
src/os/win/win_scm2_ioctl_passthrough.c
src/os/win/win_common.c
src/os/win/win_api.c
src/os/win/win_scm2_adapter.c
src/os/win/win_system.c
)
elseif(UNIX)
FILE(GLOB OS_INTERFACE_SOURCE_FILES
src/os/os_str.c
src/os/os_common.c
src/os/${OS_TYPE}/${FILE_PREFIX}_adapter_passthrough.c
src/os/${OS_TYPE}/${FILE_PREFIX}_acpi.c
src/os/${OS_TYPE}/${FILE_PREFIX}_common.c
src/os/${OS_TYPE}/${FILE_PREFIX}_api.c
src/os/${OS_TYPE}/${FILE_PREFIX}_adapter.c
src/os/${OS_TYPE}/${FILE_PREFIX}_system.c
)
endif()
add_library(ipmctl_os_interface STATIC ${OS_INTERFACE_SOURCE_FILES})
target_link_libraries(ipmctl_os_interface
${CMAKE_THREAD_LIBS_INIT}
)
target_include_directories(ipmctl_os_interface PUBLIC
src/os
src/os/${OS_TYPE}
DcpmPkg/common
DcpmPkg/cli
src/os/nvm_api
src/os/s_string
MdePkg/Include
MdePkg/Include/Uefi
src/os/efi_shim
)
if (MSVC)
string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+\\.[0-9]+" "\\1" sdk_version_major $ENV{WindowsSDKVersion})
string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" sdk_version_major2 $ENV{WindowsSDKVersion})
string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" sdk_version_minor $ENV{WindowsSDKVersion})
if (${sdk_version_major} GREATER 9 AND ${sdk_version_minor} GREATER 17650)
MESSAGE("Using Windows SDK 17650+")
else()
MESSAGE(FATAL_ERROR "Requires Windows SDK version 17650 or newer.")
endif()
endif()
#----------------------------------------------------------------------------------------------------
# libipmctl
#----------------------------------------------------------------------------------------------------
file(GLOB LIBIPMCTL_SOURCE_FILES
src/os/efi_shim/AutoGen.c
src/os/efi_shim/AutoGenIo.c
src/os/efi_shim/os_efi_api.c
src/os/efi_shim/os_efi_api_io.c
src/os/efi_shim/os_efi_preferences.c
src/os/efi_shim/os_efi_shell_parameters_protocol.c
src/os/efi_shim/os_efi_simple_file_protocol.c
src/os/efi_shim/os_efi_bs_protocol.c
src/os/ini/ini.c
src/os/eventlog/event.c
src/os/nvm_api/nvm_management.c
src/os/nvm_api/nvm_output_parsing.c
src/os/s_string/s_str.c
DcpmPkg/cli/NvmDimmCli.c
DcpmPkg/cli/CommandParser.c
DcpmPkg/cli/Common.c
DcpmPkg/cli/ShowAcpiCommand.c
DcpmPkg/cli/ShowSensorCommand.c
DcpmPkg/cli/ShowDimmsCommand.c
DcpmPkg/cli/ShowSocketsCommand.c
DcpmPkg/cli/ShowMemoryResourcesCommand.c
DcpmPkg/cli/ShowSystemCapabilitiesCommand.c
DcpmPkg/cli/ShowFirmwareCommand.c
DcpmPkg/cli/ShowPcdCommand.c
DcpmPkg/cli/DeletePcdCommand.c
DcpmPkg/cli/ShowRegionsCommand.c
DcpmPkg/cli/CreateGoalCommand.c
DcpmPkg/cli/ShowGoalCommand.c
DcpmPkg/cli/DeleteGoalCommand.c
DcpmPkg/cli/ShowErrorCommand.c
DcpmPkg/cli/ShowCelCommand.c
DcpmPkg/cli/DumpDebugCommand.c
DcpmPkg/cli/StartDiagnosticCommand.c
DcpmPkg/cli/ShowPreferencesCommand.c
DcpmPkg/cli/ShowTopologyCommand.c
DcpmPkg/cli/SetPreferencesCommand.c
DcpmPkg/cli/SetSensorCommand.c
DcpmPkg/cli/LoadGoalCommand.c
DcpmPkg/cli/DumpGoalCommand.c
DcpmPkg/cli/SetDimmCommand.c
DcpmPkg/cli/LoadCommand.c
DcpmPkg/cli/DeleteDimmCommand.c
src/os/cli_cmds/DumpSupportCommand.c
DcpmPkg/cli/ShowRegisterCommand.c
DcpmPkg/cli/StartFormatCommand.c
DcpmPkg/cli/ShowPerformanceCommand.c
DcpmPkg/cli/ShowHostServerCommand.c
DcpmPkg/cli/ShowCmdAccessPolicyCommand.c
DcpmPkg/cli/StartSessionCommand.c
DcpmPkg/cli/StopSessionCommand.c
DcpmPkg/cli/LoadSessionCommand.c
DcpmPkg/cli/ShowSessionCommand.c
DcpmPkg/cli/DumpSessionCommand.c
DcpmPkg/common/FwUtility.c
DcpmPkg/common/Utility.c
DcpmPkg/common/UtilityIo.c
DcpmPkg/common/NvmTables.c
DcpmPkg/common/ShowAcpi.c
DcpmPkg/common/NvmStatus.c
DcpmPkg/common/NvmHealth.c
DcpmPkg/common/LbaCommon.c
DcpmPkg/common/Convert.c
DcpmPkg/common/PcdCommon.c
DcpmPkg/common/OsCommon.c
DcpmPkg/common/DataSet.c
DcpmPkg/common/Printer.c
DcpmPkg/common/Strings.c
DcpmPkg/common/Nlog.c
DcpmPkg/common/ReadRunTimePreferences.c
DcpmPkg/driver/Protocol/Driver/NvmDimmConfig.c
DcpmPkg/driver/NvmDimmDriver.c
DcpmPkg/driver/Core/Dimm.c
DcpmPkg/driver/Core/Namespace.c
DcpmPkg/driver/Core/NvmSecurity.c
DcpmPkg/driver/Core/Region.c
DcpmPkg/driver/Core/Btt.c
DcpmPkg/driver/Core/Pfn.c
DcpmPkg/driver/Core/Diagnostics/ConfigDiagnostic.c
DcpmPkg/driver/Core/Diagnostics/CoreDiagnostics.c
DcpmPkg/driver/Core/Diagnostics/FwDiagnostic.c
DcpmPkg/driver/Core/Diagnostics/QuickDiagnostic.c
DcpmPkg/driver/Core/Diagnostics/SecurityDiagnostic.c
DcpmPkg/driver/Protocol/Device/NvmFirmwareManagement.c
DcpmPkg/driver/Protocol/Namespace/NvmDimmBlockIo.c
DcpmPkg/driver/Utils/PlatformConfigData.c
DcpmPkg/driver/Utils/AcpiParsing.c
DcpmPkg/driver/Utils/ProcessorAndTopologyInfo.c
DcpmPkg/driver/Utils/Interleave.c
DcpmPkg/driver/Utils/SmbiosUtility.c
DcpmPkg/driver/Utils/DumpLoadRegions.c
DcpmPkg/common/Pbr.c
DcpmPkg/common/PbrDcpmm.c
DcpmPkg/common/PbrOs.c
MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.c
MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
MdePkg/Library/UefiDevicePathLib/DevicePathToText.c
MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
MdePkg/Library/BaseLib/Math64.c
MdePkg/Library/BaseLib/MultU64x32.c
MdePkg/Library/BaseLib/DivU64x32Remainder.c
MdePkg/Library/BaseLib/Unaligned.c
MdePkg/Library/BaseLib/BitField.c
MdePkg/Library/BaseLib/LinkedList.c
MdePkg/Library/BaseLib/LShiftU64.c
MdePkg/Library/BaseLib/Math64.c
MdePkg/Library/BaseLib/SwapBytes64.c
MdePkg/Library/BaseLib/SwapBytes32.c
MdePkg/Library/BaseLib/SwapBytes16.c
MdePkg/Library/BaseLib/String.c
MdePkg/Library/BaseLib/SafeString.c
MdePkg/Library/BaseLib/RShiftU64.c
MdePkg/Library/BaseLib/Math64.c
MdePkg/Library/BaseLib/DivU64x32.c
${LIBIPMCTL_MFG_FILES}
)
# OS Files
list(APPEND LIBIPMCTL_SOURCE_FILES
src/os/efi_shim/${FILE_PREFIX}_efi_api.c
)
# if on Windows add rc file for file details
if (MSVC)
list(APPEND LIBIPMCTL_SOURCE_FILES
${CMAKE_CURRENT_BINARY_DIR}/src/os/win/libipmctl.rc
)
endif()
add_library(ipmctl ${LIB_TYPE} ${LIBIPMCTL_SOURCE_FILES})
target_include_directories(ipmctl PUBLIC
DcpmPkg/cli
src/os
src/os/efi_shim
src/os/ini
src/os/eventlog
src/os/nvm_api
src/os/s_string
src/os/cli_cmds
DcpmPkg/common
DcpmPkg/driver
DcpmPkg/driver/Utils
DcpmPkg/driver/Protocol/Driver
DcpmPkg/driver/Core
DcpmPkg/driver/Protocol/Namespace
DcpmPkg/driver/Protocol/Device
DcpmPkg/driver/Core/Diagnostics
MdePkg
MdePkg/Include
MdePkg/Include/Protocol
MdePkg/Include/Uefi
MdePkg/Include/Library
ShellPkg
ShellPkg/Include
ShellPkg/Include/Protocol
ShellPkg/Include/Library
ShellPkg/Library
MdeModulePkg
MdeModulePkg/Include
MdeModulePkg/Include/Library
)
if(MSVC)
set_target_properties(ipmctl PROPERTIES PREFIX "lib")
target_compile_options(ipmctl PRIVATE /FIAutoGen.h -D__NVM_DLL__ -D__NVM_API_DLL_EXPORTS__ )
# FIXME: Ignore warnings for secure functions
SET_SOURCE_FILES_PROPERTIES(src/os/efi_shim/os_efi_simple_file_protocol.c PROPERTIES COMPILE_FLAGS -D_CRT_SECURE_NO_WARNINGS)
SET_SOURCE_FILES_PROPERTIES(src/os/eventlog/event.c PROPERTIES COMPILE_FLAGS -D_CRT_SECURE_NO_WARNINGS)
SET_SOURCE_FILES_PROPERTIES(src/os/ini/ini.c PROPERTIES COMPILE_FLAGS -D_CRT_SECURE_NO_WARNINGS)
SET_SOURCE_FILES_PROPERTIES(src/os/efi_shim/os_efi_preferences.c PROPERTIES COMPILE_FLAGS -D_CRT_SECURE_NO_WARNINGS)
SET_SOURCE_FILES_PROPERTIES(src/os/nvm_api/nvm_management.c PROPERTIES COMPILE_FLAGS -D_CRT_SECURE_NO_WARNINGS)
SET_SOURCE_FILES_PROPERTIES(DcpmPkg/cli/Common.c PROPERTIES COMPILE_FLAGS -D_CRT_SECURE_NO_WARNINGS)
SET_SOURCE_FILES_PROPERTIES(src/os/nvm_api/nvm_output_parsing.c PROPERTIES COMPILE_FLAGS -D_CRT_SECURE_NO_WARNINGS)
SET_SOURCE_FILES_PROPERTIES(src/os/efi_shim/os_efi_shell_parameters_protocol.c PROPERTIES COMPILE_FLAGS -D_CRT_SECURE_NO_WARNINGS)
SET_SOURCE_FILES_PROPERTIES(src/os/cli_cmds/DumpSupportCommand.c PROPERTIES COMPILE_FLAGS -D_CRT_SECURE_NO_WARNINGS)
else()
target_compile_options(ipmctl PRIVATE
-include AutoGen.h
)
endif()
add_dependencies(ipmctl
stringdefs
iniconfig
)
target_link_libraries(ipmctl
ipmctl_os_interface
)
if(LNX_BUILD)
target_link_libraries(ipmctl
${NDCTL_LIBRARIES}
)
endif()
set_target_properties(ipmctl PROPERTIES
VERSION ${LIBIPMCTL_VERSION_STRING}
SOVERSION ${LIBIPMCTL_VERSION_MAJOR}
)
#---------------------------------------------------------------------------------------------------
# ipmctl executable
#---------------------------------------------------------------------------------------------------
FILE(GLOB IPMCTL_SOURCE_FILES
src/os/os_main.c
)
# if on Windows add rc file for file details
if (MSVC)
list(APPEND IPMCTL_SOURCE_FILES
${CMAKE_CURRENT_BINARY_DIR}/src/os/win/ipmctl.rc
)
endif()
add_executable(ipmctl-bin ${IPMCTL_SOURCE_FILES})
target_link_libraries(ipmctl-bin
ipmctl
)
target_include_directories(ipmctl-bin PUBLIC
src/os
src/os/nvm_api
src/os/ini
)
set_target_properties(ipmctl-bin
PROPERTIES OUTPUT_NAME ipmctl
)
if ((ASCIIDOCTOR_FOUND OR A2X_FOUND) AND LNX_BUILD)
add_dependencies(ipmctl-bin
manpage
)
endif()
if(MSVC)
set_target_properties(ipmctl-bin PROPERTIES LINK_FLAGS "/STACK:3000000")
else()
target_compile_options(ipmctl-bin PRIVATE "-fPIE")
set_target_properties(ipmctl-bin PROPERTIES LINK_FLAGS "-pie")
endif()
#----------------------------------------------------------------------------------------------------
# Generate String Definitions
#----------------------------------------------------------------------------------------------------
set(STRING_DEFS_INPUT_FILES
${ROOT}/DcpmPkg/common/NvmStatus.uni
${ROOT}/DcpmPkg/driver/Core/Diagnostics/DiagnosticsMessages.uni
${ROOT}/src/os/efi_shim/os_efi_hii_auto_gen_strings.py
${ROOT}/src/os/efi_shim/os_efi_hii_auto_gen_strings_ordered_dict.py
)
set(STRING_DEFS_OUTPUT_FILES
${ROOT}/src/os/efi_shim/os_efi_hii_auto_gen_strings.h
${ROOT}/src/os/efi_shim/os_efi_hii_auto_gen_defs.h
)
add_custom_target(stringdefs ALL
DEPENDS ${STRING_DEFS_OUTPUT_FILES} ${STRING_DEFS_INPUT_FILES})
add_custom_command(OUTPUT ${STRING_DEFS_OUTPUT_FILES}
COMMAND ${PYTHON_EXECUTABLE} ${ROOT}/src/os/efi_shim/os_efi_hii_auto_gen_strings.py
COMMENT "Generating String Definitions"
DEPENDS ${STRING_DEFS_INPUT_FILES}
)
#----------------------------------------------------------------------------------------------------
# Generate INI Default Config File
#----------------------------------------------------------------------------------------------------
add_custom_target(iniconfig ALL
DEPENDS ${OUTPUT_DIR}/ipmctl_default.conf
)
if(MSVC)
set(PRECOMPILER_FLAG /EP)
else()
set(PRECOMPILER_FLAG -E -P -D__LINUX__)
endif()
add_custom_command(OUTPUT ${OUTPUT_DIR}/ipmctl_default.conf
COMMAND ${CMAKE_C_COMPILER} ${MY_CMAKE_SYSROOT} ${PRECOMPILER_FLAG} ${ROOT}/src/os/ini/ipmctl_default.c > ${ROOT}/src/os/ini/ipmctl_default.i
COMMAND ${PYTHON_EXECUTABLE} ${ROOT}/src/os/ini/ini_auto_gen_default_config.py ${ROOT}/src/os/ini/ipmctl_default.i ${OUTPUT_DIR}/ipmctl_default.conf
COMMAND ${CMAKE_COMMAND} -E remove -f ${ROOT}/src/os/ini/ipmctl_default.i
COMMENT "Generating INI Default Config File"
)
#----------------------------------------------------------------------------------------------------
# Install
#----------------------------------------------------------------------------------------------------
FILE(GLOB NVM_HEADERS
src/os/nvm_api/export_api.h
src/os/nvm_api/nvm_management.h
src/os/nvm_api/nvm_types.h
DcpmPkg/common/NvmSharedDefs.h
)
FILE(COPY opensource/opensource_LICENSE
DESTINATION ${OUTPUT_DIR})
FILE(RENAME ${OUTPUT_DIR}/opensource_LICENSE ${OUTPUT_DIR}/LICENSE)
FILE(COPY opensource/edk2_License.txt
DESTINATION ${OUTPUT_DIR})
FILE(COPY opensource/thirdpartynotice.txt
DESTINATION ${OUTPUT_DIR})
FILE(COPY ${NVM_HEADERS}
DESTINATION ${OUTPUT_DIR})
FILE(COPY install/linux/logrotate/ipmctl.logrotate.conf
DESTINATION ${OUTPUT_DIR})
if(LNX_BUILD)
include(GNUInstallDirs)
find_package(PkgConfig)
pkg_check_modules(SYSTEMD systemd)
configure_file(${ROOT}/install/linux/libipmctl.pc.in ${OUTPUT_DIR}/libipmctl.pc @ONLY)
if(BUILD_STATIC)
install(TARGETS ipmctl-bin
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
else()
install(TARGETS ipmctl-bin ipmctl
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()
install(FILES ${OUTPUT_DIR}/LICENSE
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/ipmctl
)
install(FILES ${OUTPUT_DIR}/thirdpartynotice.txt
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/ipmctl
)
install(FILES ${OUTPUT_DIR}/edk2_License.txt
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/ipmctl
)
install(FILES ${OUTPUT_DIR}/ipmctl_default.conf
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/doc/ipmctl
)
install(FILES ${OUTPUT_DIR}/ipmctl_default.conf
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/ipmctl
RENAME ipmctl.conf
)
install(FILES ${NVM_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
file(MAKE_DIRECTORY output/ipmctl)
install(DIRECTORY output/ipmctl
DESTINATION ${CMAKE_INSTALL_LOCALSTATEDIR}/log
)
install(FILES ${OUTPUT_DIR}/ipmctl.logrotate.conf
DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/logrotate.d
RENAME ipmctl
)
install(FILES ${OUTPUT_DIR}/libipmctl.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
if(ASCIIDOCTOR_FOUND OR A2X_FOUND)
install(DIRECTORY ${OUTPUT_DIR}/manpage/
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
)
endif()
endif()
#----------------------------------------------------------------------------------------------------
# Generate man pages with asciidoctor
#----------------------------------------------------------------------------------------------------
if((ASCIIDOCTOR_FOUND OR A2X_FOUND) AND LNX_BUILD)
file(MAKE_DIRECTORY ${OUTPUT_DIR}/manpage)
file(MAKE_DIRECTORY ${OUTPUT_DIR}/docs)
set(DOCUMENTATION_INPUT_FILES
${ROOT}/Documentation/ipmctl/ipmctl.txt
${ROOT}/Documentation/ipmctl/Discovery/ipmctl-show-dimm.txt
${ROOT}/Documentation/ipmctl/Discovery/ipmctl-show-memory-resources.txt
${ROOT}/Documentation/ipmctl/Discovery/ipmctl-show-socket.txt
${ROOT}/Documentation/ipmctl/Discovery/ipmctl-show-system-capabilities.txt
${ROOT}/Documentation/ipmctl/Discovery/ipmctl-show-topology.txt
${ROOT}/Documentation/ipmctl/Memory_Subsystem_Provisioning/ipmctl-create-goal.txt
${ROOT}/Documentation/ipmctl/Memory_Subsystem_Provisioning/ipmctl-delete-goal.txt
${ROOT}/Documentation/ipmctl/Memory_Subsystem_Provisioning/ipmctl-dump-goal.txt
${ROOT}/Documentation/ipmctl/Memory_Subsystem_Provisioning/ipmctl-load-goal.txt
${ROOT}/Documentation/ipmctl/Memory_Subsystem_Provisioning/ipmctl-show-goal.txt
${ROOT}/Documentation/ipmctl/Persistent_Memory_Provisioning/ipmctl-show-region.txt
${ROOT}/Documentation/ipmctl/Instrumentation/ipmctl-set-sensor.txt
${ROOT}/Documentation/ipmctl/Instrumentation/ipmctl-show-performance.txt
${ROOT}/Documentation/ipmctl/Instrumentation/ipmctl-show-sensor.txt
${ROOT}/Documentation/ipmctl/Support_and_Maintenance/ipmctl-set-preferences.txt
${ROOT}/Documentation/ipmctl/Support_and_Maintenance/ipmctl-dump-support-data.txt
${ROOT}/Documentation/ipmctl/Support_and_Maintenance/ipmctl-help.txt
${ROOT}/Documentation/ipmctl/Support_and_Maintenance/ipmctl-set-dimm.txt
${ROOT}/Documentation/ipmctl/Support_and_Maintenance/ipmctl-show-firmware.txt
${ROOT}/Documentation/ipmctl/Support_and_Maintenance/ipmctl-show-preferences.txt
${ROOT}/Documentation/ipmctl/Support_and_Maintenance/ipmctl-load-dimm.txt
${ROOT}/Documentation/ipmctl/Support_and_Maintenance/ipmctl-version.txt
${ROOT}/Documentation/ipmctl/Debug/ipmctl-show-pcd.txt
${ROOT}/Documentation/ipmctl/Debug/ipmctl-delete-pcd.txt
${ROOT}/Documentation/ipmctl/Debug/ipmctl-dump-debug-log.txt
${ROOT}/Documentation/ipmctl/Debug/ipmctl-inject-error.txt
${ROOT}/Documentation/ipmctl/Debug/ipmctl-show-cap.txt
${ROOT}/Documentation/ipmctl/Debug/ipmctl-show-cel.txt
${ROOT}/Documentation/ipmctl/Debug/ipmctl-start-diagnostic.txt
# ${ROOT}/Documentation/ipmctl/Debug/ipmctl-diagnostic-events.txt
${ROOT}/Documentation/ipmctl/Debug/ipmctl-show-system.txt
${ROOT}/Documentation/ipmctl/Debug/ipmctl-show-error-log.txt
${ROOT}/Documentation/ipmctl/Debug/ipmctl-show-session.txt
${ROOT}/Documentation/ipmctl/Debug/ipmctl-start-session.txt
${ROOT}/Documentation/ipmctl/Debug/ipmctl-stop-session.txt
${ROOT}/Documentation/ipmctl/Debug/ipmctl-load-session.txt
${ROOT}/Documentation/ipmctl/Debug/ipmctl-dump-session.txt
)
list(LENGTH DOCUMENTATION_INPUT_FILES LEN)
math(EXPR INPUT_LENGTH "${LEN} -1")
foreach(INDEX RANGE ${INPUT_LENGTH})
list(GET DOCUMENTATION_INPUT_FILES ${INDEX} MAN_INPUT)
string(REGEX MATCH "[^/]*$" MAN_BARE_FILENAME ${MAN_INPUT})
set(MAN_TMP_INPUT ${OUTPUT_DIR}/manpage/${MAN_BARE_FILENAME})
string(REGEX REPLACE "txt$" "1.gz" MAN_OUTPUT "${MAN_TMP_INPUT}")
list(APPEND MANPAGE_OUTPUT_FILES ${MAN_OUTPUT})
if(NOT ASCIIDOCTOR_FOUND)
string(REGEX REPLACE "\\.[^.]*$" "" MAN_GZ_INPUT ${MAN_OUTPUT})
add_custom_command(OUTPUT ${MAN_OUTPUT}
COMMENT "Clean out link markup because they are invalid in the manpages"
COMMAND sed -e 's/<\\[/g' -e 's/>>/]/g' ${MAN_INPUT} > ${MAN_TMP_INPUT}
COMMAND ${A2X_BINARY} -f manpage -a mansource=ipmctl -a manmanual="ipmctl" -a ipmctl_version=${IPMCTL_VERSION_STRING} -a os_build=1 -a manpage=1 -D ${OUTPUT_DIR}/manpage ${MAN_TMP_INPUT}
COMMAND gzip -f ${MAN_GZ_INPUT}
COMMAND rm -f ${MAN_TMP_INPUT}
COMMENT "Generating man pages"
DEPENDS ${MAN_INPUT}
)
endif()
endforeach()
add_custom_target(manpage ALL
DEPENDS ${MANPAGE_OUTPUT_FILES} ${DOCUMENTATION_INPUT_FILES}
)
if(ASCIIDOCTOR_FOUND)
add_custom_command(OUTPUT ${MANPAGE_OUTPUT_FILES}
COMMAND ${ASCIIDOCTOR_BINARY} -b manpage -a mansource=ipmctl -a manmanual="ipmctl" -a ipmctl_version=${IPMCTL_VERSION_STRING} -a os_build=1 -a manpage=1 -D ${OUTPUT_DIR}/manpage ${DOCUMENTATION_INPUT_FILES}
COMMAND gzip -f ${OUTPUT_DIR}/manpage/*.1
COMMENT "Generating man pages"
DEPENDS ${DOCUMENTATION_INPUT_FILES}
)
endif()
endif()
# Allow building more documentation if we have access to it
if(EXISTS "${ROOT}/CMake/internal.cmake")
include("${ROOT}/CMake/internal.cmake")
endif()
# --------------------------------------------------------------------------------------------------
# Additional includes
# --------------------------------------------------------------------------------------------------
# CppUTest unit tests
# Ideally we want official builds to not include unit test executables and
# have it easy to build unit tests as an individual target from development
# environments. However, after some attempts of modifying linux_build.sh, I
# still haven't found a solution. So if you want to run unit tests, just
# uncomment this UNIT_TEST flag or define it using the build scripts for now.
#set(UNIT_TEST on)
if (UNIT_TEST)
add_subdirectory("./tests/cpputest" "./cpputest_out")
endif()
if(LNX_BUILD AND UNIT_TEST)
include(CMake/unit_test.cmake)
endif()
if(ESX_BUILD)
include(CMake/esx.cmake)
endif()
add_subdirectory(src/os/nvm_api_sample) ipmctl-03.00.00.0423/DcpmPkg/ 0000775 0000000 0000000 00000000000 14165347476 0015157 5 ustar 00root root 0000000 0000000 ipmctl-03.00.00.0423/DcpmPkg/cli/ 0000775 0000000 0000000 00000000000 14165347476 0015726 5 ustar 00root root 0000000 0000000 ipmctl-03.00.00.0423/DcpmPkg/cli/CommandParser.c 0000664 0000000 0000000 00000174371 14165347476 0020642 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "CommandParser.h"
#include
#include
#include
#include
#include
#include "Common.h"
#include
DispInfo gDisplayInfo;
extern int g_basic_commands;
/* local fns */
EFI_STATUS findVerb(UINTN *pStart, struct CommandInput *pInput, struct Command *pCommand);
EFI_STATUS findOptions(UINTN *pStart, struct CommandInput *pInput, struct Command *pCommand);
EFI_STATUS findTargets(UINTN *pStart, struct CommandInput *pInput, struct Command *pCommand);
EFI_STATUS findProperties(UINTN *pStart, struct CommandInput *pInput, struct Command *pCommand);
EFI_STATUS MatchCommand(struct Command *pInput, struct Command *pMatch);
EFI_STATUS MatchOptions(struct Command *pInput, struct Command *pMatch);
EFI_STATUS MatchTargets(struct Command *pInputCmd, struct Command *pCmdToMatch);
EFI_STATUS MatchProperties(struct Command *pInput, struct Command *pMatch);
static EFI_STATUS ValidateProtocolAndPayloadSizeOptions(struct Command *pCmd);
UINT16 TargetCount(struct Command *pCmd);
UINT16 TargetMatchCount(struct Command *pInputCmd, struct Command *pCmdToMatch);
/*
* Global variables
*/
static UINTN gCommandCount = 0;
static struct Command *gCommandList = NULL;
static CHAR16 *gSyntaxError = NULL;
static UINTN gPossibleMatchCount = 0;
static CHAR16 *gDetailedSyntaxError = NULL;
/*
* Add the specified command to the list of supported commands
*/
EFI_STATUS RegisterCommand(struct Command *pCommand)
{
EFI_STATUS Rc = EFI_SUCCESS;
/* make sure a verb is specified */
if (NULL == pCommand || StrLen(pCommand->verb) == 0) {
NVDIMM_WARN("Failed to register the command because it is invalid");
Rc = EFI_ABORTED;
} else {
/* allocate memory */
if (gCommandCount == 0) {
gCommandList = AllocatePool(sizeof(struct Command));
} else {
gCommandList = ReallocatePool(sizeof(struct Command) * gCommandCount,
sizeof(struct Command) * (gCommandCount + 1), gCommandList);
}
if (gCommandList) {
pCommand->CommandId = (UINT8)gCommandCount; // Save its index for better tracking.
CopyMem_S(&gCommandList[gCommandCount], sizeof(struct Command), pCommand, sizeof(struct Command));
gCommandCount++;
} else {
NVDIMM_WARN("Failed to register the command due to lack of resources");
Rc = EFI_OUT_OF_RESOURCES;
}
}
NVDIMM_EXIT_CHECK_I64(Rc);
return Rc;
}
/**
Free the allocated memory for target values
in the CLI command structure.
@param[in out] pCommand pointer to the command structure
**/
VOID
FreeCommandStructure(
IN OUT COMMAND *pCommand
)
{
UINT32 Index = 0;
if (pCommand != NULL) {
for (Index = 0; Index < MAX_TARGETS; Index++) {
FREE_POOL_SAFE(pCommand->targets[Index].pTargetValueStr);
}
for (Index = 0; Index < MAX_OPTIONS; Index++) {
FREE_POOL_SAFE(pCommand->options[Index].pOptionValueStr);
}
}
}
/**
The function parse the input string and split it to the tokens
The caller function is responsible for deallocation of pCmdInput. The FreeCommandInput function should be
used to deallocate memory.
@param[in] pCommand The input string
@param[out] pCmdInput
**/
VOID
FillCommandInput(
IN CHAR16 *pCommand,
OUT struct CommandInput *pCmdInput
)
{
if (pCommand == NULL || pCmdInput == NULL) {
return;
}
pCmdInput->ppTokens = StrSplit(pCommand, L' ', &pCmdInput->TokenCount);
}
/**
If parsing fails, retrieve a more useful syntax error
**/
CHAR16 *getSyntaxError()
{
return gSyntaxError;
}
/**
If parsing fails, set syntax error, but first free old one
**/
VOID SetSyntaxError(
IN CHAR16 *pSyntaxError
)
{
FREE_POOL_SAFE(gSyntaxError);
gSyntaxError = pSyntaxError;
}
/**
If parsing fails, set syntax error, but first free old one
**/
VOID SetDetailedSyntaxError(
IN CHAR16 *pDetailedSyntaxError
)
{
FREE_POOL_SAFE(gDetailedSyntaxError);
gDetailedSyntaxError = pDetailedSyntaxError;
}
/*
* Clean up the resources associated with the command list
*/
void FreeCommands()
{
NVDIMM_ENTRY();
gCommandCount = 0;
FREE_POOL_SAFE(gCommandList);
FREE_POOL_SAFE(gSyntaxError);
FREE_POOL_SAFE(gDetailedSyntaxError);
NVDIMM_EXIT();
}
/*
* Clean up the resources associated with the input
*/
void FreeCommandInput(struct CommandInput *pCommandInput)
{
NVDIMM_ENTRY();
if (pCommandInput == NULL) {
return;
}
if (pCommandInput->ppTokens == NULL) {
pCommandInput->TokenCount = 0;
return;
}
FreeStringArray(pCommandInput->ppTokens, pCommandInput->TokenCount);
pCommandInput->ppTokens = NULL;
pCommandInput->TokenCount = 0;
NVDIMM_EXIT();
}
/*
* Ensure cmd line args don't include '%'
*/
EFI_STATUS
InvalidTokenScreen(
IN struct CommandInput *pInput,
IN CHAR16 *pHelpStr
)
{
UINTN Index = 0;
CHAR16 *pTmpString = NULL;
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
if (NULL == pInput || NULL == pHelpStr) {
return ReturnCode;
}
for (Index = 0; Index < pInput->TokenCount; Index++) {
if (NULL != StrStr(pInput->ppTokens[Index], L"%")) {
pTmpString = CatSPrint(NULL, CLI_PARSER_ERR_UNEXPECTED_TOKEN, L"%%");
SetSyntaxError(CatSPrintClean(pTmpString, FORMAT_NL_STR FORMAT_NL_STR,
CLI_PARSER_DID_YOU_MEAN, pHelpStr));
return ReturnCode;
}
}
return EFI_SUCCESS;
}
extern BOOLEAN HelpRequested;
/*
* Parse the given the command line arguments to
* identify the correct command.
*
* Parsing is a two step process to first identify the tokens of the input
* and then try to match it against the list of supported commands.
*
* It is the responsibility of the caller function to free the allocated
* memory for target values in the Command structure.
*/
EFI_STATUS
Parse(
IN struct CommandInput *pInput,
IN OUT struct Command *pCommand
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
UINTN Start = 0;
UINTN Index = 0;
CHAR16 *pHelpStr = NULL;
CHAR16 *pSyntaxErrorStr = NULL;
NVDIMM_ENTRY();
FREE_POOL_SAFE(gSyntaxError);
FREE_POOL_SAFE(gDetailedSyntaxError);
gPossibleMatchCount = 0;
/* check input parameters */
if (pCommand == NULL || pInput == NULL || pInput->ppTokens == NULL) {
goto Finish;
}
if (pInput->TokenCount < 1) {
NVDIMM_DBG("No input specified for Parse");
goto Finish;
}
/* parse the input */
Start = 0;
ZeroMem(pCommand, sizeof(struct Command));
for (Index = 0; Index < MAX_TARGETS; Index++) {
pCommand->targets[Index].pTargetValueStr = AllocateZeroPool(TARGET_VALUE_LEN * sizeof(CHAR16));
if (!pCommand->targets[Index].pTargetValueStr) {
ReturnCode = EFI_OUT_OF_RESOURCES;
break;
}
}
for (Index = 0; Index < MAX_OPTIONS; Index++) {
pCommand->options[Index].pOptionValueStr = AllocateZeroPool(PARSER_OPTION_VALUE_LEN * sizeof(CHAR16));
if (!pCommand->options[Index].pOptionValueStr) {
ReturnCode = EFI_OUT_OF_RESOURCES;
break;
}
}
ReturnCode = findVerb(&Start, pInput, pCommand);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
pHelpStr = getCommandHelp(pCommand, FALSE);
ReturnCode = InvalidTokenScreen(pInput, pHelpStr);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
ReturnCode = findOptions(&Start, pInput, pCommand);
/** Catch errors and send appropriate message **/
if (EFI_ERROR(ReturnCode)) {
switch (ReturnCode) {
case EFI_BUFFER_TOO_SMALL: // Too long option value
SetSyntaxError(CatSPrint(NULL, CLI_PARSER_ERR_INVALID_OPTION_VALUES FORMAT_NL_STR, pHelpStr));
break;
}
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
/* If protocol or payload size options present, ensure no mutually exclusive protocol/payload options */
ReturnCode = ValidateProtocolAndPayloadSizeOptions(pCommand);
if (EFI_NOT_FOUND != ReturnCode && EFI_ERROR(ReturnCode) && FALSE == HelpRequested) {
goto Finish;
}
ReturnCode = findTargets(&Start, pInput, pCommand);
if (EFI_ERROR(ReturnCode)) {
switch (ReturnCode) {
case EFI_BUFFER_TOO_SMALL:
SetSyntaxError(CatSPrint(NULL, CLI_PARSER_ERR_INVALID_TARGET_VALUES FORMAT_NL_STR, pHelpStr));
break;
}
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
ReturnCode = findProperties(&Start, pInput, pCommand);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
/* check if input target ordering is correct */
if (!InputTargetsValid(pCommand->targets, &pSyntaxErrorStr)) {
pCommand->ShowHelp = TRUE;
SetSyntaxError(CatSPrint(NULL, FORMAT_STR_NL FORMAT_STR_NL FORMAT_STR, pSyntaxErrorStr, CLI_PARSER_DID_YOU_MEAN, pHelpStr));
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
/* try to match the parsed input against a registered command */
for (Index = 0; Index < gCommandCount; Index++) {
ReturnCode = MatchCommand(pCommand, &gCommandList[Index]);
if (!EFI_ERROR(ReturnCode)) {
pCommand->run = gCommandList[Index].run;
pCommand->PrinterCtrlSupported = gCommandList[Index].PrinterCtrlSupported;
pCommand->ExcludeDriverBinding = gCommandList[Index].ExcludeDriverBinding;
break;
}
}
if (EFI_ERROR(ReturnCode)) {
for (Index = 0; Index < gCommandCount; Index++) {
//if at least the verb matches, then set this command up for help display
if (StrICmp(pCommand->verb, gCommandList[Index].verb) == 0) {
pCommand->ShowHelp = TRUE;
ReturnCode = EFI_SUCCESS;
break;
}
}
}
/* try to give the user more useful help */
if (EFI_ERROR(ReturnCode)) {
if (pCommand->ShowHelp == TRUE) {
/**
If user used -help option, but provided command does not match any command syntax - display
syntax of any command containing verb of entered command and return EFI_SUCCESS
**/
SetSyntaxError(CatSPrint(NULL, FORMAT_STR, getCommandHelp(pCommand, FALSE)));
LongPrint(getSyntaxError());
ReturnCode = EFI_SUCCESS;
} else if (gPossibleMatchCount == 1 && gDetailedSyntaxError) {
SetSyntaxError(CatSPrint(NULL, L"Syntax Error: " FORMAT_STR_NL L"Correct syntax: " FORMAT_STR, gDetailedSyntaxError, pHelpStr));
} else {
SetSyntaxError(CatSPrint(NULL, FORMAT_STR_NL FORMAT_STR_NL FORMAT_STR, CLI_PARSER_ERR_INVALID_COMMAND, CLI_PARSER_DID_YOU_MEAN, pHelpStr));
}
}
Finish:
FREE_POOL_SAFE(pSyntaxErrorStr);
FREE_POOL_SAFE(pHelpStr);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/*
* Identify the verb in the input
*/
EFI_STATUS findVerb(UINTN *pStart, struct CommandInput *pInput, struct Command *pCommand)
{
EFI_STATUS rc = EFI_INVALID_PARAMETER;
UINTN i = 0;
NVDIMM_ENTRY();
/* there has to be at least one verb */
if (*pStart >= pInput->TokenCount) {
return rc;
}
for (i = 0; i < gCommandCount; i++)
{
if (StrICmp(gCommandList[i].verb, pInput->ppTokens[*pStart]) == 0)
{
/* verb matches, so store it and move on */
StrnCpyS(pCommand->verb, VERB_LEN, pInput->ppTokens[*pStart], VERB_LEN - 1);
(*pStart)++;
rc = EFI_SUCCESS;
break;
}
}
/* more detailed error */
if (EFI_ERROR(rc))
{
#ifdef OS_BUILD
if (g_basic_commands) {
// This should be updated when there are other commands a non-root user can run
#ifdef _MSC_VER
Print(L"Sorry, the ipmctl command you have attempted to execute requires admin privileges.\n");
#else //_MSC_VER
Print(L"Sorry, the ipmctl command you have attempted to execute requires root privileges.\n");
#endif //_MSC_VER
} else {
#endif //OS_BUILD
SetSyntaxError(CatSPrint(NULL, CLI_PARSER_ERR_VERB_EXPECTED, pInput->ppTokens[*pStart]));
#ifdef OS_BUILD
}
#endif
}
NVDIMM_EXIT_I64(rc);
return rc;
}
/*
* Identify the options in the input
*/
EFI_STATUS findOptions(UINTN *pStart, struct CommandInput *pInput, struct Command *pCommand)
{
EFI_STATUS Rc = EFI_SUCCESS;
UINTN Index = 0;
UINTN Index2 = 0;
UINTN Index3 = 0;
UINTN matchedOptions = 0;
BOOLEAN Found = FALSE;
CHAR16 *pHelpStr = NULL;
CHAR16 *pTmpString = NULL;
NVDIMM_ENTRY();
pHelpStr = getCommandHelp(pCommand, FALSE);
if (NULL == gCommandList || 0 == gCommandCount)
{
Rc = EFI_INVALID_PARAMETER;
goto Finish;
}
/** loop through the input tokens **/
while ((pInput->TokenCount - *pStart) > 0) {
Found = FALSE;
/** loop through the supported commands to find valid options **/
for (Index = 0; Index < gCommandCount && !Found; Index++) {
for (Index2 = 0; Index2 < MAX_OPTIONS && !Found; Index2++) {
/** check both the long and short version of each option **/
if ((StrICmp(pInput->ppTokens[*pStart], HELP_OPTION) == 0)
|| (StrICmp(pInput->ppTokens[*pStart], HELP_OPTION_SHORT) == 0)) {
pCommand->ShowHelp = TRUE;
Found = TRUE;
}
else if (StrICmp(gCommandList[Index].options[Index2].OptionNameShort,
pInput->ppTokens[*pStart]) == 0) {
// Check if option is copied already - to prevent duplicated option
for (Index3 = 0; Index3 < matchedOptions; Index3++) {
if (StrICmp(pCommand->options[Index3].OptionNameShort, pInput->ppTokens[*pStart]) == 0) {
pTmpString = CatSPrint(NULL, CLI_PARSER_ERR_UNEXPECTED_TOKEN, pInput->ppTokens[*pStart]);
SetSyntaxError(CatSPrintClean(pTmpString, FORMAT_NL_STR FORMAT_NL_STR,
CLI_PARSER_DID_YOU_MEAN, pHelpStr));
Rc = EFI_INVALID_PARAMETER;
goto Finish;
}
}
StrnCpyS(pCommand->options[matchedOptions].OptionNameShort, OPTION_LEN, pInput->ppTokens[*pStart], OPTION_LEN - 1);
Found = TRUE;
}
else if (StrICmp(gCommandList[Index].options[Index2].OptionName,
pInput->ppTokens[*pStart]) == 0) {
// Check if option is copied already - to prevent duplicated option
for (Index3 = 0; Index3 < matchedOptions; Index3++) {
if (StrICmp(pCommand->options[Index3].OptionName, pInput->ppTokens[*pStart]) == 0) {
pTmpString = CatSPrint(NULL, CLI_PARSER_ERR_UNEXPECTED_TOKEN, pInput->ppTokens[*pStart]);
SetSyntaxError(CatSPrintClean(pTmpString, FORMAT_NL_STR FORMAT_NL_STR,
CLI_PARSER_DID_YOU_MEAN, pHelpStr));
Rc = EFI_INVALID_PARAMETER;
goto Finish;
}
}
StrnCpyS(pCommand->options[matchedOptions].OptionName, OPTION_LEN, pInput->ppTokens[*pStart], OPTION_LEN - 1);
Found = TRUE;
}
/** if option is found, move to the next token **/
if (Found) {
(*pStart)++;
/** check for an option value **/
if (((pInput->TokenCount - *pStart) >= 1) && (pInput->ppTokens[*pStart][0] != '-')) {
if (StrLen(pInput->ppTokens[*pStart]) > PARSER_OPTION_VALUE_LEN) {
Rc = EFI_BUFFER_TOO_SMALL;
break;
}
else {
if (pCommand->options[matchedOptions].pOptionValueStr == NULL) {
pTmpString = CatSPrint(NULL, CLI_PARSER_ERR_UNEXPECTED_TOKEN, pInput->ppTokens[*pStart]);
SetSyntaxError(CatSPrintClean(pTmpString, FORMAT_NL_STR FORMAT_NL_STR,
CLI_PARSER_DID_YOU_MEAN, pHelpStr));
Rc = EFI_INVALID_PARAMETER;
goto Finish;
}
StrnCpyS(pCommand->options[matchedOptions].pOptionValueStr, PARSER_OPTION_VALUE_LEN,
pInput->ppTokens[*pStart], PARSER_OPTION_VALUE_LEN - 1);
(*pStart)++;
}
}
matchedOptions++;
}
}
}
/** then this is not an option so move on **/
if (!Found) {
break;
}
}
Finish:
FREE_POOL_SAFE(pHelpStr)
NVDIMM_EXIT_I64(Rc);
return Rc;
}
/*
* Identify the targets in the input
*/
EFI_STATUS findTargets(UINTN *pStart, struct CommandInput *pInput, struct Command *pCommand)
{
EFI_STATUS Rc = EFI_SUCCESS;
UINTN Index = 0;
UINTN Index2 = 0;
UINTN Index3 = 0;
BOOLEAN Found = FALSE;
UINTN matchedTargets = 0;
CHAR16 *pHelpStr = NULL;
CHAR16 *pTmpStr = NULL;
NVDIMM_ENTRY();
pHelpStr = getCommandHelp(pCommand, FALSE);
if (NULL == gCommandList || 0 == gCommandCount)
{
Rc = EFI_INVALID_PARAMETER;
goto Finish;
}
/* loop through the input tokens */
while ((pInput->TokenCount - *pStart) > 0)
{
Found = FALSE;
/* check input against supported targets */
for (Index = 0; Index < gCommandCount && !Found; Index++) {
for (Index2 = 0; Index2 < MAX_TARGETS && !Found; Index2++) {
if (StrICmp(gCommandList[Index].targets[Index2].TargetName,
pInput->ppTokens[*pStart]) == 0) {
// Check if option is copied already - to prevent duplicated option
for (Index3 = 0; Index3 < matchedTargets; Index3++) {
if (StrICmp(pCommand->targets[Index3].TargetName, pInput->ppTokens[*pStart]) == 0) {
pTmpStr = CatSPrint(NULL, CLI_PARSER_ERR_UNEXPECTED_TOKEN, pInput->ppTokens[*pStart]);
SetSyntaxError(CatSPrintClean(pTmpStr, FORMAT_NL_STR FORMAT_NL_STR,
CLI_PARSER_DID_YOU_MEAN, pHelpStr));
Rc = EFI_INVALID_PARAMETER;
}
}
StrnCpyS(pCommand->targets[matchedTargets].TargetName, TARGET_LEN, pInput->ppTokens[*pStart], TARGET_LEN - 1);
(*pStart)++;
Found = TRUE;
/* check for a target value */
if (((pInput->TokenCount - *pStart) >= 1) &&
(pInput->ppTokens[*pStart][0] != '-') &&
!ContainsCharacter('=', pInput->ppTokens[*pStart])) {
if (StrLen(pInput->ppTokens[*pStart]) > TARGET_VALUE_LEN) {
Rc = EFI_BUFFER_TOO_SMALL;
break;
}
else {
StrnCpyS(pCommand->targets[matchedTargets].pTargetValueStr, TARGET_VALUE_LEN, pInput->ppTokens[*pStart], TARGET_VALUE_LEN - 1);
(*pStart)++;
}
}
matchedTargets++;
}
}
}
/* then this is not an target so move on */
if (!Found) {
break;
}
}
Finish:
FREE_POOL_SAFE(pHelpStr);
NVDIMM_EXIT_I64(Rc);
return Rc;
}
/*
* Identify the properties in the input
*/
EFI_STATUS findProperties(UINTN *pStart, struct CommandInput *pInput, struct Command *pCommand)
{
EFI_STATUS Rc;
CHAR16 *propertyName;
CHAR16 *propertyValue;
UINT16 propertyLength;
UINTN matchedProperties;
BOOLEAN Found;
UINTN Index;
UINTN Index2;
CHAR16 *pHelpStr = NULL;
CHAR16 *pTmpStr = NULL;
NVDIMM_ENTRY();
Rc = EFI_SUCCESS; /* no properties are required so default to success */
matchedProperties = 0;
pHelpStr = getCommandHelp(pCommand, FALSE);
if (NULL == gCommandList || 0 == gCommandCount)
{
Rc = EFI_INVALID_PARAMETER;
goto Finish;
}
/* loop through the input tokens */
while (((pInput->TokenCount - *pStart) > 0) && (EFI_SUCCESS == Rc))
{
Rc = EFI_INVALID_PARAMETER;
Found = FALSE;
propertyName = NULL;
propertyValue = NULL;
/* properties follow the format key=value, so check for = */
if (StrStr(pInput->ppTokens[*pStart], L"=") != NULL)
{
/* split the property into name and value */
propertyLength = (UINT16)StrLen(pInput->ppTokens[*pStart]) + 1;
propertyValue = AllocatePool(propertyLength * sizeof(CHAR16));
if (!propertyValue)
{
Rc = EFI_OUT_OF_RESOURCES;
continue;
}
StrnCpyS(propertyValue, propertyLength, pInput->ppTokens[*pStart], propertyLength - 1);
propertyName = StrTok(&propertyValue, L'=');
/* name is valid */
if (propertyName)
{
/*
* loop through each command to see if the
* property name matches any supported properties
*/
for (Index = 0; Index < gCommandCount && !Found; Index++)
{
for (Index2 = 0; Index2 < MAX_PROPERTIES && !Found; Index2++)
{
/* found a matching property */
if (StrICmp(gCommandList[Index].properties[Index2].PropertyName,
propertyName) == 0)
{
StrnCpyS(pCommand->properties[matchedProperties].PropertyName, PROPERTY_KEY_LEN, propertyName, PROPERTY_KEY_LEN - 1);
/* value is valid */
if (StrLen(propertyValue) > 0) {
StrnCpyS(pCommand->properties[matchedProperties].PropertyValue, PROPERTY_VALUE_LEN, propertyValue, PROPERTY_VALUE_LEN - 1);
}
Found = 1;
(*pStart)++;
matchedProperties++;
if (matchedProperties < MAX_PROPERTIES) {
Rc = EFI_SUCCESS;
}
else {
Rc = EFI_OUT_OF_RESOURCES;
}
break; /* move to the next property */
}
}
}
/* clean up */
if (propertyName)
{
FreePool(propertyName);
}
} /* no property value */
/* clean up */
if (propertyValue)
{
FreePool(propertyValue);
}
} /* no property name */
/* bad property or unexpected token */
if (!Found) {
pTmpStr = CatSPrint(NULL, CLI_PARSER_ERR_UNEXPECTED_TOKEN, pInput->ppTokens[*pStart]);
SetSyntaxError(CatSPrintClean(pTmpStr, FORMAT_NL_STR FORMAT_NL_STR, CLI_PARSER_DID_YOU_MEAN,
pHelpStr));
Rc = EFI_INVALID_PARAMETER;
continue;
}
}
Finish:
FREE_POOL_SAFE(pHelpStr);
NVDIMM_EXIT_I(Rc);
return Rc;
}
/*
* Attempt to match the input to a command
*/
EFI_STATUS MatchCommand(struct Command *pInput, struct Command *pMatch)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
EFI_STATUS OptionsMatched = EFI_SUCCESS;
EFI_STATUS TargetsMatched = EFI_SUCCESS;
EFI_STATUS PropertiesMatched = EFI_SUCCESS;
if (pInput == NULL || pMatch == NULL) {
goto Finish;
}
/* match the verb */
if (StrICmp(pMatch->verb, pInput->verb) == 0) {
gPossibleMatchCount++;
OptionsMatched = MatchOptions(pInput, pMatch);
TargetsMatched = MatchTargets(pInput, pMatch);
PropertiesMatched = MatchProperties(pInput, pMatch);
/* try match the options, targets and properties */
if ((OptionsMatched == EFI_SUCCESS) && (TargetsMatched == EFI_SUCCESS) && (PropertiesMatched == EFI_SUCCESS)) {
/* found match! */
ReturnCode = EFI_SUCCESS;
}
}
Finish:
return ReturnCode;
}
/*
* Attempt to match the input based on the options
*/
EFI_STATUS
MatchOptions(
IN struct Command *pInput,
IN struct Command *pMatch
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
BOOLEAN MissingValue = FALSE;
BOOLEAN RedundantValue = FALSE;
UINTN MatchInputOptions = 0;
UINTN MatchInputRequired = 0;
UINTN MatchCommandOptions = 0;
UINTN MatchCommandRequired = 0;
UINTN MatchCount = 0;
UINTN Index = 0;
UINTN Index2 = 0;
// Count options that need match in input command and matching command
for (Index = 0; Index < MAX_OPTIONS; Index++) {
if (StrLen(pInput->options[Index].OptionName) > 0 || StrLen(pInput->options[Index].OptionNameShort) > 0) {
MatchInputOptions++;
} else {
break;
}
}
for (Index = 0; Index < MAX_OPTIONS; Index++) {
if (StrLen(pMatch->options[Index].OptionName) > 0 || StrLen(pMatch->options[Index].OptionNameShort) > 0) {
MatchCommandOptions++;
if (pMatch->options[Index].Required) {
MatchCommandRequired++;
}
} else {
break;
}
}
if (MatchInputOptions > MAX_OPTIONS || MatchCommandOptions > MAX_OPTIONS) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_WARN("Too many options have been provided.");
goto Finish;
}
for (Index = 0; Index < MatchInputOptions; Index++) {
MissingValue = FALSE;
RedundantValue = FALSE;
for (Index2 = 0; Index2 < MatchCommandOptions; Index2++) {
// check if option name matches
if (StrICmp(pMatch->options[Index2].OptionName, pInput->options[Index].OptionName) == 0 ||
StrICmp(pMatch->options[Index2].OptionNameShort, pInput->options[Index].OptionNameShort) == 0) {
// check if option is required
if (pMatch->options[Index2].Required) {
MatchInputRequired++;
}
// check if value is optional or required
if (pMatch->options[Index2].ValueRequirement != ValueOptional) {
if (NULL != pInput->options[Index].pOptionValueStr && StrLen(pInput->options[Index].pOptionValueStr) > 0) {
if (pMatch->options[Index2].ValueRequirement == ValueRequired) {
MatchCount++;
} else {
RedundantValue = TRUE;
}
break;
} else {
if (pMatch->options[Index2].ValueRequirement == ValueEmpty) {
MatchCount++;
} else {
MissingValue = TRUE;
}
break;
}
} else {
MatchCount++;
break;
}
}
}
if (MatchCount <= Index) {
// option specified with missing value
if (MissingValue) {
SetDetailedSyntaxError(
CatSPrint(NULL, CLI_PARSER_DETAILED_ERR_OPTION_VALUE_REQUIRED, pMatch->options[Index2].OptionName));
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
if (RedundantValue) {
SetDetailedSyntaxError(
CatSPrint(NULL, CLI_PARSER_DETAILED_ERR_OPTION_VALUE_UNEXPECTED, pMatch->options[Index2].OptionName));
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
// missing required option
if (Index2 < MatchCommandOptions && pMatch->options[Index2].Required) {
SetDetailedSyntaxError(
CatSPrint(NULL, CLI_PARSER_DETAILED_ERR_OPTION_REQUIRED, pMatch->options[Index2].OptionName));
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish; // stop looping
}
// if the user passed in an invalid option
if (StrLen(pInput->options[Index].OptionName) > 0 &&
!containsOption(pMatch, pInput->options[Index].OptionName)) {
SetSyntaxError(CatSPrint(NULL, CLI_PARSER_ERR_UNEXPECTED_TOKEN, pInput->options[Index].OptionName));
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish; // stop looping
}
// if the user passed in an invalid option abbreviation
if (StrLen(pInput->options[Index].OptionNameShort) > 0 &&
!containsOption(pMatch, pInput->options[Index].OptionNameShort)) {
SetSyntaxError(CatSPrint(NULL, CLI_PARSER_ERR_UNEXPECTED_TOKEN, pInput->options[Index].OptionNameShort));
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish; // stop looping
}
}
}
if (MatchCount < MatchInputOptions || MatchInputRequired < MatchCommandRequired) {
ReturnCode = EFI_NOT_FOUND;
}
Finish:
return ReturnCode;
}
/*
Gives the total number of targets associated with a command
*/
UINT16 TargetCount(struct Command *pCmd)
{
UINT16 val = 0;
UINT16 Index = 0;
CHAR16 *TargetName = NULL;
UINTN TargetNameLen = 0;
if (pCmd == NULL) {
return val;
}
for (Index = 0; Index < MAX_TARGETS; ++Index) {
TargetName = pCmd->targets[Index].TargetName;
TargetNameLen = StrLen(TargetName);
if (TargetNameLen == 0) {
// All targets from Input was processed, quit from loop.
break;
}
val++;
}
return val;
}
/*
Gives the total number of targets that match an input as compared to a given
*/
UINT16 TargetMatchCount(struct Command *pInputCmd, struct Command *pCmdToMatch)
{
UINT16 val = 0;
UINT16 Index1 = 0;
UINT16 Index2 = 0;
CHAR16 *InputName = NULL;
UINTN InputNameLen = 0;
CHAR16 *MatchName = NULL;
UINTN MatchNameLen = 0;
if (pInputCmd == NULL || pCmdToMatch == NULL ||
StrICmp(pInputCmd->verb, pCmdToMatch->verb) != 0) {
return val;
}
for (Index1 = 0; Index1 < MAX_TARGETS; ++Index1) {
InputName = pInputCmd->targets[Index1].TargetName;
InputNameLen = StrLen(InputName);
if (InputNameLen == 0) {
// All targets from Input was processed, quit from loop.
break;
}
for (Index2 = 0; Index2 < MAX_TARGETS; ++Index2) {
MatchName = pCmdToMatch->targets[Index2].TargetName;
MatchNameLen = StrLen(MatchName);
if (MatchNameLen == 0) {
// All targets from Input was processed, quit from loop.
break;
}
if (StrICmp(InputName, MatchName) == 0) {
val++;
}
}
}
return val;
}
/**
Validate input targets combination
Function compares input targets with invalid sequences
@param[in] pInputTargets is a pointer to the list of input command targets
@param[out] ppErrorString is a pointer to a pointer to the return error message
@retval TRUE if input command targets does not match any known invalid combination
@retval FALSE if all targets matches to invalid combination
**/
BOOLEAN InputTargetsValid(struct target *pInputTargets, CHAR16 **ppErrorString)
{
BOOLEAN ReturnValue = TRUE;
UINT16 IndexSeq = 0;
UINT16 IndexTar = 0;
CHAR16 *InputName = NULL;
CHAR16 *MatchName = NULL;
BOOLEAN Match = FALSE;
static const struct TargetsCombination InvalidSequences[] =
{
{ {L"-socket", L"-dimm", NULL}, L"Invalid input target ordering: -socket -dimm" }
};
if (pInputTargets == NULL) {
goto Finish;
}
for (IndexSeq = 0; IndexSeq < ARRAY_SIZE(InvalidSequences); IndexSeq++) {
Match = TRUE;
for (IndexTar = 0; IndexTar < MAX_TARGETS; IndexTar++) {
InputName = pInputTargets[IndexTar].TargetName;
MatchName = InvalidSequences[IndexSeq].pTargets[IndexTar];
if (MatchName == NULL) {
// Input and invalid sequence match! Quit from loop.
break;
}
if (StrICmp(InputName, MatchName) != 0) {
// Targets are different. Quit from loop.
Match = FALSE;
break;
}
}
if (Match == TRUE) {
*ppErrorString = CatSPrint(NULL, FORMAT_STR, InvalidSequences[IndexSeq].pErrString);
ReturnValue = FALSE;
break;
}
}
Finish:
return ReturnValue;
}
/*
* Attempt to match the input based on the targets
*/
EFI_STATUS MatchTargets(struct Command *pInputCmd, struct Command *pCmdToMatch)
{
EFI_STATUS ReturnCode = EFI_NOT_FOUND;
BOOLEAN MissingTargetValue = FALSE;
BOOLEAN RedundantTargetValue = FALSE;
BOOLEAN MissingRequiredTarget = FALSE;
BOOLEAN ExcessiveTarget = FALSE;
BOOLEAN Matched = FALSE;
UINT8 IndexInput = 0;
UINT8 IndexMatch = 0;
UINTN InputTargetNameLen = 0;
UINTN InputTargetValueLen = 0;
UINTN MatchTargetNameLen = 0;
CHAR16 *InputTargetName = NULL;
CHAR16 *MatchTargetName = NULL;
UINT8 RequiredTargetsAsFlags = 0;
UINT8 FoundTargetsAsFlags = 0;
// First find all required targets to match
for (IndexMatch = 0; IndexMatch < MAX_TARGETS; ++IndexMatch) {
if (pCmdToMatch->targets[IndexMatch].Required) {
RequiredTargetsAsFlags |= (1 << IndexMatch);
}
}
// Iterate all targets from input cmd
for (IndexInput = 0; IndexInput < MAX_TARGETS; ++IndexInput) {
InputTargetName = pInputCmd->targets[IndexInput].TargetName;
InputTargetNameLen = StrLen(InputTargetName);
if (InputTargetNameLen == 0) {
// All targets from Input was processed, quit from loop.
break;
}
Matched = FALSE;
// Iterate all targets from command to match
for (IndexMatch = 0; IndexMatch < MAX_TARGETS; ++IndexMatch) {
MatchTargetName = pCmdToMatch->targets[IndexMatch].TargetName;
MatchTargetNameLen = StrLen(MatchTargetName);
if (MatchTargetNameLen == 0) {
// All targets from Match processed, quit from inner loop.
break;
}
if (StrICmp(MatchTargetName, InputTargetName) == 0) {
// Matching target found, turn on flag
FoundTargetsAsFlags |= (1 << IndexMatch);
Matched = TRUE;
} else {
continue;
}
if (pInputCmd->ShowHelp == TRUE) {
continue;
}
// Get target value from user given cmd
InputTargetValueLen = StrLen(pInputCmd->targets[IndexInput].pTargetValueStr);
// Check target value if is missing or redundant:
if ((pCmdToMatch->targets[IndexMatch].ValueRequirement == ValueRequired) && InputTargetValueLen == 0) {
//If target value is required but empty print help for target
MissingTargetValue = TRUE;
SetDetailedSyntaxError(
CatSPrint(NULL, CLI_PARSER_DETAILED_ERR_TARGET_VALUE_REQUIRED, pInputCmd->targets[IndexInput].TargetName));
goto Finish;
} else if ((pCmdToMatch->targets[IndexMatch].ValueRequirement == ValueEmpty) && InputTargetValueLen != 0) {
RedundantTargetValue = TRUE;
SetDetailedSyntaxError(
CatSPrint(NULL, CLI_PARSER_DETAILED_ERR_TARGET_VALUE_UNEXPECTED, pInputCmd->targets[IndexInput].TargetName));
goto Finish;
}
}
if (Matched == FALSE){
// User target not found, command not matched.
ExcessiveTarget = TRUE;
goto Finish;
}
}
// Check if all required target has been found.
MissingRequiredTarget = (RequiredTargetsAsFlags & FoundTargetsAsFlags) != RequiredTargetsAsFlags;
Finish:
if (!MissingRequiredTarget && !ExcessiveTarget) {
// All required targets matched, now check Value errors.
if (MissingTargetValue || RedundantTargetValue) {
ReturnCode = EFI_INVALID_PARAMETER;
} else {
ReturnCode = EFI_SUCCESS; // All ok, matched target
}
} else {
//NVDIMM_WARN("Input don't match Command with ID=%d", pCmdToMatch->CommandId);
ReturnCode = EFI_NOT_FOUND;
}
return ReturnCode;
}
/*
* Attempt to match the input based on the properties
*/
EFI_STATUS MatchProperties(struct Command *pInput, struct Command *pMatch)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
BOOLEAN Matched = TRUE;
UINTN IndexInput = 0;
UINTN IndexMatch = 0;
BOOLEAN PropertyFound[MAX_PROPERTIES] = {FALSE};
UINT16 InputPropertyValueLen = 0;
for (IndexMatch = 0; IndexMatch < MAX_PROPERTIES && StrLen(pMatch->properties[IndexMatch].PropertyName) != 0; IndexMatch++) {
Matched = FALSE;
for (IndexInput = 0; IndexInput < MAX_PROPERTIES && StrLen(pInput->properties[IndexInput].PropertyName) != 0; IndexInput++) {
if (StrICmp(pMatch->properties[IndexMatch].PropertyName, pInput->properties[IndexInput].PropertyName) == 0) {
Matched = TRUE;
/* Get property value from user given cmd */
InputPropertyValueLen = (UINT16)StrLen(pInput->properties[IndexInput].PropertyValue);
/* Check property value if is missing or redundant */
if ((pMatch->properties[IndexMatch].ValueRequirement == ValueRequired) && InputPropertyValueLen == 0) {
SetDetailedSyntaxError(
CatSPrint(NULL, CLI_PARSER_DETAILED_ERR_PROPERTY_VALUE_REQUIRED, pInput->properties[IndexInput].PropertyName));
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
} else if ((pMatch->properties[IndexMatch].ValueRequirement == ValueEmpty) && InputPropertyValueLen != 0) {
SetDetailedSyntaxError(
CatSPrint(NULL, CLI_PARSER_DETAILED_ERR_PROPERTY_VALUE_UNEXPECTED, pInput->properties[IndexInput].PropertyName));
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
break;
}
}
if (!Matched && pMatch->properties[IndexMatch].Required) {
SetDetailedSyntaxError(
CatSPrint(NULL, CLI_PARSER_DETAILED_ERR_PROPERTY_REQUIRED, pMatch->properties[IndexMatch].PropertyName));
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
}
/* Looking for foreign and doubled properties */
for (IndexInput = 0; IndexInput < MAX_PROPERTIES && StrLen(pInput->properties[IndexInput].PropertyName) != 0 ; IndexInput++) {
Matched = FALSE;
for (IndexMatch = 0; IndexMatch < MAX_PROPERTIES && StrLen(pMatch->properties[IndexMatch].PropertyName) != 0; IndexMatch++) {
if ((StrICmp(pInput->properties[IndexInput].PropertyName, pMatch->properties[IndexMatch].PropertyName) == 0)
&& !PropertyFound[IndexMatch]) {
Matched = TRUE;
PropertyFound[IndexMatch] = TRUE;
break;
}
}
if (!Matched) {
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
}
Finish:
return ReturnCode;
}
/**
Get the help for a command read from the user.
@param[in] pCommand a pointer to the parsed struct Command.
@param[in] SingleCommand a BOOLEAN flag indicating if we are
trying to match to a single command help or to all commands
with the same verb.
@retval NULL if the command verb could not be matched to any
of the registered commands. Or the pointer to the help message.
NOTE: If the return pointer is not NULL, the caller is responsible
to free the memory using FreePool.
**/
CHAR16
*getCommandHelp(
IN struct Command *pCommand,
BOOLEAN SingleCommand
)
{
UINTN Index = 0;
UINTN Index2 = 0;
UINT16 CommandsToDisplay = 0;
UINT16 MatchingTargets = 0;
CHAR16 *pHelp = NULL;
NVDIMM_ENTRY();
//reset flags
for (Index = 0; Index < gCommandCount; Index++) {
gCommandList[Index].SyntaxErrorHelpNeeded = FALSE;
gCommandList[Index].VerbMatch = pCommand != NULL && StrICmp(pCommand->verb, gCommandList[Index].verb) == 0;
}
//locate which of the commands to display help for
if (TRUE == SingleCommand && pCommand != NULL) {
for (Index = 0; Index < gCommandCount; Index++) {
//don't bother with commands of a different verb
if (FALSE == gCommandList[Index].VerbMatch) {
continue;
}
//Exact matches are an immediate break for displaying that one command
if (EFI_SUCCESS == MatchCommand(pCommand, &gCommandList[Index])) {
for (Index2 = 0; Index2 < gCommandCount; Index2++) {
gCommandList[Index2].SyntaxErrorHelpNeeded = FALSE;
}
gCommandList[Index].SyntaxErrorHelpNeeded = TRUE;
CommandsToDisplay++;
break;
}
//if the caller has sent in a target, see if there is a partial match
MatchingTargets = TargetMatchCount(pCommand, &gCommandList[Index]);
if (MatchingTargets > 0) {
gCommandList[Index].SyntaxErrorHelpNeeded = TRUE;
CommandsToDisplay++;
}
}
//no matches = display them all
if (0 == CommandsToDisplay) {
for (Index = 0; Index < gCommandCount; Index++) {
//don't bother with commands of a different verb
if (FALSE == gCommandList[Index].VerbMatch) {
continue;
}
gCommandList[Index].SyntaxErrorHelpNeeded = TRUE;
}
}
}
for (Index = 0; Index < gCommandCount; Index++) {
/**
if the user wants help for a specific command
and it matches the verb, then continue to add the pHelp
**/
if (!gCommandList[Index].Hidden &&
((!SingleCommand && (pCommand == NULL || TRUE == gCommandList[Index].VerbMatch))))
{
/** full verb syntax with help string **/
if (pCommand == NULL || (pCommand != NULL && pCommand->ShowHelp == TRUE)) {
pHelp = CatSPrintClean(pHelp, L" " FORMAT_STR_NL, gCommandList[Index].pHelp);
pHelp = CatSPrintClean(pHelp, L" " FORMAT_STR_SPACE, gCommandList[Index].verb);
} else { /** syntax error help so just print syntax **/
pHelp = CatSPrintClean(pHelp, L" " FORMAT_STR_SPACE, gCommandList[Index].verb);
}
/* Only show the required fields*/
for (Index2 = 0; Index2 < MAX_OPTIONS; Index2++) {
if (StrLen(gCommandList[Index].options[Index2].OptionName) > 0) {
if (gCommandList[Index].options[Index2].Required) {
pHelp = CatSPrintClean(pHelp, FORMAT_STR_SPACE,
gCommandList[Index].options[Index2].OptionName);
if (StrLen(gCommandList[Index].options[Index2].pHelp) != 0) {
pHelp = CatSPrintClean(pHelp, L"(" FORMAT_STR_SPACE L")", gCommandList[Index].options[Index2].pHelp);
}
}
}
}
if (StrICmp(gCommandList[Index].verb, LOAD_VERB) == 0) {
pHelp = CatSPrintClean(pHelp, L"-source (filename) ");
}
else if (StrICmp(gCommandList[Index].verb, DUMP_VERB) == 0) {
pHelp = CatSPrintClean(pHelp, L"-destination (filename) ");
}
/* add the targets pHelp */
for (Index2 = 0; Index2 < MAX_TARGETS; Index2++)
{
if (StrLen(gCommandList[Index].targets[Index2].TargetName) > 0) {
if (!gCommandList[Index].targets[Index2].Required) {
pHelp = CatSPrintClean(pHelp, L"[");
}
pHelp = CatSPrintClean(pHelp, FORMAT_STR_SPACE,
gCommandList[Index].targets[Index2].TargetName);
if (NULL != gCommandList[Index].targets[Index2].pHelp && StrLen(gCommandList[Index].targets[Index2].pHelp) > 0) {
if (gCommandList[Index].targets[Index2].ValueRequirement == ValueOptional) {
pHelp = CatSPrintClean(pHelp, L"[" FORMAT_STR L"]",
gCommandList[Index].targets[Index2].pHelp);
} else {
pHelp = CatSPrintClean(pHelp, L"(" FORMAT_STR L")",
gCommandList[Index].targets[Index2].pHelp);
}
}
if (!gCommandList[Index].targets[Index2].Required) {
pHelp = CatSPrintClean(pHelp, L"]");
}
pHelp = CatSPrintClean(pHelp, L" ");
}
}
/* only show the properties that are required */
for (Index2 = 0; Index2 < MAX_PROPERTIES; Index2++) {
if(gCommandList[Index].properties[Index2].Required){
if (StrLen(gCommandList[Index].properties[Index2].PropertyName) > 0) {
pHelp = CatSPrintClean(pHelp, L" ");
pHelp = CatSPrintClean(pHelp, FORMAT_STR L"=(" FORMAT_STR L")",
gCommandList[Index].properties[Index2].PropertyName,
gCommandList[Index].properties[Index2].pHelp);
}
}
}
pHelp = CatSPrintClean(pHelp, L"\n\n");
}
else if (gCommandList[Index].SyntaxErrorHelpNeeded) {
/** full verb syntax with help string **/
if (NULL == pCommand || TRUE == SingleCommand || TRUE == pCommand->ShowHelp) {
pHelp = CatSPrintClean(pHelp, L" " FORMAT_STR_NL, gCommandList[Index].pHelp);
pHelp = CatSPrintClean(pHelp, L" " FORMAT_STR_SPACE, gCommandList[Index].verb);
}
else { /** syntax error help so just print syntax **/
pHelp = CatSPrintClean(pHelp, L" " FORMAT_STR_SPACE, gCommandList[Index].verb);
}
/* add the targets pHelp */
pHelp = CatSPrintClean(pHelp, L" [OPTIONS]");
/* Source and Destination are required for load and dump commands*/
if (StrICmp(gCommandList[Index].verb, LOAD_VERB) == 0) {
pHelp = CatSPrintClean(pHelp, L"-source (filename) ");
}
else if (StrICmp(gCommandList[Index].verb, DUMP_VERB) == 0) {
pHelp = CatSPrintClean(pHelp, L"-destination (filename) ");
}
for (Index2 = 0; Index2 < MAX_TARGETS; Index2++)
{
if (StrLen(gCommandList[Index].targets[Index2].TargetName) > 0) {
if (!gCommandList[Index].targets[Index2].Required) {
pHelp = CatSPrintClean(pHelp, L"[");
}
pHelp = CatSPrintClean(pHelp, L" "FORMAT_STR,
gCommandList[Index].targets[Index2].TargetName);
if (NULL != gCommandList[Index].targets[Index2].pHelp && StrLen(gCommandList[Index].targets[Index2].pHelp) > 0) {
if (gCommandList[Index].targets[Index2].ValueRequirement == ValueOptional) {
pHelp = CatSPrintClean(pHelp, L"[" FORMAT_STR L"]",
gCommandList[Index].targets[Index2].pHelp);
}
else {
pHelp = CatSPrintClean(pHelp, L" (" FORMAT_STR L")",
gCommandList[Index].targets[Index2].pHelp);
}
}
if (!gCommandList[Index].targets[Index2].Required) {
pHelp = CatSPrintClean(pHelp, L"]");
}
pHelp = CatSPrintClean(pHelp, L" ");
}
}
if (StrLen(gCommandList[Index].properties[0].PropertyName) > 0) {
pHelp = CatSPrintClean(pHelp, L"[PROPERTIES ...]");
}
/* add the options pHelp */
pHelp = CatSPrintClean(pHelp, L"\n\n[OPTIONS]");
pHelp = CatSPrintClean(pHelp, L"\n [-help|-h] : Display Help for the command");
for (Index2 = 0; Index2 < MAX_OPTIONS; Index2++) {
if (StrLen(gCommandList[Index].options[Index2].OptionName) > 0) {
if (!gCommandList[Index].options[Index2].Required) {
pHelp = CatSPrintClean(pHelp, L"\n [");
}
if (StrLen(gCommandList[Index].options[Index2].OptionNameShort) > 0) {
pHelp = CatSPrintClean(pHelp, FORMAT_STR L"|" FORMAT_STR,
gCommandList[Index].options[Index2].OptionName,
gCommandList[Index].options[Index2].OptionNameShort);
}
else {
pHelp = CatSPrintClean(pHelp, FORMAT_STR,
gCommandList[Index].options[Index2].OptionName);
}
if (StrLen(gCommandList[Index].options[Index2].pHelp) != 0) {
pHelp = CatSPrintClean(pHelp, L"(" FORMAT_STR L")", gCommandList[Index].options[Index2].pHelp);
}
if (!gCommandList[Index].options[Index2].Required) {
pHelp = CatSPrintClean(pHelp, L"] : ");
pHelp = CatSPrintClean(pHelp, FORMAT_STR, gCommandList[Index].options[Index2].pHelpDetails);
}
}
}
pHelp = CatSPrintClean(pHelp, L"\n");
/** add the properties pHelp **/
if (StrLen(gCommandList[Index].properties[0].PropertyName) > 0 ) {
pHelp = CatSPrintClean(pHelp, L"\n[PROPERTIES]");
}
for (Index2 = 0; Index2 < MAX_PROPERTIES; Index2++) {
if (StrLen(gCommandList[Index].properties[Index2].PropertyName) > 0) {
pHelp = CatSPrintClean(pHelp, L"\n ");
pHelp = CatSPrintClean(pHelp, FORMAT_STR L"=(" FORMAT_STR L")",
gCommandList[Index].properties[Index2].PropertyName,
gCommandList[Index].properties[Index2].pHelp);
}
pHelp = CatSPrintClean(pHelp, L" ");
}
pHelp = CatSPrintClean(pHelp, L"\n\n");
}
}
NVDIMM_EXIT();
return pHelp;
}
/**
Get the overall Help for User.
@retval NULL if the command verb could not be matched to any
of the registered commands. Or the pointer to the help message.
NOTE: If the return pointer is not NULL, the caller is responsible
to free the memory using FreePool.
**/
CHAR16
*getOverallCommandHelp()
{
UINTN Index = 0;
UINTN Index2 = 0;
CHAR16 *pHelp = NULL;
NVDIMM_ENTRY();
//check if the page break option exists
for (Index = 0; Index < gCommandCount; Index++) {
/**
Showing user Help for all the commands
This will be simplified not showing any command description
**/
/** full verb syntax **/
pHelp = CatSPrintClean(pHelp, L" " FORMAT_STR_NL, gCommandList[Index].pHelp);
pHelp = CatSPrintClean(pHelp, L" " FORMAT_STR_SPACE, gCommandList[Index].verb);
/* Only show the required fields for OPTIONS*/
for (Index2 = 0; Index2 < MAX_OPTIONS; Index2++) {
if (StrLen(gCommandList[Index].options[Index2].OptionName) > 0) {
if (gCommandList[Index].options[Index2].Required) {
pHelp = CatSPrintClean(pHelp, FORMAT_STR_SPACE,
gCommandList[Index].options[Index2].OptionName);
if (StrLen(gCommandList[Index].options[Index2].pHelp) != 0) {
pHelp = CatSPrintClean(pHelp, L"(" FORMAT_STR_SPACE L")", gCommandList[Index].options[Index2].pHelp);
}
}
}
}
/* add the Targets to pHelp */
if (gCommandList[Index].targets > 0) {
if (StrICmp(gCommandList[Index].verb, LOAD_VERB) == 0) {
pHelp = CatSPrintClean(pHelp, L"-source (filename) ");
}
else if (StrICmp(gCommandList[Index].verb, DUMP_VERB) == 0) {
pHelp = CatSPrintClean(pHelp, L"-destination (filename) ");
}
for (Index2 = 0; Index2 < MAX_TARGETS; Index2++) {
if (StrLen(gCommandList[Index].targets[Index2].TargetName)> 0) {
pHelp = CatSPrintClean(pHelp, FORMAT_STR,
gCommandList[Index].targets[Index2].TargetName);
if (NULL != gCommandList[Index].targets[Index2].pHelp
&& StrLen(gCommandList[Index].targets[Index2].pHelp) > 0) {
if (gCommandList[Index].targets[Index2].ValueRequirement == ValueOptional) {
pHelp = CatSPrintClean(pHelp, L"[" FORMAT_STR L"]",
gCommandList[Index].targets[Index2].pHelp);
} else {
pHelp = CatSPrintClean(pHelp, L"(" FORMAT_STR L")",
gCommandList[Index].targets[Index2].pHelp);
}
}
pHelp = CatSPrintClean(pHelp, L" ");
}
}
}
/* only show PROPERTIES that are required */
for (Index2 = 0; Index2 < MAX_PROPERTIES; Index2++) {
if (gCommandList[Index].properties[Index2].Required) {
if (StrLen(gCommandList[Index].properties[Index2].PropertyName) > 0) {
pHelp = CatSPrintClean(pHelp, L" ");
pHelp = CatSPrintClean(pHelp, FORMAT_STR L"=(" FORMAT_STR L")",
gCommandList[Index].properties[Index2].PropertyName,
gCommandList[Index].properties[Index2].pHelp);
}
}
}
pHelp = CatSPrintClean(pHelp, L"\n\n");
}
pHelp = CatSPrintClean(pHelp, L" Please see ipmctl -help i.e 'ipmctl show -help -dimm' for more information on specific command \n");
NVDIMM_EXIT();
return pHelp;
}
/**
Check if a specific property is found
@param[in] pCmd is a pointer to the struct Command that contains the user input.
@param[in] pProperty is a CHAR16 string that represents the property we want to find.
@retval EFI_SUCCESS if we've found the property.
@retval EFI_NOT_FOUND if no such property exists for the given pCmd.
@retval EFI_INVALID_PARAMETER if any of the parameters is a NULL.
**/
EFI_STATUS
ContainsProperty(
IN CONST struct Command *pCmd,
IN CONST CHAR16 *pProperty
)
{
EFI_STATUS ReturnCode = EFI_NOT_FOUND;
INT32 Index;
NVDIMM_ENTRY();
if (pCmd == NULL || pProperty == NULL) {
return EFI_INVALID_PARAMETER;
}
for (Index = 0; Index < MAX_PROPERTIES; Index++) {
if (StrICmp(pCmd->properties[Index].PropertyName, pProperty) == 0) {
ReturnCode = EFI_SUCCESS;
break;
}
}
NVDIMM_EXIT();
return ReturnCode;
}
/**
Get a specific property value
@param[in] pCmd is a pointer to the struct Command that .
@param[in] pProperty is a CHAR16 string that represents the property we want to find.
@param[out] ppReturnValue is a pointer to a pointer to the 16-bit character string
that will contain the return property value.
@retval EFI_SUCCESS if we've found the property and the value is set.
@retval EFI_NOT_FOUND if no such property exists for the given pCmd.
@retval EFI_INVALID_PARAMETER if any of the parameters is a NULL.
**/
EFI_STATUS
GetPropertyValue(
IN CONST struct Command *pCmd,
IN CONST CHAR16 *pProperty,
OUT CHAR16 **ppReturnValue
)
{
EFI_STATUS ReturnCode = EFI_NOT_FOUND;
INT32 Index;
NVDIMM_ENTRY();
if (pCmd == NULL || pProperty == NULL || ppReturnValue == NULL) {
return EFI_INVALID_PARAMETER;
}
*ppReturnValue = NULL;
for (Index = 0; Index < MAX_PROPERTIES; Index++) {
if (StrICmp(pCmd->properties[Index].PropertyName, pProperty) == 0) {
ReturnCode = EFI_SUCCESS;
*ppReturnValue = (CHAR16*)pCmd->properties[Index].PropertyValue;
break;
}
}
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Get the number of properties
@param[in] pCmd is a pointer to the struct Command that contains the user input.
@param[out] pPropertyCount represents the number of properties defined on the command line
@retval EFI_INVALID_PARAMETER if any of the parameters is a NULL.
@retval EFI_SUCCESS
**/
EFI_STATUS
GetPropertyCount(
IN CONST struct Command *pCmd,
IN UINT16 *pPropertyCount
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
INT32 Index;
NVDIMM_ENTRY();
if (pCmd == NULL || pPropertyCount == NULL) {
return EFI_INVALID_PARAMETER;
}
*pPropertyCount = 0;
for (Index = 0; Index < MAX_PROPERTIES; Index++) {
if (pCmd->properties[Index].PropertyName[0] != 0) {
*pPropertyCount += 1;
}
}
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/*
* Check if a specific option is found
*/
BOOLEAN containsOption(CONST struct Command *pCmd, CONST CHAR16 *option)
{
BOOLEAN found = FALSE;
INT32 i;
NVDIMM_ENTRY();
for (i = 0; i < MAX_OPTIONS; i++)
{
if (StrICmp(pCmd->options[i].OptionName, option) == 0 ||
StrICmp(pCmd->options[i].OptionNameShort, option) == 0)
{
found = TRUE;
break;
}
}
NVDIMM_EXIT();
return found;
}
/**
Check if a specific target is found in the command
@param[in] pCmd
@param[in] pTarget
@retval TRUE if the target has been found
@retval FALSE if the target has not been found
**/
BOOLEAN
ContainTarget(
IN CONST struct Command *pCmd,
IN CONST CHAR16 *pTarget
)
{
BOOLEAN Found = FALSE;
INT32 Index;
NVDIMM_ENTRY();
if (pCmd == NULL || pTarget == NULL) {
return Found;
}
for (Index = 0; Index < MAX_TARGETS; Index++) {
if (StrICmp(pCmd->targets[Index].TargetName, pTarget) == 0) {
Found = TRUE;
break;
}
}
NVDIMM_EXIT();
return Found;
}
/*
* Get the value of a specific option
*/
CHAR16* getOptionValue(CONST struct Command *pCmd,
CONST CHAR16 *option)
{
INT32 i;
CHAR16 *value = NULL;
NVDIMM_ENTRY();
for (i = 0; i < MAX_OPTIONS; i++)
{
if (StrICmp(pCmd->options[i].OptionName, option) == 0 ||
StrICmp(pCmd->options[i].OptionNameShort, option) == 0)
{
value = CatSPrint(NULL, FORMAT_STR, pCmd->options[i].pOptionValueStr);
break;
}
}
NVDIMM_EXIT();
return value;
}
/**
Get the value of a specific target
@param[in] pCmd
@param[in] pTarget
@retval the target value if the target has been found
@retval NULL otherwise
**/
CHAR16*
GetTargetValue(
IN struct Command *pCmd,
IN CONST CHAR16 *pTarget
)
{
INT32 Index;
CHAR16 *pValue = NULL;
NVDIMM_ENTRY();
if (pCmd == NULL || pTarget == NULL) {
return pValue;
}
for (Index = 0; Index < MAX_TARGETS; Index++) {
if (StrICmp(pCmd->targets[Index].TargetName, pTarget) == 0) {
pValue = pCmd->targets[Index].pTargetValueStr;
break;
}
}
NVDIMM_EXIT();
return pValue;
}
/*
* Determine if the specified value is in the specified comma
* separated display list.
*/
BOOLEAN ContainsValue(CONST CHAR16 *displayList,
CONST CHAR16 *value)
{
CHAR16 *tmpList;
CHAR16 *token;
BOOLEAN found = FALSE;
NVDIMM_ENTRY();
/* copy the input to a tmp var to avoid changing it */
tmpList = CatSPrint(NULL, FORMAT_STR, displayList);
if (tmpList)
{
token = StrTok(&tmpList, L',');
while (token && !found)
{
if (StrICmp(value, token) == 0)
{
found = TRUE;
}
FreePool(token);
token = StrTok(&tmpList, L',');
}
if (token)
{
FreePool(token);
}
if (tmpList)
{
FreePool(tmpList);
}
}
NVDIMM_EXIT();
return found;
}
BOOLEAN
ContainsCharacter(
IN CHAR16 Character,
IN CONST CHAR16* pInputString
)
{
UINT32 Length = 0;
UINT32 Index = 0;
if (pInputString == NULL) {
return FALSE;
}
Length = (UINT32)StrLen(pInputString);
for (Index=0; IndexpPrintCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_OPTION_UNITS);
goto Finish;
}
} else {
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
}
Finish:
FREE_POOL_SAFE(pOptionsValue);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Sets a display information needed when outputting alternative formats like XML.
@param[in] pName is a CHAR16 string that represents the output message.
@param[in] Type represents the type of output being displayed.
@param[in] pDelims is a CHAR16 string that represents delimiters to use when parsing text output
@retval EFI_SUCCESS if the name was copied correctly.
@retval EFI_INVALID_PARAMETER if any of the parameters is a NULL.
**/
EFI_STATUS
SetDisplayInfo(
IN CONST CHAR16 *pName,
IN CONST UINT8 Type,
IN CONST CHAR16 *pDelims
)
{
if (NULL == pName){
return EFI_INVALID_PARAMETER;
}
UnicodeSPrint(gDisplayInfo.Name, sizeof(gDisplayInfo.Name), FORMAT_STR, pName);
gDisplayInfo.Type = Type;
if(pDelims) {
UnicodeSPrint(gDisplayInfo.Delims, sizeof(gDisplayInfo.Delims), FORMAT_STR, pDelims);
}
else {
UnicodeSPrint(gDisplayInfo.Delims, sizeof(gDisplayInfo.Delims), L"");
}
return EFI_SUCCESS;
}
/**
Get display information needed when outputting alternative formats like XML.
@param[out] pName is a CHAR16 string that represents the output message.
@param[int] NameSize is the size of pName in bytes
@param[out] pType represents the type of output being displayed.
@param[out] pDelims represents the delimiters to use when parsing text output.
@param[int] DelimsSize is the size of pDelims in bytes
@retval EFI_SUCCESS if the name was copied correctly.
@retval EFI_INVALID_PARAMETER if any of the parameters is a NULL.
**/
EFI_STATUS
GetDisplayInfo(
OUT CHAR16 *pName,
IN CONST UINT32 NameSize,
OUT UINT8 *pType,
OUT CHAR16 *pDelims,
IN CONST UINT32 DelimsSize
)
{
if (NULL == pName || NULL == pType || NULL == pDelims){
return EFI_INVALID_PARAMETER;
}
UnicodeSPrint(pName, NameSize, FORMAT_STR, gDisplayInfo.Name);
UnicodeSPrint(pDelims, DelimsSize, FORMAT_STR, gDisplayInfo.Delims);
*pType = gDisplayInfo.Type;
return EFI_SUCCESS;
}
/**
Execute UpdateCmdCtx (if defined), run, and RunCleanup (if defined).
@param[in] pCommand pointer to the command structure
@retval EFI_SUCCESS if the name was copied correctly.
@retval EFI_INVALID_PARAMETER if any of the parameters is a NULL.
**/
EFI_STATUS
ExecuteCmd(COMMAND *pCommand) {
EFI_STATUS Rc = EFI_SUCCESS;
BOOLEAN CreatedPrintCtx = FALSE;
if (NULL == pCommand)
return EFI_INVALID_PARAMETER;
//Here to support migration path from legacy print handling and new printer module
if (pCommand->PrinterCtrlSupported) {
// create Printer Context if not given one to use
if (pCommand->pPrintCtx == NULL)
{
CreatedPrintCtx = TRUE;
if (EFI_SUCCESS != (Rc = PrinterCreateCtx(&pCommand->pPrintCtx))) {
return Rc;
}
if (EFI_SUCCESS != (Rc = ReadCmdLinePrintOptions(&pCommand->pPrintCtx->FormatType, pCommand))) {
goto Finish;
}
}
}
else {
//ensure printer ctx ptr is NULL
pCommand->pPrintCtx = NULL;
}
if (NULL == pCommand->run) {
Rc = EFI_INVALID_PARAMETER;
goto Finish;
}
Rc = pCommand->run(pCommand);
if (EFI_ERROR(Rc))
goto Finish;
Finish:
// clean up Printer context only if created in this routine call
if (CreatedPrintCtx == TRUE) {
PrinterDestroyCtx(pCommand->pPrintCtx);
}
return Rc;
}
EFI_STATUS ValidateProtocolAndPayloadSizeOptions(struct Command *pCmd)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
EFI_DCPMM_CONFIG_TRANSPORT_ATTRIBS Attribs;
if (NULL == pCmd) {
NVDIMM_CRIT("NULL input parameter.\n");
goto Finish;
}
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
if (containsOption(pCmd, PROTOCOL_OPTION_DDRT) && containsOption(pCmd, PROTOCOL_OPTION_SMBUS))
{
ReturnCode = EFI_INVALID_PARAMETER;
SetSyntaxError(CatSPrint(NULL, CLI_PARSER_ERR_MUTUALLY_EXCLUSIVE_OPTIONS, PROTOCOL_OPTION_DDRT, PROTOCOL_OPTION_SMBUS));
goto Finish;
}
else if (containsOption(pCmd, LARGE_PAYLOAD_OPTION) && containsOption(pCmd, SMALL_PAYLOAD_OPTION))
{
ReturnCode = EFI_INVALID_PARAMETER;
SetSyntaxError(CatSPrint(NULL, CLI_PARSER_ERR_MUTUALLY_EXCLUSIVE_OPTIONS, LARGE_PAYLOAD_OPTION, SMALL_PAYLOAD_OPTION));
goto Finish;
}
else if (containsOption(pCmd, PROTOCOL_OPTION_SMBUS) && containsOption(pCmd, LARGE_PAYLOAD_OPTION))
{
ReturnCode = EFI_INVALID_PARAMETER;
SetSyntaxError(CatSPrint(NULL, CLI_PARSER_ERR_MUTUALLY_EXCLUSIVE_OPTIONS, PROTOCOL_OPTION_SMBUS, LARGE_PAYLOAD_OPTION));
goto Finish;
}
ReturnCode = pNvmDimmConfigProtocol->GetFisTransportAttributes(pNvmDimmConfigProtocol, &Attribs);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
if (containsOption(pCmd, PROTOCOL_OPTION_DDRT)) {
Attribs.Protocol = FisTransportDdrt;
}
else if (containsOption(pCmd, PROTOCOL_OPTION_SMBUS)) {
// smbus requires small payload size
Attribs.Protocol = FisTransportSmbus;
Attribs.PayloadSize = FisTransportSizeSmallMb;
}
if (containsOption(pCmd, LARGE_PAYLOAD_OPTION)) {
// large payload implies ddrt (for now)
Attribs.Protocol = FisTransportDdrt;
Attribs.PayloadSize = FisTransportSizeLargeMb;
}
else if (containsOption(pCmd, SMALL_PAYLOAD_OPTION)) {
Attribs.PayloadSize = FisTransportSizeSmallMb;
}
ReturnCode = pNvmDimmConfigProtocol->SetFisTransportAttributes(pNvmDimmConfigProtocol, Attribs);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
Finish:
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("ValidateProtocolAndPayloadSizeOptions has returned error. Code " FORMAT_EFI_STATUS "\n", ReturnCode);
}
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/CommandParser.h 0000664 0000000 0000000 00000111031 14165347476 0020627 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _COMMAND_PARSER_H_
#define _COMMAND_PARSER_H_
#include
#include
#include
#include
#include
#define DISP_NAME_LEN 32 //!< Display string length (used when formatting output in alternative formats)
#define DISP_DELIMS_LEN 10 //!< Delimiter string length (used when formatting output in alternative formats)
#define VERB_LEN 16 //!< Verb string length
#define TARGET_LEN 32 //!< Target name string length
#define TARGET_VALUE_LEN 4096 //!< Target value string length for maximum-possible DIMM IDs
#define OPTION_LEN 16 //!< Option name string length
#define OPTION_VALUE_LEN 1024 //!< Option value string length
#define PARSER_OPTION_VALUE_LEN 2048 //!< Option value string length for command parser
#define PROPERTY_KEY_LEN 128 //!< Property name string length
#define PROPERTY_VALUE_LEN 128 //!< Property value string length
#define MAX_TARGETS 8 //!< Maximum number of targets in a single command
#define MAX_OPTIONS 12 //!< Maximum number of options in a single command
#define MAX_PROPERTIES 20 //!< Maximum number of properties in a single command
#define MAX_TOKENS 50 //!< Maximum number of tokens per line
/** command keywords **/
#define LOAD_VERB L"load"
#define HELP_VERB L"help"
#define VERSION_VERB L"version"
#define SHOW_VERB L"show"
#define SET_VERB L"set"
#define DELETE_VERB L"delete"
#define CREATE_VERB L"create"
#define DUMP_VERB L"dump"
#define START_VERB L"start"
#define STOP_VERB L"stop"
/** command options **/
#define ALL_OPTION L"-all" //!< 'all' option name
#define ALL_OPTION_SHORT L"-a" //!< 'all' option short form
#define ALL_OPTION_HELP L"Show all attributes" //!< 'all' option help text
#define DISPLAY_OPTION L"-display" //!< 'display' option name
#define DISPLAY_OPTION_SHORT L"-d" //!< 'display' option short form
#define DISPLAY_OPTION_HELP L"Show specific attributes" //!< 'display' option help text
#define HELP_OPTION L"-help" //!< 'help' option name
#define HELP_OPTION_SHORT L"-h" //!< 'help' option short form
#define SOURCE_OPTION L"-source" //!< 'source' option name
#define SOURCE_OPTION_HELP L"path" //!< 'source' option help text
#define DESTINATION_OPTION L"-destination"
#define DESTINATION_OPTION_HELP L"file"
#define DESTINATION_PREFIX_OPTION L"-destination"
#define DESTINATION_PREFIX_OPTION_HELP L"file_prefix (prefix for output files)"
#define DICTIONARY_OPTION L"-dict"
#define DICTIONARY_OPTION_HELP L"file"
#define EXAMINE_OPTION L"-examine" //!< 'examine' option name
#define EXAMINE_OPTION_SHORT L"-x" //!< 'examine' option short form
#define EXAMINE_OPTION_DETAILS_TEXT L"Test the provided firmware image for compatibility" //!< 'examine' option detailed help text
#define FORCE_OPTION L"-force" //!< 'force' option name
#define FORCE_OPTION_SHORT L"-f" //!< 'force' option short form
#define FORCE_OPTION_DETAILS_TEXT L"Suppress confirmations" //!< 'force' option help text detail
#define RECOVER_OPTION L"-recover" //!< 'recover' option name
#define RECOVER_OPTION_DETAILS_TEXT L"Run update on non-functional " PMEM_MODULES_STR L" only (deprecated)" //!< 'recover' option help text
#define UNITS_OPTION L"-units" //!< 'units' option name
#define UNITS_OPTION_B L"B" //!< 'units' option value for B
#define UNITS_OPTION_MB L"MB" //!< 'units' option value for MB
#define UNITS_OPTION_MIB L"MiB" //!< 'units' option value for MiB
#define UNITS_OPTION_GB L"GB" //!< 'units' option value for GB
#define UNITS_OPTION_GIB L"GiB" //!< 'units' option value for GiB
#define UNITS_OPTION_TB L"TB" //!< 'units' option value for TB
#define UNITS_OPTION_TIB L"TiB" //!< 'units' option value for TiB
#define UNITS_OPTION_HELP L"B|MB|MiB|GB|GiB|TB|TiB" //!< 'units' option help text
#define UNITS_OPTION_SHORT L"-u" //!< 'units' option short form
#define PROPERTY_VALUE_0_1_HELP L"0|1" //!< Property 0 or 1 value
#define PROPERTY_VALUE_NO_YES_IGN_HELP L"No|Yes|Ignore" //!< Property: No, Yes or Ignore
#define OUTPUT_OPTION_SHORT L"-o" //!< 'output' option name short form
#define OUTPUT_OPTION L"-output" //!< 'output' option
#define OUTPUT_OPTION_TEXT L"text" //!< 'output' option value for text
#define OUTPUT_OPTION_NVMXML L"nvmxml" //!< 'output' option value for nvmxml
#define OUTPUT_OPTION_ESX_XML L"esx" //!< 'output' option value for esx xml
#define OUTPUT_OPTION_ESX_TABLE_XML L"esxtable" //!< 'output' option value for esx xml
#define OUTPUT_OPTION_HELP L"text|nvmxml" //!< 'output' option help text
#define VERBOSE_OPTION_SHORT L"-v" //!< 'verbose' option short form
#define VERBOSE_OPTION L"-verbose" //!< 'verbose' option name
#define MASTER_OPTION L"-master" //!< 'master' option name
#define DEFAULT_OPTION L"-default" //!< 'default' option name
#define PBR_MODE_OPTION L"-mode" //!< 'mode' option name
#define PROTOCOL_OPTION_DDRT L"-ddrt" //!< 'ddrt' option name
#define PROTOCOL_OPTION_SMBUS L"-smbus" //!< 'smbus' option name
#define LARGE_PAYLOAD_OPTION L"-lpmb" //!< 'large payload mailbox' option name
#define SMALL_PAYLOAD_OPTION L"-spmb" //!< 'small payload mailbox' option name
#define NFIT_OPTION L"-nfit" //!< 'nfit' option name
/** command targets **/
#define DIMM_TARGET L"-dimm" //!< 'dimm' target name
#define REGION_TARGET L"-region" //!< 'region' target name
#define MEMORY_RESOURCES_TARGET L"-memoryresources" //!< 'memoryresources' target name
#define SYSTEM_TARGET L"-system" //!< 'system' target name
#define CAPABILITIES_TARGET L"-capabilities" //!< 'capabilities' target name
#define SOCKET_TARGET L"-socket" //!< 'socket' target name
#define GOAL_TARGET L"-goal" //!< 'goal' target name
#define CAP_TARGET L"-cap" //!< 'cap' target name
#define NAMESPACE_TARGET L"-namespace" //!< 'namespace' target name
#define HOST_TARGET L"-host" //!< 'host' target name
#define TOPOLOGY_TARGET L"-topology" //!< 'topology' target name
#define CONFIG_TARGET L"-config" //!< 'config' target name
#define SENSOR_TARGET L"-sensor" //!< 'sensor' target name
#define ERROR_TARGET L"-error" //!< 'error' target name
#define CEL_TARGET L"-cel" //!< 'cel' target name
#define DEBUG_TARGET L"-debug" //!< 'debug' target name
#define REGISTER_TARGET L"-register" //!< 'register' target name
#define FIRMWARE_TARGET L"-firmware" //!< 'firmware' target name
#define PCD_TARGET L"-pcd" //!< 'pcd' target name
#define SMBIOS_TARGET L"-smbios" ///< 'smbios' target name
#define SUPPORT_TARGET L"-support" //!< 'support' target name
#define CONTROLLER_TEMPERATURE_TARGET_VALUE L"ControllerTemperature" //!< 'sensor' target value
#define MEDIA_TEMPERATURE_TARGET_VALUE L"MediaTemperature" //!< 'sensor' target value
#define SPARE_CAPACITY_TARGET_VALUE L"PercentageRemaining" //!< 'sensor' target value
#define SENSOR_TARGETS \
L"MediaTemperature|ControllerTemperature|PercentageRemaining" //!< the sensors combined for the target message
#define DIAGNOSTIC_TARGET L"-diagnostic" //!< 'diagnostic' target name
#define ALL_TEST_TARGET_VALUE L"All" //!< 'diagnostic' target value
#define QUICK_TEST_TARGET_VALUE L"Quick" //!< 'diagnostic' target value
#define CONFIG_TEST_TARGET_VALUE L"Config" //!< 'diagnostic' target value
#define SECURITY_TEST_TARGET_VALUE L"Security" //!< 'diagnostic' target value
#define FW_TEST_TARGET_VALUE L"FW" //!< 'diagnostic' target value
#define ERROR_TARGET_THERMAL_VALUE L"Thermal" //!< 'error' target value
#define ERROR_TARGET_MEDIA_VALUE L"Media" //!< 'error' target value
#define ALL_DIAGNOSTICS_TARGETS L"Quick|Config|Security|FW" //!< diagnostics targets combined
#define PCD_CONFIG_TARGET_VALUE L"Config"
#define PCD_LSA_TARGET_VALUE L"LSA"
#define NFIT_TARGET_VALUE L"NFIT" //!< 'system' target value
#define PCAT_TARGET_VALUE L"PCAT" //!< 'system' target value
#define PMTT_TARGET_VALUE L"PMTT" //!< 'system' target value
#define SYSTEM_ACPI_TARGETS \
L"NFIT|PCAT|PMTT" //!< the system acpi combined
#define SMBIOS_TARGET_VALUES L"17" ///< 'smbios' target values
#define FORMAT_TARGET L"-format" //!< 'format' target value
#define PREFERENCES_TARGET L"-preferences" //!< 'preferences' target value
#define PERFORMANCE_TARGET L"-performance" //!< 'performance' target value
#define SESSION_TARGET L"-session" //!< 'session' target value
#define PBR_MODE_TARGET L"-mode" //!< 'mode' target value
#define PBR_RECORD_MODE_VAL L"record" //!< 'mode' target value
#define PBR_PLAYBACK_MODE_VAL L"playback" //!< 'mode' target value
#define PBR_PLAYBACK_MANUAL_MODE_VAL L"playback_manual" //!< 'mode' target value
#define PBR_MODE_TAG L"-tag" //!< 'tag' target value
/** Persistent memory type **/
#define PERSISTENT_MEM_TYPE_AD_STR L"AppDirect"
#define PERSISTENT_MEM_TYPE_AD_NI_STR L"AppDirectNotInterleaved"
/** command properties **/
#define TYPE_PROPERTY L"Type" //!< 'Type' property name
#define TYPE_VALUE_FW L"Fw" //!< 'Type' property FW value
#define TYPE_VALUE_TRAINING L"Training" //!< 'Type' property Training value
#define UPDATE_PROPERTY L"Update" //!< 'Update' property name
#define EXEC_PROPERTY L"Execute" //!< 'Exec' property name
#define TEMPERATURE_INJ_PROPERTY L"Temperature" //!< Inject error 'Temperature' property name
#define POISON_INJ_PROPERTY L"Poison" //!< Inject error 'Poison' property
#define POISON_TYPE_INJ_PROPERTY L"PoisonType" //!< Inject error 'PoisonType' property
#define CLEAR_ERROR_INJ_PROPERTY L"Clear" //!< Clear error injection property
#define PACKAGE_SPARING_INJ_PROPERTY L"PackageSparing" //!< PackageSparing error injection property
#define PERCENTAGE_REMAINING_INJ_PROPERTY L"PercentageRemaining" //!< PercentageRemaining error injection property
#define FATAL_MEDIA_ERROR_INJ_PROPERTY L"FatalMediaError" //!< FatalMediaError error injection property
#define DIRTY_SHUTDOWN_ERROR_INJ_PROPERTY L"DirtyShutdown" //!< DirtyShutdown error injection property
#define LOCKSTATE_PROPERTY L"LockState" //!< 'LockState' property name
#define LOCKSTATE_VALUE_ENABLED L"Enabled" //!< 'LockState' property Enabled value
#define LOCKSTATE_VALUE_DISABLED L"Disabled" //!< 'LockState' property Disabled value
#define LOCKSTATE_VALUE_UNLOCKED L"Unlocked" //!< 'LockState' property Unlocked value
#define LOCKSTATE_VALUE_FROZEN L"Frozen" //!< 'LockState' property Frozen value
#define CONFIG_STATUS_VALUE_VALID L"Valid" //!< 'ConfigStatus' property Valid value
#define CONFIG_STATUS_VALUE_NOT_CONFIG L"Not configured" //!< 'ConfigStatus' property Not Configured value
#define CONFIG_STATUS_VALUE_BAD_CONFIG L"Failed - Bad configuration" //!< 'ConfigStatus' property Bad Configuration value
#define CONFIG_STATUS_VALUE_BROKEN_INTERLEAVE L"Failed - Broken interleave" //!< 'ConfigStatus' property Broken Interleave value
#define CONFIG_STATUS_VALUE_REVERTED L"Failed - Reverted" //!< 'ConfigStatus' property Reverted value
#define CONFIG_STATUS_VALUE_UNSUPPORTED L"Failed - Unsupported" //!< 'ConfigStatus' property Unsupported value
#define CONFIG_STATUS_VALUE_PARTIALLY_SUPPORTED L"Failed - Partially supported" //!< 'ConfigStatus' property Partially Supported value
#define PASSPHRASE_PROPERTY L"Passphrase" //!< 'Passphrase' property name
#define NEWPASSPHRASE_PROPERTY L"NewPassphrase" //!< 'NewPassphrase' property name
#define CONFIRMPASSPHRASE_PROPERTY L"ConfirmPassphrase" //!< 'ConfirmPassphrase' property name
#define ALARM_THRESHOLD_PROPERTY L"AlarmThreshold" //!< 'AlarmThreshold' property
#define ALARM_ENABLED_PROPERTY L"AlarmEnabled" //!< 'AlarmEnabled' property
#define MEMORY_MODE_PROPERTY L"MemoryMode" //!< 'MemoryMode' property name
#define PERSISTENT_MEM_TYPE_PROPERTY L"PersistentMemoryType" //!< 'PersistentMemoryType' property name
#define MEMORY_SIZE_PROPERTY L"MemorySize" //!< 'MemorySize' property name
#define RESERVED_PROPERTY L"Reserved" //!< 'Reserved' property name
#define APPDIRECT_SIZE_PROPERTY L"AppDirectSize" //!< 'AppDirectSize' property name
#define APPDIRECT_INDEX_PROPERTY L"AppDirectIndex" //!< 'AppDirectIndex ' property name
#define APPDIRECT_1_SIZE_PROPERTY L"AppDirect1Size" //!< 'AppDirect1Size' property name
#define APPDIRECT_1_SETTINGS_PROPERTY L"AppDirect1Settings" //!< 'AppDirect1Setting' property name
#define APPDIRECT_1_INDEX_PROPERTY L"AppDirect1Index" //!< 'AppDirect1Index' property name
#define APPDIRECT_2_SIZE_PROPERTY L"AppDirect2Size" //!< 'AppDirect2Size' property name
#define APPDIRECT_2_SETTINGS_PROPERTY L"AppDirect2Settings" //!< 'AppDirect2Setting' property name
#define APPDIRECT_2_INDEX_PROPERTY L"AppDirect2Index" //!< 'AppDirect2Index' property name
#define MEM_INFO_PAGE_PROPERTY L"Page" //!< 'MemoryInfo page' property name
#define LOG_PROPERTY L"Log" //!< 'Log' property name
#define PROPERTY_VALUE_0 L"0" //!< Property 0 value
#define PROPERTY_VALUE_1 L"1" //!< Property 1 value
#define PROPERTY_VALUE_IGNORE L"Ignore" //!< Property 'Ignore' value
#define PROPERTY_VALUE_NO L"No" //!< Property 'No' value
#define PROPERTY_VALUE_YES L"Yes" //!< Property 'Yes' value
#define PROPERTY_VALUE_ENABLED L"Enabled" //!< Property enabled value
#define PROPERTY_VALUE_DISABLED L"Disabled" //!< Property disabled value
#define SEQUENCE_NUM_PROPERTY L"SequenceNumber" //!< 'error' property name
#define COUNT_PROPERTY L"Count" //!< 'error' property name
#define LEVEL_PROPERTY L"Level" //!< 'error' property name
#define LEVEL_HIGH_PROPERTY_VALUE L"High" //!< 'error' property 'Level' value
#define LEVEL_LOW_PROPERTY_VALUE L"Low" //!< 'error' property 'Level' value
#define NAMESPACE_ID_PROPERTY L"NamespaceId"
#define NAMESPACE_GUID_PROPERTY L"NamespaceGuid"
#define CAPACITY_PROPERTY L"Capacity"
#define NAME_PROPERTY L"Name"
#define HEALTH_PROPERTY L"HealthState"
#define REGION_ID_PROPERTY L"RegionID"
#define BLOCK_SIZE_PROPERTY L"BlockSize"
#define BLOCK_COUNT_PROPERTY L"BlockCount"
#define MODE_PROPERTY L"Mode"
#define PROPERTY_VALUE_NONE L"None"
#define PROPERTY_VALUE_SECTOR L"Sector"
#define AVG_PWR_REPORTING_TIME_CONSTANT L"AveragePowerReportingTimeConstant"
#define ACCESS_TYPE_PROPERTY L"AccessType"
#define ERASE_CAPABLE_PROPERTY L"EraseCapable"
#define ENCRYPTION_PROPERTY L"Encryption"
#define CLI_DEFAULT_DIMM_ID_PROPERTY L"CLI_DEFAULT_DIMM_ID"
#define CLI_DEFAULT_SIZE_PROPERTY L"CLI_DEFAULT_SIZE"
#define APP_DIRECT_SETTINGS_PROPERTY L"APPDIRECT_SETTINGS"
#define LABEL_VERSION_PROPERTY L"LabelVersion"
#define NS_LABEL_VERSION_PROPERTY L"NamespaceLabelVersion"
#define SEVERITY_PROPERTY L"Severity"
#define PROPERTY_VALUE_UID L"UID"
#define PROPERTY_VALUE_HANDLE L"HANDLE"
#define PROPERTY_VALUE_AUTO L"AUTO"
#define PROPERTY_VALUE_AUTO10 L"AUTO_10"
#define PROPERTY_VALUE_RECOMMENDED L"RECOMMENDED"
#define CATEGORY_PROPERTY L"Category"
#define DBG_LOG_LEVEL L"DBG_LOG_LEVEL"
#define CREATE_SUPP_NAME L"Name"
#define PROPERTY_ERROR_UNKNOWN L"Reason for failure unknown"
#define PROPERTY_ERROR_DEFAULT_DIMM_NOT_PROVIDED L"Default DimmID Type not provided"
#define PROPERTY_ERROR_INCORRECT_DEFAULT_DIMM_TYPE L"Incorrect default DimmID type"
#define PROPERTY_ERROR_DISPLAY_DEFAULT_NOT_PROVIDED L"Display default size type not provided"
#define PROPERTY_ERROR_DEFAULT_INCORRECT_SIZE_TYPE L"Incorrect default size type"
#define PROPERTY_ERROR_INTERLEAVE_TYPE_NOT_PROVIDED L"AppDirect interleave setting type not provided"
#define PROPERTY_ERROR_APPDIR_INTERLEAVE_TYPE L"Incorrect AppDirect interleave setting type"
#define PROPERTY_ERROR_GRANULARITY_NOT_PROVIDED L"AppDirect Granularity setting type not provided"
#define PROPERTY_ERROR_INVALID_GRANULARITY L"Invalid granularity"
#define PROPERTY_ERROR_INVALID_OUT_OF_RANGE L"Setting is invalid or out of range"
#define PROPERTY_ERROR_SET_FAILED_UNKNOWN L"Set operation failed"
/** Performance Metric Messages **/
#define DCPMM_PERFORMANCE_MEDIA_READS L"MediaReads"
#define DCPMM_PERFORMANCE_MEDIA_WRITES L"MediaWrites"
#define DCPMM_PERFORMANCE_READ_REQUESTS L"ReadRequests"
#define DCPMM_PERFORMANCE_WRITE_REQUESTS L"WriteRequests"
#define DCPMM_PERFORMANCE_TOTAL_MEDIA_READS L"TotalMediaReads"
#define DCPMM_PERFORMANCE_TOTAL_MEDIA_WRITES L"TotalMediaWrites"
#define DCPMM_PERFORMANCE_TOTAL_READ_REQUESTS L"TotalReadRequests"
#define DCPMM_PERFORMANCE_TOTAL_WRITE_REQUESTS L"TotalWriteRequests"
/** Sensor Detail Messages **/
#define DIMM_HEALTH_STR_DETAIL L"Health - The current " PMEM_MODULE_STR L" health as reported in the SMART log"
#define MEDIA_TEMPERATURE_STR_DETAIL L"MediaTemperature - The current " PMEM_MODULE_STR L" media temperature in Celsius"
#define CONTROLLER_TEMPERATURE_STR_DETAIL L"ControllerTemperature - The current " PMEM_MODULE_STR L" controller temperature in Celsius"
#define SPARE_CAPACITY_STR_DETAIL L"PercentageRemaining - Remaining " PMEM_MODULES_STR L" life as a percentage value of factory expected\
life spa"
#define LATCHED_DIRTY_SHUTDOWN_COUNT_STR_DETAIL L"LatchedDirtyShutdownCount - The number of shutdowns without notification over the lifetime of\
the " PMEM_MODULE_STR
#define UNLATCHED_DIRTY_SHUTDOWN_COUNT_STR_DETAIL L"UnlatchedDirtyShutdownCount - The number of shutdowns without notification over the lifetime of\
the " PMEM_MODULE_STR L"."
#define POWER_ON_TIME_STR_DETAIL L"PowerOnTime - The total power-on time over the lifetime of the " PMEM_MODULE_STR
#define UPTIME_STR_DETAIL L"UpTime - The total power-on time since the last power cycle of the " PMEM_MODULE_STR
#define POWER_CYCLES_STR_DETAIL L"PowerCycles - The number of power cycles over the lifetime of the " PMEM_MODULE_STR
#define FW_ERROR_COUNT_STR_DETAIL L"FwErrorCount - The total number of firmware error log entries"
/** common help messages **/
#define HELP_OPTIONS_DETAILS_TEXT L"Changes the output format."
#define HELP_VERBOSE_DETAILS_TEXT L"Change the Debug Level Message Display"
#define HELP_ALL_DETAILS_TEXT L"Shows all attributes."
#define HELP_DISPLAY_DETAILS_TEXT L"Shows attributes specified in a comma-separated list"
#define HELP_FORCE_DETAILS_TEXT L"Suppresses the confirmation from the User to use this operation"
#define HELP_UNIT_DETAILS_TEXT L"Desired Unit for display"
#define HELP_DDRT_DETAILS_TEXT L"Used to specify DDRT as the desired transport protocol"
#define HELP_SMBUS_DETAILS_TEXT L"Used to specify SMBUS as the desired transport protocol"
#define HELP_LPAYLOAD_DETAILS_TEXT L"Used to specify large transport payload size"
#define HELP_SPAYLOAD_DETAILS_TEXT L"Used to specify small transport payload size"
#define HELP_TEXT_DIMM_IDS L"DimmIDs"
#define HELP_TEXT_DIMM_ID L"DimmID"
#define HELP_TEXT_ATTRIBUTES L"Attributes"
#define HELP_TEXT_NAMESPACE_IDS L"NamespaceIDs"
#define HELP_TEXT_REGION_ID L"RegionID"
#define HELP_TEXT_REGION_IDS L"RegionIDs"
#define HELP_TEXT_SOCKET_IDS L"SocketIDs"
#define HELP_TEXT_SENSORS L"List of Sensors"
#define HELP_TEXT_VALUE L"value"
#define HELP_TEXT_COUNT L"count"
#define HELP_TEXT_GiB L"GiB"
#define HELP_TEXT_GB L"GB"
#define HELP_TEXT_STRING L"string"
#define HELP_TEXT_ERROR_LOG L"Thermal|Media"
#define HELP_TEXT_PERCENT L"0|%%"
#define HELP_TEXT_APPDIRECT_SETTINGS PROPERTY_VALUE_RECOMMENDED L"|" L"(IMCSize)_(ChannelSize)"
#define HELP_TEXT_NS_LABEL_VERSION L"1.1|1.2"
#define HELP_NFIT_DETAILS_TEXT L"Used to specify NFIT as the source"
#define HELP_TEXT_DEFAULT_SIZE PROPERTY_VALUE_AUTO L"|" \
PROPERTY_VALUE_AUTO10 L"|" \
UNITS_OPTION_B L"|" \
UNITS_OPTION_MB L"|" \
UNITS_OPTION_MIB L"|" \
UNITS_OPTION_GB L"|" \
UNITS_OPTION_GIB L"|" \
UNITS_OPTION_TB L"|" \
UNITS_OPTION_TIB
#define HELP_TEXT_PERSISTENT_MEM_TYPE L"AppDirect|AppDirectNotInterleaved"
#define HELP_DBG_LOG_LEVEL L"log level"
#define HELP_TEXT_PERFORMANCE_CAT L"Performance Metrics"
#define HELP_TEXT_AVG_PWR_REPORTING_TIME_CONSTANT_PROPERTY L"<100, 12000>"
#define HELP_TEXT_PERFORMANCE_CAT_DETAILS L"\n " DCPMM_PERFORMANCE_MEDIA_READS \
L"\n " DCPMM_PERFORMANCE_MEDIA_WRITES \
L"\n " DCPMM_PERFORMANCE_READ_REQUESTS \
L"\n " DCPMM_PERFORMANCE_WRITE_REQUESTS\
L"\n " DCPMM_PERFORMANCE_TOTAL_MEDIA_READS \
L"\n " DCPMM_PERFORMANCE_TOTAL_MEDIA_WRITES\
L"\n " DCPMM_PERFORMANCE_TOTAL_READ_REQUESTS\
L"\n " DCPMM_PERFORMANCE_TOTAL_WRITE_REQUESTS
#define HELP_TEXT_SENSORS_SHORT L"\n " MEDIA_TEMPERATURE_STR_DETAIL \
L"\n " CONTROLLER_TEMPERATURE_STR_DETAIL \
L"\n " SPARE_CAPACITY_STR_DETAIL
#define HELP_TEXT_SENSORS_ALL L"\n " DIMM_HEALTH_STR_DETAIL \
L"\n " MEDIA_TEMPERATURE_STR_DETAIL \
L"\n " CONTROLLER_TEMPERATURE_STR_DETAIL \
L"\n " SPARE_CAPACITY_STR_DETAIL \
L"\n " LATCHED_DIRTY_SHUTDOWN_COUNT_STR_DETAIL \
L"\n " UNLATCHED_DIRTY_SHUTDOWN_COUNT_STR_DETAIL \
L"\n " POWER_ON_TIME_STR_DETAIL \
L"\n " UPTIME_STR_DETAIL \
L"\n " POWER_CYCLES_STR_DETAIL \
L"\n " FW_ERROR_COUNT_STR_DETAIL
enum ValueRequirementType
{
ValueEmpty = 1,
ValueOptional = 2,
ValueRequired = 3
};
/**
Defines a single option of a CLI command
**/
struct option
{
CHAR16 OptionNameShort[OPTION_LEN];
CHAR16 OptionName[OPTION_LEN];
CHAR16 *pOptionValueStr;
CONST CHAR16 *pHelp;
CONST CHAR16 *pHelpDetails;
BOOLEAN Required;
UINT8 ValueRequirement;
};
/**
Defines a single target of a CLI command
**/
struct target
{
CHAR16 TargetName[TARGET_LEN];
CHAR16 *pTargetValueStr;
CONST CHAR16 *pHelp;
BOOLEAN Required;
UINT8 ValueRequirement;
};
/**
Defines a single property of a CLI command
**/
struct property
{
CHAR16 PropertyName[PROPERTY_KEY_LEN];
CHAR16 PropertyValue[PROPERTY_VALUE_LEN];
CONST CHAR16 *pHelp;
BOOLEAN Required;
UINT8 ValueRequirement;
};
enum DisplayType {
ResultsView = 0,
ListView = 1,
ListView2L = 2,
TableView = 3,
TableTabView = 4,
ErrorView = 5,
HelpView = 6,
DiagView = 7
};
/**
Defines the parts of a CLI command
**/
typedef
struct Command
{
CHAR16 verb[VERB_LEN];
struct option options[MAX_OPTIONS];
struct target targets[MAX_TARGETS];
struct property properties[MAX_PROPERTIES];
CONST CHAR16 *pHelp;
EFI_STATUS (*run)(struct Command *pCmd); //!< Execute the command
BOOLEAN PrinterCtrlSupported;
BOOLEAN ExcludeDriverBinding;
BOOLEAN Hidden; //!< Never print
BOOLEAN ShowHelp;
BOOLEAN SyntaxErrorHelpNeeded;
BOOLEAN VerbMatch;
UINT8 CommandId;
UINT8 DispType;
CHAR16 DispName[DISP_NAME_LEN];
PRINT_CONTEXT *pPrintCtx;
} COMMAND;
typedef
struct TargetsCombination
{
CHAR16 *pTargets[MAX_TARGETS];
CHAR16 *pErrString;
} TARGETS_COMBINATION;
typedef
struct CommandInput
{
UINT32 TokenCount;
CHAR16 **ppTokens;
} COMMAND_INPUT;
typedef
struct _DispInfo
{
CHAR16 Name[DISP_NAME_LEN];
UINT8 Type;
CHAR16 Delims[DISP_DELIMS_LEN];
}DispInfo;
extern DispInfo gDisplayInfo;
/**
Add the specified command to the list of supported commands
**/
EFI_STATUS RegisterCommand(struct Command *pCommand);
/**
Validate input targets combination
Function compares input targets with invalid sequences
@param[in] pInputTargets is a pointer to the list of input command targets
@param[out] ppErrorString is a pointer to a pointer to the return error message
@retval TRUE if input command targets does not match any known invalid combination
@retval FALSE if all targets matches to invalid combination
**/
BOOLEAN InputTargetsValid(struct target *pInputTargets, CHAR16 **ppErrorString);
/**
Free the allocated memory for target values
in the CLI command structure.
@param[in out] pCommand pointer to the command structure
**/
VOID
FreeCommandStructure(
IN OUT COMMAND *pCommand
);
/**
The function parse the input string and split it to the tokens
The caller function is responsible for deallocation of pCmdInput. The FreeCommandInput function should be
used to deallocate memory.
@param[in] pCommand The input string
@param[out] pCmdInput
**/
VOID
FillCommandInput(
IN CHAR16 *pCommand,
OUT struct CommandInput *pCmdInput
);
/**
Clean up the resources associated with the command list
**/
void FreeCommands();
/**
Clean up the resources associated with the input
**/
void FreeCommandInput(struct CommandInput *pCommandInput);
/**
Parse the given the command line arguments to
identify the correct command.
It is the responsibility of the caller function to free the allocated
memory for target values in the Command structure.
@param[in] the command input
@param[in,out] p_command
@return
The results of the command execution or a syntax error
**/
EFI_STATUS Parse(struct CommandInput *pInput, struct Command *pCommand);
/**
If parsing fails, retrieve a more useful syntax error
**/
CHAR16 *getSyntaxError();
/**
If parsing fails, set syntax error, but first free old one
**/
VOID SetSyntaxError(
IN CHAR16 *pSyntaxError
);
/**
Get the help for a command read from the user.
@param[in] pCommand a pointer to the parsed struct Command.
@param[in] SingleCommand a BOOLEAN flag indicating if we are
trying to match to a single command help or to all commands
with the same verb.
@retval NULL if the command verb could not be matched to any
of the registered commands. Or the pointer to the help message.
NOTE: If the return pointer is not NULL, the caller is responsible
to free the memory using FreePool.
**/
CHAR16
*getCommandHelp(
IN struct Command *pCommand,
BOOLEAN SingleCommand
);
CHAR16
*getOverallCommandHelp();
/**
Checks if the Unicode string contains the given character.
@param[in] Character is the 16-bit character that we are searching for.
@param[in] pInputString is the Unicode (16-bit) string that we want to check.
@retval TRUE if the input string contains the character we are searching for.
@retval FALSE if the character is not present in the string.
**/
BOOLEAN
ContainsCharacter(
IN CHAR16 Character,
IN CONST CHAR16* pInputString
);
/**
Get the number of properties
@param[in] pCmd is a pointer to the struct Command that contains the user input.
@param[out] pPropertyCount represents the number of properties defined on the command line
@retval EFI_INVALID_PARAMETER if any of the parameters is a NULL.
@retval EFI_SUCCESS
**/
EFI_STATUS
GetPropertyCount(
IN CONST struct Command *pCmd,
IN UINT16 *pPropertyCount
);
/**
Check if a specific property is found
@param[in] pCmd is a pointer to the struct Command that contains the user input.
@param[in] pProperty is a CHAR16 string that represents the property we want to find.
@retval EFI_SUCCESS if we've found the property.
@retval EFI_NOT_FOUND if no such property exists for the given pCmd.
@retval EFI_INVALID_PARAMETER if any of the parameters is a NULL.
**/
EFI_STATUS
ContainsProperty(
IN CONST struct Command *pCmd,
IN CONST CHAR16 *pProperty
);
/**
Get a specific property value
@param[in] pCmd is a pointer to the struct Command that contains the user input.
@param[in] pProperty is a CHAR16 string that represents the property we want to find.
@param[out] ppReturnValue is a pointer to a pointer to the 16-bit character string
that will contain the return property value.
@retval EFI_SUCCESS if we've found the property and the value is set.
@retval EFI_NOT_FOUND if no such property exists for the given pCmd.
@retval EFI_INVALID_PARAMETER if any of the parameters is a NULL.
**/
EFI_STATUS
GetPropertyValue(
IN CONST struct Command *pCmd,
IN CONST CHAR16 *pProperty,
OUT CHAR16 **ppReturnValue
);
/**
Check if a specific option is found
**/
BOOLEAN containsOption(CONST struct Command *pCmd, CONST CHAR16 *optionName);
/**
Check if a specific target is found in the command
@param[in] pCmd
@param[in] pTarget
@retval TRUE if the target has been found
@retval FALSE if the target has not been found
**/
BOOLEAN
ContainTarget(
IN CONST struct Command *pCmd,
IN CONST CHAR16 *pTarget
);
/**
Get the value of a specific option
NOTE: Returned value needs to be freed by the caller
**/
CHAR16 *getOptionValue(CONST struct Command *pCmd,
CONST CHAR16 *optionName);
/**
Get the value of a specific target
@param[in] pCmd
@param[in] pTarget
@retval the target value if the target has been found
@retval NULL otherwise
**/
CHAR16*
GetTargetValue(
IN struct Command *pCmd,
IN CONST CHAR16 *pTarget
);
/**
Determine if the specified value is in the specified comma
separated display list.
**/
BOOLEAN ContainsValue(CONST CHAR16 *displayList,
CONST CHAR16 *value);
/**
Get the value of the units option
@param[in] pCmd The input command structure
@param[out] pUnitsToDisplay Units to display based on input units option
@retval EFI_INVALID_PARAMETER if input parameter is NULL, else EFI_SUCCESS
**/
EFI_STATUS
GetUnitsOption(
IN CONST struct Command *pCmd,
OUT UINT16 *pUnitsToDisplay
);
/**
Sets a display information needed when outputting alternative formats like XML.
@param[in] pName is a CHAR16 string that represents the output message.
@param[in] Type represents the type of output being displayed.
@param[in] pDelims is a CHAR16 string that represents delimiters to use when parsing text output
@retval EFI_SUCCESS if the name was copied correctly.
@retval EFI_INVALID_PARAMETER if any of the parameters is a NULL.
**/
EFI_STATUS
SetDisplayInfo(
IN CONST CHAR16 *pName,
IN CONST UINT8 Type,
IN CONST CHAR16 *pDelims
);
/**
Get display information needed when outputting alternative formats like XML.
@param[out] pName is a CHAR16 string that represents the output message.
@param[int] NameSize is the size of pName in bytes
@param[out] pType represents the type of output being displayed.
@param[out] pDelims represents the delimiters to use when parsing text output.
@param[int] DelimsSize is the size of pDelims in bytes
@retval EFI_SUCCESS if the name was copied correctly.
@retval EFI_INVALID_PARAMETER if any of the parameters is a NULL.
**/
EFI_STATUS
GetDisplayInfo(
OUT CHAR16 *pName,
IN CONST UINT32 NameSize,
OUT UINT8 *pType,
OUT CHAR16 *pDelims,
IN CONST UINT32 DelimsSize
);
/**
Execute UpdateCmdCtx (if defined), run, and RunCleanup (if defined).
@param[in] pCommand pointer to the command structure
@retval EFI_SUCCESS if the name was copied correctly.
@retval EFI_INVALID_PARAMETER if any of the parameters is a NULL.
**/
EFI_STATUS
ExecuteCmd(COMMAND *pCommand);
#endif /** _COMMAND_PARSER_H_**/
ipmctl-03.00.00.0423/DcpmPkg/cli/Common.c 0000664 0000000 0000000 00000262160 14165347476 0017331 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include
#include "Common.h"
#include "NvmDimmCli.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#ifdef OS_BUILD
#include
#include
#endif
CONST CHAR16 *mpImcSize[] = {
L"Unknown",
L"64B",
L"128B",
L"256B",
L"4KB",
L"1GB"
};
CONST CHAR16 *mpChannelSize[] = {
L"Unknown",
L"64B",
L"128B",
L"256B",
L"4KB",
L"1GB"
};
typedef enum {
Unknown,
Interleave_64B,
Interleave_128B,
Interleave_256B,
Interleave_4KB,
Interleave_1GB
} InterleaveSizeIndex;
typedef enum {
ChannelWays_X1 = 1,
ChannelWays_X2 = 2,
ChannelWays_X3 = 3,
ChannelWays_X4 = 4,
ChannelWays_X6 = 6,
ChannelWays_X8 = 8,
ChannelWays_X12 = 12,
ChannelWays_X16 = 16,
ChannelWays_X24 = 24
} ChannelWaysNumber;
CONST CHAR16 *mpDefaultSizeStrs[DISPLAY_SIZE_MAX_SIZE] = {
PROPERTY_VALUE_AUTO,
PROPERTY_VALUE_AUTO10,
UNITS_OPTION_B,
UNITS_OPTION_MB,
UNITS_OPTION_MIB,
UNITS_OPTION_GB,
UNITS_OPTION_GIB,
UNITS_OPTION_TB,
UNITS_OPTION_TIB
};
CONST CHAR16 *mpDefaultDimmIds[DISPLAY_DIMM_ID_MAX_SIZE] = {
PROPERTY_VALUE_HANDLE,
PROPERTY_VALUE_UID,
};
/**
Compare DimmID field in DIMM_INFO Struct
@param[in] pFirst First item to compare
@param[in] pSecond Second item to compare
@retval -1 if first is less than second
@retval 0 if first is equal to second
@retval 1 if first is greater than second
**/
STATIC
INT32
CompareDimmIdInDimmInfo(
IN VOID *pFirst,
IN VOID *pSecond
)
{
DIMM_INFO *pDimmInfo = NULL;
DIMM_INFO *pDimmInfo2 = NULL;
if (pFirst == NULL || pSecond == NULL) {
NVDIMM_DBG("NULL pointer found.");
return 0;
}
pDimmInfo = (DIMM_INFO*)pFirst;
pDimmInfo2 = (DIMM_INFO*)pSecond;
if (pDimmInfo->DimmID < pDimmInfo2->DimmID) {
return -1;
}
else if (pDimmInfo->DimmID > pDimmInfo2->DimmID) {
return 1;
}
else {
return 0;
}
}
/**
Retrieve a populated array and count of DIMMs in the system. The caller is
responsible for freeing the returned array
@param[in] pNvmDimmConfigProtocol A pointer to the EFI_DCPMM_CONFIG2_PROTOCOL instance.
@param[in] pCmd A pointer to a COMMAND struct. Used to obtain the Printer context.
printed to stdout, otherwise will be directed to the printer module.
@param[in] dimmInfoCategories Categories that will be populated in
the DIMM_INFO struct.
@param[out] ppDimms A pointer to the dimm list found in NFIT.
@param[out] pDimmCount A pointer to the number of DIMMs found in NFIT.
@retval EFI_SUCCESS the dimm list was returned properly
@retval EFI_INVALID_PARAMETER one or more parameters are NULL
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_NOT_FOUND dimm not found
**/
EFI_STATUS
GetDimmList(
IN EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol,
IN struct Command *pCmd,
IN DIMM_INFO_CATEGORIES dimmInfoCategories,
OUT DIMM_INFO **ppDimms,
OUT UINT32 *pDimmCount
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
NVDIMM_ENTRY();
if (pNvmDimmConfigProtocol == NULL || ppDimms == NULL || pDimmCount == NULL || pCmd == NULL) {
NVDIMM_CRIT("NULL input parameter.\n");
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
ReturnCode = pNvmDimmConfigProtocol->GetDimmCount(pNvmDimmConfigProtocol, pDimmCount);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
NVDIMM_DBG("Failed on GetDimmCount.");
goto Finish;
}
if (*pDimmCount == 0) {
ReturnCode = EFI_NOT_FOUND;
goto Finish;
}
*ppDimms = AllocateZeroPool(sizeof(**ppDimms) * (*pDimmCount));
if (*ppDimms == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
/** retrieve the DIMM list **/
ReturnCode = pNvmDimmConfigProtocol->GetDimms(pNvmDimmConfigProtocol, *pDimmCount, dimmInfoCategories, *ppDimms);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
NVDIMM_DBG("Failed to retrieve the DIMM inventory");
goto FinishError;
}
ReturnCode = BubbleSort((VOID*)*ppDimms, *pDimmCount, sizeof(**ppDimms), CompareDimmIdInDimmInfo);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("Dimms list may not be sorted");
goto FinishError;
}
goto Finish;
FinishError:
FREE_POOL_SAFE(*ppDimms);
Finish:
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Retrieve a populated array and count of all DCPMMs (functional and non-functional)
in the system. The caller is responsible for freeing the returned array
@param[in] pNvmDimmConfigProtocol A pointer to the EFI_DCPMM_CONFIG2_PROTOCOL instance.
@param[in] pCmd A pointer to a COMMAND struct. Used to obtain the Printer context.
printed to stdout, otherwise will be directed to the printer module.
@param[in] dimmInfoCategories Categories that will be populated in
the DIMM_INFO struct.
@param[out] ppDimms A pointer to a combined DCPMM list (initialized and
uninitialized) from NFIT.
@param[out] pDimmCount A pointer to the total number of DCPMMs found in NFIT.
@retval EFI_SUCCESS the dimm list was returned properly
@retval EFI_INVALID_PARAMETER one or more parameters are NULL
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_NOT_FOUND dimm not found
**/
EFI_STATUS
GetAllDimmList(
IN EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol,
IN struct Command *pCmd,
IN DIMM_INFO_CATEGORIES dimmInfoCategories,
OUT DIMM_INFO **ppDimms,
OUT UINT32 *pDimmCount
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
UINT32 Index = 0;
UINT32 UninitializedDimmCount = 0;
UINT32 InitializedDimmCount = 0;
NVDIMM_ENTRY();
if (pNvmDimmConfigProtocol == NULL || ppDimms == NULL || pDimmCount == NULL || pCmd == NULL) {
NVDIMM_CRIT("NULL input parameter.\n");
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
ReturnCode = pNvmDimmConfigProtocol->GetDimmCount(pNvmDimmConfigProtocol, &InitializedDimmCount);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
NVDIMM_DBG("Failed on GetDimmCount.");
goto Finish;
}
ReturnCode = pNvmDimmConfigProtocol->GetUninitializedDimmCount(pNvmDimmConfigProtocol, &UninitializedDimmCount);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
if (0 == (InitializedDimmCount + UninitializedDimmCount)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_INFO_NO_DIMMS);
goto Finish;
}
*pDimmCount = InitializedDimmCount + UninitializedDimmCount;
*ppDimms = AllocateZeroPool(sizeof(**ppDimms) * (*pDimmCount));
if (*ppDimms == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
/** retrieve the DIMM list **/
ReturnCode = pNvmDimmConfigProtocol->GetDimms(pNvmDimmConfigProtocol, InitializedDimmCount, dimmInfoCategories, *ppDimms);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
NVDIMM_DBG("Failed to retrieve the DIMM inventory");
goto FinishError;
}
// Append the uninitialized dimms after the initialized dimms in the dimms array
ReturnCode = pNvmDimmConfigProtocol->GetUninitializedDimms(pNvmDimmConfigProtocol, UninitializedDimmCount, &((*ppDimms)[InitializedDimmCount]));
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
NVDIMM_WARN("Failed to retrieve the uninitialized DIMM inventory");
goto FinishError;
}
// Fill in the dimmInfoCategories for the uninitialized dimms
for (Index = InitializedDimmCount; Index < *pDimmCount; Index++) {
ReturnCode = pNvmDimmConfigProtocol->GetDimm(pNvmDimmConfigProtocol, (*ppDimms)[Index].DimmID,
dimmInfoCategories, &((*ppDimms)[Index]));
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
NVDIMM_WARN("Failed to populate the uninitialized DIMM inventory");
goto FinishError;
}
}
ReturnCode = BubbleSort((VOID*)*ppDimms, *pDimmCount, sizeof(**ppDimms), CompareDimmIdInDimmInfo);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("Dimms list may not be sorted");
goto FinishError;
}
goto Finish;
FinishError:
FREE_POOL_SAFE(*ppDimms);
Finish:
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Parse the string and return the array of unsigned integers
Example
String: "1,3,7"
Array[0]: 1
Array[1]: 3
Array[2]: 7
@param[in] pString string to parse
@param[out] ppUints allocated, filled array with the uints
@param[out] pUintsNum size of uints array
@retval EFI_SUCCESS
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_INVALID_PARAMETER the format of string is not proper
**/
EFI_STATUS
GetUintsFromString(
IN CHAR16 *pString,
OUT UINT16 **ppUints,
OUT UINT32 *pUintsNum
)
{
EFI_STATUS Rc = EFI_SUCCESS;
UINT32 Index = 0;
CHAR16 **ppUintsStr = NULL;
UINTN ParsedNumber = 0;
BOOLEAN IsNumber = FALSE;
NVDIMM_ENTRY();
if (pString == NULL || ppUints == NULL || pUintsNum == NULL) {
Rc = EFI_INVALID_PARAMETER;
goto Finish;
}
/**
No targets specified - select all targets (If value is required - command won't pass parsing process.)
**/
if (StrLen(pString) == 0) {
*ppUints = NULL;
*pUintsNum = 0;
Rc = EFI_SUCCESS;
goto Finish;
}
ppUintsStr = StrSplit(pString, L',', pUintsNum);
if (ppUintsStr == NULL) {
Rc = EFI_OUT_OF_RESOURCES;
goto Finish;
}
*ppUints = AllocateZeroPool(*pUintsNum * sizeof(**ppUints));
if (*ppUints == NULL) {
Rc = EFI_OUT_OF_RESOURCES;
goto FinishError;
}
for (Index = 0; Index < *pUintsNum; Index++) {
IsNumber = GetU64FromString(ppUintsStr[Index], &ParsedNumber);
if (!IsNumber) {
Rc = EFI_INVALID_PARAMETER;
goto FinishError;
}
(*ppUints)[Index] = (UINT16)ParsedNumber;
}
goto Finish;
FinishError:
FREE_POOL_SAFE(*ppUints);
Finish:
FreeStringArray(ppUintsStr, pUintsNum == NULL ? 0 : *pUintsNum);
NVDIMM_EXIT_I64(Rc);
return Rc;
}
/**
Parses the dimm target string (which can contain DimmIDs as NFIT handles and/or DimmUIDs),
and returns an array of DimmIDs in the SMBIOS physical-id forms.
Also checks for invalid DimmIDs and duplicate entries.
Example
String: "8089-00-0000-76543210,30,0x0022"
Array[0]: 28
Array[1]: 30
Array[2]: 34
@param[in] pCmd A pointer to a COMMAND struct. Used to obtain the Printer context.
@param[in] pDimmString The dimm target string to parse.
@param[in] pDimmInfo The dimm list found in NFIT.
@param[in] DimmCount Size of the pDimmInfo array.
@param[out] ppDimmIds Pointer to the array allocated and filled with the SMBIOS DimmIDs.
@param[out] pDimmIdsCount Size of the pDimmIds array.
@retval EFI_SUCCESS
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_INVALID_PARAMETER inputs are null, the format of string is not proper, duplicated Dimm IDs
@retval EFI_NOT_FOUND dimm not found
**/
EFI_STATUS
GetDimmIdsFromString(
IN struct Command *pCmd,
IN CHAR16 *pDimmString,
IN DIMM_INFO *pDimmInfo,
IN UINT32 DimmCount,
OUT UINT16 **ppDimmIds,
OUT UINT32 *pDimmIdsCount
)
{
EFI_STATUS Rc = EFI_SUCCESS;
CHAR16 **ppDimmIdTokensStr = NULL;
UINT32 *pParsedDimmIdNumber = NULL;
UINT64 DimmIdNumberTmp = 0;
BOOLEAN *pIsDimmIdNumber = NULL;
BOOLEAN DimmIdFound = FALSE;
UINT32 Index = 0;
UINT32 Index2 = 0;
NVDIMM_ENTRY();
if ((pDimmString == NULL) || (pDimmInfo == NULL) || (ppDimmIds == NULL) || (pDimmIdsCount == NULL) || (pCmd == NULL)) {
NVDIMM_CRIT("NULL input parameter.\n");
Rc = EFI_INVALID_PARAMETER;
goto Finish;
}
/**
No DIMM targets specified - select all targets (If value is required - command won't pass parsing process.)
**/
if (StrLen(pDimmString) == 0) {
*ppDimmIds = NULL;
*pDimmIdsCount = 0;
Rc = EFI_SUCCESS;
goto Finish;
}
ppDimmIdTokensStr = StrSplit(pDimmString, L',', pDimmIdsCount);
if (ppDimmIdTokensStr == NULL) {
Rc = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pCmd->pPrintCtx, Rc, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
*ppDimmIds = AllocateZeroPool(*pDimmIdsCount * sizeof(**ppDimmIds));
pParsedDimmIdNumber = AllocateZeroPool(*pDimmIdsCount * sizeof(*pParsedDimmIdNumber));
pIsDimmIdNumber = AllocateZeroPool(*pDimmIdsCount * sizeof(*pIsDimmIdNumber));
if ((*ppDimmIds == NULL) || (pParsedDimmIdNumber == NULL) || (pIsDimmIdNumber == NULL)) {
Rc = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pCmd->pPrintCtx, Rc, CLI_ERR_OUT_OF_MEMORY);
goto FinishError;
}
for (Index = 0; Index < *pDimmIdsCount; Index++) {
pIsDimmIdNumber[Index] = GetU64FromString(ppDimmIdTokensStr[Index], &DimmIdNumberTmp);
if ((pIsDimmIdNumber[Index]) && (DimmIdNumberTmp > MAX_UINT32)) {
Rc = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pCmd->pPrintCtx, Rc, L"DimmID size cannot exceed 32 bits. Invalid DimmID: " FORMAT_STR_NL, ppDimmIdTokensStr[Index]);
goto FinishError;
}
pParsedDimmIdNumber[Index] = (UINT32)DimmIdNumberTmp;
DimmIdNumberTmp = 0;
}
for (Index = 0; Index < *pDimmIdsCount; Index++) {
DimmIdFound = FALSE;
/**
Checking if the specified DIMMs exist
**/
for (Index2 = 0; Index2 < DimmCount; Index2++) {
if ((!pIsDimmIdNumber[Index] && StrICmp(ppDimmIdTokensStr[Index], pDimmInfo[Index2].DimmUid) == 0) ||
(pIsDimmIdNumber[Index] && pDimmInfo[Index2].DimmHandle == pParsedDimmIdNumber[Index]))
{
// This DimmID is unique for all dimms on the platform regardless of
// state and is assigned by UEFI FW. We use it for all our APIs.
// Handle seems to be a better identifier since it corresponds to the
// position on the board, but this is good enough and cheap to look up.
(*ppDimmIds)[Index] = pDimmInfo[Index2].DimmID;
DimmIdFound = TRUE;
break;
}
}
if (!DimmIdFound) {
Rc = EFI_NOT_FOUND;
PRINTER_SET_MSG(pCmd->pPrintCtx, Rc, PMEM_MODULE_STR L" not found. Invalid DimmID: " FORMAT_STR_NL, ppDimmIdTokensStr[Index]);
goto FinishError;
}
}
/**
Checking for duplicate entries
**/
for (Index = 0; Index < *pDimmIdsCount; Index++) {
for (Index2 = (Index + 1); Index2 < *pDimmIdsCount; Index2++) {
if ((*ppDimmIds)[Index] == (*ppDimmIds)[Index2]) {
Rc = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pCmd->pPrintCtx, Rc, L"Duplicated DimmID: " FORMAT_STR_NL, ppDimmIdTokensStr[Index2]);
goto FinishError;
}
}
}
goto Finish;
FinishError:
FREE_POOL_SAFE(*ppDimmIds);
Finish:
FreeStringArray(ppDimmIdTokensStr, pDimmIdsCount == NULL ? 0 : *pDimmIdsCount);
FREE_POOL_SAFE(pParsedDimmIdNumber);
FREE_POOL_SAFE(pIsDimmIdNumber);
NVDIMM_EXIT_I64(Rc);
return Rc;
}
/**
Parses the dimm target string (which can contain DimmIDs as SMBIOS type-17 handles and/or DimmUIDs),
and returns a DimmUid.
Example
String: "8089-00-0000-13325476" or "30" or "0x0022"
@param[in] pDimmString The dimm target string to parse.
@param[in] pDimmInfo The dimm list found in NFIT.
@param[in] DimmCount Size of the pDimmInfo array.
@param[out] pDimmUid Pointer to the NVM_UID buffer.
@retval EFI_SUCCESS
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_INVALID_PARAMETER the format of string is not proper
@retval EFI_NOT_FOUND dimm not found
**/
EFI_STATUS
GetDimmUidFromString(
IN CHAR16 *pDimmString,
IN DIMM_INFO *pDimmInfo,
IN UINT32 DimmCount,
OUT CHAR8 *pDimmUid
)
{
EFI_STATUS Rc = EFI_SUCCESS;
UINT32 ParsedDimmIdNumber;
UINT64 DimmIdNumberTmp = 0;
BOOLEAN IsDimmIdNumber;
BOOLEAN DimmIdFound = FALSE;
UINT32 Index = 0;
NVDIMM_ENTRY();
if ((pDimmString == NULL) || (pDimmInfo == NULL) || (pDimmUid == NULL)) {
NVDIMM_CRIT("NULL input parameter.\n");
Rc = EFI_INVALID_PARAMETER;
goto Finish;
}
/**
No DIMM targets specified - select all targets (If value is required - command won't pass parsing process.)
**/
if (StrLen(pDimmString) == 0) {
Rc = EFI_SUCCESS;
goto Finish;
}
IsDimmIdNumber = GetU64FromString(pDimmString, &DimmIdNumberTmp);
if ((IsDimmIdNumber) && (DimmIdNumberTmp > MAX_UINT32)) {
NVDIMM_DBG("DimmID size cannot exceed 32 bits.");
Rc = EFI_INVALID_PARAMETER;
goto Finish;
}
ParsedDimmIdNumber = (UINT32)DimmIdNumberTmp;
DimmIdNumberTmp = 0;
DimmIdFound = FALSE;
/**
Checking if the specified DIMMs exist
**/
for (Index = 0; Index < DimmCount; Index++) {
if ((!IsDimmIdNumber && StrICmp(pDimmString, pDimmInfo[Index].DimmUid) == 0) ||
(IsDimmIdNumber && pDimmInfo[Index].DimmHandle == ParsedDimmIdNumber))
{
UnicodeStrToAsciiStrS(pDimmInfo[Index].DimmUid, pDimmUid, MAX_DIMM_UID_LENGTH);
DimmIdFound = TRUE;
break;
}
}
if (!DimmIdFound) {
Rc = EFI_NOT_FOUND;
NVDIMM_DBG("DIMM not found.");
}
Finish:
NVDIMM_EXIT_I64(Rc);
return Rc;
}
/**
Check if the uint is in the uints array
@param[in] pUints array of the uints
@param[in] UintsNum number of uints in the array
@param[in] UintToFind searched uint
@retval TRUE if the uint has been found
@retval FALSE if the uint has not been found
**/
BOOLEAN
ContainUint(
IN UINT16 *pUints,
IN UINT32 UintsNum,
IN UINT16 UintToFind
)
{
UINT32 Index;
BOOLEAN ReturnCode = FALSE;
NVDIMM_ENTRY();
if (pUints == NULL) {
ReturnCode = FALSE;
goto Finish;
}
for (Index = 0; Index < UintsNum; Index++) {
if (pUints[Index] == UintToFind) {
ReturnCode = TRUE;
goto Finish;
}
}
Finish:
NVDIMM_EXIT_I64(ReturnCode ? EFI_SUCCESS : EFI_ABORTED);
return ReturnCode;
}
/**
Check if the Guid is in the Guids array
@param[in] ppGuids array of the Guid pointers
@param[in] GuidsNum number of Guids in the array
@param[in] pGuidToFind pointer to GUID with information to find
@retval TRUE if table contains guid with same data as *pGuidToFind
@retval FALSE
**/
BOOLEAN
ContainGuid(
IN GUID **ppGuids,
IN UINT32 GuidsNum,
IN GUID *pGuidToFind
)
{
UINT32 Index;
BOOLEAN ReturnCode = FALSE;
NVDIMM_ENTRY();
if (ppGuids == NULL || pGuidToFind == NULL) {
ReturnCode = FALSE;
goto Finish;
}
for (Index = 0; Index < GuidsNum; Index++) {
if (CompareMem(ppGuids[Index], pGuidToFind, sizeof(GUID)) == 0) {
ReturnCode = TRUE;
goto Finish;
}
}
Finish:
NVDIMM_EXIT_I64(ReturnCode ? EFI_SUCCESS : EFI_ABORTED);
return ReturnCode;
}
/**
Gets number of Manageable and supported Dimms and their IDs
@param[in] pNvmDimmConfigProtocol A pointer to the EFI_DCPMM_CONFIG2_PROTOCOL instance.
@param[in] CheckSupportedConfigDimm If true, include dimms in unmapped set of dimms (non-POR) in
returned dimm list. If false, skip these dimms from returned list.
@param[out] DimmIdsCount is the pointer to variable, where number of dimms will be stored.
@param[out] ppDimmIds is the pointer to variable, where IDs of dimms will be stored.
@retval EFI_NOT_FOUND if the connection with NvmDimmProtocol can't be established
@retval EFI_OUT_OF_RESOURCES if the memory allocation fails.
@retval EFI_INVALID_PARAMETER if number of dimms or dimm IDs have not been assigned properly.
@retval EFI_SUCCESS if successfully assigned number of dimms and IDs to variables.
**/
EFI_STATUS
GetManageableDimmsNumberAndId(
IN EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol,
IN BOOLEAN CheckSupportedConfigDimm,
OUT UINT32 *pDimmIdsCount,
OUT UINT16 **ppDimmIds
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
DIMM_INFO *pDimms = NULL;
UINT16 Index = 0;
UINT16 NewListIndex = 0;
NVDIMM_ENTRY();
if (pDimmIdsCount == NULL || ppDimmIds == NULL || pNvmDimmConfigProtocol == NULL) {
NVDIMM_CRIT("NULL input parameter.\n");
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
ReturnCode = pNvmDimmConfigProtocol->GetDimmCount(pNvmDimmConfigProtocol, pDimmIdsCount);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_ERR("Error: Communication with the device driver failed.");
goto Finish;
}
pDimms = AllocateZeroPool(sizeof(*pDimms) * (*pDimmIdsCount));
*ppDimmIds = AllocateZeroPool(sizeof(**ppDimmIds) * (*pDimmIdsCount));
if (pDimms == NULL || *ppDimmIds == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
NVDIMM_ERR("Error: Out of memory\n");
goto Finish;
}
ReturnCode = pNvmDimmConfigProtocol->GetDimms(pNvmDimmConfigProtocol, *pDimmIdsCount, DIMM_INFO_CATEGORY_NONE, pDimms);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_ERR("Failed to retrieve the DIMM inventory found in NFIT");
goto Finish;
}
for (Index = 0; Index < *pDimmIdsCount; Index++) {
if ((!CheckSupportedConfigDimm && (pDimms[Index].ManageabilityState == MANAGEMENT_VALID_CONFIG))
||((CheckSupportedConfigDimm && !pDimms[Index].IsInPopulationViolation)
&& pDimms[Index].ManageabilityState == MANAGEMENT_VALID_CONFIG)){
(*ppDimmIds)[NewListIndex] = pDimms[Index].DimmID;
NewListIndex++;
}
}
*pDimmIdsCount = NewListIndex;
if (NewListIndex == 0) {
ReturnCode = NVM_ERR_MANAGEABLE_DIMM_NOT_FOUND;
goto Finish;
}
ReturnCode = EFI_SUCCESS;
Finish:
FREE_POOL_SAFE(pDimms);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Gets number of Manageable (functional and non-functional) and supported Dimms and their IDs
@param[in] pNvmDimmConfigProtocol A pointer to the EFI_DCPMM_CONFIG2_PROTOCOL instance.
@param[in] CheckSupportedConfigDimm If true, include dimms in unmapped set of dimms (non-POR) in
returned dimm list. If false, skip these dimms from returned list.
@param[out] DimmIdsCount is the pointer to variable, where number of dimms will be stored.
@param[out] ppDimmIds is the pointer to variable, where IDs of dimms will be stored.
@retval EFI_NOT_FOUND if the connection with NvmDimmProtocol can't be established
@retval EFI_OUT_OF_RESOURCES if the memory allocation fails.
@retval EFI_INVALID_PARAMETER if number of dimms or dimm IDs have not been assigned properly.
@retval EFI_SUCCESS if successfully assigned number of dimms and IDs to variables.
**/
EFI_STATUS
GetAllManageableDimmsNumberAndId(
IN EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol,
IN BOOLEAN CheckSupportedConfigDimm,
OUT UINT32 *pDimmIdsCount,
OUT UINT16 **ppDimmIds
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
DIMM_INFO *pDimms = NULL;
UINT32 Index = 0;
UINT32 NewListIndex = 0;
UINT32 UninitializedDimmCount = 0;
UINT32 InitializedDimmCount = 0;
NVDIMM_ENTRY();
if (pDimmIdsCount == NULL || ppDimmIds == NULL || pNvmDimmConfigProtocol == NULL) {
NVDIMM_CRIT("NULL input parameter.\n");
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
ReturnCode = pNvmDimmConfigProtocol->GetDimmCount(pNvmDimmConfigProtocol, &InitializedDimmCount);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_ERR("Error: Communication with the device driver failed.");
goto Finish;
}
ReturnCode = pNvmDimmConfigProtocol->GetUninitializedDimmCount(pNvmDimmConfigProtocol, &UninitializedDimmCount);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_ERR("Error: Communication with the device driver failed.");
goto Finish;
}
if (0 == (InitializedDimmCount + UninitializedDimmCount)) {
ReturnCode = EFI_NOT_FOUND;
goto Finish;
}
*pDimmIdsCount = InitializedDimmCount + UninitializedDimmCount;
pDimms = AllocateZeroPool(sizeof(*pDimms) * (*pDimmIdsCount));
*ppDimmIds = AllocateZeroPool(sizeof(**ppDimmIds) * (*pDimmIdsCount));
if (pDimms == NULL || *ppDimmIds == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
NVDIMM_ERR("Error: Out of memory\n");
goto Finish;
}
ReturnCode = pNvmDimmConfigProtocol->GetDimms(pNvmDimmConfigProtocol, *pDimmIdsCount, DIMM_INFO_CATEGORY_NONE, pDimms);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_ERR("Failed to retrieve the DIMM inventory found in NFIT");
goto Finish;
}
// Append the uninitialized dimms after the initialized dimms in the dimms array
ReturnCode = pNvmDimmConfigProtocol->GetUninitializedDimms(pNvmDimmConfigProtocol, UninitializedDimmCount, &((pDimms)[InitializedDimmCount]));
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Failed to retrieve the uninitialized DIMM inventory");
goto Finish;
}
// Fill in the dimmInfoCategories for the uninitialized dimms
for (Index = InitializedDimmCount; Index < *pDimmIdsCount; Index++) {
ReturnCode = pNvmDimmConfigProtocol->GetDimm(pNvmDimmConfigProtocol, (pDimms)[Index].DimmID,
DIMM_INFO_CATEGORY_NONE, &((pDimms)[Index]));
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Failed to populate the uninitialized DIMM inventory");
goto Finish;
}
}
ReturnCode = BubbleSort((VOID*)pDimms, *pDimmIdsCount, sizeof(*pDimms), CompareDimmIdInDimmInfo);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("Dimms list may not be sorted");
goto Finish;
}
for (Index = 0; Index < *pDimmIdsCount; Index++) {
if ((!CheckSupportedConfigDimm && (pDimms[Index].ManageabilityState == MANAGEMENT_VALID_CONFIG))
|| ((CheckSupportedConfigDimm && !pDimms[Index].IsInPopulationViolation)
&& pDimms[Index].ManageabilityState == MANAGEMENT_VALID_CONFIG)) {
(*ppDimmIds)[NewListIndex] = pDimms[Index].DimmID;
NewListIndex++;
}
}
*pDimmIdsCount = NewListIndex;
if (NewListIndex == 0) {
ReturnCode = NVM_ERR_MANAGEABLE_DIMM_NOT_FOUND;
goto Finish;
}
ReturnCode = EFI_SUCCESS;
Finish:
FREE_POOL_SAFE(pDimms);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Checks if the provided display list string contains only the valid values.
@param[in] pDisplayValues pointer to the Unicode string containing the user
input display list.
@param[in] ppAllowedDisplayValues pointer to an array of Unicode strings
that define the valid display values.
@param[in] Count is the number of valid display values in ppAllowedDisplayValues.
@retval EFI_SUCCESS if all of the provided display values are valid.
@retval EFI_OUT_OF_RESOURCES if the memory allocation fails.
@retval EFI_INVALID_PARAMETER if one or more of the provided display values
is not a valid one. Or if pDisplayValues or ppAllowedDisplayValues is NULL.
**/
EFI_STATUS
CheckDisplayList(
IN CHAR16 *pDisplayValues,
IN CHAR16 **ppAllowedDisplayValues,
IN UINT16 Count
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
CHAR16 **ppSplitDisplayValues = NULL;
UINT32 SplitDisplayValuesSize = 0;
UINT32 Index = 0;
UINT32 Index2 = 0;
BOOLEAN CorrectDisplayValue = FALSE;
NVDIMM_ENTRY();
if (pDisplayValues == NULL || ppAllowedDisplayValues == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
ppSplitDisplayValues = StrSplit(pDisplayValues, L',', &SplitDisplayValuesSize);
if (ppSplitDisplayValues == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
goto Finish;
}
for (Index = 0; Index < SplitDisplayValuesSize; Index++) {
CorrectDisplayValue = FALSE;
for (Index2 = 0; Index2 < Count; Index2++) { // Check through all of the valid values
if (StrICmp(ppSplitDisplayValues[Index], ppAllowedDisplayValues[Index2]) == 0) {
CorrectDisplayValue = TRUE; // This value is allowed
break; // If we find a match, leave the loop
}
}
if (!CorrectDisplayValue) { // If this value is not allowed, set the return code.
ReturnCode = EFI_INVALID_PARAMETER;
}
}
FreeStringArray(ppSplitDisplayValues, SplitDisplayValuesSize);
Finish:
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Checks if user has specified the options -a|-all and -d|-display.
Those two flags exclude each other so the function also checks
if the user didn't provide them both.
If the -d|-display option has been found, the its values are checked
against the allowed values for this parameter.
@param[in] pCommand is the pointer to a Command structure that is tested
for the options presence.
@param[in] ppAllowedDisplayValues is a pointer to an array of Unicode
strings considered as the valid values for the -d|-display option.
@param[in] AllowedDisplayValuesCount is a UINT32 value that represents
the number of elements in the array pointed by ppAllowedDisplayValues.
@param[out] pDispOptions contains the following.
A BOOLEAN value that will
represent the presence of the -a|-all option in the Command pointed
by pCommand.
A BOOLEAN value that will
represent the presence of the -d|-display option in the Command pointed
by pCommand.
A pointer to an Unicode string. If the -d|-display option is present, this pointer will
be set to the option value Unicode string.
@retval EFI_SUCCESS the check went fine, there were no errors
@retval EFI_INVALID_PARAMETER if the user provided both options,
the display option has been provided and has some invalid values or
if at least one of the input pointer parameters is NULL.
@retval EFI_OUT_OF_RESOURCES if the memory allocation fails.
**/
EFI_STATUS
CheckAllAndDisplayOptions(
IN struct Command *pCommand,
IN CHAR16 **ppAllowedDisplayValues,
IN UINT32 AllowedDisplayValuesCount,
OUT CMD_DISPLAY_OPTIONS *pDispOptions
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
CHAR16 *pDisplayValues = NULL;
NVDIMM_ENTRY();
if (pDispOptions == NULL || ppAllowedDisplayValues == NULL || pCommand == NULL) {
NVDIMM_CRIT("NULL input parameter.\n");
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
/** if the all option was specified **/
if (containsOption(pCommand, ALL_OPTION) || containsOption(pCommand, ALL_OPTION_SHORT)) {
pDispOptions->AllOptionSet = TRUE;
}
/** if the display option was specified **/
pDisplayValues = getOptionValue(pCommand, DISPLAY_OPTION);
if (pDisplayValues) {
pDispOptions->DisplayOptionSet = TRUE;
}
else {
pDisplayValues = getOptionValue(pCommand, DISPLAY_OPTION_SHORT);
if (pDisplayValues) {
pDispOptions->DisplayOptionSet = TRUE;
}
}
pDispOptions->pDisplayValues = pDisplayValues;
/** make sure they didn't specify both the all and display options **/
if (pDispOptions->AllOptionSet && pDispOptions->DisplayOptionSet) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pCommand->pPrintCtx, ReturnCode, CLI_ERR_OPTIONS_ALL_DISPLAY_USED_TOGETHER);
goto Finish;
}
/** Check that the display parameters are correct (if display option is set) **/
if (pDispOptions->DisplayOptionSet) {
ReturnCode = CheckDisplayList(pDisplayValues, ppAllowedDisplayValues,
(UINT16)AllowedDisplayValuesCount);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pCommand->pPrintCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_OPTION_DISPLAY);
}
}
/** Set the text output type (table vs. list view) **/
if(pCommand->pPrintCtx && pCommand->PrinterCtrlSupported == TRUE) {
if (!(pDispOptions->AllOptionSet) && !(pDispOptions->DisplayOptionSet)) {
PRINTER_ENABLE_TEXT_TABLE_FORMAT(pCommand->pPrintCtx);
}
else {
PRINTER_ENABLE_LIST_TABLE_FORMAT(pCommand->pPrintCtx);
}
}
Finish:
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Retrieve property by name and assign its value to UINT64.
@param[in] pCmd Command containing the property
@param[in] pPropertyName String with property name
@param[out] pOutValue target UINT64 value
@retval FALSE if there was no such property or it doesn't contain
a valid value
**/
BOOLEAN
PropertyToUint64(
IN struct Command *pCmd,
IN CHAR16 *pPropertyName,
OUT UINT64 *pOutValue
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
BOOLEAN IsValid = FALSE;
CHAR16 *pStringValue = NULL;
ReturnCode = GetPropertyValue(pCmd, pPropertyName, &pStringValue);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
IsValid = GetU64FromString(pStringValue, pOutValue);
Finish:
return IsValid;
}
/**
Retrieve property by name and assign its value to double
@param[in] pCmd Command containing the property
@param[in] pPropertyName String with property name
@param[out] pOutValue Target double value
@retval EFI_INVALID_PARAMETER Property not found or no valid value inside
@retval EFI_SUCCESS Conversion successful
**/
EFI_STATUS
PropertyToDouble(
IN struct Command *pCmd,
IN CHAR16 *pPropertyName,
OUT double *pOutValue
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
CHAR16 *pPropertyValue = NULL;
if (pCmd == NULL || pPropertyName == NULL || pOutValue == NULL) {
goto Finish;
}
ReturnCode = GetPropertyValue(pCmd, pPropertyName, &pPropertyValue);
if (EFI_ERROR(ReturnCode) || pPropertyValue == NULL) {
goto Finish;
}
ReturnCode = StringToDouble(gNvmDimmCliHiiHandle, pPropertyValue, pOutValue);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
ReturnCode = EFI_SUCCESS;
NVDIMM_DBG("Converted %s string to %f double", pPropertyValue, *pOutValue);
Finish:
return ReturnCode;
}
/**
Extracts working directory path from file path
@param[in] pUserFilePath Pointer to string with user specified file path
@param[out] pOutFilePath Pointer to actual file path
@param[out] ppDevicePath Pointer to where to store device path
@retval EFI_SUCCESS Extraction success
@retval EFI_INVALID_PARAMETER Invalid parameter
@retval EFI_OUT_OF_RESOURCES Out of resources
**/
EFI_STATUS
GetDeviceAndFilePath(
IN CHAR16 *pUserFilePath,
OUT CHAR16 *pOutFilePath,
OUT EFI_DEVICE_PATH_PROTOCOL **ppDevicePath
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
EFI_SHELL_PROTOCOL *pEfiShell = NULL;
EFI_DEVICE_PATH_PROTOCOL *pDevPathInternal = NULL;
EFI_HANDLE *pHandles = NULL;
UINTN HandlesCount = 0;
CHAR16 *pTmpFilePath = NULL;
CHAR16 *pTmpWorkingDir = NULL;
CONST CHAR16* pCurDir = NULL;
CHAR16 *pCurDirPath = NULL;
NVDIMM_ENTRY();
if (pUserFilePath == NULL || pOutFilePath == NULL || ppDevicePath == NULL) {
goto Finish;
}
#ifdef OS_BUILD
StrnCpyS(pOutFilePath, OPTION_VALUE_LEN, pUserFilePath, OPTION_VALUE_LEN - 1);
return EFI_SUCCESS;
#endif
pTmpWorkingDir = AllocateZeroPool(OPTION_VALUE_LEN * sizeof(*pTmpWorkingDir));
if (pTmpWorkingDir == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
goto Finish;
}
// Add " .\ "(current dir) to the file path if relative path is specified
if (!ContainsCharacter(L':', pUserFilePath)) {
pCurDirPath = CatSPrint(NULL, L".\\" FORMAT_STR, pUserFilePath);
}
else {
pCurDirPath = CatSPrint(NULL, FORMAT_STR, pUserFilePath);
}
if (pCurDirPath == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
goto Finish;
}
// Get Efi Shell Protocol
ReturnCode = gBS->LocateHandleBuffer(ByProtocol, &gEfiShellProtocolGuid, NULL, &HandlesCount, &pHandles);
if (EFI_ERROR(ReturnCode) || HandlesCount >= MAX_SHELL_PROTOCOL_HANDLES) {
NVDIMM_WARN("Error while opening the shell protocol. Code: " FORMAT_EFI_STATUS "", ReturnCode);
ReturnCode = EFI_NOT_FOUND;
goto Finish;
}
ReturnCode = gBS->OpenProtocol(
pHandles[0],
&gEfiShellProtocolGuid,
(VOID *)&pEfiShell,
NULL,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Error while opening the shell protocol. Code: " FORMAT_EFI_STATUS "", ReturnCode);
goto Finish;
}
// If User has not typed "Fsx:\", get current working directory
if (!ContainsCharacter(L':', pCurDirPath)) {
// Otherwise, path is relative to current directory
pCurDir = pEfiShell->GetCurDir(NULL);
if (pCurDir == NULL) {
NVDIMM_DBG("Error while getting the Working Directory.");
goto Finish;
}
if (StrLen(pCurDir) + 1 > OPTION_VALUE_LEN) {
ReturnCode = EFI_OUT_OF_RESOURCES;
goto Finish;
}
StrnCpyS(pTmpWorkingDir, OPTION_VALUE_LEN, pCurDir, OPTION_VALUE_LEN - 1);
// Take null terminator into account
StrnCatS(pTmpWorkingDir, OPTION_VALUE_LEN, pCurDirPath, OPTION_VALUE_LEN - StrLen(pTmpWorkingDir) - 1);
}
else {
StrnCpyS(pTmpWorkingDir, OPTION_VALUE_LEN, pCurDirPath, OPTION_VALUE_LEN - 1);
}
// Extract working directory
pTmpFilePath = pTmpWorkingDir;
while (pTmpFilePath[0] != L'\\' && pTmpFilePath[0] != L'\0') {
pTmpFilePath++;
}
StrnCpyS(pOutFilePath, OPTION_VALUE_LEN, pTmpFilePath, OPTION_VALUE_LEN - 1);
// Get Path to Device
pDevPathInternal = pEfiShell->GetDevicePathFromFilePath(pTmpWorkingDir);
if (pDevPathInternal == NULL) {
ReturnCode = EFI_NOT_FOUND;
NVDIMM_ERR("Error: Wrong file path.");
goto Finish;
}
*ppDevicePath = pDevPathInternal;
ReturnCode = EFI_SUCCESS;
Finish:
FREE_POOL_SAFE(pCurDirPath);
if (pTmpWorkingDir != NULL) {
FreePool(pTmpWorkingDir);
}
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Match driver command status to CLI return code
@param[in] Status - NVM_STATUS returned from driver
@retval - Appropriate EFI return code
**/
EFI_STATUS
MatchCliReturnCode(
IN NVM_STATUS Status
)
{
EFI_STATUS ReturnCode = EFI_ABORTED;
switch (Status) {
case NVM_SUCCESS:
case NVM_SUCCESS_IMAGE_EXAMINE_OK:
case NVM_SUCCESS_FW_RESET_REQUIRED:
case NVM_WARN_BLOCK_MODE_DISABLED:
case NVM_WARN_MAPPED_MEM_REDUCED_DUE_TO_CPU_SKU:
case NVM_WARN_REGION_MAX_PM_INTERLEAVE_SETS_EXCEEDED:
case NVM_WARN_REGION_AD_NI_PM_INTERLEAVE_SETS_REDUCED:
case NVM_WARN_GOAL_CREATION_SECURITY_UNLOCKED:
case NVM_WARN_NMFM_RATIO_LOWER_VIOLATION_1to3_6:
case NVM_WARN_NMFM_RATIO_UPPER_VIOLATION_1to16:
case NVM_WARN_NMFM_RATIO_LOWER_VIOLATION_1to2:
case NVM_WARN_NMFM_RATIO_UPPER_VIOLATION_1to8:
case NVM_WARN_PMEM_MODULE_NOT_PAIRED_FOR_2LM:
case NVM_SUCCESS_REQUIRES_POWER_CYCLE:
case NVM_WARN_PMTT_TABLE_NOT_FOUND:
ReturnCode = EFI_SUCCESS;
break;
case NVM_ERR_PASSPHRASE_TOO_LONG:
case NVM_ERR_NEW_PASSPHRASE_NOT_PROVIDED:
case NVM_ERR_PASSPHRASE_NOT_PROVIDED:
case NVM_ERR_PASSPHRASES_DO_NOT_MATCH:
case NVM_ERR_IMAGE_FILE_NOT_VALID:
case NVM_ERR_SENSOR_NOT_VALID:
case NVM_ERR_SENSOR_CONTROLLER_TEMP_OUT_OF_RANGE:
case NVM_ERR_SENSOR_MEDIA_TEMP_OUT_OF_RANGE:
case NVM_ERR_SENSOR_CAPACITY_OUT_OF_RANGE:
case NVM_ERR_SENSOR_ENABLED_STATE_INVALID_VALUE:
case NVM_ERR_UNSUPPORTED_BLOCK_SIZE:
case NVM_ERR_NONE_DIMM_FULFILLS_CRITERIA:
case NVM_ERR_INVALID_NAMESPACE_CAPACITY:
case NVM_ERR_NAMESPACE_TOO_SMALL_FOR_BTT:
case NVM_ERR_REGION_NOT_ENOUGH_SPACE_FOR_PM_NAMESPACE:
case NVM_ERR_RESERVE_DIMM_REQUIRES_AT_LEAST_TWO_DIMMS:
case NVM_ERR_PERS_MEM_MUST_BE_APPLIED_TO_ALL_DIMMS:
case NVM_ERR_INVALID_PARAMETER:
ReturnCode = EFI_INVALID_PARAMETER;
break;
case NVM_ERR_NOT_ENOUGH_FREE_SPACE:
case NVM_ERR_NOT_ENOUGH_FREE_SPACE_BTT:
ReturnCode = EFI_OUT_OF_RESOURCES;
break;
case NVM_ERR_DIMM_NOT_FOUND:
case NVM_ERR_MANAGEABLE_DIMM_NOT_FOUND:
case NVM_ERR_DIMM_EXCLUDED:
case NVM_ERR_NO_USABLE_DIMMS:
case NVM_ERR_SOCKET_ID_NOT_VALID:
case NVM_ERR_REGION_NOT_FOUND:
case NVM_ERR_NAMESPACE_DOES_NOT_EXIST:
case NVM_ERR_REGION_NO_GOAL_EXISTS_ON_DIMM:
ReturnCode = EFI_NOT_FOUND;
break;
case NVM_ERR_ENABLE_SECURITY_NOT_ALLOWED:
case NVM_ERR_CREATE_GOAL_NOT_ALLOWED:
case NVM_ERR_INVALID_SECURITY_STATE:
case NVM_ERR_INVALID_PASSPHRASE:
case NVM_ERR_SPI_ACCESS_NOT_ENABLED:
ReturnCode = EFI_ACCESS_DENIED;
break;
case NVM_ERR_OPERATION_NOT_STARTED:
case NVM_ERR_FORCE_REQUIRED:
case NVM_ERR_OPERATION_FAILED:
case NVM_ERR_DIMM_ID_DUPLICATED:
case NVM_ERR_SOCKET_ID_INCOMPATIBLE_W_DIMM_ID:
case NVM_ERR_SOCKET_ID_DUPLICATED:
case NVM_ERR_UNABLE_TO_GET_SECURITY_STATE:
case NVM_ERR_INCONSISTENT_SECURITY_STATE:
case NVM_ERR_SECURITY_USER_PP_COUNT_EXPIRED:
case NVM_ERR_SECURITY_MASTER_PP_COUNT_EXPIRED:
case NVM_ERR_REGION_GOAL_CONF_AFFECTS_UNSPEC_DIMM:
case NVM_ERR_REGION_CURR_CONF_AFFECTS_UNSPEC_DIMM:
case NVM_ERR_REGION_GOAL_CURR_CONF_AFFECTS_UNSPEC_DIMM:
case NVM_ERR_REGION_CONF_APPLYING_FAILED:
case NVM_ERR_REGION_CONF_UNSUPPORTED_CONFIG:
case NVM_ERR_DUMP_FILE_OPERATION_FAILED:
case NVM_ERR_LOAD_VERSION:
case NVM_ERR_LOAD_INVALID_DATA_IN_FILE:
case NVM_ERR_LOAD_IMPROPER_CONFIG_IN_FILE:
case NVM_ERR_LOAD_DIMM_COUNT_MISMATCH:
case NVM_ERR_NAMESPACE_CONFIGURATION_BROKEN:
case NVM_ERR_INVALID_SECURITY_OPERATION:
case NVM_ERR_OPEN_FILE_WITH_WRITE_MODE_FAILED:
case NVM_ERR_DUMP_NO_CONFIGURED_DIMMS:
case NVM_ERR_REGION_NOT_HEALTHY:
case NVM_ERR_FAILED_TO_GET_DIMM_REGISTERS:
case NVM_ERR_FAILED_TO_UPDATE_BTT:
case NVM_ERR_SMBIOS_DIMM_ENTRY_NOT_FOUND_IN_NFIT:
case NVM_ERR_IMAGE_FILE_NOT_COMPATIBLE_TO_CTLR_STEPPING:
case NVM_ERR_IMAGE_EXAMINE_INVALID:
case NVM_ERR_FIRMWARE_API_NOT_VALID:
case NVM_ERR_FIRMWARE_VERSION_NOT_VALID:
case NVM_ERR_REGION_GOAL_NAMESPACE_EXISTS:
case NVM_ERR_REGION_REMAINING_SIZE_NOT_IN_LAST_PROPERTY:
case NVM_ERR_ARS_IN_PROGRESS:
case NVM_ERR_FWUPDATE_IN_PROGRESS:
case NVM_ERR_OVERWRITE_DIMM_IN_PROGRESS:
case NVM_ERR_UNKNOWN_LONG_OP_IN_PROGRESS:
case NVM_ERR_APPDIRECT_IN_SYSTEM:
case NVM_ERR_OPERATION_NOT_SUPPORTED_BY_MIXED_SKU:
case NVM_ERR_SECURE_ERASE_NAMESPACE_EXISTS:
case NVM_ERR_CREATE_NAMESPACE_NOT_ALLOWED:
ReturnCode = EFI_ABORTED;
break;
case NVM_ERR_OPERATION_NOT_SUPPORTED:
case NVM_ERR_ERROR_INJECTION_BIOS_KNOB_NOT_ENABLED:
case NVM_ERR_NMFM_RATIO_GREATER_THAN_ONE:
ReturnCode = EFI_UNSUPPORTED;
break;
case NVM_ERR_FIRMWARE_ALREADY_LOADED:
ReturnCode = EFI_ALREADY_STARTED;
break;
case NVM_ERR_MASTER_PASSPHRASE_NOT_SET:
ReturnCode = EFI_NOT_STARTED;
break;
default:
ReturnCode = EFI_ABORTED;
break;
}
return ReturnCode;
}
/**
Get free space of volume from given path
@param[in] pFileHandle - file handle protocol
@param[out] pFreeSpace - free space
@retval - Appropriate EFI return code
**/
EFI_STATUS
GetVolumeFreeSpace(
IN EFI_FILE_HANDLE pFileHandle,
OUT UINT64 *pFreeSpace
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
EFI_FILE_SYSTEM_INFO *pFileSystemInfo = NULL;
EFI_GUID FileSystemInfoGuid = EFI_FILE_SYSTEM_INFO_ID;
UINT64 BufferSize = MAX_FILE_SYSTEM_STRUCT_SIZE;
NVDIMM_ENTRY();
if (pFreeSpace == NULL || pFileHandle == NULL) {
goto Finish;
}
pFileSystemInfo = AllocateZeroPool(BufferSize);
if (pFileSystemInfo == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
goto Finish;
}
ReturnCode = pFileHandle->GetInfo(pFileHandle, &FileSystemInfoGuid, &BufferSize, pFileSystemInfo);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
*pFreeSpace = pFileSystemInfo->FreeSpace;
Finish:
FREE_POOL_SAFE(pFileSystemInfo);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Check if file exists
@param[in] pDumpUserPath - destination file path
@param[out] pExists - pointer to whether or not destination file already exists
@retval - Appropriate EFI return code
**/
EFI_STATUS
FileExists(
IN CHAR16* pDumpUserPath,
OUT BOOLEAN* pExists
)
{
EFI_FILE_HANDLE pFileHandle = NULL;
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
*pExists = FALSE;
NVDIMM_ENTRY();
#ifdef OS_BUILD
pFileHandle = NULL;
ReturnCode = OpenFileText(pDumpUserPath, &pFileHandle, NULL, FALSE);
if (EFI_NOT_FOUND == ReturnCode)
{
*pExists = FALSE;
ReturnCode = EFI_SUCCESS;
}
else if (EFI_SUCCESS == ReturnCode)
{
*pExists = TRUE;
pFileHandle->Close(pFileHandle);
}
#else
EFI_DEVICE_PATH_PROTOCOL *pDevicePathProtocol = NULL;
CHAR16 *pDumpFilePath = NULL;
pDumpFilePath = AllocateZeroPool(OPTION_VALUE_LEN * sizeof(*pDumpFilePath));
if (pDumpFilePath == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
goto Finish;
}
ReturnCode = GetDeviceAndFilePath(pDumpUserPath, pDumpFilePath, &pDevicePathProtocol);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Failed to get file path (" FORMAT_EFI_STATUS ")", ReturnCode);
goto Finish;
}
ReturnCode = OpenFileByDevice(pDumpFilePath, pDevicePathProtocol, FALSE, &pFileHandle);
if (!EFI_ERROR(ReturnCode)) {
*pExists = TRUE;
pFileHandle->Close(pFileHandle);
}
Finish:
FREE_POOL_SAFE(pDumpFilePath);
#endif
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Delete file
@param[in] pDumpUserPath - file path to delete
@retval - Appropriate EFI return code
**/
EFI_STATUS
DeleteFile(
IN CHAR16* pFilePath
)
{
EFI_DEVICE_PATH_PROTOCOL *pDevicePathProtocol = NULL;
EFI_FILE_HANDLE pFileHandle = NULL;
CHAR16 *pDumpFilePath = NULL;
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
EFI_FILE_HANDLE RootDirHandle = NULL;
NVDIMM_ENTRY();
pDumpFilePath = AllocateZeroPool(OPTION_VALUE_LEN * sizeof(*pDumpFilePath));
if (pDumpFilePath == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
goto Finish;
}
ReturnCode = GetDeviceAndFilePath(pFilePath, pDumpFilePath, &pDevicePathProtocol);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Failed to get file path (" FORMAT_EFI_STATUS ")", ReturnCode);
goto Finish;
}
ReturnCode = OpenRootFileVolume(pDevicePathProtocol, &RootDirHandle);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Failed to open file volume (" FORMAT_EFI_STATUS ")", ReturnCode);
goto Finish;
}
ReturnCode = RootDirHandle->Open(RootDirHandle, &pFileHandle, pFilePath, EFI_FILE_MODE_CREATE | EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
if (!EFI_ERROR(ReturnCode)) {
ReturnCode = pFileHandle->Delete(pFileHandle);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Failed to delete file path (" FORMAT_EFI_STATUS ")", ReturnCode);
goto Finish;
}
}
Finish:
FREE_POOL_SAFE(pDumpFilePath);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Dump data to file
@param[in] pDumpUserPath - destination file path
@param[in] BufferSize - data size to write
@param[in] pBuffer - pointer to buffer
@param[in] Overwrite - enforce overwriting file
@retval - Appropriate EFI return code
**/
EFI_STATUS
DumpToFile(
IN CHAR16* pDumpUserPath,
IN UINT64 BufferSize,
OUT VOID* pBuffer,
IN BOOLEAN Overwrite
)
{
#ifdef OS_BUILD
EFI_STATUS ReturnCode = EFI_SUCCESS;
CHAR8 *path = (CHAR8 *)AllocatePool(StrLen(pDumpUserPath) + 1);
if (NULL == path) {
NVDIMM_WARN("Failed to allocate enough memory.");
return EFI_OUT_OF_RESOURCES;
}
UnicodeStrToAsciiStrS(pDumpUserPath, path, StrLen(pDumpUserPath) + 1);
FILE *destFile = fopen(path, "wb+");
if (NULL == destFile) {
NVDIMM_WARN("Failed to open file (%s) errno: (%d)", path, errno);
FreePool(path);
return EFI_INVALID_PARAMETER;
}
size_t bytes_written = fwrite(pBuffer, 1, (size_t)BufferSize, destFile);
if (bytes_written != BufferSize) {
NVDIMM_WARN("Failed to write file (%s) errno: (%d)", path, errno);
ReturnCode = EFI_INVALID_PARAMETER;
}
FreePool(path);
fclose(destFile);
return ReturnCode;
#else
EFI_DEVICE_PATH_PROTOCOL *pDevicePathProtocol = NULL;
EFI_FILE_HANDLE pFileHandle = NULL;
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
EFI_FILE_HANDLE RootDirHandle = NULL;
CHAR16 *pDumpFilePath = NULL;
UINT64 FileSize = 0;
UINT64 FreeVolumeSpace = 0;
UINT64 SizeToWrite = 0;
NVDIMM_ENTRY();
if (pDumpUserPath == NULL || pBuffer == NULL) {
goto Finish;
}
pDumpFilePath = AllocateZeroPool(OPTION_VALUE_LEN * sizeof(*pDumpFilePath));
if (pDumpFilePath == NULL) {
NVDIMM_CRIT("Out of memory\n");
ReturnCode = EFI_OUT_OF_RESOURCES;
goto Finish;
}
ReturnCode = GetDeviceAndFilePath(pDumpUserPath, pDumpFilePath, &pDevicePathProtocol);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Failed to get file path (" FORMAT_EFI_STATUS ")", ReturnCode);
goto Finish;
}
ReturnCode = OpenRootFileVolume(pDevicePathProtocol, &RootDirHandle);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
ReturnCode = GetVolumeFreeSpace(RootDirHandle, &FreeVolumeSpace);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
if (FreeVolumeSpace < BufferSize) {
ReturnCode = EFI_VOLUME_FULL;
goto Finish;
}
// Create new file for dump
ReturnCode = OpenFileByDevice(pDumpFilePath, pDevicePathProtocol, TRUE, &pFileHandle);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Failed to open file (" FORMAT_EFI_STATUS ") (%s)", ReturnCode, pDumpFilePath);
goto Finish;
}
// Get File Size
ReturnCode = GetFileSize(pFileHandle, &FileSize);
// Check if file already exists and has some size
if (FileSize != 0) {
if (Overwrite) {
ReturnCode = pFileHandle->Delete(pFileHandle);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Failed deleting old dump file (" FORMAT_EFI_STATUS ")", ReturnCode);
goto Finish;
}
// Create new file for dump
ReturnCode = OpenFileByDevice(pDumpFilePath, pDevicePathProtocol, TRUE, &pFileHandle);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Failed to create dump file (" FORMAT_EFI_STATUS ")", ReturnCode);
goto Finish;
}
}
else {
NVDIMM_WARN("File exists and we're not allowed to overwrite (%s)", pDumpFilePath);
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
}
SizeToWrite = BufferSize;
ReturnCode = pFileHandle->Write(pFileHandle, &SizeToWrite, pBuffer);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Error occurred during write (%s)", pDumpFilePath);
goto FinishCloseFile;
}
FinishCloseFile:
ReturnCode = pFileHandle->Close(pFileHandle);
Finish:
FREE_POOL_SAFE(pDumpFilePath);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
#endif
}
/**
Prints supported or recommended appdirect settings
@param[in] pInterleaveFormatList pointer to variable length interleave formats array
@param[in] FormatNum number of the appdirect settings formats
@param[in] pInterleaveSize pointer to Channel & iMc interleave size, if NULL refer to older revision pInterleaveFormatList
@param[in] PrintRecommended if TRUE Recommended settings will be printed
if FALSE Supported settings will be printed
@param[in] Mode Set mode to print different format
@retval String representing AppDirect settings. Null on error.
**/
CHAR16*
PrintAppDirectSettings(
IN VOID *pInterleaveFormatList,
IN UINT16 FormatNum,
IN INTERLEAVE_SIZE *pInterleaveSize,
IN BOOLEAN PrintRecommended,
IN UINT8 Mode
)
{
UINT32 Index = 0;
UINT32 Index2 = 0;
UINT32 InterleaveWay = 0;
ChannelWaysNumber WayNumber = Unknown;
InterleaveSizeIndex ImcStringIndex = Unknown;
InterleaveSizeIndex ChannelStringIndex = Unknown;
UINT8 NumOfBitsSet = 0;
UINT8 PrevNumOfBitsSet = 0;
BOOLEAN First = TRUE;
CHAR16 *pTempBuffer = NULL;
UINT32 ChannelInterleaveSize = 0;
UINT32 ImcInterleaveSize = 0;
UINT16 NumberOfChannelWays = 0;
UINT32 Recommended = 0;
if (pInterleaveFormatList == NULL) {
NVDIMM_CRIT("NULL input parameter.\n");
return NULL;
}
for (Index = 0; Index < FormatNum; Index++) {
if (pInterleaveSize == NULL) {
INTERLEAVE_FORMAT *pFormatList = (INTERLEAVE_FORMAT *)pInterleaveFormatList;
ChannelInterleaveSize = pFormatList[Index].InterleaveFormatSplit.ChannelInterleaveSize;
ImcInterleaveSize = pFormatList[Index].InterleaveFormatSplit.iMCInterleaveSize;
NumberOfChannelWays = pFormatList[Index].InterleaveFormatSplit.NumberOfChannelWays & MAX_UINT16;
Recommended = pFormatList[Index].InterleaveFormatSplit.Recommended;
}
else {
INTERLEAVE_FORMAT3 *pFormatList = (INTERLEAVE_FORMAT3 *)pInterleaveFormatList;
ChannelInterleaveSize = pInterleaveSize->InterleaveSizeSplit.ChannelInterleaveSize;
ImcInterleaveSize = pInterleaveSize->InterleaveSizeSplit.iMCInterleaveSize;
Recommended = pFormatList[Index].InterleaveFormatSplit.Recommended;
CountNumOfBitsSet(pFormatList[Index].InterleaveFormatSplit.InterleaveMap, &NumOfBitsSet);
if (NumOfBitsSet == PrevNumOfBitsSet) {
continue;
}
GetBitFieldForNumOfChannelWays(NumOfBitsSet, &NumberOfChannelWays);
WayNumber = NumOfBitsSet;
PrevNumOfBitsSet = NumOfBitsSet;
if (WayNumber == 0) {
continue;
}
}
if (PrintRecommended && !Recommended) {
continue;
}
for (Index2 = 0; Index2 < NUMBER_OF_CHANNEL_WAYS_BITS_NUM; Index2++) {
/** Check each bit **/
InterleaveWay = NumberOfChannelWays & (1 << Index2);
switch (InterleaveWay) {
case INTERLEAVE_SET_1_WAY:
WayNumber = ChannelWays_X1;
break;
case INTERLEAVE_SET_2_WAY:
WayNumber = ChannelWays_X2;
break;
case INTERLEAVE_SET_3_WAY:
WayNumber = ChannelWays_X3;
break;
case INTERLEAVE_SET_4_WAY:
WayNumber = ChannelWays_X4;
break;
case INTERLEAVE_SET_6_WAY:
WayNumber = ChannelWays_X6;
break;
case INTERLEAVE_SET_8_WAY:
WayNumber = ChannelWays_X8;
break;
case INTERLEAVE_SET_12_WAY:
WayNumber = ChannelWays_X12;
break;
case INTERLEAVE_SET_16_WAY:
WayNumber = ChannelWays_X16;
break;
case INTERLEAVE_SET_24_WAY:
WayNumber = ChannelWays_X24;
break;
default:
WayNumber = Unknown;
break;
}
if (WayNumber == 0) {
continue;
}
switch (ImcInterleaveSize) {
case IMC_INTERLEAVE_SIZE_64B:
ImcStringIndex = Interleave_64B;
break;
case IMC_INTERLEAVE_SIZE_128B:
ImcStringIndex = Interleave_128B;
break;
case IMC_INTERLEAVE_SIZE_256B:
ImcStringIndex = Interleave_256B;
break;
case IMC_INTERLEAVE_SIZE_4KB:
ImcStringIndex = Interleave_4KB;
break;
case IMC_INTERLEAVE_SIZE_1GB:
ImcStringIndex = Interleave_1GB;
break;
default:
ImcStringIndex = Unknown;
break;
}
switch (ChannelInterleaveSize) {
case CHANNEL_INTERLEAVE_SIZE_64B:
ChannelStringIndex = Interleave_64B;
break;
case CHANNEL_INTERLEAVE_SIZE_128B:
ChannelStringIndex = Interleave_128B;
break;
case CHANNEL_INTERLEAVE_SIZE_256B:
ChannelStringIndex = Interleave_256B;
break;
case CHANNEL_INTERLEAVE_SIZE_4KB:
ChannelStringIndex = Interleave_4KB;
break;
case CHANNEL_INTERLEAVE_SIZE_1GB:
ChannelStringIndex = Interleave_1GB;
break;
default:
ChannelStringIndex = Unknown;
break;
}
if (ImcStringIndex >= sizeof(mpImcSize)) {
ImcStringIndex = 0;
}
if (ChannelStringIndex >= sizeof(mpChannelSize)) {
ChannelStringIndex = 0;
}
if (!First) {
pTempBuffer = CatSPrintClean(pTempBuffer, L", ");
}
else {
First = FALSE;
}
if (Mode == PRINT_SETTINGS_FORMAT_FOR_SHOW_SYS_CAP_CMD) {
if (InterleaveWay == INTERLEAVE_SET_1_WAY) {
pTempBuffer = CatSPrintClean(pTempBuffer, L"x1 (ByOne)");
}
else {
pTempBuffer = CatSPrintClean(pTempBuffer, L"x%d - " FORMAT_STR L" iMC x " FORMAT_STR L" Channel (", WayNumber, mpImcSize[ImcStringIndex], mpChannelSize[ChannelStringIndex]);
pTempBuffer = CatSPrintClean(pTempBuffer, FORMAT_STR L"_" FORMAT_STR L")", mpImcSize[ImcStringIndex], mpChannelSize[ChannelStringIndex]);
}
}
else if (Mode == PRINT_SETTINGS_FORMAT_FOR_SHOW_REGION_CMD) {
if (InterleaveWay == INTERLEAVE_SET_1_WAY) {
pTempBuffer = CatSPrintClean(pTempBuffer, L"x1 (ByOne)");
}
else {
pTempBuffer = CatSPrintClean(pTempBuffer, L"x%d - " FORMAT_STR L" iMC x " FORMAT_STR L" Channel (" FORMAT_STR L"_" FORMAT_STR L")", WayNumber, mpImcSize[ImcStringIndex],
mpChannelSize[ChannelStringIndex], mpImcSize[ImcStringIndex], mpChannelSize[ChannelStringIndex]);
}
}
}
}
return pTempBuffer;
}
/**
Read source file and return current passphrase to unlock device.
@param[in] pCmd A pointer to a COMMAND struct. Used to obtain the Printer context.
@param[in] pFileHandle File handler to read Passphrase from
@param[in] pDevicePath - handle to obtain generic path/location information concerning the
physical device or logical device. The device path describes the location of the device
the handle is for.
@param[out] ppCurrentPassphrase
@param[out] ppNewPassphrase
@retval EFI_SUCCESS File load and parse success
@retval EFI_INVALID_PARAMETER Invalid Parameter during load
@retval other Return Codes from TrimLineBuffer,
GetLoadPoolData, GetLoadDimmData, GetLoadValue functions
**/
EFI_STATUS
ParseSourcePassFile(
IN struct Command *pCmd,
IN CHAR16 *pFilePath,
IN EFI_DEVICE_PATH_PROTOCOL *pDevicePath,
OUT CHAR16 **ppCurrentPassphrase OPTIONAL,
OUT CHAR16 **ppNewPassphrase OPTIONAL
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
CHAR16 *pReadBuffer = NULL;
UINT32 Index = 0;
UINT32 NumberOfLines = 0;
UINT64 FileBufferSize = 0;
UINT64 StringLength = 0;
CHAR16 **ppLinesBuffer = NULL;
CHAR16 *pCurrentLine = NULL;
VOID *pFileBuffer = NULL;
CHAR16 *pPassFromFile = NULL;
CHAR16 *pFileString = NULL;
UINT32 NumberOfChars = 0;
BOOLEAN PassphraseProvided = FALSE;
BOOLEAN NewPassphraseProvided = FALSE;
BOOLEAN TextFallThrough = TRUE;
NVDIMM_ENTRY();
#ifndef OS_BUILD
if (pDevicePath == NULL || pCmd == NULL) {
NVDIMM_CRIT("NULL input parameter.\n");
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
#endif
if (pFilePath == NULL || pCmd == NULL) {
NVDIMM_CRIT("NULL input parameter.\n");
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
ReturnCode = FileRead(pFilePath, pDevicePath, MAX_CONFIG_DUMP_FILE_SIZE, FALSE, &FileBufferSize, (VOID **)&pFileBuffer);
if (EFI_ERROR(ReturnCode) || pFileBuffer == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_WRONG_FILE_PATH);
goto Finish;
}
// Verify if it is Unicode file:
//If it is not a Unicode File Convert the File String
if (*((CHAR16 *)pFileBuffer) != UTF_16_BOM) {
pFileString = AllocateZeroPool((FileBufferSize * sizeof(CHAR16)) + sizeof(L'\0'));
if (pFileString == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
ReturnCode = SafeAsciiStrToUnicodeStr((const CHAR8 *)pFileBuffer, (UINT32)FileBufferSize, pFileString);
Index = 0;
FREE_POOL_SAFE(pFileBuffer);
}
else {
// Add size of L'\0' (UTF16) char
// ReallocatePool frees pFileBuffer after completion. Do not need to call FREE_POOL_SAFE for pFileBuffer
pFileString = ReallocatePool(FileBufferSize, FileBufferSize + sizeof(L'\0'), pFileBuffer);
if (pFileString == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
Index = 1;
NumberOfChars = (UINT32)(FileBufferSize / sizeof(CHAR16));
pFileString[NumberOfChars] = L'\0';
}
// Split input file to lines
ppLinesBuffer = StrSplit(&pFileString[Index], L'\n', &NumberOfLines);
if (ppLinesBuffer == NULL || NumberOfLines == 0) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, L"Error: The file is empty.\n");
goto Finish;
}
for (Index = 0; Index < NumberOfLines; ++Index) {
pCurrentLine = ppLinesBuffer[Index];
StringLength = StrLen(pCurrentLine);
// Ignore comment line that starts with '#' or
// If the only content in line is new line chars
if ( ((NULL == pCurrentLine) || (L'#' == pCurrentLine[0]))
|| (1 == StringLength && (L'\n' == pCurrentLine[0] || L'\r' == pCurrentLine[0]))
|| (2 == StringLength && L'\r' == pCurrentLine[0] && L'\n' == pCurrentLine[1])) {
continue;
}
else {
TextFallThrough = FALSE;
}
pPassFromFile = (CHAR16*)StrStr(ppLinesBuffer[Index], L"=");
if (pPassFromFile == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_INVALID_PASSPHRASE_FROM_FILE);
goto Finish;
}
// Move offset to skip '=' char
pPassFromFile++;
StringLength = StrLen(pPassFromFile);
if (StringLength == 0) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_INVALID_PASSPHRASE_FROM_FILE);
goto Finish;
}
// Cut off new line chars present at the end
while ((1 <= StringLength)
&& (L'\r' == pPassFromFile[StringLength - 1] || L'\n' == pPassFromFile[StringLength - 1])) {
pPassFromFile[StringLength - 1] = L'\0';
StringLength--;
}
NewPassphraseProvided =
StrnCmp(ppLinesBuffer[Index], NEWPASSPHRASE_PROPERTY, StrLen(NEWPASSPHRASE_PROPERTY)) == 0;
PassphraseProvided =
StrnCmp(ppLinesBuffer[Index], PASSPHRASE_PROPERTY, StrLen(PASSPHRASE_PROPERTY)) == 0;
if (ppNewPassphrase != NULL && *ppNewPassphrase == NULL && NewPassphraseProvided) {
*ppNewPassphrase = CatSPrint(NULL, FORMAT_STR, pPassFromFile);
}
else if (ppCurrentPassphrase != NULL && *ppCurrentPassphrase == NULL && PassphraseProvided) {
*ppCurrentPassphrase = CatSPrint(NULL, FORMAT_STR, pPassFromFile);
}
else {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_WRONG_FILE_DATA);
goto Finish;
}
}
//In case the file has only comments and new line
if (TRUE == TextFallThrough) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_WRONG_FILE_DATA);
}
Finish:
for (Index = 0; ppLinesBuffer != NULL && Index < NumberOfLines; ++Index) {
FREE_POOL_SAFE(ppLinesBuffer[Index]);
}
FREE_POOL_SAFE(pFileString);
FREE_POOL_SAFE(ppLinesBuffer);
FREE_POOL_SAFE(pReadBuffer);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
#ifndef OS_BUILD
/**
Prompted input request
@param[in] pPrompt - information about expected input
@param[in] ShowInput - Show characters written by user
@param[in] OnlyAlphanumeric - Allow only for alphanumeric characters
@param[out] ppReturnValue - is a pointer to a pointer to the 16-bit character string
that will contain the return value
@retval - Appropriate CLI return code
**/
EFI_STATUS
PromptedInput(
IN CHAR16 *pPrompt,
IN BOOLEAN ShowInput,
IN BOOLEAN OnlyAlphanumeric,
OUT CHAR16 **ppReturnValue
)
{
CHAR16 *pBuffer = NULL;
EFI_STATUS ReturnCode = EFI_SUCCESS;
NVDIMM_ENTRY();
if (pPrompt == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
Print(FORMAT_STR, pPrompt);
ReturnCode = ConsoleInput(ShowInput, OnlyAlphanumeric, &pBuffer, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
*ppReturnValue = pBuffer;
Finish:
Print(L"\n");
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Display "yes/no" question and retrieve reply using prompt mechanism
@param[out] pConfirmation Confirmation from prompt
@retval EFI_INVALID_PARAMETER One or more parameters are invalid
@retval EFI_SUCCESS All Ok
**/
EFI_STATUS
PromptYesNo(
OUT BOOLEAN *pConfirmation
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
CHAR16 *pPromptReply = NULL;
BOOLEAN ValidInput = FALSE;
NVDIMM_ENTRY();
if (pConfirmation == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
ReturnCode = PromptedInput(PROMPT_CONTINUE_QUESTION, TRUE, TRUE, &pPromptReply);
if ((NULL == pPromptReply) || (EFI_ERROR(ReturnCode))) {
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
ValidInput = StrLen(pPromptReply) == 1 &&
(StrICmp(pPromptReply, L"y") == 0 || StrICmp(pPromptReply, L"n") == 0);
if (EFI_ERROR(ReturnCode) || !ValidInput) {
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
if (StrICmp(pPromptReply, L"y") == 0) {
*pConfirmation = TRUE;
}
else {
*pConfirmation = FALSE;
}
ReturnCode = EFI_SUCCESS;
Finish:
FREE_POOL_SAFE(pPromptReply);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
#endif
/**
Read input from console
@param[in] ShowInput - Show characters written by user
@param[in] OnlyAlphanumeric - Allow only for alphanumeric characters
@param[in, out] ppReturnValue - is a pointer to a pointer to the 16-bit character
string without null-terminator that will contain the return value
@param[in, out] pBufferSize - is a pointer to the Size in bytes of the return buffer
@retval - Appropriate CLI return code
**/
EFI_STATUS
ConsoleInput(
IN BOOLEAN ShowInput,
IN BOOLEAN OnlyAlphanumeric,
IN OUT CHAR16 **ppReturnValue,
IN OUT UINTN *pBufferSize OPTIONAL
)
{
EFI_INPUT_KEY Key = { 0 };
UINTN SizeInBytes = 0;
CHAR16 *pBuffer = NULL;
UINTN EventIndex = 0;
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_ENTRY();
if (ppReturnValue == NULL) {
goto Finish;
}
while (1) {
gBS->WaitForEvent(1, &gST->ConIn->WaitForKey, &EventIndex);
ReturnCode = gST->ConIn->ReadKeyStroke(gST->ConIn, &Key);
if (EFI_ERROR(ReturnCode)) {
Print(L"Error reading key strokes.\n");
goto Finish;
}
if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
if (pBuffer == NULL || StrLen(pBuffer) == 0 || SizeInBytes <= 0) {
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
else {
*ppReturnValue = pBuffer;
if (pBufferSize != NULL) {
*pBufferSize = SizeInBytes;
}
break;
}
}
if ((SizeInBytes != 0 && pBuffer == NULL) ||
(SizeInBytes == 0 && pBuffer != NULL)) {
ReturnCode = EFI_BAD_BUFFER_SIZE;
goto Finish;
}
if (Key.UnicodeChar == CHAR_BACKSPACE) {
if (pBuffer != NULL && StrLen(pBuffer) > 0) {
pBuffer[StrLen(pBuffer) - 1] = L'\0';
if (ShowInput) {
Print(L"%c", Key.UnicodeChar);
}
}
}
else {
if (!OnlyAlphanumeric || IsUnicodeAlnumCharacter(Key.UnicodeChar)) {
StrnCatGrow(&pBuffer, &SizeInBytes, &Key.UnicodeChar, 1);
if (NULL == pBuffer) {
Print(L"Failure inputting characters.\n");
break;
}
if (ShowInput) {
Print(L"%c", Key.UnicodeChar);
}
}
}
}
ReturnCode = EFI_SUCCESS;
Finish:
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Print Load Firmware progress for all DIMMs
@param[in] ProgressEvent EFI Event
@param[in] pContext context pointer
**/
VOID
EFIAPI
PrintProgress(
IN EFI_EVENT ProgressEvent,
IN VOID *pContext
)
{
OBJECT_STATUS *pObjectStatus = NULL;
LIST_ENTRY *pObjectStatusNode = NULL;
STATIC UINT32 LastObjectId = 0;
COMMAND_STATUS *pCommandStatus = NULL;
/**
For reuse of this function one should do one of two things:
1) Add string pointer to COMMAND_STATUS and pass it to Print instead of current define
2) Use some other structure instead of COMMAND_STATUS
**/
if (pContext == NULL) {
goto Finish;
}
pCommandStatus = (COMMAND_STATUS*)pContext;
if (!IsListInitialized(pCommandStatus->ObjectStatusList) && !IsListEmpty(&pCommandStatus->ObjectStatusList)) {
goto Finish;
}
LIST_FOR_EACH(pObjectStatusNode, &pCommandStatus->ObjectStatusList) {
pObjectStatus = OBJECT_STATUS_FROM_NODE(pObjectStatusNode);
if (IsSetNvmStatus(pObjectStatus, NVM_OPERATION_IN_PROGRESS)) {
if (LastObjectId == 0) {
LastObjectId = pObjectStatus->ObjectId;
}
else if (LastObjectId != pObjectStatus->ObjectId) {
Print(L"\n");
LastObjectId = pObjectStatus->ObjectId;
}
Print(CLI_PROGRESS_STR, pObjectStatus->ObjectId, pObjectStatus->Progress);
break;
}
}
Finish:
return;
}
/**
Get relative path from absolute path.
Output pointer points to the same string as input but with necessary offset. Caller shall not free it.
@param[in] pAbsolutePath Absolute path
@param[out] ppRelativePath Relative path
@retval EFI_INVALID_PARAMETER Input parameter was NULL
@retval EFI_SUCCESS All Ok
**/
EFI_STATUS
GetRelativePath(
IN CHAR16 *pAbsolutePath,
OUT CHAR16 **ppRelativePath
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
if (pAbsolutePath == NULL) {
goto Finish;
}
*ppRelativePath = pAbsolutePath;
if (ContainsCharacter(':', *ppRelativePath)) {
while (*ppRelativePath[0] != '\\' && *ppRelativePath[0] != '\0') {
(*ppRelativePath)++;
}
}
ReturnCode = EFI_SUCCESS;
Finish:
return ReturnCode;
}
/**
Check if all dimms in the specified pDimmIds list are manageable.
This helper method assumes all the dimms in the list exist.
This helper method also assumes the parameters are non-null.
@param[in] pAllDimms The dimm list found in NFIT
@param[in] AllDimmCount Size of the pAllDimms array
@param[in] pDimmsListToCheck Pointer to the array of DimmIDs to check
@param[in] DimmsToCheckCount Size of the pDimmsListToCheck array
@retval TRUE if all Dimms in pDimmsListToCheck array are manageable
@retval FALSE if at least one DIMM is not manageable
**/
BOOLEAN
AllDimmsInListAreManageable(
IN DIMM_INFO *pAllDimms,
IN UINT32 AllDimmCount,
IN UINT16 *pDimmsListToCheck,
IN UINT32 DimmsToCheckCount
)
{
BOOLEAN Manageable = TRUE;
UINT32 AllDimmListIndex = 0;
UINT32 DimmsToCheckIndex = 0;
NVDIMM_ENTRY();
for (DimmsToCheckIndex = 0; DimmsToCheckIndex < DimmsToCheckCount; DimmsToCheckIndex++) {
for (AllDimmListIndex = 0; AllDimmListIndex < AllDimmCount; AllDimmListIndex++) {
if (pAllDimms[AllDimmListIndex].DimmID == pDimmsListToCheck[DimmsToCheckIndex]) {
if (pAllDimms[AllDimmListIndex].ManageabilityState != MANAGEMENT_VALID_CONFIG) {
Manageable = FALSE;
break;
}
}
}
}
NVDIMM_EXIT();
return Manageable;
}
/**
Check if all dimms in the specified pDimmIds list are in supported
config. This helper method assumes all the dimms in the list exist.
This helper method also assumes the parameters are non-null.
@param[in] pAllDimms The dimm list found in NFIT
@param[in] AllDimmCount Size of the pAllDimms array
@param[in] pDimmsListToCheck Pointer to the array of DimmIDs to check
@param[in] DimmsToCheckCount Size of the pDimmsListToCheck array
@retval TRUE if all Dimms in pDimmsListToCheck array are in supported config
@retval FALSE if at least one DIMM is not in supported config
**/
BOOLEAN
AllDimmsInListInSupportedConfig(
IN DIMM_INFO *pAllDimms,
IN UINT32 AllDimmCount,
IN UINT16 *pDimmsListToCheck,
IN UINT32 DimmsToCheckCount
)
{
BOOLEAN InSupportedConfig = TRUE;
UINT32 AllDimmListIndex = 0;
UINT32 DimmsToCheckIndex = 0;
NVDIMM_ENTRY();
for (DimmsToCheckIndex = 0; DimmsToCheckIndex < DimmsToCheckCount; DimmsToCheckIndex++) {
for (AllDimmListIndex = 0; AllDimmListIndex < AllDimmCount; AllDimmListIndex++) {
if (pAllDimms[AllDimmListIndex].DimmID == pDimmsListToCheck[DimmsToCheckIndex]) {
if (pAllDimms[AllDimmListIndex].IsInPopulationViolation == TRUE) {
InSupportedConfig = FALSE;
break;
}
}
}
}
NVDIMM_EXIT();
return InSupportedConfig;
}
/**
Check if all dimms in the specified pDimmIds list have master passphrase enabled.
This helper method assumes all the dimms in the list exist.
This helper method also assumes the parameters are non-null.
@param[in] pAllDimms The dimm list found in NFIT
@param[in] AllDimmCount Size of the pAllDimms array
@param[in] pDimmsListToCheck Pointer to the array of DimmIDs to check
@param[in] DimmsToCheckCount Size of the pDimmsListToCheck array
@param[in] SkipFIS32Dimms indicates that Dimms with FIS 3.2 or above should always pass
@retval TRUE if all Dimms in pDimmsListToCheck array have master passphrase enabled
@retval FALSE if at least one DIMM does not have master passphrase enabled
**/
BOOLEAN
AllDimmsInListHaveMasterPassphraseEnabled(
IN DIMM_INFO *pAllDimms,
IN UINT32 AllDimmCount,
IN UINT16 *pDimmsListToCheck,
IN UINT32 DimmsToCheckCount,
IN BOOLEAN SkipFIS32Dimms
)
{
BOOLEAN MasterPassphraseEnabled = FALSE;
UINT32 AllDimmListIndex = 0;
UINT32 DimmsToCheckIndex = 0;
BOOLEAN DimmFound = FALSE;
NVDIMM_ENTRY();
if (pAllDimms == NULL || pDimmsListToCheck == NULL ||
AllDimmCount == 0 || DimmsToCheckCount == 0) {
NVDIMM_DBG("Invalid parameter.");
goto Finish;
}
for (DimmsToCheckIndex = 0; DimmsToCheckIndex < DimmsToCheckCount; DimmsToCheckIndex++) {
DimmFound = FALSE;
for (AllDimmListIndex = 0; AllDimmListIndex < AllDimmCount; AllDimmListIndex++) {
if (pAllDimms[AllDimmListIndex].DimmID == pDimmsListToCheck[DimmsToCheckIndex]) {
DimmFound = TRUE;
if (pAllDimms[AllDimmListIndex].MasterPassphraseEnabled == FALSE) {
// starting in FIS 3.2, MasterPassphraseEnabled shows as false until the passphrase is changed from the default
if (SkipFIS32Dimms) {
if (((3 == pAllDimms[AllDimmListIndex].FwVer.FwApiMajor) && (2 > pAllDimms[AllDimmListIndex].FwVer.FwApiMinor)) ||
(2 >= pAllDimms[AllDimmListIndex].FwVer.FwApiMajor)) {
goto Finish;
}
}
else {
goto Finish;
}
}
}
}
if (!DimmFound) {
NVDIMM_DBG("DimmID: 0x%04x not found.", pDimmsListToCheck[DimmsToCheckIndex]);
goto Finish;
}
}
MasterPassphraseEnabled = TRUE;
Finish:
NVDIMM_EXIT();
return MasterPassphraseEnabled;
}
/**
Retrieve the User Cli Display Preferences CMD line arguments.
@param[out] pDisplayPreferences pointer to the current driver preferences.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid
@retval EFI_SUCCESS All ok
**/
EFI_STATUS
ReadCmdLinePrintOptions(
IN OUT PRINT_FORMAT_TYPE *pFormatType,
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
CHAR16 *OutputOptions = NULL;
CHAR16 **Toks = NULL;
UINT32 NumToks = 0;
UINT32 Index = 0;
if (NULL == pFormatType) {
return EFI_INVALID_PARAMETER;
}
if (NULL == (OutputOptions = getOptionValue(pCmd, OUTPUT_OPTION_SHORT))) {
if (NULL == (OutputOptions = getOptionValue(pCmd, OUTPUT_OPTION))) {
*pFormatType = TEXT;
PRINTER_ENABLE_LIST_TABLE_FORMAT(pCmd->pPrintCtx);
return ReturnCode;
}
}
*pFormatType = TEXT; //default
if (NULL != (Toks = StrSplit(OutputOptions, L',', &NumToks))) {
for (Index = 0; Index < NumToks; ++Index) {
if (0 == StrICmp(Toks[Index], OUTPUT_OPTION_TEXT)) {
*pFormatType = TEXT;
PRINTER_ENABLE_LIST_TABLE_FORMAT(pCmd->pPrintCtx); // default for TEXT
}
else if (0 == StrICmp(Toks[Index], OUTPUT_OPTION_NVMXML)) {
*pFormatType = XML;
}
else if (0 == StrICmp(Toks[Index], OUTPUT_OPTION_ESX_XML)) {
*pFormatType = XML;
PRINTER_ENABLE_ESX_XML_FORMAT(pCmd->pPrintCtx);
}
else if (0 == StrICmp(Toks[Index], OUTPUT_OPTION_ESX_TABLE_XML)) {
*pFormatType = XML;
PRINTER_ENABLE_ESX_TABLE_XML_FORMAT(pCmd->pPrintCtx);
}
else {
// Print out syntax specific help message for invalid -output option
CHAR16 * pHelpStr = getCommandHelp(pCmd, TRUE);
CHAR16 *pSyntaxTokStr = CatSPrint(NULL, CLI_PARSER_ERR_UNEXPECTED_TOKEN, Toks[Index]);
if (NULL != pHelpStr) {
CHAR16 *pSyntaxHelp = CatSPrintClean(pSyntaxTokStr, FORMAT_NL_STR FORMAT_NL_STR, CLI_PARSER_DID_YOU_MEAN, pHelpStr);
LongPrint(pSyntaxHelp);
FREE_POOL_SAFE(pSyntaxHelp);
}
else
{
// in case the command is bad, try to print something helpful.
LongPrint(pSyntaxTokStr);
FREE_POOL_SAFE(pSyntaxTokStr);
}
FREE_POOL_SAFE(pHelpStr);
ReturnCode = EFI_INVALID_PARAMETER;
}
}
}
FREE_POOL_SAFE(OutputOptions);
FreeStringArray(Toks, NumToks);
FREE_POOL_SAFE(OutputOptions);
return ReturnCode;
}
/**
Helper to recreate -o args in string format
@param[in] pCmd command from CLI
@param[out] ppOutputStr resulting -o string
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd or ppOutputStr is NULL
**/
EFI_STATUS
CreateCmdLineOutputStr(
IN struct Command *pCmd,
OUT CHAR16 **ppOutputStr
)
{
if (NULL == pCmd || NULL == ppOutputStr) {
return EFI_INVALID_PARAMETER;
}
if (XML != pCmd->pPrintCtx->FormatType) {
*ppOutputStr = CatSPrint(NULL, L"");
return EFI_SUCCESS;
}
*ppOutputStr = CatSPrint(*ppOutputStr, OUTPUT_OPTION_SHORT L" ");
if (pCmd->pPrintCtx->FormatTypeFlags.Flags.EsxCustom) {
*ppOutputStr = CatSPrintClean(*ppOutputStr, OUTPUT_OPTION_ESX_TABLE_XML L" ");
}
else if (pCmd->pPrintCtx->FormatTypeFlags.Flags.EsxKeyVal) {
*ppOutputStr = CatSPrintClean(*ppOutputStr, OUTPUT_OPTION_ESX_XML L" ");
}
else {
*ppOutputStr = CatSPrintClean(*ppOutputStr, OUTPUT_OPTION_NVMXML L" ");
}
return EFI_SUCCESS;
}
/**
Get Dimm identifier preference
@param[out] pDimmIdentifier Variable to store Dimm identifier preference
@retval EFI_SUCCESS Success
@retval EFI_INVALID_PARAMETER Input parameter is NULL
**/
EFI_STATUS
GetDimmIdentifierPreference(
OUT UINT8 *pDimmIdentifier
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
DISPLAY_PREFERENCES DisplayPreferences;
NVDIMM_ENTRY();
ZeroMem(&DisplayPreferences, sizeof(DisplayPreferences));
if (pDimmIdentifier == NULL) {
goto Finish;
}
ReturnCode = ReadRunTimePreferences(&DisplayPreferences, DISPLAY_CLI_INFO);
if (EFI_ERROR(ReturnCode)) {
Print(FORMAT_STR_NL, CLI_ERR_DISPLAY_PREFERENCES_RETRIEVE);
goto Finish;
}
*pDimmIdentifier = DisplayPreferences.DimmIdentifier;
ReturnCode = EFI_SUCCESS;
Finish:
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Get Dimm identifier as string based on user preference
@param[in] DimmId Dimm ID as number
@param[in] pDimmUid Dimm UID as string
@param[out] pResultString String representation of preferred value
@param[in] ResultStringLen Length of pResultString
@retval EFI_SUCCESS Success
@retval EFI_INVALID_PARAMETER Input parameter is NULL
**/
EFI_STATUS
GetPreferredDimmIdAsString(
IN UINT32 DimmId,
IN CHAR16 *pDimmUid OPTIONAL,
OUT CHAR16 *pResultString,
IN UINT32 ResultStringLen
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
UINT8 DimmIdentifier = 0;
NVDIMM_ENTRY();
if (pResultString == NULL) {
goto Finish;
}
ReturnCode = GetDimmIdentifierPreference(&DimmIdentifier);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
ReturnCode = GetPreferredValueAsString(DimmId, pDimmUid, DimmIdentifier == DISPLAY_DIMM_ID_HANDLE,
pResultString, ResultStringLen);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
ReturnCode = EFI_SUCCESS;
Finish:
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Retrieve Display DimmID Runtime Index from Property String
@param[in] String to try to discover index for
@retval DimmID Index of DimmID property string
@retval Size of Array if not found
**/
UINT8 GetDimmIDIndex(
IN CHAR16 *pDimmIDStr
)
{
UINT8 Index = 0;
for (Index = 0; Index < DISPLAY_DIMM_ID_MAX_SIZE; Index++) {
if (StrICmp(pDimmIDStr, mpDefaultDimmIds[Index]) == 0) {
break;
}
}
return Index;
}
/**
Retrieve Display Size Runtime Index from Property String
@param[in] String to try to discover index for
@retval Display Size Index of Size property string
@retval Size of Array if not found
**/
UINT8 GetDisplaySizeIndex(
IN CHAR16 *pSizeStr
)
{
UINT8 Index = 0;
for (Index = 0; Index < DISPLAY_SIZE_MAX_SIZE; Index++) {
if (StrICmp(pSizeStr, mpDefaultSizeStrs[Index]) == 0) {
break;
}
}
return Index;
}
/**
Retrieve Display DimmID String from RunTime variable index
@param[in] Index to retrieve
@retval NULL Index was invalid
@retval DimmID String of user display preference
**/
CONST CHAR16 *GetDimmIDStr(
IN UINT8 DimmIDIndex
)
{
if (DimmIDIndex >= DISPLAY_DIMM_ID_MAX_SIZE) {
return NULL;
}
return mpDefaultDimmIds[DimmIDIndex];
}
/**
Retrieve Display Size String from RunTime variable index
@param[in] Index to retrieve
@retval NULL Index was invalid
@retval Size String of user display preference
**/
CONST CHAR16 *GetDisplaySizeStr(
IN UINT16 DisplaySizeIndex
)
{
if (DisplaySizeIndex >= DISPLAY_SIZE_MAX_SIZE) {
return NULL;
}
return mpDefaultSizeStrs[DisplaySizeIndex];
}
/**
Allocate and return string which is related with the binary RegionType value.
The caller function is obligated to free memory of the returned string.
@param[in] RegionType - region type
@retval - output string
**/
CHAR16 *
RegionTypeToString(
IN UINT8 RegionType
)
{
CHAR16 *pRegionTypeString = NULL;
if ((RegionType & PM_TYPE_AD) != 0) {
pRegionTypeString = CatSPrintClean(pRegionTypeString, FORMAT_STR, PERSISTENT_MEM_TYPE_AD_STR);
}
if ((RegionType & PM_TYPE_AD_NI) != 0) {
pRegionTypeString = CatSPrintClean(pRegionTypeString, FORMAT_STR FORMAT_STR,
pRegionTypeString == NULL ? L"" : L", ", PERSISTENT_MEM_TYPE_AD_NI_STR);
}
return pRegionTypeString;
}
/**
Gets the DIMM handle corresponding to Dimm PID and also the index
@param[in] DimmId - DIMM ID
@param[in] pDimms - List of DIMMs
@param[in] DimmsNum - Number of DIMMs
@param[out] pDimmHandle - The Dimm Handle corresponding to the DIMM ID
@param[out] pDimmIndex - The Index of the found DIMM
@retval - EFI_STATUS Success
@retval - EFI_INVALID_PARAMETER Invalid parameter
@retval - EFI_NOT_FOUND Dimm not found
**/
EFI_STATUS
GetDimmHandleByPid(
IN UINT16 DimmId,
IN DIMM_INFO *pDimms,
IN UINT32 DimmsNum,
OUT UINT32 *pDimmHandle,
OUT UINT32 *pDimmIndex
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
DIMM_INFO *pFoundDimm = NULL;
UINT32 Index = 0;
NVDIMM_ENTRY();
if (pDimms == NULL || pDimmHandle == NULL || pDimmIndex == NULL) {
goto Finish;
}
for (Index = 0; Index < DimmsNum; Index++) {
if (pDimms[Index].DimmID == DimmId) {
pFoundDimm = &pDimms[Index];
*pDimmIndex = Index;
break;
}
}
if (pFoundDimm == NULL) {
ReturnCode = EFI_NOT_FOUND;
goto Finish;
}
*pDimmHandle = pFoundDimm->DimmHandle;
ReturnCode = EFI_SUCCESS;
Finish:
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Convert UEFI return codes to legacy OS return codes
@param[in] UefiReturnCode - return code to Convert
@retval - Converted OS ReturnCode
**/
EFI_STATUS UefiToOsReturnCode(EFI_STATUS UefiReturnCode)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
switch (UefiReturnCode)
{
case (0):
break;
case (2):
ReturnCode = 201;
break;
case (EFI_INVALID_PARAMETER):
ReturnCode = 201;
break;
case (EFI_ALREADY_STARTED):
//this number is arbitrary, but should be distinct.
//In the case of FW update, it indicates that all DIMMs
//have a staged FW binary
ReturnCode = 20;
break;
default:
ReturnCode = 1;
}
return ReturnCode;
}
/**
Checks if user has incorrectly used master and default options. Also checks for
invalid combinations of these options with the Passphrase property.
@param[in] pCmd command from CLI
@param[in] isPassphraseProvided TRUE if user provided passphrase
@param[in] isMasterOptionSpecified TRUE if master option is specified
@param[in] isDefaultOptionSpecified TRUE if default option is specified
@retval EFI_SUCCESS Success
@retval EFI_INVALID_PARAMETER One or more parameters are invalid
**/
EFI_STATUS
CheckMasterAndDefaultOptions(
IN struct Command *pCmd,
IN BOOLEAN isPassphraseProvided,
IN BOOLEAN isMasterOptionSpecified,
IN BOOLEAN isDefaultOptionSpecified
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
PRINT_CONTEXT *pPrinterCtx = NULL;
NVDIMM_ENTRY();
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("pCmd parameter is NULL.\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
if (isPassphraseProvided) {
if (isMasterOptionSpecified && isDefaultOptionSpecified) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_DEFAULT_OPTION_PASSPHRASE_PROPERTY_USED_TOGETHER);
goto Finish;
}
else if (!isMasterOptionSpecified && isDefaultOptionSpecified) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_DEFAULT_OPTION_NOT_COMBINED);
goto Finish;
}
}
else { // Passphrase not provided
if (isMasterOptionSpecified && !isDefaultOptionSpecified) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_MISSING_PASSPHRASE_PROPERTY);
goto Finish;
}
else if (!isMasterOptionSpecified && isDefaultOptionSpecified) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_DEFAULT_OPTION_NOT_COMBINED);
goto Finish;
}
}
Finish:
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Retrieves a list of Dimms that have at least one NS.
@param[in,out] pDimmIds the dimm IDs which have NS
@param[in,out] pDimmIdCount count of dimm IDs
@param[in] maxElements the maximum size of the dimm ID list
@retval EFI_ABORTED Operation Aborted
@retval EFI_OUT_OF_RESOURCES unable to allocate memory
@retval EFI_SUCCESS All Ok
**/
EFI_STATUS
GetDimmIdsWithNamespaces(
IN OUT UINT16 *pDimmIds,
IN OUT UINT32 *pDimmIdCount,
IN UINT32 maxElements)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
COMMAND_STATUS *pCommandStatus = NULL;
UINT32 NamespacesCount = 0;
LIST_ENTRY NamespaceListHead;
NAMESPACE_INFO *pNamespaceInfo = NULL;
LIST_ENTRY *pCurNamespace = NULL;
UINT32 RegionIndex = 0;
UINT32 Index = 0;
UINT32 RegionCount = 0;
REGION_INFO *pRegions = NULL;
LIST_ENTRY *pTmpListNode = NULL;
LIST_ENTRY *pTmpListNextNode = NULL;
NVDIMM_ENTRY();
ZeroMem(&NamespaceListHead, sizeof(NamespaceListHead));
InitializeListHead(&NamespaceListHead);
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_ABORTED;
NVDIMM_DBG("Failed on InitializeCommandStatus");
goto Finish;
}
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID**)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
/* Load Regions */
ReturnCode = pNvmDimmConfigProtocol->GetRegionCount(pNvmDimmConfigProtocol, FALSE, &RegionCount);
if (EFI_ERROR(ReturnCode)) {
if (EFI_NO_RESPONSE == ReturnCode) {
ResetCmdStatus(pCommandStatus, NVM_ERR_BUSY_DEVICE);
}
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
goto Finish;
}
pRegions = AllocateZeroPool(sizeof(REGION_INFO) * RegionCount);
if (pRegions == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
goto Finish;
}
ReturnCode = pNvmDimmConfigProtocol->GetRegions(pNvmDimmConfigProtocol, RegionCount, FALSE, pRegions, pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
if (pCommandStatus->GeneralStatus != NVM_SUCCESS) {
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
}
else {
ReturnCode = EFI_ABORTED;
}
NVDIMM_WARN("Failed to retrieve the REGION list");
goto Finish;
}
/*Load Namespaces*/
ReturnCode = pNvmDimmConfigProtocol->GetNamespaces(pNvmDimmConfigProtocol, &NamespaceListHead, &NamespacesCount, pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
if (pCommandStatus->GeneralStatus != NVM_SUCCESS) {
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
}
NVDIMM_WARN("Failed to retrieve Namespaces list");
goto Finish;
}
for (RegionIndex = 0; RegionIndex < RegionCount; RegionIndex++) {
LIST_FOR_EACH(pCurNamespace, &NamespaceListHead) {
pNamespaceInfo = NAMESPACE_INFO_FROM_NODE(pCurNamespace);
if (pNamespaceInfo->RegionId == pRegions[RegionIndex].RegionId) {
//add the DIMM id to the main return list
for (Index = 0; Index < pRegions[RegionIndex].DimmIdCount; Index++) {
ReturnCode = AddElement(pDimmIds, pDimmIdCount, pRegions[RegionIndex].DimmId[Index], maxElements);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Failed to add the DIMM ID to the list");
goto Finish;
}
}
}
}
}
Finish:
NVDIMM_EXIT_I64(ReturnCode);
FREE_POOL_SAFE(pRegions);
LIST_FOR_EACH_SAFE(pTmpListNode, pTmpListNextNode, &NamespaceListHead) {
FreePool(NAMESPACE_INFO_FROM_NODE(pTmpListNode));
}
FreeCommandStatus(&pCommandStatus);
return ReturnCode;
}
/**
Adds an element to a element list without allowing duplication
@param[in,out] pElementList the list
@param[in,out] pElementCount size of the list
@param[in] newElement the new element to add
@param[in] maxElements the maximum size of the list
@retval EFI_OUT_OF_RESOURCES unable to add any more elements
@retval EFI_SUCCESS All Ok
**/
EFI_STATUS AddElement(
IN OUT UINT16 *pElementList,
IN OUT UINT32 *pElementCount,
IN UINT16 newElement,
IN UINT32 maxElements)
{
UINT32 x = 0;
//check for initial condition
if (pElementList == NULL || pElementCount == NULL)
{
return EFI_SUCCESS;
}
//see if the list already has this item
for (; x < *pElementCount && x < maxElements; x++)
{
if (pElementList[x] == newElement) {
return EFI_SUCCESS;
}
}
if (x == maxElements) {
return EFI_OUT_OF_RESOURCES;
}
*pElementCount = (*pElementCount) + 1;
pElementList[x] = newElement;
return EFI_SUCCESS;
}
/**
Checks whether the FW on the dimm restricts executing commands
with the default Master Passphrase. The restriction is implemented
in API version 3.2.
@param[in] DimmInfo is the information about the dimm to check
@retval whether default is restricted by the FW's API version
**/
BOOLEAN IsDefaultMasterPassphraseRestricted(
IN DIMM_INFO DimmInfo)
{
if (((3 == DimmInfo.FwVer.FwApiMajor) && (2 <= DimmInfo.FwVer.FwApiMinor)) ||
(4 <= DimmInfo.FwVer.FwApiMajor)) {
return TRUE;
}
else {
return FALSE;
}
} ipmctl-03.00.00.0423/DcpmPkg/cli/Common.h 0000664 0000000 0000000 00000134356 14165347476 0017343 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _COMMON_H_
#define _COMMON_H_
#include
#include "CommandParser.h"
#include "NvmStatus.h"
extern OBJECT_STATUS gAllErrorNvmStatuses;
extern OBJECT_STATUS gAllWarningNvmStatuses;
extern EFI_GUID gNvmDimmConfigProtocolGuid;
extern EFI_GUID gNvmDimmPbrProtocolGuid;
typedef struct _CMD_DISPLAY_OPTIONS {
BOOLEAN DisplayOptionSet;
BOOLEAN AllOptionSet;
CHAR16 *pDisplayValues;
}CMD_DISPLAY_OPTIONS;
/** common display options **/
#define SOCKET_ID_STR L"SocketID"
#define DIE_ID_STR L"DieID"
#define DIMM_ID_STR L"DimmID"
#define TAG_ID_STR L"TagID"
#define EXIT_CODE_STR L"RC"
#define CLI_ARGS_STR L"Args"
#define TAG_STR L"Tag"
#define DDR_STR L"DDR"
// Find PMEM_MODULE_STR in CommandParser.h
#define TOTAL_STR L"Total"
#define MEMORY_TYPE_STR L"MemoryType"
/** common display values**/
#define NA_STR L"N/A"
#define DASH_STR L"-"
#define MAX_FILE_PATH_LEN 512
#define MAX_FILE_SYSTEM_STRUCT_SIZE BLOCKSIZE_4K
#define MAX_SHELL_PROTOCOL_HANDLES 2
#define PROGRESS_EVENT_TIMEOUT EFI_TIMER_PERIOD_SECONDS(1)
#define PRINT_PRIORITY 8
// FW log level string values
#define FW_LOG_LEVEL_DISABLED_STR L"Disabled"
#define FW_LOG_LEVEL_ERROR_STR L"Error"
#define FW_LOG_LEVEL_WARNING_STR L"Warning"
#define FW_LOG_LEVEL_INFO_STR L"Info"
#define FW_LOG_LEVEL_DEBUG_STR L"Debug"
#define FW_LOG_LEVEL_UNKNOWN_STR L"Unknown"
// Parser CLI messages
#define CLI_PARSER_DID_YOU_MEAN L"Did you mean:"
#define CLI_PARSER_ERR_UNEXPECTED_TOKEN L"Syntax Error: Invalid or unexpected token " FORMAT_STR L"."
#define CLI_PARSER_ERR_INVALID_COMMAND L"Syntax Error: Invalid or unsupported command."
#define CLI_PARSER_ERR_INVALID_OPTION_VALUES L"Syntax Error: Invalid option values input."
#define CLI_PARSER_ERR_MUTUALLY_EXCLUSIVE_OPTIONS L"Syntax Error: Mutually exclusive options " FORMAT_STR L" and " FORMAT_STR L"."
#define CLI_PARSER_ERR_INVALID_TARGET_VALUES L"Syntax Error: Invalid target values input."
#define CLI_PARSER_ERR_VERB_EXPECTED L"Syntax Error: First token must be a verb, '" FORMAT_STR L"' is not a supported verb."
#define CLI_PARSER_DETAILED_ERR_OPTION_VALUE_REQUIRED L"The option " FORMAT_STR L" requires a value."
#define CLI_PARSER_DETAILED_ERR_OPTION_VALUE_UNEXPECTED L"The option " FORMAT_STR L" does not accept a value."
#define CLI_PARSER_DETAILED_ERR_TARGET_VALUE_REQUIRED L"The target " FORMAT_STR L" requires a value."
#define CLI_PARSER_DETAILED_ERR_TARGET_VALUE_UNEXPECTED L"The target " FORMAT_STR L" does not accept a value."
#define CLI_PARSER_DETAILED_ERR_PROPERTY_VALUE_REQUIRED L"The property " FORMAT_STR L" requires a value."
#define CLI_PARSER_DETAILED_ERR_PROPERTY_VALUE_UNEXPECTED L"The property " FORMAT_STR L" does not accept a value."
#define CLI_PARSER_DETAILED_ERR_OPTION_REQUIRED L"Missing required option " FORMAT_STR L"."
#define CLI_PARSER_DETAILED_ERR_PROPERTY_REQUIRED L"Missing required property " FORMAT_STR L"."
// Common CLI error messages defined in specification
#define CLI_ERR_OPENING_CONFIG_PROTOCOL L"Error: Communication with the device driver failed."
#define CLI_ERR_FAILED_TO_FIND_PROTOCOL L"Error: DCPMM_CONFIG2_PROTOCOL not found."
#define CLI_ERR_INVALID_REGION_ID L"Error: The region identifier is not valid."
#define CLI_ERR_INVALID_NAMESPACE_ID L"Error: The namespace identifier is not valid."
#define CLI_ERR_NO_DIMMS_ON_SOCKET L"Error: There are no " PMEM_MODULES_STR L" on the specified socket(s)."
#define CLI_ERR_NO_SPECIFIED_DIMMS_ON_SPECIFIED_SOCKET L"Error: None of the specified " PMEM_MODULE_STR L"(s) belong to the specified socket(s)."
#define CLI_ERR_INVALID_SOCKET_ID L"Error: The socket identifier is not valid."
#define CLI_ERR_OUT_OF_MEMORY L"Error: There is not enough memory to complete the requested operation."
#define CLI_ERR_WRONG_FILE_PATH L"Error: Wrong file path."
#define CLI_ERR_WRONG_FILE_DATA L"Error: Wrong data in the file."
#define CLI_ERR_INTERNAL_ERROR L"Error: Internal function error."
#define CLI_ERR_PROMPT_INVALID L"Error: Invalid data input."
#define CLI_ERR_WRONG_DIAGNOSTIC_TARGETS L"Error: Invalid diagnostics target, valid values are: " FORMAT_STR
#define CLI_ERR_WRONG_REGISTER L"Error: Register not found"
#define CLI_ERR_INVALID_PASSPHRASE_FROM_FILE L"Error: The file contains empty or bad formatted passphrases."
#define CLI_ERR_UNMANAGEABLE_DIMM L"Error: The specified device is not manageable by the driver."
#define CLI_ERR_POPULATION_VIOLATION L"Error: The specified device is in population violation."
#define CLI_ERR_REGION_TO_SOCKET_MAPPING L"The specified region id might not exist on the specified Socket(s).\n"
#define CLI_ERR_PCD_CORRUPTED L"Error: Unable to complete operation due to existing PCD Configuration partition corruption. Use create -f -goal to override current PCD and create goal."
#define CLI_ERR_OPENING_PBR_PROTOCOL L"Error: Communication with the device driver failed. Failed to obtain PBR protocol."
#define CLI_WARNING_CLI_DRIVER_VERSION_MISMATCH L"Warning: There is a CLI and Driver version mismatch. Behavior is undefined."
// Common CLI error messages defined in specification
#define CLI_ERR_NO_COMMAND L"Syntax Error: No input."
#define CLI_ERR_INCOMPLETE_SYNTAX L"Syntax Error: Incomplete syntax."
#define CLI_ERR_UNSUPPORTED_COMMAND_SYNTAX L"Syntax Error: Invalid or unsupported command."
#define CLI_ERR_INCORRECT_VALUE_POISON_TYPE L"Syntax Error: Incorrect value for property PoisonType."
#define CLI_ERR_INCORRECT_VALUE_OPTION_DISPLAY L"Syntax Error: Incorrect value for option -d|-display."
#define CLI_ERR_INCORRECT_VALUE_OPTION_UNITS L"Syntax Error: Incorrect value for option -units."
#define CLI_ERR_INCORRECT_VALUE_OPTION_RECOVER L"Syntax Error: Incorrect value for option -recover."
#define CLI_ERR_INCORRECT_VALUE_TARGET_REGISTER L"Syntax Error: Incorrect value for target -register."
#define CLI_ERR_INCORRECT_VALUE_TARGET_DIMM L"Syntax Error: Incorrect value for target -dimm."
#define CLI_ERR_INCORRECT_VALUE_TARGET_SOCKET L"Syntax Error: Incorrect value for target -socket."
#define CLI_ERR_INCORRECT_VALUE_TARGET_NAMESPACE L"Syntax Error: Incorrect value for target -namespace."
#define CLI_ERR_INCORRECT_VALUE_TARGET_REGION L"Syntax Error: Incorrect value for target -region."
#define CLI_ERR_INCORRECT_VALUE_TARGET_ERROR L"Syntax Error: Incorrect value for target -error."
#define CLI_ERR_INCORRECT_VALUE_TARGET_SMBIOS L"Syntax Error: Incorrect value for target -smbios."
#define CLI_ERR_INCORRECT_VALUE_TARGET_SENSOR L"Syntax Error: Incorrect value for target -sensor."
#define CLI_ERR_INCORRECT_VALUE_TARGET_PCD L"Syntax Error: Incorrect value for target -pcd."
#define CLI_ERR_INCORRECT_VALUE_TARGET_PERFORMANCE L"Syntax Error: Incorrect value for target -performance."
#define CLI_ERR_INCORRECT_VALUE_TARGET_EVENT L"Syntax Error: Incorrect value for target -event."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_MEMORY_MODE L"Syntax Error: Incorrect value for property MemoryMode."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_PERSISTENT_MEM_TYPE L"Syntax Error: Incorrect value for property PersistentMemoryType."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_RESERVED L"Syntax Error: Incorrect value for property Reserved."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_BLOCK_SIZE L"Syntax Error: Incorrect value for property BlockSize."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_BLOCK_COUNT L"Syntax Error: Incorrect value for property BlockCount."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_CAPACITY L"Syntax Error: Incorrect value for property Capacity."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_NAME L"Syntax Error: Incorrect value for property Name."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_ERASE_CAPABLE L"Syntax Error: Incorrect value for property EraseCapable."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_ENCRYPTION L"Syntax Error: Incorrect value for property Encryption."
#define CLI_ERR_INCORRECT_PROPERTY_VALUE_MODE L"Syntax Error: Incorrect value for property Mode."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_RAW_CAPACITY L"Syntax Error: Incorrect value for property Size."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_ERASE_TYPE L"Syntax Error: Incorrect value for property EraseType."
#define CLI_ERR_INCORRECT_VALUE_FOR_PROPERTY_AVG_PWR_REPORTING_TIME_CONSTANT L"Syntax Error: Incorrect value for property AveragePowerReportingTimeConstant."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_LEVEL L"Syntax Error: Incorrect value for property Level."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_COUNT L"Syntax Error: Incorrect value for property Count."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_CATEGORY L"Syntax Error: Incorrect value for property Category."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_SEQ_NUM L"Syntax Error: Incorrect value for property SequenceNumber."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_ALARM_THRESHOLD L"Syntax Error: Incorrect value for property AlarmThreshold."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_ENABLED_STATE L"Syntax Error: Incorrect value for property AlarmThreshold."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_NS_LABEL_VERSION L"Syntax Error: Incorrect value for property NamespaceLabelVersion."
#define CLI_ERR_INCORRECT_VALUE_PROPERTY_CONFIG L"Syntax Error: Incorrect value for property Config."
#define CLI_ERR_INCORRECT_VALUE_TARGET_TOKEN_ID L"Syntax Error: Incorrect value for target -tokens."
#define CLI_ERROR_POISON_TYPE_WITHOUT_ADDRESS L"Syntax Error: Poison type property should be followed by poison address."
#define CLI_ERROR_CLEAR_PROPERTY_NOT_COMBINED L"Syntax Error: Clear property should be given in combination with other error injection properties."
#define CLI_ERR_MISSING_VALUE_PROPERTY_TYPE L"Syntax Error: Type property not provided."
#define CLI_ERR_INCORRECT_VALUE_FOR_PROPERTY L" is not a valid setting for the property."
#define CLI_SYNTAX_ERROR L" Syntax Error: "
#define CLI_ERR_OPTIONS_ALL_DISPLAY_USED_TOGETHER L"Syntax Error: Options -a|-all and -d|-display can not be used together."
#define CLI_ERR_OPTIONS_EXAMINE_USED_TOGETHER L"Syntax Error: Options -x and -examine can not be used together."
#define CLI_ERR_OPTIONS_FORCE_USED_TOGETHER L"Syntax Error: Options -f and -force can not be used together."
#define CLI_ERR_VALUES_APPDIRECT_SIZE_USED_TOGETHER L"Syntax Error: Option values AppDirectSize and AppDirect1Size can not be used together."
#define CLI_ERR_VALUES_APPDIRECT_INDICES_USED_TOGETHER L"Syntax Error: Option values AppDirectIndex and AppDirect1Index can not be used together."
#define CLI_ERR_PROPERTIES_CAPACITY_BLOCKCOUNT_USED_TOGETHER L"Syntax Error: Properties Capacity and BlockCount can not be used together."
#define CLI_ERR_PROPERTIES_MEMORYMODE_RESERVED_TOO_LARGE L"Syntax Error: Properties MemoryMode and Reserved cannot sum greater than 100%%%%" //%%%% because format string is processed twice
#define CLI_INFO_NO_DIMMS L"No " PMEM_MODULES_STR L" in the system."
#define CLI_INFO_NO_FUNCTIONAL_DIMMS L"No functional " PMEM_MODULES_STR L" in the system."
#define CLI_INFO_NO_REGIONS L"There are no Regions defined in the system."
#define CLI_INFO_NO_MANAGEABLE_DIMMS L"No manageable " PMEM_MODULES_STR L" in the system."
#define CLI_INFO_NO_NON_FUNCTIONAL_DIMMS L"No non-functional " PMEM_MODULES_STR L" in the system."
#define CLI_INFO_SHOW_REGION L"Show Region"
#define CLI_INFO_NO_NAMESPACES_DEFINED L"No Namespaces defined in the system."
#define CLI_INFO_SHOW_NAMESPACE L"Show Namespace"
#define CLI_INFO_SET_NAMESPACE L"Set Namespace"
#define CLI_INFO_DELETE_NAMESPACE L"Delete Namespace"
#define CLI_INFO_DUMP_DEBUG_LOG L"Dump Debug Log"
#define CLI_INFO_LOAD_GOAL L"Load Goal"
#define CLI_INFO_LOAD_GOAL_CONFIRM_PROMPT L"Load the configuration goal from '" FORMAT_STR L"' which will delete existing data and provision the capacity of the " PMEM_MODULES_STR L" on the next reboot."
#define CLI_INFO_SHOW_REGISTER L"Show Register"
#define CLI_INFO_SHOW_PCD L"Show Platform Config Data"
#define CLI_ERR_MASTER_PASSPHRASE_NOT_ENABLED L"Master Passphrase not enabled on specified " PMEM_MODULES_STR L"."
#define CLI_ERR_MISSING_PASSPHRASE_PROPERTY L"Syntax Error: Passphrase property not provided."
#define CLI_ERR_DEFAULT_OPTION_NOT_COMBINED L"Syntax Error: Default option should be given in combination with master option."
#define CLI_ERR_DEFAULT_OPTION_PASSPHRASE_PROPERTY_USED_TOGETHER L"Syntax Error: Passphrase property and default option cannot be used together."
#define CLI_ERR_DEFAULT_NOT_SUPPORTED_FIRMWARE_REV L"Default option for Master Passphrase is only supported for setting Master Passphrase on at least one of the " PMEM_MODULES_STR "."
#define CLI_ERR_FORCE_REQUIRED L"Error: This command requires force option."
#define CLI_ERR_INVALID_BLOCKSIZE_FOR_CAPACITY L"Error: Capacity property can only be used with 512 or 4096 bytes block size."
#define CLI_ERR_INVALID_NAMESPACE_CAPACITY L"Error: Invalid value for namespace capacity."
#define CLI_ERR_SOME_VALUES_NOT_SUPPORTED L"Error: One or more of the fields specified are not supported on all the " PMEM_MODULES_STR L"."
#define CLI_ERR_PRINTING_DIAGNOSTICS_RESULTS L"Error: Printing of diagnostics results failed."
#define CLI_INJECT_ERROR_FAILED L"Error: Inject error command failed"
#define CLI_ERR_NOT_UTF16 L"Error: The file is not in UTF16 format, BOM header missing.\n"
#define CLI_ERR_EMPTY_FILE L"Error: The file is empty.\n"
#define CLI_ERR_NO_SOCKET_SKU_SUPPORT L"Platform does not support socket SKU limits.\n"
#define CLI_ERR_SOCKET_NOT_FOUND L"Socket not found. Invalid SocketID: %d\n"
#define CLI_ERR_CAPACITY_STRING L"Error: Failed creating the capacity string."
#define CLI_INFO_LOAD_FW L"Load FW"
#define CLI_INFO_LOAD_RECOVER_FW L"Load recovery FW"
#define CLI_INFO_LOAD_RECOVER_INVALID_DIMM L"The specified " PMEM_MODULE_STR L" does not exist or is not in a non-functional state."
#define CLI_INFO_ON L" on"
#define CLI_PROGRESS_STR L"\rOperation on " PMEM_MODULE_STR L" 0x%04x Progress: %d%%"
#define CLI_LOAD_MFG_FW L"MFG Load Prod FW"
#define CLI_INJECT_MFG L"MFG Inject command"
#define CLI_MEM_INFO_MFG L"MFG Mem Info page"
#define CLI_INFO_SET_FW_LOG_LEVEL L"Set firmware log level"
#define CLI_INFO_PACKAGE_SPARING_INJECT_ERROR L"Trigger package sparing"
#define CLI_INFO_POISON_INJECT_ERROR L"Poison address " FORMAT_STR
#define CLI_INFO_PERCENTAGE_REMAINING_INJECT_ERROR L"Trigger a percentage remaining"
#define CLI_INFO_FATAL_MEDIA_ERROR_INJECT_ERROR L"Create a media fatal error"
#define CLI_INFO_DIRTY_SHUT_DOWN_INJECT_ERROR L"Trigger a dirty shut down"
#define CLI_INFO_TEMPERATURE_INJECT_ERROR L"Set temperature"
#define CLI_INFO_CLEAR_PACKAGE_SPARING_INJECT_ERROR L"Clear injected package sparing"
#define CLI_INFO_CLEAR_POISON_INJECT_ERROR L"Clear injected poison of address " FORMAT_STR
#define CLI_INFO_CLEAR_PERCENTAGE_REMAINING_INJECT_ERROR L"Clear injected percentage remaining"
#define CLI_INFO_CLEAR_FATAL_MEDIA_ERROR_INJECT_ERROR L"Clear injected media fatal error"
#define CLI_INFO_CLEAR_DIRTY_SHUT_DOWN_INJECT_ERROR L"Clear dirty shut down"
#define CLI_INFO_CLEAR_TEMPERATURE_INJECT_ERROR L"Clear injected temperature"
#define PROMPT_CONTINUE_QUESTION L"Do you want to continue? [y/n] "
#define CLI_CREATE_GOAL_PROMPT_VOLATILE L"The requested goal was adjusted more than 10%% to find a valid configuration."
#define CLI_CREATE_GOAL_PROMPT_HEADER L"The following configuration will be applied:"
#define CLI_WARN_GOAL_CREATION_SECURITY_UNLOCKED L"WARNING: Goal will not be applied unless security is disabled prior to platform firmware (BIOS) provisioning!"
#define CLI_ERR_CREATE_GOAL_AUTO_PROV_ENABLED L"Error: Automatic provisioning is enabled. Please disable to manually create goals."
#define CLI_CREATE_NAMESPACE_PROMPT_ROUNDING_CAPACITY L"The requested namespace capacity %lld B will be rounded up to %lld B to align properly."
#define REGION_FOUND L"REGION FOUND."
#define CLI_ERR_DISPLAY_PREFERENCES_RETRIEVE L"Unable to retrieve user display preferences."
#define CLI_DOWNGRADE_PROMPT L"Downgrade firmware on " PMEM_MODULE_STR L" " FORMAT_STR L"?"
#define CLI_RECOVER_DIMM_PROMPT_STR L"Recover " PMEM_MODULE_STR L":"
#define CLI_FORMAT_DIMM_REBOOT_REQUIRED_STR L"A power cycle is required after a device format."
#define CLI_FORMAT_DIMM_PROMPT_STR L"This operation will take several minutes to complete and will erase all data on " PMEM_MODULE_STR L" "
#define CLI_INFO_START_FORMAT L"Format"
#define CLI_FORMAT_DIMM_STARTING_FORMAT L"Formatting " PMEM_MODULE_STR L"(s)..."
#define CLI_INFO_DUMP_SUPPORT_SUCCESS L"Dump support data successfully written to " FORMAT_STR L"."
#define CLI_INFO_DUMP_CONFIG_SUCCESS L"Successfully dumped system configuration to file: " FORMAT_STR_NL
#define CLI_ERR_INJECT_FATAL_ERROR_UNSUPPORTED_ON_OS L"Injecting a Fatal Media error is unsupported on this OS.\nPlease contact your OSV for assistance in performing this action."
#define CLI_ERR_TRANSPORT_PROTOCOL_UNSUPPORTED_ON_OS L"The following protocol " FORMAT_STR L" is unsupported on this OS. Please use " FORMAT_STR L" instead.\n"
#define PRINT_SETTINGS_FORMAT_FOR_SHOW_SYS_CAP_CMD 1
#define PRINT_SETTINGS_FORMAT_FOR_SHOW_REGION_CMD 2
#define CLI_ERR_FAILED_TO_GET_PBR_MODE L"Failed to get the current PBR mode."
#define CLI_ERR_FAILED_TO_SET_PBR_MODE L"Failed to configure the playback and record mode to: " FORMAT_STR
#define CLI_ERR_FAILED_NO_PBR_SESSION_LOADED L"Failed to configure the playback mode. No PBR session loaded."
#define CLI_ERR_FAILED_TO_SET_SESSION_TAG L"Failed to set the current tag location."
#define CLI_ERR_FAILED_TO_GET_SESSION_TAG L"Failed to get the current tag location."
#define CLI_ERR_FAILED_TO_GET_SESSION_TAG_COUNT L"Failed to get the session tag count."
#define CLI_ERR_FAILED_DURING_DRIVER_INIT L"Driver binding start failed."
#define CLI_ERR_FAILED_DURING_DRIVER_UNINIT L"Driver binding stop failed."
#define CLI_ERR_FAILED_DURING_CMD_EXECUTION L"Executing CMD during playback failed."
#define CLI_ERR_UNKNOWN_MODE L"Unknown PBR mode."
#define CLI_ERR_FAILED_TO_GET_SESSION_BUFFER L"Failed to get the current session buffer."
#define CLI_ERR_FAILED_TO_DUMP_SESSION_TO_FILE L"Failed to dump contents of session buffer to a file."
#define CLI_ERR_FAILED_TO_GET_FILE_PATH L"Failed to get file path " FORMAT_EFI_STATUS
#define CLI_ERR_FAILED_TO_READ_FILE L"Failed to read pbr file."
#define CLI_ERR_FAILED_TO_SET_SESSION_BUFFER L"Failed to set session buffer."
#define CLI_ERR_FAILED_TO_RESET_SESSION L"Failed to reset the session."
#define CLI_ERR_CMD_FAILED_NOT_ADMIN L"Error: The ipmctl command you have attempted to execute requires administrator privileges."
#define ERROR_CHECKING_MIXED_SKU L"Error: Could not check if SKU is mixed."
#define WARNING_DIMMS_SKU_MIXED L"Warning: Mixed SKU detected. Driver functionalities limited.\n"
/**
This prevents use of strlen on NULL string. StrLen fn in MdePkg has an assert if it is null.
**/
#define StrLen(Str) (((void *)(Str)==NULL)?(0):(StrLen(Str)))
/**
sizeof returns the number of bytes that the array uses.
We need to divide it by the length of a single pointer to get the number of elements.
**/
#define ALLOWED_DISP_VALUES_COUNT(A) (sizeof(A)/sizeof(CHAR16*))
/**
GUID for NvmDimmCli Variables for Get/Set via runtime services.
**/
#define NVMDIMM_CLI_NGNVM_VARIABLE_GUID \
{ 0x11c64219, 0xbfa2, 0x42ce, {0x99, 0xb1, 0x17, 0x0b, 0x4a, 0x2b, 0xe0, 0x8e}}
/**
Retrieve a populated array and count of DIMMs in the system. The caller is
responsible for freeing the returned array
@param[in] pNvmDimmConfigProtocol A pointer to the EFI_DCPMM_CONFIG2_PROTOCOL instance.
@param[in] pCmd A pointer to a COMMAND struct. Used to obtain the Printer context.
printed to stdout, otherwise will be directed to the printer module.
@param[in] dimmInfoCategories Categories that will be populated in
the DIMM_INFO struct.
@param[out] ppDimms A pointer to the dimm list found in NFIT.
@param[out] pDimmCount A pointer to the number of DIMMs found in NFIT.
@retval EFI_SUCCESS the dimm list was returned properly
@retval EFI_INVALID_PARAMETER one or more parameters are NULL
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_NOT_FOUND dimm not found
**/
EFI_STATUS
GetDimmList(
IN EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol,
IN struct Command *pCmd,
IN DIMM_INFO_CATEGORIES dimmInfoCategories,
OUT DIMM_INFO **ppDimms,
OUT UINT32 *pDimmCount
);
/**
Retrieve a populated array and count of all DCPMMs (functional and non-functional)
in the system. The caller is responsible for freeing the returned array
@param[in] pNvmDimmConfigProtocol A pointer to the EFI_DCPMM_CONFIG2_PROTOCOL instance.
@param[in] pCmd A pointer to a COMMAND struct. Used to obtain the Printer context.
printed to stdout, otherwise will be directed to the printer module.
@param[in] dimmInfoCategories Categories that will be populated in
the DIMM_INFO struct.
@param[out] ppDimms A pointer to a combined DCPMM list (initialized and
uninitialized) from NFIT.
@param[out] pDimmCount A pointer to the total number of DCPMMs found in NFIT.
@retval EFI_SUCCESS the dimm list was returned properly
@retval EFI_INVALID_PARAMETER one or more parameters are NULL
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_NOT_FOUND dimm not found
**/
EFI_STATUS
GetAllDimmList(
IN EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol,
IN struct Command *pCmd,
IN DIMM_INFO_CATEGORIES dimmInfoCategories,
OUT DIMM_INFO **ppDimms,
OUT UINT32 *pDimmCount
);
/**
Parse the string and return the array of unsigned integers
Example
String: "1,3,7"
Array[0]: 1
Array[1]: 3
Array[2]: 7
@param[in] pString string to parse
@param[out] ppUints allocated, filled array with the uints
@param[out] pUintsNum size of uints array
@retval EFI_SUCCESS
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_INVALID_PARAMETER inputs are null, the format of string is not proper, duplicated Dimm IDs
@retval EFI_NOT_FOUND Dimm not found
**/
EFI_STATUS
GetUintsFromString(
IN CHAR16 *pString,
OUT UINT16 **ppUints,
OUT UINT32 *pUintsNum
);
/**
Parses the dimm target string (which can contain DimmIDs as SMBIOS type-17 handles and/or DimmUIDs),
and returns an array of DimmIDs in the SMBIOS physical-id forms.
Also checks for invalid DimmIDs and duplicate entries.
Example
String: "8089-00-0000-13325476,30,0x0022"
Array[0]: 28
Array[1]: 30
Array[2]: 34
@param[in] pCmd A pointer to a COMMAND struct. Used to obtain the Printer context.
@param[in] pDimmString The dimm target string to parse.
@param[in] pDimmInfo The dimm list found in NFIT.
@param[in] DimmCount Size of the pDimmInfo array.
@param[out] ppDimmIds Pointer to the array allocated and filled with the SMBIOS DimmIDs.
@param[out] pDimmIdsCount Size of the pDimmIds array.
@retval EFI_SUCCESS
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_INVALID_PARAMETER the format of string is not proper
@retval EFI_NOT_FOUND dimm not found
**/
EFI_STATUS
GetDimmIdsFromString(
IN struct Command *pCmd,
IN CHAR16 *pDimmString,
IN DIMM_INFO *pDimmInfo,
IN UINT32 DimmCount,
OUT UINT16 **ppDimmIds,
OUT UINT32 *pDimmIdsCount
);
/**
Parses the dimm target string (which can contain DimmIDs as SMBIOS type-17 handles and/or DimmUIDs),
and returns a DimmUid.
Example
String: "8089-00-0000-13325476" or "30" or "0x0022"
@param[in] pDimmString The dimm target string to parse.
@param[in] pDimmInfo The dimm list found in NFIT.
@param[in] DimmCount Size of the pDimmInfo array.
@param[out] pDimmUid Pointer to the NVM_UID buffer.
@retval EFI_SUCCESS
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_INVALID_PARAMETER the format of string is not proper
@retval EFI_NOT_FOUND dimm not found
**/
EFI_STATUS
GetDimmUidFromString(
IN CHAR16 *pDimmString,
IN DIMM_INFO *pDimmInfo,
IN UINT32 DimmCount,
OUT CHAR8 *pDimmUid
);
/**
Check if the uint is in the uints array
@param[in] pUints - array of the uints
@param[in] UintsNum number of uints in the array
@param[in] UintToFind searched uint
@retval TRUE if the uint has been found
@retval FALSE if the uint has not been found
**/
BOOLEAN
ContainUint(
IN UINT16 *pSockets,
IN UINT32 SocketNum,
IN UINT16 Socket
);
/**
Check if the Guid is in the Guids array
@param[in] ppGuids array of the Guid pointers
@param[in] GuidsNum number of Guids in the array
@param[in] pGuidToFind pointer to GUID with information to find
@retval TRUE if table contains guid with same data as *pGuidToFind
@retval FALSE
**/
BOOLEAN
ContainGuid(
IN GUID **ppGuids,
IN UINT32 GuidsNum,
IN GUID *pGuidToFind
);
/**
Checks if the provided display list string contains only the valid values.
@param[in] pDisplayValues pointer to the Unicode string containing the user
input display list.
@param[in] ppAllowedDisplayValues pointer to an array of Unicode strings
that define the valid display values.
@param[in] Count is the number of valid display values in ppAllowedDisplayValues.
@retval EFI_SUCCESS if all of the provided display values are valid.
@retval EFI_OUT_OF_RESOURCES if the memory allocation fails.
@retval EFI_INVALID_PARAMETER if one or more of the provided display values
is not a valid one. Or if pDisplayValues or ppAllowedDisplayValues is NULL.
**/
EFI_STATUS
CheckDisplayList(
IN CHAR16 *pDisplayValues,
IN CHAR16 **ppAllowedDisplayValues,
IN UINT16 Count
);
/**
Gets number of Manageable and supported Dimms and their IDs and Handles
@param[in] pNvmDimmConfigProtocol A pointer to the EFI_DCPMM_CONFIG2_PROTOCOL instance.
@param[in] CheckSupportedConfigDimm If true, include dimms in unmapped set of dimms (non-POR) in
returned dimm list. If false, skip these dimms from returned list.
@param[out] DimmIdsCount is the pointer to variable, where number of dimms will be stored.
@param[out] ppDimmIds is the pointer to variable, where IDs of dimms will be stored.
@retval EFI_NOT_FOUND if the connection with NvmDimmProtocol can't be established
@retval EFI_OUT_OF_RESOURCES if the memory allocation fails.
@retval EFI_INVALID_PARAMETER if number of dimms or dimm IDs have not been assigned properly.
@retval EFI_SUCCESS if successfully assigned number of dimms and IDs to variables.
**/
EFI_STATUS
GetManageableDimmsNumberAndId(
IN EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol,
IN BOOLEAN CheckSupportedConfigDimm,
OUT UINT32 *pDimmIdsCount,
OUT UINT16 **ppDimmIds
);
/**
Gets number of Manageable (functional and non-functional) and supported Dimms and their IDs and Handles
@param[in] pNvmDimmConfigProtocol A pointer to the EFI_DCPMM_CONFIG2_PROTOCOL instance.
@param[in] CheckSupportedConfigDimm If true, include dimms in unmapped set of dimms (non-POR) in
returned dimm list. If false, skip these dimms from returned list.
@param[out] DimmIdsCount is the pointer to variable, where number of dimms will be stored.
@param[out] ppDimmIds is the pointer to variable, where IDs of dimms will be stored.
@retval EFI_NOT_FOUND if the connection with NvmDimmProtocol can't be established
@retval EFI_OUT_OF_RESOURCES if the memory allocation fails.
@retval EFI_INVALID_PARAMETER if number of dimms or dimm IDs have not been assigned properly.
@retval EFI_SUCCESS if successfully assigned number of dimms and IDs to variables.
**/
EFI_STATUS
GetAllManageableDimmsNumberAndId(
IN EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol,
IN BOOLEAN CheckSupportedConfigDimm,
OUT UINT32 *pDimmIdsCount,
OUT UINT16 **ppDimmIds
);
/**
Checks if user has specified the options -a|-all and -d|-display.
Those two flags exclude each other so the function also checks
if the user didn't provide them both.
If the -d|-display option has been found, the its values are checked
against the allowed values for this parameter.
@param[in] pCommand is the pointer to a Command structure that is tested
for the options presence.
@param[in] ppAllowedDisplayValues is a pointer to an array of Unicode
strings considered as the valid values for the -d|-display option.
@param[in] AllowedDisplayValuesCount is a UINT32 value that represents
the number of elements in the array pointed by ppAllowedDisplayValues.
@param[out] pDispOptions contains the following.
A BOOLEAN value that will
represent the presence of the -a|-all option in the Command pointed
by pCommand.
A BOOLEAN value that will
represent the presence of the -d|-display option in the Command pointed
by pCommand.
A pointer to an Unicode string. If the -d|-display option is present, this pointer will
be set to the option value Unicode string.
@retval EFI_SUCCESS the check went fine, there were no errors
@retval EFI_INVALID_PARAMETER if the user provided both options,
the display option has been provided and has some invalid values or
if at least one of the input pointer parameters is NULL.
@retval EFI_OUT_OF_RESOURCES if the memory allocation fails.
**/
EFI_STATUS
CheckAllAndDisplayOptions(
IN struct Command *pCommand,
IN CHAR16 **ppAllowedDisplayValues,
IN UINT32 AllowedDisplayValuesCount,
OUT CMD_DISPLAY_OPTIONS *pDispOptions
);
/**
Retrieve property by name and assign its value to UINT64.
@param[in] pCmd Command containing the property
@param[in] pPropertyName String with property name
@param[out] pOutValue target UINT64 value
@retval FALSE if there was no such property or it doesn't contain
a valid value
**/
BOOLEAN
PropertyToUint64 (
IN struct Command *pCmd,
IN CHAR16 *pPropertyName,
OUT UINT64 *pOutValue
);
/**
Retrieve property by name and assign its value to double
@param[in] pCmd Command containing the property
@param[in] pPropertyName String with property name
@param[out] pOutValue Target double value
@retval EFI_INVALID_PARAMETER Property not found or no valid value inside
@retval EFI_SUCCESS Conversion successful
**/
EFI_STATUS
PropertyToDouble (
IN struct Command *pCmd,
IN CHAR16 *pPropertyName,
OUT double *pOutValue
);
/**
Extracts working directory path from file path
@param[in] pUserFilePath Pointer to string with user specified file path
@param[out] pOutFilePath Pointer to actual file path
@param[out] ppDevicePath Pointer to where to store device path
@retval EFI_SUCCESS Extraction success
@retval EFI_INVALID_PARAMETER Invalid parameter
@retval EFI_OUT_OF_RESOURCES Out of resources
**/
EFI_STATUS
GetDeviceAndFilePath(
IN CHAR16 *pUserFilePath,
IN OUT CHAR16 *pOutFilePath,
IN OUT EFI_DEVICE_PATH_PROTOCOL **ppDevicePath
);
/**
Match driver command status to CLI return code
@param[in] Status - NVM_STATUS returned from driver
@retval - Appropriate EFI return code
**/
EFI_STATUS
MatchCliReturnCode (
IN NVM_STATUS Status
);
/**
Get free space of volume from given path
@param[in] pFileHandle - file handle protocol
@param[out] pFreeSpace - free space
@retval - Appropriate EFI return code
**/
EFI_STATUS
GetVolumeFreeSpace(
IN EFI_FILE_HANDLE pFileHandle,
OUT UINT64 *pFreeSpace
);
/**
Check if file exists
@param[in] pDumpUserPath - destination file path
@param[out] pExists - pointer to whether or not destination file already exists
@retval - Appropriate EFI return code
**/
EFI_STATUS
FileExists (
IN CHAR16* pDumpUserPath,
OUT BOOLEAN* pExists
);
/**
Delete file
@param[in] pDumpUserPath - file path to delete
@retval - Appropriate EFI return code
**/
EFI_STATUS
DeleteFile (
IN CHAR16* pDumpUserPath
);
/**
Dump data to file
@param[in] pDumpUserPath - destination file path
@param[in] BufferSize - data size to write
@param[in] pBuffer - pointer to buffer
@param[in] Overwrite - enforce overwriting file
@retval - Appropriate EFI return code
**/
EFI_STATUS
DumpToFile (
IN CHAR16* pDumpUserPath,
IN UINT64 BufferSize,
IN VOID* pBuffer,
IN BOOLEAN Overwrite
);
/**
Prints supported or recommended appdirect settings
@param[in] pInterleaveFormatList pointer to variable length interleave formats array
@param[in] FormatNum number of the appdirect settings formats
@param[in] pInterleaveSize pointer to Channel & iMc interleave size
@param[in] PrintRecommended if TRUE Recommended settings will be printed
if FALSE Supported settings will be printed
@param[in] Mode Set mode to print different format
@retval String representing AppDirect settings. Null on error.
**/
CHAR16*
PrintAppDirectSettings(
IN VOID *pInterleaveFormatList,
IN UINT16 FormatNum,
IN INTERLEAVE_SIZE *pInterleaveSize,
IN BOOLEAN PrintRecommended,
IN UINT8 Mode
);
/**
Read source file and return current passphrase to unlock device.
@param[in] pCmd A pointer to a COMMAND struct. Used to obtain the Printer context.
@param[in] pFileHandle File handler to read Passphrase from
@param[in] pDevicePath - handle to obtain generic path/location information concerning the
physical device or logical device. The device path describes the location of the device
the handle is for.
@param[out] Current passphrase
@retval EFI_SUCCESS File load and parse success
@retval EFI_INVALID_PARAMETER Invalid Parameter during load
@retval other Return Codes from TrimLineBuffer,
GetLoadPoolData, GetLoadDimmData, GetLoadValue functions
**/
EFI_STATUS
ParseSourcePassFile(
IN struct Command *pCmd,
IN CHAR16 *pFilePath,
IN EFI_DEVICE_PATH_PROTOCOL *pDevicePath,
OUT CHAR16 **ppCurrentPassphrase OPTIONAL,
OUT CHAR16 **ppNewPassphrase OPTIONAL
);
/**
Prompted input request
@param[in] pPrompt - information about expected input
@param[in] ShowInput - Show characters written by user
@param[in] OnlyAlphanumeric - Allow only for alphanumeric characters
@param[out] ppReturnValue - is a pointer to a pointer to the 16-bit character string
that will contain the return value
@retval - Appropriate CLI return code
**/
EFI_STATUS
PromptedInput(
IN CHAR16 *pPrompt,
IN BOOLEAN ShowInput,
IN BOOLEAN OnlyAlphanumeric,
OUT CHAR16 **ppReturnValue
);
/**
Display "yes/no" question and retrieve reply using prompt mechanism
@param[out] pConfirmation Confirmation from prompt
@retval EFI_INVALID_PARAMETER One or more parameters are invalid
@retval EFI_SUCCESS All Ok
**/
EFI_STATUS
PromptYesNo(
OUT BOOLEAN *pConfirmation
);
/**
Read input from console
@param[in] ShowInput - Show characters written by user
@param[in] OnlyAlphanumeric - Allow only for alphanumeric characters
@param[in, out] ppReturnValue - is a pointer to a pointer to the 16-bit character
string without null-terminator that will contain the return value
@param[in, out] pBufferSize - is a pointer to the Size in bytes of the return buffer
@retval - Appropriate CLI return code
**/
EFI_STATUS
ConsoleInput(
IN BOOLEAN ShowInput,
IN BOOLEAN OnlyAlphanumeric,
IN OUT CHAR16 **ppReturnValue,
IN OUT UINTN *pBufferSize OPTIONAL
);
/**
Print Load Firmware progress for all DIMMs
@param[in] ProgressEvent EFI Event
@param[in] pContext context pointer
**/
VOID
EFIAPI
PrintProgress(
IN EFI_EVENT ProgressEvent,
IN VOID *pContext
);
/**
Get relative path from absolute path
@param[in] pAbsolutePath Absolute path
@param[out] ppRelativePath Relative path
@retval EFI_INVALID_PARAMETER Input parameter was NULL
@retval EFI_SUCCESS All Ok
**/
EFI_STATUS
GetRelativePath(
IN CHAR16 *pAbsolutePath,
OUT CHAR16 **ppRelativePath
);
/**
Check if all dimms in the specified pDimmIds list are manageable.
This helper method assumes all the dimms in the list exist.
This helper method also assumes the parameters are non-null.
@param[in] pAllDimms The dimm list found in NFIT
@param[in] AllDimmCount Size of the pAllDimms array
@param[in] pDimmsListToCheck Pointer to the array of DimmIDs to check
@param[in] DimmsToCheckCount Size of the pDimmsListToCheck array
@retval TRUE if all Dimms in pDimmsListToCheck array are manageable
@retval FALSE if at least one DIMM is not manageable
**/
BOOLEAN
AllDimmsInListAreManageable(
IN DIMM_INFO *pAllDimms,
IN UINT32 AllDimmCount,
IN UINT16 *pDimmsListToCheck,
IN UINT32 DimmsToCheckCount
);
/**
Check if all dimms in the specified pDimmIds list are in supported
config. This helper method assumes all the dimms in the list exist.
This helper method also assumes the parameters are non-null.
@param[in] pAllDimms The dimm list found in NFIT
@param[in] AllDimmCount Size of the pAllDimms array
@param[in] pDimmsListToCheck Pointer to the array of DimmIDs to check
@param[in] DimmsToCheckCount Size of the pDimmsListToCheck array
@retval TRUE if all Dimms in pDimmsListToCheck array are in supported config
@retval FALSE if at least one DIMM is not in supported config
**/
BOOLEAN
AllDimmsInListInSupportedConfig(
IN DIMM_INFO *pAllDimms,
IN UINT32 AllDimmCount,
IN UINT16 *pDimmsListToCheck,
IN UINT32 DimmsToCheckCount
);
/**
Check if all dimms in the specified pDimmIds list have master passphrase enabled.
This helper method assumes all the dimms in the list exist.
This helper method also assumes the parameters are non-null.
@param[in] pAllDimms The dimm list found in NFIT
@param[in] AllDimmCount Size of the pAllDimms array
@param[in] pDimmsListToCheck Pointer to the array of DimmIDs to check
@param[in] DimmsToCheckCount Size of the pDimmsListToCheck array
@param[in] SkipFIS32Dimms indicates that Dimms with FIS 3.2 or above should always pass
@retval TRUE if all Dimms in pDimmsListToCheck array have master passphrase enabled
@retval FALSE if at least one DIMM does not have master passphrase enabled
**/
BOOLEAN
AllDimmsInListHaveMasterPassphraseEnabled(
IN DIMM_INFO *pAllDimms,
IN UINT32 AllDimmCount,
IN UINT16 *pDimmsListToCheck,
IN UINT32 DimmsToCheckCount,
IN BOOLEAN SkipFIS32Dimms
);
/**
Get Dimm identifier preference
@param[out] pDimmIdentifier Variable to store Dimm identifier preference
@retval EFI_SUCCESS Success
@retval EFI_INVALID_PARAMETER Input parameter is NULL
**/
EFI_STATUS
GetDimmIdentifierPreference(
OUT UINT8 *pDimmIdentifier
);
/**
Get Dimm identifier as string based on user preference
@param[in] DimmId Dimm ID as number
@param[in] pDimmUid Dimm UID as string
@param[out] pResultString String representation of preferred value
@param[in] ResultStringLen Length of pResultString
@retval EFI_SUCCESS Success
@retval EFI_INVALID_PARAMETER Input parameter is NULL
**/
EFI_STATUS
GetPreferredDimmIdAsString(
IN UINT32 DimmId,
IN CHAR16 *pDimmUid OPTIONAL,
OUT CHAR16 *pResultString,
IN UINT32 ResultStringLen
);
/**
Retrieve Display DimmID Runtime Index from Property String
@param[in] String to try to discover index for
@retval DimmID Index of DimmID property string
@retval Size of Array if not found
**/
UINT8 GetDimmIDIndex(
IN CHAR16 *pDimmIDStr
);
/**
Retrieve Display Size Runtime Index from Property String
@param[in] String to try to discover index for
@retval Display Size Index of Size property string
@retval Size of Array if not found
**/
UINT8 GetDisplaySizeIndex(
IN CHAR16 *pSizeStr
);
/**
Retrieve Display DimmID String from RunTime variable index
@param[in] Index to retrieve
@retval NULL Index was invalid
@retval DimmID String of user display preference
**/
CONST CHAR16 *GetDimmIDStr(
IN UINT8 DimmIDIndex
);
/**
Retrieve Display Size String from RunTime variable index
@param[in] Index to retrieve
@retval NULL Index was invalid
@retval Size String of user display preference
**/
CONST CHAR16 *GetDisplaySizeStr(
IN UINT16 DisplaySizeIndex
);
/**
Allocate and return string which is related with the binary RegionType value.
The caller function is obligated to free memory of the returned string.
@param[in] RegionType - region type
@retval - output string
**/
CHAR16 *
RegionTypeToString(
IN UINT8 RegionType
);
/**
Gets the DIMM handle corresponding to Dimm PID and also the index
@param[in] DimmId - DIMM ID
@param[in] pDimms - List of DIMMs
@param[in] DimmsNum - Number of DIMMs
@param[out] pDimmHandle - The Dimm Handle corresponding to the DIMM ID
@param[out] pDimmIndex - The Index of the found DIMM
@retval - EFI_STATUS Success
@retval - EFI_INVALID_PARAMETER Invalid parameter
@retval - EFI_NOT_FOUND Dimm not found
**/
EFI_STATUS
GetDimmHandleByPid(
IN UINT16 DimmId,
IN DIMM_INFO *pDimms,
IN UINT32 DimmsNum,
OUT UINT32 *pDimmHandle,
OUT UINT32 *pDimmIndex
);
/**
Retrieve the User Cli Display Preferences CMD line arguments.
@param[out] pDisplayPreferences pointer to the current driver preferences.
@retval EFI_INVALID_PARAMETER One or more parameters are invalid
@retval EFI_SUCCESS All ok
**/
EFI_STATUS
ReadCmdLinePrintOptions(
IN OUT PRINT_FORMAT_TYPE *pFormatType,
IN struct Command *pCmd
);
/**
Helper to recreate -o args in string format
@param[in] pCmd command from CLI
@param[out] ppOutputStr resulting -o string
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd or ppOutputStr is NULL
**/
EFI_STATUS
CreateCmdLineOutputStr(
IN struct Command *pCmd,
OUT CHAR16 **ppOutputStr
);
/**
Convert UEFI return codes to legacy OS return codes
@param[in] UefiReturnCode - return code to Convert
@retval - Converted OS ReturnCode
**/
EFI_STATUS UefiToOsReturnCode(EFI_STATUS UefiReturnCode);
/**
Checks if user has incorrectly used master and default options. Also checks for
invalid combinations of these options with the Passphrase property.
@param[in] pCmd command from CLI
@param[in] isPassphraseProvided TRUE if user provided passphrase
@param[in] isMasterOptionSpecified TRUE if master option is specified
@param[in] isDefaultOptionSpecified TRUE if default option is specified
@retval EFI_SUCCESS Success
@retval EFI_INVALID_PARAMETER One or more parameters are invalid
**/
EFI_STATUS
CheckMasterAndDefaultOptions(
IN struct Command *pCmd,
IN BOOLEAN isPassphraseProvided,
IN BOOLEAN isMasterOptionSpecified,
IN BOOLEAN isDefaultOptionSpecified
);
/**
Retrieves a list of Dimms that have at least one NS.
@param[in,out] pDimmIds the dimm IDs which have NS
@param[in,out] pDimmIdCount count of dimm IDs
@param[in] maxElements the maximum size of the dimm ID list
@retval EFI_ABORTED Operation Aborted
@retval EFI_OUT_OF_RESOURCES unable to allocate memory
@retval EFI_SUCCESS All Ok
**/
EFI_STATUS
GetDimmIdsWithNamespaces(
IN OUT UINT16 *pDimmIds,
IN OUT UINT32 *pDimmIdCount,
IN UINT32 maxElements);
/**
Adds an element to a element list without allowing duplication
@param[in,out] pElementList the list
@param[in,out] pElementCount size of the list
@param[in] newElement the new element to add
@param[in] maxElements the maximum size of the list
@retval EFI_OUT_OF_RESOURCES unable to add any more elements
@retval EFI_SUCCESS All Ok
**/
EFI_STATUS AddElement(
IN OUT UINT16 *pElementList,
IN OUT UINT32 *pElementCount,
IN UINT16 newElement,
IN UINT32 maxElements);
/**
Checks whether the FW on the dimm restricts executing commands
with the default Master Passphrase
@param[in] DimmInfo is the information about the dimm to check
@retval whether default is restricted by the FW's API version
**/
BOOLEAN IsDefaultMasterPassphraseRestricted(
IN DIMM_INFO DimmInfo);
#endif /** _COMMON_H_ **/
ipmctl-03.00.00.0423/DcpmPkg/cli/CreateGoalCommand.c 0000664 0000000 0000000 00000062070 14165347476 0021404 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include
#include "Debug.h"
#include "Types.h"
#include "Utility.h"
#include "Common.h"
#include "NvmInterface.h"
#include "CommandParser.h"
#include "CreateGoalCommand.h"
#include "NvmDimmCli.h"
#include "ShowGoalCommand.h"
#include
#include
#define CREATE_GOAL_COMMAND_STATUS_HEADER L"Create region configuration goal"
#define CREATE_GOAL_COMMAND_STATUS_CONJUNCTION L" on"
#define IS_DIMM_UNLOCKED(SecurityStateBitmask) ((SecurityStateBitmask & SECURITY_MASK_ENABLED) && !(SecurityStateBitmask & SECURITY_MASK_LOCKED))
/**
Command syntax definition
**/
struct Command CreateGoalCommand =
{
CREATE_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"", HELP_VERBOSE_DETAILS_TEXT,FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{FORCE_OPTION_SHORT, FORCE_OPTION, L"", L"",HELP_FORCE_DETAILS_TEXT, FALSE, ValueEmpty},
{UNITS_OPTION_SHORT, UNITS_OPTION, L"", UNITS_OPTION_HELP,HELP_UNIT_DETAILS_TEXT, FALSE, ValueRequired},
#ifdef OS_BUILD
{OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP,HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired}
#endif
},
{ //!< targets
{DIMM_TARGET, L"", HELP_TEXT_DIMM_IDS, FALSE, ValueOptional},
{GOAL_TARGET, L"", L"", TRUE, ValueEmpty},
{SOCKET_TARGET, L"", HELP_TEXT_SOCKET_IDS, FALSE, ValueOptional}
},
{ //!< properties
{MEMORY_MODE_PROPERTY, L"", HELP_TEXT_PERCENT, FALSE, ValueRequired},
{PERSISTENT_MEM_TYPE_PROPERTY, L"", HELP_TEXT_PERSISTENT_MEM_TYPE, FALSE, ValueRequired},
{RESERVED_PROPERTY, L"", HELP_TEXT_PERCENT, FALSE, ValueRequired},
{NS_LABEL_VERSION_PROPERTY, L"", HELP_TEXT_NS_LABEL_VERSION, FALSE, ValueRequired}
},
L"Provision capacity on one or more " PMEM_MODULES_STR L" into regions.", //!< help
CreateGoal,
TRUE, //!< enable print control support
};
/**
Traverse targeted dimms to determine if Security is enabled in Unlocked state
@param[in] SecurityFlag Security mask from FW
@retval TRUE if at least one targeted dimm has security enabled in unlocked state
@retval FALSE if none of targeted dimms have security enabled in unlocked state
**/
EFI_STATUS
EFIAPI
AreRequestedDimmsSecurityUnlocked(
IN DIMM_INFO *pDimmInfo,
IN UINT32 DimmCount,
IN UINT16 *ppDimmIds,
IN UINT32 pDimmIdsCount,
OUT BOOLEAN *isDimmUnlocked
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
UINT32 i;
UINT32 j;
NVDIMM_ENTRY();
if (NULL == pDimmInfo
|| NULL == isDimmUnlocked
|| (NULL == ppDimmIds && 0 < pDimmIdsCount))
{
goto Finish;
}
*isDimmUnlocked = FALSE;
if (0 == pDimmIdsCount) {
for (i = 0; i < DimmCount; i++)
{
if (IS_DIMM_UNLOCKED(pDimmInfo[i].SecurityStateBitmask)) {
*isDimmUnlocked = TRUE;
break;
}
}
}
else {
for (i = 0; i < pDimmIdsCount; i++)
{
for (j = 0; j < DimmCount; j++)
{
if ((ppDimmIds[i] == pDimmInfo[j].DimmID) && IS_DIMM_UNLOCKED(pDimmInfo[i].SecurityStateBitmask)) {
*isDimmUnlocked = TRUE;
break;
}
}
}
}
ReturnCode = EFI_SUCCESS;
Finish:
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
STATIC
EFI_STATUS
GetPersistentMemTypeValue(
IN CHAR16 *pStringValue,
OUT UINT8 *pPersistentMemType
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
if (pStringValue == NULL || pPersistentMemType == NULL) {
goto Finish;
}
if (StrICmp(pStringValue, PERSISTENT_MEM_TYPE_AD_STR) == 0) {
*pPersistentMemType = PM_TYPE_AD;
} else if (StrICmp(pStringValue, PERSISTENT_MEM_TYPE_AD_NI_STR) == 0) {
*pPersistentMemType = PM_TYPE_AD_NI;
} else {
goto Finish;
}
ReturnCode = EFI_SUCCESS;
Finish:
return ReturnCode;
}
STATIC
EFI_STATUS
GetLabelVersionFromStr(
IN CHAR16 *pLabelVersionStr,
OUT UINT16 *pMajor,
OUT UINT16 *pMinor
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
CHAR16 **ppSplitVersion = NULL;
UINT32 NumOfElements = 0;
UINT64 Major = 0;
UINT64 Minor = 0;
if (pLabelVersionStr == NULL || pMajor == NULL || pMinor == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
ppSplitVersion = StrSplit(pLabelVersionStr, L'.', &NumOfElements);
if (ppSplitVersion == NULL || NumOfElements != 2) {
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
ReturnCode = CrStrDecimalToUint64(ppSplitVersion[0], &Major, FALSE);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
ReturnCode = CrStrDecimalToUint64(ppSplitVersion[1], &Minor, FALSE);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
*pMajor = (UINT16) Major;
*pMinor = (UINT16) Minor;
Finish:
if (ppSplitVersion != NULL) {
FreeStringArray(ppSplitVersion, NumOfElements);
}
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Check and confirm alignments using prompt
Send user capacities to driver and retrieve alignments that will have to be done. Display these alignments and
confirm using prompt mechanism.
@param[in] pCmd command from CLI
@param[in] pNvmDimmConfigProtocol is a pointer to the EFI_DCPMM_CONFIG2_PROTOCOL instance.
@param[in] pDimmIds Pointer to an array of DIMM IDs
@param[in] DimmIdsCount Number of items in array of DIMM IDs
@param[in] pSocketIds Pointer to an array of Socket IDs
@param[in] SocketIdsCount Number of items in array of Socket IDs
@param[in] PersistentMemType Persistent memory type
@param[in] VolatilePercent Volatile region size in percents
@param[in] ReservedPercent Amount of AppDirect memory to not map in percents
@param[in] ReserveDimm Reserve one DIMM for use as not interleaved AppDirect memory
@param[in] UnitsToDisplay The units to be used to display capacity
@param[out] pConfirmation Confirmation from prompt
@retval EFI_INVALID_PARAMETER One or more parameters are invalid
@retval EFI_SUCCESS All Ok
**/
STATIC
EFI_STATUS
CheckAndConfirmAlignments(
IN struct Command *pCmd,
IN EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol,
IN UINT16 *pDimmIds OPTIONAL,
IN UINT32 DimmIdsCount,
IN UINT16 *pSocketIds OPTIONAL,
IN UINT32 SocketIdsCount,
IN UINT8 PersistentMemType,
IN UINT32 VolatilePercent,
IN UINT32 ReservedPercent,
IN UINT8 ReserveDimm,
IN UINT16 UnitsToDisplay
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
COMMAND_STATUS *pCommandStatus = NULL;
UINT32 VolatilePercentAligned = 0;
UINT32 PercentDiff = 0;
REGION_GOAL_PER_DIMM_INFO RegionConfigsInfo[MAX_DIMMS];
UINT32 RegionConfigsCount = 0;
UINT32 Index = 0;
CHAR16 *pSingleStatusCodeMessage = NULL;
UINT32 AppDirect1Regions = 0;
UINT32 AppDirect2Regions = 0;
UINT32 NumOfDimmsTargeted = 0;
UINT32 MaxPMInterleaveSetsPerDie = 0;
NVDIMM_ENTRY();
ZeroMem(RegionConfigsInfo, sizeof(RegionConfigsInfo[0]) * MAX_DIMMS);
if (pNvmDimmConfigProtocol == NULL) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("Failed on InitializeCommandStatus");
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
/** Make a copy of user's values. They will be needed in a next call. **/
VolatilePercentAligned = VolatilePercent;
ReturnCode = pNvmDimmConfigProtocol->GetActualRegionsGoalCapacities(
pNvmDimmConfigProtocol,
pDimmIds,
DimmIdsCount,
pSocketIds,
SocketIdsCount,
PersistentMemType,
&VolatilePercentAligned,
ReservedPercent,
ReserveDimm,
RegionConfigsInfo,
&RegionConfigsCount,
&NumOfDimmsTargeted,
&MaxPMInterleaveSetsPerDie,
pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
if (EFI_VOLUME_CORRUPTED == ReturnCode) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_PCD_CORRUPTED);
}
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
PRINTER_SET_COMMAND_STATUS(pCmd->pPrintCtx, ReturnCode, CREATE_GOAL_COMMAND_STATUS_HEADER, CLI_INFO_ON, pCommandStatus);
goto Finish;
}
if (VolatilePercent >= VolatilePercentAligned) {
PercentDiff = VolatilePercent - VolatilePercentAligned;
} else {
PercentDiff = VolatilePercentAligned - VolatilePercent;
}
PRINTER_PROMPT_MSG(pCmd->pPrintCtx, ReturnCode, CLI_CREATE_GOAL_PROMPT_HEADER L"\n");
PRINTER_ENABLE_TEXT_TABLE_FORMAT(pCmd->pPrintCtx);
ReturnCode = ShowGoalPrintTableView(pCmd, RegionConfigsInfo, UnitsToDisplay, RegionConfigsCount, FALSE);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
else {
PRINTER_PROCESS_SET_BUFFER_FORCE_TEXT_TABLE_MODE(pCmd->pPrintCtx);
}
if (pCommandStatus->ObjectStatusCount > 0) {
PRINTER_PROMPT_COMMAND_STATUS(pCmd->pPrintCtx, EFI_SUCCESS, L"", L"", pCommandStatus);
}
switch (pCommandStatus->GeneralStatus) {
case NVM_WARN_IMC_DDR_PMM_NOT_PAIRED:
pSingleStatusCodeMessage = GetSingleNvmStatusCodeMessage(gNvmDimmCliHiiHandle, NVM_WARN_IMC_DDR_PMM_NOT_PAIRED);
PRINTER_PROMPT_MSG(pCmd->pPrintCtx, ReturnCode, pSingleStatusCodeMessage);
FREE_POOL_SAFE(pSingleStatusCodeMessage);
break;
case NVM_WARN_NMFM_RATIO_LOWER_VIOLATION_1to3_6:
pSingleStatusCodeMessage = GetSingleNvmStatusCodeMessage(gNvmDimmCliHiiHandle, NVM_WARN_NMFM_RATIO_LOWER_VIOLATION_1to3_6);
PRINTER_PROMPT_MSG(pCmd->pPrintCtx, ReturnCode, pSingleStatusCodeMessage, TWOLM_NMFM_RATIO_LOWER_3_6_STR);
FREE_POOL_SAFE(pSingleStatusCodeMessage);
break;
case NVM_WARN_NMFM_RATIO_LOWER_VIOLATION_1to2:
pSingleStatusCodeMessage = GetSingleNvmStatusCodeMessage(gNvmDimmCliHiiHandle, NVM_WARN_NMFM_RATIO_LOWER_VIOLATION_1to2);
PRINTER_PROMPT_MSG(pCmd->pPrintCtx, ReturnCode, pSingleStatusCodeMessage, TWOLM_NMFM_RATIO_LOWER_2_STR);
FREE_POOL_SAFE(pSingleStatusCodeMessage);
break;
case NVM_WARN_NMFM_RATIO_UPPER_VIOLATION_1to16:
pSingleStatusCodeMessage = GetSingleNvmStatusCodeMessage(gNvmDimmCliHiiHandle, NVM_WARN_NMFM_RATIO_UPPER_VIOLATION_1to16);
PRINTER_PROMPT_MSG(pCmd->pPrintCtx, ReturnCode, pSingleStatusCodeMessage, TWOLM_NMFM_RATIO_UPPER_16);
FREE_POOL_SAFE(pSingleStatusCodeMessage);
break;
case NVM_WARN_NMFM_RATIO_UPPER_VIOLATION_1to8:
pSingleStatusCodeMessage = GetSingleNvmStatusCodeMessage(gNvmDimmCliHiiHandle, NVM_WARN_NMFM_RATIO_UPPER_VIOLATION_1to8);
PRINTER_PROMPT_MSG(pCmd->pPrintCtx, ReturnCode, pSingleStatusCodeMessage, TWOLM_NMFM_RATIO_UPPER_8);
FREE_POOL_SAFE(pSingleStatusCodeMessage);
break;
case NVM_WARN_PMTT_TABLE_NOT_FOUND:
pSingleStatusCodeMessage = GetSingleNvmStatusCodeMessage(gNvmDimmCliHiiHandle, NVM_WARN_PMTT_TABLE_NOT_FOUND);
PRINTER_PROMPT_MSG(pCmd->pPrintCtx, ReturnCode, pSingleStatusCodeMessage);
FREE_POOL_SAFE(pSingleStatusCodeMessage);
break;
}
if (PercentDiff > PROMPT_ALIGN_PERCENTAGE) {
PRINTER_PROMPT_MSG(pCmd->pPrintCtx, ReturnCode, L"\n" CLI_CREATE_GOAL_PROMPT_VOLATILE L"\n");
}
if ((pCommandStatus->GeneralStatus == NVM_WARN_REGION_MAX_PM_INTERLEAVE_SETS_EXCEEDED) && RegionConfigsCount > 0) {
for (Index = 0; Index < RegionConfigsCount; ++Index) {
if (RegionConfigsInfo[Index].AppDirectSize[APPDIRECT_1_INDEX] > 0) {
AppDirect1Regions++;
}
if (RegionConfigsInfo[Index].AppDirectSize[APPDIRECT_2_INDEX] > 0) {
AppDirect2Regions++;
}
}
if (PersistentMemType == PM_TYPE_AD) {
pSingleStatusCodeMessage = GetSingleNvmStatusCodeMessage(gNvmDimmCliHiiHandle, NVM_WARN_REGION_MAX_AD_PM_INTERLEAVE_SETS_EXCEEDED);
pSingleStatusCodeMessage = CatSPrintClean(NULL, pSingleStatusCodeMessage, MaxPMInterleaveSetsPerDie, AppDirect2Regions);
PRINTER_PROMPT_MSG(pCmd->pPrintCtx, ReturnCode, L"\n" FORMAT_STR_NL, pSingleStatusCodeMessage);
FREE_POOL_SAFE(pSingleStatusCodeMessage);
}
if (PersistentMemType == PM_TYPE_AD_NI) {
pSingleStatusCodeMessage = GetSingleNvmStatusCodeMessage(gNvmDimmCliHiiHandle, NVM_WARN_REGION_MAX_AD_NI_PM_INTERLEAVE_SETS_EXCEEDED);
pSingleStatusCodeMessage = CatSPrintClean(NULL, pSingleStatusCodeMessage, MaxPMInterleaveSetsPerDie, (NumOfDimmsTargeted - AppDirect1Regions));
PRINTER_PROMPT_MSG(pCmd->pPrintCtx, ReturnCode, L"\n" FORMAT_STR_NL, pSingleStatusCodeMessage);
FREE_POOL_SAFE(pSingleStatusCodeMessage);
}
}
Finish:
FreeCommandStatus(&pCommandStatus);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Execute the Create Goal command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
@retval EFI_NO_RESPONSE FW busy for one or more dimms
**/
EFI_STATUS
CreateGoal(
IN struct Command *pCmd
)
{
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
COMMAND_STATUS *pCommandStatus = NULL;
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
BOOLEAN Force = FALSE;
CHAR16 *pTargetValue = NULL;
CHAR16 *pPropertyValue = NULL;
UINT16 *pDimmIds = NULL;
UINT32 DimmIdsCount = 0;
UINT16 *pSocketIds = NULL;
UINT32 SocketIdsCount = 0;
UINT64 PropertyValue = 0;
UINT32 VolatileMode = 0;
UINT32 ReservedPercent = 0;
UINT8 ReserveDimm = RESERVE_DIMM_NONE;
UINT8 PersistentMemType = PM_TYPE_AD;
COMMAND_INPUT ShowGoalCmdInput;
COMMAND ShowGoalCmd;
BOOLEAN Confirmation = FALSE;
DIMM_INFO *pDimms = NULL;
UINT32 DimmCount = 0;
BOOLEAN Valid = FALSE;
UINT16 UnitsOption = DISPLAY_SIZE_UNIT_UNKNOWN;
UINT16 UnitsToDisplay = FixedPcdGet16(PcdDcpmmCliDefaultCapacityUnit);
CHAR16 *pUnitsStr = NULL;
CHAR16 *pCommandStr = NULL;
DISPLAY_PREFERENCES DisplayPreferences;
UINT16 LabelVersionMajor = 0;
UINT16 LabelVersionMinor = 0;
INTEL_DIMM_CONFIG *pIntelDIMMConfig = NULL;
PRINT_CONTEXT *pPrinterCtx = NULL;
CHAR16 *pShowGoalOutputArgs = NULL;
CHAR16 *pSingleStatusCodeMessage = NULL;
UINT32 MaxPMInterleaveSetsPerDie = 0;
BOOLEAN isDimmUnlocked = FALSE;
NVDIMM_ENTRY();
ZeroMem(&DisplayPreferences, sizeof(DisplayPreferences));
ZeroMem(&ShowGoalCmdInput, sizeof(ShowGoalCmdInput));
ZeroMem(&ShowGoalCmd, sizeof(ShowGoalCmd));
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("pCmd parameter is NULL.\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
// NvmDimmConfigProtocol required
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// Populate the list of DIMM_INFO structures with relevant information
ReturnCode = GetAllDimmList(pNvmDimmConfigProtocol, pCmd, DIMM_INFO_CATEGORY_SECURITY, &pDimms, &DimmCount);
if (EFI_ERROR(ReturnCode)) {
if(ReturnCode == EFI_NOT_FOUND) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_INFO_NO_FUNCTIONAL_DIMMS);
}
goto Finish;
}
if (containsOption(pCmd, FORCE_OPTION) || containsOption(pCmd, FORCE_OPTION_SHORT) || XML == pPrinterCtx->FormatType) {
Force = TRUE;
}
ReturnCode = ReadRunTimePreferences(&DisplayPreferences, DISPLAY_CLI_INFO);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_DISPLAY_PREFERENCES_RETRIEVE);
goto Finish;
}
UnitsToDisplay = DisplayPreferences.SizeUnit;
ReturnCode = GetUnitsOption(pCmd, &UnitsOption);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
/** Any valid units option will override the preferences **/
if (UnitsOption != DISPLAY_SIZE_UNIT_UNKNOWN) {
UnitsToDisplay = UnitsOption;
}
// check if auto provision is enabled
RetrieveIntelDIMMConfig(&pIntelDIMMConfig);
if(pIntelDIMMConfig != NULL) {
if (pIntelDIMMConfig->ProvisionCapacityMode == PROVISION_CAPACITY_MODE_AUTO) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_CREATE_GOAL_AUTO_PROV_ENABLED);
FreePool(pIntelDIMMConfig);
goto Finish;
} else {
FreePool(pIntelDIMMConfig);
}
}
// check targets
if (ContainTarget(pCmd, DIMM_TARGET)) {
pTargetValue = GetTargetValue(pCmd, DIMM_TARGET);
ReturnCode = GetDimmIdsFromString(pCmd, pTargetValue, pDimms, DimmCount, &pDimmIds, &DimmIdsCount);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("Failed on GetDimmIdsFromString");
goto Finish;
}
if (!AllDimmsInListAreManageable(pDimms, DimmCount, pDimmIds, DimmIdsCount)){
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_UNMANAGEABLE_DIMM);
goto Finish;
}
}
if (ContainTarget(pCmd, SOCKET_TARGET)) {
pTargetValue = GetTargetValue(pCmd, SOCKET_TARGET);
ReturnCode = GetUintsFromString(pTargetValue, &pSocketIds, &SocketIdsCount);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_TARGET_SOCKET);
NVDIMM_DBG("Failed on GetSocketsFromString");
goto Finish;
}
}
// initialize status structure
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("Failed on InitializeCommandStatus");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
ReturnCode = ContainsProperty(pCmd, MEMORY_MODE_PROPERTY);
if (!EFI_ERROR(ReturnCode)) {
Valid = PropertyToUint64(pCmd, MEMORY_MODE_PROPERTY, &PropertyValue);
/** Make sure it is in 0-100 percent range. **/
if (Valid && PropertyValue <= 100) {
VolatileMode = (UINT32)PropertyValue;
} else {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_PROPERTY_MEMORY_MODE);
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
} else {
VolatileMode = 0;
}
if ((ReturnCode = ContainsProperty(pCmd, PERSISTENT_MEM_TYPE_PROPERTY)) != EFI_NOT_FOUND) {
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
ReturnCode = GetPropertyValue(pCmd, PERSISTENT_MEM_TYPE_PROPERTY, &pPropertyValue);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
ReturnCode = GetPersistentMemTypeValue(pPropertyValue, &PersistentMemType);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_PROPERTY_PERSISTENT_MEM_TYPE);
goto Finish;
}
}
ReturnCode = ContainsProperty(pCmd, RESERVED_PROPERTY);
if (!EFI_ERROR(ReturnCode)) {
Valid = PropertyToUint64(pCmd, RESERVED_PROPERTY, &PropertyValue);
/** Make sure it is in 0-100 percent range. **/
if (Valid && PropertyValue <= 100) {
ReservedPercent = (UINT32)PropertyValue;
} else {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_PROPERTY_RESERVED);
goto Finish;
}
} else {
ReservedPercent = 0;
}
if (ReservedPercent + VolatileMode > 100) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_PROPERTIES_MEMORYMODE_RESERVED_TOO_LARGE);
goto Finish;
}
/** If Volatile and Reserved Percent sum to 100 then never map Appdirect even if alignment would allow it **/
if (ReservedPercent + VolatileMode == 100) {
PersistentMemType = PM_TYPE_RESERVED;
}
ReturnCode = ContainsProperty(pCmd, NS_LABEL_VERSION_PROPERTY);
if (!EFI_ERROR(ReturnCode)) {
ReturnCode = GetPropertyValue(pCmd, NS_LABEL_VERSION_PROPERTY, &pPropertyValue);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
ReturnCode = GetLabelVersionFromStr(pPropertyValue, &LabelVersionMajor, &LabelVersionMinor);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
if (LabelVersionMajor != NSINDEX_MAJOR) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_PROPERTY_NS_LABEL_VERSION);
goto Finish;
}
if ((LabelVersionMinor != NSINDEX_MINOR_1) &&
(LabelVersionMinor != NSINDEX_MINOR_2)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_PROPERTY_NS_LABEL_VERSION);
goto Finish;
}
} else if (ReturnCode == EFI_NOT_FOUND) {
/** Default to 1.2 labels **/
LabelVersionMajor = NSINDEX_MAJOR;
LabelVersionMinor = NSINDEX_MINOR_2;
} else {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
if (!Force) {
ReturnCode = CheckAndConfirmAlignments(pCmd, pNvmDimmConfigProtocol, pDimmIds, DimmIdsCount, pSocketIds, SocketIdsCount,
PersistentMemType, VolatileMode, ReservedPercent, ReserveDimm, UnitsToDisplay);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
ReturnCode = AreRequestedDimmsSecurityUnlocked(pDimms, DimmCount, pDimmIds, DimmIdsCount, &isDimmUnlocked);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
// send warning if security unlocked for target dimms
if (isDimmUnlocked) {
PRINTER_PROMPT_MSG(pPrinterCtx, ReturnCode, CLI_WARN_GOAL_CREATION_SECURITY_UNLOCKED);
}
ReturnCode = PromptYesNo(&Confirmation);
if (EFI_ERROR(ReturnCode)) {
PRINTER_PROMPT_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_PROMPT_INVALID);
NVDIMM_DBG("Failed on PromptedInput");
goto Finish;
}
else if (!Confirmation) {
goto Finish;
}
}
ReturnCode = pNvmDimmConfigProtocol->CreateGoalConfig(pNvmDimmConfigProtocol, FALSE, pDimmIds, DimmIdsCount,
pSocketIds, SocketIdsCount, PersistentMemType, VolatileMode, ReservedPercent, ReserveDimm,
LabelVersionMajor, LabelVersionMinor, &MaxPMInterleaveSetsPerDie, pCommandStatus);
if (!EFI_ERROR(ReturnCode)) {
ReturnCode = CreateCmdLineOutputStr(pCmd, &pShowGoalOutputArgs);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
if (UnitsOption != DISPLAY_SIZE_UNIT_UNKNOWN) {
CHECK_RESULT(UnitsToStr(gNvmDimmCliHiiHandle, UnitsToDisplay, &pUnitsStr), Finish);
pCommandStr = CatSPrintClean(pCommandStr, FORMAT_STR_SPACE FORMAT_STR FORMAT_STR L" " FORMAT_STR L" " FORMAT_STR, SHOW_VERB, pShowGoalOutputArgs, UNITS_OPTION, pUnitsStr, GOAL_TARGET);
} else {
pCommandStr = CatSPrintClean(pCommandStr, FORMAT_STR_SPACE FORMAT_STR FORMAT_STR, SHOW_VERB, pShowGoalOutputArgs, GOAL_TARGET);
}
FillCommandInput(pCommandStr, &ShowGoalCmdInput);
ReturnCode = Parse(&ShowGoalCmdInput, &ShowGoalCmd);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Failed parsing command input");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
if (ShowGoalCmd.run == NULL) {
NVDIMM_WARN("Couldn't find show -goal command");
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
if (!Force) {
PRINTER_PROMPT_MSG(pPrinterCtx, ReturnCode, CLI_CREATE_SUCCESS_STATUS);
}
ExecuteCmd(&ShowGoalCmd);
FREE_POOL_SAFE(pCommandStr);
if (pCommandStatus->GeneralStatus == NVM_WARN_REGION_AD_NI_PM_INTERLEAVE_SETS_REDUCED) {
pSingleStatusCodeMessage = GetSingleNvmStatusCodeMessage(gNvmDimmCliHiiHandle, NVM_WARN_REGION_AD_NI_PM_INTERLEAVE_SETS_REDUCED);
pSingleStatusCodeMessage = CatSPrintClean(NULL, pSingleStatusCodeMessage, MaxPMInterleaveSetsPerDie);
PRINTER_PROMPT_MSG(pCmd->pPrintCtx, ReturnCode, pSingleStatusCodeMessage);
FREE_POOL_SAFE(pSingleStatusCodeMessage);
}
goto FinishSkipPrinterProcess;
}
else {
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
PRINTER_SET_COMMAND_STATUS(pPrinterCtx, ReturnCode, CREATE_GOAL_COMMAND_STATUS_HEADER, CLI_INFO_ON, pCommandStatus);
}
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FinishSkipPrinterProcess:
FreeCommandInput(&ShowGoalCmdInput);
FreeCommandStructure(&ShowGoalCmd);
FreeCommandStatus(&pCommandStatus);
FREE_POOL_SAFE(pCommandStr);
FREE_POOL_SAFE(pSocketIds);
FREE_POOL_SAFE(pDimmIds);
FREE_POOL_SAFE(pDimms);
FREE_POOL_SAFE(pShowGoalOutputArgs);
FREE_POOL_SAFE(pUnitsStr);
FREE_POOL_SAFE(pCommandStr);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Register the create dimm command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterCreateGoalCommand(
)
{
EFI_STATUS ReturnCode;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&CreateGoalCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/CreateGoalCommand.h 0000664 0000000 0000000 00000002520 14165347476 0021403 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _CREATE_GOAL_COMMAND_
#define _CREATE_GOAL_COMMAND_
#include
// Cli will warn the user when suggested alignment is greater than this percentage
#define PROMPT_ALIGN_PERCENTAGE 10
/**
Traverse targeted dimms to determine if Security is enabled in Unlocked state
@param[in] SecurityFlag Security mask from FW
@retval TRUE if at least one targeted dimm has security enabled in unlocked state
@retval FALSE if none of targeted dimms have security enabled in unlocked state
**/
EFI_STATUS
EFIAPI
AreRequestedDimmsSecurityUnlocked(
IN DIMM_INFO *pDimmInfo,
IN UINT32 DimmCount,
IN UINT16 *ppDimmIds,
IN UINT32 pDimmIdsCount,
OUT BOOLEAN *isDimmUnlocked
);
/**
Register the Create Goal command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterCreateGoalCommand();
/**
Execute the Create Goal command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
CreateGoal(
IN struct Command *pCmd
);
#endif /** _CREATE_GOAL_COMMAND_ **/
ipmctl-03.00.00.0423/DcpmPkg/cli/CreateNamespaceCommand.h 0000664 0000000 0000000 00000001736 14165347476 0022425 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _CREATE_NAMESPACE_COMMAND_H_
#define _CREATE_NAMESPACE_COMMAND_H_
#include
#include
#include
#include
#include
#include
#include
#include "Common.h"
/**
Register the create namespace command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterCreateNamespaceCommand(
);
/**
Execute the create namespace command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS on success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_ABORTED invoking CONFIG_PROTOCOL function failure
**/
EFI_STATUS
CreateNamespaceCmd(
IN struct Command *pCmd
);
#endif /** _CREATE_NAMESPACE_COMMAND_H_ **/
ipmctl-03.00.00.0423/DcpmPkg/cli/DeleteDimmCommand.c 0000664 0000000 0000000 00000030261 14165347476 0021404 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef OS_BUILD
#include
#include
#include
#include
#include
#include
#include
#include "DeleteDimmCommand.h"
#include "SetDimmCommand.h"
#include "Common.h"
/**
Command syntax definition
**/
struct Command DeleteDimmCommand =
{
DELETE_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"", HELP_VERBOSE_DETAILS_TEXT,FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{FORCE_OPTION_SHORT, FORCE_OPTION, L"", L"",HELP_FORCE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", SOURCE_OPTION, L"", SOURCE_OPTION_HELP, L"Source of Passphrase file",FALSE, ValueRequired},
{L"", MASTER_OPTION, L"", L"", L"Master Passphrase",FALSE, ValueEmpty},
{L"", DEFAULT_OPTION, L"", L"", L"Default settings",FALSE, ValueEmpty},
#ifdef OS_BUILD
{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP,HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#endif
},
{{DIMM_TARGET, L"", HELP_TEXT_DIMM_IDS, TRUE, ValueOptional}}, //!< targets
{{PASSPHRASE_PROPERTY, L"", HELP_TEXT_STRING, FALSE, ValueOptional}}, //!< properties
L"Erase persistent data on one or more " PMEM_MODULES_STR L".", //!< help
DeleteDimm, TRUE
};
/**
Execute the delete dimm command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
DeleteDimm(
IN struct Command *pCmd
)
{
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
CHAR16 *pLoadUserPath = NULL;
CHAR16 *pLoadFilePath = NULL;
CHAR16 *pPassphrase = NULL;
CHAR16 *pPassphraseStatic = NULL;
CHAR16 *pTargetValue = NULL;
UINT16 *pDimmIds = NULL;
UINT32 DimmHandle = 0;
UINT32 DimmIndex = 0;
UINT16 Index = 0;
UINT32 DimmIdsCount = 0;
EFI_DEVICE_PATH_PROTOCOL *pDevicePathProtocol = NULL;
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
COMMAND_STATUS *pCommandStatus = NULL;
BOOLEAN Force = FALSE;
BOOLEAN Confirmation = FALSE;
DIMM_INFO *pDimms = NULL;
UINT32 DimmCount = 0;
CHAR16 DimmStr[MAX_DIMM_UID_LENGTH];
PRINT_CONTEXT *pPrinterCtx = NULL;
BOOLEAN MasterOptionSpecified = FALSE;
BOOLEAN DefaultOptionSpecified = FALSE;
UINT16 SecurityOperation = SECURITY_OPERATION_UNDEFINED;
DIMM_INFO DimmInfo;
NVDIMM_ENTRY();
ZeroMem(DimmStr, sizeof(DimmStr));
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// Populate the list of DIMM_INFO structures with relevant information
ReturnCode = GetDimmList(pNvmDimmConfigProtocol, pCmd, DIMM_INFO_CATEGORY_SECURITY, &pDimms, &DimmCount);
if (EFI_ERROR(ReturnCode)) {
if(ReturnCode == EFI_NOT_FOUND) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_INFO_NO_FUNCTIONAL_DIMMS);
}
goto Finish;
}
// initialize status structure
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
NVDIMM_DBG("Failed on InitializeCommandStatus");
goto Finish;
}
// check targets
if (ContainTarget(pCmd, DIMM_TARGET)) {
pTargetValue = GetTargetValue(pCmd, DIMM_TARGET);
ReturnCode = GetDimmIdsFromString(pCmd, pTargetValue, pDimms, DimmCount, &pDimmIds, &DimmIdsCount);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("Failed on GetDimmIdsFromString");
goto Finish;
}
if (!AllDimmsInListAreManageable(pDimms, DimmCount, pDimmIds, DimmIdsCount)){
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_UNMANAGEABLE_DIMM);
goto Finish;
}
}
/** If no dimm IDs are specified get IDs from all dimms **/
if (DimmIdsCount == 0) {
ReturnCode = GetManageableDimmsNumberAndId(pNvmDimmConfigProtocol, FALSE, &DimmIdsCount, &pDimmIds);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
if (DimmIdsCount == 0) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_INFO_NO_MANAGEABLE_DIMMS);
goto Finish;
}
}
/** Check master option **/
MasterOptionSpecified = containsOption(pCmd, MASTER_OPTION);
/** Check default option **/
DefaultOptionSpecified = containsOption(pCmd, DEFAULT_OPTION);
/** Check if default option is supported on selected modules **/
if (DefaultOptionSpecified) {
for (Index = 0; Index < DimmIdsCount; Index++) {
CHECK_RESULT((pNvmDimmConfigProtocol->GetDimm(pNvmDimmConfigProtocol, pDimmIds[Index], DIMM_INFO_CATEGORY_NONE, &DimmInfo)), Finish);
if (IsDefaultMasterPassphraseRestricted(DimmInfo)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_DEFAULT_NOT_SUPPORTED_FIRMWARE_REV);
goto Finish;
}
}
}
/** Check force option **/
if (containsOption(pCmd, FORCE_OPTION) || containsOption(pCmd, FORCE_OPTION_SHORT)) {
Force = TRUE;
}
if (MasterOptionSpecified) {
// FALSE = Master passphrase must be enabled for FIS >= 3.2 PMem modules as well
if (!AllDimmsInListHaveMasterPassphraseEnabled(pDimms, DimmCount, pDimmIds, DimmIdsCount, FALSE)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_MASTER_PASSPHRASE_NOT_ENABLED);
goto Finish;
}
}
ReturnCode = GetPropertyValue(pCmd, PASSPHRASE_PROPERTY, &pPassphraseStatic);
if (EFI_ERROR(ReturnCode)) {
if (ReturnCode != EFI_NOT_FOUND) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
}
if ((pPassphraseStatic != NULL) &&
(containsOption(pCmd, SOURCE_OPTION)) &&
(StrCmp(pPassphraseStatic, L"") != 0)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_UNSUPPORTED_COMMAND_SYNTAX);
goto Finish;
}
// Check -source option
if ((pPassphraseStatic != NULL) &&
(containsOption(pCmd, SOURCE_OPTION)) &&
(StrCmp(pPassphraseStatic, L"") == 0)) {
pLoadUserPath = getOptionValue(pCmd, SOURCE_OPTION);
if (pLoadUserPath == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
NVDIMM_ERR("Could not get -source value. Out of memory");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
ReturnCode = CheckMasterAndDefaultOptions(pCmd, TRUE, MasterOptionSpecified, DefaultOptionSpecified);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
if (MasterOptionSpecified) {
SecurityOperation = SECURITY_OPERATION_MASTER_ERASE_DEVICE;
}
else {
SecurityOperation = SECURITY_OPERATION_ERASE_DEVICE;
}
pLoadFilePath = AllocateZeroPool(OPTION_VALUE_LEN * sizeof(*pLoadFilePath));
if (pLoadFilePath == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
ReturnCode = GetDeviceAndFilePath(pLoadUserPath, pLoadFilePath, &pDevicePathProtocol);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Failed to get file path (" FORMAT_EFI_STATUS ")", ReturnCode);
goto Finish;
}
ReturnCode = ParseSourcePassFile(pCmd, pLoadFilePath, pDevicePathProtocol, &pPassphrase, NULL);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
// Check if prompt
} else if ((pPassphraseStatic != NULL) && (StrCmp(pPassphraseStatic, L"") == 0)) {
ReturnCode = CheckMasterAndDefaultOptions(pCmd, TRUE, MasterOptionSpecified, DefaultOptionSpecified);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
if (MasterOptionSpecified) {
SecurityOperation = SECURITY_OPERATION_MASTER_ERASE_DEVICE;
}
else {
SecurityOperation = SECURITY_OPERATION_ERASE_DEVICE;
}
ReturnCode = PromptedInput(L"Enter passphrase:\n", FALSE, FALSE, &pPassphrase);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_PROMPT_INVALID);
NVDIMM_DBG("Failed on PromptedInput");
goto Finish;
}
} else if (pPassphraseStatic != NULL) { // Passphrase provided
ReturnCode = CheckMasterAndDefaultOptions(pCmd, TRUE, MasterOptionSpecified, DefaultOptionSpecified);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
if (MasterOptionSpecified) {
SecurityOperation = SECURITY_OPERATION_MASTER_ERASE_DEVICE;
}
else {
SecurityOperation = SECURITY_OPERATION_ERASE_DEVICE;
}
pPassphrase = CatSPrint(NULL, FORMAT_STR, pPassphraseStatic);
} else { // Passphrase not provided
ReturnCode = CheckMasterAndDefaultOptions(pCmd, FALSE, MasterOptionSpecified, DefaultOptionSpecified);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
if (MasterOptionSpecified) {
SecurityOperation = SECURITY_OPERATION_MASTER_ERASE_DEVICE;
}
else {
SecurityOperation = SECURITY_OPERATION_ERASE_DEVICE;
}
// At this point an empty string has already been handled and we are now assuming passphrase
// was not given because security is disabled and passphrase doesn't matter OR the secure erase
// request is for the default master passphrase and an empty string is passed in for the default
// master passphrase
pPassphrase = CatSPrint(NULL, L"");
}
/** Ask for prompt when Force option is not given **/
if (!Force) {
for (Index = 0; Index < DimmIdsCount; Index++) {
ReturnCode = GetDimmHandleByPid(pDimmIds[Index], pDimms, DimmCount, &DimmHandle, &DimmIndex);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
ReturnCode = GetPreferredDimmIdAsString(DimmHandle, pDimms[DimmIndex].DimmUid,
DimmStr, MAX_DIMM_UID_LENGTH);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
PRINTER_PROMPT_MSG(pPrinterCtx, ReturnCode, L"Erasing " PMEM_MODULE_STR L" " FORMAT_STR L".", DimmStr);
ReturnCode = PromptYesNo(&Confirmation);
if (!EFI_ERROR(ReturnCode) && Confirmation) {
ReturnCode = pNvmDimmConfigProtocol->SetSecurityState(pNvmDimmConfigProtocol,&pDimmIds[Index], 1,
SecurityOperation, pPassphrase, NULL, pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
goto FinishCommandStatusSet;
}
} else {
PRINTER_PROMPT_MSG(pPrinterCtx, ReturnCode, L"Skipped erasing data from " PMEM_MODULE_STR L" " FORMAT_STR L"\n", DimmStr);
continue;
}
}
} else {
ReturnCode = pNvmDimmConfigProtocol->SetSecurityState(pNvmDimmConfigProtocol, pDimmIds, DimmIdsCount,
SecurityOperation, pPassphrase, NULL, pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
goto FinishCommandStatusSet;
}
}
FinishCommandStatusSet:
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
PRINTER_SET_COMMAND_STATUS(pPrinterCtx, ReturnCode, ERASE_STR, L"", pCommandStatus);
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
CleanUnicodeStringMemory(pPassphrase);
CleanUnicodeStringMemory(pPassphraseStatic);
FreeCommandStatus(&pCommandStatus);
FREE_POOL_SAFE(pPassphrase);
FREE_POOL_SAFE(pLoadFilePath);
FREE_POOL_SAFE(pLoadUserPath);
FREE_POOL_SAFE(pDimmIds);
FREE_POOL_SAFE(pDimms);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Register the delete dimm command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterDeleteDimmCommand(
)
{
EFI_STATUS rc;
NVDIMM_ENTRY();
rc = RegisterCommand(&DeleteDimmCommand);
NVDIMM_EXIT_I64(rc);
return rc;
}
#endif /** OS_BUILD **/
ipmctl-03.00.00.0423/DcpmPkg/cli/DeleteDimmCommand.h 0000664 0000000 0000000 00000001524 14165347476 0021411 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef OS_BUILD
#ifndef _DELETE_DIMM_COMMAND_
#define _DELETE_DIMM_COMMAND_
#include
#include "CommandParser.h"
#define ERASE_STR L"Erase"
/**
Register the delete dimm command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterDeleteDimmCommand();
/**
Execute the delete dimm command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
DeleteDimm(
IN struct Command *pCmd
);
#endif /** _DELETE_DIMM_COMMAND_ **/
#endif /** OS_BUILD **/ ipmctl-03.00.00.0423/DcpmPkg/cli/DeleteGoalCommand.c 0000664 0000000 0000000 00000013006 14165347476 0021376 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include "Debug.h"
#include "Types.h"
#include "Utility.h"
#include "NvmInterface.h"
#include "CommandParser.h"
#include "DeleteGoalCommand.h"
#include "Common.h"
/**
Command syntax definition
**/
struct Command DeleteGoalCommand =
{
DELETE_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"",HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{ L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{ L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{ L"", LARGE_PAYLOAD_OPTION, L"", L"",HELP_LPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
{ L"", SMALL_PAYLOAD_OPTION, L"", L"",HELP_SPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
#ifdef OS_BUILD
{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP,HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#else
{L"", L"", L"", L"", L"",FALSE, ValueOptional}
#endif
},
{ //!< targets
{DIMM_TARGET, L"", HELP_TEXT_DIMM_IDS, FALSE, ValueOptional},
{GOAL_TARGET, L"", L"", TRUE, ValueEmpty},
{SOCKET_TARGET, L"", HELP_TEXT_SOCKET_IDS, FALSE, ValueOptional}
},
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Delete the region configuration goal from one or more " PMEM_MODULES_STR L".", //!< help
DeleteGoal,
TRUE, //!< enable print control support
};
/**
Execute the Delete Goal command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
@retval EFI_NO_RESPONSE FW busy for one or more dimms
**/
EFI_STATUS
DeleteGoal(
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
COMMAND_STATUS *pCommandStatus = NULL;
CHAR16 *pTargetValue = NULL;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
UINT16 *pDimmIds = NULL;
UINT32 DimmIdsCount = 0;
UINT16 *pSocketIds = NULL;
UINT32 SocketIdsCount = 0;
DIMM_INFO *pDimms = NULL;
UINT32 DimmCount = 0;
PRINT_CONTEXT *pPrinterCtx = NULL;
NVDIMM_ENTRY();
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("pCmd parameter is NULL.\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
/** Need NvmDimmConfigProtocol **/
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// Populate the list of DIMM_INFO structures with relevant information
ReturnCode = GetDimmList(pNvmDimmConfigProtocol, pCmd, DIMM_INFO_CATEGORY_NONE, &pDimms, &DimmCount);
if (EFI_ERROR(ReturnCode)) {
if(ReturnCode == EFI_NOT_FOUND) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_INFO_NO_FUNCTIONAL_DIMMS);
}
goto Finish;
}
if (ContainTarget(pCmd, DIMM_TARGET)) {
pTargetValue = GetTargetValue(pCmd, DIMM_TARGET);
ReturnCode = GetDimmIdsFromString(pCmd, pTargetValue, pDimms, DimmCount, &pDimmIds, &DimmIdsCount);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("Failed on GetDimmIdsFromString");
goto Finish;
}
if (!AllDimmsInListAreManageable(pDimms, DimmCount, pDimmIds, DimmIdsCount)){
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_UNMANAGEABLE_DIMM);
goto Finish;
}
}
if (ContainTarget(pCmd, SOCKET_TARGET)) {
pTargetValue = GetTargetValue(pCmd, SOCKET_TARGET);
ReturnCode = GetUintsFromString(pTargetValue, &pSocketIds, &SocketIdsCount);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_TARGET_SOCKET);
NVDIMM_DBG("Failed on GetSocketsFromString");
goto Finish;
}
}
// initialize status structure
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
NVDIMM_DBG("Failed on InitializeCommandStatus");
goto Finish;
}
ReturnCode = pNvmDimmConfigProtocol->DeleteGoalConfig(pNvmDimmConfigProtocol, pDimmIds, DimmIdsCount, pSocketIds,
SocketIdsCount, pCommandStatus);
if (EFI_VOLUME_CORRUPTED == ReturnCode) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_PCD_CORRUPTED);
}
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
PRINTER_SET_COMMAND_STATUS(pPrinterCtx, ReturnCode, L"Delete memory allocation goal", L" from", pCommandStatus);
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FreeCommandStatus(&pCommandStatus);
FREE_POOL_SAFE(pSocketIds);
FREE_POOL_SAFE(pDimmIds);
FREE_POOL_SAFE(pDimms);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Register the Delete Goal command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterDeleteGoalCommand(
)
{
EFI_STATUS ReturnCode;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&DeleteGoalCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/DeleteGoalCommand.h 0000664 0000000 0000000 00000001335 14165347476 0021405 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _DELETE_GOAL_COMMAND_
#define _DELETE_GOAL_COMMAND_
#include
/**
Register the Delete Goal command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterDeleteGoalCommand();
/**
Execute the Delete Goal command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
DeleteGoal(
IN struct Command *pCmd
);
#endif /** _DELETE_GOAL_COMMAND_ **/
ipmctl-03.00.00.0423/DcpmPkg/cli/DeleteNamespaceCommand.h 0000664 0000000 0000000 00000001535 14165347476 0022421 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _DELETE_NAMESPACE_COMMAND_H_
#define _DELETE_NAMESPACE_COMMAND_H_
#include
#include "Common.h"
/**
Register the delete namespace command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterDeleteNamespaceCommand(
);
/**
Execute the delete namespace command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS on success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_ABORTED invoking CONFIG_PROTOCOL function failure
**/
EFI_STATUS
DeleteNamespaceCmd(
IN struct Command *pCmd
);
#endif /** _DELETE_NAMESPACE_COMMAND_H_ **/
ipmctl-03.00.00.0423/DcpmPkg/cli/DeletePcdCommand.c 0000664 0000000 0000000 00000025564 14165347476 0021236 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include
#include "CommandParser.h"
#include "Common.h"
#include "DeletePcdCommand.h"
#include
/**
Command syntax definition
**/
struct Command DeletePcdCommand =
{
DELETE_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"",HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{ L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{ L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{ L"", LARGE_PAYLOAD_OPTION, L"", L"",HELP_LPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
{ L"", SMALL_PAYLOAD_OPTION, L"", L"",HELP_SPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
{FORCE_OPTION_SHORT, FORCE_OPTION, L"", L"",HELP_FORCE_DETAILS_TEXT, FALSE, ValueEmpty}
#ifdef OS_BUILD
,{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP,HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#endif
},
{ //!< targets
{DIMM_TARGET, L"", HELP_TEXT_DIMM_IDS, FALSE, ValueOptional},
{PCD_TARGET, L"", PCD_CONFIG_TARGET_VALUE
#ifndef OS_BUILD
L"|"
PCD_LSA_TARGET_VALUE
#endif
, TRUE, ValueOptional}
},
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Clear the namespace LSA partition on one or more " PMEM_MODULES_STR L".", //!< help
DeletePcdCmd,
TRUE //!< enable print control support
};
STATIC
EFI_STATUS
ValidatePcdTarget(
IN CHAR16 *pTargetValue,
IN CHAR16 *pExpectedTargetValue
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_ENTRY();
if (pTargetValue == NULL || pExpectedTargetValue == NULL) {
goto Finish;
}
if (StrICmp(pTargetValue, pExpectedTargetValue) != 0) {
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
ReturnCode = EFI_SUCCESS;
Finish:
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Execute the Delete PCD command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_FOUND couldn't open Config Protocol
@retval EFI_ABORTED internal
**/
EFI_STATUS
DeletePcdCmd(
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
EFI_STATUS TempReturnCode = EFI_SUCCESS;
COMMAND_STATUS *pCommandStatus = NULL;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
UINT16 *pDimmIds = NULL;
UINT16 DimmIdsWithNamespaces[MAX_DIMMS];
UINT32 DimmIdsWithNamespacesCount = 0;
UINT32 DimmIdsCount = 0;
DIMM_INFO *pDimms = NULL;
DIMM_INFO *pDimm = NULL;
UINT32 DimmCount = 0;
CHAR16 DimmStr[MAX_DIMM_UID_LENGTH];
CHAR16 *pTargetValue = NULL;
UINT32 DimmIndex = 0;
UINT32 DimmHandle = 0;
UINT32 Index = 0;
UINT32 Index2 = 0;
UINT32 Attempts = 0;
UINT32 Successes = 0;
BOOLEAN Force = FALSE;
BOOLEAN DimmInNamespace = FALSE;
BOOLEAN Confirmation = FALSE;
CHAR16 *pCommandStatusMessage = NULL;
UINT32 ConfigIdMask = 0;
CHAR16 *pDisplayTargets = NULL;
PRINT_CONTEXT *pPrinterCtx = NULL;
NVDIMM_ENTRY();
SetDisplayInfo(L"DeletePcd", ResultsView, NULL);
ZeroMem(DimmStr, sizeof(DimmStr));
ZeroMem(DimmIdsWithNamespaces, sizeof(DimmIdsWithNamespaces));
if (pCmd == NULL) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
/** Get config protocol **/
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// Populate the list of DIMM_INFO structures with relevant information
ReturnCode = GetAllDimmList(pNvmDimmConfigProtocol, pCmd, DIMM_INFO_CATEGORY_NONE, &pDimms, &DimmCount);
if (EFI_ERROR(ReturnCode)) {
if(ReturnCode == EFI_NOT_FOUND) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_INFO_NO_DIMMS);
}
goto Finish;
}
/** Check force option **/
if (containsOption(pCmd, FORCE_OPTION) || containsOption(pCmd, FORCE_OPTION_SHORT)) {
Force = TRUE;
}
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
if (ContainTarget(pCmd, DIMM_TARGET)) {
pTargetValue = GetTargetValue(pCmd, DIMM_TARGET);
ReturnCode = GetDimmIdsFromString(pCmd, pTargetValue, pDimms, DimmCount, &pDimmIds, &DimmIdsCount);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
if (!AllDimmsInListAreManageable(pDimms, DimmCount, pDimmIds, DimmIdsCount)){
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_UNMANAGEABLE_DIMM);
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
}
pTargetValue = GetTargetValue(pCmd, PCD_TARGET);
if (EFI_SUCCESS == ValidatePcdTarget(pTargetValue, PCD_LSA_TARGET_VALUE)) {
#ifdef OS_BUILD
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_TARGET_PCD);
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"LSA option not available. Refer to your OSV tools for " PMEM_MODULE_STR L" namespace management.");
goto Finish;
#endif
ConfigIdMask |= DELETE_PCD_CONFIG_LSA_MASK;
}
if (EFI_SUCCESS == ValidatePcdTarget(pTargetValue, PCD_CONFIG_TARGET_VALUE)) {
ConfigIdMask |= DELETE_PCD_CONFIG_CIN_MASK | DELETE_PCD_CONFIG_COUT_MASK | DELETE_PCD_CONFIG_CCUR_MASK;
}
if (0 == ConfigIdMask) {
#ifdef OS_BUILD
ConfigIdMask |= DELETE_PCD_CONFIG_CIN_MASK | DELETE_PCD_CONFIG_COUT_MASK | DELETE_PCD_CONFIG_CCUR_MASK;
#else
ConfigIdMask |= DELETE_PCD_CONFIG_ALL_MASK;
#endif
}
/* If no dimms specified then use all dimms */
if (DimmIdsCount == 0) {
FREE_POOL_SAFE(pDimmIds);
pDimmIds = AllocateZeroPool(sizeof(*pDimmIds) * DimmCount);
if (pDimmIds == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
for (Index =0; Index < DimmCount; Index++) {
pDimmIds[Index] = pDimms[Index].DimmID;
}
DimmIdsCount = DimmCount;
}
if (ConfigIdMask & (DELETE_PCD_CONFIG_CIN_MASK | DELETE_PCD_CONFIG_COUT_MASK | DELETE_PCD_CONFIG_CCUR_MASK)) {
pDisplayTargets = CatSPrint(pDisplayTargets, L"Config ");
if (NULL == pDisplayTargets) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
}
if (ConfigIdMask & (DELETE_PCD_CONFIG_LSA_MASK)) {
if (pDisplayTargets) {
pDisplayTargets = CatSPrint(pDisplayTargets, L"& ");
if (NULL == pDisplayTargets) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
}
pDisplayTargets = CatSPrint(pDisplayTargets, L"LSA ");
if (NULL == pDisplayTargets) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
}
pCommandStatusMessage = CatSPrint(NULL, L"Clear " FORMAT_STR L"partition(s)", pDisplayTargets);
ResetCmdStatus(pCommandStatus, NVM_ERR_OPERATION_NOT_STARTED);
if (!Force) {
PRINTER_PROMPT_MSG(pPrinterCtx, ReturnCode, L"WARNING: Modifying the Platform Configuration Data can result in loss of data!\n");
PRINTER_PROMPT_MSG(pPrinterCtx, ReturnCode, L"Clear " FORMAT_STR L"partition(s) on %d " PMEM_MODULE_STR L"(s).", pDisplayTargets, DimmIdsCount);
ReturnCode = PromptYesNo(&Confirmation);
if (EFI_ERROR(ReturnCode) || !Confirmation) {
ReturnCode = EFI_NOT_STARTED;
goto Finish;
}
}
#ifdef _WINDOWS
ReturnCode = GetDimmIdsWithNamespaces(DimmIdsWithNamespaces, &DimmIdsWithNamespacesCount, MAX_DIMMS);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
#endif
PRINTER_PROMPT_MSG(pPrinterCtx, ReturnCode, L"\n");
ResetCmdStatus(pCommandStatus, NVM_ERR_OPERATION_NOT_STARTED);
for (Index = 0; Index < DimmIdsCount; Index++) {
Attempts++;
ReturnCode = GetDimmHandleByPid(pDimmIds[Index], pDimms, DimmCount, &DimmHandle, &DimmIndex);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
pDimm = &pDimms[DimmIndex];
ReturnCode = GetPreferredDimmIdAsString(pDimm->DimmHandle, pDimm->DimmUid, DimmStr, MAX_DIMM_UID_LENGTH);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
DimmInNamespace = FALSE;
for (Index2 = 0; Index2 < DimmIdsWithNamespacesCount; Index2++) {
if (DimmIdsWithNamespaces[Index2] == pDimm->DimmHandle) {
DimmInNamespace = TRUE;
break;
}
}
if (DimmInNamespace) {
PRINTER_PROMPT_MSG(pPrinterCtx, ReturnCode, PMEM_MODULE_STR L" " FORMAT_STR L" is a member of a Namespace. Will not delete data from this " PMEM_MODULE_STR L".", DimmStr);
SetObjStatusForDimmInfoWithErase(pCommandStatus, pDimm, NVM_ERR_PCD_DELETE_DENIED, TRUE);
} else {
pCommandStatus->GeneralStatus = NVM_ERR_OPERATION_NOT_STARTED;
TempReturnCode = pNvmDimmConfigProtocol->ModifyPcdConfig(pNvmDimmConfigProtocol, &pDimmIds[Index], 1, ConfigIdMask, pCommandStatus);
if (EFI_ERROR(TempReturnCode)) {
ReturnCode = TempReturnCode;
} else {
Successes++;
}
}
}
if (Attempts > 0 && Attempts == Successes) {
pCommandStatus->GeneralStatus = NVM_SUCCESS;
} else if (pCommandStatus->GeneralStatus == NVM_SUCCESS) {
pCommandStatus->GeneralStatus = NVM_ERR_OPERATION_FAILED;
}
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_COMMAND_STATUS(pPrinterCtx, ReturnCode, L"Clear partition(s)", L" on", pCommandStatus);
} else {
PRINTER_SET_COMMAND_STATUS(pPrinterCtx, ReturnCode, pCommandStatusMessage, L" on", pCommandStatus);
}
if (Successes > 0) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"\nData dependencies may result in other commands being affected. A system reboot is required before all changes will take effect.");
}
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FreeCommandStatus(&pCommandStatus);
FREE_POOL_SAFE(pCommandStatusMessage);
FREE_POOL_SAFE(pDimmIds);
FREE_POOL_SAFE(pDimms);
FREE_POOL_SAFE(pDisplayTargets);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Register the Delete PCD command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterDeletePcdCommand(
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&DeletePcdCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/DeletePcdCommand.h 0000664 0000000 0000000 00000001210 14165347476 0021221 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _DELETE_PCD_COMMAND_
#define _DELETE_PCD_COMMAND_
/**
Register the Delete PCD command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterDeletePcdCommand(
);
/**
Execute the Delete PCD command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
**/
EFI_STATUS
DeletePcdCmd(
IN struct Command *pCmd
);
#endif /* _DELETE_PCD_COMMAND_ */
ipmctl-03.00.00.0423/DcpmPkg/cli/DumpDebugCommand.c 0000664 0000000 0000000 00000025452 14165347476 0021255 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include "DumpDebugCommand.h"
#include "NvmDimmCli.h"
#include "NvmInterface.h"
#include "LoadCommand.h"
#include "Debug.h"
#include "Convert.h"
#include "Nlog.h"
/**
Get FW debug log syntax definition
**/
struct Command DumpDebugCommandSyntax =
{
DUMP_VERB, //!< verb
{ //!< options
{L"", DESTINATION_PREFIX_OPTION, L"", L"", DESTINATION_PREFIX_OPTION_HELP, FALSE, ValueRequired },
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"",HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", LARGE_PAYLOAD_OPTION, L"", L"",HELP_LPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", SMALL_PAYLOAD_OPTION, L"", L"",HELP_SPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
#ifdef OS_BUILD
{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP, HELP_OPTIONS_DETAILS_TEXT,FALSE, ValueRequired },
#endif
{ L"", DICTIONARY_OPTION, L"", DICTIONARY_OPTION_HELP, L"Dictionary to interpret the log",FALSE, ValueOptional }
},
{
{DEBUG_TARGET, L"", L"", TRUE, ValueEmpty},
{DIMM_TARGET, L"", HELP_TEXT_DIMM_IDS, FALSE, ValueOptional}
},
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Dump firmware debug log.", //!< help
DumpDebugCommand, TRUE //!< run function
};
/**
Register syntax of dump -debug
**/
EFI_STATUS
RegisterDumpDebugCommand(
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&DumpDebugCommandSyntax);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Dump debug log command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS on success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_ABORTED invoking CONFIG_PROTOCOL function failure
**/
EFI_STATUS
DumpDebugCommand(
IN struct Command *pCmd
)
{
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
COMMAND_STATUS *pCommandStatus = NULL;
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
UINT32 DimmCount = 0;
UINT16 *pDimmIds = NULL;
UINT32 DimmIdsNum = 0;
CHAR16 *pTargetValue = NULL;
CHAR16 *pDumpUserPath = NULL;
DIMM_INFO *pDimms = NULL;
UINT32 Index = 0;
nlog_dict_entry * next;
BOOLEAN dictExists = FALSE;
CHAR16 *pDictUserPath = NULL;
CHAR16 *raw_file_name = NULL;
CHAR16 *decoded_file_name = NULL;
nlog_dict_entry* dict_head = NULL;
UINT32 dict_version;
UINT64 dict_entries;
PRINT_CONTEXT *pPrinterCtx = NULL;
CHAR16 *SourceNames[NUM_FW_DEBUG_LOG_SOURCES] = {L"media", L"sram", L"spi"};
UINT8 IndexSource = 0;
VOID *RawLogBuffer = NULL;
UINT64 RawLogBufferSizeBytes = 0;
INT8 SuccessesPerDimm[MAX_DIMMS];
UINT32 Reserved = 0;
NVDIMM_ENTRY();
// Make sure SuccessesPerDimm is fully initialized to -1's.
// -1 indicates a dimm that ends up to not be specified
// so we don't care about its number of successes
SetMem(SuccessesPerDimm, MAX_DIMMS * sizeof(SuccessesPerDimm[0]), (UINT8)(-1));
if (pCmd == NULL) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
/** Open Config protocol **/
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
ReturnCode = GetAllDimmList(pNvmDimmConfigProtocol, pCmd, DIMM_INFO_CATEGORY_NONE, &pDimms, &DimmCount);
if (EFI_ERROR(ReturnCode)) {
if(ReturnCode == EFI_NOT_FOUND) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_INFO_NO_FUNCTIONAL_DIMMS);
}
goto Finish;
}
if (ContainTarget(pCmd, DIMM_TARGET)) {
/** get specific DIMM pid passed in, set it **/
pTargetValue = GetTargetValue(pCmd, DIMM_TARGET);
ReturnCode = GetDimmIdsFromString(pCmd, pTargetValue, pDimms, DimmCount, &pDimmIds, &DimmIdsNum);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Target value is not a valid Dimm ID");
goto Finish;
}
}
// Check -destination option
if (containsOption(pCmd, DESTINATION_OPTION)) {
pDumpUserPath = getOptionValue(pCmd, DESTINATION_OPTION);
if (pDumpUserPath == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
NVDIMM_ERR("Could not get -destination value. Out of memory");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
}
else {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_PARSER_DETAILED_ERR_OPTION_REQUIRED, DESTINATION_OPTION);
goto Finish;
}
if (containsOption(pCmd, DICTIONARY_OPTION)) {
pDictUserPath = getOptionValue(pCmd, DICTIONARY_OPTION);
if (pDictUserPath == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
NVDIMM_ERR("Could not get -dict value. Out of memory");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
if (EFI_ERROR(FileExists(pDictUserPath, &dictExists)))
{
ReturnCode = EFI_END_OF_FILE;
NVDIMM_ERR("Could not check for existence of the dictionary file");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
if (!dictExists)
{
ReturnCode = EFI_LOAD_ERROR;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"The passed dictionary file doesn't exist\n");
goto Finish;
}
}
// Only load the dictionary once
if (dictExists)
{
dict_head = load_nlog_dict(pCmd, pDictUserPath, &dict_version, &dict_entries);
if (!dict_head)
{
ReturnCode = EFI_LOAD_ERROR;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"Failed to load the dictionary file " FORMAT_STR L"\n", pDictUserPath);
goto Finish;
}
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"Loaded %d dictionary entries\n", dict_entries);
}
for (Index = 0; Index < DimmCount; Index++) {
// Initialize to -1 so we can ignore dimms that aren't specified
SuccessesPerDimm[Index] = -1;
// If a dimm was not specified, filter it out here
if (DimmIdsNum > 0 && !ContainUint(pDimmIds, DimmIdsNum, pDimms[Index].DimmID)) {
continue;
}
// Initialize the successes of the specified dimm to 0
// Used to calculate if we return an error or not to CLI
SuccessesPerDimm[Index] = 0;
// For easier reading
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"\n");
// Collect logs from every debug log source on each dimm
for (IndexSource = 0; IndexSource < NUM_FW_DEBUG_LOG_SOURCES; IndexSource++) {
// Re-initialize pCommandStatus messages for each dimm and debug log source
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_DEVICE_ERROR;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto FreeAndContinue;
}
// Append dimm info, source, and .txt
// We want to re-use pDumpUserPath, so use CatSPrint instead of
// CatSPrintClean
raw_file_name = CatSPrint(pDumpUserPath, L"_" FORMAT_STR L"_0x%04x_" FORMAT_STR L".bin",
pDimms[Index].DimmUid, pDimms[Index].DimmHandle, SourceNames[IndexSource]);
decoded_file_name = CatSPrint(pDumpUserPath, L"_" FORMAT_STR L"_0x%04x_" FORMAT_STR L".txt",
pDimms[Index].DimmUid, pDimms[Index].DimmHandle, SourceNames[IndexSource]);
if (raw_file_name == NULL || decoded_file_name == NULL) {
goto FreeAndContinue;
}
ReturnCode = pNvmDimmConfigProtocol->GetFwDebugLog(pNvmDimmConfigProtocol,
pDimms[Index].DimmID, IndexSource, Reserved, &RawLogBuffer, &RawLogBufferSizeBytes, pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
if (ReturnCode == EFI_NOT_STARTED) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode,
L"No " FORMAT_STR L" FW debug logs found\n",
SourceNames[IndexSource]);
goto FreeAndContinue;
}
if (pCommandStatus->GeneralStatus != NVM_SUCCESS) {
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
PRINTER_SET_MSG(pPrinterCtx, ReturnCode,
L"Unexpected error in retrieving " FORMAT_STR L" FW debug logs\n",
SourceNames[IndexSource]);
PRINTER_SET_COMMAND_STATUS(pPrinterCtx, ReturnCode, CLI_INFO_DUMP_DEBUG_LOG, L" ", pCommandStatus);
goto FreeAndContinue;
}
}
/** Get FW debug log **/
ReturnCode = DumpToFile(raw_file_name, RawLogBufferSizeBytes, RawLogBuffer, TRUE);
if (EFI_ERROR(ReturnCode)) {
if (ReturnCode == EFI_VOLUME_FULL) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode,
L"Not enough space to save file " FORMAT_STR L" with size %lu MiB\n",
raw_file_name, BYTES_TO_MIB(RawLogBufferSizeBytes));
}
else {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode,
L"Failed to dump " FORMAT_STR L" FW debug logs to file " FORMAT_STR L"\n",
SourceNames[IndexSource], raw_file_name);
}
goto FreeAndContinue;
}
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"Dumped " FORMAT_STR L" FW debug logs to file " FORMAT_STR L"\n",
SourceNames[IndexSource], raw_file_name);
/** Decode FW debug log **/
if (dictExists) {
decode_nlog_binary(pCmd, decoded_file_name, RawLogBuffer, RawLogBufferSizeBytes,
dict_version, dict_head);
}
SuccessesPerDimm[Index]++;
FreeAndContinue:
FREE_POOL_SAFE(raw_file_name);
FREE_POOL_SAFE(decoded_file_name);
FREE_POOL_SAFE(RawLogBuffer);
FreeCommandStatus(&pCommandStatus);
}
}
// Return success if any of 3 logs were retrieved on every specified dimm
ReturnCode = EFI_SUCCESS;
for (Index = 0; Index < DimmCount; Index++)
{
if (SuccessesPerDimm[Index] == 0)
{
// If any specified dimm (initialized with 0) had no successes, then return error
ReturnCode = EFI_DEVICE_ERROR;
}
}
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
while (dict_head)
{
next = dict_head->next;
FREE_POOL_SAFE(dict_head->LogLevel);
FREE_POOL_SAFE(dict_head->LogString);
FREE_POOL_SAFE(dict_head->FileName);
FREE_POOL_SAFE(dict_head);
dict_head = next;
}
FREE_POOL_SAFE(pDimms);
FREE_POOL_SAFE(pDimmIds);
FREE_POOL_SAFE(pDictUserPath);
FREE_POOL_SAFE(pDumpUserPath);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/DumpDebugCommand.h 0000664 0000000 0000000 00000001451 14165347476 0021253 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _DUMP_DEBUG_COMMAND_H_
#define _DUMP_DEBUG_COMMAND_H_
#include
#include "NvmInterface.h"
#include "Common.h"
/**
Register dump -debug command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterDumpDebugCommand(
);
/**
Dump FW debug log command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS on success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_ABORTED invoking CONFIG_PROTOCOL function failure
**/
EFI_STATUS
DumpDebugCommand(
IN struct Command *pCmd
);
#endif
ipmctl-03.00.00.0423/DcpmPkg/cli/DumpGoalCommand.c 0000664 0000000 0000000 00000011747 14165347476 0021113 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include "Debug.h"
#include "Types.h"
#include "Utility.h"
#include "NvmInterface.h"
#include "CommandParser.h"
#include "DumpGoalCommand.h"
#include "Common.h"
/**
Command syntax definition
**/
struct Command DumpGoalCommand =
{
DUMP_VERB, //!< verb
{ //!< options
{L"", DESTINATION_OPTION, L"", DESTINATION_OPTION_HELP, L"Destination to dump the goal ",FALSE, ValueRequired},
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"",HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{ L"",PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{ L"",PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{ L"",LARGE_PAYLOAD_OPTION, L"", L"", HELP_LPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
{ L"",SMALL_PAYLOAD_OPTION, L"", L"", HELP_SPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty}
#ifdef OS_BUILD
,{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP,HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#endif
},
{ //!< targets
{SYSTEM_TARGET, L"", L"", TRUE, ValueEmpty},
{CONFIG_TARGET, L"", L"", TRUE, ValueEmpty}
},
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Store the current configured memory allocation settings to a file.", //!< help
DumpGoal,
TRUE,
FALSE,
FALSE,
TRUE
};
/**
Execute the Dump Goal command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
@retval EFI_NO_RESPONSE FW busy for one or more dimms
**/
EFI_STATUS
DumpGoal(
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
COMMAND_STATUS *pCommandStatus = NULL;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
CHAR16 *pDumpUserPath = NULL;
CHAR16 *pDumpFilePath = NULL;
EFI_DEVICE_PATH_PROTOCOL *pDevicePath = NULL;
PRINT_CONTEXT *pPrinterCtx = NULL;
NVDIMM_ENTRY();
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("pCmd parameter is NULL.\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
// NvmDimmConfigProtocol required
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
pDumpFilePath = AllocateZeroPool(OPTION_VALUE_LEN * sizeof(*pDumpFilePath));
if (pDumpFilePath == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
// Check -destination option
if (containsOption(pCmd, DESTINATION_OPTION)) {
pDumpUserPath = getOptionValue(pCmd, DESTINATION_OPTION);
if (pDumpUserPath == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
NVDIMM_ERR("Could not get -destination value. Out of memory");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
}
ReturnCode = GetDeviceAndFilePath(pDumpUserPath, pDumpFilePath, &pDevicePath);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Failed to get file path (" FORMAT_EFI_STATUS ")", ReturnCode);
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_WRONG_FILE_PATH);
goto Finish;
}
// Initialize status structure
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
NVDIMM_DBG("Failed on InitializeCommandStatus");
goto Finish;
}
ReturnCode = pNvmDimmConfigProtocol->DumpGoalConfig(pNvmDimmConfigProtocol, pDumpFilePath, pDevicePath,
pCommandStatus);
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_COMMAND_STATUS(pPrinterCtx, ReturnCode, CLI_DUMP_GOAL_MSG, CLI_DUMP_GOAL_ON_MSG, pCommandStatus);
} else {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_INFO_DUMP_CONFIG_SUCCESS, pDumpUserPath);
}
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FreeCommandStatus(&pCommandStatus);
FREE_POOL_SAFE(pDumpFilePath);
FREE_POOL_SAFE(pDumpUserPath);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Register the Dump Goal command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterDumpGoalCommand(
)
{
EFI_STATUS ReturnCode;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&DumpGoalCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/DumpGoalCommand.h 0000664 0000000 0000000 00000001500 14165347476 0021102 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _DUMP_GOAL_COMMAND_
#define _DUMP_GOAL_COMMAND_
#include
#define CLI_DUMP_GOAL_MSG L"Dump configuration goal"
#define CLI_DUMP_GOAL_ON_MSG L" on"
/**
Register the Dump Goal command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterDumpGoalCommand();
/**
Execute the Dump Goal command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
DumpGoal(
IN struct Command *pCmd
);
#endif /** _DUMP_GOAL_COMMAND_ **/
ipmctl-03.00.00.0423/DcpmPkg/cli/DumpSessionCommand.c 0000664 0000000 0000000 00000011042 14165347476 0021640 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include
#include "Debug.h"
#include "Types.h"
#include "Utility.h"
#include "NvmInterface.h"
#include "CommandParser.h"
#include "DumpSessionCommand.h"
#include "Common.h"
#include
#ifdef OS_BUILD
#include
#endif
#include
#define SUCCESSFULLY_DUMPED_BUFFER_MSG L"Successfully dumped %d bytes to file."
/**
Command syntax definition
**/
struct Command DumpSessionCommand =
{
DUMP_VERB, //!< verb
{
{L"", DESTINATION_OPTION, L"", DESTINATION_OPTION_HELP, L"Destination to dump the recorded session", FALSE, ValueRequired}, //!< options
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty}
#ifdef OS_BUILD
,{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP,HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#endif
},
{ //!< targets
{SESSION_TARGET, L"", L"", TRUE, ValueEmpty}
},
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Dump the current recording (PBR) session buffer to a file.", //!< help
DumpSession,
TRUE
};
/**
Execute the Dump Session command
**/
EFI_STATUS
DumpSession(
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
EFI_DCPMM_PBR_PROTOCOL *pNvmDimmPbrProtocol = NULL;
CHAR16 *pDumpUserPath = NULL;
CHAR16 *pDumpFilePath = NULL;
UINT32 BufferSz = 0;
VOID *pBuffer = NULL;
PRINT_CONTEXT *pPrinterCtx = NULL;
PbrHeader *pHeader = NULL;
NVDIMM_ENTRY();
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("pCmd parameter is NULL.\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
// NvmDimmConfigProtocol required
ReturnCode = OpenNvmDimmProtocol(gNvmDimmPbrProtocolGuid, (VOID **)&pNvmDimmPbrProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
//If Windows, check for admin privilege needed to update registry for PBR state
CHECK_WIN_ADMIN_PERMISSIONS();
pDumpFilePath = AllocateZeroPool(OPTION_VALUE_LEN * sizeof(*pDumpFilePath));
if (pDumpFilePath == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
pDumpUserPath = getOptionValue(pCmd, DESTINATION_OPTION);
if (pDumpUserPath == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
NVDIMM_ERR("Could not get -destination value. Out of memory");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
//get the contents of the pbr session buffer
ReturnCode = pNvmDimmPbrProtocol->PbrGetSession(&pBuffer, &BufferSz);
if (EFI_ERROR(ReturnCode) || pBuffer == NULL) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_FAILED_TO_GET_SESSION_BUFFER);
goto Finish;
}
//fill in run-time versioning info
pHeader = (PbrHeader*)pBuffer;
#ifdef OS_BUILD
os_get_os_name(pHeader->OsName, PBR_OS_NAME_MAX);
os_get_os_version(pHeader->OsVersion, PBR_OS_VERSION_MAX);
AsciiSPrint(pHeader->SwVersion, PBR_SW_VERSION_MAX, NVMDIMM_VERSION_STRING_A);
#else
AsciiSPrint(pHeader->OsName, PBR_OS_NAME_MAX, "UEFI");
UnicodeStrToAsciiStrS(NVMDIMM_VERSION_STRING, pHeader->SwVersion, PBR_SW_VERSION_MAX);
#endif
//dump the buffer to a file
ReturnCode = DumpToFile(pDumpUserPath, BufferSz, pBuffer, TRUE);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_FAILED_TO_DUMP_SESSION_TO_FILE);
goto Finish;
}
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, SUCCESSFULLY_DUMPED_BUFFER_MSG, BufferSz);
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FREE_POOL_SAFE(pBuffer);
FREE_POOL_SAFE(pDumpFilePath);
FREE_POOL_SAFE(pDumpUserPath);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Register the Dump PBR command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterDumpSessionCommand(
)
{
EFI_STATUS ReturnCode;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&DumpSessionCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/DumpSessionCommand.h 0000664 0000000 0000000 00000001344 14165347476 0021651 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _DUMP_SESSION_COMMAND_
#define _DUMP_SESSION_COMMAND_
#include
/**
Register the Dump Session command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterDumpSessionCommand();
/**
Execute the Dump Session command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
DumpSession(
IN struct Command *pCmd
);
#endif /** _DUMP_SESSION_COMMAND_ **/
ipmctl-03.00.00.0423/DcpmPkg/cli/LoadCommand.c 0000664 0000000 0000000 00000057135 14165347476 0020263 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include "LoadCommand.h"
#include
#include
#include
#include
#include
#include
#include "NvmDimmCli.h"
#include "Common.h"
/**
Command syntax definition
**/
struct Command LoadCommand =
{
LOAD_VERB, //!< verb
{ //!< options
{L"", SOURCE_OPTION, L"", SOURCE_OPTION_HELP, L"Firmware Image required to use Firmware Update.", FALSE, ValueRequired},
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"", HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", LARGE_PAYLOAD_OPTION, L"", L"", HELP_LPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", SMALL_PAYLOAD_OPTION, L"", L"", HELP_SPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
{EXAMINE_OPTION_SHORT, EXAMINE_OPTION, L"", L"", EXAMINE_OPTION_DETAILS_TEXT, FALSE, ValueEmpty},
{FORCE_OPTION_SHORT, FORCE_OPTION, L"", L"", FORCE_OPTION_DETAILS_TEXT, FALSE, ValueEmpty},
{ L"", RECOVER_OPTION, L"", L"", RECOVER_OPTION_DETAILS_TEXT, FALSE, ValueEmpty }
#ifdef OS_BUILD
,{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP, HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#endif
},
{ //!< targets
{DIMM_TARGET, L"", HELP_TEXT_DIMM_IDS, TRUE, ValueOptional}
},
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Update the firmware on one or more " PMEM_MODULES_STR L".", //!< help
Load, //!< run function
TRUE //!< Enable Printer
};
/**
Register the load command
**/
EFI_STATUS
RegisterLoadCommand(
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&LoadCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Execute the load command
@param[in] pCmd the command structure that contains the user input data.
@retval EFI_SUCCESS if everything went OK - including the firmware load process.
@retval EFI_INVALID_PARAMETER if the user input is invalid or the file validation fails
@retval EFI_UNSUPPORTED if the driver is not loaded or there are no DCPMMs in the system.
@retval EFI_NOT_FOUND if there is no DIMM with the user specified PID
@retval EFI_NO_RESPONSE FW busy for one or more dimms
**/
EFI_STATUS
Load(
IN struct Command *pCmd
)
{
BOOLEAN fileExists = FALSE;
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_STATUS TempReturnCode = EFI_SUCCESS;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
CHAR16 *pFileName = NULL;
CHAR16 *pRelativeFileName = NULL;
CHAR16 *pTargetValue = NULL;
CONST CHAR16 *pWorkingDirectory = NULL;
UINT32 DimmHandle = 0;
UINT32 DimmIndex = 0;
COMMAND_STATUS *pCommandStatus = NULL;
BOOLEAN Examine = FALSE;
BOOLEAN Force = FALSE;
NVM_FW_IMAGE_INFO *pFwImageInfo = NULL;
volatile UINT32 Index = 0;
volatile UINT32 Index2 = 0;
CHAR16 DimmStr[MAX_DIMM_UID_LENGTH];
EFI_EVENT ProgressEvent = NULL;
CHAR16 *pOptionsValue = NULL;
BOOLEAN Recovery = FALSE;
DIMM_INFO *pDimmTargets = NULL;
UINT16 *pDimmIds = NULL;
UINT16 *pDimmTargetIds = NULL;
UINT32 StagedFwUpdates = 0;
DIMM_INFO *pDimms = NULL;
DIMM_INFO *pCandidateList = NULL;
UINT32 DimmCount = 0;
UINT32 DimmTargetsNum = 0;
UINT32 CandidateListCount = 0;
BOOLEAN TargetsIsNewList = FALSE;
BOOLEAN Confirmation = 0;
EFI_STATUS ReturnCodes[MAX_DIMMS];
NVM_STATUS NvmCodes[MAX_DIMMS];
NVM_STATUS generalNvmStatus = NVM_SUCCESS;
#ifndef OS_BUILD
EFI_SHELL_PROTOCOL *pEfiShell = NULL;
UINTN HandlesCount = 0;
EFI_HANDLE *pHandles = NULL;
#endif
if ((NULL != pCmd) && (NULL != pCmd->pPrintCtx)) {
if (pCmd->pPrintCtx->FormatType == XML) {
PRINTER_CONFIGURE_BUFFERING(pCmd->pPrintCtx, ON);
}
else {
PRINTER_CONFIGURE_BUFFERING(pCmd->pPrintCtx, OFF);
}
}
NVDIMM_ENTRY();
SetDisplayInfo(L"LoadFw", ResultsView, NULL);
for (Index = 0; Index < MAX_DIMMS; Index++) {
ReturnCodes[Index] = EFI_SUCCESS;
NvmCodes[Index] = NVM_SUCCESS;
}
ZeroMem(DimmStr, sizeof(DimmStr));
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
PrinterSetMsg(NULL, ReturnCode, CLI_ERR_NO_COMMAND);
goto FinishNoCommandStatus;
}
// initialize status structure
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
PrinterSetMsg(pCmd->pPrintCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR); // if pCMD->pPrintCtx is NULL then will print to stdout
NVDIMM_DBG("Failed on InitializeCommandStatus");
goto FinishNoCommandStatus;
}
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PrinterSetMsg(pCmd->pPrintCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// check options
pFileName = getOptionValue(pCmd, SOURCE_OPTION);
if (pFileName == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
PrinterSetMsg(pCmd->pPrintCtx, ReturnCode, CLI_ERR_WRONG_FILE_PATH);
goto Finish;
}
if (containsOption(pCmd, EXAMINE_OPTION) && containsOption(pCmd, EXAMINE_OPTION_SHORT)) {
ReturnCode = EFI_INVALID_PARAMETER;
PrinterSetMsg(pCmd->pPrintCtx, ReturnCode, CLI_ERR_OPTIONS_EXAMINE_USED_TOGETHER);
goto Finish;
}
if (containsOption(pCmd, FORCE_OPTION) && containsOption(pCmd, FORCE_OPTION_SHORT)) {
ReturnCode = EFI_INVALID_PARAMETER;
PrinterSetMsg(pCmd->pPrintCtx, ReturnCode, CLI_ERR_OPTIONS_FORCE_USED_TOGETHER);
goto Finish;
}
Recovery = containsOption(pCmd, RECOVER_OPTION);
Examine = containsOption(pCmd, EXAMINE_OPTION) || containsOption(pCmd, EXAMINE_OPTION_SHORT);
Force = containsOption(pCmd, FORCE_OPTION) || containsOption(pCmd, FORCE_OPTION_SHORT);
/*Get the list of functional and non-functional dimms*/
CHECK_RESULT(GetAllDimmList(pNvmDimmConfigProtocol, pCmd, DIMM_INFO_CATEGORY_SMART_AND_HEALTH,
&pDimms, &DimmCount), Finish);
if (DimmCount == 0) {
ReturnCode = EFI_NOT_STARTED;
PrinterSetMsg(pCmd->pPrintCtx, ReturnCode, CLI_INFO_NO_DIMMS);
goto Finish;
}
// Include all DCPMMs for fw update / spi flash update
pCandidateList = pDimms;
CandidateListCount = DimmCount;
/*Screen for user specific IDs*/
pTargetValue = GetTargetValue(pCmd, DIMM_TARGET);
if (pTargetValue != NULL && StrLen(pTargetValue) > 0) {
ReturnCode = GetDimmIdsFromString(pCmd, pTargetValue, pCandidateList, CandidateListCount, &pDimmIds, &DimmTargetsNum);
if (pDimmIds == NULL) {
goto Finish;
}
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("Failed on GetDimmIdsFromString");
goto Finish;
}
TargetsIsNewList = TRUE;
pDimmTargets = AllocateZeroPool(sizeof(*pDimmTargets) * DimmTargetsNum);
pDimmTargetIds = AllocateZeroPool(sizeof(*pDimmTargetIds) * DimmTargetsNum);
if (pDimmTargets == NULL || pDimmTargetIds == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PrinterSetMsg(pCmd->pPrintCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
for (Index = 0; Index < DimmTargetsNum; Index++) {
for (Index2 = 0; Index2 < CandidateListCount; Index2++) {
if (pCandidateList[Index2].DimmID == pDimmIds[Index]) {
pDimmTargets[Index] = pCandidateList[Index2];
pDimmTargetIds[Index] = pCandidateList[Index2].DimmID;
break;
}
}
}
} else {
DimmTargetsNum = CandidateListCount;
pDimmTargets = pCandidateList;
pDimmTargetIds = AllocateZeroPool(sizeof(*pDimmTargetIds) * DimmTargetsNum);
if (pDimmTargetIds == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PrinterSetMsg(pCmd->pPrintCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
for (Index = 0; Index < DimmTargetsNum; Index++) {
pDimmTargetIds[Index] = pDimmTargets[Index].DimmID;
}
}
if (NULL == pDimmTargets) {
ReturnCode = EFI_NOT_FOUND;
CHECK_RETURN_CODE(ReturnCode, Finish);
}
/**
In this case the user could have typed "FS0:\..."
We are searching for the file on all FS so we need to remove the first chars until we have a "\"
**/
#ifdef OS_BUILD
pRelativeFileName = pFileName;
#else
ReturnCode = GetRelativePath(pFileName, &pRelativeFileName);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
ReturnCode = gBS->LocateHandleBuffer(ByProtocol, &gEfiShellProtocolGuid, NULL, &HandlesCount, &pHandles);
if (!EFI_ERROR(ReturnCode) && HandlesCount < MAX_SHELL_PROTOCOL_HANDLES) {
ReturnCode = gBS->OpenProtocol(pHandles[0], &gEfiShellProtocolGuid, (VOID *)&pEfiShell, NULL, NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (!EFI_ERROR(ReturnCode)) {
pWorkingDirectory = pEfiShell->GetCurDir(NULL);
if (pWorkingDirectory == NULL) {
NVDIMM_WARN("Error while getting the Working Directory.");
}
} else {
NVDIMM_WARN("Error while opening the shell protocol. Code: " FORMAT_EFI_STATUS "", ReturnCode);
}
} else {
NVDIMM_WARN("Error while opening the shell protocol. Code: " FORMAT_EFI_STATUS "", ReturnCode);
/**
We can still try to open the file. If it is in the root directory, we will be able to open it.
**/
}
#endif
ReturnCode = FileExists(pFileName, &fileExists);
if (EFI_ERROR(ReturnCode) || FALSE == fileExists) {
NVDIMM_DBG("OpenFile returned: " FORMAT_EFI_STATUS ".\n", ReturnCode);
ResetCmdStatus(pCommandStatus, NVM_ERR_FILE_NOT_FOUND);
ReturnCode = MatchCliReturnCode(NVM_ERR_FILE_NOT_FOUND);
goto Finish;
}
pFwImageInfo = AllocateZeroPool(sizeof(*pFwImageInfo));
if (pFwImageInfo == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PrinterSetMsg(pCmd->pPrintCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
ResetCmdStatus(pCommandStatus, NVM_ERR_OPERATION_NOT_STARTED);
if (!Examine) {
PrinterSetMsg(pCmd->pPrintCtx, EFI_SUCCESS, L"Starting update on %d " PMEM_MODULE_STR L"(s)...", DimmTargetsNum);
// Create callback that will print progress
gBS->CreateEvent((EVT_TIMER | EVT_NOTIFY_SIGNAL), PRINT_PRIORITY, PrintProgress, pCommandStatus, &ProgressEvent);
gBS->SetTimer(ProgressEvent, TimerPeriodic, PROGRESS_EVENT_TIMEOUT);
}
for (Index = 0; Index < DimmTargetsNum; Index++) {
pCommandStatus->GeneralStatus = NVM_SUCCESS; //ensure that only the last error gets reported
//if the FW is already staged and this isn't an examine operation, the outcome is already known
if (FALSE == Examine && TRUE == FwHasBeenStaged(pCmd, pNvmDimmConfigProtocol, pDimmTargets[Index].DimmID)) {
pCommandStatus->GeneralStatus = NVM_ERR_FIRMWARE_ALREADY_LOADED;
NvmCodes[Index] = pCommandStatus->GeneralStatus;
ReturnCodes[Index] = MatchCliReturnCode(NvmCodes[Index]);
SetObjStatusForDimmInfoWithErase(pCommandStatus, &pDimmTargets[Index], NvmCodes[Index], TRUE);
continue;
}
ReturnCodes[Index] = pNvmDimmConfigProtocol->UpdateFw(pNvmDimmConfigProtocol, &pDimmTargetIds[Index], 1, pRelativeFileName,
(CHAR16 *)pWorkingDirectory, Examine, Force, Recovery, FALSE, pFwImageInfo, pCommandStatus);
NvmCodes[Index] = pCommandStatus->GeneralStatus;
if (Examine) {
if (NvmCodes[Index] == NVM_ERR_FIRMWARE_TOO_LOW_FORCE_REQUIRED) {
ReturnCodes[Index] = EFI_SUCCESS;
NvmCodes[Index] = NVM_SUCCESS;
}
continue;
}
if (pCommandStatus->GeneralStatus == NVM_ERR_FIRMWARE_TOO_LOW_FORCE_REQUIRED) {
ReturnCodes[Index] = GetDimmHandleByPid(pDimmTargetIds[Index], pDimmTargets, DimmTargetsNum, &DimmHandle, &DimmIndex);
if (EFI_ERROR(ReturnCodes[Index])) {
NVDIMM_DBG("Failed to get dimm handle");
NvmCodes[Index] = NVM_ERR_DIMM_NOT_FOUND;
goto Finish;
}
ReturnCodes[Index] = GetPreferredDimmIdAsString(DimmHandle, pDimmTargets[DimmIndex].DimmUid,
DimmStr, MAX_DIMM_UID_LENGTH);
if (EFI_ERROR(ReturnCodes[Index])) {
NvmCodes[Index] = NVM_ERR_INVALID_PARAMETER;
SetObjStatusForDimmInfoWithErase(pCommandStatus, &pDimmTargets[Index], NvmCodes[Index], TRUE);
goto Finish;
}
NVDIMM_BUFFER_CONTROLLED_MSG(FALSE, CLI_DOWNGRADE_PROMPT L"\n", DimmStr);
ReturnCodes[Index] = PromptYesNo(&Confirmation);
if (EFI_ERROR(ReturnCodes[Index]) || !Confirmation) {
NvmCodes[Index] = NVM_ERR_FIRMWARE_TOO_LOW_FORCE_REQUIRED;
ReturnCodes[Index] = EFI_ABORTED;
SetObjStatusForDimmInfoWithErase(pCommandStatus, &pDimmTargets[Index], NvmCodes[Index], TRUE);
continue;
}
ReturnCodes[Index] = pNvmDimmConfigProtocol->UpdateFw(pNvmDimmConfigProtocol, &pDimmTargetIds[Index], 1, pRelativeFileName,
(CHAR16 *)pWorkingDirectory, Examine, TRUE, Recovery, FALSE, pFwImageInfo, pCommandStatus);
if (EFI_ERROR(ReturnCodes[Index])) {
continue;
}
} else if (EFI_ERROR(ReturnCodes[Index])) {
continue;
}
StagedFwUpdates++;
} //for loop
if (Examine) {
//only print non 0.0.0.0 versions...
if (pFwImageInfo->ImageVersion.ProductNumber.Version != 0 ||
pFwImageInfo->ImageVersion.RevisionNumber.Version != 0 ||
pFwImageInfo->ImageVersion.SecurityRevisionNumber.Version != 0 ||
pFwImageInfo->ImageVersion.BuildNumber.Build != 0) {
PrinterSetMsg(pCmd->pPrintCtx, ReturnCode, FORMAT_STR L": %02d.%02d.%02d.%04d",
pFileName,
pFwImageInfo->ImageVersion.ProductNumber.Version,
pFwImageInfo->ImageVersion.RevisionNumber.Version,
pFwImageInfo->ImageVersion.SecurityRevisionNumber.Version,
pFwImageInfo->ImageVersion.BuildNumber.Build);
}
} else {
gBS->CloseEvent(ProgressEvent);
// move to next line after progress events have ended
PrinterSetMsg(pCmd->pPrintCtx, ReturnCode, FORMAT_NL);
if (StagedFwUpdates > 0) {
/*
At this point, all indications are that the FW is on the way to being staged.
Loop until they all report a staged version
*/
TempReturnCode = BlockForFwStage(pCmd, pCommandStatus, pNvmDimmConfigProtocol,
&ReturnCodes[0], &NvmCodes[0], pDimmTargets, DimmTargetsNum);
if (EFI_ERROR(TempReturnCode)) {
ReturnCode = TempReturnCode;
goto Finish;
}
}
}
ReturnCode = EFI_SUCCESS;
pCommandStatus->GeneralStatus = NVM_SUCCESS;
for (Index = 0; Index < DimmTargetsNum; Index++) {
TempReturnCode = GetDimmReturnCode(Examine, ReturnCodes[Index], NvmCodes[Index], &generalNvmStatus);
//the 'EFI_ALREADY_STARTED' return code is considered a minor success
//so if another error is present then prefer to report that error instead
//(in other words, if 'ReturnCode' has been set to something other than 'EFI_ALREADY_STARTED' or 'EFI_SUCCESS'
// then don't let it be altered)
if (TempReturnCode == EFI_SUCCESS ||
(TempReturnCode == EFI_ALREADY_STARTED && ReturnCode != EFI_SUCCESS && ReturnCode != TempReturnCode))
{
continue;
}
ReturnCode = TempReturnCode;
pCommandStatus->GeneralStatus = generalNvmStatus;
}
Finish:
PRINTER_SET_COMMAND_STATUS(pCmd->pPrintCtx, ReturnCode, CLI_INFO_LOAD_FW, CLI_INFO_ON, pCommandStatus);
FreeCommandStatus(&pCommandStatus);
FinishNoCommandStatus:
// if no PrintCtx then nothing can be buffered so no need to process it
if ((NULL != pCmd)) {
PRINTER_PROCESS_SET_BUFFER(pCmd->pPrintCtx);
}
FREE_POOL_SAFE(pFileName);
FREE_POOL_SAFE(pFwImageInfo);
FREE_POOL_SAFE(pDimmIds);
FREE_POOL_SAFE(pOptionsValue);
FREE_POOL_SAFE(pDimmTargetIds);
if (TargetsIsNewList) {
FREE_POOL_SAFE(pDimmTargets);
}
NVDIMM_EXIT_I64(ReturnCode);
FREE_POOL_SAFE(pOptionsValue);
return ReturnCode;
}
/**
For a given DIMM, this will evaluate what the return code should be
@param[in] examine - if the examin flag was sent by the user
@param[in] dimmReturnCode - the return code returned by the call to update the FW
@param[in] dimmNvmStatus - the NVM status returned by the call to update the FW
@param[out] generalNvmStatus - the NVM status to be applied to the general command status
@retval the return code
**/
EFI_STATUS
GetDimmReturnCode(
IN BOOLEAN Examine,
IN EFI_STATUS dimmReturnCode,
IN NVM_STATUS dimmNvmStatus,
OUT NVM_STATUS * pGeneralNvmStatus
) {
EFI_STATUS ReturnCode = EFI_SUCCESS;
NVM_STATUS NvmStatus = NVM_SUCCESS;
NVDIMM_ENTRY();
*pGeneralNvmStatus = NVM_SUCCESS;
if (Examine && (dimmNvmStatus == NVM_ERR_FIRMWARE_TOO_LOW_FORCE_REQUIRED || dimmNvmStatus == NVM_SUCCESS)) {
//these are both considered success when in examine
goto Finish;
}
*pGeneralNvmStatus = dimmNvmStatus;
NvmStatus = dimmNvmStatus;
Finish:
ReturnCode = MatchCliReturnCode(NvmStatus);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
For the lists provided, this will block until all dimms indicated in the StagedFwDimmIds report a non-zero staged FW image. This
is intended to be run after a non-recovery (normal) FW update.
@param[in] pCmd - The command object
@param[in] pCommandStatus - The command status object
@param[in] pNvmDimmConfigProtocol - The open config protocol
@param[in] pReturnCodes - The current list of return codes for each DIMM
@param[in] pNvmCodes - The current list of NVM codes for the FW work of each DIMM
@param[in] pDimmTargets - The list of DIMMs for which a FW update was attempted
@param[in] pDimmTargetsNum - The list length of the pDimmTargets list
@retval EFI_SUCCESS - All dimms staged their fw as expected.
@retval EFI_xxxx - One or more DIMMS did not stage their FW as expected.
**/
EFI_STATUS
BlockForFwStage(
IN struct Command *pCmd,
IN COMMAND_STATUS *pCommandStatus,
IN EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol,
IN EFI_STATUS *pReturnCodes,
IN NVM_STATUS *pNvmCodes,
IN DIMM_INFO *pDimmTargets,
IN UINT32 pDimmTargetsNum
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
UINT32 CurrentStageCheck = 0;
EFI_STATUS FwStagedLongOpCodes[MAX_DIMMS];
BOOLEAN FwStageDone[MAX_DIMMS];
UINT16 FwStagedPendingCount = 0;
UINT16 FwStagedCompleteCount = 0;
UINT8 CmdOpcode = 0;
UINT8 CmdSubOpcode = 0;
UINT8 PtUpdateFw = 0x09;
UINT8 SubopUpdateFw = 0x0;
EFI_STATUS LongOpEfiStatus = EFI_SUCCESS;
UINT8 TransmitFwNeverHappened = 0xFF;
UINT8 UnknownStatus = 0xFD;
volatile UINT32 Index = 0;
NVDIMM_ENTRY();
if (pDimmTargetsNum > MAX_DIMMS) {
NVDIMM_DBG("Number of target DIMMs is greater than max DIMMs number.");
goto Finish;
}
//initialize
for (Index = 0; Index < MAX_DIMMS; Index++) {
FwStagedLongOpCodes[Index] = UnknownStatus;
FwStageDone[Index] = FALSE;
}
//more initialize
for (Index = 0; Index < pDimmTargetsNum; Index++) {
if (pReturnCodes[Index] != EFI_SUCCESS) {
//this DIMM didn't transmit an image. Don't expect a long op code
FwStagedLongOpCodes[Index] = TransmitFwNeverHappened;
FwStagedCompleteCount++;
FwStageDone[Index] = TRUE;
NVDIMM_DBG("Error with FW stage on dimm %d: an existing error exists - NvmCode=[%d], ReturnCode=[%d]",
pDimmTargets[Index].DimmID, pNvmCodes[Index], pReturnCodes[Index]);
continue;
}
FwStagedPendingCount++;
CmdOpcode = 0;
CmdSubOpcode = 0;
pNvmDimmConfigProtocol->GetLongOpStatus(pNvmDimmConfigProtocol, pDimmTargets[Index].DimmID,
&CmdOpcode, &CmdSubOpcode, NULL, NULL, &LongOpEfiStatus);
if (CmdOpcode == PtUpdateFw && CmdSubOpcode == SubopUpdateFw)
{
FwStagedLongOpCodes[Index] = LongOpEfiStatus;
}
}
if (FwStagedPendingCount == 0) {
NVDIMM_DBG("No DIMMs have images expected to stage. Exiting.");
goto Finish;
}
while (CurrentStageCheck < MAX_CHECKS_FOR_SUCCESSFUL_STAGING) {
CurrentStageCheck++;
//Check each DIMM that had a image staged to see if it reports a staged version
for (Index = 0; Index < pDimmTargetsNum; Index++)
{
//don't perform unnecessary checks or repeat checks that already took place
if (FwStagedLongOpCodes[Index] == TransmitFwNeverHappened || FwStageDone[Index] == TRUE) {
continue;
}
if (FwHasBeenStaged(pCmd, pNvmDimmConfigProtocol, pDimmTargets[Index].DimmID) == TRUE) {
pNvmCodes[Index] = NVM_SUCCESS_FW_RESET_REQUIRED;
pReturnCodes[Index] = EFI_SUCCESS;
SetObjStatusForDimmInfoWithErase(pCommandStatus, &pDimmTargets[Index], pNvmCodes[Index], TRUE);
FwStagedCompleteCount++;
FwStageDone[Index] = TRUE;
FwStagedLongOpCodes[Index] = FW_SUCCESS;
NVDIMM_DBG("FW stage detected for dimm %d", pDimmTargets[Index].DimmID);
continue;
}
CmdOpcode = 0;
CmdSubOpcode = 0;
pNvmDimmConfigProtocol->GetLongOpStatus(pNvmDimmConfigProtocol, pDimmTargets[Index].DimmID,
&CmdOpcode, &CmdSubOpcode, NULL, NULL, &LongOpEfiStatus);
if (CmdOpcode == PtUpdateFw && CmdSubOpcode == SubopUpdateFw) {
if (LongOpEfiStatus != EFI_NO_RESPONSE && LongOpEfiStatus != EFI_SUCCESS) {
NVDIMM_DBG("Error with FW stage on dimm %d: Long operation failed - LongOpEfiStatus=[%d]",
pDimmTargets[Index].DimmID, LongOpEfiStatus);
if (LongOpEfiStatus == EFI_DEVICE_ERROR) {
pNvmCodes[Index] = NVM_ERR_DEVICE_ERROR;
} else if (LongOpEfiStatus == EFI_UNSUPPORTED) {
pNvmCodes[Index] = NVM_ERR_UNSUPPORTED_COMMAND;
} else if (LongOpEfiStatus == EFI_SECURITY_VIOLATION) {
pNvmCodes[Index] = NVM_ERR_FW_UPDATE_AUTH_FAILURE;
} else if (LongOpEfiStatus == EFI_ABORTED) {
pNvmCodes[Index] = NVM_ERR_LONG_OP_ABORTED_OR_REVISION_FAILURE;
} else {
pNvmCodes[Index] = NVM_ERR_LONG_OP_UNKNOWN;
}
pReturnCodes[Index] = LongOpEfiStatus;
SetObjStatusForDimmInfoWithErase(pCommandStatus, &pDimmTargets[Index], pNvmCodes[Index], TRUE);
FwStagedCompleteCount++;
FwStageDone[Index] = TRUE;
FwStagedLongOpCodes[Index] = LongOpEfiStatus;
}
}
}
if (FwStagedCompleteCount == pDimmTargetsNum) {
break; //while loop
}
gBS->Stall(MICROSECONDS_PERIOD_BETWEEN_STAGING_CHECKS);
}
//mark any DIMM which was pending an update but never confirmed it as a failure
for (Index = 0; Index < pDimmTargetsNum; Index++) {
if (FwStageDone[Index] == FALSE) {
NVDIMM_DBG("Error with FW stage on dimm %d: Long operation status unknown, image never staged", pDimmTargets[Index].DimmID);
pNvmCodes[Index] = NVM_ERR_UNABLE_TO_STAGE_NO_LONGOP;
pReturnCodes[Index] = EFI_ABORTED;
SetObjStatusForDimmInfoWithErase(pCommandStatus, &pDimmTargets[Index], pNvmCodes[Index], TRUE);
ReturnCode = EFI_ABORTED;
}
}
Finish:
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Check to see if a FW has already been staged on a DIMM
@param[in] pCmd - The command object
@param[in] pNvmDimmConfigProtocol - The open config protocol
@param[in] DimmID - The ID of the dimm to check. Must be a functional DIMM
**/
BOOLEAN
FwHasBeenStaged(
IN struct Command *pCmd,
IN EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol,
IN UINT16 DimmID
) {
BOOLEAN RetBool = FALSE;
EFI_STATUS ReturnCode = EFI_SUCCESS;
DIMM_INFO Dimm;
NVDIMM_ENTRY();
CHECK_RESULT((pNvmDimmConfigProtocol->GetDimm(pNvmDimmConfigProtocol, DimmID, DIMM_INFO_CATEGORY_FW_IMAGE_INFO, &Dimm)), Finish);
if (FALSE == FW_VERSION_UNDEFINED(Dimm.StagedFwVersion)) {
RetBool = TRUE;
}
Finish:
NVDIMM_EXIT_I64(ReturnCode);
return RetBool;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/LoadCommand.h 0000664 0000000 0000000 00000006052 14165347476 0020260 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _LOAD_COMMAND_H_
#define _LOAD_COMMAND_H_
#include
#include "CommandParser.h"
#include
#include
#define STAGING_CHECKS_PER_SECOND 4
#define MAX_CHECKS_FOR_SUCCESSFUL_STAGING (FW_UPDATE_TIMEOUT_SECONDS)*STAGING_CHECKS_PER_SECOND
#define MICROSECONDS_PERIOD_BETWEEN_STAGING_CHECKS 1000000/STAGING_CHECKS_PER_SECOND
/**
Register the load command
**/
EFI_STATUS
RegisterLoadCommand (
);
/**
Execute the load command
@param[in] pCmd the command structure that contains the user input data.
@retval EFI_SUCCESS if everything went OK - including the firmware load process.
@retval EFI_INVALID_PARAMETER if the user input is invalid or the file validation fails
@retval EFI_UNSUPPORTED if the driver is not loaded or there are no DCPMMs in the system.
@retval EFI_NOT_FOUND if there is no DIMM with the user specified PID
**/
EFI_STATUS
Load(
IN struct Command *pCmd
);
/**
For a given DIMM, this will evaluate what the return code should be
@param[in] examine - if the examine flag was sent by the user
@param[in] dimmReturnCode - the return code returned by the call to update the FW
@param[in] dimmNvmStatus - the NVM status returned by the call to update the FW
@param[out] generalNvmStatus - the NVM status to be applied to the general command status
@retval the return code
**/
EFI_STATUS
GetDimmReturnCode(
IN BOOLEAN examine,
IN EFI_STATUS dimmReturnCode,
IN NVM_STATUS dimmNvmStatus,
OUT NVM_STATUS * pGeneralNvmStatus
);
/**
For the lists provided, this will block until all dimms indicated in the StagedFwDimmIds report a non-zero staged FW image. This
is intended to be run after a non-recovery (normal) FW update.
@param[in] pCmd - The command object
@param[in] pCommandStatus - The command status object
@param[in] pNvmDimmConfigProtocol - The open config protocol
@param[in] pReturnCodes - The current list of return codes for each DIMM
@param[in] pNvmCodes - The current list of NVM codes for the FW work of each DIMM
@param[in] pDimmTargets - The list of DIMMs for which a FW update was attempted
@param[in] pDimmTargetsNum - The list length of the pDimmTargets list
@retval EFI_SUCCESS - All dimms staged their fw as expected.
@retval EFI_xxxx - One or more DIMMS did not stage their FW as expected.
**/
EFI_STATUS
BlockForFwStage(
IN struct Command *pCmd,
IN COMMAND_STATUS *pCommandStatus,
IN EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol,
IN EFI_STATUS *pReturnCodes,
IN NVM_STATUS *pNvmCodes,
IN DIMM_INFO *pDimmTargets,
IN UINT32 pDimmTargetsNum
);
/**
Check to see if a FW has already been staged on a DIMM
@param[in] pCmd - The command object
@param[in] pNvmDimmConfigProtocol - The open config protocol
@param[in] DimmID - The ID of the dimm to check. Must be a functional DIMM
**/
BOOLEAN
FwHasBeenStaged(
IN struct Command *pCmd,
IN EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol,
IN UINT16 DimmID
);
#endif /** _LOAD_COMMAND_H_ **/
ipmctl-03.00.00.0423/DcpmPkg/cli/LoadGoalCommand.c 0000664 0000000 0000000 00000033367 14165347476 0021067 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include
#include "Debug.h"
#include "Types.h"
#include "Utility.h"
#include "NvmInterface.h"
#include "CommandParser.h"
#include "LoadGoalCommand.h"
#include "CreateGoalCommand.h"
#include "Common.h"
#include "NvmDimmCli.h"
#include
/**
Command syntax definition
**/
struct Command LoadGoalCommand =
{
LOAD_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"", HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", LARGE_PAYLOAD_OPTION, L"", L"", HELP_LPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", SMALL_PAYLOAD_OPTION, L"", L"", HELP_SPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
{FORCE_OPTION_SHORT, FORCE_OPTION, L"", L"", HELP_FORCE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", SOURCE_OPTION, L"", SOURCE_OPTION_HELP, L"Source Directory required to load goal", FALSE, ValueRequired},
{UNITS_OPTION_SHORT, UNITS_OPTION, L"", UNITS_OPTION_HELP, HELP_UNIT_DETAILS_TEXT, FALSE, ValueRequired}
#ifdef OS_BUILD
,{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP, HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#endif
},
{ //!< targets
{DIMM_TARGET, L"", HELP_TEXT_DIMM_IDS, FALSE, ValueOptional},
{GOAL_TARGET, L"", L"", TRUE, ValueEmpty},
{SOCKET_TARGET, L"", HELP_TEXT_SOCKET_IDS, FALSE, ValueOptional}
},
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Create a memory allocation goal request from a file.", //!< help
LoadGoal,
TRUE
};
/**
Execute the Load Goal command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
@retval EFI_NO_RESPONSE FW busy on one or more dimms
**/
EFI_STATUS
LoadGoal(
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
UINT16 *pDimmIds = NULL;
UINT32 DimmIdsCount = 0;
UINT16 *pSocketIds = NULL;
UINT32 SocketIdsCount = 0;
COMMAND_STATUS *pCommandStatus = NULL;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
CHAR16 *pLoadUserPath = NULL;
CHAR16 *pLoadFilePath = NULL;
CHAR16 *pTargetValue = NULL;
CHAR8 *pFileString = NULL;
CHAR16 *pCommandStr = NULL;
EFI_DEVICE_PATH_PROTOCOL *pDevicePathProtocol = NULL;
BOOLEAN Force = FALSE;
COMMAND_INPUT ShowGoalCmdInput;
COMMAND ShowGoalCmd;
DIMM_INFO *pDimms = NULL;
UINT32 DimmCount = 0;
UINT16 UnitsOption = DISPLAY_SIZE_UNIT_UNKNOWN;
UINT16 UnitsToDisplay = FixedPcdGet16(PcdDcpmmCliDefaultCapacityUnit);
CHAR16 *pUnitsStr = NULL;
DISPLAY_PREFERENCES DisplayPreferences;
UINT32 SocketIndex = 0;
BOOLEAN Confirmation = FALSE;
INTEL_DIMM_CONFIG *pIntelDIMMConfig = NULL;
PRINT_CONTEXT *pPrinterCtx = NULL;
CHAR16 * pShowGoalOutputArgs = NULL;
BOOLEAN isDimmUnlocked = FALSE;
NVDIMM_ENTRY();
ZeroMem(&DisplayPreferences, sizeof(DisplayPreferences));
ZeroMem(&ShowGoalCmdInput, sizeof(ShowGoalCmdInput));
ZeroMem(&ShowGoalCmd, sizeof(ShowGoalCmd));
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
Print(FORMAT_STR_NL, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
// NvmDimmConfigProtocol required
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// Populate the list of DIMM_INFO structures with relevant information
ReturnCode = GetDimmList(pNvmDimmConfigProtocol, pCmd, DIMM_INFO_CATEGORY_SECURITY, &pDimms, &DimmCount);
if (EFI_ERROR(ReturnCode)) {
if(ReturnCode == EFI_NOT_FOUND) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_INFO_NO_FUNCTIONAL_DIMMS);
}
goto Finish;
}
ReturnCode = ReadRunTimePreferences(&DisplayPreferences, DISPLAY_CLI_INFO);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_DISPLAY_PREFERENCES_RETRIEVE);
goto Finish;
}
UnitsToDisplay = DisplayPreferences.SizeUnit;
ReturnCode = GetUnitsOption(pCmd, &UnitsOption);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
/** Any valid units option will override the preferences **/
if (UnitsOption != DISPLAY_SIZE_UNIT_UNKNOWN) {
UnitsToDisplay = UnitsOption;
}
if (containsOption(pCmd, FORCE_OPTION) || containsOption(pCmd, FORCE_OPTION_SHORT) || XML == pPrinterCtx->FormatType) {
Force = TRUE;
}
pLoadFilePath = AllocateZeroPool(OPTION_VALUE_LEN * sizeof(*pLoadFilePath));
if (pLoadFilePath == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
// Check -source option
if (containsOption(pCmd, SOURCE_OPTION)) {
pLoadUserPath = getOptionValue(pCmd, SOURCE_OPTION);
if (pLoadUserPath == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
NVDIMM_ERR("Could not get -source value. Out of memory");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
}
ReturnCode = GetDeviceAndFilePath(pLoadUserPath, pLoadFilePath, &pDevicePathProtocol);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Failed to get file path (" FORMAT_EFI_STATUS ")", ReturnCode);
goto Finish;
}
// check if auto provision is enabled
RetrieveIntelDIMMConfig(&pIntelDIMMConfig);
if(pIntelDIMMConfig != NULL) {
if (pIntelDIMMConfig->ProvisionCapacityMode == PROVISION_CAPACITY_MODE_AUTO) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_CREATE_GOAL_AUTO_PROV_ENABLED);
FreePool(pIntelDIMMConfig);
goto Finish;
} else {
FreePool(pIntelDIMMConfig);
}
}
// Check targets
if (ContainTarget(pCmd, DIMM_TARGET)) {
pTargetValue = GetTargetValue(pCmd, DIMM_TARGET);
ReturnCode = GetDimmIdsFromString(pCmd, pTargetValue, pDimms, DimmCount, &pDimmIds, &DimmIdsCount);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("Failed on GetDimmIdsFromString");
goto Finish;
}
if (!AllDimmsInListAreManageable(pDimms, DimmCount, pDimmIds, DimmIdsCount)){
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_UNMANAGEABLE_DIMM);
goto Finish;
}
if (!AllDimmsInListInSupportedConfig(pDimms, DimmCount, pDimmIds, DimmIdsCount)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_POPULATION_VIOLATION);
goto Finish;
}
}
if (ContainTarget(pCmd, SOCKET_TARGET)) {
pTargetValue = GetTargetValue(pCmd, SOCKET_TARGET);
ReturnCode = GetUintsFromString(pTargetValue, &pSocketIds, &SocketIdsCount);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_TARGET_SOCKET);
NVDIMM_DBG("Failed on GetUintsFromString");
goto Finish;
}
}
// Initialize status structure
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
NVDIMM_DBG("Failed on InitializeCommandStatus");
goto Finish;
}
ReturnCode = ParseSourceDumpFile(pLoadFilePath, pDevicePathProtocol, &pFileString);
if (EFI_ERROR(ReturnCode)) {
ResetCmdStatus(pCommandStatus, NVM_ERR_LOAD_INVALID_DATA_IN_FILE);
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
PRINTER_SET_COMMAND_STATUS(pCmd->pPrintCtx, ReturnCode, CLI_INFO_LOAD_GOAL, L"", pCommandStatus);
goto Finish;
}
if (!Force) {
PRINTER_PROMPT_MSG(pPrinterCtx, ReturnCode, CLI_INFO_LOAD_GOAL_CONFIRM_PROMPT, pLoadFilePath);
ReturnCode = AreRequestedDimmsSecurityUnlocked(pDimms, DimmCount, pDimmIds, DimmIdsCount, &isDimmUnlocked);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
// send warning if security unlocked for target dimms
if (isDimmUnlocked) {
PRINTER_PROMPT_MSG(pPrinterCtx, ReturnCode, CLI_WARN_GOAL_CREATION_SECURITY_UNLOCKED);
}
ReturnCode = PromptYesNo(&Confirmation);
if (EFI_ERROR(ReturnCode)) {
PRINTER_PROMPT_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_PROMPT_INVALID);
NVDIMM_DBG("Failed on PromptedInput");
goto Finish;
}
else if (!Confirmation) {
goto Finish;
}
}
ReturnCode = pNvmDimmConfigProtocol->LoadGoalConfig(pNvmDimmConfigProtocol, pDimmIds, DimmIdsCount, pSocketIds,
SocketIdsCount, pFileString, pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
if (pCommandStatus->GeneralStatus != NVM_SUCCESS) {
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
PRINTER_SET_COMMAND_STATUS(pCmd->pPrintCtx, ReturnCode, CLI_INFO_LOAD_GOAL, L"", pCommandStatus);
goto Finish;
}
}
if (!EFI_ERROR(ReturnCode)) {
ReturnCode = CreateCmdLineOutputStr(pCmd, &pShowGoalOutputArgs);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
if (UnitsOption != DISPLAY_SIZE_UNIT_UNKNOWN) {
CHECK_RESULT(UnitsToStr(gNvmDimmCliHiiHandle, UnitsToDisplay, &pUnitsStr), Finish);
pCommandStr = CatSPrintClean(pCommandStr, FORMAT_STR_SPACE FORMAT_STR FORMAT_STR L" " FORMAT_STR L" " FORMAT_STR, L"show", pShowGoalOutputArgs, UNITS_OPTION, pUnitsStr,
L"-goal");
} else {
pCommandStr = CatSPrintClean(pCommandStr, FORMAT_STR_SPACE FORMAT_STR FORMAT_STR, L"show", pShowGoalOutputArgs, L"-goal");
}
// Only print the socket applied
if (SocketIdsCount > 0) {
pCommandStr = CatSPrintClean(pCommandStr, L" " FORMAT_STR L" ", L"-socket");
for (SocketIndex = 0; SocketIndex < SocketIdsCount; SocketIndex++) {
if (SocketIndex == 0) {
pCommandStr = CatSPrintClean(pCommandStr, L"%d", pSocketIds[SocketIndex]);
} else {
pCommandStr = CatSPrintClean(pCommandStr, L",%d", pSocketIds[SocketIndex]);
}
}
}
FillCommandInput(pCommandStr, &ShowGoalCmdInput);
ReturnCode = Parse(&ShowGoalCmdInput, &ShowGoalCmd);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Failed parsing command input");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
if (ShowGoalCmd.run == NULL) {
NVDIMM_WARN("Couldn't find show -goal command");
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
PRINTER_PROMPT_MSG(pPrinterCtx, ReturnCode, L"Loaded following pool configuration goal\n");
ExecuteCmd(&ShowGoalCmd);
FREE_POOL_SAFE(pCommandStr);
goto FinishSkipPrinterProcess;
}
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FinishSkipPrinterProcess:
FreeCommandInput(&ShowGoalCmdInput);
FreeCommandStructure(&ShowGoalCmd);
FreeCommandStatus(&pCommandStatus);
FREE_POOL_SAFE(pCommandStr);
FREE_POOL_SAFE(pLoadFilePath);
FREE_POOL_SAFE(pFileString);
FREE_POOL_SAFE(pSocketIds);
FREE_POOL_SAFE(pDimmIds);
FREE_POOL_SAFE(pDimms);
FREE_POOL_SAFE(pLoadUserPath);
FREE_POOL_SAFE(pUnitsStr);
FREE_POOL_SAFE(pShowGoalOutputArgs);
FREE_POOL_SAFE(pCommandStr);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Read and parse source file with Pool Goal structures to be loaded.
@param[in] pFilePath Name is a pointer to a load file path
@param[in] pDevicePath - handle to obtain generic path/location information concerning the
physical device or logical device. The device path describes the location of the device
the handle is for.
@param[out] pFileString Buffer for Pool Goal configuration from file
@retval EFI_SUCCESS File read and parse success
@retval EFI_INVALID_PARAMETER At least one of parameters is NULL or format of configuration in file is not proper
@retval EFI_INVALID_PARAMETER memory allocation failure
**/
EFI_STATUS
ParseSourceDumpFile(
IN CHAR16 *pFilePath,
IN EFI_DEVICE_PATH_PROTOCOL *pDevicePath,
OUT CHAR8 **pFileString
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
UINT64 FileBufferSize = 0;
UINT8 *pFileBuffer = NULL;
UINT32 NumberOfChars = 0;
if (pFilePath == NULL || pFileString == NULL) {
NVDIMM_DBG("Invalid Pointer");
goto Finish;
}
#ifndef OS_BUILD
if (pDevicePath == NULL) {
NVDIMM_DBG("Invalid Pointer");
goto Finish;
}
#endif
ReturnCode = FileRead(pFilePath, pDevicePath, MAX_CONFIG_DUMP_FILE_SIZE, FALSE, &FileBufferSize, (VOID **) &pFileBuffer);
if (EFI_ERROR(ReturnCode) || pFileBuffer == NULL) {
goto Finish;
}
/** Prepare memory for end of string char **/
*pFileString = ReallocatePool(FileBufferSize, FileBufferSize + sizeof('\0'), pFileBuffer);
if (*pFileString == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
goto Finish;
}
NumberOfChars = (UINT32)FileBufferSize / sizeof(**pFileString);
/** Make read data from file as string **/
(*pFileString)[NumberOfChars] = '\0';
Finish:
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Register the Load Goal command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterLoadGoalCommand(
)
{
EFI_STATUS ReturnCode;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&LoadGoalCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/LoadGoalCommand.h 0000664 0000000 0000000 00000003015 14165347476 0021057 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _LOAD_GOAL_COMMAND_
#define _LOAD_GOAL_COMMAND_
#include
/**
Register the Load Goal command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterLoadGoalCommand();
/**
Read and parse source file with Pool Goal structures to be loaded.
@param[in] pFilePath Name is a pointer to a load file path
@param[in] pDevicePath - handle to obtain generic path/location information concerning the
physical device or logical device. The device path describes the location of the device
the handle is for.
@param[out] pFileString Buffer for Pool Goal configuration from file
@retval EFI_SUCCESS File read and parse success
@retval EFI_INVALID_PARAMETER At least one of parameters is NULL or format of configuration in file is not proper
@retval EFI_INVALID_PARAMETER memory allocation failure
**/
EFI_STATUS
ParseSourceDumpFile(
IN CHAR16 *pFilePath,
IN EFI_DEVICE_PATH_PROTOCOL *pDevicePath,
OUT CHAR8 **pFileString
);
/**
Execute the Load Goal command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
LoadGoal(
IN struct Command *pCmd
);
#endif /** _LOAD_GOAL_COMMAND_ **/
ipmctl-03.00.00.0423/DcpmPkg/cli/LoadSessionCommand.c 0000664 0000000 0000000 00000010772 14165347476 0021623 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include
#include "Debug.h"
#include "Types.h"
#include "NvmInterface.h"
#include "CommandParser.h"
#include "LoadSessionCommand.h"
#include "Common.h"
#include "Convert.h"
#include "Utility.h"
#include
#ifdef OS_BUILD
#include "os.h"
#endif
#define SUCCESSFULLY_LOADED_BUFFER_MSG L"Successfully loaded %d bytes to session buffer."
/**
Command syntax definition
**/
struct Command LoadSessionCommand =
{
LOAD_VERB, //!< verb
{ //!< options
{L"", SOURCE_OPTION, L"", SOURCE_OPTION_HELP, L"Source of the Session to load", FALSE, ValueRequired},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty}
#ifdef OS_BUILD
,{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP, HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#endif
},
{ //!< targets
{SESSION_TARGET, L"", L"", TRUE, ValueEmpty}
},
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Load a recorded (PBR) session into memory for playback.", //!< help
LoadSession,
TRUE,
TRUE
};
/**
Execute the Load Session command
**/
EFI_STATUS
LoadSession(
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
EFI_DCPMM_PBR_PROTOCOL *pNvmDimmPbrProtocol = NULL;
EFI_DEVICE_PATH_PROTOCOL *pDevicePathProtocol = NULL;
CHAR16 *pLoadFilePath = NULL;
CHAR16 *pLoadUserPath = NULL;
UINT64 FileBufferSize = 0;
UINT8 *pFileBuffer = NULL;
PRINT_CONTEXT *pPrinterCtx = NULL;
NVDIMM_ENTRY();
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
Print(FORMAT_STR_NL, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
//If Windows, check for admin privilege needed to update registry for PBR state
CHECK_WIN_ADMIN_PERMISSIONS();
// Check -source option
if (containsOption(pCmd, SOURCE_OPTION)) {
pLoadUserPath = getOptionValue(pCmd, SOURCE_OPTION);
if (pLoadUserPath == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
NVDIMM_ERR("Could not get -source value. Out of memory");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
}
// NvmDimmConfigProtocol required
ReturnCode = OpenNvmDimmProtocol(gNvmDimmPbrProtocolGuid, (VOID **)&pNvmDimmPbrProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
pLoadFilePath = AllocateZeroPool(OPTION_VALUE_LEN * sizeof(*pLoadFilePath));
if (pLoadFilePath == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
ReturnCode = GetDeviceAndFilePath(pLoadUserPath, pLoadFilePath, &pDevicePathProtocol);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_FAILED_TO_GET_FILE_PATH, ReturnCode);
goto Finish;
}
ReturnCode = FileRead(pLoadFilePath, pDevicePathProtocol, 0, TRUE, &FileBufferSize, (VOID **)&pFileBuffer);
if (EFI_ERROR(ReturnCode) || pFileBuffer == NULL) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_FAILED_TO_READ_FILE);
goto Finish;
}
//session module responsible for freeing buffer.
ReturnCode = pNvmDimmPbrProtocol->PbrSetSession(pFileBuffer, (UINT32)FileBufferSize);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_FAILED_TO_SET_SESSION_BUFFER);
goto Finish;
}
//reset the tagid to 0 (first tag)
PbrDcpmmSerializeTagId(0);
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, SUCCESSFULLY_LOADED_BUFFER_MSG, (UINT32)FileBufferSize);
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FREE_POOL_SAFE(pLoadFilePath);
FREE_POOL_SAFE(pLoadUserPath);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Register the Load Session command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterLoadSessionCommand(
)
{
EFI_STATUS ReturnCode;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&LoadSessionCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/LoadSessionCommand.h 0000664 0000000 0000000 00000001335 14165347476 0021623 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _LOAD_SESSION_COMMAND_
#define _LOAD_SESSION_COMMAND_
#include
/**
Register the Load Pbr command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterLoadSessionCommand();
/**
Execute the Load Session CMD
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
LoadSession(
IN struct Command *pCmd
);
#endif /** _LOAD_SESSION_COMMAND_ **/
ipmctl-03.00.00.0423/DcpmPkg/cli/NvmDimmCli.c 0000664 0000000 0000000 00000110573 14165347476 0020100 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "NvmDimmCli.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "CommandParser.h"
#include "ShowDimmsCommand.h"
#include "ShowSocketsCommand.h"
#include "SetDimmCommand.h"
#include "DeleteDimmCommand.h"
#include "ShowRegionsCommand.h"
#include "ShowAcpiCommand.h"
#include "ShowSmbiosCommand.h"
#include "LoadCommand.h"
#include "SetSensorCommand.h"
#include "ShowSensorCommand.h"
#include "CreateGoalCommand.h"
#include "ShowGoalCommand.h"
#include "DeleteGoalCommand.h"
#include "DumpGoalCommand.h"
#include "LoadGoalCommand.h"
#include "StartDiagnosticCommand.h"
#include "ShowNamespaceCommand.h"
#include "CreateNamespaceCommand.h"
#include "DeleteNamespaceCommand.h"
#include "ShowErrorCommand.h"
#include "ShowCelCommand.h"
#include "ShowTopologyCommand.h"
#include "DumpDebugCommand.h"
#include "ShowMemoryResourcesCommand.h"
#include "ShowSystemCapabilitiesCommand.h"
#include "ShowRegisterCommand.h"
#include "Common.h"
#include "ShowFirmwareCommand.h"
#include "ShowPcdCommand.h"
#include "StartFormatCommand.h"
#include "ShowPreferencesCommand.h"
#include "SetPreferencesCommand.h"
#include "ShowPerformanceCommand.h"
#include "ShowCmdAccessPolicyCommand.h"
#include "DeletePcdCommand.h"
#include
#include "StartSessionCommand.h"
#include "StopSessionCommand.h"
#include "DumpSessionCommand.h"
#include "ShowSessionCommand.h"
#include "LoadSessionCommand.h"
#ifdef OS_BUILD
#include "os_efi_shell_parameters_protocol.h"
#include
#else
#include
#endif
#include
#if _BullseyeCoverage
#ifndef OS_BUILD
extern int cov_dumpData(void);
#endif // !OS_BUILD
#endif // _BullseyeCoverage
#ifdef __MFG__
#include
#endif
#ifdef OS_BUILD
#include "DumpSupportCommand.h"
#include
extern void nvm_current_cmd(struct Command Command);
extern BOOLEAN ConfigIsDdrtProtocolDisabled();
extern BOOLEAN ConfigIsLargePayloadDisabled();
extern int g_fast_path;
#else
#include "DeletePcdCommand.h"
EFI_GUID gNvmDimmConfigProtocolGuid = EFI_DCPMM_CONFIG2_PROTOCOL_GUID;
EFI_GUID gIntelDimmConfigVariableGuid = INTEL_DIMM_CONFIG_VARIABLE_GUID;
EFI_GUID gIntelDimmPbrTagIdVariableguid = INTEL_DIMM_PBR_TAGID_VARIABLE_GUID;
EFI_GUID gNvmDimmPbrProtocolGuid = EFI_DCPMM_PBR_PROTOCOL_GUID;
#endif
EFI_GUID gNvmDimmDriverHealthGuid = EFI_DRIVER_HEALTH_PROTOCOL_GUID;
extern EFI_SHELL_INTERFACE *mEfiShellInterface;
#ifdef OS_BUILD
EFI_HANDLE gNvmDimmCliHiiHandle = (EFI_HANDLE)0x1;
extern EFI_SHELL_PARAMETERS_PROTOCOL gOsShellParametersProtocol;
extern EFI_DRIVER_BINDING_PROTOCOL gNvmDimmDriverDriverBinding;
#else
EFI_HANDLE gNvmDimmCliHiiHandle = NULL;
#ifndef MDEPKG_NDEBUG
extern volatile UINT32 _gPcd_BinaryPatch_PcdDebugPrintErrorLevel;
#endif //MDEPKG_NDEBUG
#endif
#define NVMDIMM_CLI_HII_GUID \
{ 0x26e4ac23, 0xd32f, 0x4788, {0x83, 0x95, 0xb0, 0x2a, 0x33, 0x0c, 0x28, 0x26}}
EFI_GUID gNvmDimmCliHiiGuid = NVMDIMM_CLI_HII_GUID;
/* Local fns */
static EFI_STATUS showVersion(struct Command *pCmd);
static EFI_STATUS GetPbrMode(UINT32 *Mode);
static EFI_STATUS SetPbrTag(CHAR16 *pName, CHAR16 *pDescription);
static EFI_STATUS ResetPbrSession(UINT32 TagId);
static EFI_STATUS SetDefaultProtocolAndPayloadSizeOptions();
#ifndef OS_BUILD
#ifndef MDEPKG_NDEBUG
static EFI_STATUS GetDriverDebugPrintVerbosity(UINT32 *pErrorLevel);
static EFI_STATUS SetDriverDebugPrintVerbosity(UINT32 ErrorLevel);
#endif
#endif
/**
Supported commands
Display CLI application help
**/
struct Command HelpCommand =
{
HELP_VERB, //!< verb
{
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"",HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
#ifdef OS_BUILD
{OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP,HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }, //!< options
#endif // OS_BUILD
{L"", L"", L"", L"",L"", FALSE, ValueOptional}
}, //!< options
{{L"", L"", L"", FALSE, ValueOptional}}, //!< targets
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Display the CLI help.", //!< help
showHelp, //!< run function
TRUE
};
/**
Display the CLI application version
**/
struct Command VersionCommand =
{
VERSION_VERB, //!< verb
{
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"",HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
#ifdef OS_BUILD
{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP,HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#else
{L"", L"", L"", L"", FALSE, ValueOptional} //!< options
#endif
}, //!< options
{{L"", L"", L"", FALSE, ValueOptional}}, //!< targets
{{L"", L"", L"", FALSE}}, //!< properties
L"Display the CLI version.", //!< help
showVersion, //!< run function
TRUE, //!< support printer
TRUE //!< skip initialization
};
BOOLEAN HelpRequested = FALSE;
BOOLEAN FullHelpRequested = FALSE;
/**
Reviews the passed tokens for help|-h|-help flags and prepares the token
order for proper display
**/
VOID FixHelp(CHAR16** ppTokens, UINT32* pCount){
UINT32 Index = 0;
UINT32 Index2 = 0;
UINT32 HelpIndex = 0;
CHAR16 *pHelpTokenTmp = NULL;
UINT32 HelpFlags = 0;
BOOLEAN HelpTokenIndexWrong = FALSE;
HelpRequested = FALSE;
FullHelpRequested = FALSE;
if (ppTokens == NULL || pCount == NULL || *pCount <= 0) {
return;
}
//look for simple requests for global help
if (0 == StrICmp(ppTokens[0], HELP_VERB) ||
0 == StrICmp(ppTokens[0], HELP_OPTION) ||
0 == StrICmp(ppTokens[0], HELP_OPTION_SHORT)) {
HelpRequested = TRUE;
FullHelpRequested = TRUE;
for (Index = 1; Index < *pCount; Index++) {
FREE_POOL_SAFE(ppTokens[Index]);
}
*pCount = 1;
return;
}
//Examine the post-verb to determine if/where the help token(s) are
for (Index = 1; Index < *pCount; Index++) {
if (0 == StrICmp(ppTokens[Index], HELP_VERB) ||
0 == StrICmp(ppTokens[Index], HELP_OPTION) ||
0 == StrICmp(ppTokens[Index], HELP_OPTION_SHORT)) {
HelpFlags++;
HelpRequested = TRUE;
if (HelpFlags == 1) {
//retain the help token, but change to the short version
ppTokens[Index][0] = '-';
ppTokens[Index][1] = 'h';
ppTokens[Index][2] = 0;
HelpIndex = Index;
pHelpTokenTmp = ppTokens[Index];
HelpTokenIndexWrong = Index > 1;
}
else {
//dispose of duplicate help flags
FREE_POOL_SAFE(ppTokens[Index]);
}
//create a 'hole' in the array
ppTokens[Index] = NULL;
}
}
//nothing to do
if (HelpFlags == 0) return;
if (TRUE == HelpTokenIndexWrong) {
//make a spot at slot 1 for the help token
for (Index = HelpIndex; Index > 1; Index--)
{
ppTokens[Index] = ppTokens[Index - 1];
}
}
//move the token to the right spot
ppTokens[1] = pHelpTokenTmp;
//collapse any 'holes' in the array (caused by multiple help flags)
for (Index = 1; Index < *pCount; Index++) {
if (ppTokens[Index] == NULL) {
for (Index2 = Index + 1; Index2 < *pCount; Index2++) {
if (ppTokens[Index2] != NULL) {
ppTokens[Index] = ppTokens[Index2];
ppTokens[Index2] = NULL;
break;
}
}
}
}
//adjust the count to account for removed parameters
for (Index = 1; Index < *pCount; Index++) {
if (ppTokens[Index] == NULL) {
break;
}
}
//set the new count
*pCount = Index;
}
VOID
PrintErrorMsg(CHAR16 *ErrorMsg, BOOLEAN ForESX) {
CHAR16 *pSubString = NULL;
CHAR16 *pSubStringEnd = NULL;
CHAR16 *pStringWalker = NULL;
if (ForESX) {
pSubString = AllocateZeroPool(200 *sizeof(CHAR16));
if (NULL == pSubString) {
goto StandardPrint;
}
pStringWalker = ErrorMsg;
//pSubStringBegin = pSubString;
pSubStringEnd = pSubString;
while (L'\0' != *pStringWalker) {
while ((L'\n' != *pStringWalker) && (L'\0' != *pStringWalker))
{
*pSubStringEnd = *pStringWalker;
++pSubStringEnd;
++pStringWalker;
}
if (pSubString != pSubStringEnd) {
*pSubStringEnd = L'\n';
++pSubStringEnd;
*pSubStringEnd = L'\0'; // make sure string is NULL terminated
Print(L"ERROR: ");
LongPrint(pSubString);
}
++pStringWalker;
if (L'\n' == *pStringWalker) {
Print(L"ERROR:\n");
}
pSubStringEnd = pSubString;
}
goto finish;
}
StandardPrint:
LongPrint(ErrorMsg);
Print(L"\n");
finish:
FREE_POOL_SAFE(pSubString);
}
/* ./
* The entry point for the application.
*
* @param[in] ImageHandle The firmware allocated handle for the EFI image.
* @param[in] pSystemTable A pointer to the EFI System Table.
*
* @retval EFI_SUCCESS The entry point is executed successfully.
* @retval other Some error occurs when executing this entry point.
*/
EFI_STATUS
EFIAPI
UefiMain(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *pSystemTable
)
{
EFI_STATUS Rc = EFI_SUCCESS;
struct CommandInput Input;
struct Command Command;
INT32 Index = 0;
CHAR16 *pLine = NULL;
BOOLEAN MoreInput = TRUE;
BOOLEAN HelpShown = FALSE;
UINTN Argc = 0;
CHAR16 **ppArgv = NULL;
UINT32 NextId = 0;
#ifdef OS_BUILD
BOOLEAN IsVersionCommand = FALSE;
#else
SHELL_FILE_HANDLE StdIn = NULL;
#ifndef MDEPKG_NDEBUG
UINT32 DefaultErrorLevel = 0;
GetDriverDebugPrintVerbosity(&DefaultErrorLevel);
UINT32 UpdatedErrorLevel = DefaultErrorLevel;
#endif
#endif
NVDIMM_ENTRY();
ZeroMem(&Input, sizeof(Input));
ZeroMem(&Command, sizeof(Command));
#ifndef OS_BUILD
/* only support EFI shell 2.0 */
Rc = ShellInitialize();
if (EFI_ERROR(Rc)) {
Rc = EFI_UNSUPPORTED;
NVDIMM_WARN("ShellInitialize failed, rc = 0x%llx", Rc);
Print(L"Error: EFI Shell 2.0 is required to run this application\n");
goto Finish;
}
#endif
if (gEfiShellParametersProtocol == NULL) {
Rc = EFI_UNSUPPORTED;
#ifndef OS_BUILD
NVDIMM_WARN("ShellInitialize succeeded but the shell interface and parameters protocols do not exist");
Print(L"Error: EFI Shell 2.0 is required to run this application.\n");
#else
NVDIMM_WARN("Shell interface and parameters protocols do not exist");
#endif
goto Finish;
}
#ifndef OS_BUILD
StdIn = gEfiShellParametersProtocol->StdIn;
#endif
Argc = gEfiShellParametersProtocol->Argc;
ppArgv = gEfiShellParametersProtocol->Argv;
for (Index = 1; Index < Argc; Index++) {
#ifndef OS_BUILD
#ifndef MDEPKG_NDEBUG
/** For UEFI pre-parse CLI arguments for verbose logging **/
if (0 == StrICmp(ppArgv[Index], VERBOSE_OPTION)
|| 0 == StrICmp(ppArgv[Index], VERBOSE_OPTION_SHORT)) {
PatchPcdSet32(PcdDebugPrintErrorLevel, DEBUG_VERBOSE);
UpdatedErrorLevel = DefaultErrorLevel | DEBUG_VERBOSE;
SetDriverDebugPrintVerbosity(UpdatedErrorLevel);
}
#endif
#endif
/** Need to set some flags in the case that the user wants help, but there are no DIMMs in the system **/
if (0 == StrICmp(ppArgv[Index], HELP_VERB)
|| 0 == StrICmp(ppArgv[Index], HELP_OPTION)
|| 0 == StrICmp(ppArgv[Index], HELP_OPTION_SHORT)) {
HelpRequested = TRUE;
if (Argc == 2) {
FullHelpRequested = TRUE;
}
}
}
if (Argc == 1) {
#ifndef OS_BUILD
/* Verify input was not redirected from a file */
if (ShellGetFileInfo(StdIn) == NULL) {
#endif
HelpRequested = TRUE;
FullHelpRequested = TRUE;
#ifndef OS_BUILD
}
#endif
}
#ifndef OS_BUILD
BOOLEAN Ascii = FALSE;
UINTN HandleCount = 0;
EFI_HANDLE *pHandleBuffer = NULL;
CHAR16 *pCurrentDriverName;
EFI_COMPONENT_NAME_PROTOCOL *pComponentName = NULL;
SetSerialAttributes();
#else
EFI_HANDLE FakeBindHandle = (EFI_HANDLE)0x1;
#endif
UINT32 Mode = PBR_NORMAL_MODE;
CHAR16 *pTagDescription = NULL;
if (!HelpRequested) {
//get the current pbr mode (playback/record/normal)
Rc = GetPbrMode(&Mode);
if (EFI_ERROR(Rc) && (EFI_NOT_FOUND != Rc)) {
goto Finish;
}
if (Mode == PBR_RECORD_MODE) {
Print(L"Warning - Executing in recording mode!\n\n");
}
else if (Mode == PBR_PLAYBACK_MODE) {
Print(L"Warning - Executing in playback mode!\n\n");
}
Rc = SetDefaultProtocolAndPayloadSizeOptions();
if (EFI_ERROR(Rc) && (EFI_NOT_FOUND != Rc)) {
goto Finish;
}
}
Index = 0;
/** Print runtime function address to ease calculation of GDB symbol loading offset. **/
NVDIMM_DBG_CLEAN("NvmDimmCliEntryPoint=0x%016lx\n", &UefiMain);
#ifndef OS_BUILD
/* with shell support level 3 */
if (PcdGet8(PcdShellSupportLevel) < 3) {
Rc = EFI_UNSUPPORTED;
NVDIMM_WARN("ShellSupport level %d too low", PcdGet8(PcdShellSupportLevel));
Print(L"Error: EFI Shell support level 3 is required to run this application\n");
goto Finish;
}
if (FALSE == HelpRequested) {
gNvmDimmCliHiiHandle = HiiAddPackages(&gNvmDimmCliHiiGuid, ImageHandle, ipmctlStrings, NULL);
if (gNvmDimmCliHiiHandle == NULL) {
NVDIMM_WARN("Unable to add string package to Hii");
goto Finish;
}
// Check for NVM Protocol
Rc = gBS->LocateHandleBuffer(ByProtocol, &gNvmDimmConfigProtocolGuid, NULL, &HandleCount, &pHandleBuffer);
if (EFI_NOT_FOUND != Rc && (EFI_ERROR(Rc) || HandleCount != 1)) {
if (Rc == EFI_NOT_FOUND) {
Print(FORMAT_STR_NL, CLI_ERR_FAILED_TO_FIND_PROTOCOL);
goto Finish;
}
Print(FORMAT_STR_NL, CLI_ERR_OPENING_CONFIG_PROTOCOL);
Rc = EFI_NOT_FOUND;
goto Finish;
}
Rc = OpenNvmDimmProtocol(
gEfiComponentNameProtocolGuid,
(VOID**)&pComponentName, NULL);
if (EFI_ERROR(Rc) && EFI_NOT_FOUND != Rc) {
NVDIMM_DBG("Failed to open the Component Name protocol, error = " FORMAT_EFI_STATUS "", Rc);
goto Finish;
}
if (pComponentName != NULL) {
//Get current driver name
Rc = pComponentName->GetDriverName(
pComponentName, "eng", &pCurrentDriverName);
if (EFI_ERROR(Rc)) {
NVDIMM_DBG("Could not get the driver name, error = " FORMAT_EFI_STATUS "", Rc);
goto Finish;
}
//Compare to the CLI version and print warning if there is a version mismatch
if (StrCmp(PMEM_MODULE_NAME NVMDIMM_VERSION_STRING L" Driver", pCurrentDriverName) != 0) {
Print(FORMAT_STR_NL, CLI_WARNING_CLI_DRIVER_VERSION_MISMATCH);
}
}
}
#else
// if help is requested Register all the commands so parsing will work later
if (g_basic_commands && !HelpRequested)
{
Rc = RegisterNonAdminUserCommands();
if (EFI_ERROR(Rc)) {
goto Finish;
}
}
else
#endif //OS_BUILD
{
Rc = RegisterCommands();
if (EFI_ERROR(Rc)) {
goto Finish;
}
}
while (MoreInput) {
Input.TokenCount = 0;
#ifndef OS_BUILD
/* user entered a command on the command pLine */
if (ShellGetFileInfo(StdIn) == NULL) {
#endif
/* 1st arg is the name of the app, so skip it */
if (Argc > 1 && FALSE == FullHelpRequested) {
MoreInput = FALSE; /* only one command is supported on the command pLine */
for (Index = 1; Index < Argc; Index++) {
pLine = CatSPrintClean(pLine, FORMAT_STR_SPACE, ppArgv[Index]);
if (pLine == NULL) {
Print(FORMAT_STR_NL, CLI_ERR_OUT_OF_MEMORY);
Rc = EFI_OUT_OF_RESOURCES;
goto FinishAfterRegCmds;
}
}
FillCommandInput(pLine, &Input);
if (Input.ppTokens == NULL) {
Print(FORMAT_STR_NL, CLI_ERR_OUT_OF_MEMORY);
Rc = EFI_OUT_OF_RESOURCES;
goto FinishAfterRegCmds;
}
} else {
/* user did not enter a command */
showHelp(NULL);
HelpShown = TRUE;
break;
}
#ifndef OS_BUILD
} else {
/* input was redirected from a file */
pLine = NULL;
pLine = ShellFileHandleReturnLine(StdIn, &Ascii);
if (pLine == NULL || StrLen(pLine) == 0) {
/* line was empty, go to next pLine */
if (ShellFileHandleEof(StdIn)) {
MoreInput = FALSE;
}
if (pLine != NULL) {
FreePool(pLine);
pLine = NULL;
}
continue;
}
/* parse the line into individual tokens */
FillCommandInput(pLine, &Input);
if (Input.ppTokens == NULL) {
Print(FORMAT_STR_NL, CLI_ERR_OUT_OF_MEMORY);
Rc = EFI_OUT_OF_RESOURCES;
goto FinishAfterRegCmds;
}
if (ShellFileHandleEof(StdIn)) {
MoreInput = FALSE;
}
}
#endif
/* Fix the passed tokens as needed */
FixHelp(Input.ppTokens, &Input.TokenCount);
if (TRUE == FullHelpRequested) {
showHelp(NULL);
HelpShown = TRUE;
break;
}
/* run the command */
Rc = Parse(&Input, &Command);
if (!HelpRequested) {
if (PBR_NORMAL_MODE != Mode && !Command.ExcludeDriverBinding) {
if (PBR_RECORD_MODE == Mode) {
pTagDescription = CatSPrint(NULL, L"%d", Rc);
SetPbrTag(pLine, pTagDescription);
FREE_POOL_SAFE(pTagDescription);
}
else {
//CLI is responsible for tracking the tagid.
//The id is saved to a non-persistent volatile store, and is incremented
//after each CLI cmd invocation. Given we have the tagid that should
//be executed next, explicitly reset the pbr session to that id before
//running the cmd.
PbrDcpmmDeserializeTagId(&NextId, 0);
ResetPbrSession(NextId);
PbrDcpmmSerializeTagId(NextId + 1);
}
}
}
if (!EFI_ERROR(Rc)) {
/* parse success, now run the command */
if (Command.ShowHelp) {
showHelp(&Command);
HelpShown = TRUE;
} else {
#ifdef OS_BUILD
// different handling of returncodes for version command so it works for regular users
IsVersionCommand = (StrnCmp(Command.verb, VERSION_VERB, VERB_LEN) == 0);
if (!Command.ExcludeDriverBinding && !g_fast_path) {
Rc = NvmDimmDriverDriverBindingStart(&gNvmDimmDriverDriverBinding, FakeBindHandle, NULL);
if (EFI_ERROR(Rc) && !IsVersionCommand) {
NVDIMM_ERR("Issue with driver initialization");
Print(GetSingleNvmStatusCodeMessage(gNvmDimmCliHiiHandle,GuessNvmStatusFromReturnCode(Rc)));
Print(FORMAT_NL);
}
}
if (!EFI_ERROR(Rc) || IsVersionCommand) {
#else
if (!EFI_ERROR(Rc)) {
#endif
Rc = ExecuteCmd(&Command);
}
#ifdef OS_BUILD
if (!Command.ExcludeDriverBinding && !g_fast_path) {
NvmDimmDriverDriverBindingStop(&gNvmDimmDriverDriverBinding, FakeBindHandle, 0, NULL);
}
#endif
}
if (EFI_ERROR(Rc)) {
MoreInput = FALSE; /* stop on failures */
}
}
else { /* syntax error */
#ifdef OS_BUILD
PrintErrorMsg(getSyntaxError(), is_ESX_output_requested());
#else
PrintErrorMsg(getSyntaxError(), FALSE);
#endif
MoreInput = FALSE; /* stop on failures */
}
#ifdef OS_BUILD
nvm_current_cmd(Command);
#endif
FreeCommandInput(&Input);
FreeCommandStructure(&Command);
} /* end while more input */
FinishAfterRegCmds:
/* clean up */
FreeCommands();
Finish:
FREE_POOL_SAFE(pLine);
FreeCommandInput(&Input);
if (gNvmDimmCliHiiHandle != NULL) {
HiiRemovePackages(gNvmDimmCliHiiHandle);
}
#if _BullseyeCoverage
#ifndef OS_BUILD
cov_dumpData();
#endif // !OS_BUILD
#endif // _BullseyeCoverage
//if help was displayed and not explicitly requested, ensure an error is returned
if (TRUE == HelpShown && FALSE == HelpRequested && FALSE == FullHelpRequested && EFI_SUCCESS == Rc) {
Rc = EFI_INVALID_PARAMETER;
}
#ifndef OS_BUILD
#ifndef MDEPKG_NDEBUG
//Reset driver debug print error level to original default value, otherwise will persist across cli invocations
if (DefaultErrorLevel != UpdatedErrorLevel) {
SetDriverDebugPrintVerbosity(DefaultErrorLevel);
}
#endif
#endif
NVDIMM_EXIT_I64(Rc);
return Rc;
}
/**
Register basic commands on the commands list for non-root users
@retval a return code from called functions
**/
EFI_STATUS
RegisterNonAdminUserCommands(
)
{
EFI_STATUS Rc;
NVDIMM_ENTRY();
Rc = RegisterCommand(&VersionCommand);
NVDIMM_EXIT_I64(Rc);
return Rc;
}
/**
Register commands on the commands list
@retval a return code from called functions
**/
EFI_STATUS
RegisterCommands(
)
{
EFI_STATUS Rc;
NVDIMM_ENTRY();
/* Always register */
Rc = RegisterCommand(&HelpCommand);
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterNonAdminUserCommands();
if (EFI_ERROR(Rc)) {
goto done;
}
// Dimm Discovery Commands
Rc = RegisterShowTopologyCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterShowSocketsCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterShowDimmsCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterShowMemoryResourcesCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterShowSystemCapabilitiesCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
// Provisioning Commands
Rc = RegisterCreateGoalCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterShowGoalCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterDumpGoalCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterLoadGoalCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterDeleteGoalCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
// Security Commands
Rc = RegisterSetDimmCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
#ifndef OS_BUILD
Rc = RegisterDeleteDimmCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
#endif
// Persistent Memory Provisioning Commands
Rc = RegisterShowRegionsCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
#ifndef OS_BUILD
Rc = RegisterShowNamespaceCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterCreateNamespaceCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterDeleteNamespaceCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
#endif
// Instrumentation Commands
Rc = RegisterShowSensorCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterSetSensorCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
#ifndef __MFG__
// Mfg has a low latency version of this command in RegisterMfgCommands()
Rc = RegisterShowPerformanceCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
#endif // !__MFG__
#ifdef OS_BUILD
#ifdef __MFG__
Rc = RegisterMfgCommands();
if (EFI_ERROR(Rc)) {
goto done;
}
#endif // __MFG__
#endif // OS_BUILD
// Support and Maintenance Commands
Rc = RegisterShowFirmwareCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterLoadCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterShowPreferencesCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterSetPreferencesCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
#ifdef OS_BUILD
Rc = RegisterDumpSupportCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
#endif // OS_BUILD
// Debug Commands
Rc = RegisterStartDiagnosticCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterShowErrorCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterDumpDebugCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterShowAcpiCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterShowPcdCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterDeletePcdCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterShowCmdAccessPolicyCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterShowCelCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
#ifndef OS_BUILD
/* Debug Utility commands */
Rc = registerShowSmbiosCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
#ifndef MDEPKG_NDEBUG
Rc = RegisterShowRegisterCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
#endif
#ifdef FORMAT_SUPPORTED
Rc = RegisterStartFormatCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
#endif
#endif
// PBR Commands
Rc = RegisterStartSessionCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterDumpSessionCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterLoadSessionCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterShowSessionCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
Rc = RegisterStopSessionCommand();
if (EFI_ERROR(Rc)) {
goto done;
}
done:
NVDIMM_EXIT_I64(Rc);
return Rc;
}
/*
* Print the CLI application help
*/
EFI_STATUS showHelp(struct Command *pCmd)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
CHAR16 *pHelp = NULL;
PRINT_CONTEXT *pPrinterCtx = NULL;
#ifdef OS_BUILD
UINT8 Index = 0;
BOOLEAN FormatAsESXErrorMsg = FALSE;
#endif
NVDIMM_ENTRY();
if (NULL != pCmd) {
pPrinterCtx = pCmd->pPrintCtx;
}
if ((pCmd == NULL) || (StrCmp(pCmd->verb, HELP_VERB) == 0 && pCmd->ShowHelp == FALSE)) {
#ifndef OS_BUILD
//Page break option only for UEFI
ShellSetPageBreakMode(TRUE);
#endif
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_SPACE FORMAT_STR_NL_NL L" Usage: " FORMAT_STR L" [][][]\n\nCommands:\n", PRODUCT_NAME, APP_DESCRIPTION, EXE_NAME);
pHelp = getOverallCommandHelp();
} else {
pHelp = getCommandHelp(pCmd, TRUE);
}
if (pHelp != NULL) {
#ifdef OS_BUILD
if (pPrinterCtx != NULL) {
#endif
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, pHelp);
#ifdef OS_BUILD
}
else {
// if Printer is not setup then may need to do special handling for ESX
if ((pPrinterCtx == NULL) &&
(pCmd != NULL) &&
(pCmd->options != NULL)) {
for (Index = 0; Index < MAX_OPTIONS; Index++) {
if ((StrICmp(pCmd->options[Index].OptionName, OUTPUT_OPTION) == 0) ||
(StrICmp(pCmd->options[Index].OptionNameShort, OUTPUT_OPTION_SHORT) == 0)) {
if ((StrICmp(pCmd->options[Index].pOptionValueStr, OUTPUT_OPTION_ESX_XML) == 0) ||
(StrICmp(pCmd->options[Index].pOptionValueStr, OUTPUT_OPTION_ESX_TABLE_XML) == 0)) {
FormatAsESXErrorMsg = TRUE;
break;
}
}
}
}
// Only do alternative output if for ESX to be sure not to change output for others
if (FormatAsESXErrorMsg) {
PrintErrorMsg(pHelp, FormatAsESXErrorMsg);
}
else
{
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, pHelp);
}
}
#endif
FreePool(pHelp);
}
if (NULL != pPrinterCtx) {
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
}
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
#define DS_ROOT_PATH L"/SoftwareList"
#define DS_SOFTWARE_PATH L"/SoftwareList/Software"
#define DS_SOFTWARE_INDEX_PATH L"/SoftwareList/Software[%d]"
PRINTER_LIST_ATTRIB ShowVersionListAttributes =
{
{
{
L"Software", //GROUP LEVEL TYPE
L"$(Component) Version $(Version)", //NULL or GROUP LEVEL HEADER
NULL, //NULL or KEY VAL FORMAT STR
L"Component;Version" //NULL or IGNORE KEY LIST (K1;K2)
}
}
};
PRINTER_DATA_SET_ATTRIBS ShowVersionDataSetAttribs =
{
&ShowVersionListAttributes,
NULL
};
/*
* Set a PBR session tag
*/
EFI_STATUS SetPbrTag(CHAR16 *pName, CHAR16 *pDescription) {
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_DCPMM_PBR_PROTOCOL *pNvmDimmPbrProtocol = NULL;
ReturnCode = OpenNvmDimmProtocol(gNvmDimmPbrProtocolGuid, (VOID **)&pNvmDimmPbrProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
Print(CLI_ERR_OPENING_PBR_PROTOCOL);
goto Finish;
}
ReturnCode = pNvmDimmPbrProtocol->PbrSetTag(PBR_DCPMM_CLI_SIG, pName, pDescription, NULL);
if (EFI_ERROR(ReturnCode)) {
Print(CLI_ERR_FAILED_TO_SET_SESSION_TAG);
goto Finish;
}
Finish:
return ReturnCode;
}
/*
* Get the current PBR session mode (playback/record)
*/
EFI_STATUS GetPbrMode(UINT32 *Mode) {
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_DCPMM_PBR_PROTOCOL *pNvmDimmPbrProtocol = NULL;
*Mode = PBR_NORMAL_MODE;
ReturnCode = OpenNvmDimmProtocol(gNvmDimmPbrProtocolGuid, (VOID **)&pNvmDimmPbrProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
NVDIMM_DBG("Failed to open the PBR protocol, error = " FORMAT_EFI_STATUS, ReturnCode);
goto Finish;
}
ReturnCode = pNvmDimmPbrProtocol->PbrGetMode(Mode);
if (EFI_ERROR(ReturnCode)) {
Print(CLI_ERR_FAILED_TO_GET_PBR_MODE);
goto Finish;
}
Finish:
return ReturnCode;
}
/*
* Reset the session to a specified tag
*/
EFI_STATUS ResetPbrSession(UINT32 TagId) {
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_DCPMM_PBR_PROTOCOL *pNvmDimmPbrProtocol = NULL;
ReturnCode = OpenNvmDimmProtocol(gNvmDimmPbrProtocolGuid, (VOID **)&pNvmDimmPbrProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
Print(CLI_ERR_OPENING_PBR_PROTOCOL);
goto Finish;
}
ReturnCode = pNvmDimmPbrProtocol->PbrResetSession(TagId);
if (EFI_ERROR(ReturnCode)) {
Print(CLI_ERR_FAILED_TO_SET_SESSION_TAG);
goto Finish;
}
Finish:
return ReturnCode;
}
/*
* Print the CLI app version
*/
EFI_STATUS showVersion(struct Command *pCmd)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
CHAR16 *pPath = NULL;
UINT32 DimmIndex = 0;
UINT32 DimmCount = 0;
PRINT_CONTEXT *pPrinterCtx = NULL;
DIMM_INFO *pDimms = NULL;
UINT32 DimmFromTheFutureCount = 0;
CHAR16 DimmStr[MAX_DIMM_UID_LENGTH];
#if !defined(__LINUX__)
CHAR16 ApiVersion[FW_API_VERSION_LEN] = { 0 };
#endif
NVDIMM_ENTRY();
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("pCmd parameter is NULL.\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (ReturnCode != EFI_NOT_FOUND && EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
if (ReturnCode != EFI_NOT_FOUND) {
#if !defined(__LINUX__)
ReturnCode = pNvmDimmConfigProtocol->GetDriverApiVersion(pNvmDimmConfigProtocol, ApiVersion);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
#endif
}
PRINTER_BUILD_KEY_PATH(pPath, DS_SOFTWARE_INDEX_PATH, 0);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, L"Component", PRODUCT_NAME L" " APP_DESCRIPTION);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, L"Version", NVMDIMM_VERSION_STRING);
#if !defined(__LINUX__)
PRINTER_BUILD_KEY_PATH(pPath, DS_SOFTWARE_INDEX_PATH, 1);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, L"Component", PRODUCT_NAME L" " DRIVER_API_DESCRIPTION);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, L"Version", ApiVersion);
#endif
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
/*Check FIS against compiled version in this SW... warn if the FIS version from FW is > version from this SW*/
ReturnCode = pNvmDimmConfigProtocol->GetDimmCount(pNvmDimmConfigProtocol, &DimmCount);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
pDimms = AllocateZeroPool(sizeof(*pDimms) * DimmCount);
if (NULL == pDimms) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
ReturnCode = pNvmDimmConfigProtocol->GetDimms(pNvmDimmConfigProtocol, DimmCount,
DIMM_INFO_CATEGORY_ALL, pDimms);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_ABORTED;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
NVDIMM_WARN("Failed to retrieve the DCPMM inventory found in NFIT");
goto Finish;
}
for (DimmIndex = 0; DimmIndex < DimmCount; DimmIndex++) {
ReturnCode = GetPreferredDimmIdAsString(pDimms[DimmIndex].DimmHandle, pDimms[DimmIndex].DimmUid, DimmStr, MAX_DIMM_UID_LENGTH);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_ABORTED;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"Failed to determine DimmId for " PMEM_MODULE_STR L"%d", pDimms[DimmIndex].DimmHandle);
goto Finish;
}
if (pDimms[DimmIndex].FwVer.FwApiMajor > MAX_FIS_SUPPORTED_BY_THIS_SW_MAJOR ||
(pDimms[DimmIndex].FwVer.FwApiMajor == MAX_FIS_SUPPORTED_BY_THIS_SW_MAJOR &&
pDimms[DimmIndex].FwVer.FwApiMinor > MAX_FIS_SUPPORTED_BY_THIS_SW_MINOR)) {
DimmFromTheFutureCount++;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, PMEM_MODULE_STR L" " FORMAT_STR L" supports FIS %d.%d\r\n",
DimmStr,
pDimms[DimmIndex].FwVer.FwApiMajor,
pDimms[DimmIndex].FwVer.FwApiMinor);
}
}
if (DimmFromTheFutureCount > 0) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"This ipmctl software version predates the firmware interface specification version (FIS | FWAPIVersion: %d.%d) for %d " PMEM_MODULE_STR L"(s). It is recommended to update ipmctl.\r\n",
MAX_FIS_SUPPORTED_BY_THIS_SW_MAJOR,
MAX_FIS_SUPPORTED_BY_THIS_SW_MINOR,
DimmFromTheFutureCount);
}
//Specify table attributes
PRINTER_CONFIGURE_DATA_ATTRIBUTES(pPrinterCtx, DS_ROOT_PATH, &ShowVersionDataSetAttribs);
//Force as list
PRINTER_ENABLE_LIST_TABLE_FORMAT(pPrinterCtx);
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FREE_POOL_SAFE(pPath);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
EFI_STATUS SetDefaultProtocolAndPayloadSizeOptions()
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
EFI_DCPMM_CONFIG_TRANSPORT_ATTRIBS Attribs;
#ifdef OS_BUILD
// Default value for ini file (OS only) is set in ipmctl_default.h
BOOLEAN IsDdrtProtocolDisabled = ConfigIsDdrtProtocolDisabled();
BOOLEAN IsLargePayloadDisabled = ConfigIsLargePayloadDisabled();
#endif // OS_BUILD
NVDIMM_ENTRY();
// Clearly set defaults. Auto = no restrictions
Attribs.Protocol = FisTransportAuto;
Attribs.PayloadSize = FisTransportSizeAuto;
#ifdef OS_BUILD
// Equivalent to passing "-smbus"
if (IsDdrtProtocolDisabled) {
Attribs.Protocol = FisTransportSmbus;
Attribs.PayloadSize = FisTransportSizeSmallMb;
}
if (IsLargePayloadDisabled) {
Attribs.PayloadSize = FisTransportSizeSmallMb;
}
#endif // OS_BUILD
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
CHECK_RESULT(pNvmDimmConfigProtocol->SetFisTransportAttributes(pNvmDimmConfigProtocol, Attribs), Finish);
Finish:
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
#ifndef OS_BUILD
#ifndef MDEPKG_NDEBUG
EFI_STATUS GetDriverDebugPrintVerbosity(UINT32 *pErrorLevel)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
NVDIMM_ENTRY();
if (NULL == pErrorLevel) {
NVDIMM_DBG("Input parameter is NULL");
goto Finish;
}
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
CHECK_RESULT(pNvmDimmConfigProtocol->GetDriverDebugPrintErrorLevel(pNvmDimmConfigProtocol, pErrorLevel), Finish);
Finish:
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
EFI_STATUS SetDriverDebugPrintVerbosity(UINT32 ErrorLevel)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
NVDIMM_ENTRY();
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
CHECK_RESULT(pNvmDimmConfigProtocol->SetDriverDebugPrintErrorLevel(pNvmDimmConfigProtocol, ErrorLevel), Finish);
Finish:
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
#endif //MDEPKG_NDEBUG
#endif //OS_BUILD
ipmctl-03.00.00.0423/DcpmPkg/cli/NvmDimmCli.h 0000664 0000000 0000000 00000002246 14165347476 0020102 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#if defined(__LINUX__) || defined(__ESX__)
#define EXE_NAME L"ipmctl"
#elif defined(_MSC_VER) && defined(OS_BUILD)
#define EXE_NAME L"ipmctl.exe"
#else
#define EXE_NAME L"ipmctl.efi"
#endif
#define APP_DESCRIPTION L"Command Line Interface"
#define DRIVER_API_DESCRIPTION L"Driver API"
extern EFI_HANDLE gNvmDimmCliHiiHandle;
//
// This is the generated String package data for all .UNI files.
// This data array is ready to be used as input of HiiAddPackages() to
// create a package list (which contains Form packages, String packages, etc).
//
extern unsigned char ipmctlStrings[];
extern int g_basic_commands;
/**
Register commands on the commands list
@retval a return code from called functions
**/
EFI_STATUS
RegisterCommands(
);
/**
Register basic commands on the commands list for non-root users
@retval a return code from called functions
**/
EFI_STATUS
RegisterNonAdminUserCommands(
);
/**
Print the CLI application help
**/
EFI_STATUS showHelp(struct Command *pCmd);
ipmctl-03.00.00.0423/DcpmPkg/cli/SetDimmCommand.c 0000664 0000000 0000000 00000104527 14165347476 0020744 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "SetDimmCommand.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include "Common.h"
CONST CHAR16 *pPoisonMemoryTypeStr[POISON_MEMORY_TYPE_COUNT] = {
L"MemoryMode",
L"AppDirect",
L"NotDefined",
L"PatrolScrub"
};
/** Command syntax definition **/
struct Command SetDimmCommand =
{
SET_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"",HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{FORCE_OPTION_SHORT, FORCE_OPTION, L"", L"",HELP_FORCE_DETAILS_TEXT, FALSE, ValueEmpty},
#ifndef OS_BUILD
{L"", SOURCE_OPTION, L"", SOURCE_OPTION_HELP, L"Source of the Passphrase file",FALSE, ValueRequired},
{L"", MASTER_OPTION, L"", L"",L"Set Master Passphrase", FALSE, ValueEmpty},
#endif
{L"", DEFAULT_OPTION, L"", L"",L"Set Default Settings", FALSE, ValueEmpty}
#ifdef OS_BUILD
,{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP, HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#endif
},
{{DIMM_TARGET, L"", HELP_TEXT_DIMM_IDS, TRUE, ValueOptional}}, //!< targets
{
{CLEAR_ERROR_INJ_PROPERTY, L"", PROPERTY_VALUE_1, FALSE, ValueRequired},
{TEMPERATURE_INJ_PROPERTY, L"", HELP_TEXT_VALUE, FALSE, ValueRequired },
{POISON_INJ_PROPERTY, L"", HELP_TEXT_VALUE, FALSE, ValueRequired },
{POISON_TYPE_INJ_PROPERTY, L"", HELP_TEXT_VALUE, FALSE, ValueRequired},
{PACKAGE_SPARING_INJ_PROPERTY, L"", PROPERTY_VALUE_1, FALSE, ValueRequired },
{PERCENTAGE_REMAINING_INJ_PROPERTY, L"", HELP_TEXT_PERCENT, FALSE, ValueRequired},
{FATAL_MEDIA_ERROR_INJ_PROPERTY, L"", PROPERTY_VALUE_1, FALSE, ValueRequired},
{DIRTY_SHUTDOWN_ERROR_INJ_PROPERTY, L"", PROPERTY_VALUE_1, FALSE, ValueRequired},
#ifndef OS_BUILD
{LOCKSTATE_PROPERTY, L"", LOCKSTATE_VALUE_DISABLED L"|" LOCKSTATE_VALUE_UNLOCKED L"|" LOCKSTATE_VALUE_FROZEN, FALSE, ValueRequired},
{PASSPHRASE_PROPERTY, L"", HELP_TEXT_STRING, FALSE, ValueOptional},
{NEWPASSPHRASE_PROPERTY, L"", HELP_TEXT_STRING, FALSE, ValueOptional},
{CONFIRMPASSPHRASE_PROPERTY, L"", HELP_TEXT_STRING, FALSE, ValueOptional},
#endif
{AVG_PWR_REPORTING_TIME_CONSTANT, L"", HELP_TEXT_AVG_PWR_REPORTING_TIME_CONSTANT_PROPERTY, FALSE, ValueRequired}
}, //!< properties
#ifndef OS_BUILD
L"Set properties of one or more " PMEM_MODULES_STR L", such as device security and modify device.", //!< help
#else
L"Set properties of one or more " PMEM_MODULES_STR L", such as modify device.", //!< help
#endif
SetDimm,
TRUE
};
CHAR16* GetCorrectClearMessageBasedOnProperty(UINT16 ErrorInjectType) {
CHAR16 *ClearOutputPropertyString = NULL;
switch(ErrorInjectType) {
case ERROR_INJ_POISON:
ClearOutputPropertyString = CLI_INFO_CLEAR_POISON_INJECT_ERROR;
break;
case ERROR_INJ_TEMPERATURE:
ClearOutputPropertyString = CLI_INFO_CLEAR_TEMPERATURE_INJECT_ERROR;
break;
case ERROR_INJ_PACKAGE_SPARING:
ClearOutputPropertyString = CLI_INFO_CLEAR_PACKAGE_SPARING_INJECT_ERROR;
break;
case ERROR_INJ_PERCENTAGE_REMAINING:
ClearOutputPropertyString = CLI_INFO_CLEAR_PERCENTAGE_REMAINING_INJECT_ERROR;
break;
case ERROR_INJ_FATAL_MEDIA_ERR:
ClearOutputPropertyString = CLI_INFO_CLEAR_FATAL_MEDIA_ERROR_INJECT_ERROR;
break;
case ERROR_INJ_DIRTY_SHUTDOWN:
ClearOutputPropertyString = CLI_INFO_CLEAR_DIRTY_SHUT_DOWN_INJECT_ERROR;
break;
}
return ClearOutputPropertyString;
}
/**
Execute the set dimm command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
SetDimm(
IN struct Command *pCmd
)
{
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
CHAR16 *pLockStatePropertyValue = NULL;
CHAR16 *pPassphrase = NULL;
CHAR16 *pNewPassphrase = NULL;
CHAR16 *pConfirmPassphrase = NULL;
CHAR16 *pPassphraseStatic = NULL;
CHAR16 *pNewPassphraseStatic = NULL;
CHAR16 *pConfirmPassphraseStatic = NULL;
CHAR16 *pAvgPowerReportingTimeConstantValue = NULL;
BOOLEAN IsNumber = FALSE;
UINT64 ParsedNumber = 0;
UINT32 *pAvgPowerReportingTimeConstant = NULL;
CHAR16 *pTargetValue = NULL;
CHAR16 *pLoadUserPath = NULL;
CHAR16 *pLoadFilePath = NULL;
CHAR16 *pErrorMessage = NULL;
UINT16 SecurityOperation = SECURITY_OPERATION_UNDEFINED;
UINT16 *pDimmIds = NULL;
UINT32 DimmHandle = 0;
UINT32 DimmIndex = 0;
UINT32 DimmIdsCount = 0;
UINT32 Index = 0;
EFI_DEVICE_PATH_PROTOCOL *pDevicePathProtocol = NULL;
COMMAND_STATUS *pCommandStatus = NULL;
CHAR16 *pCommandStatusMessage = NULL;
CHAR16 *pCommandStatusPreposition = NULL;
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
BOOLEAN ActionSpecified = FALSE;
BOOLEAN OneOfPassphrasesIsEmpty = FALSE;
BOOLEAN OneOfPassphrasesIsNotEmpty = FALSE;
BOOLEAN LockStateFrozen = FALSE;
BOOLEAN Force = FALSE;
BOOLEAN Confirmation = FALSE;
DIMM_INFO *pDimms = NULL;
UINT32 DimmCount = 0;
CHAR16 DimmStr[MAX_DIMM_UID_LENGTH];
PRINT_CONTEXT *pPrinterCtx = NULL;
BOOLEAN MasterOptionSpecified = FALSE;
BOOLEAN DefaultOptionSpecified = FALSE;
/*Inject error*/
CHAR16 *pTemperature = NULL;
CHAR16 *pPoisonAddress = NULL;
CHAR16 *pPoisonType = NULL;
CHAR16 *pPackageSparing = NULL;
CHAR16 *pPercentageRemaining = NULL;
CHAR16 *pFatalMediaError = NULL;
CHAR16 *pDirtyShutDown = NULL;
CHAR16 *pClearErrorInj = NULL;
UINT16 ErrInjectType = ERROR_INJ_TYPE_INVALID;
UINT64 TemperatureValue = 0;
UINT64 PoisonAddressValue = 0;
UINT64 PercentageRemainingValue = 0;
UINT64 PoisonTypeValue = POISON_MEMORY_TYPE_PATROLSCRUB;
UINT64 ErrorInjectionTypeSet = 0;
UINT64 PoisonTypeValid = 0;
UINT64 ClearStatus = 0;
UINT64 FatalMediaError = 0;
UINT64 PackageSparing = 0;
UINT64 DirtyShutDown = 0;
NVDIMM_ENTRY();
ZeroMem(DimmStr, sizeof(DimmStr));
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("pCmd parameter is NULL.\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// Populate the list of DIMM_INFO structures with relevant information
ReturnCode = GetAllDimmList(pNvmDimmConfigProtocol, pCmd, DIMM_INFO_CATEGORY_SECURITY, &pDimms, &DimmCount);
if (EFI_ERROR(ReturnCode)) {
if(ReturnCode == EFI_NOT_FOUND) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_INFO_NO_FUNCTIONAL_DIMMS);
}
goto Finish;
}
// initialize status structure
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode) || pCommandStatus == NULL) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
NVDIMM_DBG("Failed on InitializeCommandStatus");
goto Finish;
}
// check targets
if (ContainTarget(pCmd, DIMM_TARGET)) {
pTargetValue = GetTargetValue(pCmd, DIMM_TARGET);
ReturnCode = GetDimmIdsFromString(pCmd, pTargetValue, pDimms, DimmCount, &pDimmIds, &DimmIdsCount);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("Failed on GetDimmIdsFromString");
goto Finish;
}
if (!AllDimmsInListAreManageable(pDimms, DimmCount, pDimmIds, DimmIdsCount)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_UNMANAGEABLE_DIMM);
goto Finish;
}
}
/** If no dimm IDs are specified get IDs from all dimms **/
if (DimmIdsCount == 0) {
ReturnCode = GetAllManageableDimmsNumberAndId(pNvmDimmConfigProtocol, FALSE, &DimmIdsCount, &pDimmIds);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
if (DimmIdsCount == 0) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_INFO_NO_MANAGEABLE_DIMMS);
goto Finish;
}
}
/** Check master option **/
MasterOptionSpecified = containsOption(pCmd, MASTER_OPTION);
/** Check default option **/
DefaultOptionSpecified = containsOption(pCmd, DEFAULT_OPTION);
/** Check force option **/
if (containsOption(pCmd, FORCE_OPTION) || containsOption(pCmd, FORCE_OPTION_SHORT)) {
Force = TRUE;
}
/**
This command allows for different property sets depending on what action is to be taken.
Here we check if input contains properties from different actions because they are not
allowed together.
**/
if (!EFI_ERROR(ContainsProperty(pCmd, AVG_PWR_REPORTING_TIME_CONSTANT))) {
ActionSpecified = TRUE;
}
if (containsOption(pCmd, SOURCE_OPTION) ||
!EFI_ERROR(ContainsProperty(pCmd, PASSPHRASE_PROPERTY)) ||
!EFI_ERROR(ContainsProperty(pCmd, NEWPASSPHRASE_PROPERTY)) ||
!EFI_ERROR(ContainsProperty(pCmd, CONFIRMPASSPHRASE_PROPERTY)) ||
!EFI_ERROR(ContainsProperty(pCmd, LOCKSTATE_PROPERTY))
) {
if (ActionSpecified) {
/** We already found a specified action, more are not allowed **/
ReturnCode = EFI_INVALID_PARAMETER;
} else {
/** Found specified action **/
ActionSpecified = TRUE;
}
}
if (!EFI_ERROR(ContainsProperty(pCmd, TEMPERATURE_INJ_PROPERTY))) {
if (ActionSpecified) {
/** We already found a specified action, more are not allowed **/
ReturnCode = EFI_INVALID_PARAMETER;
} else {
/** Found specified action **/
ActionSpecified = TRUE;
ErrorInjectionTypeSet = 1;
}
}
if (!EFI_ERROR(ContainsProperty(pCmd, POISON_INJ_PROPERTY))) {
if (ActionSpecified) {
/** We already found a specified action, more are not allowed **/
ReturnCode = EFI_INVALID_PARAMETER;
} else {
/** Found specified action **/
ActionSpecified = TRUE;
ErrorInjectionTypeSet = 1;
}
}
/*If there is poison type property then there should be poison address property */
if (!EFI_ERROR(ContainsProperty(pCmd, POISON_TYPE_INJ_PROPERTY))) {
GetPropertyValue(pCmd, POISON_INJ_PROPERTY, &pPoisonAddress);
if ((ActionSpecified && pPoisonAddress == NULL) || !ActionSpecified) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERROR_POISON_TYPE_WITHOUT_ADDRESS);
goto Finish;
}
}
if (!EFI_ERROR(ContainsProperty(pCmd, PACKAGE_SPARING_INJ_PROPERTY))) {
if (ActionSpecified) {
/** We already found a specified action, more are not allowed **/
ReturnCode = EFI_INVALID_PARAMETER;
} else {
/** Found specified action **/
ActionSpecified = TRUE;
ErrorInjectionTypeSet = 1;
}
}
if (!EFI_ERROR(ContainsProperty(pCmd, PERCENTAGE_REMAINING_INJ_PROPERTY))) {
if (ActionSpecified) {
/** We already found a specified action, more are not allowed **/
ReturnCode = EFI_INVALID_PARAMETER;
} else {
/** Found specified action **/
ActionSpecified = TRUE;
ErrorInjectionTypeSet = 1;
}
}
if (!EFI_ERROR(ContainsProperty(pCmd, FATAL_MEDIA_ERROR_INJ_PROPERTY))) {
if (ActionSpecified) {
/** We already found a specified action, more are not allowed **/
ReturnCode = EFI_INVALID_PARAMETER;
} else {
/** Found specified action **/
ActionSpecified = TRUE;
ErrorInjectionTypeSet = 1;
}
}
if (!EFI_ERROR(ContainsProperty(pCmd, DIRTY_SHUTDOWN_ERROR_INJ_PROPERTY))) {
if (ActionSpecified) {
/** We already found a specified action, more are not allowed **/
ReturnCode = EFI_INVALID_PARAMETER;
} else {
/** Found specified action **/
ActionSpecified = TRUE;
ErrorInjectionTypeSet = 1;
}
}
/*Clear error injection requires exactly one error injection type being set*/
if (!EFI_ERROR(ContainsProperty(pCmd, CLEAR_ERROR_INJ_PROPERTY))) {
if ((ActionSpecified && !ErrorInjectionTypeSet) || !ActionSpecified) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERROR_CLEAR_PROPERTY_NOT_COMBINED);
goto Finish;
}
}
/** Syntax error - mixed properties from different set -dimm commands **/
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_UNSUPPORTED_COMMAND_SYNTAX);
goto Finish;
}
/** Syntax error - no properties specified. **/
if (!ActionSpecified) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCOMPLETE_SYNTAX);
goto Finish;
}
/**
Set Security State
**/
GetPropertyValue(pCmd, LOCKSTATE_PROPERTY, &pLockStatePropertyValue);
GetPropertyValue(pCmd, PASSPHRASE_PROPERTY, &pPassphraseStatic);
GetPropertyValue(pCmd, NEWPASSPHRASE_PROPERTY, &pNewPassphraseStatic);
GetPropertyValue(pCmd, CONFIRMPASSPHRASE_PROPERTY, &pConfirmPassphraseStatic);
if (MasterOptionSpecified) {
// DefaultOptionSpecified = Ignore Master Passphrase enabled check only when changing the master passphrase from the default on FIS >= 3.2 PMem modules
if (!AllDimmsInListHaveMasterPassphraseEnabled(pDimms, DimmCount, pDimmIds, DimmIdsCount, DefaultOptionSpecified)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_MASTER_PASSPHRASE_NOT_ENABLED);
goto Finish;
}
}
pLoadFilePath = AllocateZeroPool(OPTION_VALUE_LEN * sizeof(*pLoadFilePath));
if (pLoadFilePath == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
if (pLockStatePropertyValue != NULL ||
pPassphraseStatic != NULL ||
pNewPassphraseStatic != NULL ||
pConfirmPassphraseStatic != NULL ||
containsOption(pCmd, SOURCE_OPTION)) {
LockStateFrozen = (pLockStatePropertyValue != NULL &&
(StrICmp(pLockStatePropertyValue, LOCKSTATE_VALUE_FROZEN) == 0));
if (pLockStatePropertyValue == NULL && pPassphraseStatic == NULL && pNewPassphraseStatic != NULL &&
pConfirmPassphraseStatic != NULL) { // Passphrase not provided
ReturnCode = CheckMasterAndDefaultOptions(pCmd, FALSE, MasterOptionSpecified, DefaultOptionSpecified);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
if (MasterOptionSpecified) {
pPassphrase = CatSPrint(NULL, L"");
SecurityOperation = SECURITY_OPERATION_CHANGE_MASTER_PASSPHRASE;
pCommandStatusMessage = CatSPrint(NULL, FORMAT_STR, L"Change master passphrase");
}
else {
SecurityOperation = SECURITY_OPERATION_SET_PASSPHRASE;
pCommandStatusMessage = CatSPrint(NULL, FORMAT_STR, L"Set passphrase");
}
pCommandStatusPreposition = CatSPrint(NULL, FORMAT_STR, L" on");
} else if (pLockStatePropertyValue == NULL && pPassphraseStatic != NULL && pNewPassphraseStatic != NULL &&
pConfirmPassphraseStatic != NULL) { // Passphrase provided
ReturnCode = CheckMasterAndDefaultOptions(pCmd, TRUE, MasterOptionSpecified, DefaultOptionSpecified);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
if (MasterOptionSpecified) {
SecurityOperation = SECURITY_OPERATION_CHANGE_MASTER_PASSPHRASE;
pCommandStatusMessage = CatSPrint(NULL, FORMAT_STR, L"Change master passphrase");
}
else {
SecurityOperation = SECURITY_OPERATION_CHANGE_PASSPHRASE;
pCommandStatusMessage = CatSPrint(NULL, FORMAT_STR, L"Change passphrase");
}
pCommandStatusPreposition = CatSPrint(NULL, FORMAT_STR, L" on");
} else if (pLockStatePropertyValue != NULL && pNewPassphraseStatic != NULL &&
((StrICmp(pLockStatePropertyValue, LOCKSTATE_VALUE_DISABLED) == 0) ||
(StrICmp(pLockStatePropertyValue, LOCKSTATE_VALUE_UNLOCKED) == 0) ||
(StrICmp(pLockStatePropertyValue, LOCKSTATE_VALUE_FROZEN) == 0))) {
pErrorMessage = CatSPrint(NULL, CLI_PARSER_ERR_UNEXPECTED_TOKEN, L"NewPassphrase=");
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR, pErrorMessage);
goto Finish;
} else if (pLockStatePropertyValue != NULL && pConfirmPassphraseStatic != NULL &&
((StrICmp(pLockStatePropertyValue, LOCKSTATE_VALUE_DISABLED) == 0) ||
(StrICmp(pLockStatePropertyValue, LOCKSTATE_VALUE_UNLOCKED) == 0) ||
(StrICmp(pLockStatePropertyValue, LOCKSTATE_VALUE_FROZEN) == 0))) {
pErrorMessage = CatSPrint(NULL, CLI_PARSER_ERR_UNEXPECTED_TOKEN, L"ConfirmPassphrase=");
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR, pErrorMessage);
goto Finish;
} else if (pLockStatePropertyValue != NULL && pPassphraseStatic != NULL &&
(StrICmp(pLockStatePropertyValue, LOCKSTATE_VALUE_DISABLED) == 0)) {
SecurityOperation = SECURITY_OPERATION_DISABLE_PASSPHRASE;
pCommandStatusMessage = CatSPrint(NULL, FORMAT_STR, L"Remove passphrase");
pCommandStatusPreposition = CatSPrint(NULL, FORMAT_STR, L" from");
} else if (pLockStatePropertyValue != NULL && pPassphraseStatic != NULL &&
(StrICmp(pLockStatePropertyValue, LOCKSTATE_VALUE_UNLOCKED) == 0)) {
SecurityOperation = SECURITY_OPERATION_UNLOCK_DEVICE;
pCommandStatusMessage = CatSPrint(NULL, FORMAT_STR, L"Unlock");
pCommandStatusPreposition = CatSPrint(NULL, FORMAT_STR, L"");
} else if (LockStateFrozen) {
SecurityOperation = SECURITY_OPERATION_FREEZE_DEVICE;
pCommandStatusMessage = CatSPrint(NULL, FORMAT_STR, L"Freeze lock");
pCommandStatusPreposition = CatSPrint(NULL, FORMAT_STR, L"");
} else {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCOMPLETE_SYNTAX);
goto Finish;
}
OneOfPassphrasesIsEmpty = ((pPassphraseStatic != NULL && StrCmp(pPassphraseStatic, L"") == 0) ||
(pNewPassphraseStatic != NULL && StrCmp(pNewPassphraseStatic, L"") == 0) ||
(pConfirmPassphraseStatic != NULL && StrCmp(pConfirmPassphraseStatic, L"") == 0));
OneOfPassphrasesIsNotEmpty = ((pPassphraseStatic != NULL && StrCmp(pPassphraseStatic, L"") != 0) ||
(pNewPassphraseStatic != NULL && StrCmp(pNewPassphraseStatic, L"") != 0) ||
(pConfirmPassphraseStatic != NULL && StrCmp(pConfirmPassphraseStatic, L"") != 0));
// Check -source option
if (containsOption(pCmd, SOURCE_OPTION) && !LockStateFrozen) {
if (OneOfPassphrasesIsNotEmpty) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_UNSUPPORTED_COMMAND_SYNTAX);
goto Finish;
}
pLoadUserPath = getOptionValue(pCmd, SOURCE_OPTION);
if (pLoadUserPath == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
NVDIMM_ERR("Could not get -source value. Out of memory");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
ReturnCode = GetDeviceAndFilePath(pLoadUserPath, pLoadFilePath, &pDevicePathProtocol);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Failed to get file path (" FORMAT_EFI_STATUS ")", ReturnCode);
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_WRONG_FILE_PATH);
goto Finish;
}
ReturnCode = ParseSourcePassFile(pCmd, pLoadFilePath, pDevicePathProtocol, &pPassphrase, &pNewPassphrase);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("ParseSourcePassFile failed (" FORMAT_EFI_STATUS ")", ReturnCode);
goto Finish;
}
// Check if required passwords have been found in the file
if ((pPassphrase == NULL && pPassphraseStatic != NULL) ||
(pNewPassphrase == NULL && pNewPassphraseStatic != NULL)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_WRONG_FILE_DATA);
goto Finish;
// NewPassphrase and ConfirmPassphrase occur together
} else if (pNewPassphrase != NULL) {
pConfirmPassphrase = CatSPrint(NULL, FORMAT_STR, pNewPassphrase);
}
// Check prompts
} else {
if (OneOfPassphrasesIsEmpty && OneOfPassphrasesIsNotEmpty) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_UNSUPPORTED_COMMAND_SYNTAX);
goto Finish;
}
// Check prompt request Passphrase
if (pPassphraseStatic != NULL && StrCmp(pPassphraseStatic, L"") == 0) {
ReturnCode = PromptedInput(L"Enter passphrase:\n", FALSE, FALSE, &pPassphrase);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_PROMPT_INVALID);
NVDIMM_DBG("Failed on PromptedInput");
goto Finish;
}
} else if (pPassphraseStatic != NULL) {
pPassphrase = CatSPrint(NULL, FORMAT_STR, pPassphraseStatic);
}
// Check prompt request NewPassphrase
if (pNewPassphraseStatic != NULL && StrCmp(pNewPassphraseStatic, L"") == 0) {
ReturnCode = PromptedInput(L"Enter new passphrase:", FALSE, FALSE, &pNewPassphrase);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_PROMPT_INVALID);
NVDIMM_DBG("Failed on PromptedInput");
goto Finish;
}
} else if (pNewPassphraseStatic != NULL) {
pNewPassphrase = CatSPrint(NULL, FORMAT_STR, pNewPassphraseStatic);
}
// Check prompt request ConfirmPassphrase
if (pConfirmPassphraseStatic != NULL && StrCmp(pConfirmPassphraseStatic, L"") == 0) {
ReturnCode = PromptedInput(L"Confirm passphrase:", FALSE, FALSE, &pConfirmPassphrase);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_PROMPT_INVALID);
NVDIMM_DBG("Failed on PromptedInput");
goto Finish;
}
} else if (pConfirmPassphraseStatic != NULL) {
pConfirmPassphrase = CatSPrint(NULL, FORMAT_STR, pConfirmPassphraseStatic);
}
}
if (pLockStatePropertyValue == NULL && pNewPassphrase != NULL && pConfirmPassphrase != NULL) {
if ((StrCmp(pNewPassphrase, pConfirmPassphrase) != 0)) {
ResetCmdStatus(pCommandStatus, NVM_ERR_PASSPHRASES_DO_NOT_MATCH);
goto FinishCommandStatusSet;
}
}
ReturnCode = pNvmDimmConfigProtocol->SetSecurityState(pNvmDimmConfigProtocol,
pDimmIds, DimmIdsCount,
SecurityOperation,
pPassphrase, pNewPassphrase, pCommandStatus);
goto FinishCommandStatusSet;
}
/**
Set AveragePowerReportingTimeConstant
**/
GetPropertyValue(pCmd, AVG_PWR_REPORTING_TIME_CONSTANT, &pAvgPowerReportingTimeConstantValue);
if (pAvgPowerReportingTimeConstantValue) {
// If average power reporting time constant property exists, check its validity
IsNumber = GetU64FromString(pAvgPowerReportingTimeConstantValue, &ParsedNumber);
if (!IsNumber) {
NVDIMM_WARN("Average power reporting time constant value is not a number");
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_INCORRECT_VALUE_FOR_PROPERTY_AVG_PWR_REPORTING_TIME_CONSTANT);
goto Finish;
}
else if (ParsedNumber > AVG_PWR_REPORTING_TIME_CONSTANT_MAX) {
NVDIMM_WARN("Average power reporting time constant value %d is greater than maximum %d", ParsedNumber, AVG_PWR_REPORTING_TIME_CONSTANT_MAX);
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_INCORRECT_VALUE_FOR_PROPERTY_AVG_PWR_REPORTING_TIME_CONSTANT);
goto Finish;
}
pAvgPowerReportingTimeConstant = AllocateZeroPool(sizeof(UINT32));
*pAvgPowerReportingTimeConstant = (UINT32)ParsedNumber;
pCommandStatusMessage = CatSPrint(NULL, FORMAT_STR, L"Modify");
pCommandStatusPreposition = CatSPrint(NULL, FORMAT_STR, L"");
if (!Force) {
for (Index = 0; Index < DimmIdsCount; Index++) {
ReturnCode = GetDimmHandleByPid(pDimmIds[Index], pDimms, DimmCount, &DimmHandle, &DimmIndex);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
ReturnCode = GetPreferredDimmIdAsString(DimmHandle, pDimms[DimmIndex].DimmUid, DimmStr, MAX_DIMM_UID_LENGTH);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
PRINTER_PROMPT_MSG(pPrinterCtx, ReturnCode, L"Modifying device settings on " PMEM_MODULE_STR L" (" FORMAT_STR L").", DimmStr);
ReturnCode = PromptYesNo(&Confirmation);
if (!EFI_ERROR(ReturnCode) && Confirmation) {
ReturnCode = pNvmDimmConfigProtocol->SetOptionalConfigurationDataPolicy(pNvmDimmConfigProtocol,
&pDimmIds[Index], 1, NULL, pAvgPowerReportingTimeConstant, pCommandStatus);
} else {
PRINTER_PROMPT_MSG(pPrinterCtx, ReturnCode, L"Skipping modify device settings on " PMEM_MODULE_STR L" (" FORMAT_STR L")\n", DimmStr);
continue;
}
}
} else {
ReturnCode = pNvmDimmConfigProtocol->SetOptionalConfigurationDataPolicy(pNvmDimmConfigProtocol,
pDimmIds, DimmIdsCount, NULL, pAvgPowerReportingTimeConstant, pCommandStatus);
goto FinishCommandStatusSet;
}
}
GetPropertyValue(pCmd, TEMPERATURE_INJ_PROPERTY, &pTemperature);
GetPropertyValue(pCmd, POISON_INJ_PROPERTY, &pPoisonAddress);
GetPropertyValue(pCmd, POISON_TYPE_INJ_PROPERTY, &pPoisonType);
GetPropertyValue(pCmd, PACKAGE_SPARING_INJ_PROPERTY, &pPackageSparing);
GetPropertyValue(pCmd, PERCENTAGE_REMAINING_INJ_PROPERTY, &pPercentageRemaining);
GetPropertyValue(pCmd, FATAL_MEDIA_ERROR_INJ_PROPERTY, &pFatalMediaError);
GetPropertyValue(pCmd, DIRTY_SHUTDOWN_ERROR_INJ_PROPERTY, &pDirtyShutDown);
GetPropertyValue(pCmd, CLEAR_ERROR_INJ_PROPERTY, &pClearErrorInj);
// Implementation notes:
// Assumes only one property can be set.
// pCommandStatusMessage seems to be a print wrapper around the pCommandStatus that
// is finally returned from InjectError() at the bottom.
// If there is an error with converting to an integer, we don't want to print
// out the command status message as InjectError() is never called. Go to finish
// with an invalid parameter
/**
Inject error Temperature
**/
if (pTemperature != NULL) {
pCommandStatusMessage = CatSPrint(NULL, CLI_INFO_TEMPERATURE_INJECT_ERROR);
pCommandStatusPreposition = CatSPrint(NULL, CLI_INFO_ON);
ErrInjectType = ERROR_INJ_TEMPERATURE;
ReturnCode = GetU64FromString(pTemperature, &TemperatureValue);
if (!ReturnCode) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_UNSUPPORTED_COMMAND_SYNTAX);
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
}
/**
Inject Poison Error
**/
if (pPoisonAddress != NULL) {
pCommandStatusMessage = CatSPrint(NULL, CLI_INFO_POISON_INJECT_ERROR, pPoisonAddress);
pCommandStatusPreposition = CatSPrint(NULL, CLI_INFO_ON);
ErrInjectType = ERROR_INJ_POISON;
ReturnCode = IsHexValue(pPoisonAddress, FALSE);
// ReturnCode here indicates if it is hex value
if (!ReturnCode) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR FORMAT_STR_SINGLE_QUOTE FORMAT_STR L" 'Poison'\n", CLI_SYNTAX_ERROR,
pPoisonAddress, CLI_ERR_INCORRECT_VALUE_FOR_PROPERTY);
goto Finish;
}
ReturnCode = GetU64FromString(pPoisonAddress, &PoisonAddressValue);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR FORMAT_STR_SINGLE_QUOTE FORMAT_STR L" 'Poison'\n", CLI_SYNTAX_ERROR,
pPoisonAddress, CLI_ERR_INCORRECT_VALUE_FOR_PROPERTY);
goto Finish;
}
}
/**
Inject Poison Type Error
**/
if (pPoisonType != NULL) {
/**
Check if poison MemoryType is valid
**/
for (Index = 0; Index < POISON_MEMORY_TYPE_COUNT; ++Index) {
if (0 == StrICmp(pPoisonType, pPoisonMemoryTypeStr[Index])) {
PoisonTypeValid = 1;
PoisonTypeValue = (UINT8)Index + 1;
}
}
if (!PoisonTypeValid) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_INCORRECT_VALUE_POISON_TYPE);
goto Finish;
}
}
/**
PACKAGE_SPARING_INJ_PROPERTY
**/
if (pPackageSparing != NULL) {
pCommandStatusMessage = CatSPrint(NULL, CLI_INFO_PACKAGE_SPARING_INJECT_ERROR);
pCommandStatusPreposition = CatSPrint(NULL, CLI_INFO_ON);
ReturnCode = GetU64FromString(pPackageSparing, (UINT64 *)&PackageSparing);
if (!ReturnCode || 1 != PackageSparing) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR FORMAT_STR_SINGLE_QUOTE FORMAT_STR L" 'PackageSparing'\n", CLI_SYNTAX_ERROR,
pPackageSparing, CLI_ERR_INCORRECT_VALUE_FOR_PROPERTY);
goto Finish;
}
ErrInjectType = ERROR_INJ_PACKAGE_SPARING;
}
/**
Percentage remaining property
**/
if (pPercentageRemaining != NULL) {
pCommandStatusMessage = CatSPrint(NULL, CLI_INFO_PERCENTAGE_REMAINING_INJECT_ERROR);
pCommandStatusPreposition = CatSPrint(NULL, CLI_INFO_ON);
ReturnCode = GetU64FromString(pPercentageRemaining, &PercentageRemainingValue);
if (!ReturnCode || PercentageRemainingValue > 100) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR FORMAT_STR_SINGLE_QUOTE FORMAT_STR L" 'PercentageRemaining'\n", CLI_SYNTAX_ERROR,
pPercentageRemaining, CLI_ERR_INCORRECT_VALUE_FOR_PROPERTY);
goto Finish;
}
ErrInjectType = ERROR_INJ_PERCENTAGE_REMAINING;
}
/**
Fatal Media Error Inj property
**/
if (pFatalMediaError != NULL) {
#if defined( _MSC_VER ) && defined( OS_BUILD ) // Windows
// We can't recover from an injected fatal media error in Windows
// because nvmdimm.sys requires GetCommandEffectLog to work and that
// command requires the media to be up because it uses the large payload. Therefore
// redirect people to use the Microsoft tools for doing this that ignores the
// lack of a Command Effect Log for the dimm.
Print(CLI_ERR_INJECT_FATAL_ERROR_UNSUPPORTED_ON_OS);
ReturnCode = EFI_UNSUPPORTED;
goto Finish;
#endif // _MSC_VER
pCommandStatusMessage = CatSPrint(NULL, CLI_INFO_FATAL_MEDIA_ERROR_INJECT_ERROR);
pCommandStatusPreposition = CatSPrint(NULL, CLI_INFO_ON);
ReturnCode = GetU64FromString(pFatalMediaError, &FatalMediaError);
if (!ReturnCode || 1 != FatalMediaError) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR FORMAT_STR_SINGLE_QUOTE FORMAT_STR L" 'FatalMediaError'\n", CLI_SYNTAX_ERROR,
pFatalMediaError, CLI_ERR_INCORRECT_VALUE_FOR_PROPERTY);
goto Finish;
}
ErrInjectType = ERROR_INJ_FATAL_MEDIA_ERR;
}
/**
Dirty shutdown error injection
**/
if (pDirtyShutDown != NULL) {
pCommandStatusMessage = CatSPrint(NULL, CLI_INFO_DIRTY_SHUT_DOWN_INJECT_ERROR);
pCommandStatusPreposition = CatSPrint(NULL, CLI_INFO_ON);
ReturnCode = GetU64FromString(pDirtyShutDown, &DirtyShutDown);
if (!ReturnCode || 1 != DirtyShutDown) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR FORMAT_STR_SINGLE_QUOTE FORMAT_STR L" 'DirtyShutDown'\n", CLI_SYNTAX_ERROR, pDirtyShutDown,
CLI_ERR_INCORRECT_VALUE_FOR_PROPERTY);
goto Finish;
}
ErrInjectType = ERROR_INJ_DIRTY_SHUTDOWN;
}
/**
Clear error injection
**/
if (pClearErrorInj != NULL) {
pCommandStatusMessage = CatSPrint(NULL, GetCorrectClearMessageBasedOnProperty(ErrInjectType), pPoisonAddress);
pCommandStatusPreposition = CatSPrint(NULL, CLI_INFO_ON);
ReturnCode = GetU64FromString(pClearErrorInj, &ClearStatus);
if (!ReturnCode || 1 != ClearStatus) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR FORMAT_STR_SINGLE_QUOTE FORMAT_STR L" 'Clear'\n", CLI_SYNTAX_ERROR, ClearStatus,
CLI_ERR_INCORRECT_VALUE_FOR_PROPERTY);
goto Finish;
}
}
if (ErrInjectType != ERROR_INJ_TYPE_INVALID) {
ReturnCode = pNvmDimmConfigProtocol->InjectError(pNvmDimmConfigProtocol, pDimmIds, DimmIdsCount,
(UINT8)ErrInjectType, (UINT8)ClearStatus, &TemperatureValue,
&PoisonAddressValue, (UINT8 *)&PoisonTypeValue, (UINT8 *)&PercentageRemainingValue, pCommandStatus);
}
FinishCommandStatusSet:
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
PRINTER_SET_COMMAND_STATUS(pPrinterCtx, ReturnCode, pCommandStatusMessage, pCommandStatusPreposition, pCommandStatus);
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FreeCommandStatus(&pCommandStatus);
CleanUnicodeStringMemory(pLockStatePropertyValue);
CleanUnicodeStringMemory(pPassphraseStatic);
CleanUnicodeStringMemory(pNewPassphraseStatic);
CleanUnicodeStringMemory(pConfirmPassphraseStatic);
CleanUnicodeStringMemory(pPassphrase);
CleanUnicodeStringMemory(pNewPassphrase);
CleanUnicodeStringMemory(pConfirmPassphrase);
FREE_POOL_SAFE(pPassphrase);
FREE_POOL_SAFE(pNewPassphrase);
FREE_POOL_SAFE(pConfirmPassphrase);
FREE_POOL_SAFE(pLoadFilePath);
FREE_POOL_SAFE(pLoadUserPath);
FREE_POOL_SAFE(pErrorMessage);
FREE_POOL_SAFE(pDimmIds);
FREE_POOL_SAFE(pDimms);
FREE_POOL_SAFE(pCommandStatusMessage);
FREE_POOL_SAFE(pCommandStatusPreposition);
FREE_POOL_SAFE(pAvgPowerReportingTimeConstant);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Register the set dimm command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterSetDimmCommand(
)
{
EFI_STATUS ReturnCode;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&SetDimmCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/SetDimmCommand.h 0000664 0000000 0000000 00000002464 14165347476 0020746 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SET_DIMM_COMMAND_
#define _SET_DIMM_COMMAND_
#include
#include "CommandParser.h"
#include
#define FW_LOG_LEVELS_COUNT 4
#define FW_LOG_LEVELS_INVALID_LEVEL 255
#define POISON_MEMORY_TYPE_COUNT 4
#define POISON_MEMORY_TYPE_MEMORYMODE 0x01 // currently allocated in Memory mode
#define POISON_MEMORY_TYPE_APPDIRECT 0x02 // currently allocated in AppDirect
#define POISON_MEMORY_TYPE_PATROLSCRUB 0x04// simulating an error found during a patrol scrub operation
/**
Register the set dimm command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterSetDimmCommand();
/**
Execute the set dimm command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
SetDimm(
IN struct Command *pCmd
);
/**
Print detailed information on root cause of failure
@param[in] FwReturnCode is a FW status code returned by PassThru protocol
**/
void
PrintFailureDetails(
IN UINT8 FwReturnCode
);
#endif /** _SET_DIMM_COMMAND_ **/
ipmctl-03.00.00.0423/DcpmPkg/cli/SetPreferencesCommand.c 0000664 0000000 0000000 00000037102 14165347476 0022311 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include
#include "Debug.h"
#include "Types.h"
#include "NvmInterface.h"
#include "CommandParser.h"
#include "SetPreferencesCommand.h"
#include "Common.h"
#include "Convert.h"
#include "Utility.h"
#include
#ifdef OS_BUILD
#include
#else
extern EFI_RUNTIME_SERVICES *gRT;
#endif
/**
Local definitions
**/
#define MIN_LOG_LEVEL_VALUE 0
#define MAX_LOG_LEVEL_VALUE 4
/**
Command syntax definition
**/
struct Command SetPreferencesCommand =
{
SET_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"",HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
#ifdef OS_BUILD
{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP, HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#else
{L"", L"", L"", L"", L"", FALSE, ValueOptional}
#endif
},
{ //!< targets
{PREFERENCES_TARGET, L"", L"", TRUE, ValueEmpty},
},
{ //!< properties
{CLI_DEFAULT_DIMM_ID_PROPERTY, L"", PROPERTY_VALUE_HANDLE L"|" PROPERTY_VALUE_UID, FALSE, ValueRequired},
{CLI_DEFAULT_SIZE_PROPERTY, L"", HELP_TEXT_DEFAULT_SIZE, FALSE, ValueRequired},
{APP_DIRECT_SETTINGS_PROPERTY, L"", HELP_TEXT_APPDIRECT_SETTINGS, FALSE, ValueRequired},
#ifdef OS_BUILD
{DBG_LOG_LEVEL, L"", HELP_DBG_LOG_LEVEL, FALSE, ValueRequired},
#endif
},
L"Set user preferences.", //!< help
SetPreferences,
TRUE
};
STATIC
UINT8
GetBitFieldForInterleaveChannelSize(
IN CHAR16 *pStringValue
)
{
UINT8 BitField = CHANNEL_INTERLEAVE_SIZE_INVALID;
if (pStringValue == NULL) {
return BitField;
}
if (StrICmp(pStringValue, L"64B") == 0) {
BitField = CHANNEL_INTERLEAVE_SIZE_64B;
} else if (StrICmp(pStringValue, L"128B") == 0) {
BitField = CHANNEL_INTERLEAVE_SIZE_128B;
} else if (StrICmp(pStringValue, L"256B") == 0) {
BitField = CHANNEL_INTERLEAVE_SIZE_256B;
} else if (StrICmp(pStringValue, L"4KB") == 0) {
BitField = CHANNEL_INTERLEAVE_SIZE_4KB;
} else if (StrICmp(pStringValue, L"1GB") == 0) {
BitField = CHANNEL_INTERLEAVE_SIZE_1GB;
}
return BitField;
}
STATIC
UINT8
GetBitFieldForInterleaveImcSize(
IN CHAR16 *pStringValue
)
{
UINT8 BitField = IMC_INTERLEAVE_SIZE_INVALID;
if (pStringValue == NULL) {
return BitField;
}
if (StrICmp(pStringValue, L"64B") == 0) {
BitField = IMC_INTERLEAVE_SIZE_64B;
} else if (StrICmp(pStringValue, L"128B") == 0) {
BitField = IMC_INTERLEAVE_SIZE_128B;
} else if (StrICmp(pStringValue, L"256B") == 0) {
BitField = IMC_INTERLEAVE_SIZE_256B;
} else if (StrICmp(pStringValue, L"4KB") == 0) {
BitField = IMC_INTERLEAVE_SIZE_4KB;
} else if (StrICmp(pStringValue, L"1GB") == 0) {
BitField = IMC_INTERLEAVE_SIZE_1GB;
}
return BitField;
}
STATIC
EFI_STATUS
GetAppDirectSettingsBitFields(
IN CHAR16 *pAppDirectSettings,
OUT UINT8 *pImcBitField,
OUT UINT8 *pChannelBitField
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
CHAR16 **ppSplitSettings = NULL;
UINT32 NumOfElements = 0;
if (pAppDirectSettings == NULL || pImcBitField == NULL || pChannelBitField == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
// default values
*pImcBitField = DEFAULT_IMC_INTERLEAVE_SIZE;
*pChannelBitField = DEFAULT_CHANNEL_INTERLEAVE_SIZE;
ppSplitSettings = StrSplit(pAppDirectSettings, L'_', &NumOfElements);
if (ppSplitSettings == NULL || NumOfElements != 2) {
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
*pImcBitField = GetBitFieldForInterleaveImcSize(ppSplitSettings[0]);
*pChannelBitField = GetBitFieldForInterleaveChannelSize(ppSplitSettings[1]);
if (*pImcBitField == IMC_INTERLEAVE_SIZE_INVALID ||
*pChannelBitField == CHANNEL_INTERLEAVE_SIZE_INVALID)
{
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
Finish:
if (ppSplitSettings != NULL) {
FreeStringArray(ppSplitSettings, NumOfElements);
}
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
#ifdef OS_BUILD
EFI_STATUS ValidateAndConvertInput(CHAR16 *InputString, UINT64 MinVal, UINT64 MaxValue, UINT64 *IntegerEq) {
EFI_STATUS rc = EFI_INVALID_PARAMETER;
if (!GetU64FromString(InputString, IntegerEq)) {
goto Finish;
}
if (*IntegerEq > MaxValue || *IntegerEq < MinVal) {
goto Finish;
}
rc = EFI_SUCCESS;
Finish:
return rc;
}
EFI_STATUS SetPreferenceStr(IN struct Command *pCmd, IN CONST CHAR16 * pName, IN CONST CHAR8 *pIfNotFoundWarning, IN UINT64 MinVal, IN UINT64 MaxValue, OUT COMMAND_STATUS* pCommandStatus)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
CHAR16 *pTypeValue = NULL;
UINT64 IntegerValue;
if ((ReturnCode = ContainsProperty(pCmd, pName)) != EFI_NOT_FOUND) {
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
SetObjStatus(pCommandStatus, 0, NULL, 0, NVM_ERR_OPERATION_FAILED, ObjectTypeUnknown);
goto Finish;
}
ReturnCode = GetPropertyValue(pCmd, pName, &pTypeValue);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
SetObjStatus(pCommandStatus, 0, NULL, 0, NVM_ERR_OPERATION_FAILED, ObjectTypeUnknown);
goto Finish;
}
ReturnCode = ValidateAndConvertInput(pTypeValue, MinVal, MaxValue, &IntegerValue);
if (EFI_ERROR(ReturnCode) || ((StrCmp(pName, DBG_LOG_LEVEL) == 0) && IntegerValue > 4)) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_SET_PREFERENCE_ERROR, pName, pTypeValue, ReturnCode, PROPERTY_ERROR_INVALID_OUT_OF_RANGE);
SetObjStatus(pCommandStatus, 0, NULL, 0, NVM_ERR_INVALID_PARAMETER, ObjectTypeUnknown);
goto Finish;
} else {
if (ReturnCode == EFI_SUCCESS) {
ReturnCode = SET_STR_VARIABLE_NV(pName, gNvmDimmVariableGuid, pTypeValue);
if (!EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_SET_PREFERENCE_SUCCESS, pName, pTypeValue);
SetObjStatus(pCommandStatus, 0, NULL, 0, NVM_SUCCESS, ObjectTypeUnknown);
} else {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_SET_PREFERENCE_ERROR, pName, pTypeValue, ReturnCode, PROPERTY_ERROR_SET_FAILED_UNKNOWN);
SetObjStatus(pCommandStatus, 0, NULL, 0, NVM_ERR_OPERATION_FAILED, ObjectTypeUnknown);
}
}
}
}
Finish:
return ReturnCode;
}
#endif
/**
Execute the Set Preferences command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
@retval EFI_NOT_FOUND Cli display preferences could not be retrieved successfully
**/
EFI_STATUS
SetPreferences(
IN struct Command *pCmd
)
{
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
COMMAND_STATUS *pCommandStatus = NULL;
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_STATUS TempReturnCode = EFI_SUCCESS;
DRIVER_PREFERENCES DriverPreferences;
DISPLAY_PREFERENCES DisplayPreferences;
UINT8 Index = 0;
CHAR16 *pTypeValue = NULL;
UINTN VariableSize = 0;
PRINT_CONTEXT *pPrinterCtx = NULL;
UINT16 PropertyCnt = 0;
NVDIMM_ENTRY();
ZeroMem(&DriverPreferences, sizeof(DriverPreferences));
ZeroMem(&DisplayPreferences, sizeof(DisplayPreferences));
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("pCmd parameter is NULL.\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
//verify we have at least one preference to set.
ReturnCode = GetPropertyCount(pCmd, &PropertyCnt);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
else if (0 == PropertyCnt) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("Preference not specified\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCOMPLETE_SYNTAX);
goto Finish;
}
/** Need NvmDimmConfigProtocol **/
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// Retrieve current settings
ReturnCode = pNvmDimmConfigProtocol->GetDriverPreferences(pNvmDimmConfigProtocol, &DriverPreferences, pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
PRINTER_SET_COMMAND_STATUS(pPrinterCtx, ReturnCode, L"Set preferences", L" on", pCommandStatus);
goto Finish;
}
ReturnCode = ReadRunTimePreferences(&DisplayPreferences, DISPLAY_CLI_INFO);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_DISPLAY_PREFERENCES_RETRIEVE);
goto Finish;
}
if ((TempReturnCode = ContainsProperty(pCmd, CLI_DEFAULT_DIMM_ID_PROPERTY)) != EFI_NOT_FOUND) {
if (EFI_ERROR(TempReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
KEEP_ERROR(ReturnCode, TempReturnCode);
goto Finish;
}
TempReturnCode = GetPropertyValue(pCmd, CLI_DEFAULT_DIMM_ID_PROPERTY, &pTypeValue);
if (EFI_ERROR(TempReturnCode)) {
KEEP_ERROR(ReturnCode, EFI_INVALID_PARAMETER);
NVDIMM_WARN("Default DimmID Type not provided");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_SET_PREFERENCE_ERROR, CLI_DEFAULT_DIMM_ID_PROPERTY, L"", ReturnCode, PROPERTY_ERROR_DEFAULT_DIMM_NOT_PROVIDED);
} else if ((Index = GetDimmIDIndex(pTypeValue)) >= DISPLAY_DIMM_ID_MAX_SIZE) {
KEEP_ERROR(ReturnCode, EFI_INVALID_PARAMETER);
NVDIMM_WARN("Incorrect default DimmID type");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_SET_PREFERENCE_ERROR, CLI_DEFAULT_DIMM_ID_PROPERTY, pTypeValue, ReturnCode, PROPERTY_ERROR_INCORRECT_DEFAULT_DIMM_TYPE);
} else {
DisplayPreferences.DimmIdentifier = Index;
VariableSize = sizeof(DisplayPreferences.DimmIdentifier);
TempReturnCode = SET_VARIABLE_NV(
CLI_DEFAULT_DIMM_ID_PROPERTY,
gNvmDimmVariableGuid,
VariableSize,
&DisplayPreferences.DimmIdentifier);
if (!EFI_ERROR(TempReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_SET_PREFERENCE_SUCCESS, CLI_DEFAULT_DIMM_ID_PROPERTY, pTypeValue);
} else {
KEEP_ERROR(ReturnCode,TempReturnCode);
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_SET_PREFERENCE_ERROR, CLI_DEFAULT_DIMM_ID_PROPERTY, pTypeValue, ReturnCode, PROPERTY_ERROR_UNKNOWN);
}
}
}
if ((TempReturnCode = ContainsProperty(pCmd, CLI_DEFAULT_SIZE_PROPERTY)) != EFI_NOT_FOUND) {
if (EFI_ERROR(TempReturnCode)) {
KEEP_ERROR(ReturnCode, TempReturnCode);
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
TempReturnCode = GetPropertyValue(pCmd, CLI_DEFAULT_SIZE_PROPERTY, &pTypeValue);
if (EFI_ERROR(TempReturnCode)) {
KEEP_ERROR(ReturnCode, EFI_INVALID_PARAMETER);
NVDIMM_WARN("Display default size type not provided");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_SET_PREFERENCE_ERROR, CLI_DEFAULT_SIZE_PROPERTY, L"", ReturnCode, PROPERTY_ERROR_DISPLAY_DEFAULT_NOT_PROVIDED);
} else if ((Index = GetDisplaySizeIndex(pTypeValue)) >= DISPLAY_SIZE_MAX_SIZE) {
KEEP_ERROR(ReturnCode, EFI_INVALID_PARAMETER);
NVDIMM_WARN("Incorrect default size type");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_SET_PREFERENCE_ERROR, CLI_DEFAULT_SIZE_PROPERTY, pTypeValue, ReturnCode, PROPERTY_ERROR_DEFAULT_INCORRECT_SIZE_TYPE);
} else {
DisplayPreferences.SizeUnit = Index;
VariableSize = sizeof(DisplayPreferences.SizeUnit);
TempReturnCode = SET_VARIABLE_NV(
CLI_DEFAULT_SIZE_PROPERTY,
gNvmDimmVariableGuid,
VariableSize,
&DisplayPreferences.SizeUnit);
if (TempReturnCode == EFI_SUCCESS) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_SET_PREFERENCE_SUCCESS, CLI_DEFAULT_SIZE_PROPERTY, pTypeValue);
} else {
KEEP_ERROR(ReturnCode,TempReturnCode);
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_SET_PREFERENCE_ERROR, CLI_DEFAULT_SIZE_PROPERTY, pTypeValue, ReturnCode, PROPERTY_ERROR_UNKNOWN);
}
}
}
if ((TempReturnCode = ContainsProperty(pCmd, APP_DIRECT_SETTINGS_PROPERTY)) != EFI_NOT_FOUND) {
if (EFI_ERROR(ReturnCode)) {
KEEP_ERROR(ReturnCode, TempReturnCode);
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
TempReturnCode = GetPropertyValue(pCmd, APP_DIRECT_SETTINGS_PROPERTY, &pTypeValue);
if (EFI_ERROR(TempReturnCode)) {
KEEP_ERROR(ReturnCode, EFI_INVALID_PARAMETER);
NVDIMM_WARN("AppDirect interleave setting type not provided");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_SET_PREFERENCE_ERROR, APP_DIRECT_SETTINGS_PROPERTY, L"", ReturnCode, PROPERTY_ERROR_INTERLEAVE_TYPE_NOT_PROVIDED);
} else {
if (StrICmp(pTypeValue, PROPERTY_VALUE_RECOMMENDED) == 0) {
DriverPreferences.ChannelInterleaving = DEFAULT_CHANNEL_INTERLEAVE_SIZE;
DriverPreferences.ImcInterleaving = DEFAULT_IMC_INTERLEAVE_SIZE;
} else if ((TempReturnCode = GetAppDirectSettingsBitFields(pTypeValue, &DriverPreferences.ImcInterleaving, &DriverPreferences.ChannelInterleaving)) != EFI_SUCCESS) {
KEEP_ERROR(ReturnCode, EFI_INVALID_PARAMETER);
NVDIMM_WARN("Incorrect AppDirect interleave setting type");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_SET_PREFERENCE_ERROR, APP_DIRECT_SETTINGS_PROPERTY, pTypeValue, ReturnCode, PROPERTY_ERROR_APPDIR_INTERLEAVE_TYPE);
}
if (TempReturnCode == EFI_SUCCESS) {
TempReturnCode = pNvmDimmConfigProtocol->SetDriverPreferences(pNvmDimmConfigProtocol, &DriverPreferences, pCommandStatus);
if (TempReturnCode == EFI_SUCCESS) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_SET_PREFERENCE_SUCCESS, APP_DIRECT_SETTINGS_PROPERTY, pTypeValue);
} else {
TempReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
KEEP_ERROR(ReturnCode, TempReturnCode);
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_SET_PREFERENCE_ERROR, APP_DIRECT_SETTINGS_PROPERTY, pTypeValue, ReturnCode, PROPERTY_ERROR_UNKNOWN);
}
}
}
}
#ifdef OS_BUILD
SetPreferenceStr(pCmd, DBG_LOG_LEVEL, "Log level setting type not provided", MIN_LOG_LEVEL_VALUE, MAX_LOG_LEVEL_VALUE, pCommandStatus);
TempReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
KEEP_ERROR(ReturnCode, TempReturnCode);
#endif
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FreeCommandStatus(&pCommandStatus);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Register the Set Preferences command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterSetPreferencesCommand(
)
{
EFI_STATUS ReturnCode;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&SetPreferencesCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/SetPreferencesCommand.h 0000664 0000000 0000000 00000001752 14165347476 0022320 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SET_PREFERENCES_COMMAND_
#define _SET_PREFERENCES_COMMAND_
#include
#include "CommandParser.h"
#define CLI_SET_PREFERENCE_SUCCESS L"Set " FORMAT_STR L"=" FORMAT_STR L": Success\n"
#define CLI_SET_PREFERENCE_ERROR L"Set " FORMAT_STR L"=" FORMAT_STR L". Error: %d. " FORMAT_STR L"\n"
/**
Register the Set Preferences command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterSetPreferencesCommand();
/**
Execute the Set Preferences command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
SetPreferences(
IN struct Command *pCmd
);
#endif /** _SET_PREFERENCES_COMMAND_ **/
ipmctl-03.00.00.0423/DcpmPkg/cli/SetSensorCommand.c 0000664 0000000 0000000 00000022454 14165347476 0021325 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include "SetSensorCommand.h"
#include
#include
#include
#include
#include "Common.h"
#include "NvmDimmCli.h"
/** Command syntax definition **/
struct Command SetSensorCommand =
{
SET_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"",HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{FORCE_OPTION_SHORT, FORCE_OPTION, L"", L"",HELP_FORCE_DETAILS_TEXT, FALSE, ValueEmpty}
#ifdef OS_BUILD
,{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP,HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#endif
},
{ //!< targets
{SENSOR_TARGET, L"", HELP_TEXT_SENSORS, TRUE, ValueRequired},
{DIMM_TARGET, L"", HELP_TEXT_DIMM_IDS, FALSE, ValueOptional}
},
{ //!< properties
{ALARM_THRESHOLD_PROPERTY, L"", HELP_TEXT_VALUE, FALSE},
{ALARM_ENABLED_PROPERTY, L"", PROPERTY_VALUE_0 L"|" PROPERTY_VALUE_1, FALSE}
},
L"Modify the alarm threshold(s) for one or more " PMEM_MODULES_STR L".", //!< help
SetSensor,
TRUE
};
/**
Execute the set sensor command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
SetSensor(
IN struct Command *pCmd
)
{
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
UINT16 *pDimmIds = NULL;
UINT32 DimmHandle = 0;
UINT32 DimmIndex = 0;
UINT32 DimmIdsCount = 0;
UINT64 TempValue = 0;
CHAR16* pTargetValue = NULL;
CHAR16* pCommandStatusMessage = NULL;
INT16 NonCriticalThreshold = THRESHOLD_UNDEFINED;
UINT16 Index = 0;
UINT8 EnabledState = ENABLED_STATE_UNDEFINED;
UINT8 SensorId = SENSOR_ID_UNDEFINED;
BOOLEAN ValidPropertyAndValue = FALSE;
BOOLEAN Force = FALSE;
EFI_STATUS ReturnCode = EFI_SUCCESS;
COMMAND_STATUS *pCommandStatus = NULL;
BOOLEAN Confirmation = FALSE;
DIMM_INFO *pDimms = NULL;
UINT32 DimmCount = 0;
CHAR16 DimmStr[MAX_DIMM_UID_LENGTH];
PRINT_CONTEXT *pPrinterCtx = NULL;
NVDIMM_ENTRY();
ZeroMem(DimmStr, sizeof(DimmStr));
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("pCmd parameter is NULL.\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// Populate the list of DIMM_INFO structures with relevant information
ReturnCode = GetDimmList(pNvmDimmConfigProtocol, pCmd, DIMM_INFO_CATEGORY_NONE, &pDimms, &DimmCount);
if (EFI_ERROR(ReturnCode)) {
if(ReturnCode == EFI_NOT_FOUND) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_INFO_NO_FUNCTIONAL_DIMMS);
}
goto Finish;
}
// check targets
if (ContainTarget(pCmd, DIMM_TARGET)) {
pTargetValue = GetTargetValue(pCmd, DIMM_TARGET);
ReturnCode = GetDimmIdsFromString(pCmd, pTargetValue, pDimms, DimmCount, &pDimmIds, &DimmIdsCount);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("Failed on GetDimmIdsFromString");
goto Finish;
}
if (!AllDimmsInListAreManageable(pDimms, DimmCount, pDimmIds, DimmIdsCount)){
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_UNMANAGEABLE_DIMM);
goto Finish;
}
if (!AllDimmsInListInSupportedConfig(pDimms, DimmCount, pDimmIds, DimmIdsCount)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_POPULATION_VIOLATION);
goto Finish;
}
}
if (DimmIdsCount == 0) {
ReturnCode = GetManageableDimmsNumberAndId(pNvmDimmConfigProtocol, TRUE, &DimmIdsCount, &pDimmIds);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
if (DimmIdsCount == 0) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_INFO_NO_MANAGEABLE_DIMMS);
goto Finish;
}
}
// check properties
if (!EFI_ERROR(ContainsProperty(pCmd, ALARM_THRESHOLD_PROPERTY))) {
if (PropertyToUint64(pCmd, ALARM_THRESHOLD_PROPERTY, &TempValue)) {
NonCriticalThreshold = (INT16) TempValue;
ValidPropertyAndValue = TRUE;
} else {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_PROPERTY_ALARM_THRESHOLD);
goto Finish;
}
}
if (!EFI_ERROR(ContainsProperty(pCmd, ALARM_ENABLED_PROPERTY))) {
if (PropertyToUint64(pCmd, ALARM_ENABLED_PROPERTY, &TempValue)) {
EnabledState = (UINT8) TempValue;
ValidPropertyAndValue = TRUE;
} else {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_PROPERTY_ENABLED_STATE);
goto Finish;
}
}
if (!ValidPropertyAndValue) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCOMPLETE_SYNTAX);
goto Finish;
}
if (ContainTarget(pCmd, SENSOR_TARGET)) {
pTargetValue = GetTargetValue(pCmd, SENSOR_TARGET);
if (StrICmp(pTargetValue, CONTROLLER_TEMPERATURE_TARGET_VALUE) == 0) {
SensorId = SENSOR_TYPE_CONTROLLER_TEMPERATURE;
} else if (StrICmp(pTargetValue, MEDIA_TEMPERATURE_TARGET_VALUE) == 0) {
SensorId = SENSOR_TYPE_MEDIA_TEMPERATURE;
} else if (StrICmp(pTargetValue, SPARE_CAPACITY_TARGET_VALUE) == 0) {
SensorId = SENSOR_TYPE_PERCENTAGE_REMAINING;
} else {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_TARGET_SENSOR);
goto Finish;
}
}
/** Check force option **/
if (containsOption(pCmd, FORCE_OPTION) || containsOption(pCmd, FORCE_OPTION_SHORT)) {
Force = TRUE;
}
// initialize status structure
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
NVDIMM_DBG("Failed on InitializeCommandStatus");
goto Finish;
}
if (SensorId == SENSOR_TYPE_CONTROLLER_TEMPERATURE) {
pCommandStatusMessage = CatSPrint(NULL, L"Modify controller temperature settings");
} else if (SensorId == SENSOR_TYPE_MEDIA_TEMPERATURE) {
pCommandStatusMessage = CatSPrint(NULL, L"Modify media temperature settings");
} else {
pCommandStatusMessage = CatSPrint(NULL, L"Modify percentage remaining settings");
}
if (!Force) {
for (Index = 0; Index < DimmIdsCount; Index++) {
ReturnCode = GetDimmHandleByPid(pDimmIds[Index], pDimms, DimmCount, &DimmHandle, &DimmIndex);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
ReturnCode = GetPreferredDimmIdAsString(DimmHandle, pDimms[DimmIndex].DimmUid,
DimmStr, MAX_DIMM_UID_LENGTH);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
PRINTER_PROMPT_MSG(pPrinterCtx, ReturnCode, L"Modifying settings on " PMEM_MODULE_STR L" " FORMAT_STR L".", DimmStr);
ReturnCode = PromptYesNo(&Confirmation);
if (!EFI_ERROR(ReturnCode) && Confirmation) {
ReturnCode = pNvmDimmConfigProtocol->SetAlarmThresholds(pNvmDimmConfigProtocol, &pDimmIds[Index], 1,
SensorId, NonCriticalThreshold, EnabledState, pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
goto FinishCommandStatusSet;
}
} else {
PRINTER_PROMPT_MSG(pPrinterCtx, ReturnCode, L"Skipped modifying settings for " PMEM_MODULE_STR L" " FORMAT_STR L"\n", DimmStr);
continue;
}
}
} else {
ReturnCode = pNvmDimmConfigProtocol->SetAlarmThresholds(pNvmDimmConfigProtocol, &pDimmIds[Index], DimmIdsCount,
SensorId, NonCriticalThreshold, EnabledState, pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
goto FinishCommandStatusSet;
}
}
FinishCommandStatusSet:
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
PRINTER_SET_COMMAND_STATUS(pPrinterCtx, ReturnCode, pCommandStatusMessage, L" on", pCommandStatus);
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FreeCommandStatus(&pCommandStatus);
FREE_POOL_SAFE(pDimmIds);
FREE_POOL_SAFE(pCommandStatusMessage);
FREE_POOL_SAFE(pDimms);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Register the set sensor command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterSetSensorCommand(
)
{
EFI_STATUS ReturnCode;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&SetSensorCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/SetSensorCommand.h 0000664 0000000 0000000 00000001371 14165347476 0021325 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SET_SENSOR_COMMAND_H_
#define _SET_SENSOR_COMMAND_H_
#include
#include "CommandParser.h"
/**
Register the set sensor command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterSetSensorCommand(
);
/**
Execute the set sensor command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
SetSensor(
IN struct Command *pCmd
);
#endif /** _SET_SENSOR_COMMAND_H_ **/
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowAcpiCommand.c 0000664 0000000 0000000 00000022230 14165347476 0021105 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include "ShowAcpiCommand.h"
#include
#include
#include
#include
#include
#include "Common.h"
#include "NvmDimmCli.h"
#include
#include
/*
* PRINT LIST ATTRIBUTES (2 levels: Target-->Type)
* ---NVDIMM Firmware Interface Table---
* ---TableType=0X0
* Length: 56 bytes
* TypeEquals: SpaRange
* ...
*/
PRINTER_LIST_ATTRIB ShowAcpiListAttributes =
{
{
{
ACPI_MODE_STR, //GROUP LEVEL TYPE
L"---$(" SYSTEM_TARGET_STR L")---", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT FORMAT_STR L": " FORMAT_STR, //NULL or KEY VAL FORMAT STR
SYSTEM_TARGET_STR //NULL or IGNORE KEY LIST (K1;K2)
},
{
ACPITYPE_MODE_STR, //GROUP LEVEL TYPE
SHOW_LIST_IDENT L"---" ACPI_TYPE_STR L"=$(" ACPI_TYPE_STR L")", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT SHOW_LIST_IDENT FORMAT_STR L": " FORMAT_STR, //NULL or KEY VAL FORMAT STR
ACPI_TYPE_STR //NULL or IGNORE KEY LIST (K1;K2)
}
}
};
PRINTER_DATA_SET_ATTRIBS ShowAcpiDataSetAttribs =
{
&ShowAcpiListAttributes,
NULL
};
/* Command syntax definition */
struct Command showAcpiCommand =
{
SHOW_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"", HELP_VERBOSE_DETAILS_TEXT,FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
#ifdef OS_BUILD
{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP,HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#else
{L"", L"", L"", L"",L"", FALSE, ValueOptional}
#endif
}, //!< options
{{SYSTEM_TARGET, L"", SYSTEM_ACPI_TARGETS, TRUE, ValueOptional}}, //!< targets
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Show the ACPI tables related to the " PMEM_MODULES_STR L" in the system.", //!< help
showAcpi, //!< run function
TRUE //!< enable print control support
};
/*
* Register the show acpi command
*/
EFI_STATUS RegisterShowAcpiCommand() {
EFI_STATUS rc = EFI_SUCCESS;
NVDIMM_ENTRY();
rc = RegisterCommand(&showAcpiCommand);
NVDIMM_EXIT_I64(rc);
return rc;
}
/**
PrintInvalidAcpiRevisionString - Prints the invalid ACPI revision string
@param[in] Revision ACPI Table Revision
@param[in] AcpiTableType ACPI Table (NFIT/PCAT/PMTT)
@param[in] DisplayAsMajorMinor flag to indicate if Revision needs to be printed as Major & Minor
@param[in] pPrinterCtx pointer to command's printer context
**/
VOID
PrintInvalidAcpiRevisionString(
IN ACPI_REVISION Revision,
IN AcpiType AcpiTableType,
IN BOOLEAN DisplayAsMajorMinor,
IN PRINT_CONTEXT *pPrinterCtx
)
{
CHAR16 *pInvalidAcpiRevisionMessage = NULL;
CHAR16 *pAcpiTableTypeString = NULL;
if (pPrinterCtx == NULL) {
return;
}
switch (AcpiTableType) {
case AcpiNfit:
pAcpiTableTypeString = HiiGetString(gNvmDimmCliHiiHandle, STRING_TOKEN(STR_ACPI_STATUS_NFIT), NULL);
break;
case AcpiPcat:
pAcpiTableTypeString = HiiGetString(gNvmDimmCliHiiHandle, STRING_TOKEN(STR_ACPI_STATUS_PCAT), NULL);
break;
case AcpiPMTT:
pAcpiTableTypeString = HiiGetString(gNvmDimmCliHiiHandle, STRING_TOKEN(STR_ACPI_STATUS_PMTT), NULL);
break;
default:
pAcpiTableTypeString = HiiGetString(gNvmDimmCliHiiHandle, STRING_TOKEN(STR_ACPI_STATUS_UNKNOWN_TABLE), NULL);
break;
}
if (DisplayAsMajorMinor) {
pInvalidAcpiRevisionMessage = HiiGetString(gNvmDimmCliHiiHandle, STRING_TOKEN(STR_ACPI_STATUS_ERR_INVALID_MAJOR_MINOR_REVISION), NULL);
pInvalidAcpiRevisionMessage = CatSPrintClean(NULL, pInvalidAcpiRevisionMessage, pAcpiTableTypeString, Revision.Split.Major, Revision.Split.Minor);
}
else {
pInvalidAcpiRevisionMessage = HiiGetString(gNvmDimmCliHiiHandle, STRING_TOKEN(STR_ACPI_STATUS_ERR_INVALID_REVISION), NULL);
pInvalidAcpiRevisionMessage = CatSPrintClean(NULL, pInvalidAcpiRevisionMessage, pAcpiTableTypeString, Revision.AsUint8);
}
PRINTER_SET_MSG(pPrinterCtx, EFI_INVALID_PARAMETER, FORMAT_STR, pInvalidAcpiRevisionMessage);
FREE_POOL_SAFE(pInvalidAcpiRevisionMessage);
FREE_POOL_SAFE(pAcpiTableTypeString);
}
/*
* Execute the show acpi command
*/
EFI_STATUS showAcpi(struct Command *pCmd) {
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
ParsedFitHeader *pNFit = NULL;
ParsedPcatHeader *pPcat = NULL;
TABLE_HEADER *pPMTT = NULL;
CHAR16 *pSystemTargetValue = NULL;
CHAR16 **ppStringElements = NULL;
UINT32 ElementsCount = 0;
UINT8 ChosenAcpiSystem = AcpiUnknown;
UINT16 Index = 0;
PRINT_CONTEXT *pPrinterCtx = NULL;
NVDIMM_ENTRY();
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
ReturnCode = EFI_NOT_FOUND;
goto Finish;
}
if (!ContainTarget(pCmd, SYSTEM_TARGET)) {
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
pSystemTargetValue = GetTargetValue(pCmd, SYSTEM_TARGET);
ppStringElements = StrSplit(pSystemTargetValue, L',', &ElementsCount);
if (ppStringElements != NULL) {
for (Index = 0; Index < ElementsCount; ++Index) {
if (StrICmp(ppStringElements[Index], NFIT_TARGET_VALUE) == 0) {
ChosenAcpiSystem |= AcpiNfit;
} else if (StrICmp(ppStringElements[Index], PCAT_TARGET_VALUE) == 0) {
ChosenAcpiSystem |= AcpiPcat;
} else if (StrICmp(ppStringElements[Index], PMTT_TARGET_VALUE) == 0) {
ChosenAcpiSystem |= AcpiPMTT;
} else {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"The provided system ACPI Table: " FORMAT_STR L" is not valid\n", pSystemTargetValue);
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
}
} else {
/* If no target value is mentioned, then print all */
ChosenAcpiSystem = AcpiAll;
}
if (ChosenAcpiSystem == AcpiAll || ChosenAcpiSystem == AcpiNfit) {
ReturnCode = pNvmDimmConfigProtocol->GetAcpiNFit(pNvmDimmConfigProtocol, &pNFit);
if (EFI_ERROR(ReturnCode) || pNFit == NULL) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"Error: Failed to find the NVDIMM Firmware Interface ACPI tables\n");
ReturnCode = EFI_ABORTED;
} else if (IS_NFIT_REVISION_INVALID(pNFit->pFit->Header.Revision)) {
PrintInvalidAcpiRevisionString(pNFit->pFit->Header.Revision, AcpiNfit, FALSE, pCmd->pPrintCtx);
ReturnCode = EFI_UNSUPPORTED;
} else {
PrintNFit(pNFit, pPrinterCtx);
}
}
if (ChosenAcpiSystem == AcpiAll || ChosenAcpiSystem == AcpiPcat) {
ReturnCode = pNvmDimmConfigProtocol->GetAcpiPcat(pNvmDimmConfigProtocol, &pPcat);
if (EFI_ERROR(ReturnCode) || pPcat == NULL) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"Error: Failed to find the PCAT tables\n");
} else if (IS_PCAT_REVISION_INVALID(pPcat->pPlatformConfigAttr->Header.Revision)) {
PrintInvalidAcpiRevisionString(pPcat->pPlatformConfigAttr->Header.Revision, AcpiPcat, TRUE, pCmd->pPrintCtx);
ReturnCode = EFI_UNSUPPORTED;
} else {
PrintPcat(pPcat, pPrinterCtx);
}
}
if (ChosenAcpiSystem == AcpiAll || ChosenAcpiSystem == AcpiPMTT) {
ReturnCode = pNvmDimmConfigProtocol->GetAcpiPMTT(pNvmDimmConfigProtocol, (VOID *)&pPMTT);
if (ReturnCode == EFI_NOT_FOUND) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"PMTT table not found.\n");
ReturnCode = EFI_SUCCESS;
} else if (EFI_ERROR(ReturnCode)|| pPMTT == NULL) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"Error: Failed to find the PMTT tables\n");
} else if (IS_PMTT_REVISION_INVALID(pPMTT->Revision)) {
PrintInvalidAcpiRevisionString(pPMTT->Revision, AcpiPMTT, FALSE, pCmd->pPrintCtx);
FREE_POOL_SAFE(pPMTT);
ReturnCode = EFI_UNSUPPORTED;
} else {
PrintPmtt(pPMTT, pPrinterCtx);
FREE_POOL_SAFE(pPMTT);
}
}
//Specify list attributes & display dataset as a list
PRINTER_CONFIGURE_DATA_ATTRIBUTES(pPrinterCtx, DS_ROOT_PATH, &ShowAcpiDataSetAttribs);
PRINTER_ENABLE_LIST_TABLE_FORMAT(pPrinterCtx);
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
if (ppStringElements != NULL) {
FreeStringArray(ppStringElements, ElementsCount);
}
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowAcpiCommand.h 0000664 0000000 0000000 00000001102 14165347476 0021105 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SHOW_ACPI_COMMAND_H_
#define _SHOW_ACPI_COMMAND_H_
#include "CommandParser.h"
typedef enum {
AcpiUnknown = 0,
AcpiNfit = BIT0,
AcpiPcat = BIT1,
AcpiPMTT = BIT2,
AcpiAll = AcpiUnknown | AcpiNfit | AcpiPcat | AcpiPMTT
} AcpiType;
/**
Register the show ACPI tables command
**/
EFI_STATUS
RegisterShowAcpiCommand(
);
/**
Execute the show ACPI command
**/
EFI_STATUS
showAcpi(
IN struct Command *pCmd
);
#endif /** _SHOW_ACPI_COMMAND_H_ **/
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowCelCommand.c 0000664 0000000 0000000 00000027242 14165347476 0020744 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
/* TODO: Include headers */
#include
#include "ShowCelCommand.h"
#include "NvmDimmCli.h"
#include "NvmInterface.h"
#include "LoadCommand.h"
#include "Debug.h"
#include "Convert.h"
#define DS_ROOT_PATH L"/CelList"
#define DS_DIMM_PATH L"/CelList/Dimm"
#define DS_DIMM_INDEX_PATH L"/CelList/Dimm[%d]"
#define DS_CEL_PATH L"/CelList/Dimm/Cel"
#define DS_CEL_INDEX_PATH L"/CelList/Dimm[%d]/Cel[%d]"
/**
show -cel syntax definition
**/
struct Command ShowCelCommandSyntax =
{
SHOW_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"",HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", LARGE_PAYLOAD_OPTION, L"", L"", HELP_LPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", SMALL_PAYLOAD_OPTION, L"", L"", HELP_SPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
#ifdef OS_BUILD
{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP, HELP_OPTIONS_DETAILS_TEXT,FALSE, ValueRequired }
#else
{L"", L"", L"", L"", L"",FALSE, ValueOptional}
#endif
},
{
{CEL_TARGET, L"", HELP_TEXT_DIMM_IDS, TRUE, ValueEmpty},
{DIMM_TARGET, L"", HELP_TEXT_DIMM_IDS, FALSE, ValueOptional}
},
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Show command effect log (CEL) for one or more " PMEM_MODULES_STR L".", //!< help
ShowCelCommand, //!< run function
TRUE
};
// Table heading names
#define OPCODE_STR L"Opcode"
#define SUBOPCODE_STR L"SubOpcode"
#define CE_DESCRIPTION_STR L"CE Description"
/*
* SHOW CAP ATTRIBUTES (4 columns)
* DimmID | Opcode | SubOpcode | CE Description
* ===========================================
* 0x0001 | X | X | X
* ...
*/
PRINTER_TABLE_ATTRIB ShowCelTableAttributes =
{
{
{
DIMM_ID_STR, //COLUMN HEADER
DIMM_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_DIMM_PATH PATH_KEY_DELIM DIMM_ID_STR //COLUMN DATA PATH
},
{
OPCODE_STR, //COLUMN HEADER
TABLE_MIN_HEADER_LENGTH(OPCODE_STR), //COLUMN MAX STR WIDTH
DS_CEL_PATH PATH_KEY_DELIM OPCODE_STR //COLUMN DATA PATH
},
{
SUBOPCODE_STR, //COLUMN HEADER
TABLE_MIN_HEADER_LENGTH(SUBOPCODE_STR), //COLUMN MAX STR WIDTH
DS_CEL_PATH PATH_KEY_DELIM SUBOPCODE_STR //COLUMN DATA PATH
},
{
CE_DESCRIPTION_STR, //COLUMN HEADER
TABLE_MIN_HEADER_LENGTH(CE_DESCRIPTION_STR), //COLUMN MAX STR WIDTH
DS_CEL_PATH PATH_KEY_DELIM CE_DESCRIPTION_STR //COLUMN DATA PATH
}
}
};
PRINTER_DATA_SET_ATTRIBS ShowCmdEffectLogDataSetAttribs =
{
NULL,
&ShowCelTableAttributes
};
/**
Create the string from Command Effect Bits.
param[in] Value is the value to be printed.
param[in] SensorType - type of sensor
**/
STATIC
CHAR16 *
GetCommandEffectDescriptionStr(
IN COMMAND_EFFECT_LOG_ENTRY CelEntry
)
{
CHAR16 *pReturnBuffer = NULL;
// Return immediately if opcode not supported
if (0 == CelEntry.EffectName.AsUint32) {
pReturnBuffer = CatSPrintClean(pReturnBuffer, OPCODE_NOT_SUPPORTED);
return pReturnBuffer;
}
if (1 == CelEntry.EffectName.Separated.NoEffects) {
if (NULL != pReturnBuffer) {
pReturnBuffer = CatSPrintClean(pReturnBuffer, L", ");
}
pReturnBuffer = CatSPrintClean(pReturnBuffer, NO_EFFECTS);
}
if (1 == CelEntry.EffectName.Separated.SecurityStateChange) {
if (NULL != pReturnBuffer) {
pReturnBuffer = CatSPrintClean(pReturnBuffer, L", ");
}
pReturnBuffer = CatSPrintClean(pReturnBuffer, SECURITY_STATE_CHANGE);
}
if (1 == CelEntry.EffectName.Separated.DimmConfigChangeAfterReboot) {
if (NULL != pReturnBuffer) {
pReturnBuffer = CatSPrintClean(pReturnBuffer, L", ");
}
pReturnBuffer = CatSPrintClean(pReturnBuffer, DIMM_CONFIGURATION_CHANGE_AFTER_REBOOT);
}
if (1 == CelEntry.EffectName.Separated.ImmediateDimmConfigChange) {
if (NULL != pReturnBuffer) {
pReturnBuffer = CatSPrintClean(pReturnBuffer, L", ");
}
pReturnBuffer = CatSPrintClean(pReturnBuffer, IMMEDIATE_DIMM_CONFIGURATION_CHANGE);
}
if (1 == CelEntry.EffectName.Separated.QuiesceAllIo) {
if (NULL != pReturnBuffer) {
pReturnBuffer = CatSPrintClean(pReturnBuffer, L", ");
}
pReturnBuffer = CatSPrintClean(pReturnBuffer, QUIESCE_ALL_IO);
}
if (1 == CelEntry.EffectName.Separated.ImmediateDimmDataChange) {
if (NULL != pReturnBuffer) {
pReturnBuffer = CatSPrintClean(pReturnBuffer, L", ");
}
pReturnBuffer = CatSPrintClean(pReturnBuffer, IMMEDIATE_DIMM_DATA_CHANGE);
}
if (1 == CelEntry.EffectName.Separated.TestMode) {
if (NULL != pReturnBuffer) {
pReturnBuffer = CatSPrintClean(pReturnBuffer, L", ");
}
pReturnBuffer = CatSPrintClean(pReturnBuffer, TEST_MODE);
}
if (1 == CelEntry.EffectName.Separated.DebugMode) {
if (NULL != pReturnBuffer) {
pReturnBuffer = CatSPrintClean(pReturnBuffer, L", ");
}
pReturnBuffer = CatSPrintClean(pReturnBuffer, DEBUG_MODE);
}
if (1 == CelEntry.EffectName.Separated.ImmediateDimmPolicyChange) {
if (NULL != pReturnBuffer) {
pReturnBuffer = CatSPrintClean(pReturnBuffer, L", ");
}
pReturnBuffer = CatSPrintClean(pReturnBuffer, IMMEDIATE_DIMM_POLICY_CHANGE);
}
return pReturnBuffer;
}
/**
Register the show -cel command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowCelCommand(
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&ShowCelCommandSyntax);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Get command effect log command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
ShowCelCommand(
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
PRINT_CONTEXT *pPrinterCtx = NULL;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
DIMM_INFO *pDimms = NULL;
UINT32 DimmCount = 0;
CHAR16 *pDimmsValue = NULL;
UINT16 *pDimmIds = NULL;
UINT32 DimmIdsNum = 0;
UINT32 DimmIndex = 0;
COMMAND_EFFECT_LOG_ENTRY *pCelEntry = NULL;
UINT32 EntryCount = 0;
UINT32 DimmHandle = 0;
UINT32 DimmIdIndex = 0;
UINT32 CelEntryIndex = 0;
CHAR16 DimmStr[MAX_DIMM_UID_LENGTH];
CHAR16 *pPath = NULL;
CHAR16 *pCommandEffectDescription = NULL;
NVDIMM_ENTRY();
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("pCmd parameter is NULL.\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// Populate the list of DIMM_INFO structures with relevant information
ReturnCode = GetDimmList(pNvmDimmConfigProtocol, pCmd, DIMM_INFO_CATEGORY_NONE, &pDimms, &DimmCount);
if (EFI_ERROR(ReturnCode)) {
if (ReturnCode == EFI_NOT_FOUND) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_INFO_NO_FUNCTIONAL_DIMMS);
}
goto Finish;
}
// check targets
if (ContainTarget(pCmd, DIMM_TARGET)) {
pDimmsValue = GetTargetValue(pCmd, DIMM_TARGET);
ReturnCode = GetDimmIdsFromString(pCmd, pDimmsValue, pDimms, DimmCount, &pDimmIds, &DimmIdsNum);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Target value is not a valid Dimm ID");
goto Finish;
}
if (!AllDimmsInListAreManageable(pDimms, DimmCount, pDimmIds, DimmIdsNum)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_UNMANAGEABLE_DIMM);
goto Finish;
}
if (!AllDimmsInListInSupportedConfig(pDimms, DimmCount, pDimmIds, DimmIdsNum)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_POPULATION_VIOLATION);
goto Finish;
}
}
// If no dimm IDs are specified get IDs from all dimms
if (DimmIdsNum == 0) {
ReturnCode = GetManageableDimmsNumberAndId(pNvmDimmConfigProtocol, TRUE, &DimmIdsNum, &pDimmIds);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
if (DimmIdsNum == 0) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_INFO_NO_MANAGEABLE_DIMMS);
goto Finish;
}
}
// Traverse each DIMM
for (DimmIndex = 0; DimmIndex < DimmCount; DimmIndex++) {
if (!ContainUint(pDimmIds, DimmIdsNum, pDimms[DimmIndex].DimmID)) {
continue;
}
if ((MANAGEMENT_VALID_CONFIG != pDimms[DimmIndex].ManageabilityState)
|| (TRUE == pDimms[DimmIndex].IsInPopulationViolation)){
continue;
}
// Get CEL table for each DIMM
ReturnCode = pNvmDimmConfigProtocol->GetCommandEffectLog(pNvmDimmConfigProtocol, pDimms[DimmIndex].DimmID, &pCelEntry, &EntryCount);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
// Retrieve DimmHandle and DimmIdIndex for given DimmId
ReturnCode = GetDimmHandleByPid(pDimms[DimmIndex].DimmID, pDimms, DimmCount, &DimmHandle, &DimmIdIndex);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
// Retrieve DimmId as string based on preferences
ReturnCode = GetPreferredDimmIdAsString(pDimms[DimmIdIndex].DimmHandle, pDimms[DimmIdIndex].DimmUid, DimmStr, MAX_DIMM_UID_LENGTH);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
PRINTER_BUILD_KEY_PATH(pPath, DS_DIMM_INDEX_PATH, DimmIndex);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DIMM_ID_STR, DimmStr);
for (CelEntryIndex = 0; CelEntryIndex < EntryCount; CelEntryIndex++) {
PRINTER_BUILD_KEY_PATH(pPath, DS_CEL_INDEX_PATH, DimmIndex, CelEntryIndex);
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, OPCODE_STR, (UINT8)pCelEntry[CelEntryIndex].Opcode.Separated.Opcode, HEX);
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, SUBOPCODE_STR, (UINT8)pCelEntry[CelEntryIndex].Opcode.Separated.SubOpcode, HEX);
pCommandEffectDescription = GetCommandEffectDescriptionStr(pCelEntry[CelEntryIndex]);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, CE_DESCRIPTION_STR, pCommandEffectDescription);
FREE_POOL_SAFE(pCommandEffectDescription);
}
FREE_POOL_SAFE(pCelEntry);
}
//Switch text output type to display as a table
PRINTER_ENABLE_TEXT_TABLE_FORMAT(pPrinterCtx);
//Specify table attributes
PRINTER_CONFIGURE_DATA_ATTRIBUTES(pPrinterCtx, DS_ROOT_PATH, &ShowCmdEffectLogDataSetAttribs);
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FREE_POOL_SAFE(pPath);
FREE_POOL_SAFE(pCommandEffectDescription);
FREE_POOL_SAFE(pDimms);
FREE_POOL_SAFE(pDimmIds);
FREE_POOL_SAFE(pCelEntry);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowCelCommand.h 0000664 0000000 0000000 00000002205 14165347476 0020741 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SHOW_CEL_COMMAND_H_
#define _SHOW_CEL_COMMAND_H_
#include
#include "NvmInterface.h"
#include "Common.h"
// Command Effect Description strings
#define NO_EFFECTS L"NE"
#define SECURITY_STATE_CHANGE L"SSC"
#define DIMM_CONFIGURATION_CHANGE_AFTER_REBOOT L"DCC"
#define IMMEDIATE_DIMM_CONFIGURATION_CHANGE L"IDCC"
#define QUIESCE_ALL_IO L"QIO"
#define IMMEDIATE_DIMM_DATA_CHANGE L"IDDC"
#define TEST_MODE L"TM"
#define DEBUG_MODE L"DM"
#define IMMEDIATE_DIMM_POLICY_CHANGE L"IDPC"
#define OPCODE_NOT_SUPPORTED L"N/A"
/**
Register syntax of show -error
**/
EFI_STATUS
RegisterShowCelCommand(
);
/**
Get command effect log command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
ShowCelCommand(
IN struct Command *pCmd
);
#endif ipmctl-03.00.00.0423/DcpmPkg/cli/ShowCmdAccessPolicyCommand.c 0000664 0000000 0000000 00000027174 14165347476 0023252 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include
#include
#include "Debug.h"
#include "Types.h"
#include "Utility.h"
#include "NvmDimmCli.h"
#include "NvmInterface.h"
#include "CommandParser.h"
#include "ShowCmdAccessPolicyCommand.h"
#include "Common.h"
#include "Convert.h"
#define DS_ROOT_PATH L"/OpCodePolicyList"
#define DS_DIMM_PATH L"/OpCodePolicyList/Dimm"
#define DS_DIMM_INDEX_PATH L"/OpCodePolicyList/Dimm[%d]"
#define DS_OPCODE_PATH L"/OpCodePolicyList/Dimm/OpCode"
#define DS_OPCODE_INDEX_PATH L"/OpCodePolicyList/Dimm[%d]/OpCode[%d]"
/**
Command syntax definition
**/
struct Command ShowCmdAccessPolicyCommand =
{
SHOW_VERB, //!< verb
/**
options
**/
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"", HELP_VERBOSE_DETAILS_TEXT,FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
#ifdef OS_BUILD
{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP,HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#else
{L"", L"", L"", L"", L"",FALSE, ValueOptional}
#endif
},
/**
targets
**/
{
{ DIMM_TARGET, L"", HELP_TEXT_DIMM_IDS, FALSE, ValueOptional },
{ CAP_TARGET, L"", L"", TRUE, ValueEmpty },
},
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Show command access policy (CAP) restrictions for one ore more " PMEM_MODULE_STR L"(s).", //!< help
ShowCmdAccessPolicy, //!< run function
TRUE, //!< enable print control support
};
// Table heading names
#define OPCODE_STR L"Opcode"
#define SUBOPCODE_STR L"SubOpcode"
#define RESTRICTION_STR L"Restriction"
/*
* SHOW CAP ATTRIBUTES (4 columns)
* DimmID | Opcode | SubOpcode | Restricted
* ===========================================
* 0x0001 | X | X | X
* ...
*/
PRINTER_TABLE_ATTRIB ShowCapTableAttributes =
{
{
{
DIMM_ID_STR, //COLUMN HEADER
DIMM_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_DIMM_PATH PATH_KEY_DELIM DIMM_ID_STR //COLUMN DATA PATH
},
{
OPCODE_STR, //COLUMN HEADER
TABLE_MIN_HEADER_LENGTH(OPCODE_STR), //COLUMN MAX STR WIDTH
DS_OPCODE_PATH PATH_KEY_DELIM OPCODE_STR //COLUMN DATA PATH
},
{
SUBOPCODE_STR, //COLUMN HEADER
TABLE_MIN_HEADER_LENGTH(SUBOPCODE_STR), //COLUMN MAX STR WIDTH
DS_OPCODE_PATH PATH_KEY_DELIM SUBOPCODE_STR //COLUMN DATA PATH
},
{
RESTRICTION_STR, //COLUMN HEADER
CAP_MB_RESTRICTION_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_OPCODE_PATH PATH_KEY_DELIM RESTRICTION_STR //COLUMN DATA PATH
}
}
};
PRINTER_DATA_SET_ATTRIBS ShowCmdAccessPolicyDataSetAttribs =
{
NULL,
&ShowCapTableAttributes
};
/**
Register the show cmd access policy command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowCmdAccessPolicyCommand(
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&ShowCmdAccessPolicyCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Execute the show cmd access policy command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_NOT_FOUND failed to open Config protocol, or run-time preferences could
not be retrieved
@retval Other errors returned by the driver
**/
EFI_STATUS
ShowCmdAccessPolicy(
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
UINT32 DimmIndex = 0;
UINT32 OpCodeIndex = 0;
CHAR16 *pTargetValue = NULL;
DIMM_INFO *pDimms = NULL;
UINT32 DimmCount = 0;
UINT16 *pDimmIds = NULL;
UINT32 DimmIdsCount = 0;
COMMAND_ACCESS_POLICY_ENTRY *pCapEntries = NULL;
COMMAND_ACCESS_POLICY_ENTRY *pCapEntry = NULL;
PRINT_CONTEXT *pPrinterCtx = NULL;
CHAR16 *pPath = NULL;
UINT32 DimmHandle = 0;
UINT32 DimmIdIndex = 0;
CHAR16 DimmStr[MAX_DIMM_UID_LENGTH];
CHAR16 *RestrictionStr = NULL;
UINT32 CapCount = 0;
NVDIMM_ENTRY();
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
/**
Make sure we can access the config protocol
**/
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// Populate the list of DIMM_INFO structures with relevant information
ReturnCode = GetAllDimmList(pNvmDimmConfigProtocol, pCmd, DIMM_INFO_CATEGORY_NONE, &pDimms, &DimmCount);
if (EFI_ERROR(ReturnCode)) {
if(ReturnCode == EFI_NOT_FOUND) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_INFO_NO_FUNCTIONAL_DIMMS);
}
goto Finish;
}
// check targets
if (ContainTarget(pCmd, DIMM_TARGET)) {
pTargetValue = GetTargetValue(pCmd, DIMM_TARGET);
ReturnCode = GetDimmIdsFromString(pCmd, pTargetValue, pDimms, DimmCount, &pDimmIds, &DimmIdsCount);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("Failed on GetDimmIdsFromString");
goto Finish;
}
if (!AllDimmsInListAreManageable(pDimms, DimmCount, pDimmIds, DimmIdsCount)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_UNMANAGEABLE_DIMM);
goto Finish;
}
}
/** If no dimm IDs are specified get IDs from all dimms **/
if (DimmIdsCount == 0) {
ReturnCode = GetAllManageableDimmsNumberAndId(pNvmDimmConfigProtocol, FALSE, &DimmIdsCount, &pDimmIds);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
if (DimmIdsCount == 0) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_INFO_NO_MANAGEABLE_DIMMS);
goto Finish;
}
}
/**
Retrieve the count of access policy entries.
**/
ReturnCode = pNvmDimmConfigProtocol->GetCommandAccessPolicy(pNvmDimmConfigProtocol, pDimmIds[0], &CapCount, NULL);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
pCapEntries = AllocateZeroPool(sizeof(*pCapEntries) * CapCount * DimmIdsCount);
if (pCapEntries == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
for (DimmIndex = 0; DimmIndex < DimmIdsCount; DimmIndex++) {
/**
Retrieve all CAP for each DIMM
**/
ReturnCode = pNvmDimmConfigProtocol->GetCommandAccessPolicy(pNvmDimmConfigProtocol, pDimmIds[DimmIndex], &CapCount, &pCapEntries[DimmIndex*CapCount]);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("Failed to get the access policy for pDimmIds[%d] - ReturnCode=0x%x",
DimmIndex, ReturnCode);
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
/*
Retrieve DimmHandle and DimmIdIndex for given DimmId
*/
ReturnCode = GetDimmHandleByPid(pDimmIds[DimmIndex], pDimms, DimmCount, &DimmHandle, &DimmIdIndex);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
/*
Retrieve DimmId as string based on preferences
*/
ReturnCode = GetPreferredDimmIdAsString(pDimms[DimmIdIndex].DimmHandle, pDimms[DimmIdIndex].DimmUid, DimmStr, MAX_DIMM_UID_LENGTH);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
PRINTER_BUILD_KEY_PATH(pPath, DS_DIMM_INDEX_PATH, DimmIndex);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DIMM_ID_STR, DimmStr);
for (OpCodeIndex = 0; OpCodeIndex < CapCount; OpCodeIndex++) {
PRINTER_BUILD_KEY_PATH(pPath, DS_OPCODE_INDEX_PATH, DimmIndex, OpCodeIndex);
pCapEntry = &(pCapEntries[DimmIndex * CapCount + OpCodeIndex]);
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, OPCODE_STR, pCapEntry->Opcode, HEX);
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, SUBOPCODE_STR, pCapEntry->SubOpcode, HEX);
switch (pCapEntry->Restriction) {
case COMMAND_ACCESS_POLICY_RESTRICTION_NONE:
RestrictionStr = HiiGetString(gNvmDimmCliHiiHandle, STRING_TOKEN(STR_DCPMM_RESTRICTION_NONE), NULL);
break;
case COMMAND_ACCESS_POLICY_RESTRICTION_BIOSONLY:
RestrictionStr = HiiGetString(gNvmDimmCliHiiHandle, STRING_TOKEN(STR_DCPMM_RESTRICTION_BIOS_ONLY), NULL);
break;
case COMMAND_ACCESS_POLICY_RESTRICTION_SMBUSONLY:
RestrictionStr = HiiGetString(gNvmDimmCliHiiHandle, STRING_TOKEN(STR_DCPMM_RESTRICTION_SMBUS_ONLY), NULL);
break;
case COMMAND_ACCESS_POLICY_RESTRICTION_BIOSSMBUSONLY:
RestrictionStr = HiiGetString(gNvmDimmCliHiiHandle, STRING_TOKEN(STR_DCPMM_RESTRICTION_BIOS_SMBUS_ONLY), NULL);
break;
case COMMAND_ACCESS_POLICY_RESTRICTION_MGMTONLY:
RestrictionStr = HiiGetString(gNvmDimmCliHiiHandle, STRING_TOKEN(STR_DCPMM_RESTRICTION_MGMT_ONLY), NULL);
break;
case COMMAND_ACCESS_POLICY_RESTRICTION_MGMTBIOSONLY:
RestrictionStr = HiiGetString(gNvmDimmCliHiiHandle, STRING_TOKEN(STR_DCPMM_RESTRICTION_MGMT_BIOS_ONLY), NULL);
break;
case COMMAND_ACCESS_POLICY_RESTRICTION_MGMTSMBUSONLY:
RestrictionStr = HiiGetString(gNvmDimmCliHiiHandle, STRING_TOKEN(STR_DCPMM_RESTRICTION_MGMT_SMBUS_ONLY), NULL);
break;
case COMMAND_ACCESS_POLICY_RESTRICTION_MGMTBIOSSMBUSONLY:
RestrictionStr = HiiGetString(gNvmDimmCliHiiHandle, STRING_TOKEN(STR_DCPMM_RESTRICTION_MGMT_BIOS_SMBUS_ONLY), NULL);
break;
case COMMAND_ACCESS_POLICY_RESTRICTION_UNSUPPORTED:
RestrictionStr = HiiGetString(gNvmDimmCliHiiHandle, STRING_TOKEN(STR_DCPMM_RESTRICTION_UNSUPPORTED), NULL);;
break;
default:
RestrictionStr = HiiGetString(gNvmDimmCliHiiHandle, STRING_TOKEN(STR_DCPMM_RESTRICTION_INVALID), NULL);
break;
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, RESTRICTION_STR, RestrictionStr);
}
FREE_POOL_SAFE(RestrictionStr);
}
//Switch text output type to display as a table
PRINTER_ENABLE_TEXT_TABLE_FORMAT(pPrinterCtx);
//Specify table attributes
PRINTER_CONFIGURE_DATA_ATTRIBUTES(pPrinterCtx, DS_ROOT_PATH, &ShowCmdAccessPolicyDataSetAttribs);
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FREE_POOL_SAFE(RestrictionStr);
FREE_POOL_SAFE(pPath);
FREE_POOL_SAFE(pDimmIds);
FREE_POOL_SAFE(pCapEntries);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowCmdAccessPolicyCommand.h 0000664 0000000 0000000 00000001665 14165347476 0023254 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SHOW_CAP_COMMAND_H_
#define _SHOW_CAP_COMMAND_H_
#include "CommandParser.h"
/**
Register the show cmd access policy command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowCmdAccessPolicyCommand(
);
/**
Execute the show cmd access policy command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS on success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_NOT_FOUND failed to open Config protocol, or run-time preferences could
not be retrieved
@retval Other errors returned by the driver
**/
EFI_STATUS
ShowCmdAccessPolicy(
IN struct Command *pCmd
);
#endif /* _SHOW_CAP_COMMAND_H_*/
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowDimmsCommand.c 0000664 0000000 0000000 00000220322 14165347476 0021304 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include
#include
#include
#include "ShowDimmsCommand.h"
#include
#include
#include
#include
#include
#include "Common.h"
#include "NvmDimmCli.h"
#include
#include
#include
#include
#include
#include
#define DS_ROOT_PATH L"/DimmList"
#define DS_DIMM_PATH L"/DimmList/Dimm"
#define DS_DIMM_INDEX_PATH L"/DimmList/Dimm[%d]"
/*
* PRINT LIST ATTRIBUTES
* ---DimmId=0x0001---
* Capacity=125.7 GiB
* LockState=Locked
* HealthState=Healthy
* ...
*/
PRINTER_LIST_ATTRIB ShowDimmListAttributes =
{
{
{
DIMM_NODE_STR, //GROUP LEVEL TYPE
L"---" DIMM_ID_STR L"=$(" DIMM_ID_STR L")---", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT L"%ls=%ls", //NULL or KEY VAL FORMAT STR
DIMM_ID_STR //NULL or IGNORE KEY LIST (K1;K2)
}
}
};
/*
* PRINTER TABLE ATTRIBUTES (5 columns)
* DimmID | Capacity | LockState | HealthState | FWVersion
* ========================================================
* 0x0001 | X | X | X | X
* ...
*/
PRINTER_TABLE_ATTRIB ShowDimmTableAttributes =
{
{
{
DIMM_ID_STR, //COLUMN HEADER
DIMM_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_DIMM_PATH PATH_KEY_DELIM DIMM_ID_STR //COLUMN DATA PATH
},
{
CAPACITY_STR, //COLUMN HEADER
CAPACITY_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_DIMM_PATH PATH_KEY_DELIM CAPACITY_STR //COLUMN DATA PATH
},
{
SECURITY_STR, //COLUMN HEADER
SECURITY_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_DIMM_PATH PATH_KEY_DELIM SECURITY_STR //COLUMN DATA PATH
},
{
HEALTH_STR, //COLUMN HEADER
HEALTH_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_DIMM_PATH PATH_KEY_DELIM HEALTH_STR //COLUMN DATA PATH
},
{
FW_VER_STR, //COLUMN HEADER
FW_VERSION_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_DIMM_PATH PATH_KEY_DELIM FW_VER_STR //COLUMN DATA PATH
}
}
};
PRINTER_DATA_SET_ATTRIBS ShowDimmDataSetAttribs =
{
&ShowDimmListAttributes,
&ShowDimmTableAttributes
};
extern BOOLEAN gDisplayNulls;
extern UINT32 gNullValuesEncounteredForDisplay;
extern CHAR16* gNullValueToDisplay;
/* Command syntax definition */
struct Command ShowDimmsCommand =
{
SHOW_VERB, //!< verb
/**
options
**/
{
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"",HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{ALL_OPTION_SHORT, ALL_OPTION, L"", L"",HELP_ALL_DETAILS_TEXT, FALSE, ValueEmpty},
{DISPLAY_OPTION_SHORT, DISPLAY_OPTION, L"", HELP_TEXT_ATTRIBUTES,HELP_DISPLAY_DETAILS_TEXT, FALSE, ValueRequired},
{UNITS_OPTION_SHORT, UNITS_OPTION, L"", UNITS_OPTION_HELP,HELP_UNIT_DETAILS_TEXT, FALSE, ValueRequired}
#ifdef OS_BUILD
,{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP,HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#endif
},
/**
targets
**/
{
{DIMM_TARGET, L"", HELP_TEXT_DIMM_IDS, TRUE, ValueOptional},
{SOCKET_TARGET, L"", HELP_TEXT_SOCKET_IDS, FALSE, ValueOptional}
},
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Show information about one or more " PMEM_MODULES_STR L".", //!< help
ShowDimms, //!< run function
TRUE, //!< enable print control support
};
CHAR16 *mppAllowedShowDimmsDisplayValues[] =
{
DIMM_ID_STR,
SOCKET_ID_STR,
FW_VER_STR,
FW_API_VER_STR,
FW_ACTIVE_API_VER_STR,
INTERFACE_FORMAT_CODE_STR,
CAPACITY_STR,
MANAGEABILITY_STR,
POPULATION_VIOLATION_STR,
SECURITY_STR,
SVN_DOWNGRADE_OPT_IN_STR,
SEP_OPT_IN_STR,
S3_RESUME_OPT_IN_STR,
FW_ACTIVATE_OPT_IN_STR,
HEALTH_STR,
HEALTH_STATE_REASON_STR,
FORM_FACTOR_STR,
VENDOR_ID_STR,
MANUFACTURER_ID_STR,
DEVICE_ID_STR,
REVISION_ID_STR,
SUBSYSTEM_VENDOR_ID_STR,
SUBSYSTEM_DEVICE_ID_STR,
SUBSYSTEM_REVISION_ID_STR,
CONTROLLER_REVISION_ID_STR,
MANUFACTURING_INFO_VALID,
MANUFACTURING_LOCATION,
MANUFACTURING_DATE,
PART_NUMBER_STR,
SERIAL_NUMBER_STR,
DEVICE_LOCATOR_STR,
MEMORY_CONTROLLER_STR,
DATA_WIDTH_STR,
TOTAL_WIDTH_STR,
SPEED_STR,
MEMORY_MODE_CAPACITY_STR,
APPDIRECT_MODE_CAPACITY_STR,
UNCONFIGURED_CAPACITY_STR,
PACKAGE_SPARING_ENABLED_STR,
PACKAGE_SPARING_CAPABLE_STR,
PACKAGE_SPARES_AVAILABLE_STR,
IS_NEW_STR,
BANK_LABEL_STR,
MEMORY_TYPE_STR,
AVG_PWR_REPORTING_TIME_CONSTANT,
MANUFACTURER_STR,
CHANNEL_ID_STR,
SLOT_ID_STR,
CHANNEL_POS_STR,
PEAK_POWER_BUDGET_STR,
AVG_POWER_LIMIT_STR,
AVG_POWER_TIME_CONSTANT_STR,
MEMORY_BANDWIDTH_BOOST_FEATURE_STR,
MEMORY_BANDWIDTH_BOOST_MAX_POWER_LIMIT_STR,
MEMORY_BANDWIDTH_BOOST_AVERAGE_POWER_TIME_CONSTANT_STR,
MAX_AVG_POWER_LIMIT_STR,
MAX_MEMORY_BANDWIDTH_BOOST_MAX_POWER_LIMIT,
MAX_MEMORY_BANDWIDTH_BOOST_AVERAGE_POWER_TIME_CONSTANT,
MEMORY_BANDWIDTH_BOOST_AVERAGE_POWER_TIME_CONSTANT_STEP,
MAX_AVERAGE_POWER_REPORTING_TIME_CONSTANT,
AVERAGE_POWER_REPORTING_TIME_CONSTANT_STEP,
LATCHED_LAST_SHUTDOWN_STATUS_STR,
UNLATCHED_LAST_SHUTDOWN_STATUS_STR,
MAX_MEDIA_TEMPERATURE_STR,
MAX_CONTROLLER_TEMPERATURE_STR,
THERMAL_THROTTLE_LOSS_STR,
DIMM_HANDLE_STR,
DIMM_UID_STR,
MODES_SUPPORTED_STR,
SECURITY_CAPABILITIES_STR,
MASTER_PASS_ENABLED_STR,
DIMM_CONFIG_STATUS_STR,
SKU_VIOLATION_STR,
ARS_STATUS_STR,
OVERWRITE_STATUS_STR,
LAST_SHUTDOWN_TIME_STR,
INACCESSIBLE_CAPACITY_STR,
RESERVED_CAPACITY_STR,
VIRAL_POLICY_STR,
VIRAL_STATE_STR,
AIT_DRAM_ENABLED_STR,
BOOT_STATUS_STR,
PHYSICAL_ID_STR,
ERROR_INJECT_ENABLED_STR,
MEDIA_TEMP_INJ_ENABLED_STR,
SW_TRIGGERS_ENABLED_STR,
SW_TRIGGER_ENABLED_DETAILS_STR,
POISON_ERR_INJ_CTR_STR,
POISON_ERR_CLR_CTR_STR,
MEDIA_TEMP_INJ_CTR_STR,
SW_TRIGGER_CTR_STR,
BOOT_STATUS_REGISTER_STR,
DCPMM_AVERAGE_POWER_STR,
AVERAGE_12V_POWER_STR,
AVERAGE_1_2V_POWER_STR,
EXTENDED_ADR_ENABLED_STR,
PPC_EXTENDED_ADR_ENABLED_STR,
LATCH_SYSTEM_SHUTDOWN_STATE_STR,
PREV_PWR_CYCLE_LATCH_SYSTEM_SHUTDOWN_STATE_STR,
MIXED_SKU_STR,
FIPS_MODE_STATUS_STR
};
CHAR16 *mppAllowedShowDimmsConfigStatuses[] = {
CONFIG_STATUS_VALUE_VALID,
CONFIG_STATUS_VALUE_NOT_CONFIG,
CONFIG_STATUS_VALUE_BAD_CONFIG,
CONFIG_STATUS_VALUE_BROKEN_INTERLEAVE,
CONFIG_STATUS_VALUE_REVERTED,
CONFIG_STATUS_VALUE_UNSUPPORTED,
CONFIG_STATUS_VALUE_PARTIALLY_SUPPORTED,
};
CHAR16 *pOnlyManageableAllowedDisplayValues[] = {
MANUFACTURER_ID_STR,
CONTROLLER_REVISION_ID_STR,
MEMORY_MODE_CAPACITY_STR,
APPDIRECT_MODE_CAPACITY_STR,
UNCONFIGURED_CAPACITY_STR,
INACCESSIBLE_CAPACITY_STR,
RESERVED_CAPACITY_STR,
PACKAGE_SPARING_CAPABLE_STR,
PACKAGE_SPARING_ENABLED_STR,
PACKAGE_SPARES_AVAILABLE_STR,
IS_NEW_STR,
AVG_PWR_REPORTING_TIME_CONSTANT,
VIRAL_POLICY_STR,
VIRAL_STATE_STR,
PEAK_POWER_BUDGET_STR,
AVG_POWER_LIMIT_STR,
AVG_POWER_TIME_CONSTANT_STR,
MEMORY_BANDWIDTH_BOOST_FEATURE_STR,
MEMORY_BANDWIDTH_BOOST_MAX_POWER_LIMIT_STR,
MEMORY_BANDWIDTH_BOOST_AVERAGE_POWER_TIME_CONSTANT_STR,
MAX_AVG_POWER_LIMIT_STR,
MAX_MEMORY_BANDWIDTH_BOOST_MAX_POWER_LIMIT,
MAX_MEMORY_BANDWIDTH_BOOST_AVERAGE_POWER_TIME_CONSTANT,
MEMORY_BANDWIDTH_BOOST_AVERAGE_POWER_TIME_CONSTANT_STEP,
MAX_AVERAGE_POWER_REPORTING_TIME_CONSTANT,
AVERAGE_POWER_REPORTING_TIME_CONSTANT_STEP,
LATCHED_LAST_SHUTDOWN_STATUS_STR,
UNLATCHED_LAST_SHUTDOWN_STATUS_STR,
MAX_MEDIA_TEMPERATURE_STR,
MAX_CONTROLLER_TEMPERATURE_STR,
THERMAL_THROTTLE_LOSS_STR,
LAST_SHUTDOWN_TIME_STR,
MODES_SUPPORTED_STR,
SECURITY_CAPABILITIES_STR,
MASTER_PASS_ENABLED_STR,
DIMM_CONFIG_STATUS_STR,
SKU_VIOLATION_STR,
ARS_STATUS_STR,
OVERWRITE_STATUS_STR,
AIT_DRAM_ENABLED_STR,
BOOT_STATUS_STR,
ERROR_INJECT_ENABLED_STR,
MEDIA_TEMP_INJ_ENABLED_STR,
SW_TRIGGERS_ENABLED_STR,
SW_TRIGGER_ENABLED_DETAILS_STR,
POISON_ERR_INJ_CTR_STR,
POISON_ERR_CLR_CTR_STR,
MEDIA_TEMP_INJ_CTR_STR,
SW_TRIGGER_CTR_STR,
BOOT_STATUS_REGISTER_STR,
DCPMM_AVERAGE_POWER_STR,
AVERAGE_12V_POWER_STR,
AVERAGE_1_2V_POWER_STR,
EXTENDED_ADR_ENABLED_STR,
PPC_EXTENDED_ADR_ENABLED_STR,
LATCH_SYSTEM_SHUTDOWN_STATE_STR,
PREV_PWR_CYCLE_LATCH_SYSTEM_SHUTDOWN_STATE_STR,
MIXED_SKU_STR,
FIPS_MODE_STATUS_STR
};
/* local functions */
STATIC CHAR16 *ManageabilityToString(UINT8 ManageabilityState);
STATIC CHAR16 *PopulationViolationToString(UINT8 ManageabilityState);
STATIC CHAR16 *FormFactorToString(UINT8 FormFactor);
/*
* Register the show dimms command
*/
EFI_STATUS
RegisterShowDimmsCommand(
)
{
EFI_STATUS Rc = EFI_SUCCESS;
NVDIMM_ENTRY();
Rc = RegisterCommand(&ShowDimmsCommand);
NVDIMM_EXIT_I64(Rc);
return Rc;
}
/**
Get manageability state for Dimm
@param[in] pDimm the DIMM_INFO struct
@retval BOOLEAN whether or not dimm is manageable
**/
BOOLEAN
IsDimmManageableByDimmInfo(
IN DIMM_INFO *pDimm
)
{
if (pDimm == NULL)
{
return FALSE;
}
return IsDimmManageableByValues(pDimm->SubsystemVendorId,
pDimm->InterfaceFormatCodeNum,
pDimm->InterfaceFormatCode,
pDimm->SubsystemDeviceId,
pDimm->FwVer.FwApiMajor,
pDimm->FwVer.FwApiMinor);
}
EFI_STATUS IsDimmsMixedSkuCfg(PRINT_CONTEXT *pPrinterCtx,
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol,
BOOLEAN *pIsMixedSku,
BOOLEAN *pIsSkuViolation)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
UINT32 DimmCount = 0;
DIMM_INFO *pDimms = NULL;
UINT32 i;
ReturnCode = pNvmDimmConfigProtocol->GetDimmCount(pNvmDimmConfigProtocol, &DimmCount);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
return ReturnCode;
}
pDimms = AllocateZeroPool(sizeof(*pDimms) * DimmCount);
if (pDimms == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
return ReturnCode;
}
/** retrieve the DIMM list **/
ReturnCode = pNvmDimmConfigProtocol->GetDimms(pNvmDimmConfigProtocol, DimmCount,
DIMM_INFO_CATEGORY_PACKAGE_SPARING, pDimms);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_ABORTED;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
NVDIMM_WARN("Failed to retrieve the DIMM inventory found in NFIT");
goto Finish;
}
*pIsMixedSku = FALSE;
*pIsSkuViolation = FALSE;
for (i = 0; i < DimmCount; ++i)
{
if (FALSE == IsDimmManageableByDimmInfo(&pDimms[i]))
{
continue;
}
if (pDimms[i].SKUViolation)
{
*pIsSkuViolation = TRUE;
}
if (NVM_SUCCESS != SkuComparison(pDimms[0].SkuInformation,
pDimms[i].SkuInformation))
{
*pIsMixedSku = TRUE;
}
}
Finish:
FreePool(pDimms);
return ReturnCode;
}
/**
Execute the show dimms command
**/
EFI_STATUS
ShowDimms(
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_STATUS TempReturnCode = EFI_SUCCESS;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
UINT32 DimmCount = 0;
DIMM_INFO *pDimms = NULL;
DIMM_INFO *pAllDimms = NULL;
UINT16 *pSocketIds = NULL;
UINT32 SocketsNum = 0;
UINT16 *pDimmIds = NULL;
UINT32 DimmIdsNum = 0;
CHAR16 *pSocketsValue = NULL;
CHAR16 *pSecurityStr = NULL;
CHAR16 *pSVNDowngradeStr = NULL;
CHAR16 *pSecureErasePolicyStr = NULL;
CHAR16 *pS3ResumeStr = NULL;
CHAR16 *pFwActivateStr = NULL;
CHAR16 *pHealthStr = NULL;
CHAR16 *pHealthStateReasonStr = NULL;
CHAR16 *pManageabilityStr = NULL;
CHAR16 *pPopulationViolationStr = NULL;
CHAR16 *pFormFactorStr = NULL;
CHAR16 *pDimmsValue = NULL;
CHAR16 TmpFwVerString[MAX(FW_VERSION_LEN, FW_API_VERSION_LEN)];
UINT32 DimmIndex = 0;
UINT32 Index1 = 0;
UINT32 Index2 = 0;
UINT32 Index3 = 0;
UINT16 UnitsOption = DISPLAY_SIZE_UNIT_UNKNOWN;
UINT16 UnitsToDisplay = FixedPcdGet16(PcdDcpmmCliDefaultCapacityUnit);
BOOLEAN Found = FALSE;
BOOLEAN ShowAll = FALSE;
BOOLEAN ShowTableView = FALSE;
BOOLEAN ContainSocketTarget = FALSE;
COMMAND_STATUS *pCommandStatus = NULL;
CHAR16 *pAttributeStr = NULL;
CHAR16 *pCapacityStr = NULL;
CHAR16 *pDimmErrStr = NULL;
CHAR16 *pOriginalNullVal = NULL;
LAST_SHUTDOWN_STATUS_DETAILS_COMBINED LatchedLastShutdownStatusDetails;
LAST_SHUTDOWN_STATUS_DETAILS_COMBINED UnlatchedLastShutdownStatusDetails;
DISPLAY_PREFERENCES DisplayPreferences;
CHAR16 DimmStr[MAX_DIMM_UID_LENGTH];
BOOLEAN ByteAddressable = FALSE;
UINT16 BootStatusBitMask = 0;
UINT64 BootStatusRegister = 0;
CHAR16 *pSteppingStr = NULL;
CMD_DISPLAY_OPTIONS *pDispOptions = NULL;
PRINT_CONTEXT *pPrinterCtx = NULL;
CHAR16 *pPath = NULL;
BOOLEAN volatile DimmIsOkToDisplay[MAX_DIMMS];
BOOLEAN IsMixedSku;
BOOLEAN IsSkuViolation;
DIMM_INFO_CATEGORIES DimmCategories = DIMM_INFO_CATEGORY_NONE;
BOOLEAN FIS_2_0 = FALSE;
CHAR16 *pStatusStr = NULL;
FIPS_MODE FIPSMode;
NVDIMM_ENTRY();
gNullValuesEncounteredForDisplay = 0;
ZeroMem(TmpFwVerString, sizeof(TmpFwVerString));
ZeroMem(&DisplayPreferences, sizeof(DisplayPreferences));
ZeroMem(DimmStr, sizeof(DimmStr));
ZeroMem(&LatchedLastShutdownStatusDetails, sizeof(LatchedLastShutdownStatusDetails));
ZeroMem(&UnlatchedLastShutdownStatusDetails, sizeof(UnlatchedLastShutdownStatusDetails));
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("pCmd parameter is NULL.\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
for (Index1 = 0; Index1 < MAX_DIMMS; Index1++) {
DimmIsOkToDisplay[Index1] = FALSE;
}
pPrinterCtx = pCmd->pPrintCtx;
pDispOptions = AllocateZeroPool(sizeof(CMD_DISPLAY_OPTIONS));
if (NULL == pDispOptions) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
ReturnCode = CheckAllAndDisplayOptions(pCmd, mppAllowedShowDimmsDisplayValues,
ALLOWED_DISP_VALUES_COUNT(mppAllowedShowDimmsDisplayValues), pDispOptions);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("CheckAllAndDisplayOptions has returned error. Code " FORMAT_EFI_STATUS "\n", ReturnCode);
goto Finish;
}
ContainSocketTarget = ContainTarget(pCmd, SOCKET_TARGET);
/**
if sockets were specified
**/
if (ContainSocketTarget) {
pSocketsValue = GetTargetValue(pCmd, SOCKET_TARGET);
ReturnCode = GetUintsFromString(pSocketsValue, &pSocketIds, &SocketsNum);
if (EFI_ERROR(ReturnCode)) {
/** Error Code returned by function above **/
NVDIMM_DBG("GetUintsFromString returned error");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_TARGET_SOCKET);
goto Finish;
}
}
ReturnCode = ReadRunTimePreferences(&DisplayPreferences, DISPLAY_CLI_INFO);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_DISPLAY_PREFERENCES_RETRIEVE);
goto Finish;
}
UnitsToDisplay = DisplayPreferences.SizeUnit;
ReturnCode = GetUnitsOption(pCmd, &UnitsOption);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
/** Any valid units option will override the preferences **/
if (UnitsOption != DISPLAY_SIZE_UNIT_UNKNOWN) {
UnitsToDisplay = UnitsOption;
}
/** make sure we can access the config protocol **/
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// initialize status structure
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
NVDIMM_DBG("Failed on InitializeCommandStatus");
goto Finish;
}
ShowTableView = !pDispOptions->AllOptionSet && !pDispOptions->DisplayOptionSet;
if (ShowTableView) {
DimmCategories = DIMM_INFO_CATEGORY_SECURITY | DIMM_INFO_CATEGORY_SMART_AND_HEALTH;
} else {
DimmCategories = DIMM_INFO_CATEGORY_ALL;
}
// Populate the list of DIMM_INFO structures with relevant information
ReturnCode = GetAllDimmList(pNvmDimmConfigProtocol, pCmd, DimmCategories, &pDimms, &DimmCount);
if (EFI_ERROR(ReturnCode) || (pDimms == NULL)) {
NVDIMM_WARN("Failed to populate the list of DIMM_INFO structures");
goto Finish;
}
ReturnCode = IsDimmsMixedSkuCfg(pPrinterCtx, pNvmDimmConfigProtocol, &IsMixedSku, &IsSkuViolation);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
if (IsMixedSku) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, WARNING_DIMMS_SKU_MIXED);
NVDIMM_WARN("Mixed SKU detected. Driver functionalities limited.");
}
/** if a specific DIMM pid was passed in, set it **/
if (NULL != pCmd->targets[0].pTargetValueStr && StrLen(pCmd->targets[0].pTargetValueStr) > 0) {
pAllDimms = AllocateZeroPool(sizeof(*pAllDimms) * (DimmCount));
if (NULL == pAllDimms) {
ReturnCode = EFI_OUT_OF_RESOURCES;
goto Finish;
}
CopyMem_S(pAllDimms, sizeof(*pAllDimms) * (DimmCount), pDimms, sizeof(*pDimms) * DimmCount);
pDimmsValue = GetTargetValue(pCmd, DIMM_TARGET);
ReturnCode = GetDimmIdsFromString(pCmd, pDimmsValue, pAllDimms, DimmCount, &pDimmIds,
&DimmIdsNum);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Target value is not a valid Dimm ID");
goto Finish;
}
/*Mark each dimm as ok to display based on the dimms passed by the user*/
for (Index1 = 0; Index1 < DimmCount; Index1++) {
for (Index2 = 0; Index2 < DimmIdsNum; Index2++) {
if (pAllDimms[Index1].DimmID == pDimmIds[Index2]) {
DimmIsOkToDisplay[Index1] = TRUE;
}
}
}
}
else {
/*Since no dimms were specified, mark them all as ok to display*/
for (DimmIndex = 0; DimmIndex < MAX_DIMMS; DimmIndex++) {
DimmIsOkToDisplay[DimmIndex] = TRUE;
}
}
if (SocketsNum > 0) {
Found = FALSE;
/*Only display sockets which match the dimms that the user has indicated*/
for (DimmIndex = 0; DimmIndex < DimmCount; DimmIndex++) {
if (DimmIsOkToDisplay[DimmIndex] == TRUE &&
ContainUint(pSocketIds, SocketsNum, pDimms[DimmIndex].SocketId)) {
Found = TRUE;
break;
}
}
if (!Found) {
ReturnCode = EFI_NOT_FOUND;
if (DimmIdsNum > 0) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_SPECIFIED_DIMMS_ON_SPECIFIED_SOCKET);
}
else {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_DIMMS_ON_SOCKET);
}
NVDIMM_DBG("No DIMMs on provided Socket");
goto Finish;
}
}
/** display a summary table of all dimms **/
if (ShowTableView) {
for (DimmIndex = 0; DimmIndex < DimmCount; DimmIndex++) {
if (SocketsNum > 0 && !ContainUint(pSocketIds, SocketsNum, pDimms[DimmIndex].SocketId)) {
continue;
}
if (DimmIdsNum > 0 && !ContainUint(pDimmIds, DimmIdsNum, pDimms[DimmIndex].DimmID)) {
continue;
}
PRINTER_BUILD_KEY_PATH(pPath, DS_DIMM_INDEX_PATH, DimmIndex);
ReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, pDimms[DimmIndex].Capacity, UnitsToDisplay, TRUE, &pCapacityStr);
pHealthStr = HealthToString(gNvmDimmCliHiiHandle, pDimms[DimmIndex].HealthState);
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_SECURITY_INFO ||
MANAGEMENT_VALID_CONFIG != pDimms[DimmIndex].ManageabilityState) {
pSecurityStr = CatSPrint(NULL, FORMAT_STR, UNKNOWN_ATTRIB_VAL);
}
else {
pSecurityStr = SecurityStateBitmaskToString(gNvmDimmCliHiiHandle, pDimms[DimmIndex].SecurityStateBitmask);
}
ConvertFwVersion(TmpFwVerString, pDimms[DimmIndex].FwVer.FwProduct,
pDimms[DimmIndex].FwVer.FwRevision, pDimms[DimmIndex].FwVer.FwSecurityVersion, pDimms[DimmIndex].FwVer.FwBuild);
ReturnCode = GetPreferredDimmIdAsString(pDimms[DimmIndex].DimmHandle, pDimms[DimmIndex].DimmUid,
DimmStr, MAX_DIMM_UID_LENGTH);
pDimmErrStr = CatSPrint(NULL, FORMAT_STR, UNKNOWN_ATTRIB_VAL);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, CAPACITY_STR, pCapacityStr);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, HEALTH_STR, pHealthStr);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, SECURITY_STR, pSecurityStr);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, FW_VER_STR, TmpFwVerString);
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_UID) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DIMM_ID_STR, pDimmErrStr);
}
else {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DIMM_ID_STR, DimmStr);
}
FREE_POOL_SAFE(pDimmErrStr);
FREE_POOL_SAFE(pHealthStr);
FREE_POOL_SAFE(pSecurityStr);
FREE_POOL_SAFE(pCapacityStr);
}
}
/** display detailed view **/
else {
ShowAll = pDispOptions->AllOptionSet;
if (pDispOptions->DisplayOptionSet) {
gDisplayNulls = TRUE;
pOriginalNullVal = gNullValueToDisplay;
gNullValueToDisplay = L"Unsupported Field";
}
/** show dimms from Initialized list **/
for (DimmIndex = 0; DimmIndex < DimmCount; DimmIndex++) {
/** matching pid **/
if (DimmIdsNum > 0 && !ContainUint(pDimmIds, DimmIdsNum, pDimms[DimmIndex].DimmID)) {
continue;
}
if (SocketsNum > 0 && !ContainUint(pSocketIds, SocketsNum, pDimms[DimmIndex].SocketId)) {
continue;
}
PRINTER_BUILD_KEY_PATH(pPath, DS_DIMM_INDEX_PATH, DimmIndex);
//Checking the FIS Version
if ((pDimms[DimmIndex].FwVer.FwApiMajor >= 2) || (pDimms[DimmIndex].FwVer.FwApiMajor == 1 && pDimms[DimmIndex].FwVer.FwApiMinor >= 13)) {
FIS_2_0 = TRUE;
}
/** always print the DimmID **/
ReturnCode = GetPreferredDimmIdAsString(pDimms[DimmIndex].DimmHandle, pDimms[DimmIndex].DimmUid, DimmStr,
MAX_DIMM_UID_LENGTH);
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_UID) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DIMM_ID_STR, UNKNOWN_ATTRIB_VAL);
}
else {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DIMM_ID_STR, DimmStr);
}
/** Capacity **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, CAPACITY_STR))) {
ReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, pDimms[DimmIndex].Capacity, UnitsToDisplay, TRUE, &pCapacityStr);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, CAPACITY_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
}
/** Security State **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SECURITY_STR))) {
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_SECURITY_INFO ||
MANAGEMENT_VALID_CONFIG != pDimms[DimmIndex].ManageabilityState) {
pSecurityStr = CatSPrint(NULL, FORMAT_STR, UNKNOWN_ATTRIB_VAL);
}
else {
pSecurityStr = SecurityStateBitmaskToString(gNvmDimmCliHiiHandle, pDimms[DimmIndex].SecurityStateBitmask);
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, SECURITY_STR, pSecurityStr);
FREE_POOL_SAFE(pSecurityStr);
}
/** SVN Downgrade Opt-In **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SVN_DOWNGRADE_OPT_IN_STR))) {
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_SVN_DOWNGRADE) {
pSVNDowngradeStr = CatSPrint(NULL, FORMAT_STR, UNKNOWN_ATTRIB_VAL);
}
else {
pSVNDowngradeStr = SVNDowngradeOptInToString(gNvmDimmCliHiiHandle, pDimms[DimmIndex].SVNDowngradeOptIn);
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, SVN_DOWNGRADE_OPT_IN_STR, pSVNDowngradeStr);
FREE_POOL_SAFE(pSVNDowngradeStr);
}
/** Secure Erase Policy Opt-In **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SEP_OPT_IN_STR))) {
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_SECURE_ERASE_POLICY) {
pSecureErasePolicyStr = CatSPrint(NULL, FORMAT_STR, UNKNOWN_ATTRIB_VAL);
}
else {
pSecureErasePolicyStr = SecureErasePolicyOptInToString(gNvmDimmCliHiiHandle, pDimms[DimmIndex].SecureErasePolicyOptIn);
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, SEP_OPT_IN_STR, pSecureErasePolicyStr);
FREE_POOL_SAFE(pSecureErasePolicyStr);
}
/** S3 Resume Opt-In **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, S3_RESUME_OPT_IN_STR))) {
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_S3RESUME) {
pS3ResumeStr = CatSPrint(NULL, FORMAT_STR, UNKNOWN_ATTRIB_VAL);
} else {
pS3ResumeStr = S3ResumeOptInToString(gNvmDimmCliHiiHandle, pDimms[DimmIndex].S3ResumeOptIn);
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, S3_RESUME_OPT_IN_STR, pS3ResumeStr);
FREE_POOL_SAFE(pS3ResumeStr);
}
/** FW Activate Opt-In **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, FW_ACTIVATE_OPT_IN_STR))) {
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_FW_ACTIVATE) {
pFwActivateStr = CatSPrint(NULL, FORMAT_STR, UNKNOWN_ATTRIB_VAL);
}
else {
pFwActivateStr = FwActivateOptInToString(gNvmDimmCliHiiHandle, pDimms[DimmIndex].FwActivateOptIn);
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, FW_ACTIVATE_OPT_IN_STR, pFwActivateStr);
FREE_POOL_SAFE(pFwActivateStr);
}
/** Health State **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, HEALTH_STR))) {
pHealthStr = HealthToString(gNvmDimmCliHiiHandle, pDimms[DimmIndex].HealthState);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, HEALTH_STR, pHealthStr);
FREE_POOL_SAFE(pHealthStr);
}
/** Health State Reason**/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, HEALTH_STATE_REASON_STR))) {
ReturnCode = ConvertHealthStateReasonToHiiStr(gNvmDimmCliHiiHandle,
pDimms[DimmIndex].HealthStatusReason, &pHealthStateReasonStr);
if (pHealthStateReasonStr == NULL || EFI_ERROR(ReturnCode)) {
goto Finish;
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, HEALTH_STATE_REASON_STR, pHealthStateReasonStr);
FREE_POOL_SAFE(pHealthStateReasonStr);
}
/** FwVersion **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, FW_VER_STR))) {
ConvertFwVersion(TmpFwVerString, pDimms[DimmIndex].FwVer.FwProduct, pDimms[DimmIndex].FwVer.FwRevision,
pDimms[DimmIndex].FwVer.FwSecurityVersion, pDimms[DimmIndex].FwVer.FwBuild);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, FW_VER_STR, TmpFwVerString);
}
/** FwApiVersion **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, FW_API_VER_STR))) {
ConvertFwApiVersion(TmpFwVerString, pDimms[DimmIndex].FwVer.FwApiMajor, pDimms[DimmIndex].FwVer.FwApiMinor);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, FW_API_VER_STR, TmpFwVerString);
}
/** FwActiveApiVersion **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, FW_ACTIVE_API_VER_STR))) {
ConvertFwApiVersion(TmpFwVerString, pDimms[DimmIndex].FwActiveApiVersionMajor, pDimms[DimmIndex].FwActiveApiVersionMinor);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, FW_ACTIVE_API_VER_STR, TmpFwVerString);
}
/** InterfaceFormatCode **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, INTERFACE_FORMAT_CODE_STR))) {
if (pDimms[DimmIndex].InterfaceFormatCodeNum <= MAX_IFC_NUM) {
CHAR16 *tmpIfc = NULL;
for (Index2 = 0; Index2 < pDimms[DimmIndex].InterfaceFormatCodeNum; Index2++) {
if (pDimms[DimmIndex].InterfaceFormatCode[Index2] == DCPMM_FMT_CODE_APP_DIRECT) {
ByteAddressable = TRUE;
}
}
if (ByteAddressable) {
tmpIfc = CatSPrint(tmpIfc, FORMAT_HEX L" ", DCPMM_FMT_CODE_APP_DIRECT);
tmpIfc = CatSPrint(tmpIfc, FORMAT_CODE_APP_DIRECT_STR);
}
if (pDimms[DimmIndex].InterfaceFormatCodeNum > 1) {
tmpIfc = CatSPrint(tmpIfc, L", ");
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, INTERFACE_FORMAT_CODE_STR, tmpIfc);
FREE_POOL_SAFE(tmpIfc);
}
}
/** Manageability **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MANAGEABILITY_STR))) {
pManageabilityStr = ManageabilityToString(pDimms[DimmIndex].ManageabilityState);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, MANAGEABILITY_STR, pManageabilityStr);
FREE_POOL_SAFE(pManageabilityStr);
}
/** PopulationViolation **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, POPULATION_VIOLATION_STR))) {
pPopulationViolationStr = PopulationViolationToString(pDimms[DimmIndex].IsInPopulationViolation);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, POPULATION_VIOLATION_STR, pPopulationViolationStr);
FREE_POOL_SAFE(pPopulationViolationStr);
}
/** PhysicalID **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, PHYSICAL_ID_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, PHYSICAL_ID_STR, FORMAT_HEX, pDimms[DimmIndex].DimmID);
}
/** DimmHandle **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, DIMM_HANDLE_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, DIMM_HANDLE_STR, FORMAT_HEX, pDimms[DimmIndex].DimmHandle);
}
/** DimmUID **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, DIMM_UID_STR))) {
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_UID) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DIMM_UID_STR, UNKNOWN_ATTRIB_VAL);
}
else {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DIMM_UID_STR, pDimms[DimmIndex].DimmUid);
}
}
/** SocketId **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SOCKET_ID_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, SOCKET_ID_STR, FORMAT_HEX, pDimms[DimmIndex].SocketId);
}
/** MemoryControllerId **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MEMORY_CONTROLLER_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MEMORY_CONTROLLER_STR, FORMAT_HEX, pDimms[DimmIndex].ImcId);
}
/** ChannelID **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, CHANNEL_ID_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, CHANNEL_ID_STR, FORMAT_HEX, pDimms[DimmIndex].ChannelId);
}
/** ChannelPos **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, CHANNEL_POS_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, CHANNEL_POS_STR, FORMAT_INT32, pDimms[DimmIndex].ChannelPos);
}
/** MemoryType **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MEMORY_TYPE_STR))) {
pAttributeStr = MemoryTypeToStr(pDimms[DimmIndex].MemoryType);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, MEMORY_TYPE_STR, pAttributeStr);
FREE_POOL_SAFE(pAttributeStr);
}
/** ManufacturerStr **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MANUFACTURER_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, MANUFACTURER_STR, pDimms[DimmIndex].ManufacturerStr);
}
/** VendorId **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, VENDOR_ID_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, VENDOR_ID_STR, FORMAT_HEX, EndianSwapUint16(pDimms[DimmIndex].VendorId));
}
/** DeviceId **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, DEVICE_ID_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, DEVICE_ID_STR, FORMAT_HEX, EndianSwapUint16(pDimms[DimmIndex].DeviceId));
}
/** RevisionId **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, REVISION_ID_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, REVISION_ID_STR, FORMAT_HEX, pDimms[DimmIndex].Rid);
}
/** SubsystemVendorId **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SUBSYSTEM_VENDOR_ID_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, SUBSYSTEM_VENDOR_ID_STR, FORMAT_HEX, EndianSwapUint16(pDimms[DimmIndex].SubsystemVendorId));
}
/** SubsystemDeviceId **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SUBSYSTEM_DEVICE_ID_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, SUBSYSTEM_DEVICE_ID_STR, FORMAT_HEX, pDimms[DimmIndex].SubsystemDeviceId);
}
/** SubsystemRevisionId **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SUBSYSTEM_REVISION_ID_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, SUBSYSTEM_REVISION_ID_STR, FORMAT_HEX, pDimms[DimmIndex].SubsystemRid);
}
/** DeviceLocator **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, DEVICE_LOCATOR_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DEVICE_LOCATOR_STR, pDimms[DimmIndex].DeviceLocator);
}
/** ManufacturingInfoValid **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MANUFACTURING_INFO_VALID))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MANUFACTURING_INFO_VALID, FORMAT_INT32, pDimms[DimmIndex].ManufacturingInfoValid);
}
/** ManufacturingLocation **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MANUFACTURING_LOCATION))) {
if (pDimms[DimmIndex].ManufacturingInfoValid) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MANUFACTURING_LOCATION, FORMAT_HEX_PREFIX FORMAT_UINT8_HEX, pDimms[DimmIndex].ManufacturingLocation);
} else {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, MANUFACTURING_LOCATION, NA_STR);
}
}
/** ManufacturingDate **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MANUFACTURING_DATE))) {
if (pDimms[DimmIndex].ManufacturingInfoValid) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MANUFACTURING_DATE, FORMAT_SHOW_DIMM_MANU_DATE, pDimms[DimmIndex].ManufacturingDate & 0xFF, (pDimms[DimmIndex].ManufacturingDate >> 8) & 0xFF);
} else {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, MANUFACTURING_DATE, NA_STR);
}
}
/** SerialNumber **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SERIAL_NUMBER_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, SERIAL_NUMBER_STR, FORMAT_HEX_PREFIX FORMAT_UINT32_HEX, EndianSwapUint32(pDimms[DimmIndex].SerialNumber));
}
/** PartNumber **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, PART_NUMBER_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, PART_NUMBER_STR, pDimms[DimmIndex].PartNumber);
}
/** BankLabel **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, BANK_LABEL_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, BANK_LABEL_STR, pDimms[DimmIndex].BankLabel);
}
/** DataWidth **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, DATA_WIDTH_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, DATA_WIDTH_STR, FORMAT_INT32 L" " BYTE_STR, pDimms[DimmIndex].DataWidth);
}
/** TotalWidth **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, TOTAL_WIDTH_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, TOTAL_WIDTH_STR, FORMAT_INT32 L" " BYTE_STR, pDimms[DimmIndex].TotalWidth);
}
/** Speed **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SPEED_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, SPEED_STR, FORMAT_INT32 L" " MEGA_TRANSFERS_PER_SEC_STR, pDimms[DimmIndex].Speed);
}
/** FormFactor **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, FORM_FACTOR_STR))) {
pFormFactorStr = FormFactorToString(pDimms[DimmIndex].FormFactor);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, FORM_FACTOR_STR, pFormFactorStr);
FREE_POOL_SAFE(pFormFactorStr);
}
/** If Dimm is Manageable print rest of the attributes **/
if (pDimms[DimmIndex].ManageabilityState) {
/** ManufacturerId **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MANUFACTURER_ID_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MANUFACTURER_ID_STR, FORMAT_HEX, EndianSwapUint16(pDimms[DimmIndex].ManufacturerId));
}
/** ControllerRevisionId **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, CONTROLLER_REVISION_ID_STR))) {
pSteppingStr = ControllerRidToStr(pDimms[DimmIndex].ControllerRid, pDimms[DimmIndex].SubsystemDeviceId);
if (pSteppingStr != NULL) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, CONTROLLER_REVISION_ID_STR, pSteppingStr);
FREE_POOL_SAFE(pSteppingStr);
}
}
/** VolatileCapacity **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MEMORY_MODE_CAPACITY_STR))) {
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_CAPACITY) {
pCapacityStr = CatSPrint(NULL, FORMAT_STR, UNKNOWN_ATTRIB_VAL);
}
else {
TempReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, pDimms[DimmIndex].VolatileCapacity, UnitsToDisplay, TRUE, &pCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, MEMORY_MODE_CAPACITY_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
}
/** AppDirectCapacity **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, APPDIRECT_MODE_CAPACITY_STR))) {
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_CAPACITY) {
pCapacityStr = CatSPrint(NULL, FORMAT_STR, UNKNOWN_ATTRIB_VAL);
}
else {
TempReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, pDimms[DimmIndex].AppDirectCapacity, UnitsToDisplay, TRUE, &pCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, APPDIRECT_MODE_CAPACITY_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
}
/** UnconfiguredCapacity **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, UNCONFIGURED_CAPACITY_STR))) {
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_CAPACITY) {
pCapacityStr = CatSPrint(NULL, FORMAT_STR, UNKNOWN_ATTRIB_VAL);
}
else {
TempReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, pDimms[DimmIndex].UnconfiguredCapacity, UnitsToDisplay, TRUE,
&pCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, UNCONFIGURED_CAPACITY_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
}
/** InaccessibleCapacity **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, INACCESSIBLE_CAPACITY_STR))) {
KEEP_ERROR(ReturnCode, TempReturnCode);
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_CAPACITY) {
pCapacityStr = CatSPrint(NULL, FORMAT_STR, UNKNOWN_ATTRIB_VAL);
}
else {
TempReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, pDimms[DimmIndex].InaccessibleCapacity, UnitsToDisplay, TRUE,
&pCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, INACCESSIBLE_CAPACITY_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
}
/** ReservedCapacity **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, RESERVED_CAPACITY_STR))) {
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_CAPACITY) {
pCapacityStr = CatSPrint(NULL, FORMAT_STR, UNKNOWN_ATTRIB_VAL);
}
else {
TempReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, pDimms[DimmIndex].ReservedCapacity, UnitsToDisplay, TRUE, &pCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, RESERVED_CAPACITY_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
}
/** PackageSparingCapable **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, PACKAGE_SPARING_CAPABLE_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, PACKAGE_SPARING_CAPABLE_STR, FORMAT_INT32, pDimms[DimmIndex].PackageSparingCapable);
}
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_PACKAGE_SPARING) {
/** PackageSparingEnabled **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, PACKAGE_SPARING_ENABLED_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, PACKAGE_SPARING_ENABLED_STR, UNKNOWN_ATTRIB_VAL);
}
/** PackageSparesAvailable **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, PACKAGE_SPARES_AVAILABLE_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, PACKAGE_SPARES_AVAILABLE_STR, UNKNOWN_ATTRIB_VAL);
}
}
else {
/** PackageSparingEnabled **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, PACKAGE_SPARING_ENABLED_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, PACKAGE_SPARING_ENABLED_STR, FORMAT_INT32, pDimms[DimmIndex].PackageSparingEnabled);
}
/** PackageSparesAvailable **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, PACKAGE_SPARES_AVAILABLE_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, PACKAGE_SPARES_AVAILABLE_STR, FORMAT_INT32, pDimms[DimmIndex].PackageSparesAvailable);
}
}
/** IsNew **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, IS_NEW_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, IS_NEW_STR, FORMAT_INT32, pDimms[DimmIndex].IsNew);
}
/** AveragePowerReportingTimeConstant (FIS 2.1 and higher) **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, AVG_PWR_REPORTING_TIME_CONSTANT))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, AVG_PWR_REPORTING_TIME_CONSTANT, ConvertDimmInfoAttribToString((VOID*)&pDimms[DimmIndex].AvgPowerReportingTimeConstant, FORMAT_UINT64 L" " TIME_MSR_MS));
}
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_VIRAL_POLICY) {
/** ViralPolicyEnable **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, VIRAL_POLICY_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, VIRAL_POLICY_STR, UNKNOWN_ATTRIB_VAL);
}
/** ViralStatus **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, VIRAL_STATE_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, VIRAL_STATE_STR, UNKNOWN_ATTRIB_VAL);
}
}
else {
/** ViralPolicyEnable **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, VIRAL_POLICY_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, VIRAL_POLICY_STR, FORMAT_INT32, pDimms[DimmIndex].ViralPolicyEnable);
}
/** ViralStatus **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, VIRAL_STATE_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, VIRAL_STATE_STR, FORMAT_INT32, pDimms[DimmIndex].ViralStatus);
}
}
/** PeakPowerBudget **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, PEAK_POWER_BUDGET_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, PEAK_POWER_BUDGET_STR, ConvertDimmInfoAttribToString((VOID*)&pDimms[DimmIndex].PeakPowerBudget, FORMAT_INT32 L" " MILI_WATT_STR));
}
/** AvgPowerLimit **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, AVG_POWER_LIMIT_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, AVG_POWER_LIMIT_STR, ConvertDimmInfoAttribToString((VOID*)&pDimms[DimmIndex].AvgPowerLimit, FORMAT_INT32 L" " MILI_WATT_STR));
}
/** 2.1+: MemoryBandwidthBoostFeature **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MEMORY_BANDWIDTH_BOOST_FEATURE_STR))) {
if ((2 == pDimms[DimmIndex].FwVer.FwApiMajor && 1 <= pDimms[DimmIndex].FwVer.FwApiMinor)
|| 3 <= pDimms[DimmIndex].FwVer.FwApiMajor) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MEMORY_BANDWIDTH_BOOST_FEATURE_STR, ConvertDimmInfoAttribToString((VOID*)&pDimms[DimmIndex].MemoryBandwidthBoostFeature, FORMAT_HEX_NOWIDTH));
}
}
/** 2.1+: MemoryBandwidthBoostMaxPowerLimit **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MEMORY_BANDWIDTH_BOOST_MAX_POWER_LIMIT_STR))) {
if ((2 == pDimms[DimmIndex].FwVer.FwApiMajor && 1 <= pDimms[DimmIndex].FwVer.FwApiMinor)
|| 3 <= pDimms[DimmIndex].FwVer.FwApiMajor) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MEMORY_BANDWIDTH_BOOST_MAX_POWER_LIMIT_STR, ConvertDimmInfoAttribToString((VOID*)&pDimms[DimmIndex].MemoryBandwidthBoostMaxPowerLimit, FORMAT_INT32 L" " MILI_WATT_STR));
}
}
/** MemoryBandwidthBoostAveragePowerTimeConstant **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MEMORY_BANDWIDTH_BOOST_AVERAGE_POWER_TIME_CONSTANT_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MEMORY_BANDWIDTH_BOOST_AVERAGE_POWER_TIME_CONSTANT_STR, ConvertDimmInfoAttribToString((VOID*)&pDimms[DimmIndex].MemoryBandwidthBoostAveragePowerTimeConstant, FORMAT_UINT64 L" " TIME_MSR_MS));
}
/** MaxAveragePowerLimit **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MAX_AVG_POWER_LIMIT_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MAX_AVG_POWER_LIMIT_STR, ConvertDimmInfoAttribToString((VOID*)&pDimms[DimmIndex].MaxAveragePowerLimit, FORMAT_INT32 L" " MILI_WATT_STR));
}
/** MaxMemoryBandwidthBoostMaxPowerLimit **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MAX_MEMORY_BANDWIDTH_BOOST_MAX_POWER_LIMIT))) {
if ((2 == pDimms[DimmIndex].FwVer.FwApiMajor && 0 <= pDimms[DimmIndex].FwVer.FwApiMinor)
|| 3 <= pDimms[DimmIndex].FwVer.FwApiMajor) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MAX_MEMORY_BANDWIDTH_BOOST_MAX_POWER_LIMIT, ConvertDimmInfoAttribToString((VOID*)&pDimms[DimmIndex].MaxMemoryBandwidthBoostMaxPowerLimit, FORMAT_INT32 L" " MILI_WATT_STR));
}
}
/** MaxMemoryBandwidthBoostAveragePowerTimeConstant **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MAX_MEMORY_BANDWIDTH_BOOST_AVERAGE_POWER_TIME_CONSTANT))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MAX_MEMORY_BANDWIDTH_BOOST_AVERAGE_POWER_TIME_CONSTANT, ConvertDimmInfoAttribToString((VOID*)&pDimms[DimmIndex].MaxMemoryBandwidthBoostAveragePowerTimeConstant, FORMAT_INT32 L" " TIME_MSR_MS));
}
/** MemoryBandwidthBoostAveragePowerTimeConstantStep **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MEMORY_BANDWIDTH_BOOST_AVERAGE_POWER_TIME_CONSTANT_STEP))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MEMORY_BANDWIDTH_BOOST_AVERAGE_POWER_TIME_CONSTANT_STEP, ConvertDimmInfoAttribToString((VOID*)&pDimms[DimmIndex].MemoryBandwidthBoostAveragePowerTimeConstantStep, FORMAT_INT32 L" " TIME_MSR_MS));
}
/** MaxAveragePowerReportingTimeConstant **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MAX_AVERAGE_POWER_REPORTING_TIME_CONSTANT))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MAX_AVERAGE_POWER_REPORTING_TIME_CONSTANT, ConvertDimmInfoAttribToString((VOID*)&pDimms[DimmIndex].MaxAveragePowerReportingTimeConstant, FORMAT_INT32 L" " TIME_MSR_MS));
}
/** AveragePowerReportingTimeConstantStep **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, AVERAGE_POWER_REPORTING_TIME_CONSTANT_STEP))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, AVERAGE_POWER_REPORTING_TIME_CONSTANT_STEP, ConvertDimmInfoAttribToString((VOID*)&pDimms[DimmIndex].AveragePowerReportingTimeConstantStep, FORMAT_INT32 L" " TIME_MSR_MS));
}
/** DcpmmAveragePower **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, DCPMM_AVERAGE_POWER_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, DCPMM_AVERAGE_POWER_STR, ConvertDimmInfoAttribToString((VOID*)&pDimms[DimmIndex].DcpmmAveragePower, FORMAT_INT32 L" " MILI_WATT_STR));
}
/** AveragePower12V **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, AVERAGE_12V_POWER_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, AVERAGE_12V_POWER_STR, ConvertDimmInfoAttribToString((VOID*)&pDimms[DimmIndex].AveragePower12V, FORMAT_INT32 L" " MILI_WATT_STR));
}
/** AveragePower1_2V **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, AVERAGE_1_2V_POWER_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, AVERAGE_1_2V_POWER_STR, ConvertDimmInfoAttribToString((VOID*)&pDimms[DimmIndex].AveragePower1_2V, FORMAT_INT32 L" " MILI_WATT_STR));
}
/** LatchedLastShutdownStatusDetails **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, LATCHED_LAST_SHUTDOWN_STATUS_STR))) {
LatchedLastShutdownStatusDetails.AsUint32 = pDimms[DimmIndex].LatchedLastShutdownStatusDetails;
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_SMART_AND_HEALTH) {
pAttributeStr = CatSPrint(NULL, FORMAT_STR, UNKNOWN_ATTRIB_VAL);
}
else {
pAttributeStr = LastShutdownStatusToStr(LatchedLastShutdownStatusDetails, pDimms[DimmIndex].FwVer);
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, LATCHED_LAST_SHUTDOWN_STATUS_STR, pAttributeStr);
FREE_POOL_SAFE(pAttributeStr);
}
/** UnlatchedLastShutdownStatusDetails **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, UNLATCHED_LAST_SHUTDOWN_STATUS_STR))) {
UnlatchedLastShutdownStatusDetails.AsUint32 = pDimms[DimmIndex].UnlatchedLastShutdownStatusDetails;
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_SMART_AND_HEALTH) {
pAttributeStr = CatSPrint(NULL, FORMAT_STR, UNKNOWN_ATTRIB_VAL);
}
else {
pAttributeStr = LastShutdownStatusToStr(UnlatchedLastShutdownStatusDetails, pDimms[DimmIndex].FwVer);
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, UNLATCHED_LAST_SHUTDOWN_STATUS_STR, pAttributeStr);
FREE_POOL_SAFE(pAttributeStr);
}
/** ThermalThrottlePerformanceLossPrct **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, THERMAL_THROTTLE_LOSS_STR))) {
if ((pDimms[DimmIndex].FwVer.FwApiMajor == 0x2 && pDimms[DimmIndex].FwVer.FwApiMinor >= 0x1) ||
(pDimms[DimmIndex].FwVer.FwApiMajor >= 0x3)) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, THERMAL_THROTTLE_LOSS_STR, FORMAT_UINT32, pDimms[DimmIndex].ThermalThrottlePerformanceLossPrct);
}
else {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, THERMAL_THROTTLE_LOSS_STR, NA_STR);
}
}
/** LastShutdownTime **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, LAST_SHUTDOWN_TIME_STR))) {
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_SMART_AND_HEALTH) {
pAttributeStr = CatSPrint(NULL, FORMAT_STR, UNKNOWN_ATTRIB_VAL);
}
else {
pAttributeStr = GetTimeFormatString(pDimms[DimmIndex].LastShutdownTime, TRUE);
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, LAST_SHUTDOWN_TIME_STR, pAttributeStr);
FREE_POOL_SAFE(pAttributeStr);
}
/** ModesSupported **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MODES_SUPPORTED_STR))) {
pAttributeStr = ModesSupportedToStr(pDimms[DimmIndex].ModesSupported);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, MODES_SUPPORTED_STR, pAttributeStr);
FREE_POOL_SAFE(pAttributeStr);
}
/** SecurityCapabilities **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SECURITY_CAPABILITIES_STR))) {
pAttributeStr = SecurityCapabilitiesToStr(pDimms[DimmIndex].SecurityCapabilities);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, SECURITY_CAPABILITIES_STR, pAttributeStr);
FREE_POOL_SAFE(pAttributeStr);
}
/** MasterPassphraseEnabled **/
if (ShowAll || (pDispOptions->DisplayOptionSet &&
ContainsValue(pDispOptions->pDisplayValues, MASTER_PASS_ENABLED_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MASTER_PASS_ENABLED_STR, FORMAT_INT32,
pDimms[DimmIndex].MasterPassphraseEnabled);
}
/** ConfigurationStatus **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, DIMM_CONFIG_STATUS_STR))) {
pAttributeStr = mppAllowedShowDimmsConfigStatuses[pDimms[DimmIndex].ConfigStatus];
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DIMM_CONFIG_STATUS_STR, pAttributeStr);
}
/** SKUViolation **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SKU_VIOLATION_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, SKU_VIOLATION_STR, FORMAT_INT32, pDimms[DimmIndex].SKUViolation);
}
/** ARSStatus **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, ARS_STATUS_STR))) {
pAttributeStr = LongOpStatusToStr(gNvmDimmCliHiiHandle, pDimms[DimmIndex].ARSStatus);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ARS_STATUS_STR, pAttributeStr);
FREE_POOL_SAFE(pAttributeStr);
}
/** OverwriteDimmStatus **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, OVERWRITE_STATUS_STR))) {
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_OVERWRITE_STATUS) {
pAttributeStr = CatSPrint(NULL, FORMAT_STR, UNKNOWN_ATTRIB_VAL);
}
else {
pAttributeStr = LongOpStatusToStr(gNvmDimmCliHiiHandle, pDimms[DimmIndex].OverwriteDimmStatus);
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, OVERWRITE_STATUS_STR, pAttributeStr);
FREE_POOL_SAFE(pAttributeStr);
}
/** AitDramEnabled **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, AIT_DRAM_ENABLED_STR))) {
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_SMART_AND_HEALTH) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, AIT_DRAM_ENABLED_STR, UNKNOWN_ATTRIB_VAL);
}
else {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, AIT_DRAM_ENABLED_STR, FORMAT_INT32, pDimms[DimmIndex].AitDramEnabled);
}
}
/** Boot Status and/or Boot Status Register **/
if (ShowAll || (pDispOptions->DisplayOptionSet &&
(ContainsValue(pDispOptions->pDisplayValues, BOOT_STATUS_STR) ||
ContainsValue(pDispOptions->pDisplayValues, BOOT_STATUS_REGISTER_STR)))) {
pNvmDimmConfigProtocol->GetBSRAndBootStatusBitMask(pNvmDimmConfigProtocol, pDimms[DimmIndex].DimmID, &BootStatusRegister, &BootStatusBitMask);
pAttributeStr = BootStatusBitmaskToStr(gNvmDimmCliHiiHandle, BootStatusBitMask);
if (ShowAll || (pDispOptions->DisplayOptionSet &&
ContainsValue(pDispOptions->pDisplayValues, BOOT_STATUS_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, BOOT_STATUS_STR, pAttributeStr);
FREE_POOL_SAFE(pAttributeStr);
}
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, BOOT_STATUS_REGISTER_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, BOOT_STATUS_REGISTER_STR,
FORMAT_HEX_PREFIX FORMAT_UINT32_HEX L"_" FORMAT_UINT32_HEX, ((BootStatusRegister >> 32) & 0xFFFFFFFF), (BootStatusRegister & 0xFFFFFFFF));
}
}
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_LATCH_SYSTEM_SHUTDOWN_STATE) {
/** LatchSystemShutdownState **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, LATCH_SYSTEM_SHUTDOWN_STATE_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, LATCH_SYSTEM_SHUTDOWN_STATE_STR, UNKNOWN_ATTRIB_VAL);
}
/** PreviousPowerCycleLatchSystemShutdownState **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, PREV_PWR_CYCLE_LATCH_SYSTEM_SHUTDOWN_STATE_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, PREV_PWR_CYCLE_LATCH_SYSTEM_SHUTDOWN_STATE_STR, UNKNOWN_ATTRIB_VAL);
}
}
else {
/** LatchSystemShutdownState **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, LATCH_SYSTEM_SHUTDOWN_STATE_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, LATCH_SYSTEM_SHUTDOWN_STATE_STR, FORMAT_INT32, pDimms[DimmIndex].LatchSystemShutdownState);
}
/** PreviousPowerCycleLatchSystemShutdownState **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, PREV_PWR_CYCLE_LATCH_SYSTEM_SHUTDOWN_STATE_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, PREV_PWR_CYCLE_LATCH_SYSTEM_SHUTDOWN_STATE_STR, FORMAT_INT32, pDimms[DimmIndex].PrevPwrCycleLatchSystemShutdownState);
}
}
/** ExtendedAdrEnabled **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, EXTENDED_ADR_ENABLED_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, EXTENDED_ADR_ENABLED_STR, ConvertDimmInfoAttribToString((VOID*)&pDimms[DimmIndex].ExtendedAdrEnabled, FORMAT_INT32));
}
/** PpcExtendedAdrEnabled **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, PPC_EXTENDED_ADR_ENABLED_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, PPC_EXTENDED_ADR_ENABLED_STR, ConvertDimmInfoAttribToString((VOID*)&pDimms[DimmIndex].PrevPwrCycleExtendedAdrEnabled, FORMAT_INT32));
}
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_MEM_INFO_PAGE) {
/** ErrorInjectionEnabled **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, ERROR_INJECT_ENABLED_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_INJECT_ENABLED_STR, UNKNOWN_ATTRIB_VAL);
}
/** MediaTemperatureInjectionEnabled **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MEDIA_TEMP_INJ_ENABLED_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, MEDIA_TEMP_INJ_ENABLED_STR, UNKNOWN_ATTRIB_VAL);
}
/** SoftwareTriggersEnabled **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SW_TRIGGERS_ENABLED_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, SW_TRIGGERS_ENABLED_STR, UNKNOWN_ATTRIB_VAL);
}
/** SoftwareTriggersEnabledDetails **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SW_TRIGGER_ENABLED_DETAILS_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, SW_TRIGGER_ENABLED_DETAILS_STR, UNKNOWN_ATTRIB_VAL);
}
/** PoisonErrorInjectionsCounter **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, POISON_ERR_INJ_CTR_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, POISON_ERR_INJ_CTR_STR, UNKNOWN_ATTRIB_VAL);
}
/** PoisonErrorClearCounter **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, POISON_ERR_CLR_CTR_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, POISON_ERR_CLR_CTR_STR, UNKNOWN_ATTRIB_VAL);
}
/** MediaTemperatureInjectionsCounter **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MEDIA_TEMP_INJ_CTR_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, MEDIA_TEMP_INJ_CTR_STR, UNKNOWN_ATTRIB_VAL);
}
/** SoftwareTriggersCounter **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SW_TRIGGER_CTR_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, SW_TRIGGER_CTR_STR, UNKNOWN_ATTRIB_VAL);
}
}
else {
/** ErrorInjectionEnabled **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, ERROR_INJECT_ENABLED_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, ERROR_INJECT_ENABLED_STR, FORMAT_INT32, pDimms[DimmIndex].ErrorInjectionEnabled);
}
/** MediaTemperatureInjectionEnabled **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MEDIA_TEMP_INJ_ENABLED_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MEDIA_TEMP_INJ_ENABLED_STR, FORMAT_INT32, pDimms[DimmIndex].MediaTemperatureInjectionEnabled);
}
/** SoftwareTriggersEnabled **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SW_TRIGGERS_ENABLED_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, SW_TRIGGERS_ENABLED_STR, FORMAT_INT32, pDimms[DimmIndex].SoftwareTriggersEnabled);
}
/** SoftwareTriggersEnabledDetails **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SW_TRIGGER_ENABLED_DETAILS_STR))) {
pAttributeStr = SoftwareTriggersEnabledToStr(pDimms[DimmIndex].SoftwareTriggersEnabledDetails);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, SW_TRIGGER_ENABLED_DETAILS_STR, pAttributeStr);
FREE_POOL_SAFE(pAttributeStr);
}
/** PoisonErrorInjectionsCounter **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, POISON_ERR_INJ_CTR_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, POISON_ERR_INJ_CTR_STR, FORMAT_INT32, pDimms[DimmIndex].PoisonErrorInjectionsCounter);
}
/** PoisonErrorClearCounter **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, POISON_ERR_CLR_CTR_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, POISON_ERR_CLR_CTR_STR, FORMAT_INT32, pDimms[DimmIndex].PoisonErrorClearCounter);
}
/** MediaTemperatureInjectionsCounter **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MEDIA_TEMP_INJ_CTR_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MEDIA_TEMP_INJ_CTR_STR, FORMAT_INT32, pDimms[DimmIndex].MediaTemperatureInjectionsCounter);
}
/** SoftwareTriggersCounter **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SW_TRIGGER_CTR_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, SW_TRIGGER_CTR_STR, FORMAT_INT32, pDimms[DimmIndex].SoftwareTriggersCounter);
}
if (!FIS_2_0) {
/** Max Controller Temperature **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MAX_CONTROLLER_TEMPERATURE_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MAX_CONTROLLER_TEMPERATURE_STR, NOT_APPLICABLE_SHORT_STR);
}
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MAX_MEDIA_TEMPERATURE_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MAX_MEDIA_TEMPERATURE_STR, NOT_APPLICABLE_SHORT_STR);
}
}
else {
/** Max Controller Temperature **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MAX_CONTROLLER_TEMPERATURE_STR))) {
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_SMART_AND_HEALTH) {
pAttributeStr = CatSPrint(NULL, FORMAT_STR, UNKNOWN_ATTRIB_VAL);
}
else {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MAX_CONTROLLER_TEMPERATURE_STR, FORMAT_UINT32 L" " TEMPERATURE_MSR, pDimms[DimmIndex].MaxControllerTemperature);
}
FREE_POOL_SAFE(pAttributeStr);
}
/** Max Media Temperature **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MAX_MEDIA_TEMPERATURE_STR))) {
if (pDimms[DimmIndex].ErrorMask & DIMM_INFO_ERROR_SMART_AND_HEALTH) {
pAttributeStr = CatSPrint(NULL, FORMAT_STR, UNKNOWN_ATTRIB_VAL);
}
else {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, MAX_MEDIA_TEMPERATURE_STR, FORMAT_UINT32 L" " TEMPERATURE_MSR, pDimms[DimmIndex].MaxMediaTemperature);
}
FREE_POOL_SAFE(pAttributeStr);
}
}
}
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MIXED_SKU_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, MIXED_SKU_STR, (IsMixedSku == TRUE) ? L"1" : L"0");
}
// Pass FIS version into determine FIPS string (print N/A for older versions)
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, FIPS_MODE_STATUS_STR))) {
// Get FIPS status
ReturnCode = pNvmDimmConfigProtocol->GetFIPSMode(pNvmDimmConfigProtocol, pDimms[DimmIndex].DimmID, &FIPSMode, pCommandStatus);
pStatusStr = ConvertFIPSModeToString(gNvmDimmCliHiiHandle, FIPSMode, pDimms[DimmIndex].FwVer, ReturnCode);
// Overwrite ReturnCode since we don't care if it failed
ReturnCode = EFI_SUCCESS;
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, FIPS_MODE_STATUS_STR, pStatusStr);
FREE_POOL_SAFE(pStatusStr);
}
}
else {
// Set certain fields to N/A if NVDIMM is unmanageable
for (Index3 = 0; Index3 < ALLOWED_DISP_VALUES_COUNT(pOnlyManageableAllowedDisplayValues); Index3++) {
if (ShowAll || ContainsValue(pDispOptions->pDisplayValues, pOnlyManageableAllowedDisplayValues[Index3])) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, pOnlyManageableAllowedDisplayValues[Index3], NA_STR);
}
}
}
}
}
if (FALSE == ShowAll && gNullValuesEncounteredForDisplay > 0) {
if (ReturnCode == EFI_SUCCESS) {
ReturnCode = EFI_INVALID_PARAMETER;
}
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_SOME_VALUES_NOT_SUPPORTED);
}
//Specify table attributes
PRINTER_CONFIGURE_DATA_ATTRIBUTES(pPrinterCtx, DS_ROOT_PATH, &ShowDimmDataSetAttribs);
Finish:
gDisplayNulls = FALSE;
gNullValuesEncounteredForDisplay = 0;
gNullValueToDisplay = pOriginalNullVal;
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FREE_POOL_SAFE(pPath);
FREE_CMD_DISPLAY_OPTIONS_SAFE(pDispOptions);
FREE_POOL_SAFE(pDimms);
FREE_POOL_SAFE(pAllDimms);
FREE_POOL_SAFE(pDimmIds);
FreeCommandStatus(&pCommandStatus);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Convert manageability state to a string
**/
STATIC
CHAR16*
ManageabilityToString(
IN UINT8 ManageabilityState
)
{
CHAR16 *pManageabilityString = NULL;
switch (ManageabilityState) {
case MANAGEMENT_VALID_CONFIG:
pManageabilityString = CatSPrint(NULL, FORMAT_STR, L"Manageable");
break;
case MANAGEMENT_INVALID_CONFIG:
default:
pManageabilityString = CatSPrint(NULL, FORMAT_STR, L"Unmanageable");
break;
}
return pManageabilityString;
}
/**
Convert population violation state to a string
**/
STATIC
CHAR16*
PopulationViolationToString(
IN BOOLEAN IsInPopulationViolation
)
{
CHAR16 *pPopulationViolationString = NULL;
pPopulationViolationString = CatSPrint(NULL, FORMAT_STR, IsInPopulationViolation ? L"Yes" : L"No");
return pPopulationViolationString;
}
/**
Convert type to string
**/
STATIC
CHAR16*
FormFactorToString(
IN UINT8 FormFactor
)
{
CHAR16 *pFormFactorStr = NULL;
switch (FormFactor) {
case MemoryFormFactorDimm:
pFormFactorStr = CatSPrint(NULL, FORMAT_STR, L"DIMM");
break;
case MemoryFormFactorSodimm:
pFormFactorStr = CatSPrint(NULL, FORMAT_STR, L"SODIMM");
break;
default:
pFormFactorStr = CatSPrint(NULL, FORMAT_STR, L"Other");
break;
}
return pFormFactorStr;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowDimmsCommand.h 0000664 0000000 0000000 00000015606 14165347476 0021320 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SHOW_DIMMS_COMMAND_H_
#define _SHOW_DIMMS_COMMAND_H_
#include "CommandParser.h"
#define UNKNOWN_ATTRIB_VAL L"Unknown"
/**
show -dimm display options
some of common display options are in CommandParser.h
**/
#define FW_VER_STR L"FWVersion"
#define FW_API_VER_STR L"FWAPIVersion"
#define FW_ACTIVE_API_VER_STR L"FWActiveAPIVersion"
#define INTERFACE_FORMAT_CODE_STR L"InterfaceFormatCode"
#define CAPACITY_STR L"Capacity"
#define MANAGEABILITY_STR L"ManageabilityState"
#define POPULATION_VIOLATION_STR L"PopulationViolation"
#define MANAGEABILITY_SHORT_STR L"Manageability"
#define HEALTH_STR L"HealthState"
#define HEALTH_STATE_REASON_STR L"HealthStateReason"
#define HEALTH_SHORT_STR L"Health"
#define SECURITY_STR L"LockState"
#define SVN_DOWNGRADE_OPT_IN_STR L"SVNDowngrade"
#define SEP_OPT_IN_STR L"SecureErasePolicy"
#define S3_RESUME_OPT_IN_STR L"S3ResumeOptIn"
#define FW_ACTIVATE_OPT_IN_STR L"FwActivateOptIn"
#define SECURITY_SKU_ID_STR L"SecuritySKUId"
#define SECURITY_SHORT_STR L"Security"
#define MASTER_STR L"Master"
#define TYPE_STR L"Type"
#define FORM_FACTOR_STR L"FormFactor"
#define VENDOR_ID_STR L"VendorID"
#define MANUFACTURER_ID_STR L"ManufacturerID"
#define MANUFACTURER_STR L"Manufacturer"
#define DEVICE_ID_STR L"DeviceID"
#define REVISION_ID_STR L"RevisionID"
#define SUBSYSTEM_VENDOR_ID_STR L"SubsystemVendorID"
#define SUBSYSTEM_DEVICE_ID_STR L"SubsystemDeviceID"
#define SUBSYSTEM_REVISION_ID_STR L"SubsystemRevisionID"
#define CONTROLLER_REVISION_ID_STR L"ControllerRevisionID"
#define MANUFACTURING_INFO_VALID L"ManufacturingInfoValid"
#define MANUFACTURING_LOCATION L"ManufacturingLocation"
#define MANUFACTURING_DATE L"ManufacturingDate"
#define PART_NUMBER_STR L"PartNumber"
#define SERIAL_NUMBER_STR L"SerialNumber"
#define BOOT_STATUS_REGISTER_STR L"BootStatusRegister"
#define DEVICE_LOCATOR_STR L"DeviceLocator"
#define MEMORY_CONTROLLER_STR L"MemControllerID"
#define CHANNEL_ID_STR L"ChannelID"
#define SLOT_ID_STR L"SlotID"
#define CHANNEL_POS_STR L"ChannelPos"
#define DATA_WIDTH_STR L"DataWidth"
#define TOTAL_WIDTH_STR L"TotalWidth"
#define SPEED_STR L"Speed"
#define MEMORY_MODE_CAPACITY_STR L"MemoryCapacity"
#define APPDIRECT_MODE_CAPACITY_STR L"AppDirectCapacity"
#define UNCONFIGURED_CAPACITY_STR L"UnconfiguredCapacity"
#define RESERVED_CAPACITY_STR L"ReservedCapacity"
#define PACKAGE_SPARING_ENABLED_STR L"PackageSparingEnabled"
#define PACKAGE_SPARING_CAPABLE_STR L"PackageSparingCapable"
#define PACKAGE_SPARES_AVAILABLE_STR L"PackageSparesAvailable"
#define IS_NEW_STR L"IsNew"
#define IN_VOLATILE_CAPACITY_STR L"InaccessibleVolatileCapacity"
#define IN_PERSISTENT_CAPACITY_STR L"InaccessiblePersistentCapacity"
#define BANK_LABEL_STR L"BankLabel"
#define MEMORY_TYPE_STR L"MemoryType"
#define PEAK_POWER_BUDGET_STR L"PeakPowerBudget"
#define AVG_POWER_LIMIT_STR L"AvgPowerLimit"
#define AVG_POWER_TIME_CONSTANT_STR L"AvgPowerTimeConstant"
#define MEMORY_BANDWIDTH_BOOST_FEATURE_STR L"MemoryBandwidthBoostFeature"
#define MEMORY_BANDWIDTH_BOOST_MAX_POWER_LIMIT_STR L"MemoryBandwidthBoostMaxPowerLimit"
#define MEMORY_BANDWIDTH_BOOST_AVERAGE_POWER_TIME_CONSTANT_STR L"MemoryBandwidthBoostAveragePowerTimeConstant"
#define LATCHED_LAST_SHUTDOWN_STATUS_STR L"LatchedLastShutdownStatus"
#define UNLATCHED_LAST_SHUTDOWN_STATUS_STR L"UnlatchedLastShutdownStatus"
#define THERMAL_THROTTLE_LOSS_STR L"ThermalThrottleLossPercent"
#define LAST_SHUTDOWN_TIME_STR L"LastShutdownTime"
#define PHYSICAL_ID_STR L"PhysicalID"
#define DIMM_HANDLE_STR L"DimmHandle"
#define DIMM_UID_STR L"DimmUID"
#define MODES_SUPPORTED_STR L"ModesSupported"
#define SECURITY_CAPABILITIES_STR L"SecurityCapabilities"
#define MASTER_PASS_ENABLED_STR L"MasterPassphraseEnabled"
#define DIMM_CONFIG_STATUS_STR L"ConfigurationStatus"
#define SKU_VIOLATION_STR L"SKUViolation"
#define ARS_STATUS_STR L"ARSStatus"
#define OVERWRITE_STATUS_STR L"OverwriteStatus"
#define RESERVED_CAPACITY_STR L"ReservedCapacity"
#define INACCESSIBLE_CAPACITY_STR L"InaccessibleCapacity"
#define VIRAL_POLICY_STR L"ViralPolicy"
#define VIRAL_STATE_STR L"ViralState"
#define AIT_DRAM_ENABLED_STR L"AitDramEnabled"
#define BOOT_STATUS_STR L"BootStatus"
#define ERROR_INJECT_ENABLED_STR L"ErrorInjectionEnabled"
#define MEDIA_TEMP_INJ_ENABLED_STR L"MediaTemperatureInjectionEnabled"
#define SW_TRIGGERS_ENABLED_STR L"SoftwareTriggersEnabled"
#define POISON_ERR_INJ_CTR_STR L"PoisonErrorInjectionsCounter"
#define POISON_ERR_CLR_CTR_STR L"PoisonErrorClearCounter"
#define MEDIA_TEMP_INJ_CTR_STR L"MediaTemperatureInjectionsCounter"
#define SW_TRIGGER_CTR_STR L"SoftwareTriggersCounter"
#define SW_TRIGGER_ENABLED_DETAILS_STR L"SoftwareTriggersEnabledDetails"
#define MAX_AVG_POWER_LIMIT_STR L"MaxAveragePowerLimit"
#define MAX_MEDIA_TEMPERATURE_STR L"MaxMediaTemperature"
#define MAX_CONTROLLER_TEMPERATURE_STR L"MaxControllerTemperature"
#define MAX_MEMORY_BANDWIDTH_BOOST_MAX_POWER_LIMIT L"MaxMemoryBandwidthBoostMaxPowerLimit"
#define MAX_MEMORY_BANDWIDTH_BOOST_AVERAGE_POWER_TIME_CONSTANT L"MaxMemoryBandwidthBoostAveragePowerTimeConstant"
#define MEMORY_BANDWIDTH_BOOST_AVERAGE_POWER_TIME_CONSTANT_STEP L"MemoryBandwidthBoostAveragePowerTimeConstantStep"
#define MAX_AVERAGE_POWER_REPORTING_TIME_CONSTANT L"MaxAveragePowerReportingTimeConstant"
#define AVERAGE_POWER_REPORTING_TIME_CONSTANT_STEP L"AveragePowerReportingTimeConstantStep"
#define MIXED_SKU_STR L"MixedSKU"
#define DCPMM_AVERAGE_POWER_STR L"AveragePower"
#define AVERAGE_12V_POWER_STR L"Average12vPower"
#define AVERAGE_1_2V_POWER_STR L"Average1_2vPower"
#define EXTENDED_ADR_ENABLED_STR L"ExtendedAdrEnabled"
#define PPC_EXTENDED_ADR_ENABLED_STR L"PpcExtendedAdrEnabled"
#define LATCH_SYSTEM_SHUTDOWN_STATE_STR L"LatchSystemShutdownState"
#define PREV_PWR_CYCLE_LATCH_SYSTEM_SHUTDOWN_STATE_STR L"PreviousPowerCycleLatchSystemShutdownState"
#define MILI_WATT_STR L"mW"
#define MEGA_TRANSFERS_PER_SEC_STR L"MT/s"
#define BYTE_STR L"b"
#define FIPS_MODE_STATUS_STR L"FIPSModeStatus"
/*
* Register the show dimms command
*/
EFI_STATUS RegisterShowDimmsCommand();
/*
* Execute the show dimms command
*/
EFI_STATUS ShowDimms(struct Command *pCmd);
#endif /* _SHOW_DIMMS_COMMAND_H_ */
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowErrorCommand.c 0000664 0000000 0000000 00000103501 14165347476 0021323 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include "ShowErrorCommand.h"
#include "DumpDebugCommand.h"
#include "NvmDimmCli.h"
#include "NvmInterface.h"
#include "LoadCommand.h"
#include "Debug.h"
#include "Convert.h"
/**
show -error syntax definition
**/
struct Command ShowErrorCommandSyntax =
{
SHOW_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"",HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{ALL_OPTION_SHORT, ALL_OPTION, L"", L"", HELP_ALL_DETAILS_TEXT,FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", LARGE_PAYLOAD_OPTION, L"", L"", HELP_LPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", SMALL_PAYLOAD_OPTION, L"", L"", HELP_SPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
#ifdef OS_BUILD
{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP, HELP_OPTIONS_DETAILS_TEXT,FALSE, ValueRequired }
#else
{L"", L"", L"", L"", L"",FALSE, ValueOptional}
#endif
},
{
{ERROR_TARGET, L"", HELP_TEXT_ERROR_LOG, TRUE, ValueRequired},
{DIMM_TARGET, L"", HELP_TEXT_DIMM_IDS, FALSE, ValueOptional}
},
{
{SEQUENCE_NUM_PROPERTY, L"", HELP_TEXT_ERROR_LOG_SEQ_NUM_PROPERTY, FALSE, ValueRequired},
{LEVEL_PROPERTY, L"", HELP_TEXT_ERROR_LOG_LEVEL_PROPERTY, FALSE, ValueRequired},
{COUNT_PROPERTY, L"", HELP_TEXT_ERROR_LOG_COUNT_PROPERTY, FALSE, ValueRequired}
}, //!< properties
L"Show error log for one or more " PMEM_MODULES_STR L".", //!< help
ShowErrorCommand, //!< run function
TRUE
};
#define DS_ROOT_PATH L"/ErrorList"
#define DS_DIMM_PATH L"/ErrorList/Dimm"
#define DS_DIMM_INDEX_PATH L"/ErrorList/Dimm[%d]"
#define DS_ERROR_PATH L"/ErrorList/Dimm/Error"
#define DS_ERROR_INDEX_PATH L"/ErrorList/Dimm[%d]/Error[%d]"
/**
List heading names
**/
#define ERROR_STR L"Error"
CHAR16 *mppAllowedShowErrorDisplayValues[] =
{
DIMM_ID_STR,
ERROR_STR
};
/*
* SHOW MEDIA ERROR ATTRIBUTES (3 columns)
* DimmID | System Timestamp | Error Type
* ==========================================
* 0x0001 | 01/01/1998 00:03:30 | x
* ...
*/
PRINTER_TABLE_ATTRIB ShowMediaErrorTableAttributes =
{
{
{
DIMM_ID_STR, //COLUMN HEADER
DIMM_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_DIMM_PATH PATH_KEY_DELIM DIMM_ID_STR //COLUMN DATA PATH
},
{
ERROR_SYSTEM_TIMESTAMP_STR, //COLUMN HEADER
SENSOR_VALUE_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_ERROR_PATH PATH_KEY_DELIM ERROR_SYSTEM_TIMESTAMP_STR //COLUMN DATA PATH
},
{
ERROR_MEDIA_ERROR_TYPE_STR, //COLUMN HEADER
ERROR_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_ERROR_PATH PATH_KEY_DELIM ERROR_MEDIA_ERROR_TYPE_STR //COLUMN DATA PATH
},
}
};
/*
* SHOW THERMAL ERROR ATTRIBUTES (4 columns)
* DimmID | System Timestamp | Temperature | Reported
* =======================================================
* 0x0001 | x | x | x
* ...
*/
PRINTER_TABLE_ATTRIB ShowThermalErrorTableAttributes =
{
{
{
DIMM_ID_STR, //COLUMN HEADER
DIMM_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_DIMM_PATH PATH_KEY_DELIM DIMM_ID_STR //COLUMN DATA PATH
},
{
ERROR_SYSTEM_TIMESTAMP_STR, //COLUMN HEADER
SENSOR_VALUE_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_ERROR_PATH PATH_KEY_DELIM ERROR_SYSTEM_TIMESTAMP_STR //COLUMN DATA PATH
},
{
ERROR_THERMAL_TEMPERATURE_STR, //COLUMN HEADER
TABLE_MIN_HEADER_LENGTH(ERROR_THERMAL_TEMPERATURE_STR), //COLUMN MAX STR WIDTH
DS_ERROR_PATH PATH_KEY_DELIM ERROR_THERMAL_TEMPERATURE_STR //COLUMN DATA PATH
},
{
ERROR_THERMAL_REPORTED_STR, //COLUMN HEADER
SENSOR_STATE_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_ERROR_PATH PATH_KEY_DELIM ERROR_THERMAL_REPORTED_STR //COLUMN DATA PATH
},
}
};
// List view for Media error
PRINTER_LIST_ATTRIB ShowMediaErrorListAttributes =
{
{
{
DIMM_NODE_STR, //GROUP LEVEL TYPE
L"---" DIMM_ID_STR L"=$(" DIMM_ID_STR L")---", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT FORMAT_STR L"=" FORMAT_STR, //NULL or KEY VAL FORMAT STR
DIMM_ID_STR //NULL or IGNORE KEY LIST (K1;K2)
},
{
ERROR_STR, //GROUP LEVEL TYPE
SHOW_LIST_IDENT L"---" ERROR_STR L"=$(" ERROR_STR L")", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT SHOW_LIST_IDENT FORMAT_STR L"=" FORMAT_STR, //NULL or KEY VAL FORMAT STR
ERROR_STR //NULL or IGNORE KEY LIST (K1;K2)
}
}
};
// List view for Thermal error
PRINTER_LIST_ATTRIB ShowThermalErrorListAttributes =
{
{
{
DIMM_NODE_STR, //GROUP LEVEL TYPE
L"---" DIMM_ID_STR L"=$(" DIMM_ID_STR L")---", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT FORMAT_STR L"=" FORMAT_STR, //NULL or KEY VAL FORMAT STR
DIMM_ID_STR //NULL or IGNORE KEY LIST (K1;K2)
},
{
ERROR_STR, //GROUP LEVEL TYPE
SHOW_LIST_IDENT L"---" ERROR_STR L"=$(" ERROR_STR L")", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT SHOW_LIST_IDENT FORMAT_STR L"=" FORMAT_STR, //NULL or KEY VAL FORMAT STR
ERROR_STR //NULL or IGNORE KEY LIST (K1;K2)
}
}
};
PRINTER_DATA_SET_ATTRIBS ShowMediaErrorDataSetAttribs =
{
&ShowMediaErrorListAttributes,
&ShowMediaErrorTableAttributes
};
PRINTER_DATA_SET_ATTRIBS ShowThermalErrorDataSetAttribs =
{
&ShowThermalErrorListAttributes,
&ShowThermalErrorTableAttributes
};
/**
Register the show -error command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowErrorCommand(
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&ShowErrorCommandSyntax);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Get error log command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
ShowErrorCommand(
IN struct Command *pCmd
)
{
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
COMMAND_STATUS *pCommandStatus = NULL;
EFI_STATUS ReturnCode = EFI_SUCCESS;
BOOLEAN ThermalError = FALSE;
BOOLEAN HighLevel = FALSE;
BOOLEAN IsNumber = FALSE;
CHAR16 *pTargetValue = NULL;
CHAR16 *pPropertyValue = NULL;
CHAR16 *pErrorType = NULL;
UINT16 *pDimmIds = NULL;
UINT32 DimmHandle = 0;
UINT32 DimmIndex = 0;
UINT16 Index = 0;
UINT16 Index2 = 0;
UINT32 DimmIdsNum = 0;
UINT16 SequenceNum = ERROR_LOG_DEFAULT_SEQUENCE_NUMBER; // By default start from first log
UINT32 RequestedCount = ERROR_LOG_MAX_COUNT; // By default get all logs
UINT32 ReturnedCount = 0;
UINT64 ParsedNumber = 0;
ERROR_LOG_INFO ErrorsArray[ERROR_LOG_MAX_COUNT];
MEDIA_ERROR_LOG_INFO *pMediaErrorInfo = NULL;
THERMAL_ERROR_LOG_INFO *pThermalErrorInfo = NULL;
DIMM_INFO *pDimms = NULL;
UINT32 DimmCount = 0;
CHAR16 DimmStr[MAX_DIMM_UID_LENGTH];
UINT16 ManageableListIndex = 0;
UINT64 RangeInBytes = 0;
CHAR16 *pTempStr = NULL;
PRINT_CONTEXT *pPrinterCtx = NULL;
CHAR16 *pPath = NULL;
CMD_DISPLAY_OPTIONS *pDispOptions = NULL;
BOOLEAN FoundMediaErrorFlag = FALSE;
UINT8 MediaErrorInfoCount = 0;
BOOLEAN ExcludeInvalidFields = FALSE;
NVDIMM_ENTRY();
ZeroMem(ErrorsArray, sizeof(ErrorsArray));
ZeroMem(DimmStr, sizeof(DimmStr));
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode) || pCommandStatus == NULL) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_INTERNAL_ERROR);
NVDIMM_DBG("Failed on InitializeCommandStatus");
goto Finish;
}
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("pCmd parameter is NULL.\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_NO_COMMAND);
goto Finish;
}
/**
Printing will still work via compatibility mode if NULL so no need to check for NULL.
**/
pPrinterCtx = pCmd->pPrintCtx;
pDispOptions = AllocateZeroPool(sizeof(CMD_DISPLAY_OPTIONS));
if (NULL == pDispOptions) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
ReturnCode = CheckAllAndDisplayOptions(pCmd, mppAllowedShowErrorDisplayValues,
ALLOWED_DISP_VALUES_COUNT(mppAllowedShowErrorDisplayValues), pDispOptions);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("CheckAllAndDisplayOptions has returned error. Code " FORMAT_EFI_STATUS "\n", ReturnCode);
goto Finish;
}
/** Get value of "error" target **/
pTargetValue = GetTargetValue(pCmd, ERROR_TARGET);
if (pTargetValue == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_INCOMPLETE_SYNTAX);
goto Finish;
}
if (StrICmp(pTargetValue, ERROR_TARGET_THERMAL_VALUE) == 0) {
ThermalError = TRUE;
}
else if (StrICmp(pTargetValue, ERROR_TARGET_MEDIA_VALUE) == 0) {
ThermalError = FALSE;
}
else {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_INCORRECT_VALUE_TARGET_ERROR);
goto Finish;
}
/** Open Config protocol **/
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// Populate the list of DIMM_INFO structures with relevant information
ReturnCode = GetAllDimmList(pNvmDimmConfigProtocol, pCmd, DIMM_INFO_CATEGORY_NONE, &pDimms, &DimmCount);
if (EFI_ERROR(ReturnCode)) {
if (ReturnCode == EFI_NOT_FOUND) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_INFO_NO_FUNCTIONAL_DIMMS);
}
goto Finish;
}
/** if a specific DIMM pid was passed in, set it **/
if (ContainTarget(pCmd, DIMM_TARGET)) {
pTargetValue = GetTargetValue(pCmd, DIMM_TARGET);
ReturnCode = GetDimmIdsFromString(pCmd, pTargetValue, pDimms, DimmCount, &pDimmIds, &DimmIdsNum);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Target value is not a valid Dimm ID");
goto Finish;
}
if (!AllDimmsInListAreManageable(pDimms, DimmCount, pDimmIds, DimmIdsNum)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_UNMANAGEABLE_DIMM);
goto Finish;
}
}
ReturnCode = GetPropertyValue(pCmd, SEQUENCE_NUM_PROPERTY, &pPropertyValue);
if (!EFI_ERROR(ReturnCode)) {
// If sequence number property exists, check it validity
IsNumber = GetU64FromString(pPropertyValue, &ParsedNumber);
if (!IsNumber) {
NVDIMM_WARN("Sequence number value is not a number");
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_INCORRECT_VALUE_PROPERTY_SEQ_NUM);
goto Finish;
}
else if (ParsedNumber > ERROR_LOG_MAX_SEQUENCE_NUMBER) {
NVDIMM_WARN("Sequence number value %d is greater than maximum %d", ParsedNumber, ERROR_LOG_MAX_SEQUENCE_NUMBER);
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_INCORRECT_VALUE_PROPERTY_SEQ_NUM);
goto Finish;
}
SequenceNum = (UINT16)ParsedNumber;
}
else {
// If sequence number property doesn't exists is ok, it is optional param, using default value
ReturnCode = EFI_SUCCESS;
}
ReturnCode = GetPropertyValue(pCmd, LEVEL_PROPERTY, &pPropertyValue);
if (!EFI_ERROR(ReturnCode)) {
// If level property exists, check it validity
if (StrICmp(pPropertyValue, LEVEL_HIGH_PROPERTY_VALUE) == 0) {
HighLevel = TRUE;
}
else if (StrICmp(pPropertyValue, LEVEL_LOW_PROPERTY_VALUE) == 0) {
HighLevel = FALSE;
}
else {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_WARN("Invalid Error Level. Error Level can be %s or %s", LEVEL_HIGH_PROPERTY_VALUE, LEVEL_LOW_PROPERTY_VALUE);
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_INCORRECT_VALUE_PROPERTY_LEVEL);
goto Finish;
}
}
else {
// If level property doesn't exists is ok, it is optional param, using default value
HighLevel = TRUE;
ReturnCode = EFI_SUCCESS;
}
ReturnCode = GetPropertyValue(pCmd, COUNT_PROPERTY, &pPropertyValue);
if (!EFI_ERROR(ReturnCode)) {
// If Count property exists, check it validity
IsNumber = GetU64FromString(pPropertyValue, &ParsedNumber);
if (!IsNumber) {
NVDIMM_WARN("Count value is not a number");
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_INCORRECT_VALUE_PROPERTY_COUNT);
goto Finish;
}
else if (ParsedNumber > ERROR_LOG_MAX_COUNT) {
NVDIMM_WARN("Count value %d is greater than maximum %d", ParsedNumber, ERROR_LOG_MAX_COUNT);
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_INCORRECT_VALUE_PROPERTY_COUNT);
goto Finish;
}
RequestedCount = (UINT32)ParsedNumber;
}
else {
// If count property doesn't exists is ok, it is optional param, using default value
ReturnCode = EFI_SUCCESS;
}
if (DimmIdsNum == 0) {
DimmIdsNum = DimmCount;
FREE_POOL_SAFE(pDimmIds);
pDimmIds = AllocateZeroPool(sizeof(*pDimmIds) * DimmIdsNum);
if (pDimmIds == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
NVDIMM_WARN("Failed on memory allocation.");
goto Finish;
}
for (Index = 0; Index < DimmIdsNum; Index++) {
if (MANAGEMENT_VALID_CONFIG == pDimms[Index].ManageabilityState){
pDimmIds[ManageableListIndex] = pDimms[Index].DimmID;
ManageableListIndex++;
}
}
DimmIdsNum = ManageableListIndex;
}
if (DimmIdsNum == 0) {
ResetCmdStatus(pCommandStatus, NVM_ERR_MANAGEABLE_DIMM_NOT_FOUND);
goto Finish;
}
for (Index = 0; Index < DimmIdsNum; Index++) {
ReturnedCount = RequestedCount;
ReturnCode = GetDimmHandleByPid(pDimmIds[Index], pDimms, DimmCount, &DimmHandle, &DimmIndex);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
ReturnCode = GetPreferredDimmIdAsString(DimmHandle, pDimms[DimmIndex].DimmUid,
DimmStr, MAX_DIMM_UID_LENGTH);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
ReturnCode = pNvmDimmConfigProtocol->GetErrorLog(pNvmDimmConfigProtocol,
&pDimmIds[Index],
1,
ThermalError,
SequenceNum,
HighLevel,
&ReturnedCount,
ErrorsArray,
pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
if (pCommandStatus->GeneralStatus != NVM_SUCCESS) {
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
}
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"Failed to get error logs from " PMEM_MODULE_STR L" " FORMAT_STR L"\n", DimmStr);
continue;
}
if (ReturnedCount == 0) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"No errors found on " PMEM_MODULE_STR L" " FORMAT_STR L"\n", DimmStr);
}
else {
PRINTER_BUILD_KEY_PATH(pPath, DS_DIMM_INDEX_PATH, Index);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DIMM_ID_STR, DimmStr);
for (Index2 = 0; Index2 < ReturnedCount; Index2++) {
pErrorType = (ErrorsArray[Index2].ErrorType == THERMAL_ERROR ?
ERROR_THERMAL_OCCURRED_STR : ERROR_MEDIA_OCCURRED_STR);
PRINTER_BUILD_KEY_PATH(pPath, DS_ERROR_INDEX_PATH, Index, Index2);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_STR, pErrorType);
pTempStr = GetTimeFormatString(ErrorsArray[Index2].SystemTimestamp, FALSE);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_SYSTEM_TIMESTAMP_STR, pTempStr);
FREE_POOL_SAFE(pTempStr);
if (ErrorsArray[Index2].ErrorType == THERMAL_ERROR) {
pThermalErrorInfo = (THERMAL_ERROR_LOG_INFO *)ErrorsArray[Index2].OutputData;
PRINTER_SET_KEY_VAL_UINT16(pPrinterCtx, pPath, ERROR_THERMAL_TEMPERATURE_STR, pThermalErrorInfo->Temperature, DECIMAL);
// Thermal Reported
if (pThermalErrorInfo->Reported == ERROR_THERMAL_REPORTED_USER_ALARM) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_THERMAL_REPORTED_STR, ERROR_THERMAL_REPORTED_USER_ALARM_STR);
}
else if (pThermalErrorInfo->Reported == ERROR_THERMAL_REPORTED_LOW) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_THERMAL_REPORTED_STR, ERROR_THERMAL_REPORTED_LOW_STR);
}
else if (pThermalErrorInfo->Reported == ERROR_THERMAL_REPORTED_HIGH) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_THERMAL_REPORTED_STR, ERROR_THERMAL_REPORTED_HIGH_STR);
}
else if (pThermalErrorInfo->Reported == ERROR_THERMAL_REPORTED_CRITICAL) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_THERMAL_REPORTED_STR, ERROR_THERMAL_REPORTED_CRITICAL_STR);
}
else {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_THERMAL_REPORTED_STR, ERROR_THERMAL_REPORTED_UNKNOWN_STR);
}
// Temperature Type
if (pDispOptions->AllOptionSet || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, ERROR_SEQUENCE_NUMBER))) {
if (pThermalErrorInfo->Type == ERROR_THERMAL_TYPE_MEDIA) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_THERMAL_TYPE_STR, ERROR_THERMAL_TYPE_MEDIA_STR);
}
else if (pThermalErrorInfo->Type == ERROR_THERMAL_TYPE_CONTROLLER) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_THERMAL_TYPE_STR, ERROR_THERMAL_TYPE_CONTROLLER_STR);
}
else {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_THERMAL_TYPE_STR, ERROR_THERMAL_TYPE_UNKNOWN_STR);
}
}
if (pDispOptions->AllOptionSet || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, ERROR_SEQUENCE_NUMBER))) {
PRINTER_SET_KEY_VAL_UINT16(pPrinterCtx, pPath, ERROR_SEQUENCE_NUMBER, pThermalErrorInfo->SequenceNum, DECIMAL);
}
}
else {
pMediaErrorInfo = (MEDIA_ERROR_LOG_INFO *)ErrorsArray[Index2].OutputData;
ExcludeInvalidFields = FALSE;
// Error Type
switch (pMediaErrorInfo->ErrorType) {
case ERROR_TYPE_UNCORRECTABLE:
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_TYPE_UNCORRECTABLE, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_TYPE_UNCORRECTABLE_STR);
break;
case ERROR_TYPE_DPA_MISMATCH:
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_TYPE_DPA_MISMATCH, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_TYPE_DPA_MISMATCH_STR);
break;
case ERROR_TYPE_AIT_ERROR:
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_TYPE_AIT_ERROR, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_TYPE_AIT_ERROR_STR);
break;
case ERROR_TYPE_DATA_PATH_ERROR:
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_TYPE_DATA_PATH_ERROR, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_TYPE_DATA_PATH_ERROR_STR);
break;
case ERROR_TYPE_LOCKED_ILLEGAL_ACCESS:
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_TYPE_LOCKED_ILLEGAL_ACCESS, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_TYPE_LOCKED_ILLEGAL_ACCESS_STR);
break;
case ERROR_TYPE_PERCENTAGE_REMAINING:
ExcludeInvalidFields = TRUE;
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_TYPE_PERCENTAGE_REMAINING, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_TYPE_PERCENTAGE_REMAINING_STR);
break;
case ERROR_TYPE_SMART_CHANGE:
ExcludeInvalidFields = TRUE;
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_TYPE_SMART_CHANGE, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_TYPE_SMART_CHANGE_STR);
break;
case ERROR_TYPE_PERSISTENT_WRITE_ECC:
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_TYPE_PERSISTENT_WRITE_ECC, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_TYPE_PERSISTENT_WRITE_ECC_STR);
break;
default:
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_TYPE_STR, ERROR_TYPE_UNKNOWN_STR);
break;
}
// Transaction Type
if (!ExcludeInvalidFields && (pDispOptions->AllOptionSet ||
(pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, ERROR_MEDIA_TRANSACTION_TYPE_STR)))) {
switch (pMediaErrorInfo->TransactionType) {
case TRANSACTION_TYPE_2LM_READ:
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_2LM_READ, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_2LM_READ_STR);
break;
case TRANSACTION_TYPE_2LM_WRITE:
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_2LM_WRITE, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_2LM_WRITE_STR);
break;
case TRANSACTION_TYPE_PM_READ:
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_PM_READ, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_PM_READ_STR);
break;
case TRANSACTION_TYPE_PM_WRITE:
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_PM_WRITE, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_PM_WRITE_STR);
break;
case TRANSACTION_TYPE_AIT_READ:
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_AIT_READ, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_AIT_READ_STR);
break;
case TRANSACTION_TYPE_AIT_WRITE:
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_AIT_WRITE, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_AIT_WRITE_STR);
break;
case TRANSACTION_TYPE_WEAR_LEVEL_MOVE:
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_WEAR_LEVEL_MOVE, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_WEAR_LEVEL_MOVE_STR);
break;
case TRANSACTION_TYPE_PATROL_SCRUB:
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_PATROL_SCRUB, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_PATROL_SCRUB_STR);
break;
case TRANSACTION_TYPE_CSR_READ:
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_CSR_READ, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_CSR_READ_STR);
break;
case TRANSACTION_TYPE_CSR_WRITE:
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_CSR_WRITE, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_CSR_WRITE_STR);
break;
case TRANSACTION_TYPE_ARS:
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_ARS, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_ARS_STR);
break;
case TRANSACTION_TYPE_UNAVAILABLE:
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_UNAVAILABLE, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, ERROR_MSG_EXTRA_SPACE);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_UNAVAILABLE_STR);
break;
default:
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, TRANSACTION_TYPE_UNKNOWN_STR);
break;
}
}
else if (ExcludeInvalidFields) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_TRANSACTION_TYPE_STR, NA_STR);
}
// Media Error info flags
if (pDispOptions->AllOptionSet || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, ERROR_MEDIA_ERROR_FLAGS_STR))) {
if (pMediaErrorInfo->PdaValid) {
MediaErrorInfoCount = MediaErrorInfoCount | pMediaErrorInfo->PdaValid;
}
if (pMediaErrorInfo->DpaValid) {
MediaErrorInfoCount = MediaErrorInfoCount | (pMediaErrorInfo->DpaValid << 1);
}
if (pMediaErrorInfo->Interrupt) {
MediaErrorInfoCount = MediaErrorInfoCount | (pMediaErrorInfo->Interrupt << 2);
}
PRINTER_SET_KEY_VAL_UINT8(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_FLAGS_STR, MediaErrorInfoCount, HEX);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_FLAGS_STR, ERROR_MSG_EXTRA_SPACE);
if (pMediaErrorInfo->PdaValid) {
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_FLAGS_STR, ERROR_FLAGS_PDA_VALID_STR);
FoundMediaErrorFlag = TRUE;
}
if (pMediaErrorInfo->DpaValid) {
if (FoundMediaErrorFlag == TRUE) {
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_FLAGS_STR, ERROR_MSG_COMA_CHAR);
}
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_FLAGS_STR, ERROR_FLAGS_DPA_VALID_STR);
FoundMediaErrorFlag = TRUE;
}
if (pMediaErrorInfo->Interrupt) {
if (FoundMediaErrorFlag == TRUE) {
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_FLAGS_STR, ERROR_MSG_COMA_CHAR);
}
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_ERROR_FLAGS_STR, ERROR_FLAGS_INTERRUPT_STR);
}
FoundMediaErrorFlag = FALSE;
MediaErrorInfoCount = 0;
}
if (pDispOptions->AllOptionSet || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, ERROR_MEDIA_DPA_STR))) {
if (ExcludeInvalidFields || !pMediaErrorInfo->DpaValid) {
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_DPA_STR, NA_STR);
}
else {
PRINTER_SET_KEY_VAL_UINT64(pPrinterCtx, pPath, ERROR_MEDIA_DPA_STR, pMediaErrorInfo->Dpa, HEX);
}
}
if (pDispOptions->AllOptionSet || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, ERROR_MEDIA_PDA_STR))) {
if (ExcludeInvalidFields || !pMediaErrorInfo->PdaValid) {
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_PDA_STR, NA_STR);
}
else {
PRINTER_SET_KEY_VAL_UINT64(pPrinterCtx, pPath, ERROR_MEDIA_PDA_STR, pMediaErrorInfo->Pda, HEX);
}
}
// Range in bytes
if (pDispOptions->AllOptionSet || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, ERROR_MEDIA_RANGE_STR))) {
RangeInBytes = Pow(2, pMediaErrorInfo->Range);
if (ExcludeInvalidFields) {
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_RANGE_STR, NA_STR);
}
else {
PRINTER_SET_KEY_VAL_UINT64(pPrinterCtx, pPath, ERROR_MEDIA_RANGE_STR, RangeInBytes, DECIMAL);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ERROR_MEDIA_RANGE_STR, ERROR_MSG_BYTE_CHAR);
}
}
if (pDispOptions->AllOptionSet || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, ERROR_SEQUENCE_NUMBER))) {
PRINTER_SET_KEY_VAL_UINT64(pPrinterCtx, pPath, ERROR_SEQUENCE_NUMBER, pMediaErrorInfo->SequenceNum, DECIMAL);
}
}
}
}
}
if (ThermalError == FALSE) {
PRINTER_CONFIGURE_DATA_ATTRIBUTES(pPrinterCtx, DS_ROOT_PATH, &ShowMediaErrorDataSetAttribs);
}
else {
PRINTER_CONFIGURE_DATA_ATTRIBUTES(pPrinterCtx, DS_ROOT_PATH, &ShowThermalErrorDataSetAttribs);
}
Finish:
PRINTER_SET_COMMAND_STATUS(pCmd->pPrintCtx, ReturnCode, L"Show Error", CLI_INFO_ON, pCommandStatus);
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FREE_POOL_SAFE(pPath);
FreeCommandStatus(&pCommandStatus);
FREE_POOL_SAFE(pDimmIds);
FREE_POOL_SAFE(pDimms);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowErrorCommand.h 0000664 0000000 0000000 00000011600 14165347476 0021326 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SHOW_ERROR_COMMAND_H_
#define _SHOW_ERROR_COMMAND_H_
#include
#include "NvmInterface.h"
#include "Common.h"
#define ERROR_MAX_STR_WIDTH 36
#define ERROR_MIN_STR_WIDTH 8
#define ERROR_MSG_EXTRA_SPACE L" - "
#define ERROR_MSG_BYTE_CHAR L"B"
#define ERROR_MSG_COMA_CHAR L", "
#define ERROR_THERMAL_OCCURRED_STR L"Thermal"
#define ERROR_MEDIA_OCCURRED_STR L"Media"
#define ERROR_SYSTEM_TIMESTAMP_STR L"System Timestamp"
#define ERROR_THERMAL_TEMPERATURE_STR L"Temperature"
#define ERROR_THERMAL_REPORTED_STR L"Reported"
#define ERROR_THERMAL_TYPE_STR L"Temperature Type"
#define ERROR_MEDIA_DPA_STR L"DPA"
#define ERROR_MEDIA_PDA_STR L"PDA"
#define ERROR_MEDIA_RANGE_STR L"Range"
#define ERROR_MEDIA_ERROR_TYPE_STR L"Error Type"
#define ERROR_MEDIA_ERROR_FLAGS_STR L"Error Flags"
#define ERROR_MEDIA_TRANSACTION_TYPE_STR L"Transaction Type"
#define ERROR_SEQUENCE_NUMBER L"Sequence Number"
#define ERROR_THERMAL_REPORTED_USER_ALARM 0 //0b000
#define ERROR_THERMAL_REPORTED_LOW 1 //0b001
#define ERROR_THERMAL_REPORTED_HIGH 2 //0b010
#define ERROR_THERMAL_REPORTED_CRITICAL 4 //0b100
#define ERROR_THERMAL_REPORTED_USER_ALARM_STR L"User Alarm Trip"
#define ERROR_THERMAL_REPORTED_LOW_STR L"Low"
#define ERROR_THERMAL_REPORTED_HIGH_STR L"High"
#define ERROR_THERMAL_REPORTED_CRITICAL_STR L"Critical"
#define ERROR_THERMAL_REPORTED_UNKNOWN_STR L"Unknown"
#define ERROR_THERMAL_TYPE_MEDIA 0x00
#define ERROR_THERMAL_TYPE_CONTROLLER 0x01
#define ERROR_THERMAL_TYPE_MEDIA_STR L"Media Temperature"
#define ERROR_THERMAL_TYPE_CONTROLLER_STR L"Controller Temperature"
#define ERROR_THERMAL_TYPE_UNKNOWN_STR L"Unknown"
#define ERROR_TYPE_UNCORRECTABLE 0x00
#define ERROR_TYPE_DPA_MISMATCH 0x01
#define ERROR_TYPE_AIT_ERROR 0x02
#define ERROR_TYPE_DATA_PATH_ERROR 0x03
#define ERROR_TYPE_LOCKED_ILLEGAL_ACCESS 0x04
#define ERROR_TYPE_PERCENTAGE_REMAINING 0x05
#define ERROR_TYPE_SMART_CHANGE 0x06
#define ERROR_TYPE_PERSISTENT_WRITE_ECC 0x07
#define ERROR_TYPE_UNCORRECTABLE_STR L"Uncorrectable"
#define ERROR_TYPE_DPA_MISMATCH_STR L"DPA Mismatch"
#define ERROR_TYPE_AIT_ERROR_STR L"AIT Error"
#define ERROR_TYPE_DATA_PATH_ERROR_STR L"Data Path Error"
#define ERROR_TYPE_LOCKED_ILLEGAL_ACCESS_STR L"Locked/Illegal Access"
#define ERROR_TYPE_PERCENTAGE_REMAINING_STR L"User Percentage Remaining Alarm Trip"
#define ERROR_TYPE_SMART_CHANGE_STR L"Smart Health Status Change"
#define ERROR_TYPE_PERSISTENT_WRITE_ECC_STR L"Persistent Write ECC"
#define ERROR_TYPE_UNKNOWN_STR L"Unknown"
#define ERROR_FLAGS_PDA_VALID_STR L"PDA Valid"
#define ERROR_FLAGS_DPA_VALID_STR L"DPA Valid"
#define ERROR_FLAGS_INTERRUPT_STR L"Interrupt"
#define ERROR_FLAGS_VIRAL_STR L"Viral"
#define TRANSACTION_TYPE_2LM_READ 0x00
#define TRANSACTION_TYPE_2LM_WRITE 0x01
#define TRANSACTION_TYPE_PM_READ 0x02
#define TRANSACTION_TYPE_PM_WRITE 0x03
#define TRANSACTION_TYPE_AIT_READ 0x06
#define TRANSACTION_TYPE_AIT_WRITE 0x07
#define TRANSACTION_TYPE_WEAR_LEVEL_MOVE 0x08
#define TRANSACTION_TYPE_PATROL_SCRUB 0x09
#define TRANSACTION_TYPE_CSR_READ 0x0A
#define TRANSACTION_TYPE_CSR_WRITE 0x0B
#define TRANSACTION_TYPE_ARS 0x0C
#define TRANSACTION_TYPE_UNAVAILABLE 0x0D
#define TRANSACTION_TYPE_2LM_READ_STR L"2LM Read"
#define TRANSACTION_TYPE_2LM_WRITE_STR L"2LM Write"
#define TRANSACTION_TYPE_PM_READ_STR L"PM Read"
#define TRANSACTION_TYPE_PM_WRITE_STR L"PM Write"
#define TRANSACTION_TYPE_AIT_READ_STR L"AIT Read"
#define TRANSACTION_TYPE_AIT_WRITE_STR L"AIT Write"
#define TRANSACTION_TYPE_WEAR_LEVEL_MOVE_STR L"Wear Level Mode"
#define TRANSACTION_TYPE_PATROL_SCRUB_STR L"Patrol Scrub"
#define TRANSACTION_TYPE_CSR_READ_STR L"CSR Read"
#define TRANSACTION_TYPE_CSR_WRITE_STR L"CSR Write"
#define TRANSACTION_TYPE_ARS_STR L"Address Range Scrub"
#define TRANSACTION_TYPE_UNAVAILABLE_STR L"Unavailable"
#define TRANSACTION_TYPE_UNKNOWN_STR L"Unknown"
#define HELP_TEXT_ERROR_LOG_SEQ_NUM_PROPERTY L"<1, 65535>"
#define HELP_TEXT_ERROR_LOG_COUNT_PROPERTY L"<0, 255>"
#define HELP_TEXT_ERROR_LOG_LEVEL_PROPERTY L"Low|High"
/**
Register syntax of show -error
**/
EFI_STATUS
RegisterShowErrorCommand(
);
/**
Get error log command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
ShowErrorCommand(
IN struct Command *pCmd
);
#endif
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowFirmwareCommand.c 0000664 0000000 0000000 00000030415 14165347476 0022011 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include
#include "ShowFirmwareCommand.h"
#include "NvmDimmCli.h"
#define ACTIVE_FW_VERSION_STR L"ActiveFWVersion"
#define STAGED_FW_VERSION_STR L"StagedFWVersion"
#define STAGED_FW_ACTIVATABLE_STR L"StagedFWActivatable"
#define FW_UPDATE_STATUS_STR L"FWUpdateStatus"
#define FW_IMAGE_MAX_SIZE_STR L"FWImageMaxSize"
#define QUIESCE_REQUIRED_STR L"QuiesceRequired"
#define ACTIVATION_TIME_STR L"ActivationTime"
#define DS_ROOT_PATH L"/DimmFirmwareList"
#define DS_DIMM_FW_PATH L"/DimmFirmwareList/DimmFirmware"
#define DS_DIMM_FW_INDEX_PATH L"/DimmFirmwareList/DimmFirmware[%d]"
#define DS_GROUP_STR L"DimmFirmware"
/*
* PRINT LIST ATTRIBUTES
* ---DimmId=0x0001---
* ActiveFwVersion=X
* StagedFwVersion=X
* ...
*/
PRINTER_LIST_ATTRIB ShowFirmwareListAttributes =
{
{
{
DS_GROUP_STR, //GROUP LEVEL TYPE
L"---" DIMM_ID_STR L"=$(" DIMM_ID_STR L")---", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT L"%ls=%ls", //NULL or KEY VAL FORMAT STR
DIMM_ID_STR //NULL or IGNORE KEY LIST (K1;K2)
}
}
};
/*
* PRINTER TABLE ATTRIBUTES (3 columns)
* DimmID | ActiveFwVersion | StagedFwVersion
* ================================================
* 0x0001 | aa.bb.cc.dddd | aa.bb.cc.dddd
* ...
*/
PRINTER_TABLE_ATTRIB ShowFirmwareTableAttributes =
{
{
{
DIMM_ID_STR, //COLUMN HEADER
DIMM_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_DIMM_FW_PATH PATH_KEY_DELIM DIMM_ID_STR //COLUMN DATA PATH
},
{
ACTIVE_FW_VERSION_STR, //COLUMN HEADER
ACTIVE_FW_VERSION_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_DIMM_FW_PATH PATH_KEY_DELIM ACTIVE_FW_VERSION_STR //COLUMN DATA PATH
},
{
STAGED_FW_VERSION_STR, //COLUMN HEADER
STAGED_FW_VERSION_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_DIMM_FW_PATH PATH_KEY_DELIM STAGED_FW_VERSION_STR //COLUMN DATA PATH
}
}
};
PRINTER_DATA_SET_ATTRIBS ShowFirmwareDataSetAttribs =
{
&ShowFirmwareListAttributes,
&ShowFirmwareTableAttributes
};
/** Command syntax definition **/
struct Command ShowFirmwareCommand =
{
SHOW_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"",HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{ALL_OPTION_SHORT, ALL_OPTION, L"", L"",HELP_ALL_DETAILS_TEXT, FALSE, ValueEmpty},
{DISPLAY_OPTION_SHORT, DISPLAY_OPTION, L"", HELP_TEXT_ATTRIBUTES,HELP_DISPLAY_DETAILS_TEXT, FALSE, ValueRequired}
#ifdef OS_BUILD
,{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP,HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#endif
},
{ //!< targets
{DIMM_TARGET, L"", HELP_TEXT_DIMM_IDS, FALSE, ValueOptional},
{FIRMWARE_TARGET, L"", L"", TRUE, ValueEmpty}
},
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Show information about firmware on one or more " PMEM_MODULES_STR L".", //!< help
ShowFirmware, //!< run function
TRUE, //!< enable print control support
};
CHAR16 *mppAllowedShowFirmwareDisplayValues[] = {
DIMM_ID_STR,
ACTIVE_FW_VERSION_STR,
STAGED_FW_VERSION_STR,
STAGED_FW_ACTIVATABLE_STR,
FW_UPDATE_STATUS_STR,
FW_IMAGE_MAX_SIZE_STR,
QUIESCE_REQUIRED_STR,
ACTIVATION_TIME_STR
};
/**
Register the show firmware command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowFirmwareCommand(
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&ShowFirmwareCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Execute the show firmware command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS on success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_ABORTED invoking CONFIG_PROTOCOL function failure
**/
EFI_STATUS
ShowFirmware(
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
COMMAND_STATUS *pCommandStatus = NULL;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
CHAR16 *pTargetValue = NULL;
UINT16 *pDimmIds = NULL;
UINT32 DimmIdsCount = 0;
UINT32 Index = 0;
CHAR16 *pFwUpdateStatusString = NULL;
CHAR16 *pQuiesceRequiredString = NULL;
CHAR16 *pStagedFwActivatableString = NULL;
DIMM_INFO *pDimms = NULL;
UINT32 DimmCount = 0;
CHAR16 DimmStr[MAX_DIMM_UID_LENGTH];
CMD_DISPLAY_OPTIONS *pDispOptions = NULL;
BOOLEAN ShowAll = FALSE;
PRINT_CONTEXT *pPrinterCtx = NULL;
CHAR16 *pPath = NULL;
CHAR16 FwVerStr[FW_VERSION_LEN];
UINT8 ManageableDimmsCount = 0;
NVDIMM_ENTRY();
ZeroMem(DimmStr, sizeof(DimmStr));
if (pCmd == NULL || pCmd->pPrintCtx == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
pDispOptions = AllocateZeroPool(sizeof(CMD_DISPLAY_OPTIONS));
if (NULL == pDispOptions) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
ReturnCode = CheckAllAndDisplayOptions(pCmd, mppAllowedShowFirmwareDisplayValues,
ALLOWED_DISP_VALUES_COUNT(mppAllowedShowFirmwareDisplayValues), pDispOptions);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("CheckAllAndDisplayOptions has returned error. Code " FORMAT_EFI_STATUS "\n", ReturnCode);
goto Finish;
}
ShowAll = (!pDispOptions->AllOptionSet && !pDispOptions->DisplayOptionSet) || pDispOptions->AllOptionSet;
/** Make sure we can access the config protocol **/
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// Populate the list of DIMM_INFO structures with relevant information
CHECK_RESULT(GetAllDimmList(pNvmDimmConfigProtocol, pCmd, DIMM_INFO_CATEGORY_FW_IMAGE_INFO, &pDimms, &DimmCount), Finish);
/** Initialize status structure **/
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_ABORTED;
NVDIMM_DBG("Failed on InitializeCommandStatus");
goto Finish;
}
/** Get DCPMMs list **/
if (ContainTarget(pCmd, DIMM_TARGET)) {
pTargetValue = GetTargetValue(pCmd, DIMM_TARGET);
ReturnCode = GetDimmIdsFromString(pCmd, pTargetValue, pDimms, DimmCount, &pDimmIds, &DimmIdsCount);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
if (!AllDimmsInListAreManageable(pDimms, DimmCount, pDimmIds, DimmIdsCount)){
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_UNMANAGEABLE_DIMM);
goto Finish;
}
}
/** Print table **/
for (Index = 0; Index < DimmCount; Index++) {
if (DimmIdsCount > 0) {
if (!ContainUint(pDimmIds, DimmIdsCount, pDimms[Index].DimmID)) {
continue;
}
}
if (pDimms[Index].ManageabilityState != MANAGEMENT_VALID_CONFIG) {
continue;
}
ManageableDimmsCount++;
ReturnCode = GetPreferredDimmIdAsString(pDimms[Index].DimmHandle, pDimms[Index].DimmUid,
DimmStr, MAX_DIMM_UID_LENGTH);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
PRINTER_BUILD_KEY_PATH(pPath, DS_DIMM_FW_INDEX_PATH, Index);
/** DimmID **/
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DIMM_ID_STR, DimmStr);
/** ActiveFwVersion **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, ACTIVE_FW_VERSION_STR))) {
ConvertFwVersion(FwVerStr, pDimms[Index].FwVer.FwProduct, pDimms[Index].FwVer.FwRevision,
pDimms[Index].FwVer.FwSecurityVersion, pDimms[Index].FwVer.FwBuild);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ACTIVE_FW_VERSION_STR, FwVerStr);
}
/** StagedFwVersion **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, STAGED_FW_VERSION_STR))) {
ConvertFwVersion(FwVerStr, pDimms[Index].StagedFwVersion.FwProduct, pDimms[Index].StagedFwVersion.FwRevision,
pDimms[Index].StagedFwVersion.FwSecurityVersion, pDimms[Index].StagedFwVersion.FwBuild);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, STAGED_FW_VERSION_STR, FwVerStr);
}
/** StagedFwActivatable **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, STAGED_FW_ACTIVATABLE_STR))) {
pStagedFwActivatableString = StagedFwActivatableToString(gNvmDimmCliHiiHandle, pDimms[Index].StagedFwActivatable);
if (pStagedFwActivatableString == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, STAGED_FW_ACTIVATABLE_STR, pStagedFwActivatableString);
FREE_POOL_SAFE(pStagedFwActivatableString);
}
/** FwUpdateStatus **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, FW_UPDATE_STATUS_STR))) {
pFwUpdateStatusString = LastFwUpdateStatusToString(gNvmDimmCliHiiHandle, pDimms[Index].LastFwUpdateStatus);
if (pFwUpdateStatusString == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, FW_UPDATE_STATUS_STR, pFwUpdateStatusString);
FREE_POOL_SAFE(pFwUpdateStatusString);
}
/** FwImageMaxSize **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, FW_IMAGE_MAX_SIZE_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, FW_IMAGE_MAX_SIZE_STR, FORMAT_UINT32, pDimms[Index].FWImageMaxSize);
}
/** Quiesce Required **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, QUIESCE_REQUIRED_STR))) {
pQuiesceRequiredString = QuiesceRequiredToString(gNvmDimmCliHiiHandle, pDimms[Index].QuiesceRequired);
if (pQuiesceRequiredString == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, QUIESCE_REQUIRED_STR, pQuiesceRequiredString);
FREE_POOL_SAFE(pQuiesceRequiredString);
}
/** Activation Time **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, ACTIVATION_TIME_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, ACTIVATION_TIME_STR, FORMAT_UINT32, pDimms[Index].ActivationTime);
}
}
if (ManageableDimmsCount == 0) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_INFO_NO_MANAGEABLE_DIMMS);
goto Finish;
}
ReturnCode = EFI_SUCCESS;
//Specify table attributes
PRINTER_CONFIGURE_DATA_ATTRIBUTES(pPrinterCtx, DS_ROOT_PATH, &ShowFirmwareDataSetAttribs);
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FREE_POOL_SAFE(pPath);
FREE_CMD_DISPLAY_OPTIONS_SAFE(pDispOptions);
FREE_POOL_SAFE(pDimmIds);
FREE_POOL_SAFE(pDimms);
FreeCommandStatus(&pCommandStatus);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowFirmwareCommand.h 0000664 0000000 0000000 00000001733 14165347476 0022017 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SHOW_FIRMWARE_COMMAND_H_
#define _SHOW_FIRMWARE_COMMAND_H_
#include
#include
#include
#include
#include
#include
#include
#include "Common.h"
#include
/**
Register the show firmware command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowFirmwareCommand(
);
/**
Execute the show firmware command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS on success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_ABORTED invoking CONFIG_PROTOCOL function failure
**/
EFI_STATUS
ShowFirmware(
IN struct Command *pCmd
);
#endif /* _SHOW_FIRMWARE_COMMAND_H_ */
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowGoalCommand.c 0000664 0000000 0000000 00000051336 14165347476 0021124 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include
#include "Debug.h"
#include "Types.h"
#include
#include "Utility.h"
#include "NvmDimmCli.h"
#include "NvmInterface.h"
#include "CommandParser.h"
#include "ShowGoalCommand.h"
#include "Common.h"
#include "Convert.h"
#define DS_ROOT_PATH L"/ConfigGoalList"
#define DS_CONFIG_GOAL_PATH L"/ConfigGoalList/ConfigGoal"
#define DS_CONFIG_GOAL_INDEX_PATH L"/ConfigGoalList/ConfigGoal[%d]"
/*
* PRINT LIST ATTRIBUTES
* ---DimmID=0x0001---
* SocketID=X
* MemorySize=X
* ...
*/
PRINTER_LIST_ATTRIB ShowGoalListAttributes =
{
{
{
CONFIG_GOAL_NODE_STR, //GROUP LEVEL TYPE
L"---" DIMM_ID_STR L"=$(" DIMM_ID_STR L")---", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT L"%ls=%ls", //NULL or KEY VAL FORMAT STR
DIMM_ID_STR //NULL or IGNORE KEY LIST (K1;K2)
}
}
};
/*
* PRINTER TABLE ATTRIBUTES ( columns)
* SocketID | DimmID | MemorySize | AppDirect1Size | AppDirect2Size
* ================================================================
* 0x0001 | X |X | X | X
* ...
*/
PRINTER_TABLE_ATTRIB ShowGoalTableAttributes =
{
{
{
SOCKET_ID_STR, //COLUMN HEADER
SOCKET_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_CONFIG_GOAL_PATH PATH_KEY_DELIM SOCKET_ID_STR //COLUMN DATA PATH
},
{
DIMM_ID_STR, //COLUMN HEADER
DIMM_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_CONFIG_GOAL_PATH PATH_KEY_DELIM DIMM_ID_STR //COLUMN DATA PATH
},
{
MEMORY_SIZE_PROPERTY, //COLUMN HEADER
MEMORY_SIZE_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_CONFIG_GOAL_PATH PATH_KEY_DELIM MEMORY_SIZE_PROPERTY //COLUMN DATA PATH
},
{
APPDIRECT_1_SIZE_PROPERTY, //COLUMN HEADER
MEMORY_SIZE_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_CONFIG_GOAL_PATH PATH_KEY_DELIM APPDIRECT_1_SIZE_PROPERTY //COLUMN DATA PATH
},
{
APPDIRECT_2_SIZE_PROPERTY, //COLUMN HEADER
MEMORY_SIZE_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_CONFIG_GOAL_PATH PATH_KEY_DELIM APPDIRECT_2_SIZE_PROPERTY //COLUMN DATA PATH
}
}
};
PRINTER_DATA_SET_ATTRIBS ShowGoalDataSetAttribs =
{
&ShowGoalListAttributes,
&ShowGoalTableAttributes
};
/**
Command syntax definition
**/
struct Command ShowGoalCommand =
{
SHOW_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"",HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{ALL_OPTION_SHORT, ALL_OPTION, L"", L"",HELP_ALL_DETAILS_TEXT, FALSE, ValueEmpty},
{DISPLAY_OPTION_SHORT, DISPLAY_OPTION, L"", HELP_TEXT_ATTRIBUTES,HELP_DISPLAY_DETAILS_TEXT, FALSE, ValueRequired},
{UNITS_OPTION_SHORT, UNITS_OPTION, L"", UNITS_OPTION_HELP,HELP_UNIT_DETAILS_TEXT, FALSE, ValueRequired}
#ifdef OS_BUILD
, {OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP,HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired}
#endif // OS_BUILD
},
{ //!< targets
{DIMM_TARGET, L"", HELP_TEXT_DIMM_IDS, FALSE, ValueOptional},
{GOAL_TARGET, L"", L"", TRUE, ValueEmpty},
{SOCKET_TARGET, L"", HELP_TEXT_SOCKET_IDS, FALSE, ValueOptional}
},
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Show a pending memory allocation goal on one or more " PMEM_MODULES_STR L" to be applied on reboot.", //!< help
ShowGoal,
TRUE, //!< enable print control support
};
CHAR16 *mppAllowedShowGoalDisplayValues[] =
{
SOCKET_ID_STR,
DIMM_ID_STR,
MEMORY_SIZE_PROPERTY,
APPDIRECT_SIZE_PROPERTY,
APPDIRECT_INDEX_PROPERTY,
APPDIRECT_1_SIZE_PROPERTY,
APPDIRECT_1_SETTINGS_PROPERTY,
APPDIRECT_1_INDEX_PROPERTY,
APPDIRECT_2_SIZE_PROPERTY,
APPDIRECT_2_SETTINGS_PROPERTY,
APPDIRECT_2_INDEX_PROPERTY,
STATUS_STR
};
/**
Print results of show goal according to table view
@param[in] pCmd command from CLI
@param[in] pRegionConfigsInfo - Region Config table to be printed
@param[in] CurrentUnits The requested type of units to convert the capacity into
@param[in] RegionConfigsCount - Number of elements in array
@retval EFI_SUCCESS if printing is successful
@retval EFI_INVALID_PARAMETER if input parameter is incorrect
**/
EFI_STATUS
ShowGoalPrintTableView(
IN struct Command *pCmd,
IN REGION_GOAL_PER_DIMM_INFO *pRegionConfigsInfo,
IN UINT16 CurrentUnits,
IN UINT32 RegionConfigsCount,
IN BOOLEAN Buffered
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_STATUS TempReturnCode = EFI_SUCCESS;
UINT32 Index = 0;
CHAR16 DimmStr[MAX_DIMM_UID_LENGTH];
CHAR16 *pVolatileCapacityStr = NULL;
CHAR16 *pAppDirect1CapacityStr = NULL;
CHAR16 *pAppDirect2CapacityStr = NULL;
REGION_GOAL_PER_DIMM_INFO *pCurrentGoal = NULL;
CHAR16 *pPath = NULL;
ZeroMem(DimmStr, sizeof(DimmStr));
if (pRegionConfigsInfo == NULL) {
goto Finish;
}
for (Index = 0; Index < RegionConfigsCount; ++Index) {
pCurrentGoal = &pRegionConfigsInfo[Index];
PRINTER_BUILD_KEY_PATH(pPath, DS_CONFIG_GOAL_INDEX_PATH, Index);
ReturnCode = GetPreferredDimmIdAsString(pCurrentGoal->DimmID, pCurrentGoal->DimmUid, DimmStr, MAX_DIMM_UID_LENGTH);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
TempReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, ROUNDDOWN(pCurrentGoal->VolatileSize, SIZE_1GB), CurrentUnits,
TRUE, &pVolatileCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
TempReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, pCurrentGoal->AppDirectSize[0],
CurrentUnits, TRUE, &pAppDirect1CapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
TempReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, pCurrentGoal->AppDirectSize[1],
CurrentUnits, TRUE, &pAppDirect2CapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pCmd->pPrintCtx, pPath, SOCKET_ID_STR, FORMAT_HEX, pCurrentGoal->SocketId);
PRINTER_SET_KEY_VAL_WIDE_STR(pCmd->pPrintCtx, pPath, DIMM_ID_STR, DimmStr);
PRINTER_SET_KEY_VAL_WIDE_STR(pCmd->pPrintCtx, pPath, MEMORY_SIZE_PROPERTY, pVolatileCapacityStr);
PRINTER_SET_KEY_VAL_WIDE_STR(pCmd->pPrintCtx, pPath, APPDIRECT_1_SIZE_PROPERTY, pAppDirect1CapacityStr);
PRINTER_SET_KEY_VAL_WIDE_STR(pCmd->pPrintCtx, pPath, APPDIRECT_2_SIZE_PROPERTY, pAppDirect2CapacityStr);
FREE_POOL_SAFE(pVolatileCapacityStr);
FREE_POOL_SAFE(pAppDirect1CapacityStr);
FREE_POOL_SAFE(pAppDirect2CapacityStr);
}
Finish:
//Specify table attributes
PRINTER_CONFIGURE_DATA_ATTRIBUTES(pCmd->pPrintCtx, DS_ROOT_PATH, &ShowGoalDataSetAttribs);
FREE_POOL_SAFE(pPath);
return ReturnCode;
}
/**
Print results of show goal according to detailed view
@param[in] pCmd command from CLI
@param[in] pRegionConfigsInfo - Region Config table to be printed
@param[in] RegionConfigsCount - Number of elements in array
@param[in] AllOptionSet - Print all display options
@param[in] DisplayOptionSet - Print specified display options
@param[in] CurrentUnits The requested type of units to convert the capacity into
@param[in] pDisplayValues - Selected display options
@retval EFI_SUCCESS if printing is successful
@retval EFI_INVALID_PARAMETER if input parameter is incorrect
**/
EFI_STATUS
ShowGoalPrintDetailedView(
IN struct Command *pCmd,
IN REGION_GOAL_PER_DIMM_INFO *pRegionConfigsInfo,
IN UINT32 RegionConfigsCount,
IN BOOLEAN AllOptionSet,
IN BOOLEAN DisplayOptionSet,
IN UINT16 CurrentUnits,
IN CHAR16 *pDisplayValues
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_STATUS TempReturnCode = EFI_SUCCESS;
UINT32 Index = 0;
REGION_GOAL_PER_DIMM_INFO *pCurrentGoal = NULL;
CHAR16 *pSettingsString = NULL;
CHAR16 *pStatusString = NULL;
CHAR16 DimmStr[MAX_DIMM_UID_LENGTH];
CHAR16 *pCapacityStr = NULL;
CHAR16 *pPath = NULL;
ZeroMem(DimmStr, sizeof(DimmStr));
if (pRegionConfigsInfo == NULL || (DisplayOptionSet && pDisplayValues == NULL)) {
goto Finish;
}
for (Index = 0; Index < RegionConfigsCount; ++Index) {
pCurrentGoal = &pRegionConfigsInfo[Index];
PRINTER_BUILD_KEY_PATH(pPath, DS_CONFIG_GOAL_INDEX_PATH, Index);
/* always print dimmID */
/** Dimm ID **/
ReturnCode = GetPreferredDimmIdAsString(pCurrentGoal->DimmID, pCurrentGoal->DimmUid,
DimmStr, MAX_DIMM_UID_LENGTH);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
PRINTER_SET_KEY_VAL_WIDE_STR(pCmd->pPrintCtx, pPath, DIMM_ID_STR, DimmStr);
/** Socket Id **/
if (AllOptionSet || (DisplayOptionSet && ContainsValue(pDisplayValues, SOCKET_ID_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pCmd->pPrintCtx, pPath, SOCKET_ID_STR, FORMAT_HEX, pCurrentGoal->SocketId);
}
/** Volatile Size **/
if (AllOptionSet || (DisplayOptionSet && ContainsValue(pDisplayValues, MEMORY_SIZE_PROPERTY))) {
ReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, ROUNDDOWN(pCurrentGoal->VolatileSize, SIZE_1GB), CurrentUnits,
TRUE, &pCapacityStr);
PRINTER_SET_KEY_VAL_WIDE_STR(pCmd->pPrintCtx, pPath, MEMORY_SIZE_PROPERTY, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
}
/** AppDirect1Size **/
if (AllOptionSet || (DisplayOptionSet && ContainsValue(pDisplayValues, APPDIRECT_1_SIZE_PROPERTY))) {
TempReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, pCurrentGoal->AppDirectSize[0], CurrentUnits, TRUE, &pCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pCmd->pPrintCtx, pPath, APPDIRECT_1_SIZE_PROPERTY, FORMAT_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
}
/** AppDirect1Index **/
if (AllOptionSet || (DisplayOptionSet && ContainsValue(pDisplayValues, APPDIRECT_1_INDEX_PROPERTY))) {
if (pCurrentGoal->AppDirectSize[0] == 0) {
PRINTER_SET_KEY_VAL_WIDE_STR(pCmd->pPrintCtx, pPath, APPDIRECT_1_INDEX_PROPERTY, NA_STR);
} else {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pCmd->pPrintCtx, pPath, APPDIRECT_1_INDEX_PROPERTY, FORMAT_INT32, pCurrentGoal->AppDirectIndex[0]);
}
}
/** AppDirect1Settings **/
if (AllOptionSet || (DisplayOptionSet && ContainsValue(pDisplayValues, APPDIRECT_1_SETTINGS_PROPERTY))) {
InterleaveSettingsToString(pCurrentGoal->AppDirectSize[0], pCurrentGoal->NumberOfInterleavedDimms[0],
pCurrentGoal->ImcInterleaving[0], pCurrentGoal->ChannelInterleaving[0], &pSettingsString);
PRINTER_SET_KEY_VAL_WIDE_STR(pCmd->pPrintCtx, pPath, APPDIRECT_1_SETTINGS_PROPERTY, pSettingsString);
FREE_POOL_SAFE(pSettingsString);
}
/** AppDirect2Size **/
if (AllOptionSet || (DisplayOptionSet && ContainsValue(pDisplayValues, APPDIRECT_2_SIZE_PROPERTY))) {
TempReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, pCurrentGoal->AppDirectSize[1], CurrentUnits, TRUE, &pCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pCmd->pPrintCtx, pPath, APPDIRECT_2_SIZE_PROPERTY, FORMAT_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
}
/** AppDirect2Index **/
if (AllOptionSet || (DisplayOptionSet && ContainsValue(pDisplayValues, APPDIRECT_2_INDEX_PROPERTY))) {
if (pCurrentGoal->AppDirectSize[1] == 0) {
PRINTER_SET_KEY_VAL_WIDE_STR(pCmd->pPrintCtx, pPath, APPDIRECT_2_INDEX_PROPERTY, NA_STR);
} else {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pCmd->pPrintCtx, pPath, APPDIRECT_2_INDEX_PROPERTY, FORMAT_INT32, pCurrentGoal->AppDirectIndex[1]);
}
}
/** AppDirect2Settings **/
if (AllOptionSet || (DisplayOptionSet && ContainsValue(pDisplayValues, APPDIRECT_2_SETTINGS_PROPERTY))) {
InterleaveSettingsToString(pCurrentGoal->AppDirectSize[1], pCurrentGoal->NumberOfInterleavedDimms[1],
pCurrentGoal->ImcInterleaving[1], pCurrentGoal->ChannelInterleaving[1], &pSettingsString);
PRINTER_SET_KEY_VAL_WIDE_STR(pCmd->pPrintCtx, pPath, APPDIRECT_2_SETTINGS_PROPERTY, pSettingsString);
FREE_POOL_SAFE(pSettingsString);
}
/** Status **/
if (AllOptionSet || (DisplayOptionSet && ContainsValue(pDisplayValues, STATUS_STR))) {
pStatusString = GoalStatusToString(gNvmDimmCliHiiHandle, pCurrentGoal->Status);
PRINTER_SET_KEY_VAL_WIDE_STR(pCmd->pPrintCtx, pPath, STATUS_STR, pStatusString);
FREE_POOL_SAFE(pStatusString);
}
}
Finish:
//Specify table attributes
PRINTER_CONFIGURE_DATA_ATTRIBUTES(pCmd->pPrintCtx, DS_ROOT_PATH, &ShowGoalDataSetAttribs);
FREE_POOL_SAFE(pPath);
return ReturnCode;
}
/**
Execute the Show Goal command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
ShowGoal(
IN struct Command *pCmd
)
{
BOOLEAN AllOptionSet = FALSE;
BOOLEAN DisplayOptionSet = FALSE;
UINT16 *pDimmIds = NULL;
UINT16 *pSocketIds = NULL;
UINT16 UnitsOption = DISPLAY_SIZE_UNIT_UNKNOWN;
UINT16 UnitsToDisplay = FixedPcdGet16(PcdDcpmmCliDefaultCapacityUnit);
UINT32 DimmIdsCount = 0;
UINT32 SocketIdsCount = 0;
UINT32 RegionConfigsCount = 0;
CHAR16 *pSettingsString = NULL;
CHAR16 *pDisplayValues = NULL;
CHAR16 *pTargetValue = NULL;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
COMMAND_STATUS *pCommandStatus = NULL;
REGION_GOAL_PER_DIMM_INFO RegionConfigsInfo[MAX_DIMMS];
EFI_STATUS ReturnCode = EFI_SUCCESS;
DIMM_INFO *pDimms = NULL;
UINT32 DimmCount = 0;
DISPLAY_PREFERENCES DisplayPreferences;
PRINT_CONTEXT *pPrinterCtx = NULL;
CMD_DISPLAY_OPTIONS *pDispOptions = NULL;
NVDIMM_ENTRY();
SetMem(RegionConfigsInfo, sizeof(RegionConfigsInfo), 0x0);
ZeroMem(&DisplayPreferences, sizeof(DisplayPreferences));
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("pCmd parameter is NULL.\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
pDispOptions = AllocateZeroPool(sizeof(CMD_DISPLAY_OPTIONS));
if (NULL == pDispOptions) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
ReturnCode = CheckAllAndDisplayOptions(pCmd, mppAllowedShowGoalDisplayValues,
ALLOWED_DISP_VALUES_COUNT(mppAllowedShowGoalDisplayValues), pDispOptions);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("CheckAllAndDisplayOptions has returned error. Code " FORMAT_EFI_STATUS "\n", ReturnCode);
goto Finish;
}
pDisplayValues = pDispOptions->pDisplayValues;
AllOptionSet = pDispOptions->AllOptionSet;
DisplayOptionSet = pDispOptions->DisplayOptionSet;
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
/** Need NvmDimmConfigProtocol **/
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// Populate the list of DIMM_INFO structures with relevant information
ReturnCode = GetDimmList(pNvmDimmConfigProtocol, pCmd, DIMM_INFO_CATEGORY_NONE, &pDimms, &DimmCount);
if (EFI_ERROR(ReturnCode)) {
if(ReturnCode == EFI_NOT_FOUND) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_INFO_NO_FUNCTIONAL_DIMMS);
}
goto Finish;
}
// check targets
if (ContainTarget(pCmd, DIMM_TARGET)) {
pTargetValue = GetTargetValue(pCmd, DIMM_TARGET);
ReturnCode = GetDimmIdsFromString(pCmd, pTargetValue, pDimms, DimmCount, &pDimmIds, &DimmIdsCount);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("Failed on GetDimmIdsFromString");
goto Finish;
}
if (!AllDimmsInListAreManageable(pDimms, DimmCount, pDimmIds, DimmIdsCount)){
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_UNMANAGEABLE_DIMM);
goto Finish;
}
}
// check sockets
if (ContainTarget(pCmd, SOCKET_TARGET)) {
pTargetValue = GetTargetValue(pCmd, SOCKET_TARGET);
ReturnCode = GetUintsFromString(pTargetValue, &pSocketIds, &SocketIdsCount);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_TARGET_SOCKET);
NVDIMM_DBG("Failed on GetUintsFromString");
goto Finish;
}
}
ReturnCode = ReadRunTimePreferences(&DisplayPreferences, DISPLAY_CLI_INFO);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_DISPLAY_PREFERENCES_RETRIEVE);
goto Finish;
}
UnitsToDisplay = DisplayPreferences.SizeUnit;
ReturnCode = GetUnitsOption(pCmd, &UnitsOption);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
/** Any valid units option will override the preferences **/
if (UnitsOption != DISPLAY_SIZE_UNIT_UNKNOWN) {
UnitsToDisplay = UnitsOption;
}
if (ContainsValue(pDisplayValues, APPDIRECT_1_INDEX_PROPERTY) &&
ContainsValue(pDisplayValues, APPDIRECT_INDEX_PROPERTY)) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_WARN("Values used together");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_VALUES_APPDIRECT_INDICES_USED_TOGETHER);
goto Finish;
}
if (ContainsValue(pDisplayValues, APPDIRECT_1_SIZE_PROPERTY) &&
ContainsValue(pDisplayValues, APPDIRECT_SIZE_PROPERTY)) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_WARN("Values used together");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_VALUES_APPDIRECT_SIZE_USED_TOGETHER);
goto Finish;
}
/** Fetch goal configs from driver **/
ReturnCode = pNvmDimmConfigProtocol->GetGoalConfigs(
pNvmDimmConfigProtocol,
pDimmIds,
DimmIdsCount,
pSocketIds,
SocketIdsCount,
MAX_DIMMS,
RegionConfigsInfo,
&RegionConfigsCount,
pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
if (EFI_VOLUME_CORRUPTED == ReturnCode) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_PCD_CORRUPTED);
}
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
PrinterSetCommandStatus(pPrinterCtx, ReturnCode, CLI_GET_REGION_MSG, CLI_GET_REGION_ON_MSG, pCommandStatus);
goto Finish;
}
if (RegionConfigsCount == 0) {
//WA, to ensure ESX prints a message when no entries are found.
if (PRINTER_ESX_FORMAT_ENABLED(pPrinterCtx)) {
if (SocketIdsCount > 0) {
PRINTER_SET_MSG(pPrinterCtx, EFI_NOT_FOUND, CLI_NO_GOALS_ON_SOCKET_MSG);
} else {
PRINTER_SET_MSG(pPrinterCtx, EFI_NOT_FOUND, CLI_NO_GOALS_MSG);
}
} else {
if (SocketIdsCount > 0) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_NO_GOALS_ON_SOCKET_MSG);
} else {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_NO_GOALS_MSG);
}
}
goto Finish;
}
if (!DisplayOptionSet && !AllOptionSet) {
/** Default table view **/
ReturnCode = ShowGoalPrintTableView(pCmd, RegionConfigsInfo, UnitsToDisplay, RegionConfigsCount, TRUE);
} else {
/** Detailed view **/
ReturnCode = ShowGoalPrintDetailedView(pCmd, RegionConfigsInfo, RegionConfigsCount, AllOptionSet,
DisplayOptionSet, UnitsToDisplay, pDisplayValues);
}
if (!EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_REBOOT_REQUIRED_MSG);
}
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FreeCommandStatus(&pCommandStatus);
FREE_POOL_SAFE(pDimmIds);
FREE_POOL_SAFE(pDimms);
FREE_POOL_SAFE(pSocketIds);
FREE_POOL_SAFE(pSettingsString);
FREE_CMD_DISPLAY_OPTIONS_SAFE(pDispOptions);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Register the Show Goal command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowGoalCommand(
)
{
EFI_STATUS ReturnCode;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&ShowGoalCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowGoalCommand.h 0000664 0000000 0000000 00000004473 14165347476 0021131 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SHOW_GOAL_COMMAND_
#define _SHOW_GOAL_COMMAND_
#define APPDIRECT_1_SIZE_TABLE_HEADER L"AppDirect1Size"
#define APPDIRECT_2_SIZE_TABLE_HEADER L"AppDirect2Size"
#define MEMORY_SIZE_TABLE_HEADER L"MemorySize"
#define SOCKET_ID_TABLE_HEADER L"SocketID"
#define DIMM_ID_TABLE_HEADER L"DimmID"
#define STATUS_STR L"Status"
#define CLI_REBOOT_REQUIRED_MSG L"A reboot is required to process new memory allocation goals.\n"
#define CLI_NO_GOALS_MSG L"There are no goal configs defined in the system.\nPlease use 'show -region' to display currently valid persistent memory regions.\n"
#define CLI_NO_GOALS_ON_SOCKET_MSG L"There are no goal configs defined on the specified socket.\nPlease use 'show -region' to display currently valid persistent memory regions.\n"
#define CLI_GET_REGION_MSG L"Get region configuration goal"
#define CLI_GET_REGION_ON_MSG L" on"
#define CLI_CREATE_SUCCESS_STATUS L"Created following region configuration goal\n"
#include
/**
Register the Show Goal command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowGoalCommand();
/**
Print results of show goal according to table view
@param[in] pCmd command from CLI
@param[in] pRegionConfigsInfo - Region Config table to be printed
@param[in] CurrentUnits The requested type of units to convert the capacity into
@param[in] RegionConfigsCount - Number of elements in array
@retval EFI_SUCCESS if printing is successful
@retval EFI_INVALID_PARAMETER if input parameter is incorrect
**/
EFI_STATUS
ShowGoalPrintTableView(
IN struct Command *pCmd,
IN REGION_GOAL_PER_DIMM_INFO *pRegionConfigsInfo,
IN UINT16 CurrentUnits,
IN UINT32 RegionConfigsCount,
IN BOOLEAN Buffered
);
/**
Execute the Show Goal command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
ShowGoal(
IN struct Command *pCmd
);
#endif /** _SHOW_GOAL_COMMAND_ **/
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowMemoryResourcesCommand.c 0000664 0000000 0000000 00000033403 14165347476 0023400 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include
#include
#include "ShowMemoryResourcesCommand.h"
#include
#include
#include
#include
#include
#include
#include
#include "Common.h"
#include "NvmDimmCli.h"
#include
#define DS_MEMORY_RESOURCES_PATH L"/MemoryResources"
#define DS_MEMORY_RESOURCES_DATA_PATH L"/MemoryResources/data"
#define DS_MEMORY_RESOURCES_DATA_INDEX_PATH L"/MemoryResources/data[%d]"
/*
* PRINTER TABLE ATTRIBUTES (5 columns)
* | DDR | PMemModule | Total |
* ===========================================================================
* Volatile | Volatile DDR Mem | Volatile PMem | Volatile Mem |
* AppDirect | N/A | AppDirect Mem | AppDirect Mem |
* Cache | DDR Cache Mem | N/A | Cache Mem |
* Inaccessible | N/A | Inaccessible Mem | Inaccessible Mem |
* Physical | Total DDR Mem | Total DCPMM Mem | Total Mem |
*/
PRINTER_TABLE_ATTRIB ShowMemoryResourcesTableAttributes =
{
{
{
MEMORY_TYPE_STR, //COLUMN HEADER
MEMORY_TYPE_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_MEMORY_RESOURCES_DATA_PATH PATH_KEY_DELIM MEMORY_TYPE_STR //COLUMN DATA PATH
},
{
DDR_STR, //COLUMN HEADER
DDR_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_MEMORY_RESOURCES_DATA_PATH PATH_KEY_DELIM DDR_STR //COLUMN DATA PATH
},
{
PMEM_MODULE_PASCAL_CASE_STR, //COLUMN HEADER
PMEM_MODULE_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_MEMORY_RESOURCES_DATA_PATH PATH_KEY_DELIM PMEM_MODULE_PASCAL_CASE_STR //COLUMN DATA PATH
},
{
TOTAL_STR, //COLUMN HEADER
TOTAL_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_MEMORY_RESOURCES_DATA_PATH PATH_KEY_DELIM TOTAL_STR //COLUMN DATA PATH
}
}
};
PRINTER_DATA_SET_ATTRIBS ShowMemoryResourcesDataSetAttribsPmtt3 =
{
NULL,
&ShowMemoryResourcesTableAttributes
};
/**
Command syntax definition
**/
struct Command ShowMemoryResourcesCommand = {
SHOW_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"",HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{UNITS_OPTION_SHORT, UNITS_OPTION, L"", UNITS_OPTION_HELP,HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired}
#ifdef OS_BUILD
,{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP,HELP_UNIT_DETAILS_TEXT, FALSE, ValueRequired }
#endif
},
{{MEMORY_RESOURCES_TARGET, L"", L"", TRUE, ValueEmpty}}, //!< targets
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Show memory allocation information for this platform.", //!< help
ShowMemoryResources,
TRUE, //!< enable print control support
};
PRINTER_DATA_SET_ATTRIBS ShowMemResourcesDataSetAttribs =
{
NULL,
NULL
};
/**
Execute the show memory resources command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_ABORTED invoking CONFIG_PROTOCOL function failure
**/
EFI_STATUS
ShowMemoryResources(
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_STATUS TempReturnCode = EFI_SUCCESS;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
MEMORY_RESOURCES_INFO MemoryResourcesInfo;
UINT16 UnitsOption = DISPLAY_SIZE_UNIT_UNKNOWN;
UINT16 UnitsToDisplay = FixedPcdGet16(PcdDcpmmCliDefaultCapacityUnit);
UINT64 DcpmmInaccessibleCapacity = 0;
UINT64 TotalCapacity = 0;
CHAR16 *pCapacityStr = NULL;
CHAR16 *pPcdMissingStr = NULL;
DISPLAY_PREFERENCES DisplayPreferences;
PRINT_CONTEXT *pPrinterCtx = NULL;
CHAR16 *pPath = NULL;
UINT32 Index = 0;
NVDIMM_ENTRY();
ZeroMem(&DisplayPreferences, sizeof(DisplayPreferences));
SetMem(&MemoryResourcesInfo, sizeof(MemoryResourcesInfo), 0x0);
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
ReturnCode = ReadRunTimePreferences(&DisplayPreferences, DISPLAY_CLI_INFO);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_DISPLAY_PREFERENCES_RETRIEVE);
goto Finish;
}
UnitsToDisplay = DisplayPreferences.SizeUnit;
ReturnCode = GetUnitsOption(pCmd, &UnitsOption);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
/** Any valid units option will override the preferences **/
if (UnitsOption != DISPLAY_SIZE_UNIT_UNKNOWN) {
UnitsToDisplay = UnitsOption;
}
/**
Make sure we can access the config protocol
**/
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
Print(FORMAT_STR_NL, CLI_ERR_OPENING_CONFIG_PROTOCOL);
ReturnCode = EFI_NOT_FOUND;
goto Finish;
}
// Ignore errors from this! Always print what we can
ReturnCode = pNvmDimmConfigProtocol->GetMemoryResourcesInfo(pNvmDimmConfigProtocol, &MemoryResourcesInfo);
if (EFI_ERROR(ReturnCode)) {
if (MemoryResourcesInfo.PcdInvalid) {
pPcdMissingStr = HiiGetString(gNvmDimmCliHiiHandle, STRING_TOKEN(STR_DCPMM_STATUS_ERR_PCD_CURR_CONF_MISSING), NULL);
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, pPcdMissingStr);
}
// Ignore errors. Always print what we can
ReturnCode = EFI_SUCCESS;
}
/* Print Volatile Capacities */
Index = 0;
PRINTER_BUILD_KEY_PATH(pPath, DS_MEMORY_RESOURCES_DATA_INDEX_PATH, Index);
// Print Header
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, MEMORY_TYPE_STR, L"Volatile");
// Print DDR Memory/Volatile Capacity
TempReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, MemoryResourcesInfo.DDRVolatileCapacity, UnitsToDisplay, TRUE, &pCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DDR_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
// Print PMem module Volatile Capacity
TempReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, MemoryResourcesInfo.VolatileCapacity, UnitsToDisplay, TRUE, &pCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, PMEM_MODULE_PASCAL_CASE_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
// Print Total Volatile Capacity
if (MemoryResourcesInfo.DDRVolatileCapacity == ACPI_TABLE_VALUE_UNKNOWN ||
MemoryResourcesInfo.VolatileCapacity == ACPI_TABLE_VALUE_UNKNOWN) {
TotalCapacity = ACPI_TABLE_VALUE_UNKNOWN;
} else {
TotalCapacity = MemoryResourcesInfo.DDRVolatileCapacity + MemoryResourcesInfo.VolatileCapacity;
}
TempReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, TotalCapacity, UnitsToDisplay, TRUE, &pCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, TOTAL_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
/* Print App Direct Capacities */
Index = 1;
PRINTER_BUILD_KEY_PATH(pPath, DS_MEMORY_RESOURCES_DATA_INDEX_PATH, Index);
// Print Header
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, MEMORY_TYPE_STR, L"AppDirect");
// Print DDR App Direct Capacities (as of now, this is N/A)
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DDR_STR, DASH_STR);
// Print PMem module DDR App Direct Capacities
TempReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, MemoryResourcesInfo.AppDirectCapacity, UnitsToDisplay, TRUE, &pCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, PMEM_MODULE_PASCAL_CASE_STR, pCapacityStr);
// Print Total App Direct Capacities
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, TOTAL_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
/* Print DDR Cache Capacities */
Index = 2;
PRINTER_BUILD_KEY_PATH(pPath, DS_MEMORY_RESOURCES_DATA_INDEX_PATH, Index);
// Print header
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, MEMORY_TYPE_STR, L"Cache");
TempReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, MemoryResourcesInfo.DDRCacheCapacity, UnitsToDisplay, TRUE, &pCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
// Print DDR Cache Capacity
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DDR_STR, pCapacityStr);
// Print PMem module Cache Capacity
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, PMEM_MODULE_PASCAL_CASE_STR, DASH_STR);
// Print Total Cache Capacity
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, TOTAL_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
Index = 3;
PRINTER_BUILD_KEY_PATH(pPath, DS_MEMORY_RESOURCES_DATA_INDEX_PATH, Index);
// Print Header
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, MEMORY_TYPE_STR, L"Inaccessible");
// Print DDR Inaccessible Capacity
TempReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, MemoryResourcesInfo.DDRInaccessibleCapacity, UnitsToDisplay, TRUE, &pCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DDR_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
// Print PMem module Inaccessible Capacity
if (MemoryResourcesInfo.InaccessibleCapacity == ACPI_TABLE_VALUE_UNKNOWN ||
MemoryResourcesInfo.ReservedCapacity == ACPI_TABLE_VALUE_UNKNOWN ||
MemoryResourcesInfo.UnconfiguredCapacity == ACPI_TABLE_VALUE_UNKNOWN) {
DcpmmInaccessibleCapacity = ACPI_TABLE_VALUE_UNKNOWN;
} else {
DcpmmInaccessibleCapacity = MemoryResourcesInfo.InaccessibleCapacity + MemoryResourcesInfo.ReservedCapacity + MemoryResourcesInfo.UnconfiguredCapacity;
}
TempReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, DcpmmInaccessibleCapacity, UnitsToDisplay, TRUE, &pCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, PMEM_MODULE_PASCAL_CASE_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
// Print Total Inaccessible Capacity
// If one of the elements is unknown, then the total should be unknown too
if (MemoryResourcesInfo.DDRInaccessibleCapacity == ACPI_TABLE_VALUE_UNKNOWN ||
DcpmmInaccessibleCapacity == ACPI_TABLE_VALUE_UNKNOWN) {
TotalCapacity = ACPI_TABLE_VALUE_UNKNOWN;
} else {
TotalCapacity = MemoryResourcesInfo.DDRInaccessibleCapacity + DcpmmInaccessibleCapacity;
}
TempReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, TotalCapacity, UnitsToDisplay, TRUE, &pCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, TOTAL_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
/* Print Physical Capacities */
Index = 4;
PRINTER_BUILD_KEY_PATH(pPath, DS_MEMORY_RESOURCES_DATA_INDEX_PATH, Index);
// Print header
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, MEMORY_TYPE_STR, L"Physical");
// Print DDR Physical Capacity
ReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, MemoryResourcesInfo.DDRRawCapacity, UnitsToDisplay, TRUE, &pCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DDR_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
// Print PMem module Physical Capacity
ReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, MemoryResourcesInfo.RawCapacity, UnitsToDisplay, TRUE, &pCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, PMEM_MODULE_PASCAL_CASE_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
// Print Total Physical Capacity
// If one of the elements is unknown, then the total should be unknown too
if (MemoryResourcesInfo.DDRRawCapacity == ACPI_TABLE_VALUE_UNKNOWN ||
MemoryResourcesInfo.RawCapacity == ACPI_TABLE_VALUE_UNKNOWN) {
TotalCapacity = ACPI_TABLE_VALUE_UNKNOWN;
} else {
TotalCapacity = MemoryResourcesInfo.DDRRawCapacity + MemoryResourcesInfo.RawCapacity;
}
ReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, TotalCapacity, UnitsToDisplay, TRUE, &pCapacityStr);
KEEP_ERROR(ReturnCode, TempReturnCode);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, TOTAL_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
Finish:
PRINTER_ENABLE_TEXT_TABLE_FORMAT(pPrinterCtx);
PRINTER_CONFIGURE_DATA_ATTRIBUTES(pPrinterCtx, DS_MEMORY_RESOURCES_PATH, &ShowMemoryResourcesDataSetAttribsPmtt3);
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FREE_POOL_SAFE(pPath);
FREE_POOL_SAFE(pPcdMissingStr);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Register the show memory resources command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowMemoryResourcesCommand(
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&ShowMemoryResourcesCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowMemoryResourcesCommand.h 0000664 0000000 0000000 00000002417 14165347476 0023406 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SRC_CLI_SHOW_MEMORY_RESOURCES_COMMAND_H_
#define _SRC_CLI_SHOW_MEMORY_RESOURCES_COMMAND_H_
#include "CommandParser.h"
#define DISPLAYED_CAPACITY_STR L"Capacity"
#define DISPLAYED_MEMORY_CAPACITY_STR L"MemoryCapacity"
#define DISPLAYED_APPDIRECT_CAPACITY_STR L"AppDirectCapacity"
#define DISPLAYED_UNCONFIGURED_CAPACITY_STR L"UnconfiguredCapacity"
#define DISPLAYED_INACCESSIBLE_CAPACITY_STR L"InaccessibleCapacity"
#define DISPLAYED_RESERVED_CAPACITY_STR L"ReservedCapacity"
/**
Execute the show memory resources command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_ABORTED invoking CONFIG_PROTOCOL function failure
**/
EFI_STATUS
ShowMemoryResources(
IN struct Command *pCmd
);
/**
Register the show memory resources command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowMemoryResourcesCommand(
);
#endif /* _SRC_CLI_SHOW_MEMORY_RESOURCES_COMMAND_H_ */
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowNamespaceCommand.h 0000664 0000000 0000000 00000002714 14165347476 0022137 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SHOW_NAMESPACE_COMMAND_H_
#define _SHOW_NAMESPACE_COMMAND_H_
#include
#include
#include
#include
#include
#include
#include
#include "Common.h"
#include
#define NAMESPACE_ID_STR L"NamespaceId"
#define NAME_STR L"Name"
#define CAPACITY_STR L"Capacity"
#define HEALTH_STATE_STR L"HealthState"
#define REGION_ID_STR L"RegionID"
#define BLOCK_SIZE_STR L"BlockSize"
#define MODE_STR L"Mode"
#define LABEL_VERSION_STR L"LabelVersion"
#define NAMESPACE_GUID_STR L"NamespaceGuid"
#define REGION_ID_STR L"RegionID"
/**
Register the show namespace command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowNamespaceCommand(
);
/**
Execute the show namespace command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS on success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_ABORTED invoking CONFIG_PROTOCOL function failure
**/
EFI_STATUS
ShowNamespace(
IN struct Command *pCmd
);
#endif /* _SHOW_NAMESPACE_COMMAND_H_ */
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowPcdCommand.c 0000664 0000000 0000000 00000133720 14165347476 0020746 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include
#include
#include "CommandParser.h"
#include "Common.h"
#include "ShowPcdCommand.h"
#include
#include
/**
Command syntax definition
**/
struct Command ShowPcdCommand =
{
SHOW_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"", HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", LARGE_PAYLOAD_OPTION, L"", L"", HELP_LPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", SMALL_PAYLOAD_OPTION, L"", L"", HELP_SPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
#ifdef OS_BUILD
{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP, HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#else
{L"", L"", L"", L"",L"", FALSE, ValueOptional}
#endif
},
{ //!< targets
{DIMM_TARGET, L"", HELP_TEXT_DIMM_IDS, FALSE, ValueOptional},
{PCD_TARGET, L"", PCD_CONFIG_TARGET_VALUE L"|" PCD_LSA_TARGET_VALUE, TRUE, ValueOptional}
},
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Show platform configuration data (PCD) stored on one or more " PMEM_MODULES_STR L".", //!< help
ShowPcd,
TRUE
};
#define DS_ROOT_PATH L"/PcdList"
#define DS_DIMM_PATH L"/PcdList/Dimm"
#define DS_DIMM_INDEX_PATH L"/PcdList/Dimm[%d]"
#define DS_PCD_PATH L"/PcdList/Dimm/Pcd"
#define DS_PCD_INDEX_PATH L"/PcdList/Dimm[%d]/Pcd[%d]"
#define DS_TABLE_PATH L"/PcdList/Dimm/Pcd/Table"
#define DS_TABLE_INDEX_PATH L"/PcdList/Dimm[%d]/Pcd[%d]/Table[%d]"
#define DS_PCD_PCAT_TABLE_INDEX_PATH L"/PcdList/Dimm[%d]/Pcd[%d]/Table[%d]/PcatTable[%d]"
#define DS_IDENTIFICATION_INFO_INDEX_PATH L"/PcdList/Dimm[%d]/Pcd[%d]/Table[%d]/PcatTable[%d]/IdentificationInfoTable[%d]"
#define PCD_TARGET_CONFIG_STR L"Target cfg "
#define PCD_TARGET_NAMESPACE_STR L"Target namespace "
#define PCD_TABLE_STR L"Table"
#define PCD_STR L"Pcd"
#define PCD_PCAT_TABLE_STR L"PcatTable"
#define PCD_IDENTIFICATION_INFO_STR L"IdentificationInfoTable"
#define COLUMN_IN_HEX_DUMP 16
CHAR16 *gpPathLba = NULL;
PRINT_CONTEXT *gpPrinterCtxLbaCommon = NULL;
UINT16 gDimmIndex = 0;
UINT8 ConfigIndex = 0;
PRINTER_LIST_ATTRIB ShowPcdListAttributes =
{
{
{
DIMM_NODE_STR, //GROUP LEVEL TYPE
L"--" DIMM_ID_STR L":$(" DIMM_ID_STR L")--", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT FORMAT_STR L": " FORMAT_STR, //NULL or KEY VAL FORMAT STR
DIMM_ID_STR //NULL or IGNORE KEY LIST (K1;K2)
},
{
PCD_STR, //GROUP LEVEL TYPE
L"--" PCD_STR L":$(" PCD_STR L")--", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT FORMAT_STR L": " FORMAT_STR, //NULL or KEY VAL FORMAT STR
PCD_STR //NULL or IGNORE KEY LIST (K1;K2)
},
{
PCD_TABLE_STR, //GROUP LEVEL TYPE
SHOW_LIST_IDENT L"---" PCD_TABLE_STR L": $(" PCD_TABLE_STR L")---", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT SHOW_LIST_IDENT FORMAT_STR L": " FORMAT_STR, //NULL or KEY VAL FORMAT STR
PCD_TABLE_STR //NULL or IGNORE KEY LIST (K1;K2)
},
{
PCD_PCAT_TABLE_STR, //GROUP LEVEL TYPE
SHOW_LIST_IDENT SHOW_LIST_IDENT PCD_PCAT_TABLE_STR SHOW_LIST_IDENT L": $(" PCD_PCAT_TABLE_STR L")", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT SHOW_LIST_IDENT FORMAT_STR L": " FORMAT_STR, //NULL or KEY VAL FORMAT STR
PCD_PCAT_TABLE_STR //NULL or IGNORE KEY LIST (K1;K2)
},
{
PCD_IDENTIFICATION_INFO_STR, //GROUP LEVEL TYPE
SHOW_LIST_IDENT SHOW_LIST_IDENT PCD_IDENTIFICATION_INFO_STR SHOW_LIST_IDENT L": $(" PCD_IDENTIFICATION_INFO_STR L")", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT SHOW_LIST_IDENT FORMAT_STR L": " FORMAT_STR, //NULL or KEY VAL FORMAT STR
PCD_IDENTIFICATION_INFO_STR //NULL or IGNORE KEY LIST (K1;K2)
}
}
};
PRINTER_DATA_SET_ATTRIBS ShowPcdDataSetAttribs =
{
&ShowPcdListAttributes,
NULL
};
/**
Register the Show PCD command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowPcdCommand(
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&ShowPcdCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
STATIC
EFI_STATUS
GetPcdTarget(
IN CHAR16 *pTargetValue,
OUT UINT8 *pPcdTarget
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_ENTRY();
if (pTargetValue == NULL || pPcdTarget == NULL) {
goto Finish;
}
if (StrLen(pTargetValue) == 0) {
*pPcdTarget = PCD_TARGET_ALL;
}
else if (StrICmp(pTargetValue, PCD_CONFIG_TARGET_VALUE) == 0) {
*pPcdTarget = PCD_TARGET_CONFIG;
}
else if (StrICmp(pTargetValue, PCD_LSA_TARGET_VALUE) == 0) {
*pPcdTarget = PCD_TARGET_NAMESPACES;
}
else {
ReturnCode = EFI_INVALID_PARAMETER;
goto Finish;
}
ReturnCode = EFI_SUCCESS;
Finish:
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Execute the Show PCD command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_FOUND couldn't open Config Protocol
@retval EFI_ABORTED internal
**/
EFI_STATUS
ShowPcd(
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
COMMAND_STATUS *pCommandStatus = NULL;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
DIMM_PCD_INFO *pDimmPcdInfo = NULL;
UINT32 DimmPcdInfoCount = 0;
UINT16 *pDimmIds = NULL;
UINT32 DimmIdsCount = 0;
CHAR16 *pTargetValue = NULL;
UINT8 PcdTarget = PCD_TARGET_ALL;
UINT32 Index = 0;
DIMM_INFO *pDimms = NULL;
UINT32 DimmCount = 0;
CHAR16 DimmStr[MAX_DIMM_UID_LENGTH];
PRINT_CONTEXT *pPrinterCtx = NULL;
CHAR16 *pPath = NULL;
NVDIMM_ENTRY();
SetDisplayInfo(L"ShowPcd", ResultsView, NULL);
ZeroMem(DimmStr, sizeof(DimmStr));
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
/**
Printing will still work via compatibility mode if NULL so no need to check for NULL.
**/
pPrinterCtx = pCmd->pPrintCtx;
/** Get config protocol **/
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// Populate the list of DIMM_INFO structures with relevant information
ReturnCode = GetAllDimmList(pNvmDimmConfigProtocol, pCmd, DIMM_INFO_CATEGORY_NONE, &pDimms, &DimmCount);
if (EFI_ERROR(ReturnCode)) {
if (ReturnCode == EFI_NOT_FOUND) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_INFO_NO_DIMMS);
}
goto Finish;
}
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
if (ContainTarget(pCmd, DIMM_TARGET)) {
pTargetValue = GetTargetValue(pCmd, DIMM_TARGET);
ReturnCode = GetDimmIdsFromString(pCmd, pTargetValue, pDimms, DimmCount, &pDimmIds, &DimmIdsCount);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
if (!AllDimmsInListAreManageable(pDimms, DimmCount, pDimmIds, DimmIdsCount)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_UNMANAGEABLE_DIMM);
goto Finish;
}
}
pTargetValue = GetTargetValue(pCmd, PCD_TARGET);
ReturnCode = GetPcdTarget(pTargetValue, &PcdTarget);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR_NL, CLI_ERR_INCORRECT_VALUE_TARGET_PCD);
goto Finish;
}
ReturnCode = pNvmDimmConfigProtocol->GetPcd(pNvmDimmConfigProtocol, PcdTarget, pDimmIds, DimmIdsCount,
&pDimmPcdInfo, &DimmPcdInfoCount, pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
goto Finish;
}
for (Index = 0; Index < DimmPcdInfoCount; Index++) {
ReturnCode = GetPreferredDimmIdAsString(pDimmPcdInfo[Index].DimmId, pDimmPcdInfo[Index].DimmUid,
DimmStr, MAX_DIMM_UID_LENGTH);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
PRINTER_BUILD_KEY_PATH(pPath, DS_DIMM_INDEX_PATH, Index);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DIMM_ID_STR, DimmStr);
if (PcdTarget == PCD_TARGET_ALL || PcdTarget == PCD_TARGET_NAMESPACES) {
PRINTER_BUILD_KEY_PATH(pPath, DS_PCD_INDEX_PATH, Index, 0);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, PCD_STR, L"LSA");
PrintLabelStorageArea(pDimmPcdInfo[Index].pLabelStorageArea, pPrinterCtx, pPath);
}
if (PcdTarget == PCD_TARGET_ALL || PcdTarget == PCD_TARGET_CONFIG) {
PRINTER_BUILD_KEY_PATH(pPath, DS_PCD_INDEX_PATH, Index, 1);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, PCD_STR, L"Config");
PrintPcdConfigurationHeader(pDimmPcdInfo[Index].pConfHeader, pPrinterCtx, pPath);
}
gDimmIndex++;
}
ReturnCode = EFI_SUCCESS;
PRINTER_CONFIGURE_DATA_ATTRIBUTES(pPrinterCtx, DS_ROOT_PATH, &ShowPcdDataSetAttribs);
PRINTER_ENABLE_LIST_TABLE_FORMAT(pPrinterCtx);
pPrinterCtx->DoNotPrintGeneralStatusSuccessCode = TRUE;
Finish:
PRINTER_SET_COMMAND_STATUS(pPrinterCtx, ReturnCode, CLI_INFO_SHOW_PCD, CLI_INFO_ON, pCommandStatus);
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FreeCommandStatus(&pCommandStatus);
FreeDimmPcdInfoArray(pDimmPcdInfo, DimmPcdInfoCount);
pDimmPcdInfo = NULL;
FREE_POOL_SAFE(pDimmIds);
FREE_POOL_SAFE(pDimms);
FREE_POOL_SAFE(pPath);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Print Platform Config Data table header
@param[in] pHeader table header
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintPcdTableHeader(
IN TABLE_HEADER *pHeader,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
)
{
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx,
pPath,
L"Signature ",
L"%c%c%c%c",
pHeader->Signature & 0xFF,
(pHeader->Signature >> 8) & 0xFF,
(pHeader->Signature >> 16) & 0xFF,
(pHeader->Signature >> 24) & 0xFF);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"Length ", FORMAT_HEX_NOWIDTH, pHeader->Length);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"Revision ", FORMAT_HEX_NOWIDTH, pHeader->Revision);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"Checksum ", FORMAT_HEX_NOWIDTH, pHeader->Checksum);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"OemId ", L"%c%c%c%c%c%c",
pHeader->OemId[0],
pHeader->OemId[1],
pHeader->OemId[2],
pHeader->OemId[3],
pHeader->OemId[4],
pHeader->OemId[5]);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"OemTableId ", L"%c%c%c%c%c%c",
((UINT8 *)&pHeader->OemTableId)[0],
((UINT8 *)&pHeader->OemTableId)[1],
((UINT8 *)&pHeader->OemTableId)[2],
((UINT8 *)&pHeader->OemTableId)[3],
((UINT8 *)&pHeader->OemTableId)[4],
((UINT8 *)&pHeader->OemTableId)[5]);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"OemRevision ", FORMAT_HEX_NOWIDTH, pHeader->OemRevision);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"CreatorId ", L"%c%c%c%c",
((UINT8 *)&pHeader->CreatorId)[0],
((UINT8 *)&pHeader->CreatorId)[1],
((UINT8 *)&pHeader->CreatorId)[2],
((UINT8 *)&pHeader->CreatorId)[3]);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"CreatorRevision ", FORMAT_HEX_NOWIDTH, pHeader->CreatorRevision);
}
/**
Print Platform Config Data PCAT table header
@param[in] pHeader PCAT table header
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintPcdPcatTableHeader(
IN PCAT_TABLE_HEADER *pHeader,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
)
{
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"Type ", FORMAT_HEX_NOWIDTH, pHeader->Type);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"Length ", FORMAT_HEX_NOWIDTH, pHeader->Length);
}
/**
Print Platform Config Data Partition Size Change table
@param[in] pPartitionSizeChange Partition Size Change table
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintPcdPartitionSizeChange(
IN NVDIMM_PARTITION_SIZE_CHANGE *pPartitionSizeChange,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
)
{
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, PCD_PCAT_TABLE_STR, L"PCD Partition Size Change");
PrintPcdPcatTableHeader(&pPartitionSizeChange->Header, pPrinterCtx, pPath);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"PartitionSizeChangeStatus ", FORMAT_HEX_NOWIDTH, pPartitionSizeChange->PartitionSizeChangeStatus);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"PartitionSize ", FORMAT_UINT64_HEX_NOWIDTH, pPartitionSizeChange->PmPartitionSize);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, L"PartitionSize ", L"\n");
}
/**
Print Platform Config Data Identification Information table
@param[in] pIdentificationInfo Identification Information table
@param[in] PcdConfigTableRevision Revision of the PCD Config tables
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintPcdIdentificationInformation(
IN VOID *pIdentificationInfoTable,
IN ACPI_REVISION PcdConfigTableRevision,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
)
{
CHAR16 PartNumber[PART_NUMBER_SIZE + 1];
CHAR16 *pTmpDimmUid = NULL;
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, PCD_IDENTIFICATION_INFO_STR, L"PCD Identification Info");
if (IS_ACPI_REV_MAJ_0_MIN_VALID(PcdConfigTableRevision)) {
NVDIMM_IDENTIFICATION_INFORMATION *pIdentificationInfo = (NVDIMM_IDENTIFICATION_INFORMATION *)pIdentificationInfoTable;
ZeroMem(PartNumber, sizeof(PartNumber));
AsciiStrToUnicodeStrS(pIdentificationInfo->DimmIdentification.Version1.DimmPartNumber, PartNumber, PART_NUMBER_SIZE + 1);
if (IS_ACPI_REV_MAJ_0_MIN_1(PcdConfigTableRevision)) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"DimmManufacturerId ", FORMAT_HEX_NOWIDTH,
EndianSwapUint16(pIdentificationInfo->DimmIdentification.Version1.DimmManufacturerId));
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"DimmSerialNumber ", FORMAT_HEX_NOWIDTH,
EndianSwapUint32(pIdentificationInfo->DimmIdentification.Version1.DimmSerialNumber));
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"DimmPartNumber ", FORMAT_STR, PartNumber);
}
else {
pTmpDimmUid = CatSPrint(NULL, L"%04x-%02x-%04x-%08x", EndianSwapUint16(pIdentificationInfo->DimmIdentification.Version2.Uid.ManufacturerId),
pIdentificationInfo->DimmIdentification.Version2.Uid.ManufacturingLocation,
EndianSwapUint16(pIdentificationInfo->DimmIdentification.Version2.Uid.ManufacturingDate),
EndianSwapUint32(pIdentificationInfo->DimmIdentification.Version2.Uid.SerialNumber));
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"DimmUniqueIdentifer ", FORMAT_STR, pTmpDimmUid);
}
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"PartitionOffset ", FORMAT_UINT64_HEX_NOWIDTH, pIdentificationInfo->PartitionOffset);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"PmPartitionSize ", FORMAT_UINT64_HEX_NOWIDTH L"\n", pIdentificationInfo->PmPartitionSize);
}
else if (IS_ACPI_REV_MAJ_1_OR_MAJ_3(PcdConfigTableRevision)) {
NVDIMM_IDENTIFICATION_INFORMATION3 *pIdentificationInfo = (NVDIMM_IDENTIFICATION_INFORMATION3 *)pIdentificationInfoTable;
pTmpDimmUid = CatSPrint(NULL, L"%04x-%02x-%04x-%08x", EndianSwapUint16(pIdentificationInfo->DimmIdentification.ManufacturerId),
pIdentificationInfo->DimmIdentification.ManufacturingLocation,
EndianSwapUint16(pIdentificationInfo->DimmIdentification.ManufacturingDate),
EndianSwapUint32(pIdentificationInfo->DimmIdentification.SerialNumber));
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"DimmUniqueIdentifer ", FORMAT_STR, pTmpDimmUid);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"DimmLocation ", FORMAT_UINT64_HEX_NOWIDTH, pIdentificationInfo->DimmLocation.AsUint64);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"PartitionOffset ", FORMAT_UINT64_HEX_NOWIDTH, pIdentificationInfo->PartitionOffset);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"PmPartitionSize ", FORMAT_UINT64_HEX_NOWIDTH L"\n", pIdentificationInfo->PmPartitionSize);
}
if (pTmpDimmUid != NULL) {
FREE_POOL_SAFE(pTmpDimmUid);
}
}
/**
Print Platform Config Data Interleave Information table and its extension tables
@param[in] pInterleaveInfo Interleave Information table
@param[in] PcdConfigTableRevision Revision of the PCD Config tables
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintPcdInterleaveInformation(
IN PCAT_TABLE_HEADER *pInterleaveInfoTable,
IN ACPI_REVISION PcdConfigTableRevision,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
)
{
UINT32 Index = 0;
UINT32 IdentificationInfoIndex = 0;
CHAR16 *pPathPcdIdentificationInfo = NULL;
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, PCD_PCAT_TABLE_STR, L"PCD Interleave Info");
if (IS_ACPI_REV_MAJ_0_MIN_VALID(PcdConfigTableRevision)) {
NVDIMM_INTERLEAVE_INFORMATION *pInterleaveInfo = (NVDIMM_INTERLEAVE_INFORMATION *)pInterleaveInfoTable;
PrintPcdPcatTableHeader(&pInterleaveInfo->Header, pPrinterCtx, pPath);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"InterleaveSetIndex ", FORMAT_HEX_NOWIDTH, pInterleaveInfo->InterleaveSetIndex);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"NumOfDimmsInInterleaveSet ", FORMAT_HEX_NOWIDTH, pInterleaveInfo->NumOfDimmsInInterleaveSet);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"InterleaveMemoryType ", FORMAT_HEX_NOWIDTH, pInterleaveInfo->InterleaveMemoryType);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"InterleaveFormatChannel ", FORMAT_HEX_NOWIDTH, pInterleaveInfo->InterleaveFormatChannel);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"InterleaveFormatImc ", FORMAT_HEX_NOWIDTH, pInterleaveInfo->InterleaveFormatImc);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"InterleaveFormatWays ", FORMAT_HEX_NOWIDTH, pInterleaveInfo->InterleaveFormatWays);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"InterleaveChangeStatus ", FORMAT_HEX_NOWIDTH L"\n", pInterleaveInfo->InterleaveChangeStatus);
NVDIMM_IDENTIFICATION_INFORMATION *pCurrentIdentInfo = (NVDIMM_IDENTIFICATION_INFORMATION *)&pInterleaveInfo->pIdentificationInfoList;
for (Index = 0; Index < pInterleaveInfo->NumOfDimmsInInterleaveSet; Index++) {
PRINTER_BUILD_KEY_PATH(pPathPcdIdentificationInfo, DS_IDENTIFICATION_INFO_INDEX_PATH, gDimmIndex, 1, ConfigIndex, 1, Index);
IdentificationInfoIndex++;
PrintPcdIdentificationInformation(pCurrentIdentInfo, PcdConfigTableRevision, pPrinterCtx, pPathPcdIdentificationInfo);
pCurrentIdentInfo++;
}
}
else if (IS_ACPI_REV_MAJ_1_OR_MAJ_3(PcdConfigTableRevision)) {
NVDIMM_INTERLEAVE_INFORMATION3 *pInterleaveInfo = (NVDIMM_INTERLEAVE_INFORMATION3 *)pInterleaveInfoTable;
PrintPcdPcatTableHeader(&pInterleaveInfo->Header, pPrinterCtx, pPath);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"InterleaveSetIndex ", FORMAT_HEX_NOWIDTH, pInterleaveInfo->InterleaveSetIndex);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"NumOfDimmsInInterleaveSet ", FORMAT_HEX_NOWIDTH, pInterleaveInfo->NumOfDimmsInInterleaveSet);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"InterleaveMemoryType ", FORMAT_HEX_NOWIDTH, pInterleaveInfo->InterleaveMemoryType);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"InterleaveSizeChannel ", FORMAT_HEX_NOWIDTH, pInterleaveInfo->InterleaveFormatChannel);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"InterleaveSizeImc ", FORMAT_HEX_NOWIDTH, pInterleaveInfo->InterleaveFormatImc);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"InterleaveChangeStatus ", FORMAT_HEX_NOWIDTH , pInterleaveInfo->InterleaveChangeStatus);
NVDIMM_IDENTIFICATION_INFORMATION3 *pCurrentIdentInfo = (NVDIMM_IDENTIFICATION_INFORMATION3 *)&pInterleaveInfo->pIdentificationInfoList;
for (Index = 0; Index < pInterleaveInfo->NumOfDimmsInInterleaveSet; Index++) {
PRINTER_BUILD_KEY_PATH(pPathPcdIdentificationInfo, DS_IDENTIFICATION_INFO_INDEX_PATH, gDimmIndex, 1, ConfigIndex, 1, Index);
IdentificationInfoIndex++;
PrintPcdIdentificationInformation(pCurrentIdentInfo, PcdConfigTableRevision, pPrinterCtx, pPathPcdIdentificationInfo);
pCurrentIdentInfo++;
}
}
FREE_POOL_SAFE(pPathPcdIdentificationInfo);
}
VOID
PrintPcdConfigManagementAttributesInformation(
IN CONFIG_MANAGEMENT_ATTRIBUTES_EXTENSION_TABLE *pConfigManagementAttributesInfo,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
)
{
INTEL_DIMM_CONFIG *pIntelDIMMConfig = NULL;
EFI_GUID IntelDimmConfigVariableGuid = INTEL_DIMM_CONFIG_VARIABLE_GUID;
CHAR16 *pGuidStr = NULL;
pGuidStr = GuidToStr(&pConfigManagementAttributesInfo->Guid);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"Mngmt Table ", L"PCD Cfg Mngmt Attr Extension");
PrintPcdPcatTableHeader(&pConfigManagementAttributesInfo->Header, pPrinterCtx, pPath);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"VendorID ", FORMAT_HEX_NOWIDTH, pConfigManagementAttributesInfo->VendorId);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"GUID ", FORMAT_STR_NL, pGuidStr);
if (CompareGuid(&pConfigManagementAttributesInfo->Guid, &IntelDimmConfigVariableGuid)) {
pIntelDIMMConfig = (INTEL_DIMM_CONFIG *)pConfigManagementAttributesInfo->pGuidData;
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"Revision ", FORMAT_INT32, pIntelDIMMConfig->Revision);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"ProvisionCapacityMode ", FORMAT_INT32, pIntelDIMMConfig->ProvisionCapacityMode);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"MemorySize ", FORMAT_INT32, pIntelDIMMConfig->MemorySize);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"PMType ", FORMAT_INT32, pIntelDIMMConfig->PMType);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"ProvisionNamespaceMode ", FORMAT_INT32, pIntelDIMMConfig->ProvisionNamespaceMode);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"NamespaceFlags ", FORMAT_INT32, pIntelDIMMConfig->NamespaceFlags);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"NamespaceLabelVersion ", FORMAT_INT32, pIntelDIMMConfig->NamespaceLabelVersion);
}
FREE_POOL_SAFE(pGuidStr);
}
/**
Print Platform Config Data Current Config table and its PCAT tables
@param[in] pCurrentConfig Current Config table
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintPcdCurrentConfig(
IN NVDIMM_CURRENT_CONFIG *pCurrentConfig,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
)
{
NVDIMM_PARTITION_SIZE_CHANGE *pPartSizeChange = NULL;
CONFIG_MANAGEMENT_ATTRIBUTES_EXTENSION_TABLE *pConfigManagementAttributesInfo = NULL;
PCAT_TABLE_HEADER *pCurPcatTable = NULL;
UINT32 SizeOfPcatTables = 0;
EFI_STATUS ReturnCode = EFI_SUCCESS;
CHAR16 *pPathPcdPcatTable = NULL;
if (IS_ACPI_HEADER_REV_INVALID(pCurrentConfig)){
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"Error: Invalid revision value %d for PCD current config table.", pCurrentConfig->Header.Revision);
return;
}
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, PCD_TABLE_STR, L"PCD Current Config");
PrintPcdTableHeader(&pCurrentConfig->Header, pPrinterCtx, pPath);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"ConfigStatus ", FORMAT_HEX_NOWIDTH, pCurrentConfig->ConfigStatus);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"VolatileMemSizeIntoSpa ", FORMAT_UINT64_HEX_NOWIDTH, pCurrentConfig->VolatileMemSizeIntoSpa);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"PersistentMemSizeIntoSpa ", FORMAT_UINT64_HEX_NOWIDTH, pCurrentConfig->PersistentMemSizeIntoSpa);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, L"PersistentMemSizeIntoSpa ", L"\n");
/**
Check if there is at least one PCAT table
**/
if (pCurrentConfig->Header.Length <= sizeof(*pCurrentConfig)) {
return;
}
pCurPcatTable = (PCAT_TABLE_HEADER *)&pCurrentConfig->pPcatTables;
SizeOfPcatTables = pCurrentConfig->Header.Length - (UINT32)((UINT8 *)pCurPcatTable - (UINT8 *)pCurrentConfig);
/**
Example of the use of the while loop condition
PCAT table #1 offset: 0 size: 10
PCAT table #2 offset: 10 size: 5
Size of PCAT tables: 15 (10 + 5)
Iteration #1: offset: 0
Iteration #2: offset: 10
Iteration #3: offset: 15 stop the loop: offset isn't less than size
**/
while ((UINT32)((UINT8 *)pCurPcatTable - (UINT8 *)&pCurrentConfig->pPcatTables) < SizeOfPcatTables) {
if (pCurPcatTable->Type == PCAT_TYPE_PARTITION_SIZE_CHANGE_TABLE) {
PRINTER_BUILD_KEY_PATH(pPathPcdPcatTable, DS_PCD_PCAT_TABLE_INDEX_PATH, gDimmIndex, 1, ConfigIndex, 0);
pPartSizeChange = (NVDIMM_PARTITION_SIZE_CHANGE *)pCurPcatTable;
PrintPcdPartitionSizeChange(pPartSizeChange, pPrinterCtx, pPathPcdPcatTable);
pCurPcatTable = GET_VOID_PTR_OFFSET(pCurPcatTable, pPartSizeChange->Header.Length);
}
else if (pCurPcatTable->Type == PCAT_TYPE_INTERLEAVE_INFORMATION_TABLE) {
PRINTER_BUILD_KEY_PATH(pPathPcdPcatTable, DS_PCD_PCAT_TABLE_INDEX_PATH, gDimmIndex, 1, ConfigIndex, 1);
PrintPcdInterleaveInformation(pCurPcatTable, pCurrentConfig->Header.Revision, pPrinterCtx, pPathPcdPcatTable);
pCurPcatTable = GET_VOID_PTR_OFFSET(pCurPcatTable, pCurPcatTable->Length);
}
else if (pCurPcatTable->Type == PCAT_TYPE_CONFIG_MANAGEMENT_ATTRIBUTES_TABLE) {
pConfigManagementAttributesInfo = (CONFIG_MANAGEMENT_ATTRIBUTES_EXTENSION_TABLE *)pCurPcatTable;
pCurPcatTable = GET_VOID_PTR_OFFSET(pCurPcatTable, pConfigManagementAttributesInfo->Header.Length);
}
else {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"Error: wrong PCAT table type");
break;
}
FREE_POOL_SAFE(pPathPcdPcatTable);
}
}
/**
Print Platform Config Data Config Input table and its PCAT tables
@param[in] pConfigInput Config Input table
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintPcdConfInput(
IN NVDIMM_PLATFORM_CONFIG_INPUT *pConfigInput,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
)
{
NVDIMM_PARTITION_SIZE_CHANGE *pPartSizeChange = NULL;
CONFIG_MANAGEMENT_ATTRIBUTES_EXTENSION_TABLE *pConfigManagementAttributesInfo = NULL;
PCAT_TABLE_HEADER *pCurPcatTable = NULL;
UINT32 SizeOfPcatTables = 0;
EFI_STATUS ReturnCode = EFI_SUCCESS;
CHAR16 *pPathPcdPcatTable = NULL;
if (IS_ACPI_HEADER_REV_INVALID(pConfigInput)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"Error: Invalid revision value %d for PCD config input table.", pConfigInput->Header.Revision);
return;
}
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, PCD_TABLE_STR, L"Platform Config Data Conf Input table");
PrintPcdTableHeader(&pConfigInput->Header, pPrinterCtx, pPath);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"SequenceNumber ", FORMAT_HEX_NOWIDTH, pConfigInput->SequenceNumber);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, L"SequenceNumber ", L"\n");
/**
Check if there is at least one PCAT table
**/
if (pConfigInput->Header.Length <= sizeof(*pConfigInput)) {
return;
}
pCurPcatTable = (PCAT_TABLE_HEADER *)&pConfigInput->pPcatTables;
SizeOfPcatTables = pConfigInput->Header.Length - (UINT32)((UINT8 *)pCurPcatTable - (UINT8 *)pConfigInput);
/**
Example of the use of the while loop condition
PCAT table #1 offset: 0 size: 10
PCAT table #2 offset: 10 size: 5
Size of PCAT tables: 15 (10 + 5)
Iteration #1: offset: 0
Iteration #2: offset: 10
Iteration #3: offset: 15 stop the loop: offset isn't less than size
**/
while ((UINT32)((UINT8 *)pCurPcatTable - (UINT8 *)&pConfigInput->pPcatTables) < SizeOfPcatTables) {
if (pCurPcatTable->Type == PCAT_TYPE_PARTITION_SIZE_CHANGE_TABLE) {
PRINTER_BUILD_KEY_PATH(pPathPcdPcatTable, DS_PCD_PCAT_TABLE_INDEX_PATH, gDimmIndex, 1, ConfigIndex, 0);
pPartSizeChange = (NVDIMM_PARTITION_SIZE_CHANGE *)pCurPcatTable;
PrintPcdPartitionSizeChange(pPartSizeChange, pPrinterCtx, pPathPcdPcatTable);
pCurPcatTable = GET_VOID_PTR_OFFSET(pCurPcatTable, pPartSizeChange->Header.Length);
}
else if (pCurPcatTable->Type == PCAT_TYPE_INTERLEAVE_INFORMATION_TABLE) {
PRINTER_BUILD_KEY_PATH(pPathPcdPcatTable, DS_PCD_PCAT_TABLE_INDEX_PATH, gDimmIndex, 1, ConfigIndex, 1);
PrintPcdInterleaveInformation(pCurPcatTable, pConfigInput->Header.Revision, pPrinterCtx, pPathPcdPcatTable);
pCurPcatTable = GET_VOID_PTR_OFFSET(pCurPcatTable, pCurPcatTable->Length);
}
else if (pCurPcatTable->Type == PCAT_TYPE_CONFIG_MANAGEMENT_ATTRIBUTES_TABLE) {
PRINTER_BUILD_KEY_PATH(pPathPcdPcatTable, DS_PCD_PCAT_TABLE_INDEX_PATH, gDimmIndex, 1, ConfigIndex, 2);
pConfigManagementAttributesInfo = (CONFIG_MANAGEMENT_ATTRIBUTES_EXTENSION_TABLE *)pCurPcatTable;
PrintPcdConfigManagementAttributesInformation(pConfigManagementAttributesInfo, pPrinterCtx, pPathPcdPcatTable);
pCurPcatTable = GET_VOID_PTR_OFFSET(pCurPcatTable, pConfigManagementAttributesInfo->Header.Length);
}
else {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"Error: wrong PCAT table type");
break;
}
FREE_POOL_SAFE(pPathPcdPcatTable);
}
}
/**
Print Platform Config Data Config Output table and its PCAT tables
@param[in] pConfigOutput Config Output table
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintPcdConfOutput(
IN NVDIMM_PLATFORM_CONFIG_OUTPUT *pConfigOutput,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
)
{
NVDIMM_PARTITION_SIZE_CHANGE *pPartSizeChange = NULL;
CONFIG_MANAGEMENT_ATTRIBUTES_EXTENSION_TABLE *pConfigManagementAttributesInfo = NULL;
PCAT_TABLE_HEADER *pCurPcatTable = NULL;
UINT32 SizeOfPcatTables = 0;
EFI_STATUS ReturnCode = EFI_SUCCESS;
CHAR16 *pPathPcdPcatTable = NULL;
if (IS_ACPI_HEADER_REV_INVALID(pConfigOutput)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"Error: Invalid revision value %d for PCD config output table.", pConfigOutput->Header.Revision);
return;
}
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, PCD_TABLE_STR, L"Platform Config Data Conf Output table");
PrintPcdTableHeader(&pConfigOutput->Header, pPrinterCtx, pPath);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"SequenceNumber ", FORMAT_HEX_NOWIDTH, pConfigOutput->SequenceNumber);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"ValidationStatus ", FORMAT_HEX_NOWIDTH, pConfigOutput->ValidationStatus);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, L"ValidationStatus ", L"\n");
/** Check if there is at least one PCAT table **/
if (pConfigOutput->Header.Length <= sizeof(*pConfigOutput)) {
return;
}
pCurPcatTable = (PCAT_TABLE_HEADER *)&pConfigOutput->pPcatTables;
SizeOfPcatTables = pConfigOutput->Header.Length - (UINT32)((UINT8 *)pCurPcatTable - (UINT8 *)pConfigOutput);
/**
Example of the use of the while loop condition
PCAT table #1 offset: 0 size: 10
PCAT table #2 offset: 10 size: 5
Size of PCAT tables: 15 (10 + 5)
Iteration #1: offset: 0
Iteration #2: offset: 10
Iteration #3: offset: 15 stop the loop: offset isn't less than size
**/
while ((UINT32)((UINT8 *)pCurPcatTable - (UINT8 *)&pConfigOutput->pPcatTables) < SizeOfPcatTables) {
if (pCurPcatTable->Type == PCAT_TYPE_PARTITION_SIZE_CHANGE_TABLE) {
PRINTER_BUILD_KEY_PATH(pPathPcdPcatTable, DS_PCD_PCAT_TABLE_INDEX_PATH, gDimmIndex, 1, ConfigIndex, 0);
pPartSizeChange = (NVDIMM_PARTITION_SIZE_CHANGE *)pCurPcatTable;
PrintPcdPartitionSizeChange(pPartSizeChange, pPrinterCtx, pPathPcdPcatTable);
pCurPcatTable = GET_VOID_PTR_OFFSET(pCurPcatTable, pPartSizeChange->Header.Length);
}
else if (pCurPcatTable->Type == PCAT_TYPE_INTERLEAVE_INFORMATION_TABLE) {
PRINTER_BUILD_KEY_PATH(pPathPcdPcatTable, DS_PCD_PCAT_TABLE_INDEX_PATH, gDimmIndex, 1, ConfigIndex, 1);
PrintPcdInterleaveInformation(pCurPcatTable, pConfigOutput->Header.Revision, pPrinterCtx, pPathPcdPcatTable);
pCurPcatTable = GET_VOID_PTR_OFFSET(pCurPcatTable, pCurPcatTable->Length);
}
else if (pCurPcatTable->Type == PCAT_TYPE_CONFIG_MANAGEMENT_ATTRIBUTES_TABLE) {
pConfigManagementAttributesInfo = (CONFIG_MANAGEMENT_ATTRIBUTES_EXTENSION_TABLE *)pCurPcatTable;
pCurPcatTable = GET_VOID_PTR_OFFSET(pCurPcatTable, pConfigManagementAttributesInfo->Header.Length);
}
else {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"Error: wrong PCAT table type");
break;
}
FREE_POOL_SAFE(pPathPcdPcatTable);
}
}
/**
Print Platform Config Data Configuration Header table and all subtables
@param[in] pConfHeader Configuration Header table
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintPcdConfigurationHeader(
IN NVDIMM_CONFIGURATION_HEADER *pConfHeader,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
)
{
CHAR16 *pPathPcdTable = NULL;
ConfigIndex = 0;
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"Table ", L"PCD Config Header");
PrintPcdTableHeader(&pConfHeader->Header, pPrinterCtx, pPath);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"CurrentConfDataSize ", FORMAT_HEX_NOWIDTH, pConfHeader->CurrentConfDataSize);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"CurrentConfStartOffset ", FORMAT_HEX_NOWIDTH, pConfHeader->CurrentConfStartOffset);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"ConfInputDataSize ", FORMAT_HEX_NOWIDTH, pConfHeader->ConfInputDataSize);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"ConfInputDataOffset ", FORMAT_HEX_NOWIDTH, pConfHeader->ConfInputStartOffset);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"ConfOutputDataSize ", FORMAT_HEX_NOWIDTH, pConfHeader->ConfOutputDataSize);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"ConfOutputDataOffset ", FORMAT_HEX_NOWIDTH, pConfHeader->ConfOutputStartOffset);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, L"ConfOutputDataOffset ", L"\n");
if (pConfHeader->CurrentConfStartOffset != 0 && pConfHeader->CurrentConfDataSize != 0) {
PRINTER_BUILD_KEY_PATH(pPathPcdTable, DS_TABLE_INDEX_PATH, gDimmIndex, 1, ConfigIndex);
PrintPcdCurrentConfig(GET_NVDIMM_CURRENT_CONFIG(pConfHeader), pPrinterCtx, pPathPcdTable);
ConfigIndex++;
}
if (pConfHeader->ConfInputStartOffset != 0 && pConfHeader->ConfInputDataSize != 0) {
PRINTER_BUILD_KEY_PATH(pPathPcdTable, DS_TABLE_INDEX_PATH, gDimmIndex, 1, ConfigIndex);
PrintPcdConfInput(GET_NVDIMM_PLATFORM_CONFIG_INPUT(pConfHeader), pPrinterCtx, pPathPcdTable);
ConfigIndex++;
}
if (pConfHeader->ConfOutputStartOffset != 0 && pConfHeader->ConfOutputDataSize != 0) {
PRINTER_BUILD_KEY_PATH(pPathPcdTable, DS_TABLE_INDEX_PATH, gDimmIndex, 1, ConfigIndex);
PrintPcdConfOutput(GET_NVDIMM_PLATFORM_CONFIG_OUTPUT(pConfHeader), pPrinterCtx, pPathPcdTable);
ConfigIndex++;
}
FREE_POOL_SAFE(pPathPcdTable);
}
/**
Print Namespace Index
@param[in] pNamespaceIndex Namespace Index
**/
VOID
PrintNamespaceIndex(
IN NAMESPACE_INDEX *pNamespaceIndex
)
{
CHAR16 Buffer[NSINDEX_SIG_LEN + 1];
if (pNamespaceIndex == NULL) {
return;
}
ZeroMem(Buffer, sizeof(Buffer));
AsciiStrToUnicodeStrS((CHAR8 *)&pNamespaceIndex->Signature, Buffer, NSINDEX_SIG_LEN + 1);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(gpPrinterCtxLbaCommon, gpPathLba, L"Signature ", FORMAT_STR, Buffer);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(gpPrinterCtxLbaCommon, gpPathLba, L"Flags ", FORMAT_HEX_NOWIDTH, *pNamespaceIndex->Flags);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(gpPrinterCtxLbaCommon, gpPathLba, L"LabelSize ", FORMAT_HEX_NOWIDTH, pNamespaceIndex->LabelSize);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(gpPrinterCtxLbaCommon, gpPathLba, L"Sequence ", FORMAT_HEX_NOWIDTH, pNamespaceIndex->Sequence);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(gpPrinterCtxLbaCommon, gpPathLba, L"MyOffset ", FORMAT_UINT64_HEX_NOWIDTH, pNamespaceIndex->MyOffset);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(gpPrinterCtxLbaCommon, gpPathLba, L"MySize ", FORMAT_UINT64_HEX_NOWIDTH, pNamespaceIndex->MySize);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(gpPrinterCtxLbaCommon, gpPathLba, L"OtherOffset ", FORMAT_UINT64_HEX_NOWIDTH, pNamespaceIndex->OtherOffset);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(gpPrinterCtxLbaCommon, gpPathLba, L"LabelOffset ", FORMAT_UINT64_HEX_NOWIDTH, pNamespaceIndex->LabelOffset);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(gpPrinterCtxLbaCommon, gpPathLba, L"NumOfLabel ", FORMAT_HEX_NOWIDTH, pNamespaceIndex->NumberOfLabels);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(gpPrinterCtxLbaCommon, gpPathLba, L"Major ", FORMAT_HEX_NOWIDTH, pNamespaceIndex->Major);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(gpPrinterCtxLbaCommon, gpPathLba, L"Minor ", FORMAT_HEX_NOWIDTH, pNamespaceIndex->Minor);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(gpPrinterCtxLbaCommon, gpPathLba, L"Checksum ", FORMAT_UINT64_HEX_NOWIDTH, pNamespaceIndex->Checksum);
PrintLsaHex(pNamespaceIndex->pFree,
LABELS_TO_FREE_BYTES(ROUNDUP(pNamespaceIndex->NumberOfLabels, 8)));
}
/**
Print Namespace Label
@param[in] pNamespaceLabel Namespace Label
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintNamespaceLabel(
IN NAMESPACE_LABEL *pNamespaceLabel,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
)
{
CHAR16 Buffer[NLABEL_NAME_LEN_WITH_TERMINATOR];
CHAR16 *pUuidStr = NULL;
CHAR16 *pTypeGuidStr = NULL;
CHAR16 *pAddrAbstrGuidStr = NULL;
if (pNamespaceLabel == NULL) {
return;
}
ZeroMem(Buffer, sizeof(Buffer));
AsciiStrToUnicodeStrS((CHAR8 *)&pNamespaceLabel->Name, Buffer, NLABEL_NAME_LEN_WITH_TERMINATOR);
pUuidStr = GuidToStr(&pNamespaceLabel->Uuid);
pTypeGuidStr = GuidToStr(&pNamespaceLabel->TypeGuid);
pAddrAbstrGuidStr = GuidToStr(&pNamespaceLabel->AddressAbstractionGuid);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"Uuid ", FORMAT_STR, pUuidStr);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"Name ", FORMAT_STR, Buffer);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"LabelFlags ", FORMAT_HEX_NOWIDTH, pNamespaceLabel->Flags);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"NumOfLabels ", FORMAT_HEX_NOWIDTH, pNamespaceLabel->NumberOfLabels);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"Position ", FORMAT_HEX_NOWIDTH, pNamespaceLabel->Position);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"ISetCookie ", FORMAT_UINT64_HEX_NOWIDTH, pNamespaceLabel->InterleaveSetCookie);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"LbaSize ", FORMAT_UINT64_HEX_NOWIDTH, pNamespaceLabel->LbaSize);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"Dpa ", FORMAT_UINT64_HEX_NOWIDTH, pNamespaceLabel->Dpa);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"RawSize ", FORMAT_UINT64_HEX_NOWIDTH, pNamespaceLabel->RawSize);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"Slot ", FORMAT_HEX_NOWIDTH, pNamespaceLabel->Slot);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"Alignment ", FORMAT_HEX_NOWIDTH, pNamespaceLabel->Alignment);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"TypeGuid ", FORMAT_STR, pTypeGuidStr);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"AddrAbstrGuid ", FORMAT_STR, pAddrAbstrGuidStr);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"LabelChecksum ", FORMAT_UINT64_HEX_NOWIDTH, pNamespaceLabel->Checksum);
PRINTER_APPEND_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, L"LabelChecksum ", L"\n");
FREE_POOL_SAFE(pUuidStr);
FREE_POOL_SAFE(pTypeGuidStr);
FREE_POOL_SAFE(pAddrAbstrGuidStr);
}
/**
Print Label Storage Area and all subtables
@param[in] pLba Label Storage Area
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintLabelStorageArea(
IN LABEL_STORAGE_AREA *pLba,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
UINT16 Index = 0;
UINT16 CurrentIndex = 0;
UINT16 SlotStatus = SLOT_UNKNOWN;
BOOLEAN First = FALSE;
PRINT_CONTEXT *pPrinterCtxNsLabel = NULL;
CHAR16 *pPathNsLabel = NULL;
pPrinterCtxNsLabel = pPrinterCtx;
if (pLba == NULL) {
return;
}
ReturnCode = GetLsaIndexes(pLba, &CurrentIndex, NULL);
if (EFI_ERROR(ReturnCode)) {
return;
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, L"Label Storage Area ", L"Current Index");
gpPathLba = pPath;
gpPrinterCtxLbaCommon = pPrinterCtx;
PrintNamespaceIndex(&pLba->Index[CurrentIndex]);
for (Index = 0, First = TRUE; Index < pLba->Index[CurrentIndex].NumberOfLabels; Index++) {
CheckSlotStatus(&pLba->Index[CurrentIndex], Index, &SlotStatus);
if (SlotStatus == SLOT_FREE) {
continue;
}
if (First) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, L"Labels", L"Label Storage Area ");
First = FALSE;
}
PRINTER_BUILD_KEY_PATH(pPathNsLabel, DS_TABLE_INDEX_PATH, gDimmIndex, 0, Index);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtxNsLabel, pPathNsLabel, PCD_TABLE_STR, L"Namespace Label Info");
PrintNamespaceLabel(&pLba->pLabels[Index], pPrinterCtxNsLabel, pPathNsLabel);
}
FREE_POOL_SAFE(pPathNsLabel);
}
/**
Function that allows for nicely formatted HEX & ASCII console output.
It can be used to inspect memory objects without a need for debugger or dumping raw DIMM data.
@param[in] pBuffer Pointer to an arbitrary object
@param[in] Bytes Number of bytes to display
**/
VOID
PrintLsaHex(
IN VOID *pBuffer,
IN UINT32 Bytes
)
{
UINT8 Byte, AsciiBuffer[COLUMN_IN_HEX_DUMP];
UINT16 Column, NextColumn, Index, Index2;
UINT8 *pData;
CHAR16 *message = NULL;
CHAR16 *messageId = NULL;
if (pBuffer == NULL) {
NVDIMM_DBG("pBuffer is NULL");
return;
}
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(gpPrinterCtxLbaCommon, gpPathLba, L"Hexdump", L"For %d bytes", Bytes);
pData = (UINT8 *)pBuffer;
for (Index = 0; Index < Bytes; Index++) {
Column = Index % COLUMN_IN_HEX_DUMP;
NextColumn = (Index + 1) % COLUMN_IN_HEX_DUMP;
Byte = *(pData + Index);
if (Column == 0) {
messageId = CatSPrintClean(messageId, L"%.3d", Index);
}
if (Index % 8 == 0) {
message = CatSPrintClean(message, L" ");
}
message = CatSPrintClean(message, L"%.2x", *(pData + Index));
AsciiBuffer[Column] = IsAsciiAlnumCharacter(Byte) ? Byte : '.';
if (NextColumn == 0 && Index != 0) {
message = CatSPrintClean(message, L" ");
for (Index2 = 0; Index2 < COLUMN_IN_HEX_DUMP; Index2++) {
message = CatSPrintClean(message, L"%c", AsciiBuffer[Index2]);
if (Index2 == COLUMN_IN_HEX_DUMP / 2 - 1) {
message = CatSPrintClean(message, L" ");
}
}
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(gpPrinterCtxLbaCommon, gpPathLba, messageId, message);
FREE_POOL_SAFE(message);
FREE_POOL_SAFE(messageId);
}
}
FREE_POOL_SAFE(message);
FREE_POOL_SAFE(messageId);
}
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowPcdCommand.h 0000664 0000000 0000000 00000011461 14165347476 0020750 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SHOW_PCD_COMMAND_
#define _SHOW_PCD_COMMAND_
/**
Register the Show PCD command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowPcdCommand(
);
/**
Execute the Show PCD command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
**/
EFI_STATUS
ShowPcd(
IN struct Command *pCmd
);
/**
Print Platform Config Data table header
@param[in] pHeader table header
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintPcdTableHeader(
IN TABLE_HEADER *pHeader,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
);
/**
Print Platform Config Data PCAT table header
@param[in] pHeader PCAT table header
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintPcdPcatTableHeader(
IN PCAT_TABLE_HEADER *pHeader,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
);
/**
Print Platform Config Data Partition Size Change table
@param[in] pPartitionSizeChange Partition Size Change table
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintPcdPartitionSizeChange(
IN NVDIMM_PARTITION_SIZE_CHANGE *pPartitionSizeChange,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
);
/**
Print Platform Config Data Identification Information table
@param[in] pIdentificationInfo Identification Information table
@param[in] PcdConfigTableRevision Revision of the PCD Config tables
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintPcdIdentificationInformation(
IN VOID *pIdentificationInfo,
IN ACPI_REVISION PcdConfigTableRevision,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
);
/**
Print Platform Config Data Interleave Information table and its extension tables
@param[in] pInterleaveInfo Interleave Information table
@param[in] PcdConfigTableRevision Revision of the PCD Config tables
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintPcdInterleaveInformation(
IN PCAT_TABLE_HEADER *pInterleaveInfo,
IN ACPI_REVISION PcdConfigTableRevision,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
);
/**
Print Platform Config Data Current Config table and its PCAT tables
@param[in] pCurrentConfig Current Config table
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintPcdCurrentConfig(
IN NVDIMM_CURRENT_CONFIG *pCurrentConfig,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
);
/**
Print Platform Config Data Config Input table and its PCAT tables
@param[in] pConfigInput Config Input table
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintPcdConfInput(
IN NVDIMM_PLATFORM_CONFIG_INPUT *pConfigInput,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
);
/**
Print Platform Config Data Config Output table and its PCAT tables
@param[in] pConfigOutput Config Output table
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintPcdConfOutput(
IN NVDIMM_PLATFORM_CONFIG_OUTPUT *pConfigOutput,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
);
/**
Print Platform Config Data Configuration Header table and all subtables
@param[in] pConfHeader Configuration Header table
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintPcdConfigurationHeader(
IN NVDIMM_CONFIGURATION_HEADER *pConfHeader,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
);
/**
Print Namespace Index
@param[in] pNamespaceIndex Namespace Index
**/
VOID
PrintNamespaceIndex(
IN NAMESPACE_INDEX *pNamespaceIndex
);
/**
Print Namespace Label
@param[in] pNamespaceLabel Namespace Label
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintNamespaceLabel(
IN NAMESPACE_LABEL *pNamespaceLabel,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
);
/**
Print Label Storage Area and all subtables
@param[in] pLba Label Storage Area
@param[in] pPrinterCtx pointer for printer
@param[in] pPath
**/
VOID
PrintLabelStorageArea(
IN LABEL_STORAGE_AREA *pLba,
IN PRINT_CONTEXT *pPrinterCtx,
IN CHAR16 *pPath
);
/**
Function that allows for nicely formatted HEX & ASCII console output.
It can be used to inspect memory objects without a need for debugger or dumping raw DIMM data.
@param[in] pBuffer Pointer to an arbitrary object
@param[in] Bytes Number of bytes to display
**/
VOID
PrintLsaHex(
IN VOID *pBuffer,
IN UINT32 Bytes
);
#endif /* _SHOW_PCD_COMMAND_ */
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowPerformanceCommand.c 0000664 0000000 0000000 00000030631 14165347476 0022476 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include
#include
#include
#include "CommandParser.h"
#include "ShowPerformanceCommand.h"
#include "Common.h"
#include "Convert.h"
#include "NvmTypes.h"
#define DS_ROOT_PATH L"/DimmPerformanceList"
#define DS_SOCKET_PATH L"/DimmPerformanceList/DimmPerformance"
#define DS_SOCKET_INDEX_PATH L"/DimmPerformanceList/DimmPerformance[%d]"
/*
* PRINT LIST ATTRIBUTES
* ---DimmId=0x0001---
* MediaReads=0x000000000000000000000000cc3bb004
* MediaWrites=0x00000000000000000000000049437ab4
* ReadRequests=0x000000000000000000000000000c0008
* ...
*/
PRINTER_LIST_ATTRIB ShowPerformanceListAttributes =
{
{
{
L"DimmPerformance", //GROUP LEVEL TYPE
L"---" DIMM_ID_STR L"=$(" DIMM_ID_STR L")---", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT L"%ls=%ls", //NULL or KEY VAL FORMAT STR
DIMM_ID_STR //NULL or IGNORE KEY LIST (K1;K2)
}
}
};
PRINTER_DATA_SET_ATTRIBS ShowPerformanceDataSetAttribs =
{
&ShowPerformanceListAttributes,
NULL
};
EFI_STATUS
ShowPerformance(IN struct Command *pCmd);
/**
Command syntax definition
**/
struct Command ShowPerformanceCommand =
{
SHOW_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"", HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
#ifdef OS_BUILD
{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP, HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#else
{L"", L"", L"", L"", L"",FALSE, ValueOptional}
#endif
},
{ //!< targets
{ DIMM_TARGET, L"", HELP_TEXT_DIMM_IDS, FALSE, ValueOptional },
{ PERFORMANCE_TARGET, L"", HELP_TEXT_PERFORMANCE_CAT, TRUE, ValueOptional }
},
{ //!< properties
{ L"", L"", L"", FALSE, ValueOptional },
},
L"Show performance statistics of one or more " PMEM_MODULES_STR L".", //!< help
ShowPerformance,
TRUE, //!< enable print control support
};
CHAR16 *mppAllowedShowPerformanceDisplayValues[] =
{
DCPMM_PERFORMANCE_MEDIA_READS,
DCPMM_PERFORMANCE_MEDIA_WRITES,
DCPMM_PERFORMANCE_READ_REQUESTS,
DCPMM_PERFORMANCE_WRITE_REQUESTS,
DCPMM_PERFORMANCE_TOTAL_MEDIA_READS,
DCPMM_PERFORMANCE_TOTAL_MEDIA_WRITES,
DCPMM_PERFORMANCE_TOTAL_READ_REQUESTS,
DCPMM_PERFORMANCE_TOTAL_WRITE_REQUESTS
};
#define PERFORMANCE_DATA_FORMAT L"0x"FORMAT_UINT64_HEX FORMAT_UINT64_HEX
EFI_STATUS GetDimmIdOrDimmHandleToPrint(UINT16 DimmId, DIMM_INFO *AllDimmInfos,
UINT32 DimmCount, UINT32 *HandleToPrint)
{
UINT32 Index = 0;
for (Index = 0; Index < DimmCount; ++Index) {
if (AllDimmInfos[Index].DimmID == DimmId) {
*HandleToPrint = AllDimmInfos[Index].DimmHandle;
return EFI_SUCCESS;
}
}
return EFI_INVALID_PARAMETER;
}
STATIC
VOID
PrintPerformanceData(PRINT_CONTEXT *pPrinterCtx, UINT16 *DimmId, UINT32 DimmIdsNum, DIMM_INFO *AllDimmInfos,
UINT32 DimmCount, DIMM_PERFORMANCE_DATA *pDimmsPerformanceData,
BOOLEAN AllOptionSet, BOOLEAN DisplayOptionSet, CHAR16 *pDisplayOptionValue)
{
UINT32 AllDimmsIndex = 0;
UINT32 InfoIndex = 0;
EFI_STATUS ReturnCode = EFI_INVALID_PARAMETER;
CHAR16 DimmStr[MAX_DIMM_UID_LENGTH];
UINT32 DimmIndex = 0;
CHAR16 *pPath = NULL;
BOOLEAN InfoFound = FALSE;
// Account for multiple or no input dimms given
for (AllDimmsIndex = 0; AllDimmsIndex < DimmCount; AllDimmsIndex++) {
if (DimmIdsNum > 0 && !ContainUint(DimmId, DimmIdsNum,
pDimmsPerformanceData[AllDimmsIndex].DimmId)) {
continue;
}
// find info record that corresponds to the performance data
InfoFound = FALSE;
for (InfoIndex = 0; InfoIndex < DimmCount; InfoIndex++) {
if (AllDimmInfos[InfoIndex].DimmID == pDimmsPerformanceData[AllDimmsIndex].DimmId) {
InfoFound = TRUE;
break;
}
}
// skip record with no matching info record
if (!InfoFound) {
continue;
}
// Print the DimmID
ReturnCode = GetPreferredDimmIdAsString(AllDimmInfos[InfoIndex].DimmHandle,
AllDimmInfos[InfoIndex].DimmUid, DimmStr, MAX_DIMM_UID_LENGTH);
if (EFI_ERROR(ReturnCode)) {
continue;
}
PRINTER_BUILD_KEY_PATH(pPath, DS_SOCKET_INDEX_PATH, DimmIndex);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DIMM_ID_STR, DimmStr);
/** MediaReads **/
if (AllOptionSet || (DisplayOptionSet && ContainsValue(pDisplayOptionValue, DCPMM_PERFORMANCE_MEDIA_READS))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, DCPMM_PERFORMANCE_MEDIA_READS, PERFORMANCE_DATA_FORMAT,
pDimmsPerformanceData[AllDimmsIndex].MediaReads.Uint64_1,
pDimmsPerformanceData[AllDimmsIndex].MediaReads.Uint64);
}
/** MediaWrites **/
if (AllOptionSet || (DisplayOptionSet && ContainsValue(pDisplayOptionValue, DCPMM_PERFORMANCE_MEDIA_WRITES))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, DCPMM_PERFORMANCE_MEDIA_WRITES, PERFORMANCE_DATA_FORMAT,
pDimmsPerformanceData[AllDimmsIndex].MediaWrites.Uint64_1,
pDimmsPerformanceData[AllDimmsIndex].MediaWrites.Uint64);
}
/** ReadRequests **/
if (AllOptionSet || (DisplayOptionSet && ContainsValue(pDisplayOptionValue, DCPMM_PERFORMANCE_READ_REQUESTS))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, DCPMM_PERFORMANCE_READ_REQUESTS, PERFORMANCE_DATA_FORMAT,
pDimmsPerformanceData[AllDimmsIndex].ReadRequests.Uint64_1,
pDimmsPerformanceData[AllDimmsIndex].ReadRequests.Uint64);
}
/** WriteRequests **/
if (AllOptionSet || (DisplayOptionSet && ContainsValue(pDisplayOptionValue, DCPMM_PERFORMANCE_WRITE_REQUESTS))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, DCPMM_PERFORMANCE_WRITE_REQUESTS, PERFORMANCE_DATA_FORMAT,
pDimmsPerformanceData[AllDimmsIndex].WriteRequests.Uint64_1,
pDimmsPerformanceData[AllDimmsIndex].WriteRequests.Uint64);
}
/** TotalMediaReads **/
if (AllOptionSet || (DisplayOptionSet && ContainsValue(pDisplayOptionValue, DCPMM_PERFORMANCE_TOTAL_MEDIA_READS))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, DCPMM_PERFORMANCE_TOTAL_MEDIA_READS, PERFORMANCE_DATA_FORMAT,
pDimmsPerformanceData[AllDimmsIndex].TotalMediaReads.Uint64_1,
pDimmsPerformanceData[AllDimmsIndex].TotalMediaReads.Uint64);
}
/** TotalMediaWrites **/
if (AllOptionSet || (DisplayOptionSet && ContainsValue(pDisplayOptionValue, DCPMM_PERFORMANCE_TOTAL_MEDIA_WRITES))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, DCPMM_PERFORMANCE_TOTAL_MEDIA_WRITES, PERFORMANCE_DATA_FORMAT,
pDimmsPerformanceData[AllDimmsIndex].TotalMediaWrites.Uint64_1,
pDimmsPerformanceData[AllDimmsIndex].TotalMediaWrites.Uint64);
}
/** TotalReadRequests **/
if (AllOptionSet || (DisplayOptionSet && ContainsValue(pDisplayOptionValue, DCPMM_PERFORMANCE_TOTAL_READ_REQUESTS))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, DCPMM_PERFORMANCE_TOTAL_READ_REQUESTS, PERFORMANCE_DATA_FORMAT,
pDimmsPerformanceData[AllDimmsIndex].TotalReadRequests.Uint64_1,
pDimmsPerformanceData[AllDimmsIndex].TotalReadRequests.Uint64);
}
/** TotalWriteRequests **/
if (AllOptionSet || (DisplayOptionSet && ContainsValue(pDisplayOptionValue, DCPMM_PERFORMANCE_TOTAL_WRITE_REQUESTS))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, DCPMM_PERFORMANCE_TOTAL_WRITE_REQUESTS, PERFORMANCE_DATA_FORMAT,
pDimmsPerformanceData[AllDimmsIndex].TotalWriteRequests.Uint64_1,
pDimmsPerformanceData[AllDimmsIndex].TotalWriteRequests.Uint64);
}
++DimmIndex;
}
FREE_POOL_SAFE(pPath);
}
/**
Execute the Show Performance command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
ShowPerformance(
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
UINT32 DimmCount;
DIMM_PERFORMANCE_DATA *pDimmsPerformanceData = NULL;
UINT32 DimmIdsNum = 0;
CHAR16 *pDimmsValue = NULL;
UINT32 DimmsCount = 0;
DIMM_INFO *pDimms = NULL;
UINT16 *pDimmIds = NULL;
// Print all unless some are specified
BOOLEAN AllOptionSet = TRUE;
BOOLEAN DisplayOptionSet = FALSE;
CHAR16 *pPerformanceValueStr = NULL;
UINT16 Index;
PRINT_CONTEXT *pPrinterCtx = NULL;
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("pCmd parameter is NULL.\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
// Make sure we can access the config protocol
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// Populate the list of DIMM_INFO structures with relevant information
ReturnCode = GetAllDimmList(pNvmDimmConfigProtocol, pCmd, DIMM_INFO_CATEGORY_NONE, &pDimms, &DimmsCount);
if (EFI_ERROR(ReturnCode)) {
if(ReturnCode == EFI_NOT_FOUND) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_INFO_NO_FUNCTIONAL_DIMMS);
}
goto Finish;
}
if (ContainTarget(pCmd, DIMM_TARGET)) {
pDimmsValue = GetTargetValue(pCmd, DIMM_TARGET);
ReturnCode = GetDimmIdsFromString(pCmd, pDimmsValue, pDimms, DimmsCount, &pDimmIds, &DimmIdsNum);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Target value is not a valid Dimm ID");
goto Finish;
}
if (!AllDimmsInListAreManageable(pDimms, DimmsCount, pDimmIds, DimmIdsNum)) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_UNMANAGEABLE_DIMM);
goto Finish;
}
}
// So, instead of parsing the -d parameter with CheckAllAndDisplayOptions(),
// we're going to maintain the existing implementation for now of just taking
// a comma separated list after the performance parameter
// Get any specified parameters after "-performance"
// TODO: Decide what we want to do long term and move to Common.c
pPerformanceValueStr = GetTargetValue(pCmd, PERFORMANCE_TARGET);
// Check if any valid strings exist in the performance value string
// TODO: Add invalid value checking
for (Index = 0; Index < ALLOWED_DISP_VALUES_COUNT(mppAllowedShowPerformanceDisplayValues); Index++) {
if (ContainsValue(pPerformanceValueStr, mppAllowedShowPerformanceDisplayValues[Index])) {
AllOptionSet = FALSE;
DisplayOptionSet = TRUE;
break; // If we find a match, leave the loop
}
}
// Get the performance data
ReturnCode = pNvmDimmConfigProtocol->GetDimmsPerformanceData(pNvmDimmConfigProtocol,
&DimmCount, &pDimmsPerformanceData);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// Print the data out
PrintPerformanceData(pPrinterCtx, pDimmIds, DimmIdsNum, pDimms, DimmCount, pDimmsPerformanceData,
AllOptionSet, DisplayOptionSet, pPerformanceValueStr);
//Specify table attributes
PRINTER_CONFIGURE_DATA_ATTRIBUTES(pPrinterCtx, DS_ROOT_PATH, &ShowPerformanceDataSetAttribs);
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FREE_POOL_SAFE(pDimmIds);
FREE_POOL_SAFE(pDimmsPerformanceData);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/*
* Register the show dimms command
*/
EFI_STATUS
RegisterShowPerformanceCommand(
)
{
EFI_STATUS Rc = EFI_SUCCESS;
NVDIMM_ENTRY();
Rc = RegisterCommand(&ShowPerformanceCommand);
NVDIMM_EXIT_I64(Rc);
return Rc;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowPerformanceCommand.h 0000664 0000000 0000000 00000001153 14165347476 0022500 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SHOW_PERFORMANCE_COMMAND_H_
#define _SHOW_PERFORMANCE_COMMAND_H_
#include
/**
Execute the Show Performance command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
ShowPerformance(
IN struct Command *pCmd
);
/*
* Register the show dimms command
*/
EFI_STATUS
RegisterShowPerformanceCommand(
);
#endif //_SHOW_PERFORMANCE_COMMAND_H_
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowPreferencesCommand.c 0000664 0000000 0000000 00000013356 14165347476 0022503 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include
#include "Debug.h"
#include "Types.h"
#include "Utility.h"
#include "NvmInterface.h"
#include "CommandParser.h"
#include "ShowPreferencesCommand.h"
#include "Common.h"
#include "Convert.h"
#include
#ifdef OS_BUILD
#include
#endif
#define DS_ROOT_PATH L"/Preferences"
/**
Command syntax definition
**/
struct Command ShowPreferencesCommand =
{
SHOW_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"", HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
#ifdef OS_BUILD
{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP, HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#else
{L"", L"", L"", L"",L"", FALSE, ValueOptional}
#endif
},
{ //!< targets
{PREFERENCES_TARGET, L"", L"", TRUE, ValueEmpty},
},
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Show user preferences.", //!< help
ShowPreferences,
TRUE
};
/**
Execute the Show Preferences command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
@retval EFI_DEVICE_ERROR Communications failure with driver
@retval EFI_NOT_FOUND Cli display preferences could not be retrieved successfully
**/
EFI_STATUS
ShowPreferences(
IN struct Command *pCmd
)
{
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
COMMAND_STATUS *pCommandStatus = NULL;
EFI_STATUS ReturnCode = EFI_SUCCESS;
DRIVER_PREFERENCES DriverPreferences;
DISPLAY_PREFERENCES DisplayPreferences;
CONST CHAR16 *pImcInterleaving = NULL;
CONST CHAR16 *pChannelInterleaving = NULL;
#ifdef OS_BUILD
CHAR16 tempStr[PROPERTY_VALUE_LEN];
UINTN TempStrLen = PROPERTY_VALUE_LEN;
#endif
PRINT_CONTEXT *pPrinterCtx = NULL;
CHAR16 *pPath = NULL;
NVDIMM_ENTRY();
ZeroMem(&DriverPreferences, sizeof(DriverPreferences));
ZeroMem(&DisplayPreferences, sizeof(DisplayPreferences));
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("pCmd parameter is NULL.\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
}
/** Need NvmDimmConfigProtocol **/
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
ReturnCode = pNvmDimmConfigProtocol->GetDriverPreferences(pNvmDimmConfigProtocol, &DriverPreferences, pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
PRINTER_SET_COMMAND_STATUS(pCmd->pPrintCtx, ReturnCode, L"Show preferences", L" on", pCommandStatus);
goto Finish;
}
ReturnCode = ReadRunTimePreferences(&DisplayPreferences, DISPLAY_CLI_INFO);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_DISPLAY_PREFERENCES_RETRIEVE);
goto Finish;
}
PRINTER_BUILD_KEY_PATH(pPath, DS_ROOT_PATH);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, CLI_DEFAULT_DIMM_ID_PROPERTY, GetDimmIDStr(DisplayPreferences.DimmIdentifier));
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, CLI_DEFAULT_SIZE_PROPERTY, GetDisplaySizeStr(DisplayPreferences.SizeUnit));
if (DriverPreferences.ImcInterleaving == DEFAULT_IMC_INTERLEAVE_SIZE &&
DriverPreferences.ChannelInterleaving == DEFAULT_CHANNEL_INTERLEAVE_SIZE)
{
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, APP_DIRECT_SETTINGS_PROPERTY, PROPERTY_VALUE_RECOMMENDED);
} else {
pChannelInterleaving = ParseChannelInterleavingValue(DriverPreferences.ChannelInterleaving);
pImcInterleaving = ParseImcInterleavingValue(DriverPreferences.ImcInterleaving);
if (pChannelInterleaving == NULL || pImcInterleaving == NULL) {
ReturnCode = EFI_DEVICE_ERROR;
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
} else {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, APP_DIRECT_SETTINGS_PROPERTY, FORMAT_STR L"_" FORMAT_STR_NL, pImcInterleaving, pChannelInterleaving);
}
}
#ifdef OS_BUILD
ReturnCode = GET_VARIABLE_STR(DBG_LOG_LEVEL, gNvmDimmConfigProtocolGuid, &TempStrLen, tempStr);
if (!EFI_ERROR(ReturnCode)) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DBG_LOG_LEVEL, tempStr);
}
#endif
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FREE_POOL_SAFE(pPath);
FreeCommandStatus(&pCommandStatus);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Register the Show Preferences command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowPreferencesCommand(
)
{
EFI_STATUS ReturnCode;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&ShowPreferencesCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowPreferencesCommand.h 0000664 0000000 0000000 00000001433 14165347476 0022501 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SHOW_PREFERENCES_COMMAND_
#define _SHOW_PREFERENCES_COMMAND_
#include
#include "CommandParser.h"
/**
Register the Show Preferences command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowPreferencesCommand();
/**
Execute the Show Preferences command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
ShowPreferences(
IN struct Command *pCmd
);
#endif /** _SHOW_PREFERENCES_COMMAND_ **/
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowRegionsCommand.c 0000664 0000000 0000000 00000051226 14165347476 0021646 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include "ShowRegionsCommand.h"
#include
#include
#include
#include
#include
#include "Common.h"
#include "NvmDimmCli.h"
#include
#ifdef OS_BUILD
#include "BaseMemoryLib.h"
#else
#include
#endif
#define DS_ROOT_PATH L"/RegionList"
#define DS_REGION_PATH L"/RegionList/Region"
#define DS_DIMM_INDEX_PATH L"/RegionList/Region[%d]"
#ifdef OS_BUILD
/*
* PRINT LIST ATTRIBUTES
* ---ISetID=0xce8049e0a393f6ea---
* SocketID=0x00000000
* PersistentMemoryType=AppDirect
* Capacity=750.0 GiB
* FreeCapacity=750.0 GiB
* HealthState=Locked
* DimmID=0x0001, 0x0011, 0x0021, 0x0101, 0x0111, 0x0121
* ...
*/
PRINTER_LIST_ATTRIB ShowRegionListAttributes =
{
{
{
REGION_NODE_STR, //GROUP LEVEL TYPE
L"---" ISET_ID_STR L"=$(" ISET_ID_STR L")---", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT L"%ls=%ls", //NULL or KEY VAL FORMAT STR
ISET_ID_STR L";" REGION_ID_STR //NULL or IGNORE KEY LIST (K1;K2)
}
}
};
#else
/*
* PRINT LIST ATTRIBUTES
* ---IRegionID=0x0001---
* SocketID=0x00000000
* PersistentMemoryType=AppDirect
* Capacity=750.0 GiB
* FreeCapacity=750.0 GiB
* HealthState=Locked
* DimmID=0x0001, 0x0011, 0x0021, 0x0101, 0x0111, 0x0121
* ISetID=0xce8049e0a393f6ea
* ...
*/
PRINTER_LIST_ATTRIB ShowRegionListAttributes =
{
{
{
REGION_NODE_STR, //GROUP LEVEL TYPE
L"---" REGION_ID_STR L"=$(" REGION_ID_STR L")---", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT L"%ls=%ls", //NULL or KEY VAL FORMAT STR
REGION_ID_STR //NULL or IGNORE KEY LIST (K1;K2)
}
}
};
#endif
#ifdef OS_BUILD
/*
* PRINTER TABLE ATTRIBUTES (6 columns)
* SocketID | ISetID | PMEM Type | Capacity | Free Capacity | HealthState
* ======================================================================
* 0x0001 | X | X | X | X | X
* ...
*/
PRINTER_TABLE_ATTRIB ShowRegionTableAttributes =
{
{
{
SOCKET_ID_STR, //COLUMN HEADER
SOCKET_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_REGION_PATH PATH_KEY_DELIM SOCKET_ID_STR //COLUMN DATA PATH
},
#ifdef OS_BUILD
{
ISET_ID_STR, //COLUMN HEADER
ISET_ID_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_REGION_PATH PATH_KEY_DELIM ISET_ID_STR //COLUMN DATA PATH
},
#else
{
REGION_ID_STR, //COLUMN HEADER
REGION_ID_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_REGION_PATH PATH_KEY_DELIM REGION_ID_STR //COLUMN DATA PATH
},
#endif
{
PERSISTENT_MEM_TYPE_STR, //COLUMN HEADER
PMEM_TYPE_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_REGION_PATH PATH_KEY_DELIM PERSISTENT_MEM_TYPE_STR //COLUMN DATA PATH
},
{
TOTAL_CAPACITY_STR, //COLUMN HEADER
CAPACITY_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_REGION_PATH PATH_KEY_DELIM TOTAL_CAPACITY_STR //COLUMN DATA PATH
},
{
FREE_CAPACITY_STR, //COLUMN HEADER
FREE_CAPACITY_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_REGION_PATH PATH_KEY_DELIM FREE_CAPACITY_STR //COLUMN DATA PATH
},
{
REGION_HEALTH_STATE_STR, //COLUMN HEADER
HEALTH_SHORT_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_REGION_PATH PATH_KEY_DELIM REGION_HEALTH_STATE_STR //COLUMN DATA PATH
}
}
};
#else
/*
* PRINTER TABLE ATTRIBUTES ( columns)
* RegionID | SocketID | PMEM Type | Capacity | Free Capacity | HealthState
* =================================================================================
* 0x0001 | 0x0001 | X | X | X | X
* ...
*/
PRINTER_TABLE_ATTRIB ShowRegionTableAttributes =
{
{
{
REGION_ID_STR, //COLUMN HEADER
REGION_ID_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_REGION_PATH PATH_KEY_DELIM REGION_ID_STR //COLUMN DATA PATH
},
{
SOCKET_ID_STR, //COLUMN HEADER
SOCKET_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_REGION_PATH PATH_KEY_DELIM SOCKET_ID_STR //COLUMN DATA PATH
},
{
PERSISTENT_MEM_TYPE_STR, //COLUMN HEADER
PMEM_TYPE_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_REGION_PATH PATH_KEY_DELIM PERSISTENT_MEM_TYPE_STR //COLUMN DATA PATH
},
{
TOTAL_CAPACITY_STR, //COLUMN HEADER
CAPACITY_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_REGION_PATH PATH_KEY_DELIM TOTAL_CAPACITY_STR //COLUMN DATA PATH
},
{
FREE_CAPACITY_STR, //COLUMN HEADER
FREE_CAPACITY_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_REGION_PATH PATH_KEY_DELIM FREE_CAPACITY_STR //COLUMN DATA PATH
},
{
REGION_HEALTH_STATE_STR, //COLUMN HEADER
HEALTH_SHORT_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_REGION_PATH PATH_KEY_DELIM REGION_HEALTH_STATE_STR //COLUMN DATA PATH
}
}
};
#endif
PRINTER_DATA_SET_ATTRIBS ShowRegionsDataSetAttribs =
{
&ShowRegionListAttributes,
&ShowRegionTableAttributes
};
/**
Command syntax definition
**/
struct Command ShowRegionsCommand =
{
SHOW_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"", HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", NFIT_OPTION, L"", L"",HELP_NFIT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", LARGE_PAYLOAD_OPTION, L"", L"", HELP_LPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", SMALL_PAYLOAD_OPTION, L"", L"", HELP_SPAYLOAD_DETAILS_TEXT, FALSE, ValueEmpty},
{ALL_OPTION_SHORT, ALL_OPTION, L"", L"",HELP_ALL_DETAILS_TEXT, FALSE, ValueEmpty},
{DISPLAY_OPTION_SHORT, DISPLAY_OPTION, L"", HELP_TEXT_ATTRIBUTES, HELP_DISPLAY_DETAILS_TEXT, FALSE, ValueRequired},
{UNITS_OPTION_SHORT, UNITS_OPTION, L"", UNITS_OPTION_HELP, HELP_UNIT_DETAILS_TEXT, FALSE, ValueRequired}
#ifdef OS_BUILD
,{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP, HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#endif // OS_BUILD
},
{ //!< targets
#ifdef OS_BUILD
{REGION_TARGET, L"", L"", TRUE, ValueEmpty},
#endif
#ifndef OS_BUILD
{REGION_TARGET, L"", HELP_TEXT_REGION_IDS, TRUE, ValueOptional},
#endif
{ SOCKET_TARGET, L"", HELP_TEXT_SOCKET_IDS, FALSE, ValueOptional },
},
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Show information about one or more regions.", //!< help
ShowRegions, //!< run function
TRUE, //!< enable print control support
};
CHAR16 *mppAllowedShowRegionsDisplayValues[] =
{
REGION_ID_STR,
PERSISTENT_MEM_TYPE_STR,
TOTAL_CAPACITY_STR,
FREE_CAPACITY_STR,
SOCKET_ID_STR,
REGION_HEALTH_STATE_STR,
DIMM_ID_STR,
ISET_ID_STR,
};
/**
Register the show regions command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowRegionsCommand(
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&ShowRegionsCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Convert the health state to a health string
@param[in] Health - Region Health State
@retval Const Pointer to Region Health State string
**/
STATIC
CONST CHAR16 *
RegionHealthToString(
IN UINT16 Health
)
{
switch (Health) {
case RegionHealthStateNormal:
return HEALTHY_STATE;
case RegionHealthStateError:
return ERROR_STATE;
case RegionHealthStatePending:
return PENDING_STATE;
case RegionHealthStateLocked:
return LOCKED_STATE;
case RegionHealthStateUnknown:
default:
return UNKNOWN_STATE;
}
}
/**
Execute the show regions command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_ABORTED invoking CONFIG_PROTOCOL function failure
@retval EFI_NO_RESPONSE FW busy for one or more dimms
**/
EFI_STATUS
ShowRegions(
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
UINT32 RegionCount = 0;
REGION_INFO *pRegions = NULL;
UINT16 *pRegionsIds = NULL;
UINT32 RegionIdsNum = 0;
UINT16 *pSocketIds = NULL;
UINT32 SocketsNum = 0;
CHAR16 *pSocketsValue = NULL;
CHAR16 *pRegionsValue = NULL;
BOOLEAN AllOptionSet = FALSE;
UINT32 RegionIndex = 0;
BOOLEAN Found = FALSE;
CHAR16 *pRegionTempStr = NULL;
INTERLEAVE_FORMAT *pInterleaveFormat = NULL;
UINT16 UnitsOption = DISPLAY_SIZE_UNIT_UNKNOWN;
UINT16 UnitsToDisplay = FixedPcdGet16(PcdDcpmmCliDefaultCapacityUnit);
CHAR16 *pCapacityStr = NULL;
CONST CHAR16 *pHealthStateStr = NULL;
DISPLAY_PREFERENCES DisplayPreferences;
COMMAND_STATUS *pCommandStatus = NULL;
UINT32 AppDirectRegionCount = 0;
CMD_DISPLAY_OPTIONS *pDispOptions = NULL;
CHAR16 *pDimmIds = NULL;
CHAR16 *pNfitOption = NULL;
BOOLEAN UseNfit = FALSE;
PRINT_CONTEXT *pPrinterCtx = NULL;
CHAR16 *pPath = NULL;
NVDIMM_ENTRY();
ReturnCode = EFI_SUCCESS;
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("pCmd parameter is NULL.\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
pDispOptions = AllocateZeroPool(sizeof(CMD_DISPLAY_OPTIONS));
if (NULL == pDispOptions) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
ReturnCode = CheckAllAndDisplayOptions(pCmd, mppAllowedShowRegionsDisplayValues,
ALLOWED_DISP_VALUES_COUNT(mppAllowedShowRegionsDisplayValues), pDispOptions);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("CheckAllAndDisplayOptions has returned error. Code " FORMAT_EFI_STATUS "\n", ReturnCode);
goto Finish;
}
AllOptionSet = (!pDispOptions->AllOptionSet && !pDispOptions->DisplayOptionSet) || pDispOptions->AllOptionSet;
#ifdef OS_BUILD
ZeroMem(&DisplayPreferences, sizeof(DisplayPreferences));
#endif
/** initialize status structure **/
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
NVDIMM_DBG("Failed on InitializeCommandStatus");
goto Finish;
}
/**
Make sure we can access the config protocol
**/
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
ReturnCode = EFI_NOT_FOUND;
goto Finish;
}
/**
If sockets were specified
**/
if (ContainTarget(pCmd, SOCKET_TARGET)) {
pSocketsValue = GetTargetValue(pCmd, SOCKET_TARGET);
ReturnCode = GetUintsFromString(pSocketsValue, &pSocketIds, &SocketsNum);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_TARGET_SOCKET);
goto Finish;
}
}
/**
if Region IDs were passed in, read them
**/
if (NULL != pCmd->targets[0].pTargetValueStr && StrLen(pCmd->targets[0].pTargetValueStr) > 0) {
pRegionsValue = GetTargetValue(pCmd, REGION_TARGET);
ReturnCode = GetUintsFromString(pRegionsValue, &pRegionsIds, &RegionIdsNum);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_TARGET_REGION);
goto Finish;
}
}
ReturnCode = ReadRunTimePreferences(&DisplayPreferences, DISPLAY_CLI_INFO);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_DISPLAY_PREFERENCES_RETRIEVE);
goto Finish;
}
UnitsToDisplay = DisplayPreferences.SizeUnit;
ReturnCode = GetUnitsOption(pCmd, &UnitsOption);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
/** Any valid units option will override the preferences **/
if (UnitsOption != DISPLAY_SIZE_UNIT_UNKNOWN) {
UnitsToDisplay = UnitsOption;
}
/** Check if nfit option is set **/
pNfitOption = getOptionValue(pCmd, NFIT_OPTION);
if (pNfitOption) {
UseNfit = TRUE;
}
ReturnCode = pNvmDimmConfigProtocol->GetRegionCount(pNvmDimmConfigProtocol, UseNfit, &RegionCount);
if (EFI_ERROR(ReturnCode)) {
if (EFI_NO_RESPONSE == ReturnCode) {
ResetCmdStatus(pCommandStatus, NVM_ERR_BUSY_DEVICE);
}
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
PRINTER_SET_COMMAND_STATUS(pPrinterCtx, ReturnCode, L"Show region", L" on", pCommandStatus);
goto Finish;
}
if (0 == RegionCount) {
ReturnCode = EFI_SUCCESS;
//WA, to ensure ESX prints a message when no entries are found.
if (PRINTER_ESX_FORMAT_ENABLED(pPrinterCtx)) {
PRINTER_SET_MSG(pPrinterCtx, EFI_NOT_FOUND, CLI_INFO_NO_REGIONS);
}
else {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_INFO_NO_REGIONS);
}
goto Finish;
}
pRegions = AllocateZeroPool(sizeof(REGION_INFO) * RegionCount);
if (pRegions == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
ReturnCode = pNvmDimmConfigProtocol->GetRegions(pNvmDimmConfigProtocol, RegionCount, UseNfit, pRegions, pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
if (pCommandStatus->GeneralStatus != NVM_SUCCESS) {
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
PRINTER_SET_COMMAND_STATUS(pPrinterCtx, ReturnCode, CLI_INFO_SHOW_REGION, L"", pCommandStatus);
} else {
ReturnCode = EFI_ABORTED;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
}
NVDIMM_WARN("Failed to retrieve the REGION list");
goto Finish;
}
for (RegionIndex = 0; RegionIndex < RegionCount; RegionIndex++) {
if (((pRegions[RegionIndex].RegionType & PM_TYPE_AD) != 0) ||
((pRegions[RegionIndex].RegionType & PM_TYPE_AD_NI) != 0)) {
AppDirectRegionCount++;
}
}
if (AppDirectRegionCount == 0) {
ReturnCode = EFI_SUCCESS;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_INFO_NO_REGIONS);
goto Finish;
}
for (RegionIndex = 0; RegionIndex < RegionCount; RegionIndex++) {
/**
Skip if the RegionId is not matching.
**/
if (RegionIdsNum > 0 && !ContainUint(pRegionsIds, RegionIdsNum, pRegions[RegionIndex].RegionId)) {
continue;
}
/**
Skip if the socket is not matching.
**/
if (SocketsNum > 0 && !ContainUint(pSocketIds, SocketsNum, pRegions[RegionIndex].SocketId)) {
continue;
}
PRINTER_BUILD_KEY_PATH(pPath, DS_DIMM_INDEX_PATH, RegionIndex);
Found = TRUE;
/**
SocketId
**/
if (AllOptionSet ||
(pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SOCKET_ID_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, SOCKET_ID_STR, FORMAT_HEX, pRegions[RegionIndex].SocketId);
}
/**
Display all the persistent memory types supported by the region.
**/
if (AllOptionSet ||
(pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, PERSISTENT_MEM_TYPE_STR))) {
pRegionTempStr = RegionTypeToString(pRegions[RegionIndex].RegionType);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, PERSISTENT_MEM_TYPE_STR, pRegionTempStr);
FREE_POOL_SAFE(pRegionTempStr);
}
/**
Capacity
**/
if (AllOptionSet ||
(pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, TOTAL_CAPACITY_STR))) {
ReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, pRegions[RegionIndex].Capacity, UnitsToDisplay, TRUE, &pCapacityStr);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_CAPACITY_STRING);
goto Finish;
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, TOTAL_CAPACITY_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
}
/**
FreeCapacity
**/
if (AllOptionSet ||
(pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, FREE_CAPACITY_STR))) {
ReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, pRegions[RegionIndex].FreeCapacity, UnitsToDisplay, TRUE, &pCapacityStr);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_CAPACITY_STRING);
goto Finish;
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, FREE_CAPACITY_STR, pCapacityStr);
FREE_POOL_SAFE(pCapacityStr);
}
/**
HealthState
**/
if (AllOptionSet ||
(pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, REGION_HEALTH_STATE_STR))) {
pHealthStateStr = RegionHealthToString(pRegions[RegionIndex].Health);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, REGION_HEALTH_STATE_STR, pHealthStateStr);
}
/**
Dimms
**/
if (AllOptionSet ||
(pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, DIMM_ID_STR))) {
ReturnCode = ConvertRegionDimmIdsToDimmListStr(&pRegions[RegionIndex], pNvmDimmConfigProtocol, DisplayPreferences.DimmIdentifier, &pDimmIds);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DIMM_ID_STR, pDimmIds);
FREE_POOL_SAFE(pDimmIds);
}
/**
RegionID
**/
#ifdef OS_BUILD
if (AllOptionSet ||
(pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, REGION_ID_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, REGION_ID_STR, FORMAT_HEX, pRegions[RegionIndex].RegionId);
}
#else
/** Always include for non OS builds **/
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, REGION_ID_STR, FORMAT_HEX, pRegions[RegionIndex].RegionId);
#endif
/**
ISetID
**/
#ifdef OS_BUILD
/** Always include for OS builds **/
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, ISET_ID_STR, FORMAT_SHOW_ISET_ID, pRegions[RegionIndex].CookieId);
#else
if (AllOptionSet ||
(pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, ISET_ID_STR))) {
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, ISET_ID_STR, FORMAT_SHOW_ISET_ID, pRegions[RegionIndex].CookieId);
}
#endif
}
if (RegionIdsNum > 0 && !Found) {
CHAR16 *ErrMsg = NULL;
ReturnCode = EFI_NOT_FOUND;
ErrMsg = CatSPrint(NULL, FORMAT_STR_SPACE FORMAT_STR_NL, CLI_ERR_INVALID_REGION_ID, pCmd->targets[0].pTargetValueStr);
if (SocketsNum > 0) {
ErrMsg = CatSPrintClean(ErrMsg, CLI_ERR_REGION_TO_SOCKET_MAPPING);
}
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, FORMAT_STR, ErrMsg);
FREE_POOL_SAFE(ErrMsg);
goto Finish;
}
//Specify table attributes
PRINTER_CONFIGURE_DATA_ATTRIBUTES(pPrinterCtx, DS_ROOT_PATH, &ShowRegionsDataSetAttribs);
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
if (pRegions != NULL) {
for (RegionIndex = 0; RegionIndex < RegionCount; RegionIndex++) {
pInterleaveFormat = (INTERLEAVE_FORMAT *) pRegions[RegionIndex].PtrInterleaveFormats;
FREE_POOL_SAFE(pInterleaveFormat);
}
}
FREE_CMD_DISPLAY_OPTIONS_SAFE(pDispOptions);
FREE_POOL_SAFE(pPath);
FREE_POOL_SAFE(pRegions);
FREE_POOL_SAFE(pRegionsIds);
FREE_POOL_SAFE(pSocketIds);
FREE_POOL_SAFE(pNfitOption);
FreeCommandStatus(&pCommandStatus);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowRegionsCommand.h 0000664 0000000 0000000 00000002703 14165347476 0021647 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SHOW_REGIONS_COMMAND_H_
#define _SHOW_REGIONS_COMMAND_H_
#include "CommandParser.h"
#define REGION_ID_STR L"RegionID"
#define ISET_ID_STR L"ISetID"
#define PERSISTENT_MEM_TYPE_STR L"PersistentMemoryType"
#define TOTAL_CAPACITY_STR L"Capacity"
#define FREE_CAPACITY_STR L"FreeCapacity"
#define REGION_HEALTH_STATE_STR L"HealthState"
/** Region Health States */
#define HEALTHY_STATE L"Healthy"
#define ERROR_STATE L"Error"
#define PENDING_STATE L"Pending"
#define LOCKED_STATE L"Locked"
#define UNKNOWN_STATE L"Unknown"
#define DIMM_ID_STR_DELIM L", "
/**
Register the show regions command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowRegionsCommand(
);
/**
Execute the show regions command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS on success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_ABORTED invoking CONFIG_PROTOCOL function failure
**/
EFI_STATUS
ShowRegions(
IN struct Command *pCmd
);
#endif /* _SHOW_REGIONS_COMMAND_H_ */
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowRegisterCommand.c 0000664 0000000 0000000 00000032613 14165347476 0022023 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include "ShowRegisterCommand.h"
#include
#include
#include
#include
#include
#include
#include "Common.h"
#define DIMM_ID_STR L"DimmID"
#define REGISTER_TARGET_STR L"RegType"
#define DS_ROOT_PATH L"/RegList"
#define DS_DIMM_PATH L"/RegList/Dimm"
#define DS_DIMM_INDEX_PATH L"/RegList/Dimm[%d]"
#define DS_REGISTER_PATH L"/RegList/Dimm/Register"
#define DS_REGISTER_INDEX_PATH L"/RegList/Dimm[%d]/Register[%d]"
/*
* PRINT LIST ATTRIBUTES
* ---DimmID=0x0011 Registers---
* ---RegType=BSR
* Boot Status: 00000000181D00F0
* [07:00] MajorCheckpoint ------: 0xF0
* [15:08] MinorCheckpoint ------: 0x0
* ...
*/
PRINTER_LIST_ATTRIB ShowRegisterListAttributes =
{
{
{
DIMM_NODE_STR, //GROUP LEVEL TYPE
L"---" DIMM_ID_STR L"=$(" DIMM_ID_STR L") Registers---", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT FORMAT_STR L"=" FORMAT_STR, //NULL or KEY VAL FORMAT STR
DIMM_ID_STR //NULL or IGNORE KEY LIST (K1;K2)
},
{
REGISTER_MODE_STR, //GROUP LEVEL TYPE
SHOW_LIST_IDENT L"---" REGISTER_TARGET_STR L"=$(" REGISTER_TARGET_STR L")", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT SHOW_LIST_IDENT FORMAT_STR L": " FORMAT_STR, //NULL or KEY VAL FORMAT STR
REGISTER_TARGET_STR //NULL or IGNORE KEY LIST (K1;K2)
}
}
};
PRINTER_DATA_SET_ATTRIBS ShowRegisterDataSetAttribs =
{
&ShowRegisterListAttributes,
NULL
};
/**
Command syntax definition
**/
struct Command ShowRegisterCommand =
{
SHOW_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"",HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
#ifdef OS_BUILD
{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP, HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#else
{L"", L"", L"", L"",L"", FALSE, ValueOptional}
#endif
},
{ //!< targets
{DIMM_TARGET, L"", L"DimmIDs", TRUE, ValueOptional},
{REGISTER_TARGET, L"", L"Register", TRUE, ValueOptional},
},
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Show Key " PMEM_MODULE_STR L" Registers.", //!< help
ShowRegister,
TRUE //!< enable print control support
};
CHAR16 *mppAllowedShowDimmRegistersValues[] = {
REGISTER_BSR_STR,
REGISTER_OS_STR
};
/**
Register the show register command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowRegisterCommand(
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&ShowRegisterCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Execute the show pools command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_ABORTED Failure invoking CONFIG_PROTOCOL function
**/
EFI_STATUS
ShowRegister(
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
UINT16 *pDimmIds = NULL;
UINT32 DimmIdsNum = 0;
CHAR16 *pRegisterValues = NULL;
CHAR16 *pDimmValues = NULL;
UINT32 Index = 0;
COMMAND_STATUS *pCommandStatus = NULL;
BOOLEAN ShowAllRegisters = FALSE;
DIMM_BSR Bsr;
UINT32 DimmCount = 0;
DIMM_INFO *pDimms = NULL;
CHAR16 DimmStr[MAX_DIMM_UID_LENGTH];
PRINT_CONTEXT *pPrinterCtx = NULL;
CHAR16 *pPath = NULL;
UINT32 DimmIndex = 0;
UINT32 RegIndex = 0;
NVDIMM_ENTRY();
ZeroMem(DimmStr, sizeof(DimmStr));
Bsr.AsUint64 = 0;
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
/** Make sure we can access the config protocol **/
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
ReturnCode = EFI_NOT_FOUND;
goto Finish;
}
// Populate the list of DIMM_INFO structures with relevant information
ReturnCode = GetDimmList(pNvmDimmConfigProtocol, pCmd, DIMM_INFO_CATEGORY_NONE, &pDimms, &DimmCount);
if (EFI_ERROR(ReturnCode)) {
if(ReturnCode == EFI_NOT_FOUND) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_INFO_NO_FUNCTIONAL_DIMMS);
}
goto Finish;
}
/** if a specific DIMM pid was passed in, set it **/
pDimmValues = GetTargetValue(pCmd, DIMM_TARGET);
if (pDimmValues != NULL) {
if (StrLen(pDimmValues) > 0) {
ReturnCode = GetDimmIdsFromString(pCmd, pDimmValues, pDimms, DimmCount, &pDimmIds, &DimmIdsNum);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Target value is not a valid DIMM ID");
goto Finish;
}
} else {
DimmIdsNum = 0;
}
} else {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_WARN("Missing Dimm target");
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_INCOMPLETE_SYNTAX);
goto Finish;
}
if (ContainTarget(pCmd, REGISTER_TARGET)) {
pRegisterValues = GetTargetValue(pCmd, REGISTER_TARGET);
if (StrLen(pRegisterValues) == 0) {
ShowAllRegisters = TRUE;
} else {
ShowAllRegisters = FALSE;
}
} else {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_INCOMPLETE_SYNTAX);
goto Finish;
}
CHECK_RESULT(InitializeCommandStatus(&pCommandStatus), Finish);
/** check that the register parameters are correct if provided**/
if (!ShowAllRegisters) {
ReturnCode = CheckDisplayList(pRegisterValues, mppAllowedShowDimmRegistersValues,
ALLOWED_DISP_VALUES_COUNT(mppAllowedShowDimmRegistersValues));
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_TARGET_REGISTER);
goto Finish;
}
}
/** Get and print registers for each requested dimm **/
for (Index = 0; Index < DimmCount; Index++) {
if (DimmIdsNum > 0 && !ContainUint(pDimmIds, DimmIdsNum, pDimms[Index].DimmID)) {
NVDIMM_WARN("Dimm 0x%x not found", pDimms[Index].DimmHandle);
continue;
}
ReturnCode = pNvmDimmConfigProtocol->RetrieveDimmRegisters(pNvmDimmConfigProtocol,
pDimms[Index].DimmID, &Bsr.AsUint64, NULL, pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_WARN("Failed to retrieve Dimm Registers");
goto Finish;
}
ReturnCode = GetPreferredDimmIdAsString(pDimms[Index].DimmHandle, pDimms[Index].DimmUid,
DimmStr, MAX_DIMM_UID_LENGTH);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
PRINTER_BUILD_KEY_PATH(pPath, DS_DIMM_INDEX_PATH, DimmIndex);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DIMM_ID_STR, DimmStr);
if (ContainsValue(pRegisterValues, REGISTER_BSR_STR) || ShowAllRegisters) {
PRINTER_BUILD_KEY_PATH(pPath, DS_REGISTER_INDEX_PATH, DimmIndex, RegIndex);
RegIndex++;
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, REGISTER_TARGET_STR, REGISTER_BSR_STR);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L"Boot Status", FORMAT_HEX_PREFIX FORMAT_UINT64_HEX, Bsr.AsUint64);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [07:00] MajorCheckpoint --------------------------", FORMAT_HEX_NOWIDTH, Bsr.Separated_Current_FIS.Major);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [15:08] MinorCheckpoint --------------------------", FORMAT_HEX_NOWIDTH, Bsr.Separated_Current_FIS.Minor);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [17:16] MR (Media Ready) -------------------------", FORMAT_HEX_NOWIDTH L" (00:notReady; 1:Ready; 2:Error; 3:Rsv)", Bsr.Separated_Current_FIS.MR);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [18:18] DT (DDRT IO Init Started) ----------------", FORMAT_HEX_NOWIDTH L" (0:notStarted; 1:Training Started)", Bsr.Separated_Current_FIS.DT);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [19:19] PCR (PCR access locked) ------------------", FORMAT_HEX_NOWIDTH L" (0:Unlocked; 1:Locked)", Bsr.Separated_Current_FIS.PCR);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [20:20] MBR (Mailbox Ready) ----------------------", FORMAT_HEX_NOWIDTH L" (0:notReady; 1:Ready)", Bsr.Separated_Current_FIS.MBR);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [21:21] WTS (Watchdog Status)---------------------", FORMAT_HEX_NOWIDTH L" (0:noChange; 1:WT NMI generated)", Bsr.Separated_Current_FIS.WTS);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [22:22] FRCF (First Fast Refresh Completed) ------", FORMAT_HEX_NOWIDTH L" (0:noChange; 1:1stRefreshCycleCompleted)", Bsr.Separated_Current_FIS.FRCF);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [23:23] CR (Credit Ready) ------------------------", FORMAT_HEX_NOWIDTH L" (0:WDB notFlushed; 1:WDB Flushed)", Bsr.Separated_Current_FIS.CR);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [24:24] MD (Media Disabled) ----------------------", FORMAT_HEX_NOWIDTH L" (0:User Data is accessible; 1:User Data is not accessible)", Bsr.Separated_Current_FIS.MD);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [25:25] SVNDE (SVN Downgrade Opt-In Enable) ------", FORMAT_HEX_NOWIDTH L" (0:Not Enabled; 1:Enabled)", Bsr.Separated_Current_FIS.SVNDE);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [26:26] SVNCOIS (SVN Downgrade Opt-In Was Enabled)", FORMAT_HEX_NOWIDTH L" (0:Never Enabled; 1:Has Been Enabled)", Bsr.Separated_Current_FIS.SVNCOIS);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [28:27] DR (DRAM Ready(AIT)) ---------------------", FORMAT_HEX_NOWIDTH L" (0:Not trained,Not Loaded; 1:Trained,Not Loaded; 2:Error; 3:Trained,Loaded(Ready))", Bsr.Separated_Current_FIS.DR);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [29:29] RR (Reboot Required) ---------------------", FORMAT_HEX_NOWIDTH L" (0:No reset is needed by the " PMEM_MODULE_STR L"; 1:The " PMEM_MODULES_STR L" internal state requires a platform power cycle)", Bsr.Separated_Current_FIS.RR);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [30:30] LFOPB ------------------------------------", FORMAT_HEX_NOWIDTH L" (0:No Error; 1:Fatal Link Error)", Bsr.Separated_Current_FIS.LFOPB);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [31:31] SVNWC ------------------------------------", FORMAT_HEX_NOWIDTH L" (0:The SVN Opt-In Window is open; 1:The SVN Opt-In Window is closed)", Bsr.Separated_Current_FIS.SVNWC);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [33:32] Rsvd -------------------------------------", FORMAT_HEX_NOWIDTH L" (Rsvd)", Bsr.Separated_Current_FIS.Rsvd);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [35:34] DTS --------------------------------------", FORMAT_HEX_NOWIDTH L" (00:Training Not Complete; 1:Training Complete; 2:Training Failure; 3:S3 Complete)", Bsr.Separated_Current_FIS.DTS);
if ((pDimms[DimmIndex].FwVer.FwApiMajor > 2) || (pDimms[DimmIndex].FwVer.FwApiMajor == 2 && pDimms[DimmIndex].FwVer.FwApiMinor >= 3)) { // Current FIS version
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [36:36] FAC --------------------------------------", FORMAT_HEX_NOWIDTH L" (0:FW Activate has not completed; 1:FW Activate has completed)\n", Bsr.Separated_Current_FIS.FAC);
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [63:37] Rsvd1 ------------------------------------", FORMAT_HEX_NOWIDTH L" (Rsvd1)\n", Bsr.Separated_Current_FIS.Rsvd1);
}
else { // FIS version 2.2 or earlier detected
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, L" [63:36] Rsvd1 ------------------------------------", FORMAT_HEX_NOWIDTH L" (Rsvd1)\n", Bsr.Separated_FIS_1_15.Rsvd1);
}
}
DimmIndex++;
}
ReturnCode = MatchCliReturnCode(pCommandStatus->GeneralStatus);
PRINTER_SET_COMMAND_STATUS(pPrinterCtx, ReturnCode, CLI_INFO_SHOW_REGISTER, L" on", pCommandStatus);
//Specify DataSet attributes
PRINTER_CONFIGURE_DATA_ATTRIBUTES(pPrinterCtx, DS_ROOT_PATH, &ShowRegisterDataSetAttribs);
//Force as list
PRINTER_ENABLE_LIST_TABLE_FORMAT(pPrinterCtx);
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FREE_POOL_SAFE(pPath);
FreeCommandStatus(&pCommandStatus);
FREE_POOL_SAFE(pDimms);
FREE_POOL_SAFE(pDimmIds);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowRegisterCommand.h 0000664 0000000 0000000 00000001537 14165347476 0022031 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SHOW_REGISTER_COMMAND_H_
#define _SHOW_REGISTER_COMMAND_H_
#include "CommandParser.h"
#define FW_MB_SMALL_OUTPUT_REG_USED 1
/**
Register the show register command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowRegisterCommand(
);
/**
Execute the show register command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS on success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_ABORTED invoking CONFIG_PROTOCOL function failure
**/
EFI_STATUS
ShowRegister(
IN struct Command *pCmd
);
#endif /* _SHOW_REGISTER_COMMAND_H_ */
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowSensorCommand.c 0000664 0000000 0000000 00000044541 14165347476 0021513 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "ShowSensorCommand.h"
#include
#include
#include
#include
#include "Common.h"
#include
#include "NvmDimmCli.h"
#include
#include
#include
#include
#define DIMM_ID_STR L"DimmID"
#define SENSOR_TYPE_STR L"Type"
#define CURRENT_VALUE_STR L"CurrentValue"
#define ALARM_THRESHOLD_STR L"AlarmThreshold"
#define THROTTLING_STOP_THRESHOLD_STR L"ThrottlingStopThreshold"
#define THROTTLING_START_THRESHOLD_STR L"ThrottlingStartThreshold"
#define SHUTDOWN_THRESHOLD_STR L"ShutdownThreshold"
#define MAX_TEMPERATURE L"MaxTemperature"
#define DISABLED_STR L"Disabled"
#define DS_ROOT_PATH L"/SensorList"
#define DS_DIMM_PATH L"/SensorList/Dimm"
#define DS_DIMM_INDEX_PATH L"/SensorList/Dimm[%d]"
#define DS_SENSOR_PATH L"/SensorList/Dimm/Sensor"
#define DS_SENSOR_INDEX_PATH L"/SensorList/Dimm[%d]/Sensor[%d]"
/*
* PRINT LIST ATTRIBUTES (2 levels: Dimm-->Sensor)
* ---DimmId=0x0001---
* ---Type=Health
* CurrentVal=Healthy
* CurrentState=Normal
* ...
*/
PRINTER_LIST_ATTRIB ShowSensorListAttributes =
{
{
{
DIMM_NODE_STR, //GROUP LEVEL TYPE
L"---" DIMM_ID_STR L"=$(" DIMM_ID_STR L")---", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT FORMAT_STR L"=" FORMAT_STR, //NULL or KEY VAL FORMAT STR
DIMM_ID_STR //NULL or IGNORE KEY LIST (K1;K2)
},
{
SENSOR_NODE_STR, //GROUP LEVEL TYPE
SHOW_LIST_IDENT L"---" SENSOR_TYPE_STR L"=$(" SENSOR_TYPE_STR L")", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT SHOW_LIST_IDENT FORMAT_STR L"=" FORMAT_STR, //NULL or KEY VAL FORMAT STR
SENSOR_TYPE_STR //NULL or IGNORE KEY LIST (K1;K2)
}
}
};
/*
* PRINTER TABLE ATTRIBUTES (4 columns)
* DimmID | Type | CurrentValue | CurrentState
* ===========================================
* 0x0001 | X | X | X
* ...
*/
PRINTER_TABLE_ATTRIB ShowSensorTableAttributes =
{
{
{
DIMM_ID_STR, //COLUMN HEADER
DIMM_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_DIMM_PATH PATH_KEY_DELIM DIMM_ID_STR //COLUMN DATA PATH
},
{
SENSOR_TYPE_STR, //COLUMN HEADER
SENSOR_TYPE_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_SENSOR_PATH PATH_KEY_DELIM SENSOR_TYPE_STR //COLUMN DATA PATH
},
{
CURRENT_VALUE_STR, //COLUMN HEADER
SENSOR_VALUE_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_SENSOR_PATH PATH_KEY_DELIM CURRENT_VALUE_STR //COLUMN DATA PATH
}
}
};
PRINTER_DATA_SET_ATTRIBS ShowSensorDataSetAttribs =
{
&ShowSensorListAttributes,
&ShowSensorTableAttributes
};
/** Command syntax definition **/
struct Command ShowSensorCommand =
{
SHOW_VERB, //!< verb
{ //!< options
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"",HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{ALL_OPTION_SHORT, ALL_OPTION, L"", L"", HELP_ALL_DETAILS_TEXT, FALSE, ValueEmpty},
{DISPLAY_OPTION_SHORT, DISPLAY_OPTION, L"", HELP_TEXT_ATTRIBUTES, HELP_DISPLAY_DETAILS_TEXT, FALSE, ValueRequired}
#ifdef OS_BUILD
,{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP, HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#endif
},
{
{SENSOR_TARGET, L"", HELP_TEXT_SENSORS, TRUE, ValueOptional},
{DIMM_TARGET, L"", HELP_TEXT_DIMM_IDS, FALSE, ValueOptional} //!< targets
},
{
{L"", L"", L"", FALSE, ValueOptional},
}, //!< properties
L"Show health statistics.", //!< help
ShowSensor,
TRUE, //!< enable print control support
};
CHAR16 *mppAllowedShowSensorDisplayValues[] =
{
DIMM_ID_STR,
SENSOR_TYPE_STR,
CURRENT_VALUE_STR,
ALARM_THRESHOLD_STR,
THROTTLING_STOP_THRESHOLD_STR,
THROTTLING_START_THRESHOLD_STR,
SHUTDOWN_THRESHOLD_STR,
ALARM_ENABLED_PROPERTY,
MAX_TEMPERATURE
};
/**
Create the string from value for a sensor.
param[in] Value is the value to be printed.
param[in] SensorType - type of sensor
**/
STATIC
CHAR16 *
GetSensorValue(
IN INT64 Value,
IN UINT8 SensorType
)
{
CHAR16 *pReturnBuffer = NULL;
pReturnBuffer = CatSPrintClean(pReturnBuffer, L"%lld" FORMAT_STR L"", Value, SensorValueMeasure(SensorType));
return pReturnBuffer;
}
/**
Execute the show sensor command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
ShowSensor(
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
UINT16 *pDimmIds = NULL;
UINT32 DimmIdsNum = 0;
CHAR16 *pDimmsValue = NULL;
UINT32 DimmsCount = 0;
DIMM_INFO *pDimms = NULL;
UINT32 DimmIndex = 0;
BOOLEAN Found = FALSE;
UINT32 SensorIndex = 0;
CHAR16 *pTempBuff = NULL;
UINT32 SensorToDisplay = SENSOR_TYPE_ALL;
COMMAND_STATUS *pCommandStatus = NULL;
DIMM_SENSOR DimmSensorsSet[SENSOR_TYPE_COUNT];
CHAR16 *pTargetValue = NULL;
DISPLAY_PREFERENCES DisplayPreferences;
CMD_DISPLAY_OPTIONS *pDispOptions = NULL;
PRINT_CONTEXT *pPrinterCtx = NULL;
CHAR16 *pPath = NULL;
BOOLEAN FIS_1_13 = FALSE;
struct {
CHAR16 *pSensorStr;
UINT32 Sensor;
} Sensors[] = {
{CONTROLLER_TEMPERATURE_STR, SENSOR_TYPE_CONTROLLER_TEMPERATURE},
{MEDIA_TEMPERATURE_STR, SENSOR_TYPE_MEDIA_TEMPERATURE},
{SPARE_CAPACITY_STR, SENSOR_TYPE_PERCENTAGE_REMAINING},
{POWER_CYCLES_STR, SENSOR_TYPE_POWER_CYCLES},
{POWER_ON_TIME_STR, SENSOR_TYPE_POWER_ON_TIME},
{LATCHED_DIRTY_SHUTDOWN_COUNT_STR, SENSOR_TYPE_LATCHED_DIRTY_SHUTDOWN_COUNT},
{UPTIME_STR, SENSOR_TYPE_UP_TIME},
{FW_ERROR_COUNT_STR, SENSOR_TYPE_FW_ERROR_COUNT},
{DIMM_HEALTH_STR, SENSOR_TYPE_DIMM_HEALTH},
{UNLATCHED_DIRTY_SHUTDOWN_COUNT_STR, SENSOR_TYPE_UNLATCHED_DIRTY_SHUTDOWN_COUNT},
};
UINT32 SensorsNum = ARRAY_SIZE(Sensors);
CHAR16 DimmStr[MAX_DIMM_UID_LENGTH];
NVDIMM_ENTRY();
ZeroMem(DimmSensorsSet, sizeof(DimmSensorsSet));
ZeroMem(DimmStr, sizeof(DimmStr));
ZeroMem(&DisplayPreferences, sizeof(DisplayPreferences));
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("pCmd parameter is NULL.\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
pDispOptions = AllocateZeroPool(sizeof(CMD_DISPLAY_OPTIONS));
if (NULL == pDispOptions) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
ReturnCode = CheckAllAndDisplayOptions(pCmd, mppAllowedShowSensorDisplayValues,
ALLOWED_DISP_VALUES_COUNT(mppAllowedShowSensorDisplayValues), pDispOptions);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("CheckAllAndDisplayOptions has returned error. Code " FORMAT_EFI_STATUS "\n", ReturnCode);
goto Finish;
}
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
// initialize status structure
ReturnCode = InitializeCommandStatus(&pCommandStatus);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"Failed on InitializeCommandStatus");
goto Finish;
}
// Populate the list of DIMM_INFO structures with relevant information
ReturnCode = GetAllDimmList(pNvmDimmConfigProtocol, pCmd, DIMM_INFO_CATEGORY_NONE, &pDimms, &DimmsCount);
if (EFI_ERROR(ReturnCode)) {
if (ReturnCode == EFI_NOT_FOUND) {
PRINTER_SET_MSG(pCmd->pPrintCtx, ReturnCode, CLI_INFO_NO_FUNCTIONAL_DIMMS);
}
goto Finish;
}
if (ContainTarget(pCmd, DIMM_TARGET)) {
pDimmsValue = GetTargetValue(pCmd, DIMM_TARGET);
ReturnCode = GetDimmIdsFromString(pCmd, pDimmsValue, pDimms, DimmsCount, &pDimmIds, &DimmIdsNum);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
}
/**
The user has provided a sensor. Try to match it to our list.
Return an error if the sensor name is invalid.
**/
pTargetValue = GetTargetValue(pCmd, SENSOR_TARGET);
if (pTargetValue != NULL && StrLen(pTargetValue) > 0) {
Found = FALSE;
for (DimmIndex = 0; DimmIndex < SensorsNum; DimmIndex++) {
if (StrICmp(pTargetValue, Sensors[DimmIndex].pSensorStr) == 0) {
SensorToDisplay = Sensors[DimmIndex].Sensor;
Found = TRUE;
break;
}
}
if (!Found) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"The provided sensor: " FORMAT_STR L" is not valid.\n", pTargetValue);
goto Finish;
}
}
for (DimmIndex = 0; DimmIndex < DimmsCount; DimmIndex++) {
if (DimmIdsNum > 0 && !ContainUint(pDimmIds, DimmIdsNum, pDimms[DimmIndex].DimmID)) {
continue;
}
ReturnCode = GetPreferredDimmIdAsString(pDimms[DimmIndex].DimmHandle, pDimms[DimmIndex].DimmUid,
DimmStr, MAX_DIMM_UID_LENGTH);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"Failed to translate " PMEM_MODULE_STR L" identifier to string\n");
goto Finish;
}
ReturnCode = GetSensorsInfo(pNvmDimmConfigProtocol, pDimms[DimmIndex].DimmID, DimmSensorsSet);
if (EFI_ERROR(ReturnCode)) {
/**
We do not return on error. Just inform the user and skip to the next PMem module or end.
**/
if (ReturnCode == EFI_NOT_READY) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"Failed to read the sensors or thresholds values from " PMEM_MODULE_STR L" " FORMAT_STR L" - " PMEM_MODULE_STR L" is unmanageable.\n",
DimmStr);
}
else {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, L"Failed to read the sensors or thresholds values from " PMEM_MODULE_STR L" " FORMAT_STR L". Code: " FORMAT_EFI_STATUS "\n",
DimmStr, ReturnCode);
}
continue;
}
PRINTER_BUILD_KEY_PATH(pPath, DS_DIMM_INDEX_PATH, DimmIndex);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, DIMM_ID_STR, DimmStr);
//Checking the FIS Version
if ((pDimms[DimmIndex].FwVer.FwApiMajor >= 2 )||(pDimms[DimmIndex].FwVer.FwApiMajor == 1 && pDimms[DimmIndex].FwVer.FwApiMinor >= 13)) {
FIS_1_13 = TRUE;
}
for (SensorIndex = 0; SensorIndex < SENSOR_TYPE_COUNT; SensorIndex++) {
if ((SensorToDisplay != SENSOR_TYPE_ALL
&& DimmSensorsSet[SensorIndex].Type != SensorToDisplay)) {
continue;
}
PRINTER_BUILD_KEY_PATH(pPath, DS_SENSOR_INDEX_PATH, DimmIndex, SensorIndex);
/**
Type
**/
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, SENSOR_TYPE_STR, SensorTypeToString(DimmSensorsSet[SensorIndex].Type));
/**
Value
**/
if (!pDispOptions->DisplayOptionSet || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, CURRENT_VALUE_STR))) {
/**
Only for Health State
**/
if (ContainsValue(SensorTypeToString(DimmSensorsSet[SensorIndex].Type), DIMM_HEALTH_STR)) {
pTempBuff = HealthToString(gNvmDimmCliHiiHandle, (UINT8)DimmSensorsSet[SensorIndex].Value);
if (pTempBuff == NULL) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
}
else {
pTempBuff = GetSensorValue(DimmSensorsSet[SensorIndex].Value, DimmSensorsSet[SensorIndex].Type);
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, CURRENT_VALUE_STR, pTempBuff);
FREE_POOL_SAFE(pTempBuff);
}
/**
AlarmThreshold
**/
if (pDispOptions->AllOptionSet || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, ALARM_THRESHOLD_STR))) {
switch (SensorIndex) {
case SENSOR_TYPE_MEDIA_TEMPERATURE:
case SENSOR_TYPE_CONTROLLER_TEMPERATURE:
case SENSOR_TYPE_PERCENTAGE_REMAINING:
// Only media, controller, and percentage possess alarm thresholds
pTempBuff = GetSensorValue(DimmSensorsSet[SensorIndex].AlarmThreshold, DimmSensorsSet[SensorIndex].Type);
break;
default:
pTempBuff = NULL;
break;
}
if (NULL != pTempBuff) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ALARM_THRESHOLD_STR, pTempBuff);
FREE_POOL_SAFE(pTempBuff);
}
}
/**
AlarmEnabled
**/
if (pDispOptions->AllOptionSet || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, ALARM_ENABLED_PROPERTY))) {
switch (SensorIndex) {
case SENSOR_TYPE_MEDIA_TEMPERATURE:
case SENSOR_TYPE_CONTROLLER_TEMPERATURE:
case SENSOR_TYPE_PERCENTAGE_REMAINING:
// Only media, controller, and percentage possess alarm thresholds
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, ALARM_ENABLED_PROPERTY, SensorEnabledStateToString(DimmSensorsSet[SensorIndex].Enabled));
break;
default:
//do nothing
break;
}
}
/**
ThrottlingStopThreshold
**/
if (pDispOptions->AllOptionSet || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, THROTTLING_STOP_THRESHOLD_STR))) {
switch (SensorIndex) {
case SENSOR_TYPE_CONTROLLER_TEMPERATURE:
case SENSOR_TYPE_MEDIA_TEMPERATURE:
// Only Media temperature sensor got lower critical threshold
pTempBuff = GetSensorValue(DimmSensorsSet[SensorIndex].ThrottlingStopThreshold, DimmSensorsSet[SensorIndex].Type);
break;
default:
pTempBuff = NULL;
break;
}
if (NULL != pTempBuff) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, THROTTLING_STOP_THRESHOLD_STR, pTempBuff);
FREE_POOL_SAFE(pTempBuff);
}
}
/**
ThrottlingStartThreshold
**/
if (pDispOptions->AllOptionSet || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, THROTTLING_START_THRESHOLD_STR))) {
switch (SensorIndex) {
case SENSOR_TYPE_CONTROLLER_TEMPERATURE:
case SENSOR_TYPE_MEDIA_TEMPERATURE:
// Only Media temperature sensor got upper critical threshold
pTempBuff = GetSensorValue(DimmSensorsSet[SensorIndex].ThrottlingStartThreshold, DimmSensorsSet[SensorIndex].Type);
break;
default:
pTempBuff = NULL;
break;
}
if (NULL != pTempBuff) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, THROTTLING_START_THRESHOLD_STR, pTempBuff);
FREE_POOL_SAFE(pTempBuff);
}
}
/**
ShutdownThreshold
**/
if (pDispOptions->AllOptionSet || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, SHUTDOWN_THRESHOLD_STR))) {
switch (SensorIndex) {
case SENSOR_TYPE_CONTROLLER_TEMPERATURE:
case SENSOR_TYPE_MEDIA_TEMPERATURE:
// Only Controller/Media temperature sensor got upper fatal threshold
pTempBuff = GetSensorValue(DimmSensorsSet[SensorIndex].ShutdownThreshold, DimmSensorsSet[SensorIndex].Type);
break;
default:
pTempBuff = NULL;
break;
}
if (NULL != pTempBuff) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, SHUTDOWN_THRESHOLD_STR, pTempBuff);
FREE_POOL_SAFE(pTempBuff);
}
}
/**
MaxTemperature
**/
if (pDispOptions->AllOptionSet || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MAX_TEMPERATURE))) {
switch (SensorIndex) {
case SENSOR_TYPE_CONTROLLER_TEMPERATURE:
case SENSOR_TYPE_MEDIA_TEMPERATURE:
// Only Controller/Media temperature sensor have MaxTemperature attribute (FIS 1.13+)
if (FIS_1_13) {
pTempBuff = GetSensorValue(DimmSensorsSet[SensorIndex].MaxTemperature, DimmSensorsSet[SensorIndex].Type);
}
else {
pTempBuff = CatSPrintClean(NULL, FORMAT_STR, NOT_APPLICABLE_SHORT_STR);
}
break;
default:
pTempBuff = NULL;
break;
}
if (NULL != pTempBuff) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, MAX_TEMPERATURE, pTempBuff);
FREE_POOL_SAFE(pTempBuff);
}
}
}
}
//Specify table attributes
PRINTER_CONFIGURE_DATA_ATTRIBUTES(pPrinterCtx, DS_ROOT_PATH, &ShowSensorDataSetAttribs);
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FREE_POOL_SAFE(pPath);
FREE_CMD_DISPLAY_OPTIONS_SAFE(pDispOptions);
FreeCommandStatus(&pCommandStatus);
FREE_POOL_SAFE(pDimms);
FREE_POOL_SAFE(pDimmIds);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Register the set sensor command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowSensorCommand(
)
{
EFI_STATUS ReturnCode;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&ShowSensorCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowSensorCommand.h 0000664 0000000 0000000 00000001430 14165347476 0021506 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SHOW_SENSOR_COMMAND_H_
#define _SHOW_SENSOR_COMMAND_H_
#include
#include "CommandParser.h"
#include
/**
Register the show sensor command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowSensorCommand(
);
/**
Execute the show sensor command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_NOT_READY Invalid device state to perform action
**/
EFI_STATUS
ShowSensor(
IN struct Command *pCmd
);
#endif /** _SHOW_SENSOR_COMMAND_H_ **/
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowSessionCommand.c 0000664 0000000 0000000 00000015010 14165347476 0021652 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include
#include "ShowSessionCommand.h"
#include
#include
#include
#include
#include
#include "Common.h"
#include
#include
#ifdef OS_BUILD
#include "os.h"
#endif
#define DS_ROOT_PATH L"/Session"
#define DS_TAG_PATH L"/Session/Tag"
#define DS_TAG_INDEX_PATH L"/Session/Tag[%d]"
#define TAG_ID_FORMAT L"0x%x"
#define TAG_ID_SELECTED_FORMAT L"0x%x*"
EFI_STATUS
MapTagToCurrentSessionState(
IN EFI_DCPMM_PBR_PROTOCOL *pNvmDimmPbrProtocol,
OUT UINT32 *pTag
);
/*
* PRINT LIST ATTRIBUTES
* ---TagId=0x0001---
* CliArgs=
*/
PRINTER_LIST_ATTRIB ShowSessionListAttributes =
{
{
{
TAG_STR, //GROUP LEVEL TYPE
L"---" TAG_ID_STR L"=$(" TAG_ID_STR L")---", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT L"%ls=%ls", //NULL or KEY VAL FORMAT STR
TAG_ID_STR //NULL or IGNORE KEY LIST (K1;K2)
}
}
};
/*
* PRINTER TABLE ATTRIBUTES (3 columns)
* TagID | ExitCode | CliArgs
* ========================================================================
* 0x0001 | X | X
* ...
*/
PRINTER_TABLE_ATTRIB ShowSessionTableAttributes =
{
{
{
TAG_ID_STR, //COLUMN HEADER
DEFAULT_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_TAG_PATH PATH_KEY_DELIM TAG_ID_STR //COLUMN DATA PATH
},
{
CLI_ARGS_STR, //COLUMN HEADER
DEFAULT_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_TAG_PATH PATH_KEY_DELIM CLI_ARGS_STR //COLUMN DATA PATH
}
}
};
PRINTER_DATA_SET_ATTRIBS ShowSessionDataSetAttribs =
{
&ShowSessionListAttributes,
&ShowSessionTableAttributes
};
/**
Command syntax definition
**/
struct Command ShowSessionCommand = {
SHOW_VERB, //!< verb
{
#ifdef OS_BUILD
{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP, HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired },
#endif
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", L"", L"", L"",FALSE, ValueOptional}
}, //!< options
{{SESSION_TARGET, L"", L"", TRUE, ValueEmpty}}, //!< targets
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Show information about the current playback or record (PBR) session.", //!< help
ShowSession,
TRUE,
TRUE //exclude from PBR
};
/**
Execute the show host server command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_ABORTED invoking CONFIG_PROTOCOL function failure
**/
EFI_STATUS
ShowSession(
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_DCPMM_PBR_PROTOCOL *pNvmDimmPbrProtocol = NULL;
DISPLAY_PREFERENCES DisplayPreferences;
PRINT_CONTEXT *pPrinterCtx = NULL;
CHAR16 *pPath = NULL;
UINT32 TagCount = 0;
UINT32 Index = 0;
CHAR16 *pName = NULL;
CHAR16 *pDescription = NULL;
CHAR16 *pTagId = NULL;
UINT32 TagId = INVALID_TAG_ID;
UINT32 Signature;
NVDIMM_ENTRY();
ZeroMem(&DisplayPreferences, sizeof(DisplayPreferences));
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
//If Windows, check for admin privilege needed to update registry for PBR state
CHECK_WIN_ADMIN_PERMISSIONS();
ReturnCode = ReadRunTimePreferences(&DisplayPreferences, DISPLAY_CLI_INFO);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_DISPLAY_PREFERENCES_RETRIEVE);
goto Finish;
}
/**
Make sure we can access the config protocol
**/
ReturnCode = OpenNvmDimmProtocol(gNvmDimmPbrProtocolGuid, (VOID **)&pNvmDimmPbrProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
//Retrieve the current TagID (CLI's job to track/increment/reset the tag id).
PbrDcpmmDeserializeTagId(&TagId, 0);
ReturnCode = pNvmDimmPbrProtocol->PbrGetTagCount(&TagCount);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_FAILED_TO_GET_SESSION_TAG_COUNT);
goto Finish;
}
for (Index = 0; Index < TagCount; ++Index) {
if (Index == TagId) {
pTagId = CatSPrintClean(NULL, TAG_ID_SELECTED_FORMAT, Index);
}
else {
pTagId = CatSPrintClean(NULL, TAG_ID_FORMAT, Index);
}
PRINTER_BUILD_KEY_PATH(pPath, DS_TAG_INDEX_PATH, Index);
ReturnCode = pNvmDimmPbrProtocol->PbrGetTag(Index, &Signature, &pName, &pDescription, NULL, NULL);
if (ReturnCode == EFI_SUCCESS) {
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, TAG_ID_STR, pTagId);
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, CLI_ARGS_STR, pName);
}
FREE_POOL_SAFE(pTagId);
FREE_POOL_SAFE(pName);
FREE_POOL_SAFE(pDescription);
}
//Specify table attributes
PRINTER_CONFIGURE_DATA_ATTRIBUTES(pPrinterCtx, DS_ROOT_PATH, &ShowSessionDataSetAttribs);
PRINTER_ENABLE_TEXT_TABLE_FORMAT(pPrinterCtx);
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
NVDIMM_EXIT_I64(ReturnCode);
FREE_POOL_SAFE(pPath);
FREE_POOL_SAFE(pTagId);
FREE_POOL_SAFE(pName);
FREE_POOL_SAFE(pDescription);
return ReturnCode;
}
/**
Register the show session command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowSessionCommand(
EFI_DCPMM_PBR_PROTOCOL *pNvmDimmPbrProtocol
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&ShowSessionCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowSessionCommand.h 0000664 0000000 0000000 00000001440 14165347476 0021661 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SHOW_SESSION_COMMAND_
#define _SHOW_SESSION_COMMAND_
#include "CommandParser.h"
/**
Execute the show host server command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_ABORTED invoking CONFIG_PROTOCOL function failure
**/
EFI_STATUS
ShowSession(
IN struct Command *pCmd
);
/**
Register the show session command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowSessionCommand(
);
#endif /* _SHOW_SESSION_COMMAND_ */
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowSmbiosCommand.h 0000664 0000000 0000000 00000000644 14165347476 0021477 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SHOW_SMBIOS_COMMAND_H_
#define _SHOW_SMBIOS_COMMAND_H_
#include "CommandParser.h"
/**
Register the show SMBIOS tables command.
**/
EFI_STATUS
registerShowSmbiosCommand(
);
/**
Execute the show SMBIOS command.
**/
EFI_STATUS
showSmbios(
IN struct Command *pCmd
);
#endif /** _SHOW_SMBIOS_COMMAND_H_ **/
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowSocketsCommand.c 0000664 0000000 0000000 00000024765 14165347476 0021663 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include
#include "Debug.h"
#include "Types.h"
#include "Utility.h"
#include "NvmDimmCli.h"
#include "NvmInterface.h"
#include "CommandParser.h"
#include "ShowSocketsCommand.h"
#include "Common.h"
#include "Convert.h"
#include
#define DS_ROOT_PATH L"/SocketList"
#define DS_SOCKET_PATH L"/SocketList/Socket"
#define DS_SOCKET_INDEX_PATH L"/SocketList/Socket[%d]"
/*
* PRINT LIST ATTRIBUTES
* ---SocketId=0x0001---
* MappedMemoryLimit=X
* TotalMappedMemory=X
* ...
*/
PRINTER_LIST_ATTRIB ShowSocketListAttributes =
{
{
{
SOCKET_NODE_STR, //GROUP LEVEL TYPE
L"---" SOCKET_ID_STR L"=$(" SOCKET_ID_STR L")---", //NULL or GROUP LEVEL HEADER
SHOW_LIST_IDENT L"%ls=%ls", //NULL or KEY VAL FORMAT STR
SOCKET_ID_STR //NULL or IGNORE KEY LIST (K1;K2)
}
}
};
/*
* PRINTER TABLE ATTRIBUTES (3 columns)
* SocketID | MappedMemoryLimit | TotalMappedMemory
* ================================================
* 0x0001 | X | X
* ...
*/
PRINTER_TABLE_ATTRIB ShowSocketTableAttributes =
{
{
{
SOCKET_ID_STR, //COLUMN HEADER
SOCKET_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_SOCKET_PATH PATH_KEY_DELIM SOCKET_ID_STR //COLUMN DATA PATH
},
{
MAPPED_MEMORY_LIMIT_STR, //COLUMN HEADER
MAPPED_MEMORY_LIMIT_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_SOCKET_PATH PATH_KEY_DELIM MAPPED_MEMORY_LIMIT_STR //COLUMN DATA PATH
},
{
TOTAL_MAPPED_MEMORY_STR, //COLUMN HEADER
TOTAL_MAPPED_MEMORY_MAX_STR_WIDTH, //COLUMN MAX STR WIDTH
DS_SOCKET_PATH PATH_KEY_DELIM TOTAL_MAPPED_MEMORY_STR //COLUMN DATA PATH
}
}
};
PRINTER_DATA_SET_ATTRIBS ShowSocketDataSetAttribs =
{
&ShowSocketListAttributes,
&ShowSocketTableAttributes
};
/**
Command syntax definition
**/
struct Command ShowSocketsCommand =
{
SHOW_VERB, //!< verb
/**
options
**/
{
{VERBOSE_OPTION_SHORT, VERBOSE_OPTION, L"", L"", HELP_VERBOSE_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_DDRT, L"", L"",HELP_DDRT_DETAILS_TEXT, FALSE, ValueEmpty},
{L"", PROTOCOL_OPTION_SMBUS, L"", L"",HELP_SMBUS_DETAILS_TEXT, FALSE, ValueEmpty},
{ALL_OPTION_SHORT, ALL_OPTION, L"", L"", HELP_ALL_DETAILS_TEXT, FALSE, ValueEmpty},
{DISPLAY_OPTION_SHORT, DISPLAY_OPTION, L"", HELP_TEXT_ATTRIBUTES, HELP_DISPLAY_DETAILS_TEXT, FALSE, ValueRequired},
{UNITS_OPTION_SHORT, UNITS_OPTION, L"", UNITS_OPTION_HELP, HELP_UNIT_DETAILS_TEXT, FALSE, ValueRequired}
#ifdef OS_BUILD
,{ OUTPUT_OPTION_SHORT, OUTPUT_OPTION, L"", OUTPUT_OPTION_HELP, HELP_OPTIONS_DETAILS_TEXT, FALSE, ValueRequired }
#endif
},
/**
targets
**/
{
{SOCKET_TARGET, L"", HELP_TEXT_SOCKET_IDS, TRUE, ValueOptional}
},
{{L"", L"", L"", FALSE, ValueOptional}}, //!< properties
L"Show mapped memory limit and total mapped memory of each socket.", //!< help
ShowSockets, //!< run function
TRUE, //!< enable print control support
};
CHAR16 *mppAllowedShowSocketsDisplayValues[] =
{
SOCKET_ID_STR,
MAPPED_MEMORY_LIMIT_STR,
TOTAL_MAPPED_MEMORY_STR
};
/**
Register the show sockets command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowSocketsCommand(
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
NVDIMM_ENTRY();
ReturnCode = RegisterCommand(&ShowSocketsCommand);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
/**
Execute the show sockets command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_NOT_FOUND failed to open Config protocol, or run-time preferences could
not be retrieved, or user-specified socket ID is invalid
@retval Other errors returned by the driver
**/
EFI_STATUS
ShowSockets(
IN struct Command *pCmd
)
{
EFI_STATUS ReturnCode = EFI_SUCCESS;
EFI_DCPMM_CONFIG2_PROTOCOL *pNvmDimmConfigProtocol = NULL;
UINT32 SocketCount = 0;
SOCKET_INFO *pSockets = NULL;
UINT16 *pSocketIds = NULL;
UINT32 SocketIdsNum = 0;
CHAR16 *pSocketsValue = NULL;
UINT32 Index = 0;
UINT32 Index2 = 0;
UINT16 UnitsOption = DISPLAY_SIZE_UNIT_UNKNOWN;
UINT16 UnitsToDisplay = FixedPcdGet16(PcdDcpmmCliDefaultCapacityUnit);
DISPLAY_PREFERENCES DisplayPreferences;
CHAR16 *pMappedMemLimitStr = NULL;
CHAR16 *pTotalMappedMemStr = NULL;
BOOLEAN SocketIdFound = FALSE;
CMD_DISPLAY_OPTIONS *pDispOptions = NULL;
BOOLEAN ShowAll = FALSE;
PRINT_CONTEXT *pPrinterCtx = NULL;
CHAR16 *pPath = NULL;
NVDIMM_ENTRY();
ZeroMem(&DisplayPreferences, sizeof(DisplayPreferences));
if (pCmd == NULL) {
ReturnCode = EFI_INVALID_PARAMETER;
NVDIMM_DBG("pCmd parameter is NULL.\n");
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_COMMAND);
goto Finish;
}
pPrinterCtx = pCmd->pPrintCtx;
pDispOptions = AllocateZeroPool(sizeof(CMD_DISPLAY_OPTIONS));
if (NULL == pDispOptions) {
ReturnCode = EFI_OUT_OF_RESOURCES;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OUT_OF_MEMORY);
goto Finish;
}
ReturnCode = CheckAllAndDisplayOptions(pCmd, mppAllowedShowSocketsDisplayValues,
ALLOWED_DISP_VALUES_COUNT(mppAllowedShowSocketsDisplayValues), pDispOptions);
if (EFI_ERROR(ReturnCode)) {
NVDIMM_DBG("CheckAllAndDisplayOptions has returned error. Code " FORMAT_EFI_STATUS "\n", ReturnCode);
goto Finish;
}
ShowAll = (!pDispOptions->AllOptionSet && !pDispOptions->DisplayOptionSet) || pDispOptions->AllOptionSet;
/**
Make sure we can access the config protocol
**/
ReturnCode = OpenNvmDimmProtocol(gNvmDimmConfigProtocolGuid, (VOID **)&pNvmDimmConfigProtocol, NULL);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_OPENING_CONFIG_PROTOCOL);
goto Finish;
}
/**
if Socket IDs were passed in, read them
**/
if (pCmd->targets[0].pTargetValueStr && StrLen(pCmd->targets[0].pTargetValueStr) > 0) {
pSocketsValue = GetTargetValue(pCmd, SOCKET_TARGET);
ReturnCode = GetUintsFromString(pSocketsValue, &pSocketIds, &SocketIdsNum);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INCORRECT_VALUE_TARGET_SOCKET);
goto Finish;
}
}
/**
Determine the units to display the sizes in
**/
ReturnCode = ReadRunTimePreferences(&DisplayPreferences, DISPLAY_CLI_INFO);
if (EFI_ERROR(ReturnCode)) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_DISPLAY_PREFERENCES_RETRIEVE);
goto Finish;
}
UnitsToDisplay = DisplayPreferences.SizeUnit;
ReturnCode = GetUnitsOption(pCmd, &UnitsOption);
if (EFI_ERROR(ReturnCode)) {
goto Finish;
}
/**
Any valid units option will override the preferences
**/
if (UnitsOption != DISPLAY_SIZE_UNIT_UNKNOWN) {
UnitsToDisplay = UnitsOption;
}
/**
Retrieve the list of sockets on the platform
**/
ReturnCode = pNvmDimmConfigProtocol->GetSockets(pNvmDimmConfigProtocol, &SocketCount, &pSockets);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_INTERNAL_ERROR);
goto Finish;
} else if (pSockets == NULL) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_NO_SOCKET_SKU_SUPPORT);
goto Finish;
}
/**
Check if proper -socket target is given
**/
for (Index = 0; Index < SocketIdsNum; Index++) {
SocketIdFound = FALSE;
/**
Checking if the specified socket exist
**/
for (Index2 = 0; Index2 < SocketCount; Index2++) {
if (pSockets[Index2].SocketId == pSocketIds[Index]) {
SocketIdFound = TRUE;
break;
}
}
if (!SocketIdFound) {
ReturnCode = EFI_NOT_FOUND;
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_SOCKET_NOT_FOUND CLI_ERR_INCORRECT_VALUE_TARGET_SOCKET, pSocketIds[Index]);
goto Finish;
}
}
for (Index = 0; Index < SocketCount; Index++) {
if (SocketIdsNum > 0 && !ContainUint(pSocketIds, SocketIdsNum, pSockets[Index].SocketId)) {
continue;
}
PRINTER_BUILD_KEY_PATH(pPath, DS_SOCKET_INDEX_PATH, Index);
/** SocketID **/
PRINTER_SET_KEY_VAL_WIDE_STR_FORMAT(pPrinterCtx, pPath, SOCKET_ID_STR, FORMAT_HEX, pSockets[Index].SocketId);
/** MappedMemoryLimit **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, MAPPED_MEMORY_LIMIT_STR))) {
ReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, pSockets[Index].MappedMemoryLimit, UnitsToDisplay, TRUE, &pMappedMemLimitStr);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_CAPACITY_STRING);
goto Finish;
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, MAPPED_MEMORY_LIMIT_STR, pMappedMemLimitStr);
FREE_POOL_SAFE(pMappedMemLimitStr);
}
/** TotalMappedMemory **/
if (ShowAll || (pDispOptions->DisplayOptionSet && ContainsValue(pDispOptions->pDisplayValues, TOTAL_MAPPED_MEMORY_STR))) {
ReturnCode = MakeCapacityString(gNvmDimmCliHiiHandle, pSockets[Index].TotalMappedMemory, UnitsToDisplay, TRUE, &pTotalMappedMemStr);
if (EFI_ERROR(ReturnCode)) {
PRINTER_SET_MSG(pPrinterCtx, ReturnCode, CLI_ERR_CAPACITY_STRING);
goto Finish;
}
PRINTER_SET_KEY_VAL_WIDE_STR(pPrinterCtx, pPath, TOTAL_MAPPED_MEMORY_STR, pTotalMappedMemStr);
FREE_POOL_SAFE(pTotalMappedMemStr);
}
}
//Specify table attributes
PRINTER_CONFIGURE_DATA_ATTRIBUTES(pPrinterCtx, DS_ROOT_PATH, &ShowSocketDataSetAttribs);
Finish:
PRINTER_PROCESS_SET_BUFFER(pPrinterCtx);
FREE_POOL_SAFE(pPath);
FREE_CMD_DISPLAY_OPTIONS_SAFE(pDispOptions);
FREE_POOL_SAFE(pSockets);
FREE_POOL_SAFE(pSocketIds);
FREE_POOL_SAFE(pMappedMemLimitStr);
FREE_POOL_SAFE(pTotalMappedMemStr);
NVDIMM_EXIT_I64(ReturnCode);
return ReturnCode;
}
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowSocketsCommand.h 0000664 0000000 0000000 00000002060 14165347476 0021650 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _SHOW_SOCKETS_COMMAND_H_
#define _SHOW_SOCKETS_COMMAND_H_
#include "CommandParser.h"
#define MAPPED_MEMORY_LIMIT_STR L"MappedMemoryLimit"
#define TOTAL_MAPPED_MEMORY_STR L"TotalMappedMemory"
/**
Register the show sockets command
@retval EFI_SUCCESS success
@retval EFI_ABORTED registering failure
@retval EFI_OUT_OF_RESOURCES memory allocation failure
**/
EFI_STATUS
RegisterShowSocketsCommand(
);
/**
Execute the show sockets command
@param[in] pCmd command from CLI
@retval EFI_SUCCESS on success
@retval EFI_INVALID_PARAMETER pCmd is NULL or invalid command line parameters
@retval EFI_OUT_OF_RESOURCES memory allocation failure
@retval EFI_NOT_FOUND failed to open Config protocol, or run-time preferences could
not be retrieved, or user-specified socket ID is invalid
@retval Other errors returned by the driver
**/
EFI_STATUS
ShowSockets(
IN struct Command *pCmd
);
#endif /* _SHOW_SOCKETS_COMMAND_H_*/
ipmctl-03.00.00.0423/DcpmPkg/cli/ShowSystemCapabilitiesCommand.c 0000664 0000000 0000000 00000041577 14165347476 0024046 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2018, Intel Corporation.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include
#include
#include "ShowSystemCapabilitiesCommand.h"
#include
#include
#include