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