2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2023-01-23 22:55:52 +08:00
|
|
|
* Copyright (C) 2020-2023 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"
|
2020-03-17 18:55:53 +08:00
|
|
|
#include "shared/source/os_interface/windows/sys_calls.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2023-01-23 22:55:52 +08:00
|
|
|
#include <algorithm>
|
|
|
|
|
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) {
|
|
|
|
|
2023-06-22 16:53:53 +08:00
|
|
|
status = NEO::SysCalls::getModuleFileName(handle, pathW, MAX_PATH);
|
2020-03-17 18:55:53 +08:00
|
|
|
if (status != 0) {
|
|
|
|
std::wcstombs(path, pathW, MAX_PATH);
|
|
|
|
returnValue.append(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2020-11-05 20:40:03 +08:00
|
|
|
DriverInfoWindows::DriverInfoWindows(const std::string &fullPath, const PhysicalDevicePciBusInfo &pciBusInfo)
|
2022-08-04 19:29:25 +08:00
|
|
|
: DriverInfo(DriverInfoType::WINDOWS), path(DriverInfoWindows::trimRegistryKey(fullPath)), registryReader(createRegistryReaderFunc(path)) {
|
2020-11-05 20:40:03 +08:00
|
|
|
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) {
|
2022-05-10 00:21:21 +08:00
|
|
|
return registryReader->getSetting("HardwareInformation.AdapterString", defaultName);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string DriverInfoWindows::getVersion(std::string defaultVersion) {
|
2022-05-10 00:21:21 +08:00
|
|
|
return registryReader->getSetting("DriverVersion", defaultVersion);
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2020-03-17 18:55:53 +08:00
|
|
|
|
|
|
|
bool DriverInfoWindows::isCompatibleDriverStore() const {
|
2023-10-20 22:34:45 +08:00
|
|
|
auto toLowerAndUnifyDriverStore = [](std::string input) -> std::string {
|
2021-07-02 02:26:01 +08:00
|
|
|
std::transform(input.begin(), input.end(), input.begin(), [](unsigned char c) { return std::tolower(c); });
|
|
|
|
auto hostDriverStorePos = input.find("\\hostdriverstore\\");
|
|
|
|
if (hostDriverStorePos != std::string::npos) {
|
|
|
|
input.erase(hostDriverStorePos + 1, 4);
|
|
|
|
}
|
|
|
|
return input;
|
|
|
|
};
|
|
|
|
auto currentLibraryPath = toLowerAndUnifyDriverStore(getCurrentLibraryPath());
|
2022-05-10 00:21:21 +08:00
|
|
|
auto openclDriverName = registryReader->getSetting("OpenCLDriverName", std::string{});
|
2020-08-24 07:55:47 +08:00
|
|
|
if (openclDriverName.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-05-10 00:21:21 +08:00
|
|
|
auto driverStorePath = toLowerAndUnifyDriverStore(registryReader->getSetting("DriverStorePathForComputeRuntime", currentLibraryPath));
|
2020-03-17 18:55:53 +08:00
|
|
|
return currentLibraryPath.find(driverStorePath.c_str()) == 0u;
|
|
|
|
}
|
|
|
|
|
2021-05-20 04:12:09 +08:00
|
|
|
bool isCompatibleDriverStore(std::string &&deviceRegistryPath) {
|
2022-05-10 01:40:30 +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();
|
|
|
|
}
|
|
|
|
|
2022-08-04 19:29:25 +08:00
|
|
|
bool DriverInfoWindows::containsSetting(const char *setting) {
|
|
|
|
return registryReader->getSetting(setting, std::string("")) != "<>";
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|