Commit 0202a665 authored by Ming Qian's avatar Ming Qian Committed by Mauro Carvalho Chehab

media: amphion: fix a bug that vpu core may not resume after suspend

driver will enable the vpu core when request the first instance
on the core.
one vpu core can only support 8 streaming instances in the same
time, the instance won't be added to core's list before streamon.

so the actual instance count may be greater then the number in
the core's list.

in pm resume callback, driver will resume the core immediately if
core's list is not empty.
but this check is not accurate,
if suspend during one instance is requested, but not streamon,
then after suspend, the core won't be resume, and led to instance failure.

use the request_count instead of the core's list to check
whether is the core needed to resume immediately after suspend.

And it can make the pm suspend and resume callback more clear.

Fixes: 9f599f35 ("media: amphion: add vpu core driver")
Signed-off-by: default avatarMing Qian <ming.qian@nxp.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent c65c3f3a
...@@ -119,7 +119,6 @@ struct vpu_mbox { ...@@ -119,7 +119,6 @@ struct vpu_mbox {
enum vpu_core_state { enum vpu_core_state {
VPU_CORE_DEINIT = 0, VPU_CORE_DEINIT = 0,
VPU_CORE_ACTIVE, VPU_CORE_ACTIVE,
VPU_CORE_SNAPSHOT,
VPU_CORE_HANG VPU_CORE_HANG
}; };
......
...@@ -89,7 +89,7 @@ static int vpu_core_boot_done(struct vpu_core *core) ...@@ -89,7 +89,7 @@ static int vpu_core_boot_done(struct vpu_core *core)
core->supported_instance_count = min(core->supported_instance_count, count); core->supported_instance_count = min(core->supported_instance_count, count);
} }
core->fw_version = fw_version; core->fw_version = fw_version;
core->state = VPU_CORE_ACTIVE; vpu_core_set_state(core, VPU_CORE_ACTIVE);
return 0; return 0;
} }
...@@ -172,10 +172,26 @@ int vpu_alloc_dma(struct vpu_core *core, struct vpu_buffer *buf) ...@@ -172,10 +172,26 @@ int vpu_alloc_dma(struct vpu_core *core, struct vpu_buffer *buf)
return __vpu_alloc_dma(core->dev, buf); return __vpu_alloc_dma(core->dev, buf);
} }
static void vpu_core_check_hang(struct vpu_core *core) void vpu_core_set_state(struct vpu_core *core, enum vpu_core_state state)
{ {
if (core->hang_mask) if (state != core->state)
core->state = VPU_CORE_HANG; vpu_trace(core->dev, "vpu core state change from %d to %d\n", core->state, state);
core->state = state;
if (core->state == VPU_CORE_DEINIT)
core->hang_mask = 0;
}
static void vpu_core_update_state(struct vpu_core *core)
{
if (!vpu_iface_get_power_state(core)) {
if (core->request_count)
vpu_core_set_state(core, VPU_CORE_HANG);
else
vpu_core_set_state(core, VPU_CORE_DEINIT);
} else if (core->state == VPU_CORE_ACTIVE && core->hang_mask) {
vpu_core_set_state(core, VPU_CORE_HANG);
}
} }
static struct vpu_core *vpu_core_find_proper_by_type(struct vpu_dev *vpu, u32 type) static struct vpu_core *vpu_core_find_proper_by_type(struct vpu_dev *vpu, u32 type)
...@@ -188,11 +204,13 @@ static struct vpu_core *vpu_core_find_proper_by_type(struct vpu_dev *vpu, u32 ty ...@@ -188,11 +204,13 @@ static struct vpu_core *vpu_core_find_proper_by_type(struct vpu_dev *vpu, u32 ty
dev_dbg(c->dev, "instance_mask = 0x%lx, state = %d\n", c->instance_mask, c->state); dev_dbg(c->dev, "instance_mask = 0x%lx, state = %d\n", c->instance_mask, c->state);
if (c->type != type) if (c->type != type)
continue; continue;
mutex_lock(&c->lock);
vpu_core_update_state(c);
mutex_unlock(&c->lock);
if (c->state == VPU_CORE_DEINIT) { if (c->state == VPU_CORE_DEINIT) {
core = c; core = c;
break; break;
} }
vpu_core_check_hang(c);
if (c->state != VPU_CORE_ACTIVE) if (c->state != VPU_CORE_ACTIVE)
continue; continue;
if (c->request_count < request_count) { if (c->request_count < request_count) {
...@@ -409,6 +427,12 @@ int vpu_inst_register(struct vpu_inst *inst) ...@@ -409,6 +427,12 @@ int vpu_inst_register(struct vpu_inst *inst)
} }
mutex_lock(&core->lock); mutex_lock(&core->lock);
if (core->state != VPU_CORE_ACTIVE) {
dev_err(core->dev, "vpu core is not active, state = %d\n", core->state);
ret = -EINVAL;
goto exit;
}
if (inst->id >= 0 && inst->id < core->supported_instance_count) if (inst->id >= 0 && inst->id < core->supported_instance_count)
goto exit; goto exit;
...@@ -450,7 +474,7 @@ int vpu_inst_unregister(struct vpu_inst *inst) ...@@ -450,7 +474,7 @@ int vpu_inst_unregister(struct vpu_inst *inst)
vpu_core_release_instance(core, inst->id); vpu_core_release_instance(core, inst->id);
inst->id = VPU_INST_NULL_ID; inst->id = VPU_INST_NULL_ID;
} }
vpu_core_check_hang(core); vpu_core_update_state(core);
if (core->state == VPU_CORE_HANG && !core->instance_mask) { if (core->state == VPU_CORE_HANG && !core->instance_mask) {
int err; int err;
...@@ -459,7 +483,7 @@ int vpu_inst_unregister(struct vpu_inst *inst) ...@@ -459,7 +483,7 @@ int vpu_inst_unregister(struct vpu_inst *inst)
err = vpu_core_sw_reset(core); err = vpu_core_sw_reset(core);
mutex_lock(&core->lock); mutex_lock(&core->lock);
if (!err) { if (!err) {
core->state = VPU_CORE_ACTIVE; vpu_core_set_state(core, VPU_CORE_ACTIVE);
core->hang_mask = 0; core->hang_mask = 0;
} }
} }
...@@ -609,7 +633,7 @@ static int vpu_core_probe(struct platform_device *pdev) ...@@ -609,7 +633,7 @@ static int vpu_core_probe(struct platform_device *pdev)
mutex_init(&core->cmd_lock); mutex_init(&core->cmd_lock);
init_completion(&core->cmp); init_completion(&core->cmp);
init_waitqueue_head(&core->ack_wq); init_waitqueue_head(&core->ack_wq);
core->state = VPU_CORE_DEINIT; vpu_core_set_state(core, VPU_CORE_DEINIT);
core->res = of_device_get_match_data(dev); core->res = of_device_get_match_data(dev);
if (!core->res) if (!core->res)
...@@ -758,33 +782,18 @@ static int __maybe_unused vpu_core_resume(struct device *dev) ...@@ -758,33 +782,18 @@ static int __maybe_unused vpu_core_resume(struct device *dev)
mutex_lock(&core->lock); mutex_lock(&core->lock);
pm_runtime_resume_and_get(dev); pm_runtime_resume_and_get(dev);
vpu_core_get_vpu(core); vpu_core_get_vpu(core);
if (core->state != VPU_CORE_SNAPSHOT)
goto exit;
if (!vpu_iface_get_power_state(core)) { if (core->request_count) {
if (!list_empty(&core->instances)) { if (!vpu_iface_get_power_state(core))
ret = vpu_core_boot(core, false); ret = vpu_core_boot(core, false);
if (ret) { else
dev_err(core->dev, "%s boot fail\n", __func__);
core->state = VPU_CORE_DEINIT;
goto exit;
}
} else {
core->state = VPU_CORE_DEINIT;
}
} else {
if (!list_empty(&core->instances)) {
ret = vpu_core_sw_reset(core); ret = vpu_core_sw_reset(core);
if (ret) { if (ret) {
dev_err(core->dev, "%s sw_reset fail\n", __func__); dev_err(core->dev, "resume fail\n");
core->state = VPU_CORE_HANG; vpu_core_set_state(core, VPU_CORE_HANG);
goto exit;
}
} }
core->state = VPU_CORE_ACTIVE;
} }
vpu_core_update_state(core);
exit:
pm_runtime_put_sync(dev); pm_runtime_put_sync(dev);
mutex_unlock(&core->lock); mutex_unlock(&core->lock);
...@@ -798,18 +807,11 @@ static int __maybe_unused vpu_core_suspend(struct device *dev) ...@@ -798,18 +807,11 @@ static int __maybe_unused vpu_core_suspend(struct device *dev)
int ret = 0; int ret = 0;
mutex_lock(&core->lock); mutex_lock(&core->lock);
if (core->state == VPU_CORE_ACTIVE) { if (core->request_count)
if (!list_empty(&core->instances)) {
ret = vpu_core_snapshot(core); ret = vpu_core_snapshot(core);
if (ret) {
mutex_unlock(&core->lock); mutex_unlock(&core->lock);
if (ret)
return ret; return ret;
}
}
core->state = VPU_CORE_SNAPSHOT;
}
mutex_unlock(&core->lock);
vpu_core_cancel_work(core); vpu_core_cancel_work(core);
......
...@@ -11,5 +11,6 @@ u32 csr_readl(struct vpu_core *core, u32 reg); ...@@ -11,5 +11,6 @@ u32 csr_readl(struct vpu_core *core, u32 reg);
int vpu_alloc_dma(struct vpu_core *core, struct vpu_buffer *buf); int vpu_alloc_dma(struct vpu_core *core, struct vpu_buffer *buf);
void vpu_free_dma(struct vpu_buffer *buf); void vpu_free_dma(struct vpu_buffer *buf);
struct vpu_inst *vpu_core_find_instance(struct vpu_core *core, u32 index); struct vpu_inst *vpu_core_find_instance(struct vpu_core *core, u32 index);
void vpu_core_set_state(struct vpu_core *core, enum vpu_core_state state);
#endif #endif
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include "vpu.h" #include "vpu.h"
#include "vpu_defs.h" #include "vpu_defs.h"
#include "vpu_core.h"
#include "vpu_helpers.h" #include "vpu_helpers.h"
#include "vpu_cmds.h" #include "vpu_cmds.h"
#include "vpu_rpc.h" #include "vpu_rpc.h"
...@@ -233,6 +234,10 @@ static int vpu_dbg_core(struct seq_file *s, void *data) ...@@ -233,6 +234,10 @@ static int vpu_dbg_core(struct seq_file *s, void *data)
if (seq_write(s, str, num)) if (seq_write(s, str, num))
return 0; return 0;
num = scnprintf(str, sizeof(str), "power %s\n",
vpu_iface_get_power_state(core) ? "on" : "off");
if (seq_write(s, str, num))
return 0;
num = scnprintf(str, sizeof(str), "state = %d\n", core->state); num = scnprintf(str, sizeof(str), "state = %d\n", core->state);
if (seq_write(s, str, num)) if (seq_write(s, str, num))
return 0; return 0;
...@@ -346,10 +351,10 @@ static ssize_t vpu_dbg_core_write(struct file *file, ...@@ -346,10 +351,10 @@ static ssize_t vpu_dbg_core_write(struct file *file,
pm_runtime_resume_and_get(core->dev); pm_runtime_resume_and_get(core->dev);
mutex_lock(&core->lock); mutex_lock(&core->lock);
if (core->state != VPU_CORE_DEINIT && !core->instance_mask) { if (vpu_iface_get_power_state(core) && !core->request_count) {
dev_info(core->dev, "reset\n"); dev_info(core->dev, "reset\n");
if (!vpu_core_sw_reset(core)) { if (!vpu_core_sw_reset(core)) {
core->state = VPU_CORE_ACTIVE; vpu_core_set_state(core, VPU_CORE_ACTIVE);
core->hang_mask = 0; core->hang_mask = 0;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment