Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2499567imu; Thu, 29 Nov 2018 06:05:19 -0800 (PST) X-Google-Smtp-Source: AFSGD/VCb39A5ZfGceQJSCKM2CMxpLrZn++X4acOe06Yw43UgD9kJ6mJlwsTdQAa4ckU2tj7jamX X-Received: by 2002:a62:28c9:: with SMTP id o192mr1536779pfo.57.1543500319768; Thu, 29 Nov 2018 06:05:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543500319; cv=none; d=google.com; s=arc-20160816; b=tadwknOjAnr/MWoR218rOS07xhC4Pu/nhoabdwNw3bnuPrleht7M7rXDyEeZuWzCbZ 6pNWwa6MGmJRQkp/taeFbhc2hQBJwU+o7Yt0UXNgrjH7UEOZdHP1r9DfwX8eT0j47bHx AOUUNx4fJclHwZmnp/bX5smIkXkqsIDKDseupibt9mHrh5hnBWKyIsTc8yN903PpGvKj 4t6/fimKIRn22Ac46O2xPpGwQQ49d9wkIOJurdUAOCXMG6aFW4xSFAoZLqw1gOnGkzvB IgMIzWda/IJLi0xOZGkcX9h+VpqGQCVZmxN7HlWwQ4ymKKOePYCuEbnsp2GvfXVaNCh6 XgkA== 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=FGlkn9l/Dq9L1Rnt5X8Fm0FRYCjPhGW89VsisbBnwqM=; b=vVbX46x2k7QVURv7O51Lcn/WmGoThUnXy7LQzKhPgLv3ShjdPWIHOkMPFi/E5HelUv c38Oj7OSc4jOt7rrxGey7JBagl3OSyvgzeLC5fhr+W7bYbSaUwXRmKRIR71G9+j7ddrW +gvAzrbiqpQdwxdMHiVOOnvLrrjCYRODr7DQ1zfosdhnyDM7n931yKHmcxAR51ThQ7/P TQkFnDm3WL8tBdhXbsyBG6QaCCS1b/PDJatU+hNPejW2kt88zEM0eAcEgLwQ3rbebOc9 LBLeZhCnmLus+jPTEzybm2bXK5Jb989oZt6NFx43j5ExUPs+nZeB7vq+r7o1viyf6oeT 324Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=YuGbiPJR; dkim=pass header.i=@codeaurora.org header.s=default header.b=hVUigHyt; 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 r197si2680124pfr.192.2018.11.29.06.04.53; Thu, 29 Nov 2018 06:05:19 -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=YuGbiPJR; dkim=pass header.i=@codeaurora.org header.s=default header.b=hVUigHyt; 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 S1728475AbeK3BIz (ORCPT + 99 others); Thu, 29 Nov 2018 20:08:55 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:37904 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728446AbeK3BIy (ORCPT ); Thu, 29 Nov 2018 20:08:54 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 6EB1360C4B; Thu, 29 Nov 2018 14:03:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1543500206; bh=sxFMD/76Jtw6QWug0AqQn7YNLlWUypjhsnIqJ7q7kGo=; h=From:To:Cc:Subject:Date:From; b=YuGbiPJRGHcqqPOTAWvIgFxea/I/HgehayrvIvX7PUZkfYDWNKaMNEoByE2gZPmR2 LDoL/1072uuZ7x07UWl00tuJWaFw8LEXq4pP33KNW/2niqU7FRZPhSUv7dQpoIPdMd 5bzLmus5uBt3pC5iPXq2jzcShtHGQWvpi/xwHMjk= 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 DC48D60B73; Thu, 29 Nov 2018 14:03:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1543500205; bh=sxFMD/76Jtw6QWug0AqQn7YNLlWUypjhsnIqJ7q7kGo=; h=From:To:Cc:Subject:Date:From; b=hVUigHytcaPBCb0n1dEC/hySpyBg4FbT7LvzzhZU8MOn1KSmIC/RMDPF/Y0ABEBzB /VQ4mgAHeoaspCzKSayVkf41Ehn2wij5glpVjpWpo4fh/BUwwuX1OnRPUOhKwF4ve6 FjKODYh8RN3yTgUbvgcBcw6n8X/9IwevUohRkN5Y= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org DC48D60B73 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: airlied@linux.ie, robdclark@gmail.com Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, freedreno@lists.freedesktop.org, tfiga@chromium.org, architt@codeaurora.org, linux-arm-msm@vger.kernel.org, Vivek Gautam , Christoph Hellwig , Robin Murphy , Jordan Crouse , Sean Paul Subject: [PATCH v3 1/1] drm: msm: Replace dma_map_sg with dma_sync_sg* Date: Thu, 29 Nov 2018 19:33:15 +0530 Message-Id: <20181129140315.28476-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 Cc: Rob Clark Cc: Christoph Hellwig Cc: Robin Murphy Cc: Jordan Crouse Cc: Sean Paul --- Changes since v2: - Addressed Tomasz's comment to keep DMA_BIDIRECTIONAL dma direction flag intact. - Updated comment for sg's dma-address assignment as per Tomasz' suggestion. drivers/gpu/drm/msm/msm_gem.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c index 00c795ced02c..7048e9fe00c6 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); @@ -104,12 +106,23 @@ static struct page **get_pages(struct drm_gem_object *obj) return ptr; } - /* For non-cached buffers, ensure the new pages are clean + /* + * Some implementations of the DMA mapping ops expect + * physical addresses of the pages to be stored as DMA + * addresses of the sglist entries. To work around it, + * set them here explicitly. + */ + for_each_sg(msm_obj->sgt->sgl, s, msm_obj->sgt->nents, i) + sg_dma_address(s) = sg_phys(s); + + /* + * 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)) + dma_sync_sg_for_device(dev->dev, msm_obj->sgt->sgl, + msm_obj->sgt->nents, + DMA_BIDIRECTIONAL); } return msm_obj->pages; @@ -133,14 +146,16 @@ static void put_pages(struct drm_gem_object *obj) if (msm_obj->pages) { if (msm_obj->sgt) { - /* For non-cached buffers, ensure the new + /* + * 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_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_BIDIRECTIONAL); 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