/* * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * */ #include "shared/source/debugger/debugger_l0.h" #include "shared/source/device/sub_device.h" #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/helpers/basic_math.h" #include "shared/source/helpers/hw_helper.h" #include "shared/source/kernel/debug_data.h" #include "shared/source/os_interface/linux/drm_allocation.h" #include "shared/source/os_interface/linux/drm_neo.h" #include "shared/source/os_interface/os_interface.h" namespace NEO { bool DebuggerL0::initDebuggingInOs(NEO::OSInterface *osInterface) { if (osInterface != nullptr) { auto drm = osInterface->getDriverModel()->as(); if (drm->isVmBindAvailable() && drm->isPerContextVMRequired()) { drm->registerResourceClasses(); return true; } } return false; } void DebuggerL0::initSbaTrackingMode() { singleAddressSpaceSbaTracking = false; } void DebuggerL0::registerAllocationType(GraphicsAllocation *allocation) {} void DebuggerL0::registerElf(NEO::DebugData *debugData, NEO::GraphicsAllocation *isaAllocation) { if (device->getRootDeviceEnvironment().osInterface.get() != nullptr) { auto drm = device->getRootDeviceEnvironment().osInterface->getDriverModel()->as(); auto handle = drm->registerResource(NEO::DrmResourceClass::Elf, debugData->vIsa, debugData->vIsaSize); static_cast(isaAllocation)->linkWithRegisteredHandle(handle); } } bool DebuggerL0::attachZebinModuleToSegmentAllocations(const StackVec &allocs, uint32_t &moduleHandle) { if (device->getRootDeviceEnvironment().osInterface == nullptr) { return false; } auto drm = device->getRootDeviceEnvironment().osInterface->getDriverModel()->as(); uint32_t segmentCount = static_cast(allocs.size()); moduleHandle = drm->registerResource(NEO::DrmResourceClass::L0ZebinModule, &segmentCount, sizeof(uint32_t)); for (auto &allocation : allocs) { auto drmAllocation = static_cast(allocation); drmAllocation->linkWithRegisteredHandle(moduleHandle); } return true; } bool DebuggerL0::removeZebinModule(uint32_t moduleHandle) { if (device->getRootDeviceEnvironment().osInterface == nullptr || moduleHandle == 0) { return false; } auto drm = device->getRootDeviceEnvironment().osInterface->getDriverModel()->as(); drm->unregisterResource(moduleHandle); return true; } void DebuggerL0::notifyModuleDestroy(uint64_t moduleLoadAddress) {} void DebuggerL0::notifyCommandQueueCreated(NEO::Device *device) { if (this->device->getRootDeviceEnvironment().osInterface.get() != nullptr) { std::unique_lock commandQueueCountLock(debuggerL0Mutex); if (!device->isSubDevice() && device->getDeviceBitfield().count() > 1) { UNRECOVERABLE_IF(this->device->getNumSubDevices() != device->getDeviceBitfield().count()); for (size_t i = 0; i < device->getDeviceBitfield().size(); i++) { if (device->getDeviceBitfield().test(i)) { if (++commandQueueCount[i] == 1) { auto drm = this->device->getRootDeviceEnvironment().osInterface->getDriverModel()->as(); CommandQueueNotification notification = {static_cast(i), this->device->getNumSubDevices()}; uuidL0CommandQueueHandle[i] = drm->notifyFirstCommandQueueCreated(¬ification, sizeof(CommandQueueNotification)); } } } return; } auto index = 0u; auto deviceIndex = 0u; if (device->isSubDevice()) { index = static_cast(device)->getSubDeviceIndex(); deviceIndex = index; } else if (device->getDeviceBitfield().count() == 1) { deviceIndex = Math::log2(static_cast(device->getDeviceBitfield().to_ulong())); } if (++commandQueueCount[index] == 1) { auto drm = this->device->getRootDeviceEnvironment().osInterface->getDriverModel()->as(); CommandQueueNotification notification = {deviceIndex, this->device->getNumSubDevices()}; uuidL0CommandQueueHandle[index] = drm->notifyFirstCommandQueueCreated(¬ification, sizeof(CommandQueueNotification)); } } } void DebuggerL0::notifyCommandQueueDestroyed(NEO::Device *device) { if (this->device->getRootDeviceEnvironment().osInterface.get() != nullptr) { std::unique_lock commandQueueCountLock(debuggerL0Mutex); if (!device->isSubDevice() && device->getDeviceBitfield().count() > 1) { UNRECOVERABLE_IF(this->device->getNumSubDevices() != device->getDeviceBitfield().count()); for (size_t i = 0; i < device->getDeviceBitfield().size(); i++) { if (device->getDeviceBitfield().test(i)) { if (--commandQueueCount[i] == 0) { auto drm = this->device->getRootDeviceEnvironment().osInterface->getDriverModel()->as(); drm->notifyLastCommandQueueDestroyed(uuidL0CommandQueueHandle[i]); uuidL0CommandQueueHandle[i] = 0; } } } return; } auto index = device->isSubDevice() ? static_cast(device)->getSubDeviceIndex() : 0; if (--commandQueueCount[index] == 0) { auto drm = this->device->getRootDeviceEnvironment().osInterface->getDriverModel()->as(); drm->notifyLastCommandQueueDestroyed(uuidL0CommandQueueHandle[index]); uuidL0CommandQueueHandle[index] = 0; } } } void DebuggerL0::notifyModuleCreate(void *module, uint32_t moduleSize, uint64_t moduleLoadAddress) {} } // namespace NEO