2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2021-05-17 02:51:16 +08:00
|
|
|
* Copyright (C) 2018-2021 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "drm_neo.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
2020-03-17 14:26:46 +08:00
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
2020-07-07 15:34:31 +08:00
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
2020-04-02 17:28:38 +08:00
|
|
|
#include "shared/source/helpers/constants.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/debug_helpers.h"
|
2020-07-07 15:34:31 +08:00
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/hw_info.h"
|
2020-06-09 21:51:26 +08:00
|
|
|
#include "shared/source/helpers/ptr_math.h"
|
2020-11-05 20:40:03 +08:00
|
|
|
#include "shared/source/os_interface/driver_info.h"
|
2021-05-21 07:17:57 +08:00
|
|
|
#include "shared/source/os_interface/linux/drm_gem_close_worker.h"
|
|
|
|
#include "shared/source/os_interface/linux/drm_memory_manager.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/linux/hw_device_id.h"
|
|
|
|
#include "shared/source/os_interface/linux/os_inc.h"
|
2021-05-20 06:36:24 +08:00
|
|
|
#include "shared/source/os_interface/linux/pci_path.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/linux/sys_calls.h"
|
2020-11-24 23:00:33 +08:00
|
|
|
#include "shared/source/os_interface/linux/system_info.h"
|
2020-03-17 14:26:46 +08:00
|
|
|
#include "shared/source/os_interface/os_environment.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/os_interface.h"
|
|
|
|
#include "shared/source/utilities/directory.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-11-19 19:04:17 +08:00
|
|
|
#include "drm_query_flags.h"
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
2020-02-07 21:32:02 +08:00
|
|
|
#include <linux/limits.h>
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-01-31 23:10:03 +08:00
|
|
|
namespace IoctlHelper {
|
|
|
|
constexpr const char *getIoctlParamString(int param) {
|
|
|
|
switch (param) {
|
|
|
|
case I915_PARAM_CHIPSET_ID:
|
|
|
|
return "I915_PARAM_CHIPSET_ID";
|
|
|
|
case I915_PARAM_REVISION:
|
|
|
|
return "I915_PARAM_REVISION";
|
|
|
|
case I915_PARAM_HAS_EXEC_SOFTPIN:
|
|
|
|
return "I915_PARAM_HAS_EXEC_SOFTPIN";
|
|
|
|
case I915_PARAM_HAS_POOLED_EU:
|
|
|
|
return "I915_PARAM_HAS_POOLED_EU";
|
|
|
|
case I915_PARAM_HAS_SCHEDULER:
|
|
|
|
return "I915_PARAM_HAS_SCHEDULER";
|
|
|
|
case I915_PARAM_EU_TOTAL:
|
|
|
|
return "I915_PARAM_EU_TOTAL";
|
|
|
|
case I915_PARAM_SUBSLICE_TOTAL:
|
|
|
|
return "I915_PARAM_SUBSLICE_TOTAL";
|
|
|
|
case I915_PARAM_MIN_EU_IN_POOL:
|
|
|
|
return "I915_PARAM_MIN_EU_IN_POOL";
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace IoctlHelper
|
|
|
|
|
2021-05-25 01:34:55 +08:00
|
|
|
Drm::Drm(std::unique_ptr<HwDeviceIdDrm> hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment)
|
2021-05-21 07:17:57 +08:00
|
|
|
: DriverModel(DriverModelType::DRM),
|
|
|
|
hwDeviceId(std::move(hwDeviceIdIn)), rootDeviceEnvironment(rootDeviceEnvironment) {
|
2021-02-05 23:27:21 +08:00
|
|
|
pagingFence.fill(0u);
|
|
|
|
fenceVal.fill(0u);
|
2020-07-15 14:07:53 +08:00
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
int Drm::ioctl(unsigned long request, void *arg) {
|
|
|
|
int ret;
|
2021-05-12 23:09:01 +08:00
|
|
|
int returnedErrno;
|
2017-12-21 07:45:38 +08:00
|
|
|
SYSTEM_ENTER();
|
|
|
|
do {
|
2021-04-21 21:52:11 +08:00
|
|
|
auto measureTime = DebugManager.flags.PrintIoctlTimes.get();
|
|
|
|
std::chrono::steady_clock::time_point start;
|
|
|
|
std::chrono::steady_clock::time_point end;
|
|
|
|
|
|
|
|
if (measureTime) {
|
|
|
|
start = std::chrono::steady_clock::now();
|
|
|
|
}
|
|
|
|
|
2021-04-22 21:37:02 +08:00
|
|
|
auto printIoctl = DebugManager.flags.PrintIoctlEntries.get();
|
|
|
|
|
|
|
|
if (printIoctl) {
|
2021-05-12 15:42:33 +08:00
|
|
|
printf("IOCTL %s called\n", this->ioctlToString(request).c_str());
|
2021-04-22 21:37:02 +08:00
|
|
|
}
|
|
|
|
|
2020-02-13 20:26:40 +08:00
|
|
|
ret = SysCalls::ioctl(getFileDescriptor(), request, arg);
|
2021-04-21 21:52:11 +08:00
|
|
|
|
2021-05-12 23:09:01 +08:00
|
|
|
returnedErrno = errno;
|
|
|
|
|
2021-04-22 21:37:02 +08:00
|
|
|
if (printIoctl) {
|
2021-06-16 15:11:32 +08:00
|
|
|
printf("IOCTL %s returns %d, errno %d(%s)\n", this->ioctlToString(request).c_str(), ret, returnedErrno, strerror(returnedErrno));
|
2021-04-22 21:37:02 +08:00
|
|
|
}
|
|
|
|
|
2021-04-21 21:52:11 +08:00
|
|
|
if (measureTime) {
|
|
|
|
end = std::chrono::steady_clock::now();
|
|
|
|
auto elapsedTime = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count();
|
|
|
|
|
|
|
|
std::pair<long long, uint64_t> ioctlData{};
|
|
|
|
auto ioctlDataIt = this->ioctlStatistics.find(request);
|
|
|
|
if (ioctlDataIt != this->ioctlStatistics.end()) {
|
|
|
|
ioctlData = ioctlDataIt->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
ioctlData.first += elapsedTime;
|
|
|
|
ioctlData.second++;
|
|
|
|
|
|
|
|
this->ioctlStatistics[request] = ioctlData;
|
|
|
|
}
|
2021-05-12 23:09:01 +08:00
|
|
|
} while (ret == -1 && (returnedErrno == EINTR || returnedErrno == EAGAIN || returnedErrno == EBUSY));
|
2017-12-21 07:45:38 +08:00
|
|
|
SYSTEM_LEAVE(request);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-03-12 19:03:20 +08:00
|
|
|
int Drm::getParamIoctl(int param, int *dstValue) {
|
|
|
|
drm_i915_getparam_t getParam = {};
|
|
|
|
getParam.param = param;
|
|
|
|
getParam.value = dstValue;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-01-31 23:10:03 +08:00
|
|
|
int retVal = ioctl(DRM_IOCTL_I915_GETPARAM, &getParam);
|
|
|
|
|
2020-09-25 17:24:15 +08:00
|
|
|
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stdout,
|
|
|
|
"\nDRM_IOCTL_I915_GETPARAM: param: %s, output value: %d, retCode: %d\n",
|
|
|
|
IoctlHelper::getIoctlParamString(param), *getParam.value, retVal);
|
2020-01-31 23:10:03 +08:00
|
|
|
|
|
|
|
return retVal;
|
2018-03-12 19:03:20 +08:00
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-03-12 19:03:20 +08:00
|
|
|
int Drm::getDeviceID(int &devId) {
|
|
|
|
return getParamIoctl(I915_PARAM_CHIPSET_ID, &devId);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int Drm::getDeviceRevID(int &revId) {
|
2018-03-12 19:03:20 +08:00
|
|
|
return getParamIoctl(I915_PARAM_REVISION, &revId);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int Drm::getExecSoftPin(int &execSoftPin) {
|
2018-03-12 19:03:20 +08:00
|
|
|
return getParamIoctl(I915_PARAM_HAS_EXEC_SOFTPIN, &execSoftPin);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int Drm::enableTurboBoost() {
|
2018-03-20 17:49:09 +08:00
|
|
|
drm_i915_gem_context_param contextParam = {};
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
contextParam.param = I915_CONTEXT_PRIVATE_PARAM_BOOST;
|
|
|
|
contextParam.value = 1;
|
2018-03-20 17:49:09 +08:00
|
|
|
return ioctl(DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &contextParam);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int Drm::getEnabledPooledEu(int &enabled) {
|
2018-03-12 19:03:20 +08:00
|
|
|
return getParamIoctl(I915_PARAM_HAS_POOLED_EU, &enabled);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2020-04-09 00:14:19 +08:00
|
|
|
std::string Drm::getSysFsPciPath() {
|
|
|
|
std::string path = std::string(Os::sysFsPciPathPrefix) + hwDeviceId->getPciPath() + "/drm";
|
|
|
|
std::string expectedFilePrefix = path + "/card";
|
|
|
|
auto files = Directory::getFiles(path.c_str());
|
|
|
|
for (auto &file : files) {
|
|
|
|
if (file.find(expectedFilePrefix.c_str()) != std::string::npos) {
|
|
|
|
return file;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
}
|
2020-04-09 00:14:19 +08:00
|
|
|
return {};
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2019-12-17 22:17:52 +08:00
|
|
|
int Drm::queryGttSize(uint64_t >tSizeOutput) {
|
2019-04-23 21:42:33 +08:00
|
|
|
drm_i915_gem_context_param contextParam = {0};
|
|
|
|
contextParam.param = I915_CONTEXT_PARAM_GTT_SIZE;
|
|
|
|
|
2019-12-17 22:17:52 +08:00
|
|
|
int ret = ioctl(DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &contextParam);
|
2019-04-23 21:42:33 +08:00
|
|
|
if (ret == 0) {
|
2019-12-17 22:17:52 +08:00
|
|
|
gttSizeOutput = contextParam.value;
|
2019-04-23 21:42:33 +08:00
|
|
|
}
|
2019-12-17 22:17:52 +08:00
|
|
|
|
|
|
|
return ret;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-12-07 22:03:23 +08:00
|
|
|
void Drm::checkPreemptionSupport() {
|
2017-12-21 07:45:38 +08:00
|
|
|
int value = 0;
|
2019-03-22 13:21:52 +08:00
|
|
|
auto ret = getParamIoctl(I915_PARAM_HAS_SCHEDULER, &value);
|
|
|
|
preemptionSupported = ((0 == ret) && (value & I915_SCHEDULER_CAP_PREEMPTION));
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2019-08-21 18:50:47 +08:00
|
|
|
void Drm::checkQueueSliceSupport() {
|
|
|
|
sliceCountChangeSupported = getQueueSliceCount(&sseu) == 0 ? true : false;
|
|
|
|
}
|
|
|
|
|
2018-12-11 15:21:56 +08:00
|
|
|
void Drm::setLowPriorityContextParam(uint32_t drmContextId) {
|
2018-12-07 22:03:23 +08:00
|
|
|
drm_i915_gem_context_param gcp = {};
|
2018-12-11 15:21:56 +08:00
|
|
|
gcp.ctx_id = drmContextId;
|
2017-12-21 07:45:38 +08:00
|
|
|
gcp.param = I915_CONTEXT_PARAM_PRIORITY;
|
|
|
|
gcp.value = -1023;
|
|
|
|
|
2018-12-11 15:21:56 +08:00
|
|
|
auto retVal = ioctl(DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &gcp);
|
|
|
|
UNRECOVERABLE_IF(retVal != 0);
|
|
|
|
}
|
|
|
|
|
2019-08-21 18:50:47 +08:00
|
|
|
int Drm::getQueueSliceCount(drm_i915_gem_context_param_sseu *sseu) {
|
|
|
|
drm_i915_gem_context_param contextParam = {};
|
|
|
|
contextParam.param = I915_CONTEXT_PARAM_SSEU;
|
|
|
|
sseu->engine.engine_class = I915_ENGINE_CLASS_RENDER;
|
|
|
|
sseu->engine.engine_instance = I915_EXEC_DEFAULT;
|
|
|
|
contextParam.value = reinterpret_cast<uint64_t>(sseu);
|
|
|
|
contextParam.size = sizeof(struct drm_i915_gem_context_param_sseu);
|
|
|
|
|
|
|
|
return ioctl(DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &contextParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t Drm::getSliceMask(uint64_t sliceCount) {
|
2019-11-28 01:00:52 +08:00
|
|
|
return maxNBitValue(sliceCount);
|
2019-08-21 18:50:47 +08:00
|
|
|
}
|
|
|
|
bool Drm::setQueueSliceCount(uint64_t sliceCount) {
|
|
|
|
if (sliceCountChangeSupported) {
|
|
|
|
drm_i915_gem_context_param contextParam = {};
|
|
|
|
sseu.slice_mask = getSliceMask(sliceCount);
|
|
|
|
|
|
|
|
contextParam.param = I915_CONTEXT_PARAM_SSEU;
|
|
|
|
contextParam.ctx_id = 0;
|
|
|
|
contextParam.value = reinterpret_cast<uint64_t>(&sseu);
|
|
|
|
contextParam.size = sizeof(struct drm_i915_gem_context_param_sseu);
|
|
|
|
int retVal = ioctl(DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &contextParam);
|
|
|
|
if (retVal == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-11 00:05:32 +08:00
|
|
|
void Drm::checkNonPersistentContextsSupport() {
|
2019-12-19 02:38:22 +08:00
|
|
|
drm_i915_gem_context_param contextParam = {};
|
|
|
|
contextParam.param = I915_CONTEXT_PARAM_PERSISTENCE;
|
2020-02-11 00:05:32 +08:00
|
|
|
|
|
|
|
auto retVal = ioctl(DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, &contextParam);
|
|
|
|
if (retVal == 0 && contextParam.value == 1) {
|
|
|
|
nonPersistentContextsSupported = true;
|
|
|
|
} else {
|
|
|
|
nonPersistentContextsSupported = false;
|
|
|
|
}
|
2019-12-19 02:38:22 +08:00
|
|
|
}
|
|
|
|
|
2019-12-24 19:20:23 +08:00
|
|
|
void Drm::setNonPersistentContext(uint32_t drmContextId) {
|
2019-12-19 02:38:22 +08:00
|
|
|
drm_i915_gem_context_param contextParam = {};
|
|
|
|
contextParam.ctx_id = drmContextId;
|
|
|
|
contextParam.param = I915_CONTEXT_PARAM_PERSISTENCE;
|
|
|
|
|
2020-02-11 00:05:32 +08:00
|
|
|
ioctl(DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, &contextParam);
|
2019-12-19 02:38:22 +08:00
|
|
|
}
|
|
|
|
|
2021-05-11 19:12:49 +08:00
|
|
|
uint32_t Drm::createDrmContext(uint32_t drmVmId, bool isSpecialContextRequested) {
|
2021-02-10 19:30:48 +08:00
|
|
|
drm_i915_gem_context_create_ext gcc = {};
|
2021-02-10 23:13:50 +08:00
|
|
|
|
2021-05-11 19:12:49 +08:00
|
|
|
this->appendDrmContextFlags(gcc, isSpecialContextRequested);
|
2021-02-10 23:13:50 +08:00
|
|
|
|
2021-02-10 19:30:48 +08:00
|
|
|
auto retVal = ioctl(DRM_IOCTL_I915_GEM_CONTEXT_CREATE_EXT, &gcc);
|
2018-12-07 22:03:23 +08:00
|
|
|
UNRECOVERABLE_IF(retVal != 0);
|
2018-12-11 15:21:56 +08:00
|
|
|
|
2020-08-04 16:23:54 +08:00
|
|
|
if (drmVmId > 0) {
|
|
|
|
drm_i915_gem_context_param param{};
|
|
|
|
param.ctx_id = gcc.ctx_id;
|
|
|
|
param.value = drmVmId;
|
|
|
|
param.param = I915_CONTEXT_PARAM_VM;
|
|
|
|
retVal = ioctl(DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM, ¶m);
|
|
|
|
UNRECOVERABLE_IF(retVal != 0);
|
|
|
|
}
|
2020-07-23 16:50:19 +08:00
|
|
|
|
2018-12-11 15:21:56 +08:00
|
|
|
return gcc.ctx_id;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-12-11 15:21:56 +08:00
|
|
|
void Drm::destroyDrmContext(uint32_t drmContextId) {
|
2018-03-20 17:49:09 +08:00
|
|
|
drm_i915_gem_context_destroy destroy = {};
|
2018-12-11 15:21:56 +08:00
|
|
|
destroy.ctx_id = drmContextId;
|
2018-12-07 22:03:23 +08:00
|
|
|
auto retVal = ioctl(DRM_IOCTL_I915_GEM_CONTEXT_DESTROY, &destroy);
|
|
|
|
UNRECOVERABLE_IF(retVal != 0);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2020-07-07 15:34:31 +08:00
|
|
|
void Drm::destroyDrmVirtualMemory(uint32_t drmVmId) {
|
|
|
|
drm_i915_gem_vm_control ctl = {};
|
|
|
|
ctl.vm_id = drmVmId;
|
|
|
|
auto ret = SysCalls::ioctl(getFileDescriptor(), DRM_IOCTL_I915_GEM_VM_DESTROY, &ctl);
|
|
|
|
UNRECOVERABLE_IF(ret != 0);
|
|
|
|
}
|
|
|
|
|
2020-08-31 13:04:58 +08:00
|
|
|
int Drm::queryVmId(uint32_t drmContextId, uint32_t &vmId) {
|
2020-08-17 18:07:39 +08:00
|
|
|
drm_i915_gem_context_param param{};
|
|
|
|
param.ctx_id = drmContextId;
|
|
|
|
param.value = 0;
|
|
|
|
param.param = I915_CONTEXT_PARAM_VM;
|
|
|
|
auto retVal = this->ioctl(DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM, ¶m);
|
|
|
|
|
2020-08-31 13:04:58 +08:00
|
|
|
vmId = static_cast<uint32_t>(param.value);
|
2020-08-17 18:07:39 +08:00
|
|
|
|
2020-08-31 13:04:58 +08:00
|
|
|
return retVal;
|
2020-08-17 18:07:39 +08:00
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
int Drm::getEuTotal(int &euTotal) {
|
2019-07-23 17:45:10 +08:00
|
|
|
return getParamIoctl(I915_PARAM_EU_TOTAL, &euTotal);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int Drm::getSubsliceTotal(int &subsliceTotal) {
|
2018-03-12 19:03:20 +08:00
|
|
|
return getParamIoctl(I915_PARAM_SUBSLICE_TOTAL, &subsliceTotal);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int Drm::getMinEuInPool(int &minEUinPool) {
|
2018-03-12 19:03:20 +08:00
|
|
|
return getParamIoctl(I915_PARAM_MIN_EU_IN_POOL, &minEUinPool);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-02-28 19:09:48 +08:00
|
|
|
int Drm::getErrno() {
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
|
2019-10-18 16:15:09 +08:00
|
|
|
int Drm::setupHardwareInfo(DeviceDescriptor *device, bool setupFeatureTableAndWorkaroundTable) {
|
|
|
|
HardwareInfo *hwInfo = const_cast<HardwareInfo *>(device->pHwInfo);
|
|
|
|
int ret;
|
|
|
|
|
2021-04-27 22:45:13 +08:00
|
|
|
Drm::QueryTopologyData topologyData = {};
|
|
|
|
|
|
|
|
bool status = queryTopology(*hwInfo, topologyData);
|
2020-06-09 21:51:26 +08:00
|
|
|
|
|
|
|
if (!status) {
|
2020-09-25 17:24:15 +08:00
|
|
|
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "WARNING: Topology query failed!\n");
|
2020-06-09 21:51:26 +08:00
|
|
|
|
2021-04-27 22:45:13 +08:00
|
|
|
ret = getEuTotal(topologyData.euCount);
|
2020-06-09 21:51:26 +08:00
|
|
|
if (ret != 0) {
|
2020-09-25 17:24:15 +08:00
|
|
|
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "FATAL: Cannot query EU total parameter!\n");
|
2020-06-09 21:51:26 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2019-10-18 16:15:09 +08:00
|
|
|
|
2021-04-27 22:45:13 +08:00
|
|
|
ret = getSubsliceTotal(topologyData.subSliceCount);
|
2020-06-09 21:51:26 +08:00
|
|
|
if (ret != 0) {
|
2020-09-25 17:24:15 +08:00
|
|
|
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "FATAL: Cannot query subslice total parameter!\n");
|
2020-06-09 21:51:26 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2019-10-18 16:15:09 +08:00
|
|
|
}
|
|
|
|
|
2021-04-27 22:45:13 +08:00
|
|
|
hwInfo->gtSystemInfo.SliceCount = static_cast<uint32_t>(topologyData.sliceCount);
|
|
|
|
hwInfo->gtSystemInfo.SubSliceCount = static_cast<uint32_t>(topologyData.subSliceCount);
|
2021-06-01 21:07:41 +08:00
|
|
|
hwInfo->gtSystemInfo.DualSubSliceCount = static_cast<uint32_t>(topologyData.subSliceCount);
|
2021-04-27 22:45:13 +08:00
|
|
|
hwInfo->gtSystemInfo.EUCount = static_cast<uint32_t>(topologyData.euCount);
|
|
|
|
|
2020-11-24 23:00:33 +08:00
|
|
|
status = querySystemInfo();
|
|
|
|
if (!status) {
|
|
|
|
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stdout, "%s", "INFO: System Info query failed!\n");
|
|
|
|
}
|
|
|
|
if (systemInfo) {
|
|
|
|
setupSystemInfo(hwInfo, *systemInfo);
|
|
|
|
}
|
|
|
|
|
2019-10-18 16:15:09 +08:00
|
|
|
device->setupHardwareInfo(hwInfo, setupFeatureTableAndWorkaroundTable);
|
2020-11-24 23:00:33 +08:00
|
|
|
|
2021-01-30 06:23:06 +08:00
|
|
|
setupCacheInfo(*hwInfo);
|
|
|
|
|
2019-10-18 16:15:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-11-24 23:00:33 +08:00
|
|
|
void Drm::setupSystemInfo(HardwareInfo *hwInfo, SystemInfo &sysInfo) {
|
|
|
|
GT_SYSTEM_INFO *gtSysInfo = &hwInfo->gtSystemInfo;
|
|
|
|
gtSysInfo->ThreadCount = gtSysInfo->EUCount * sysInfo.getNumThreadsPerEu();
|
|
|
|
gtSysInfo->L3CacheSizeInKb = sysInfo.getL3CacheSizeInKb();
|
|
|
|
gtSysInfo->L3BankCount = sysInfo.getL3BankCount();
|
|
|
|
gtSysInfo->MaxFillRate = sysInfo.getMaxFillRate();
|
|
|
|
gtSysInfo->TotalVsThreads = sysInfo.getTotalVsThreads();
|
|
|
|
gtSysInfo->TotalHsThreads = sysInfo.getTotalHsThreads();
|
|
|
|
gtSysInfo->TotalDsThreads = sysInfo.getTotalDsThreads();
|
|
|
|
gtSysInfo->TotalGsThreads = sysInfo.getTotalGsThreads();
|
|
|
|
gtSysInfo->TotalPsThreadsWindowerRange = sysInfo.getTotalPsThreads();
|
|
|
|
gtSysInfo->MaxEuPerSubSlice = sysInfo.getMaxEuPerDualSubSlice();
|
|
|
|
gtSysInfo->MaxSlicesSupported = sysInfo.getMaxSlicesSupported();
|
|
|
|
gtSysInfo->MaxSubSlicesSupported = sysInfo.getMaxDualSubSlicesSupported();
|
|
|
|
gtSysInfo->MaxDualSubSlicesSupported = sysInfo.getMaxDualSubSlicesSupported();
|
|
|
|
}
|
|
|
|
|
2020-04-09 00:14:19 +08:00
|
|
|
void appendHwDeviceId(std::vector<std::unique_ptr<HwDeviceId>> &hwDeviceIds, int fileDescriptor, const char *pciPath) {
|
2020-04-08 17:27:04 +08:00
|
|
|
if (fileDescriptor >= 0) {
|
|
|
|
if (Drm::isi915Version(fileDescriptor)) {
|
2021-05-25 01:34:55 +08:00
|
|
|
hwDeviceIds.push_back(std::make_unique<HwDeviceIdDrm>(fileDescriptor, pciPath));
|
2020-04-08 17:27:04 +08:00
|
|
|
} else {
|
|
|
|
SysCalls::close(fileDescriptor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-28 01:44:47 +08:00
|
|
|
std::vector<std::unique_ptr<HwDeviceId>> Drm::discoverDevices(ExecutionEnvironment &executionEnvironment) {
|
2020-02-17 23:14:22 +08:00
|
|
|
std::vector<std::unique_ptr<HwDeviceId>> hwDeviceIds;
|
2020-03-17 14:26:46 +08:00
|
|
|
executionEnvironment.osEnvironment = std::make_unique<OsEnvironment>();
|
2020-04-08 17:27:04 +08:00
|
|
|
std::string devicePrefix = std::string(Os::pciDevicesDirectory) + "/pci-0000:";
|
|
|
|
const char *renderDeviceSuffix = "-render";
|
|
|
|
size_t numRootDevices = 0u;
|
2020-02-17 23:14:22 +08:00
|
|
|
if (DebugManager.flags.CreateMultipleRootDevices.get()) {
|
|
|
|
numRootDevices = DebugManager.flags.CreateMultipleRootDevices.get();
|
|
|
|
}
|
2020-04-08 17:27:04 +08:00
|
|
|
|
|
|
|
std::vector<std::string> files = Directory::getFiles(Os::pciDevicesDirectory);
|
|
|
|
|
|
|
|
if (files.size() == 0) {
|
|
|
|
const char *pathPrefix = "/dev/dri/renderD";
|
|
|
|
const unsigned int maxDrmDevices = 64;
|
|
|
|
unsigned int startNum = 128;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < maxDrmDevices; i++) {
|
|
|
|
std::string path = std::string(pathPrefix) + std::to_string(i + startNum);
|
|
|
|
int fileDescriptor = SysCalls::open(path.c_str(), O_RDWR);
|
2021-03-29 19:43:50 +08:00
|
|
|
|
2021-05-20 06:36:24 +08:00
|
|
|
auto pciPath = NEO::getPciPath(fileDescriptor);
|
2021-03-29 19:43:50 +08:00
|
|
|
|
|
|
|
appendHwDeviceId(hwDeviceIds, fileDescriptor, pciPath.value_or("00:02.0").c_str());
|
2020-05-21 19:01:07 +08:00
|
|
|
if (!hwDeviceIds.empty() && hwDeviceIds.size() == numRootDevices) {
|
|
|
|
break;
|
|
|
|
}
|
2020-02-07 21:32:02 +08:00
|
|
|
}
|
2020-02-17 23:14:22 +08:00
|
|
|
return hwDeviceIds;
|
2020-02-07 21:32:02 +08:00
|
|
|
}
|
|
|
|
|
2020-04-08 17:27:04 +08:00
|
|
|
do {
|
|
|
|
for (std::vector<std::string>::iterator file = files.begin(); file != files.end(); ++file) {
|
|
|
|
if (file->find(renderDeviceSuffix) == std::string::npos) {
|
|
|
|
continue;
|
2020-02-07 21:32:02 +08:00
|
|
|
}
|
2020-04-08 17:27:04 +08:00
|
|
|
std::string pciPath = file->substr(devicePrefix.size(), file->size() - devicePrefix.size() - strlen(renderDeviceSuffix));
|
|
|
|
|
|
|
|
if (DebugManager.flags.ForceDeviceId.get() != "unk") {
|
|
|
|
if (file->find(DebugManager.flags.ForceDeviceId.get().c_str()) == std::string::npos) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int fileDescriptor = SysCalls::open(file->c_str(), O_RDWR);
|
2020-04-09 00:14:19 +08:00
|
|
|
appendHwDeviceId(hwDeviceIds, fileDescriptor, pciPath.c_str());
|
2020-05-21 19:01:07 +08:00
|
|
|
if (!hwDeviceIds.empty() && hwDeviceIds.size() == numRootDevices) {
|
|
|
|
break;
|
|
|
|
}
|
2020-02-07 21:32:02 +08:00
|
|
|
}
|
2020-04-08 17:27:04 +08:00
|
|
|
if (hwDeviceIds.empty()) {
|
|
|
|
return hwDeviceIds;
|
|
|
|
}
|
|
|
|
} while (hwDeviceIds.size() < numRootDevices);
|
2020-02-17 23:14:22 +08:00
|
|
|
return hwDeviceIds;
|
2020-02-07 21:32:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Drm::isi915Version(int fileDescriptor) {
|
|
|
|
drm_version_t version = {};
|
|
|
|
char name[5] = {};
|
|
|
|
version.name = name;
|
|
|
|
version.name_len = 5;
|
|
|
|
|
2020-02-13 20:26:40 +08:00
|
|
|
int ret = SysCalls::ioctl(fileDescriptor, DRM_IOCTL_VERSION, &version);
|
2020-02-07 21:32:02 +08:00
|
|
|
if (ret) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
name[4] = '\0';
|
|
|
|
return strcmp(name, "i915") == 0;
|
|
|
|
}
|
|
|
|
|
2020-11-19 19:04:17 +08:00
|
|
|
std::unique_ptr<uint8_t[]> Drm::query(uint32_t queryId, uint32_t queryItemFlags, int32_t &length) {
|
2020-06-09 21:51:26 +08:00
|
|
|
drm_i915_query query{};
|
|
|
|
drm_i915_query_item queryItem{};
|
|
|
|
queryItem.query_id = queryId;
|
|
|
|
queryItem.length = 0; // query length first
|
2020-11-19 19:04:17 +08:00
|
|
|
queryItem.flags = queryItemFlags;
|
2020-06-09 21:51:26 +08:00
|
|
|
query.items_ptr = reinterpret_cast<__u64>(&queryItem);
|
|
|
|
query.num_items = 1;
|
|
|
|
length = 0;
|
|
|
|
|
|
|
|
auto ret = this->ioctl(DRM_IOCTL_I915_QUERY, &query);
|
|
|
|
if (ret != 0 || queryItem.length <= 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto data = std::make_unique<uint8_t[]>(queryItem.length);
|
|
|
|
memset(data.get(), 0, queryItem.length);
|
|
|
|
queryItem.data_ptr = castToUint64(data.get());
|
|
|
|
|
|
|
|
ret = this->ioctl(DRM_IOCTL_I915_QUERY, &query);
|
|
|
|
if (ret != 0 || queryItem.length <= 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
length = queryItem.length;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2021-04-21 21:52:11 +08:00
|
|
|
void Drm::printIoctlStatistics() {
|
|
|
|
if (!DebugManager.flags.PrintIoctlTimes.get()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-11 20:56:07 +08:00
|
|
|
printf("\n--- Ioctls statistics ---\n");
|
|
|
|
printf("%40s %15s %10s %20s", "Request", "Total time(ns)", "Count", "Avg time per ioctl\n");
|
2021-04-21 21:52:11 +08:00
|
|
|
for (const auto &ioctlData : this->ioctlStatistics) {
|
2021-05-11 20:56:07 +08:00
|
|
|
printf("%40s %15llu %10lu %20f\n", this->ioctlToString(ioctlData.first).c_str(), ioctlData.second.first, static_cast<unsigned long>(ioctlData.second.second), ioctlData.second.first / static_cast<double>(ioctlData.second.second));
|
2021-04-21 21:52:11 +08:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2021-05-11 20:56:07 +08:00
|
|
|
std::string Drm::ioctlToString(unsigned long request) {
|
|
|
|
switch (request) {
|
|
|
|
case DRM_IOCTL_I915_GEM_EXECBUFFER2:
|
|
|
|
return "DRM_IOCTL_I915_GEM_EXECBUFFER2";
|
|
|
|
case DRM_IOCTL_I915_GEM_WAIT:
|
|
|
|
return "DRM_IOCTL_I915_GEM_WAIT";
|
|
|
|
case DRM_IOCTL_GEM_CLOSE:
|
|
|
|
return "DRM_IOCTL_GEM_CLOSE";
|
|
|
|
case DRM_IOCTL_I915_GEM_USERPTR:
|
|
|
|
return "DRM_IOCTL_I915_GEM_USERPTR";
|
|
|
|
case DRM_IOCTL_I915_INIT:
|
|
|
|
return "DRM_IOCTL_I915_INIT";
|
|
|
|
case DRM_IOCTL_I915_FLUSH:
|
|
|
|
return "DRM_IOCTL_I915_FLUSH";
|
|
|
|
case DRM_IOCTL_I915_FLIP:
|
|
|
|
return "DRM_IOCTL_I915_FLIP";
|
|
|
|
case DRM_IOCTL_I915_BATCHBUFFER:
|
|
|
|
return "DRM_IOCTL_I915_BATCHBUFFER";
|
|
|
|
case DRM_IOCTL_I915_IRQ_EMIT:
|
|
|
|
return "DRM_IOCTL_I915_IRQ_EMIT";
|
|
|
|
case DRM_IOCTL_I915_IRQ_WAIT:
|
|
|
|
return "DRM_IOCTL_I915_IRQ_WAIT";
|
|
|
|
case DRM_IOCTL_I915_GETPARAM:
|
|
|
|
return "DRM_IOCTL_I915_GETPARAM";
|
|
|
|
case DRM_IOCTL_I915_SETPARAM:
|
|
|
|
return "DRM_IOCTL_I915_SETPARAM";
|
|
|
|
case DRM_IOCTL_I915_ALLOC:
|
|
|
|
return "DRM_IOCTL_I915_ALLOC";
|
|
|
|
case DRM_IOCTL_I915_FREE:
|
|
|
|
return "DRM_IOCTL_I915_FREE";
|
|
|
|
case DRM_IOCTL_I915_INIT_HEAP:
|
|
|
|
return "DRM_IOCTL_I915_INIT_HEAP";
|
|
|
|
case DRM_IOCTL_I915_CMDBUFFER:
|
|
|
|
return "DRM_IOCTL_I915_CMDBUFFER";
|
|
|
|
case DRM_IOCTL_I915_DESTROY_HEAP:
|
|
|
|
return "DRM_IOCTL_I915_DESTROY_HEAP";
|
|
|
|
case DRM_IOCTL_I915_SET_VBLANK_PIPE:
|
|
|
|
return "DRM_IOCTL_I915_SET_VBLANK_PIPE";
|
|
|
|
case DRM_IOCTL_I915_GET_VBLANK_PIPE:
|
|
|
|
return "DRM_IOCTL_I915_GET_VBLANK_PIPE";
|
|
|
|
case DRM_IOCTL_I915_VBLANK_SWAP:
|
|
|
|
return "DRM_IOCTL_I915_VBLANK_SWAP";
|
|
|
|
case DRM_IOCTL_I915_HWS_ADDR:
|
|
|
|
return "DRM_IOCTL_I915_HWS_ADDR";
|
|
|
|
case DRM_IOCTL_I915_GEM_INIT:
|
|
|
|
return "DRM_IOCTL_I915_GEM_INIT";
|
|
|
|
case DRM_IOCTL_I915_GEM_EXECBUFFER:
|
|
|
|
return "DRM_IOCTL_I915_GEM_EXECBUFFER";
|
|
|
|
case DRM_IOCTL_I915_GEM_EXECBUFFER2_WR:
|
|
|
|
return "DRM_IOCTL_I915_GEM_EXECBUFFER2_WR";
|
|
|
|
case DRM_IOCTL_I915_GEM_PIN:
|
|
|
|
return "DRM_IOCTL_I915_GEM_PIN";
|
|
|
|
case DRM_IOCTL_I915_GEM_UNPIN:
|
|
|
|
return "DRM_IOCTL_I915_GEM_UNPIN";
|
|
|
|
case DRM_IOCTL_I915_GEM_BUSY:
|
|
|
|
return "DRM_IOCTL_I915_GEM_BUSY";
|
|
|
|
case DRM_IOCTL_I915_GEM_SET_CACHING:
|
|
|
|
return "DRM_IOCTL_I915_GEM_SET_CACHING";
|
|
|
|
case DRM_IOCTL_I915_GEM_GET_CACHING:
|
|
|
|
return "DRM_IOCTL_I915_GEM_GET_CACHING";
|
|
|
|
case DRM_IOCTL_I915_GEM_THROTTLE:
|
|
|
|
return "DRM_IOCTL_I915_GEM_THROTTLE";
|
|
|
|
case DRM_IOCTL_I915_GEM_ENTERVT:
|
|
|
|
return "DRM_IOCTL_I915_GEM_ENTERVT";
|
|
|
|
case DRM_IOCTL_I915_GEM_LEAVEVT:
|
|
|
|
return "DRM_IOCTL_I915_GEM_LEAVEVT";
|
|
|
|
case DRM_IOCTL_I915_GEM_CREATE:
|
|
|
|
return "DRM_IOCTL_I915_GEM_CREATE";
|
|
|
|
case DRM_IOCTL_I915_GEM_PREAD:
|
|
|
|
return "DRM_IOCTL_I915_GEM_PREAD";
|
|
|
|
case DRM_IOCTL_I915_GEM_PWRITE:
|
|
|
|
return "DRM_IOCTL_I915_GEM_PWRITE";
|
|
|
|
case DRM_IOCTL_I915_GEM_SET_DOMAIN:
|
|
|
|
return "DRM_IOCTL_I915_GEM_SET_DOMAIN";
|
|
|
|
case DRM_IOCTL_I915_GEM_SW_FINISH:
|
|
|
|
return "DRM_IOCTL_I915_GEM_SW_FINISH";
|
|
|
|
case DRM_IOCTL_I915_GEM_SET_TILING:
|
|
|
|
return "DRM_IOCTL_I915_GEM_SET_TILING";
|
|
|
|
case DRM_IOCTL_I915_GEM_GET_TILING:
|
|
|
|
return "DRM_IOCTL_I915_GEM_GET_TILING";
|
|
|
|
case DRM_IOCTL_I915_GEM_GET_APERTURE:
|
|
|
|
return "DRM_IOCTL_I915_GEM_GET_APERTURE";
|
|
|
|
case DRM_IOCTL_I915_GET_PIPE_FROM_CRTC_ID:
|
|
|
|
return "DRM_IOCTL_I915_GET_PIPE_FROM_CRTC_ID";
|
|
|
|
case DRM_IOCTL_I915_GEM_MADVISE:
|
|
|
|
return "DRM_IOCTL_I915_GEM_MADVISE";
|
|
|
|
case DRM_IOCTL_I915_OVERLAY_PUT_IMAGE:
|
|
|
|
return "DRM_IOCTL_I915_OVERLAY_PUT_IMAGE";
|
|
|
|
case DRM_IOCTL_I915_OVERLAY_ATTRS:
|
|
|
|
return "DRM_IOCTL_I915_OVERLAY_ATTRS";
|
|
|
|
case DRM_IOCTL_I915_SET_SPRITE_COLORKEY:
|
|
|
|
return "DRM_IOCTL_I915_SET_SPRITE_COLORKEY";
|
|
|
|
case DRM_IOCTL_I915_GET_SPRITE_COLORKEY:
|
|
|
|
return "DRM_IOCTL_I915_GET_SPRITE_COLORKEY";
|
|
|
|
case DRM_IOCTL_I915_GEM_CONTEXT_CREATE:
|
|
|
|
return "DRM_IOCTL_I915_GEM_CONTEXT_CREATE";
|
|
|
|
case DRM_IOCTL_I915_GEM_CONTEXT_CREATE_EXT:
|
|
|
|
return "DRM_IOCTL_I915_GEM_CONTEXT_CREATE_EXT";
|
|
|
|
case DRM_IOCTL_I915_GEM_CONTEXT_DESTROY:
|
|
|
|
return "DRM_IOCTL_I915_GEM_CONTEXT_DESTROY";
|
|
|
|
case DRM_IOCTL_I915_REG_READ:
|
|
|
|
return "DRM_IOCTL_I915_REG_READ";
|
|
|
|
case DRM_IOCTL_I915_GET_RESET_STATS:
|
|
|
|
return "DRM_IOCTL_I915_GET_RESET_STATS";
|
|
|
|
case DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM:
|
|
|
|
return "DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM";
|
|
|
|
case DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM:
|
|
|
|
return "DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM";
|
|
|
|
case DRM_IOCTL_I915_PERF_OPEN:
|
|
|
|
return "DRM_IOCTL_I915_PERF_OPEN";
|
|
|
|
case DRM_IOCTL_I915_PERF_ADD_CONFIG:
|
|
|
|
return "DRM_IOCTL_I915_PERF_ADD_CONFIG";
|
|
|
|
case DRM_IOCTL_I915_PERF_REMOVE_CONFIG:
|
|
|
|
return "DRM_IOCTL_I915_PERF_REMOVE_CONFIG";
|
|
|
|
case DRM_IOCTL_I915_QUERY:
|
|
|
|
return "DRM_IOCTL_I915_QUERY";
|
|
|
|
default:
|
|
|
|
return ioctlToStringImpl(request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-07 15:34:31 +08:00
|
|
|
bool Drm::createVirtualMemoryAddressSpace(uint32_t vmCount) {
|
|
|
|
for (auto i = 0u; i < vmCount; i++) {
|
2021-03-17 01:47:26 +08:00
|
|
|
uint32_t id = i;
|
2020-07-14 10:36:16 +08:00
|
|
|
if (0 != createDrmVirtualMemory(id)) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-07-07 15:34:31 +08:00
|
|
|
virtualMemoryIds.push_back(id);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drm::destroyVirtualMemoryAddressSpace() {
|
|
|
|
for (auto id : virtualMemoryIds) {
|
|
|
|
destroyDrmVirtualMemory(id);
|
|
|
|
}
|
2020-08-04 16:23:54 +08:00
|
|
|
virtualMemoryIds.clear();
|
2020-07-07 15:34:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Drm::getVirtualMemoryAddressSpace(uint32_t vmId) {
|
2020-07-14 10:36:16 +08:00
|
|
|
if (vmId < virtualMemoryIds.size()) {
|
|
|
|
return virtualMemoryIds[vmId];
|
|
|
|
}
|
|
|
|
return 0;
|
2020-07-07 15:34:31 +08:00
|
|
|
}
|
|
|
|
|
2021-05-07 23:29:28 +08:00
|
|
|
bool Drm::translateTopologyInfo(const drm_i915_query_topology_info *queryTopologyInfo, QueryTopologyData &data, TopologyMapping &mapping) {
|
|
|
|
int sliceCount = 0;
|
|
|
|
int subSliceCount = 0;
|
|
|
|
int euCount = 0;
|
2021-05-17 23:04:01 +08:00
|
|
|
int maxSliceCount = 0;
|
|
|
|
int maxSubSliceCountPerSlice = 0;
|
2021-04-27 22:45:13 +08:00
|
|
|
std::vector<int> sliceIndices;
|
|
|
|
sliceIndices.reserve(maxSliceCount);
|
2021-01-26 19:02:17 +08:00
|
|
|
|
|
|
|
for (int x = 0; x < queryTopologyInfo->max_slices; x++) {
|
|
|
|
bool isSliceEnable = (queryTopologyInfo->data[x / 8] >> (x % 8)) & 1;
|
|
|
|
if (!isSliceEnable) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-04-27 22:45:13 +08:00
|
|
|
sliceIndices.push_back(x);
|
2021-01-26 19:02:17 +08:00
|
|
|
sliceCount++;
|
2021-05-17 23:04:01 +08:00
|
|
|
|
|
|
|
std::vector<int> subSliceIndices;
|
|
|
|
subSliceIndices.reserve(queryTopologyInfo->max_subslices);
|
|
|
|
|
2021-01-26 19:02:17 +08:00
|
|
|
for (int y = 0; y < queryTopologyInfo->max_subslices; y++) {
|
|
|
|
size_t yOffset = (queryTopologyInfo->subslice_offset + x * queryTopologyInfo->subslice_stride + y / 8);
|
|
|
|
bool isSubSliceEnabled = (queryTopologyInfo->data[yOffset] >> (y % 8)) & 1;
|
|
|
|
if (!isSubSliceEnabled) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
subSliceCount++;
|
2021-05-17 23:04:01 +08:00
|
|
|
subSliceIndices.push_back(y);
|
|
|
|
|
2021-01-26 19:02:17 +08:00
|
|
|
for (int z = 0; z < queryTopologyInfo->max_eus_per_subslice; z++) {
|
|
|
|
size_t zOffset = (queryTopologyInfo->eu_offset + (x * queryTopologyInfo->max_subslices + y) * queryTopologyInfo->eu_stride + z / 8);
|
|
|
|
bool isEUEnabled = (queryTopologyInfo->data[zOffset] >> (z % 8)) & 1;
|
|
|
|
if (!isEUEnabled) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
euCount++;
|
|
|
|
}
|
|
|
|
}
|
2021-05-17 23:04:01 +08:00
|
|
|
|
|
|
|
if (subSliceIndices.size()) {
|
|
|
|
maxSubSliceCountPerSlice = std::max(maxSubSliceCountPerSlice, subSliceIndices[subSliceIndices.size() - 1] + 1);
|
|
|
|
}
|
2021-01-26 19:02:17 +08:00
|
|
|
}
|
|
|
|
|
2021-04-27 22:45:13 +08:00
|
|
|
if (sliceIndices.size()) {
|
|
|
|
maxSliceCount = sliceIndices[sliceIndices.size() - 1] + 1;
|
2021-05-07 23:29:28 +08:00
|
|
|
mapping.sliceIndices = std::move(sliceIndices);
|
2021-04-27 22:45:13 +08:00
|
|
|
}
|
2021-05-07 23:29:28 +08:00
|
|
|
|
|
|
|
data.sliceCount = sliceCount;
|
|
|
|
data.subSliceCount = subSliceCount;
|
|
|
|
data.euCount = euCount;
|
|
|
|
data.maxSliceCount = maxSliceCount;
|
2021-05-17 23:04:01 +08:00
|
|
|
data.maxSubSliceCount = maxSubSliceCountPerSlice;
|
2021-05-07 23:29:28 +08:00
|
|
|
|
|
|
|
return (data.sliceCount && data.subSliceCount && data.euCount);
|
2021-01-26 19:02:17 +08:00
|
|
|
}
|
|
|
|
|
2020-11-05 20:40:03 +08:00
|
|
|
PhysicalDevicePciBusInfo Drm::getPciBusInfo() const {
|
|
|
|
PhysicalDevicePciBusInfo pciBusInfo(PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue, PhysicalDevicePciBusInfo::InvalidValue);
|
|
|
|
|
2021-06-01 00:58:10 +08:00
|
|
|
if (adapterBDF.Data != std::numeric_limits<uint32_t>::max()) {
|
|
|
|
pciBusInfo.pciDomain = 0;
|
|
|
|
pciBusInfo.pciBus = adapterBDF.Bus;
|
|
|
|
pciBusInfo.pciDevice = adapterBDF.Device;
|
|
|
|
pciBusInfo.pciFunction = adapterBDF.Function;
|
2020-11-05 20:40:03 +08:00
|
|
|
}
|
|
|
|
return pciBusInfo;
|
|
|
|
}
|
|
|
|
|
2020-07-07 15:34:31 +08:00
|
|
|
Drm::~Drm() {
|
|
|
|
destroyVirtualMemoryAddressSpace();
|
2021-04-21 21:52:11 +08:00
|
|
|
this->printIoctlStatistics();
|
2020-07-07 15:34:31 +08:00
|
|
|
}
|
2020-02-13 22:04:21 +08:00
|
|
|
|
2021-06-01 00:58:10 +08:00
|
|
|
int Drm::queryAdapterBDF() {
|
2021-04-23 22:30:04 +08:00
|
|
|
constexpr int pciBusInfoTokensNum = 3;
|
|
|
|
uint32_t bus, device, function;
|
|
|
|
|
|
|
|
if (std::sscanf(hwDeviceId->getPciPath(), "%02x:%02x.%01x", &bus, &device, &function) != pciBusInfoTokensNum) {
|
2021-06-01 00:58:10 +08:00
|
|
|
adapterBDF.Data = std::numeric_limits<uint32_t>::max();
|
|
|
|
return 1;
|
2021-04-23 22:30:04 +08:00
|
|
|
}
|
|
|
|
adapterBDF.Bus = bus;
|
|
|
|
adapterBDF.Function = function;
|
|
|
|
adapterBDF.Device = device;
|
2021-06-01 00:58:10 +08:00
|
|
|
return 0;
|
2021-04-23 22:30:04 +08:00
|
|
|
}
|
|
|
|
|
2021-05-21 07:17:57 +08:00
|
|
|
void Drm::setGmmInputArgs(void *args) {
|
|
|
|
auto gmmInArgs = reinterpret_cast<GMM_INIT_IN_ARGS *>(args);
|
|
|
|
auto adapterBDF = this->getAdapterBDF();
|
2021-05-26 19:23:04 +08:00
|
|
|
#if defined(__linux__)
|
2021-05-21 07:17:57 +08:00
|
|
|
gmmInArgs->FileDescriptor = adapterBDF.Data;
|
2021-05-26 19:23:04 +08:00
|
|
|
#endif
|
2021-05-21 07:17:57 +08:00
|
|
|
gmmInArgs->ClientType = GMM_CLIENT::GMM_OCL_VISTA;
|
|
|
|
}
|
|
|
|
|
2021-05-07 23:29:28 +08:00
|
|
|
const std::vector<int> &Drm::getSliceMappings(uint32_t deviceIndex) {
|
|
|
|
return topologyMap[deviceIndex].sliceIndices;
|
|
|
|
}
|
|
|
|
|
2021-06-15 19:31:12 +08:00
|
|
|
int Drm::waitHandle(uint32_t waitHandle, int64_t timeout) {
|
2021-06-04 20:23:20 +08:00
|
|
|
drm_i915_gem_wait wait = {};
|
|
|
|
wait.bo_handle = waitHandle;
|
2021-06-15 19:31:12 +08:00
|
|
|
wait.timeout_ns = timeout;
|
2021-06-04 20:23:20 +08:00
|
|
|
|
2021-06-15 19:31:12 +08:00
|
|
|
int ret = ioctl(DRM_IOCTL_I915_GEM_WAIT, &wait);
|
|
|
|
if (ret != 0) {
|
|
|
|
int err = errno;
|
|
|
|
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "ioctl(I915_GEM_WAIT) failed with %d. errno=%d(%s)\n", ret, err, strerror(err));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2021-06-04 20:23:20 +08:00
|
|
|
}
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|