drm: Create a driver hook for allocating GEM object structs.

The CMA helpers had no way for a driver to extend the struct with its
own fields.  Since the CMA helpers are mostly "Allocate a
drm_gem_cma_object, then fill in a few fields", it's hard to write as
pure helpers without passing in a driver callback for the allocate
step.

Signed-off-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
Eric Anholt 2015-11-30 10:55:13 -08:00
parent 8005c49d9a
commit 10028c5ab1
2 changed files with 13 additions and 4 deletions

View File

@ -59,11 +59,13 @@ __drm_gem_cma_create(struct drm_device *drm, size_t size)
struct drm_gem_object *gem_obj; struct drm_gem_object *gem_obj;
int ret; int ret;
cma_obj = kzalloc(sizeof(*cma_obj), GFP_KERNEL); if (drm->driver->gem_create_object)
if (!cma_obj) gem_obj = drm->driver->gem_create_object(drm, size);
else
gem_obj = kzalloc(sizeof(*cma_obj), GFP_KERNEL);
if (!gem_obj)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
cma_obj = container_of(gem_obj, struct drm_gem_cma_object, base);
gem_obj = &cma_obj->base;
ret = drm_gem_object_init(drm, gem_obj, size); ret = drm_gem_object_init(drm, gem_obj, size);
if (ret) if (ret)

View File

@ -580,6 +580,13 @@ struct drm_driver {
int (*gem_open_object) (struct drm_gem_object *, struct drm_file *); int (*gem_open_object) (struct drm_gem_object *, struct drm_file *);
void (*gem_close_object) (struct drm_gem_object *, struct drm_file *); void (*gem_close_object) (struct drm_gem_object *, struct drm_file *);
/**
* Hook for allocating the GEM object struct, for use by core
* helpers.
*/
struct drm_gem_object *(*gem_create_object)(struct drm_device *dev,
size_t size);
/* prime: */ /* prime: */
/* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */ /* export handle -> fd (see drm_gem_prime_handle_to_fd() helper) */
int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv, int (*prime_handle_to_fd)(struct drm_device *dev, struct drm_file *file_priv,