Lines Matching refs:ctx

31 static int gsc_m2m_ctx_stop_req(struct gsc_ctx *ctx)  in gsc_m2m_ctx_stop_req()  argument
34 struct gsc_dev *gsc = ctx->gsc_dev; in gsc_m2m_ctx_stop_req()
38 if (!gsc_m2m_pending(gsc) || (curr_ctx != ctx)) in gsc_m2m_ctx_stop_req()
41 gsc_ctx_state_lock_set(GSC_CTX_STOP_REQ, ctx); in gsc_m2m_ctx_stop_req()
43 !gsc_ctx_state_is_set(GSC_CTX_STOP_REQ, ctx), in gsc_m2m_ctx_stop_req()
49 static void __gsc_m2m_job_abort(struct gsc_ctx *ctx) in __gsc_m2m_job_abort() argument
53 ret = gsc_m2m_ctx_stop_req(ctx); in __gsc_m2m_job_abort()
54 if ((ret == -ETIMEDOUT) || (ctx->state & GSC_CTX_ABORT)) { in __gsc_m2m_job_abort()
55 gsc_ctx_state_lock_clear(GSC_CTX_STOP_REQ | GSC_CTX_ABORT, ctx); in __gsc_m2m_job_abort()
56 gsc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR); in __gsc_m2m_job_abort()
62 struct gsc_ctx *ctx = q->drv_priv; in gsc_m2m_start_streaming() local
65 ret = pm_runtime_get_sync(&ctx->gsc_dev->pdev->dev); in gsc_m2m_start_streaming()
71 struct gsc_ctx *ctx = q->drv_priv; in gsc_m2m_stop_streaming() local
73 __gsc_m2m_job_abort(ctx); in gsc_m2m_stop_streaming()
75 pm_runtime_put(&ctx->gsc_dev->pdev->dev); in gsc_m2m_stop_streaming()
78 void gsc_m2m_job_finish(struct gsc_ctx *ctx, int vb_state) in gsc_m2m_job_finish() argument
82 if (!ctx || !ctx->m2m_ctx) in gsc_m2m_job_finish()
85 src_vb = v4l2_m2m_src_buf_remove(ctx->m2m_ctx); in gsc_m2m_job_finish()
86 dst_vb = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx); in gsc_m2m_job_finish()
99 v4l2_m2m_job_finish(ctx->gsc_dev->m2m.m2m_dev, in gsc_m2m_job_finish()
100 ctx->m2m_ctx); in gsc_m2m_job_finish()
109 static int gsc_get_bufs(struct gsc_ctx *ctx) in gsc_get_bufs() argument
115 s_frame = &ctx->s_frame; in gsc_get_bufs()
116 d_frame = &ctx->d_frame; in gsc_get_bufs()
118 src_vb = v4l2_m2m_next_src_buf(ctx->m2m_ctx); in gsc_get_bufs()
119 ret = gsc_prepare_addr(ctx, &src_vb->vb2_buf, s_frame, &s_frame->addr); in gsc_get_bufs()
123 dst_vb = v4l2_m2m_next_dst_buf(ctx->m2m_ctx); in gsc_get_bufs()
124 ret = gsc_prepare_addr(ctx, &dst_vb->vb2_buf, d_frame, &d_frame->addr); in gsc_get_bufs()
135 struct gsc_ctx *ctx = priv; in gsc_m2m_device_run() local
141 if (WARN(!ctx, "null hardware context\n")) in gsc_m2m_device_run()
144 gsc = ctx->gsc_dev; in gsc_m2m_device_run()
150 if (gsc->m2m.ctx != ctx) { in gsc_m2m_device_run()
152 gsc->m2m.ctx, ctx); in gsc_m2m_device_run()
153 ctx->state |= GSC_PARAMS; in gsc_m2m_device_run()
154 gsc->m2m.ctx = ctx; in gsc_m2m_device_run()
157 is_set = ctx->state & GSC_CTX_STOP_REQ; in gsc_m2m_device_run()
159 ctx->state &= ~GSC_CTX_STOP_REQ; in gsc_m2m_device_run()
160 ctx->state |= GSC_CTX_ABORT; in gsc_m2m_device_run()
165 ret = gsc_get_bufs(ctx); in gsc_m2m_device_run()
171 gsc_set_prefbuf(gsc, &ctx->s_frame); in gsc_m2m_device_run()
172 gsc_hw_set_input_addr(gsc, &ctx->s_frame.addr, GSC_M2M_BUF_NUM); in gsc_m2m_device_run()
173 gsc_hw_set_output_addr(gsc, &ctx->d_frame.addr, GSC_M2M_BUF_NUM); in gsc_m2m_device_run()
175 if (ctx->state & GSC_PARAMS) { in gsc_m2m_device_run()
181 if (gsc_set_scaler_info(ctx)) { in gsc_m2m_device_run()
186 gsc_hw_set_input_path(ctx); in gsc_m2m_device_run()
187 gsc_hw_set_in_size(ctx); in gsc_m2m_device_run()
188 gsc_hw_set_in_image_format(ctx); in gsc_m2m_device_run()
190 gsc_hw_set_output_path(ctx); in gsc_m2m_device_run()
191 gsc_hw_set_out_size(ctx); in gsc_m2m_device_run()
192 gsc_hw_set_out_image_format(ctx); in gsc_m2m_device_run()
194 gsc_hw_set_prescaler(ctx); in gsc_m2m_device_run()
195 gsc_hw_set_mainscaler(ctx); in gsc_m2m_device_run()
196 gsc_hw_set_rotation(ctx); in gsc_m2m_device_run()
197 gsc_hw_set_global_alpha(ctx); in gsc_m2m_device_run()
201 gsc_hw_set_sfr_update(ctx); in gsc_m2m_device_run()
203 ctx->state &= ~GSC_PARAMS; in gsc_m2m_device_run()
210 ctx->state &= ~GSC_PARAMS; in gsc_m2m_device_run()
219 struct gsc_ctx *ctx = vb2_get_drv_priv(vq); in gsc_m2m_queue_setup() local
223 frame = ctx_get_frame(ctx, vq->type); in gsc_m2m_queue_setup()
233 allocators[i] = ctx->gsc_dev->alloc_ctx; in gsc_m2m_queue_setup()
240 struct gsc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); in gsc_m2m_buf_prepare() local
244 frame = ctx_get_frame(ctx, vb->vb2_queue->type); in gsc_m2m_buf_prepare()
259 struct gsc_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); in gsc_m2m_buf_queue() local
261 pr_debug("ctx: %p, ctx->state: 0x%x", ctx, ctx->state); in gsc_m2m_buf_queue()
263 if (ctx->m2m_ctx) in gsc_m2m_buf_queue()
264 v4l2_m2m_buf_queue(ctx->m2m_ctx, vbuf); in gsc_m2m_buf_queue()
280 struct gsc_ctx *ctx = fh_to_ctx(fh); in gsc_m2m_querycap() local
281 struct gsc_dev *gsc = ctx->gsc_dev; in gsc_m2m_querycap()
302 struct gsc_ctx *ctx = fh_to_ctx(fh); in gsc_m2m_g_fmt_mplane() local
304 return gsc_g_fmt_mplane(ctx, f); in gsc_m2m_g_fmt_mplane()
310 struct gsc_ctx *ctx = fh_to_ctx(fh); in gsc_m2m_try_fmt_mplane() local
312 return gsc_try_fmt_mplane(ctx, f); in gsc_m2m_try_fmt_mplane()
318 struct gsc_ctx *ctx = fh_to_ctx(fh); in gsc_m2m_s_fmt_mplane() local
328 vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type); in gsc_m2m_s_fmt_mplane()
336 frame = &ctx->s_frame; in gsc_m2m_s_fmt_mplane()
338 frame = &ctx->d_frame; in gsc_m2m_s_fmt_mplane()
352 gsc_ctx_state_lock_set(GSC_PARAMS | GSC_DST_FMT, ctx); in gsc_m2m_s_fmt_mplane()
354 gsc_ctx_state_lock_set(GSC_PARAMS | GSC_SRC_FMT, ctx); in gsc_m2m_s_fmt_mplane()
364 struct gsc_ctx *ctx = fh_to_ctx(fh); in gsc_m2m_reqbufs() local
365 struct gsc_dev *gsc = ctx->gsc_dev; in gsc_m2m_reqbufs()
374 gsc_ctx_state_lock_clear(GSC_SRC_FMT, ctx); in gsc_m2m_reqbufs()
376 gsc_ctx_state_lock_clear(GSC_DST_FMT, ctx); in gsc_m2m_reqbufs()
379 return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs); in gsc_m2m_reqbufs()
385 struct gsc_ctx *ctx = fh_to_ctx(fh); in gsc_m2m_expbuf() local
386 return v4l2_m2m_expbuf(file, ctx->m2m_ctx, eb); in gsc_m2m_expbuf()
392 struct gsc_ctx *ctx = fh_to_ctx(fh); in gsc_m2m_querybuf() local
393 return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf); in gsc_m2m_querybuf()
399 struct gsc_ctx *ctx = fh_to_ctx(fh); in gsc_m2m_qbuf() local
400 return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf); in gsc_m2m_qbuf()
406 struct gsc_ctx *ctx = fh_to_ctx(fh); in gsc_m2m_dqbuf() local
407 return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf); in gsc_m2m_dqbuf()
413 struct gsc_ctx *ctx = fh_to_ctx(fh); in gsc_m2m_streamon() local
417 if (!gsc_ctx_state_is_set(GSC_SRC_FMT, ctx)) in gsc_m2m_streamon()
419 } else if (!gsc_ctx_state_is_set(GSC_DST_FMT, ctx)) { in gsc_m2m_streamon()
423 return v4l2_m2m_streamon(file, ctx->m2m_ctx, type); in gsc_m2m_streamon()
429 struct gsc_ctx *ctx = fh_to_ctx(fh); in gsc_m2m_streamoff() local
430 return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type); in gsc_m2m_streamoff()
452 struct gsc_ctx *ctx = fh_to_ctx(fh); in gsc_m2m_g_selection() local
458 frame = ctx_get_frame(ctx, s->type); in gsc_m2m_g_selection()
489 struct gsc_ctx *ctx = fh_to_ctx(fh); in gsc_m2m_s_selection() local
491 struct gsc_variant *variant = ctx->gsc_dev->variant; in gsc_m2m_s_selection()
501 ret = gsc_try_crop(ctx, &cr); in gsc_m2m_s_selection()
519 frame = &ctx->s_frame; in gsc_m2m_s_selection()
525 frame = &ctx->d_frame; in gsc_m2m_s_selection()
533 if (gsc_ctx_state_is_set(GSC_DST_FMT | GSC_SRC_FMT, ctx)) { in gsc_m2m_s_selection()
536 cr.c.height, ctx->d_frame.crop.width, in gsc_m2m_s_selection()
537 ctx->d_frame.crop.height, in gsc_m2m_s_selection()
538 ctx->gsc_ctrls.rotate->val, ctx->out_path); in gsc_m2m_s_selection()
541 ctx->s_frame.crop.width, in gsc_m2m_s_selection()
542 ctx->s_frame.crop.height, cr.c.width, in gsc_m2m_s_selection()
543 cr.c.height, ctx->gsc_ctrls.rotate->val, in gsc_m2m_s_selection()
544 ctx->out_path); in gsc_m2m_s_selection()
555 gsc_ctx_state_lock_set(GSC_PARAMS, ctx); in gsc_m2m_s_selection()
583 struct gsc_ctx *ctx = priv; in queue_init() local
589 src_vq->drv_priv = ctx; in queue_init()
594 src_vq->lock = &ctx->gsc_dev->lock; in queue_init()
603 dst_vq->drv_priv = ctx; in queue_init()
608 dst_vq->lock = &ctx->gsc_dev->lock; in queue_init()
616 struct gsc_ctx *ctx = NULL; in gsc_m2m_open() local
624 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); in gsc_m2m_open()
625 if (!ctx) { in gsc_m2m_open()
630 v4l2_fh_init(&ctx->fh, gsc->m2m.vfd); in gsc_m2m_open()
631 ret = gsc_ctrls_create(ctx); in gsc_m2m_open()
636 ctx->fh.ctrl_handler = &ctx->ctrl_handler; in gsc_m2m_open()
637 file->private_data = &ctx->fh; in gsc_m2m_open()
638 v4l2_fh_add(&ctx->fh); in gsc_m2m_open()
640 ctx->gsc_dev = gsc; in gsc_m2m_open()
642 ctx->s_frame.fmt = get_format(0); in gsc_m2m_open()
643 ctx->d_frame.fmt = get_format(0); in gsc_m2m_open()
645 ctx->state = GSC_CTX_M2M; in gsc_m2m_open()
646 ctx->flags = 0; in gsc_m2m_open()
647 ctx->in_path = GSC_DMA; in gsc_m2m_open()
648 ctx->out_path = GSC_DMA; in gsc_m2m_open()
650 ctx->m2m_ctx = v4l2_m2m_ctx_init(gsc->m2m.m2m_dev, ctx, queue_init); in gsc_m2m_open()
651 if (IS_ERR(ctx->m2m_ctx)) { in gsc_m2m_open()
653 ret = PTR_ERR(ctx->m2m_ctx); in gsc_m2m_open()
660 pr_debug("gsc m2m driver is opened, ctx(0x%p)", ctx); in gsc_m2m_open()
666 gsc_ctrls_delete(ctx); in gsc_m2m_open()
668 v4l2_fh_del(&ctx->fh); in gsc_m2m_open()
669 v4l2_fh_exit(&ctx->fh); in gsc_m2m_open()
670 kfree(ctx); in gsc_m2m_open()
678 struct gsc_ctx *ctx = fh_to_ctx(file->private_data); in gsc_m2m_release() local
679 struct gsc_dev *gsc = ctx->gsc_dev; in gsc_m2m_release()
686 v4l2_m2m_ctx_release(ctx->m2m_ctx); in gsc_m2m_release()
687 gsc_ctrls_delete(ctx); in gsc_m2m_release()
688 v4l2_fh_del(&ctx->fh); in gsc_m2m_release()
689 v4l2_fh_exit(&ctx->fh); in gsc_m2m_release()
693 kfree(ctx); in gsc_m2m_release()
702 struct gsc_ctx *ctx = fh_to_ctx(file->private_data); in gsc_m2m_poll() local
703 struct gsc_dev *gsc = ctx->gsc_dev; in gsc_m2m_poll()
709 ret = v4l2_m2m_poll(file, ctx->m2m_ctx, wait); in gsc_m2m_poll()
717 struct gsc_ctx *ctx = fh_to_ctx(file->private_data); in gsc_m2m_mmap() local
718 struct gsc_dev *gsc = ctx->gsc_dev; in gsc_m2m_mmap()
724 ret = v4l2_m2m_mmap(file, ctx->m2m_ctx, vma); in gsc_m2m_mmap()