drm/i915: Update to Linux 3.17
[dragonfly.git] / sys / dev / drm / i915 / intel_fbdev.c
blobd7c569545531e50e60d75f5c057a2693f71fc38f
1 /*
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
13 * Software.
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.
23 * Authors:
24 * David Airlie
27 #include <drm/drmP.h>
28 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/errno.h>
31 #include <linux/string.h>
32 #include <linux/mm.h>
33 #include <linux/delay.h>
34 #include <linux/fb.h>
36 #include <drm/drmP.h>
37 #include <drm/drm_crtc.h>
38 #include <drm/drm_fb_helper.h>
39 #include "intel_drv.h"
40 #include <drm/i915_drm.h>
41 #include "i915_drv.h"
43 #if 0
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);
49 int ret;
51 ret = drm_fb_helper_set_par(info);
53 if (ret == 0) {
55 * FIXME: fbdev presumes that all callbacks also work from
56 * atomic contexts and relies on that for emergency oops
57 * printing. KMS totally doesn't do that and the locking here is
58 * by far not the only place this goes wrong. Ignore this for
59 * now until we solve this for real.
61 mutex_lock(&fb_helper->dev->struct_mutex);
62 ret = i915_gem_object_set_to_gtt_domain(ifbdev->fb->obj,
63 true);
64 mutex_unlock(&fb_helper->dev->struct_mutex);
67 return ret;
70 static struct fb_ops intelfb_ops = {
71 .owner = THIS_MODULE,
72 .fb_check_var = drm_fb_helper_check_var,
73 .fb_set_par = intel_fbdev_set_par,
74 .fb_fillrect = cfb_fillrect,
75 .fb_copyarea = cfb_copyarea,
76 .fb_imageblit = cfb_imageblit,
77 .fb_pan_display = drm_fb_helper_pan_display,
78 .fb_blank = drm_fb_helper_blank,
79 .fb_setcmap = drm_fb_helper_setcmap,
80 .fb_debug_enter = drm_fb_helper_debug_enter,
81 .fb_debug_leave = drm_fb_helper_debug_leave,
83 #endif
85 static int intelfb_alloc(struct drm_fb_helper *helper,
86 struct drm_fb_helper_surface_size *sizes)
88 struct intel_fbdev *ifbdev =
89 container_of(helper, struct intel_fbdev, helper);
90 struct drm_framebuffer *fb;
91 struct drm_device *dev = helper->dev;
92 struct drm_mode_fb_cmd2 mode_cmd = {};
93 struct drm_i915_gem_object *obj;
94 int size, ret;
96 /* we don't do packed 24bpp */
97 if (sizes->surface_bpp == 24)
98 sizes->surface_bpp = 32;
100 mode_cmd.width = sizes->surface_width;
101 mode_cmd.height = sizes->surface_height;
103 mode_cmd.pitches[0] = ALIGN(mode_cmd.width *
104 DIV_ROUND_UP(sizes->surface_bpp, 8), 64);
105 mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp,
106 sizes->surface_depth);
108 size = mode_cmd.pitches[0] * mode_cmd.height;
109 size = PAGE_ALIGN(size);
110 obj = i915_gem_object_create_stolen(dev, size);
111 if (obj == NULL)
112 obj = i915_gem_alloc_object(dev, size);
113 if (!obj) {
114 DRM_ERROR("failed to allocate framebuffer\n");
115 ret = -ENOMEM;
116 goto out;
119 /* Flush everything out, we'll be doing GTT only from now on */
120 ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
121 if (ret) {
122 DRM_ERROR("failed to pin obj: %d\n", ret);
123 goto out_unref;
126 fb = __intel_framebuffer_create(dev, &mode_cmd, obj);
127 if (IS_ERR(fb)) {
128 ret = PTR_ERR(fb);
129 goto out_unpin;
132 ifbdev->fb = to_intel_framebuffer(fb);
134 return 0;
136 out_unpin:
137 i915_gem_object_ggtt_unpin(obj);
138 out_unref:
139 drm_gem_object_unreference(&obj->base);
140 out:
141 return ret;
144 static int intelfb_create(struct drm_fb_helper *helper,
145 struct drm_fb_helper_surface_size *sizes)
147 struct intel_fbdev *ifbdev =
148 container_of(helper, struct intel_fbdev, helper);
149 struct intel_framebuffer *intel_fb = ifbdev->fb;
150 struct drm_device *dev = helper->dev;
151 #if 0
152 struct drm_i915_private *dev_priv = dev->dev_private;
153 #endif
154 struct fb_info *info;
155 struct drm_framebuffer *fb;
156 struct drm_i915_gem_object *obj;
157 device_t vga_dev;
158 int size, ret;
159 bool prealloc = false;
161 mutex_lock(&dev->struct_mutex);
163 if (intel_fb &&
164 (sizes->fb_width > intel_fb->base.width ||
165 sizes->fb_height > intel_fb->base.height)) {
166 DRM_DEBUG_KMS("BIOS fb too small (%dx%d), we require (%dx%d),"
167 " releasing it\n",
168 intel_fb->base.width, intel_fb->base.height,
169 sizes->fb_width, sizes->fb_height);
170 drm_framebuffer_unreference(&intel_fb->base);
171 intel_fb = ifbdev->fb = NULL;
173 if (!intel_fb || WARN_ON(!intel_fb->obj)) {
174 DRM_DEBUG_KMS("no BIOS fb, allocating a new one\n");
175 ret = intelfb_alloc(helper, sizes);
176 if (ret)
177 goto out_unlock;
178 intel_fb = ifbdev->fb;
179 } else {
180 DRM_DEBUG_KMS("re-using BIOS fb\n");
181 prealloc = true;
182 sizes->fb_width = intel_fb->base.width;
183 sizes->fb_height = intel_fb->base.height;
186 obj = intel_fb->obj;
187 size = obj->base.size;
189 #if 0
190 info = framebuffer_alloc(0, &dev->pdev->dev);
191 #else
192 info = kmalloc(sizeof(struct fb_info), M_DRM, M_WAITOK | M_ZERO);
193 #endif
194 if (!info) {
195 ret = -ENOMEM;
196 goto out_unpin;
198 #if 0
199 info->par = helper;
200 #endif
202 #ifdef __DragonFly__
203 vga_dev = device_get_parent(dev->dev);
204 info = kmalloc(sizeof(struct fb_info), M_DRM, M_WAITOK | M_ZERO);
205 info->width = sizes->fb_width;
206 info->height = sizes->fb_height;
207 info->stride =
208 ALIGN(sizes->surface_width * ((sizes->surface_bpp + 7) / 8), 64);
209 info->depth = sizes->surface_bpp;
210 info->paddr = dev->agp->base + i915_gem_obj_ggtt_offset(obj);
211 info->is_vga_boot_display = vga_pci_is_boot_display(vga_dev);
212 info->vaddr =
213 (vm_offset_t)pmap_mapdev_attr(info->paddr,
214 sizes->surface_height * info->stride,
215 VM_MEMATTR_WRITE_COMBINING);
216 #endif
218 fb = &ifbdev->fb->base;
220 ifbdev->helper.fb = fb;
221 ifbdev->helper.fbdev = info;
223 #if 0
224 strcpy(info->fix.id, "inteldrmfb");
226 info->flags = FBINFO_DEFAULT | FBINFO_CAN_FORCE_OUTPUT;
227 info->fbops = &intelfb_ops;
229 ret = fb_alloc_cmap(&info->cmap, 256, 0);
230 if (ret) {
231 ret = -ENOMEM;
232 goto out_unpin;
234 /* setup aperture base/size for vesafb takeover */
235 info->apertures = alloc_apertures(1);
236 if (!info->apertures) {
237 ret = -ENOMEM;
238 goto out_unpin;
240 info->apertures->ranges[0].base = dev->mode_config.fb_base;
241 info->apertures->ranges[0].size = dev_priv->gtt.mappable_end;
243 info->fix.smem_start = dev->mode_config.fb_base + i915_gem_obj_ggtt_offset(obj);
244 info->fix.smem_len = size;
246 info->screen_base =
247 ioremap_wc(dev_priv->gtt.mappable_base + i915_gem_obj_ggtt_offset(obj),
248 size);
249 if (!info->screen_base) {
250 ret = -ENOSPC;
251 goto out_unpin;
253 info->screen_size = size;
255 /* This driver doesn't need a VT switch to restore the mode on resume */
256 info->skip_vt_switch = true;
258 drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth);
259 drm_fb_helper_fill_var(info, &ifbdev->helper, sizes->fb_width, sizes->fb_height);
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 (ifbdev->fb->obj->stolen && !prealloc)
266 memset_io(info->screen_base, 0, info->screen_size);
268 /* Use default scratch pixmap (info->pixmap.flags = FB_PIXMAP_SYSTEM) */
269 #endif
271 DRM_DEBUG_KMS("allocated %dx%d fb: 0x%08lx, bo %p\n",
272 fb->width, fb->height,
273 i915_gem_obj_ggtt_offset(obj), obj);
275 mutex_unlock(&dev->struct_mutex);
276 #if 0
277 vga_switcheroo_client_fb_set(dev->pdev, info);
278 #endif
279 return 0;
281 out_unpin:
282 i915_gem_object_ggtt_unpin(obj);
283 drm_gem_object_unreference(&obj->base);
284 out_unlock:
285 mutex_unlock(&dev->struct_mutex);
286 return ret;
289 /** Sets the color ramps on behalf of RandR */
290 static void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
291 u16 blue, int regno)
293 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
295 intel_crtc->lut_r[regno] = red >> 8;
296 intel_crtc->lut_g[regno] = green >> 8;
297 intel_crtc->lut_b[regno] = blue >> 8;
300 static void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
301 u16 *blue, int regno)
303 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
305 *red = intel_crtc->lut_r[regno] << 8;
306 *green = intel_crtc->lut_g[regno] << 8;
307 *blue = intel_crtc->lut_b[regno] << 8;
310 static struct drm_fb_helper_crtc *
311 intel_fb_helper_crtc(struct drm_fb_helper *fb_helper, struct drm_crtc *crtc)
313 int i;
315 for (i = 0; i < fb_helper->crtc_count; i++)
316 if (fb_helper->crtc_info[i].mode_set.crtc == crtc)
317 return &fb_helper->crtc_info[i];
319 return NULL;
323 * Try to read the BIOS display configuration and use it for the initial
324 * fb configuration.
326 * The BIOS or boot loader will generally create an initial display
327 * configuration for us that includes some set of active pipes and displays.
328 * This routine tries to figure out which pipes and connectors are active
329 * and stuffs them into the crtcs and modes array given to us by the
330 * drm_fb_helper code.
332 * The overall sequence is:
333 * intel_fbdev_init - from driver load
334 * intel_fbdev_init_bios - initialize the intel_fbdev using BIOS data
335 * drm_fb_helper_init - build fb helper structs
336 * drm_fb_helper_single_add_all_connectors - more fb helper structs
337 * intel_fbdev_initial_config - apply the config
338 * drm_fb_helper_initial_config - call ->probe then register_framebuffer()
339 * drm_setup_crtcs - build crtc config for fbdev
340 * intel_fb_initial_config - find active connectors etc
341 * drm_fb_helper_single_fb_probe - set up fbdev
342 * intelfb_create - re-use or alloc fb, build out fbdev structs
344 * Note that we don't make special consideration whether we could actually
345 * switch to the selected modes without a full modeset. E.g. when the display
346 * is in VGA mode we need to recalculate watermarks and set a new high-res
347 * framebuffer anyway.
349 static bool intel_fb_initial_config(struct drm_fb_helper *fb_helper,
350 struct drm_fb_helper_crtc **crtcs,
351 struct drm_display_mode **modes,
352 bool *enabled, int width, int height)
354 struct drm_device *dev = fb_helper->dev;
355 int i, j;
356 bool *save_enabled;
357 bool fallback = true;
358 int num_connectors_enabled = 0;
359 int num_connectors_detected = 0;
362 * If the user specified any force options, just bail here
363 * and use that config.
365 for (i = 0; i < fb_helper->connector_count; i++) {
366 struct drm_fb_helper_connector *fb_conn;
367 struct drm_connector *connector;
369 fb_conn = fb_helper->connector_info[i];
370 connector = fb_conn->connector;
372 if (!enabled[i])
373 continue;
375 if (connector->force != DRM_FORCE_UNSPECIFIED)
376 return false;
379 save_enabled = kcalloc(dev->mode_config.num_connector, sizeof(bool),
380 GFP_KERNEL);
381 if (!save_enabled)
382 return false;
384 memcpy(save_enabled, enabled, dev->mode_config.num_connector);
386 for (i = 0; i < fb_helper->connector_count; i++) {
387 struct drm_fb_helper_connector *fb_conn;
388 struct drm_connector *connector;
389 struct drm_encoder *encoder;
390 struct drm_fb_helper_crtc *new_crtc;
392 fb_conn = fb_helper->connector_info[i];
393 connector = fb_conn->connector;
395 if (connector->status == connector_status_connected)
396 num_connectors_detected++;
398 if (!enabled[i]) {
399 DRM_DEBUG_KMS("connector %s not enabled, skipping\n",
400 connector->name);
401 continue;
404 encoder = connector->encoder;
405 if (!encoder || WARN_ON(!encoder->crtc)) {
406 DRM_DEBUG_KMS("connector %s has no encoder or crtc, skipping\n",
407 connector->name);
408 enabled[i] = false;
409 continue;
412 num_connectors_enabled++;
414 new_crtc = intel_fb_helper_crtc(fb_helper, encoder->crtc);
417 * Make sure we're not trying to drive multiple connectors
418 * with a single CRTC, since our cloning support may not
419 * match the BIOS.
421 for (j = 0; j < fb_helper->connector_count; j++) {
422 if (crtcs[j] == new_crtc) {
423 DRM_DEBUG_KMS("fallback: cloned configuration\n");
424 fallback = true;
425 goto out;
429 DRM_DEBUG_KMS("looking for cmdline mode on connector %s\n",
430 connector->name);
432 /* go for command line mode first */
433 modes[i] = drm_pick_cmdline_mode(fb_conn, width, height);
435 /* try for preferred next */
436 if (!modes[i]) {
437 DRM_DEBUG_KMS("looking for preferred mode on connector %s\n",
438 connector->name);
439 modes[i] = drm_has_preferred_mode(fb_conn, width,
440 height);
443 /* No preferred mode marked by the EDID? Are there any modes? */
444 if (!modes[i] && !list_empty(&connector->modes)) {
445 DRM_DEBUG_KMS("using first mode listed on connector %s\n",
446 connector->name);
447 modes[i] = list_first_entry(&connector->modes,
448 struct drm_display_mode,
449 head);
452 /* last resort: use current mode */
453 if (!modes[i]) {
455 * IMPORTANT: We want to use the adjusted mode (i.e.
456 * after the panel fitter upscaling) as the initial
457 * config, not the input mode, which is what crtc->mode
458 * usually contains. But since our current fastboot
459 * code puts a mode derived from the post-pfit timings
460 * into crtc->mode this works out correctly. We don't
461 * use hwmode anywhere right now, so use it for this
462 * since the fb helper layer wants a pointer to
463 * something we own.
465 DRM_DEBUG_KMS("looking for current mode on connector %s\n",
466 connector->name);
467 intel_mode_from_pipe_config(&encoder->crtc->hwmode,
468 &to_intel_crtc(encoder->crtc)->config);
469 modes[i] = &encoder->crtc->hwmode;
471 crtcs[i] = new_crtc;
473 DRM_DEBUG_KMS("connector %s on pipe %c [CRTC:%d]: %dx%d%s\n",
474 connector->name,
475 pipe_name(to_intel_crtc(encoder->crtc)->pipe),
476 encoder->crtc->base.id,
477 modes[i]->hdisplay, modes[i]->vdisplay,
478 modes[i]->flags & DRM_MODE_FLAG_INTERLACE ? "i" :"");
480 fallback = false;
484 * If the BIOS didn't enable everything it could, fall back to have the
485 * same user experiencing of lighting up as much as possible like the
486 * fbdev helper library.
488 if (num_connectors_enabled != num_connectors_detected &&
489 num_connectors_enabled < INTEL_INFO(dev)->num_pipes) {
490 DRM_DEBUG_KMS("fallback: Not all outputs enabled\n");
491 DRM_DEBUG_KMS("Enabled: %i, detected: %i\n", num_connectors_enabled,
492 num_connectors_detected);
493 fallback = true;
496 out:
497 if (fallback) {
498 DRM_DEBUG_KMS("Not using firmware configuration\n");
499 memcpy(enabled, save_enabled, dev->mode_config.num_connector);
500 kfree(save_enabled);
501 return false;
504 kfree(save_enabled);
505 return true;
508 static const struct drm_fb_helper_funcs intel_fb_helper_funcs = {
509 .initial_config = intel_fb_initial_config,
510 .gamma_set = intel_crtc_fb_gamma_set,
511 .gamma_get = intel_crtc_fb_gamma_get,
512 .fb_probe = intelfb_create,
515 static void intel_fbdev_destroy(struct drm_device *dev,
516 struct intel_fbdev *ifbdev)
518 #if 0
519 if (ifbdev->helper.fbdev) {
520 struct fb_info *info = ifbdev->helper.fbdev;
522 unregister_framebuffer(info);
523 iounmap(info->screen_base);
524 if (info->cmap.len)
525 fb_dealloc_cmap(&info->cmap);
527 framebuffer_release(info);
529 #endif
531 drm_fb_helper_fini(&ifbdev->helper);
533 drm_framebuffer_unregister_private(&ifbdev->fb->base);
534 drm_framebuffer_unreference(&ifbdev->fb->base);
538 * Build an intel_fbdev struct using a BIOS allocated framebuffer, if possible.
539 * The core display code will have read out the current plane configuration,
540 * so we use that to figure out if there's an object for us to use as the
541 * fb, and if so, we re-use it for the fbdev configuration.
543 * Note we only support a single fb shared across pipes for boot (mostly for
544 * fbcon), so we just find the biggest and use that.
546 static bool intel_fbdev_init_bios(struct drm_device *dev,
547 struct intel_fbdev *ifbdev)
549 struct intel_framebuffer *fb = NULL;
550 struct drm_crtc *crtc;
551 struct intel_crtc *intel_crtc;
552 struct intel_plane_config *plane_config = NULL;
553 unsigned int max_size = 0;
555 if (!i915.fastboot)
556 return false;
558 /* Find the largest fb */
559 for_each_crtc(dev, crtc) {
560 intel_crtc = to_intel_crtc(crtc);
562 if (!intel_crtc->active || !crtc->primary->fb) {
563 DRM_DEBUG_KMS("pipe %c not active or no fb, skipping\n",
564 pipe_name(intel_crtc->pipe));
565 continue;
568 if (intel_crtc->plane_config.size > max_size) {
569 DRM_DEBUG_KMS("found possible fb from plane %c\n",
570 pipe_name(intel_crtc->pipe));
571 plane_config = &intel_crtc->plane_config;
572 fb = to_intel_framebuffer(crtc->primary->fb);
573 max_size = plane_config->size;
577 if (!fb) {
578 DRM_DEBUG_KMS("no active fbs found, not using BIOS config\n");
579 goto out;
582 /* Now make sure all the pipes will fit into it */
583 for_each_crtc(dev, crtc) {
584 unsigned int cur_size;
586 intel_crtc = to_intel_crtc(crtc);
588 if (!intel_crtc->active) {
589 DRM_DEBUG_KMS("pipe %c not active, skipping\n",
590 pipe_name(intel_crtc->pipe));
591 continue;
594 DRM_DEBUG_KMS("checking plane %c for BIOS fb\n",
595 pipe_name(intel_crtc->pipe));
598 * See if the plane fb we found above will fit on this
599 * pipe. Note we need to use the selected fb's pitch and bpp
600 * rather than the current pipe's, since they differ.
602 cur_size = intel_crtc->config.adjusted_mode.crtc_hdisplay;
603 cur_size = cur_size * fb->base.bits_per_pixel / 8;
604 if (fb->base.pitches[0] < cur_size) {
605 DRM_DEBUG_KMS("fb not wide enough for plane %c (%d vs %d)\n",
606 pipe_name(intel_crtc->pipe),
607 cur_size, fb->base.pitches[0]);
608 plane_config = NULL;
609 fb = NULL;
610 break;
613 cur_size = intel_crtc->config.adjusted_mode.crtc_vdisplay;
614 cur_size = ALIGN(cur_size, plane_config->tiled ? (IS_GEN2(dev) ? 16 : 8) : 1);
615 cur_size *= fb->base.pitches[0];
616 DRM_DEBUG_KMS("pipe %c area: %dx%d, bpp: %d, size: %d\n",
617 pipe_name(intel_crtc->pipe),
618 intel_crtc->config.adjusted_mode.crtc_hdisplay,
619 intel_crtc->config.adjusted_mode.crtc_vdisplay,
620 fb->base.bits_per_pixel,
621 cur_size);
623 if (cur_size > max_size) {
624 DRM_DEBUG_KMS("fb not big enough for plane %c (%d vs %d)\n",
625 pipe_name(intel_crtc->pipe),
626 cur_size, max_size);
627 plane_config = NULL;
628 fb = NULL;
629 break;
632 DRM_DEBUG_KMS("fb big enough for plane %c (%d >= %d)\n",
633 pipe_name(intel_crtc->pipe),
634 max_size, cur_size);
637 if (!fb) {
638 DRM_DEBUG_KMS("BIOS fb not suitable for all pipes, not using\n");
639 goto out;
642 ifbdev->preferred_bpp = fb->base.bits_per_pixel;
643 ifbdev->fb = fb;
645 drm_framebuffer_reference(&ifbdev->fb->base);
647 /* Final pass to check if any active pipes don't have fbs */
648 for_each_crtc(dev, crtc) {
649 intel_crtc = to_intel_crtc(crtc);
651 if (!intel_crtc->active)
652 continue;
654 WARN(!crtc->primary->fb,
655 "re-used BIOS config but lost an fb on crtc %d\n",
656 crtc->base.id);
660 DRM_DEBUG_KMS("using BIOS fb for initial console\n");
661 return true;
663 out:
665 return false;
668 int intel_fbdev_init(struct drm_device *dev)
670 struct intel_fbdev *ifbdev;
671 struct drm_i915_private *dev_priv = dev->dev_private;
672 int ret;
674 if (WARN_ON(INTEL_INFO(dev)->num_pipes == 0))
675 return -ENODEV;
677 ifbdev = kzalloc(sizeof(struct intel_fbdev), GFP_KERNEL);
678 if (ifbdev == NULL)
679 return -ENOMEM;
681 drm_fb_helper_prepare(dev, &ifbdev->helper, &intel_fb_helper_funcs);
683 if (!intel_fbdev_init_bios(dev, ifbdev))
684 ifbdev->preferred_bpp = 32;
686 ret = drm_fb_helper_init(dev, &ifbdev->helper,
687 INTEL_INFO(dev)->num_pipes, 4);
688 if (ret) {
689 kfree(ifbdev);
690 return ret;
693 dev_priv->fbdev = ifbdev;
694 drm_fb_helper_single_add_all_connectors(&ifbdev->helper);
696 return 0;
699 void intel_fbdev_initial_config(struct drm_device *dev)
701 struct drm_i915_private *dev_priv = dev->dev_private;
703 /* Due to peculiar init order wrt to hpd handling this is separate. */
704 drm_fb_helper_initial_config(&dev_priv->fbdev->helper, 32);
707 void intel_fbdev_fini(struct drm_device *dev)
709 struct drm_i915_private *dev_priv = dev->dev_private;
710 if (!dev_priv->fbdev)
711 return;
713 intel_fbdev_destroy(dev, dev_priv->fbdev);
714 kfree(dev_priv->fbdev);
715 dev_priv->fbdev = NULL;
718 void intel_fbdev_set_suspend(struct drm_device *dev, int state)
720 #if 0
721 struct drm_i915_private *dev_priv = dev->dev_private;
722 struct intel_fbdev *ifbdev = dev_priv->fbdev;
723 struct fb_info *info;
725 if (!ifbdev)
726 return;
728 info = ifbdev->helper.fbdev;
730 /* On resume from hibernation: If the object is shmemfs backed, it has
731 * been restored from swap. If the object is stolen however, it will be
732 * full of whatever garbage was left in there.
734 if (state == FBINFO_STATE_RUNNING && ifbdev->ifb.obj->stolen)
735 memset_io(info->screen_base, 0, info->screen_size);
737 fb_set_suspend(info, state);
738 #endif
741 void intel_fbdev_output_poll_changed(struct drm_device *dev)
743 struct drm_i915_private *dev_priv = dev->dev_private;
744 drm_fb_helper_hotplug_event(&dev_priv->fbdev->helper);
747 void intel_fbdev_restore_mode(struct drm_device *dev)
749 int ret;
750 struct drm_i915_private *dev_priv = dev->dev_private;
752 if (INTEL_INFO(dev)->num_pipes == 0)
753 return;
755 ret = drm_fb_helper_restore_fbdev_mode_unlocked(&dev_priv->fbdev->helper);
756 if (ret)
757 DRM_DEBUG("failed to restore crtc mode\n");