From patchwork Mon Oct 17 19:44:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jernej_=C5=A0krabec?= X-Patchwork-Id: 13009382 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 46DB7C433FE for ; Mon, 17 Oct 2022 19:45:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To: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=RCmHtYKVDxnAGvuqX76y+F8x0mW8oFPwMltilLHDBDA=; b=Tspd/dPAv0Tdi+ KYnyzi7J05aNgEHHnAHlBJGoLMJD1h+KbRCqnjJuTECVpXvEmjSC6Re/T2aAGt96u/aFallNrCTQN rCx91+hg9uZIx+XO2iz7/rjbKi6f/u9aE4fnMpUmYYu++HWRInt7WlRmrPoFMKssIDOQWDNcGqiiI pX84p7nat6EnWreDH1z5ykNqrEpKbigJTUh8QksBsnvCG5BSYk8WLbZeL+0OA2/ZdrI6CFQNWd1Xq snCOtMr/OWmcUOlkE/4q/8VQiNBNNJ1y1czoNeX0eYITdLQkQCD9pa3DYW6XHHqSJBmdDySKD+fRX e6OAjTW892WdVmitx03g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1okW2Y-00Eacq-V6; Mon, 17 Oct 2022 19:44:47 +0000 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1okW2W-00Eaau-HZ for linux-arm-kernel@lists.infradead.org; Mon, 17 Oct 2022 19:44:45 +0000 Received: by mail-ej1-x632.google.com with SMTP id fy4so27310492ejc.5 for ; Mon, 17 Oct 2022 12:44:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TATHs2k56ufe8lMmyZToJvN32Rg6lEJir/LHJFUdZoQ=; b=N3sgwEdi/Li9SwIj/vg8LX7AlvncoeCI/CvSob3JryDoMtcajL9Cd/gfa/CHNCK3V2 /+e09Gsxp9TYe/Um/zGAOSjHpKWWCn705BM0SuiF2d2RfEM9Uemyj3dh+G/l+9fYWOGG bkL8KJH3p/ZHIb5bJL5DAg4abHZX86DtWHAuiKneynkSRDr/Ct0vEUIFnNEwU0p8Vp9U HVCjMCoBZqky86jWTElx7jHZgqj/cQNDLZpTU3QL91+EKAspLGMdmatW3Ef6ndE7xkWM Ili2sXBR2M8G/TbUFT8qf0GArmRWYYC24xWAucLpcMA3BVA6z7pZTy7ZMoXJfrXfc4P3 vODg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TATHs2k56ufe8lMmyZToJvN32Rg6lEJir/LHJFUdZoQ=; b=VpK94XAw/OtmAjaD+4L+6toytGDsUZuBEcqPEuEn7G762MiF8qrs4hyafU5D3/CFFC 80JTwLRZPMw+VuKTPJ9xtUTaJkpZz9CXPOW1qAfLfuXllEOMkZt2ZscijcK4AIiFNUlw /+HyEMEuGbHGyyg+NlTtl0I57huYKpF35VBNHjEmjQU2SmGkxepc53KB/VdL48674OXN jDaZEoCamf25VIHQ36X+D3g8V4oLzwnvJ3ciYpqs8Xk2vjT0IOMGyDYmzH3th7GitEYe nnM3jSTRBvBKjvT/86nLc/Plf8x4jrePodSor2bZrI5rzkGxaNvxgKXEdY78mIEFy9Ul 92TA== X-Gm-Message-State: ACrzQf2mMAFMT/pkGaaHMFSgZ3E+QOAB/9b1awnaU0ODuhTVfiacHEIv sgufGSPZBUyKxc9blyOjudI= X-Google-Smtp-Source: AMsMyM6VFvvFARE0TYh11hDuODd833Jng1g6K9nzB2kniIQ47qpcVhXiqYHDBu0L24rK8hkcGYdGJg== X-Received: by 2002:a17:907:1ded:b0:78d:4606:268 with SMTP id og45-20020a1709071ded00b0078d46060268mr10090820ejc.163.1666035881499; Mon, 17 Oct 2022 12:44:41 -0700 (PDT) Received: from kista.localdomain (82-149-19-102.dynamic.telemach.net. [82.149.19.102]) by smtp.gmail.com with ESMTPSA id z5-20020a17090665c500b0078d9c2c8250sm6588957ejn.84.2022.10.17.12.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 12:44:40 -0700 (PDT) From: Jernej Skrabec To: mripard@kernel.org, paul.kocialkowski@bootlin.com Cc: mchehab@kernel.org, gregkh@linuxfoundation.org, wens@csie.org, samuel@sholland.org, hverkuil-cisco@xs4all.nl, linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Jernej Skrabec Subject: [PATCH] media: cedrus: hevc: Fix offset adjustments Date: Mon, 17 Oct 2022 21:44:13 +0200 Message-Id: <20221017194413.1198301-1-jernej.skrabec@gmail.com> X-Mailer: git-send-email 2.38.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221017_124444_601372_BDBBF69F X-CRM114-Status: GOOD ( 14.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org As it turns out, current padding size check works fine in theory but it doesn't in practice. Most probable reason are caching issues. Let's rework reading data from bitstream using Cedrus engine instead of CPU. That way we avoid all cache issues and make sure that we're reading same data as Cedrus. Fixes: e7060d9a78c2 ("media: uapi: Change data_bit_offset definition") Signed-off-by: Jernej Skrabec --- .../staging/media/sunxi/cedrus/cedrus_h265.c | 25 ++++++++++++++----- .../staging/media/sunxi/cedrus/cedrus_regs.h | 2 ++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c index 687f87598f78..d3a29359a5a2 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c @@ -241,6 +241,18 @@ static void cedrus_h265_skip_bits(struct cedrus_dev *dev, int num) } } +static u32 cedrus_h265_show_bits(struct cedrus_dev *dev, int num) +{ + cedrus_write(dev, VE_DEC_H265_TRIGGER, + VE_DEC_H265_TRIGGER_SHOW_BITS | + VE_DEC_H265_TRIGGER_TYPE_N_BITS(num)); + + cedrus_wait_for(dev, VE_DEC_H265_STATUS, + VE_DEC_H265_STATUS_VLD_BUSY); + + return cedrus_read(dev, VE_DEC_H265_BITS_READ); +} + static void cedrus_h265_write_scaling_list(struct cedrus_ctx *ctx, struct cedrus_run *run) { @@ -405,7 +417,7 @@ static int cedrus_h265_setup(struct cedrus_ctx *ctx, struct cedrus_run *run) u32 num_entry_point_offsets; u32 output_pic_list_index; u32 pic_order_cnt[2]; - u8 *padding; + u8 padding; int count; u32 reg; @@ -519,21 +531,22 @@ static int cedrus_h265_setup(struct cedrus_ctx *ctx, struct cedrus_run *run) if (slice_params->data_byte_offset == 0) return -EOPNOTSUPP; - padding = (u8 *)vb2_plane_vaddr(&run->src->vb2_buf, 0) + - slice_params->data_byte_offset - 1; + cedrus_h265_skip_bits(dev, (slice_params->data_byte_offset - 1) * 8); + + padding = cedrus_h265_show_bits(dev, 8); /* at least one bit must be set in that byte */ - if (*padding == 0) + if (padding == 0) return -EINVAL; for (count = 0; count < 8; count++) - if (*padding & (1 << count)) + if (padding & (1 << count)) break; /* Include the one bit. */ count++; - cedrus_h265_skip_bits(dev, slice_params->data_byte_offset * 8 - count); + cedrus_h265_skip_bits(dev, 8 - count); /* Bitstream parameters. */ diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_regs.h b/drivers/staging/media/sunxi/cedrus/cedrus_regs.h index d81f7513ade0..655c05b389cf 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_regs.h +++ b/drivers/staging/media/sunxi/cedrus/cedrus_regs.h @@ -505,6 +505,8 @@ #define VE_DEC_H265_LOW_ADDR_ENTRY_POINTS_BUF(a) \ SHIFT_AND_MASK_BITS(a, 7, 0) +#define VE_DEC_H265_BITS_READ (VE_ENGINE_DEC_H265 + 0xdc) + #define VE_DEC_H265_SRAM_OFFSET (VE_ENGINE_DEC_H265 + 0xe0) #define VE_DEC_H265_SRAM_OFFSET_PRED_WEIGHT_LUMA_L0 0x00