habanalabs: move asic property to correct structure
PATCH 1/1 habanalabs: move asic property to correct structure
Whether an ASIC has MMU towards its DRAM is an ASIC property, so move it to the asic fixed properties structure.
Signed-off-by Oded Gabbay <[email protected]>
--- drivers/misc/habanalabs/common/debugfs.c | 2 +- drivers/misc/habanalabs/common/habanalabs.h | 4 ++-- drivers/misc/habanalabs/common/memory.c | 6 +++--- drivers/misc/habanalabs/common/mmu_v1.c | 4 ++-- drivers/misc/habanalabs/gaudi/gaudi.c | 3 +-- drivers/misc/habanalabs/goya/goya.c | 2 +- 6 files changed, 10 insertions(+), 11 deletions(-)
drivers/misc/habanalabs/common/debugfs.c +1 -1
@@ -598,7 +598,7 @@ static bool hl_is_device_va(struct hl_device *hdev, u64 addr)if (!hdev->mmu_enable) goto out; -if (hdev->dram_supports_virtual_memory && +if (prop->dram_supports_virtual_memory && (addr >= prop->dmmu.start_addr && addr < prop->dmmu.end_addr))return true;
drivers/misc/habanalabs/common/habanalabs.h +2 -2
@@ -411,6 +411,7 @@ struct hl_mmu_properties {* false otherwise * @fw_security_status_valid: security status bits are valid and can be fetched * from BOOT_DEV_STS0 +* @dram_supports_virtual_memory: is there an MMU towards the DRAM */ struct asic_fixed_properties {struct hw_queue_properties *hw_queues_props;
@@ -467,6 +468,7 @@ struct asic_fixed_properties {u8 completion_queues_count;u8 fw_security_disabled;u8 fw_security_status_valid; +u8 dram_supports_virtual_memory; };/**
@@ -1772,7 +1774,6 @@ struct hl_mmu_funcs {* @heartbeat: is heartbeat sanity check towards CPU-CP enabled. * @reset_on_lockup: true if a reset should be done in case of stuck CS, false * otherwise. -* @dram_supports_virtual_memory: is MMU enabled towards DRAM. * @dram_default_page_mapping: is DRAM default page mapping enabled. * @memory_scrub: true to perform device memory scrub in various locations, * such as context-switch, context close, page free, etc.
@@ -1886,7 +1887,6 @@ struct hl_device {u8 hard_reset_pending;u8 heartbeat;u8 reset_on_lockup; -u8 dram_supports_virtual_memory;u8 dram_default_page_mapping;u8 memory_scrub;u8 pmmu_huge_range;
drivers/misc/habanalabs/common/memory.c +3 -3
@@ -1351,7 +1351,7 @@ int hl_mem_ioctl(struct hl_fpriv *hpriv, void *data)* the user's input, the driver can't ensure the validity * of this accounting. */ -if (!hdev->dram_supports_virtual_memory) { +if (!hdev->asic_prop.dram_supports_virtual_memory) {atomic64_add (args->in.alloc.mem_size, &ctx->dram_phys_mem); atomic64_add(args->in.alloc.mem_size,
@@ -1380,7 +1380,7 @@ int hl_mem_ioctl(struct hl_fpriv *hpriv, void *data)* the user's input, the driver can't ensure the validity * of this accounting. */ -if (!hdev->dram_supports_virtual_memory) { +if (!hdev->asic_prop.dram_supports_virtual_memory) {atomic64_sub (args->in.alloc.mem_size, &ctx->dram_phys_mem); atomic64_sub(args->in.alloc.mem_size,
@@ -1915,7 +1915,7 @@ void hl_vm_ctx_fini(struct hl_ctx *ctx)* because the user notifies us on allocations. If the user is no more, * all DRAM is available */ -if (!ctx->hdev->dram_supports_virtual_memory) +if (!ctx->hdev->asic_prop.dram_supports_virtual_memory)atomic64_set (&ctx->hdev->dram_used_mem,0 ); }
drivers/misc/habanalabs/common/mmu_v1.c +2 -2
@@ -262,7 +262,7 @@ static int dram_default_mapping_init(struct hl_ctx *ctx) hop2_pte_addr, hop3_pte_addr, pte_val;int rc, i, j, hop3_allocated =0 ; -if ((!hdev->dram_supports_virtual_memory) || +if ((!prop->dram_supports_virtual_memory) || (!hdev->dram_default_page_mapping) || (ctx->asid ==HL_KERNEL_ASID_ID ))return 0 ;
@@ -362,7 +362,7 @@ static void dram_default_mapping_fini(struct hl_ctx *ctx) hop2_pte_addr, hop3_pte_addr;int i, j; -if ((!hdev->dram_supports_virtual_memory) || +if ((!prop->dram_supports_virtual_memory) || (!hdev->dram_default_page_mapping) || (ctx->asid ==HL_KERNEL_ASID_ID ))return ;
drivers/misc/habanalabs/gaudi/gaudi.c +1 -2
@@ -462,6 +462,7 @@ static int gaudi_get_fixed_properties(struct hl_device *hdev) prop->mmu_hop_table_size =HOP_TABLE_SIZE ; prop->mmu_hop0_tables_total_size =HOP0_TABLES_TOTAL_SIZE ; prop->dram_page_size =PAGE_SIZE_2MB ; + prop->dram_supports_virtual_memory = false; prop->pmmu.hop0_shift =HOP0_SHIFT ; prop->pmmu.hop1_shift =HOP1_SHIFT ;
@@ -3573,8 +3574,6 @@ static int gaudi_mmu_init(struct hl_device *hdev)if (gaudi->hw_cap_initialized &HW_CAP_MMU )return 0 ; - hdev->dram_supports_virtual_memory = false; -for (i =0 ; i < prop->max_asid ; i++) { hop0_addr = prop->mmu_pgt_addr + (i * prop->mmu_hop_table_size);
drivers/misc/habanalabs/goya/goya.c +1 -1
@@ -410,6 +410,7 @@ int goya_get_fixed_properties(struct hl_device *hdev) prop->mmu_hop_table_size =HOP_TABLE_SIZE ; prop->mmu_hop0_tables_total_size =HOP0_TABLES_TOTAL_SIZE ; prop->dram_page_size =PAGE_SIZE_2MB ; + prop->dram_supports_virtual_memory = true; prop->dmmu.hop0_shift =HOP0_SHIFT ; prop->dmmu.hop1_shift =HOP1_SHIFT ;
@@ -2481,7 +2482,6 @@ int goya_mmu_init(struct hl_device *hdev)if (goya->hw_cap_initialized &HW_CAP_MMU )return 0 ; - hdev->dram_supports_virtual_memory = true; hdev->dram_default_page_mapping = true;for (i =0 ; i < prop->max_asid ; i++) {
Signature · 1 line
2.17.1
PATCH 1/1 habanalabs: use host va range for internal pools
From: Ofir Bitton <[email protected]>
Instead of using a dedicated va range for each internal pool, we introduce a new way for reserving a va block from an existing va range. This is a more generic way of reserving va blocks for future use.
Signed-off-by Ofir Bitton <[email protected]>
Reviewed-by Oded Gabbay <[email protected]>
Signed-off-by Oded Gabbay <[email protected]>
--- drivers/misc/habanalabs/common/habanalabs.h | 4 ++ drivers/misc/habanalabs/common/memory.c | 79 +++++++++++++++++++++ drivers/misc/habanalabs/gaudi/gaudi.c | 18 +++-- drivers/misc/habanalabs/gaudi/gaudiP.h | 5 +- 4 files changed, 98 insertions(+), 8 deletions(-)
drivers/misc/habanalabs/common/habanalabs.h +4 -0
@@ -2109,6 +2109,10 @@ void hl_vm_ctx_fini(struct hl_ctx *ctx);int hl_vm_init (struct hl_device *hdev);void hl_vm_fini (struct hl_device *hdev); +u64 hl_reserve_va_block (struct hl_device *hdev,struct hl_ctx *ctx, +enum hl_va_range_type type,u32 size); +int hl_unreserve_va_block (struct hl_device *hdev,struct hl_ctx *ctx, +u64 start_addr,u64 size);int hl_pin_host_memory (struct hl_device *hdev,u64 addr,u64 size,struct hl_userptr *userptr);void hl_unpin_host_memory (struct hl_device *hdev,struct hl_userptr *userptr);
drivers/misc/habanalabs/common/memory.c +79 -0
85 lines not on this page · raw message
drivers/misc/habanalabs/gaudi/gaudi.c +14 -4
@@ -7768,7 +7768,11 @@ static int gaudi_internal_cb_pool_init(struct hl_device *hdev, goto destroy_internal_cb_pool; } - hdev->internal_cb_va_base =VA_HOST_SPACE_INTERNAL_CB_START ; + hdev->internal_cb_va_base =hl_reserve_va_block (hdev, ctx, +HL_VA_RANGE_TYPE_HOST ,HOST_SPACE_INTERNAL_CB_SZ ); + +if (!hdev->internal_cb_va_base) + goto destroy_internal_cb_pool;mutex_lock (&ctx->mmu_lock);
@@ -7776,7 +7780,7 @@ static int gaudi_internal_cb_pool_init(struct hl_device *hdev,* is aligned to HOST_SPACE_INTERNAL_CB_SZ */ for (off =0 ; off <HOST_SPACE_INTERNAL_CB_SZ ; off +=PAGE_SIZE_4KB ) { - va =VA_HOST_SPACE_INTERNAL_CB_START + off; + va = hdev->internal_cb_va_base + off; pa = hdev->internal_cb_pool_dma_addr + off; flush_pte = (off +PAGE_SIZE_4KB ) >=HOST_SPACE_INTERNAL_CB_SZ ; rc =hl_mmu_map (ctx, va, pa,PAGE_SIZE_4KB , flush_pte);
@@ -7796,13 +7800,16 @@ static int gaudi_internal_cb_pool_init(struct hl_device *hdev, unmap:for (; off >=0 ; off -=PAGE_SIZE_4KB ) { - va =VA_HOST_SPACE_INTERNAL_CB_START + off; + va = hdev->internal_cb_va_base + off; flush_pte = (off - (s32 )PAGE_SIZE_4KB ) <0 ;if (hl_mmu_unmap (ctx, va,PAGE_SIZE_4KB , flush_pte))dev_warn_ratelimited (hdev->dev,"failed to unmap va 0x%llx\n" , va); } +hl_unreserve_va_block (hdev, ctx, hdev->internal_cb_va_base, +HOST_SPACE_INTERNAL_CB_SZ ); + hdev->asic_funcs->mmu_invalidate_cache (hdev, true,VM_TYPE_USERPTR );mutex_unlock (&ctx->mmu_lock);
@@ -7832,7 +7839,7 @@ static void gaudi_internal_cb_pool_fini(struct hl_device *hdev,mutex_lock (&ctx->mmu_lock);for (off =0 ; off <HOST_SPACE_INTERNAL_CB_SZ ; off +=PAGE_SIZE_4KB ) { - va =VA_HOST_SPACE_INTERNAL_CB_START + off; + va = hdev->internal_cb_va_base + off;if (off +PAGE_SIZE_4KB >=HOST_SPACE_INTERNAL_CB_SZ ) flush_pte = true;
@@ -7842,6 +7849,9 @@ static void gaudi_internal_cb_pool_fini(struct hl_device *hdev, "failed to unmap va 0x%llx\n", va); } +hl_unreserve_va_block (hdev, ctx, hdev->internal_cb_va_base, +HOST_SPACE_INTERNAL_CB_SZ ); + hdev->asic_funcs->mmu_invalidate_cache (hdev, true,VM_TYPE_USERPTR );mutex_unlock (&ctx->mmu_lock);
drivers/misc/habanalabs/gaudi/gaudiP.h +1 -4
@@ -153,12 +153,9 @@/* Virtual address space */ #define VA_HOST_SPACE_START 0x1000000000000ull/* 256TB */ -#define VA_HOST_SPACE_END 0x3FF7FFFE00000ull/* 1PB - 1TB */ +#define VA_HOST_SPACE_END 0x3FF8000000000ull/* 1PB - 512GB */ #define VA_HOST_SPACE_SIZE (VA_HOST_SPACE_END - \ VA_HOST_SPACE_START)/* 767TB */ - -#define VA_HOST_SPACE_INTERNAL_CB_START 0x3FF7FFFE00000ull/* 1PB - 1TB - 2MB */ -#define VA_HOST_SPACE_INTERNAL_CB_END 0x3FF8000000000ull/* 1PB - 1TB */ #define HOST_SPACE_INTERNAL_CB_SZ SZ_2M#define HW_CAP_PLL BIT(0)
Signature · 1 line
2.17.1