nvdla: kmd: set DMA direction based on access type

Based on access permission requested through pin, DMA direction
is set. This allows setting a reduced access permission for DLA
firmware and/or hardware.

Jira DLA-5775

Change-Id: Ie28e9da87325f36de12269eab1487407f6272053
Signed-off-by: Arvind M <am@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvidia/+/2682040
Reviewed-by: Amit Sharma (SW-TEGRA) <amisharma@nvidia.com>
Reviewed-by: Praveen K <kpraveen@nvidia.com>
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-cert <svc-mobile-cert@nvidia.com>
Reviewed-by: Ken Adams <kadams@nvidia.com>
GVS: Gerrit_Virtual_Submit
This commit is contained in:
Arvind M
2022-03-15 21:28:56 +05:30
committed by Laxman Dewangan
parent 1c9a3507d5
commit 3349513ab1
2 changed files with 21 additions and 2 deletions

View File

@@ -140,7 +140,18 @@ static int nvdla_buffer_map(struct platform_device *pdev,
goto buf_attach_err;
}
if (desc->access_flags == NVDLA_MEM_ACCESS_READ) {
sgt = dma_buf_map_attachment(attach, DMA_TO_DEVICE);
} else if (desc->access_flags == NVDLA_MEM_ACCESS_READ_WRITE) {
sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
} else {
err = -EINVAL;
dev_err(&pdev->dev,
"Invalid access permission: %u\n",
desc->access_flags);
goto buf_map_err;
}
if (IS_ERR_OR_NULL(sgt)) {
err = PTR_ERR(sgt);
dev_err(&pdev->dev, "dma mapping failed: %d\n", err);
@@ -199,7 +210,11 @@ static void nvdla_buffer_unmap(struct nvdla_buffers *nvdla_buffers,
if ((vm->user_map_count != 0) || (vm->submit_map_count != 0))
return;
if (vm->access_flags == NVDLA_MEM_ACCESS_READ)
dma_buf_unmap_attachment(vm->attach, vm->sgt, DMA_TO_DEVICE);
else
dma_buf_unmap_attachment(vm->attach, vm->sgt, DMA_BIDIRECTIONAL);
dma_buf_detach(vm->dmabuf, vm->attach);
dma_buf_put(vm->dmabuf);

View File

@@ -75,6 +75,10 @@ struct nvdla_ping_args {
struct nvdla_mem_share_handle {
__u32 share_id;
__u32 offset;
#define NVDLA_MEM_ACCESS_NONE (0U)
#define NVDLA_MEM_ACCESS_READ (1U << 0U)
#define NVDLA_MEM_ACCESS_WRITE (1U << 1U)
#define NVDLA_MEM_ACCESS_READ_WRITE (NVDLA_MEM_ACCESS_READ | NVDLA_MEM_ACCESS_WRITE)
__u32 access_flags;
__u32 import_id;
};