2020-06-22 14:34:44 +02:00
|
|
|
/*
|
2021-01-29 22:23:06 +00:00
|
|
|
* Copyright (C) 2020-2021 Intel Corporation
|
2020-06-22 14:34:44 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2021-09-29 23:24:19 +02:00
|
|
|
#include "shared/source/helpers/debug_helpers.h"
|
2021-11-02 15:36:22 +00:00
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
2021-09-29 23:24:19 +02:00
|
|
|
#include "shared/source/helpers/string.h"
|
2020-06-22 14:34:44 +02:00
|
|
|
#include "shared/source/os_interface/linux/drm_engine_mapper.h"
|
2020-08-24 13:08:59 -04:00
|
|
|
#include "shared/source/os_interface/linux/engine_info_impl.h"
|
2021-10-13 13:30:46 +00:00
|
|
|
#include "shared/source/os_interface/linux/local_memory_helper.h"
|
2020-06-22 14:34:44 +02:00
|
|
|
#include "shared/source/os_interface/linux/memory_info_impl.h"
|
2021-03-16 17:47:26 +00:00
|
|
|
#include "shared/source/os_interface/linux/sys_calls.h"
|
2020-06-22 14:34:44 +02:00
|
|
|
|
|
|
|
|
#include "drm_neo.h"
|
2020-11-19 12:04:17 +01:00
|
|
|
#include "drm_query_flags.h"
|
2020-06-22 14:34:44 +02:00
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
|
namespace NEO {
|
2020-08-11 14:00:41 +02:00
|
|
|
class OsContext;
|
2020-06-22 14:34:44 +02:00
|
|
|
|
2021-06-28 13:17:49 +00:00
|
|
|
namespace IoctlHelper {
|
|
|
|
|
std::string getIoctlStringRemaining(unsigned long request) {
|
2021-09-22 14:31:27 +02:00
|
|
|
return std::to_string(request);
|
2021-06-28 13:17:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string getIoctlParamStringRemaining(int param) {
|
2021-09-22 14:31:27 +02:00
|
|
|
return std::to_string(param);
|
2021-06-28 13:17:49 +00:00
|
|
|
}
|
2021-09-29 23:24:19 +02:00
|
|
|
|
2021-06-28 13:17:49 +00:00
|
|
|
} // namespace IoctlHelper
|
|
|
|
|
|
2021-03-31 11:24:22 +05:30
|
|
|
bool Drm::queryEngineInfo(bool isSysmanEnabled) {
|
2020-08-24 13:08:59 -04:00
|
|
|
auto length = 0;
|
2020-11-19 12:04:17 +01:00
|
|
|
auto dataQuery = this->query(DRM_I915_QUERY_ENGINE_INFO, DrmQueryItemFlags::empty, length);
|
2020-08-24 13:08:59 -04:00
|
|
|
auto data = reinterpret_cast<drm_i915_query_engine_info *>(dataQuery.get());
|
|
|
|
|
if (data) {
|
|
|
|
|
this->engineInfo.reset(new EngineInfoImpl(data->engines, data->num_engines));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2020-06-22 14:34:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Drm::queryMemoryInfo() {
|
2021-11-02 15:36:22 +00:00
|
|
|
auto pHwInfo = getRootDeviceEnvironment().getHardwareInfo();
|
|
|
|
|
auto isLocalMemSupported = HwHelper::get(pHwInfo->platform.eRenderCoreFamily).getEnableLocalMemory(*pHwInfo);
|
|
|
|
|
if (!isLocalMemSupported) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-22 14:34:44 +02:00
|
|
|
auto length = 0;
|
2020-11-19 12:04:17 +01:00
|
|
|
auto dataQuery = this->query(DRM_I915_QUERY_MEMORY_REGIONS, DrmQueryItemFlags::empty, length);
|
2021-09-29 23:24:19 +02:00
|
|
|
if (dataQuery) {
|
2021-10-13 13:30:46 +00:00
|
|
|
auto pHwInfo = getRootDeviceEnvironment().getHardwareInfo();
|
|
|
|
|
auto localMemHelper = LocalMemoryHelper::get(pHwInfo->platform.eProductFamily);
|
|
|
|
|
auto data = localMemHelper->translateIfRequired(dataQuery.release(), length);
|
|
|
|
|
auto memRegions = reinterpret_cast<drm_i915_query_memory_regions *>(data.get());
|
|
|
|
|
this->memoryInfo.reset(new MemoryInfoImpl(memRegions->regions, memRegions->num_regions));
|
2020-06-22 14:34:44 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-11 15:17:47 +00:00
|
|
|
unsigned int Drm::bindDrmContext(uint32_t drmContextId, uint32_t deviceIndex, aub_stream::EngineType engineType, bool engineInstancedDevice) {
|
2020-06-22 14:34:44 +02:00
|
|
|
return DrmEngineMapper::engineNodeMap(engineType);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-16 17:47:26 +00:00
|
|
|
int Drm::createDrmVirtualMemory(uint32_t &drmVmId) {
|
|
|
|
|
drm_i915_gem_vm_control ctl = {};
|
|
|
|
|
auto ret = SysCalls::ioctl(getFileDescriptor(), DRM_IOCTL_I915_GEM_VM_CREATE, &ctl);
|
|
|
|
|
if (ret == 0) {
|
2020-09-20 15:41:43 +00:00
|
|
|
if (ctl.vm_id == 0) {
|
|
|
|
|
// 0 is reserved for invalid/unassigned ppgtt
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2021-03-16 17:47:26 +00:00
|
|
|
drmVmId = ctl.vm_id;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-22 14:34:44 +02:00
|
|
|
} // namespace NEO
|