21 #include <linux/slab.h>
23 #include <linux/export.h>
30 static unsigned int get_gem_mmap_offset(
struct drm_gem_object *obj)
32 return (
unsigned int)obj->map_list.hash.key <<
PAGE_SHIFT;
35 static void drm_gem_cma_buf_destroy(
struct drm_device *drm,
52 struct drm_gem_object *gem_obj;
57 cma_obj = kzalloc(
sizeof(*cma_obj),
GFP_KERNEL);
63 if (!cma_obj->
vaddr) {
64 dev_err(drm->dev,
"failed to allocate buffer with size %d\n", size);
69 gem_obj = &cma_obj->
base;
77 goto err_create_mmap_offset;
81 err_create_mmap_offset:
85 drm_gem_cma_buf_destroy(drm, cma_obj);
102 struct drm_file *file_priv,
107 struct drm_gem_object *gem_obj;
114 gem_obj = &cma_obj->
base;
122 goto err_handle_create;
125 drm_gem_object_unreference_unlocked(gem_obj);
143 if (gem_obj->map_list.map)
148 cma_obj = to_drm_gem_cma_obj(gem_obj);
150 drm_gem_cma_buf_destroy(gem_obj->dev, cma_obj);
169 if (args->
pitch < min_pitch)
170 args->
pitch = min_pitch;
175 cma_obj = drm_gem_cma_create_with_handle(file_priv, dev,
178 return PTR_ERR(cma_obj);
191 struct drm_gem_object *gem_obj;
197 dev_err(drm->dev,
"failed to lookup gem object\n");
202 *offset = get_gem_mmap_offset(gem_obj);
204 drm_gem_object_unreference(gem_obj);
223 struct drm_gem_object *gem_obj;
232 cma_obj = to_drm_gem_cma_obj(gem_obj);