Subversion Repositories Kolibri OS

Rev

Rev 4280 | Rev 4560 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright © 2008 Intel Corporation
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a
  5.  * copy of this software and associated documentation files (the "Software"),
  6.  * to deal in the Software without restriction, including without limitation
  7.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8.  * and/or sell copies of the Software, and to permit persons to whom the
  9.  * Software is furnished to do so, subject to the following conditions:
  10.  *
  11.  * The above copyright notice and this permission notice (including the next
  12.  * paragraph) shall be included in all copies or substantial portions of the
  13.  * Software.
  14.  *
  15.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  18.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20.  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21.  * IN THE SOFTWARE.
  22.  *
  23.  * Authors:
  24.  *    Eric Anholt <eric@anholt.net>
  25.  *
  26.  */
  27.  
  28. #include <linux/types.h>
  29. #include <linux/slab.h>
  30. #include <linux/mm.h>
  31. #include <linux/module.h>
  32. #include <linux/shmem_fs.h>
  33. #include <linux/err.h>
  34. #include <drm/drmP.h>
  35. #include <drm/drm_vma_manager.h>
  36.  
  37. /** @file drm_gem.c
  38.  *
  39.  * This file provides some of the base ioctls and library routines for
  40.  * the graphics memory manager implemented by each device driver.
  41.  *
  42.  * Because various devices have different requirements in terms of
  43.  * synchronization and migration strategies, implementing that is left up to
  44.  * the driver, and all that the general API provides should be generic --
  45.  * allocating objects, reading/writing data with the cpu, freeing objects.
  46.  * Even there, platform-dependent optimizations for reading/writing data with
  47.  * the CPU mean we'll likely hook those out to driver-specific calls.  However,
  48.  * the DRI2 implementation wants to have at least allocate/mmap be generic.
  49.  *
  50.  * The goal was to have swap-backed object allocation managed through
  51.  * struct file.  However, file descriptors as handles to a struct file have
  52.  * two major failings:
  53.  * - Process limits prevent more than 1024 or so being used at a time by
  54.  *   default.
  55.  * - Inability to allocate high fds will aggravate the X Server's select()
  56.  *   handling, and likely that of many GL client applications as well.
  57.  *
  58.  * This led to a plan of using our own integer IDs (called handles, following
  59.  * DRM terminology) to mimic fds, and implement the fd syscalls we need as
  60.  * ioctls.  The objects themselves will still include the struct file so
  61.  * that we can transition to fds if the required kernel infrastructure shows
  62.  * up at a later date, and as our interface with shmfs for memory allocation.
  63.  */
  64.  
  65. /*
  66.  * We make up offsets for buffer objects so we can recognize them at
  67.  * mmap time.
  68.  */
  69.  
  70. /* pgoff in mmap is an unsigned long, so we need to make sure that
  71.  * the faked up offset will fit
  72.  */
  73.  
  74. #if BITS_PER_LONG == 64
  75. #define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFFUL >> PAGE_SHIFT) + 1)
  76. #define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFFUL >> PAGE_SHIFT) * 16)
  77. #else
  78. #define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFUL >> PAGE_SHIFT) + 1)
  79. #define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFUL >> PAGE_SHIFT) * 16)
  80. #endif
  81.  
  82. /**
  83.  * Initialize the GEM device fields
  84.  */
  85.  
  86. int
  87. drm_gem_init(struct drm_device *dev)
  88. {
  89.         struct drm_gem_mm *mm;
  90.  
  91.         mutex_init(&dev->object_name_lock);
  92.         idr_init(&dev->object_name_idr);
  93.  
  94.         mm = kzalloc(sizeof(struct drm_gem_mm), GFP_KERNEL);
  95.         if (!mm) {
  96.                 DRM_ERROR("out of memory\n");
  97.                 return -ENOMEM;
  98.         }
  99.  
  100.         dev->mm_private = mm;
  101.         drm_vma_offset_manager_init(&mm->vma_manager,
  102.                                     DRM_FILE_PAGE_OFFSET_START,
  103.                     DRM_FILE_PAGE_OFFSET_SIZE);
  104.  
  105.         return 0;
  106. }
  107.  
  108. void
  109. drm_gem_destroy(struct drm_device *dev)
  110. {
  111.         struct drm_gem_mm *mm = dev->mm_private;
  112.  
  113.         drm_vma_offset_manager_destroy(&mm->vma_manager);
  114.         kfree(mm);
  115.         dev->mm_private = NULL;
  116. }
  117.  
  118. /**
  119.  * Initialize an already allocated GEM object of the specified size with
  120.  * shmfs backing store.
  121.  */
  122. int drm_gem_object_init(struct drm_device *dev,
  123.                         struct drm_gem_object *obj, size_t size)
  124. {
  125.         struct file *filp;
  126.  
  127.         filp = shmem_file_setup("drm mm object", size, VM_NORESERVE);
  128.         if (IS_ERR(filp))
  129.                 return PTR_ERR(filp);
  130.  
  131.         drm_gem_private_object_init(dev, obj, size);
  132.         obj->filp = filp;
  133.  
  134.         return 0;
  135. }
  136. EXPORT_SYMBOL(drm_gem_object_init);
  137.  
  138. /**
  139.  * Initialize an already allocated GEM object of the specified size with
  140.  * no GEM provided backing store. Instead the caller is responsible for
  141.  * backing the object and handling it.
  142.  */
  143. void drm_gem_private_object_init(struct drm_device *dev,
  144.                         struct drm_gem_object *obj, size_t size)
  145. {
  146.         BUG_ON((size & (PAGE_SIZE - 1)) != 0);
  147.  
  148.         obj->dev = dev;
  149.         obj->filp = NULL;
  150.  
  151.         kref_init(&obj->refcount);
  152.         obj->handle_count = 0;
  153.         obj->size = size;
  154.         drm_vma_node_reset(&obj->vma_node);
  155. }
  156. EXPORT_SYMBOL(drm_gem_private_object_init);
  157.  
  158. /**
  159.  * Allocate a GEM object of the specified size with shmfs backing store
  160.  */
  161. struct drm_gem_object *
  162. drm_gem_object_alloc(struct drm_device *dev, size_t size)
  163. {
  164.         struct drm_gem_object *obj;
  165.  
  166.         obj = kzalloc(sizeof(*obj), GFP_KERNEL);
  167.         if (!obj)
  168.                 goto free;
  169.  
  170.         if (drm_gem_object_init(dev, obj, size) != 0)
  171.                 goto free;
  172.  
  173.         if (dev->driver->gem_init_object != NULL &&
  174.             dev->driver->gem_init_object(obj) != 0) {
  175.                 goto fput;
  176.         }
  177.         return obj;
  178. fput:
  179.         /* Object_init mangles the global counters - readjust them. */
  180.         free(obj->filp);
  181. free:
  182.         kfree(obj);
  183.         return NULL;
  184. }
  185. EXPORT_SYMBOL(drm_gem_object_alloc);
  186.  
  187. static void drm_gem_object_ref_bug(struct kref *list_kref)
  188. {
  189.         BUG();
  190. }
  191.  
  192. /**
  193.  * Called after the last handle to the object has been closed
  194.  *
  195.  * Removes any name for the object. Note that this must be
  196.  * called before drm_gem_object_free or we'll be touching
  197.  * freed memory
  198.  */
  199. static void drm_gem_object_handle_free(struct drm_gem_object *obj)
  200. {
  201.         struct drm_device *dev = obj->dev;
  202.  
  203.         /* Remove any name for this object */
  204.         if (obj->name) {
  205.                 idr_remove(&dev->object_name_idr, obj->name);
  206.                 obj->name = 0;
  207.                 /*
  208.                  * The object name held a reference to this object, drop
  209.                  * that now.
  210.                 *
  211.                 * This cannot be the last reference, since the handle holds one too.
  212.                  */
  213.                 kref_put(&obj->refcount, drm_gem_object_ref_bug);
  214.         }
  215. }
  216.  
  217.  
  218. static void
  219. drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj)
  220. {
  221.         if (WARN_ON(obj->handle_count == 0))
  222.                 return;
  223.  
  224.         /*
  225.         * Must bump handle count first as this may be the last
  226.         * ref, in which case the object would disappear before we
  227.         * checked for a name
  228.         */
  229.  
  230.         mutex_lock(&obj->dev->object_name_lock);
  231.         if (--obj->handle_count == 0) {
  232.                 drm_gem_object_handle_free(obj);
  233.         }
  234.         mutex_unlock(&obj->dev->object_name_lock);
  235.  
  236.         drm_gem_object_unreference_unlocked(obj);
  237. }
  238.  
  239. /**
  240.  * Removes the mapping from handle to filp for this object.
  241.  */
  242. int
  243. drm_gem_handle_delete(struct drm_file *filp, u32 handle)
  244. {
  245.         struct drm_device *dev;
  246.         struct drm_gem_object *obj;
  247.  
  248.         /* This is gross. The idr system doesn't let us try a delete and
  249.          * return an error code.  It just spews if you fail at deleting.
  250.          * So, we have to grab a lock around finding the object and then
  251.          * doing the delete on it and dropping the refcount, or the user
  252.          * could race us to double-decrement the refcount and cause a
  253.          * use-after-free later.  Given the frequency of our handle lookups,
  254.          * we may want to use ida for number allocation and a hash table
  255.          * for the pointers, anyway.
  256.          */
  257.         spin_lock(&filp->table_lock);
  258.  
  259.         /* Check if we currently have a reference on the object */
  260.         obj = idr_find(&filp->object_idr, handle);
  261.         if (obj == NULL) {
  262.                 spin_unlock(&filp->table_lock);
  263.                 return -EINVAL;
  264.         }
  265.         dev = obj->dev;
  266.  
  267.         /* Release reference and decrement refcount. */
  268.         idr_remove(&filp->object_idr, handle);
  269.         spin_unlock(&filp->table_lock);
  270.  
  271.  
  272.         if (dev->driver->gem_close_object)
  273.                 dev->driver->gem_close_object(obj, filp);
  274.         drm_gem_object_handle_unreference_unlocked(obj);
  275.  
  276.         return 0;
  277. }
  278. EXPORT_SYMBOL(drm_gem_handle_delete);
  279.  
  280. /**
  281.  * Create a handle for this object. This adds a handle reference
  282.  * to the object, which includes a regular reference count. Callers
  283.  * will likely want to dereference the object afterwards.
  284. /**
  285.  * drm_gem_handle_create_tail - internal functions to create a handle
  286.  *
  287.  * This expects the dev->object_name_lock to be held already and will drop it
  288.  * before returning. Used to avoid races in establishing new handles when
  289.  * importing an object from either an flink name or a dma-buf.
  290.  */
  291. int
  292. drm_gem_handle_create_tail(struct drm_file *file_priv,
  293.                        struct drm_gem_object *obj,
  294.                        u32 *handlep)
  295. {
  296.         struct drm_device *dev = obj->dev;
  297.         int ret;
  298.  
  299.         WARN_ON(!mutex_is_locked(&dev->object_name_lock));
  300.  
  301.         /*
  302.          * Get the user-visible handle using idr.  Preload and perform
  303.          * allocation under our spinlock.
  304.          */
  305.         idr_preload(GFP_KERNEL);
  306.         spin_lock(&file_priv->table_lock);
  307.  
  308.         ret = idr_alloc(&file_priv->object_idr, obj, 1, 0, GFP_NOWAIT);
  309.         drm_gem_object_reference(obj);
  310.         obj->handle_count++;
  311.         spin_unlock(&file_priv->table_lock);
  312.         idr_preload_end();
  313.         mutex_unlock(&dev->object_name_lock);
  314.         if (ret < 0) {
  315.                 drm_gem_object_handle_unreference_unlocked(obj);
  316.                 return ret;
  317.         }
  318.         *handlep = ret;
  319.  
  320.         if (dev->driver->gem_open_object) {
  321.                 ret = dev->driver->gem_open_object(obj, file_priv);
  322.                 if (ret) {
  323.                         drm_gem_handle_delete(file_priv, *handlep);
  324.                         return ret;
  325.                 }
  326.         }
  327.  
  328.         return 0;
  329. }
  330.  
  331. /**
  332.  * Create a handle for this object. This adds a handle reference
  333.  * to the object, which includes a regular reference count. Callers
  334.  * will likely want to dereference the object afterwards.
  335.  */
  336. int
  337. drm_gem_handle_create(struct drm_file *file_priv,
  338.                        struct drm_gem_object *obj,
  339.                        u32 *handlep)
  340. {
  341.         mutex_lock(&obj->dev->object_name_lock);
  342.  
  343.         return drm_gem_handle_create_tail(file_priv, obj, handlep);
  344. }
  345. EXPORT_SYMBOL(drm_gem_handle_create);
  346.  
  347.  
  348. /**
  349.  * drm_gem_free_mmap_offset - release a fake mmap offset for an object
  350.  * @obj: obj in question
  351.  *
  352.  * This routine frees fake offsets allocated by drm_gem_create_mmap_offset().
  353.  */
  354. #if 0
  355. void
  356. drm_gem_free_mmap_offset(struct drm_gem_object *obj)
  357. {
  358.         struct drm_device *dev = obj->dev;
  359.         struct drm_gem_mm *mm = dev->mm_private;
  360.  
  361.         drm_vma_offset_remove(&mm->vma_manager, &obj->vma_node);
  362. }
  363. EXPORT_SYMBOL(drm_gem_free_mmap_offset);
  364.  
  365. /**
  366.  * drm_gem_create_mmap_offset_size - create a fake mmap offset for an object
  367.  * @obj: obj in question
  368.  * @size: the virtual size
  369.  *
  370.  * GEM memory mapping works by handing back to userspace a fake mmap offset
  371.  * it can use in a subsequent mmap(2) call.  The DRM core code then looks
  372.  * up the object based on the offset and sets up the various memory mapping
  373.  * structures.
  374.  *
  375.  * This routine allocates and attaches a fake offset for @obj, in cases where
  376.  * the virtual size differs from the physical size (ie. obj->size).  Otherwise
  377.  * just use drm_gem_create_mmap_offset().
  378.  */
  379. int
  380. drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size)
  381. {
  382.         struct drm_device *dev = obj->dev;
  383.         struct drm_gem_mm *mm = dev->mm_private;
  384.  
  385.         /* Set the object up for mmap'ing */
  386.         list = &obj->map_list;
  387.         list->map = kzalloc(sizeof(struct drm_map_list), GFP_KERNEL);
  388.         if (!list->map)
  389.                 return -ENOMEM;
  390.  
  391.         map = list->map;
  392.         map->type = _DRM_GEM;
  393.         map->size = obj->size;
  394.         map->handle = obj;
  395.  
  396.         /* Get a DRM GEM mmap offset allocated... */
  397.         list->file_offset_node = drm_mm_search_free(&mm->offset_manager,
  398.                         obj->size / PAGE_SIZE, 0, false);
  399.  
  400.         if (!list->file_offset_node) {
  401.                 DRM_ERROR("failed to allocate offset for bo %d\n", obj->name);
  402.                 ret = -ENOSPC;
  403.                 goto out_free_list;
  404.         }
  405.  
  406.         list->file_offset_node = drm_mm_get_block(list->file_offset_node,
  407.                         obj->size / PAGE_SIZE, 0);
  408.         if (!list->file_offset_node) {
  409.                 ret = -ENOMEM;
  410.                 goto out_free_list;
  411.         }
  412.  
  413.         list->hash.key = list->file_offset_node->start;
  414.         ret = drm_ht_insert_item(&mm->offset_hash, &list->hash);
  415.         if (ret) {
  416.                 DRM_ERROR("failed to add to map hash\n");
  417.                 goto out_free_mm;
  418.         }
  419.  
  420.         return 0;
  421.  
  422. out_free_mm:
  423.         drm_mm_put_block(list->file_offset_node);
  424. out_free_list:
  425.         kfree(list->map);
  426.         list->map = NULL;
  427.  
  428.         return ret;
  429. }
  430. EXPORT_SYMBOL(drm_gem_create_mmap_offset);
  431. #endif
  432.  
  433. /** Returns a reference to the object named by the handle. */
  434. struct drm_gem_object *
  435. drm_gem_object_lookup(struct drm_device *dev, struct drm_file *filp,
  436.                       u32 handle)
  437. {
  438.         struct drm_gem_object *obj;
  439.  
  440.         spin_lock(&filp->table_lock);
  441.  
  442.         /* Check if we currently have a reference on the object */
  443.         obj = idr_find(&filp->object_idr, handle);
  444.         if (obj == NULL) {
  445.                 spin_unlock(&filp->table_lock);
  446.                 return NULL;
  447.         }
  448.  
  449.         drm_gem_object_reference(obj);
  450.  
  451.         spin_unlock(&filp->table_lock);
  452.  
  453.         return obj;
  454. }
  455. EXPORT_SYMBOL(drm_gem_object_lookup);
  456.  
  457. /**
  458.  * Releases the handle to an mm object.
  459.  */
  460. int
  461. drm_gem_close_ioctl(struct drm_device *dev, void *data,
  462.                     struct drm_file *file_priv)
  463. {
  464.         struct drm_gem_close *args = data;
  465.         int ret;
  466.  
  467.         ret = drm_gem_handle_delete(file_priv, args->handle);
  468.  
  469.         return ret;
  470. }
  471.  
  472. /**
  473.  * Create a global name for an object, returning the name.
  474.  *
  475.  * Note that the name does not hold a reference; when the object
  476.  * is freed, the name goes away.
  477.  */
  478. int
  479. drm_gem_flink_ioctl(struct drm_device *dev, void *data,
  480.                     struct drm_file *file_priv)
  481. {
  482.         struct drm_gem_flink *args = data;
  483.         struct drm_gem_object *obj;
  484.         int ret;
  485.  
  486.         if (!(dev->driver->driver_features & DRIVER_GEM))
  487.                 return -ENODEV;
  488.  
  489.         obj = drm_gem_object_lookup(dev, file_priv, args->handle);
  490.         if (obj == NULL)
  491.                 return -ENOENT;
  492.  
  493.         mutex_lock(&dev->object_name_lock);
  494.         idr_preload(GFP_KERNEL);
  495.         /* prevent races with concurrent gem_close. */
  496.         if (obj->handle_count == 0) {
  497.                 ret = -ENOENT;
  498.                 goto err;
  499.         }
  500.  
  501.         if (!obj->name) {
  502.                 ret = idr_alloc(&dev->object_name_idr, obj, 1, 0, GFP_NOWAIT);
  503.                 if (ret < 0)
  504.                         goto err;
  505.  
  506.                 obj->name = ret;
  507.  
  508.                 /* Allocate a reference for the name table.  */
  509.                 drm_gem_object_reference(obj);
  510.         }
  511.  
  512.                 args->name = (uint64_t) obj->name;
  513.                 ret = 0;
  514.  
  515. err:
  516.         idr_preload_end();
  517.         mutex_unlock(&dev->object_name_lock);
  518.         drm_gem_object_unreference_unlocked(obj);
  519.         return ret;
  520. }
  521.  
  522. /**
  523.  * Open an object using the global name, returning a handle and the size.
  524.  *
  525.  * This handle (of course) holds a reference to the object, so the object
  526.  * will not go away until the handle is deleted.
  527.  */
  528. int
  529. drm_gem_open_ioctl(struct drm_device *dev, void *data,
  530.                    struct drm_file *file_priv)
  531. {
  532.         struct drm_gem_open *args = data;
  533.         struct drm_gem_object *obj;
  534.         int ret;
  535.         u32 handle;
  536.  
  537.         if (!(dev->driver->driver_features & DRIVER_GEM))
  538.                 return -ENODEV;
  539.  
  540.         mutex_lock(&dev->object_name_lock);
  541.         obj = idr_find(&dev->object_name_idr, (int) args->name);
  542.         if (obj) {
  543.                 drm_gem_object_reference(obj);
  544.         } else {
  545.                 mutex_unlock(&dev->object_name_lock);
  546.                 return -ENOENT;
  547.         }
  548.  
  549.         /* drm_gem_handle_create_tail unlocks dev->object_name_lock. */
  550.         ret = drm_gem_handle_create_tail(file_priv, obj, &handle);
  551.         drm_gem_object_unreference_unlocked(obj);
  552.         if (ret)
  553.                 return ret;
  554.  
  555.         args->handle = handle;
  556.         args->size = obj->size;
  557.  
  558.         return 0;
  559. }
  560.  
  561. #if 0
  562. /**
  563.  * Called at device open time, sets up the structure for handling refcounting
  564.  * of mm objects.
  565.  */
  566. void
  567. drm_gem_open(struct drm_device *dev, struct drm_file *file_private)
  568. {
  569.         idr_init(&file_private->object_idr);
  570.         spin_lock_init(&file_private->table_lock);
  571. }
  572.  
  573. /**
  574.  * Called at device close to release the file's
  575.  * handle references on objects.
  576.  */
  577. static int
  578. drm_gem_object_release_handle(int id, void *ptr, void *data)
  579. {
  580.         struct drm_file *file_priv = data;
  581.         struct drm_gem_object *obj = ptr;
  582.         struct drm_device *dev = obj->dev;
  583.  
  584.         drm_gem_remove_prime_handles(obj, file_priv);
  585.         drm_vma_node_revoke(&obj->vma_node, file_priv->filp);
  586.  
  587.         if (dev->driver->gem_close_object)
  588.                 dev->driver->gem_close_object(obj, file_priv);
  589.  
  590.         drm_gem_object_handle_unreference_unlocked(obj);
  591.  
  592.         return 0;
  593. }
  594.  
  595. /**
  596.  * Called at close time when the filp is going away.
  597.  *
  598.  * Releases any remaining references on objects by this filp.
  599.  */
  600. void
  601. drm_gem_release(struct drm_device *dev, struct drm_file *file_private)
  602. {
  603.         idr_for_each(&file_private->object_idr,
  604.                      &drm_gem_object_release_handle, file_private);
  605.         idr_destroy(&file_private->object_idr);
  606. }
  607. #endif
  608.  
  609. void
  610. drm_gem_object_release(struct drm_gem_object *obj)
  611. {
  612.         if (obj->filp)
  613.             free(obj->filp);
  614. }
  615. EXPORT_SYMBOL(drm_gem_object_release);
  616.  
  617. /**
  618.  * Called after the last reference to the object has been lost.
  619.  * Must be called holding struct_ mutex
  620.  *
  621.  * Frees the object
  622.  */
  623. void
  624. drm_gem_object_free(struct kref *kref)
  625. {
  626.         struct drm_gem_object *obj = (struct drm_gem_object *) kref;
  627.         struct drm_device *dev = obj->dev;
  628.  
  629.         BUG_ON(!mutex_is_locked(&dev->struct_mutex));
  630.  
  631.         if (dev->driver->gem_free_object != NULL)
  632.                 dev->driver->gem_free_object(obj);
  633. }
  634. EXPORT_SYMBOL(drm_gem_object_free);
  635.  
  636.  
  637. #if 0
  638. void drm_gem_vm_open(struct vm_area_struct *vma)
  639. {
  640.         struct drm_gem_object *obj = vma->vm_private_data;
  641.  
  642.         drm_gem_object_reference(obj);
  643.  
  644.         mutex_lock(&obj->dev->struct_mutex);
  645.         drm_vm_open_locked(obj->dev, vma);
  646.         mutex_unlock(&obj->dev->struct_mutex);
  647. }
  648. EXPORT_SYMBOL(drm_gem_vm_open);
  649.  
  650. void drm_gem_vm_close(struct vm_area_struct *vma)
  651. {
  652.         struct drm_gem_object *obj = vma->vm_private_data;
  653.         struct drm_device *dev = obj->dev;
  654.  
  655.         mutex_lock(&dev->struct_mutex);
  656.         drm_vm_close_locked(obj->dev, vma);
  657.         drm_gem_object_unreference(obj);
  658.         mutex_unlock(&dev->struct_mutex);
  659. }
  660. EXPORT_SYMBOL(drm_gem_vm_close);
  661.  
  662. #endif
  663.  
  664.  
  665.  
  666.