1
2#ifndef __DRM_GEM_CMA_HELPER_H__
3#define __DRM_GEM_CMA_HELPER_H__
4
5#include <drm/drm_file.h>
6#include <drm/drm_ioctl.h>
7#include <drm/drm_gem.h>
8
9struct drm_mode_create_dumb;
10
11
12
13
14
15
16
17
18
19
20struct drm_gem_cma_object {
21 struct drm_gem_object base;
22 dma_addr_t paddr;
23 struct sg_table *sgt;
24
25
26 void *vaddr;
27};
28
29#define to_drm_gem_cma_obj(gem_obj) \
30 container_of(gem_obj, struct drm_gem_cma_object, base)
31
32#ifndef CONFIG_MMU
33#define DRM_GEM_CMA_UNMAPPED_AREA_FOPS \
34 .get_unmapped_area = drm_gem_cma_get_unmapped_area,
35#else
36#define DRM_GEM_CMA_UNMAPPED_AREA_FOPS
37#endif
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52#define DEFINE_DRM_GEM_CMA_FOPS(name) \
53 static const struct file_operations name = {\
54 .owner = THIS_MODULE,\
55 .open = drm_open,\
56 .release = drm_release,\
57 .unlocked_ioctl = drm_ioctl,\
58 .compat_ioctl = drm_compat_ioctl,\
59 .poll = drm_poll,\
60 .read = drm_read,\
61 .llseek = noop_llseek,\
62 .mmap = drm_gem_mmap,\
63 DRM_GEM_CMA_UNMAPPED_AREA_FOPS \
64 }
65
66
67void drm_gem_cma_free_object(struct drm_gem_object *gem_obj);
68
69
70int drm_gem_cma_dumb_create_internal(struct drm_file *file_priv,
71 struct drm_device *drm,
72 struct drm_mode_create_dumb *args);
73
74
75int drm_gem_cma_dumb_create(struct drm_file *file_priv,
76 struct drm_device *drm,
77 struct drm_mode_create_dumb *args);
78
79
80struct drm_gem_cma_object *drm_gem_cma_create(struct drm_device *drm,
81 size_t size);
82
83extern const struct vm_operations_struct drm_gem_cma_vm_ops;
84
85#ifndef CONFIG_MMU
86unsigned long drm_gem_cma_get_unmapped_area(struct file *filp,
87 unsigned long addr,
88 unsigned long len,
89 unsigned long pgoff,
90 unsigned long flags);
91#endif
92
93void drm_gem_cma_print_info(struct drm_printer *p, unsigned int indent,
94 const struct drm_gem_object *obj);
95
96struct sg_table *drm_gem_cma_get_sg_table(struct drm_gem_object *obj);
97struct drm_gem_object *
98drm_gem_cma_prime_import_sg_table(struct drm_device *dev,
99 struct dma_buf_attachment *attach,
100 struct sg_table *sgt);
101int drm_gem_cma_vmap(struct drm_gem_object *obj, struct dma_buf_map *map);
102int drm_gem_cma_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117#define DRM_GEM_CMA_DRIVER_OPS_WITH_DUMB_CREATE(dumb_create_func) \
118 .dumb_create = (dumb_create_func), \
119 .prime_handle_to_fd = drm_gem_prime_handle_to_fd, \
120 .prime_fd_to_handle = drm_gem_prime_fd_to_handle, \
121 .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table, \
122 .gem_prime_mmap = drm_gem_prime_mmap
123
124
125
126
127
128
129
130
131
132
133
134
135
136#define DRM_GEM_CMA_DRIVER_OPS \
137 DRM_GEM_CMA_DRIVER_OPS_WITH_DUMB_CREATE(drm_gem_cma_dumb_create)
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155#define DRM_GEM_CMA_DRIVER_OPS_VMAP_WITH_DUMB_CREATE(dumb_create_func) \
156 .dumb_create = dumb_create_func, \
157 .prime_handle_to_fd = drm_gem_prime_handle_to_fd, \
158 .prime_fd_to_handle = drm_gem_prime_fd_to_handle, \
159 .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table_vmap, \
160 .gem_prime_mmap = drm_gem_prime_mmap
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177#define DRM_GEM_CMA_DRIVER_OPS_VMAP \
178 DRM_GEM_CMA_DRIVER_OPS_VMAP_WITH_DUMB_CREATE(drm_gem_cma_dumb_create)
179
180struct drm_gem_object *
181drm_gem_cma_prime_import_sg_table_vmap(struct drm_device *drm,
182 struct dma_buf_attachment *attach,
183 struct sg_table *sgt);
184
185#endif
186