From f833dc029139b7c2902a85fe8cd09a24498d1592 Mon Sep 17 00:00:00 2001 From: Mayank Raghuwanshi Date: Wed, 20 Jul 2022 18:55:49 +0000 Subject: [PATCH] Add sysman Firmware support for windows Related-To: LOCI-3226 Signed-off-by: Mayank Raghuwanshi --- .../source/sysman/firmware/firmware_imp.cpp | 8 +++- .../sysman/firmware/windows/CMakeLists.txt | 3 +- .../firmware/windows/os_firmware_imp.cpp | 45 ++++++++++++++++--- .../sysman/firmware/windows/os_firmware_imp.h | 13 +++++- .../linux/test_zes_sysman_firmware.cpp | 21 ++++++++- 5 files changed, 77 insertions(+), 13 deletions(-) diff --git a/level_zero/tools/source/sysman/firmware/firmware_imp.cpp b/level_zero/tools/source/sysman/firmware/firmware_imp.cpp index 576cb8992b94a..d66a0e61d699a 100644 --- a/level_zero/tools/source/sysman/firmware/firmware_imp.cpp +++ b/level_zero/tools/source/sysman/firmware/firmware_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -17,7 +17,11 @@ namespace L0 { ze_result_t FirmwareImp::firmwareGetProperties(zes_firmware_properties_t *pProperties) { pOsFirmware->osGetFwProperties(pProperties); - strncpy_s(pProperties->name, ZES_STRING_PROPERTY_SIZE, fwType.c_str(), fwType.size()); + std::string fwName = fwType; + if (fwName == "GSC") { + fwName = "GFX"; + } + strncpy_s(pProperties->name, ZES_STRING_PROPERTY_SIZE, fwName.c_str(), fwName.size()); return ZE_RESULT_SUCCESS; } diff --git a/level_zero/tools/source/sysman/firmware/windows/CMakeLists.txt b/level_zero/tools/source/sysman/firmware/windows/CMakeLists.txt index f62c869ceb838..7fde7cf431594 100644 --- a/level_zero/tools/source/sysman/firmware/windows/CMakeLists.txt +++ b/level_zero/tools/source/sysman/firmware/windows/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2020 Intel Corporation +# Copyright (C) 2020-2022 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -7,6 +7,7 @@ set(L0_SRCS_TOOLS_SYSMAN_FIRMWARE_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt ${CMAKE_CURRENT_SOURCE_DIR}/os_firmware_imp.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/os_firmware_imp.h ) if(WIN32) diff --git a/level_zero/tools/source/sysman/firmware/windows/os_firmware_imp.cpp b/level_zero/tools/source/sysman/firmware/windows/os_firmware_imp.cpp index ea5b1bcbcc489..3177c214a027d 100644 --- a/level_zero/tools/source/sysman/firmware/windows/os_firmware_imp.cpp +++ b/level_zero/tools/source/sysman/firmware/windows/os_firmware_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,23 +7,56 @@ #include "level_zero/tools/source/sysman/firmware/windows/os_firmware_imp.h" +#include "level_zero/tools/source/sysman/firmware_util/firmware_util.h" +#include "level_zero/tools/source/sysman/windows/os_sysman_imp.h" + namespace L0 { +const std::vector deviceSupportedFwTypes = {"GSC", "OptionROM"}; + +ze_result_t WddmFirmwareImp::getFirmwareVersion(std::string fwType, zes_firmware_properties_t *pProperties) { + std::string fwVersion; + ze_result_t result = pFwInterface->getFwVersion(fwType, fwVersion); + if (ZE_RESULT_SUCCESS == result) { + strncpy_s(static_cast(pProperties->version), ZES_STRING_PROPERTY_SIZE, fwVersion.c_str(), ZES_STRING_PROPERTY_SIZE); + } + return result; +} + +void WddmFirmwareImp::osGetFwProperties(zes_firmware_properties_t *pProperties) { + if (ZE_RESULT_SUCCESS != getFirmwareVersion(osFwType, pProperties)) { + strncpy_s(static_cast(pProperties->version), ZES_STRING_PROPERTY_SIZE, unknown.c_str(), ZES_STRING_PROPERTY_SIZE); + } + pProperties->canControl = true; // Assuming that user has permission to flash the firmware +} +ze_result_t WddmFirmwareImp::osFirmwareFlash(void *pImage, uint32_t size) { + return pFwInterface->flashFirmware(osFwType, pImage, size); +} bool WddmFirmwareImp::isFirmwareSupported(void) { + if (pFwInterface != nullptr) { + isFWInitialized = ((ZE_RESULT_SUCCESS == pFwInterface->fwDeviceInit()) ? true : false); + return this->isFWInitialized; + } return false; } -void WddmFirmwareImp::osGetFwProperties(zes_firmware_properties_t *pProperties){}; -ze_result_t WddmFirmwareImp::osFirmwareFlash(void *pImage, uint32_t size) { - return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; -}; +WddmFirmwareImp::WddmFirmwareImp(OsSysman *pOsSysman, const std::string &fwType) : osFwType(fwType) { + WddmSysmanImp *pWddmSysmanImp = static_cast(pOsSysman); + pFwInterface = pWddmSysmanImp->getFwUtilInterface(); +} std::unique_ptr OsFirmware::create(OsSysman *pOsSysman, const std::string &fwType) { - std::unique_ptr pWddmFirmwareImp = std::make_unique(); + std::unique_ptr pWddmFirmwareImp = std::make_unique(pOsSysman, fwType); return pWddmFirmwareImp; } ze_result_t OsFirmware::getSupportedFwTypes(std::vector &supportedFwTypes, OsSysman *pOsSysman) { + WddmSysmanImp *pWddmSysmanImp = static_cast(pOsSysman); + FirmwareUtil *pFwInterface = pWddmSysmanImp->getFwUtilInterface(); + if (pFwInterface != nullptr) { + supportedFwTypes = deviceSupportedFwTypes; + return ZE_RESULT_SUCCESS; + } return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/level_zero/tools/source/sysman/firmware/windows/os_firmware_imp.h b/level_zero/tools/source/sysman/firmware/windows/os_firmware_imp.h index 85facb50cc097..cfc3f4b873d10 100644 --- a/level_zero/tools/source/sysman/firmware/windows/os_firmware_imp.h +++ b/level_zero/tools/source/sysman/firmware/windows/os_firmware_imp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -9,14 +9,23 @@ #include "shared/source/helpers/non_copyable_or_moveable.h" #include "sysman/firmware/os_firmware.h" -#include "sysman/windows/os_sysman_imp.h" namespace L0 { +class FirmwareUtil; class WddmFirmwareImp : public OsFirmware { public: bool isFirmwareSupported(void) override; void osGetFwProperties(zes_firmware_properties_t *pProperties) override; ze_result_t osFirmwareFlash(void *pImage, uint32_t size) override; + ze_result_t getFirmwareVersion(std::string fwType, zes_firmware_properties_t *pProperties); + WddmFirmwareImp() = default; + WddmFirmwareImp(OsSysman *pOsSysman, const std::string &fwType); + ~WddmFirmwareImp() override = default; + + protected: + FirmwareUtil *pFwInterface = nullptr; + bool isFWInitialized = false; + std::string osFwType; }; } // namespace L0 diff --git a/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/test_zes_sysman_firmware.cpp b/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/test_zes_sysman_firmware.cpp index 27a2ba3b8aaf7..db68dd6ec79e6 100644 --- a/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/test_zes_sysman_firmware.cpp +++ b/level_zero/tools/test/unit_tests/sources/sysman/firmware/linux/test_zes_sysman_firmware.cpp @@ -111,13 +111,30 @@ TEST_F(ZesFirmwareFixture, GivenValidFirmwareHandleWhenGettingFirmwareProperties zes_firmware_properties_t properties = {}; EXPECT_EQ(ZE_RESULT_SUCCESS, zesFirmwareGetProperties(handles[0], &properties)); - EXPECT_STREQ(mockSupportedFwTypes[0].c_str(), properties.name); + EXPECT_STREQ("GFX", properties.name); EXPECT_STREQ(mockFwVersion.c_str(), properties.version); pSysmanDeviceImp->pFirmwareHandleContext->handleList.pop_back(); delete ptestFirmwareImp; } +TEST_F(ZesFirmwareFixture, GivenValidFirmwareHandleWhenGettingOptionRomPropertiesThenVersionIsReturned) { + initFirmware(); + + FirmwareImp *pTestFirmwareImp = new FirmwareImp(pSysmanDeviceImp->pFirmwareHandleContext->pOsSysman, mockSupportedFwTypes[1]); + pSysmanDeviceImp->pFirmwareHandleContext->handleList.push_back(pTestFirmwareImp); + + auto handles = getFirmwareHandles(mockHandleCount); + + zes_firmware_properties_t properties = {}; + EXPECT_EQ(ZE_RESULT_SUCCESS, zesFirmwareGetProperties(handles[1], &properties)); + EXPECT_STREQ(mockSupportedFwTypes[1].c_str(), properties.name); + EXPECT_STREQ(mockOpromVersion.c_str(), properties.version); + + pSysmanDeviceImp->pFirmwareHandleContext->handleList.pop_back(); + delete pTestFirmwareImp; +} + TEST_F(ZesFirmwareFixture, GivenValidFirmwareHandleWhenGettingOpromPropertiesThenVersionIsReturned) { initFirmware(); @@ -232,7 +249,7 @@ TEST_F(ZesFirmwareFixture, GivenValidFirmwareHandleFirmwareLibraryCallFailureWhe zes_firmware_properties_t properties = {}; EXPECT_EQ(ZE_RESULT_SUCCESS, zesFirmwareGetProperties(handles[0], &properties)); - EXPECT_STREQ(mockSupportedFwTypes[0].c_str(), properties.name); + EXPECT_STREQ("GFX", properties.name); EXPECT_STREQ("unknown", properties.version); EXPECT_EQ(ZE_RESULT_SUCCESS, zesFirmwareGetProperties(handles[1], &properties));