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/console.h>
32 #include <linux/errno.h>
33 #include <linux/string.h>
35 #include <linux/delay.h>
37 #include <linux/vga_switcheroo.h>
40 #include <drm/drm_crtc.h>
41 #include <drm/drm_fb_helper.h>
42 #include "intel_drv.h"
43 #include <drm/i915_drm.h>
46 static int intel_fbdev_set_par(struct fb_info *info)
48 struct drm_fb_helper *fb_helper = info->par;
49 struct intel_fbdev *ifbdev =
50 container_of(fb_helper, struct intel_fbdev, helper);
53 ret = drm_fb_helper_set_par(info);
56 mutex_lock(&fb_helper->dev->struct_mutex);
57 intel_fb_obj_invalidate(ifbdev->fb->obj, ORIGIN_GTT);
58 mutex_unlock(&fb_helper->dev->struct_mutex);
64 static int intel_fbdev_blank(int blank, struct fb_info *info)
66 struct drm_fb_helper *fb_helper = info->par;
67 struct intel_fbdev *ifbdev =
68 container_of(fb_helper, struct intel_fbdev, helper);
71 ret = drm_fb_helper_blank(blank, info);
74 mutex_lock(&fb_helper->dev->struct_mutex);
75 intel_fb_obj_invalidate(ifbdev->fb->obj, ORIGIN_GTT);
76 mutex_unlock(&fb_helper->dev->struct_mutex);
83 static int intel_fbdev_pan_display(struct fb_var_screeninfo *var,
86 struct drm_fb_helper *fb_helper = info->par;
87 struct intel_fbdev *ifbdev =
88 container_of(fb_helper, struct intel_fbdev, helper);
91 ret = drm_fb_helper_pan_display(var, info);
94 mutex_lock(&fb_helper->dev->struct_mutex);
95 intel_fb_obj_invalidate(ifbdev->fb->obj, ORIGIN_GTT);
96 mutex_unlock(&fb_helper->dev->struct_mutex);
103 static struct fb_ops intelfb_ops = {
105 .owner = THIS_MODULE,
106 .fb_check_var = drm_fb_helper_check_var,
108 .fb_set_par = intel_fbdev_set_par,
110 .fb_fillrect = drm_fb_helper_cfb_fillrect,
111 .fb_copyarea = drm_fb_helper_cfb_copyarea,
112 .fb_imageblit = drm_fb_helper_cfb_imageblit,
113 .fb_pan_display = intel_fbdev_pan_display,
115 .fb_blank = intel_fbdev_blank,
117 .fb_setcmap = drm_fb_helper_setcmap,
119 .fb_debug_enter = drm_fb_helper_debug_enter,
121 .fb_debug_leave = drm_fb_helper_debug_leave,
125 static int intelfb_alloc(struct drm_fb_helper *helper,
126 struct drm_fb_helper_surface_size *sizes)
128 struct intel_fbdev *ifbdev =
129 container_of(helper, struct intel_fbdev, helper);
130 struct drm_framebuffer *fb;
131 struct drm_device *dev = helper->dev;
132 struct drm_i915_private *dev_priv = to_i915(dev);
133 struct i915_ggtt *ggtt = &dev_priv->ggtt;
134 struct drm_mode_fb_cmd2 mode_cmd = {};
135 struct drm_i915_gem_object *obj = NULL;
138 /* we don't do packed 24bpp */
139 if (sizes->surface_bpp == 24)
140 sizes->surface_bpp = 32;
142 mode_cmd.width = sizes->surface_width;
143 mode_cmd.height = sizes->surface_height;
145 mode_cmd.pitches[0] = ALIGN(mode_cmd.width *
146 DIV_ROUND_UP(sizes->surface_bpp, 8), 64);
147 mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
148 sizes->surface_depth);
150 mutex_lock(&dev->struct_mutex);
152 size = mode_cmd.pitches[0] * mode_cmd.height;
153 size = PAGE_ALIGN(size);
155 /* If the FB is too big, just don't use it since fbdev is not very
156 * important and we should probably use that space with FBC or other
158 if (size * 2 < ggtt->stolen_usable_size)
159 obj = i915_gem_object_create_stolen(dev, size);
161 obj = i915_gem_alloc_object(dev, size);
163 DRM_ERROR("failed to allocate framebuffer\n");
168 fb = __intel_framebuffer_create(dev, &mode_cmd, obj);
170 drm_gem_object_unreference(&obj->base);
175 mutex_unlock(&dev->struct_mutex);
177 ifbdev->fb = to_intel_framebuffer(fb);
182 mutex_unlock(&dev->struct_mutex);
186 static int intelfb_create(struct drm_fb_helper *helper,
187 struct drm_fb_helper_surface_size *sizes)
189 struct intel_fbdev *ifbdev =
190 container_of(helper, struct intel_fbdev, helper);
191 struct intel_framebuffer *intel_fb = ifbdev->fb;
192 struct drm_device *dev = helper->dev;
193 struct drm_i915_private *dev_priv = to_i915(dev);
194 struct fb_info *info;
195 struct drm_framebuffer *fb;
196 struct drm_i915_gem_object *obj;
199 bool prealloc = false;
202 (sizes->fb_width > intel_fb->base.width ||
203 sizes->fb_height > intel_fb->base.height)) {
204 DRM_DEBUG_KMS("BIOS fb too small (%dx%d), we require (%dx%d),"
206 intel_fb->base.width, intel_fb->base.height,
207 sizes->fb_width, sizes->fb_height);
208 drm_framebuffer_unreference(&intel_fb->base);
209 intel_fb = ifbdev->fb = NULL;
211 if (!intel_fb || WARN_ON(!intel_fb->obj)) {
212 DRM_DEBUG_KMS("no BIOS fb, allocating a new one\n");
213 ret = intelfb_alloc(helper, sizes);
216 intel_fb = ifbdev->fb;
218 DRM_DEBUG_KMS("re-using BIOS fb\n");
220 sizes->fb_width = intel_fb->base.width;
221 sizes->fb_height = intel_fb->base.height;
225 size = obj->base.size;
227 mutex_lock(&dev->struct_mutex);
229 /* Pin the GGTT vma for our access via info->screen_base.
230 * This also validates that any existing fb inherited from the
231 * BIOS is suitable for own access.
233 ret = intel_pin_and_fence_fb_obj(&ifbdev->fb->base, BIT(DRM_ROTATE_0));
237 info = drm_fb_helper_alloc_fbi(helper);
239 DRM_ERROR("Failed to allocate fb_info\n");
246 fb = &ifbdev->fb->base;
248 ifbdev->helper.fb = fb;
251 vga_dev = device_get_parent(dev->dev->bsddev);
252 info->width = sizes->fb_width;
253 info->height = sizes->fb_height;
254 info->stride = fb->pitches[0];
255 info->depth = sizes->surface_bpp;
256 info->paddr = dev_priv->ggtt.mappable_base + i915_gem_obj_ggtt_offset(obj);
257 info->is_vga_boot_display = vga_pci_is_boot_display(vga_dev);
258 info->vaddr = (vm_offset_t)pmap_mapdev_attr(info->paddr, size,
259 VM_MEMATTR_WRITE_COMBINING);
260 info->fbops = intelfb_ops;
262 strcpy(info->fix.id, "inteldrmfb");
264 info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT;
265 info->fbops = &intelfb_ops;
267 /* setup aperture base/size for vesafb takeover */
268 info->apertures->ranges[0].base = dev->mode_config.fb_base;
269 info->apertures->ranges[0].size = ggtt->mappable_end;
271 info->fix.smem_start = dev->mode_config.fb_base + i915_gem_obj_ggtt_offset(obj);
272 info->fix.smem_len = size;
275 ioremap_wc(ggtt->mappable_base + i915_gem_obj_ggtt_offset(obj),
277 if (!info->screen_base) {
278 DRM_ERROR("Failed to remap framebuffer into virtual memory\n");
280 goto out_destroy_fbi;
282 info->screen_size = size;
284 /* This driver doesn't need a VT switch to restore the mode on resume */
285 info->skip_vt_switch = true;
287 drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth);
288 drm_fb_helper_fill_var(info, &ifbdev->helper, sizes->fb_width, sizes->fb_height);
290 /* If the object is shmemfs backed, it will have given us zeroed pages.
291 * If the object is stolen however, it will be full of whatever
292 * garbage was left in there.
294 if (ifbdev->fb->obj->stolen && !prealloc)
295 memset_io(info->screen_base, 0, info->screen_size);
297 /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */
300 DRM_DEBUG_KMS("allocated %dx%d fb: 0x%08llx, bo %p\n",
301 fb->width, fb->height,
302 i915_gem_obj_ggtt_offset(obj), obj);
304 mutex_unlock(&dev->struct_mutex);
306 vga_switcheroo_client_fb_set(dev->pdev, info);
312 drm_fb_helper_release_fbi(helper);
315 i915_gem_object_ggtt_unpin(obj);
317 mutex_unlock(&dev->struct_mutex);
321 /** Sets the color ramps on behalf of RandR */
322 static void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
325 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
327 intel_crtc->lut_r[regno] = red >> 8;
328 intel_crtc->lut_g[regno] = green >> 8;
329 intel_crtc->lut_b[regno] = blue >> 8;
332 static void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
333 u16 *blue, int regno)
335 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
337 *red = intel_crtc->lut_r[regno] << 8;
338 *green = intel_crtc->lut_g[regno] << 8;
339 *blue = intel_crtc->lut_b[regno] << 8;
342 static struct drm_fb_helper_crtc *
343 intel_fb_helper_crtc(struct drm_fb_helper *fb_helper, struct drm_crtc *crtc)
347 for (i = 0; i < fb_helper->crtc_count; i++)
348 if (fb_helper->crtc_info[i].mode_set.crtc == crtc)
349 return &fb_helper->crtc_info[i];
355 * Try to read the BIOS display configuration and use it for the initial
358 * The BIOS or boot loader will generally create an initial display
359 * configuration for us that includes some set of active pipes and displays.
360 * This routine tries to figure out which pipes and connectors are active
361 * and stuffs them into the crtcs and modes array given to us by the
362 * drm_fb_helper code.
364 * The overall sequence is:
365 * intel_fbdev_init - from driver load
366 * intel_fbdev_init_bios - initialize the intel_fbdev using BIOS data
367 * drm_fb_helper_init - build fb helper structs
368 * drm_fb_helper_single_add_all_connectors - more fb helper structs
369 * intel_fbdev_initial_config - apply the config
370 * drm_fb_helper_initial_config - call ->probe then register_framebuffer()
371 * drm_setup_crtcs - build crtc config for fbdev
372 * intel_fb_initial_config - find active connectors etc
373 * drm_fb_helper_single_fb_probe - set up fbdev
374 * intelfb_create - re-use or alloc fb, build out fbdev structs
376 * Note that we don't make special consideration whether we could actually
377 * switch to the selected modes without a full modeset. E.g. when the display
378 * is in VGA mode we need to recalculate watermarks and set a new high-res
379 * framebuffer anyway.
381 static bool intel_fb_initial_config(struct drm_fb_helper *fb_helper,
382 struct drm_fb_helper_crtc **crtcs,
383 struct drm_display_mode **modes,
384 struct drm_fb_offset *offsets,
385 bool *enabled, int width, int height)
387 struct drm_device *dev = fb_helper->dev;
390 bool fallback = true;
391 int num_connectors_enabled = 0;
392 int num_connectors_detected = 0;
393 uint64_t conn_configured = 0, mask;
396 save_enabled = kcalloc(fb_helper->connector_count, sizeof(bool),
401 memcpy(save_enabled, enabled, fb_helper->connector_count);
402 mask = (1 << fb_helper->connector_count) - 1;
404 for (i = 0; i < fb_helper->connector_count; i++) {
405 struct drm_fb_helper_connector *fb_conn;
406 struct drm_connector *connector;
407 struct drm_encoder *encoder;
408 struct drm_fb_helper_crtc *new_crtc;
409 struct intel_crtc *intel_crtc;
411 fb_conn = fb_helper->connector_info[i];
412 connector = fb_conn->connector;
414 if (conn_configured & (1 << i))
417 if (pass == 0 && !connector->has_tile)
420 if (connector->status == connector_status_connected)
421 num_connectors_detected++;
424 DRM_DEBUG_KMS("connector %s not enabled, skipping\n",
426 conn_configured |= (1 << i);
430 if (connector->force == DRM_FORCE_OFF) {
431 DRM_DEBUG_KMS("connector %s is disabled by user, skipping\n",
437 encoder = connector->state->best_encoder;
438 if (!encoder || WARN_ON(!connector->state->crtc)) {
439 if (connector->force > DRM_FORCE_OFF)
442 DRM_DEBUG_KMS("connector %s has no encoder or crtc, skipping\n",
445 conn_configured |= (1 << i);
449 num_connectors_enabled++;
451 intel_crtc = to_intel_crtc(connector->state->crtc);
452 for (j = 0; j < 256; j++) {
453 intel_crtc->lut_r[j] = j;
454 intel_crtc->lut_g[j] = j;
455 intel_crtc->lut_b[j] = j;
458 new_crtc = intel_fb_helper_crtc(fb_helper, connector->state->crtc);
461 * Make sure we're not trying to drive multiple connectors
462 * with a single CRTC, since our cloning support may not
465 for (j = 0; j < fb_helper->connector_count; j++) {
466 if (crtcs[j] == new_crtc) {
467 DRM_DEBUG_KMS("fallback: cloned configuration\n");
472 DRM_DEBUG_KMS("looking for cmdline mode on connector %s\n",
475 /* go for command line mode first */
476 modes[i] = drm_pick_cmdline_mode(fb_conn, width, height);
478 /* try for preferred next */
480 DRM_DEBUG_KMS("looking for preferred mode on connector %s %d\n",
481 connector->name, connector->has_tile);
482 modes[i] = drm_has_preferred_mode(fb_conn, width,
486 /* No preferred mode marked by the EDID? Are there any modes? */
487 if (!modes[i] && !list_empty(&connector->modes)) {
488 DRM_DEBUG_KMS("using first mode listed on connector %s\n",
490 modes[i] = list_first_entry(&connector->modes,
491 struct drm_display_mode,
495 /* last resort: use current mode */
498 * IMPORTANT: We want to use the adjusted mode (i.e.
499 * after the panel fitter upscaling) as the initial
500 * config, not the input mode, which is what crtc->mode
501 * usually contains. But since our current
502 * code puts a mode derived from the post-pfit timings
503 * into crtc->mode this works out correctly.
505 * This is crtc->mode and not crtc->state->mode for the
506 * fastboot check to work correctly. crtc_state->mode has
507 * I915_MODE_FLAG_INHERITED, which we clear to force check
510 DRM_DEBUG_KMS("looking for current mode on connector %s\n",
512 modes[i] = &connector->state->crtc->mode;
516 DRM_DEBUG_KMS("connector %s on pipe %c [CRTC:%d]: %dx%d%s\n",
518 pipe_name(to_intel_crtc(connector->state->crtc)->pipe),
519 connector->state->crtc->base.id,
520 modes[i]->hdisplay, modes[i]->vdisplay,
521 modes[i]->flags & DRM_MODE_FLAG_INTERLACE ? "i" :"");
524 conn_configured |= (1 << i);
527 if ((conn_configured & mask) != mask) {
533 * If the BIOS didn't enable everything it could, fall back to have the
534 * same user experiencing of lighting up as much as possible like the
535 * fbdev helper library.
537 if (num_connectors_enabled != num_connectors_detected &&
538 num_connectors_enabled < INTEL_INFO(dev)->num_pipes) {
539 DRM_DEBUG_KMS("fallback: Not all outputs enabled\n");
540 DRM_DEBUG_KMS("Enabled: %i, detected: %i\n", num_connectors_enabled,
541 num_connectors_detected);
547 DRM_DEBUG_KMS("Not using firmware configuration\n");
548 memcpy(enabled, save_enabled, fb_helper->connector_count);
557 static const struct drm_fb_helper_funcs intel_fb_helper_funcs = {
558 .initial_config = intel_fb_initial_config,
559 .gamma_set = intel_crtc_fb_gamma_set,
560 .gamma_get = intel_crtc_fb_gamma_get,
561 .fb_probe = intelfb_create,
564 static void intel_fbdev_destroy(struct drm_device *dev,
565 struct intel_fbdev *ifbdev)
567 /* We rely on the object-free to release the VMA pinning for
568 * the info->screen_base mmaping. Leaking the VMA is simpler than
569 * trying to rectify all the possible error paths leading here.
572 drm_fb_helper_unregister_fbi(&ifbdev->helper);
573 drm_fb_helper_release_fbi(&ifbdev->helper);
575 drm_fb_helper_fini(&ifbdev->helper);
578 drm_framebuffer_unregister_private(&ifbdev->fb->base);
579 drm_framebuffer_remove(&ifbdev->fb->base);
584 * Build an intel_fbdev struct using a BIOS allocated framebuffer, if possible.
585 * The core display code will have read out the current plane configuration,
586 * so we use that to figure out if there's an object for us to use as the
587 * fb, and if so, we re-use it for the fbdev configuration.
589 * Note we only support a single fb shared across pipes for boot (mostly for
590 * fbcon), so we just find the biggest and use that.
592 static bool intel_fbdev_init_bios(struct drm_device *dev,
593 struct intel_fbdev *ifbdev)
595 struct intel_framebuffer *fb = NULL;
596 struct drm_crtc *crtc;
597 struct intel_crtc *intel_crtc;
598 unsigned int max_size = 0;
600 /* Find the largest fb */
601 for_each_crtc(dev, crtc) {
602 struct drm_i915_gem_object *obj =
603 intel_fb_obj(crtc->primary->state->fb);
604 intel_crtc = to_intel_crtc(crtc);
606 if (!crtc->state->active || !obj) {
607 DRM_DEBUG_KMS("pipe %c not active or no fb, skipping\n",
608 pipe_name(intel_crtc->pipe));
612 if (obj->base.size > max_size) {
613 DRM_DEBUG_KMS("found possible fb from plane %c\n",
614 pipe_name(intel_crtc->pipe));
615 fb = to_intel_framebuffer(crtc->primary->state->fb);
616 max_size = obj->base.size;
621 DRM_DEBUG_KMS("no active fbs found, not using BIOS config\n");
625 /* Now make sure all the pipes will fit into it */
626 for_each_crtc(dev, crtc) {
627 unsigned int cur_size;
629 intel_crtc = to_intel_crtc(crtc);
631 if (!crtc->state->active) {
632 DRM_DEBUG_KMS("pipe %c not active, skipping\n",
633 pipe_name(intel_crtc->pipe));
637 DRM_DEBUG_KMS("checking plane %c for BIOS fb\n",
638 pipe_name(intel_crtc->pipe));
641 * See if the plane fb we found above will fit on this
642 * pipe. Note we need to use the selected fb's pitch and bpp
643 * rather than the current pipe's, since they differ.
645 cur_size = intel_crtc->config->base.adjusted_mode.crtc_hdisplay;
646 cur_size = cur_size * fb->base.bits_per_pixel / 8;
647 if (fb->base.pitches[0] < cur_size) {
648 DRM_DEBUG_KMS("fb not wide enough for plane %c (%d vs %d)\n",
649 pipe_name(intel_crtc->pipe),
650 cur_size, fb->base.pitches[0]);
655 cur_size = intel_crtc->config->base.adjusted_mode.crtc_vdisplay;
656 cur_size = intel_fb_align_height(dev, cur_size,
657 fb->base.pixel_format,
658 fb->base.modifier[0]);
659 cur_size *= fb->base.pitches[0];
660 DRM_DEBUG_KMS("pipe %c area: %dx%d, bpp: %d, size: %d\n",
661 pipe_name(intel_crtc->pipe),
662 intel_crtc->config->base.adjusted_mode.crtc_hdisplay,
663 intel_crtc->config->base.adjusted_mode.crtc_vdisplay,
664 fb->base.bits_per_pixel,
667 if (cur_size > max_size) {
668 DRM_DEBUG_KMS("fb not big enough for plane %c (%d vs %d)\n",
669 pipe_name(intel_crtc->pipe),
675 DRM_DEBUG_KMS("fb big enough for plane %c (%d >= %d)\n",
676 pipe_name(intel_crtc->pipe),
681 DRM_DEBUG_KMS("BIOS fb not suitable for all pipes, not using\n");
685 ifbdev->preferred_bpp = fb->base.bits_per_pixel;
688 drm_framebuffer_reference(&ifbdev->fb->base);
690 /* Final pass to check if any active pipes don't have fbs */
691 for_each_crtc(dev, crtc) {
692 intel_crtc = to_intel_crtc(crtc);
694 if (!crtc->state->active)
697 WARN(!crtc->primary->fb,
698 "re-used BIOS config but lost an fb on crtc %d\n",
703 DRM_DEBUG_KMS("using BIOS fb for initial console\n");
711 static void intel_fbdev_suspend_worker(struct work_struct *work)
713 intel_fbdev_set_suspend(container_of(work,
714 struct drm_i915_private,
715 fbdev_suspend_work)->dev,
716 FBINFO_STATE_RUNNING,
720 int intel_fbdev_init(struct drm_device *dev)
722 struct intel_fbdev *ifbdev;
723 struct drm_i915_private *dev_priv = dev->dev_private;
726 if (WARN_ON(INTEL_INFO(dev)->num_pipes == 0))
729 ifbdev = kzalloc(sizeof(struct intel_fbdev), GFP_KERNEL);
733 drm_fb_helper_prepare(dev, &ifbdev->helper, &intel_fb_helper_funcs);
735 if (!intel_fbdev_init_bios(dev, ifbdev))
736 ifbdev->preferred_bpp = 32;
738 ret = drm_fb_helper_init(dev, &ifbdev->helper,
739 INTEL_INFO(dev)->num_pipes, 4);
745 ifbdev->helper.atomic = true;
747 dev_priv->fbdev = ifbdev;
748 INIT_WORK(&dev_priv->fbdev_suspend_work, intel_fbdev_suspend_worker);
750 drm_fb_helper_single_add_all_connectors(&ifbdev->helper);
755 static void intel_fbdev_initial_config(void *data, async_cookie_t cookie)
757 struct drm_i915_private *dev_priv = data;
758 struct intel_fbdev *ifbdev = dev_priv->fbdev;
760 /* Due to peculiar init order wrt to hpd handling this is separate. */
761 if (drm_fb_helper_initial_config(&ifbdev->helper,
762 ifbdev->preferred_bpp))
763 intel_fbdev_fini(dev_priv->dev);
766 void intel_fbdev_initial_config_async(struct drm_device *dev)
768 async_schedule(intel_fbdev_initial_config, to_i915(dev));
771 void intel_fbdev_fini(struct drm_device *dev)
773 struct drm_i915_private *dev_priv = dev->dev_private;
774 if (!dev_priv->fbdev)
778 flush_work(&dev_priv->fbdev_suspend_work);
780 if (!current_is_async())
782 async_synchronize_full();
783 intel_fbdev_destroy(dev, dev_priv->fbdev);
784 kfree(dev_priv->fbdev);
785 dev_priv->fbdev = NULL;
788 void intel_fbdev_set_suspend(struct drm_device *dev, int state, bool synchronous)
791 struct drm_i915_private *dev_priv = dev->dev_private;
792 struct intel_fbdev *ifbdev = dev_priv->fbdev;
793 struct fb_info *info;
798 info = ifbdev->helper.fbdev;
801 /* Flush any pending work to turn the console on, and then
802 * wait to turn it off. It must be synchronous as we are
803 * about to suspend or unload the driver.
805 * Note that from within the work-handler, we cannot flush
806 * ourselves, so only flush outstanding work upon suspend!
808 if (state != FBINFO_STATE_RUNNING)
809 flush_work(&dev_priv->fbdev_suspend_work);
813 * The console lock can be pretty contented on resume due
814 * to all the printk activity. Try to keep it out of the hot
815 * path of resume if possible.
817 WARN_ON(state != FBINFO_STATE_RUNNING);
818 if (!console_trylock()) {
819 /* Don't block our own workqueue as this can
820 * be run in parallel with other i915.ko tasks.
822 schedule_work(&dev_priv->fbdev_suspend_work);
827 /* On resume from hibernation: If the object is shmemfs backed, it has
828 * been restored from swap. If the object is stolen however, it will be
829 * full of whatever garbage was left in there.
831 if (state == FBINFO_STATE_RUNNING && ifbdev->fb->obj->stolen)
832 memset_io(info->screen_base, 0, info->screen_size);
834 drm_fb_helper_set_suspend(&ifbdev->helper, state);
839 void intel_fbdev_output_poll_changed(struct drm_device *dev)
841 struct drm_i915_private *dev_priv = dev->dev_private;
843 drm_fb_helper_hotplug_event(&dev_priv->fbdev->helper);
846 void intel_fbdev_restore_mode(struct drm_device *dev)
849 struct drm_i915_private *dev_priv = dev->dev_private;
850 struct intel_fbdev *ifbdev = dev_priv->fbdev;
851 struct drm_fb_helper *fb_helper;
856 fb_helper = &ifbdev->helper;
858 /* XXX: avoid dead-locking the Xorg on exit */
859 if (mutex_is_locked(&dev->mode_config.mutex)) {
860 DRM_ERROR("fubar while trying to restore kms_console\n");
861 return; /* drm_modeset_unlock_all(dev) ? */
864 ret = drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper);
866 DRM_DEBUG("failed to restore crtc mode\n");
868 mutex_lock(&fb_helper->dev->struct_mutex);
869 intel_fb_obj_invalidate(ifbdev->fb->obj, ORIGIN_GTT);
870 mutex_unlock(&fb_helper->dev->struct_mutex);