mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-08 03:40:35 +09:00
video: rockchip: mpp: refactoring code for reg_offset_info
combine the same code into one function Change-Id: I9c5102c59b8dd0a4e9f8213dac4d9ad400ac4a40 Signed-off-by: Ding Wei <leo.ding@rock-chips.com>
This commit is contained in:
@@ -1337,6 +1337,28 @@ int mpp_check_req(struct mpp_request *req, int base,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mpp_extract_reg_offset_info(struct reg_offset_info *off_inf,
|
||||
struct mpp_request *req)
|
||||
{
|
||||
int max_size = ARRAY_SIZE(off_inf->elem);
|
||||
int cnt = req->size / sizeof(off_inf->elem[0]);
|
||||
|
||||
if ((cnt + off_inf->cnt) > max_size) {
|
||||
mpp_err("count %d, total %d, max_size %d\n",
|
||||
cnt, off_inf->cnt, max_size);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (copy_from_user(&off_inf->elem[off_inf->cnt],
|
||||
req->data,
|
||||
req->size)) {
|
||||
mpp_err("copy_from_user failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
off_inf->cnt += cnt;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mpp_query_reg_offset_info(struct reg_offset_info *off_inf,
|
||||
u32 index)
|
||||
{
|
||||
|
||||
@@ -435,6 +435,8 @@ int mpp_translate_reg_address(struct mpp_session *session,
|
||||
|
||||
int mpp_check_req(struct mpp_request *req, int base,
|
||||
int max_size, u32 off_s, u32 off_e);
|
||||
int mpp_extract_reg_offset_info(struct reg_offset_info *off_inf,
|
||||
struct mpp_request *req);
|
||||
int mpp_query_reg_offset_info(struct reg_offset_info *off_inf,
|
||||
u32 index);
|
||||
int mpp_translate_reg_offset_info(struct mpp_task *task,
|
||||
|
||||
@@ -276,9 +276,7 @@ static int iep2_extract_task_msg(struct iep_task *task,
|
||||
struct mpp_task_msgs *msgs)
|
||||
{
|
||||
u32 i;
|
||||
int ret;
|
||||
struct mpp_request *req;
|
||||
struct reg_offset_info *off_inf = &task->off_inf;
|
||||
|
||||
for (i = 0; i < msgs->req_cnt; i++) {
|
||||
req = &msgs->reqs[i];
|
||||
@@ -298,19 +296,7 @@ static int iep2_extract_task_msg(struct iep_task *task,
|
||||
req, sizeof(*req));
|
||||
} break;
|
||||
case MPP_CMD_SET_REG_ADDR_OFFSET: {
|
||||
int off = off_inf->cnt * sizeof(off_inf->elem[0]);
|
||||
|
||||
ret = mpp_check_req(req, off, sizeof(off_inf->elem),
|
||||
0, sizeof(off_inf->elem));
|
||||
if (ret)
|
||||
continue;
|
||||
if (copy_from_user(&off_inf->elem[off_inf->cnt],
|
||||
req->data,
|
||||
req->size)) {
|
||||
mpp_err("copy_from_user failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
off_inf->cnt += req->size / sizeof(off_inf->elem[0]);
|
||||
mpp_extract_reg_offset_info(&task->off_inf, req);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -744,7 +744,6 @@ static int rkvdec_extract_task_msg(struct rkvdec_task *task,
|
||||
u32 i;
|
||||
int ret;
|
||||
struct mpp_request *req;
|
||||
struct reg_offset_info *off_inf = &task->off_inf;
|
||||
struct mpp_hw_info *hw_info = task->mpp_task.hw_info;
|
||||
|
||||
for (i = 0; i < msgs->req_cnt; i++) {
|
||||
@@ -781,19 +780,7 @@ static int rkvdec_extract_task_msg(struct rkvdec_task *task,
|
||||
req, sizeof(*req));
|
||||
} break;
|
||||
case MPP_CMD_SET_REG_ADDR_OFFSET: {
|
||||
int off = off_inf->cnt * sizeof(off_inf->elem[0]);
|
||||
|
||||
ret = mpp_check_req(req, off, sizeof(off_inf->elem),
|
||||
0, sizeof(off_inf->elem));
|
||||
if (ret)
|
||||
continue;
|
||||
if (copy_from_user(&off_inf->elem[off_inf->cnt],
|
||||
req->data,
|
||||
req->size)) {
|
||||
mpp_err("copy_from_user failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
off_inf->cnt += req->size / sizeof(off_inf->elem[0]);
|
||||
mpp_extract_reg_offset_info(&task->off_inf, req);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -233,7 +233,6 @@ static int rkvenc_extract_task_msg(struct rkvenc_task *task,
|
||||
u32 i;
|
||||
int ret;
|
||||
struct mpp_request *req;
|
||||
struct reg_offset_info *off_inf = &task->off_inf;
|
||||
|
||||
for (i = 0; i < msgs->req_cnt; i++) {
|
||||
req = &msgs->reqs[i];
|
||||
@@ -290,18 +289,7 @@ static int rkvenc_extract_task_msg(struct rkvenc_task *task,
|
||||
req, sizeof(*req));
|
||||
} break;
|
||||
case MPP_CMD_SET_REG_ADDR_OFFSET: {
|
||||
ret = mpp_check_req(req, req->offset,
|
||||
sizeof(off_inf->elem),
|
||||
0, sizeof(off_inf->elem));
|
||||
if (ret)
|
||||
return ret;
|
||||
if (copy_from_user(&off_inf->elem[off_inf->cnt],
|
||||
req->data,
|
||||
req->size)) {
|
||||
mpp_err("copy_from_user failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
off_inf->cnt += req->size / sizeof(off_inf->elem[0]);
|
||||
mpp_extract_reg_offset_info(&task->off_inf, req);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -280,7 +280,6 @@ static int vdpu_extract_task_msg(struct vdpu_task *task,
|
||||
u32 i;
|
||||
int ret;
|
||||
struct mpp_request *req;
|
||||
struct reg_offset_info *off_inf = &task->off_inf;
|
||||
struct mpp_hw_info *hw_info = task->mpp_task.hw_info;
|
||||
|
||||
for (i = 0; i < msgs->req_cnt; i++) {
|
||||
@@ -317,19 +316,7 @@ static int vdpu_extract_task_msg(struct vdpu_task *task,
|
||||
req, sizeof(*req));
|
||||
} break;
|
||||
case MPP_CMD_SET_REG_ADDR_OFFSET: {
|
||||
int off = off_inf->cnt * sizeof(off_inf->elem[0]);
|
||||
|
||||
ret = mpp_check_req(req, off, sizeof(off_inf->elem),
|
||||
0, sizeof(off_inf->elem));
|
||||
if (ret)
|
||||
continue;
|
||||
if (copy_from_user(&off_inf->elem[off_inf->cnt],
|
||||
req->data,
|
||||
req->size)) {
|
||||
mpp_err("copy_from_user failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
off_inf->cnt += req->size / sizeof(off_inf->elem[0]);
|
||||
mpp_extract_reg_offset_info(&task->off_inf, req);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -237,7 +237,6 @@ static int vdpu_extract_task_msg(struct vdpu_task *task,
|
||||
u32 i;
|
||||
int ret;
|
||||
struct mpp_request *req;
|
||||
struct reg_offset_info *off_inf = &task->off_inf;
|
||||
struct mpp_hw_info *hw_info = task->mpp_task.hw_info;
|
||||
|
||||
for (i = 0; i < msgs->req_cnt; i++) {
|
||||
@@ -274,19 +273,7 @@ static int vdpu_extract_task_msg(struct vdpu_task *task,
|
||||
req, sizeof(*req));
|
||||
} break;
|
||||
case MPP_CMD_SET_REG_ADDR_OFFSET: {
|
||||
int off = off_inf->cnt * sizeof(off_inf->elem[0]);
|
||||
|
||||
ret = mpp_check_req(req, off, sizeof(off_inf->elem),
|
||||
0, sizeof(off_inf->elem));
|
||||
if (ret)
|
||||
continue;
|
||||
if (copy_from_user(&off_inf->elem[off_inf->cnt],
|
||||
req->data,
|
||||
req->size)) {
|
||||
mpp_err("copy_from_user failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
off_inf->cnt += req->size / sizeof(off_inf->elem[0]);
|
||||
mpp_extract_reg_offset_info(&task->off_inf, req);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -155,7 +155,6 @@ static int vepu_extract_task_msg(struct vepu_task *task,
|
||||
u32 i;
|
||||
int ret;
|
||||
struct mpp_request *req;
|
||||
struct reg_offset_info *off_inf = &task->off_inf;
|
||||
struct mpp_hw_info *hw_info = task->mpp_task.hw_info;
|
||||
|
||||
for (i = 0; i < msgs->req_cnt; i++) {
|
||||
@@ -192,19 +191,7 @@ static int vepu_extract_task_msg(struct vepu_task *task,
|
||||
req, sizeof(*req));
|
||||
} break;
|
||||
case MPP_CMD_SET_REG_ADDR_OFFSET: {
|
||||
int off = off_inf->cnt * sizeof(off_inf->elem[0]);
|
||||
|
||||
ret = mpp_check_req(req, off, sizeof(off_inf->elem),
|
||||
0, sizeof(off_inf->elem));
|
||||
if (ret)
|
||||
continue;
|
||||
if (copy_from_user(&off_inf->elem[off_inf->cnt],
|
||||
req->data,
|
||||
req->size)) {
|
||||
mpp_err("copy_from_user failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
off_inf->cnt += req->size / sizeof(off_inf->elem[0]);
|
||||
mpp_extract_reg_offset_info(&task->off_inf, req);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -165,7 +165,6 @@ static int vepu_extract_task_msg(struct vepu_task *task,
|
||||
u32 i;
|
||||
int ret;
|
||||
struct mpp_request *req;
|
||||
struct reg_offset_info *off_inf = &task->off_inf;
|
||||
struct mpp_hw_info *hw_info = task->mpp_task.hw_info;
|
||||
|
||||
for (i = 0; i < msgs->req_cnt; i++) {
|
||||
@@ -202,19 +201,7 @@ static int vepu_extract_task_msg(struct vepu_task *task,
|
||||
req, sizeof(*req));
|
||||
} break;
|
||||
case MPP_CMD_SET_REG_ADDR_OFFSET: {
|
||||
int off = off_inf->cnt * sizeof(off_inf->elem[0]);
|
||||
|
||||
ret = mpp_check_req(req, off, sizeof(off_inf->elem),
|
||||
0, sizeof(off_inf->elem));
|
||||
if (ret)
|
||||
continue;
|
||||
if (copy_from_user(&off_inf->elem[off_inf->cnt],
|
||||
req->data,
|
||||
req->size)) {
|
||||
mpp_err("copy_from_user failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
off_inf->cnt += req->size / sizeof(off_inf->elem[0]);
|
||||
mpp_extract_reg_offset_info(&task->off_inf, req);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user