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