Skip to content

Commit

Permalink
media: amphion: try to wakeup vpu core to avoid failure
Browse files Browse the repository at this point in the history
[ Upstream commit 0827444 ]

firmware should be waked up by start or configure command,
but there is a very small chance that firmware failed to wakeup.
in such case, try to wakeup firmware again by sending a noop command

Fixes: 6de8d62 ("media: amphion: add v4l2 m2m vpu decoder stateful driver")
Signed-off-by: Ming Qian <ming.qian@nxp.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
mingqian-0 authored and gregkh committed Dec 31, 2022
1 parent 5100ab6 commit 1ca1405
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions drivers/media/platform/amphion/vpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <linux/mailbox_controller.h>
#include <linux/kfifo.h>

#define VPU_TIMEOUT_WAKEUP msecs_to_jiffies(200)
#define VPU_TIMEOUT msecs_to_jiffies(1000)
#define VPU_INST_NULL_ID (-1L)
#define VPU_MSG_BUFFER_SIZE (8192)
Expand Down
39 changes: 35 additions & 4 deletions drivers/media/platform/amphion/vpu_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ static bool check_is_responsed(struct vpu_inst *inst, unsigned long key)
return flag;
}

static int sync_session_response(struct vpu_inst *inst, unsigned long key)
static int sync_session_response(struct vpu_inst *inst, unsigned long key, long timeout, int try)
{
struct vpu_core *core;

Expand All @@ -279,10 +279,12 @@ static int sync_session_response(struct vpu_inst *inst, unsigned long key)
core = inst->core;

call_void_vop(inst, wait_prepare);
wait_event_timeout(core->ack_wq, check_is_responsed(inst, key), VPU_TIMEOUT);
wait_event_timeout(core->ack_wq, check_is_responsed(inst, key), timeout);
call_void_vop(inst, wait_finish);

if (!check_is_responsed(inst, key)) {
if (try)
return -EINVAL;
dev_err(inst->dev, "[%d] sync session timeout\n", inst->id);
set_bit(inst->id, &core->hang_mask);
mutex_lock(&inst->core->cmd_lock);
Expand All @@ -294,6 +296,19 @@ static int sync_session_response(struct vpu_inst *inst, unsigned long key)
return 0;
}

static void vpu_core_keep_active(struct vpu_core *core)
{
struct vpu_rpc_event pkt;

memset(&pkt, 0, sizeof(pkt));
vpu_iface_pack_cmd(core, &pkt, 0, VPU_CMD_ID_NOOP, NULL);

dev_dbg(core->dev, "try to wake up\n");
mutex_lock(&core->cmd_lock);
vpu_cmd_send(core, &pkt);
mutex_unlock(&core->cmd_lock);
}

static int vpu_session_send_cmd(struct vpu_inst *inst, u32 id, void *data)
{
unsigned long key;
Expand All @@ -304,9 +319,25 @@ static int vpu_session_send_cmd(struct vpu_inst *inst, u32 id, void *data)
return -EINVAL;

ret = vpu_request_cmd(inst, id, data, &key, &sync);
if (!ret && sync)
ret = sync_session_response(inst, key);
if (ret)
goto exit;

/* workaround for a firmware issue,
* firmware should be waked up by start or configure command,
* but there is a very small change that firmware failed to wakeup.
* in such case, try to wakeup firmware again by sending a noop command
*/
if (sync && (id == VPU_CMD_ID_CONFIGURE_CODEC || id == VPU_CMD_ID_START)) {
if (sync_session_response(inst, key, VPU_TIMEOUT_WAKEUP, 1))
vpu_core_keep_active(inst->core);
else
goto exit;
}

if (sync)
ret = sync_session_response(inst, key, VPU_TIMEOUT, 0);

exit:
if (ret)
dev_err(inst->dev, "[%d] send cmd(0x%x) fail\n", inst->id, id);

Expand Down
1 change: 1 addition & 0 deletions drivers/media/platform/amphion/vpu_malone.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ int vpu_malone_set_decode_params(struct vpu_shared_addr *shared,
}

static struct vpu_pair malone_cmds[] = {
{VPU_CMD_ID_NOOP, VID_API_CMD_NULL},
{VPU_CMD_ID_START, VID_API_CMD_START},
{VPU_CMD_ID_STOP, VID_API_CMD_STOP},
{VPU_CMD_ID_ABORT, VID_API_CMD_ABORT},
Expand Down
1 change: 1 addition & 0 deletions drivers/media/platform/amphion/vpu_windsor.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ int vpu_windsor_get_stream_buffer_size(struct vpu_shared_addr *shared)
}

static struct vpu_pair windsor_cmds[] = {
{VPU_CMD_ID_NOOP, GTB_ENC_CMD_NOOP},
{VPU_CMD_ID_CONFIGURE_CODEC, GTB_ENC_CMD_CONFIGURE_CODEC},
{VPU_CMD_ID_START, GTB_ENC_CMD_STREAM_START},
{VPU_CMD_ID_STOP, GTB_ENC_CMD_STREAM_STOP},
Expand Down

0 comments on commit 1ca1405

Please sign in to comment.