2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2022-01-04 22:48:05 +08:00
|
|
|
* Copyright (C) 2018-2022 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
|
|
|
|
|
2020-07-07 15:34:31 +08:00
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
2020-09-17 19:27:32 +08:00
|
|
|
#include "shared/source/helpers/string.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/linux/drm_neo.h"
|
2022-01-04 22:48:05 +08:00
|
|
|
#include "shared/test/common/helpers/default_hw_info.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <cstdio>
|
|
|
|
#include <fstream>
|
2019-08-21 18:50:47 +08:00
|
|
|
#include <limits.h>
|
2021-06-28 21:17:49 +08:00
|
|
|
#include <map>
|
2017-12-21 07:45:38 +08:00
|
|
|
|
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:
|
2020-11-20 04:43:01 +08:00
|
|
|
using Drm::bindAvailable;
|
2021-01-30 06:23:06 +08:00
|
|
|
using Drm::cacheInfo;
|
2019-08-21 18:50:47 +08:00
|
|
|
using Drm::checkQueueSliceSupport;
|
2020-09-14 19:28:47 +08:00
|
|
|
using Drm::classHandles;
|
2021-01-26 04:43:48 +08:00
|
|
|
using Drm::contextDebugSupported;
|
2021-10-19 10:39:47 +08:00
|
|
|
using Drm::createDrmContextExt;
|
2019-11-09 01:49:54 +08:00
|
|
|
using Drm::engineInfo;
|
2020-12-12 05:28:22 +08:00
|
|
|
using Drm::generateElfUUID;
|
2020-09-08 23:33:33 +08:00
|
|
|
using Drm::generateUUID;
|
2019-08-21 18:50:47 +08:00
|
|
|
using Drm::getQueueSliceCount;
|
2019-03-19 20:53:55 +08:00
|
|
|
using Drm::memoryInfo;
|
2020-02-11 00:05:32 +08:00
|
|
|
using Drm::nonPersistentContextsSupported;
|
2021-11-09 05:42:07 +08:00
|
|
|
using Drm::pageFaultSupported;
|
2018-12-11 15:21:56 +08:00
|
|
|
using Drm::preemptionSupported;
|
2019-04-30 19:09:49 +08:00
|
|
|
using Drm::query;
|
2020-07-15 14:07:53 +08:00
|
|
|
using Drm::requirePerContextVM;
|
2019-08-21 18:50:47 +08:00
|
|
|
using Drm::sliceCountChangeSupported;
|
2020-11-24 23:00:33 +08:00
|
|
|
using Drm::systemInfo;
|
2021-04-27 22:45:13 +08:00
|
|
|
using Drm::translateTopologyInfo;
|
2020-07-07 15:34:31 +08:00
|
|
|
using Drm::virtualMemoryIds;
|
2018-12-11 15:21:56 +08:00
|
|
|
|
2021-05-25 01:34:55 +08:00
|
|
|
DrmMock(int fd, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::make_unique<HwDeviceIdDrm>(fd, ""), rootDeviceEnvironment) {
|
2019-08-21 18:50:47 +08:00
|
|
|
sliceCountChangeSupported = true;
|
2020-11-23 22:31:20 +08:00
|
|
|
|
|
|
|
if (rootDeviceEnvironment.executionEnvironment.isDebuggingEnabled()) {
|
|
|
|
setPerContextVMRequired(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isPerContextVMRequired()) {
|
2020-07-15 14:07:53 +08:00
|
|
|
createVirtualMemoryAddressSpace(HwHelper::getSubDevicesCount(rootDeviceEnvironment.getHardwareInfo()));
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2020-07-07 15:34:31 +08:00
|
|
|
DrmMock(RootDeviceEnvironment &rootDeviceEnvironment) : DrmMock(mockFd, rootDeviceEnvironment) {}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-07-23 17:45:10 +08:00
|
|
|
int ioctl(unsigned long request, void *arg) override;
|
2020-09-10 18:36:44 +08:00
|
|
|
int getErrno() override {
|
|
|
|
if (baseErrno) {
|
|
|
|
return Drm::getErrno();
|
|
|
|
}
|
|
|
|
return errnoRetVal;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
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) {
|
2021-05-25 01:34:55 +08:00
|
|
|
hwDeviceId = std::make_unique<HwDeviceIdDrm>(fd, "");
|
2020-04-09 00:14:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void setPciPath(const char *pciPath) {
|
2021-05-25 01:34:55 +08:00
|
|
|
hwDeviceId = std::make_unique<HwDeviceIdDrm>(getFileDescriptor(), pciPath);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void setDeviceID(int deviceId) { this->deviceId = deviceId; }
|
|
|
|
void setDeviceRevID(int revisionId) { this->revisionId = revisionId; }
|
2020-11-20 04:43:01 +08:00
|
|
|
void setBindAvailable() {
|
|
|
|
this->bindAvailable = true;
|
|
|
|
}
|
2021-01-26 04:43:48 +08:00
|
|
|
void setContextDebugFlag(uint32_t drmContextId) override {
|
|
|
|
passedContextDebugId = drmContextId;
|
|
|
|
return Drm::setContextDebugFlag(drmContextId);
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2021-02-24 01:57:27 +08:00
|
|
|
bool isDebugAttachAvailable() override {
|
|
|
|
if (allowDebugAttachCallBase) {
|
|
|
|
return Drm::isDebugAttachAvailable();
|
|
|
|
}
|
|
|
|
return allowDebugAttach;
|
|
|
|
}
|
|
|
|
|
2021-11-12 06:11:38 +08:00
|
|
|
void queryPageFaultSupport() override {
|
|
|
|
Drm::queryPageFaultSupport();
|
|
|
|
queryPageFaultSupportCalled = true;
|
|
|
|
}
|
|
|
|
|
2019-04-10 20:32:41 +08:00
|
|
|
static const int mockFd = 33;
|
|
|
|
|
2020-06-09 21:51:26 +08:00
|
|
|
bool failRetTopology = false;
|
2020-09-10 18:36:44 +08:00
|
|
|
bool baseErrno = true;
|
|
|
|
int errnoRetVal = 0;
|
2021-06-25 23:33:33 +08:00
|
|
|
int storedEUVal = 8;
|
|
|
|
int storedSSVal = 2;
|
|
|
|
int storedSVal = 1;
|
|
|
|
int storedDeviceID = 1;
|
|
|
|
int storedDeviceRevID = 1;
|
|
|
|
int storedHasPooledEU = 1;
|
|
|
|
int storedMinEUinPool = 1;
|
|
|
|
int storedPersistentContextsSupport = 1;
|
|
|
|
int storedRetVal = 0;
|
|
|
|
int storedRetValForGetGttSize = 0;
|
|
|
|
int storedRetValForGetSSEU = 0;
|
|
|
|
int storedRetValForSetSSEU = 0;
|
|
|
|
int storedRetValForDeviceID = 0;
|
|
|
|
int storedRetValForEUVal = 0;
|
|
|
|
int storedRetValForSSVal = 0;
|
|
|
|
int storedRetValForDeviceRevID = 0;
|
|
|
|
int storedRetValForPooledEU = 0;
|
|
|
|
int storedRetValForMinEUinPool = 0;
|
|
|
|
int storedRetValForPersistant = 0;
|
|
|
|
int storedPreemptionSupport =
|
2019-03-22 13:21:52 +08:00
|
|
|
I915_SCHEDULER_CAP_ENABLED |
|
|
|
|
I915_SCHEDULER_CAP_PRIORITY |
|
|
|
|
I915_SCHEDULER_CAP_PREEMPTION;
|
2021-06-25 23:33:33 +08:00
|
|
|
int storedExecSoftPin = 0;
|
|
|
|
int storedRetValForVmId = 1;
|
|
|
|
int storedCsTimestampFrequency = 1000;
|
2020-06-09 21:51:26 +08:00
|
|
|
|
|
|
|
bool disableSomeTopology = false;
|
2021-02-24 01:57:27 +08:00
|
|
|
bool allowDebugAttach = false;
|
|
|
|
bool allowDebugAttachCallBase = false;
|
2021-06-25 23:33:33 +08:00
|
|
|
uint32_t passedContextDebugId = std::numeric_limits<uint32_t>::max();
|
2020-06-09 21:51:26 +08:00
|
|
|
|
2021-10-19 10:39:47 +08:00
|
|
|
drm_i915_gem_context_create_ext_setparam receivedContextCreateSetParam = {};
|
2021-02-10 23:13:50 +08:00
|
|
|
uint32_t receivedContextCreateFlags = 0;
|
2020-07-07 15:34:31 +08:00
|
|
|
uint32_t receivedCreateContextId = 0;
|
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 = {};
|
2021-09-10 05:16:11 +08:00
|
|
|
uint64_t receivedRecoverableContextValue = std::numeric_limits<uint64_t>::max();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2021-11-12 06:11:38 +08:00
|
|
|
bool queryPageFaultSupportCalled = false;
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
//DRM_IOCTL_I915_GEM_EXECBUFFER2
|
|
|
|
drm_i915_gem_execbuffer2 execBuffer = {0};
|
2020-09-21 19:52:17 +08:00
|
|
|
uint64_t bbFlags;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
//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;
|
2020-10-21 16:50:53 +08:00
|
|
|
int fdToHandleRetVal = 0;
|
|
|
|
//DRM_IOCTL_HANDLE_TO_FD
|
|
|
|
__s32 outputFd = 0;
|
2017-12-21 07:45:38 +08:00
|
|
|
//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];
|
2020-11-19 19:04:17 +08:00
|
|
|
//DRM_IOCTL_I915_QUERY
|
|
|
|
drm_i915_query_item storedQueryItem = {};
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-04-23 21:42:33 +08:00
|
|
|
uint64_t storedGTTSize = 1ull << 47;
|
2019-08-21 18:50:47 +08:00
|
|
|
uint64_t storedParamSseu = ULONG_MAX;
|
2019-04-23 21:42:33 +08:00
|
|
|
|
2019-07-23 17:45:10 +08:00
|
|
|
virtual int handleRemainingRequests(unsigned long request, void *arg) { return -1; }
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2020-08-11 20:00:41 +08:00
|
|
|
|
|
|
|
class DrmMockNonFailing : public DrmMock {
|
|
|
|
public:
|
|
|
|
using DrmMock::DrmMock;
|
|
|
|
int handleRemainingRequests(unsigned long request, void *arg) override { return 0; }
|
|
|
|
};
|
2020-08-25 01:08:59 +08:00
|
|
|
|
2021-10-12 09:32:45 +08:00
|
|
|
class DrmMockReturnErrorNotSupported : public DrmMock {
|
|
|
|
public:
|
|
|
|
using DrmMock::DrmMock;
|
|
|
|
int ioctl(unsigned long request, void *arg) override {
|
|
|
|
if (request == DRM_IOCTL_I915_GEM_EXECBUFFER2) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int getErrno() override { return EOPNOTSUPP; }
|
|
|
|
};
|
|
|
|
|
2020-08-25 01:08:59 +08:00
|
|
|
class DrmMockEngine : public DrmMock {
|
|
|
|
public:
|
|
|
|
uint32_t i915QuerySuccessCount = std::numeric_limits<uint32_t>::max();
|
|
|
|
uint32_t queryEngineInfoSuccessCount = std::numeric_limits<uint32_t>::max();
|
|
|
|
|
2022-01-04 22:48:05 +08:00
|
|
|
DrmMockEngine(RootDeviceEnvironment &rootDeviceEnvironment) : DrmMock(rootDeviceEnvironment) {
|
|
|
|
rootDeviceEnvironment.setHwInfo(defaultHwInfo.get());
|
|
|
|
}
|
2020-09-11 20:18:23 +08:00
|
|
|
|
2021-06-26 07:28:22 +08:00
|
|
|
int handleRemainingRequests(unsigned long request, void *arg) override;
|
2020-08-25 01:08:59 +08:00
|
|
|
|
2021-06-26 07:28:22 +08:00
|
|
|
void handleQueryItem(drm_i915_query_item *queryItem);
|
2021-11-13 01:34:33 +08:00
|
|
|
bool failQueryDeviceBlob = false;
|
2020-08-25 01:08:59 +08:00
|
|
|
};
|
2020-09-14 19:28:47 +08:00
|
|
|
|
|
|
|
class DrmMockResources : public DrmMock {
|
|
|
|
public:
|
2020-11-23 22:31:20 +08:00
|
|
|
DrmMockResources(RootDeviceEnvironment &rootDeviceEnvironment) : DrmMock(mockFd, rootDeviceEnvironment) {
|
|
|
|
setBindAvailable();
|
|
|
|
}
|
2020-09-14 19:28:47 +08:00
|
|
|
|
|
|
|
bool registerResourceClasses() override {
|
|
|
|
registerClassesCalled = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-17 06:52:18 +08:00
|
|
|
uint32_t registerResource(ResourceClass classType, const void *data, size_t size) override {
|
2020-09-14 19:28:47 +08:00
|
|
|
registeredClass = classType;
|
2020-09-17 19:27:32 +08:00
|
|
|
memcpy_s(registeredData, sizeof(registeredData), data, size);
|
|
|
|
registeredDataSize = size;
|
2020-09-14 19:28:47 +08:00
|
|
|
return registerResourceReturnHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void unregisterResource(uint32_t handle) override {
|
|
|
|
unregisterCalledCount++;
|
|
|
|
unregisteredHandle = handle;
|
|
|
|
}
|
|
|
|
|
2020-10-26 21:48:20 +08:00
|
|
|
uint32_t registerIsaCookie(uint32_t isaHanlde) override {
|
|
|
|
return currentCookie++;
|
|
|
|
}
|
|
|
|
|
2020-11-23 22:31:20 +08:00
|
|
|
bool isVmBindAvailable() override {
|
|
|
|
return bindAvailable;
|
|
|
|
}
|
|
|
|
|
2020-09-14 19:28:47 +08:00
|
|
|
static const uint32_t registerResourceReturnHandle;
|
|
|
|
|
|
|
|
uint32_t unregisteredHandle = 0;
|
|
|
|
uint32_t unregisterCalledCount = 0;
|
|
|
|
ResourceClass registeredClass = ResourceClass::MaxSize;
|
|
|
|
bool registerClassesCalled = false;
|
2020-09-17 19:27:32 +08:00
|
|
|
uint64_t registeredData[128];
|
|
|
|
size_t registeredDataSize;
|
2020-10-26 21:48:20 +08:00
|
|
|
uint32_t currentCookie = 2;
|
2020-09-14 19:28:47 +08:00
|
|
|
};
|
2021-06-28 21:17:49 +08:00
|
|
|
|
|
|
|
extern std::map<unsigned long, const char *> ioctlCodeStringMap;
|
|
|
|
extern std::map<int, const char *> ioctlParamCodeStringMap;
|