PCI driver fix for Discrete devices

Change-Id: I91e444c88b5e72463c7f181ece535da4150a2665
Signed-off-by: Vilvaraj, T J Vivek <t.j.vivek.vilvaraj@intel.com>
This commit is contained in:
T.J. Vivek Vilvaraj
2020-07-03 05:41:51 +00:00
committed by sys_ocldev
parent fb7082f0f8
commit 6224db771a
11 changed files with 294 additions and 43 deletions

View File

@@ -22,6 +22,18 @@ constexpr uint8_t maxPciBars = 6;
// Linux kernel would report 255 link width, as an indication of unknown.
constexpr uint32_t unknownPcieLinkWidth = 255u;
std::string changeDirNLevelsUp(std::string realRootPath, uint8_t nLevel) {
size_t loc;
while (nLevel > 0) {
loc = realRootPath.find_last_of('/');
realRootPath = realRootPath.substr(0, loc);
nLevel--;
}
return realRootPath;
}
void LinuxPciImp::setLmemSupport(bool val) {
isLmemSupported = val;
}
ze_result_t LinuxPciImp::getPciBdf(std::string &bdf) {
std::string bdfDir;
ze_result_t result = pSysfsAccess->readSymLink(deviceDir, bdfDir);
@@ -34,28 +46,65 @@ ze_result_t LinuxPciImp::getPciBdf(std::string &bdf) {
}
ze_result_t LinuxPciImp::getMaxLinkSpeed(double &maxLinkSpeed) {
double val;
ze_result_t result = pSysfsAccess->read(maxLinkSpeedFile, val);
if (ZE_RESULT_SUCCESS != result) {
maxLinkSpeed = 0;
return result;
ze_result_t result;
if (isLmemSupported) {
std::string rootPortPath;
std::string realRootPath;
result = pSysfsAccess->getRealPath(deviceDir, realRootPath);
// we need to change the absolute path to two levels up to get actual
// values of speed and width at the Discrete card's root port.
// the root port is always at a fixed distance as defined in HW
rootPortPath = changeDirNLevelsUp(realRootPath, 2);
if (ZE_RESULT_SUCCESS != result) {
maxLinkSpeed = 0;
return result;
}
result = pfsAccess->read(rootPortPath + '/' + "max_link_speed", maxLinkSpeed);
if (ZE_RESULT_SUCCESS != result) {
maxLinkSpeed = 0;
return result;
}
} else {
result = pSysfsAccess->read(maxLinkSpeedFile, maxLinkSpeed);
if (ZE_RESULT_SUCCESS != result) {
maxLinkSpeed = 0;
return result;
}
}
maxLinkSpeed = val;
return ZE_RESULT_SUCCESS;
}
ze_result_t LinuxPciImp::getMaxLinkWidth(uint32_t &maxLinkwidth) {
int intVal;
ze_result_t result = pSysfsAccess->read(maxLinkWidthFile, intVal);
if (ZE_RESULT_SUCCESS != result) {
return result;
ze_result_t result;
if (isLmemSupported) {
std::string rootPortPath;
std::string realRootPath;
result = pSysfsAccess->getRealPath(deviceDir, realRootPath);
// we need to change the absolute path to two levels up to get actual
// values of speed and width at the Discrete card's root port.
// the root port is always at a fixed distance as defined in HW
rootPortPath = changeDirNLevelsUp(realRootPath, 2);
if (ZE_RESULT_SUCCESS != result) {
maxLinkwidth = 0;
return result;
}
result = pfsAccess->read(rootPortPath + '/' + "max_link_width", maxLinkwidth);
if (ZE_RESULT_SUCCESS != result) {
maxLinkwidth = 0;
return result;
}
if (maxLinkwidth == static_cast<uint32_t>(unknownPcieLinkWidth)) {
maxLinkwidth = 0;
}
} else {
result = pSysfsAccess->read(maxLinkWidthFile, maxLinkwidth);
if (ZE_RESULT_SUCCESS != result) {
return result;
}
if (maxLinkwidth == static_cast<uint32_t>(unknownPcieLinkWidth)) {
maxLinkwidth = 0;
}
}
if (intVal == static_cast<int>(unknownPcieLinkWidth)) {
intVal = 0;
}
maxLinkwidth = intVal;
return ZE_RESULT_SUCCESS;
}
@@ -129,8 +178,8 @@ ze_result_t LinuxPciImp::initializeBarProperties(std::vector<zet_pci_bar_propert
LinuxPciImp::LinuxPciImp(OsSysman *pOsSysman) {
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
pSysfsAccess = &pLinuxSysmanImp->getSysfsAccess();
pfsAccess = &pLinuxSysmanImp->getFsAccess();
}
OsPci *OsPci::create(OsSysman *pOsSysman) {

View File

@@ -13,6 +13,7 @@
namespace L0 {
class SysfsAccess;
class FsAccess;
class LinuxPciImp : public OsPci, NEO::NonCopyableOrMovableClass {
public:
@@ -20,6 +21,7 @@ class LinuxPciImp : public OsPci, NEO::NonCopyableOrMovableClass {
ze_result_t getMaxLinkSpeed(double &maxLinkSpeed) override;
ze_result_t getMaxLinkWidth(uint32_t &maxLinkwidth) override;
ze_result_t getLinkGen(uint32_t &linkGen) override;
void setLmemSupport(bool val) override;
ze_result_t initializeBarProperties(std::vector<zet_pci_bar_properties_t *> &pBarProperties) override;
LinuxPciImp() = default;
LinuxPciImp(OsSysman *pOsSysman);
@@ -27,12 +29,14 @@ class LinuxPciImp : public OsPci, NEO::NonCopyableOrMovableClass {
protected:
SysfsAccess *pSysfsAccess = nullptr;
FsAccess *pfsAccess = nullptr;
private:
static const std::string deviceDir;
static const std::string resourceFile;
static const std::string maxLinkSpeedFile;
static const std::string maxLinkWidthFile;
bool isLmemSupported = false;
};
} // namespace L0

View File

@@ -21,6 +21,7 @@ class OsPci {
virtual ze_result_t getMaxLinkSpeed(double &maxLinkSpeed) = 0;
virtual ze_result_t getMaxLinkWidth(uint32_t &maxLinkWidth) = 0;
virtual ze_result_t getLinkGen(uint32_t &linkGen) = 0;
virtual void setLmemSupport(bool val) = 0;
virtual ze_result_t initializeBarProperties(std::vector<zet_pci_bar_properties_t *> &pBarProperties) = 0;
static OsPci *create(OsSysman *pOsSysman);
virtual ~OsPci() = default;

View File

@@ -65,6 +65,8 @@ void PciImp::init() {
pOsPci = OsPci::create(pOsSysman);
}
UNRECOVERABLE_IF(nullptr == pOsPci);
Device *device = L0::Device::fromHandle(hCoreDevice);
pOsPci->setLmemSupport(device->getDriverHandle()->getMemoryManager()->isLocalMemorySupported(device->getRootDeviceIndex()));
std::string bdf;
pOsPci->getPciBdf(bdf);
if (bdf.empty()) {

View File

@@ -7,7 +7,9 @@
#pragma once
#include "shared/source/helpers/non_copyable_or_moveable.h"
#include "shared/source/memory_manager/memory_manager.h"
#include "level_zero/core/source/device/device.h"
#include <level_zero/zet_api.h>
#include "os_pci.h"
@@ -24,9 +26,13 @@ class PciImp : public Pci, NEO::NonCopyableOrMovableClass {
ze_result_t pciGetInitializedBars(uint32_t *pCount, zet_pci_bar_properties_t *pProperties) override;
PciImp() = default;
PciImp(OsSysman *pOsSysman) : pOsSysman(pOsSysman) { pOsPci = nullptr; };
PciImp(OsSysman *pOsSysman, ze_device_handle_t hDevice) : pOsSysman(pOsSysman) {
pOsPci = nullptr;
hCoreDevice = hDevice;
};
~PciImp() override;
OsPci *pOsPci = nullptr;
ze_device_handle_t hCoreDevice = {};
private:
OsSysman *pOsSysman = nullptr;

View File

@@ -16,6 +16,7 @@ class WddmPciImp : public OsPci {
ze_result_t getMaxLinkSpeed(double &maxLinkSpeed) override;
ze_result_t getMaxLinkWidth(uint32_t &maxLinkwidth) override;
ze_result_t getLinkGen(uint32_t &linkGen) override;
void setLmemSupport(bool val) override;
ze_result_t initializeBarProperties(std::vector<zet_pci_bar_properties_t *> &pBarProperties) override;
~WddmPciImp() override = default;
};
@@ -36,6 +37,8 @@ ze_result_t WddmPciImp::getLinkGen(uint32_t &linkGen) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
void WddmPciImp::setLmemSupport(bool val) {}
ze_result_t WddmPciImp::initializeBarProperties(std::vector<zet_pci_bar_properties_t *> &pBarProperties) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}