Skip to content

Commit

Permalink
Add sysman Firmware support for windows
Browse files Browse the repository at this point in the history
Related-To: LOCI-3226

Signed-off-by: Mayank Raghuwanshi <mayank.raghuwanshi@intel.com>
  • Loading branch information
mraghuwa authored and Compute-Runtime-Automation committed Aug 5, 2022
1 parent ba24463 commit f833dc0
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 13 deletions.
8 changes: 6 additions & 2 deletions level_zero/tools/source/sysman/firmware/firmware_imp.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#
# Copyright (C) 2020 Intel Corporation
# Copyright (C) 2020-2022 Intel Corporation
#
# SPDX-License-Identifier: MIT
#

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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,62 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/

#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<std ::string> 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<char *>(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<char *>(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<WddmSysmanImp *>(pOsSysman);
pFwInterface = pWddmSysmanImp->getFwUtilInterface();
}

std::unique_ptr<OsFirmware> OsFirmware::create(OsSysman *pOsSysman, const std::string &fwType) {
std::unique_ptr<WddmFirmwareImp> pWddmFirmwareImp = std::make_unique<WddmFirmwareImp>();
std::unique_ptr<WddmFirmwareImp> pWddmFirmwareImp = std::make_unique<WddmFirmwareImp>(pOsSysman, fwType);
return pWddmFirmwareImp;
}

ze_result_t OsFirmware::getSupportedFwTypes(std::vector<std::string> &supportedFwTypes, OsSysman *pOsSysman) {
WddmSysmanImp *pWddmSysmanImp = static_cast<WddmSysmanImp *>(pOsSysman);
FirmwareUtil *pFwInterface = pWddmSysmanImp->getFwUtilInterface();
if (pFwInterface != nullptr) {
supportedFwTypes = deviceSupportedFwTypes;
return ZE_RESULT_SUCCESS;
}
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}

Expand Down
13 changes: 11 additions & 2 deletions level_zero/tools/source/sysman/firmware/windows/os_firmware_imp.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit f833dc0

Please sign in to comment.