2020-09-14 19:28:47 +08:00
|
|
|
/*
|
2022-02-10 19:13:59 +08:00
|
|
|
* Copyright (C) 2020-2022 Intel Corporation
|
2020-09-14 19:28:47 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-02-28 21:56:41 +08:00
|
|
|
#include "shared/source/os_interface/linux/drm_debug.h"
|
|
|
|
|
2022-05-18 03:04:23 +08:00
|
|
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
2022-02-28 21:56:41 +08:00
|
|
|
#include "shared/source/helpers/string.h"
|
|
|
|
#include "shared/source/os_interface/linux/drm_neo.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
2020-09-14 19:28:47 +08:00
|
|
|
|
|
|
|
namespace NEO {
|
2020-10-26 21:48:20 +08:00
|
|
|
|
2020-09-14 19:28:47 +08:00
|
|
|
bool Drm::registerResourceClasses() {
|
2022-02-28 21:56:41 +08:00
|
|
|
for (auto classNameUUID : classNamesToUuid) {
|
|
|
|
auto className = classNameUUID.first;
|
|
|
|
auto uuid = classNameUUID.second;
|
|
|
|
|
2022-06-30 00:49:29 +08:00
|
|
|
const auto result = ioctlHelper->registerStringClassUuid(uuid, (uintptr_t)className, strnlen_s(className, 100));
|
2022-02-28 21:56:41 +08:00
|
|
|
if (result.retVal != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
classHandles.push_back(result.handle);
|
|
|
|
}
|
|
|
|
return true;
|
2020-09-14 19:28:47 +08:00
|
|
|
}
|
|
|
|
|
2022-05-09 23:52:12 +08:00
|
|
|
uint32_t Drm::registerResource(DrmResourceClass classType, const void *data, size_t size) {
|
2022-02-28 21:56:41 +08:00
|
|
|
if (classHandles.size() < static_cast<uint32_t>(classType)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string uuid;
|
2022-05-09 23:52:12 +08:00
|
|
|
if (classType == NEO::DrmResourceClass::Elf) {
|
2022-02-28 21:56:41 +08:00
|
|
|
uuid = generateElfUUID(data);
|
|
|
|
} else {
|
|
|
|
uuid = generateUUID();
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto uuidClass = classHandles[static_cast<uint32_t>(classType)];
|
|
|
|
const auto ptr = size > 0 ? (uintptr_t)data : 0;
|
2022-06-30 00:49:29 +08:00
|
|
|
const auto result = ioctlHelper->registerUuid(uuid, uuidClass, ptr, size);
|
2022-02-28 21:56:41 +08:00
|
|
|
|
|
|
|
PRINT_DEBUGGER_INFO_LOG("PRELIM_DRM_IOCTL_I915_UUID_REGISTER: classType = %d, uuid = %s, data = %p, handle = %lu, ret = %d\n", (int)classType, std::string(uuid, 36).c_str(), ptr, result.handle, result.retVal);
|
|
|
|
DEBUG_BREAK_IF(result.retVal != 0);
|
|
|
|
|
|
|
|
return result.handle;
|
2020-09-14 19:28:47 +08:00
|
|
|
}
|
|
|
|
|
2020-10-26 21:48:20 +08:00
|
|
|
uint32_t Drm::registerIsaCookie(uint32_t isaHandle) {
|
2022-02-28 21:56:41 +08:00
|
|
|
auto uuid = generateUUID();
|
|
|
|
|
2022-06-30 00:49:29 +08:00
|
|
|
const auto result = ioctlHelper->registerUuid(uuid, isaHandle, 0, 0);
|
2022-02-28 21:56:41 +08:00
|
|
|
|
|
|
|
PRINT_DEBUGGER_INFO_LOG("PRELIM_DRM_IOCTL_I915_UUID_REGISTER: isa handle = %lu, uuid = %s, data = %p, handle = %lu, ret = %d\n", isaHandle, std::string(uuid, 36).c_str(), 0, result.handle, result.retVal);
|
|
|
|
DEBUG_BREAK_IF(result.retVal != 0);
|
|
|
|
|
|
|
|
return result.handle;
|
2020-10-26 21:48:20 +08:00
|
|
|
}
|
|
|
|
|
2020-09-14 19:28:47 +08:00
|
|
|
void Drm::unregisterResource(uint32_t handle) {
|
2022-02-28 21:56:41 +08:00
|
|
|
PRINT_DEBUGGER_INFO_LOG("PRELIM_DRM_IOCTL_I915_UUID_UNREGISTER: handle = %lu\n", handle);
|
2022-06-30 00:49:29 +08:00
|
|
|
[[maybe_unused]] const auto ret = ioctlHelper->unregisterUuid(handle);
|
2022-02-28 21:56:41 +08:00
|
|
|
DEBUG_BREAK_IF(ret != 0);
|
2020-09-14 19:28:47 +08:00
|
|
|
}
|
2020-12-12 05:28:22 +08:00
|
|
|
|
|
|
|
std::string Drm::generateUUID() {
|
|
|
|
const char uuidString[] = "00000000-0000-0000-%04" SCNx64 "-%012" SCNx64;
|
|
|
|
char buffer[36 + 1] = "00000000-0000-0000-0000-000000000000";
|
|
|
|
uuid++;
|
|
|
|
|
|
|
|
UNRECOVERABLE_IF(uuid == 0xFFFFFFFFFFFFFFFF);
|
|
|
|
|
|
|
|
uint64_t parts[2] = {0, 0};
|
|
|
|
parts[0] = uuid & 0xFFFFFFFFFFFF;
|
|
|
|
parts[1] = (uuid & 0xFFFF000000000000) >> 48;
|
|
|
|
snprintf(buffer, sizeof(buffer), uuidString, parts[1], parts[0]);
|
|
|
|
|
|
|
|
return std::string(buffer, 36);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Drm::generateElfUUID(const void *data) {
|
2022-05-12 22:04:41 +08:00
|
|
|
std::string elfClassUuid = classNamesToUuid[static_cast<uint32_t>(DrmResourceClass::Elf)].second;
|
|
|
|
std::string uuiD1st = elfClassUuid.substr(0, 18);
|
2022-02-28 21:56:41 +08:00
|
|
|
|
|
|
|
const char uuidString[] = "%s-%04" SCNx64 "-%012" SCNx64;
|
|
|
|
char buffer[36 + 1] = "00000000-0000-0000-0000-000000000000";
|
|
|
|
|
|
|
|
uint64_t parts[2] = {0, 0};
|
|
|
|
parts[0] = reinterpret_cast<uintptr_t>(data) & 0xFFFFFFFFFFFF;
|
|
|
|
parts[1] = (reinterpret_cast<uintptr_t>(data) & 0xFFFF000000000000) >> 48;
|
2022-05-12 22:04:41 +08:00
|
|
|
snprintf(buffer, sizeof(buffer), uuidString, uuiD1st.c_str(), parts[1], parts[0]);
|
2022-02-28 21:56:41 +08:00
|
|
|
|
|
|
|
return std::string(buffer, 36);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drm::checkContextDebugSupport() {
|
2022-06-30 00:49:29 +08:00
|
|
|
contextDebugSupported = ioctlHelper->isContextDebugSupported();
|
2022-02-28 21:56:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Drm::setContextDebugFlag(uint32_t drmContextId) {
|
2022-06-30 00:49:29 +08:00
|
|
|
[[maybe_unused]] const auto retVal = ioctlHelper->setContextDebugFlag(drmContextId);
|
2022-02-28 21:56:41 +08:00
|
|
|
DEBUG_BREAK_IF(retVal != 0 && contextDebugSupported);
|
2020-12-12 05:28:22 +08:00
|
|
|
}
|
|
|
|
|
2022-07-22 20:07:36 +08:00
|
|
|
uint32_t Drm::notifyFirstCommandQueueCreated(const void *data, size_t size) {
|
|
|
|
const auto result = ioctlHelper->registerStringClassUuid(uuidL0CommandQueueHash, (uintptr_t)data, size);
|
2022-02-28 21:56:41 +08:00
|
|
|
DEBUG_BREAK_IF(result.retVal);
|
|
|
|
return result.handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drm::notifyLastCommandQueueDestroyed(uint32_t handle) {
|
|
|
|
unregisterResource(handle);
|
|
|
|
}
|
2021-01-26 04:43:48 +08:00
|
|
|
|
2020-10-17 06:52:18 +08:00
|
|
|
} // namespace NEO
|