2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2021-05-17 02:51:16 +08:00
|
|
|
* Copyright (C) 2020-2021 Intel Corporation
|
2018-09-18 15:11:08 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-03-16 19:41:25 +08:00
|
|
|
#include "shared/source/os_interface/windows/driver_info_windows.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/windows/debug_registry_reader.h"
|
|
|
|
#include "shared/source/os_interface/windows/os_interface.h"
|
2020-03-17 18:55:53 +08:00
|
|
|
#include "shared/source/os_interface/windows/sys_calls.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/windows/wddm/wddm.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-03-17 18:55:53 +08:00
|
|
|
std::string getCurrentLibraryPath() {
|
|
|
|
std::string returnValue;
|
|
|
|
WCHAR pathW[MAX_PATH];
|
|
|
|
char path[MAX_PATH];
|
|
|
|
HMODULE handle = NULL;
|
|
|
|
|
|
|
|
auto status = NEO::SysCalls::getModuleHandle(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
|
|
|
|
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
|
|
|
reinterpret_cast<LPCWSTR>(&getCurrentLibraryPath), &handle);
|
|
|
|
if (status != 0) {
|
|
|
|
|
|
|
|
status = NEO::SysCalls::getModuleFileName(handle, pathW, sizeof(pathW));
|
|
|
|
if (status != 0) {
|
|
|
|
std::wcstombs(path, pathW, MAX_PATH);
|
|
|
|
returnValue.append(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-11-05 20:40:03 +08:00
|
|
|
DriverInfo *DriverInfo::create(const HardwareInfo *hwInfo, const OSInterface *osInterface) {
|
|
|
|
if (osInterface == nullptr) {
|
|
|
|
return nullptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2020-11-05 20:40:03 +08:00
|
|
|
auto osInterfaceImpl = osInterface->get();
|
|
|
|
UNRECOVERABLE_IF(osInterfaceImpl == nullptr);
|
|
|
|
|
|
|
|
auto wddm = osInterfaceImpl->getWddm();
|
|
|
|
UNRECOVERABLE_IF(wddm == nullptr);
|
|
|
|
|
|
|
|
return new DriverInfoWindows(wddm->getDeviceRegistryPath(), wddm->getPciBusInfo());
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
2020-11-05 20:40:03 +08:00
|
|
|
DriverInfoWindows::DriverInfoWindows(const std::string &fullPath, const PhysicalDevicePciBusInfo &pciBusInfo)
|
|
|
|
: path(DriverInfoWindows::trimRegistryKey(fullPath)), registryReader(createRegistryReaderFunc(path)) {
|
|
|
|
this->pciBusInfo = pciBusInfo;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2021-05-20 04:12:09 +08:00
|
|
|
DriverInfoWindows::~DriverInfoWindows() = default;
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
std::string DriverInfoWindows::trimRegistryKey(std::string path) {
|
|
|
|
std::string prefix("\\REGISTRY\\MACHINE\\");
|
|
|
|
auto pos = prefix.find(prefix);
|
|
|
|
if (pos != std::string::npos)
|
|
|
|
path.erase(pos, prefix.length());
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string DriverInfoWindows::getDeviceName(std::string defaultName) {
|
|
|
|
return registryReader.get()->getSetting("HardwareInformation.AdapterString", defaultName);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string DriverInfoWindows::getVersion(std::string defaultVersion) {
|
|
|
|
return registryReader.get()->getSetting("DriverVersion", defaultVersion);
|
|
|
|
};
|
2020-03-17 18:55:53 +08:00
|
|
|
|
|
|
|
bool DriverInfoWindows::isCompatibleDriverStore() const {
|
|
|
|
auto currentLibraryPath = getCurrentLibraryPath();
|
2020-08-24 07:55:47 +08:00
|
|
|
auto openclDriverName = registryReader.get()->getSetting("OpenCLDriverName", std::string{});
|
|
|
|
if (openclDriverName.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-17 18:55:53 +08:00
|
|
|
auto driverStorePath = registryReader.get()->getSetting("DriverStorePathForComputeRuntime", currentLibraryPath);
|
|
|
|
return currentLibraryPath.find(driverStorePath.c_str()) == 0u;
|
|
|
|
}
|
|
|
|
|
2021-05-20 04:12:09 +08:00
|
|
|
bool isCompatibleDriverStore(std::string &&deviceRegistryPath) {
|
2020-11-05 20:40:03 +08:00
|
|
|
DriverInfoWindows driverInfo(deviceRegistryPath, PhysicalDevicePciBusInfo(PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue));
|
2021-05-20 04:12:09 +08:00
|
|
|
return driverInfo.isCompatibleDriverStore();
|
|
|
|
}
|
|
|
|
|
2020-03-17 18:55:53 +08:00
|
|
|
decltype(DriverInfoWindows::createRegistryReaderFunc) DriverInfoWindows::createRegistryReaderFunc = [](const std::string ®istryPath) -> std::unique_ptr<SettingsReader> {
|
|
|
|
return std::make_unique<RegistryReader>(false, registryPath);
|
|
|
|
};
|
2020-03-18 22:19:03 +08:00
|
|
|
|
|
|
|
bool DriverInfoWindows::getMediaSharingSupport() {
|
|
|
|
return registryReader.get()->getSetting(is64bit ? "UserModeDriverName" : "UserModeDriverNameWOW", std::string("")) != "<>";
|
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|