accel/habanalabs: set hl_dmabuf_priv.device_address only when needed
authorTomer Tayar <ttayar@habana.ai>
Sun, 20 Aug 2023 11:17:06 +0000 (14:17 +0300)
committerOded Gabbay <ogabbay@kernel.org>
Mon, 9 Oct 2023 09:37:22 +0000 (12:37 +0300)
The device_address member of 'struct hl_dmabuf_priv' is used only when
virtual device memory is not supported and dma-buf is exported from
address.
Set the value of this field only when it is relevant, and add "phys" to
its name so it would be clearer that it can't be a device virtual
address.

Signed-off-by: Tomer Tayar <ttayar@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
drivers/accel/habanalabs/common/habanalabs.h
drivers/accel/habanalabs/common/memory.c

index 7c2da8cfe844d7e50718164c0757629c45f50ae1..43e682cdeb7555a84712a6ee152ea0fd092d8f0b 100644 (file)
@@ -1811,16 +1811,16 @@ struct hl_cs_counters_atomic {
  * @phys_pg_pack: pointer to physical page pack if the dma-buf was exported
  *                where virtual memory is supported.
  * @memhash_hnode: pointer to the memhash node. this object holds the export count.
- * @device_address: physical address of the device's memory. Relevant only
- *                  if phys_pg_pack is NULL (dma-buf was exported from address).
- *                  The total size can be taken from the dmabuf object.
+ * device_phys_addr: physical address of the device's memory. Relevant only
+ *                   if phys_pg_pack is NULL (dma-buf was exported from address).
+ *                   The total size can be taken from the dmabuf object.
  */
 struct hl_dmabuf_priv {
        struct dma_buf                  *dmabuf;
        struct hl_ctx                   *ctx;
        struct hl_vm_phys_pg_pack       *phys_pg_pack;
        struct hl_vm_hash_node          *memhash_hnode;
-       uint64_t                        device_address;
+       u64                             device_phys_addr;
 };
 
 #define HL_CS_OUTCOME_HISTORY_LEN 256
index f42cb04b578bfd3d014a53388e4001c9c75c698c..fe896edc18ace469da911f9adefe49e4d52d20a9 100644 (file)
@@ -1731,7 +1731,7 @@ static struct sg_table *hl_map_dmabuf(struct dma_buf_attachment *attachment,
                npages = phys_pg_pack->npages;
                page_size = phys_pg_pack->page_size;
        } else {
-               pages = &hl_dmabuf->device_address;
+               pages = &hl_dmabuf->device_phys_addr;
                npages = 1;
                page_size = hl_dmabuf->dmabuf->size;
        }
@@ -2064,9 +2064,9 @@ static int export_dmabuf_from_addr(struct hl_ctx *ctx, u64 addr, u64 size, u64 o
                rc = validate_export_params_no_mmu(hdev, export_addr, size);
                if (rc)
                        goto err_free_dmabuf_wrapper;
-       }
 
-       hl_dmabuf->device_address = export_addr;
+               hl_dmabuf->device_phys_addr = export_addr;
+       }
 
        rc = export_dmabuf(ctx, hl_dmabuf, size, flags, dmabuf_fd);
        if (rc)