Commit 2364839a authored by Joonyoung Shim's avatar Joonyoung Shim Committed by Inki Dae

drm/exynos: Split creation of gem object and gem handle

exynos_drm_gem_create function created gem object with gem handle but it
can be called externally without gem handle creation through this patch.
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 2d91cf17
...@@ -162,9 +162,7 @@ exynos_drm_fb_init(struct drm_file *file_priv, struct drm_device *dev, ...@@ -162,9 +162,7 @@ exynos_drm_fb_init(struct drm_file *file_priv, struct drm_device *dev,
goto out; goto out;
} else { } else {
exynos_gem_obj = exynos_drm_gem_create(dev, file_priv, exynos_gem_obj = exynos_drm_gem_create(dev, size);
&mode_cmd->handles[0],
size);
if (IS_ERR(exynos_gem_obj)) { if (IS_ERR(exynos_gem_obj)) {
ret = PTR_ERR(exynos_gem_obj); ret = PTR_ERR(exynos_gem_obj);
goto err_buffer; goto err_buffer;
......
...@@ -55,62 +55,84 @@ static unsigned int convert_to_vm_err_msg(int msg) ...@@ -55,62 +55,84 @@ static unsigned int convert_to_vm_err_msg(int msg)
return out_msg; return out_msg;
} }
static struct exynos_drm_gem_obj * static int exynos_drm_gem_handle_create(struct drm_gem_object *obj,
exynos_drm_gem_init(struct drm_device *drm_dev, struct drm_file *file_priv, struct drm_file *file_priv,
unsigned int *handle, unsigned int size) unsigned int *handle)
{ {
struct exynos_drm_gem_obj *exynos_gem_obj;
struct drm_gem_object *obj;
int ret; int ret;
exynos_gem_obj = kzalloc(sizeof(*exynos_gem_obj), GFP_KERNEL);
if (!exynos_gem_obj) {
DRM_ERROR("failed to allocate exynos gem object.\n");
return ERR_PTR(-ENOMEM);
}
obj = &exynos_gem_obj->base;
ret = drm_gem_object_init(drm_dev, obj, size);
if (ret < 0) {
DRM_ERROR("failed to initialize gem object.\n");
ret = -EINVAL;
goto err;
}
DRM_DEBUG_KMS("created file object = 0x%x\n", (unsigned int)obj->filp);
/* /*
* allocate a id of idr table where the obj is registered * allocate a id of idr table where the obj is registered
* and handle has the id what user can see. * and handle has the id what user can see.
*/ */
ret = drm_gem_handle_create(file_priv, obj, handle); ret = drm_gem_handle_create(file_priv, obj, handle);
if (ret) if (ret)
goto err_release; return ret;
DRM_DEBUG_KMS("gem handle = 0x%x\n", *handle); DRM_DEBUG_KMS("gem handle = 0x%x\n", *handle);
/* drop reference from allocate - handle holds it now. */ /* drop reference from allocate - handle holds it now. */
drm_gem_object_unreference_unlocked(obj); drm_gem_object_unreference_unlocked(obj);
return exynos_gem_obj; return 0;
}
void exynos_drm_gem_destroy(struct exynos_drm_gem_obj *exynos_gem_obj)
{
struct drm_gem_object *obj;
DRM_DEBUG_KMS("%s\n", __FILE__);
if (!exynos_gem_obj)
return;
obj = &exynos_gem_obj->base;
DRM_DEBUG_KMS("handle count = %d\n", atomic_read(&obj->handle_count));
exynos_drm_buf_destroy(obj->dev, exynos_gem_obj->buffer);
err_release: if (obj->map_list.map)
drm_gem_free_mmap_offset(obj);
/* release file pointer to gem object. */
drm_gem_object_release(obj); drm_gem_object_release(obj);
err:
kfree(exynos_gem_obj); kfree(exynos_gem_obj);
return ERR_PTR(ret); }
static struct exynos_drm_gem_obj *exynos_drm_gem_init(struct drm_device *dev,
unsigned long size)
{
struct exynos_drm_gem_obj *exynos_gem_obj;
struct drm_gem_object *obj;
int ret;
exynos_gem_obj = kzalloc(sizeof(*exynos_gem_obj), GFP_KERNEL);
if (!exynos_gem_obj) {
DRM_ERROR("failed to allocate exynos gem object\n");
return NULL;
}
obj = &exynos_gem_obj->base;
ret = drm_gem_object_init(dev, obj, size);
if (ret < 0) {
DRM_ERROR("failed to initialize gem object\n");
kfree(exynos_gem_obj);
return NULL;
}
DRM_DEBUG_KMS("created file object = 0x%x\n", (unsigned int)obj->filp);
return exynos_gem_obj;
} }
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,
unsigned int *handle,
unsigned long size) unsigned long size)
{ {
struct exynos_drm_gem_obj *exynos_gem_obj;
struct exynos_drm_gem_buf *buffer; struct exynos_drm_gem_buf *buffer;
struct exynos_drm_gem_obj *exynos_gem_obj;
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);
...@@ -119,10 +141,10 @@ struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev, ...@@ -119,10 +141,10 @@ struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
if (!buffer) if (!buffer)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
exynos_gem_obj = exynos_drm_gem_init(dev, file_priv, handle, size); exynos_gem_obj = exynos_drm_gem_init(dev, size);
if (IS_ERR(exynos_gem_obj)) { if (!exynos_gem_obj) {
exynos_drm_buf_destroy(dev, buffer); exynos_drm_buf_destroy(dev, buffer);
return exynos_gem_obj; return ERR_PTR(-ENOMEM);
} }
exynos_gem_obj->buffer = buffer; exynos_gem_obj->buffer = buffer;
...@@ -135,14 +157,21 @@ int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data, ...@@ -135,14 +157,21 @@ int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data,
{ {
struct drm_exynos_gem_create *args = data; struct drm_exynos_gem_create *args = data;
struct exynos_drm_gem_obj *exynos_gem_obj; struct exynos_drm_gem_obj *exynos_gem_obj;
int ret;
DRM_DEBUG_KMS("%s\n", __FILE__); DRM_DEBUG_KMS("%s\n", __FILE__);
exynos_gem_obj = exynos_drm_gem_create(dev, file_priv, &args->handle, exynos_gem_obj = exynos_drm_gem_create(dev, 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);
ret = exynos_drm_gem_handle_create(&exynos_gem_obj->base, file_priv,
&args->handle);
if (ret) {
exynos_drm_gem_destroy(exynos_gem_obj);
return ret;
}
return 0; return 0;
} }
...@@ -177,6 +206,7 @@ static int exynos_drm_gem_mmap_buffer(struct file *filp, ...@@ -177,6 +206,7 @@ static int exynos_drm_gem_mmap_buffer(struct file *filp,
vma->vm_flags |= (VM_IO | VM_RESERVED); vma->vm_flags |= (VM_IO | VM_RESERVED);
/* in case of direct mapping, always having non-cachable attribute */
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
vma->vm_file = filp; vma->vm_file = filp;
...@@ -261,24 +291,9 @@ int exynos_drm_gem_init_object(struct drm_gem_object *obj) ...@@ -261,24 +291,9 @@ int exynos_drm_gem_init_object(struct drm_gem_object *obj)
void exynos_drm_gem_free_object(struct drm_gem_object *obj) void exynos_drm_gem_free_object(struct drm_gem_object *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", exynos_drm_gem_destroy(to_exynos_gem_obj(obj));
atomic_read(&obj->handle_count));
if (obj->map_list.map)
drm_gem_free_mmap_offset(obj);
/* release file pointer to gem object. */
drm_gem_object_release(obj);
exynos_gem_obj = to_exynos_gem_obj(obj);
exynos_drm_buf_destroy(obj->dev, exynos_gem_obj->buffer);
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,
...@@ -286,6 +301,7 @@ int exynos_drm_gem_dumb_create(struct drm_file *file_priv, ...@@ -286,6 +301,7 @@ int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
struct drm_mode_create_dumb *args) struct drm_mode_create_dumb *args)
{ {
struct exynos_drm_gem_obj *exynos_gem_obj; struct exynos_drm_gem_obj *exynos_gem_obj;
int ret;
DRM_DEBUG_KMS("%s\n", __FILE__); DRM_DEBUG_KMS("%s\n", __FILE__);
...@@ -298,11 +314,17 @@ int exynos_drm_gem_dumb_create(struct drm_file *file_priv, ...@@ -298,11 +314,17 @@ int exynos_drm_gem_dumb_create(struct drm_file *file_priv,
args->pitch = args->width * args->bpp >> 3; args->pitch = args->width * args->bpp >> 3;
args->size = args->pitch * args->height; args->size = args->pitch * args->height;
exynos_gem_obj = exynos_drm_gem_create(dev, file_priv, &args->handle, exynos_gem_obj = exynos_drm_gem_create(dev, 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);
ret = exynos_drm_gem_handle_create(&exynos_gem_obj->base, file_priv,
&args->handle);
if (ret) {
exynos_drm_gem_destroy(exynos_gem_obj);
return ret;
}
return 0; return 0;
} }
......
...@@ -64,10 +64,11 @@ struct exynos_drm_gem_obj { ...@@ -64,10 +64,11 @@ struct exynos_drm_gem_obj {
struct exynos_drm_gem_buf *buffer; struct exynos_drm_gem_buf *buffer;
}; };
/* create a new buffer and get a new gem handle. */ /* destroy a buffer with gem object */
void exynos_drm_gem_destroy(struct exynos_drm_gem_obj *exynos_gem_obj);
/* create a new buffer with gem object */
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,
unsigned int *handle,
unsigned long size); unsigned long size);
/* /*
......
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