2 * Copyright © 2007 David Airlie
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:
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
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.
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>
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>
40 #include <drm/drm_crtc.h>
41 #include <drm/drm_fb_helper.h>
42 #include <drm/drm_fourcc.h>
43 #include <drm/i915_drm.h>
46 #include "intel_drv.h"
47 #include "intel_fbdev.h"
48 #include "intel_frontbuffer.h"
50 static void intel_fbdev_invalidate(struct intel_fbdev *ifbdev)
52 struct drm_i915_gem_object *obj = intel_fb_obj(&ifbdev->fb->base);
54 ifbdev->vma_flags & PLANE_HAS_FENCE ? ORIGIN_GTT : ORIGIN_CPU;
56 intel_fb_obj_invalidate(obj, origin);
59 static int intel_fbdev_set_par(struct fb_info *info)
61 struct drm_fb_helper *fb_helper = info->par;
62 struct intel_fbdev *ifbdev =
63 container_of(fb_helper, struct intel_fbdev, helper);
66 ret = drm_fb_helper_set_par(info);
68 intel_fbdev_invalidate(ifbdev);
73 static int intel_fbdev_blank(int blank, struct fb_info *info)
75 struct drm_fb_helper *fb_helper = info->par;
76 struct intel_fbdev *ifbdev =
77 container_of(fb_helper, struct intel_fbdev, helper);
80 ret = drm_fb_helper_blank(blank, info);
82 intel_fbdev_invalidate(ifbdev);
87 static int intel_fbdev_pan_display(struct fb_var_screeninfo *var,
90 struct drm_fb_helper *fb_helper = info->par;
91 struct intel_fbdev *ifbdev =
92 container_of(fb_helper, struct intel_fbdev, helper);
95 ret = drm_fb_helper_pan_display(var, info);
97 intel_fbdev_invalidate(ifbdev);
102 static struct fb_ops intelfb_ops = {
103 .owner = THIS_MODULE,
104 DRM_FB_HELPER_DEFAULT_OPS,
105 .fb_set_par = intel_fbdev_set_par,
106 .fb_fillrect = drm_fb_helper_cfb_fillrect,
107 .fb_copyarea = drm_fb_helper_cfb_copyarea,
108 .fb_imageblit = drm_fb_helper_cfb_imageblit,
109 .fb_pan_display = intel_fbdev_pan_display,
110 .fb_blank = intel_fbdev_blank,
113 static int intelfb_alloc(struct drm_fb_helper *helper,
114 struct drm_fb_helper_surface_size *sizes)
116 struct intel_fbdev *ifbdev =
117 container_of(helper, struct intel_fbdev, helper);
118 struct drm_framebuffer *fb;
119 struct drm_device *dev = helper->dev;
120 struct drm_i915_private *dev_priv = to_i915(dev);
121 struct drm_mode_fb_cmd2 mode_cmd = {};
122 struct drm_i915_gem_object *obj;
125 /* we don't do packed 24bpp */
126 if (sizes->surface_bpp == 24)
127 sizes->surface_bpp = 32;
129 mode_cmd.width = sizes->surface_width;
130 mode_cmd.height = sizes->surface_height;
132 mode_cmd.pitches[0] = ALIGN(mode_cmd.width *
133 DIV_ROUND_UP(sizes->surface_bpp, 8), 64);
134 mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
135 sizes->surface_depth);
137 size = mode_cmd.pitches[0] * mode_cmd.height;
138 size = PAGE_ALIGN(size);
140 /* If the FB is too big, just don't use it since fbdev is not very
141 * important and we should probably use that space with FBC or other
144 if (size * 2 < dev_priv->stolen_usable_size)
145 obj = i915_gem_object_create_stolen(dev_priv, size);
147 obj = i915_gem_object_create(dev_priv, size);
149 DRM_ERROR("failed to allocate framebuffer\n");
154 fb = intel_framebuffer_create(obj, &mode_cmd);
160 ifbdev->fb = to_intel_framebuffer(fb);
165 i915_gem_object_put(obj);
170 static int intelfb_create(struct drm_fb_helper *helper,
171 struct drm_fb_helper_surface_size *sizes)
173 struct intel_fbdev *ifbdev =
174 container_of(helper, struct intel_fbdev, helper);
175 struct intel_framebuffer *intel_fb = ifbdev->fb;
176 struct drm_device *dev = helper->dev;
177 struct drm_i915_private *dev_priv = to_i915(dev);
178 struct pci_dev *pdev = dev_priv->drm.pdev;
179 struct i915_ggtt *ggtt = &dev_priv->ggtt;
180 const struct i915_ggtt_view view = {
181 .type = I915_GGTT_VIEW_NORMAL,
183 struct drm_framebuffer *fb;
184 intel_wakeref_t wakeref;
185 struct fb_info *info;
186 struct i915_vma *vma;
187 unsigned long flags = 0;
188 bool prealloc = false;
193 (sizes->fb_width > intel_fb->base.width ||
194 sizes->fb_height > intel_fb->base.height)) {
195 DRM_DEBUG_KMS("BIOS fb too small (%dx%d), we require (%dx%d),"
197 intel_fb->base.width, intel_fb->base.height,
198 sizes->fb_width, sizes->fb_height);
199 drm_framebuffer_put(&intel_fb->base);
200 intel_fb = ifbdev->fb = NULL;
202 if (!intel_fb || WARN_ON(!intel_fb_obj(&intel_fb->base))) {
203 DRM_DEBUG_KMS("no BIOS fb, allocating a new one\n");
204 ret = intelfb_alloc(helper, sizes);
207 intel_fb = ifbdev->fb;
209 DRM_DEBUG_KMS("re-using BIOS fb\n");
211 sizes->fb_width = intel_fb->base.width;
212 sizes->fb_height = intel_fb->base.height;
215 mutex_lock(&dev->struct_mutex);
216 wakeref = intel_runtime_pm_get(dev_priv);
218 /* Pin the GGTT vma for our access via info->screen_base.
219 * This also validates that any existing fb inherited from the
220 * BIOS is suitable for own access.
222 vma = intel_pin_and_fence_fb_obj(&ifbdev->fb->base,
223 &view, false, &flags);
229 fb = &ifbdev->fb->base;
230 intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_DIRTYFB);
232 info = drm_fb_helper_alloc_fbi(helper);
234 DRM_ERROR("Failed to allocate fb_info\n");
239 ifbdev->helper.fb = fb;
241 info->fbops = &intelfb_ops;
243 /* setup aperture base/size for vesafb takeover */
244 info->apertures->ranges[0].base = dev->mode_config.fb_base;
245 info->apertures->ranges[0].size = ggtt->mappable_end;
247 info->fix.smem_start = dev->mode_config.fb_base + i915_ggtt_offset(vma);
248 info->fix.smem_len = vma->node.size;
250 vaddr = i915_vma_pin_iomap(vma);
252 DRM_ERROR("Failed to remap framebuffer into virtual memory\n");
253 ret = PTR_ERR(vaddr);
256 info->screen_base = vaddr;
257 info->screen_size = vma->node.size;
259 drm_fb_helper_fill_info(info, &ifbdev->helper, sizes);
261 /* If the object is shmemfs backed, it will have given us zeroed pages.
262 * If the object is stolen however, it will be full of whatever
263 * garbage was left in there.
265 if (intel_fb_obj(fb)->stolen && !prealloc)
266 memset_io(info->screen_base, 0, info->screen_size);
268 /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */
270 DRM_DEBUG_KMS("allocated %dx%d fb: 0x%08x\n",
271 fb->width, fb->height, i915_ggtt_offset(vma));
273 ifbdev->vma_flags = flags;
275 intel_runtime_pm_put(dev_priv, wakeref);
276 mutex_unlock(&dev->struct_mutex);
277 vga_switcheroo_client_fb_set(pdev, info);
281 intel_unpin_fb_vma(vma, flags);
283 intel_runtime_pm_put(dev_priv, wakeref);
284 mutex_unlock(&dev->struct_mutex);
288 static struct drm_fb_helper_crtc *
289 intel_fb_helper_crtc(struct drm_fb_helper *fb_helper, struct drm_crtc *crtc)
293 for (i = 0; i < fb_helper->crtc_count; i++)
294 if (fb_helper->crtc_info[i].mode_set.crtc == crtc)
295 return &fb_helper->crtc_info[i];
301 * Try to read the BIOS display configuration and use it for the initial
304 * The BIOS or boot loader will generally create an initial display
305 * configuration for us that includes some set of active pipes and displays.
306 * This routine tries to figure out which pipes and connectors are active
307 * and stuffs them into the crtcs and modes array given to us by the
308 * drm_fb_helper code.
310 * The overall sequence is:
311 * intel_fbdev_init - from driver load
312 * intel_fbdev_init_bios - initialize the intel_fbdev using BIOS data
313 * drm_fb_helper_init - build fb helper structs
314 * drm_fb_helper_single_add_all_connectors - more fb helper structs
315 * intel_fbdev_initial_config - apply the config
316 * drm_fb_helper_initial_config - call ->probe then register_framebuffer()
317 * drm_setup_crtcs - build crtc config for fbdev
318 * intel_fb_initial_config - find active connectors etc
319 * drm_fb_helper_single_fb_probe - set up fbdev
320 * intelfb_create - re-use or alloc fb, build out fbdev structs
322 * Note that we don't make special consideration whether we could actually
323 * switch to the selected modes without a full modeset. E.g. when the display
324 * is in VGA mode we need to recalculate watermarks and set a new high-res
325 * framebuffer anyway.
327 static bool intel_fb_initial_config(struct drm_fb_helper *fb_helper,
328 struct drm_fb_helper_crtc **crtcs,
329 struct drm_display_mode **modes,
330 struct drm_fb_offset *offsets,
331 bool *enabled, int width, int height)
333 struct drm_i915_private *dev_priv = to_i915(fb_helper->dev);
334 unsigned int count = min(fb_helper->connector_count, BITS_PER_LONG);
335 unsigned long conn_configured, conn_seq;
338 bool fallback = true, ret = true;
339 int num_connectors_enabled = 0;
340 int num_connectors_detected = 0;
341 struct drm_modeset_acquire_ctx ctx;
343 save_enabled = kcalloc(count, sizeof(bool), GFP_KERNEL);
347 drm_modeset_acquire_init(&ctx, 0);
349 while (drm_modeset_lock_all_ctx(fb_helper->dev, &ctx) != 0)
350 drm_modeset_backoff(&ctx);
352 memcpy(save_enabled, enabled, count);
353 conn_seq = GENMASK(count - 1, 0);
356 for (i = 0; i < count; i++) {
357 struct drm_fb_helper_connector *fb_conn;
358 struct drm_connector *connector;
359 struct drm_encoder *encoder;
360 struct drm_fb_helper_crtc *new_crtc;
362 fb_conn = fb_helper->connector_info[i];
363 connector = fb_conn->connector;
365 if (conn_configured & BIT(i))
368 /* First pass, only consider tiled connectors */
369 if (conn_seq == GENMASK(count - 1, 0) && !connector->has_tile)
372 if (connector->status == connector_status_connected)
373 num_connectors_detected++;
376 DRM_DEBUG_KMS("connector %s not enabled, skipping\n",
378 conn_configured |= BIT(i);
382 if (connector->force == DRM_FORCE_OFF) {
383 DRM_DEBUG_KMS("connector %s is disabled by user, skipping\n",
389 encoder = connector->state->best_encoder;
390 if (!encoder || WARN_ON(!connector->state->crtc)) {
391 if (connector->force > DRM_FORCE_OFF)
394 DRM_DEBUG_KMS("connector %s has no encoder or crtc, skipping\n",
397 conn_configured |= BIT(i);
401 num_connectors_enabled++;
403 new_crtc = intel_fb_helper_crtc(fb_helper,
404 connector->state->crtc);
407 * Make sure we're not trying to drive multiple connectors
408 * with a single CRTC, since our cloning support may not
411 for (j = 0; j < count; j++) {
412 if (crtcs[j] == new_crtc) {
413 DRM_DEBUG_KMS("fallback: cloned configuration\n");
418 DRM_DEBUG_KMS("looking for cmdline mode on connector %s\n",
421 /* go for command line mode first */
422 modes[i] = drm_pick_cmdline_mode(fb_conn);
424 /* try for preferred next */
426 DRM_DEBUG_KMS("looking for preferred mode on connector %s %d\n",
427 connector->name, connector->has_tile);
428 modes[i] = drm_has_preferred_mode(fb_conn, width,
432 /* No preferred mode marked by the EDID? Are there any modes? */
433 if (!modes[i] && !list_empty(&connector->modes)) {
434 DRM_DEBUG_KMS("using first mode listed on connector %s\n",
436 modes[i] = list_first_entry(&connector->modes,
437 struct drm_display_mode,
441 /* last resort: use current mode */
444 * IMPORTANT: We want to use the adjusted mode (i.e.
445 * after the panel fitter upscaling) as the initial
446 * config, not the input mode, which is what crtc->mode
447 * usually contains. But since our current
448 * code puts a mode derived from the post-pfit timings
449 * into crtc->mode this works out correctly.
451 * This is crtc->mode and not crtc->state->mode for the
452 * fastboot check to work correctly. crtc_state->mode has
453 * I915_MODE_FLAG_INHERITED, which we clear to force check
456 DRM_DEBUG_KMS("looking for current mode on connector %s\n",
458 modes[i] = &connector->state->crtc->mode;
462 DRM_DEBUG_KMS("connector %s on [CRTC:%d:%s]: %dx%d%s\n",
464 connector->state->crtc->base.id,
465 connector->state->crtc->name,
466 modes[i]->hdisplay, modes[i]->vdisplay,
467 modes[i]->flags & DRM_MODE_FLAG_INTERLACE ? "i" :"");
470 conn_configured |= BIT(i);
473 if (conn_configured != conn_seq) { /* repeat until no more are found */
474 conn_seq = conn_configured;
479 * If the BIOS didn't enable everything it could, fall back to have the
480 * same user experiencing of lighting up as much as possible like the
481 * fbdev helper library.
483 if (num_connectors_enabled != num_connectors_detected &&
484 num_connectors_enabled < INTEL_INFO(dev_priv)->num_pipes) {
485 DRM_DEBUG_KMS("fallback: Not all outputs enabled\n");
486 DRM_DEBUG_KMS("Enabled: %i, detected: %i\n", num_connectors_enabled,
487 num_connectors_detected);
493 DRM_DEBUG_KMS("Not using firmware configuration\n");
494 memcpy(enabled, save_enabled, count);
498 drm_modeset_drop_locks(&ctx);
499 drm_modeset_acquire_fini(&ctx);
505 static const struct drm_fb_helper_funcs intel_fb_helper_funcs = {
506 .initial_config = intel_fb_initial_config,
507 .fb_probe = intelfb_create,
510 static void intel_fbdev_destroy(struct intel_fbdev *ifbdev)
512 /* We rely on the object-free to release the VMA pinning for
513 * the info->screen_base mmaping. Leaking the VMA is simpler than
514 * trying to rectify all the possible error paths leading here.
517 drm_fb_helper_fini(&ifbdev->helper);
520 mutex_lock(&ifbdev->helper.dev->struct_mutex);
521 intel_unpin_fb_vma(ifbdev->vma, ifbdev->vma_flags);
522 mutex_unlock(&ifbdev->helper.dev->struct_mutex);
526 drm_framebuffer_remove(&ifbdev->fb->base);
532 * Build an intel_fbdev struct using a BIOS allocated framebuffer, if possible.
533 * The core display code will have read out the current plane configuration,
534 * so we use that to figure out if there's an object for us to use as the
535 * fb, and if so, we re-use it for the fbdev configuration.
537 * Note we only support a single fb shared across pipes for boot (mostly for
538 * fbcon), so we just find the biggest and use that.
540 static bool intel_fbdev_init_bios(struct drm_device *dev,
541 struct intel_fbdev *ifbdev)
543 struct intel_framebuffer *fb = NULL;
544 struct drm_crtc *crtc;
545 struct intel_crtc *intel_crtc;
546 unsigned int max_size = 0;
548 /* Find the largest fb */
549 for_each_crtc(dev, crtc) {
550 struct drm_i915_gem_object *obj =
551 intel_fb_obj(crtc->primary->state->fb);
552 intel_crtc = to_intel_crtc(crtc);
554 if (!crtc->state->active || !obj) {
555 DRM_DEBUG_KMS("pipe %c not active or no fb, skipping\n",
556 pipe_name(intel_crtc->pipe));
560 if (obj->base.size > max_size) {
561 DRM_DEBUG_KMS("found possible fb from plane %c\n",
562 pipe_name(intel_crtc->pipe));
563 fb = to_intel_framebuffer(crtc->primary->state->fb);
564 max_size = obj->base.size;
569 DRM_DEBUG_KMS("no active fbs found, not using BIOS config\n");
573 /* Now make sure all the pipes will fit into it */
574 for_each_crtc(dev, crtc) {
575 unsigned int cur_size;
577 intel_crtc = to_intel_crtc(crtc);
579 if (!crtc->state->active) {
580 DRM_DEBUG_KMS("pipe %c not active, skipping\n",
581 pipe_name(intel_crtc->pipe));
585 DRM_DEBUG_KMS("checking plane %c for BIOS fb\n",
586 pipe_name(intel_crtc->pipe));
589 * See if the plane fb we found above will fit on this
590 * pipe. Note we need to use the selected fb's pitch and bpp
591 * rather than the current pipe's, since they differ.
593 cur_size = crtc->state->adjusted_mode.crtc_hdisplay;
594 cur_size = cur_size * fb->base.format->cpp[0];
595 if (fb->base.pitches[0] < cur_size) {
596 DRM_DEBUG_KMS("fb not wide enough for plane %c (%d vs %d)\n",
597 pipe_name(intel_crtc->pipe),
598 cur_size, fb->base.pitches[0]);
603 cur_size = crtc->state->adjusted_mode.crtc_vdisplay;
604 cur_size = intel_fb_align_height(&fb->base, 0, cur_size);
605 cur_size *= fb->base.pitches[0];
606 DRM_DEBUG_KMS("pipe %c area: %dx%d, bpp: %d, size: %d\n",
607 pipe_name(intel_crtc->pipe),
608 crtc->state->adjusted_mode.crtc_hdisplay,
609 crtc->state->adjusted_mode.crtc_vdisplay,
610 fb->base.format->cpp[0] * 8,
613 if (cur_size > max_size) {
614 DRM_DEBUG_KMS("fb not big enough for plane %c (%d vs %d)\n",
615 pipe_name(intel_crtc->pipe),
621 DRM_DEBUG_KMS("fb big enough for plane %c (%d >= %d)\n",
622 pipe_name(intel_crtc->pipe),
627 DRM_DEBUG_KMS("BIOS fb not suitable for all pipes, not using\n");
631 ifbdev->preferred_bpp = fb->base.format->cpp[0] * 8;
634 drm_framebuffer_get(&ifbdev->fb->base);
636 /* Final pass to check if any active pipes don't have fbs */
637 for_each_crtc(dev, crtc) {
638 intel_crtc = to_intel_crtc(crtc);
640 if (!crtc->state->active)
643 WARN(!crtc->primary->state->fb,
644 "re-used BIOS config but lost an fb on crtc %d\n",
649 DRM_DEBUG_KMS("using BIOS fb for initial console\n");
657 static void intel_fbdev_suspend_worker(struct work_struct *work)
659 intel_fbdev_set_suspend(&container_of(work,
660 struct drm_i915_private,
661 fbdev_suspend_work)->drm,
662 FBINFO_STATE_RUNNING,
666 int intel_fbdev_init(struct drm_device *dev)
668 struct drm_i915_private *dev_priv = to_i915(dev);
669 struct intel_fbdev *ifbdev;
672 if (WARN_ON(!HAS_DISPLAY(dev_priv)))
675 ifbdev = kzalloc(sizeof(struct intel_fbdev), GFP_KERNEL);
679 mutex_init(&ifbdev->hpd_lock);
680 drm_fb_helper_prepare(dev, &ifbdev->helper, &intel_fb_helper_funcs);
682 if (!intel_fbdev_init_bios(dev, ifbdev))
683 ifbdev->preferred_bpp = 32;
685 ret = drm_fb_helper_init(dev, &ifbdev->helper, 4);
691 dev_priv->fbdev = ifbdev;
692 INIT_WORK(&dev_priv->fbdev_suspend_work, intel_fbdev_suspend_worker);
694 drm_fb_helper_single_add_all_connectors(&ifbdev->helper);
699 static void intel_fbdev_initial_config(void *data, async_cookie_t cookie)
701 struct intel_fbdev *ifbdev = data;
703 /* Due to peculiar init order wrt to hpd handling this is separate. */
704 if (drm_fb_helper_initial_config(&ifbdev->helper,
705 ifbdev->preferred_bpp))
706 intel_fbdev_unregister(to_i915(ifbdev->helper.dev));
709 void intel_fbdev_initial_config_async(struct drm_device *dev)
711 struct intel_fbdev *ifbdev = to_i915(dev)->fbdev;
716 ifbdev->cookie = async_schedule(intel_fbdev_initial_config, ifbdev);
719 static void intel_fbdev_sync(struct intel_fbdev *ifbdev)
724 /* Only serialises with all preceding async calls, hence +1 */
725 async_synchronize_cookie(ifbdev->cookie + 1);
729 void intel_fbdev_unregister(struct drm_i915_private *dev_priv)
731 struct intel_fbdev *ifbdev = dev_priv->fbdev;
736 cancel_work_sync(&dev_priv->fbdev_suspend_work);
737 if (!current_is_async())
738 intel_fbdev_sync(ifbdev);
740 drm_fb_helper_unregister_fbi(&ifbdev->helper);
743 void intel_fbdev_fini(struct drm_i915_private *dev_priv)
745 struct intel_fbdev *ifbdev = fetch_and_zero(&dev_priv->fbdev);
750 intel_fbdev_destroy(ifbdev);
753 /* Suspends/resumes fbdev processing of incoming HPD events. When resuming HPD
754 * processing, fbdev will perform a full connector reprobe if a hotplug event
755 * was received while HPD was suspended.
757 static void intel_fbdev_hpd_set_suspend(struct intel_fbdev *ifbdev, int state)
759 bool send_hpd = false;
761 mutex_lock(&ifbdev->hpd_lock);
762 ifbdev->hpd_suspended = state == FBINFO_STATE_SUSPENDED;
763 send_hpd = !ifbdev->hpd_suspended && ifbdev->hpd_waiting;
764 ifbdev->hpd_waiting = false;
765 mutex_unlock(&ifbdev->hpd_lock);
768 DRM_DEBUG_KMS("Handling delayed fbcon HPD event\n");
769 drm_fb_helper_hotplug_event(&ifbdev->helper);
773 void intel_fbdev_set_suspend(struct drm_device *dev, int state, bool synchronous)
775 struct drm_i915_private *dev_priv = to_i915(dev);
776 struct intel_fbdev *ifbdev = dev_priv->fbdev;
777 struct fb_info *info;
779 if (!ifbdev || !ifbdev->vma)
782 info = ifbdev->helper.fbdev;
785 /* Flush any pending work to turn the console on, and then
786 * wait to turn it off. It must be synchronous as we are
787 * about to suspend or unload the driver.
789 * Note that from within the work-handler, we cannot flush
790 * ourselves, so only flush outstanding work upon suspend!
792 if (state != FBINFO_STATE_RUNNING)
793 flush_work(&dev_priv->fbdev_suspend_work);
798 * The console lock can be pretty contented on resume due
799 * to all the printk activity. Try to keep it out of the hot
800 * path of resume if possible.
802 WARN_ON(state != FBINFO_STATE_RUNNING);
803 if (!console_trylock()) {
804 /* Don't block our own workqueue as this can
805 * be run in parallel with other i915.ko tasks.
807 schedule_work(&dev_priv->fbdev_suspend_work);
812 /* On resume from hibernation: If the object is shmemfs backed, it has
813 * been restored from swap. If the object is stolen however, it will be
814 * full of whatever garbage was left in there.
816 if (state == FBINFO_STATE_RUNNING &&
817 intel_fb_obj(&ifbdev->fb->base)->stolen)
818 memset_io(info->screen_base, 0, info->screen_size);
820 drm_fb_helper_set_suspend(&ifbdev->helper, state);
823 intel_fbdev_hpd_set_suspend(ifbdev, state);
826 void intel_fbdev_output_poll_changed(struct drm_device *dev)
828 struct intel_fbdev *ifbdev = to_i915(dev)->fbdev;
834 intel_fbdev_sync(ifbdev);
836 mutex_lock(&ifbdev->hpd_lock);
837 send_hpd = !ifbdev->hpd_suspended;
838 ifbdev->hpd_waiting = true;
839 mutex_unlock(&ifbdev->hpd_lock);
841 if (send_hpd && (ifbdev->vma || ifbdev->helper.deferred_setup))
842 drm_fb_helper_hotplug_event(&ifbdev->helper);
845 void intel_fbdev_restore_mode(struct drm_device *dev)
847 struct intel_fbdev *ifbdev = to_i915(dev)->fbdev;
852 intel_fbdev_sync(ifbdev);
856 if (drm_fb_helper_restore_fbdev_mode_unlocked(&ifbdev->helper) == 0)
857 intel_fbdev_invalidate(ifbdev);