Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2936600rwb; Mon, 15 Aug 2022 14:24:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR61EavQY38Dk1BrBVACxMtNed4ZojkdPNvtYZVg4y3qsOq4w4MYJJbb1lzbftwpiouve9AS X-Received: by 2002:a17:906:7952:b0:732:f993:75bf with SMTP id l18-20020a170906795200b00732f99375bfmr11779810ejo.165.1660598662470; Mon, 15 Aug 2022 14:24:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660598662; cv=none; d=google.com; s=arc-20160816; b=CfDl5Le9orqX7dhSrD0/tLDlpIvsqGBc0q/DGbUcZRxUedhtwfJhVkXS7KfpL9R6sM b3kSQfFACFpye9SORrB3vDNRUzcTPax6e+JMmL9193JEuZL6TwkcsPsxUJ/kxJYIAhOD InSe0BB4Xu81sfcVK/RRaZNPYTiAicK1YUterxjmU7XJJ7zPpcDjH4yov7LjatiLBVUP WcEWVQ3b+n8i9bQOx+r/wPBb/jH5vQN85AZbMZC5nt+FWQ8+3hyINfyJvUH3b+TTx5jN d4mwDP7jxyF+tVKtOSGgcU8KXnl6ZR3wNYT3vfKr8OFstjfKr3zWVBwGu28HCT654mW1 2bRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZObpSXKLlmRdVddewRfB/ZHvlwOJt/0ufWGiQtY2rOA=; b=Il/sYtGI23hH8yL41ebNwJ37TcqULpATcjdn7NwW7F9LUDxEhcMY2khRV8rQ9sJWdz uQgOHKr5r3Bce0ARVFfLD/bF0w5hwHv29RXQ1++0nhbs/DqThc2WiW52J82D1FlC2+ki DxfsEeDqypMv0XM+YfWrCc1kth8xb7JKipiT8+FkktFPGsVoRlUIUm1kfqCV2c+6aDF8 337CI01pAMl950f04oAOo8jQtA9Z9fn+7h9jaw/4H5cmtqJi1VVBHIEClpJ/SruhPSBO J8dtMRdHOr8YQaGJEddUW6vCUh60UkD6A7rK2q6SkDQ+sndbcTq1q8z0A3krwoRqwKi8 aJfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Cwr1SnVs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f27-20020a170906049b00b007311b7d141dsi8126038eja.595.2022.08.15.14.23.45; Mon, 15 Aug 2022 14:24:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Cwr1SnVs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244646AbiHOVQj (ORCPT + 99 others); Mon, 15 Aug 2022 17:16:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348042AbiHOVIA (ORCPT ); Mon, 15 Aug 2022 17:08:00 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 165D43C8D8; Mon, 15 Aug 2022 12:18:03 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BD9A9B810C6; Mon, 15 Aug 2022 19:18:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21D4FC433C1; Mon, 15 Aug 2022 19:17:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660591080; bh=mhEgBORyV3PVFKJt5jhDc4jGPUxc6GqM6YMT/Qmh7G4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cwr1SnVsUckarkzKQAFCfHNbSMDzqrnyN34f9Y4MUpFv6JUcGxGY3ubG//gjpwgZ1 SFwqx/8gokSjXHatTaFuBSuyvMkXgWhxdVeW9MnIIfkHRKwuyUkacbwbMvnjskHOCT T8yfa4DrV2KOiDwaAsiZuwBQDXhK5VT6oOey9YAY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Benjamin Gaignard , Ezequiel Garcia , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 5.18 0435/1095] media: hantro: HEVC: Fix reference frames management Date: Mon, 15 Aug 2022 19:57:14 +0200 Message-Id: <20220815180447.674145076@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Benjamin Gaignard [ Upstream commit 387d1176956883635c63a7d1c91b1f45e19c1777 ] PoC shall be int the range of -2^31 to 2^31 -1 (HEVC spec section 8.3.1 Decoding process for picture order count). The current way to know if an entry in reference picture array is free is to test if PoC = UNUSED_REF. Since UNUSED_REF is defined as '-1' that could lead to decode issue if one PoC also equal '-1'. PoC with value = '-1' exists in conformance test SLIST_B_Sony_9. Change the way unused entries are managed in reference pictures array to avoid using PoC to detect then. This patch doesn't change fluster HEVC score. Signed-off-by: Benjamin Gaignard Reviewed-by: Ezequiel Garcia Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- .../staging/media/hantro/hantro_g2_hevc_dec.c | 4 +-- drivers/staging/media/hantro/hantro_hevc.c | 27 +++---------------- drivers/staging/media/hantro/hantro_hw.h | 2 +- 3 files changed, 5 insertions(+), 28 deletions(-) diff --git a/drivers/staging/media/hantro/hantro_g2_hevc_dec.c b/drivers/staging/media/hantro/hantro_g2_hevc_dec.c index 7c046d456038..5df6f08e26f5 100644 --- a/drivers/staging/media/hantro/hantro_g2_hevc_dec.c +++ b/drivers/staging/media/hantro/hantro_g2_hevc_dec.c @@ -415,7 +415,7 @@ static int set_ref(struct hantro_ctx *ctx) set_ref_pic_list(ctx); /* We will only keep the reference pictures that are still used */ - ctx->hevc_dec.ref_bufs_used = 0; + hantro_hevc_ref_init(ctx); /* Set up addresses of DPB buffers */ dpb_longterm_e = 0; @@ -456,8 +456,6 @@ static int set_ref(struct hantro_ctx *ctx) hantro_write_addr(vpu, G2_OUT_CHROMA_ADDR, chroma_addr); hantro_write_addr(vpu, G2_OUT_MV_ADDR, mv_addr); - hantro_hevc_ref_remove_unused(ctx); - for (; i < V4L2_HEVC_DPB_ENTRIES_NUM_MAX; i++) { hantro_write_addr(vpu, G2_REF_LUMA_ADDR(i), 0); hantro_write_addr(vpu, G2_REF_CHROMA_ADDR(i), 0); diff --git a/drivers/staging/media/hantro/hantro_hevc.c b/drivers/staging/media/hantro/hantro_hevc.c index b3a057beaf19..f86c98e19177 100644 --- a/drivers/staging/media/hantro/hantro_hevc.c +++ b/drivers/staging/media/hantro/hantro_hevc.c @@ -25,15 +25,11 @@ #define MAX_TILE_COLS 20 #define MAX_TILE_ROWS 22 -#define UNUSED_REF -1 - -static void hantro_hevc_ref_init(struct hantro_ctx *ctx) +void hantro_hevc_ref_init(struct hantro_ctx *ctx) { struct hantro_hevc_dec_hw_ctx *hevc_dec = &ctx->hevc_dec; - int i; - for (i = 0; i < NUM_REF_PICTURES; i++) - hevc_dec->ref_bufs_poc[i] = UNUSED_REF; + hevc_dec->ref_bufs_used = 0; } dma_addr_t hantro_hevc_get_ref_buf(struct hantro_ctx *ctx, @@ -60,7 +56,7 @@ int hantro_hevc_add_ref_buf(struct hantro_ctx *ctx, int poc, dma_addr_t addr) /* Add a new reference buffer */ for (i = 0; i < NUM_REF_PICTURES; i++) { - if (hevc_dec->ref_bufs_poc[i] == UNUSED_REF) { + if (!(hevc_dec->ref_bufs_used & 1 << i)) { hevc_dec->ref_bufs_used |= 1 << i; hevc_dec->ref_bufs_poc[i] = poc; hevc_dec->ref_bufs[i].dma = addr; @@ -71,23 +67,6 @@ int hantro_hevc_add_ref_buf(struct hantro_ctx *ctx, int poc, dma_addr_t addr) return -EINVAL; } -void hantro_hevc_ref_remove_unused(struct hantro_ctx *ctx) -{ - struct hantro_hevc_dec_hw_ctx *hevc_dec = &ctx->hevc_dec; - int i; - - /* Just tag buffer as unused, do not free them */ - for (i = 0; i < NUM_REF_PICTURES; i++) { - if (hevc_dec->ref_bufs_poc[i] == UNUSED_REF) - continue; - - if (hevc_dec->ref_bufs_used & (1 << i)) - continue; - - hevc_dec->ref_bufs_poc[i] = UNUSED_REF; - } -} - static int tile_buffer_reallocate(struct hantro_ctx *ctx) { struct hantro_dev *vpu = ctx->dev; diff --git a/drivers/staging/media/hantro/hantro_hw.h b/drivers/staging/media/hantro/hantro_hw.h index df142f31e31b..699c1efc0215 100644 --- a/drivers/staging/media/hantro/hantro_hw.h +++ b/drivers/staging/media/hantro/hantro_hw.h @@ -338,9 +338,9 @@ int hantro_hevc_dec_init(struct hantro_ctx *ctx); void hantro_hevc_dec_exit(struct hantro_ctx *ctx); int hantro_g2_hevc_dec_run(struct hantro_ctx *ctx); int hantro_hevc_dec_prepare_run(struct hantro_ctx *ctx); +void hantro_hevc_ref_init(struct hantro_ctx *ctx); dma_addr_t hantro_hevc_get_ref_buf(struct hantro_ctx *ctx, int poc); int hantro_hevc_add_ref_buf(struct hantro_ctx *ctx, int poc, dma_addr_t addr); -void hantro_hevc_ref_remove_unused(struct hantro_ctx *ctx); static inline unsigned short hantro_vp9_num_sbs(unsigned short dimension) { -- 2.35.1