From patchwork Wed Dec 26 09:15:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inki Dae X-Patchwork-Id: 1910821 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id EC947DFAC4 for ; Wed, 26 Dec 2012 09:15:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D63ACE60B1 for ; Wed, 26 Dec 2012 01:15:37 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by gabe.freedesktop.org (Postfix) with ESMTP id 09F9EE603C for ; Wed, 26 Dec 2012 01:15:18 -0800 (PST) Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MFM00KYISCQKW40@mailout4.samsung.com> for dri-devel@lists.freedesktop.org; Wed, 26 Dec 2012 18:15:17 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [203.254.230.42]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 28.E8.12699.520CAD05; Wed, 26 Dec 2012 18:15:17 +0900 (KST) X-AuditID: cbfee61b-b7f616d00000319b-eb-50dac025116b Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 97.E8.12699.520CAD05; Wed, 26 Dec 2012 18:15:17 +0900 (KST) Received: from daeinki-desktop.10.32.193.11 ([10.90.51.53]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MFM00J2RSDGPF30@mmp2.samsung.com> for dri-devel@lists.freedesktop.org; Wed, 26 Dec 2012 18:15:17 +0900 (KST) From: Inki Dae To: airlied@linux.ie, dri-devel@lists.freedesktop.org Subject: [PATCH] drm/exynos: consider buffer allocation without iommu Date: Wed, 26 Dec 2012 18:15:15 +0900 Message-id: <1356513315-29265-1-git-send-email-inki.dae@samsung.com> X-Mailer: git-send-email 1.7.4.1 DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMLMWRmVeSWpSXmKPExsVy+t8zLV3VA7cCDNa+k7K48vU9mwOjx/3u 40wBjFFcNimpOZllqUX6dglcGWv+rWMs6JOoePtgA0sD43vhLkZODgkBE4nGTQdYIGwxiQv3 1rOB2EICyxglXr/kgKlZ/3YiUA0XUHw6o8SWzd1QznomiZ1zD4J1swmoSkxccR+sW0TAVKJj 0lKwOLNAocTCnqdANgeHsICrxK6GTJAwC1B589MHzCA2r4CLRMfbTmaIZQoSC+69ZYOoEZD4 NvkQWKuEgKzEpgPMIGslBHawSbxq2sMGUS8pcXDFDZYJjIILGBlWMYqmFiQXFCel5xrpFSfm Fpfmpesl5+duYoSElPQOxlUNFocYBTgYlXh4OX/dDBBiTSwrrsw9xCjBwawkwquw6laAEG9K YmVValF+fFFpTmrxIUYfoEsmMkuJJucDwz2vJN7Q2MDY0NDS0MzU0tQAh7CSOG+zR0qAkEB6 YklqdmpqQWoRzDgmDk6pBsbFBWmOGR+W+8rsLQrOnSKd++aQ31l1NYbg6S45SjPP+Fqwlz6e e/OWBvNGyxczEuK6WQRni0mLT3rb7yLaPuFrj6sIs+mJZIvyK07Pik/P3t2p43V39hFV+Yea jfu7Kp8a8mtLME5af7PjeJtN/quw/sKn7bYChvl7OcosWaPKkrpUvxuZKrEUZyQaajEXFScC AHvt4fRWAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrMLMWRmVeSWpSXmKPExsVy+t9jQV3VA7cCDA49FrK48vU9mwOjx/3u 40wBjFENjDYZqYkpqUUKqXnJ+SmZeem2St7B8c7xpmYGhrqGlhbmSgp5ibmptkouPgG6bpk5 QGOVFMoSc0qBQgGJxcVK+naYJoSGuOlawDRG6PqGBMH1GBmggYR1jBlr/q1jLOiTqHj7YANL A+N74S5GTg4JAROJ9W8nskDYYhIX7q1n62Lk4hASmM4osWVzNwuEs55JYufcg2BVbAKqEhNX 3GcDsUUETCU6Ji0FizMLFEos7HkKZHNwCAu4SuxqyAQJswCVNz99wAxi8wq4SHS87WSGWKYg seDeW7YJjNwLGBlWMYqmFiQXFCel5xrpFSfmFpfmpesl5+duYgSH7DPpHYyrGiwOMQpwMCrx 8HL+uhkgxJpYVlyZe4hRgoNZSYRXYdWtACHelMTKqtSi/Pii0pzU4kOMPkDbJzJLiSbnA+Mp ryTe0NjEzMjSyMzYxNzYGIewkjhvs0dKgJBAemJJanZqakFqEcw4Jg5OqQZGEelV9a8Mg1wf mIidvzHh3PfrN3umOqzWXNphxWT6Mtf7m9K0zEszFe8U9walOb5OPOzw51xuwMTkuq1tFxVK mebO2VDD6lZUucbtE+sirT2PmddbK919fj+wZMsep2WubWuWBarNNbkc2NLakcmduZx9usuU gIWONsozrDSL7z7641t29eUtJZbijERDLeai4kQAR2+pV4YCAAA= X-CFilter-Loop: Reflected Cc: kyungmin.park@samsung.com, sw0312.kim@samsung.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org This patch fixes the issue that when buffer allocation is requested without iommu, the allocation is failed. Without iommu, dma_alloc_attrs function allocates some memory region and returns cpu address so this patch makes the cpu address to be set to buf->kvaddr correctly. Signed-off-by: Inki Dae Signed-off-by: Kyungmin Park --- drivers/gpu/drm/exynos/exynos_drm_buf.c | 50 +++++++++++++++++++++++++++---- 1 files changed, 44 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_buf.c b/drivers/gpu/drm/exynos/exynos_drm_buf.c index 9601bad..22fb574 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_buf.c +++ b/drivers/gpu/drm/exynos/exynos_drm_buf.c @@ -29,6 +29,7 @@ #include "exynos_drm_drv.h" #include "exynos_drm_gem.h" #include "exynos_drm_buf.h" +#include "exynos_drm_iommu.h" static int lowlevel_buffer_allocate(struct drm_device *dev, unsigned int flags, struct exynos_drm_gem_buf *buf) @@ -66,14 +67,45 @@ static int lowlevel_buffer_allocate(struct drm_device *dev, dma_set_attr(attr, &buf->dma_attrs); dma_set_attr(DMA_ATTR_NO_KERNEL_MAPPING, &buf->dma_attrs); - buf->pages = dma_alloc_attrs(dev->dev, buf->size, - &buf->dma_addr, GFP_KERNEL, &buf->dma_attrs); - if (!buf->pages) { - DRM_ERROR("failed to allocate buffer.\n"); - return -ENOMEM; + nr_pages = buf->size >> PAGE_SHIFT; + + if (!is_drm_iommu_supported(dev)) { + dma_addr_t start_addr; + unsigned int i = 0; + + buf->pages = kzalloc(sizeof(struct page) * nr_pages, + GFP_KERNEL); + if (!buf->pages) { + DRM_ERROR("failed to allocate pages.\n"); + return -ENOMEM; + } + + buf->kvaddr = dma_alloc_attrs(dev->dev, buf->size, + &buf->dma_addr, GFP_KERNEL, + &buf->dma_attrs); + if (!buf->kvaddr) { + DRM_ERROR("failed to allocate buffer.\n"); + kfree(buf->pages); + return -ENOMEM; + } + + start_addr = buf->dma_addr; + while (i < nr_pages) { + buf->pages[i] = phys_to_page(start_addr); + start_addr += PAGE_SIZE; + i++; + } + } else { + + buf->pages = dma_alloc_attrs(dev->dev, buf->size, + &buf->dma_addr, GFP_KERNEL, + &buf->dma_attrs); + if (!buf->pages) { + DRM_ERROR("failed to allocate buffer.\n"); + return -ENOMEM; + } } - nr_pages = buf->size >> PAGE_SHIFT; buf->sgt = drm_prime_pages_to_sg(buf->pages, nr_pages); if (!buf->sgt) { DRM_ERROR("failed to get sg table.\n"); @@ -92,6 +124,9 @@ err_free_attrs: (dma_addr_t)buf->dma_addr, &buf->dma_attrs); buf->dma_addr = (dma_addr_t)NULL; + if (!is_drm_iommu_supported(dev)) + kfree(buf->pages); + return ret; } @@ -117,6 +152,9 @@ static void lowlevel_buffer_deallocate(struct drm_device *dev, dma_free_attrs(dev->dev, buf->size, buf->pages, (dma_addr_t)buf->dma_addr, &buf->dma_attrs); buf->dma_addr = (dma_addr_t)NULL; + + if (!is_drm_iommu_supported(dev)) + kfree(buf->pages); } struct exynos_drm_gem_buf *exynos_drm_init_buf(struct drm_device *dev,