feature(sysman): supports pci module for zesInit windows

Related-To: LOCI-4204

Signed-off-by: Kulkarni, Ashwin Kumar <ashwin.kumar.kulkarni@intel.com>
This commit is contained in:
Kulkarni, Ashwin Kumar
2023-07-03 10:26:26 +00:00
committed by Compute-Runtime-Automation
parent 6f29e3b100
commit ed972bb21c
7 changed files with 620 additions and 8 deletions

View File

@@ -7,36 +7,208 @@
#include "level_zero/sysman/source/pci/windows/sysman_os_pci_imp.h"
#include "level_zero/sysman/source/windows/sysman_kmd_sys_manager.h"
#include "level_zero/sysman/source/windows/zes_os_sysman_imp.h"
namespace L0 {
namespace Sysman {
ze_result_t WddmPciImp::getProperties(zes_pci_properties_t *properties) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
properties->haveBandwidthCounters = false;
properties->havePacketCounters = false;
properties->haveReplayCounters = false;
return ZE_RESULT_SUCCESS;
}
ze_result_t WddmPciImp::getPciBdf(zes_pci_properties_t &pciProperties) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
uint32_t domain = 0, bus = 0, dev = 0, func = 0;
std::vector<KmdSysman::RequestProperty> vRequests = {};
std::vector<KmdSysman::ResponseProperty> vResponses = {};
KmdSysman::RequestProperty request = {};
request.commandId = KmdSysman::Command::Get;
request.componentId = KmdSysman::Component::PciComponent;
request.paramInfo = (isLocalMemSupported()) ? KmdSysman::PciDomainsType::PciRootPort : KmdSysman::PciDomainsType::PciCurrentDevice;
request.requestId = KmdSysman::Requests::Pci::Bus;
vRequests.push_back(request);
request.requestId = KmdSysman::Requests::Pci::Domain;
vRequests.push_back(request);
request.requestId = KmdSysman::Requests::Pci::Device;
vRequests.push_back(request);
request.requestId = KmdSysman::Requests::Pci::Function;
vRequests.push_back(request);
ze_result_t status = pKmdSysManager->requestMultiple(vRequests, vResponses);
if ((status != ZE_RESULT_SUCCESS) || (vResponses.size() != vRequests.size())) {
return status;
}
if (vResponses[0].returnCode == KmdSysman::Success) {
memcpy_s(&bus, sizeof(uint32_t), vResponses[0].dataBuffer, sizeof(uint32_t));
}
if (vResponses[1].returnCode == KmdSysman::Success) {
memcpy_s(&domain, sizeof(uint32_t), vResponses[1].dataBuffer, sizeof(uint32_t));
}
if (vResponses[2].returnCode == KmdSysman::Success) {
memcpy_s(&dev, sizeof(uint32_t), vResponses[2].dataBuffer, sizeof(uint32_t));
}
if (vResponses[3].returnCode == KmdSysman::Success) {
memcpy_s(&func, sizeof(uint32_t), vResponses[3].dataBuffer, sizeof(uint32_t));
}
pciProperties.address.domain = domain;
pciProperties.address.bus = bus;
pciProperties.address.device = dev;
pciProperties.address.function = func;
return ZE_RESULT_SUCCESS;
}
void WddmPciImp::getMaxLinkCaps(double &maxLinkSpeed, int32_t &maxLinkWidth) {}
void WddmPciImp::getMaxLinkCaps(double &maxLinkSpeed, int32_t &maxLinkWidth) {
uint32_t valueSmall = 0;
KmdSysman::RequestProperty request;
KmdSysman::ResponseProperty response;
request.commandId = KmdSysman::Command::Get;
request.componentId = KmdSysman::Component::PciComponent;
request.requestId = KmdSysman::Requests::Pci::MaxLinkSpeed;
request.paramInfo = (isLocalMemSupported()) ? KmdSysman::PciDomainsType::PciRootPort : KmdSysman::PciDomainsType::PciCurrentDevice;
ze_result_t status = pKmdSysManager->requestSingle(request, response);
if (status != ZE_RESULT_SUCCESS) {
maxLinkSpeed = 0;
} else {
memcpy_s(&valueSmall, sizeof(uint32_t), response.dataBuffer, sizeof(uint32_t));
maxLinkSpeed = convertPciGenToLinkSpeed(valueSmall);
}
request.requestId = KmdSysman::Requests::Pci::MaxLinkWidth;
status = pKmdSysManager->requestSingle(request, response);
if (status != ZE_RESULT_SUCCESS) {
maxLinkWidth = -1;
return;
}
memcpy_s(&valueSmall, sizeof(uint32_t), response.dataBuffer, sizeof(uint32_t));
maxLinkWidth = static_cast<int32_t>(valueSmall);
return;
}
ze_result_t WddmPciImp::getState(zes_pci_state_t *state) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
uint32_t valueSmall = 0;
std::vector<KmdSysman::RequestProperty> vRequests = {};
std::vector<KmdSysman::ResponseProperty> vResponses = {};
KmdSysman::RequestProperty request = {};
state->qualityIssues = ZES_PCI_LINK_QUAL_ISSUE_FLAG_FORCE_UINT32;
state->stabilityIssues = ZES_PCI_LINK_STAB_ISSUE_FLAG_FORCE_UINT32;
state->status = ZES_PCI_LINK_STATUS_FORCE_UINT32;
state->speed.gen = -1;
state->speed.width = -1;
state->speed.maxBandwidth = -1;
request.commandId = KmdSysman::Command::Get;
request.componentId = KmdSysman::Component::PciComponent;
request.paramInfo = (isLocalMemSupported()) ? KmdSysman::PciDomainsType::PciRootPort : KmdSysman::PciDomainsType::PciCurrentDevice;
request.requestId = KmdSysman::Requests::Pci::CurrentLinkSpeed;
vRequests.push_back(request);
request.requestId = KmdSysman::Requests::Pci::CurrentLinkWidth;
vRequests.push_back(request);
ze_result_t status = pKmdSysManager->requestMultiple(vRequests, vResponses);
if ((status != ZE_RESULT_SUCCESS) || (vResponses.size() != vRequests.size())) {
return status;
}
if (vResponses[0].returnCode == KmdSysman::Success) {
memcpy_s(&valueSmall, sizeof(uint32_t), vResponses[0].dataBuffer, sizeof(uint32_t));
state->speed.gen = static_cast<int32_t>(valueSmall);
}
if (vResponses[1].returnCode == KmdSysman::Success) {
memcpy_s(&valueSmall, sizeof(uint32_t), vResponses[1].dataBuffer, sizeof(uint32_t));
state->speed.width = static_cast<int32_t>(valueSmall);
}
double currentLinkSpeed = convertPciGenToLinkSpeed(state->speed.gen);
state->speed.maxBandwidth = state->speed.width * convertPcieSpeedFromGTsToBs(currentLinkSpeed);
if (state->speed.maxBandwidth == 0) {
state->speed.maxBandwidth = -1;
}
return ZE_RESULT_SUCCESS;
}
bool WddmPciImp::resizableBarSupported() {
return false;
uint32_t valueSmall = 0;
bool supported = false;
KmdSysman::RequestProperty request;
KmdSysman::ResponseProperty response;
request.commandId = KmdSysman::Command::Get;
request.componentId = KmdSysman::Component::PciComponent;
request.paramInfo = KmdSysman::PciDomainsType::PciCurrentDevice;
request.requestId = KmdSysman::Requests::Pci::ResizableBarSupported;
if (pKmdSysManager->requestSingle(request, response) == ZE_RESULT_SUCCESS) {
memcpy_s(&valueSmall, sizeof(uint32_t), response.dataBuffer, sizeof(uint32_t));
supported = static_cast<bool>(valueSmall);
}
return supported;
}
bool WddmPciImp::resizableBarEnabled(uint32_t barIndex) {
return false;
uint32_t valueSmall = 0;
bool enabled = false;
KmdSysman::RequestProperty request;
KmdSysman::ResponseProperty response;
request.commandId = KmdSysman::Command::Get;
request.componentId = KmdSysman::Component::PciComponent;
request.paramInfo = KmdSysman::PciDomainsType::PciCurrentDevice;
request.requestId = KmdSysman::Requests::Pci::ResizableBarEnabled;
if (pKmdSysManager->requestSingle(request, response) == ZE_RESULT_SUCCESS) {
memcpy_s(&valueSmall, sizeof(uint32_t), response.dataBuffer, sizeof(uint32_t));
enabled = static_cast<bool>(valueSmall);
}
return enabled;
}
ze_result_t WddmPciImp::initializeBarProperties(std::vector<zes_pci_bar_properties_t *> &pBarProperties) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
zes_pci_bar_properties_t *pBarProp = new zes_pci_bar_properties_t;
memset(pBarProp, 0, sizeof(zes_pci_bar_properties_t));
pBarProperties.push_back(pBarProp);
return ZE_RESULT_SUCCESS;
}
WddmPciImp::WddmPciImp(OsSysman *pOsSysman) {}
WddmPciImp::WddmPciImp(OsSysman *pOsSysman) {
WddmSysmanImp *pWddmSysmanImp = static_cast<WddmSysmanImp *>(pOsSysman);
pKmdSysManager = &pWddmSysmanImp->getKmdSysManager();
isLmemSupported = !(pWddmSysmanImp->getSysmanDeviceImp()->getRootDeviceEnvironment().getHardwareInfo()->capabilityTable.isIntegratedDevice);
}
bool WddmPciImp::isLocalMemSupported() {
return isLmemSupported;
}
OsPci *OsPci::create(OsSysman *pOsSysman) {
WddmPciImp *pWddmPciImp = new WddmPciImp(pOsSysman);

View File

@@ -13,6 +13,7 @@
namespace L0 {
namespace Sysman {
struct OsSysman;
class KmdSysManager;
class WddmPciImp : public OsPci, NEO::NonCopyableOrMovableClass {
public:
ze_result_t getPciBdf(zes_pci_properties_t &pciProperties) override;
@@ -24,6 +25,13 @@ class WddmPciImp : public OsPci, NEO::NonCopyableOrMovableClass {
ze_result_t initializeBarProperties(std::vector<zes_pci_bar_properties_t *> &pBarProperties) override;
WddmPciImp(OsSysman *pOsSysman);
~WddmPciImp() override = default;
bool isLocalMemSupported();
protected:
KmdSysManager *pKmdSysManager = nullptr;
private:
bool isLmemSupported = false;
};
} // namespace Sysman

View File

@@ -42,6 +42,10 @@ uint32_t WddmSysmanImp::getSubDeviceCount() {
return subDeviceCount;
}
SysmanDeviceImp *WddmSysmanImp::getSysmanDeviceImp() {
return pParentSysmanDeviceImp;
}
void WddmSysmanImp::createFwUtilInterface() {
const auto pciBusInfo = pParentSysmanDeviceImp->getRootDeviceEnvironment().osInterface->getDriverModel()->getPciBusInfo();
const uint16_t domain = static_cast<uint16_t>(pciBusInfo.pciDomain);

View File

@@ -33,6 +33,7 @@ class WddmSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
void releaseFwUtilInterface();
uint32_t getSubDeviceCount() override;
SysmanDeviceImp *getSysmanDeviceImp();
protected:
FirmwareUtil *pFwUtilInterface = nullptr;

View File

@@ -0,0 +1,14 @@
#
# Copyright (C) 2023 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
if(WIN32)
target_sources(${TARGET_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/test_zes_pci.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_pci.h
)
endif()

View File

@@ -0,0 +1,126 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "level_zero/sysman/source/pci/sysman_pci_imp.h"
#include "level_zero/sysman/source/pci/windows/sysman_os_pci_imp.h"
#include "level_zero/sysman/test/unit_tests/sources/windows/mock_kmd_sys_manager.h"
namespace L0 {
namespace Sysman {
namespace ult {
struct PciKmdSysManager : public MockKmdSysManager {
// PciCurrentDevice, PciParentDevice, PciRootPort
uint32_t mockDomain[3] = {0, 0, 0};
uint32_t mockBus[3] = {0, 0, 3};
uint32_t mockDevice[3] = {2, 0, 0};
uint32_t mockFunction[3] = {0, 0, 0};
uint32_t mockMaxLinkSpeed[3] = {1, 0, 4};
uint32_t mockMaxLinkWidth[3] = {1, 0, 8};
uint32_t mockCurrentLinkSpeed[3] = {1, 0, 3};
uint32_t mockCurrentLinkWidth[3] = {1, 0, 1};
int64_t mockCurrentMaxBandwidth[3] = {250000000, -1, 984615384};
uint32_t mockResizableBarSupported[3] = {1, 1, 1};
uint32_t mockResizableBarEnabled[3] = {1, 1, 1};
uint32_t pciBusReturnCode = KmdSysman::KmdSysmanSuccess;
uint32_t pciDomainReturnCode = KmdSysman::KmdSysmanSuccess;
uint32_t pciDeviceReturnCode = KmdSysman::KmdSysmanSuccess;
uint32_t pciFunctionReturnCode = KmdSysman::KmdSysmanSuccess;
uint32_t pciMaxLinkSpeedReturnCode = KmdSysman::KmdSysmanSuccess;
uint32_t pciMaxLinkWidthReturnCode = KmdSysman::KmdSysmanSuccess;
uint32_t pciCurrentLinkSpeedReturnCode = KmdSysman::KmdSysmanSuccess;
uint32_t pciCurrentLinkWidthReturnCode = KmdSysman::KmdSysmanSuccess;
uint32_t pciResizableBarSupportedReturnCode = KmdSysman::KmdSysmanSuccess;
uint32_t pciResizableBarEnabledReturnCode = KmdSysman::KmdSysmanSuccess;
void getPciProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) override {
uint8_t *pBuffer = reinterpret_cast<uint8_t *>(pResponse);
pBuffer += sizeof(KmdSysman::GfxSysmanReqHeaderOut);
KmdSysman::PciDomainsType domain = static_cast<KmdSysman::PciDomainsType>(pRequest->inCommandParam);
switch (pRequest->inRequestId) {
case KmdSysman::Requests::Pci::Domain: {
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
*pValue = mockDomain[domain];
pResponse->outReturnCode = pciDomainReturnCode;
pResponse->outDataSize = sizeof(uint32_t);
} break;
case KmdSysman::Requests::Pci::Bus: {
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
*pValue = mockBus[domain];
pResponse->outReturnCode = pciBusReturnCode;
pResponse->outDataSize = sizeof(uint32_t);
} break;
case KmdSysman::Requests::Pci::Device: {
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
*pValue = mockDevice[domain];
pResponse->outReturnCode = pciDeviceReturnCode;
pResponse->outDataSize = sizeof(uint32_t);
} break;
case KmdSysman::Requests::Pci::Function: {
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
*pValue = mockFunction[domain];
pResponse->outReturnCode = pciFunctionReturnCode;
pResponse->outDataSize = sizeof(uint32_t);
} break;
case KmdSysman::Requests::Pci::MaxLinkSpeed: {
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
*pValue = mockMaxLinkSpeed[domain];
pResponse->outReturnCode = pciMaxLinkSpeedReturnCode;
pResponse->outDataSize = sizeof(uint32_t);
} break;
case KmdSysman::Requests::Pci::MaxLinkWidth: {
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
*pValue = mockMaxLinkWidth[domain];
pResponse->outReturnCode = pciMaxLinkWidthReturnCode;
pResponse->outDataSize = sizeof(uint32_t);
} break;
case KmdSysman::Requests::Pci::CurrentLinkSpeed: {
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
*pValue = mockCurrentLinkSpeed[domain];
pResponse->outReturnCode = pciCurrentLinkSpeedReturnCode;
pResponse->outDataSize = sizeof(uint32_t);
} break;
case KmdSysman::Requests::Pci::CurrentLinkWidth: {
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
*pValue = mockCurrentLinkWidth[domain];
pResponse->outReturnCode = pciCurrentLinkWidthReturnCode;
pResponse->outDataSize = sizeof(uint32_t);
} break;
case KmdSysman::Requests::Pci::ResizableBarSupported: {
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
*pValue = mockResizableBarSupported[domain];
pResponse->outReturnCode = pciResizableBarSupportedReturnCode;
pResponse->outDataSize = sizeof(uint32_t);
} break;
case KmdSysman::Requests::Pci::ResizableBarEnabled: {
uint32_t *pValue = reinterpret_cast<uint32_t *>(pBuffer);
*pValue = mockResizableBarEnabled[domain];
pResponse->outReturnCode = pciResizableBarEnabledReturnCode;
pResponse->outDataSize = sizeof(uint32_t);
} break;
default: {
pResponse->outDataSize = 0;
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
} break;
}
}
void setPciProperty(KmdSysman::GfxSysmanReqHeaderIn *pRequest, KmdSysman::GfxSysmanReqHeaderOut *pResponse) override {
uint8_t *pBuffer = reinterpret_cast<uint8_t *>(pRequest);
pBuffer += sizeof(KmdSysman::GfxSysmanReqHeaderIn);
pResponse->outDataSize = 0;
pResponse->outReturnCode = KmdSysman::KmdSysmanFail;
}
};
} // namespace ult
} // namespace Sysman
} // namespace L0

View File

@@ -0,0 +1,287 @@
/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/sysman/source/sysman_const.h"
#include "level_zero/sysman/test/unit_tests/sources/windows/mock_sysman_fixture.h"
#include "mock_pci.h"
namespace L0 {
namespace Sysman {
namespace ult {
class SysmanDevicePciFixture : public SysmanDeviceFixture {
protected:
std::unique_ptr<PciKmdSysManager> pKmdSysManager = nullptr;
KmdSysManager *pOriginalKmdSysManager = nullptr;
void SetUp() override {
SysmanDeviceFixture::SetUp();
pKmdSysManager.reset(new PciKmdSysManager);
pOriginalKmdSysManager = pWddmSysmanImp->pKmdSysManager;
pWddmSysmanImp->pKmdSysManager = pKmdSysManager.get();
delete pSysmanDeviceImp->pPci;
pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = false;
pSysmanDeviceImp->pPci = new PciImp(pOsSysman);
if (pSysmanDeviceImp->pPci) {
pSysmanDeviceImp->pPci->init();
}
}
void TearDown() override {
pWddmSysmanImp->pKmdSysManager = pOriginalKmdSysManager;
SysmanDeviceFixture::TearDown();
}
void setLocalMemorySupportedAndReinit(bool supported) {
delete pSysmanDeviceImp->pPci;
pSysmanDeviceImp->getRootDeviceEnvironment().getMutableHardwareInfo()->capabilityTable.isIntegratedDevice = !supported;
pSysmanDeviceImp->pPci = new PciImp(pOsSysman);
if (pSysmanDeviceImp->pPci) {
pSysmanDeviceImp->pPci->init();
}
}
};
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetPropertiesWithLocalMemoryThenVerifyzetSysmanPciGetPropertiesCallSucceeds) {
setLocalMemorySupportedAndReinit(true);
zes_pci_properties_t properties;
ze_result_t result = zesDevicePciGetProperties(pSysmanDevice->toHandle(), &properties);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(properties.address.domain, pKmdSysManager->mockDomain[KmdSysman::PciDomainsType::PciRootPort]);
EXPECT_EQ(properties.address.bus, pKmdSysManager->mockBus[KmdSysman::PciDomainsType::PciRootPort]);
EXPECT_EQ(properties.address.device, pKmdSysManager->mockDevice[KmdSysman::PciDomainsType::PciRootPort]);
EXPECT_EQ(properties.address.function, pKmdSysManager->mockFunction[KmdSysman::PciDomainsType::PciRootPort]);
EXPECT_EQ(properties.maxSpeed.gen, pKmdSysManager->mockMaxLinkSpeed[KmdSysman::PciDomainsType::PciRootPort]);
EXPECT_EQ(properties.maxSpeed.width, pKmdSysManager->mockMaxLinkWidth[KmdSysman::PciDomainsType::PciRootPort]);
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallinggetPciBdfAndkmdSysmanCallFailsThenUnknownValuesArereturned) {
setLocalMemorySupportedAndReinit(true);
pKmdSysManager->pciBusReturnCode = KmdSysman::KmdSysmanFail;
pKmdSysManager->pciDomainReturnCode = KmdSysman::KmdSysmanFail;
pKmdSysManager->pciDeviceReturnCode = KmdSysman::KmdSysmanFail;
pKmdSysManager->pciFunctionReturnCode = KmdSysman::KmdSysmanFail;
zes_pci_properties_t properties = {};
WddmPciImp *pPciImp = new WddmPciImp(pOsSysman);
EXPECT_EQ(ZE_RESULT_SUCCESS, pPciImp->getPciBdf(properties));
EXPECT_EQ(0, properties.address.domain);
EXPECT_EQ(0, properties.address.bus);
EXPECT_EQ(0, properties.address.device);
EXPECT_EQ(0, properties.address.function);
delete pPciImp;
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetProLocalMemoryThenVerifyzetSysmanPciGetPropertiesCallSucceeds) {
setLocalMemorySupportedAndReinit(true);
zes_pci_properties_t properties;
ze_result_t result = zesDevicePciGetProperties(pSysmanDevice->toHandle(), &properties);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(properties.address.domain, pKmdSysManager->mockDomain[KmdSysman::PciDomainsType::PciRootPort]);
EXPECT_EQ(properties.address.bus, pKmdSysManager->mockBus[KmdSysman::PciDomainsType::PciRootPort]);
EXPECT_EQ(properties.address.device, pKmdSysManager->mockDevice[KmdSysman::PciDomainsType::PciRootPort]);
EXPECT_EQ(properties.address.function, pKmdSysManager->mockFunction[KmdSysman::PciDomainsType::PciRootPort]);
EXPECT_EQ(properties.maxSpeed.gen, pKmdSysManager->mockMaxLinkSpeed[KmdSysman::PciDomainsType::PciRootPort]);
EXPECT_EQ(properties.maxSpeed.width, pKmdSysManager->mockMaxLinkWidth[KmdSysman::PciDomainsType::PciRootPort]);
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingGetPciBdfAndRequestMultpileFailsThenFailureIsReturned) {
setLocalMemorySupportedAndReinit(true);
pKmdSysManager->mockRequestMultiple = true;
pKmdSysManager->mockRequestMultipleResult = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
zes_pci_properties_t properties = {};
WddmPciImp *pPciImp = new WddmPciImp(pOsSysman);
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pPciImp->getPciBdf(properties));
delete pPciImp;
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenGettingMaxLinkSpeedAndMaxLinkWidthAndRequestSingleFailsThenUnknownValuesAreReturned) {
setLocalMemorySupportedAndReinit(true);
pKmdSysManager->mockRequestSingle = true;
pKmdSysManager->mockRequestSingleResult = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
double maxLinkSpeed;
int32_t maxLinkWidth;
WddmPciImp *pPciImp = new WddmPciImp(pOsSysman);
pPciImp->getMaxLinkCaps(maxLinkSpeed, maxLinkWidth);
EXPECT_DOUBLE_EQ(0.0, maxLinkSpeed);
EXPECT_EQ(-1, maxLinkWidth);
delete pPciImp;
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceeds) {
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(pSysmanDevice->toHandle(), &count, nullptr));
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2Extension) {
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(pSysmanDevice->toHandle(), &count, nullptr));
EXPECT_NE(count, 0u);
std::vector<zes_pci_bar_properties_t> pBarProps(count);
std::vector<zes_pci_bar_properties_1_2_t> props1_2(count);
for (uint32_t i = 0; i < count; i++) {
props1_2[i].stype = ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2;
props1_2[i].pNext = nullptr;
pBarProps[i].stype = ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES;
pBarProps[i].pNext = static_cast<void *>(&props1_2[i]);
}
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(pSysmanDevice->toHandle(), &count, pBarProps.data()));
for (uint32_t i = 0; i < count; i++) {
EXPECT_EQ(pBarProps[i].stype, zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES);
EXPECT_EQ(props1_2[i].stype, zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES_1_2);
EXPECT_EQ(props1_2[i].resizableBarSupported, true);
EXPECT_EQ(props1_2[i].resizableBarEnabled, true);
}
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingPciGetBarsThenVerifyAPICallSucceedsWith1_2ExtensionWithNullPtr) {
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(pSysmanDevice->toHandle(), &count, nullptr));
EXPECT_NE(count, 0u);
zes_pci_bar_properties_t *pBarProps = new zes_pci_bar_properties_t[count];
for (uint32_t i = 0; i < count; i++) {
pBarProps[i].pNext = nullptr;
pBarProps[i].stype = zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES;
}
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(pSysmanDevice->toHandle(), &count, pBarProps));
delete[] pBarProps;
pBarProps = nullptr;
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetBarsThenVerifyzetSysmanPciGetBarsCallSucceedsWith1_2ExtensionWrongType) {
uint32_t count = 0;
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(pSysmanDevice->toHandle(), &count, nullptr));
EXPECT_NE(count, 0u);
std::vector<zes_pci_bar_properties_t> pBarProps(count);
std::vector<zes_pci_bar_properties_1_2_t> props1_2(count);
for (uint32_t i = 0; i < count; i++) {
props1_2[i].stype = ZES_STRUCTURE_TYPE_PCI_STATE;
props1_2[i].pNext = nullptr;
pBarProps[i].stype = ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES;
pBarProps[i].pNext = static_cast<void *>(&props1_2[i]);
}
EXPECT_EQ(ZE_RESULT_SUCCESS, zesDevicePciGetBars(pSysmanDevice->toHandle(), &count, pBarProps.data()));
for (uint32_t i = 0; i < count; i++) {
EXPECT_EQ(pBarProps[i].stype, zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_BAR_PROPERTIES);
EXPECT_LE(pBarProps[i].type, ZES_PCI_BAR_TYPE_MEM);
EXPECT_EQ(props1_2[i].stype, zes_structure_type_t::ZES_STRUCTURE_TYPE_PCI_STATE);
}
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetStatsWithLocalMemoryThenVerifyzetSysmanPciGetBarsCallSucceeds) {
setLocalMemorySupportedAndReinit(true);
zes_pci_state_t state;
ze_result_t result = zesDevicePciGetState(pSysmanDevice->toHandle(), &state);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(state.speed.gen, pKmdSysManager->mockCurrentLinkSpeed[KmdSysman::PciDomainsType::PciRootPort]);
EXPECT_EQ(state.speed.width, pKmdSysManager->mockCurrentLinkWidth[KmdSysman::PciDomainsType::PciRootPort]);
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetStatsWithNoLocalMemoryThenVerifyzetSysmanPciGetBarsCallSucceeds) {
setLocalMemorySupportedAndReinit(false);
zes_pci_state_t state;
ze_result_t result = zesDevicePciGetState(pSysmanDevice->toHandle(), &state);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(state.speed.gen, pKmdSysManager->mockCurrentLinkSpeed[KmdSysman::PciDomainsType::PciCurrentDevice]);
EXPECT_EQ(state.speed.width, pKmdSysManager->mockCurrentLinkWidth[KmdSysman::PciDomainsType::PciCurrentDevice]);
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetStateThenValidCurrentMaxBandwidthIsReturned) {
setLocalMemorySupportedAndReinit(true);
zes_pci_state_t state = {};
ze_result_t result = zesDevicePciGetState(pSysmanDevice->toHandle(), &state);
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
EXPECT_EQ(state.speed.maxBandwidth, pKmdSysManager->mockCurrentMaxBandwidth[KmdSysman::PciDomainsType::PciRootPort]);
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingGetPciStateAndRequestMultipleFailsThenFailureIsReturned) {
setLocalMemorySupportedAndReinit(true);
pKmdSysManager->mockRequestMultiple = true;
pKmdSysManager->mockRequestMultipleResult = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
zes_pci_state_t pState = {};
WddmPciImp *pPciImp = new WddmPciImp(pOsSysman);
EXPECT_EQ(ZE_RESULT_ERROR_UNSUPPORTED_FEATURE, pPciImp->getState(&pState));
delete pPciImp;
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenCallingGetPciStateAndKmdSysmanCallFailsThenUnknownValuesAreReturned) {
setLocalMemorySupportedAndReinit(true);
pKmdSysManager->pciCurrentLinkSpeedReturnCode = KmdSysman::KmdSysmanFail;
pKmdSysManager->pciCurrentLinkWidthReturnCode = KmdSysman::KmdSysmanFail;
zes_pci_state_t pState = {};
pState.speed.gen = -1;
pState.speed.width = -1;
WddmPciImp *pPciImp = new WddmPciImp(pOsSysman);
EXPECT_EQ(ZE_RESULT_SUCCESS, pPciImp->getState(&pState));
EXPECT_EQ(pState.speed.gen, -1);
EXPECT_EQ(pState.speed.gen, -1);
delete pPciImp;
}
TEST_F(SysmanDevicePciFixture, WhenConvertingLinkSpeedThenResultIsCorrect) {
for (int32_t i = PciGenerations::PciGen1; i <= PciGenerations::PciGen5; i++) {
double speed = convertPciGenToLinkSpeed(i);
int32_t gen = convertLinkSpeedToPciGen(speed);
EXPECT_EQ(i, gen);
}
EXPECT_EQ(-1, convertLinkSpeedToPciGen(0.0));
EXPECT_EQ(0.0, convertPciGenToLinkSpeed(0));
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenGettingResizableBarSupportAndRequestSingleFailsThenUnknownValuesAreReturned) {
setLocalMemorySupportedAndReinit(true);
pKmdSysManager->mockRequestSingle = true;
pKmdSysManager->mockRequestSingleResult = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
WddmPciImp *pPciImp = new WddmPciImp(pOsSysman);
EXPECT_EQ(false, pPciImp->resizableBarSupported());
delete pPciImp;
}
TEST_F(SysmanDevicePciFixture, GivenValidSysmanHandleWhenGettingResizableBarEnabledAndRequestSingleFailsThenUnknownValuesAreReturned) {
setLocalMemorySupportedAndReinit(true);
pKmdSysManager->mockRequestSingle = true;
pKmdSysManager->mockRequestSingleResult = ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
uint32_t barIndex = 1;
WddmPciImp *pPciImp = new WddmPciImp(pOsSysman);
EXPECT_EQ(false, pPciImp->resizableBarEnabled(barIndex));
delete pPciImp;
}
} // namespace ult
} // namespace Sysman
} // namespace L0