History

drm/exynos: use drm generic mmap interface

This patch removes DRM_EXYNOS_GEM_MMAP ictrl feature specific to Exynos drm and instead uses drm generic mmap. We had used the interface specific to Exynos drm to do mmap directly, not to use demand paging which maps each page with physical memory at page fault handler. We don't need the specific mmap interface because the drm generic mmap which uses vm offset manager stuff can also do mmap directly. This patch makes a userspace region to be mapped with whole physical memory region allocated by userspace request when mmap system call is requested. Changelog v2: - do not set VM_IO, VM_DONTEXPEND and VM_DONTDUMP. These flags were already set by drm_gem_mmap - do not include <linux/anon_inodes.h>, which isn't needed anymore.

Inki Dae committed 12 years ago

Commit 832316c1 parent d9315895 files · +16 −132Browse files

Unified · Split

5 files
  1. drivers/gpu/drm/exynos/exynos_drm_drv.c +0 −26
  2. drivers/gpu/drm/exynos/exynos_drm_drv.h +0 −1
  3. drivers/gpu/drm/exynos/exynos_drm_gem.c +16 −73
  4. drivers/gpu/drm/exynos/exynos_drm_gem.h +0 −10
  5. include/uapi/drm/exynos_drm.h +0 −22
drivers/gpu/drm/exynos/exynos_drm_drv.c+0−26
@@ -15,7 +15,6 @@ · 14 unmodified lines
1515 #include <drm/drmP.h>
1616 #include <drm/drm_crtc_helper.h>
1717
18−#include <linux/anon_inodes.h>
1918 #include <linux/component.h>
2019
2120 #include <drm/exynos_drm.h>
@@ -166,10 +165,6 @@ static int exynos_drm_unload(struct drm_device *dev) · 144 unmodified lines
166165 return 0;
167166 }
168167
169−static const struct file_operations exynos_drm_gem_fops = {
170− .mmap = exynos_drm_gem_mmap_buffer,
171−};
172−
173168 static int exynos_drm_suspend(struct drm_device *dev, pm_message_t state)
174169 {
175170 struct drm_connector *connector;
@@ -208,7 +203,6 @@ static int exynos_drm_resume(struct drm_device *dev) · 32 unmodified lines
208203 static int exynos_drm_open(struct drm_device *dev, struct drm_file *file)
209204 {
210205 struct drm_exynos_file_private *file_priv;
211− struct file *anon_filp;
212206 int ret;
213207
214208 file_priv = kzalloc(sizeof(*file_priv), GFP_KERNEL);
@@ -221,21 +215,8 @@ static int exynos_drm_open(struct drm_device *dev, struct drm_file *file) · 6 unmodified lines
221215 if (ret)
222216 goto err_file_priv_free;
223217
224− anon_filp = anon_inode_getfile("exynos_gem", &exynos_drm_gem_fops,
225− NULL, 0);
226− if (IS_ERR(anon_filp)) {
227− ret = PTR_ERR(anon_filp);
228− goto err_subdrv_close;
229− }
230−
231− anon_filp->f_mode = FMODE_READ | FMODE_WRITE;
232− file_priv->anon_filp = anon_filp;
233−
234218 return ret;
235219
236−err_subdrv_close:
237− exynos_drm_subdrv_close(dev, file);
238−
239220 err_file_priv_free:
240221 kfree(file_priv);
241222 file->driver_priv = NULL;
@@ -251,7 +232,6 @@ static void exynos_drm_preclose(struct drm_device *dev, · 9 unmodified lines
251232 static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file)
252233 {
253234 struct exynos_drm_private *private = dev->dev_private;
254− struct drm_exynos_file_private *file_priv;
255235 struct drm_pending_vblank_event *v, *vt;
256236 struct drm_pending_event *e, *et;
257237 unsigned long flags;
@@ -277,10 +257,6 @@ static void exynos_drm_postclose(struct drm_device *dev, struct drm_file *file) · 19 unmodified lines
277257 }
278258 spin_unlock_irqrestore(&dev->event_lock, flags);
279259
280− file_priv = file->driver_priv;
281− if (file_priv->anon_filp)
282− fput(file_priv->anon_filp);
283−
284260 kfree(file->driver_priv);
285261 file->driver_priv = NULL;
286262 }
@@ -299,8 +275,6 @@ static const struct vm_operations_struct exynos_drm_gem_vm_ops = { · 12 unmodified lines
299275 static const struct drm_ioctl_desc exynos_ioctls[] = {
300276 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_CREATE, exynos_drm_gem_create_ioctl,
301277 DRM_UNLOCKED | DRM_AUTH),
302− DRM_IOCTL_DEF_DRV(EXYNOS_GEM_MMAP,
303− exynos_drm_gem_mmap_ioctl, DRM_UNLOCKED | DRM_AUTH),
304278 DRM_IOCTL_DEF_DRV(EXYNOS_GEM_GET,
305279 exynos_drm_gem_get_ioctl, DRM_UNLOCKED),
306280 DRM_IOCTL_DEF_DRV(EXYNOS_VIDI_CONNECTION,
drivers/gpu/drm/exynos/exynos_drm_drv.h+0−1
@@ -240,7 +240,6 @@ struct exynos_drm_g2d_private { · 239 unmodified lines
240240 struct drm_exynos_file_private {
241241 struct exynos_drm_g2d_private *g2d_priv;
242242 struct device *ipp_dev;
243− struct file *anon_filp;
244243 };
245244
246245 /*
drivers/gpu/drm/exynos/exynos_drm_gem.c+16−73
@@ -318,23 +318,16 @@ void exynos_drm_gem_put_dma_addr(struct drm_device *dev, · 317 unmodified lines
318318 drm_gem_object_unreference_unlocked(obj);
319319 }
320320
321−int exynos_drm_gem_mmap_buffer(struct file *filp,
321+int exynos_drm_gem_mmap_buffer(struct exynos_drm_gem_obj *exynos_gem_obj,
322322 struct vm_area_struct *vma)
323323 {
324− struct drm_gem_object *obj = filp->private_data;
325− struct exynos_drm_gem_obj *exynos_gem_obj = to_exynos_gem_obj(obj);
326− struct drm_device *drm_dev = obj->dev;
324+ struct drm_device *drm_dev = exynos_gem_obj->base.dev;
327325 struct exynos_drm_gem_buf *buffer;
328326 unsigned long vm_size;
329327 int ret;
330328
331− WARN_ON(!mutex_is_locked(&obj->dev->struct_mutex));
332−
333− vma->vm_flags |= VM_IO | VM_DONTEXPAND | VM_DONTDUMP;
334− vma->vm_private_data = obj;
335− vma->vm_ops = drm_dev->driver->gem_vm_ops;
336−
337− update_vm_cache_attr(exynos_gem_obj, vma);
329+ vma->vm_flags &= ~VM_PFNMAP;
330+ vma->vm_pgoff = 0;
338331
339332 vm_size = vma->vm_end - vma->vm_start;
340333
@@ -356,60 +349,6 @@ int exynos_drm_gem_mmap_buffer(struct file *filp, · 15 unmodified lines
356349 return ret;
357350 }
358351
359− /*
360− * take a reference to this mapping of the object. And this reference
361− * is unreferenced by the corresponding vm_close call.
362− */
363− drm_gem_object_reference(obj);
364−
365− drm_vm_open_locked(drm_dev, vma);
366−
367− return 0;
368−}
369−
370−int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
371− struct drm_file *file_priv)
372−{
373− struct drm_exynos_file_private *exynos_file_priv;
374− struct drm_exynos_gem_mmap *args = data;
375− struct drm_gem_object *obj;
376− struct file *anon_filp;
377− unsigned long addr;
378−
379− if (!(dev->driver->driver_features & DRIVER_GEM)) {
380− DRM_ERROR("does not support GEM.\n");
381− return -ENODEV;
382− }
383−
384− mutex_lock(&dev->struct_mutex);
385−
386− obj = drm_gem_object_lookup(dev, file_priv, args->handle);
387− if (!obj) {
388− DRM_ERROR("failed to lookup gem object.\n");
389− mutex_unlock(&dev->struct_mutex);
390− return -EINVAL;
391− }
392−
393− exynos_file_priv = file_priv->driver_priv;
394− anon_filp = exynos_file_priv->anon_filp;
395− anon_filp->private_data = obj;
396−
397− addr = vm_mmap(anon_filp, 0, args->size, PROT_READ | PROT_WRITE,
398− MAP_SHARED, 0);
399−
400− drm_gem_object_unreference(obj);
401−
402− if (IS_ERR_VALUE(addr)) {
403− mutex_unlock(&dev->struct_mutex);
404− return (int)addr;
405− }
406−
407− mutex_unlock(&dev->struct_mutex);
408−
409− args->mapped = addr;
410−
411− DRM_DEBUG_KMS("mapped = 0x%lx\n", (unsigned long)args->mapped);
412−
413352 return 0;
414353 }
415354
@@ -693,16 +632,20 @@ int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) · 277 unmodified lines
693632 exynos_gem_obj = to_exynos_gem_obj(obj);
694633
695634 ret = check_gem_flags(exynos_gem_obj->flags);
696− if (ret) {
697− drm_gem_vm_close(vma);
698− drm_gem_free_mmap_offset(obj);
699− return ret;
700− }
701−
702− vma->vm_flags &= ~VM_PFNMAP;
703− vma->vm_flags |= VM_MIXEDMAP;
635+ if (ret)
636+ goto err_close_vm;
704637
705638 update_vm_cache_attr(exynos_gem_obj, vma);
706639
640+ ret = exynos_drm_gem_mmap_buffer(exynos_gem_obj, vma);
641+ if (ret)
642+ goto err_close_vm;
643+
644+ return ret;
645+
646+err_close_vm:
647+ drm_gem_vm_close(vma);
648+ drm_gem_free_mmap_offset(obj);
649+
707650 return ret;
708651 }
drivers/gpu/drm/exynos/exynos_drm_gem.h+0−10
@@ -111,16 +111,6 @@ void exynos_drm_gem_put_dma_addr(struct drm_device *dev, · 110 unmodified lines
111111 unsigned int gem_handle,
112112 struct drm_file *filp);
113113
114−/*
115− * mmap the physically continuous memory that a gem object contains
116− * to user space.
117− */
118−int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
119− struct drm_file *file_priv);
120−
121−int exynos_drm_gem_mmap_buffer(struct file *filp,
122− struct vm_area_struct *vma);
123−
124114 /* map user space allocated by malloc to pages. */
125115 int exynos_drm_gem_userptr_ioctl(struct drm_device *dev, void *data,
126116 struct drm_file *file_priv);
include/uapi/drm/exynos_drm.h+0−22
@@ -32,24 +32,6 @@ struct drm_exynos_gem_create { · 31 unmodified lines
3232 unsigned int handle;
3333 };
3434
35−/**
36− * A structure for mapping buffer.
37− *
38− * @handle: a handle to gem object created.
39− * @pad: just padding to be 64-bit aligned.
40− * @size: memory size to be mapped.
41− * @mapped: having user virtual address mmaped.
42− * - this variable would be filled by exynos gem module
43− * of kernel side with user virtual address which is allocated
44− * by do_mmap().
45− */
46−struct drm_exynos_gem_mmap {
47− unsigned int handle;
48− unsigned int pad;
49− uint64_t size;
50− uint64_t mapped;
51−};
52−
5335 /**
5436 * A structure to gem information.
5537 *
@@ -302,7 +284,6 @@ struct drm_exynos_ipp_cmd_ctrl { · 246 unmodified lines
302284 };
303285
304286 #define DRM_EXYNOS_GEM_CREATE 0x00
305−#define DRM_EXYNOS_GEM_MMAP 0x02
306287 /* Reserved 0x03 ~ 0x05 for exynos specific gem ioctl */
307288 #define DRM_EXYNOS_GEM_GET 0x04
308289 #define DRM_EXYNOS_VIDI_CONNECTION 0x07
@@ -321,9 +302,6 @@ struct drm_exynos_ipp_cmd_ctrl { · 12 unmodified lines
321302 #define DRM_IOCTL_EXYNOS_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + \
322303 DRM_EXYNOS_GEM_CREATE, struct drm_exynos_gem_create)
323304
324−#define DRM_IOCTL_EXYNOS_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + \
325− DRM_EXYNOS_GEM_MMAP, struct drm_exynos_gem_mmap)
326−
327305 #define DRM_IOCTL_EXYNOS_GEM_GET DRM_IOWR(DRM_COMMAND_BASE + \
328306 DRM_EXYNOS_GEM_GET, struct drm_exynos_gem_info)
329307

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t