From patchwork Thu Jan 3 05:25:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inki Dae X-Patchwork-Id: 1926171 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 3FDF63FDDA for ; Thu, 3 Jan 2013 05:26:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 048FFE63A2 for ; Wed, 2 Jan 2013 21:26:05 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by gabe.freedesktop.org (Postfix) with ESMTP id 538C5E60A2 for ; Wed, 2 Jan 2013 21:25:50 -0800 (PST) Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MG1001YHB2YHUG0@mailout3.samsung.com> for dri-devel@lists.freedesktop.org; Thu, 03 Jan 2013 14:25:48 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [203.254.230.41]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 3A.A5.12699.C5615E05; Thu, 03 Jan 2013 14:25:48 +0900 (KST) X-AuditID: cbfee61b-b7f616d00000319b-9f-50e5165cbca8 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id D9.A5.12699.C5615E05; Thu, 03 Jan 2013 14:25:48 +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 <0MG100MCKB2ZDB10@mmp2.samsung.com> for dri-devel@lists.freedesktop.org; Thu, 03 Jan 2013 14:25:48 +0900 (KST) From: Inki Dae To: airlied@linux.ie, dri-devel@lists.freedesktop.org Subject: [PATCH v2] drm/exynos: consider buffer allocation without iommu Date: Thu, 03 Jan 2013 14:25:47 +0900 Message-id: <1357190747-20611-1-git-send-email-inki.dae@samsung.com> X-Mailer: git-send-email 1.7.4.1 In-reply-to: <1356513315-29265-1-git-send-email-inki.dae@samsung.com> References: <1356513315-29265-1-git-send-email-inki.dae@samsung.com> DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrDLMWRmVeSWpSXmKPExsVy+t8zTd0YsacBBiva5CyufH3P5sDocb/7 OFMAYxSXTUpqTmZZapG+XQJXxsP2lSwFF6Qqdq+fw9LA+F60i5GTQ0LARKLr0F1GCFtM4sK9 9WxdjFwcQgLLGCXurrjACFN0/3sHM0RiOqPEspUTWCGc9UwS2yc8ZQWpYhNQlZi44j4biC0i YCrRMWkpC4jNLFAosbDnKZgtLOAhMfvNQqAaDg4WoPoHj6pAwrwCLhLzjq5ihVimILHg3luw MZwCrhK77lwGO0IIqKZ3wnawGhYBAYlvkw+xgIyREJCV2HQA7DYJgTNsEo9mTmCDmCMpcXDF DZYJjMILGBlWMYqmFiQXFCel5xrpFSfmFpfmpesl5+duYoQEofQOxlUNFocYBTgYlXh4Geuf BAixJpYVV+YeYpTgYFYS4b2eAxTiTUmsrEotyo8vKs1JLT7E6AN0yURmKdHkfGCE5JXEGxob GBsaWhqamVqaGuAQVhLnZTwFNEsgPbEkNTs1tSC1CGYcEwenVANjx780mTu/gnf1Lo/42+P/ Vc7HdPdvNWsuyy2Kn4w2xW2ZJHO0xP7+zkR5rsPl/5Sbz6YdnXDo3aZLGpO2z62R6WBb5fpU 8XL01Zkqb+eJ/mz77/Fv9TpZsXX7LJo8vrNv/D53vXr7svcPQv7unDZvtfbqb8KTavZIvrF5 6H+c8cTpxf4bp24J2qvEUpyRaKjFXFScCAAeOhaTbwIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupmkeLIzCtJLcpLzFFi42I5/e+xoG6M2NMAg2mLxCyufH3P5sDocb/7 OFMAY1QDo01GamJKapFCal5yfkpmXrqtkndwvHO8qZmBoa6hpYW5kkJeYm6qrZKLT4CuW2YO 0FglhbLEnFKgUEBicbGSvh2mCaEhbroWMI0Rur4hQXA9RgZoIGEdY8bD9pUsBRekKnavn8PS wPhetIuRk0NCwETi/vcOZghbTOLCvfVsXYxcHEIC0xkllq2cwArhrGeS2D7hKStIFZuAqsTE FffZQGwRAVOJjklLWUBsZoFCiYU9T8FsYQEPidlvFgLVcHCwANU/eFQFEuYVcJGYd3QVK8Qy BYkF996CjeEUcJXYdecyI4gtBFTTO2E76wRG3gWMDKsYRVMLkguKk9JzjfSKE3OLS/PS9ZLz czcxgkP8mfQOxlUNFocYBTgYlXh4GeufBAixJpYVV+YeYpTgYFYS4b2eAxTiTUmsrEotyo8v Ks1JLT7E6AN01ERmKdHkfGD85ZXEGxqbmBlZGpkZm5gbG+MQVhLnZTwFNEsgPbEkNTs1tSC1 CGYcEwenVAMjb93LsD9W02ybY+TDAx8W1ykpd0zr9bMMrMmI1tdRbkri17jFxPPmRW2SsvGV oEx3SSWPfNaVyV42P33vSM1u5curnq9iu+PSEgPRmOo9S/kzu1b8SXzN9zxKwy7WIObBult9 KxWevNOSiF0aZZ0Y7quQZXJltRsH6/q/CvK7mqTOSx31UmIpzkg01GIuKk4EAOrYvKyeAgAA 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. Changelog v2: - fix buffer free . Without iommu, dma_free_attrs function requires kernel space address as argument. So it changes the argument, buf->pages to buf->kvaddr. Signed-off-by: Inki Dae Signed-off-by: Kyungmin Park --- drivers/gpu/drm/exynos/exynos_drm_buf.c | 55 +++++++++++++++++++++++++++---- 1 files changed, 48 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_buf.c b/drivers/gpu/drm/exynos/exynos_drm_buf.c index 13a8489..b7937a6 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_buf.c +++ b/drivers/gpu/drm/exynos/exynos_drm_buf.c @@ -15,6 +15,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) @@ -52,14 +53,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"); @@ -78,6 +110,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; } @@ -100,8 +135,14 @@ static void lowlevel_buffer_deallocate(struct drm_device *dev, kfree(buf->sgt); buf->sgt = NULL; - dma_free_attrs(dev->dev, buf->size, buf->pages, + if (!is_drm_iommu_supported(dev)) { + dma_free_attrs(dev->dev, buf->size, buf->kvaddr, (dma_addr_t)buf->dma_addr, &buf->dma_attrs); + kfree(buf->pages); + } else + 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; }