From nobody Thu Nov 14 05:55:17 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7484DEB64DC for ; Tue, 4 Jul 2023 01:51:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231317AbjGDBv4 (ORCPT ); Mon, 3 Jul 2023 21:51:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229897AbjGDBvy (ORCPT ); Mon, 3 Jul 2023 21:51:54 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52982E4E; Mon, 3 Jul 2023 18:51:47 -0700 (PDT) X-UUID: 518017aa1a0d11eeb20a276fd37b9834-20230704 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=IPhmurxIVo/R0GRBWKcyDnc4vP2+DDeDn+FJPxUQvro=; b=Lo7Fp9YJzKNU2+IXARn4LoFOyys4yb1J2oHaH6pfqGYuDdJoxqGNs5jzVQ7xJNfXLAY5PM3X/U9oTTsIfqmjTJITfTS8vAd7RIdokERzO7I8I+hQUadLOcE/lQ5mEFupZB/vfRQMJEGBH+UIavVGLkX5Xr6c8GoKyeWfFaN2DHA=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.27,REQID:5f027663-c10e-461a-be6c-0c33f285a6fb,IP:0,U RL:0,TC:0,Content:-5,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:01c9525,CLOUDID:3da8d20d-c22b-45ab-8a43-3004e9216b56,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:11|1,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR: NO X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULN X-UUID: 518017aa1a0d11eeb20a276fd37b9834-20230704 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1497641359; Tue, 04 Jul 2023 09:51:39 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Tue, 4 Jul 2023 09:51:38 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Tue, 4 Jul 2023 09:51:37 +0800 From: Xiaoyong Lu To: Yunfei Dong , Alexandre Courbot , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Tiffany Lin , Andrew-CT Chen , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Tomasz Figa CC: George Sun , Xiaoyong Lu , Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , dri-devel , Irui Wang , Steve Cho , , , , , , Subject: [v2] media: mediatek: vcodec: fix AV1 decode fail for 36bit iova Date: Tue, 4 Jul 2023 09:51:35 +0800 Message-ID: <20230704015135.31850-1-xiaoyong.lu@mediatek.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Fix av1 decode fail when iova is 36bit. Decoder hardware will access incorrect iova address when tile buffer is 36bit, it will lead to iommu fault when hardware access dram data. Fixes: 2f5d0aef37c6 ("media: mediatek: vcodec: support stateless AV1 decode= r") Signed-off-by: Xiaoyong Lu Reviewed-by: Nicolas Dufresne --- Changes from v1 - prefer '|' rather than '+' - prefer '&' rather than shift operation - add comments for address operations v1: - VDEC HW can access tile buffer and decode normally. - Test ok by mt8195 32bit and mt8188 36bit iova. --- .../mediatek/vcodec/vdec/vdec_av1_req_lat_if.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_i= f.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c index 404a1a23fd402..e9f2393f6a883 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c +++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c @@ -1658,9 +1658,9 @@ static void vdec_av1_slice_setup_tile_buffer(struct v= dec_av1_slice_instance *ins u32 allow_update_cdf =3D 0; u32 sb_boundary_x_m1 =3D 0, sb_boundary_y_m1 =3D 0; int tile_info_base; - u32 tile_buf_pa; + u64 tile_buf_pa; u32 *tile_info_buf =3D instance->tile.va; - u32 pa =3D (u32)bs->dma_addr; + u64 pa =3D (u64)bs->dma_addr; =20 if (uh->disable_cdf_update =3D=3D 0) allow_update_cdf =3D 1; @@ -1673,8 +1673,12 @@ static void vdec_av1_slice_setup_tile_buffer(struct = vdec_av1_slice_instance *ins tile_info_buf[tile_info_base + 0] =3D (tile_group->tile_size[tile_num] <= < 3); tile_buf_pa =3D pa + tile_group->tile_start_offset[tile_num]; =20 - tile_info_buf[tile_info_base + 1] =3D (tile_buf_pa >> 4) << 4; - tile_info_buf[tile_info_base + 2] =3D (tile_buf_pa % 16) << 3; + /* save av1 tile high 4bits(bit 32-35) address in lower 4 bits position + * and clear original for hw requirement. + */ + tile_info_buf[tile_info_base + 1] =3D (tile_buf_pa & 0xFFFFFFF0ull) | + ((tile_buf_pa & 0xF00000000ull) >> 32); + tile_info_buf[tile_info_base + 2] =3D (tile_buf_pa & 0xFull) << 3; =20 sb_boundary_x_m1 =3D (tile->mi_col_starts[tile_col + 1] - tile->mi_col_starts[tile_col] - 1)= & --=20 2.18.0