diff options
Diffstat (limited to 'linux-core')
-rw-r--r-- | linux-core/drmP.h | 26 | ||||
-rw-r--r-- | linux-core/drm_gem.c | 45 | ||||
-rw-r--r-- | linux-core/i915_gem.c | 44 |
3 files changed, 53 insertions, 62 deletions
diff --git a/linux-core/drmP.h b/linux-core/drmP.h index 0df9f19b..d2dc065a 100644 --- a/linux-core/drmP.h +++ b/linux-core/drmP.h @@ -740,10 +740,8 @@ struct drm_driver { * * Returns 0 on success. */ - int (*gem_init_object) (struct drm_device *dev, - struct drm_gem_object *obj); - void (*gem_free_object) (struct drm_device *dev, - struct drm_gem_object *obj); + int (*gem_init_object) (struct drm_gem_object *obj); + void (*gem_free_object) (struct drm_gem_object *obj); struct drm_fence_driver *fence_driver; struct drm_bo_driver *bo_driver; @@ -1307,11 +1305,23 @@ static inline struct drm_memrange *drm_get_mm(struct drm_memrange_node *block) return block->mm; } +void +drm_gem_object_free (struct kref *kref); + /* Graphics Execution Manager library functions (drm_gem.c) */ -void drm_gem_object_reference(struct drm_device *dev, - struct drm_gem_object *obj); -void drm_gem_object_unreference(struct drm_device *dev, - struct drm_gem_object *obj); +static inline void drm_gem_object_reference(struct drm_gem_object *obj) +{ + kref_get(&obj->refcount); +} + +static inline void drm_gem_object_unreference(struct drm_gem_object *obj) +{ + if (obj == NULL) + return; + + kref_put (&obj->refcount, drm_gem_object_free); +} + struct drm_gem_object * drm_gem_object_lookup(struct drm_device *dev, struct drm_file *filp, int handle); diff --git a/linux-core/drm_gem.c b/linux-core/drm_gem.c index 41976bc7..80e8657b 100644 --- a/linux-core/drm_gem.c +++ b/linux-core/drm_gem.c @@ -84,7 +84,7 @@ drm_gem_object_alloc(struct drm_device *dev, size_t size) obj->size = size; if (dev->driver->gem_init_object != NULL && - dev->driver->gem_init_object(dev, obj) != 0) { + dev->driver->gem_init_object(obj) != 0) { fput(obj->filp); kfree(obj); return NULL; @@ -121,7 +121,7 @@ drm_gem_handle_delete(struct drm_device *dev, struct drm_file *filp, /* Release reference and decrement refcount. */ idr_remove(&filp->object_idr, handle); - drm_gem_object_unreference(dev, obj); + drm_gem_object_unreference(obj); spin_unlock(&filp->table_lock); @@ -144,7 +144,7 @@ drm_gem_object_lookup(struct drm_device *dev, struct drm_file *filp, return NULL; } - drm_gem_object_reference(dev, obj); + drm_gem_object_reference(obj); spin_unlock(&filp->table_lock); @@ -189,7 +189,7 @@ drm_gem_alloc_ioctl(struct drm_device *dev, void *data, } while (ret == -EAGAIN); if (ret != 0) { - drm_gem_object_unreference(dev, obj); + drm_gem_object_unreference(obj); return -EFAULT; } @@ -236,14 +236,14 @@ drm_gem_pread_ioctl(struct drm_device *dev, void *data, read = obj->filp->f_op->read(obj->filp, (char __user *)(uintptr_t)args->data_ptr, args->size, &offset); if (read != args->size) { - drm_gem_object_unreference(dev, obj); + drm_gem_object_unreference(obj); if (read < 0) return read; else return -EINVAL; } - drm_gem_object_unreference(dev, obj); + drm_gem_object_unreference(obj); return 0; } @@ -275,7 +275,7 @@ drm_gem_mmap_ioctl(struct drm_device *dev, void *data, args->offset); up_write(¤t->mm->mmap_sem); - drm_gem_object_unreference(dev, obj); + drm_gem_object_unreference(obj); return 0; } @@ -300,17 +300,17 @@ drm_gem_pwrite_ioctl(struct drm_device *dev, void *data, offset = args->offset; - written = obj->filp->f_op->write(obj->filp, (char __user *)args->data_ptr, + written = obj->filp->f_op->write(obj->filp, (char __user *)(uintptr_t) args->data_ptr, args->size, &offset); if (written != args->size) { - drm_gem_object_unreference(dev, obj); + drm_gem_object_unreference(obj); if (written < 0) return written; else return -EINVAL; } - drm_gem_object_unreference(dev, obj); + drm_gem_object_unreference(obj); return 0; } @@ -329,10 +329,9 @@ drm_gem_open(struct drm_device *dev, struct drm_file *file_private) static int drm_gem_object_release(int id, void *ptr, void *data) { - struct drm_device *dev = data; struct drm_gem_object *obj = ptr; - drm_gem_object_unreference(dev, obj); + drm_gem_object_unreference(obj); return 0; } @@ -345,37 +344,21 @@ drm_gem_object_release(int id, void *ptr, void *data) void drm_gem_release(struct drm_device *dev, struct drm_file *file_private) { - idr_for_each(&file_private->object_idr, &drm_gem_object_release, dev); + idr_for_each(&file_private->object_idr, &drm_gem_object_release, NULL); idr_destroy(&file_private->object_idr); } void -drm_gem_object_reference(struct drm_device *dev, struct drm_gem_object *obj) -{ - kref_get(&obj->refcount); -} -EXPORT_SYMBOL(drm_gem_object_reference); - -static void drm_gem_object_free (struct kref *kref) { struct drm_gem_object *obj = (struct drm_gem_object *) kref; struct drm_device *dev = obj->dev; if (dev->driver->gem_free_object != NULL) - dev->driver->gem_free_object(dev, obj); + dev->driver->gem_free_object(obj); fput(obj->filp); kfree(obj); } - -void -drm_gem_object_unreference(struct drm_device *dev, struct drm_gem_object *obj) -{ - if (obj == NULL) - return; - - kref_put (&obj->refcount, drm_gem_object_free); -} -EXPORT_SYMBOL(drm_gem_object_unreference); +EXPORT_SYMBOL(drm_gem_object_free); diff --git a/linux-core/i915_gem.c b/linux-core/i915_gem.c index 30e67742..16bb3923 100644 --- a/linux-core/i915_gem.c +++ b/linux-core/i915_gem.c @@ -49,8 +49,7 @@ i915_gem_init_ioctl(struct drm_device *dev, void *data, } static void -i915_gem_object_free_page_list(struct drm_device *dev, - struct drm_gem_object *obj) +i915_gem_object_free_page_list(struct drm_gem_object *obj) { struct drm_i915_gem_object *obj_priv = obj->driver_private; int page_count = obj->size / PAGE_SIZE; @@ -74,7 +73,7 @@ i915_gem_object_free_page_list(struct drm_device *dev, * Unbinds an object from the GTT aperture. */ static void -i915_gem_object_unbind(struct drm_device *dev, struct drm_gem_object *obj) +i915_gem_object_unbind(struct drm_gem_object *obj) { struct drm_i915_gem_object *obj_priv = obj->driver_private; @@ -86,7 +85,7 @@ i915_gem_object_unbind(struct drm_device *dev, struct drm_gem_object *obj) drm_free_agp(obj_priv->agp_mem, obj->size / PAGE_SIZE); } - i915_gem_object_free_page_list(dev, obj); + i915_gem_object_free_page_list(obj); drm_memrange_put_block(obj_priv->gtt_space); obj_priv->gtt_space = NULL; @@ -96,8 +95,9 @@ i915_gem_object_unbind(struct drm_device *dev, struct drm_gem_object *obj) * Finds free space in the GTT aperture and binds the object there. */ static int -i915_gem_object_bind_to_gtt(struct drm_device *dev, struct drm_gem_object *obj, unsigned alignment) +i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment) { + struct drm_device *dev = obj->dev; drm_i915_private_t *dev_priv = dev->dev_private; struct drm_i915_gem_object *obj_priv = obj->driver_private; struct drm_memrange_node *free_space; @@ -141,7 +141,7 @@ i915_gem_object_bind_to_gtt(struct drm_device *dev, struct drm_gem_object *obj, find_or_create_page(obj->filp->f_mapping, i, GFP_HIGHUSER); if (obj_priv->page_list[i] == NULL) { - i915_gem_object_free_page_list(dev, obj); + i915_gem_object_free_page_list(obj); drm_memrange_put_block(obj_priv->gtt_space); obj_priv->gtt_space = NULL; return -ENOMEM; @@ -156,7 +156,7 @@ i915_gem_object_bind_to_gtt(struct drm_device *dev, struct drm_gem_object *obj, page_count, obj_priv->gtt_offset); if (obj_priv->agp_mem == NULL) { - i915_gem_object_free_page_list(dev, obj); + i915_gem_object_free_page_list(obj); drm_memrange_put_block(obj_priv->gtt_space); obj_priv->gtt_space = NULL; return -ENOMEM; @@ -166,11 +166,11 @@ i915_gem_object_bind_to_gtt(struct drm_device *dev, struct drm_gem_object *obj, } static int -i915_gem_reloc_and_validate_object(struct drm_device *dev, +i915_gem_reloc_and_validate_object(struct drm_gem_object *obj, struct drm_file *file_priv, - struct drm_i915_gem_validate_entry *entry, - struct drm_gem_object *obj) + struct drm_i915_gem_validate_entry *entry) { + struct drm_device *dev = obj->dev; struct drm_i915_gem_relocation_entry reloc; struct drm_i915_gem_relocation_entry __user *relocs; struct drm_i915_gem_object *obj_priv = obj->driver_private; @@ -178,7 +178,7 @@ i915_gem_reloc_and_validate_object(struct drm_device *dev, /* Choose the GTT offset for our buffer and put it there. */ if (obj_priv->gtt_space == NULL) { - i915_gem_object_bind_to_gtt(dev, obj, (unsigned) entry->alignment); + i915_gem_object_bind_to_gtt(obj, (unsigned) entry->alignment); if (obj_priv->gtt_space == NULL) return -ENOMEM; } @@ -198,7 +198,7 @@ i915_gem_reloc_and_validate_object(struct drm_device *dev, if (ret != 0) return ret; - target_obj = drm_gem_object_lookup(dev, file_priv, + target_obj = drm_gem_object_lookup(obj->dev, file_priv, reloc.target_handle); if (target_obj == NULL) return -EINVAL; @@ -248,12 +248,11 @@ i915_gem_reloc_and_validate_object(struct drm_device *dev, static int evict_callback(struct drm_memrange_node *node, void *data) { - struct drm_device *dev = data; struct drm_gem_object *obj = node->private; struct drm_i915_gem_object *obj_priv = obj->driver_private; if (obj_priv->pin_count == 0) - i915_gem_object_unbind(dev, obj); + i915_gem_object_unbind(obj); return 0; } @@ -274,7 +273,7 @@ i915_gem_sync_and_evict(struct drm_device *dev) return ret; /* Evict everything so we have space for sure. */ - drm_memrange_for_each(&dev_priv->mm.gtt_space, evict_callback, dev); + drm_memrange_for_each(&dev_priv->mm.gtt_space, evict_callback, NULL); return 0; } @@ -321,9 +320,8 @@ i915_gem_execbuffer(struct drm_device *dev, void *data, goto err; } - i915_gem_reloc_and_validate_object(dev, file_priv, - &validate_list[i], - object_list[i]); + i915_gem_reloc_and_validate_object(object_list[i], file_priv, + &validate_list[i]); } /* Exec the batchbuffer */ @@ -346,7 +344,7 @@ i915_gem_execbuffer(struct drm_device *dev, void *data, err: if (object_list != NULL) { for (i = 0; i < args->buffer_count; i++) - drm_gem_object_unreference(dev, object_list[i]); + drm_gem_object_unreference(object_list[i]); } drm_free(object_list, sizeof(*object_list) * args->buffer_count, DRM_MEM_DRIVER); @@ -372,7 +370,7 @@ i915_gem_pin_ioctl(struct drm_device *dev, void *data, return -EINVAL; } - ret = i915_gem_object_bind_to_gtt(dev, obj, (unsigned) args->alignment); + ret = i915_gem_object_bind_to_gtt(obj, (unsigned) args->alignment); if (ret != 0) { DRM_ERROR("Failure to bind in i915_gem_pin_ioctl(): %d\n", ret); @@ -407,7 +405,7 @@ i915_gem_unpin_ioctl(struct drm_device *dev, void *data, return 0; } -int i915_gem_init_object(struct drm_device *dev, struct drm_gem_object *obj) +int i915_gem_init_object(struct drm_gem_object *obj) { struct drm_i915_gem_object *obj_priv; @@ -420,9 +418,9 @@ int i915_gem_init_object(struct drm_device *dev, struct drm_gem_object *obj) return 0; } -void i915_gem_free_object(struct drm_device *dev, struct drm_gem_object *obj) +void i915_gem_free_object(struct drm_gem_object *obj) { - i915_gem_object_unbind(dev, obj); + i915_gem_object_unbind(obj); drm_free(obj->driver_private, 1, DRM_MEM_DRIVER); } |