Return proper clDevice for given media adapter

Signed-off-by: Kamil Diedrich <kamil.diedrich@intel.com>
This commit is contained in:
Kamil Diedrich
2021-02-17 22:17:01 +01:00
committed by Compute-Runtime-Automation
parent 64d772d366
commit edf066a54b
10 changed files with 328 additions and 41 deletions

View File

@@ -1,10 +1,11 @@
/*
* Copyright (C) 2020 Intel Corporation
* Copyright (C) 2020-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/string.h"
#include "shared/source/os_interface/linux/sys_calls.h"
#include "drm/i915_drm.h"
@@ -12,7 +13,11 @@
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <system_error>
namespace NEO {
namespace SysCalls {
@@ -20,6 +25,8 @@ uint32_t closeFuncCalled = 0u;
int closeFuncArgPassed = 0;
constexpr int fakeFileDescriptor = 123;
uint32_t vmId = 0;
bool makeFakeDevicePath = false;
bool allowFakeDevicePath = false;
int close(int fileDescriptor) {
closeFuncCalled++;
@@ -55,5 +62,35 @@ int ioctl(int fileDescriptor, unsigned long int request, void *arg) {
}
return 0;
}
int access(const char *pathName, int mode) {
if (allowFakeDevicePath || strcmp(pathName, "/sys/dev/char/226:128") == 0) {
return 0;
}
return -1;
}
int readlink(const char *path, char *buf, size_t bufsize) {
if (strcmp(path, "/sys/dev/char/226:128") != 0) {
return -1;
}
constexpr size_t sizeofPath = sizeof("../../devices/pci0000:00/0000:00:02.0/drm/renderD128");
strcpy_s(buf, sizeofPath, "../../devices/pci0000:00/0000:00:02.0/drm/renderD128");
return sizeofPath;
}
int getDevicePath(int deviceFd, char *buf, size_t &bufSize) {
if (deviceFd <= 0) {
return -1;
}
constexpr size_t sizeofPath = sizeof("/sys/dev/char/226:128");
makeFakeDevicePath ? strcpy_s(buf, sizeofPath, "/sys/dev/char/xyzwerq") : strcpy_s(buf, sizeofPath, "/sys/dev/char/226:128");
bufSize = sizeofPath;
return 0;
}
} // namespace SysCalls
} // namespace NEO