From patchwork Fri May 22 20:21:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Karlman X-Patchwork-Id: 11566119 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 1C6C814B7 for ; Fri, 22 May 2020 20:21:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 85E0920723 for ; Fri, 22 May 2020 20:21:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FFgKlJdI"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kwiboo.se header.i=@kwiboo.se header.b="Kq7Xrgkr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 85E0920723 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kwiboo.se Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:To:Message-Id:Date: Subject:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=mPBHzk/EJ0nUm9+ytykkSzXslhYrWFK8883fzF/w7Qc=; b=FFgKlJdIiY0yAa se0TlXhPlxUPc9+MH0v5iaNsEroirrztWQ1FqVVb8HS38UQvBbcqtXAJIxW01Zan6l1UwPOY8M6Db RhBTd3WE6/Vjyjg9q9/rfskffRbhk0Fc8yjhS+XTQa9Z6uJl/bMGdOVVkPQiIfiHpKaTlEoXuQqMP rSZun1as/LBJFDcLQNNepjr1yff1c6U3lgDczwPdNcp5QovBzOVAUBL1wl6vSWmhfOoIB7CISV5Uv JkZwUApBdnjt9U9a97yCx4VExVOCpyPW9kA+Q8FZ1FfVkh5xC8tccIW9JNMxOqzskzrwcZoqLF4hd qbeQDW6VUnOrqQXqerYw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jcEAy-0002B8-1G; Fri, 22 May 2020 20:21:52 +0000 Received: from o1.b.az.sendgrid.net ([208.117.55.133]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jcEAv-0002Ab-PV for linux-rockchip@lists.infradead.org; Fri, 22 May 2020 20:21:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kwiboo.se; h=from:subject:to:cc:content-type:content-transfer-encoding; s=001; bh=PatGu4e0L35jex+C17yq0C5gkVs5IsVrc2a8WfW6a+Q=; b=Kq7XrgkrQXfTp8d3NfcfqBHPPcsYZoGG6DV9+vp3A1z2aChdHci6ICW12C0aNprkdGIq LiWfnM8BP+kz1Bz71QZiHcKBY9Mv4KyN/6Q0YMg86Q2+gNllk5RUcuKOTBVzKBNTthHasM lu9KmMuyj45RhNBXATdnbXf8LRBNedfrM= Received: by filterdrecv-p3mdw1-6dbfd75bfd-t2sth with SMTP id filterdrecv-p3mdw1-6dbfd75bfd-t2sth-19-5EC8344D-9 2020-05-22 20:21:33.151143666 +0000 UTC m=+4994047.240839536 Received: from bionic.localdomain (unknown) by ismtpd0006p1lon1.sendgrid.net (SG) with ESMTP id l_Bd5uXtT7eVIJYpo_gFxw Fri, 22 May 2020 20:21:32.847 +0000 (UTC) From: Jonas Karlman Subject: [PATCH] media: rkvdec: Fix H264 scaling list order Date: Fri, 22 May 2020 20:21:33 +0000 (UTC) Message-Id: <20200522202130.13306-1-jonas@kwiboo.se> X-Mailer: git-send-email 2.17.1 X-SG-EID: TdbjyGynYnRZWhH+7lKUQJL+ZxmxpowvO2O9SQF5CwCVrYgcwUXgU5DKUU3QxAfZekEeQsTe+RrMu3cja6a0hwUhGxDi/yRArtKnhioanv+vIiE7e1ehouOJbeenmjctoBV51SaPnRLiVPL0eGyd9ilFVNczc/0T5Re/HKGEoX0J/Y582OewvbO8f2G3yVnZZUj/A6iYcrha3KrpfpNOQfJbk7BLnqg4LtqawW4AZ2Qi2EDAT6UDJNAQyerW0C0uJjAEC5L9BpFoVHS3QI5ohw== To: Ezequiel Garcia , Hans Verkuil , Mauro Carvalho Chehab X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200522_132149_877996_AC25BF1F X-CRM114-Status: GOOD ( 10.74 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [208.117.55.133 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [208.117.55.133 listed in wl.mailspike.net] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jonas Karlman , linux-kernel@vger.kernel.org, Tomasz Figa , linux-rockchip@lists.infradead.org, Boris Brezillon , Nicolas Dufresne , linux-media@vger.kernel.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org The Rockchip Video Decoder driver is expecting that the values in a scaling list are in zig-zag order and applies the inverse scanning process to get the values in matrix order. Commit 0b0393d59eb4 ("media: uapi: h264: clarify expected scaling_list_4x4/8x8 order") clarified that the values in the scaling list should already be in matrix order. Fix this by removing the reordering and change to use two memcpy. Fixes: cd33c830448b ("media: rkvdec: Add the rkvdec driver") Signed-off-by: Jonas Karlman Tested-by: Nicolas Dufresne Reviewed-by: Ezequiel Garcia --- drivers/staging/media/rkvdec/rkvdec-h264.c | 70 +++++++--------------- 1 file changed, 22 insertions(+), 48 deletions(-) diff --git a/drivers/staging/media/rkvdec/rkvdec-h264.c b/drivers/staging/media/rkvdec/rkvdec-h264.c index cd4980d06be7..2719f0c66a4a 100644 --- a/drivers/staging/media/rkvdec/rkvdec-h264.c +++ b/drivers/staging/media/rkvdec/rkvdec-h264.c @@ -18,11 +18,16 @@ /* Size with u32 units. */ #define RKV_CABAC_INIT_BUFFER_SIZE (3680 + 128) #define RKV_RPS_SIZE ((128 + 128) / 4) -#define RKV_SCALING_LIST_SIZE (6 * 16 + 6 * 64 + 128) #define RKV_ERROR_INFO_SIZE (256 * 144 * 4) #define RKVDEC_NUM_REFLIST 3 +struct rkvdec_scaling_matrix { + u8 scaling_list_4x4[6][16]; + u8 scaling_list_8x8[6][64]; + u8 padding[128]; +}; + struct rkvdec_sps_pps_packet { u32 info[8]; }; @@ -86,7 +91,7 @@ struct rkvdec_ps_field { /* Data structure describing auxiliary buffer format. */ struct rkvdec_h264_priv_tbl { s8 cabac_table[4][464][2]; - u8 scaling_list[RKV_SCALING_LIST_SIZE]; + struct rkvdec_scaling_matrix scaling_list; u32 rps[RKV_RPS_SIZE]; struct rkvdec_sps_pps_packet param_set[256]; u8 err_info[RKV_ERROR_INFO_SIZE]; @@ -785,56 +790,25 @@ static void assemble_hw_rps(struct rkvdec_ctx *ctx, } } -/* - * NOTE: The values in a scaling list are in zig-zag order, apply inverse - * scanning process to get the values in matrix order. - */ -static const u32 zig_zag_4x4[16] = { - 0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15 -}; - -static const u32 zig_zag_8x8[64] = { - 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, - 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, - 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51, - 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63 -}; - -static void reorder_scaling_list(struct rkvdec_ctx *ctx, - struct rkvdec_h264_run *run) +static void assemble_hw_scaling_list(struct rkvdec_ctx *ctx, + struct rkvdec_h264_run *run) { const struct v4l2_ctrl_h264_scaling_matrix *scaling = run->scaling_matrix; - const size_t num_list_4x4 = ARRAY_SIZE(scaling->scaling_list_4x4); - const size_t list_len_4x4 = ARRAY_SIZE(scaling->scaling_list_4x4[0]); - const size_t num_list_8x8 = ARRAY_SIZE(scaling->scaling_list_8x8); - const size_t list_len_8x8 = ARRAY_SIZE(scaling->scaling_list_8x8[0]); struct rkvdec_h264_ctx *h264_ctx = ctx->priv; struct rkvdec_h264_priv_tbl *tbl = h264_ctx->priv_tbl.cpu; - u8 *dst = tbl->scaling_list; - const u8 *src; - int i, j; - - BUILD_BUG_ON(ARRAY_SIZE(zig_zag_4x4) != list_len_4x4); - BUILD_BUG_ON(ARRAY_SIZE(zig_zag_8x8) != list_len_8x8); - BUILD_BUG_ON(ARRAY_SIZE(tbl->scaling_list) < - num_list_4x4 * list_len_4x4 + - num_list_8x8 * list_len_8x8); - - src = &scaling->scaling_list_4x4[0][0]; - for (i = 0; i < num_list_4x4; ++i) { - for (j = 0; j < list_len_4x4; ++j) - dst[zig_zag_4x4[j]] = src[j]; - src += list_len_4x4; - dst += list_len_4x4; - } - src = &scaling->scaling_list_8x8[0][0]; - for (i = 0; i < num_list_8x8; ++i) { - for (j = 0; j < list_len_8x8; ++j) - dst[zig_zag_8x8[j]] = src[j]; - src += list_len_8x8; - dst += list_len_8x8; - } + BUILD_BUG_ON(sizeof(tbl->scaling_list.scaling_list_4x4) != + sizeof(scaling->scaling_list_4x4)); + BUILD_BUG_ON(sizeof(tbl->scaling_list.scaling_list_8x8) != + sizeof(scaling->scaling_list_8x8)); + + memcpy(tbl->scaling_list.scaling_list_4x4, + scaling->scaling_list_4x4, + sizeof(scaling->scaling_list_4x4)); + + memcpy(tbl->scaling_list.scaling_list_8x8, + scaling->scaling_list_8x8, + sizeof(scaling->scaling_list_8x8)); } /* @@ -1126,7 +1100,7 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx) v4l2_h264_build_b_ref_lists(&reflist_builder, h264_ctx->reflists.b0, h264_ctx->reflists.b1); - reorder_scaling_list(ctx, &run); + assemble_hw_scaling_list(ctx, &run); assemble_hw_pps(ctx, &run); assemble_hw_rps(ctx, &run); config_registers(ctx, &run);