From patchwork Tue Oct 13 10:22:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 54830 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 A03FF23001 for ; Tue, 13 Oct 2015 10:22:54 +0000 (UTC) Received: by lbbti1 with SMTP id ti1sf6870156lbb.3 for ; Tue, 13 Oct 2015 03:22:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:delivered-to:from:to:subject:date :message-id:cc:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=CqhHeiIZLnCVA1tMpKp7gglbODmFBIlcueAJsi8uQak=; b=FZI2Y/EiURmxIztETWBwmh2suogGrjmjCI1EsyL0G7f3rjZbZ8PxH/N4ZnnT/8c4k8 sTobGStwXYVGFqBKlHtk2NUHSuVHGoBHZ0lVSra/1PlpyOJuVvPjmcIuA0VXA58HDV7c LC/r+cXThgvnc/HRsXlsYpx7v9Pkuizerhd3TxiJ62gXbqodjhyXLIHMYRjCH9egdVch NRXWjekiDlJ8/skSRKtacCjC6Ve8jWlHfRXcckKRDAxL7GCOp1Xesq4RGm/l3JZ+/ZFp UYSRLysTkzAXYcNdbKugu5H7l7tcZ5+pP10ZE/ZldjqfROs2cODkcpWjwRKMhQqUQvHM aU6A== X-Gm-Message-State: ALoCoQnM1CuvP0u4jR0dPG1MV51wiYnB5XxSU/zUHw5BGJNU2rYsOwq9pwuXCwLqyFa5vD6ClI3o X-Received: by 10.112.184.170 with SMTP id ev10mr212949lbc.4.1444731773673; Tue, 13 Oct 2015 03:22:53 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.18.90 with SMTP id h87ls355182lfi.9.gmail; Tue, 13 Oct 2015 03:22:53 -0700 (PDT) X-Received: by 10.25.157.131 with SMTP id g125mr9492407lfe.75.1444731773396; Tue, 13 Oct 2015 03:22:53 -0700 (PDT) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com. [209.85.217.177]) by mx.google.com with ESMTPS id r7si1714377lfe.1.2015.10.13.03.22.53 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Oct 2015 03:22:53 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by lbcao8 with SMTP id ao8so14183141lbc.3 for ; Tue, 13 Oct 2015 03:22:53 -0700 (PDT) X-Received: by 10.112.64.72 with SMTP id m8mr14221255lbs.41.1444731773279; Tue, 13 Oct 2015 03:22:53 -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 w3csp2039178lbq; Tue, 13 Oct 2015 03:22:52 -0700 (PDT) X-Received: by 10.50.64.210 with SMTP id q18mr18347244igs.15.1444731772337; Tue, 13 Oct 2015 03:22:52 -0700 (PDT) Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTP id ka4si2210555igb.104.2015.10.13.03.22.51; Tue, 13 Oct 2015 03:22:52 -0700 (PDT) Received-SPF: pass (google.com: domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B7D606E043; Tue, 13 Oct 2015 03:22:50 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout4.w1.samsung.com (mailout4.w1.samsung.com [210.118.77.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id D53546E043 for ; Tue, 13 Oct 2015 03:22:48 -0700 (PDT) Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NW500KOSM5XIYA0@mailout4.w1.samsung.com> for dri-devel@lists.freedesktop.org; Tue, 13 Oct 2015 11:22:45 +0100 (BST) X-AuditID: cbfec7f5-f794b6d000001495-87-561cdb75211d Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id B2.89.05269.57BDC165; Tue, 13 Oct 2015 11:22:45 +0100 (BST) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NW500KUTM5TO570@eusync1.samsung.com>; Tue, 13 Oct 2015 11:22:45 +0100 (BST) From: Marek Szyprowski To: dri-devel@lists.freedesktop.org, linux-samsung-soc@vger.kernel.org Subject: [PATCH] drm/exynos/gem: remove DMA-mapping hacks used for constructing page array Date: Tue, 13 Oct 2015 12:22:29 +0200 Message-id: <1444731749-10759-1-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrAJMWRmVeSWpSXmKPExsVy+t/xy7qlt2XCDDY8Z7a4te4cq8WVr+/Z LCbdn8Bi8eLeRRaLGef3MVmsPXKX3WLG5JdsDuwe97uPM3n0bVnF6PF5k1wAcxSXTUpqTmZZ apG+XQJXRvvB2IIZchXbrgg2ML6W6GLk5JAQMJFY+KCLFcIWk7hwbz1bFyMXh5DAUkaJT7/v M0E4TUwSM1+9YQapYhMwlOh628UGYosIuEk0HZ7JClLELHCaUeLYpwdARRwcwgIxEjsnF4LU sAioStzoOsAIYvMKeEh8u72TCWKbnMT/lyuYJjByL2BkWMUomlqaXFCclJ5rpFecmFtcmpeu l5yfu4kREg5fdzAuPWZ1iFGAg1GJh/dFpEyYEGtiWXFl7iFGCQ5mJRHepBagEG9KYmVValF+ fFFpTmrxIUZpDhYlcd6Zu96HCAmkJ5akZqemFqQWwWSZODilGhh9zwfU8yWK8eT+Zloz+Zhg /vnoyerH1955kj3r7TSmnRYrgvrf8/vO3/CsbqpCSv/67JjLOqX7r7uobwq+u1LSOzNyI/PH ygSdSR9S0x+fufz5pPFkM7fVT2+eN5rLL/Ht3qMjO5+ZZKi91eI8dv5wUtVdDsl95eln1ld/ s2hu2Wm34nbIdNf9SizFGYmGWsxFxYkATO4RwQMCAAA= Cc: Andrzej Hajda , Seung-Woo Kim , Marek Szyprowski X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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.177 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 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. --- drivers/gpu/drm/exynos/exynos_drm_gem.c | 60 +++++++++++++++++++-------------- 1 file changed, 35 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..e998a64a3dd0 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_gem.c +++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c @@ -25,6 +25,10 @@ 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; + struct scatterlist *s; + int ret = -ENOMEM; + int i, j; if (exynos_gem->dma_addr) { DRM_DEBUG_KMS("already allocated.\n"); @@ -56,13 +60,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 +71,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; + } + + j = 0; + for_each_sg(sgt.sgl, s, sgt.orig_nents, i) { + int size = s->length >> PAGE_SHIFT; + struct page *page = sg_page(s); + + while (size-- > 0) + exynos_gem->pages[j++] = page++; } + 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_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 +123,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,