Move Pci bdf parsing to os specific layer
Related-To: LOCI-2879 Signed-off-by: Mayank Raghuwanshi <mayank.raghuwanshi@intel.com>
This commit is contained in:
parent
45100d15ff
commit
fac75222a3
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include "level_zero/tools/source/sysman/pci/linux/os_pci_imp.h"
|
||||
|
||||
#include "shared/source/utilities/directory.h"
|
||||
|
||||
#include "level_zero/tools/source/sysman/linux/fs_access.h"
|
||||
#include "level_zero/tools/source/sysman/sysman_const.h"
|
||||
|
||||
|
@ -27,14 +29,21 @@ ze_result_t LinuxPciImp::getProperties(zes_pci_properties_t *properties) {
|
|||
properties->haveReplayCounters = false;
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
ze_result_t LinuxPciImp::getPciBdf(std::string &bdf) {
|
||||
ze_result_t LinuxPciImp::getPciBdf(zes_pci_properties_t &pciProperties) {
|
||||
std::string bdfDir;
|
||||
ze_result_t result = pSysfsAccess->readSymLink(deviceDir, bdfDir);
|
||||
if (ZE_RESULT_SUCCESS != result) {
|
||||
return result;
|
||||
}
|
||||
const auto loc = bdfDir.find_last_of('/');
|
||||
bdf = bdfDir.substr(loc + 1);
|
||||
std::string bdf = bdfDir.substr(loc + 1);
|
||||
uint16_t domain = 0;
|
||||
uint8_t bus = 0, device = 0, function = 0;
|
||||
NEO::parseBdfString(bdf.c_str(), domain, bus, device, function);
|
||||
pciProperties.address.domain = static_cast<uint32_t>(domain);
|
||||
pciProperties.address.bus = static_cast<uint32_t>(bus);
|
||||
pciProperties.address.device = static_cast<uint32_t>(device);
|
||||
pciProperties.address.function = static_cast<uint32_t>(function);
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
@ -19,7 +19,7 @@ class FsAccess;
|
|||
|
||||
class LinuxPciImp : public OsPci, NEO::NonCopyableOrMovableClass {
|
||||
public:
|
||||
ze_result_t getPciBdf(std::string &bdf) override;
|
||||
ze_result_t getPciBdf(zes_pci_properties_t &pciProperties) override;
|
||||
ze_result_t getMaxLinkSpeed(double &maxLinkSpeed) override;
|
||||
ze_result_t getMaxLinkWidth(int32_t &maxLinkwidth) override;
|
||||
ze_result_t getState(zes_pci_state_t *state) override;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
@ -19,7 +19,7 @@ int32_t convertLinkSpeedToPciGen(double speed);
|
|||
double convertPciGenToLinkSpeed(uint32_t gen);
|
||||
class OsPci {
|
||||
public:
|
||||
virtual ze_result_t getPciBdf(std::string &bdf) = 0;
|
||||
virtual ze_result_t getPciBdf(zes_pci_properties_t &pciProperties) = 0;
|
||||
virtual ze_result_t getMaxLinkSpeed(double &maxLinkSpeed) = 0;
|
||||
virtual ze_result_t getMaxLinkWidth(int32_t &maxLinkWidth) = 0;
|
||||
virtual ze_result_t getState(zes_pci_state_t *state) = 0;
|
||||
|
|
|
@ -125,22 +125,7 @@ void PciImp::pciGetStaticFields() {
|
|||
pOsPci->getProperties(&pciProperties);
|
||||
resizableBarSupported = pOsPci->resizableBarSupported();
|
||||
std::string bdf;
|
||||
pOsPci->getPciBdf(bdf);
|
||||
if (bdf.empty()) {
|
||||
pciProperties.address.domain = 0;
|
||||
pciProperties.address.bus = 0;
|
||||
pciProperties.address.device = 0;
|
||||
pciProperties.address.function = 0;
|
||||
} else {
|
||||
uint16_t domain = -1;
|
||||
uint8_t bus = -1, device = -1, function = -1;
|
||||
NEO::parseBdfString(bdf.c_str(), domain, bus, device, function);
|
||||
pciProperties.address.domain = static_cast<uint32_t>(domain);
|
||||
pciProperties.address.bus = static_cast<uint32_t>(bus);
|
||||
pciProperties.address.device = static_cast<uint32_t>(device);
|
||||
pciProperties.address.function = static_cast<uint32_t>(function);
|
||||
}
|
||||
|
||||
pOsPci->getPciBdf(pciProperties);
|
||||
int32_t maxLinkWidth = -1;
|
||||
int64_t maxBandWidth = -1;
|
||||
double maxLinkSpeed = 0;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
@ -16,7 +16,7 @@ ze_result_t WddmPciImp::getProperties(zes_pci_properties_t *properties) {
|
|||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t WddmPciImp::getPciBdf(std::string &bdf) {
|
||||
ze_result_t WddmPciImp::getPciBdf(zes_pci_properties_t &pciProperties) {
|
||||
uint32_t valueSmall = 0;
|
||||
uint32_t domain = 0, bus = 0, dev = 0, func = 0;
|
||||
std::vector<KmdSysman::RequestProperty> vRequests = {};
|
||||
|
@ -65,7 +65,10 @@ ze_result_t WddmPciImp::getPciBdf(std::string &bdf) {
|
|||
func = valueSmall;
|
||||
}
|
||||
|
||||
bdf = std::to_string(domain) + std::string(":") + std::to_string(bus) + std::string(":") + std::to_string(dev) + std::string(".") + std::to_string(func);
|
||||
pciProperties.address.domain = domain;
|
||||
pciProperties.address.bus = bus;
|
||||
pciProperties.address.device = dev;
|
||||
pciProperties.address.function = func;
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
@ -15,7 +15,7 @@ namespace L0 {
|
|||
class KmdSysManager;
|
||||
class WddmPciImp : public OsPci, NEO::NonCopyableOrMovableClass {
|
||||
public:
|
||||
ze_result_t getPciBdf(std::string &bdf) override;
|
||||
ze_result_t getPciBdf(zes_pci_properties_t &pciProperties) override;
|
||||
ze_result_t getMaxLinkSpeed(double &maxLinkSpeed) override;
|
||||
ze_result_t getMaxLinkWidth(int32_t &maxLinkwidth) override;
|
||||
ze_result_t getState(zes_pci_state_t *state) override;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
@ -114,6 +114,14 @@ struct Mock<PciSysfsAccess> : public PciSysfsAccess {
|
|||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ze_result_t getValStringSymLinkEmpty(const std::string file, std::string &val) {
|
||||
if (file.compare(deviceDir) == 0) {
|
||||
val = "/sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/0000:02:01.0/";
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ze_result_t getValStringSymLink(const std::string file, std::string &val) {
|
||||
if (file.compare(deviceDir) == 0) {
|
||||
val = mockBdf;
|
||||
|
@ -121,6 +129,7 @@ struct Mock<PciSysfsAccess> : public PciSysfsAccess {
|
|||
}
|
||||
return ZE_RESULT_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
ze_result_t getValStringRealPath(const std::string file, std::string &val) {
|
||||
if (file.compare(deviceDir) == 0) {
|
||||
val = mockRealPath;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
* Copyright (C) 2020-2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
@ -274,6 +274,20 @@ TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenSettingLmemSupportAndCallingzetS
|
|||
EXPECT_NE(properties.maxSpeed.maxBandwidth, propertiesBefore.maxSpeed.maxBandwidth);
|
||||
}
|
||||
|
||||
TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenCallingzetSysmanPciGetPropertiesAndBdfStringIsEmptyThenVerifyApiCallSucceeds) {
|
||||
zes_pci_properties_t properties;
|
||||
ON_CALL(*pSysfsAccess.get(), readSymLink(_, _))
|
||||
.WillByDefault(::testing::Invoke(pSysfsAccess.get(), &Mock<PciSysfsAccess>::getValStringSymLinkEmpty));
|
||||
pPciImp->init();
|
||||
|
||||
ze_result_t result = zesDevicePciGetProperties(device, &properties);
|
||||
|
||||
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
|
||||
EXPECT_EQ(properties.address.bus, 0u);
|
||||
EXPECT_EQ(properties.address.device, 0u);
|
||||
EXPECT_EQ(properties.address.function, 0u);
|
||||
}
|
||||
|
||||
TEST_F(ZesPciFixture, GivenValidSysmanHandleWhenGettingPCIWidthThenZeroWidthIsReturnedIfSystemProvidesInvalidValue) {
|
||||
int32_t width = 0;
|
||||
pSysfsAccess->setValInt(maxLinkWidthFile, mockMaxLinkWidthInvalid);
|
||||
|
|
Loading…
Reference in New Issue