File: sys_calls_linux_ult.cpp

package info (click to toggle)
intel-compute-runtime 20.44.18297-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 34,780 kB
  • sloc: cpp: 379,729; lisp: 4,931; python: 299; sh: 196; makefile: 8
file content (59 lines) | stat: -rw-r--r-- 1,525 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * Copyright (C) 2020 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/source/os_interface/linux/sys_calls.h"

#include "drm/i915_drm.h"

#include <cstdint>
#include <cstdio>
#include <cstring>
#include <sys/ioctl.h>

namespace NEO {
namespace SysCalls {
uint32_t closeFuncCalled = 0u;
int closeFuncArgPassed = 0;
constexpr int fakeFileDescriptor = 123;
uint32_t vmId = 0;

int close(int fileDescriptor) {
    closeFuncCalled++;
    closeFuncArgPassed = fileDescriptor;
    return 0;
}

int open(const char *file, int flags) {
    if (strcmp(file, "/dev/dri/by-path/pci-0000:invalid-render") == 0) {
        return 0;
    }
    if (strcmp(file, "./test_files/linux/by-path/pci-0000-device-render") == 0) {
        return fakeFileDescriptor;
    }
    return 0;
}
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");
        }
    }
    if (request == DRM_IOCTL_I915_GEM_VM_CREATE) {
        auto control = static_cast<drm_i915_gem_vm_control *>(arg);
        control->vm_id = ++vmId;
        return 0;
    }
    if (request == DRM_IOCTL_I915_GEM_VM_DESTROY) {
        auto control = static_cast<drm_i915_gem_vm_control *>(arg);
        vmId--;
        return (control->vm_id > 0) ? 0 : -1;
    }
    return 0;
}
} // namespace SysCalls
} // namespace NEO