From patchwork Thu May 14 16:01:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11549203 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99379618 for ; Thu, 14 May 2020 16:02:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 80A4E2065F for ; Thu, 14 May 2020 16:02:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KHPWS2g0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728068AbgENQCq (ORCPT ); Thu, 14 May 2020 12:02:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbgENQCq (ORCPT ); Thu, 14 May 2020 12:02:46 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABD11C061A0C; Thu, 14 May 2020 09:02:45 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id b190so1499694pfg.6; Thu, 14 May 2020 09:02:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gjGveS3ShwN3M2V+xFbQcb2X+FYrrI//RaMYz+fhQ8Y=; b=KHPWS2g0O3szfeTlExjTGiVnhcUCBcL29pepM/NBas7fPxZSbmRSCEOoL2FkNgbdrq iW1lObr2E8R9bp3iwqPPraL0EECicJ1ZKrHWz3kEoA8YBGnUks9oJ5XI4jRrmoEstd7l vRiCvtefIaQLrwK8YXvLqWCnXySS9CUwuuSIdTV9mnTqR4oVhCzMEMtSZ5l8gwqMOzcs NYtNBXrYxK2oeXrGm1qKuBIyP1+icZ4vBAeCfxqm3aHTurGOiQyhupOIR7wbeu1O1/XJ 7+gz7lcOkf2wRvGhQOP3cv28NPDo5l7m60eQyx5DA5q5dEXhF0nd9FlvmnjLiKpk17IM CvSg== 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:mime-version:content-transfer-encoding; bh=gjGveS3ShwN3M2V+xFbQcb2X+FYrrI//RaMYz+fhQ8Y=; b=p4I06tuvQ8fXWprrg0FFaD8pqLkAVYF3+0m2mNAHvv+7oWXM6mLnKmwpbhMTjh+WTb x8RThEO692R0Ziy2S2pO9HneG0Kn8U9vj/spyCN87otGqk1tf8wRYBV1fdHRIeGZnhrL RLV8tGrLc00ExmJaIncSpvtzamy5xXxcGc8/LMyQwYGTWP6EoB5oQcG4Cuj7aWq1351U x4j1gNeEEPyGLNRg58HcIXHwcEt37BdwPA1IBN2be1KheoQWemvxPrL9L8mxY6Z1q3SN Tb/qIzJLGUyDx9j7oJguTLl1XMIGXKMGdM+bbfdvUa8pP7SYX6PiOZOF3n135hBgpWIP uDXw== X-Gm-Message-State: AOAM531ZDyQ1zwX9ecbOAoVxmGXkt9wtDT3zZriWBgm8o75p5sI8OYDt lxckM9GpV8rGHa1KFFNoey9V1gFd X-Google-Smtp-Source: ABdhPJySaVHnqRrA8exiVtLmKm9JksxLsY/i0LWDZu4E8m7ZG6wEQ6YpXPPxVSNi4zmLSugqZ5z66Q== X-Received: by 2002:a63:c842:: with SMTP id l2mr4672083pgi.221.1589472165174; Thu, 14 May 2020 09:02:45 -0700 (PDT) Received: from localhost.localdomain ([2409:10:2e40:5100:6e29:95ff:fe2d:8f34]) by smtp.gmail.com with ESMTPSA id y6sm18178691pjw.15.2020.05.14.09.02.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 09:02:43 -0700 (PDT) From: Sergey Senozhatsky To: Hans Verkuil Cc: Mauro Carvalho Chehab , Tomasz Figa , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Sergey Senozhatsky Subject: [PATCH v6 07/14] videobuf2: factor out planes prepare/finish functions Date: Fri, 15 May 2020 01:01:46 +0900 Message-Id: <20200514160153.3646-8-sergey.senozhatsky@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200514160153.3646-1-sergey.senozhatsky@gmail.com> References: <20200514160153.3646-1-sergey.senozhatsky@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Sergey Senozhatsky Factor out the code, no functional changes. Signed-off-by: Sergey Senozhatsky --- .../media/common/videobuf2/videobuf2-core.c | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 6efac531006f..6a95663afcd1 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -296,6 +296,32 @@ static void __vb2_buf_dmabuf_put(struct vb2_buffer *vb) __vb2_plane_dmabuf_put(vb, &vb->planes[plane]); } +/* + * __vb2_buf_mem_prepare() - call ->prepare() on buffer's private memory + * to sync caches + */ +static void __vb2_buf_mem_prepare(struct vb2_buffer *vb) +{ + unsigned int plane; + + for (plane = 0; plane < vb->num_planes; ++plane) + call_void_memop(vb, prepare, vb->planes[plane].mem_priv); + vb->synced = 1; +} + +/* + * __vb2_buf_mem_finish() - call ->finish on buffer's private memory + * to sync caches + */ +static void __vb2_buf_mem_finish(struct vb2_buffer *vb) +{ + unsigned int plane; + + for (plane = 0; plane < vb->num_planes; ++plane) + call_void_memop(vb, finish, vb->planes[plane].mem_priv); + vb->synced = 0; +} + /* * __setup_offsets() - setup unique offsets ("cookies") for every plane in * the buffer. @@ -960,7 +986,6 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state) { struct vb2_queue *q = vb->vb2_queue; unsigned long flags; - unsigned int plane; if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE)) return; @@ -980,12 +1005,8 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state) dprintk(4, "done processing on buffer %d, state: %d\n", vb->index, state); - if (state != VB2_BUF_STATE_QUEUED) { - /* sync buffers */ - for (plane = 0; plane < vb->num_planes; ++plane) - call_void_memop(vb, finish, vb->planes[plane].mem_priv); - vb->synced = 0; - } + if (state != VB2_BUF_STATE_QUEUED) + __vb2_buf_mem_finish(vb); spin_lock_irqsave(&q->done_lock, flags); if (state == VB2_BUF_STATE_QUEUED) { @@ -1310,7 +1331,6 @@ static int __buf_prepare(struct vb2_buffer *vb) { struct vb2_queue *q = vb->vb2_queue; enum vb2_buffer_state orig_state = vb->state; - unsigned int plane; int ret; if (q->error) { @@ -1354,11 +1374,7 @@ static int __buf_prepare(struct vb2_buffer *vb) return ret; } - /* sync buffers */ - for (plane = 0; plane < vb->num_planes; ++plane) - call_void_memop(vb, prepare, vb->planes[plane].mem_priv); - - vb->synced = 1; + __vb2_buf_mem_prepare(vb); vb->prepared = 1; vb->state = orig_state; @@ -1978,14 +1994,8 @@ static void __vb2_queue_cancel(struct vb2_queue *q) call_void_vb_qop(vb, buf_request_complete, vb); } - if (vb->synced) { - unsigned int plane; - - for (plane = 0; plane < vb->num_planes; ++plane) - call_void_memop(vb, finish, - vb->planes[plane].mem_priv); - vb->synced = 0; - } + if (vb->synced) + __vb2_buf_mem_finish(vb); if (vb->prepared) { call_void_vb_qop(vb, buf_finish, vb);