Commit f088d5a9 authored by Inki Dae's avatar Inki Dae

drm/exynos: use gem create function generically

this patch addes exynos_drm_gem_init() creating and initialzing a gem.
allocation functions could use this function to create new gem and
it changes size type of exynos_drm_gem_create structure to 64bit
and also corrects comments to exynos_drm_gem_create structure.
Signed-off-by: default avatarInki Dae <inki.dae@samsung.com>
Signed-off-by: default avatarKyungmin Park <kyungmin.park@samsung.com>
parent b0e0f856
...@@ -165,9 +165,9 @@ exynos_drm_fb_init(struct drm_file *file_priv, struct drm_device *dev, ...@@ -165,9 +165,9 @@ 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(file_priv, dev, exynos_gem_obj = exynos_drm_gem_create(dev, file_priv,
size, &mode_cmd->handle,
&mode_cmd->handle); 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;
......
...@@ -62,40 +62,28 @@ static unsigned int get_gem_mmap_offset(struct drm_gem_object *obj) ...@@ -62,40 +62,28 @@ 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;
} }
struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_file *file_priv, static struct exynos_drm_gem_obj
struct drm_device *dev, unsigned int size, *exynos_drm_gem_init(struct drm_device *drm_dev,
unsigned int *handle) struct drm_file *file_priv, unsigned int *handle,
unsigned int size)
{ {
struct exynos_drm_gem_obj *exynos_gem_obj; struct exynos_drm_gem_obj *exynos_gem_obj;
struct exynos_drm_buf_entry *entry;
struct drm_gem_object *obj; struct drm_gem_object *obj;
int ret; int ret;
DRM_DEBUG_KMS("%s\n", __FILE__);
size = roundup(size, PAGE_SIZE);
exynos_gem_obj = kzalloc(sizeof(*exynos_gem_obj), GFP_KERNEL); exynos_gem_obj = kzalloc(sizeof(*exynos_gem_obj), GFP_KERNEL);
if (!exynos_gem_obj) { if (!exynos_gem_obj) {
DRM_ERROR("failed to allocate exynos gem object.\n"); DRM_ERROR("failed to allocate exynos gem object.\n");
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
} }
/* allocate the new buffer object and memory region. */
entry = exynos_drm_buf_create(dev, size);
if (!entry) {
kfree(exynos_gem_obj);
return ERR_PTR(-ENOMEM);
}
exynos_gem_obj->entry = entry;
obj = &exynos_gem_obj->base; obj = &exynos_gem_obj->base;
ret = drm_gem_object_init(dev, obj, size); ret = drm_gem_object_init(drm_dev, obj, size);
if (ret < 0) { if (ret < 0) {
DRM_ERROR("failed to initailize gem object.\n"); DRM_ERROR("failed to initialize gem object.\n");
goto err_obj_init; ret = -EINVAL;
goto err_object_init;
} }
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);
...@@ -127,24 +115,55 @@ struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_file *file_priv, ...@@ -127,24 +115,55 @@ struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_file *file_priv,
err_create_mmap_offset: err_create_mmap_offset:
drm_gem_object_release(obj); drm_gem_object_release(obj);
err_obj_init: err_object_init:
exynos_drm_buf_destroy(dev, exynos_gem_obj->entry);
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 drm_file *file_priv,
unsigned int *handle, unsigned long size)
{
struct exynos_drm_gem_obj *exynos_gem_obj = NULL;
struct exynos_drm_buf_entry *entry;
int ret;
size = roundup(size, PAGE_SIZE);
DRM_DEBUG_KMS("%s: size = 0x%lx\n", __FILE__, size);
entry = exynos_drm_buf_create(dev, size);
if (!entry)
return ERR_PTR(-ENOMEM);
exynos_gem_obj = exynos_drm_gem_init(dev, file_priv, handle, size);
if (IS_ERR(exynos_gem_obj)) {
ret = PTR_ERR(exynos_gem_obj);
goto err_gem_init;
}
exynos_gem_obj->entry = entry;
return exynos_gem_obj;
err_gem_init:
exynos_drm_buf_destroy(dev, exynos_gem_obj->entry);
return ERR_PTR(ret);
}
int exynos_drm_gem_create_ioctl(struct drm_device *dev, void *data, 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; struct exynos_drm_gem_obj *exynos_gem_obj = NULL;
DRM_DEBUG_KMS("%s : size = 0x%x\n", __FILE__, args->size); DRM_DEBUG_KMS("%s\n", __FILE__);
exynos_gem_obj = exynos_drm_gem_create(file_priv, dev, args->size, exynos_gem_obj = exynos_drm_gem_create(dev, file_priv,
&args->handle); &args->handle, 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);
...@@ -302,8 +321,8 @@ int exynos_drm_gem_dumb_create(struct drm_file *file_priv, ...@@ -302,8 +321,8 @@ 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(file_priv, dev, args->size, exynos_gem_obj = exynos_drm_gem_create(dev, file_priv, &args->handle,
&args->handle); 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);
......
...@@ -49,9 +49,9 @@ struct exynos_drm_gem_obj { ...@@ -49,9 +49,9 @@ 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_file *file_priv, struct exynos_drm_gem_obj *exynos_drm_gem_create(struct drm_device *dev,
struct drm_device *dev, unsigned int size, struct drm_file *file_priv,
unsigned int *handle); 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
......
...@@ -32,17 +32,16 @@ ...@@ -32,17 +32,16 @@
/** /**
* User-desired buffer creation information structure. * User-desired buffer creation information structure.
* *
* @size: requested size for the object. * @size: user-desired memory allocation size.
* - this size value would be page-aligned internally. * - this size value would be page-aligned internally.
* @flags: user request for setting memory type or cache attributes. * @flags: user request for setting memory type or cache attributes.
* @handle: returned handle for the object. * @handle: returned a handle to created gem object.
* @pad: just padding to be 64-bit aligned. * - this handle will be set by gem module of kernel side.
*/ */
struct drm_exynos_gem_create { struct drm_exynos_gem_create {
unsigned int size; uint64_t size;
unsigned int flags; unsigned int flags;
unsigned int handle; unsigned int handle;
unsigned int pad;
}; };
/** /**
......
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