From patchwork Tue Oct 13 11:47:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 54846 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by patches.linaro.org (Postfix) with ESMTPS id A382623001 for ; Tue, 13 Oct 2015 11:47:44 +0000 (UTC) Received: by lbwr8 with SMTP id r8sf8018625lbw.0 for ; Tue, 13 Oct 2015 04:47:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=OzI1OI2mfmsywu9vui0JGGU2AQvq5Fc+Y+AGmAIk+UE=; b=EmOzsdNL8o4f3x7pHkdVtDIAxqZi/EoLwFSUNkVCoJbd84E47p52DtTtP2sfWn4Yte K8bXKy93IePnnmfrhSU22S0vbENIWFth+Se9Vt2Zn6TUrGpTRgBZl6DAkyqOzY8jLe0H OyPLy0a86uz0MvVthPIgHJ0JOy3NRHJSujsxhlT4KuSI3KAHm5lq1dzQFOqWGZnvubKP MHF3WUozuJLFmb2wpxOgtlSox4FIq/9u4spl0rhDg/TfTAj0fvbDJSZV1+eLnuua+N8Z mL/KUDJGevYnAoCr5h3Knxk6K4cbFuXEiSJhzpGDjykmhaHnnasnwdzR0KaNBB+BUJF4 +1KQ== X-Gm-Message-State: ALoCoQmXditBffJkcY7WfILog/fMvPRaW5JIYMc1cRRLM2L3JRr8Tn8nhy0vgqffb65AHO6xO0Lz X-Received: by 10.180.107.167 with SMTP id hd7mr4130500wib.6.1444736863467; Tue, 13 Oct 2015 04:47:43 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.205.7 with SMTP id d7ls665248lfg.82.gmail; Tue, 13 Oct 2015 04:47:43 -0700 (PDT) X-Received: by 10.112.132.74 with SMTP id os10mr14792686lbb.40.1444736863314; Tue, 13 Oct 2015 04:47:43 -0700 (PDT) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id 29si1933839lfq.18.2015.10.13.04.47.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Oct 2015 04:47:43 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by lbbck17 with SMTP id ck17so16579562lbb.1 for ; Tue, 13 Oct 2015 04:47:43 -0700 (PDT) X-Received: by 10.112.139.201 with SMTP id ra9mr14704167lbb.29.1444736863161; Tue, 13 Oct 2015 04:47:43 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp2080560lbq; Tue, 13 Oct 2015 04:47:42 -0700 (PDT) X-Received: by 10.107.152.134 with SMTP id a128mr32888859ioe.164.1444736862165; Tue, 13 Oct 2015 04:47:42 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s8si12338848ign.45.2015.10.13.04.47.41; Tue, 13 Oct 2015 04:47:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-samsung-soc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752305AbbJMLrl (ORCPT + 4 others); Tue, 13 Oct 2015 07:47:41 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:15035 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751733AbbJMLrk (ORCPT ); Tue, 13 Oct 2015 07:47:40 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NW5006PMQ3EBG10@mailout3.w1.samsung.com> for linux-samsung-soc@vger.kernel.org; Tue, 13 Oct 2015 12:47:38 +0100 (BST) X-AuditID: cbfec7f5-f794b6d000001495-35-561cef597ef3 Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 54.68.05269.95FEC165; Tue, 13 Oct 2015 12:47:37 +0100 (BST) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NW500KSPQ39MP80@eusync4.samsung.com>; Tue, 13 Oct 2015 12:47:37 +0100 (BST) From: Marek Szyprowski To: dri-devel@lists.freedesktop.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Inki Dae , Joonyoung Shim , Seung-Woo Kim , Andrzej Hajda Subject: [PATCH v2] drm/exynos/gem: remove DMA-mapping hacks used for constructing page array Date: Tue, 13 Oct 2015 13:47:20 +0200 Message-id: <1444736840-22883-1-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <561CE317.4020209@samsung.com> References: <561CE317.4020209@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupiluLIzCtJLcpLzFFi42I5/e/4Nd3I9zJhBl9eGVjcWneO1eLK1/ds FpPuT2CxeHHvIovFjPP7mCzWHrnLbjFj8ks2B3aP+93HmTz6tqxi9Pi8SS6AOYrLJiU1J7Ms tUjfLoErY+G/jywF6+UqjrU9Y2xg7JbsYuTkkBAwkbj/p5kNwhaTuHBvPZDNxSEksJRRYvmC zcwQThOTxLHzZ1hAqtgEDCW63naBdYgIuEk0HZ7JClLELHCaUeLYpwfMIAlhgXiJ/pZLYEUs AqoSS05PZ+xi5ODgFfCQmNNSArFNTuL/yxVMIDangLbEkhNXGUFsIQEtiTt/2pgmMPIuYGRY xSiaWppcUJyUnmukV5yYW1yal66XnJ+7iRESQl93MC49ZnWIUYCDUYmH90WkTJgQa2JZcWXu IUYJDmYlEd6kFqAQb0piZVVqUX58UWlOavEhRmkOFiVx3pm73ocICaQnlqRmp6YWpBbBZJk4 OKUaGLWXCkyPWndXfZlHqvHWC2d/e94/ylU4L+JPz//M/Wv/veW8wsPFev/ooY1KN3+wRu+J +b7Dn+G7z+6lNoG1FsVeLDXH3yprrlAMfJjib9X+OlFQ9mPll0UbPRYohPv9jsneNy9yro+p CndMx3r/GJ7on+060bMahHnlPdflvPgp8tbXL/mLkxJLcUaioRZzUXEiAOzTCzwdAgAA Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: m.szyprowski@samsung.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Exynos GEM objects contains an array of pointers to the pages, which the allocated buffer consists of. Till now the code used some hacks (like relying on DMA-mapping internal structures or using ARM-specific dma_to_pfn helper) to build this array. This patch fixes this by adding proper call to dma_get_sgtable_attrs() and using the acquired scatter-list to construct needed array. This approach is more portable (work also for ARM64) and finally fixes the layering violation that was present in this code. Signed-off-by: Marek Szyprowski --- Patch is based on exynos-drm-next branch. v2: use drm_prime_sg_to_page_addr_arrays() --- drivers/gpu/drm/exynos/exynos_drm_gem.c | 58 +++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c index 29f48756e72f..183aa4a74686 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_gem.c +++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c @@ -25,6 +25,8 @@ static int exynos_drm_alloc_buf(struct exynos_drm_gem *exynos_gem) struct drm_device *dev = exynos_gem->base.dev; enum dma_attr attr; unsigned int nr_pages; + struct sg_table sgt; + int ret = -ENOMEM; if (exynos_gem->dma_addr) { DRM_DEBUG_KMS("already allocated.\n"); @@ -56,13 +58,10 @@ static int exynos_drm_alloc_buf(struct exynos_drm_gem *exynos_gem) nr_pages = exynos_gem->size >> PAGE_SHIFT; - if (!is_drm_iommu_supported(dev)) { - exynos_gem->pages = drm_calloc_large(nr_pages, - sizeof(struct page *)); - if (!exynos_gem->pages) { - DRM_ERROR("failed to allocate pages.\n"); - return -ENOMEM; - } + exynos_gem->pages = drm_calloc_large(nr_pages, sizeof(struct page *)); + if (!exynos_gem->pages) { + DRM_ERROR("failed to allocate pages.\n"); + return -ENOMEM; } exynos_gem->cookie = dma_alloc_attrs(dev->dev, exynos_gem->size, @@ -70,30 +69,40 @@ static int exynos_drm_alloc_buf(struct exynos_drm_gem *exynos_gem) &exynos_gem->dma_attrs); if (!exynos_gem->cookie) { DRM_ERROR("failed to allocate buffer.\n"); - if (exynos_gem->pages) - drm_free_large(exynos_gem->pages); - return -ENOMEM; + goto err_free; } - if (exynos_gem->pages) { - dma_addr_t start_addr; - unsigned int i = 0; - - start_addr = exynos_gem->dma_addr; - while (i < nr_pages) { - exynos_gem->pages[i] = - pfn_to_page(dma_to_pfn(dev->dev, start_addr)); - start_addr += PAGE_SIZE; - i++; - } - } else { - exynos_gem->pages = exynos_gem->cookie; + ret = dma_get_sgtable_attrs(dev->dev, &sgt, exynos_gem->cookie, + exynos_gem->dma_addr, exynos_gem->size, + &exynos_gem->dma_attrs); + if (ret < 0) { + DRM_ERROR("failed to get sgtable.\n"); + goto err_dma_free; + } + + if (drm_prime_sg_to_page_addr_arrays(&sgt, exynos_gem->pages, NULL, + nr_pages)) { + DRM_ERROR("invalid sgtable.\n"); + ret = -EINVAL; + goto err_sgt_free; } + sg_free_table(&sgt); + DRM_DEBUG_KMS("dma_addr(0x%lx), size(0x%lx)\n", (unsigned long)exynos_gem->dma_addr, exynos_gem->size); return 0; + +err_sgt_free: + sg_free_table(&sgt); +err_dma_free: + dma_free_attrs(dev->dev, exynos_gem->size, exynos_gem->cookie, + exynos_gem->dma_addr, &exynos_gem->dma_attrs); +err_free: + drm_free_large(exynos_gem->pages); + + return ret; } static void exynos_drm_free_buf(struct exynos_drm_gem *exynos_gem) @@ -112,8 +121,7 @@ static void exynos_drm_free_buf(struct exynos_drm_gem *exynos_gem) (dma_addr_t)exynos_gem->dma_addr, &exynos_gem->dma_attrs); - if (!is_drm_iommu_supported(dev)) - drm_free_large(exynos_gem->pages); + drm_free_large(exynos_gem->pages); } static int exynos_drm_gem_handle_create(struct drm_gem_object *obj,