Commit 4d92d7d7 authored by Thomas Zimmermann's avatar Thomas Zimmermann

drm/vram-helper: Set object function iff they are not provided by driver

Don't override the GEM object functions unconditionally. If the driver
sets the GEM functions, VRAM helpers will not set them. The idea has been
taken from SHMEM helpers.

v2:
	* updated the commit message (Sam)
	* document the new feature for drm_gem_vram_create()
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20200922145700.25413-3-tzimmermann@suse.de
parent 7faa92df
...@@ -173,6 +173,12 @@ static void drm_gem_vram_placement(struct drm_gem_vram_object *gbo, ...@@ -173,6 +173,12 @@ static void drm_gem_vram_placement(struct drm_gem_vram_object *gbo,
* @size: the buffer size in bytes * @size: the buffer size in bytes
* @pg_align: the buffer's alignment in multiples of the page size * @pg_align: the buffer's alignment in multiples of the page size
* *
* GEM objects are allocated by calling struct drm_driver.gem_create_object,
* if set. Otherwise kzalloc() will be used. Drivers can set their own GEM
* object functions in struct drm_driver.gem_create_object. If no functions
* are set, the new GEM object will use the default functions from GEM VRAM
* helpers.
*
* Returns: * Returns:
* A new instance of &struct drm_gem_vram_object on success, or * A new instance of &struct drm_gem_vram_object on success, or
* an ERR_PTR()-encoded error code otherwise. * an ERR_PTR()-encoded error code otherwise.
...@@ -182,6 +188,7 @@ struct drm_gem_vram_object *drm_gem_vram_create(struct drm_device *dev, ...@@ -182,6 +188,7 @@ struct drm_gem_vram_object *drm_gem_vram_create(struct drm_device *dev,
unsigned long pg_align) unsigned long pg_align)
{ {
struct drm_gem_vram_object *gbo; struct drm_gem_vram_object *gbo;
struct drm_gem_object *gem;
struct drm_vram_mm *vmm = dev->vram_mm; struct drm_vram_mm *vmm = dev->vram_mm;
struct ttm_bo_device *bdev; struct ttm_bo_device *bdev;
int ret; int ret;
...@@ -191,8 +198,7 @@ struct drm_gem_vram_object *drm_gem_vram_create(struct drm_device *dev, ...@@ -191,8 +198,7 @@ struct drm_gem_vram_object *drm_gem_vram_create(struct drm_device *dev,
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
if (dev->driver->gem_create_object) { if (dev->driver->gem_create_object) {
struct drm_gem_object *gem = gem = dev->driver->gem_create_object(dev, size);
dev->driver->gem_create_object(dev, size);
if (!gem) if (!gem)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
gbo = drm_gem_vram_of_gem(gem); gbo = drm_gem_vram_of_gem(gem);
...@@ -200,11 +206,13 @@ struct drm_gem_vram_object *drm_gem_vram_create(struct drm_device *dev, ...@@ -200,11 +206,13 @@ struct drm_gem_vram_object *drm_gem_vram_create(struct drm_device *dev,
gbo = kzalloc(sizeof(*gbo), GFP_KERNEL); gbo = kzalloc(sizeof(*gbo), GFP_KERNEL);
if (!gbo) if (!gbo)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
gem = &gbo->bo.base;
} }
gbo->bo.base.funcs = &drm_gem_vram_object_funcs; if (!gem->funcs)
gem->funcs = &drm_gem_vram_object_funcs;
ret = drm_gem_object_init(dev, &gbo->bo.base, size); ret = drm_gem_object_init(dev, gem, size);
if (ret) { if (ret) {
kfree(gbo); kfree(gbo);
return ERR_PTR(ret); return ERR_PTR(ret);
......
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