Skip to content

Commit

Permalink
media: amphion: add helper function to get id name
Browse files Browse the repository at this point in the history
convert numbers into meaningful names,
then it can improve the log readability

Fixes: 9f599f3 ("media: amphion: add vpu core driver")
Signed-off-by: Ming Qian <ming.qian@nxp.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
  • Loading branch information
mingqian-0 authored and Hans Verkuil committed Jul 25, 2023
1 parent 73e3f09 commit 12cd8b8
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 13 deletions.
9 changes: 5 additions & 4 deletions drivers/media/platform/amphion/vdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ static int vdec_update_state(struct vpu_inst *inst, enum vpu_codec_state state,
vdec->state = VPU_CODEC_STATE_DYAMIC_RESOLUTION_CHANGE;

if (inst->state != pre_state)
vpu_trace(inst->dev, "[%d] %d -> %d\n", inst->id, pre_state, inst->state);
vpu_trace(inst->dev, "[%d] %s -> %s\n", inst->id,
vpu_codec_state_name(pre_state), vpu_codec_state_name(inst->state));

if (inst->state == VPU_CODEC_STATE_DYAMIC_RESOLUTION_CHANGE)
vdec_handle_resolution_change(inst);
Expand Down Expand Up @@ -1037,8 +1038,8 @@ static int vdec_response_frame(struct vpu_inst *inst, struct vb2_v4l2_buffer *vb
return -EINVAL;
}

dev_dbg(inst->dev, "[%d] state = %d, alloc fs %d, tag = 0x%x\n",
inst->id, inst->state, vbuf->vb2_buf.index, vdec->seq_tag);
dev_dbg(inst->dev, "[%d] state = %s, alloc fs %d, tag = 0x%x\n",
inst->id, vpu_codec_state_name(inst->state), vbuf->vb2_buf.index, vdec->seq_tag);
vpu_buf = to_vpu_vb2_buffer(vbuf);

memset(&info, 0, sizeof(info));
Expand Down Expand Up @@ -1400,7 +1401,7 @@ static void vdec_abort(struct vpu_inst *inst)
struct vpu_rpc_buffer_desc desc;
int ret;

vpu_trace(inst->dev, "[%d] state = %d\n", inst->id, inst->state);
vpu_trace(inst->dev, "[%d] state = %s\n", inst->id, vpu_codec_state_name(inst->state));

vdec->aborting = true;
vpu_iface_add_scode(inst, SCODE_PADDING_ABORT);
Expand Down
3 changes: 3 additions & 0 deletions drivers/media/platform/amphion/vpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ void vpu_inst_record_flow(struct vpu_inst *inst, u32 flow);
int vpu_core_driver_init(void);
void vpu_core_driver_exit(void);

const char *vpu_id_name(u32 id);
const char *vpu_codec_state_name(enum vpu_codec_state state);

extern bool debug;
#define vpu_trace(dev, fmt, arg...) \
do { \
Expand Down
11 changes: 6 additions & 5 deletions drivers/media/platform/amphion/vpu_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static struct vpu_cmd_t *vpu_alloc_cmd(struct vpu_inst *inst, u32 id, void *data
cmd->id = id;
ret = vpu_iface_pack_cmd(inst->core, cmd->pkt, inst->id, id, data);
if (ret) {
dev_err(inst->dev, "iface pack cmd(%d) fail\n", id);
dev_err(inst->dev, "iface pack cmd %s fail\n", vpu_id_name(id));
vfree(cmd->pkt);
vfree(cmd);
return NULL;
Expand All @@ -123,14 +123,14 @@ static int vpu_session_process_cmd(struct vpu_inst *inst, struct vpu_cmd_t *cmd)
{
int ret;

dev_dbg(inst->dev, "[%d]send cmd(0x%x)\n", inst->id, cmd->id);
dev_dbg(inst->dev, "[%d]send cmd %s\n", inst->id, vpu_id_name(cmd->id));
vpu_iface_pre_send_cmd(inst);
ret = vpu_cmd_send(inst->core, cmd->pkt);
if (!ret) {
vpu_iface_post_send_cmd(inst);
vpu_inst_record_flow(inst, cmd->id);
} else {
dev_err(inst->dev, "[%d] iface send cmd(0x%x) fail\n", inst->id, cmd->id);
dev_err(inst->dev, "[%d] iface send cmd %s fail\n", inst->id, vpu_id_name(cmd->id));
}

return ret;
Expand All @@ -147,7 +147,8 @@ static void vpu_process_cmd_request(struct vpu_inst *inst)
list_for_each_entry_safe(cmd, tmp, &inst->cmd_q, list) {
list_del_init(&cmd->list);
if (vpu_session_process_cmd(inst, cmd))
dev_err(inst->dev, "[%d] process cmd(%d) fail\n", inst->id, cmd->id);
dev_err(inst->dev, "[%d] process cmd %s fail\n",
inst->id, vpu_id_name(cmd->id));
if (cmd->request) {
inst->pending = (void *)cmd;
break;
Expand Down Expand Up @@ -337,7 +338,7 @@ static int vpu_session_send_cmd(struct vpu_inst *inst, u32 id, void *data)

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

return ret;
}
Expand Down
6 changes: 3 additions & 3 deletions drivers/media/platform/amphion/vpu_dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static int vpu_dbg_instance(struct seq_file *s, void *data)
num = scnprintf(str, sizeof(str), "tgig = %d,pid = %d\n", inst->tgid, inst->pid);
if (seq_write(s, str, num))
return 0;
num = scnprintf(str, sizeof(str), "state = %d\n", inst->state);
num = scnprintf(str, sizeof(str), "state = %s\n", vpu_codec_state_name(inst->state));
if (seq_write(s, str, num))
return 0;
num = scnprintf(str, sizeof(str),
Expand Down Expand Up @@ -188,9 +188,9 @@ static int vpu_dbg_instance(struct seq_file *s, void *data)

if (!inst->flows[idx])
continue;
num = scnprintf(str, sizeof(str), "\t[%s]0x%x\n",
num = scnprintf(str, sizeof(str), "\t[%s] %s\n",
inst->flows[idx] >= VPU_MSG_ID_NOOP ? "M" : "C",
inst->flows[idx]);
vpu_id_name(inst->flows[idx]));
if (seq_write(s, str, num)) {
mutex_unlock(&inst->core->cmd_lock);
return 0;
Expand Down
61 changes: 61 additions & 0 deletions drivers/media/platform/amphion/vpu_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <linux/module.h>
#include <linux/platform_device.h>
#include "vpu.h"
#include "vpu_defs.h"
#include "vpu_core.h"
#include "vpu_rpc.h"
#include "vpu_helpers.h"
Expand Down Expand Up @@ -447,3 +448,63 @@ int vpu_find_src_by_dst(struct vpu_pair *pairs, u32 cnt, u32 dst)

return -EINVAL;
}

const char *vpu_id_name(u32 id)
{
switch (id) {
case VPU_CMD_ID_NOOP: return "noop";
case VPU_CMD_ID_CONFIGURE_CODEC: return "configure codec";
case VPU_CMD_ID_START: return "start";
case VPU_CMD_ID_STOP: return "stop";
case VPU_CMD_ID_ABORT: return "abort";
case VPU_CMD_ID_RST_BUF: return "reset buf";
case VPU_CMD_ID_SNAPSHOT: return "snapshot";
case VPU_CMD_ID_FIRM_RESET: return "reset firmware";
case VPU_CMD_ID_UPDATE_PARAMETER: return "update parameter";
case VPU_CMD_ID_FRAME_ENCODE: return "encode frame";
case VPU_CMD_ID_SKIP: return "skip";
case VPU_CMD_ID_FS_ALLOC: return "alloc fb";
case VPU_CMD_ID_FS_RELEASE: return "release fb";
case VPU_CMD_ID_TIMESTAMP: return "timestamp";
case VPU_CMD_ID_DEBUG: return "debug";
case VPU_MSG_ID_RESET_DONE: return "reset done";
case VPU_MSG_ID_START_DONE: return "start done";
case VPU_MSG_ID_STOP_DONE: return "stop done";
case VPU_MSG_ID_ABORT_DONE: return "abort done";
case VPU_MSG_ID_BUF_RST: return "buf reset done";
case VPU_MSG_ID_MEM_REQUEST: return "mem request";
case VPU_MSG_ID_PARAM_UPD_DONE: return "param upd done";
case VPU_MSG_ID_FRAME_INPUT_DONE: return "frame input done";
case VPU_MSG_ID_ENC_DONE: return "encode done";
case VPU_MSG_ID_DEC_DONE: return "frame display";
case VPU_MSG_ID_FRAME_REQ: return "fb request";
case VPU_MSG_ID_FRAME_RELEASE: return "fb release";
case VPU_MSG_ID_SEQ_HDR_FOUND: return "seq hdr found";
case VPU_MSG_ID_RES_CHANGE: return "resolution change";
case VPU_MSG_ID_PIC_HDR_FOUND: return "pic hdr found";
case VPU_MSG_ID_PIC_DECODED: return "picture decoded";
case VPU_MSG_ID_PIC_EOS: return "eos";
case VPU_MSG_ID_FIFO_LOW: return "fifo low";
case VPU_MSG_ID_BS_ERROR: return "bs error";
case VPU_MSG_ID_UNSUPPORTED: return "unsupported";
case VPU_MSG_ID_FIRMWARE_XCPT: return "exception";
case VPU_MSG_ID_PIC_SKIPPED: return "skipped";
}
return "<unknown>";
}

const char *vpu_codec_state_name(enum vpu_codec_state state)
{
switch (state) {
case VPU_CODEC_STATE_DEINIT: return "initialization";
case VPU_CODEC_STATE_CONFIGURED: return "configured";
case VPU_CODEC_STATE_START: return "start";
case VPU_CODEC_STATE_STARTED: return "started";
case VPU_CODEC_STATE_ACTIVE: return "active";
case VPU_CODEC_STATE_SEEK: return "seek";
case VPU_CODEC_STATE_STOP: return "stop";
case VPU_CODEC_STATE_DRAIN: return "drain";
case VPU_CODEC_STATE_DYAMIC_RESOLUTION_CHANGE: return "resolution change";
}
return "<unknown>";
}
2 changes: 1 addition & 1 deletion drivers/media/platform/amphion/vpu_msgs.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static int vpu_session_handle_msg(struct vpu_inst *inst, struct vpu_rpc_event *m
return -EINVAL;

msg_id = ret;
dev_dbg(inst->dev, "[%d] receive event(0x%x)\n", inst->id, msg_id);
dev_dbg(inst->dev, "[%d] receive event(%s)\n", inst->id, vpu_id_name(msg_id));

for (i = 0; i < ARRAY_SIZE(handlers); i++) {
if (handlers[i].id == msg_id) {
Expand Down

0 comments on commit 12cd8b8

Please sign in to comment.