From patchwork Tue May 1 12:49:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 10373845 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 D6BAA601C7 for ; Tue, 1 May 2018 12:49:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7CD028C0C for ; Tue, 1 May 2018 12:49:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCAF928C59; Tue, 1 May 2018 12:49:36 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 4EFE428C0C for ; Tue, 1 May 2018 12:49:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755462AbeEAMtd (ORCPT ); Tue, 1 May 2018 08:49:33 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:48368 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755259AbeEAMtb (ORCPT ); Tue, 1 May 2018 08:49:31 -0400 Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 370D86166; Tue, 1 May 2018 14:49:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1525178967; bh=ihEuJyvZKYSiSjXbZj4YQcfgKWZrjT4i1fD5guI3MHo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=rDjDXwkpfUULNOBM/bOHqAQTQfSSKODAv0hOode9hGe3fjAuXPnD7mvsg0ro/av5h 19MtHrKO1KL8tsVzt3h+kqtxtQl/19R3fvSbJHwuvkiYcv6ORl6QKBo6epEzXle1Ku y6dCp9iGjaXXIi1FBWwS6vy9fTGpFRH+w484eKdc= From: Kieran Bingham To: Laurent Pinchart , linux-renesas-soc@vger.kernel.org, linux-media@vger.kernel.org Cc: mchehab@kernel.org, Kieran Bingham Subject: [PATCH v8 5/8] media: vsp1: Use reference counting for bodies Date: Tue, 1 May 2018 13:49:17 +0100 Message-Id: <2fedca817bfe96479bae9908cfde43a12d4f9648.1525178613.git-series.kieran.bingham+renesas@ideasonboard.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: References: In-Reply-To: References: 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 Reviewed-by: Laurent Pinchart --- 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. Changes since v7: - Fix comment style drivers/media/platform/vsp1/vsp1_clu.c | 7 ++++++- drivers/media/platform/vsp1/vsp1_dl.c | 16 ++++++++++++++-- drivers/media/platform/vsp1/vsp1_lut.c | 7 ++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/vsp1/vsp1_clu.c b/drivers/media/platform/vsp1/vsp1_clu.c index 8efa12f5e53f..ea83f1b7d125 100644 --- a/drivers/media/platform/vsp1/vsp1_clu.c +++ b/drivers/media/platform/vsp1/vsp1_clu.c @@ -212,8 +212,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 5074a83c0cf4..e07ed3a2acda 100644 --- a/drivers/media/platform/vsp1/vsp1_dl.c +++ b/drivers/media/platform/vsp1/vsp1_dl.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -54,6 +55,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; @@ -258,6 +261,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); @@ -278,6 +282,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); @@ -463,8 +470,11 @@ void vsp1_dl_list_write(struct vsp1_dl_list *dl, u32 reg, u32 data) * 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, and must not release it - * explicitly with vsp1_dl_body_put(). + * 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. @@ -475,6 +485,8 @@ int vsp1_dl_list_add_body(struct vsp1_dl_list *dl, struct vsp1_dl_body *dlb) 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 6b358617ce15..b3ea90172439 100644 --- a/drivers/media/platform/vsp1/vsp1_lut.c +++ b/drivers/media/platform/vsp1/vsp1_lut.c @@ -168,8 +168,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; } }