Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp473014imu; Tue, 20 Nov 2018 02:05:41 -0800 (PST) X-Google-Smtp-Source: AJdET5fCzJTlG2Kgu66W2Bkr7NXhspSy18pk4p35DWp9FPgnaTWRVX8xzgjZ0LZqlPoP6OcrDDkN X-Received: by 2002:a62:8893:: with SMTP id l141mr1490961pfd.1.1542708341086; Tue, 20 Nov 2018 02:05:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542708341; cv=none; d=google.com; s=arc-20160816; b=MvlJl73+UE3lY16Qtwza86wz4QhumVdbqbsgYsiHIuG7jIZ2PLx8+Qt5+Xv6xvRUR6 e+GdXr+0//EvYtWouRx7Bwy6FXtYo1RGUzviquLXhlqbA0Ob1apzsUtxn2ubz3+2suA1 RSYBHVTWz/4JFk9aFmr6W/50F7MjzNOOrJ6H9mUOH7F8yCKpe85i9UZwFkLEROqubqHO WrWEj8jOTd8lkZxYFD1YgQu3XrGd2N9lFgbuv93EI3j6C2C5NmSLr/q9YhSuF2jNOGb2 rb5JkNN6EOXOJkFBA3yxQwpWJQ1ZaI3tqB3seczB7q4KhCt02LpcEF9bAflc0IdXl4SF yFZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature:dkim-signature; bh=7MJt5oRKYTx7sL2UTXb6ivYQoHSTGKkpKGXjCPHeMFo=; b=FQgKrgO1syp9jFBmtb8cY6boOyTwRD6zMqj+iksSiPdPrCAjJz/RjLYKf+50NuJco7 2KapIJr22ZsIJdcAMLK4rN/NyDQPPLsrKZXg78w7bMiT9cHC+IxrzVHXaCwGAl5LdJOl 1jwe0QoVuS1WaaxZyoc0iZhAIxPZPJNpT84YYUxvsc+LPhYNMw+50HO2ndQxDKkoiUPp WxHgZ+iaiSPgev6Nejl0xtoLwMvPWV77QhSTz2PxbQaVFGWxrqi0SISE/zCZjjUhM1JX MlQSOOQ/E/ydnSzHjHyGkbTD8t0mLyOoG+iMB3m2LF4YyyvWgI5xwUi0Ox6NSS62EcqU riYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=d7lOWIXJ; dkim=pass header.i=@codeaurora.org header.s=default header.b=aX5BEFpf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r12si42545632pgf.22.2018.11.20.02.05.25; Tue, 20 Nov 2018 02:05:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=d7lOWIXJ; dkim=pass header.i=@codeaurora.org header.s=default header.b=aX5BEFpf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728076AbeKTUX0 (ORCPT + 99 others); Tue, 20 Nov 2018 15:23:26 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:56892 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727131AbeKTUX0 (ORCPT ); Tue, 20 Nov 2018 15:23:26 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 0023D607DC; Tue, 20 Nov 2018 09:55:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1542707710; bh=sBbu+0gGeDeVTUJHEDPT+DUyuG8owCDgrf9Y2yTAucc=; h=From:To:Cc:Subject:Date:From; b=d7lOWIXJMyO6EDDvJH3OynMWI7HzNvw5o/KtXRgWpt7IcnnKoyu7MZ7Utz/AOkaAz nNiUBfuWM+cAaw8+GQLQVPBTPEmwvlyQ6CJ+BYmIevpzr3FsjlnXK7AbRtK3M6QGlS qyyOnAT7ETEsipT7Hl0Yu9/F4s9ebqdfWT0WDqFk= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from blr-ubuntu-41.ap.qualcomm.com (blr-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.18.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek.gautam@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 4FA38607DC; Tue, 20 Nov 2018 09:55:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1542707709; bh=sBbu+0gGeDeVTUJHEDPT+DUyuG8owCDgrf9Y2yTAucc=; h=From:To:Cc:Subject:Date:From; b=aX5BEFpfgvhPappPDG6/snNbc8YlyfJSyMJu95j2BmSmlaPSqpuA5awMNjRHpLTov OirFX6HKbgj9rk+HLWdh9ZH2LBCJZvyp4ZQjsnRszQYsIDsmD/hCExJGork+LwjQ3e BpIkHyhr/+XVm4zhgEkIV65NOeQm4bKLiB0TuM/0= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 4FA38607DC Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=vivek.gautam@codeaurora.org From: Vivek Gautam To: robdclark@gmail.com, airlied@linux.ie Cc: linux-kernel@vger.kernel.org, freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, tfiga@chromium.org, jcrouse@codeaurora.org, Vivek Gautam Subject: [PATCH 1/1] drm: msm: Replace dma_map_sg with dma_sync_sg* Date: Tue, 20 Nov 2018 15:24:37 +0530 Message-Id: <20181120095437.29820-1-vivek.gautam@codeaurora.org> X-Mailer: git-send-email 2.16.1.72.g5be1f00a9a70 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org dma_map_sg() expects a DMA domain. However, the drm devices have been traditionally using unmanaged iommu domain which is non-dma type. Using dma mapping APIs with that domain is bad. Replace dma_map_sg() calls with dma_sync_sg_for_device{|cpu}() to do the cache maintenance. Signed-off-by: Vivek Gautam Suggested-by: Tomasz Figa --- Tested on an MTP sdm845: https://github.com/vivekgautam1/linux/tree/v4.19/sdm845-mtp-display-working drivers/gpu/drm/msm/msm_gem.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c index 00c795ced02c..d7a7af610803 100644 --- a/drivers/gpu/drm/msm/msm_gem.c +++ b/drivers/gpu/drm/msm/msm_gem.c @@ -81,6 +81,8 @@ static struct page **get_pages(struct drm_gem_object *obj) struct drm_device *dev = obj->dev; struct page **p; int npages = obj->size >> PAGE_SHIFT; + struct scatterlist *s; + int i; if (use_pages(obj)) p = drm_gem_get_pages(obj); @@ -107,9 +109,19 @@ static struct page **get_pages(struct drm_gem_object *obj) /* For non-cached buffers, ensure the new pages are clean * because display controller, GPU, etc. are not coherent: */ - if (msm_obj->flags & (MSM_BO_WC|MSM_BO_UNCACHED)) - dma_map_sg(dev->dev, msm_obj->sgt->sgl, - msm_obj->sgt->nents, DMA_BIDIRECTIONAL); + if (msm_obj->flags & (MSM_BO_WC | MSM_BO_UNCACHED)) { + /* + * Fake up the SG table so that dma_sync_sg_*() + * can be used to flush the pages associated with it. + */ + for_each_sg(msm_obj->sgt->sgl, s, + msm_obj->sgt->nents, i) + sg_dma_address(s) = sg_phys(s); + + dma_sync_sg_for_device(dev->dev, msm_obj->sgt->sgl, + msm_obj->sgt->nents, + DMA_TO_DEVICE); + } } return msm_obj->pages; @@ -137,10 +149,11 @@ static void put_pages(struct drm_gem_object *obj) * pages are clean because display controller, * GPU, etc. are not coherent: */ - if (msm_obj->flags & (MSM_BO_WC|MSM_BO_UNCACHED)) - dma_unmap_sg(obj->dev->dev, msm_obj->sgt->sgl, - msm_obj->sgt->nents, - DMA_BIDIRECTIONAL); + if (msm_obj->flags & (MSM_BO_WC | MSM_BO_UNCACHED)) + dma_sync_sg_for_cpu(obj->dev->dev, + msm_obj->sgt->sgl, + msm_obj->sgt->nents, + DMA_FROM_DEVICE); sg_free_table(msm_obj->sgt); kfree(msm_obj->sgt); -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation