Commit dd08335f authored by Yuri Nudelman's avatar Yuri Nudelman Committed by Oded Gabbay

habanalabs: fix debugfs device memory MMU VA translation

The translation in debugfs of device memory MMU virtual addresses was
wrong as it did not take into consideration the fact that the page
sizes there can be not power of 2.
Signed-off-by: default avatarYuri Nudelman <ynudelman@habana.ai>
Reviewed-by: default avatarOded Gabbay <ogabbay@kernel.org>
Signed-off-by: default avatarOded Gabbay <ogabbay@kernel.org>
parent d62b9a69
...@@ -501,23 +501,25 @@ static void hl_mmu_pa_page_with_offset(struct hl_ctx *ctx, u64 virt_addr, ...@@ -501,23 +501,25 @@ static void hl_mmu_pa_page_with_offset(struct hl_ctx *ctx, u64 virt_addr,
if ((hops->range_type == HL_VA_RANGE_TYPE_DRAM) && if ((hops->range_type == HL_VA_RANGE_TYPE_DRAM) &&
!is_power_of_2(prop->dram_page_size)) { !is_power_of_2(prop->dram_page_size)) {
unsigned long dram_page_size = prop->dram_page_size; u64 dram_page_size, dram_base, abs_phys_addr, abs_virt_addr,
u64 page_offset_mask; page_id, page_start;
u64 phys_addr_mask; u32 page_off;
u32 bit;
/* /*
* find last set bit in page_size to cover all bits of page * Bit arithmetics cannot be used for non power of two page
* offset. note that 1 has to be added to bit index. * sizes. In addition, since bit arithmetics is not used,
* note that the internal ulong variable is used to avoid * we cannot ignore dram base. All that shall be considerd.
* alignment issue.
*/ */
bit = find_last_bit(&dram_page_size,
sizeof(dram_page_size) * BITS_PER_BYTE) + 1; dram_page_size = prop->dram_page_size;
page_offset_mask = (BIT_ULL(bit) - 1); dram_base = prop->dram_base_address;
phys_addr_mask = ~page_offset_mask; abs_phys_addr = tmp_phys_addr - dram_base;
*phys_addr = (tmp_phys_addr & phys_addr_mask) | abs_virt_addr = virt_addr - dram_base;
(virt_addr & page_offset_mask); page_id = DIV_ROUND_DOWN_ULL(abs_phys_addr, dram_page_size);
page_start = page_id * dram_page_size;
div_u64_rem(abs_virt_addr, dram_page_size, &page_off);
*phys_addr = page_start + page_off + dram_base;
} else { } else {
/* /*
* find the correct hop shift field in hl_mmu_properties * find the correct hop shift field in hl_mmu_properties
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment