Skip to content

Commit d89d329

Browse files
Tomer Tayarogabbay
authored andcommitted
accel/habanalabs: tiny refactor of hl_map_dmabuf()
alloc_sgt_from_device_pages() includes relatively many parameters, and in a subsequent change another offset parameter is going to be added. Using structure fields directly when calling this function, and in hl_map_dmabuf() it is done twice, makes it a little bit difficult to understand the meaning of the parameters. To make it clearer, assign the required values into local variables with explicit names, and use the variables when calling the function. Signed-off-by: Tomer Tayar <ttayar@habana.ai> Reviewed-by: Oded Gabbay <ogabbay@kernel.org> Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
1 parent 0b75cb5 commit d89d329

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

drivers/accel/habanalabs/common/memory.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,7 @@ static int hl_dmabuf_attach(struct dma_buf *dmabuf,
16991699
static struct sg_table *hl_map_dmabuf(struct dma_buf_attachment *attachment,
17001700
enum dma_data_direction dir)
17011701
{
1702+
u64 *pages, npages, page_size, exported_size;
17021703
struct dma_buf *dma_buf = attachment->dmabuf;
17031704
struct hl_vm_phys_pg_pack *phys_pg_pack;
17041705
struct hl_dmabuf_priv *hl_dmabuf;
@@ -1707,30 +1708,27 @@ static struct sg_table *hl_map_dmabuf(struct dma_buf_attachment *attachment,
17071708

17081709
hl_dmabuf = dma_buf->priv;
17091710
hdev = hl_dmabuf->ctx->hdev;
1710-
phys_pg_pack = hl_dmabuf->phys_pg_pack;
17111711

17121712
if (!attachment->peer2peer) {
17131713
dev_dbg(hdev->dev, "Failed to map dmabuf because p2p is disabled\n");
17141714
return ERR_PTR(-EPERM);
17151715
}
17161716

1717-
if (phys_pg_pack)
1718-
sgt = alloc_sgt_from_device_pages(hdev,
1719-
phys_pg_pack->pages,
1720-
phys_pg_pack->npages,
1721-
phys_pg_pack->page_size,
1722-
hl_dmabuf->dmabuf->size,
1723-
attachment->dev,
1724-
dir);
1725-
else
1726-
sgt = alloc_sgt_from_device_pages(hdev,
1727-
&hl_dmabuf->device_address,
1728-
1,
1729-
hl_dmabuf->dmabuf->size,
1730-
hl_dmabuf->dmabuf->size,
1731-
attachment->dev,
1732-
dir);
1717+
exported_size = hl_dmabuf->dmabuf->size;
1718+
phys_pg_pack = hl_dmabuf->phys_pg_pack;
1719+
1720+
if (phys_pg_pack) {
1721+
pages = phys_pg_pack->pages;
1722+
npages = phys_pg_pack->npages;
1723+
page_size = phys_pg_pack->page_size;
1724+
} else {
1725+
pages = &hl_dmabuf->device_address;
1726+
npages = 1;
1727+
page_size = hl_dmabuf->dmabuf->size;
1728+
}
17331729

1730+
sgt = alloc_sgt_from_device_pages(hdev, pages, npages, page_size, exported_size,
1731+
attachment->dev, dir);
17341732
if (IS_ERR(sgt))
17351733
dev_err(hdev->dev, "failed (%ld) to initialize sgt for dmabuf\n", PTR_ERR(sgt));
17361734

0 commit comments

Comments
 (0)