]> Git Repo - linux.git/blob - drivers/gpu/drm/i915/display/intel_fbdev.c
drm/i915/display: Implement fb_mmap callback function
[linux.git] / drivers / gpu / drm / i915 / display / intel_fbdev.c
1 /*
2  * Copyright © 2007 David Airlie
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  *
23  * Authors:
24  *     David Airlie
25  */
26
27 #include <linux/async.h>
28 #include <linux/console.h>
29 #include <linux/delay.h>
30 #include <linux/errno.h>
31 #include <linux/init.h>
32 #include <linux/kernel.h>
33 #include <linux/mm.h>
34 #include <linux/module.h>
35 #include <linux/string.h>
36 #include <linux/sysrq.h>
37 #include <linux/tty.h>
38 #include <linux/vga_switcheroo.h>
39
40 #include <drm/drm_crtc.h>
41 #include <drm/drm_fb_helper.h>
42 #include <drm/drm_fourcc.h>
43 #include <drm/drm_gem_framebuffer_helper.h>
44
45 #include "gem/i915_gem_lmem.h"
46 #include "gem/i915_gem_mman.h"
47
48 #include "i915_drv.h"
49 #include "intel_display_types.h"
50 #include "intel_fb.h"
51 #include "intel_fb_pin.h"
52 #include "intel_fbdev.h"
53 #include "intel_frontbuffer.h"
54
55 struct intel_fbdev {
56         struct drm_fb_helper helper;
57         struct intel_framebuffer *fb;
58         struct i915_vma *vma;
59         unsigned long vma_flags;
60         async_cookie_t cookie;
61         int preferred_bpp;
62
63         /* Whether or not fbdev hpd processing is temporarily suspended */
64         bool hpd_suspended: 1;
65         /* Set when a hotplug was received while HPD processing was suspended */
66         bool hpd_waiting: 1;
67
68         /* Protects hpd_suspended */
69         struct mutex hpd_lock;
70 };
71
72 static struct intel_fbdev *to_intel_fbdev(struct drm_fb_helper *fb_helper)
73 {
74         return container_of(fb_helper, struct intel_fbdev, helper);
75 }
76
77 static struct intel_frontbuffer *to_frontbuffer(struct intel_fbdev *ifbdev)
78 {
79         return ifbdev->fb->frontbuffer;
80 }
81
82 static void intel_fbdev_invalidate(struct intel_fbdev *ifbdev)
83 {
84         intel_frontbuffer_invalidate(to_frontbuffer(ifbdev), ORIGIN_CPU);
85 }
86
87 static int intel_fbdev_set_par(struct fb_info *info)
88 {
89         struct intel_fbdev *ifbdev = to_intel_fbdev(info->par);
90         int ret;
91
92         ret = drm_fb_helper_set_par(info);
93         if (ret == 0)
94                 intel_fbdev_invalidate(ifbdev);
95
96         return ret;
97 }
98
99 static int intel_fbdev_blank(int blank, struct fb_info *info)
100 {
101         struct intel_fbdev *ifbdev = to_intel_fbdev(info->par);
102         int ret;
103
104         ret = drm_fb_helper_blank(blank, info);
105         if (ret == 0)
106                 intel_fbdev_invalidate(ifbdev);
107
108         return ret;
109 }
110
111 static int intel_fbdev_pan_display(struct fb_var_screeninfo *var,
112                                    struct fb_info *info)
113 {
114         struct intel_fbdev *ifbdev = to_intel_fbdev(info->par);
115         int ret;
116
117         ret = drm_fb_helper_pan_display(var, info);
118         if (ret == 0)
119                 intel_fbdev_invalidate(ifbdev);
120
121         return ret;
122 }
123
124 static int intel_fbdev_mmap(struct fb_info *info, struct vm_area_struct *vma)
125 {
126         struct intel_fbdev *fbdev = to_intel_fbdev(info->par);
127         struct drm_gem_object *bo = drm_gem_fb_get_obj(&fbdev->fb->base, 0);
128         struct drm_i915_gem_object *obj = to_intel_bo(bo);
129
130         return i915_gem_fb_mmap(obj, vma);
131 }
132
133 static const struct fb_ops intelfb_ops = {
134         .owner = THIS_MODULE,
135         DRM_FB_HELPER_DEFAULT_OPS,
136         .fb_set_par = intel_fbdev_set_par,
137         .fb_read = drm_fb_helper_cfb_read,
138         .fb_write = drm_fb_helper_cfb_write,
139         .fb_fillrect = drm_fb_helper_cfb_fillrect,
140         .fb_copyarea = drm_fb_helper_cfb_copyarea,
141         .fb_imageblit = drm_fb_helper_cfb_imageblit,
142         .fb_pan_display = intel_fbdev_pan_display,
143         .fb_blank = intel_fbdev_blank,
144         .fb_mmap = intel_fbdev_mmap,
145 };
146
147 static int intelfb_alloc(struct drm_fb_helper *helper,
148                          struct drm_fb_helper_surface_size *sizes)
149 {
150         struct intel_fbdev *ifbdev = to_intel_fbdev(helper);
151         struct drm_framebuffer *fb;
152         struct drm_device *dev = helper->dev;
153         struct drm_i915_private *dev_priv = to_i915(dev);
154         struct drm_mode_fb_cmd2 mode_cmd = {};
155         struct drm_i915_gem_object *obj;
156         int size;
157
158         /* we don't do packed 24bpp */
159         if (sizes->surface_bpp == 24)
160                 sizes->surface_bpp = 32;
161
162         mode_cmd.width = sizes->surface_width;
163         mode_cmd.height = sizes->surface_height;
164
165         mode_cmd.pitches[0] = ALIGN(mode_cmd.width *
166                                     DIV_ROUND_UP(sizes->surface_bpp, 8), 64);
167         mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
168                                                           sizes->surface_depth);
169
170         size = mode_cmd.pitches[0] * mode_cmd.height;
171         size = PAGE_ALIGN(size);
172
173         obj = ERR_PTR(-ENODEV);
174         if (HAS_LMEM(dev_priv)) {
175                 obj = i915_gem_object_create_lmem(dev_priv, size,
176                                                   I915_BO_ALLOC_CONTIGUOUS |
177                                                   I915_BO_ALLOC_USER);
178         } else {
179                 /*
180                  * If the FB is too big, just don't use it since fbdev is not very
181                  * important and we should probably use that space with FBC or other
182                  * features.
183                  */
184                 if (size * 2 < dev_priv->stolen_usable_size)
185                         obj = i915_gem_object_create_stolen(dev_priv, size);
186                 if (IS_ERR(obj))
187                         obj = i915_gem_object_create_shmem(dev_priv, size);
188         }
189
190         if (IS_ERR(obj)) {
191                 drm_err(&dev_priv->drm, "failed to allocate framebuffer (%pe)\n", obj);
192                 return PTR_ERR(obj);
193         }
194
195         fb = intel_framebuffer_create(obj, &mode_cmd);
196         i915_gem_object_put(obj);
197         if (IS_ERR(fb))
198                 return PTR_ERR(fb);
199
200         ifbdev->fb = to_intel_framebuffer(fb);
201         return 0;
202 }
203
204 static int intelfb_create(struct drm_fb_helper *helper,
205                           struct drm_fb_helper_surface_size *sizes)
206 {
207         struct intel_fbdev *ifbdev = to_intel_fbdev(helper);
208         struct intel_framebuffer *intel_fb = ifbdev->fb;
209         struct drm_device *dev = helper->dev;
210         struct drm_i915_private *dev_priv = to_i915(dev);
211         struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
212         struct i915_ggtt *ggtt = to_gt(dev_priv)->ggtt;
213         const struct i915_gtt_view view = {
214                 .type = I915_GTT_VIEW_NORMAL,
215         };
216         intel_wakeref_t wakeref;
217         struct fb_info *info;
218         struct i915_vma *vma;
219         unsigned long flags = 0;
220         bool prealloc = false;
221         void __iomem *vaddr;
222         struct drm_i915_gem_object *obj;
223         int ret;
224
225         mutex_lock(&ifbdev->hpd_lock);
226         ret = ifbdev->hpd_suspended ? -EAGAIN : 0;
227         mutex_unlock(&ifbdev->hpd_lock);
228         if (ret)
229                 return ret;
230
231         if (intel_fb &&
232             (sizes->fb_width > intel_fb->base.width ||
233              sizes->fb_height > intel_fb->base.height)) {
234                 drm_dbg_kms(&dev_priv->drm,
235                             "BIOS fb too small (%dx%d), we require (%dx%d),"
236                             " releasing it\n",
237                             intel_fb->base.width, intel_fb->base.height,
238                             sizes->fb_width, sizes->fb_height);
239                 drm_framebuffer_put(&intel_fb->base);
240                 intel_fb = ifbdev->fb = NULL;
241         }
242         if (!intel_fb || drm_WARN_ON(dev, !intel_fb_obj(&intel_fb->base))) {
243                 drm_dbg_kms(&dev_priv->drm,
244                             "no BIOS fb, allocating a new one\n");
245                 ret = intelfb_alloc(helper, sizes);
246                 if (ret)
247                         return ret;
248                 intel_fb = ifbdev->fb;
249         } else {
250                 drm_dbg_kms(&dev_priv->drm, "re-using BIOS fb\n");
251                 prealloc = true;
252                 sizes->fb_width = intel_fb->base.width;
253                 sizes->fb_height = intel_fb->base.height;
254         }
255
256         wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
257
258         /* Pin the GGTT vma for our access via info->screen_base.
259          * This also validates that any existing fb inherited from the
260          * BIOS is suitable for own access.
261          */
262         vma = intel_pin_and_fence_fb_obj(&ifbdev->fb->base, false,
263                                          &view, false, &flags);
264         if (IS_ERR(vma)) {
265                 ret = PTR_ERR(vma);
266                 goto out_unlock;
267         }
268
269         info = drm_fb_helper_alloc_info(helper);
270         if (IS_ERR(info)) {
271                 drm_err(&dev_priv->drm, "Failed to allocate fb_info (%pe)\n", info);
272                 ret = PTR_ERR(info);
273                 goto out_unpin;
274         }
275
276         ifbdev->helper.fb = &ifbdev->fb->base;
277
278         info->fbops = &intelfb_ops;
279
280         /* setup aperture base/size for vesafb takeover */
281         obj = intel_fb_obj(&intel_fb->base);
282         if (i915_gem_object_is_lmem(obj)) {
283                 struct intel_memory_region *mem = obj->mm.region;
284
285                 info->apertures->ranges[0].base = mem->io_start;
286                 info->apertures->ranges[0].size = mem->io_size;
287
288                 /* Use fbdev's framebuffer from lmem for discrete */
289                 info->fix.smem_start =
290                         (unsigned long)(mem->io_start +
291                                         i915_gem_object_get_dma_address(obj, 0));
292                 info->fix.smem_len = obj->base.size;
293         } else {
294                 info->apertures->ranges[0].base = ggtt->gmadr.start;
295                 info->apertures->ranges[0].size = ggtt->mappable_end;
296
297                 /* Our framebuffer is the entirety of fbdev's system memory */
298                 info->fix.smem_start =
299                         (unsigned long)(ggtt->gmadr.start + i915_ggtt_offset(vma));
300                 info->fix.smem_len = vma->size;
301         }
302
303         vaddr = i915_vma_pin_iomap(vma);
304         if (IS_ERR(vaddr)) {
305                 drm_err(&dev_priv->drm,
306                         "Failed to remap framebuffer into virtual memory (%pe)\n", vaddr);
307                 ret = PTR_ERR(vaddr);
308                 goto out_unpin;
309         }
310         info->screen_base = vaddr;
311         info->screen_size = vma->size;
312
313         drm_fb_helper_fill_info(info, &ifbdev->helper, sizes);
314
315         /* If the object is shmemfs backed, it will have given us zeroed pages.
316          * If the object is stolen however, it will be full of whatever
317          * garbage was left in there.
318          */
319         if (!i915_gem_object_is_shmem(vma->obj) && !prealloc)
320                 memset_io(info->screen_base, 0, info->screen_size);
321
322         /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */
323
324         drm_dbg_kms(&dev_priv->drm, "allocated %dx%d fb: 0x%08x\n",
325                     ifbdev->fb->base.width, ifbdev->fb->base.height,
326                     i915_ggtt_offset(vma));
327         ifbdev->vma = vma;
328         ifbdev->vma_flags = flags;
329
330         intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
331         vga_switcheroo_client_fb_set(pdev, info);
332         return 0;
333
334 out_unpin:
335         intel_unpin_fb_vma(vma, flags);
336 out_unlock:
337         intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
338         return ret;
339 }
340
341 static const struct drm_fb_helper_funcs intel_fb_helper_funcs = {
342         .fb_probe = intelfb_create,
343 };
344
345 static void intel_fbdev_destroy(struct intel_fbdev *ifbdev)
346 {
347         /* We rely on the object-free to release the VMA pinning for
348          * the info->screen_base mmaping. Leaking the VMA is simpler than
349          * trying to rectify all the possible error paths leading here.
350          */
351
352         drm_fb_helper_fini(&ifbdev->helper);
353
354         if (ifbdev->vma)
355                 intel_unpin_fb_vma(ifbdev->vma, ifbdev->vma_flags);
356
357         if (ifbdev->fb)
358                 drm_framebuffer_remove(&ifbdev->fb->base);
359
360         kfree(ifbdev);
361 }
362
363 /*
364  * Build an intel_fbdev struct using a BIOS allocated framebuffer, if possible.
365  * The core display code will have read out the current plane configuration,
366  * so we use that to figure out if there's an object for us to use as the
367  * fb, and if so, we re-use it for the fbdev configuration.
368  *
369  * Note we only support a single fb shared across pipes for boot (mostly for
370  * fbcon), so we just find the biggest and use that.
371  */
372 static bool intel_fbdev_init_bios(struct drm_device *dev,
373                                   struct intel_fbdev *ifbdev)
374 {
375         struct drm_i915_private *i915 = to_i915(dev);
376         struct intel_framebuffer *fb = NULL;
377         struct intel_crtc *crtc;
378         unsigned int max_size = 0;
379
380         /* Find the largest fb */
381         for_each_intel_crtc(dev, crtc) {
382                 struct intel_crtc_state *crtc_state =
383                         to_intel_crtc_state(crtc->base.state);
384                 struct intel_plane *plane =
385                         to_intel_plane(crtc->base.primary);
386                 struct intel_plane_state *plane_state =
387                         to_intel_plane_state(plane->base.state);
388                 struct drm_i915_gem_object *obj =
389                         intel_fb_obj(plane_state->uapi.fb);
390
391                 if (!crtc_state->uapi.active) {
392                         drm_dbg_kms(&i915->drm,
393                                     "[CRTC:%d:%s] not active, skipping\n",
394                                     crtc->base.base.id, crtc->base.name);
395                         continue;
396                 }
397
398                 if (!obj) {
399                         drm_dbg_kms(&i915->drm,
400                                     "[PLANE:%d:%s] no fb, skipping\n",
401                                     plane->base.base.id, plane->base.name);
402                         continue;
403                 }
404
405                 if (obj->base.size > max_size) {
406                         drm_dbg_kms(&i915->drm,
407                                     "found possible fb from [PLANE:%d:%s]\n",
408                                     plane->base.base.id, plane->base.name);
409                         fb = to_intel_framebuffer(plane_state->uapi.fb);
410                         max_size = obj->base.size;
411                 }
412         }
413
414         if (!fb) {
415                 drm_dbg_kms(&i915->drm,
416                             "no active fbs found, not using BIOS config\n");
417                 goto out;
418         }
419
420         /* Now make sure all the pipes will fit into it */
421         for_each_intel_crtc(dev, crtc) {
422                 struct intel_crtc_state *crtc_state =
423                         to_intel_crtc_state(crtc->base.state);
424                 struct intel_plane *plane =
425                         to_intel_plane(crtc->base.primary);
426                 unsigned int cur_size;
427
428                 if (!crtc_state->uapi.active) {
429                         drm_dbg_kms(&i915->drm,
430                                     "[CRTC:%d:%s] not active, skipping\n",
431                                     crtc->base.base.id, crtc->base.name);
432                         continue;
433                 }
434
435                 drm_dbg_kms(&i915->drm, "checking [PLANE:%d:%s] for BIOS fb\n",
436                             plane->base.base.id, plane->base.name);
437
438                 /*
439                  * See if the plane fb we found above will fit on this
440                  * pipe.  Note we need to use the selected fb's pitch and bpp
441                  * rather than the current pipe's, since they differ.
442                  */
443                 cur_size = crtc_state->uapi.adjusted_mode.crtc_hdisplay;
444                 cur_size = cur_size * fb->base.format->cpp[0];
445                 if (fb->base.pitches[0] < cur_size) {
446                         drm_dbg_kms(&i915->drm,
447                                     "fb not wide enough for [PLANE:%d:%s] (%d vs %d)\n",
448                                     plane->base.base.id, plane->base.name,
449                                     cur_size, fb->base.pitches[0]);
450                         fb = NULL;
451                         break;
452                 }
453
454                 cur_size = crtc_state->uapi.adjusted_mode.crtc_vdisplay;
455                 cur_size = intel_fb_align_height(&fb->base, 0, cur_size);
456                 cur_size *= fb->base.pitches[0];
457                 drm_dbg_kms(&i915->drm,
458                             "[CRTC:%d:%s] area: %dx%d, bpp: %d, size: %d\n",
459                             crtc->base.base.id, crtc->base.name,
460                             crtc_state->uapi.adjusted_mode.crtc_hdisplay,
461                             crtc_state->uapi.adjusted_mode.crtc_vdisplay,
462                             fb->base.format->cpp[0] * 8,
463                             cur_size);
464
465                 if (cur_size > max_size) {
466                         drm_dbg_kms(&i915->drm,
467                                     "fb not big enough for [PLANE:%d:%s] (%d vs %d)\n",
468                                     plane->base.base.id, plane->base.name,
469                                     cur_size, max_size);
470                         fb = NULL;
471                         break;
472                 }
473
474                 drm_dbg_kms(&i915->drm,
475                             "fb big enough [PLANE:%d:%s] (%d >= %d)\n",
476                             plane->base.base.id, plane->base.name,
477                             max_size, cur_size);
478         }
479
480         if (!fb) {
481                 drm_dbg_kms(&i915->drm,
482                             "BIOS fb not suitable for all pipes, not using\n");
483                 goto out;
484         }
485
486         ifbdev->preferred_bpp = fb->base.format->cpp[0] * 8;
487         ifbdev->fb = fb;
488
489         drm_framebuffer_get(&ifbdev->fb->base);
490
491         /* Final pass to check if any active pipes don't have fbs */
492         for_each_intel_crtc(dev, crtc) {
493                 struct intel_crtc_state *crtc_state =
494                         to_intel_crtc_state(crtc->base.state);
495                 struct intel_plane *plane =
496                         to_intel_plane(crtc->base.primary);
497                 struct intel_plane_state *plane_state =
498                         to_intel_plane_state(plane->base.state);
499
500                 if (!crtc_state->uapi.active)
501                         continue;
502
503                 drm_WARN(dev, !plane_state->uapi.fb,
504                          "re-used BIOS config but lost an fb on [PLANE:%d:%s]\n",
505                          plane->base.base.id, plane->base.name);
506         }
507
508
509         drm_dbg_kms(&i915->drm, "using BIOS fb for initial console\n");
510         return true;
511
512 out:
513
514         return false;
515 }
516
517 static void intel_fbdev_suspend_worker(struct work_struct *work)
518 {
519         intel_fbdev_set_suspend(&container_of(work,
520                                               struct drm_i915_private,
521                                               display.fbdev.suspend_work)->drm,
522                                 FBINFO_STATE_RUNNING,
523                                 true);
524 }
525
526 int intel_fbdev_init(struct drm_device *dev)
527 {
528         struct drm_i915_private *dev_priv = to_i915(dev);
529         struct intel_fbdev *ifbdev;
530         int ret;
531
532         if (drm_WARN_ON(dev, !HAS_DISPLAY(dev_priv)))
533                 return -ENODEV;
534
535         ifbdev = kzalloc(sizeof(struct intel_fbdev), GFP_KERNEL);
536         if (ifbdev == NULL)
537                 return -ENOMEM;
538
539         mutex_init(&ifbdev->hpd_lock);
540         drm_fb_helper_prepare(dev, &ifbdev->helper, &intel_fb_helper_funcs);
541
542         if (!intel_fbdev_init_bios(dev, ifbdev))
543                 ifbdev->preferred_bpp = 32;
544
545         ret = drm_fb_helper_init(dev, &ifbdev->helper);
546         if (ret) {
547                 kfree(ifbdev);
548                 return ret;
549         }
550
551         dev_priv->display.fbdev.fbdev = ifbdev;
552         INIT_WORK(&dev_priv->display.fbdev.suspend_work, intel_fbdev_suspend_worker);
553
554         return 0;
555 }
556
557 static void intel_fbdev_initial_config(void *data, async_cookie_t cookie)
558 {
559         struct intel_fbdev *ifbdev = data;
560
561         /* Due to peculiar init order wrt to hpd handling this is separate. */
562         if (drm_fb_helper_initial_config(&ifbdev->helper,
563                                          ifbdev->preferred_bpp))
564                 intel_fbdev_unregister(to_i915(ifbdev->helper.dev));
565 }
566
567 void intel_fbdev_initial_config_async(struct drm_device *dev)
568 {
569         struct intel_fbdev *ifbdev = to_i915(dev)->display.fbdev.fbdev;
570
571         if (!ifbdev)
572                 return;
573
574         ifbdev->cookie = async_schedule(intel_fbdev_initial_config, ifbdev);
575 }
576
577 static void intel_fbdev_sync(struct intel_fbdev *ifbdev)
578 {
579         if (!ifbdev->cookie)
580                 return;
581
582         /* Only serialises with all preceding async calls, hence +1 */
583         async_synchronize_cookie(ifbdev->cookie + 1);
584         ifbdev->cookie = 0;
585 }
586
587 void intel_fbdev_unregister(struct drm_i915_private *dev_priv)
588 {
589         struct intel_fbdev *ifbdev = dev_priv->display.fbdev.fbdev;
590
591         if (!ifbdev)
592                 return;
593
594         intel_fbdev_set_suspend(&dev_priv->drm, FBINFO_STATE_SUSPENDED, true);
595
596         if (!current_is_async())
597                 intel_fbdev_sync(ifbdev);
598
599         drm_fb_helper_unregister_info(&ifbdev->helper);
600 }
601
602 void intel_fbdev_fini(struct drm_i915_private *dev_priv)
603 {
604         struct intel_fbdev *ifbdev = fetch_and_zero(&dev_priv->display.fbdev.fbdev);
605
606         if (!ifbdev)
607                 return;
608
609         intel_fbdev_destroy(ifbdev);
610 }
611
612 /* Suspends/resumes fbdev processing of incoming HPD events. When resuming HPD
613  * processing, fbdev will perform a full connector reprobe if a hotplug event
614  * was received while HPD was suspended.
615  */
616 static void intel_fbdev_hpd_set_suspend(struct drm_i915_private *i915, int state)
617 {
618         struct intel_fbdev *ifbdev = i915->display.fbdev.fbdev;
619         bool send_hpd = false;
620
621         mutex_lock(&ifbdev->hpd_lock);
622         ifbdev->hpd_suspended = state == FBINFO_STATE_SUSPENDED;
623         send_hpd = !ifbdev->hpd_suspended && ifbdev->hpd_waiting;
624         ifbdev->hpd_waiting = false;
625         mutex_unlock(&ifbdev->hpd_lock);
626
627         if (send_hpd) {
628                 drm_dbg_kms(&i915->drm, "Handling delayed fbcon HPD event\n");
629                 drm_fb_helper_hotplug_event(&ifbdev->helper);
630         }
631 }
632
633 void intel_fbdev_set_suspend(struct drm_device *dev, int state, bool synchronous)
634 {
635         struct drm_i915_private *dev_priv = to_i915(dev);
636         struct intel_fbdev *ifbdev = dev_priv->display.fbdev.fbdev;
637         struct fb_info *info;
638
639         if (!ifbdev || !ifbdev->vma)
640                 goto set_suspend;
641
642         info = ifbdev->helper.info;
643
644         if (synchronous) {
645                 /* Flush any pending work to turn the console on, and then
646                  * wait to turn it off. It must be synchronous as we are
647                  * about to suspend or unload the driver.
648                  *
649                  * Note that from within the work-handler, we cannot flush
650                  * ourselves, so only flush outstanding work upon suspend!
651                  */
652                 if (state != FBINFO_STATE_RUNNING)
653                         flush_work(&dev_priv->display.fbdev.suspend_work);
654
655                 console_lock();
656         } else {
657                 /*
658                  * The console lock can be pretty contented on resume due
659                  * to all the printk activity.  Try to keep it out of the hot
660                  * path of resume if possible.
661                  */
662                 drm_WARN_ON(dev, state != FBINFO_STATE_RUNNING);
663                 if (!console_trylock()) {
664                         /* Don't block our own workqueue as this can
665                          * be run in parallel with other i915.ko tasks.
666                          */
667                         schedule_work(&dev_priv->display.fbdev.suspend_work);
668                         return;
669                 }
670         }
671
672         /* On resume from hibernation: If the object is shmemfs backed, it has
673          * been restored from swap. If the object is stolen however, it will be
674          * full of whatever garbage was left in there.
675          */
676         if (state == FBINFO_STATE_RUNNING &&
677             !i915_gem_object_is_shmem(intel_fb_obj(&ifbdev->fb->base)))
678                 memset_io(info->screen_base, 0, info->screen_size);
679
680         drm_fb_helper_set_suspend(&ifbdev->helper, state);
681         console_unlock();
682
683 set_suspend:
684         intel_fbdev_hpd_set_suspend(dev_priv, state);
685 }
686
687 void intel_fbdev_output_poll_changed(struct drm_device *dev)
688 {
689         struct intel_fbdev *ifbdev = to_i915(dev)->display.fbdev.fbdev;
690         bool send_hpd;
691
692         if (!ifbdev)
693                 return;
694
695         intel_fbdev_sync(ifbdev);
696
697         mutex_lock(&ifbdev->hpd_lock);
698         send_hpd = !ifbdev->hpd_suspended;
699         ifbdev->hpd_waiting = true;
700         mutex_unlock(&ifbdev->hpd_lock);
701
702         if (send_hpd && (ifbdev->vma || ifbdev->helper.deferred_setup))
703                 drm_fb_helper_hotplug_event(&ifbdev->helper);
704 }
705
706 void intel_fbdev_restore_mode(struct drm_device *dev)
707 {
708         struct intel_fbdev *ifbdev = to_i915(dev)->display.fbdev.fbdev;
709
710         if (!ifbdev)
711                 return;
712
713         intel_fbdev_sync(ifbdev);
714         if (!ifbdev->vma)
715                 return;
716
717         if (drm_fb_helper_restore_fbdev_mode_unlocked(&ifbdev->helper) == 0)
718                 intel_fbdev_invalidate(ifbdev);
719 }
720
721 struct intel_framebuffer *intel_fbdev_framebuffer(struct intel_fbdev *fbdev)
722 {
723         if (!fbdev || !fbdev->helper.fb)
724                 return NULL;
725
726         return to_intel_framebuffer(fbdev->helper.fb);
727 }
This page took 0.080218 seconds and 4 git commands to generate.