From patchwork Thu Nov 15 05:23:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Inki Dae X-Patchwork-Id: 1747031 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 8BB87DF2AB for ; Thu, 15 Nov 2012 05:23:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 566379E8B5 for ; Wed, 14 Nov 2012 21:23:30 -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 234999E744 for ; Wed, 14 Nov 2012 21:23:15 -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 <0MDI00K1PKA3PP90@mailout4.samsung.com> for dri-devel@lists.freedesktop.org; Thu, 15 Nov 2012 14:23:14 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [203.254.230.42]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 0A.88.12699.24C74A05; Thu, 15 Nov 2012 14:23:14 +0900 (KST) X-AuditID: cbfee61b-b7f616d00000319b-e2-50a47c4260cb Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 69.88.12699.24C74A05; Thu, 15 Nov 2012 14:23:14 +0900 (KST) Received: from daeinki-desktop.10.32.193.11 ([10.90.51.53]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MDI006NBKAQPA10@mmp1.samsung.com> for dri-devel@lists.freedesktop.org; Thu, 15 Nov 2012 14:23:14 +0900 (KST) From: Inki Dae To: airlied@linux.ie, dri-devel@lists.freedesktop.org Subject: [PATCH v2] drm/exynos: add vm_ops to specific gem mmaper Date: Thu, 15 Nov 2012 14:23:13 +0900 Message-id: <1352956993-2048-1-git-send-email-inki.dae@samsung.com> X-Mailer: git-send-email 1.7.4.1 In-reply-to: <1352449443-19300-1-git-send-email-inki.dae@samsung.com> References: <1352449443-19300-1-git-send-email-inki.dae@samsung.com> DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrNLMWRmVeSWpSXmKPExsVy+t8zLV2nmiUBBo+PqVhc+fqezYHR4373 caYAxigum5TUnMyy1CJ9uwSujNltP1gKPgpVdPYdZ21gfMHfxcjJISFgIvGn9TQ7hC0mceHe erYuRi4OIYFljBKbTk4CcjjAiprn+kPEFzFKPP17lRnCWc8kcf3xOhaQbjYBVYmJK+6zgdgi AqYSHZOWgsWZBQolFvY8BbOFBRwl5h44yARiswDVz/mwD6yeV8BZ4vuNU4wQVyhILLj3Fmwx p4CrRN/vHJCwkICLxML+PnaIVgGJb5MPsUDcJiux6QDYORIC19kkTj9cyQwxRlLi4IobLBMY hRcwMqxiFE0tSC4oTkrPNdIrTswtLs1L10vOz93ECAlB6R2MqxosDjEKcDAq8fBafFwcIMSa WFZcmXuIUYKDWUmE98VBoBBvSmJlVWpRfnxRaU5q8SFGH6BLJjJLiSbnA+MjryTe0NjA2NDQ 0tDM1NLUAIewkjhvs0dKgJBAemJJanZqakFqEcw4Jg5OqQbG8JdLHHTzY8WFmF/PcWy7rbvj oGaWrZDt4fkZagej+yOWXubg3L3PfZ3c3MXXO04yOV9aLhN5MKHwfMXZP0xdjQuuv/LYf/md 0XWxTbt3LzrG55EeUXSGL+j8jpsLP9cE3No57dSXbTNXma2bcGNVU1LZhAUH/yfpHlx1VWVr ekn1syXXCi/v/q7EUpyRaKjFXFScCACc9oD6bgIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupikeLIzCtJLcpLzFFi42I5/e+xgK5TzZIAg98L5SyufH3P5sDocb/7 OFMAY1QDo01GamJKapFCal5yfkpmXrqtkndwvHO8qZmBoa6hpYW5kkJeYm6qrZKLT4CuW2YO 0FglhbLEnFKgUEBicbGSvh2mCaEhbroWMI0Rur4hQXA9RgZoIGEdY8bsth8sBR+FKjr7jrM2 ML7g72Lk4JAQMJFonuvfxcgJZIpJXLi3nq2LkYtDSGARo8TTv1eZIZz1TBLXH69jAaliE1CV mLjiPhuILSJgKtExaSlYnFmgUGJhz1MwW1jAUWLugYNMIDYLUP2cD/vA6nkFnCW+3zjFCLFN QWLBvbdsIEdwCrhK9P3OAQkLCbhILOzvY5/AyLuAkWEVo2hqQXJBcVJ6rpFecWJucWleul5y fu4mRnCAP5PewbiqweIQowAHoxIPr8XHxQFCrIllxZW5hxglOJiVRHhfHAQK8aYkVlalFuXH F5XmpBYfYvQBOmois5Rocj4w+vJK4g2NTcyMLI3MjE3MjY1xCCuJ8zZ7pAQICaQnlqRmp6YW pBbBjGPi4JRqYDS//3Jr97YDX6fpZwVefTzxd418bvUNEYHJf3ZfOpkbzM/TZ3BGR8/RX+Ks gyRHhtzHuKpjAj4CV79PXNzTLuN7025S+dYFC8Qv7GjNnp6erXPlzkrx1Wn/u/2fOcgk7Mp3 ucdQcGJT37YH5zWTP38OrczpTjhgUnQxvZv9U2LE7OUyfS9ezVdiKc5INNRiLipOBABRQrLa nQIAAA== 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 Changelog v2: call mutex_lock before drm_vm_open_locked is called. Changelog v1: This patch makes it takes a reference to gem object when specific gem mmap is requested. For this, it sets dev->driver->gem_vm_ops to vma->vm_ops. And this patch is based on exynos-drm-next-iommu branch of git://git.kernel.org/pub/scm/linux/kernel/git/daeinki/drm-exynos Signed-off-by: Inki Dae Signed-off-by: Kyungmin Park --- drivers/gpu/drm/exynos/exynos_drm_gem.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c index 50d73f1..de524d9 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_gem.c +++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c @@ -372,10 +372,13 @@ static int exynos_drm_gem_mmap_buffer(struct file *filp, struct exynos_drm_gem_obj *exynos_gem_obj = to_exynos_gem_obj(obj); struct exynos_drm_gem_buf *buffer; unsigned long vm_size; + int ret; DRM_DEBUG_KMS("%s\n", __FILE__); vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP; + vma->vm_private_data = obj; + vma->vm_ops = obj->dev->driver->gem_vm_ops; update_vm_cache_attr(exynos_gem_obj, vma); @@ -391,9 +394,25 @@ static int exynos_drm_gem_mmap_buffer(struct file *filp, if (vm_size > buffer->size) return -EINVAL; - return dma_mmap_attrs(obj->dev->dev, vma, buffer->kvaddr, + ret = dma_mmap_attrs(obj->dev->dev, vma, buffer->kvaddr, buffer->dma_addr, buffer->size, &buffer->dma_attrs); + if (ret < 0) { + DRM_ERROR("failed to mmap.\n"); + return ret; + } + + /* + * take a reference to this mapping of the object. And this reference + * is unreferenced by the corresponding vm_close call. + */ + drm_gem_object_reference(obj); + + mutex_lock(&obj->dev->struct_mutex); + drm_vm_open_locked(obj->dev, vma); + mutex_unlock(&obj->dev->struct_mutex); + + return 0; } static const struct file_operations exynos_drm_gem_fops = { @@ -426,6 +445,8 @@ int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data, addr = vm_mmap(obj->filp, 0, args->size, PROT_READ | PROT_WRITE, MAP_SHARED, 0); + /* restore it to drm_file object. */ + obj->filp->private_data = file_priv; drm_gem_object_unreference_unlocked(obj); if (IS_ERR((void *)addr))