video: tegra: host: dla: use different structure for cmd mem

- use another structure for storing command memory pool params
- fix checkpatch errors

Jira DLA-243

Change-Id: I1ab92ce7a48a7345d1041fa995b2c884d2408683
Signed-off-by: Shridhar Rasal <srasal@nvidia.com>
Reviewed-on: http://git-master/r/1275943
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Shridhar Rasal
2016-12-23 11:46:39 +05:30
committed by Laxman Dewangan
parent d05b5d5d1c
commit e1255dbab1
4 changed files with 67 additions and 38 deletions

View File

@@ -96,18 +96,18 @@ static int nvdla_alloc_cmd_memory(struct platform_device *pdev)
int err = 0;
/* allocate memory for command */
nvdla_dev->cmd_mem_va = dma_alloc_attrs(&pdev->dev,
nvdla_dev->cmd_mem.va = dma_alloc_attrs(&pdev->dev,
MAX_CMD_SIZE * MAX_COMMANDS_PER_DEVICE,
&nvdla_dev->cmd_mem_pa, GFP_KERNEL,
&nvdla_dev->cmd_mem.pa, GFP_KERNEL,
&attrs);
if (nvdla_dev->cmd_mem_va == NULL) {
if (nvdla_dev->cmd_mem.va == NULL) {
err = -ENOMEM;
goto err_alloc_cmd_mem;
}
mutex_init(&nvdla_dev->cmd_mem_lock);
nvdla_dev->cmd_alloc_table = 0;
mutex_init(&nvdla_dev->cmd_mem.lock);
nvdla_dev->cmd_mem.alloc_table = 0;
err_alloc_cmd_mem:
return err;
@@ -121,9 +121,9 @@ static int nvdla_free_cmd_memory(struct platform_device *pdev)
/* free memory for command */
dma_free_attrs(&pdev->dev,
MAX_CMD_SIZE * MAX_COMMANDS_PER_DEVICE,
nvdla_dev->cmd_mem_va, nvdla_dev->cmd_mem_pa, &attrs);
nvdla_dev->cmd_mem.va, nvdla_dev->cmd_mem.pa, &attrs);
nvdla_dev->cmd_alloc_table = 0;
nvdla_dev->cmd_mem.alloc_table = 0;
return 0;
}
@@ -135,9 +135,9 @@ int nvdla_get_cmd_memory(struct platform_device *pdev,
struct nvdla_device *nvdla_dev = pdata->private_data;
int err = 0, index, offset;
mutex_lock(&nvdla_dev->cmd_mem_lock);
mutex_lock(&nvdla_dev->cmd_mem.lock);
index = find_first_zero_bit(&nvdla_dev->cmd_alloc_table,
index = find_first_zero_bit(&nvdla_dev->cmd_mem.alloc_table,
MAX_COMMANDS_PER_DEVICE);
if (index >= MAX_COMMANDS_PER_DEVICE) {
nvdla_dbg_err(pdev, "failed to get cmd mem from pool\n");
@@ -146,15 +146,15 @@ int nvdla_get_cmd_memory(struct platform_device *pdev,
}
/* assign mem */
set_bit(index, &nvdla_dev->cmd_alloc_table);
set_bit(index, &nvdla_dev->cmd_mem.alloc_table);
offset = NVDLA_CMD_OFFSET(index);
cmd_mem_info->va = nvdla_dev->cmd_mem_va + offset;
cmd_mem_info->pa = nvdla_dev->cmd_mem_pa + offset;
cmd_mem_info->va = nvdla_dev->cmd_mem.va + offset;
cmd_mem_info->pa = nvdla_dev->cmd_mem.pa + offset;
cmd_mem_info->index = index;
err_get_mem:
mutex_unlock(&nvdla_dev->cmd_mem_lock);
mutex_unlock(&nvdla_dev->cmd_mem.lock);
return err;
}
@@ -163,9 +163,9 @@ int nvdla_put_cmd_memory(struct platform_device *pdev, int index)
struct nvhost_device_data *pdata = platform_get_drvdata(pdev);
struct nvdla_device *nvdla_dev = pdata->private_data;
mutex_lock(&nvdla_dev->cmd_mem_lock);
clear_bit(index, &nvdla_dev->cmd_alloc_table);
mutex_unlock(&nvdla_dev->cmd_mem_lock);
mutex_lock(&nvdla_dev->cmd_mem.lock);
clear_bit(index, &nvdla_dev->cmd_mem.alloc_table);
mutex_unlock(&nvdla_dev->cmd_mem.lock);
return 0;
}

View File

@@ -75,12 +75,35 @@ union nvdla_cmd_mem_list {
#define MAX_CMD_SIZE sizeof(union nvdla_cmd_mem_list)
#define NVDLA_CMD_OFFSET(index) (MAX_CMD_SIZE * index)
/**
* data structure to keep command memory
*
* @pa IOVA pointing to cmd memory with offset
* @va VA of cmd memory
* @index index pointing command in pool
*
*/
struct nvdla_cmd_mem_info {
dma_addr_t pa;
void *va;
int index;
dma_addr_t pa;
void *va;
int index;
};
/**
* data structure to keep command memory pool
*
* @pa IOVA pointing to cmd memory
* @va VA of cmd memory
* @lock mutex lock
* @alloc_table memory usage bitmap table
*/
struct nvdla_cmd_mem {
dma_addr_t pa;
void *va;
struct mutex lock;
unsigned long alloc_table;
};
/**
* data structure to keep per DLA engine device data
@@ -89,6 +112,8 @@ struct nvdla_cmd_mem_info {
* @pool pointer to queue table
* @dbg_mask debug mask for print level
* @en_trace flag to enable tracing
* @fw_version saves current firmware version
* @cmd_mem structure to hold command memory pool
*/
struct nvdla_device {
struct platform_device *pdev;
@@ -100,12 +125,7 @@ struct nvdla_device {
u32 dbg_mask;
u32 en_trace;
u32 fw_version;
/* cmd memory fields */
dma_addr_t cmd_mem_pa;
void *cmd_mem_va;
struct mutex cmd_mem_lock;
unsigned long cmd_alloc_table;
struct nvdla_cmd_mem cmd_mem;
};
/**

View File

@@ -41,12 +41,6 @@
#define FLCN_IDLE_TIMEOUT_DEFAULT 10000 /* 10 milliseconds */
#define ALIGNED_DMA(x) ((x >> 8) & 0xffffffff)
#define MAX_NVDLA_TASK_SIZE (sizeof(struct nvdla_task) + \
((MAX_NUM_NVDLA_PREFENCES + MAX_NUM_NVDLA_POSTFENCES) * \
sizeof(struct nvdla_fence)) + \
((MAX_NUM_NVDLA_IN_TASK_STATUS) * sizeof(struct nvdla_status_notify)) + \
((MAX_NUM_NVDLA_OUT_TASK_STATUS) * sizeof(struct nvdla_status_notify)))
/**
* struct nvdla_private per unique FD private data
* @pdev pointer to platform device
@@ -192,7 +186,8 @@ static int nvdla_get_actions(struct nvdla_ioctl_submit_task *user_task,
/* get input task status */
if (copy_from_user(task->in_task_status,
(void __user *)user_task->input_task_status,
(task->num_in_task_status * sizeof(struct nvdla_status_notify)))) {
(task->num_in_task_status *
sizeof(struct nvdla_status_notify)))) {
err = -EFAULT;
nvdla_dbg_err(pdev, "failed to copy input task status");
goto fail;
@@ -210,7 +205,8 @@ static int nvdla_get_actions(struct nvdla_ioctl_submit_task *user_task,
/* get output task status */
if (copy_from_user(task->out_task_status,
(void __user *)user_task->output_task_status,
(task->num_out_task_status * sizeof(struct nvdla_status_notify)))) {
(task->num_out_task_status *
sizeof(struct nvdla_status_notify)))) {
err = -EFAULT;
nvdla_dbg_err(pdev, "failed to copy output task status");
goto fail;
@@ -276,6 +272,15 @@ fail:
return err;
}
static inline int nvdla_get_max_task_size(void)
{
return (sizeof(struct nvdla_task) +
((MAX_NUM_NVDLA_PREFENCES + MAX_NUM_NVDLA_POSTFENCES) *
sizeof(struct nvdla_fence)) +
((MAX_NUM_NVDLA_IN_TASK_STATUS +
MAX_NUM_NVDLA_OUT_TASK_STATUS) *
sizeof(struct nvdla_status_notify)));
}
static int nvdla_fill_task(struct nvhost_queue *queue,
struct nvhost_buffers *buffers,
@@ -290,7 +295,7 @@ static int nvdla_fill_task(struct nvhost_queue *queue,
nvdla_dbg_fn(pdev, "");
/* allocate task resource */
task = kzalloc(MAX_NVDLA_TASK_SIZE, GFP_KERNEL);
task = kzalloc(nvdla_get_max_task_size(), GFP_KERNEL);
if (!task) {
err = -ENOMEM;
nvdla_dbg_err(pdev, "KMD task allocation failed");

View File

@@ -340,8 +340,10 @@ static inline int nvdla_get_max_preaction_size(void)
{
return (((MAX_NUM_NVDLA_PREFENCES + MAX_NUM_NVDLA_IN_TASK_STATUS) *
sizeof(struct dla_action_opcode)) +
(MAX_NUM_NVDLA_PREFENCES * sizeof(struct dla_action_semaphore)) +
(MAX_NUM_NVDLA_IN_TASK_STATUS * sizeof(struct dla_action_task_status)) +
(MAX_NUM_NVDLA_PREFENCES *
sizeof(struct dla_action_semaphore)) +
(MAX_NUM_NVDLA_IN_TASK_STATUS *
sizeof(struct dla_action_task_status)) +
sizeof(struct dla_action_opcode));
}
@@ -349,8 +351,10 @@ static inline int nvdla_get_max_postaction_size(void)
{
return (((MAX_NUM_NVDLA_POSTFENCES + MAX_NUM_NVDLA_OUT_TASK_STATUS) *
sizeof(struct dla_action_opcode)) +
(MAX_NUM_NVDLA_POSTFENCES * sizeof(struct dla_action_semaphore)) +
(MAX_NUM_NVDLA_OUT_TASK_STATUS * sizeof(struct dla_action_task_status)) +
(MAX_NUM_NVDLA_POSTFENCES *
sizeof(struct dla_action_semaphore)) +
(MAX_NUM_NVDLA_OUT_TASK_STATUS *
sizeof(struct dla_action_task_status)) +
sizeof(struct dla_action_opcode));
}