blob: c8a7829d73d6a378b0540e28f91d474ffe9396d8 [file] [log] [blame]
Daniel Vetter7520a272016-08-15 16:07:02 +02001/*
2 * Copyright (c) 2016 Intel Corporation
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23#include <linux/export.h>
24#include <drm/drmP.h>
25#include <drm/drm_auth.h>
26#include <drm/drm_framebuffer.h>
Daniel Vetter941b8ca2017-04-03 10:33:03 +020027#include <drm/drm_atomic.h>
Noralf Trønnes45d58b42017-11-07 20:13:40 +010028#include <drm/drm_print.h>
Daniel Vetter7520a272016-08-15 16:07:02 +020029
Noralf Trønnes45d58b42017-11-07 20:13:40 +010030#include "drm_internal.h"
Daniel Vetter7520a272016-08-15 16:07:02 +020031#include "drm_crtc_internal.h"
32
33/**
Daniel Vetter750fb8c2016-08-12 22:48:48 +020034 * DOC: overview
35 *
36 * Frame buffers are abstract memory objects that provide a source of pixels to
37 * scanout to a CRTC. Applications explicitly request the creation of frame
38 * buffers through the DRM_IOCTL_MODE_ADDFB(2) ioctls and receive an opaque
39 * handle that can be passed to the KMS CRTC control, plane configuration and
40 * page flip functions.
41 *
42 * Frame buffers rely on the underlying memory manager for allocating backing
43 * storage. When creating a frame buffer applications pass a memory handle
44 * (or a list of memory handles for multi-planar formats) through the
Daniel Vetterea0dd852016-12-29 21:48:26 +010045 * &struct drm_mode_fb_cmd2 argument. For drivers using GEM as their userspace
Daniel Vetter750fb8c2016-08-12 22:48:48 +020046 * buffer management interface this would be a GEM handle. Drivers are however
47 * free to use their own backing storage object handles, e.g. vmwgfx directly
48 * exposes special TTM handles to userspace and so expects TTM handles in the
49 * create ioctl and not GEM handles.
50 *
Daniel Vetterea0dd852016-12-29 21:48:26 +010051 * Framebuffers are tracked with &struct drm_framebuffer. They are published
Daniel Vetter750fb8c2016-08-12 22:48:48 +020052 * using drm_framebuffer_init() - after calling that function userspace can use
53 * and access the framebuffer object. The helper function
54 * drm_helper_mode_fill_fb_struct() can be used to pre-fill the required
55 * metadata fields.
56 *
57 * The lifetime of a drm framebuffer is controlled with a reference count,
Thierry Redinga4a69da2017-02-28 15:46:40 +010058 * drivers can grab additional references with drm_framebuffer_get() and drop
59 * them again with drm_framebuffer_put(). For driver-private framebuffers for
60 * which the last reference is never dropped (e.g. for the fbdev framebuffer
61 * when the struct &struct drm_framebuffer is embedded into the fbdev helper
62 * struct) drivers can manually clean up a framebuffer at module unload time
63 * with drm_framebuffer_unregister_private(). But doing this is not
64 * recommended, and it's better to have a normal free-standing &struct
Daniel Vetterd5745282017-01-25 07:26:45 +010065 * drm_framebuffer.
Daniel Vetter750fb8c2016-08-12 22:48:48 +020066 */
67
Daniel Vetter43968d72016-09-21 10:59:24 +020068int drm_framebuffer_check_src_coords(uint32_t src_x, uint32_t src_y,
69 uint32_t src_w, uint32_t src_h,
70 const struct drm_framebuffer *fb)
71{
72 unsigned int fb_width, fb_height;
73
74 fb_width = fb->width << 16;
75 fb_height = fb->height << 16;
76
77 /* Make sure source coordinates are inside the fb. */
78 if (src_w > fb_width ||
79 src_x > fb_width - src_w ||
80 src_h > fb_height ||
81 src_y > fb_height - src_h) {
82 DRM_DEBUG_KMS("Invalid source coordinates "
Ville Syrjälä0338f0d2017-11-01 20:35:33 +020083 "%u.%06ux%u.%06u+%u.%06u+%u.%06u (fb %ux%u)\n",
Daniel Vetter43968d72016-09-21 10:59:24 +020084 src_w >> 16, ((src_w & 0xffff) * 15625) >> 10,
85 src_h >> 16, ((src_h & 0xffff) * 15625) >> 10,
86 src_x >> 16, ((src_x & 0xffff) * 15625) >> 10,
Ville Syrjälä0338f0d2017-11-01 20:35:33 +020087 src_y >> 16, ((src_y & 0xffff) * 15625) >> 10,
88 fb->width, fb->height);
Daniel Vetter43968d72016-09-21 10:59:24 +020089 return -ENOSPC;
90 }
91
92 return 0;
93}
94
Daniel Vetter750fb8c2016-08-12 22:48:48 +020095/**
Daniel Vetter7520a272016-08-15 16:07:02 +020096 * drm_mode_addfb - add an FB to the graphics configuration
97 * @dev: drm device for the ioctl
Noralf Trønnesd30827c2018-06-18 16:17:30 +020098 * @or: pointer to request structure
99 * @file_priv: drm file
Daniel Vetter7520a272016-08-15 16:07:02 +0200100 *
101 * Add a new FB to the specified CRTC, given a user request. This is the
102 * original addfb ioctl which only supported RGB formats.
103 *
Noralf Trønnesd30827c2018-06-18 16:17:30 +0200104 * Called by the user via ioctl, or by an in-kernel client.
Daniel Vetter7520a272016-08-15 16:07:02 +0200105 *
106 * Returns:
107 * Zero on success, negative errno on failure.
108 */
Noralf Trønnesd30827c2018-06-18 16:17:30 +0200109int drm_mode_addfb(struct drm_device *dev, struct drm_mode_fb_cmd *or,
110 struct drm_file *file_priv)
Daniel Vetter7520a272016-08-15 16:07:02 +0200111{
Daniel Vetter7520a272016-08-15 16:07:02 +0200112 struct drm_mode_fb_cmd2 r = {};
113 int ret;
114
Chris Wilson70109352018-09-05 16:31:16 +0100115 r.pixel_format = drm_mode_legacy_fb_format(or->bpp, or->depth);
116 if (r.pixel_format == DRM_FORMAT_INVALID) {
117 DRM_DEBUG("bad {bpp:%d, depth:%d}\n", or->bpp, or->depth);
118 return -EINVAL;
119 }
120
Daniel Vetter7520a272016-08-15 16:07:02 +0200121 /* convert to new format and call new ioctl */
122 r.fb_id = or->fb_id;
123 r.width = or->width;
124 r.height = or->height;
125 r.pitches[0] = or->pitch;
Daniel Vetter7520a272016-08-15 16:07:02 +0200126 r.handles[0] = or->handle;
127
Gerd Hoffmann0e940432018-09-05 08:04:40 +0200128 if (dev->mode_config.quirk_addfb_prefer_xbgr_30bpp &&
129 r.pixel_format == DRM_FORMAT_XRGB2101010)
Ilia Mirkinc20bb152018-02-03 14:11:23 -0500130 r.pixel_format = DRM_FORMAT_XBGR2101010;
131
Gerd Hoffmann6960e6d2018-09-05 08:04:43 +0200132 if (dev->mode_config.quirk_addfb_prefer_host_byte_order) {
133 if (r.pixel_format == DRM_FORMAT_XRGB8888)
134 r.pixel_format = DRM_FORMAT_HOST_XRGB8888;
135 if (r.pixel_format == DRM_FORMAT_ARGB8888)
136 r.pixel_format = DRM_FORMAT_HOST_ARGB8888;
137 if (r.pixel_format == DRM_FORMAT_RGB565)
138 r.pixel_format = DRM_FORMAT_HOST_RGB565;
139 if (r.pixel_format == DRM_FORMAT_XRGB1555)
140 r.pixel_format = DRM_FORMAT_HOST_XRGB1555;
141 }
142
Daniel Vetter7520a272016-08-15 16:07:02 +0200143 ret = drm_mode_addfb2(dev, &r, file_priv);
144 if (ret)
145 return ret;
146
147 or->fb_id = r.fb_id;
148
149 return 0;
150}
151
Noralf Trønnesd30827c2018-06-18 16:17:30 +0200152int drm_mode_addfb_ioctl(struct drm_device *dev,
153 void *data, struct drm_file *file_priv)
154{
155 return drm_mode_addfb(dev, data, file_priv);
156}
157
Ville Syrjälä568c5e42017-03-21 20:12:14 +0200158static int fb_plane_width(int width,
159 const struct drm_format_info *format, int plane)
160{
161 if (plane == 0)
162 return width;
163
Ville Syrjälä33f673a2017-03-21 20:12:15 +0200164 return DIV_ROUND_UP(width, format->hsub);
Ville Syrjälä568c5e42017-03-21 20:12:14 +0200165}
166
167static int fb_plane_height(int height,
168 const struct drm_format_info *format, int plane)
169{
170 if (plane == 0)
171 return height;
172
Ville Syrjälä33f673a2017-03-21 20:12:15 +0200173 return DIV_ROUND_UP(height, format->vsub);
Ville Syrjälä568c5e42017-03-21 20:12:14 +0200174}
175
Ville Syrjälä6a0f9eb2017-03-21 20:12:16 +0200176static int framebuffer_check(struct drm_device *dev,
177 const struct drm_mode_fb_cmd2 *r)
Daniel Vetter7520a272016-08-15 16:07:02 +0200178{
Laurent Pinchartd5493492016-10-18 01:41:11 +0300179 const struct drm_format_info *info;
180 int i;
Daniel Vetter7520a272016-08-15 16:07:02 +0200181
Ville Syrjälä6a0f9eb2017-03-21 20:12:16 +0200182 /* check if the format is supported at all */
Gerd Hoffmann00409fd2018-09-05 08:04:42 +0200183 info = __drm_format_info(r->pixel_format);
Laurent Pinchartd5493492016-10-18 01:41:11 +0300184 if (!info) {
Eric Engestromb3c11ac2016-11-12 01:12:56 +0000185 struct drm_format_name_buf format_name;
Ville Syrjäläc10496c2018-03-05 16:49:19 +0200186
Eric Engestromb3c11ac2016-11-12 01:12:56 +0000187 DRM_DEBUG_KMS("bad framebuffer format %s\n",
Ville Syrjäläc10496c2018-03-05 16:49:19 +0200188 drm_get_format_name(r->pixel_format,
189 &format_name));
Laurent Pinchartd5493492016-10-18 01:41:11 +0300190 return -EINVAL;
Daniel Vetter7520a272016-08-15 16:07:02 +0200191 }
192
Ville Syrjälä6a0f9eb2017-03-21 20:12:16 +0200193 /* now let the driver pick its own format info */
194 info = drm_get_format_info(dev, r);
195
Ville Syrjälä33f673a2017-03-21 20:12:15 +0200196 if (r->width == 0) {
Daniel Vetter7520a272016-08-15 16:07:02 +0200197 DRM_DEBUG_KMS("bad framebuffer width %u\n", r->width);
198 return -EINVAL;
199 }
200
Ville Syrjälä33f673a2017-03-21 20:12:15 +0200201 if (r->height == 0) {
Daniel Vetter7520a272016-08-15 16:07:02 +0200202 DRM_DEBUG_KMS("bad framebuffer height %u\n", r->height);
203 return -EINVAL;
204 }
205
Laurent Pinchartd5493492016-10-18 01:41:11 +0300206 for (i = 0; i < info->num_planes; i++) {
Ville Syrjälä568c5e42017-03-21 20:12:14 +0200207 unsigned int width = fb_plane_width(r->width, info, i);
208 unsigned int height = fb_plane_height(r->height, info, i);
Laurent Pinchartd5493492016-10-18 01:41:11 +0300209 unsigned int cpp = info->cpp[i];
Daniel Vetter7520a272016-08-15 16:07:02 +0200210
211 if (!r->handles[i]) {
212 DRM_DEBUG_KMS("no buffer object handle for plane %d\n", i);
213 return -EINVAL;
214 }
215
216 if ((uint64_t) width * cpp > UINT_MAX)
217 return -ERANGE;
218
219 if ((uint64_t) height * r->pitches[i] + r->offsets[i] > UINT_MAX)
220 return -ERANGE;
221
222 if (r->pitches[i] < width * cpp) {
223 DRM_DEBUG_KMS("bad pitch %u for plane %d\n", r->pitches[i], i);
224 return -EINVAL;
225 }
226
227 if (r->modifier[i] && !(r->flags & DRM_MODE_FB_MODIFIERS)) {
228 DRM_DEBUG_KMS("bad fb modifier %llu for plane %d\n",
229 r->modifier[i], i);
230 return -EINVAL;
231 }
232
Ville Syrjäläbae781b2016-11-16 13:33:16 +0200233 if (r->flags & DRM_MODE_FB_MODIFIERS &&
234 r->modifier[i] != r->modifier[0]) {
235 DRM_DEBUG_KMS("bad fb modifier %llu for plane %d\n",
236 r->modifier[i], i);
237 return -EINVAL;
238 }
239
Daniel Vetter7520a272016-08-15 16:07:02 +0200240 /* modifier specific checks: */
241 switch (r->modifier[i]) {
242 case DRM_FORMAT_MOD_SAMSUNG_64_32_TILE:
243 /* NOTE: the pitch restriction may be lifted later if it turns
244 * out that no hw has this restriction:
245 */
246 if (r->pixel_format != DRM_FORMAT_NV12 ||
247 width % 128 || height % 32 ||
248 r->pitches[i] % 128) {
249 DRM_DEBUG_KMS("bad modifier data for plane %d\n", i);
250 return -EINVAL;
251 }
252 break;
253
254 default:
255 break;
256 }
257 }
258
Laurent Pinchartd5493492016-10-18 01:41:11 +0300259 for (i = info->num_planes; i < 4; i++) {
Daniel Vetter7520a272016-08-15 16:07:02 +0200260 if (r->modifier[i]) {
261 DRM_DEBUG_KMS("non-zero modifier for unused plane %d\n", i);
262 return -EINVAL;
263 }
264
265 /* Pre-FB_MODIFIERS userspace didn't clear the structs properly. */
266 if (!(r->flags & DRM_MODE_FB_MODIFIERS))
267 continue;
268
269 if (r->handles[i]) {
270 DRM_DEBUG_KMS("buffer object handle for unused plane %d\n", i);
271 return -EINVAL;
272 }
273
274 if (r->pitches[i]) {
275 DRM_DEBUG_KMS("non-zero pitch for unused plane %d\n", i);
276 return -EINVAL;
277 }
278
279 if (r->offsets[i]) {
280 DRM_DEBUG_KMS("non-zero offset for unused plane %d\n", i);
281 return -EINVAL;
282 }
283 }
284
285 return 0;
286}
287
288struct drm_framebuffer *
289drm_internal_framebuffer_create(struct drm_device *dev,
290 const struct drm_mode_fb_cmd2 *r,
291 struct drm_file *file_priv)
292{
293 struct drm_mode_config *config = &dev->mode_config;
294 struct drm_framebuffer *fb;
295 int ret;
296
297 if (r->flags & ~(DRM_MODE_FB_INTERLACED | DRM_MODE_FB_MODIFIERS)) {
298 DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r->flags);
299 return ERR_PTR(-EINVAL);
300 }
301
302 if ((config->min_width > r->width) || (r->width > config->max_width)) {
303 DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n",
304 r->width, config->min_width, config->max_width);
305 return ERR_PTR(-EINVAL);
306 }
307 if ((config->min_height > r->height) || (r->height > config->max_height)) {
308 DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n",
309 r->height, config->min_height, config->max_height);
310 return ERR_PTR(-EINVAL);
311 }
312
313 if (r->flags & DRM_MODE_FB_MODIFIERS &&
314 !dev->mode_config.allow_fb_modifiers) {
315 DRM_DEBUG_KMS("driver does not support fb modifiers\n");
316 return ERR_PTR(-EINVAL);
317 }
318
Ville Syrjälä6a0f9eb2017-03-21 20:12:16 +0200319 ret = framebuffer_check(dev, r);
Daniel Vetter7520a272016-08-15 16:07:02 +0200320 if (ret)
321 return ERR_PTR(ret);
322
323 fb = dev->mode_config.funcs->fb_create(dev, file_priv, r);
324 if (IS_ERR(fb)) {
325 DRM_DEBUG_KMS("could not create framebuffer\n");
326 return fb;
327 }
328
329 return fb;
330}
331
332/**
333 * drm_mode_addfb2 - add an FB to the graphics configuration
334 * @dev: drm device for the ioctl
335 * @data: data pointer for the ioctl
336 * @file_priv: drm file for the ioctl call
337 *
338 * Add a new FB to the specified CRTC, given a user request with format. This is
339 * the 2nd version of the addfb ioctl, which supports multi-planar framebuffers
340 * and uses fourcc codes as pixel format specifiers.
341 *
342 * Called by the user via ioctl.
343 *
344 * Returns:
345 * Zero on success, negative errno on failure.
346 */
347int drm_mode_addfb2(struct drm_device *dev,
348 void *data, struct drm_file *file_priv)
349{
350 struct drm_mode_fb_cmd2 *r = data;
351 struct drm_framebuffer *fb;
352
353 if (!drm_core_check_feature(dev, DRIVER_MODESET))
354 return -EINVAL;
355
356 fb = drm_internal_framebuffer_create(dev, r, file_priv);
357 if (IS_ERR(fb))
358 return PTR_ERR(fb);
359
360 DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id);
361 r->fb_id = fb->base.id;
362
363 /* Transfer ownership to the filp for reaping on close */
364 mutex_lock(&file_priv->fbs_lock);
365 list_add(&fb->filp_head, &file_priv->fbs);
366 mutex_unlock(&file_priv->fbs_lock);
367
368 return 0;
369}
370
371struct drm_mode_rmfb_work {
372 struct work_struct work;
373 struct list_head fbs;
374};
375
376static void drm_mode_rmfb_work_fn(struct work_struct *w)
377{
378 struct drm_mode_rmfb_work *arg = container_of(w, typeof(*arg), work);
379
380 while (!list_empty(&arg->fbs)) {
381 struct drm_framebuffer *fb =
382 list_first_entry(&arg->fbs, typeof(*fb), filp_head);
383
384 list_del_init(&fb->filp_head);
385 drm_framebuffer_remove(fb);
386 }
387}
388
389/**
390 * drm_mode_rmfb - remove an FB from the configuration
Noralf Trønnesd30827c2018-06-18 16:17:30 +0200391 * @dev: drm device
392 * @fb_id: id of framebuffer to remove
393 * @file_priv: drm file
Daniel Vetter7520a272016-08-15 16:07:02 +0200394 *
Noralf Trønnesd30827c2018-06-18 16:17:30 +0200395 * Remove the specified FB.
Daniel Vetter7520a272016-08-15 16:07:02 +0200396 *
Noralf Trønnesd30827c2018-06-18 16:17:30 +0200397 * Called by the user via ioctl, or by an in-kernel client.
Daniel Vetter7520a272016-08-15 16:07:02 +0200398 *
399 * Returns:
400 * Zero on success, negative errno on failure.
401 */
Noralf Trønnesd30827c2018-06-18 16:17:30 +0200402int drm_mode_rmfb(struct drm_device *dev, u32 fb_id,
403 struct drm_file *file_priv)
Daniel Vetter7520a272016-08-15 16:07:02 +0200404{
405 struct drm_framebuffer *fb = NULL;
406 struct drm_framebuffer *fbl = NULL;
Daniel Vetter7520a272016-08-15 16:07:02 +0200407 int found = 0;
408
409 if (!drm_core_check_feature(dev, DRIVER_MODESET))
410 return -EINVAL;
411
Noralf Trønnesd30827c2018-06-18 16:17:30 +0200412 fb = drm_framebuffer_lookup(dev, file_priv, fb_id);
Daniel Vetter7520a272016-08-15 16:07:02 +0200413 if (!fb)
414 return -ENOENT;
415
416 mutex_lock(&file_priv->fbs_lock);
417 list_for_each_entry(fbl, &file_priv->fbs, filp_head)
418 if (fb == fbl)
419 found = 1;
420 if (!found) {
421 mutex_unlock(&file_priv->fbs_lock);
422 goto fail_unref;
423 }
424
425 list_del_init(&fb->filp_head);
426 mutex_unlock(&file_priv->fbs_lock);
427
428 /* drop the reference we picked up in framebuffer lookup */
Thierry Redinga4a69da2017-02-28 15:46:40 +0100429 drm_framebuffer_put(fb);
Daniel Vetter7520a272016-08-15 16:07:02 +0200430
431 /*
432 * we now own the reference that was stored in the fbs list
433 *
434 * drm_framebuffer_remove may fail with -EINTR on pending signals,
435 * so run this in a separate stack as there's no way to correctly
436 * handle this after the fb is already removed from the lookup table.
437 */
438 if (drm_framebuffer_read_refcount(fb) > 1) {
439 struct drm_mode_rmfb_work arg;
440
441 INIT_WORK_ONSTACK(&arg.work, drm_mode_rmfb_work_fn);
442 INIT_LIST_HEAD(&arg.fbs);
443 list_add_tail(&fb->filp_head, &arg.fbs);
444
445 schedule_work(&arg.work);
446 flush_work(&arg.work);
447 destroy_work_on_stack(&arg.work);
448 } else
Thierry Redinga4a69da2017-02-28 15:46:40 +0100449 drm_framebuffer_put(fb);
Daniel Vetter7520a272016-08-15 16:07:02 +0200450
451 return 0;
452
453fail_unref:
Thierry Redinga4a69da2017-02-28 15:46:40 +0100454 drm_framebuffer_put(fb);
Daniel Vetter7520a272016-08-15 16:07:02 +0200455 return -ENOENT;
456}
457
Noralf Trønnesd30827c2018-06-18 16:17:30 +0200458int drm_mode_rmfb_ioctl(struct drm_device *dev,
459 void *data, struct drm_file *file_priv)
460{
461 uint32_t *fb_id = data;
462
463 return drm_mode_rmfb(dev, *fb_id, file_priv);
464}
465
Daniel Vetter7520a272016-08-15 16:07:02 +0200466/**
467 * drm_mode_getfb - get FB info
468 * @dev: drm device for the ioctl
469 * @data: data pointer for the ioctl
470 * @file_priv: drm file for the ioctl call
471 *
472 * Lookup the FB given its ID and return info about it.
473 *
474 * Called by the user via ioctl.
475 *
476 * Returns:
477 * Zero on success, negative errno on failure.
478 */
479int drm_mode_getfb(struct drm_device *dev,
480 void *data, struct drm_file *file_priv)
481{
482 struct drm_mode_fb_cmd *r = data;
483 struct drm_framebuffer *fb;
484 int ret;
485
486 if (!drm_core_check_feature(dev, DRIVER_MODESET))
487 return -EINVAL;
488
Keith Packard418da172017-03-14 23:25:07 -0700489 fb = drm_framebuffer_lookup(dev, file_priv, r->fb_id);
Daniel Vetter7520a272016-08-15 16:07:02 +0200490 if (!fb)
491 return -ENOENT;
492
Daniel Stoneb24791f2018-03-20 22:58:39 +0000493 /* Multi-planar framebuffers need getfb2. */
494 if (fb->format->num_planes > 1) {
495 ret = -EINVAL;
496 goto out;
497 }
498
Daniel Stone487da612018-03-23 13:45:51 +0000499 if (!fb->funcs->create_handle) {
500 ret = -ENODEV;
501 goto out;
502 }
503
Daniel Vetter7520a272016-08-15 16:07:02 +0200504 r->height = fb->height;
505 r->width = fb->width;
Ville Syrjäläb00c6002016-12-14 23:31:35 +0200506 r->depth = fb->format->depth;
Ville Syrjälä272725c2016-12-14 23:32:20 +0200507 r->bpp = fb->format->cpp[0] * 8;
Daniel Vetter7520a272016-08-15 16:07:02 +0200508 r->pitch = fb->pitches[0];
Daniel Stone487da612018-03-23 13:45:51 +0000509
510 /* GET_FB() is an unprivileged ioctl so we must not return a
511 * buffer-handle to non-master processes! For
512 * backwards-compatibility reasons, we cannot make GET_FB() privileged,
513 * so just return an invalid handle for non-masters.
514 */
Daniel Vetter0d49f302018-04-20 08:51:59 +0200515 if (!drm_is_current_master(file_priv) && !capable(CAP_SYS_ADMIN)) {
Daniel Stone487da612018-03-23 13:45:51 +0000516 r->handle = 0;
517 ret = 0;
518 goto out;
Daniel Vetter7520a272016-08-15 16:07:02 +0200519 }
520
Daniel Stone487da612018-03-23 13:45:51 +0000521 ret = fb->funcs->create_handle(fb, file_priv, &r->handle);
522
Daniel Stoneb24791f2018-03-20 22:58:39 +0000523out:
Thierry Redinga4a69da2017-02-28 15:46:40 +0100524 drm_framebuffer_put(fb);
Daniel Vetter7520a272016-08-15 16:07:02 +0200525
526 return ret;
527}
528
529/**
530 * drm_mode_dirtyfb_ioctl - flush frontbuffer rendering on an FB
531 * @dev: drm device for the ioctl
532 * @data: data pointer for the ioctl
533 * @file_priv: drm file for the ioctl call
534 *
535 * Lookup the FB and flush out the damaged area supplied by userspace as a clip
536 * rectangle list. Generic userspace which does frontbuffer rendering must call
537 * this ioctl to flush out the changes on manual-update display outputs, e.g.
538 * usb display-link, mipi manual update panels or edp panel self refresh modes.
539 *
540 * Modesetting drivers which always update the frontbuffer do not need to
Daniel Vetterd5745282017-01-25 07:26:45 +0100541 * implement the corresponding &drm_framebuffer_funcs.dirty callback.
Daniel Vetter7520a272016-08-15 16:07:02 +0200542 *
543 * Called by the user via ioctl.
544 *
545 * Returns:
546 * Zero on success, negative errno on failure.
547 */
548int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
549 void *data, struct drm_file *file_priv)
550{
551 struct drm_clip_rect __user *clips_ptr;
552 struct drm_clip_rect *clips = NULL;
553 struct drm_mode_fb_dirty_cmd *r = data;
554 struct drm_framebuffer *fb;
555 unsigned flags;
556 int num_clips;
557 int ret;
558
559 if (!drm_core_check_feature(dev, DRIVER_MODESET))
560 return -EINVAL;
561
Keith Packard418da172017-03-14 23:25:07 -0700562 fb = drm_framebuffer_lookup(dev, file_priv, r->fb_id);
Daniel Vetter7520a272016-08-15 16:07:02 +0200563 if (!fb)
564 return -ENOENT;
565
566 num_clips = r->num_clips;
567 clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr;
568
569 if (!num_clips != !clips_ptr) {
570 ret = -EINVAL;
571 goto out_err1;
572 }
573
574 flags = DRM_MODE_FB_DIRTY_FLAGS & r->flags;
575
576 /* If userspace annotates copy, clips must come in pairs */
577 if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY && (num_clips % 2)) {
578 ret = -EINVAL;
579 goto out_err1;
580 }
581
582 if (num_clips && clips_ptr) {
583 if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
584 ret = -EINVAL;
585 goto out_err1;
586 }
587 clips = kcalloc(num_clips, sizeof(*clips), GFP_KERNEL);
588 if (!clips) {
589 ret = -ENOMEM;
590 goto out_err1;
591 }
592
593 ret = copy_from_user(clips, clips_ptr,
594 num_clips * sizeof(*clips));
595 if (ret) {
596 ret = -EFAULT;
597 goto out_err2;
598 }
599 }
600
601 if (fb->funcs->dirty) {
602 ret = fb->funcs->dirty(fb, file_priv, flags, r->color,
603 clips, num_clips);
604 } else {
605 ret = -ENOSYS;
606 }
607
608out_err2:
609 kfree(clips);
610out_err1:
Thierry Redinga4a69da2017-02-28 15:46:40 +0100611 drm_framebuffer_put(fb);
Daniel Vetter7520a272016-08-15 16:07:02 +0200612
613 return ret;
614}
615
616/**
617 * drm_fb_release - remove and free the FBs on this file
618 * @priv: drm file for the ioctl
619 *
620 * Destroy all the FBs associated with @filp.
621 *
622 * Called by the user via ioctl.
623 *
624 * Returns:
625 * Zero on success, negative errno on failure.
626 */
627void drm_fb_release(struct drm_file *priv)
628{
629 struct drm_framebuffer *fb, *tfb;
630 struct drm_mode_rmfb_work arg;
631
632 INIT_LIST_HEAD(&arg.fbs);
633
634 /*
635 * When the file gets released that means no one else can access the fb
636 * list any more, so no need to grab fpriv->fbs_lock. And we need to
637 * avoid upsetting lockdep since the universal cursor code adds a
638 * framebuffer while holding mutex locks.
639 *
640 * Note that a real deadlock between fpriv->fbs_lock and the modeset
641 * locks is impossible here since no one else but this function can get
642 * at it any more.
643 */
644 list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) {
645 if (drm_framebuffer_read_refcount(fb) > 1) {
646 list_move_tail(&fb->filp_head, &arg.fbs);
647 } else {
648 list_del_init(&fb->filp_head);
649
650 /* This drops the fpriv->fbs reference. */
Thierry Redinga4a69da2017-02-28 15:46:40 +0100651 drm_framebuffer_put(fb);
Daniel Vetter7520a272016-08-15 16:07:02 +0200652 }
653 }
654
655 if (!list_empty(&arg.fbs)) {
656 INIT_WORK_ONSTACK(&arg.work, drm_mode_rmfb_work_fn);
657
658 schedule_work(&arg.work);
659 flush_work(&arg.work);
660 destroy_work_on_stack(&arg.work);
661 }
662}
663
664void drm_framebuffer_free(struct kref *kref)
665{
666 struct drm_framebuffer *fb =
667 container_of(kref, struct drm_framebuffer, base.refcount);
668 struct drm_device *dev = fb->dev;
669
670 /*
671 * The lookup idr holds a weak reference, which has not necessarily been
672 * removed at this point. Check for that.
673 */
674 drm_mode_object_unregister(dev, &fb->base);
675
676 fb->funcs->destroy(fb);
677}
678
679/**
680 * drm_framebuffer_init - initialize a framebuffer
681 * @dev: DRM device
682 * @fb: framebuffer to be initialized
683 * @funcs: ... with these functions
684 *
685 * Allocates an ID for the framebuffer's parent mode object, sets its mode
686 * functions & device file and adds it to the master fd list.
687 *
688 * IMPORTANT:
689 * This functions publishes the fb and makes it available for concurrent access
690 * by other users. Which means by this point the fb _must_ be fully set up -
691 * since all the fb attributes are invariant over its lifetime, no further
692 * locking but only correct reference counting is required.
693 *
694 * Returns:
695 * Zero on success, error code on failure.
696 */
697int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb,
698 const struct drm_framebuffer_funcs *funcs)
699{
700 int ret;
701
Ville Syrjälä570cec32016-11-18 21:52:58 +0200702 if (WARN_ON_ONCE(fb->dev != dev || !fb->format))
Ville Syrjälä95bce762016-11-18 21:52:54 +0200703 return -EINVAL;
704
Daniel Vetter7520a272016-08-15 16:07:02 +0200705 INIT_LIST_HEAD(&fb->filp_head);
Ville Syrjälä95bce762016-11-18 21:52:54 +0200706
Daniel Vetter7520a272016-08-15 16:07:02 +0200707 fb->funcs = funcs;
Maarten Lankhorst8d44e9e2017-12-20 10:35:44 +0100708 strcpy(fb->comm, current->comm);
Daniel Vetter7520a272016-08-15 16:07:02 +0200709
Thierry Reding2135ea72017-02-28 15:46:37 +0100710 ret = __drm_mode_object_add(dev, &fb->base, DRM_MODE_OBJECT_FB,
711 false, drm_framebuffer_free);
Daniel Vetter7520a272016-08-15 16:07:02 +0200712 if (ret)
713 goto out;
714
715 mutex_lock(&dev->mode_config.fb_lock);
716 dev->mode_config.num_fb++;
717 list_add(&fb->head, &dev->mode_config.fb_list);
718 mutex_unlock(&dev->mode_config.fb_lock);
719
720 drm_mode_object_register(dev, &fb->base);
721out:
722 return ret;
723}
724EXPORT_SYMBOL(drm_framebuffer_init);
725
726/**
727 * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference
728 * @dev: drm device
Dave Airliee7e62c72017-11-09 09:35:04 +1000729 * @file_priv: drm file to check for lease against.
Daniel Vetter7520a272016-08-15 16:07:02 +0200730 * @id: id of the fb object
731 *
732 * If successful, this grabs an additional reference to the framebuffer -
733 * callers need to make sure to eventually unreference the returned framebuffer
Thierry Redinga4a69da2017-02-28 15:46:40 +0100734 * again, using drm_framebuffer_put().
Daniel Vetter7520a272016-08-15 16:07:02 +0200735 */
736struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
Keith Packard418da172017-03-14 23:25:07 -0700737 struct drm_file *file_priv,
Daniel Vetter7520a272016-08-15 16:07:02 +0200738 uint32_t id)
739{
740 struct drm_mode_object *obj;
741 struct drm_framebuffer *fb = NULL;
742
Keith Packard418da172017-03-14 23:25:07 -0700743 obj = __drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_FB);
Daniel Vetter7520a272016-08-15 16:07:02 +0200744 if (obj)
745 fb = obj_to_fb(obj);
746 return fb;
747}
748EXPORT_SYMBOL(drm_framebuffer_lookup);
749
750/**
751 * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr
752 * @fb: fb to unregister
753 *
754 * Drivers need to call this when cleaning up driver-private framebuffers, e.g.
755 * those used for fbdev. Note that the caller must hold a reference of it's own,
756 * i.e. the object may not be destroyed through this call (since it'll lead to a
757 * locking inversion).
Rongrong Zou03e93ac2016-10-31 19:59:56 +0800758 *
759 * NOTE: This function is deprecated. For driver-private framebuffers it is not
760 * recommended to embed a framebuffer struct info fbdev struct, instead, a
Thierry Redinga4a69da2017-02-28 15:46:40 +0100761 * framebuffer pointer is preferred and drm_framebuffer_put() should be called
762 * when the framebuffer is to be cleaned up.
Daniel Vetter7520a272016-08-15 16:07:02 +0200763 */
764void drm_framebuffer_unregister_private(struct drm_framebuffer *fb)
765{
766 struct drm_device *dev;
767
768 if (!fb)
769 return;
770
771 dev = fb->dev;
772
773 /* Mark fb as reaped and drop idr ref. */
774 drm_mode_object_unregister(dev, &fb->base);
775}
776EXPORT_SYMBOL(drm_framebuffer_unregister_private);
777
778/**
779 * drm_framebuffer_cleanup - remove a framebuffer object
780 * @fb: framebuffer to remove
781 *
782 * Cleanup framebuffer. This function is intended to be used from the drivers
Daniel Vetterd5745282017-01-25 07:26:45 +0100783 * &drm_framebuffer_funcs.destroy callback. It can also be used to clean up
784 * driver private framebuffers embedded into a larger structure.
Daniel Vetter7520a272016-08-15 16:07:02 +0200785 *
Daniel Vetterd5745282017-01-25 07:26:45 +0100786 * Note that this function does not remove the fb from active usage - if it is
Daniel Vetter7520a272016-08-15 16:07:02 +0200787 * still used anywhere, hilarity can ensue since userspace could call getfb on
788 * the id and get back -EINVAL. Obviously no concern at driver unload time.
789 *
790 * Also, the framebuffer will not be removed from the lookup idr - for
791 * user-created framebuffers this will happen in in the rmfb ioctl. For
792 * driver-private objects (e.g. for fbdev) drivers need to explicitly call
793 * drm_framebuffer_unregister_private.
794 */
795void drm_framebuffer_cleanup(struct drm_framebuffer *fb)
796{
797 struct drm_device *dev = fb->dev;
798
799 mutex_lock(&dev->mode_config.fb_lock);
800 list_del(&fb->head);
801 dev->mode_config.num_fb--;
802 mutex_unlock(&dev->mode_config.fb_lock);
803}
804EXPORT_SYMBOL(drm_framebuffer_cleanup);
805
Daniel Vetter941b8ca2017-04-03 10:33:03 +0200806static int atomic_remove_fb(struct drm_framebuffer *fb)
807{
808 struct drm_modeset_acquire_ctx ctx;
809 struct drm_device *dev = fb->dev;
810 struct drm_atomic_state *state;
811 struct drm_plane *plane;
812 struct drm_connector *conn;
813 struct drm_connector_state *conn_state;
Maarten Lankhorst846c7df2017-11-01 16:04:33 +0100814 int i, ret;
Daniel Vetter941b8ca2017-04-03 10:33:03 +0200815 unsigned plane_mask;
Maarten Lankhorst846c7df2017-11-01 16:04:33 +0100816 bool disable_crtcs = false;
817
818retry_disable:
819 drm_modeset_acquire_init(&ctx, 0);
Daniel Vetter941b8ca2017-04-03 10:33:03 +0200820
821 state = drm_atomic_state_alloc(dev);
Maarten Lankhorst846c7df2017-11-01 16:04:33 +0100822 if (!state) {
823 ret = -ENOMEM;
824 goto out;
825 }
Daniel Vetter941b8ca2017-04-03 10:33:03 +0200826 state->acquire_ctx = &ctx;
827
828retry:
829 plane_mask = 0;
830 ret = drm_modeset_lock_all_ctx(dev, &ctx);
831 if (ret)
832 goto unlock;
833
834 drm_for_each_plane(plane, dev) {
835 struct drm_plane_state *plane_state;
836
837 if (plane->state->fb != fb)
838 continue;
839
840 plane_state = drm_atomic_get_plane_state(state, plane);
841 if (IS_ERR(plane_state)) {
842 ret = PTR_ERR(plane_state);
843 goto unlock;
844 }
845
Maarten Lankhorst846c7df2017-11-01 16:04:33 +0100846 if (disable_crtcs && plane_state->crtc->primary == plane) {
Daniel Vetter941b8ca2017-04-03 10:33:03 +0200847 struct drm_crtc_state *crtc_state;
848
849 crtc_state = drm_atomic_get_existing_crtc_state(state, plane_state->crtc);
850
851 ret = drm_atomic_add_affected_connectors(state, plane_state->crtc);
852 if (ret)
853 goto unlock;
854
855 crtc_state->active = false;
856 ret = drm_atomic_set_mode_for_crtc(crtc_state, NULL);
857 if (ret)
858 goto unlock;
859 }
860
861 drm_atomic_set_fb_for_plane(plane_state, NULL);
862 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
863 if (ret)
864 goto unlock;
865
Ville Syrjälä62f77ad2018-06-26 22:47:07 +0300866 plane_mask |= drm_plane_mask(plane);
Daniel Vetter941b8ca2017-04-03 10:33:03 +0200867 }
868
Maarten Lankhorst846c7df2017-11-01 16:04:33 +0100869 /* This list is only filled when disable_crtcs is set. */
Maarten Lankhorst0c3eb122017-07-12 10:13:30 +0200870 for_each_new_connector_in_state(state, conn, conn_state, i) {
Daniel Vetter941b8ca2017-04-03 10:33:03 +0200871 ret = drm_atomic_set_crtc_for_connector(conn_state, NULL);
872
873 if (ret)
874 goto unlock;
875 }
876
877 if (plane_mask)
878 ret = drm_atomic_commit(state);
879
880unlock:
Daniel Vetter941b8ca2017-04-03 10:33:03 +0200881 if (ret == -EDEADLK) {
Maarten Lankhorst4086d902017-06-29 13:59:54 +0200882 drm_atomic_state_clear(state);
Daniel Vetter941b8ca2017-04-03 10:33:03 +0200883 drm_modeset_backoff(&ctx);
884 goto retry;
885 }
886
887 drm_atomic_state_put(state);
888
Maarten Lankhorst846c7df2017-11-01 16:04:33 +0100889out:
Daniel Vetter941b8ca2017-04-03 10:33:03 +0200890 drm_modeset_drop_locks(&ctx);
891 drm_modeset_acquire_fini(&ctx);
892
Maarten Lankhorst846c7df2017-11-01 16:04:33 +0100893 if (ret == -EINVAL && !disable_crtcs) {
894 disable_crtcs = true;
895 goto retry_disable;
896 }
897
Daniel Vetter941b8ca2017-04-03 10:33:03 +0200898 return ret;
899}
900
901static void legacy_remove_fb(struct drm_framebuffer *fb)
902{
903 struct drm_device *dev = fb->dev;
904 struct drm_crtc *crtc;
905 struct drm_plane *plane;
906
907 drm_modeset_lock_all(dev);
908 /* remove from any CRTC */
909 drm_for_each_crtc(crtc, dev) {
910 if (crtc->primary->fb == fb) {
911 /* should turn off the crtc */
912 if (drm_crtc_force_disable(crtc))
913 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc);
914 }
915 }
916
917 drm_for_each_plane(plane, dev) {
918 if (plane->fb == fb)
919 drm_plane_force_disable(plane);
920 }
921 drm_modeset_unlock_all(dev);
922}
923
Daniel Vetter7520a272016-08-15 16:07:02 +0200924/**
925 * drm_framebuffer_remove - remove and unreference a framebuffer object
926 * @fb: framebuffer to remove
927 *
928 * Scans all the CRTCs and planes in @dev's mode_config. If they're
929 * using @fb, removes it, setting it to NULL. Then drops the reference to the
930 * passed-in framebuffer. Might take the modeset locks.
931 *
932 * Note that this function optimizes the cleanup away if the caller holds the
933 * last reference to the framebuffer. It is also guaranteed to not take the
934 * modeset locks in this case.
935 */
936void drm_framebuffer_remove(struct drm_framebuffer *fb)
937{
938 struct drm_device *dev;
Daniel Vetter7520a272016-08-15 16:07:02 +0200939
940 if (!fb)
941 return;
942
943 dev = fb->dev;
944
945 WARN_ON(!list_empty(&fb->filp_head));
946
947 /*
948 * drm ABI mandates that we remove any deleted framebuffers from active
949 * useage. But since most sane clients only remove framebuffers they no
950 * longer need, try to optimize this away.
951 *
952 * Since we're holding a reference ourselves, observing a refcount of 1
953 * means that we're the last holder and can skip it. Also, the refcount
954 * can never increase from 1 again, so we don't need any barriers or
955 * locks.
956 *
957 * Note that userspace could try to race with use and instate a new
958 * usage _after_ we've cleared all current ones. End result will be an
959 * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot
960 * in this manner.
961 */
962 if (drm_framebuffer_read_refcount(fb) > 1) {
Maarten Lankhorstdb8f6402017-02-21 14:51:41 +0100963 if (drm_drv_uses_atomic_modeset(dev)) {
Daniel Vetter941b8ca2017-04-03 10:33:03 +0200964 int ret = atomic_remove_fb(fb);
Maarten Lankhorstdb8f6402017-02-21 14:51:41 +0100965 WARN(ret, "atomic remove_fb failed with %i\n", ret);
Daniel Vetter941b8ca2017-04-03 10:33:03 +0200966 } else
967 legacy_remove_fb(fb);
Daniel Vetter7520a272016-08-15 16:07:02 +0200968 }
969
Thierry Redinga4a69da2017-02-28 15:46:40 +0100970 drm_framebuffer_put(fb);
Daniel Vetter7520a272016-08-15 16:07:02 +0200971}
972EXPORT_SYMBOL(drm_framebuffer_remove);
Ville Syrjälä8f8f6a62016-11-18 21:53:05 +0200973
974/**
975 * drm_framebuffer_plane_width - width of the plane given the first plane
976 * @width: width of the first plane
977 * @fb: the framebuffer
978 * @plane: plane index
979 *
980 * Returns:
981 * The width of @plane, given that the width of the first plane is @width.
982 */
983int drm_framebuffer_plane_width(int width,
984 const struct drm_framebuffer *fb, int plane)
985{
986 if (plane >= fb->format->num_planes)
987 return 0;
988
Ville Syrjälä568c5e42017-03-21 20:12:14 +0200989 return fb_plane_width(width, fb->format, plane);
Ville Syrjälä8f8f6a62016-11-18 21:53:05 +0200990}
991EXPORT_SYMBOL(drm_framebuffer_plane_width);
992
993/**
994 * drm_framebuffer_plane_height - height of the plane given the first plane
995 * @height: height of the first plane
996 * @fb: the framebuffer
997 * @plane: plane index
998 *
999 * Returns:
1000 * The height of @plane, given that the height of the first plane is @height.
1001 */
1002int drm_framebuffer_plane_height(int height,
1003 const struct drm_framebuffer *fb, int plane)
1004{
1005 if (plane >= fb->format->num_planes)
1006 return 0;
1007
Ville Syrjälä568c5e42017-03-21 20:12:14 +02001008 return fb_plane_height(height, fb->format, plane);
Ville Syrjälä8f8f6a62016-11-18 21:53:05 +02001009}
1010EXPORT_SYMBOL(drm_framebuffer_plane_height);
Noralf Trønnes45d58b42017-11-07 20:13:40 +01001011
1012void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,
1013 const struct drm_framebuffer *fb)
1014{
1015 struct drm_format_name_buf format_name;
1016 unsigned int i;
1017
Maarten Lankhorst8d44e9e2017-12-20 10:35:44 +01001018 drm_printf_indent(p, indent, "allocated by = %s\n", fb->comm);
Noralf Trønnes45d58b42017-11-07 20:13:40 +01001019 drm_printf_indent(p, indent, "refcount=%u\n",
1020 drm_framebuffer_read_refcount(fb));
1021 drm_printf_indent(p, indent, "format=%s\n",
1022 drm_get_format_name(fb->format->format, &format_name));
1023 drm_printf_indent(p, indent, "modifier=0x%llx\n", fb->modifier);
1024 drm_printf_indent(p, indent, "size=%ux%u\n", fb->width, fb->height);
1025 drm_printf_indent(p, indent, "layers:\n");
1026
1027 for (i = 0; i < fb->format->num_planes; i++) {
1028 drm_printf_indent(p, indent + 1, "size[%u]=%dx%d\n", i,
1029 drm_framebuffer_plane_width(fb->width, fb, i),
1030 drm_framebuffer_plane_height(fb->height, fb, i));
1031 drm_printf_indent(p, indent + 1, "pitch[%u]=%u\n", i, fb->pitches[i]);
1032 drm_printf_indent(p, indent + 1, "offset[%u]=%u\n", i, fb->offsets[i]);
1033 drm_printf_indent(p, indent + 1, "obj[%u]:%s\n", i,
1034 fb->obj[i] ? "" : "(null)");
1035 if (fb->obj[i])
1036 drm_gem_print_info(p, indent + 2, fb->obj[i]);
1037 }
1038}
1039
1040#ifdef CONFIG_DEBUG_FS
1041static int drm_framebuffer_info(struct seq_file *m, void *data)
1042{
1043 struct drm_info_node *node = m->private;
1044 struct drm_device *dev = node->minor->dev;
1045 struct drm_printer p = drm_seq_file_printer(m);
1046 struct drm_framebuffer *fb;
1047
1048 mutex_lock(&dev->mode_config.fb_lock);
1049 drm_for_each_fb(fb, dev) {
1050 drm_printf(&p, "framebuffer[%u]:\n", fb->base.id);
1051 drm_framebuffer_print_info(&p, 1, fb);
1052 }
1053 mutex_unlock(&dev->mode_config.fb_lock);
1054
1055 return 0;
1056}
1057
1058static const struct drm_info_list drm_framebuffer_debugfs_list[] = {
1059 { "framebuffer", drm_framebuffer_info, 0 },
1060};
1061
1062int drm_framebuffer_debugfs_init(struct drm_minor *minor)
1063{
1064 return drm_debugfs_create_files(drm_framebuffer_debugfs_list,
1065 ARRAY_SIZE(drm_framebuffer_debugfs_list),
1066 minor->debugfs_root, minor);
1067}
1068#endif