From patchwork Mon Jan 15 16:38:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 10164783 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6EA9760325 for ; Mon, 15 Jan 2018 16:40:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5ECC6201B0 for ; Mon, 15 Jan 2018 16:40:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50C3720501; Mon, 15 Jan 2018 16:40:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI,URIBL_GREY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9D2A204C4 for ; Mon, 15 Jan 2018 16:40:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965155AbeAOQkM (ORCPT ); Mon, 15 Jan 2018 11:40:12 -0500 Received: from o1.7nn.fshared.sendgrid.net ([167.89.55.65]:55484 "EHLO o1.7nn.fshared.sendgrid.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966776AbeAOQio (ORCPT ); Mon, 15 Jan 2018 11:38:44 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=sendgrid.me; h=from:to:cc:subject:in-reply-to:references:in-reply-to:references; s=smtpapi; bh=vUzl2lZb1e3C/DsDtncgVSoQEuQ=; b=w5F9xMI+6KEhovsRbE QsNJ95nXWw0incHxjvx0vZVViJdzzKKO/BwoKwlhiSGnKLc5ub2JA6LH2lsupcl2 lXDF6pcUpYgcbB8Wy3jhzguXFfAFnl0Yx/EvuatdEfEE77YdMeRHWanbB5izBkDf eG0M7huEkXlIUkk9ctn99EG1A= Received: by filter0001p3iad2.sendgrid.net with SMTP id filter0001p3iad2-639-5A5CD912-27 2018-01-15 16:38:42.530340508 +0000 UTC Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by ismtpd0003p1lon1.sendgrid.net (SG) with ESMTP id jEGii0ZQQQm9imSK_gJQag Mon, 15 Jan 2018 16:38:42.243 +0000 (UTC) From: Kieran Bingham To: linux-media@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: Laurent Pinchart , Kieran Bingham , Kieran Bingham Subject: [PATCH v5 5/9] v4l: vsp1: Use reference counting for bodies Date: Mon, 15 Jan 2018 16:38:42 +0000 (UTC) Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-SG-EID: 8V71jyRnV10cxvLYTaW9vh8CCDNIgitSt4v541MRe1uDw0Xke9mkdk+md0c3JBuP53SGFCbxPsym8C /LgDD/eJNTDrxDmSlPJkN9Tuc8K8gaLBJZkHJKzdPOOen0rg/g0mJNaTmcpNgojOg86ug9MwPwv16P WmDDwO3CTJ4fWbjc+4SjTIjBWlZ7PzIW4ePpWJgnaCduFW5NBrrbbq5D2lUsJCAlMz3eZnRgbpT5am /k9h7tqeqbmAOPVQJYcU+1NlmfHIuvVbIR6hot9/cYLw== Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Extend the display list body with a reference count, allowing bodies to be kept as long as a reference is maintained. This provides the ability to keep a cached copy of bodies which will not change, so that they can be re-applied to multiple display lists. Signed-off-by: Kieran Bingham --- This could be squashed into the body update code, but it's not a straightforward squash as the refcounts will affect both: v4l: vsp1: Provide a body pool and v4l: vsp1: Convert display lists to use new body pool therefore, I have kept this separate to prevent breaking bisectability of the vsp-tests. v3: - 's/fragment/body/' v4: - Fix up reference handling comments. --- drivers/media/platform/vsp1/vsp1_clu.c | 7 ++++++- drivers/media/platform/vsp1/vsp1_dl.c | 15 ++++++++++++++- drivers/media/platform/vsp1/vsp1_lut.c | 7 ++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/vsp1/vsp1_clu.c b/drivers/media/platform/vsp1/vsp1_clu.c index a765d56c4118..1142d004e238 100644 --- a/drivers/media/platform/vsp1/vsp1_clu.c +++ b/drivers/media/platform/vsp1/vsp1_clu.c @@ -216,8 +216,13 @@ static void clu_configure(struct vsp1_entity *entity, clu->clu = NULL; spin_unlock_irqrestore(&clu->lock, flags); - if (dlb) + if (dlb) { vsp1_dl_list_add_body(dl, dlb); + + /* release our local reference */ + vsp1_dl_body_put(dlb); + } + break; } } diff --git a/drivers/media/platform/vsp1/vsp1_dl.c b/drivers/media/platform/vsp1/vsp1_dl.c index 961c3fd2ff1c..2784d3b48b02 100644 --- a/drivers/media/platform/vsp1/vsp1_dl.c +++ b/drivers/media/platform/vsp1/vsp1_dl.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -58,6 +59,8 @@ struct vsp1_dl_body { struct list_head list; struct list_head free; + refcount_t refcnt; + struct vsp1_dl_body_pool *pool; struct vsp1_device *vsp1; @@ -259,6 +262,7 @@ struct vsp1_dl_body *vsp1_dl_body_get(struct vsp1_dl_body_pool *pool) if (!list_empty(&pool->free)) { dlb = list_first_entry(&pool->free, struct vsp1_dl_body, free); list_del(&dlb->free); + refcount_set(&dlb->refcnt, 1); } spin_unlock_irqrestore(&pool->lock, flags); @@ -279,6 +283,9 @@ void vsp1_dl_body_put(struct vsp1_dl_body *dlb) if (!dlb) return; + if (!refcount_dec_and_test(&dlb->refcnt)) + return; + dlb->num_entries = 0; spin_lock_irqsave(&dlb->pool->lock, flags); @@ -465,7 +472,11 @@ void vsp1_dl_list_write(struct vsp1_dl_list *dl, u32 reg, u32 data) * in the order in which bodies are added. * * Adding a body to a display list passes ownership of the body to the list. The - * caller must not touch the body after this call. + * caller retains its reference to the fragment when adding it to the display + * list, but is not allowed to add new entries to the body. + * + * The reference must be explicitly released by a call to vsp1_dl_body_put() + * when the body isn't needed anymore. * * Additional bodies are only usable for display lists in header mode. * Attempting to add a body to a header-less display list will return an error. @@ -477,6 +488,8 @@ int vsp1_dl_list_add_body(struct vsp1_dl_list *dl, if (dl->dlm->mode != VSP1_DL_MODE_HEADER) return -EINVAL; + refcount_inc(&dlb->refcnt); + list_add_tail(&dlb->list, &dl->bodies); return 0; } diff --git a/drivers/media/platform/vsp1/vsp1_lut.c b/drivers/media/platform/vsp1/vsp1_lut.c index a9cf874312c1..7643f18b1ea6 100644 --- a/drivers/media/platform/vsp1/vsp1_lut.c +++ b/drivers/media/platform/vsp1/vsp1_lut.c @@ -172,8 +172,13 @@ static void lut_configure(struct vsp1_entity *entity, lut->lut = NULL; spin_unlock_irqrestore(&lut->lock, flags); - if (dlb) + if (dlb) { vsp1_dl_list_add_body(dl, dlb); + + /* release our local reference */ + vsp1_dl_body_put(dlb); + } + break; } }