forked from Minki/linux
drm: extract drm_gem_object_init
This function can be used by drivers who allocate the drm gem object on their own. No functional change in here, just preparation. Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Acked-by: Eric Anholt <eric@anholt.net> Signed-off-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
parent
153549b8b6
commit
1d397043bc
@ -123,6 +123,31 @@ drm_gem_destroy(struct drm_device *dev)
|
|||||||
dev->mm_private = NULL;
|
dev->mm_private = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize an already allocate GEM object of the specified size with
|
||||||
|
* shmfs backing store.
|
||||||
|
*/
|
||||||
|
int drm_gem_object_init(struct drm_device *dev,
|
||||||
|
struct drm_gem_object *obj, size_t size)
|
||||||
|
{
|
||||||
|
BUG_ON((size & (PAGE_SIZE - 1)) != 0);
|
||||||
|
|
||||||
|
obj->dev = dev;
|
||||||
|
obj->filp = shmem_file_setup("drm mm object", size, VM_NORESERVE);
|
||||||
|
if (IS_ERR(obj->filp))
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
kref_init(&obj->refcount);
|
||||||
|
kref_init(&obj->handlecount);
|
||||||
|
obj->size = size;
|
||||||
|
|
||||||
|
atomic_inc(&dev->object_count);
|
||||||
|
atomic_add(obj->size, &dev->object_memory);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(drm_gem_object_init);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocate a GEM object of the specified size with shmfs backing store
|
* Allocate a GEM object of the specified size with shmfs backing store
|
||||||
*/
|
*/
|
||||||
@ -131,28 +156,22 @@ drm_gem_object_alloc(struct drm_device *dev, size_t size)
|
|||||||
{
|
{
|
||||||
struct drm_gem_object *obj;
|
struct drm_gem_object *obj;
|
||||||
|
|
||||||
BUG_ON((size & (PAGE_SIZE - 1)) != 0);
|
|
||||||
|
|
||||||
obj = kzalloc(sizeof(*obj), GFP_KERNEL);
|
obj = kzalloc(sizeof(*obj), GFP_KERNEL);
|
||||||
if (!obj)
|
if (!obj)
|
||||||
goto free;
|
goto free;
|
||||||
|
|
||||||
obj->dev = dev;
|
if (drm_gem_object_init(dev, obj, size) != 0)
|
||||||
obj->filp = shmem_file_setup("drm mm object", size, VM_NORESERVE);
|
|
||||||
if (IS_ERR(obj->filp))
|
|
||||||
goto free;
|
goto free;
|
||||||
|
|
||||||
kref_init(&obj->refcount);
|
|
||||||
kref_init(&obj->handlecount);
|
|
||||||
obj->size = size;
|
|
||||||
if (dev->driver->gem_init_object != NULL &&
|
if (dev->driver->gem_init_object != NULL &&
|
||||||
dev->driver->gem_init_object(obj) != 0) {
|
dev->driver->gem_init_object(obj) != 0) {
|
||||||
goto fput;
|
goto fput;
|
||||||
}
|
}
|
||||||
atomic_inc(&dev->object_count);
|
|
||||||
atomic_add(obj->size, &dev->object_memory);
|
|
||||||
return obj;
|
return obj;
|
||||||
fput:
|
fput:
|
||||||
|
/* Object_init mangles the global counters - readjust them. */
|
||||||
|
atomic_dec(&dev->object_count);
|
||||||
|
atomic_sub(obj->size, &dev->object_memory);
|
||||||
fput(obj->filp);
|
fput(obj->filp);
|
||||||
free:
|
free:
|
||||||
kfree(obj);
|
kfree(obj);
|
||||||
|
@ -1432,6 +1432,8 @@ void drm_gem_object_free(struct kref *kref);
|
|||||||
void drm_gem_object_free_unlocked(struct kref *kref);
|
void drm_gem_object_free_unlocked(struct kref *kref);
|
||||||
struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev,
|
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,
|
||||||
|
struct drm_gem_object *obj, size_t size);
|
||||||
void drm_gem_object_handle_free(struct kref *kref);
|
void drm_gem_object_handle_free(struct kref *kref);
|
||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user