]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/drm_fb_cma_helper.c
Merge tag 'pci-v4.13-fixes-2' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaa...
[karo-tx-linux.git] / drivers / gpu / drm / drm_fb_cma_helper.c
1 /*
2  * drm kms/fb cma (contiguous memory allocator) helper functions
3  *
4  * Copyright (C) 2012 Analog Device Inc.
5  *   Author: Lars-Peter Clausen <lars@metafoo.de>
6  *
7  * Based on udl_fbdev.c
8  *  Copyright (C) 2012 Red Hat
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  */
19
20 #include <drm/drmP.h>
21 #include <drm/drm_atomic.h>
22 #include <drm/drm_crtc.h>
23 #include <drm/drm_fb_helper.h>
24 #include <drm/drm_crtc_helper.h>
25 #include <drm/drm_gem_cma_helper.h>
26 #include <drm/drm_fb_cma_helper.h>
27 #include <linux/dma-buf.h>
28 #include <linux/dma-mapping.h>
29 #include <linux/module.h>
30 #include <linux/reservation.h>
31
32 #define DEFAULT_FBDEFIO_DELAY_MS 50
33
34 struct drm_fb_cma {
35         struct drm_framebuffer          fb;
36         struct drm_gem_cma_object       *obj[4];
37 };
38
39 struct drm_fbdev_cma {
40         struct drm_fb_helper    fb_helper;
41         struct drm_fb_cma       *fb;
42         const struct drm_framebuffer_funcs *fb_funcs;
43 };
44
45 /**
46  * DOC: framebuffer cma helper functions
47  *
48  * Provides helper functions for creating a cma (contiguous memory allocator)
49  * backed framebuffer.
50  *
51  * drm_fb_cma_create() is used in the &drm_mode_config_funcs.fb_create
52  * callback function to create a cma backed framebuffer.
53  *
54  * An fbdev framebuffer backed by cma is also available by calling
55  * drm_fbdev_cma_init(). drm_fbdev_cma_fini() tears it down.
56  * If the &drm_framebuffer_funcs.dirty callback is set, fb_deferred_io will be
57  * set up automatically. &drm_framebuffer_funcs.dirty is called by
58  * drm_fb_helper_deferred_io() in process context (&struct delayed_work).
59  *
60  * Example fbdev deferred io code::
61  *
62  *     static int driver_fb_dirty(struct drm_framebuffer *fb,
63  *                                struct drm_file *file_priv,
64  *                                unsigned flags, unsigned color,
65  *                                struct drm_clip_rect *clips,
66  *                                unsigned num_clips)
67  *     {
68  *         struct drm_gem_cma_object *cma = drm_fb_cma_get_gem_obj(fb, 0);
69  *         ... push changes ...
70  *         return 0;
71  *     }
72  *
73  *     static struct drm_framebuffer_funcs driver_fb_funcs = {
74  *         .destroy       = drm_fb_cma_destroy,
75  *         .create_handle = drm_fb_cma_create_handle,
76  *         .dirty         = driver_fb_dirty,
77  *     };
78  *
79  * Initialize::
80  *
81  *     fbdev = drm_fbdev_cma_init_with_funcs(dev, 16,
82  *                                           dev->mode_config.num_crtc,
83  *                                           dev->mode_config.num_connector,
84  *                                           &driver_fb_funcs);
85  *
86  */
87
88 static inline struct drm_fbdev_cma *to_fbdev_cma(struct drm_fb_helper *helper)
89 {
90         return container_of(helper, struct drm_fbdev_cma, fb_helper);
91 }
92
93 static inline struct drm_fb_cma *to_fb_cma(struct drm_framebuffer *fb)
94 {
95         return container_of(fb, struct drm_fb_cma, fb);
96 }
97
98 void drm_fb_cma_destroy(struct drm_framebuffer *fb)
99 {
100         struct drm_fb_cma *fb_cma = to_fb_cma(fb);
101         int i;
102
103         for (i = 0; i < 4; i++) {
104                 if (fb_cma->obj[i])
105                         drm_gem_object_put_unlocked(&fb_cma->obj[i]->base);
106         }
107
108         drm_framebuffer_cleanup(fb);
109         kfree(fb_cma);
110 }
111 EXPORT_SYMBOL(drm_fb_cma_destroy);
112
113 int drm_fb_cma_create_handle(struct drm_framebuffer *fb,
114         struct drm_file *file_priv, unsigned int *handle)
115 {
116         struct drm_fb_cma *fb_cma = to_fb_cma(fb);
117
118         return drm_gem_handle_create(file_priv,
119                         &fb_cma->obj[0]->base, handle);
120 }
121 EXPORT_SYMBOL(drm_fb_cma_create_handle);
122
123 static struct drm_framebuffer_funcs drm_fb_cma_funcs = {
124         .destroy        = drm_fb_cma_destroy,
125         .create_handle  = drm_fb_cma_create_handle,
126 };
127
128 static struct drm_fb_cma *drm_fb_cma_alloc(struct drm_device *dev,
129         const struct drm_mode_fb_cmd2 *mode_cmd,
130         struct drm_gem_cma_object **obj,
131         unsigned int num_planes, const struct drm_framebuffer_funcs *funcs)
132 {
133         struct drm_fb_cma *fb_cma;
134         int ret;
135         int i;
136
137         fb_cma = kzalloc(sizeof(*fb_cma), GFP_KERNEL);
138         if (!fb_cma)
139                 return ERR_PTR(-ENOMEM);
140
141         drm_helper_mode_fill_fb_struct(dev, &fb_cma->fb, mode_cmd);
142
143         for (i = 0; i < num_planes; i++)
144                 fb_cma->obj[i] = obj[i];
145
146         ret = drm_framebuffer_init(dev, &fb_cma->fb, funcs);
147         if (ret) {
148                 dev_err(dev->dev, "Failed to initialize framebuffer: %d\n", ret);
149                 kfree(fb_cma);
150                 return ERR_PTR(ret);
151         }
152
153         return fb_cma;
154 }
155
156 /**
157  * drm_fb_cma_create_with_funcs() - helper function for the
158  *                                  &drm_mode_config_funcs.fb_create
159  *                                  callback
160  * @dev: DRM device
161  * @file_priv: drm file for the ioctl call
162  * @mode_cmd: metadata from the userspace fb creation request
163  * @funcs: vtable to be used for the new framebuffer object
164  *
165  * This can be used to set &drm_framebuffer_funcs for drivers that need the
166  * &drm_framebuffer_funcs.dirty callback. Use drm_fb_cma_create() if you don't
167  * need to change &drm_framebuffer_funcs.
168  */
169 struct drm_framebuffer *drm_fb_cma_create_with_funcs(struct drm_device *dev,
170         struct drm_file *file_priv, const struct drm_mode_fb_cmd2 *mode_cmd,
171         const struct drm_framebuffer_funcs *funcs)
172 {
173         const struct drm_format_info *info;
174         struct drm_fb_cma *fb_cma;
175         struct drm_gem_cma_object *objs[4];
176         struct drm_gem_object *obj;
177         int ret;
178         int i;
179
180         info = drm_get_format_info(dev, mode_cmd);
181         if (!info)
182                 return ERR_PTR(-EINVAL);
183
184         for (i = 0; i < info->num_planes; i++) {
185                 unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
186                 unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
187                 unsigned int min_size;
188
189                 obj = drm_gem_object_lookup(file_priv, mode_cmd->handles[i]);
190                 if (!obj) {
191                         dev_err(dev->dev, "Failed to lookup GEM object\n");
192                         ret = -ENOENT;
193                         goto err_gem_object_put;
194                 }
195
196                 min_size = (height - 1) * mode_cmd->pitches[i]
197                          + width * info->cpp[i]
198                          + mode_cmd->offsets[i];
199
200                 if (obj->size < min_size) {
201                         drm_gem_object_put_unlocked(obj);
202                         ret = -EINVAL;
203                         goto err_gem_object_put;
204                 }
205                 objs[i] = to_drm_gem_cma_obj(obj);
206         }
207
208         fb_cma = drm_fb_cma_alloc(dev, mode_cmd, objs, i, funcs);
209         if (IS_ERR(fb_cma)) {
210                 ret = PTR_ERR(fb_cma);
211                 goto err_gem_object_put;
212         }
213
214         return &fb_cma->fb;
215
216 err_gem_object_put:
217         for (i--; i >= 0; i--)
218                 drm_gem_object_put_unlocked(&objs[i]->base);
219         return ERR_PTR(ret);
220 }
221 EXPORT_SYMBOL_GPL(drm_fb_cma_create_with_funcs);
222
223 /**
224  * drm_fb_cma_create() - &drm_mode_config_funcs.fb_create callback function
225  * @dev: DRM device
226  * @file_priv: drm file for the ioctl call
227  * @mode_cmd: metadata from the userspace fb creation request
228  *
229  * If your hardware has special alignment or pitch requirements these should be
230  * checked before calling this function. Use drm_fb_cma_create_with_funcs() if
231  * you need to set &drm_framebuffer_funcs.dirty.
232  */
233 struct drm_framebuffer *drm_fb_cma_create(struct drm_device *dev,
234         struct drm_file *file_priv, const struct drm_mode_fb_cmd2 *mode_cmd)
235 {
236         return drm_fb_cma_create_with_funcs(dev, file_priv, mode_cmd,
237                                             &drm_fb_cma_funcs);
238 }
239 EXPORT_SYMBOL_GPL(drm_fb_cma_create);
240
241 /**
242  * drm_fb_cma_get_gem_obj() - Get CMA GEM object for framebuffer
243  * @fb: The framebuffer
244  * @plane: Which plane
245  *
246  * Return the CMA GEM object for given framebuffer.
247  *
248  * This function will usually be called from the CRTC callback functions.
249  */
250 struct drm_gem_cma_object *drm_fb_cma_get_gem_obj(struct drm_framebuffer *fb,
251                                                   unsigned int plane)
252 {
253         struct drm_fb_cma *fb_cma = to_fb_cma(fb);
254
255         if (plane >= 4)
256                 return NULL;
257
258         return fb_cma->obj[plane];
259 }
260 EXPORT_SYMBOL_GPL(drm_fb_cma_get_gem_obj);
261
262 /**
263  * drm_fb_cma_get_gem_addr() - Get physical address for framebuffer
264  * @fb: The framebuffer
265  * @state: Which state of drm plane
266  * @plane: Which plane
267  * Return the CMA GEM address for given framebuffer.
268  *
269  * This function will usually be called from the PLANE callback functions.
270  */
271 dma_addr_t drm_fb_cma_get_gem_addr(struct drm_framebuffer *fb,
272                                    struct drm_plane_state *state,
273                                    unsigned int plane)
274 {
275         struct drm_fb_cma *fb_cma = to_fb_cma(fb);
276         dma_addr_t paddr;
277
278         if (plane >= 4)
279                 return 0;
280
281         paddr = fb_cma->obj[plane]->paddr + fb->offsets[plane];
282         paddr += fb->format->cpp[plane] * (state->src_x >> 16);
283         paddr += fb->pitches[plane] * (state->src_y >> 16);
284
285         return paddr;
286 }
287 EXPORT_SYMBOL_GPL(drm_fb_cma_get_gem_addr);
288
289 /**
290  * drm_fb_cma_prepare_fb() - Prepare CMA framebuffer
291  * @plane: Which plane
292  * @state: Plane state attach fence to
293  *
294  * This should be set as the &struct drm_plane_helper_funcs.prepare_fb hook.
295  *
296  * This function checks if the plane FB has an dma-buf attached, extracts
297  * the exclusive fence and attaches it to plane state for the atomic helper
298  * to wait on.
299  *
300  * There is no need for cleanup_fb for CMA based framebuffer drivers.
301  */
302 int drm_fb_cma_prepare_fb(struct drm_plane *plane,
303                           struct drm_plane_state *state)
304 {
305         struct dma_buf *dma_buf;
306         struct dma_fence *fence;
307
308         if ((plane->state->fb == state->fb) || !state->fb)
309                 return 0;
310
311         dma_buf = drm_fb_cma_get_gem_obj(state->fb, 0)->base.dma_buf;
312         if (dma_buf) {
313                 fence = reservation_object_get_excl_rcu(dma_buf->resv);
314                 drm_atomic_set_fence_for_plane(state, fence);
315         }
316
317         return 0;
318 }
319 EXPORT_SYMBOL_GPL(drm_fb_cma_prepare_fb);
320
321 #ifdef CONFIG_DEBUG_FS
322 static void drm_fb_cma_describe(struct drm_framebuffer *fb, struct seq_file *m)
323 {
324         struct drm_fb_cma *fb_cma = to_fb_cma(fb);
325         int i;
326
327         seq_printf(m, "fb: %dx%d@%4.4s\n", fb->width, fb->height,
328                         (char *)&fb->format->format);
329
330         for (i = 0; i < fb->format->num_planes; i++) {
331                 seq_printf(m, "   %d: offset=%d pitch=%d, obj: ",
332                                 i, fb->offsets[i], fb->pitches[i]);
333                 drm_gem_cma_describe(fb_cma->obj[i], m);
334         }
335 }
336
337 /**
338  * drm_fb_cma_debugfs_show() - Helper to list CMA framebuffer objects
339  *                             in debugfs.
340  * @m: output file
341  * @arg: private data for the callback
342  */
343 int drm_fb_cma_debugfs_show(struct seq_file *m, void *arg)
344 {
345         struct drm_info_node *node = (struct drm_info_node *) m->private;
346         struct drm_device *dev = node->minor->dev;
347         struct drm_framebuffer *fb;
348
349         mutex_lock(&dev->mode_config.fb_lock);
350         drm_for_each_fb(fb, dev)
351                 drm_fb_cma_describe(fb, m);
352         mutex_unlock(&dev->mode_config.fb_lock);
353
354         return 0;
355 }
356 EXPORT_SYMBOL_GPL(drm_fb_cma_debugfs_show);
357 #endif
358
359 static int drm_fb_cma_mmap(struct fb_info *info, struct vm_area_struct *vma)
360 {
361         return dma_mmap_writecombine(info->device, vma, info->screen_base,
362                                      info->fix.smem_start, info->fix.smem_len);
363 }
364
365 static struct fb_ops drm_fbdev_cma_ops = {
366         .owner          = THIS_MODULE,
367         DRM_FB_HELPER_DEFAULT_OPS,
368         .fb_fillrect    = drm_fb_helper_sys_fillrect,
369         .fb_copyarea    = drm_fb_helper_sys_copyarea,
370         .fb_imageblit   = drm_fb_helper_sys_imageblit,
371         .fb_mmap        = drm_fb_cma_mmap,
372 };
373
374 static int drm_fbdev_cma_deferred_io_mmap(struct fb_info *info,
375                                           struct vm_area_struct *vma)
376 {
377         fb_deferred_io_mmap(info, vma);
378         vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
379
380         return 0;
381 }
382
383 static int drm_fbdev_cma_defio_init(struct fb_info *fbi,
384                                     struct drm_gem_cma_object *cma_obj)
385 {
386         struct fb_deferred_io *fbdefio;
387         struct fb_ops *fbops;
388
389         /*
390          * Per device structures are needed because:
391          * fbops: fb_deferred_io_cleanup() clears fbops.fb_mmap
392          * fbdefio: individual delays
393          */
394         fbdefio = kzalloc(sizeof(*fbdefio), GFP_KERNEL);
395         fbops = kzalloc(sizeof(*fbops), GFP_KERNEL);
396         if (!fbdefio || !fbops) {
397                 kfree(fbdefio);
398                 kfree(fbops);
399                 return -ENOMEM;
400         }
401
402         /* can't be offset from vaddr since dirty() uses cma_obj */
403         fbi->screen_buffer = cma_obj->vaddr;
404         /* fb_deferred_io_fault() needs a physical address */
405         fbi->fix.smem_start = page_to_phys(virt_to_page(fbi->screen_buffer));
406
407         *fbops = *fbi->fbops;
408         fbi->fbops = fbops;
409
410         fbdefio->delay = msecs_to_jiffies(DEFAULT_FBDEFIO_DELAY_MS);
411         fbdefio->deferred_io = drm_fb_helper_deferred_io;
412         fbi->fbdefio = fbdefio;
413         fb_deferred_io_init(fbi);
414         fbi->fbops->fb_mmap = drm_fbdev_cma_deferred_io_mmap;
415
416         return 0;
417 }
418
419 static void drm_fbdev_cma_defio_fini(struct fb_info *fbi)
420 {
421         if (!fbi->fbdefio)
422                 return;
423
424         fb_deferred_io_cleanup(fbi);
425         kfree(fbi->fbdefio);
426         kfree(fbi->fbops);
427 }
428
429 static int
430 drm_fbdev_cma_create(struct drm_fb_helper *helper,
431         struct drm_fb_helper_surface_size *sizes)
432 {
433         struct drm_fbdev_cma *fbdev_cma = to_fbdev_cma(helper);
434         struct drm_mode_fb_cmd2 mode_cmd = { 0 };
435         struct drm_device *dev = helper->dev;
436         struct drm_gem_cma_object *obj;
437         struct drm_framebuffer *fb;
438         unsigned int bytes_per_pixel;
439         unsigned long offset;
440         struct fb_info *fbi;
441         size_t size;
442         int ret;
443
444         DRM_DEBUG_KMS("surface width(%d), height(%d) and bpp(%d)\n",
445                         sizes->surface_width, sizes->surface_height,
446                         sizes->surface_bpp);
447
448         bytes_per_pixel = DIV_ROUND_UP(sizes->surface_bpp, 8);
449
450         mode_cmd.width = sizes->surface_width;
451         mode_cmd.height = sizes->surface_height;
452         mode_cmd.pitches[0] = sizes->surface_width * bytes_per_pixel;
453         mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
454                 sizes->surface_depth);
455
456         size = mode_cmd.pitches[0] * mode_cmd.height;
457         obj = drm_gem_cma_create(dev, size);
458         if (IS_ERR(obj))
459                 return -ENOMEM;
460
461         fbi = drm_fb_helper_alloc_fbi(helper);
462         if (IS_ERR(fbi)) {
463                 ret = PTR_ERR(fbi);
464                 goto err_gem_free_object;
465         }
466
467         fbdev_cma->fb = drm_fb_cma_alloc(dev, &mode_cmd, &obj, 1,
468                                          fbdev_cma->fb_funcs);
469         if (IS_ERR(fbdev_cma->fb)) {
470                 dev_err(dev->dev, "Failed to allocate DRM framebuffer.\n");
471                 ret = PTR_ERR(fbdev_cma->fb);
472                 goto err_fb_info_destroy;
473         }
474
475         fb = &fbdev_cma->fb->fb;
476         helper->fb = fb;
477
478         fbi->par = helper;
479         fbi->flags = FBINFO_FLAG_DEFAULT;
480         fbi->fbops = &drm_fbdev_cma_ops;
481
482         drm_fb_helper_fill_fix(fbi, fb->pitches[0], fb->format->depth);
483         drm_fb_helper_fill_var(fbi, helper, sizes->fb_width, sizes->fb_height);
484
485         offset = fbi->var.xoffset * bytes_per_pixel;
486         offset += fbi->var.yoffset * fb->pitches[0];
487
488         dev->mode_config.fb_base = (resource_size_t)obj->paddr;
489         fbi->screen_base = obj->vaddr + offset;
490         fbi->fix.smem_start = (unsigned long)(obj->paddr + offset);
491         fbi->screen_size = size;
492         fbi->fix.smem_len = size;
493
494         if (fbdev_cma->fb_funcs->dirty) {
495                 ret = drm_fbdev_cma_defio_init(fbi, obj);
496                 if (ret)
497                         goto err_cma_destroy;
498         }
499
500         return 0;
501
502 err_cma_destroy:
503         drm_framebuffer_remove(&fbdev_cma->fb->fb);
504 err_fb_info_destroy:
505         drm_fb_helper_fini(helper);
506 err_gem_free_object:
507         drm_gem_object_put_unlocked(&obj->base);
508         return ret;
509 }
510
511 static const struct drm_fb_helper_funcs drm_fb_cma_helper_funcs = {
512         .fb_probe = drm_fbdev_cma_create,
513 };
514
515 /**
516  * drm_fbdev_cma_init_with_funcs() - Allocate and initializes a drm_fbdev_cma struct
517  * @dev: DRM device
518  * @preferred_bpp: Preferred bits per pixel for the device
519  * @max_conn_count: Maximum number of connectors
520  * @funcs: fb helper functions, in particular a custom dirty() callback
521  *
522  * Returns a newly allocated drm_fbdev_cma struct or a ERR_PTR.
523  */
524 struct drm_fbdev_cma *drm_fbdev_cma_init_with_funcs(struct drm_device *dev,
525         unsigned int preferred_bpp, unsigned int max_conn_count,
526         const struct drm_framebuffer_funcs *funcs)
527 {
528         struct drm_fbdev_cma *fbdev_cma;
529         struct drm_fb_helper *helper;
530         int ret;
531
532         fbdev_cma = kzalloc(sizeof(*fbdev_cma), GFP_KERNEL);
533         if (!fbdev_cma) {
534                 dev_err(dev->dev, "Failed to allocate drm fbdev.\n");
535                 return ERR_PTR(-ENOMEM);
536         }
537         fbdev_cma->fb_funcs = funcs;
538
539         helper = &fbdev_cma->fb_helper;
540
541         drm_fb_helper_prepare(dev, helper, &drm_fb_cma_helper_funcs);
542
543         ret = drm_fb_helper_init(dev, helper, max_conn_count);
544         if (ret < 0) {
545                 dev_err(dev->dev, "Failed to initialize drm fb helper.\n");
546                 goto err_free;
547         }
548
549         ret = drm_fb_helper_single_add_all_connectors(helper);
550         if (ret < 0) {
551                 dev_err(dev->dev, "Failed to add connectors.\n");
552                 goto err_drm_fb_helper_fini;
553
554         }
555
556         ret = drm_fb_helper_initial_config(helper, preferred_bpp);
557         if (ret < 0) {
558                 dev_err(dev->dev, "Failed to set initial hw configuration.\n");
559                 goto err_drm_fb_helper_fini;
560         }
561
562         return fbdev_cma;
563
564 err_drm_fb_helper_fini:
565         drm_fb_helper_fini(helper);
566 err_free:
567         kfree(fbdev_cma);
568
569         return ERR_PTR(ret);
570 }
571 EXPORT_SYMBOL_GPL(drm_fbdev_cma_init_with_funcs);
572
573 /**
574  * drm_fbdev_cma_init() - Allocate and initializes a drm_fbdev_cma struct
575  * @dev: DRM device
576  * @preferred_bpp: Preferred bits per pixel for the device
577  * @max_conn_count: Maximum number of connectors
578  *
579  * Returns a newly allocated drm_fbdev_cma struct or a ERR_PTR.
580  */
581 struct drm_fbdev_cma *drm_fbdev_cma_init(struct drm_device *dev,
582         unsigned int preferred_bpp, unsigned int max_conn_count)
583 {
584         return drm_fbdev_cma_init_with_funcs(dev, preferred_bpp,
585                                              max_conn_count,
586                                              &drm_fb_cma_funcs);
587 }
588 EXPORT_SYMBOL_GPL(drm_fbdev_cma_init);
589
590 /**
591  * drm_fbdev_cma_fini() - Free drm_fbdev_cma struct
592  * @fbdev_cma: The drm_fbdev_cma struct
593  */
594 void drm_fbdev_cma_fini(struct drm_fbdev_cma *fbdev_cma)
595 {
596         drm_fb_helper_unregister_fbi(&fbdev_cma->fb_helper);
597         if (fbdev_cma->fb_helper.fbdev)
598                 drm_fbdev_cma_defio_fini(fbdev_cma->fb_helper.fbdev);
599
600         if (fbdev_cma->fb)
601                 drm_framebuffer_remove(&fbdev_cma->fb->fb);
602
603         drm_fb_helper_fini(&fbdev_cma->fb_helper);
604         kfree(fbdev_cma);
605 }
606 EXPORT_SYMBOL_GPL(drm_fbdev_cma_fini);
607
608 /**
609  * drm_fbdev_cma_restore_mode() - Restores initial framebuffer mode
610  * @fbdev_cma: The drm_fbdev_cma struct, may be NULL
611  *
612  * This function is usually called from the &drm_driver.lastclose callback.
613  */
614 void drm_fbdev_cma_restore_mode(struct drm_fbdev_cma *fbdev_cma)
615 {
616         if (fbdev_cma)
617                 drm_fb_helper_restore_fbdev_mode_unlocked(&fbdev_cma->fb_helper);
618 }
619 EXPORT_SYMBOL_GPL(drm_fbdev_cma_restore_mode);
620
621 /**
622  * drm_fbdev_cma_hotplug_event() - Poll for hotpulug events
623  * @fbdev_cma: The drm_fbdev_cma struct, may be NULL
624  *
625  * This function is usually called from the &drm_mode_config.output_poll_changed
626  * callback.
627  */
628 void drm_fbdev_cma_hotplug_event(struct drm_fbdev_cma *fbdev_cma)
629 {
630         if (fbdev_cma)
631                 drm_fb_helper_hotplug_event(&fbdev_cma->fb_helper);
632 }
633 EXPORT_SYMBOL_GPL(drm_fbdev_cma_hotplug_event);
634
635 /**
636  * drm_fbdev_cma_set_suspend - wrapper around drm_fb_helper_set_suspend
637  * @fbdev_cma: The drm_fbdev_cma struct, may be NULL
638  * @state: desired state, zero to resume, non-zero to suspend
639  *
640  * Calls drm_fb_helper_set_suspend, which is a wrapper around
641  * fb_set_suspend implemented by fbdev core.
642  */
643 void drm_fbdev_cma_set_suspend(struct drm_fbdev_cma *fbdev_cma, int state)
644 {
645         if (fbdev_cma)
646                 drm_fb_helper_set_suspend(&fbdev_cma->fb_helper, state);
647 }
648 EXPORT_SYMBOL(drm_fbdev_cma_set_suspend);
649
650 /**
651  * drm_fbdev_cma_set_suspend_unlocked - wrapper around
652  *                                      drm_fb_helper_set_suspend_unlocked
653  * @fbdev_cma: The drm_fbdev_cma struct, may be NULL
654  * @state: desired state, zero to resume, non-zero to suspend
655  *
656  * Calls drm_fb_helper_set_suspend, which is a wrapper around
657  * fb_set_suspend implemented by fbdev core.
658  */
659 void drm_fbdev_cma_set_suspend_unlocked(struct drm_fbdev_cma *fbdev_cma,
660                                         int state)
661 {
662         if (fbdev_cma)
663                 drm_fb_helper_set_suspend_unlocked(&fbdev_cma->fb_helper,
664                                                    state);
665 }
666 EXPORT_SYMBOL(drm_fbdev_cma_set_suspend_unlocked);