2018-08-23 17:53:58 +02:00
|
|
|
/*
|
2020-01-13 14:47:05 +01:00
|
|
|
* Copyright (C) 2018-2020 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
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/os_interface/linux/drm_neo.h"
|
|
|
|
|
#include "shared/source/os_interface/linux/os_interface.h"
|
|
|
|
|
#include "shared/source/os_interface/os_context.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
|
|
|
|
2019-03-13 15:00:07 +01:00
|
|
|
OsContext *OsContext::create(OSInterface *osInterface, uint32_t contextId, DeviceBitfield deviceBitfield,
|
2020-03-03 23:33:31 +01:00
|
|
|
aub_stream::EngineType engineType, PreemptionMode preemptionMode,
|
|
|
|
|
bool lowPriority, bool internalEngine, bool rootDevice) {
|
2018-11-08 13:05:46 +01:00
|
|
|
if (osInterface) {
|
2020-03-03 23:33:31 +01:00
|
|
|
return new OsContextLinux(*osInterface->get()->getDrm(), contextId, deviceBitfield, engineType, preemptionMode,
|
|
|
|
|
lowPriority, internalEngine, rootDevice);
|
2018-11-08 13:05:46 +01:00
|
|
|
}
|
2020-03-03 23:33:31 +01:00
|
|
|
return new OsContext(contextId, deviceBitfield, engineType, preemptionMode,
|
|
|
|
|
lowPriority, internalEngine, rootDevice);
|
2018-08-23 17:53:58 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-13 15:00:07 +01:00
|
|
|
OsContextLinux::OsContextLinux(Drm &drm, uint32_t contextId, DeviceBitfield deviceBitfield,
|
2020-03-03 23:33:31 +01:00
|
|
|
aub_stream::EngineType engineType, PreemptionMode preemptionMode,
|
|
|
|
|
bool lowPriority, bool internalEngine, bool rootDevice)
|
|
|
|
|
: OsContext(contextId, deviceBitfield, engineType, preemptionMode, lowPriority, internalEngine, rootDevice),
|
|
|
|
|
drm(drm) {
|
2019-07-11 14:29:45 +02:00
|
|
|
for (auto deviceIndex = 0u; deviceIndex < deviceBitfield.size(); deviceIndex++) {
|
|
|
|
|
if (deviceBitfield.test(deviceIndex)) {
|
|
|
|
|
auto drmContextId = drm.createDrmContext();
|
2020-02-10 08:05:32 -08:00
|
|
|
if (drm.areNonPersistentContextsSupported()) {
|
2019-12-24 12:20:23 +01:00
|
|
|
drm.setNonPersistentContext(drmContextId);
|
2019-12-18 19:38:22 +01:00
|
|
|
}
|
2019-07-11 14:29:45 +02:00
|
|
|
if (drm.isPreemptionSupported() && lowPriority) {
|
|
|
|
|
drm.setLowPriorityContextParam(drmContextId);
|
|
|
|
|
}
|
|
|
|
|
this->engineFlag = drm.bindDrmContext(drmContextId, deviceIndex, engineType);
|
|
|
|
|
this->drmContextIds.push_back(drmContextId);
|
|
|
|
|
}
|
2018-12-11 08:21:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-27 11:17:17 +01:00
|
|
|
OsContextLinux::~OsContextLinux() {
|
2019-07-11 14:29:45 +02:00
|
|
|
for (auto drmContextId : drmContextIds) {
|
|
|
|
|
drm.destroyDrmContext(drmContextId);
|
|
|
|
|
}
|
2018-11-26 14:04:52 +01:00
|
|
|
}
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|