28 #include <linux/types.h>
29 #include <linux/slab.h>
34 #include <linux/module.h>
35 #include <linux/mman.h>
78 #if BITS_PER_LONG == 64
79 #define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFFUL >> PAGE_SHIFT) + 1)
80 #define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFFUL >> PAGE_SHIFT) * 16)
82 #define DRM_FILE_PAGE_OFFSET_START ((0xFFFFFFFUL >> PAGE_SHIFT) + 1)
83 #define DRM_FILE_PAGE_OFFSET_SIZE ((0xFFFFFFFUL >> PAGE_SHIFT) * 16)
93 struct drm_gem_mm *mm;
98 mm = kzalloc(
sizeof(
struct drm_gem_mm),
GFP_KERNEL);
100 DRM_ERROR(
"out of memory\n");
104 dev->mm_private = mm;
124 struct drm_gem_mm *mm = dev->mm_private;
129 dev->mm_private =
NULL;
137 struct drm_gem_object *obj,
size_t size)
143 if (IS_ERR(obj->filp))
144 return PTR_ERR(obj->filp);
146 kref_init(&obj->refcount);
160 struct drm_gem_object *obj,
size_t size)
167 kref_init(&obj->refcount);
178 struct drm_gem_object *
181 struct drm_gem_object *obj;
190 if (dev->driver->gem_init_object !=
NULL &&
191 dev->driver->gem_init_object(obj) != 0) {
205 drm_gem_remove_prime_handles(
struct drm_gem_object *obj,
struct drm_file *filp)
207 if (obj->import_attach) {
209 obj->import_attach->dmabuf);
211 if (obj->export_dma_buf) {
213 obj->export_dma_buf);
224 struct drm_gem_object *obj;
235 spin_lock(&filp->table_lock);
238 obj =
idr_find(&filp->object_idr, handle);
240 spin_unlock(&filp->table_lock);
247 spin_unlock(&filp->table_lock);
249 drm_gem_remove_prime_handles(obj, filp);
251 if (dev->driver->gem_close_object)
252 dev->driver->gem_close_object(obj, filp);
253 drm_gem_object_handle_unreference_unlocked(obj);
266 struct drm_gem_object *obj,
281 spin_lock(&file_priv->table_lock);
283 spin_unlock(&file_priv->table_lock);
289 drm_gem_object_handle_reference(obj);
291 if (dev->driver->gem_open_object) {
292 ret = dev->driver->gem_open_object(obj, file_priv);
314 struct drm_gem_mm *mm = dev->mm_private;
315 struct drm_map_list *
list = &obj->map_list;
339 struct drm_gem_mm *mm = dev->mm_private;
340 struct drm_map_list *
list;
341 struct drm_local_map *
map;
345 list = &obj->map_list;
346 list->map = kzalloc(
sizeof(
struct drm_map_list),
GFP_KERNEL);
352 map->size = obj->size;
356 list->file_offset_node = drm_mm_search_free(&mm->offset_manager,
359 if (!list->file_offset_node) {
360 DRM_ERROR(
"failed to allocate offset for bo %d\n", obj->name);
365 list->file_offset_node = drm_mm_get_block(list->file_offset_node,
367 if (!list->file_offset_node) {
372 list->hash.key = list->file_offset_node->start;
375 DRM_ERROR(
"failed to add to map hash\n");
392 struct drm_gem_object *
396 struct drm_gem_object *obj;
398 spin_lock(&filp->table_lock);
401 obj =
idr_find(&filp->object_idr, handle);
403 spin_unlock(&filp->table_lock);
407 drm_gem_object_reference(obj);
409 spin_unlock(&filp->table_lock);
420 struct drm_file *file_priv)
425 if (!(dev->driver->driver_features & DRIVER_GEM))
441 struct drm_file *file_priv)
444 struct drm_gem_object *obj;
447 if (!(dev->driver->driver_features & DRIVER_GEM))
460 spin_lock(&dev->object_name_lock);
465 spin_unlock(&dev->object_name_lock);
473 drm_gem_object_reference(obj);
476 spin_unlock(&dev->object_name_lock);
481 drm_gem_object_unreference_unlocked(obj);
493 struct drm_file *file_priv)
496 struct drm_gem_object *obj;
500 if (!(dev->driver->driver_features & DRIVER_GEM))
503 spin_lock(&dev->object_name_lock);
504 obj =
idr_find(&dev->object_name_idr, (
int) args->
name);
506 drm_gem_object_reference(obj);
507 spin_unlock(&dev->object_name_lock);
512 drm_gem_object_unreference_unlocked(obj);
517 args->
size = obj->size;
529 idr_init(&file_private->object_idr);
538 drm_gem_object_release_handle(
int id,
void *
ptr,
void *
data)
540 struct drm_file *file_priv =
data;
541 struct drm_gem_object *obj =
ptr;
544 drm_gem_remove_prime_handles(obj, file_priv);
546 if (dev->driver->gem_close_object)
547 dev->driver->gem_close_object(obj, file_priv);
549 drm_gem_object_handle_unreference_unlocked(obj);
563 &drm_gem_object_release_handle, file_private);
586 struct drm_gem_object *obj = (
struct drm_gem_object *) kref;
589 BUG_ON(!mutex_is_locked(&dev->struct_mutex));
591 if (dev->driver->gem_free_object !=
NULL)
592 dev->driver->gem_free_object(obj);
596 static void drm_gem_object_ref_bug(
struct kref *list_kref)
613 spin_lock(&dev->object_name_lock);
617 spin_unlock(&dev->object_name_lock);
624 kref_put(&obj->refcount, drm_gem_object_ref_bug);
626 spin_unlock(&dev->object_name_lock);
635 drm_gem_object_reference(obj);
650 drm_gem_object_unreference(obj);
674 struct drm_gem_mm *mm = dev->mm_private;
675 struct drm_local_map *
map =
NULL;
676 struct drm_gem_object *obj;
680 if (drm_device_is_unplugged(dev))
704 if (!obj->dev->driver->gem_vm_ops) {
709 vma->
vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP;
710 vma->
vm_ops = obj->dev->driver->gem_vm_ops;
720 drm_gem_object_reference(obj);