2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2021-02-23 17:57:27 +00:00
|
|
|
* Copyright (C) 2017-2021 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/os_interface/linux/os_interface.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/execution_environment/execution_environment.h"
|
|
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
2020-03-02 14:11:08 +01:00
|
|
|
#include "shared/source/gmm_helper/gmm_lib.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/os_interface/hw_info_config.h"
|
|
|
|
|
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
|
|
|
|
|
#include "shared/source/os_interface/linux/drm_neo.h"
|
2021-03-29 13:43:50 +02:00
|
|
|
#include "shared/source/os_interface/linux/sys_calls.h"
|
|
|
|
|
|
|
|
|
|
#include <optional>
|
|
|
|
|
#include <string_view>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <system_error>
|
|
|
|
|
#include <unistd.h>
|
2020-02-11 17:48:40 +01:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
bool OSInterface::osEnabled64kbPages = false;
|
2020-09-22 16:29:34 +02:00
|
|
|
bool OSInterface::newResourceImplicitFlush = true;
|
|
|
|
|
bool OSInterface::gpuIdleImplicitFlush = true;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-02-11 17:48:40 +01:00
|
|
|
OSInterface::OSInterfaceImpl::OSInterfaceImpl() = default;
|
|
|
|
|
OSInterface::OSInterfaceImpl::~OSInterfaceImpl() = default;
|
|
|
|
|
void OSInterface::OSInterfaceImpl::setDrm(Drm *drm) {
|
|
|
|
|
this->drm.reset(drm);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-23 17:57:27 +00:00
|
|
|
bool OSInterface::OSInterfaceImpl::isDebugAttachAvailable() const {
|
|
|
|
|
if (drm) {
|
|
|
|
|
return drm->isDebugAttachAvailable();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
OSInterface::OSInterface() {
|
|
|
|
|
osInterfaceImpl = new OSInterfaceImpl();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OSInterface::~OSInterface() {
|
|
|
|
|
delete osInterfaceImpl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool OSInterface::are64kbPagesEnabled() {
|
|
|
|
|
return osEnabled64kbPages;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-20 14:44:14 +02:00
|
|
|
uint32_t OSInterface::getDeviceHandle() const {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-23 17:57:27 +00:00
|
|
|
bool OSInterface::isDebugAttachAvailable() const {
|
|
|
|
|
return osInterfaceImpl->isDebugAttachAvailable();
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-10 12:36:44 +02:00
|
|
|
bool RootDeviceEnvironment::initOsInterface(std::unique_ptr<HwDeviceId> &&hwDeviceId, uint32_t rootDeviceIndex) {
|
2020-02-13 13:26:40 +01:00
|
|
|
Drm *drm = Drm::create(std::move(hwDeviceId), *this);
|
|
|
|
|
if (!drm) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
osInterface.reset(new OSInterface());
|
|
|
|
|
osInterface->get()->setDrm(drm);
|
2020-03-04 08:51:02 +01:00
|
|
|
auto hardwareInfo = getMutableHardwareInfo();
|
2020-02-13 13:26:40 +01:00
|
|
|
HwInfoConfig *hwConfig = HwInfoConfig::get(hardwareInfo->platform.eProductFamily);
|
|
|
|
|
if (hwConfig->configureHwInfo(hardwareInfo, hardwareInfo, osInterface.get())) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-09-30 13:01:05 +02:00
|
|
|
memoryOperationsInterface = DrmMemoryOperationsHandler::create(*drm, rootDeviceIndex);
|
2020-02-13 13:26:40 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2021-03-29 13:43:50 +02:00
|
|
|
|
|
|
|
|
std::optional<std::string> OSInterface::OSInterfaceImpl::getPciPath(int deviceFd) {
|
|
|
|
|
char path[256] = {0};
|
|
|
|
|
size_t pathlen = 256;
|
|
|
|
|
|
|
|
|
|
if (SysCalls::getDevicePath(deviceFd, path, pathlen)) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (SysCalls::access(path, F_OK)) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int readLinkSize = 0;
|
|
|
|
|
char devicePath[256] = {0};
|
|
|
|
|
readLinkSize = SysCalls::readlink(path, devicePath, pathlen);
|
|
|
|
|
|
|
|
|
|
if (readLinkSize == -1) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string_view devicePathView(devicePath, static_cast<size_t>(readLinkSize));
|
|
|
|
|
devicePathView = devicePathView.substr(devicePathView.find("/drm/render") - 7u, 7u);
|
|
|
|
|
|
|
|
|
|
return std::string(devicePathView);
|
|
|
|
|
}
|
2019-08-21 10:53:07 +02:00
|
|
|
} // namespace NEO
|