From patchwork Mon Jun 12 16:27:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanimir Varbanov X-Patchwork-Id: 103648 Delivered-To: patch@linaro.org Received: by 10.182.29.35 with SMTP id g3csp76402obh; Mon, 12 Jun 2017 09:29:47 -0700 (PDT) X-Received: by 10.98.82.200 with SMTP id g191mr17634216pfb.181.1497284987344; Mon, 12 Jun 2017 09:29:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497284987; cv=none; d=google.com; s=arc-20160816; b=e2g7C5g1QcsZQGgxKi6e8q4MWVI9e0H8z/fa/FhFYcp7XHIL7JqamaYHAfiZ8ossDK wg99zqqwzi7E8+AJrNw0w4TbzSMMg+kML9QHhPu4ILANEZvCRxgMDPStnmNfjqFSfPjR FkY4iyVc4M8hx6RpitSZ54Eyo+5rq8Hq205thZhOsHddLPriuSPtqPYKTHAGBulCgEG5 2KNYSAaTYTGNCvxGsBiXmZnXXoMbUr+Lyl7DbWIT7TVR637M6bcg3OsaS+fm7Xobsxd2 3pOb215UrSQ9oIsi79So3HdsVNWUu1ZILG3qWqPeUqS+icL46IaNg3DOfJoc4dt8CmUl lMkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=IoXMroDIV0WDBJovHns6UBoXCCeF8YNdRfSsxMagTZs=; b=WOvtegHuLFLLhh+f1k18C6qz95bSOyhDzoayQ/wxUywrSc8tu40csqC24feimtMmNf aVEridcA90+FYAgtd+xBaZ4wu8dnsoQbvBI6zRpiIRU2aonX5tvUQ792T/UCc1ePP1E2 sigtQHIbSWy/FpffpEtyC2hDTv7CFIuKyj27xiAW3UawnHiEcRnofscnx7Vs4ryUec7v 9V22mt0PHHE42OMGAOdYf6Ktl71hdd/201oXo0tE8gMXvW/xQjoE+lrplLWQEB+5ScUG nHEYxFWfnS+nkC3+GYbIxOMzXA04h8za1M73+iUKJKrQKXCwPn6cR2w9YEQhTYu0u35W 85VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r8si7262474pfb.22.2017.06.12.09.29.47; Mon, 12 Jun 2017 09:29:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753263AbdFLQ3c (ORCPT + 10 others); Mon, 12 Jun 2017 12:29:32 -0400 Received: from mail-wr0-f180.google.com ([209.85.128.180]:32907 "EHLO mail-wr0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753857AbdFLQ3a (ORCPT ); Mon, 12 Jun 2017 12:29:30 -0400 Received: by mail-wr0-f180.google.com with SMTP id v104so101950400wrb.0 for ; Mon, 12 Jun 2017 09:29:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OrAlylWhhHEYYyebsMFbln5HOCDCCiwo6pmL/qgrjWk=; b=h0AaemQVgQzARzd1F/B0GQT4gu+VseTe8Wp3lLQDaF87NAesWv4Gl2VrXIBpH3Xd/k +0GDgLx+ZdlnW55mYNAml7TWi19zeaXBhDcVJ0arSnI9a3ol4tigNo7XWRnBDjjtDFLt vcPl/ItsfIscIj6t/30cqJgDW6I/585X9cHh0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OrAlylWhhHEYYyebsMFbln5HOCDCCiwo6pmL/qgrjWk=; b=GBggvdtSO2uyIsu9bx1VFdN3f87CJEcagTQ8rUKMc/XQ7JCuBPSFjr0toWPh/u1zJ5 C87cn5WyqIv8QoSM1+FfoT7/8k/MF7WFCbqfeP+Nmhv80PH/tgfz51CT/4WIwWhKzkNL dWqoKVgPFlgFBOp/tZioSlc03SYcgU+y4TAruqwPzXNbOAFCf/yYaDks0hgqm8QB5Vq3 /CDrknSRFuaZdSfQBSgTgGrm+P4Ob9Ztxa45qCqRBrOVbLmW//4ZFAdjEHcgRzPOlzZ7 jLBntEcsSA6ZFfDwSHPA/s51zo4y5S9FfVk/8A5uXdHdwW/Cl+B0EEAfj6cJENS0wB3w dtdQ== X-Gm-Message-State: AKS2vOzzggL/KtvVzAVe0en9Z/qgLGR0nWgeoQnfEKqW3p8bdu7od9g5 HVPPhcp0z9CD/kDW X-Received: by 10.28.107.88 with SMTP id g85mr2310854wmc.42.1497284960290; Mon, 12 Jun 2017 09:29:20 -0700 (PDT) Received: from mms-0440.qualcomm.mm-sol.com ([37.157.136.206]) by smtp.gmail.com with ESMTPSA id 49sm14493531wrz.8.2017.06.12.09.29.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Jun 2017 09:29:19 -0700 (PDT) From: Stanimir Varbanov To: Mauro Carvalho Chehab , Hans Verkuil Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Stanimir Varbanov Subject: [PATCH v10 01/18] media: v4l2-mem2mem: extend m2m APIs for more accurate buffer management Date: Mon, 12 Jun 2017 19:27:38 +0300 Message-Id: <1497284875-19999-2-git-send-email-stanimir.varbanov@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497284875-19999-1-git-send-email-stanimir.varbanov@linaro.org> References: <1497284875-19999-1-git-send-email-stanimir.varbanov@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org this add functions for: - remove buffers from src/dst queue by index - remove exact buffer from src/dst queue also extends m2m API to iterate over a list of src/dst buffers in safely and non-safely manner. Signed-off-by: Stanimir Varbanov --- drivers/media/v4l2-core/v4l2-mem2mem.c | 37 ++++++++++++++ include/media/v4l2-mem2mem.h | 92 ++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c index 6bc27e7b2a33..f62e68aa04c4 100644 --- a/drivers/media/v4l2-core/v4l2-mem2mem.c +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c @@ -126,6 +126,43 @@ void *v4l2_m2m_buf_remove(struct v4l2_m2m_queue_ctx *q_ctx) } EXPORT_SYMBOL_GPL(v4l2_m2m_buf_remove); +void v4l2_m2m_buf_remove_by_buf(struct v4l2_m2m_queue_ctx *q_ctx, + struct vb2_v4l2_buffer *vbuf) +{ + struct v4l2_m2m_buffer *b; + unsigned long flags; + + spin_lock_irqsave(&q_ctx->rdy_spinlock, flags); + b = container_of(vbuf, struct v4l2_m2m_buffer, vb); + list_del(&b->list); + q_ctx->num_rdy--; + spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags); +} +EXPORT_SYMBOL_GPL(v4l2_m2m_buf_remove_by_buf); + +struct vb2_v4l2_buffer * +v4l2_m2m_buf_remove_by_idx(struct v4l2_m2m_queue_ctx *q_ctx, unsigned int idx) + +{ + struct v4l2_m2m_buffer *b, *tmp; + struct vb2_v4l2_buffer *ret = NULL; + unsigned long flags; + + spin_lock_irqsave(&q_ctx->rdy_spinlock, flags); + list_for_each_entry_safe(b, tmp, &q_ctx->rdy_queue, list) { + if (b->vb.vb2_buf.index == idx) { + list_del(&b->list); + q_ctx->num_rdy--; + ret = &b->vb; + break; + } + } + spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags); + + return ret; +} +EXPORT_SYMBOL_GPL(v4l2_m2m_buf_remove_by_idx); + /* * Scheduling handlers */ diff --git a/include/media/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h index 3ccd01bd245e..e157d5c9b224 100644 --- a/include/media/v4l2-mem2mem.h +++ b/include/media/v4l2-mem2mem.h @@ -437,6 +437,47 @@ static inline void *v4l2_m2m_next_dst_buf(struct v4l2_m2m_ctx *m2m_ctx) } /** + * v4l2_m2m_for_each_dst_buf() - iterate over a list of destination ready + * buffers + * + * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx + * @b: current buffer of type struct v4l2_m2m_buffer + */ +#define v4l2_m2m_for_each_dst_buf(m2m_ctx, b) \ + list_for_each_entry(b, &m2m_ctx->cap_q_ctx.rdy_queue, list) + +/** + * v4l2_m2m_for_each_src_buf() - iterate over a list of source ready buffers + * + * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx + * @b: current buffer of type struct v4l2_m2m_buffer + */ +#define v4l2_m2m_for_each_src_buf(m2m_ctx, b) \ + list_for_each_entry(b, &m2m_ctx->out_q_ctx.rdy_queue, list) + +/** + * v4l2_m2m_for_each_dst_buf_safe() - iterate over a list of destination ready + * buffers safely + * + * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx + * @b: current buffer of type struct v4l2_m2m_buffer + * @n: used as temporary storage + */ +#define v4l2_m2m_for_each_dst_buf_safe(m2m_ctx, b, n) \ + list_for_each_entry_safe(b, n, &m2m_ctx->cap_q_ctx.rdy_queue, list) + +/** + * v4l2_m2m_for_each_src_buf_safe() - iterate over a list of source ready + * buffers safely + * + * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx + * @b: current buffer of type struct v4l2_m2m_buffer + * @n: used as temporary storage + */ +#define v4l2_m2m_for_each_src_buf_safe(m2m_ctx, b, n) \ + list_for_each_entry_safe(b, n, &m2m_ctx->out_q_ctx.rdy_queue, list) + +/** * v4l2_m2m_get_src_vq() - return vb2_queue for source buffers * * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx @@ -488,6 +529,57 @@ static inline void *v4l2_m2m_dst_buf_remove(struct v4l2_m2m_ctx *m2m_ctx) return v4l2_m2m_buf_remove(&m2m_ctx->cap_q_ctx); } +/** + * v4l2_m2m_buf_remove_by_buf() - take off exact buffer from the list of ready + * buffers + * + * @q_ctx: pointer to struct @v4l2_m2m_queue_ctx + * @vbuf: the buffer to be removed + */ +void v4l2_m2m_buf_remove_by_buf(struct v4l2_m2m_queue_ctx *q_ctx, + struct vb2_v4l2_buffer *vbuf); + +/** + * v4l2_m2m_src_buf_remove_by_buf() - take off exact source buffer from the list + * of ready buffers + * + * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx + * @vbuf: the buffer to be removed + */ +static inline void v4l2_m2m_src_buf_remove_by_buf(struct v4l2_m2m_ctx *m2m_ctx, + struct vb2_v4l2_buffer *vbuf) +{ + v4l2_m2m_buf_remove_by_buf(&m2m_ctx->out_q_ctx, vbuf); +} + +/** + * v4l2_m2m_dst_buf_remove_by_buf() - take off exact destination buffer from the + * list of ready buffers + * + * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx + * @vbuf: the buffer to be removed + */ +static inline void v4l2_m2m_dst_buf_remove_by_buf(struct v4l2_m2m_ctx *m2m_ctx, + struct vb2_v4l2_buffer *vbuf) +{ + v4l2_m2m_buf_remove_by_buf(&m2m_ctx->cap_q_ctx, vbuf); +} + +struct vb2_v4l2_buffer * +v4l2_m2m_buf_remove_by_idx(struct v4l2_m2m_queue_ctx *q_ctx, unsigned int idx); + +static inline struct vb2_v4l2_buffer * +v4l2_m2m_src_buf_remove_by_idx(struct v4l2_m2m_ctx *m2m_ctx, unsigned int idx) +{ + return v4l2_m2m_buf_remove_by_idx(&m2m_ctx->out_q_ctx, idx); +} + +static inline struct vb2_v4l2_buffer * +v4l2_m2m_dst_buf_remove_by_idx(struct v4l2_m2m_ctx *m2m_ctx, unsigned int idx) +{ + return v4l2_m2m_buf_remove_by_idx(&m2m_ctx->cap_q_ctx, idx); +} + /* v4l2 ioctl helpers */ int v4l2_m2m_ioctl_reqbufs(struct file *file, void *priv,