Add a method to check drm support
Related-To: NEO-6999 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
parent
fb40e8d1a6
commit
3ac5853e8d
|
@ -246,7 +246,7 @@ int drmVirtualMemoryDestroy(drm_i915_gem_vm_control *control) {
|
|||
}
|
||||
|
||||
int drmVersion(drm_version_t *version) {
|
||||
strcpy(version->name, providedDrmVersion); // NOLINT(clang-analyzer-security.insecureAPI.strcpy)
|
||||
memcpy_s(version->name, version->name_len, providedDrmVersion, strlen(providedDrmVersion) + 1);
|
||||
|
||||
return failOnDrmVersion;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ set(NEO_CORE_OS_INTERFACE_LINUX
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_operations_handler_default.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_operations_handler_default.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_create_multi_host_allocation.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}drm_version.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_wrappers.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_wrappers.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_drm.cpp
|
||||
|
|
|
@ -563,7 +563,7 @@ int Drm::setupHardwareInfo(DeviceDescriptor *device, bool setupFeatureTableAndWo
|
|||
|
||||
void appendHwDeviceId(std::vector<std::unique_ptr<HwDeviceId>> &hwDeviceIds, int fileDescriptor, const char *pciPath) {
|
||||
if (fileDescriptor >= 0) {
|
||||
if (Drm::isi915Version(fileDescriptor)) {
|
||||
if (Drm::isDrmSupported(fileDescriptor)) {
|
||||
hwDeviceIds.push_back(std::make_unique<HwDeviceIdDrm>(fileDescriptor, pciPath));
|
||||
} else {
|
||||
SysCalls::close(fileDescriptor);
|
||||
|
@ -658,7 +658,7 @@ std::vector<std::unique_ptr<HwDeviceId>> Drm::discoverDevices(ExecutionEnvironme
|
|||
return hwDeviceIds;
|
||||
}
|
||||
|
||||
bool Drm::isi915Version(int fileDescriptor) {
|
||||
std::string Drm::getDrmVersion(int fileDescriptor) {
|
||||
drm_version_t version = {};
|
||||
char name[5] = {};
|
||||
version.name = name;
|
||||
|
@ -666,11 +666,11 @@ bool Drm::isi915Version(int fileDescriptor) {
|
|||
|
||||
int ret = SysCalls::ioctl(fileDescriptor, DRM_IOCTL_VERSION, &version);
|
||||
if (ret) {
|
||||
return false;
|
||||
return {};
|
||||
}
|
||||
|
||||
name[4] = '\0';
|
||||
return strcmp(name, "i915") == 0;
|
||||
return std::string(name);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Drm::query(uint32_t queryId, uint32_t queryItemFlags) {
|
||||
|
|
|
@ -202,7 +202,7 @@ class Drm : public DriverModel {
|
|||
return classHandles.size() > 0;
|
||||
}
|
||||
|
||||
static bool isi915Version(int fd);
|
||||
static bool isDrmSupported(int fileDescriptor);
|
||||
|
||||
static Drm *create(std::unique_ptr<HwDeviceIdDrm> &&hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment);
|
||||
static void overrideBindSupport(bool &useVmBind);
|
||||
|
@ -265,6 +265,7 @@ class Drm : public DriverModel {
|
|||
void printIoctlStatistics();
|
||||
void setupIoctlHelper(const PRODUCT_FAMILY productFamily);
|
||||
void queryAndSetVmBindPatIndexProgrammingSupport();
|
||||
static std::string getDrmVersion(int fileDescriptor);
|
||||
|
||||
#pragma pack(1)
|
||||
struct PCIConfig {
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/os_interface/linux/drm_neo.h"
|
||||
|
||||
namespace NEO {
|
||||
bool Drm::isDrmSupported(int fileDescriptor) {
|
||||
auto drmVersion = Drm::getDrmVersion(fileDescriptor);
|
||||
return "i915" == drmVersion;
|
||||
}
|
||||
|
||||
} // namespace NEO
|
|
@ -44,6 +44,7 @@ uint32_t pwriteFuncCalled = 0u;
|
|||
uint32_t mmapFuncCalled = 0u;
|
||||
uint32_t munmapFuncCalled = 0u;
|
||||
bool isInvalidAILTest = false;
|
||||
const char *drmVersion = "i915";
|
||||
|
||||
int (*sysCallsOpen)(const char *pathname, int flags) = nullptr;
|
||||
ssize_t (*sysCallsPread)(int fd, void *buf, size_t count, off_t offset) = nullptr;
|
||||
|
@ -89,7 +90,7 @@ int ioctl(int fileDescriptor, unsigned long int request, void *arg) {
|
|||
if (fileDescriptor == fakeFileDescriptor) {
|
||||
if (request == DRM_IOCTL_VERSION) {
|
||||
auto pVersion = static_cast<drm_version_t *>(arg);
|
||||
snprintf(pVersion->name, pVersion->name_len, "i915");
|
||||
memcpy_s(pVersion->name, pVersion->name_len, drmVersion, strlen(drmVersion) + 1);
|
||||
}
|
||||
}
|
||||
if (request == DRM_IOCTL_I915_GEM_VM_CREATE) {
|
||||
|
|
|
@ -20,5 +20,6 @@ extern int (*sysCallsIoctl)(int fileDescriptor, unsigned long int request, void
|
|||
extern int (*sysCallsPoll)(struct pollfd *pollFd, unsigned long int numberOfFds, int timeout);
|
||||
extern ssize_t (*sysCallsRead)(int fd, void *buf, size_t count);
|
||||
|
||||
extern const char *drmVersion;
|
||||
} // namespace SysCalls
|
||||
} // namespace NEO
|
||||
|
|
|
@ -11,6 +11,7 @@ set(NEO_CORE_OS_INTERFACE_TESTS_LINUX
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/drm_bind_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_command_stream_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_engine_info_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_version_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_mock_impl.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_query_topology_upstream_tests.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/drm_special_heap_test.cpp
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* Copyright (C) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/os_interface/linux/drm_neo.h"
|
||||
#include "shared/test/common/helpers/variable_backup.h"
|
||||
#include "shared/test/common/os_interface/linux/sys_calls_linux_ult.h"
|
||||
#include "shared/test/common/test_macros/test.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
TEST(DrmVersionTest, givenDrmVersionI915WhenCheckingDrmSupportThenSuccessIsReturned) {
|
||||
int fileDescriptor = 123;
|
||||
VariableBackup<const char *> backup(&SysCalls::drmVersion);
|
||||
SysCalls::drmVersion = "i915";
|
||||
EXPECT_TRUE(Drm::isDrmSupported(fileDescriptor));
|
||||
}
|
||||
|
||||
TEST(DrmVersionTest, givenInvalidDrmVersionWhenCheckingDrmSupportThenFalseIsReturned) {
|
||||
int fileDescriptor = 123;
|
||||
VariableBackup<const char *> backup(&SysCalls::drmVersion);
|
||||
SysCalls::drmVersion = "unknown";
|
||||
EXPECT_FALSE(Drm::isDrmSupported(fileDescriptor));
|
||||
}
|
Loading…
Reference in New Issue