2018-08-23 17:53:58 +02:00
|
|
|
/*
|
2023-01-02 11:52:22 +00:00
|
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
2018-09-18 09:11:08 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
2018-08-23 17:53:58 +02:00
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/os_interface/linux/os_context_linux.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2021-04-01 14:12:51 +00:00
|
|
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
2021-01-25 20:43:48 +00:00
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
|
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
2021-03-12 10:46:18 +00:00
|
|
|
#include "shared/source/helpers/engine_node_helper.h"
|
2021-02-10 15:13:50 +00:00
|
|
|
#include "shared/source/helpers/hw_info.h"
|
2021-11-22 12:49:26 +00:00
|
|
|
#include "shared/source/os_interface/hw_info_config.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/os_interface/linux/drm_neo.h"
|
2023-01-23 14:55:52 +00:00
|
|
|
#include "shared/source/os_interface/linux/ioctl_helper.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/os_interface/os_context.h"
|
2021-05-21 01:17:57 +02:00
|
|
|
#include "shared/source/os_interface/os_interface.h"
|
2018-08-23 17:53:58 +02:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2018-11-08 13:05:46 +01:00
|
|
|
|
2022-11-16 19:31:25 +00:00
|
|
|
OsContext *OsContextLinux::create(OSInterface *osInterface, uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor) {
|
2018-11-08 13:05:46 +01:00
|
|
|
if (osInterface) {
|
2022-11-16 19:31:25 +00:00
|
|
|
return new OsContextLinux(*osInterface->getDriverModel()->as<Drm>(), rootDeviceIndex, contextId, engineDescriptor);
|
2018-11-08 13:05:46 +01:00
|
|
|
}
|
2022-11-16 19:31:25 +00:00
|
|
|
return new OsContext(rootDeviceIndex, contextId, engineDescriptor);
|
2018-08-23 17:53:58 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-16 19:31:25 +00:00
|
|
|
OsContextLinux::OsContextLinux(Drm &drm, uint32_t rootDeviceIndex, uint32_t contextId, const EngineDescriptor &engineDescriptor)
|
|
|
|
|
: OsContext(rootDeviceIndex, contextId, engineDescriptor),
|
2021-04-15 16:14:04 +00:00
|
|
|
drm(drm) {}
|
|
|
|
|
|
|
|
|
|
void OsContextLinux::initializeContext() {
|
2021-02-10 15:13:50 +00:00
|
|
|
auto hwInfo = drm.getRootDeviceEnvironment().getHardwareInfo();
|
|
|
|
|
auto defaultEngineType = getChosenEngineType(*hwInfo);
|
|
|
|
|
|
2021-03-08 18:50:32 +00:00
|
|
|
if (engineType == defaultEngineType && !isLowPriority() && !isInternalEngine()) {
|
2021-02-10 15:13:50 +00:00
|
|
|
this->setDefaultContext(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool submitDirect = false;
|
|
|
|
|
this->isDirectSubmissionAvailable(*drm.getRootDeviceEnvironment().getHardwareInfo(), submitDirect);
|
|
|
|
|
|
2021-04-29 16:02:10 +00:00
|
|
|
if (drm.isPerContextVMRequired()) {
|
|
|
|
|
this->drmVmIds.resize(deviceBitfield.size(), 0);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-11 14:29:45 +02:00
|
|
|
for (auto deviceIndex = 0u; deviceIndex < deviceBitfield.size(); deviceIndex++) {
|
|
|
|
|
if (deviceBitfield.test(deviceIndex)) {
|
2020-07-07 09:34:31 +02:00
|
|
|
auto drmVmId = drm.getVirtualMemoryAddressSpace(deviceIndex);
|
2022-06-28 17:10:24 +02:00
|
|
|
auto drmContextId = drm.getIoctlHelper()->createDrmContext(drm, *this, drmVmId, deviceIndex);
|
2021-03-12 10:46:18 +00:00
|
|
|
|
2019-07-11 14:29:45 +02:00
|
|
|
this->drmContextIds.push_back(drmContextId);
|
2020-08-17 12:07:39 +02:00
|
|
|
|
|
|
|
|
if (drm.isPerContextVMRequired()) {
|
2021-10-22 11:43:24 +00:00
|
|
|
[[maybe_unused]] auto ret = drm.queryVmId(drmContextId, drmVmId);
|
2020-08-31 07:04:58 +02:00
|
|
|
DEBUG_BREAK_IF(drmVmId == 0);
|
|
|
|
|
DEBUG_BREAK_IF(ret != 0);
|
2021-10-22 11:43:24 +00:00
|
|
|
|
2021-04-29 16:02:10 +00:00
|
|
|
UNRECOVERABLE_IF(this->drmVmIds.size() <= deviceIndex);
|
|
|
|
|
this->drmVmIds[deviceIndex] = drmVmId;
|
2020-08-17 12:07:39 +02:00
|
|
|
}
|
2019-07-11 14:29:45 +02:00
|
|
|
}
|
2018-12-11 08:21:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-31 13:06:23 +00:00
|
|
|
bool OsContextLinux::isDirectSubmissionSupported(const HardwareInfo &hwInfo) const {
|
2023-01-02 11:52:22 +00:00
|
|
|
auto &productHelper = this->getDrm().getRootDeviceEnvironment().getHelper<ProductHelper>();
|
|
|
|
|
|
|
|
|
|
return this->getDrm().isVmBindAvailable() && productHelper.isDirectSubmissionSupported(hwInfo);
|
2021-03-31 13:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-02 11:49:46 +02:00
|
|
|
Drm &OsContextLinux::getDrm() const {
|
|
|
|
|
return this->drm;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-05 15:27:21 +00:00
|
|
|
void OsContextLinux::waitForPagingFence() {
|
|
|
|
|
for (auto drmIterator = 0u; drmIterator < this->deviceBitfield.size(); drmIterator++) {
|
|
|
|
|
if (this->deviceBitfield.test(drmIterator)) {
|
|
|
|
|
drm.waitForBind(drmIterator);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-16 02:13:00 +00:00
|
|
|
void OsContextLinux::reInitializeContext() {}
|
|
|
|
|
|
2019-02-27 11:17:17 +01:00
|
|
|
OsContextLinux::~OsContextLinux() {
|
2021-04-15 16:14:04 +00:00
|
|
|
if (contextInitialized) {
|
|
|
|
|
for (auto drmContextId : drmContextIds) {
|
|
|
|
|
drm.destroyDrmContext(drmContextId);
|
|
|
|
|
}
|
2019-07-11 14:29:45 +02:00
|
|
|
}
|
2021-10-07 07:26:03 +00:00
|
|
|
drmContextIds.clear();
|
|
|
|
|
drmVmIds.clear();
|
2018-11-26 14:04:52 +01:00
|
|
|
}
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|