From 4e741029edf43be5fccf6d98306f2d781817fb87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bojan=20Ro=C5=A1ko?= <156314064+broskoTT@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:16:23 +0200 Subject: [PATCH] Move atu disable to silicondevice destructor (#42) --- device/tt_silicon_driver.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/device/tt_silicon_driver.cpp b/device/tt_silicon_driver.cpp index f0b49ab1..f406fc6f 100644 --- a/device/tt_silicon_driver.cpp +++ b/device/tt_silicon_driver.cpp @@ -199,15 +199,6 @@ struct TTDevice : TTDeviceBase TTDevice() = default; void reset() { - if (arch == tt::ARCH::BLACKHOLE && bar2_uc != nullptr && bar2_uc != MAP_FAILED) { - // Disable ATU index 0 - // TODO: Implement disabling for all indexes, once more host channels are enabled. - uint64_t iatu_index = 0; - uint64_t iatu_base = UNROLL_ATU_OFFSET_BAR + iatu_index * 0x200; - uint32_t region_ctrl_2 = 0 << 31; // REGION_EN = 0 - write_regs(reinterpret_cast(static_cast(bar2_uc) + iatu_base + 0x04), ®ion_ctrl_2, 1); - } - if (device_fd != -1) { close(device_fd); } @@ -2105,6 +2096,21 @@ tt_SiliconDevice::~tt_SiliconDevice () { for (auto &device_it : m_pci_device_map){ chip_id_t device_id = device_it.first; + struct PCIdevice* pci_device = device_it.second; + + // If IATU was setup, host_channel_size will be setup for that device_id + // The asumption is that only a single tt_SiliconDevice for which start_device was called, exists at one moment. + // Two tt_SiliconDevice instances for the same device_id which are both started will clash with each other. + if (host_channel_size.find(device_id) != host_channel_size.end()) { + if (archs_in_cluster[device_id] == tt::ARCH::BLACKHOLE) { + // Disable ATU index 0 + // TODO: Implement disabling for all indexes, once more host channels are enabled. + uint64_t iatu_index = 0; + uint64_t iatu_base = UNROLL_ATU_OFFSET_BAR + iatu_index * 0x200; + uint32_t region_ctrl_2 = 0 << 31; // REGION_EN = 0 + write_regs(reinterpret_cast(static_cast(pci_device->hdev->bar2_uc) + iatu_base + 0x04), ®ion_ctrl_2, 1); + } + } for (int ch = 0; ch < m_num_host_mem_channels; ch ++) { if (hugepage_mapping.at(device_id).at(ch)) { @@ -2112,8 +2118,6 @@ tt_SiliconDevice::~tt_SiliconDevice () { } } - struct PCIdevice* pci_device = device_it.second; - ttkmd_close (*pci_device); delete pci_device; pci_device = NULL;