From patchwork Mon Sep 20 17:04:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 12506209 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9D85C433F5 for ; Mon, 20 Sep 2021 18:51:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD37F61213 for ; Mon, 20 Sep 2021 18:51:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353829AbhITSwd (ORCPT ); Mon, 20 Sep 2021 14:52:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385494AbhITSu3 (ORCPT ); Mon, 20 Sep 2021 14:50:29 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3043C0A8888; Mon, 20 Sep 2021 10:04:23 -0700 (PDT) Received: from guri.fritz.box (unknown [IPv6:2a02:810a:880:f54:34ca:272f:b5af:bab9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: dafna) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 914251F42EBB; Mon, 20 Sep 2021 18:04:21 +0100 (BST) From: Dafna Hirschfeld To: linux-media@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alexandre Courbot , dafna.hirschfeld@collabora.com, kernel@collabora.com, Enric Balletbo i Serra , dafna3@gmail.com, tiffany.lin@mediatek.com, andrew-ct.chen@mediatek.com, minghsiu.tsai@mediatek.com, houlong.wei@mediatek.com, mchehab@kernel.org, matthias.bgg@gmail.com, hverkuil@xs4all.nl Subject: [PATCH v4] media: mtk-vpu: Ensure alignment of 8 for DTCM buffer Date: Mon, 20 Sep 2021 19:04:08 +0200 Message-Id: <20210920170408.1561-1-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Alexandre Courbot When running memcpy_toio: memcpy_toio(send_obj->share_buf, buf, len); it was found that errors appear if len is not a multiple of 8: [58.350841] mtk-mdp 14001000.rdma: processing failed: -22 This patch ensures the copy of a multiple of 8 size by calling round_up(len, 8) when copying Fixes: e6599adfad30 ("media: mtk-vpu: avoid unaligned access to DTCM buffer.") Signed-off-by: Alexandre Courbot Signed-off-by: Enric Balletbo i Serra Signed-off-by: Dafna Hirschfeld Reviewed-by: Houlong Wei Reviewed-by: AngeloGioacchino Del Regno --- changes since v3: 1. multile -> multiple 2. add inline doc changes since v2: 1. do the extra copy only if len is not multiple of 8 changes since v1: 1. change sign-off-by tags 2. change values to memset drivers/media/platform/mtk-vpu/mtk_vpu.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/mtk-vpu/mtk_vpu.c b/drivers/media/platform/mtk-vpu/mtk_vpu.c index ec290dde59cf..1df031716c8f 100644 --- a/drivers/media/platform/mtk-vpu/mtk_vpu.c +++ b/drivers/media/platform/mtk-vpu/mtk_vpu.c @@ -349,7 +349,20 @@ int vpu_ipi_send(struct platform_device *pdev, } } while (vpu_cfg_readl(vpu, HOST_TO_VPU)); - memcpy_toio(send_obj->share_buf, buf, len); + /* + * when copying data to the vpu hardware, the memcpy_toio operation must copy + * a multiple of 8. Otherwise the processing fails + */ + if (len % 8 != 0) { + unsigned char data[SHARE_BUF_SIZE]; + + memset(data + len, 0, sizeof(data) - len); + memcpy(data, buf, len); + memcpy_toio(send_obj->share_buf, data, round_up(len, 8)); + } else { + memcpy_toio(send_obj->share_buf, buf, len); + } + writel(len, &send_obj->len); writel(id, &send_obj->id);