提交 89c8233f 编写于 作者: D David Herrmann 提交者: Dave Airlie

drm/gem: simplify object initialization

drm_gem_object_init() and drm_gem_private_object_init() do exactly the
same (except for shmem alloc) so make the first use the latter to reduce
code duplication.

Also drop the return code from drm_gem_private_object_init(). It seems
unlikely that we will extend it any time soon so no reason to keep it
around. This simplifies code paths in drivers, too.

Last but not least, fix gma500 to call drm_gem_object_release() before
freeing objects that were allocated via drm_gem_private_object_init().
That isn't actually necessary for now, but might be in the future.
Signed-off-by: NDavid Herrmann <dh.herrmann@gmail.com>
Reviewed-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: NPatrik Jakobsson <patrik.r.jakobsson@gmail.com>
Acked-by: NRob Clark <robdclark@gmail.com>
Signed-off-by: NDave Airlie <airlied@gmail.com>
上级 23367ff4
...@@ -132,16 +132,14 @@ drm_gem_destroy(struct drm_device *dev) ...@@ -132,16 +132,14 @@ drm_gem_destroy(struct drm_device *dev)
int drm_gem_object_init(struct drm_device *dev, int drm_gem_object_init(struct drm_device *dev,
struct drm_gem_object *obj, size_t size) struct drm_gem_object *obj, size_t size)
{ {
BUG_ON((size & (PAGE_SIZE - 1)) != 0); struct file *filp;
obj->dev = dev; filp = shmem_file_setup("drm mm object", size, VM_NORESERVE);
obj->filp = shmem_file_setup("drm mm object", size, VM_NORESERVE); if (IS_ERR(filp))
if (IS_ERR(obj->filp)) return PTR_ERR(filp);
return PTR_ERR(obj->filp);
kref_init(&obj->refcount); drm_gem_private_object_init(dev, obj, size);
atomic_set(&obj->handle_count, 0); obj->filp = filp;
obj->size = size;
return 0; return 0;
} }
...@@ -152,8 +150,8 @@ EXPORT_SYMBOL(drm_gem_object_init); ...@@ -152,8 +150,8 @@ EXPORT_SYMBOL(drm_gem_object_init);
* no GEM provided backing store. Instead the caller is responsible for * no GEM provided backing store. Instead the caller is responsible for
* backing the object and handling it. * backing the object and handling it.
*/ */
int drm_gem_private_object_init(struct drm_device *dev, void drm_gem_private_object_init(struct drm_device *dev,
struct drm_gem_object *obj, size_t size) struct drm_gem_object *obj, size_t size)
{ {
BUG_ON((size & (PAGE_SIZE - 1)) != 0); BUG_ON((size & (PAGE_SIZE - 1)) != 0);
...@@ -163,8 +161,6 @@ int drm_gem_private_object_init(struct drm_device *dev, ...@@ -163,8 +161,6 @@ int drm_gem_private_object_init(struct drm_device *dev,
kref_init(&obj->refcount); kref_init(&obj->refcount);
atomic_set(&obj->handle_count, 0); atomic_set(&obj->handle_count, 0);
obj->size = size; obj->size = size;
return 0;
} }
EXPORT_SYMBOL(drm_gem_private_object_init); EXPORT_SYMBOL(drm_gem_private_object_init);
......
...@@ -321,10 +321,8 @@ static struct gtt_range *psbfb_alloc(struct drm_device *dev, int aligned_size) ...@@ -321,10 +321,8 @@ static struct gtt_range *psbfb_alloc(struct drm_device *dev, int aligned_size)
/* Begin by trying to use stolen memory backing */ /* Begin by trying to use stolen memory backing */
backing = psb_gtt_alloc_range(dev, aligned_size, "fb", 1); backing = psb_gtt_alloc_range(dev, aligned_size, "fb", 1);
if (backing) { if (backing) {
if (drm_gem_private_object_init(dev, drm_gem_private_object_init(dev, &backing->gem, aligned_size);
&backing->gem, aligned_size) == 0) return backing;
return backing;
psb_gtt_free_range(dev, backing);
} }
return NULL; return NULL;
} }
......
...@@ -261,11 +261,12 @@ static int psb_gem_create_stolen(struct drm_file *file, struct drm_device *dev, ...@@ -261,11 +261,12 @@ static int psb_gem_create_stolen(struct drm_file *file, struct drm_device *dev,
struct gtt_range *gtt = psb_gtt_alloc_range(dev, size, "gem", 1); struct gtt_range *gtt = psb_gtt_alloc_range(dev, size, "gem", 1);
if (gtt == NULL) if (gtt == NULL)
return -ENOMEM; return -ENOMEM;
if (drm_gem_private_object_init(dev, &gtt->gem, size) != 0)
goto free_gtt; drm_gem_private_object_init(dev, &gtt->gem, size);
if (drm_gem_handle_create(file, &gtt->gem, handle) == 0) if (drm_gem_handle_create(file, &gtt->gem, handle) == 0)
return 0; return 0;
free_gtt:
drm_gem_object_release(&gtt->gem);
psb_gtt_free_range(dev, gtt); psb_gtt_free_range(dev, gtt);
return -ENOMEM; return -ENOMEM;
} }
......
...@@ -289,12 +289,7 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev, ...@@ -289,12 +289,7 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
goto fail_detach; goto fail_detach;
} }
ret = drm_gem_private_object_init(dev, &obj->base, dma_buf->size); drm_gem_private_object_init(dev, &obj->base, dma_buf->size);
if (ret) {
i915_gem_object_free(obj);
goto fail_detach;
}
i915_gem_object_init(obj, &i915_gem_object_dmabuf_ops); i915_gem_object_init(obj, &i915_gem_object_dmabuf_ops);
obj->base.import_attach = attach; obj->base.import_attach = attach;
......
...@@ -291,9 +291,7 @@ _i915_gem_object_create_stolen(struct drm_device *dev, ...@@ -291,9 +291,7 @@ _i915_gem_object_create_stolen(struct drm_device *dev,
if (obj == NULL) if (obj == NULL)
return NULL; return NULL;
if (drm_gem_private_object_init(dev, &obj->base, stolen->size)) drm_gem_private_object_init(dev, &obj->base, stolen->size);
goto cleanup;
i915_gem_object_init(obj, &i915_gem_object_stolen_ops); i915_gem_object_init(obj, &i915_gem_object_stolen_ops);
obj->pages = i915_pages_create_for_stolen(dev, obj->pages = i915_pages_create_for_stolen(dev,
......
...@@ -1427,8 +1427,9 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev, ...@@ -1427,8 +1427,9 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev,
omap_obj->height = gsize.tiled.height; omap_obj->height = gsize.tiled.height;
} }
ret = 0;
if (flags & (OMAP_BO_DMA|OMAP_BO_EXT_MEM)) if (flags & (OMAP_BO_DMA|OMAP_BO_EXT_MEM))
ret = drm_gem_private_object_init(dev, obj, size); drm_gem_private_object_init(dev, obj, size);
else else
ret = drm_gem_object_init(dev, obj, size); ret = drm_gem_object_init(dev, obj, size);
......
...@@ -1601,8 +1601,8 @@ struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev, ...@@ -1601,8 +1601,8 @@ struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev,
size_t size); size_t size);
int drm_gem_object_init(struct drm_device *dev, int drm_gem_object_init(struct drm_device *dev,
struct drm_gem_object *obj, size_t size); struct drm_gem_object *obj, size_t size);
int drm_gem_private_object_init(struct drm_device *dev, void drm_gem_private_object_init(struct drm_device *dev,
struct drm_gem_object *obj, size_t size); struct drm_gem_object *obj, size_t size);
void drm_gem_object_handle_free(struct drm_gem_object *obj); void drm_gem_object_handle_free(struct drm_gem_object *obj);
void drm_gem_vm_open(struct vm_area_struct *vma); void drm_gem_vm_open(struct vm_area_struct *vma);
void drm_gem_vm_close(struct vm_area_struct *vma); void drm_gem_vm_close(struct vm_area_struct *vma);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册