From patchwork Thu Jun 3 05:35:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chen Li X-Patchwork-Id: 12296497 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=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 700B0C47096 for ; Thu, 3 Jun 2021 07:35:26 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 E8D49613D6 for ; Thu, 3 Jun 2021 07:35:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E8D49613D6 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=uniontech.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9086D6F40F; Thu, 3 Jun 2021 07:35:21 +0000 (UTC) X-Greylist: delayed 415 seconds by postgrey-1.36 at gabe; Thu, 03 Jun 2021 05:42:03 UTC Received: from lucky1.263xmail.com (lucky1.263xmail.com [211.157.147.132]) by gabe.freedesktop.org (Postfix) with ESMTPS id E9FBD6E0A8; Thu, 3 Jun 2021 05:42:03 +0000 (UTC) Received: from localhost (unknown [192.168.167.235]) by lucky1.263xmail.com (Postfix) with ESMTP id 557A5F4A65; Thu, 3 Jun 2021 13:35:03 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-SKE-CHECKED: 0 X-ANTISPAM-LEVEL: 2 X-ABS-CHECKED: 0 Received: from manjaro.uniontech.com (unknown [58.246.122.242]) by smtp.263.net (postfix) whith ESMTP id P31747T140095311525632S1622698503302937_; Thu, 03 Jun 2021 13:35:03 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: <7f511b6a22986db5f8114fb85f19d034> X-RL-SENDER: chenli@uniontech.com X-SENDER: chenli@uniontech.com X-LOGIN-NAME: chenli@uniontech.com X-FST-TO: alexander.deucher@amd.com X-RCPT-COUNT: 4 X-SENDER-IP: 58.246.122.242 X-ATTACHMENT-NUM: 0 X-System-Flag: 0 Date: Thu, 03 Jun 2021 13:35:03 +0800 Message-ID: <87o8cnfr3s.wl-chenli@uniontech.com> From: Chen Li To: Alex Deucher , =?iso-8859-1?q?=22Christian_K?= =?iso-8859-1?q?=F6nig=22?= , dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Subject: [PATCH] radeon: use memcpy_to/fromio for UVD fw upload User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?iso-8859-4?q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-Mailman-Approved-At: Thu, 03 Jun 2021 07:35:20 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" I met a gpu addr bug recently and the kernel log tells me the pc is memcpy/memset and link register is radeon_uvd_resume. As we know, in some architectures, optimized memcpy/memset may not work well on device memory. Trival memcpy_toio/memset_io can fix this problem. BTW, amdgpu has already done it in: commit ba0b2275a678 ("drm/amdgpu: use memcpy_to/fromio for UVD fw upload"), that's why it has no this issue on the same gpu and platform. Also fix some coding issues reported from sparse. Signed-off-by: Chen Li Acked-by: Christian König Reviewed-by: Christian König --- drivers/gpu/drm/radeon/radeon_uvd.c | 30 ++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/radeon/radeon_uvd.c b/drivers/gpu/drm/radeon/radeon_uvd.c index dfa9fdbe98da..0d6a5cfa2abf 100644 --- a/drivers/gpu/drm/radeon/radeon_uvd.c +++ b/drivers/gpu/drm/radeon/radeon_uvd.c @@ -152,9 +152,11 @@ int radeon_uvd_init(struct radeon_device *rdev) rdev->uvd.fw_header_present = true; - family_id = le32_to_cpu(hdr->ucode_version) & 0xff; - version_major = (le32_to_cpu(hdr->ucode_version) >> 24) & 0xff; - version_minor = (le32_to_cpu(hdr->ucode_version) >> 8) & 0xff; + family_id = (__force u32)(hdr->ucode_version) & 0xff; + version_major = (le32_to_cpu((__force __le32)(hdr->ucode_version)) + >> 24) & 0xff; + version_minor = (le32_to_cpu((__force __le32)(hdr->ucode_version)) + >> 8) & 0xff; DRM_INFO("Found UVD firmware Version: %u.%u Family ID: %u\n", version_major, version_minor, family_id); @@ -286,7 +288,9 @@ int radeon_uvd_resume(struct radeon_device *rdev) if (rdev->uvd.vcpu_bo == NULL) return -EINVAL; - memcpy(rdev->uvd.cpu_addr, rdev->uvd_fw->data, rdev->uvd_fw->size); + memcpy_toio((void __iomem *)rdev->uvd.cpu_addr, + rdev->uvd_fw->data, + le32_to_cpu((__force __le32)rdev->uvd_fw->size)); size = radeon_bo_size(rdev->uvd.vcpu_bo); size -= rdev->uvd_fw->size; @@ -294,7 +298,7 @@ int radeon_uvd_resume(struct radeon_device *rdev) ptr = rdev->uvd.cpu_addr; ptr += rdev->uvd_fw->size; - memset(ptr, 0, size); + memset_io((void __iomem *)ptr, 0, size); return 0; } @@ -791,17 +795,17 @@ int radeon_uvd_get_create_msg(struct radeon_device *rdev, int ring, return r; /* stitch together an UVD create msg */ - writel(cpu_to_le32(0x00000de4), &msg[0]); + writel((__force u32)cpu_to_le32(0x00000de4), &msg[0]); writel(0x0, (void __iomem *)&msg[1]); - writel(cpu_to_le32(handle), &msg[2]); + writel((__force u32)cpu_to_le32(handle), &msg[2]); writel(0x0, &msg[3]); writel(0x0, &msg[4]); writel(0x0, &msg[5]); writel(0x0, &msg[6]); - writel(cpu_to_le32(0x00000780), &msg[7]); - writel(cpu_to_le32(0x00000440), &msg[8]); + writel((__force u32)cpu_to_le32(0x00000780), &msg[7]); + writel((__force u32)cpu_to_le32(0x00000440), &msg[8]); writel(0x0, &msg[9]); - writel(cpu_to_le32(0x01b37000), &msg[10]); + writel((__force u32)cpu_to_le32(0x01b37000), &msg[10]); for (i = 11; i < 1024; ++i) writel(0x0, &msg[i]); @@ -827,9 +831,9 @@ int radeon_uvd_get_destroy_msg(struct radeon_device *rdev, int ring, return r; /* stitch together an UVD destroy msg */ - writel(cpu_to_le32(0x00000de4), &msg[0]); - writel(cpu_to_le32(0x00000002), &msg[1]); - writel(cpu_to_le32(handle), &msg[2]); + writel((__force u32)cpu_to_le32(0x00000de4), &msg[0]); + writel((__force u32)cpu_to_le32(0x00000002), &msg[1]); + writel((__force u32)cpu_to_le32(handle), &msg[2]); writel(0x0, &msg[3]); for (i = 4; i < 1024; ++i) writel(0x0, &msg[i]); From patchwork Fri Jun 4 03:04:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Li X-Patchwork-Id: 12299015 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=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 25C20C47083 for ; Fri, 4 Jun 2021 07:24:07 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 9F63E61417 for ; Fri, 4 Jun 2021 07:24:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9F63E61417 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=uniontech.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3C08F6F5B6; Fri, 4 Jun 2021 07:24:03 +0000 (UTC) Received: from smtphy.263.net (sg-smtp01.263.net [54.255.195.220]) by gabe.freedesktop.org (Postfix) with ESMTPS id C536B6F570; Fri, 4 Jun 2021 03:11:11 +0000 (UTC) Received: from smtp.263.net (unknown [211.157.147.163]) by smtphy.263.net (Postfix) with ESMTPS id 4C9C5134; Fri, 4 Jun 2021 11:04:43 +0800 (CST) Received: from regular1.263xmail.com (unknown [192.168.165.183]) by smtp.263.net (Postfix) with ESMTP id 58A602A9; Fri, 4 Jun 2021 11:04:40 +0800 (CST) Received: from localhost (unknown [192.168.167.235]) by regular1.263xmail.com (Postfix) with ESMTP id 45948807; Fri, 4 Jun 2021 11:04:37 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-ANTISPAM-LEVEL: 2 X-SKE-CHECKED: 1 X-ABS-CHECKED: 1 Received: from manjaro.uniontech.com (unknown [58.246.122.242]) by smtp.263.net (postfix) whith ESMTP id P31747T140094946129664S1622775876983625_; Fri, 04 Jun 2021 11:04:37 +0800 (CST) X-IP-DOMAINF: 1 X-UNIQUE-TAG: X-RL-SENDER: chenli@uniontech.com X-SENDER: chenli@uniontech.com X-LOGIN-NAME: chenli@uniontech.com X-FST-TO: alexander.deucher@amd.com X-RCPT-COUNT: 4 X-SENDER-IP: 58.246.122.242 X-ATTACHMENT-NUM: 0 X-System-Flag: 0 Date: Fri, 04 Jun 2021 11:04:36 +0800 Message-ID: <87im2ufhyz.wl-chenli@uniontech.com> From: Chen Li To: Alex Deucher , =?iso-8859-1?q?=22Christian_K?= =?iso-8859-1?q?=F6nig=22?= , dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Subject: [PATCH v2 2/2] radeon: use memcpy_to/fromio for UVD fw upload In-Reply-To: <87o8cnfr3s.wl-chenli@uniontech.com> References: <87o8cnfr3s.wl-chenli@uniontech.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?iso-8859-4?q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-Mailman-Approved-At: Fri, 04 Jun 2021 07:24:01 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" I met a gpu addr bug recently and the kernel log tells me the pc is memcpy/memset and link register is radeon_uvd_resume. As we know, in some architectures, optimized memcpy/memset may not work well on device memory. Trival memcpy_toio/memset_io can fix this problem. BTW, amdgpu has already done it in: commit ba0b2275a678 ("drm/amdgpu: use memcpy_to/fromio for UVD fw upload"), that's why it has no this issue on the same gpu and platform. Signed-off-by: Chen Li --- drivers/gpu/drm/radeon/radeon_uvd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/radeon/radeon_uvd.c b/drivers/gpu/drm/radeon/radeon_uvd.c index 85a1f2c31749..0d6a5cfa2abf 100644 --- a/drivers/gpu/drm/radeon/radeon_uvd.c +++ b/drivers/gpu/drm/radeon/radeon_uvd.c @@ -288,7 +288,9 @@ int radeon_uvd_resume(struct radeon_device *rdev) if (rdev->uvd.vcpu_bo == NULL) return -EINVAL; - memcpy(rdev->uvd.cpu_addr, rdev->uvd_fw->data, rdev->uvd_fw->size); + memcpy_toio((void __iomem *)rdev->uvd.cpu_addr, + rdev->uvd_fw->data, + le32_to_cpu((__force __le32)rdev->uvd_fw->size)); size = radeon_bo_size(rdev->uvd.vcpu_bo); size -= rdev->uvd_fw->size; @@ -296,7 +298,7 @@ int radeon_uvd_resume(struct radeon_device *rdev) ptr = rdev->uvd.cpu_addr; ptr += rdev->uvd_fw->size; - memset(ptr, 0, size); + memset_io((void __iomem *)ptr, 0, size); return 0; }