From patchwork Wed Nov 30 13:19:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 85867 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp225066qgi; Wed, 30 Nov 2016 05:19:59 -0800 (PST) X-Received: by 10.99.175.26 with SMTP id w26mr59415353pge.144.1480511999406; Wed, 30 Nov 2016 05:19:59 -0800 (PST) Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id x6si64427184pgx.75.2016.11.30.05.19.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Nov 2016 05:19:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4258C6E2F3; Wed, 30 Nov 2016 13:19:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x236.google.com (mail-wm0-x236.google.com [IPv6:2a00:1450:400c:c09::236]) by gabe.freedesktop.org (Postfix) with ESMTPS id 527EF6E145 for ; Wed, 30 Nov 2016 13:19:26 +0000 (UTC) Received: by mail-wm0-x236.google.com with SMTP id c184so53850045wmd.0 for ; Wed, 30 Nov 2016 05:19:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=wwPpbXAsdZHYhWsS0QGQsvc4YEvt1sh37gq5/E3OuJw=; b=e3em1XwWuBGvq67sMOM4f3DiNHHAFs4FmcxUR46bgZ4nxCfqrITBtXHFOoVUOdg4T2 aj4p/SeQTYyatmbLjufNw+kEjJYXsbdebsvimR0BlUXfH3JG168YVfCncvZ0sNVDqQoC C6uLsRJZdOSIgcvCq9rvLe2c0HF2KQ6SFo43U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=wwPpbXAsdZHYhWsS0QGQsvc4YEvt1sh37gq5/E3OuJw=; b=GiFAfKKXloP45yp3HwwdOBBiy94KtKHxC812Ug2P6CFIFVWmdOVQvK096yGFU0vb3B 8j1J3x1NuD/eDOaSwjhqkeTnMxG4muH4ZVsKMHAvIiiCn0xuk1iiStF4JL7dkMhS5knM Ss1phAduiV6HF4lVzGiUgUsNNTKK2Mms3IDFnVGgkp7SeYwH3xA41z7Ttizq9N1U1VqB Rd8eJq9DOK2u+7AmBal7cqheXjcvZuyC+gflU6GVR0I+N83QZTngVDhESeR5ScwUfP5n vUP0r3pxgAlmbHWqr+5k1weXaEVOhyfZOypMJBtirQOHGLJknNz3yJoPYEvuAspcX3k7 UjuA== X-Gm-Message-State: AKaTC01fOmCv26Lbg8r0hnpaamCC+SF4uB/9l0GiOrRifNgMIdQsJoGsI9GLP+nVKNg7o3Dl X-Received: by 10.28.148.81 with SMTP id w78mr9685934wmd.42.1480511964602; Wed, 30 Nov 2016 05:19:24 -0800 (PST) Received: from lmenx321.st.com. ([80.215.92.72]) by smtp.gmail.com with ESMTPSA id d8sm7960836wmi.21.2016.11.30.05.19.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Nov 2016 05:19:24 -0800 (PST) From: Benjamin Gaignard To: dri-devel@lists.freedesktop.org, airlied@redhat.com, daniel@ffwll.ch, robdclark@gmail.com, laurent.pinchart@ideasonboard.com Subject: [RFC v2 1/1] drm: allow to use mmuless SoC Date: Wed, 30 Nov 2016 14:19:18 +0100 Message-Id: <1480511958-10266-1-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 Cc: yannick.fertre@st.com, linaro-kernel@lists.linaro.org, philippe.cornu@st.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development 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" Some SoC without MMU have display driver where a drm/kms driver could be implemented. Before doing such kind of thing drm/kms must allow to use mmuless devices. This patch propose to remove MMU configuration flag and add some cma helpers functions to help implementing mmuless display driver version 2: - define get_fb_unmapped_area() in drivers/video/fbdev/core/fbmem.c if HAVE_ARCH_FB_UNMAPPED_AREA is set and get_fb_unmapped_area not already defined in the architecture Signed-off-by: Benjamin Gaignard --- drivers/gpu/drm/Kconfig | 4 +-- drivers/gpu/drm/drm_fb_cma_helper.c | 4 +++ drivers/gpu/drm/drm_gem_cma_helper.c | 62 ++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_vm.c | 4 +++ drivers/video/fbdev/core/fbmem.c | 15 +++++++++ include/drm/drm_gem_cma_helper.h | 6 ++++ 6 files changed, 93 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 8d9cf73..36c102b 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -6,7 +6,7 @@ # menuconfig DRM tristate "Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)" - depends on (AGP || AGP=n) && !EMULATED_CMPXCHG && MMU && HAS_DMA + depends on (AGP || AGP=n) && !EMULATED_CMPXCHG && HAS_DMA select HDMI select FB_CMDLINE select I2C @@ -98,7 +98,7 @@ config DRM_LOAD_EDID_FIRMWARE config DRM_TTM tristate - depends on DRM + depends on DRM && MMU help GPU memory management subsystem for devices with multiple GPU memory types. Will be enabled automatically if a device driver diff --git a/drivers/gpu/drm/drm_fb_cma_helper.c b/drivers/gpu/drm/drm_fb_cma_helper.c index 81b3558..b1414b6 100644 --- a/drivers/gpu/drm/drm_fb_cma_helper.c +++ b/drivers/gpu/drm/drm_fb_cma_helper.c @@ -343,8 +343,12 @@ int drm_fb_cma_debugfs_show(struct seq_file *m, void *arg) static int drm_fb_cma_mmap(struct fb_info *info, struct vm_area_struct *vma) { +#ifdef CONFIG_MMU return dma_mmap_writecombine(info->device, vma, info->screen_base, info->fix.smem_start, info->fix.smem_len); +#else + return vm_iomap_memory(vma, vma->vm_start, info->fix.smem_len); +#endif } static struct fb_ops drm_fbdev_cma_ops = { diff --git a/drivers/gpu/drm/drm_gem_cma_helper.c b/drivers/gpu/drm/drm_gem_cma_helper.c index 1d6c335..de13535 100644 --- a/drivers/gpu/drm/drm_gem_cma_helper.c +++ b/drivers/gpu/drm/drm_gem_cma_helper.c @@ -318,11 +318,16 @@ static int drm_gem_cma_mmap_obj(struct drm_gem_cma_object *cma_obj, vma->vm_flags &= ~VM_PFNMAP; vma->vm_pgoff = 0; +#ifdef CONFIG_MMU ret = dma_mmap_wc(cma_obj->base.dev->dev, vma, cma_obj->vaddr, cma_obj->paddr, vma->vm_end - vma->vm_start); if (ret) drm_gem_vm_close(vma); +#else + ret = vm_iomap_memory(vma, vma->vm_start, + (vma->vm_end - vma->vm_start)); +#endif return ret; } @@ -358,6 +363,63 @@ int drm_gem_cma_mmap(struct file *filp, struct vm_area_struct *vma) } EXPORT_SYMBOL_GPL(drm_gem_cma_mmap); +#ifdef CONFIG_MMU +#define drm_gem_cma_get_unmapped_area NULL +#else +unsigned long drm_gem_cma_get_unmapped_area(struct file *filp, + unsigned long addr, + unsigned long len, + unsigned long pgoff, + unsigned long flags) +{ + struct drm_gem_cma_object *cma_obj; + struct drm_gem_object *obj = NULL; + struct drm_file *priv = filp->private_data; + struct drm_device *dev = priv->minor->dev; + struct drm_vma_offset_node *node; + + if (drm_device_is_unplugged(dev)) + return -ENODEV; + + drm_vma_offset_lock_lookup(dev->vma_offset_manager); + node = drm_vma_offset_exact_lookup_locked(dev->vma_offset_manager, + pgoff, + len >> PAGE_SHIFT); + if (likely(node)) { + obj = container_of(node, struct drm_gem_object, vma_node); + /* + * When the object is being freed, after it hits 0-refcnt it + * proceeds to tear down the object. In the process it will + * attempt to remove the VMA offset and so acquire this + * mgr->vm_lock. Therefore if we find an object with a 0-refcnt + * that matches our range, we know it is in the process of being + * destroyed and will be freed as soon as we release the lock - + * so we have to check for the 0-refcnted object and treat it as + * invalid. + */ + if (!kref_get_unless_zero(&obj->refcount)) + obj = NULL; + } + + drm_vma_offset_unlock_lookup(dev->vma_offset_manager); + + if (!obj) + return -EINVAL; + + if (!drm_vma_node_is_allowed(node, priv)) { + drm_gem_object_unreference_unlocked(obj); + return -EACCES; + } + + cma_obj = to_drm_gem_cma_obj(obj); + + drm_gem_object_unreference_unlocked(obj); + + return cma_obj->vaddr ? (unsigned long)cma_obj->vaddr : -EINVAL; +} +#endif +EXPORT_SYMBOL_GPL(drm_gem_cma_get_unmapped_area); + #ifdef CONFIG_DEBUG_FS /** * drm_gem_cma_describe - describe a CMA GEM object for debugfs diff --git a/drivers/gpu/drm/drm_vm.c b/drivers/gpu/drm/drm_vm.c index caa4e4c..974e02b 100644 --- a/drivers/gpu/drm/drm_vm.c +++ b/drivers/gpu/drm/drm_vm.c @@ -489,6 +489,7 @@ static int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma) #if defined(__i386__) || defined(__x86_64__) pgprot_val(vma->vm_page_prot) &= ~_PAGE_RW; #else +#ifdef CONFIG_MMU /* Ye gads this is ugly. With more thought we could move this up higher and use `protection_map' instead. */ @@ -497,6 +498,7 @@ static int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma) (pte_wrprotect (__pte(pgprot_val(vma->vm_page_prot))))); #endif +#endif } vma->vm_ops = &drm_vm_dma_ops; @@ -573,6 +575,7 @@ static int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma) #if defined(__i386__) || defined(__x86_64__) pgprot_val(vma->vm_page_prot) &= ~_PAGE_RW; #else +#ifdef CONFIG_MMU /* Ye gads this is ugly. With more thought we could move this up higher and use `protection_map' instead. */ @@ -581,6 +584,7 @@ static int drm_mmap_locked(struct file *filp, struct vm_area_struct *vma) (pte_wrprotect (__pte(pgprot_val(vma->vm_page_prot))))); #endif +#endif } switch (map->type) { diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index 76c1ad9..54488ee 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -1492,6 +1492,21 @@ static long fb_compat_ioctl(struct file *file, unsigned int cmd, return 0; } +#if defined(HAVE_ARCH_FB_UNMAPPED_AREA) && !defined(get_fb_unmapped_area) +unsigned long get_fb_unmapped_area(struct file *filp, + unsigned long addr, unsigned long len, + unsigned long pgoff, unsigned long flags) +{ + struct fb_info * const info = filp->private_data; + unsigned long fb_size = PAGE_ALIGN(info->fix.smem_len); + + if (pgoff > fb_size || len > fb_size - pgoff) + return -EINVAL; + + return (unsigned long)info->screen_base + pgoff; +} +#endif + static const struct file_operations fb_fops = { .owner = THIS_MODULE, .read = fb_read, diff --git a/include/drm/drm_gem_cma_helper.h b/include/drm/drm_gem_cma_helper.h index acd6af8..177a20d 100644 --- a/include/drm/drm_gem_cma_helper.h +++ b/include/drm/drm_gem_cma_helper.h @@ -53,6 +53,12 @@ struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm, extern const struct vm_operations_struct drm_gem_cma_vm_ops; +unsigned long drm_gem_cma_get_unmapped_area(struct file *filp, + unsigned long addr, + unsigned long len, + unsigned long pgoff, + unsigned long flags); + #ifdef CONFIG_DEBUG_FS void drm_gem_cma_describe(struct drm_gem_cma_object *obj, struct seq_file *m); #endif