Commit e11f3e6e authored by Philipp Zabel's avatar Philipp Zabel Committed by Mauro Carvalho Chehab

[media] media: coda: keep track of active instances

Determining the next free instance just by incrementing and decrementing
an instance counter does not work: if there are two instances opened,
0 and 1, and instance 0 is released, the next call to coda_open will
create a new instance with index 1, but instance 1 is already in use.
Instead, scan a bitfield of active instances to determine the first
free instance index.
Signed-off-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
Tested-by: default avatarJavier Martin <javier.martin@vista-silicon.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent bcedb4c2
...@@ -134,7 +134,8 @@ struct coda_dev { ...@@ -134,7 +134,8 @@ struct coda_dev {
struct mutex dev_mutex; struct mutex dev_mutex;
struct v4l2_m2m_dev *m2m_dev; struct v4l2_m2m_dev *m2m_dev;
struct vb2_alloc_ctx *alloc_ctx; struct vb2_alloc_ctx *alloc_ctx;
int instances; struct list_head instances;
unsigned long instance_mask;
}; };
struct coda_params { struct coda_params {
...@@ -152,6 +153,7 @@ struct coda_params { ...@@ -152,6 +153,7 @@ struct coda_params {
struct coda_ctx { struct coda_ctx {
struct coda_dev *dev; struct coda_dev *dev;
struct list_head list;
int aborting; int aborting;
int rawstreamon; int rawstreamon;
int compstreamon; int compstreamon;
...@@ -1360,14 +1362,22 @@ static int coda_queue_init(void *priv, struct vb2_queue *src_vq, ...@@ -1360,14 +1362,22 @@ static int coda_queue_init(void *priv, struct vb2_queue *src_vq,
return vb2_queue_init(dst_vq); return vb2_queue_init(dst_vq);
} }
static int coda_next_free_instance(struct coda_dev *dev)
{
return ffz(dev->instance_mask);
}
static int coda_open(struct file *file) static int coda_open(struct file *file)
{ {
struct coda_dev *dev = video_drvdata(file); struct coda_dev *dev = video_drvdata(file);
struct coda_ctx *ctx = NULL; struct coda_ctx *ctx = NULL;
int ret = 0; int ret = 0;
int idx;
if (dev->instances >= CODA_MAX_INSTANCES) idx = coda_next_free_instance(dev);
if (idx >= CODA_MAX_INSTANCES)
return -EBUSY; return -EBUSY;
set_bit(idx, &dev->instance_mask);
ctx = kzalloc(sizeof *ctx, GFP_KERNEL); ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
if (!ctx) if (!ctx)
...@@ -1377,6 +1387,7 @@ static int coda_open(struct file *file) ...@@ -1377,6 +1387,7 @@ static int coda_open(struct file *file)
file->private_data = &ctx->fh; file->private_data = &ctx->fh;
v4l2_fh_add(&ctx->fh); v4l2_fh_add(&ctx->fh);
ctx->dev = dev; ctx->dev = dev;
ctx->idx = idx;
set_default_params(ctx); set_default_params(ctx);
ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx,
...@@ -1405,7 +1416,7 @@ static int coda_open(struct file *file) ...@@ -1405,7 +1416,7 @@ static int coda_open(struct file *file)
} }
coda_lock(ctx); coda_lock(ctx);
ctx->idx = dev->instances++; list_add(&ctx->list, &dev->instances);
coda_unlock(ctx); coda_unlock(ctx);
clk_prepare_enable(dev->clk_per); clk_prepare_enable(dev->clk_per);
...@@ -1432,7 +1443,7 @@ static int coda_release(struct file *file) ...@@ -1432,7 +1443,7 @@ static int coda_release(struct file *file)
ctx); ctx);
coda_lock(ctx); coda_lock(ctx);
dev->instances--; list_del(&ctx->list);
coda_unlock(ctx); coda_unlock(ctx);
dma_free_coherent(&dev->plat_dev->dev, CODA_PARA_BUF_SIZE, dma_free_coherent(&dev->plat_dev->dev, CODA_PARA_BUF_SIZE,
...@@ -1443,6 +1454,7 @@ static int coda_release(struct file *file) ...@@ -1443,6 +1454,7 @@ static int coda_release(struct file *file)
clk_disable_unprepare(dev->clk_ahb); clk_disable_unprepare(dev->clk_ahb);
v4l2_fh_del(&ctx->fh); v4l2_fh_del(&ctx->fh);
v4l2_fh_exit(&ctx->fh); v4l2_fh_exit(&ctx->fh);
clear_bit(ctx->idx, &dev->instance_mask);
kfree(ctx); kfree(ctx);
return 0; return 0;
...@@ -1826,6 +1838,7 @@ static int __devinit coda_probe(struct platform_device *pdev) ...@@ -1826,6 +1838,7 @@ static int __devinit coda_probe(struct platform_device *pdev)
} }
spin_lock_init(&dev->irqlock); spin_lock_init(&dev->irqlock);
INIT_LIST_HEAD(&dev->instances);
dev->plat_dev = pdev; dev->plat_dev = pdev;
dev->clk_per = devm_clk_get(&pdev->dev, "per"); dev->clk_per = devm_clk_get(&pdev->dev, "per");
......
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