Linux 4.14.5
[linux/fpc-iii.git] / include / drm / drm_gem_cma_helper.h
blob520e3feb502c569374f5c30f69f1afdb449728b9
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __DRM_GEM_CMA_HELPER_H__
3 #define __DRM_GEM_CMA_HELPER_H__
5 #include <drm/drmP.h>
6 #include <drm/drm_gem.h>
8 /**
9 * struct drm_gem_cma_object - GEM object backed by CMA memory allocations
10 * @base: base GEM object
11 * @paddr: physical address of the backing memory
12 * @sgt: scatter/gather table for imported PRIME buffers
13 * @vaddr: kernel virtual address of the backing memory
15 struct drm_gem_cma_object {
16 struct drm_gem_object base;
17 dma_addr_t paddr;
18 struct sg_table *sgt;
20 /* For objects with DMA memory allocated by GEM CMA */
21 void *vaddr;
24 static inline struct drm_gem_cma_object *
25 to_drm_gem_cma_obj(struct drm_gem_object *gem_obj)
27 return container_of(gem_obj, struct drm_gem_cma_object, base);
30 #ifndef CONFIG_MMU
31 #define DRM_GEM_CMA_UNMAPPED_AREA_FOPS \
32 .get_unmapped_area = drm_gem_cma_get_unmapped_area,
33 #else
34 #define DRM_GEM_CMA_UNMAPPED_AREA_FOPS
35 #endif
37 /**
38 * DEFINE_DRM_GEM_CMA_FOPS() - macro to generate file operations for CMA drivers
39 * @name: name for the generated structure
41 * This macro autogenerates a suitable &struct file_operations for CMA based
42 * drivers, which can be assigned to &drm_driver.fops. Note that this structure
43 * cannot be shared between drivers, because it contains a reference to the
44 * current module using THIS_MODULE.
46 * Note that the declaration is already marked as static - if you need a
47 * non-static version of this you're probably doing it wrong and will break the
48 * THIS_MODULE reference by accident.
50 #define DEFINE_DRM_GEM_CMA_FOPS(name) \
51 static const struct file_operations name = {\
52 .owner = THIS_MODULE,\
53 .open = drm_open,\
54 .release = drm_release,\
55 .unlocked_ioctl = drm_ioctl,\
56 .compat_ioctl = drm_compat_ioctl,\
57 .poll = drm_poll,\
58 .read = drm_read,\
59 .llseek = noop_llseek,\
60 .mmap = drm_gem_cma_mmap,\
61 DRM_GEM_CMA_UNMAPPED_AREA_FOPS \
64 /* free GEM object */
65 void drm_gem_cma_free_object(struct drm_gem_object *gem_obj);
67 /* create memory region for DRM framebuffer */
68 int drm_gem_cma_dumb_create_internal(struct drm_file *file_priv,
69 struct drm_device *drm,
70 struct drm_mode_create_dumb *args);
72 /* create memory region for DRM framebuffer */
73 int drm_gem_cma_dumb_create(struct drm_file *file_priv,
74 struct drm_device *drm,
75 struct drm_mode_create_dumb *args);
77 /* set vm_flags and we can change the VM attribute to other one at here */
78 int drm_gem_cma_mmap(struct file *filp, struct vm_area_struct *vma);
80 /* allocate physical memory */
81 struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm,
82 size_t size);
84 extern const struct vm_operations_struct drm_gem_cma_vm_ops;
86 #ifndef CONFIG_MMU
87 unsigned long drm_gem_cma_get_unmapped_area(struct file *filp,
88 unsigned long addr,
89 unsigned long len,
90 unsigned long pgoff,
91 unsigned long flags);
92 #endif
94 #ifdef CONFIG_DEBUG_FS
95 void drm_gem_cma_describe(struct drm_gem_cma_object *obj, struct seq_file *m);
96 #endif
98 struct sg_table *drm_gem_cma_prime_get_sg_table(struct drm_gem_object *obj);
99 struct drm_gem_object *
100 drm_gem_cma_prime_import_sg_table(struct drm_device *dev,
101 struct dma_buf_attachment *attach,
102 struct sg_table *sgt);
103 int drm_gem_cma_prime_mmap(struct drm_gem_object *obj,
104 struct vm_area_struct *vma);
105 void *drm_gem_cma_prime_vmap(struct drm_gem_object *obj);
106 void drm_gem_cma_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
108 #endif /* __DRM_GEM_CMA_HELPER_H__ */