2019-03-19 23:04:18 +08:00
|
|
|
/*
|
2020-02-06 00:43:02 +08:00
|
|
|
* Copyright (C) 2019-2020 Intel Corporation
|
2019-03-19 23:04:18 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/os_interface/linux/drm_mock.h"
|
2019-03-19 23:04:18 +08:00
|
|
|
|
2020-06-16 16:12:15 +08:00
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
|
|
|
#include "shared/source/helpers/hw_info.h"
|
|
|
|
|
2020-06-09 21:51:26 +08:00
|
|
|
#include <cstring>
|
|
|
|
|
2020-02-06 00:43:02 +08:00
|
|
|
const int DrmMock::mockFd;
|
2020-09-14 19:28:47 +08:00
|
|
|
const uint32_t DrmMockResources::registerResourceReturnHandle = 3;
|
2020-02-06 00:43:02 +08:00
|
|
|
|
2019-07-23 17:45:10 +08:00
|
|
|
int DrmMock::ioctl(unsigned long request, void *arg) {
|
|
|
|
ioctlCallsCount++;
|
|
|
|
|
|
|
|
if ((request == DRM_IOCTL_I915_GETPARAM) && (arg != nullptr)) {
|
|
|
|
auto gp = static_cast<drm_i915_getparam_t *>(arg);
|
|
|
|
if (gp->param == I915_PARAM_EU_TOTAL) {
|
|
|
|
if (0 == this->StoredRetValForEUVal) {
|
|
|
|
*gp->value = this->StoredEUVal;
|
|
|
|
}
|
|
|
|
return this->StoredRetValForEUVal;
|
|
|
|
}
|
|
|
|
if (gp->param == I915_PARAM_SUBSLICE_TOTAL) {
|
|
|
|
if (0 == this->StoredRetValForSSVal) {
|
|
|
|
*gp->value = this->StoredSSVal;
|
|
|
|
}
|
|
|
|
return this->StoredRetValForSSVal;
|
|
|
|
}
|
|
|
|
if (gp->param == I915_PARAM_CHIPSET_ID) {
|
|
|
|
if (0 == this->StoredRetValForDeviceID) {
|
|
|
|
*gp->value = this->StoredDeviceID;
|
|
|
|
}
|
|
|
|
return this->StoredRetValForDeviceID;
|
|
|
|
}
|
|
|
|
if (gp->param == I915_PARAM_REVISION) {
|
|
|
|
if (0 == this->StoredRetValForDeviceRevID) {
|
|
|
|
*gp->value = this->StoredDeviceRevID;
|
|
|
|
}
|
|
|
|
return this->StoredRetValForDeviceRevID;
|
|
|
|
}
|
|
|
|
if (gp->param == I915_PARAM_HAS_POOLED_EU) {
|
|
|
|
if (0 == this->StoredRetValForPooledEU) {
|
|
|
|
*gp->value = this->StoredHasPooledEU;
|
|
|
|
}
|
|
|
|
return this->StoredRetValForPooledEU;
|
|
|
|
}
|
|
|
|
if (gp->param == I915_PARAM_MIN_EU_IN_POOL) {
|
|
|
|
if (0 == this->StoredRetValForMinEUinPool) {
|
|
|
|
*gp->value = this->StoredMinEUinPool;
|
|
|
|
}
|
|
|
|
return this->StoredRetValForMinEUinPool;
|
|
|
|
}
|
|
|
|
if (gp->param == I915_PARAM_HAS_SCHEDULER) {
|
|
|
|
*gp->value = this->StoredPreemptionSupport;
|
|
|
|
return this->StoredRetVal;
|
|
|
|
}
|
|
|
|
if (gp->param == I915_PARAM_HAS_EXEC_SOFTPIN) {
|
|
|
|
*gp->value = this->StoredExecSoftPin;
|
|
|
|
return this->StoredRetVal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((request == DRM_IOCTL_I915_GEM_CONTEXT_CREATE) && (arg != nullptr)) {
|
|
|
|
auto create = static_cast<drm_i915_gem_context_create *>(arg);
|
2020-07-07 15:34:31 +08:00
|
|
|
this->receivedCreateContextId = create->ctx_id;
|
2019-07-23 17:45:10 +08:00
|
|
|
return this->StoredRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((request == DRM_IOCTL_I915_GEM_CONTEXT_DESTROY) && (arg != nullptr)) {
|
|
|
|
auto destroy = static_cast<drm_i915_gem_context_destroy *>(arg);
|
|
|
|
this->receivedDestroyContextId = destroy->ctx_id;
|
|
|
|
return this->StoredRetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((request == DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM) && (arg != nullptr)) {
|
|
|
|
receivedContextParamRequestCount++;
|
|
|
|
receivedContextParamRequest = *static_cast<drm_i915_gem_context_param *>(arg);
|
|
|
|
if (receivedContextParamRequest.param == I915_CONTEXT_PARAM_PRIORITY) {
|
|
|
|
return this->StoredRetVal;
|
|
|
|
}
|
|
|
|
if ((receivedContextParamRequest.param == I915_CONTEXT_PRIVATE_PARAM_BOOST) && (receivedContextParamRequest.value == 1)) {
|
|
|
|
return this->StoredRetVal;
|
|
|
|
}
|
2019-08-21 18:50:47 +08:00
|
|
|
if (receivedContextParamRequest.param == I915_CONTEXT_PARAM_SSEU) {
|
|
|
|
if (StoredRetValForSetSSEU == 0) {
|
|
|
|
storedParamSseu = (*static_cast<drm_i915_gem_context_param_sseu *>(reinterpret_cast<void *>(receivedContextParamRequest.value))).slice_mask;
|
|
|
|
}
|
|
|
|
return this->StoredRetValForSetSSEU;
|
|
|
|
}
|
2019-12-19 02:38:22 +08:00
|
|
|
if (receivedContextParamRequest.param == I915_CONTEXT_PARAM_PERSISTENCE) {
|
2020-02-11 00:05:32 +08:00
|
|
|
return this->StoredRetValForPersistant;
|
2019-12-19 02:38:22 +08:00
|
|
|
}
|
2020-07-23 16:50:19 +08:00
|
|
|
if (receivedContextParamRequest.param == I915_CONTEXT_PARAM_VM) {
|
|
|
|
return this->StoredRetVal;
|
|
|
|
}
|
2019-07-23 17:45:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((request == DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM) && (arg != nullptr)) {
|
|
|
|
receivedContextParamRequestCount++;
|
|
|
|
receivedContextParamRequest = *static_cast<drm_i915_gem_context_param *>(arg);
|
|
|
|
if (receivedContextParamRequest.param == I915_CONTEXT_PARAM_GTT_SIZE) {
|
|
|
|
static_cast<drm_i915_gem_context_param *>(arg)->value = this->storedGTTSize;
|
2019-12-17 22:17:52 +08:00
|
|
|
return this->StoredRetValForGetGttSize;
|
2019-07-23 17:45:10 +08:00
|
|
|
}
|
2019-08-21 18:50:47 +08:00
|
|
|
if (receivedContextParamRequest.param == I915_CONTEXT_PARAM_SSEU) {
|
|
|
|
if (StoredRetValForGetSSEU == 0) {
|
|
|
|
(*static_cast<drm_i915_gem_context_param_sseu *>(reinterpret_cast<void *>(receivedContextParamRequest.value))).slice_mask = storedParamSseu;
|
|
|
|
}
|
|
|
|
return this->StoredRetValForGetSSEU;
|
|
|
|
}
|
2019-12-19 02:38:22 +08:00
|
|
|
if (receivedContextParamRequest.param == I915_CONTEXT_PARAM_PERSISTENCE) {
|
2020-02-11 00:05:32 +08:00
|
|
|
static_cast<drm_i915_gem_context_param *>(arg)->value = this->StoredPersistentContextsSupport;
|
|
|
|
return this->StoredRetValForPersistant;
|
2019-12-19 02:38:22 +08:00
|
|
|
}
|
2020-07-02 17:49:46 +08:00
|
|
|
|
|
|
|
if (receivedContextParamRequest.param == I915_CONTEXT_PARAM_VM) {
|
2020-08-17 18:07:39 +08:00
|
|
|
static_cast<drm_i915_gem_context_param *>(arg)->value = this->StoredRetValForVmId;
|
2020-07-02 17:49:46 +08:00
|
|
|
return 0u;
|
|
|
|
}
|
2019-07-23 17:45:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (request == DRM_IOCTL_I915_GEM_EXECBUFFER2) {
|
|
|
|
auto execbuf = static_cast<drm_i915_gem_execbuffer2 *>(arg);
|
|
|
|
this->execBuffer = *execbuf;
|
2020-09-21 19:52:17 +08:00
|
|
|
this->bbFlags = reinterpret_cast<drm_i915_gem_exec_object2 *>(execbuf->buffers_ptr)[execbuf->buffer_count - 1].flags;
|
2019-07-23 17:45:10 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (request == DRM_IOCTL_I915_GEM_USERPTR) {
|
|
|
|
auto userPtrParams = static_cast<drm_i915_gem_userptr *>(arg);
|
|
|
|
userPtrParams->handle = returnHandle;
|
|
|
|
returnHandle++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (request == DRM_IOCTL_I915_GEM_CREATE) {
|
|
|
|
auto createParams = static_cast<drm_i915_gem_create *>(arg);
|
|
|
|
this->createParamsSize = createParams->size;
|
|
|
|
this->createParamsHandle = createParams->handle = 1u;
|
2020-03-19 20:17:17 +08:00
|
|
|
if (0 == this->createParamsSize) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
2019-07-23 17:45:10 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (request == DRM_IOCTL_I915_GEM_SET_TILING) {
|
|
|
|
auto setTilingParams = static_cast<drm_i915_gem_set_tiling *>(arg);
|
|
|
|
setTilingMode = setTilingParams->tiling_mode;
|
|
|
|
setTilingHandle = setTilingParams->handle;
|
|
|
|
setTilingStride = setTilingParams->stride;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (request == DRM_IOCTL_PRIME_FD_TO_HANDLE) {
|
|
|
|
auto primeToHandleParams = static_cast<drm_prime_handle *>(arg);
|
|
|
|
//return BO
|
|
|
|
primeToHandleParams->handle = outputHandle;
|
|
|
|
inputFd = primeToHandleParams->fd;
|
2020-10-21 16:50:53 +08:00
|
|
|
return fdToHandleRetVal;
|
|
|
|
}
|
|
|
|
if (request == DRM_IOCTL_PRIME_HANDLE_TO_FD) {
|
|
|
|
auto primeToFdParams = static_cast<drm_prime_handle *>(arg);
|
|
|
|
primeToFdParams->fd = outputFd;
|
2019-07-23 17:45:10 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (request == DRM_IOCTL_I915_GEM_GET_APERTURE) {
|
|
|
|
auto aperture = static_cast<drm_i915_gem_get_aperture *>(arg);
|
|
|
|
aperture->aper_available_size = gpuMemSize;
|
|
|
|
aperture->aper_size = gpuMemSize;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (request == DRM_IOCTL_I915_GEM_MMAP) {
|
|
|
|
auto mmap_arg = static_cast<drm_i915_gem_mmap *>(arg);
|
|
|
|
mmap_arg->addr_ptr = reinterpret_cast<__u64>(lockedPtr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (request == DRM_IOCTL_I915_GEM_WAIT) {
|
|
|
|
return 0;
|
|
|
|
}
|
2020-08-25 14:48:18 +08:00
|
|
|
if (request == DRM_IOCTL_GEM_CLOSE) {
|
|
|
|
return 0;
|
|
|
|
}
|
2020-06-09 21:51:26 +08:00
|
|
|
if (request == DRM_IOCTL_I915_QUERY && arg != nullptr) {
|
|
|
|
auto queryArg = static_cast<drm_i915_query *>(arg);
|
|
|
|
auto queryItemArg = reinterpret_cast<drm_i915_query_item *>(queryArg->items_ptr);
|
2020-06-16 16:12:15 +08:00
|
|
|
|
|
|
|
auto realEuCount = rootDeviceEnvironment.getHardwareInfo()->gtSystemInfo.EUCount;
|
2020-09-18 19:11:50 +08:00
|
|
|
auto dataSize = static_cast<size_t>(std::ceil(realEuCount / 8.0));
|
2020-06-16 16:12:15 +08:00
|
|
|
|
2020-06-09 21:51:26 +08:00
|
|
|
if (queryItemArg->length == 0) {
|
|
|
|
if (queryItemArg->query_id == DRM_I915_QUERY_TOPOLOGY_INFO) {
|
2020-09-18 19:11:50 +08:00
|
|
|
queryItemArg->length = static_cast<int32_t>(sizeof(drm_i915_query_topology_info) + dataSize);
|
2020-06-09 21:51:26 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (queryItemArg->query_id == DRM_I915_QUERY_TOPOLOGY_INFO) {
|
|
|
|
auto topologyArg = reinterpret_cast<drm_i915_query_topology_info *>(queryItemArg->data_ptr);
|
|
|
|
if (this->failRetTopology) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
topologyArg->max_slices = this->StoredSVal;
|
2020-06-16 16:12:15 +08:00
|
|
|
topologyArg->max_subslices = this->StoredSVal ? (this->StoredSSVal / this->StoredSVal) : 0;
|
|
|
|
topologyArg->max_eus_per_subslice = this->StoredSSVal ? (this->StoredEUVal / this->StoredSSVal) : 0;
|
|
|
|
|
2020-06-09 21:51:26 +08:00
|
|
|
if (this->disableSomeTopology) {
|
2020-06-16 16:12:15 +08:00
|
|
|
memset(topologyArg->data, 0xCA, dataSize);
|
2020-06-09 21:51:26 +08:00
|
|
|
} else {
|
2020-06-16 16:12:15 +08:00
|
|
|
memset(topologyArg->data, 0xFF, dataSize);
|
2020-06-09 21:51:26 +08:00
|
|
|
}
|
2020-06-16 16:12:15 +08:00
|
|
|
|
2020-06-09 21:51:26 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-23 17:45:10 +08:00
|
|
|
|
|
|
|
return handleRemainingRequests(request, arg);
|
|
|
|
}
|