This source file includes following definitions.
- drm_gem_fb_get_obj
- drm_gem_fb_alloc
- drm_gem_fb_destroy
- drm_gem_fb_create_handle
- drm_gem_fb_create_with_funcs
- drm_gem_fb_create
- drm_gem_fb_create_with_dirty
- drm_gem_fb_prepare_fb
- drm_gem_fb_simple_display_pipe_prepare_fb
1
2
3
4
5
6
7
8 #include <linux/dma-buf.h>
9 #include <linux/dma-fence.h>
10 #include <linux/dma-resv.h>
11 #include <linux/slab.h>
12
13 #include <drm/drm_atomic.h>
14 #include <drm/drm_atomic_uapi.h>
15 #include <drm/drm_damage_helper.h>
16 #include <drm/drm_fb_helper.h>
17 #include <drm/drm_fourcc.h>
18 #include <drm/drm_framebuffer.h>
19 #include <drm/drm_gem.h>
20 #include <drm/drm_gem_framebuffer_helper.h>
21 #include <drm/drm_modeset_helper.h>
22 #include <drm/drm_simple_kms_helper.h>
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
48 unsigned int plane)
49 {
50 if (plane >= 4)
51 return NULL;
52
53 return fb->obj[plane];
54 }
55 EXPORT_SYMBOL_GPL(drm_gem_fb_get_obj);
56
57 static struct drm_framebuffer *
58 drm_gem_fb_alloc(struct drm_device *dev,
59 const struct drm_mode_fb_cmd2 *mode_cmd,
60 struct drm_gem_object **obj, unsigned int num_planes,
61 const struct drm_framebuffer_funcs *funcs)
62 {
63 struct drm_framebuffer *fb;
64 int ret, i;
65
66 fb = kzalloc(sizeof(*fb), GFP_KERNEL);
67 if (!fb)
68 return ERR_PTR(-ENOMEM);
69
70 drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
71
72 for (i = 0; i < num_planes; i++)
73 fb->obj[i] = obj[i];
74
75 ret = drm_framebuffer_init(dev, fb, funcs);
76 if (ret) {
77 DRM_DEV_ERROR(dev->dev, "Failed to init framebuffer: %d\n",
78 ret);
79 kfree(fb);
80 return ERR_PTR(ret);
81 }
82
83 return fb;
84 }
85
86
87
88
89
90
91
92
93
94 void drm_gem_fb_destroy(struct drm_framebuffer *fb)
95 {
96 int i;
97
98 for (i = 0; i < 4; i++)
99 drm_gem_object_put_unlocked(fb->obj[i]);
100
101 drm_framebuffer_cleanup(fb);
102 kfree(fb);
103 }
104 EXPORT_SYMBOL(drm_gem_fb_destroy);
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119 int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file,
120 unsigned int *handle)
121 {
122 return drm_gem_handle_create(file, fb->obj[0], handle);
123 }
124 EXPORT_SYMBOL(drm_gem_fb_create_handle);
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142 struct drm_framebuffer *
143 drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
144 const struct drm_mode_fb_cmd2 *mode_cmd,
145 const struct drm_framebuffer_funcs *funcs)
146 {
147 const struct drm_format_info *info;
148 struct drm_gem_object *objs[4];
149 struct drm_framebuffer *fb;
150 int ret, i;
151
152 info = drm_get_format_info(dev, mode_cmd);
153 if (!info)
154 return ERR_PTR(-EINVAL);
155
156 for (i = 0; i < info->num_planes; i++) {
157 unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
158 unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
159 unsigned int min_size;
160
161 objs[i] = drm_gem_object_lookup(file, mode_cmd->handles[i]);
162 if (!objs[i]) {
163 DRM_DEBUG_KMS("Failed to lookup GEM object\n");
164 ret = -ENOENT;
165 goto err_gem_object_put;
166 }
167
168 min_size = (height - 1) * mode_cmd->pitches[i]
169 + drm_format_info_min_pitch(info, i, width)
170 + mode_cmd->offsets[i];
171
172 if (objs[i]->size < min_size) {
173 drm_gem_object_put_unlocked(objs[i]);
174 ret = -EINVAL;
175 goto err_gem_object_put;
176 }
177 }
178
179 fb = drm_gem_fb_alloc(dev, mode_cmd, objs, i, funcs);
180 if (IS_ERR(fb)) {
181 ret = PTR_ERR(fb);
182 goto err_gem_object_put;
183 }
184
185 return fb;
186
187 err_gem_object_put:
188 for (i--; i >= 0; i--)
189 drm_gem_object_put_unlocked(objs[i]);
190
191 return ERR_PTR(ret);
192 }
193 EXPORT_SYMBOL_GPL(drm_gem_fb_create_with_funcs);
194
195 static const struct drm_framebuffer_funcs drm_gem_fb_funcs = {
196 .destroy = drm_gem_fb_destroy,
197 .create_handle = drm_gem_fb_create_handle,
198 };
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222 struct drm_framebuffer *
223 drm_gem_fb_create(struct drm_device *dev, struct drm_file *file,
224 const struct drm_mode_fb_cmd2 *mode_cmd)
225 {
226 return drm_gem_fb_create_with_funcs(dev, file, mode_cmd,
227 &drm_gem_fb_funcs);
228 }
229 EXPORT_SYMBOL_GPL(drm_gem_fb_create);
230
231 static const struct drm_framebuffer_funcs drm_gem_fb_funcs_dirtyfb = {
232 .destroy = drm_gem_fb_destroy,
233 .create_handle = drm_gem_fb_create_handle,
234 .dirty = drm_atomic_helper_dirtyfb,
235 };
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260 struct drm_framebuffer *
261 drm_gem_fb_create_with_dirty(struct drm_device *dev, struct drm_file *file,
262 const struct drm_mode_fb_cmd2 *mode_cmd)
263 {
264 return drm_gem_fb_create_with_funcs(dev, file, mode_cmd,
265 &drm_gem_fb_funcs_dirtyfb);
266 }
267 EXPORT_SYMBOL_GPL(drm_gem_fb_create_with_dirty);
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287 int drm_gem_fb_prepare_fb(struct drm_plane *plane,
288 struct drm_plane_state *state)
289 {
290 struct drm_gem_object *obj;
291 struct dma_fence *fence;
292
293 if (!state->fb)
294 return 0;
295
296 obj = drm_gem_fb_get_obj(state->fb, 0);
297 fence = dma_resv_get_excl_rcu(obj->resv);
298 drm_atomic_set_fence_for_plane(state, fence);
299
300 return 0;
301 }
302 EXPORT_SYMBOL_GPL(drm_gem_fb_prepare_fb);
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319 int drm_gem_fb_simple_display_pipe_prepare_fb(struct drm_simple_display_pipe *pipe,
320 struct drm_plane_state *plane_state)
321 {
322 return drm_gem_fb_prepare_fb(&pipe->plane, plane_state);
323 }
324 EXPORT_SYMBOL(drm_gem_fb_simple_display_pipe_prepare_fb);