Commit ee5e770e authored by Joonyoung Shim's avatar Joonyoung Shim Committed by Inki Dae

drm/exynos: gem code cleanup

This cleans codes of exynos gem - indents and order function and so on.
Signed-off-by: default avatarJoonyoung Shim <jy0922.shim@samsung.com>
Signed-off-by: default avatarInki Dae <inki.dae@samsung.com>
Signed-off-by: default avatarKyungmin Park <kyungmin.park@samsung.com>
parent 5c2a5ce6
...@@ -73,7 +73,7 @@ struct exynos_drm_gem_buf *exynos_drm_buf_create(struct drm_device *dev, ...@@ -73,7 +73,7 @@ struct exynos_drm_gem_buf *exynos_drm_buf_create(struct drm_device *dev,
buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
if (!buffer) { if (!buffer) {
DRM_ERROR("failed to allocate exynos_drm_gem_buf.\n"); DRM_ERROR("failed to allocate exynos_drm_gem_buf.\n");
return ERR_PTR(-ENOMEM); return NULL;
} }
buffer->size = size; buffer->size = size;
...@@ -84,8 +84,7 @@ struct exynos_drm_gem_buf *exynos_drm_buf_create(struct drm_device *dev, ...@@ -84,8 +84,7 @@ struct exynos_drm_gem_buf *exynos_drm_buf_create(struct drm_device *dev,
*/ */
if (lowlevel_buffer_allocate(dev, buffer) < 0) { if (lowlevel_buffer_allocate(dev, buffer) < 0) {
kfree(buffer); kfree(buffer);
buffer = NULL; return NULL;
return ERR_PTR(-ENOMEM);
} }
return buffer; return buffer;
......
...@@ -150,8 +150,8 @@ exynos_drm_fb_init(struct drm_file *file_priv, struct drm_device *dev, ...@@ -150,8 +150,8 @@ exynos_drm_fb_init(struct drm_file *file_priv, struct drm_device *dev,
* for default framebuffer. * for default framebuffer.
*/ */
buffer = exynos_drm_buf_create(dev, size); buffer = exynos_drm_buf_create(dev, size);
if (IS_ERR(buffer)) { if (!buffer) {
ret = PTR_ERR(buffer); ret = -ENOMEM;
goto err_buffer; goto err_buffer;
} }
......
...@@ -62,10 +62,9 @@ static unsigned int get_gem_mmap_offset(struct drm_gem_object *obj) ...@@ -62,10 +62,9 @@ static unsigned int get_gem_mmap_offset(struct drm_gem_object *obj)
return (unsigned int)obj->map_list.hash.key << PAGE_SHIFT; return (unsigned int)obj->map_list.hash.key << PAGE_SHIFT;
} }
static struct exynos_drm_gem_obj static struct exynos_drm_gem_obj *
*exynos_drm_gem_init(struct drm_device *drm_dev, exynos_drm_gem_init(struct drm_device *drm_dev, struct drm_file *file_priv,
struct drm_file *file_priv, unsigned int *handle, unsigned int *handle, unsigned int size)
unsigned int size)
{ {
struct exynos_drm_gem_obj *exynos_gem_obj; struct exynos_drm_gem_obj *exynos_gem_obj;
struct drm_gem_object *obj; struct drm_gem_object *obj;
...@@ -83,7 +82,7 @@ static struct exynos_drm_gem_obj ...@@ -83,7 +82,7 @@ static struct exynos_drm_gem_obj
if (ret < 0) { if (ret < 0) {
DRM_ERROR("failed to initialize gem object.\n"); DRM_ERROR("failed to initialize gem object.\n");
ret = -EINVAL; ret = -EINVAL;
goto err_object_init; goto err;
} }
DRM_DEBUG_KMS("created file object = 0x%x\n", (unsigned int)obj->filp); DRM_DEBUG_KMS("created file object = 0x%x\n", (unsigned int)obj->filp);
...@@ -91,7 +90,7 @@ static struct exynos_drm_gem_obj ...@@ -91,7 +90,7 @@ static struct exynos_drm_gem_obj
ret = drm_gem_create_mmap_offset(obj); ret = drm_gem_create_mmap_offset(obj);
if (ret < 0) { if (ret < 0) {
DRM_ERROR("failed to allocate mmap offset.\n"); DRM_ERROR("failed to allocate mmap offset.\n");
goto err_create_mmap_offset; goto err_release;
} }
/* /*
...@@ -100,7 +99,7 @@ static struct exynos_drm_gem_obj ...@@ -100,7 +99,7 @@ static struct exynos_drm_gem_obj
*/ */
ret = drm_gem_handle_create(file_priv, obj, handle); ret = drm_gem_handle_create(file_priv, obj, handle);
if (ret) if (ret)
goto err_handle_create; goto err_free_mmap_offset;
DRM_DEBUG_KMS("gem handle = 0x%x\n", *handle); DRM_DEBUG_KMS("gem handle = 0x%x\n", *handle);
...@@ -109,34 +108,32 @@ static struct exynos_drm_gem_obj ...@@ -109,34 +108,32 @@ static struct exynos_drm_gem_obj
return exynos_gem_obj; return exynos_gem_obj;
err_handle_create: err_free_mmap_offset:
drm_gem_free_mmap_offset(obj); drm_gem_free_mmap_offset(obj);
err_create_mmap_offset: err_release:
drm_gem_object_release(obj); drm_gem_object_release(obj);
err_object_init: err:
kfree(exynos_gem_obj); kfree(exynos_gem_obj);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev, struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
struct drm_file *file_priv, struct drm_file *file_priv,
unsigned int *handle, unsigned long size) unsigned int *handle,
unsigned long size)
{ {
struct exynos_drm_gem_obj *exynos_gem_obj = NULL; struct exynos_drm_gem_obj *exynos_gem_obj;
struct exynos_drm_gem_buf *buffer; struct exynos_drm_gem_buf *buffer;
size = roundup(size, PAGE_SIZE); size = roundup(size, PAGE_SIZE);
DRM_DEBUG_KMS("%s: size = 0x%lx\n", __FILE__, size); DRM_DEBUG_KMS("%s: size = 0x%lx\n", __FILE__, size);
buffer = exynos_drm_buf_create(dev, size); buffer = exynos_drm_buf_create(dev, size);
if (IS_ERR(buffer)) { if (!buffer)
return ERR_CAST(buffer); return ERR_PTR(-ENOMEM);
}
exynos_gem_obj = exynos_drm_gem_init(dev, file_priv, handle, size); exynos_gem_obj = exynos_drm_gem_init(dev, file_priv, handle, size);
if (IS_ERR(exynos_gem_obj)) { if (IS_ERR(exynos_gem_obj)) {
...@@ -153,12 +150,12 @@ int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data, ...@@ -153,12 +150,12 @@ int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv) struct drm_file *file_priv)
{ {
struct drm_exynos_gem_create *args = data; struct drm_exynos_gem_create *args = data;
struct exynos_drm_gem_obj *exynos_gem_obj = NULL; struct exynos_drm_gem_obj *exynos_gem_obj;
DRM_DEBUG_KMS("%s\n", __FILE__); DRM_DEBUG_KMS("%s\n", __FILE__);
exynos_gem_obj = exynos_drm_gem_create(dev, file_priv, exynos_gem_obj = exynos_drm_gem_create(dev, file_priv, &args->handle,
&args->handle, args->size); args->size);
if (IS_ERR(exynos_gem_obj)) if (IS_ERR(exynos_gem_obj))
return PTR_ERR(exynos_gem_obj); return PTR_ERR(exynos_gem_obj);
...@@ -278,30 +275,31 @@ int exynos_drm_gem_init_object(struct drm_gem_object *obj) ...@@ -278,30 +275,31 @@ int exynos_drm_gem_init_object(struct drm_gem_object *obj)
return 0; return 0;
} }
void exynos_drm_gem_free_object(struct drm_gem_object *gem_obj) void exynos_drm_gem_free_object(struct drm_gem_object *obj)
{ {
struct exynos_drm_gem_obj *exynos_gem_obj; struct exynos_drm_gem_obj *exynos_gem_obj;
DRM_DEBUG_KMS("%s\n", __FILE__); DRM_DEBUG_KMS("%s\n", __FILE__);
DRM_DEBUG_KMS("handle count = %d\n", DRM_DEBUG_KMS("handle count = %d\n",
atomic_read(&gem_obj->handle_count)); atomic_read(&obj->handle_count));
if (gem_obj->map_list.map) if (obj->map_list.map)
drm_gem_free_mmap_offset(gem_obj); drm_gem_free_mmap_offset(obj);
/* release file pointer to gem object. */ /* release file pointer to gem object. */
drm_gem_object_release(gem_obj); drm_gem_object_release(obj);
exynos_gem_obj = to_exynos_gem_obj(gem_obj); exynos_gem_obj = to_exynos_gem_obj(obj);
exynos_drm_buf_destroy(gem_obj->dev, exynos_gem_obj->buffer); exynos_drm_buf_destroy(obj->dev, exynos_gem_obj->buffer);
kfree(exynos_gem_obj); kfree(exynos_gem_obj);
} }
int exynos_drm_gem_dumb_create(struct drm_file *file_priv, int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
struct drm_device *dev, struct drm_mode_create_dumb *args) struct drm_device *dev,
struct drm_mode_create_dumb *args)
{ {
struct exynos_drm_gem_obj *exynos_gem_obj; struct exynos_drm_gem_obj *exynos_gem_obj;
...@@ -325,7 +323,8 @@ int exynos_drm_gem_dumb_create(struct drm_file *file_priv, ...@@ -325,7 +323,8 @@ int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
} }
int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv, int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv,
struct drm_device *dev, uint32_t handle, uint64_t *offset) struct drm_device *dev, uint32_t handle,
uint64_t *offset)
{ {
struct exynos_drm_gem_obj *exynos_gem_obj; struct exynos_drm_gem_obj *exynos_gem_obj;
struct drm_gem_object *obj; struct drm_gem_object *obj;
...@@ -360,6 +359,28 @@ int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv, ...@@ -360,6 +359,28 @@ int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv,
return 0; return 0;
} }
int exynos_drm_gem_dumb_destroy(struct drm_file *file_priv,
struct drm_device *dev,
unsigned int handle)
{
int ret;
DRM_DEBUG_KMS("%s\n", __FILE__);
/*
* obj->refcount and obj->handle_count are decreased and
* if both them are 0 then exynos_drm_gem_free_object()
* would be called by callback to release resources.
*/
ret = drm_gem_handle_delete(file_priv, handle);
if (ret < 0) {
DRM_ERROR("failed to delete drm_gem_handle.\n");
return ret;
}
return 0;
}
int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
{ {
struct drm_gem_object *obj = vma->vm_private_data; struct drm_gem_object *obj = vma->vm_private_data;
...@@ -403,28 +424,6 @@ int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) ...@@ -403,28 +424,6 @@ int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma)
return ret; return ret;
} }
int exynos_drm_gem_dumb_destroy(struct drm_file *file_priv,
struct drm_device *dev, unsigned int handle)
{
int ret;
DRM_DEBUG_KMS("%s\n", __FILE__);
/*
* obj->refcount and obj->handle_count are decreased and
* if both them are 0 then exynos_drm_gem_free_object()
* would be called by callback to release resources.
*/
ret = drm_gem_handle_delete(file_priv, handle);
if (ret < 0) {
DRM_ERROR("failed to delete drm_gem_handle.\n");
return ret;
}
return 0;
}
MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>"); MODULE_AUTHOR("Inki Dae <inki.dae@samsung.com>");
MODULE_DESCRIPTION("Samsung SoC DRM GEM Module"); MODULE_DESCRIPTION("Samsung SoC DRM GEM Module");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
...@@ -67,7 +67,8 @@ struct exynos_drm_gem_obj { ...@@ -67,7 +67,8 @@ struct exynos_drm_gem_obj {
/* create a new buffer and get a new gem handle. */ /* create a new buffer and get a new gem handle. */
struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev, struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
struct drm_file *file_priv, struct drm_file *file_priv,
unsigned int *handle, unsigned long size); unsigned int *handle,
unsigned long size);
/* /*
* request gem object creation and buffer allocation as the size * request gem object creation and buffer allocation as the size
...@@ -81,8 +82,11 @@ int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data, ...@@ -81,8 +82,11 @@ int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
int exynos_drm_gem_map_offset_ioctl(struct drm_device *dev, void *data, int exynos_drm_gem_map_offset_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv); struct drm_file *file_priv);
/* unmap a buffer from user space. */ /*
int exynos_drm_gem_munmap_ioctl(struct drm_device *dev, void *data, * mmap the physically continuous memory that a gem object contains
* to user space.
*/
int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv); struct drm_file *file_priv);
/* initialize gem object. */ /* initialize gem object. */
...@@ -93,24 +97,13 @@ void exynos_drm_gem_free_object(struct drm_gem_object *gem_obj); ...@@ -93,24 +97,13 @@ void exynos_drm_gem_free_object(struct drm_gem_object *gem_obj);
/* create memory region for drm framebuffer. */ /* create memory region for drm framebuffer. */
int exynos_drm_gem_dumb_create(struct drm_file *file_priv, int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
struct drm_device *dev, struct drm_mode_create_dumb *args); struct drm_device *dev,
struct drm_mode_create_dumb *args);
/* map memory region for drm framebuffer to user space. */ /* map memory region for drm framebuffer to user space. */
int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv, int exynos_drm_gem_dumb_map_offset(struct drm_file *file_priv,
struct drm_device *dev, uint32_t handle, uint64_t *offset); struct drm_device *dev, uint32_t handle,
uint64_t *offset);
/* page fault handler and mmap fault address(virtual) to physical memory. */
int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
/*
* mmap the physically continuous memory that a gem object contains
* to user space.
*/
int exynos_drm_gem_mmap_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv);
/* set vm_flags and we can change the vm attribute to other one at here. */
int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
/* /*
* destroy memory region allocated. * destroy memory region allocated.
...@@ -118,6 +111,13 @@ int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); ...@@ -118,6 +111,13 @@ int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
* would be released by drm_gem_handle_delete(). * would be released by drm_gem_handle_delete().
*/ */
int exynos_drm_gem_dumb_destroy(struct drm_file *file_priv, int exynos_drm_gem_dumb_destroy(struct drm_file *file_priv,
struct drm_device *dev, unsigned int handle); struct drm_device *dev,
unsigned int handle);
/* page fault handler and mmap fault address(virtual) to physical memory. */
int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
/* set vm_flags and we can change the vm attribute to other one at here. */
int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment