struct mutex dev_mutex;
struct v4l2_m2m_dev *m2m_dev;
struct vb2_alloc_ctx *alloc_ctx;
- int instances;
+ struct list_head instances;
+ unsigned long instance_mask;
};
struct coda_params {
struct coda_ctx {
struct coda_dev *dev;
+ struct list_head list;
int aborting;
int rawstreamon;
int compstreamon;
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)
{
struct coda_dev *dev = video_drvdata(file);
struct coda_ctx *ctx = NULL;
int ret = 0;
+ int idx;
- if (dev->instances >= CODA_MAX_INSTANCES)
+ idx = coda_next_free_instance(dev);
+ if (idx >= CODA_MAX_INSTANCES)
return -EBUSY;
+ set_bit(idx, &dev->instance_mask);
ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
if (!ctx)
file->private_data = &ctx->fh;
v4l2_fh_add(&ctx->fh);
ctx->dev = dev;
+ ctx->idx = idx;
set_default_params(ctx);
ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx,
}
coda_lock(ctx);
- ctx->idx = dev->instances++;
+ list_add(&ctx->list, &dev->instances);
coda_unlock(ctx);
clk_prepare_enable(dev->clk_per);
ctx);
coda_lock(ctx);
- dev->instances--;
+ list_del(&ctx->list);
coda_unlock(ctx);
dma_free_coherent(&dev->plat_dev->dev, CODA_PARA_BUF_SIZE,
clk_disable_unprepare(dev->clk_ahb);
v4l2_fh_del(&ctx->fh);
v4l2_fh_exit(&ctx->fh);
+ clear_bit(ctx->idx, &dev->instance_mask);
kfree(ctx);
return 0;
}
spin_lock_init(&dev->irqlock);
+ INIT_LIST_HEAD(&dev->instances);
dev->plat_dev = pdev;
dev->clk_per = devm_clk_get(&pdev->dev, "per");