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.
28 #include <linux/async.h>
29 #include <linux/module.h>
30 #include <linux/kernel.h>
31 #include <linux/errno.h>
32 #include <linux/string.h>
34 #include <linux/delay.h>
38 #include <drm/drm_crtc.h>
39 #include <drm/drm_fb_helper.h>
40 #include "intel_drv.h"
41 #include <drm/i915_drm.h>
44 static int intel_fbdev_set_par(struct fb_info *info)
46 struct drm_fb_helper *fb_helper = info->par;
47 struct intel_fbdev *ifbdev =
48 container_of(fb_helper, struct intel_fbdev, helper);
51 ret = drm_fb_helper_set_par(info);
54 mutex_lock(&fb_helper->dev->struct_mutex);
55 intel_fb_obj_invalidate(ifbdev->fb->obj, ORIGIN_GTT);
56 mutex_unlock(&fb_helper->dev->struct_mutex);
62 static int intel_fbdev_blank(int blank, struct fb_info *info)
64 struct drm_fb_helper *fb_helper = info->par;
65 struct intel_fbdev *ifbdev =
66 container_of(fb_helper, struct intel_fbdev, helper);
69 ret = drm_fb_helper_blank(blank, info);
72 mutex_lock(&fb_helper->dev->struct_mutex);
73 intel_fb_obj_invalidate(ifbdev->fb->obj, ORIGIN_GTT);
74 mutex_unlock(&fb_helper->dev->struct_mutex);
81 static int intel_fbdev_pan_display(struct fb_var_screeninfo *var,
84 struct drm_fb_helper *fb_helper = info->par;
85 struct intel_fbdev *ifbdev =
86 container_of(fb_helper, struct intel_fbdev, helper);
89 ret = drm_fb_helper_pan_display(var, info);
92 mutex_lock(&fb_helper->dev->struct_mutex);
93 intel_fb_obj_invalidate(ifbdev->fb->obj, ORIGIN_GTT);
94 mutex_unlock(&fb_helper->dev->struct_mutex);
101 static struct fb_ops intelfb_ops = {
103 .owner = THIS_MODULE,
104 .fb_check_var = drm_fb_helper_check_var,
106 .fb_set_par = intel_fbdev_set_par,
108 .fb_fillrect = drm_fb_helper_cfb_fillrect,
109 .fb_copyarea = drm_fb_helper_cfb_copyarea,
110 .fb_imageblit = drm_fb_helper_cfb_imageblit,
111 .fb_pan_display = intel_fbdev_pan_display,
113 .fb_blank = intel_fbdev_blank,
115 .fb_setcmap = drm_fb_helper_setcmap,
117 .fb_debug_enter = drm_fb_helper_debug_enter,
119 .fb_debug_leave = drm_fb_helper_debug_leave,
123 static int intelfb_alloc(struct drm_fb_helper *helper,
124 struct drm_fb_helper_surface_size *sizes)
126 struct intel_fbdev *ifbdev =
127 container_of(helper, struct intel_fbdev, helper);
128 struct drm_framebuffer *fb;
129 struct drm_device *dev = helper->dev;
130 struct drm_i915_private *dev_priv = to_i915(dev);
131 struct drm_mode_fb_cmd2 mode_cmd = {};
132 struct drm_i915_gem_object *obj = NULL;
135 /* we don't do packed 24bpp */
136 if (sizes->surface_bpp == 24)
137 sizes->surface_bpp = 32;
139 mode_cmd.width = sizes->surface_width;
140 mode_cmd.height = sizes->surface_height;
142 mode_cmd.pitches[0] = ALIGN(mode_cmd.width *
143 DIV_ROUND_UP(sizes->surface_bpp, 8), 64);
144 mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
145 sizes->surface_depth);
147 mutex_lock(&dev->struct_mutex);
149 size = mode_cmd.pitches[0] * mode_cmd.height;
150 size = PAGE_ALIGN(size);
152 /* If the FB is too big, just don't use it since fbdev is not very
153 * important and we should probably use that space with FBC or other
155 if (size * 2 < dev_priv->gtt.stolen_usable_size)
156 obj = i915_gem_object_create_stolen(dev, size);
158 obj = i915_gem_alloc_object(dev, size);
160 DRM_ERROR("failed to allocate framebuffer\n");
165 fb = __intel_framebuffer_create(dev, &mode_cmd, obj);
167 drm_gem_object_unreference(&obj->base);
172 mutex_unlock(&dev->struct_mutex);
174 ifbdev->fb = to_intel_framebuffer(fb);
179 mutex_unlock(&dev->struct_mutex);
183 static int intelfb_create(struct drm_fb_helper *helper,
184 struct drm_fb_helper_surface_size *sizes)
186 struct intel_fbdev *ifbdev =
187 container_of(helper, struct intel_fbdev, helper);
188 struct intel_framebuffer *intel_fb = ifbdev->fb;
189 struct drm_device *dev = helper->dev;
190 struct drm_i915_private *dev_priv = dev->dev_private;
191 struct fb_info *info;
192 struct drm_framebuffer *fb;
193 struct drm_i915_gem_object *obj;
196 bool prealloc = false;
199 (sizes->fb_width > intel_fb->base.width ||
200 sizes->fb_height > intel_fb->base.height)) {
201 DRM_DEBUG_KMS("BIOS fb too small (%dx%d), we require (%dx%d),"
203 intel_fb->base.width, intel_fb->base.height,
204 sizes->fb_width, sizes->fb_height);
205 drm_framebuffer_unreference(&intel_fb->base);
206 intel_fb = ifbdev->fb = NULL;
208 if (!intel_fb || WARN_ON(!intel_fb->obj)) {
209 DRM_DEBUG_KMS("no BIOS fb, allocating a new one\n");
210 ret = intelfb_alloc(helper, sizes);
213 intel_fb = ifbdev->fb;
215 DRM_DEBUG_KMS("re-using BIOS fb\n");
217 sizes->fb_width = intel_fb->base.width;
218 sizes->fb_height = intel_fb->base.height;
222 size = obj->base.size;
224 mutex_lock(&dev->struct_mutex);
226 /* Pin the GGTT vma for our access via info->screen_base.
227 * This also validates that any existing fb inherited from the
228 * BIOS is suitable for own access.
230 ret = intel_pin_and_fence_fb_obj(NULL, &ifbdev->fb->base, NULL);
234 info = drm_fb_helper_alloc_fbi(helper);
236 DRM_ERROR("Failed to allocate fb_info\n");
243 fb = &ifbdev->fb->base;
245 ifbdev->helper.fb = fb;
248 vga_dev = device_get_parent(dev->dev->bsddev);
249 info->width = sizes->fb_width;
250 info->height = sizes->fb_height;
251 info->stride = fb->pitches[0];
252 info->depth = sizes->surface_bpp;
253 info->paddr = dev_priv->gtt.mappable_base + i915_gem_obj_ggtt_offset(obj);
254 info->is_vga_boot_display = vga_pci_is_boot_display(vga_dev);
255 info->vaddr = (vm_offset_t)pmap_mapdev_attr(info->paddr, size,
256 VM_MEMATTR_WRITE_COMBINING);
257 info->fbops = intelfb_ops;
259 strcpy(info->fix.id, "inteldrmfb");
261 info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT;
262 info->fbops = &intelfb_ops;
264 /* setup aperture base/size for vesafb takeover */
265 info->apertures->ranges[0].base = dev->mode_config.fb_base;
266 info->apertures->ranges[0].size = dev_priv->gtt.mappable_end;
268 info->fix.smem_start = dev->mode_config.fb_base + i915_gem_obj_ggtt_offset(obj);
269 info->fix.smem_len = size;
272 ioremap_wc(dev_priv->gtt.mappable_base + i915_gem_obj_ggtt_offset(obj),
274 if (!info->screen_base) {
275 DRM_ERROR("Failed to remap framebuffer into virtual memory\n");
277 goto out_destroy_fbi;
279 info->screen_size = size;
281 /* This driver doesn't need a VT switch to restore the mode on resume */
282 info->skip_vt_switch = true;
284 drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth);
285 drm_fb_helper_fill_var(info, &ifbdev->helper, sizes->fb_width, sizes->fb_height);
287 /* If the object is shmemfs backed, it will have given us zeroed pages.
288 * If the object is stolen however, it will be full of whatever
289 * garbage was left in there.
291 if (ifbdev->fb->obj->stolen && !prealloc)
292 memset_io(info->screen_base, 0, info->screen_size);
294 /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */
297 DRM_DEBUG_KMS("allocated %dx%d fb: 0x%08lx, bo %p\n",
298 fb->width, fb->height,
299 i915_gem_obj_ggtt_offset(obj), obj);
301 mutex_unlock(&dev->struct_mutex);
303 vga_switcheroo_client_fb_set(dev->pdev, info);
309 drm_fb_helper_release_fbi(helper);
312 i915_gem_object_ggtt_unpin(obj);
314 mutex_unlock(&dev->struct_mutex);
318 /** Sets the color ramps on behalf of RandR */
319 static void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
322 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
324 intel_crtc->lut_r[regno] = red >> 8;
325 intel_crtc->lut_g[regno] = green >> 8;
326 intel_crtc->lut_b[regno] = blue >> 8;
329 static void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
330 u16 *blue, int regno)
332 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
334 *red = intel_crtc->lut_r[regno] << 8;
335 *green = intel_crtc->lut_g[regno] << 8;
336 *blue = intel_crtc->lut_b[regno] << 8;
339 static struct drm_fb_helper_crtc *
340 intel_fb_helper_crtc(struct drm_fb_helper *fb_helper, struct drm_crtc *crtc)
344 for (i = 0; i < fb_helper->crtc_count; i++)
345 if (fb_helper->crtc_info[i].mode_set.crtc == crtc)
346 return &fb_helper->crtc_info[i];
352 * Try to read the BIOS display configuration and use it for the initial
355 * The BIOS or boot loader will generally create an initial display
356 * configuration for us that includes some set of active pipes and displays.
357 * This routine tries to figure out which pipes and connectors are active
358 * and stuffs them into the crtcs and modes array given to us by the
359 * drm_fb_helper code.
361 * The overall sequence is:
362 * intel_fbdev_init - from driver load
363 * intel_fbdev_init_bios - initialize the intel_fbdev using BIOS data
364 * drm_fb_helper_init - build fb helper structs
365 * drm_fb_helper_single_add_all_connectors - more fb helper structs
366 * intel_fbdev_initial_config - apply the config
367 * drm_fb_helper_initial_config - call ->probe then register_framebuffer()
368 * drm_setup_crtcs - build crtc config for fbdev
369 * intel_fb_initial_config - find active connectors etc
370 * drm_fb_helper_single_fb_probe - set up fbdev
371 * intelfb_create - re-use or alloc fb, build out fbdev structs
373 * Note that we don't make special consideration whether we could actually
374 * switch to the selected modes without a full modeset. E.g. when the display
375 * is in VGA mode we need to recalculate watermarks and set a new high-res
376 * framebuffer anyway.
378 static bool intel_fb_initial_config(struct drm_fb_helper *fb_helper,
379 struct drm_fb_helper_crtc **crtcs,
380 struct drm_display_mode **modes,
381 struct drm_fb_offset *offsets,
382 bool *enabled, int width, int height)
384 struct drm_device *dev = fb_helper->dev;
387 bool fallback = true;
388 int num_connectors_enabled = 0;
389 int num_connectors_detected = 0;
390 uint64_t conn_configured = 0, mask;
393 save_enabled = kcalloc(dev->mode_config.num_connector, sizeof(bool),
398 memcpy(save_enabled, enabled, dev->mode_config.num_connector);
399 mask = (1 << fb_helper->connector_count) - 1;
401 for (i = 0; i < fb_helper->connector_count; i++) {
402 struct drm_fb_helper_connector *fb_conn;
403 struct drm_connector *connector;
404 struct drm_encoder *encoder;
405 struct drm_fb_helper_crtc *new_crtc;
407 fb_conn = fb_helper->connector_info[i];
408 connector = fb_conn->connector;
410 if (conn_configured & (1 << i))
413 if (pass == 0 && !connector->has_tile)
416 if (connector->status == connector_status_connected)
417 num_connectors_detected++;
420 DRM_DEBUG_KMS("connector %s not enabled, skipping\n",
422 conn_configured |= (1 << i);
426 if (connector->force == DRM_FORCE_OFF) {
427 DRM_DEBUG_KMS("connector %s is disabled by user, skipping\n",
433 encoder = connector->state->best_encoder;
434 if (!encoder || WARN_ON(!connector->state->crtc)) {
435 if (connector->force > DRM_FORCE_OFF)
438 DRM_DEBUG_KMS("connector %s has no encoder or crtc, skipping\n",
441 conn_configured |= (1 << i);
445 num_connectors_enabled++;
447 new_crtc = intel_fb_helper_crtc(fb_helper, connector->state->crtc);
450 * Make sure we're not trying to drive multiple connectors
451 * with a single CRTC, since our cloning support may not
454 for (j = 0; j < fb_helper->connector_count; j++) {
455 if (crtcs[j] == new_crtc) {
456 DRM_DEBUG_KMS("fallback: cloned configuration\n");
461 DRM_DEBUG_KMS("looking for cmdline mode on connector %s\n",
464 /* go for command line mode first */
465 modes[i] = drm_pick_cmdline_mode(fb_conn, width, height);
467 /* try for preferred next */
469 DRM_DEBUG_KMS("looking for preferred mode on connector %s %d\n",
470 connector->name, connector->has_tile);
471 modes[i] = drm_has_preferred_mode(fb_conn, width,
475 /* No preferred mode marked by the EDID? Are there any modes? */
476 if (!modes[i] && !list_empty(&connector->modes)) {
477 DRM_DEBUG_KMS("using first mode listed on connector %s\n",
479 modes[i] = list_first_entry(&connector->modes,
480 struct drm_display_mode,
484 /* last resort: use current mode */
487 * IMPORTANT: We want to use the adjusted mode (i.e.
488 * after the panel fitter upscaling) as the initial
489 * config, not the input mode, which is what crtc->mode
490 * usually contains. But since our current
491 * code puts a mode derived from the post-pfit timings
492 * into crtc->mode this works out correctly.
494 * This is crtc->mode and not crtc->state->mode for the
495 * fastboot check to work correctly. crtc_state->mode has
496 * I915_MODE_FLAG_INHERITED, which we clear to force check
499 DRM_DEBUG_KMS("looking for current mode on connector %s\n",
501 modes[i] = &connector->state->crtc->mode;
505 DRM_DEBUG_KMS("connector %s on pipe %c [CRTC:%d]: %dx%d%s\n",
507 pipe_name(to_intel_crtc(connector->state->crtc)->pipe),
508 connector->state->crtc->base.id,
509 modes[i]->hdisplay, modes[i]->vdisplay,
510 modes[i]->flags & DRM_MODE_FLAG_INTERLACE ? "i" :"");
513 conn_configured |= (1 << i);
516 if ((conn_configured & mask) != mask) {
522 * If the BIOS didn't enable everything it could, fall back to have the
523 * same user experiencing of lighting up as much as possible like the
524 * fbdev helper library.
526 if (num_connectors_enabled != num_connectors_detected &&
527 num_connectors_enabled < INTEL_INFO(dev)->num_pipes) {
528 DRM_DEBUG_KMS("fallback: Not all outputs enabled\n");
529 DRM_DEBUG_KMS("Enabled: %i, detected: %i\n", num_connectors_enabled,
530 num_connectors_detected);
536 DRM_DEBUG_KMS("Not using firmware configuration\n");
537 memcpy(enabled, save_enabled, dev->mode_config.num_connector);
546 static const struct drm_fb_helper_funcs intel_fb_helper_funcs = {
547 .initial_config = intel_fb_initial_config,
548 .gamma_set = intel_crtc_fb_gamma_set,
549 .gamma_get = intel_crtc_fb_gamma_get,
550 .fb_probe = intelfb_create,
553 static void intel_fbdev_destroy(struct drm_device *dev,
554 struct intel_fbdev *ifbdev)
556 /* We rely on the object-free to release the VMA pinning for
557 * the info->screen_base mmaping. Leaking the VMA is simpler than
558 * trying to rectify all the possible error paths leading here.
561 drm_fb_helper_unregister_fbi(&ifbdev->helper);
562 drm_fb_helper_release_fbi(&ifbdev->helper);
564 drm_fb_helper_fini(&ifbdev->helper);
567 drm_framebuffer_unregister_private(&ifbdev->fb->base);
568 drm_framebuffer_remove(&ifbdev->fb->base);
573 * Build an intel_fbdev struct using a BIOS allocated framebuffer, if possible.
574 * The core display code will have read out the current plane configuration,
575 * so we use that to figure out if there's an object for us to use as the
576 * fb, and if so, we re-use it for the fbdev configuration.
578 * Note we only support a single fb shared across pipes for boot (mostly for
579 * fbcon), so we just find the biggest and use that.
581 static bool intel_fbdev_init_bios(struct drm_device *dev,
582 struct intel_fbdev *ifbdev)
584 struct intel_framebuffer *fb = NULL;
585 struct drm_crtc *crtc;
586 struct intel_crtc *intel_crtc;
587 unsigned int max_size = 0;
589 /* Find the largest fb */
590 for_each_crtc(dev, crtc) {
591 struct drm_i915_gem_object *obj =
592 intel_fb_obj(crtc->primary->state->fb);
593 intel_crtc = to_intel_crtc(crtc);
595 if (!crtc->state->active || !obj) {
596 DRM_DEBUG_KMS("pipe %c not active or no fb, skipping\n",
597 pipe_name(intel_crtc->pipe));
601 if (obj->base.size > max_size) {
602 DRM_DEBUG_KMS("found possible fb from plane %c\n",
603 pipe_name(intel_crtc->pipe));
604 fb = to_intel_framebuffer(crtc->primary->state->fb);
605 max_size = obj->base.size;
610 DRM_DEBUG_KMS("no active fbs found, not using BIOS config\n");
614 /* Now make sure all the pipes will fit into it */
615 for_each_crtc(dev, crtc) {
616 unsigned int cur_size;
618 intel_crtc = to_intel_crtc(crtc);
620 if (!crtc->state->active) {
621 DRM_DEBUG_KMS("pipe %c not active, skipping\n",
622 pipe_name(intel_crtc->pipe));
626 DRM_DEBUG_KMS("checking plane %c for BIOS fb\n",
627 pipe_name(intel_crtc->pipe));
630 * See if the plane fb we found above will fit on this
631 * pipe. Note we need to use the selected fb's pitch and bpp
632 * rather than the current pipe's, since they differ.
634 cur_size = intel_crtc->config->base.adjusted_mode.crtc_hdisplay;
635 cur_size = cur_size * fb->base.bits_per_pixel / 8;
636 if (fb->base.pitches[0] < cur_size) {
637 DRM_DEBUG_KMS("fb not wide enough for plane %c (%d vs %d)\n",
638 pipe_name(intel_crtc->pipe),
639 cur_size, fb->base.pitches[0]);
644 cur_size = intel_crtc->config->base.adjusted_mode.crtc_vdisplay;
645 cur_size = intel_fb_align_height(dev, cur_size,
646 fb->base.pixel_format,
647 fb->base.modifier[0]);
648 cur_size *= fb->base.pitches[0];
649 DRM_DEBUG_KMS("pipe %c area: %dx%d, bpp: %d, size: %d\n",
650 pipe_name(intel_crtc->pipe),
651 intel_crtc->config->base.adjusted_mode.crtc_hdisplay,
652 intel_crtc->config->base.adjusted_mode.crtc_vdisplay,
653 fb->base.bits_per_pixel,
656 if (cur_size > max_size) {
657 DRM_DEBUG_KMS("fb not big enough for plane %c (%d vs %d)\n",
658 pipe_name(intel_crtc->pipe),
664 DRM_DEBUG_KMS("fb big enough for plane %c (%d >= %d)\n",
665 pipe_name(intel_crtc->pipe),
670 DRM_DEBUG_KMS("BIOS fb not suitable for all pipes, not using\n");
674 ifbdev->preferred_bpp = fb->base.bits_per_pixel;
677 drm_framebuffer_reference(&ifbdev->fb->base);
679 /* Final pass to check if any active pipes don't have fbs */
680 for_each_crtc(dev, crtc) {
681 intel_crtc = to_intel_crtc(crtc);
683 if (!crtc->state->active)
686 WARN(!crtc->primary->fb,
687 "re-used BIOS config but lost an fb on crtc %d\n",
692 DRM_DEBUG_KMS("using BIOS fb for initial console\n");
700 static void intel_fbdev_suspend_worker(struct work_struct *work)
702 intel_fbdev_set_suspend(container_of(work,
703 struct drm_i915_private,
704 fbdev_suspend_work)->dev,
705 FBINFO_STATE_RUNNING,
709 int intel_fbdev_init(struct drm_device *dev)
711 struct intel_fbdev *ifbdev;
712 struct drm_i915_private *dev_priv = dev->dev_private;
715 if (WARN_ON(INTEL_INFO(dev)->num_pipes == 0))
718 ifbdev = kzalloc(sizeof(struct intel_fbdev), GFP_KERNEL);
722 drm_fb_helper_prepare(dev, &ifbdev->helper, &intel_fb_helper_funcs);
724 if (!intel_fbdev_init_bios(dev, ifbdev))
725 ifbdev->preferred_bpp = 32;
727 ret = drm_fb_helper_init(dev, &ifbdev->helper,
728 INTEL_INFO(dev)->num_pipes, 4);
734 ifbdev->helper.atomic = true;
736 dev_priv->fbdev = ifbdev;
737 INIT_WORK(&dev_priv->fbdev_suspend_work, intel_fbdev_suspend_worker);
739 drm_fb_helper_single_add_all_connectors(&ifbdev->helper);
744 static void intel_fbdev_initial_config(void *data, async_cookie_t cookie)
746 struct drm_i915_private *dev_priv = data;
747 struct intel_fbdev *ifbdev = dev_priv->fbdev;
749 /* Due to peculiar init order wrt to hpd handling this is separate. */
750 if (drm_fb_helper_initial_config(&ifbdev->helper,
751 ifbdev->preferred_bpp))
752 intel_fbdev_fini(dev_priv->dev);
755 void intel_fbdev_initial_config_async(struct drm_device *dev)
757 async_schedule(intel_fbdev_initial_config, to_i915(dev));
760 void intel_fbdev_fini(struct drm_device *dev)
762 struct drm_i915_private *dev_priv = dev->dev_private;
763 if (!dev_priv->fbdev)
767 flush_work(&dev_priv->fbdev_suspend_work);
769 if (!current_is_async())
771 async_synchronize_full();
772 intel_fbdev_destroy(dev, dev_priv->fbdev);
773 kfree(dev_priv->fbdev);
774 dev_priv->fbdev = NULL;
777 void intel_fbdev_set_suspend(struct drm_device *dev, int state, bool synchronous)
780 struct drm_i915_private *dev_priv = dev->dev_private;
781 struct intel_fbdev *ifbdev = dev_priv->fbdev;
782 struct fb_info *info;
787 info = ifbdev->helper.fbdev;
790 /* Flush any pending work to turn the console on, and then
791 * wait to turn it off. It must be synchronous as we are
792 * about to suspend or unload the driver.
794 * Note that from within the work-handler, we cannot flush
795 * ourselves, so only flush outstanding work upon suspend!
797 if (state != FBINFO_STATE_RUNNING)
798 flush_work(&dev_priv->fbdev_suspend_work);
802 * The console lock can be pretty contented on resume due
803 * to all the printk activity. Try to keep it out of the hot
804 * path of resume if possible.
806 WARN_ON(state != FBINFO_STATE_RUNNING);
807 if (!console_trylock()) {
808 /* Don't block our own workqueue as this can
809 * be run in parallel with other i915.ko tasks.
811 schedule_work(&dev_priv->fbdev_suspend_work);
816 /* On resume from hibernation: If the object is shmemfs backed, it has
817 * been restored from swap. If the object is stolen however, it will be
818 * full of whatever garbage was left in there.
820 if (state == FBINFO_STATE_RUNNING && ifbdev->fb->obj->stolen)
821 memset_io(info->screen_base, 0, info->screen_size);
823 drm_fb_helper_set_suspend(&ifbdev->helper, state);
828 void intel_fbdev_output_poll_changed(struct drm_device *dev)
830 struct drm_i915_private *dev_priv = dev->dev_private;
832 drm_fb_helper_hotplug_event(&dev_priv->fbdev->helper);
835 void intel_fbdev_restore_mode(struct drm_device *dev)
838 struct drm_i915_private *dev_priv = dev->dev_private;
839 struct intel_fbdev *ifbdev = dev_priv->fbdev;
840 struct drm_fb_helper *fb_helper;
845 fb_helper = &ifbdev->helper;
847 /* XXX: avoid dead-locking the Xorg on exit */
848 if (mutex_is_locked(&dev->mode_config.mutex)) {
849 DRM_ERROR("fubar while trying to restore kms_console\n");
850 return; /* drm_modeset_unlock_all(dev) ? */
853 ret = drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper);
855 DRM_DEBUG("failed to restore crtc mode\n");
857 mutex_lock(&fb_helper->dev->struct_mutex);
858 intel_fb_obj_invalidate(ifbdev->fb->obj, ORIGIN_GTT);
859 mutex_unlock(&fb_helper->dev->struct_mutex);