Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/msm: Implement msm drm fb_mmap callback function

This change implements msm drm specific fb_mmap function for fb device
to properly map the fb address to userspace.

Signed-off-by: Hai Li <hali@codeaurora.org>
Signed-off-by: Stephane Viau <sviau@codeaurora.org>
Signed-off-by: Rob Clark <robdclark@gmail.com> (+ minor comment tweak)

authored by

Hai Li and committed by
Rob Clark
8f67da33 3bf6c1ec

+42 -3
+42 -3
drivers/gpu/drm/msm/msm_fbdev.c
··· 19 19 20 20 #include "drm_crtc.h" 21 21 #include "drm_fb_helper.h" 22 + #include "msm_gem.h" 23 + 24 + extern int msm_gem_mmap_obj(struct drm_gem_object *obj, 25 + struct vm_area_struct *vma); 26 + static int msm_fbdev_mmap(struct fb_info *info, struct vm_area_struct *vma); 22 27 23 28 /* 24 29 * fbdev funcs, to implement legacy fbdev interface on top of drm driver ··· 48 43 .fb_fillrect = sys_fillrect, 49 44 .fb_copyarea = sys_copyarea, 50 45 .fb_imageblit = sys_imageblit, 46 + .fb_mmap = msm_fbdev_mmap, 51 47 52 48 .fb_check_var = drm_fb_helper_check_var, 53 49 .fb_set_par = drm_fb_helper_set_par, ··· 56 50 .fb_blank = drm_fb_helper_blank, 57 51 .fb_setcmap = drm_fb_helper_setcmap, 58 52 }; 53 + 54 + static int msm_fbdev_mmap(struct fb_info *info, struct vm_area_struct *vma) 55 + { 56 + struct drm_fb_helper *helper = (struct drm_fb_helper *)info->par; 57 + struct msm_fbdev *fbdev = to_msm_fbdev(helper); 58 + struct drm_gem_object *drm_obj = fbdev->bo; 59 + struct drm_device *dev = helper->dev; 60 + int ret = 0; 61 + 62 + if (drm_device_is_unplugged(dev)) 63 + return -ENODEV; 64 + 65 + mutex_lock(&dev->struct_mutex); 66 + 67 + ret = drm_gem_mmap_obj(drm_obj, drm_obj->size, vma); 68 + 69 + mutex_unlock(&dev->struct_mutex); 70 + 71 + if (ret) { 72 + pr_err("%s:drm_gem_mmap_obj fail\n", __func__); 73 + return ret; 74 + } 75 + 76 + return msm_gem_mmap_obj(drm_obj, vma); 77 + } 59 78 60 79 static int msm_fbdev_create(struct drm_fb_helper *helper, 61 80 struct drm_fb_helper_surface_size *sizes) ··· 135 104 136 105 mutex_lock(&dev->struct_mutex); 137 106 138 - /* TODO implement our own fb_mmap so we don't need this: */ 139 - msm_gem_get_iova_locked(fbdev->bo, 0, &paddr); 107 + /* 108 + * NOTE: if we can be guaranteed to be able to map buffer 109 + * in panic (ie. lock-safe, etc) we could avoid pinning the 110 + * buffer now: 111 + */ 112 + ret = msm_gem_get_iova_locked(fbdev->bo, 0, &paddr); 113 + if (ret) { 114 + dev_err(dev->dev, "failed to get buffer obj iova: %d\n", ret); 115 + goto fail; 116 + } 140 117 141 118 fbi = framebuffer_alloc(0, dev->dev); 142 119 if (!fbi) { ··· 228 189 struct msm_drm_private *priv = dev->dev_private; 229 190 struct msm_fbdev *fbdev = NULL; 230 191 struct drm_fb_helper *helper; 231 - int ret = 0; 192 + int ret; 232 193 233 194 fbdev = kzalloc(sizeof(*fbdev), GFP_KERNEL); 234 195 if (!fbdev)