2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-02-27 18:39:32 +08:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-07-23 17:45:10 +08:00
|
|
|
#include "runtime/memory_manager/memory_constants.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/os_interface/linux/drm_neo.h"
|
|
|
|
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "drm/i915_drm.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include <fstream>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
// Mock DRM class that responds to DRM_IOCTL_I915_GETPARAMs
|
2018-03-30 15:00:26 +08:00
|
|
|
class DrmMock : public Drm {
|
2017-12-21 07:45:38 +08:00
|
|
|
public:
|
2019-03-19 20:53:55 +08:00
|
|
|
using Drm::memoryInfo;
|
2018-12-11 15:21:56 +08:00
|
|
|
using Drm::preemptionSupported;
|
2019-04-30 19:09:49 +08:00
|
|
|
using Drm::query;
|
2018-12-11 15:21:56 +08:00
|
|
|
|
2018-03-30 15:00:26 +08:00
|
|
|
DrmMock() : Drm(mockFd) {
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-03-30 15:00:26 +08:00
|
|
|
~DrmMock() {
|
2017-12-21 07:45:38 +08:00
|
|
|
if (sysFsDefaultGpuPathToRestore != nullptr) {
|
|
|
|
sysFsDefaultGpuPath = sysFsDefaultGpuPathToRestore;
|
|
|
|
}
|
|
|
|
}
|
2019-04-23 21:42:33 +08:00
|
|
|
|
2019-07-23 17:45:10 +08:00
|
|
|
int ioctl(unsigned long request, void *arg) override;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
void setSysFsDefaultGpuPath(const char *path) {
|
|
|
|
sysFsDefaultGpuPathToRestore = sysFsDefaultGpuPath;
|
|
|
|
sysFsDefaultGpuPath = path;
|
|
|
|
}
|
|
|
|
|
|
|
|
void writeConfigFile(const char *name, int deviceID) {
|
|
|
|
std::ofstream tempfile(name, std::ios::binary);
|
|
|
|
if (tempfile.is_open()) {
|
|
|
|
PCIConfig config;
|
|
|
|
config.DeviceID = deviceID;
|
|
|
|
tempfile.write(reinterpret_cast<char *>(&config), sizeof(config));
|
|
|
|
tempfile.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteConfigFile(const char *name) {
|
|
|
|
std::ofstream tempfile(name);
|
|
|
|
if (tempfile.is_open()) {
|
|
|
|
tempfile.close();
|
|
|
|
remove(name);
|
|
|
|
}
|
|
|
|
}
|
2019-07-23 17:45:10 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
void setFileDescriptor(int fd) {
|
|
|
|
this->fd = fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDeviceID(int deviceId) { this->deviceId = deviceId; }
|
|
|
|
void setDeviceRevID(int revisionId) { this->revisionId = revisionId; }
|
|
|
|
|
2019-04-10 20:32:41 +08:00
|
|
|
static const int mockFd = 33;
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
int StoredEUVal = -1;
|
|
|
|
int StoredSSVal = -1;
|
|
|
|
int StoredDeviceID = 1;
|
|
|
|
int StoredDeviceRevID = 1;
|
|
|
|
int StoredHasPooledEU = 1;
|
|
|
|
int StoredMinEUinPool = 1;
|
|
|
|
int StoredRetVal = 0;
|
|
|
|
int StoredRetValForDeviceID = 0;
|
|
|
|
int StoredRetValForEUVal = 0;
|
|
|
|
int StoredRetValForSSVal = 0;
|
|
|
|
int StoredRetValForDeviceRevID = 0;
|
|
|
|
int StoredRetValForPooledEU = 0;
|
|
|
|
int StoredRetValForMinEUinPool = 0;
|
2019-03-22 13:21:52 +08:00
|
|
|
int StoredPreemptionSupport =
|
|
|
|
I915_SCHEDULER_CAP_ENABLED |
|
|
|
|
I915_SCHEDULER_CAP_PRIORITY |
|
|
|
|
I915_SCHEDULER_CAP_PREEMPTION;
|
2017-12-21 07:45:38 +08:00
|
|
|
int StoredExecSoftPin = 0;
|
|
|
|
uint32_t StoredCtxId = 1;
|
2018-12-11 15:21:56 +08:00
|
|
|
uint32_t receivedDestroyContextId = 0;
|
2019-03-19 20:53:55 +08:00
|
|
|
uint32_t ioctlCallsCount = 0;
|
2018-12-11 15:21:56 +08:00
|
|
|
|
|
|
|
uint32_t receivedContextParamRequestCount = 0;
|
|
|
|
drm_i915_gem_context_param receivedContextParamRequest = {};
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
//DRM_IOCTL_I915_GEM_EXECBUFFER2
|
|
|
|
drm_i915_gem_execbuffer2 execBuffer = {0};
|
|
|
|
|
|
|
|
//DRM_IOCTL_I915_GEM_CREATE
|
|
|
|
__u64 createParamsSize = 0;
|
|
|
|
__u32 createParamsHandle = 0;
|
|
|
|
//DRM_IOCTL_I915_GEM_SET_TILING
|
|
|
|
__u32 setTilingMode = 0;
|
|
|
|
__u32 setTilingHandle = 0;
|
|
|
|
__u32 setTilingStride = 0;
|
|
|
|
//DRM_IOCTL_PRIME_FD_TO_HANDLE
|
|
|
|
__u32 outputHandle = 0;
|
|
|
|
__s32 inputFd = 0;
|
|
|
|
//DRM_IOCTL_I915_GEM_USERPTR
|
|
|
|
__u32 returnHandle = 0;
|
|
|
|
__u64 gpuMemSize = 3u * MemoryConstants::gigaByte;
|
2019-03-13 06:24:30 +08:00
|
|
|
//DRM_IOCTL_I915_GEM_MMAP
|
|
|
|
uint64_t lockedPtr[4];
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-04-23 21:42:33 +08:00
|
|
|
uint64_t storedGTTSize = 1ull << 47;
|
|
|
|
|
2019-07-23 17:45:10 +08:00
|
|
|
virtual int handleRemainingRequests(unsigned long request, void *arg) { return -1; }
|
2019-03-13 09:43:05 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
private:
|
2019-07-23 17:45:10 +08:00
|
|
|
const char *sysFsDefaultGpuPathToRestore = nullptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|