2 * Copyright (c) 2006-2009 Red Hat Inc.
3 * Copyright (c) 2006-2008 Intel Corporation
6 * DRM framebuffer helper functions
8 * Permission to use, copy, modify, distribute, and sell this software and its
9 * documentation for any purpose is hereby granted without fee, provided that
10 * the above copyright notice appear in all copies and that both that copyright
11 * notice and this permission notice appear in supporting documentation, and
12 * that the name of the copyright holders not be used in advertising or
13 * publicity pertaining to distribution of the software without specific,
14 * written prior permission. The copyright holders make no representations
15 * about the suitability of this software for any purpose. It is provided "as
16 * is" without express or implied warranty.
18 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
20 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
21 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
22 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
23 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32 #include <linux/kernel.h>
33 #include <linux/sysrq.h>
34 #include <linux/slab.h>
36 #include <linux/module.h>
38 #include <drm/drm_crtc.h>
39 #include <drm/drm_fb_helper.h>
40 #include <drm/drm_crtc_helper.h>
42 static LIST_HEAD(kernel_fb_helper_list);
47 * The fb helper functions are useful to provide an fbdev on top of a drm kernel
48 * mode setting driver. They can be used mostly independently from the crtc
49 * helper functions used by many drivers to implement the kernel mode setting
52 * Initialization is done as a four-step process with drm_fb_helper_prepare(),
53 * drm_fb_helper_init(), drm_fb_helper_single_add_all_connectors() and
54 * drm_fb_helper_initial_config(). Drivers with fancier requirements than the
55 * default behaviour can override the third step with their own code.
56 * Teardown is done with drm_fb_helper_fini().
58 * At runtime drivers should restore the fbdev console by calling
59 * drm_fb_helper_restore_fbdev_mode() from their ->lastclose callback. They
60 * should also notify the fb helper code from updates to the output
61 * configuration by calling drm_fb_helper_hotplug_event(). For easier
62 * integration with the output polling code in drm_crtc_helper.c the modeset
63 * code provides a ->output_poll_changed callback.
65 * All other functions exported by the fb helper library can be used to
66 * implement the fbdev driver interface by the driver.
68 * It is possible, though perhaps somewhat tricky, to implement race-free
69 * hotplug detection using the fbdev helpers. The drm_fb_helper_prepare()
70 * helper must be called first to initialize the minimum required to make
71 * hotplug detection work. Drivers also need to make sure to properly set up
72 * the dev->mode_config.funcs member. After calling drm_kms_helper_poll_init()
73 * it is safe to enable interrupts and start processing hotplug events. At the
74 * same time, drivers should initialize all modeset objects such as CRTCs,
75 * encoders and connectors. To finish up the fbdev helper initialization, the
76 * drm_fb_helper_init() function is called. To probe for all attached displays
77 * and set up an initial configuration using the detected hardware, drivers
78 * should call drm_fb_helper_single_add_all_connectors() followed by
79 * drm_fb_helper_initial_config().
83 * drm_fb_helper_single_add_all_connectors() - add all connectors to fbdev
85 * @fb_helper: fbdev initialized with drm_fb_helper_init
87 * This functions adds all the available connectors for use with the given
88 * fb_helper. This is a separate step to allow drivers to freely assign
89 * connectors to the fbdev, e.g. if some are reserved for special purposes or
90 * not adequate to be used for the fbcon.
92 * Since this is part of the initial setup before the fbdev is published, no
93 * locking is required.
95 int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
97 struct drm_device *dev = fb_helper->dev;
98 struct drm_connector *connector;
101 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
102 struct drm_fb_helper_connector *fb_helper_connector;
104 fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL);
105 if (!fb_helper_connector)
108 fb_helper_connector->connector = connector;
109 fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector;
113 for (i = 0; i < fb_helper->connector_count; i++) {
114 kfree(fb_helper->connector_info[i]);
115 fb_helper->connector_info[i] = NULL;
117 fb_helper->connector_count = 0;
120 EXPORT_SYMBOL(drm_fb_helper_single_add_all_connectors);
122 int drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper, struct drm_connector *connector)
124 struct drm_fb_helper_connector **temp;
125 struct drm_fb_helper_connector *fb_helper_connector;
127 WARN_ON(!mutex_is_locked(&fb_helper->dev->mode_config.mutex));
128 if (fb_helper->connector_count + 1 > fb_helper->connector_info_alloc_count) {
129 temp = krealloc(fb_helper->connector_info, sizeof(struct drm_fb_helper_connector *) * (fb_helper->connector_count + 1), GFP_KERNEL);
133 fb_helper->connector_info_alloc_count = fb_helper->connector_count + 1;
134 fb_helper->connector_info = temp;
138 fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL);
139 if (!fb_helper_connector)
142 fb_helper_connector->connector = connector;
143 fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector;
146 EXPORT_SYMBOL(drm_fb_helper_add_one_connector);
148 int drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper,
149 struct drm_connector *connector)
151 struct drm_fb_helper_connector *fb_helper_connector;
154 WARN_ON(!mutex_is_locked(&fb_helper->dev->mode_config.mutex));
156 for (i = 0; i < fb_helper->connector_count; i++) {
157 if (fb_helper->connector_info[i]->connector == connector)
161 if (i == fb_helper->connector_count)
163 fb_helper_connector = fb_helper->connector_info[i];
165 for (j = i + 1; j < fb_helper->connector_count; j++) {
166 fb_helper->connector_info[j - 1] = fb_helper->connector_info[j];
168 fb_helper->connector_count--;
169 kfree(fb_helper_connector);
172 EXPORT_SYMBOL(drm_fb_helper_remove_one_connector);
174 static void drm_fb_helper_save_lut_atomic(struct drm_crtc *crtc, struct drm_fb_helper *helper)
176 uint16_t *r_base, *g_base, *b_base;
179 if (helper->funcs->gamma_get == NULL)
182 r_base = crtc->gamma_store;
183 g_base = r_base + crtc->gamma_size;
184 b_base = g_base + crtc->gamma_size;
186 for (i = 0; i < crtc->gamma_size; i++)
187 helper->funcs->gamma_get(crtc, &r_base[i], &g_base[i], &b_base[i], i);
190 static void drm_fb_helper_restore_lut_atomic(struct drm_crtc *crtc)
192 uint16_t *r_base, *g_base, *b_base;
194 if (crtc->funcs->gamma_set == NULL)
197 r_base = crtc->gamma_store;
198 g_base = r_base + crtc->gamma_size;
199 b_base = g_base + crtc->gamma_size;
201 crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size);
205 * drm_fb_helper_debug_enter - implementation for ->fb_debug_enter
206 * @info: fbdev registered by the helper
208 int drm_fb_helper_debug_enter(struct fb_info *info)
210 struct drm_fb_helper *helper = info->par;
211 struct drm_crtc_helper_funcs *funcs;
214 list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) {
215 for (i = 0; i < helper->crtc_count; i++) {
216 struct drm_mode_set *mode_set =
217 &helper->crtc_info[i].mode_set;
219 if (!mode_set->crtc->enabled)
222 funcs = mode_set->crtc->helper_private;
223 drm_fb_helper_save_lut_atomic(mode_set->crtc, helper);
224 funcs->mode_set_base_atomic(mode_set->crtc,
228 ENTER_ATOMIC_MODE_SET);
234 EXPORT_SYMBOL(drm_fb_helper_debug_enter);
236 /* Find the real fb for a given fb helper CRTC */
237 static struct drm_framebuffer *drm_mode_config_fb(struct drm_crtc *crtc)
239 struct drm_device *dev = crtc->dev;
242 list_for_each_entry(c, &dev->mode_config.crtc_list, head) {
243 if (crtc->base.id == c->base.id)
244 return c->primary->fb;
251 * drm_fb_helper_debug_leave - implementation for ->fb_debug_leave
252 * @info: fbdev registered by the helper
254 int drm_fb_helper_debug_leave(struct fb_info *info)
256 struct drm_fb_helper *helper = info->par;
257 struct drm_crtc *crtc;
258 struct drm_crtc_helper_funcs *funcs;
259 struct drm_framebuffer *fb;
262 for (i = 0; i < helper->crtc_count; i++) {
263 struct drm_mode_set *mode_set = &helper->crtc_info[i].mode_set;
264 crtc = mode_set->crtc;
265 funcs = crtc->helper_private;
266 fb = drm_mode_config_fb(crtc);
272 DRM_ERROR("no fb to restore??\n");
276 drm_fb_helper_restore_lut_atomic(mode_set->crtc);
277 funcs->mode_set_base_atomic(mode_set->crtc, fb, crtc->x,
278 crtc->y, LEAVE_ATOMIC_MODE_SET);
283 EXPORT_SYMBOL(drm_fb_helper_debug_leave);
285 static bool restore_fbdev_mode(struct drm_fb_helper *fb_helper)
287 struct drm_device *dev = fb_helper->dev;
288 struct drm_plane *plane;
292 drm_warn_on_modeset_not_all_locked(dev);
294 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
295 if (plane->type != DRM_PLANE_TYPE_PRIMARY)
296 drm_plane_force_disable(plane);
298 if (dev->mode_config.rotation_property) {
299 drm_mode_plane_set_obj_prop(plane,
300 dev->mode_config.rotation_property,
305 for (i = 0; i < fb_helper->crtc_count; i++) {
306 struct drm_mode_set *mode_set = &fb_helper->crtc_info[i].mode_set;
307 struct drm_crtc *crtc = mode_set->crtc;
310 if (crtc->funcs->cursor_set) {
311 ret = crtc->funcs->cursor_set(crtc, NULL, 0, 0, 0);
316 ret = drm_mode_set_config_internal(mode_set);
323 * drm_fb_helper_restore_fbdev_mode - restore fbdev configuration
324 * @fb_helper: fbcon to restore
326 * This should be called from driver's drm ->lastclose callback
327 * when implementing an fbcon on top of kms using this helper. This ensures that
328 * the user isn't greeted with a black screen when e.g. X dies.
330 * Use this variant if you need to bypass locking (panic), or already
331 * hold all modeset locks. Otherwise use drm_fb_helper_restore_fbdev_mode_unlocked()
333 static bool drm_fb_helper_restore_fbdev_mode(struct drm_fb_helper *fb_helper)
335 return restore_fbdev_mode(fb_helper);
339 * drm_fb_helper_restore_fbdev_mode_unlocked - restore fbdev configuration
340 * @fb_helper: fbcon to restore
342 * This should be called from driver's drm ->lastclose callback
343 * when implementing an fbcon on top of kms using this helper. This ensures that
344 * the user isn't greeted with a black screen when e.g. X dies.
346 bool drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper)
348 struct drm_device *dev = fb_helper->dev;
350 drm_modeset_lock_all(dev);
351 ret = restore_fbdev_mode(fb_helper);
352 drm_modeset_unlock_all(dev);
355 EXPORT_SYMBOL(drm_fb_helper_restore_fbdev_mode_unlocked);
358 * restore fbcon display for all kms driver's using this helper, used for sysrq
359 * and panic handling.
361 static bool drm_fb_helper_force_kernel_mode(void)
363 bool ret, error = false;
364 struct drm_fb_helper *helper;
366 if (list_empty(&kernel_fb_helper_list))
369 list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) {
370 struct drm_device *dev = helper->dev;
372 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
376 * NOTE: Use trylock mode to avoid deadlocks and sleeping in
379 if (__drm_modeset_lock_all(dev, true) != 0) {
384 ret = drm_fb_helper_restore_fbdev_mode(helper);
388 drm_modeset_unlock_all(dev);
393 static int drm_fb_helper_panic(struct notifier_block *n, unsigned long ununsed,
397 * It's a waste of time and effort to switch back to text console
398 * if the kernel should reboot before panic messages can be seen.
400 if (panic_timeout < 0)
403 pr_err("panic occurred, switching back to text console\n");
404 return drm_fb_helper_force_kernel_mode();
407 static struct notifier_block paniced = {
408 .notifier_call = drm_fb_helper_panic,
411 static bool drm_fb_helper_is_bound(struct drm_fb_helper *fb_helper)
413 struct drm_device *dev = fb_helper->dev;
414 struct drm_crtc *crtc;
415 int bound = 0, crtcs_bound = 0;
417 /* Sometimes user space wants everything disabled, so don't steal the
418 * display if there's a master. */
419 if (dev->primary->master)
422 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
423 if (crtc->primary->fb)
425 if (crtc->primary->fb == fb_helper->fb)
429 if (bound < crtcs_bound)
435 #ifdef CONFIG_MAGIC_SYSRQ
436 static void drm_fb_helper_restore_work_fn(struct work_struct *ignored)
439 ret = drm_fb_helper_force_kernel_mode();
441 DRM_ERROR("Failed to restore crtc configuration\n");
443 static DECLARE_WORK(drm_fb_helper_restore_work, drm_fb_helper_restore_work_fn);
445 static void drm_fb_helper_sysrq(int dummy1)
447 schedule_work(&drm_fb_helper_restore_work);
450 static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = {
451 .handler = drm_fb_helper_sysrq,
452 .help_msg = "force-fb(V)",
453 .action_msg = "Restore framebuffer console",
456 static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { };
459 static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode)
461 struct drm_fb_helper *fb_helper = info->par;
462 struct drm_device *dev = fb_helper->dev;
463 struct drm_crtc *crtc;
464 struct drm_connector *connector;
468 * fbdev->blank can be called from irq context in case of a panic.
469 * Since we already have our own special panic handler which will
470 * restore the fbdev console mode completely, just bail out early.
472 if (oops_in_progress)
476 * For each CRTC in this fb, turn the connectors on/off.
478 drm_modeset_lock_all(dev);
479 if (!drm_fb_helper_is_bound(fb_helper)) {
480 drm_modeset_unlock_all(dev);
484 for (i = 0; i < fb_helper->crtc_count; i++) {
485 crtc = fb_helper->crtc_info[i].mode_set.crtc;
490 /* Walk the connectors & encoders on this fb turning them on/off */
491 for (j = 0; j < fb_helper->connector_count; j++) {
492 connector = fb_helper->connector_info[j]->connector;
493 connector->funcs->dpms(connector, dpms_mode);
494 drm_object_property_set_value(&connector->base,
495 dev->mode_config.dpms_property, dpms_mode);
498 drm_modeset_unlock_all(dev);
502 * drm_fb_helper_blank - implementation for ->fb_blank
503 * @blank: desired blanking state
504 * @info: fbdev registered by the helper
506 int drm_fb_helper_blank(int blank, struct fb_info *info)
509 /* Display: On; HSync: On, VSync: On */
510 case FB_BLANK_UNBLANK:
511 drm_fb_helper_dpms(info, DRM_MODE_DPMS_ON);
513 /* Display: Off; HSync: On, VSync: On */
514 case FB_BLANK_NORMAL:
515 drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY);
517 /* Display: Off; HSync: Off, VSync: On */
518 case FB_BLANK_HSYNC_SUSPEND:
519 drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY);
521 /* Display: Off; HSync: On, VSync: Off */
522 case FB_BLANK_VSYNC_SUSPEND:
523 drm_fb_helper_dpms(info, DRM_MODE_DPMS_SUSPEND);
525 /* Display: Off; HSync: Off, VSync: Off */
526 case FB_BLANK_POWERDOWN:
527 drm_fb_helper_dpms(info, DRM_MODE_DPMS_OFF);
532 EXPORT_SYMBOL(drm_fb_helper_blank);
534 static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper)
538 for (i = 0; i < helper->connector_count; i++)
539 kfree(helper->connector_info[i]);
540 kfree(helper->connector_info);
541 for (i = 0; i < helper->crtc_count; i++) {
542 kfree(helper->crtc_info[i].mode_set.connectors);
543 if (helper->crtc_info[i].mode_set.mode)
544 drm_mode_destroy(helper->dev, helper->crtc_info[i].mode_set.mode);
546 kfree(helper->crtc_info);
550 * drm_fb_helper_prepare - setup a drm_fb_helper structure
552 * @helper: driver-allocated fbdev helper structure to set up
553 * @funcs: pointer to structure of functions associate with this helper
555 * Sets up the bare minimum to make the framebuffer helper usable. This is
556 * useful to implement race-free initialization of the polling helpers.
558 void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,
559 const struct drm_fb_helper_funcs *funcs)
561 INIT_LIST_HEAD(&helper->kernel_fb_list);
562 helper->funcs = funcs;
565 EXPORT_SYMBOL(drm_fb_helper_prepare);
568 * drm_fb_helper_init - initialize a drm_fb_helper structure
570 * @fb_helper: driver-allocated fbdev helper structure to initialize
571 * @crtc_count: maximum number of crtcs to support in this fbdev emulation
572 * @max_conn_count: max connector count
574 * This allocates the structures for the fbdev helper with the given limits.
575 * Note that this won't yet touch the hardware (through the driver interfaces)
576 * nor register the fbdev. This is only done in drm_fb_helper_initial_config()
577 * to allow driver writes more control over the exact init sequence.
579 * Drivers must call drm_fb_helper_prepare() before calling this function.
582 * Zero if everything went ok, nonzero otherwise.
584 int drm_fb_helper_init(struct drm_device *dev,
585 struct drm_fb_helper *fb_helper,
586 int crtc_count, int max_conn_count)
588 struct drm_crtc *crtc;
594 fb_helper->crtc_info = kcalloc(crtc_count, sizeof(struct drm_fb_helper_crtc), GFP_KERNEL);
595 if (!fb_helper->crtc_info)
598 fb_helper->crtc_count = crtc_count;
599 fb_helper->connector_info = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_fb_helper_connector *), GFP_KERNEL);
600 if (!fb_helper->connector_info) {
601 kfree(fb_helper->crtc_info);
604 fb_helper->connector_info_alloc_count = dev->mode_config.num_connector;
605 fb_helper->connector_count = 0;
607 for (i = 0; i < crtc_count; i++) {
608 fb_helper->crtc_info[i].mode_set.connectors =
609 kcalloc(max_conn_count,
610 sizeof(struct drm_connector *),
613 if (!fb_helper->crtc_info[i].mode_set.connectors)
615 fb_helper->crtc_info[i].mode_set.num_connectors = 0;
619 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
620 fb_helper->crtc_info[i].mode_set.crtc = crtc;
626 drm_fb_helper_crtc_free(fb_helper);
629 EXPORT_SYMBOL(drm_fb_helper_init);
631 void drm_fb_helper_fini(struct drm_fb_helper *fb_helper)
633 if (!list_empty(&fb_helper->kernel_fb_list)) {
634 list_del(&fb_helper->kernel_fb_list);
635 if (list_empty(&kernel_fb_helper_list)) {
636 pr_info("drm: unregistered panic notifier\n");
637 atomic_notifier_chain_unregister(&panic_notifier_list,
639 unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
643 drm_fb_helper_crtc_free(fb_helper);
646 EXPORT_SYMBOL(drm_fb_helper_fini);
648 static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green,
649 u16 blue, u16 regno, struct fb_info *info)
651 struct drm_fb_helper *fb_helper = info->par;
652 struct drm_framebuffer *fb = fb_helper->fb;
655 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
658 /* place color in psuedopalette */
661 palette = (u32 *)info->pseudo_palette;
662 red >>= (16 - info->var.red.length);
663 green >>= (16 - info->var.green.length);
664 blue >>= (16 - info->var.blue.length);
665 value = (red << info->var.red.offset) |
666 (green << info->var.green.offset) |
667 (blue << info->var.blue.offset);
668 if (info->var.transp.length > 0) {
669 u32 mask = (1 << info->var.transp.length) - 1;
670 mask <<= info->var.transp.offset;
673 palette[regno] = value;
678 * The driver really shouldn't advertise pseudo/directcolor
679 * visuals if it can't deal with the palette.
681 if (WARN_ON(!fb_helper->funcs->gamma_set ||
682 !fb_helper->funcs->gamma_get))
687 if (fb->bits_per_pixel == 16) {
690 if (fb->depth == 16 && regno > 63)
692 if (fb->depth == 15 && regno > 31)
695 if (fb->depth == 16) {
699 for (i = 0; i < 8; i++)
700 fb_helper->funcs->gamma_set(crtc, red,
701 green, blue, pindex + i);
704 fb_helper->funcs->gamma_get(crtc, &r,
708 for (i = 0; i < 4; i++)
709 fb_helper->funcs->gamma_set(crtc, r,
716 fb_helper->funcs->gamma_set(crtc, red, green, blue, pindex);
721 * drm_fb_helper_setcmap - implementation for ->fb_setcmap
723 * @info: fbdev registered by the helper
725 int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
727 struct drm_fb_helper *fb_helper = info->par;
728 struct drm_device *dev = fb_helper->dev;
729 struct drm_crtc_helper_funcs *crtc_funcs;
730 u16 *red, *green, *blue, *transp;
731 struct drm_crtc *crtc;
735 drm_modeset_lock_all(dev);
736 if (!drm_fb_helper_is_bound(fb_helper)) {
737 drm_modeset_unlock_all(dev);
741 for (i = 0; i < fb_helper->crtc_count; i++) {
742 crtc = fb_helper->crtc_info[i].mode_set.crtc;
743 crtc_funcs = crtc->helper_private;
748 transp = cmap->transp;
751 for (j = 0; j < cmap->len; j++) {
752 u16 hred, hgreen, hblue, htransp = 0xffff;
761 rc = setcolreg(crtc, hred, hgreen, hblue, start++, info);
765 if (crtc_funcs->load_lut)
766 crtc_funcs->load_lut(crtc);
769 drm_modeset_unlock_all(dev);
772 EXPORT_SYMBOL(drm_fb_helper_setcmap);
775 * drm_fb_helper_check_var - implementation for ->fb_check_var
776 * @var: screeninfo to check
777 * @info: fbdev registered by the helper
779 int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
780 struct fb_info *info)
782 struct drm_fb_helper *fb_helper = info->par;
783 struct drm_framebuffer *fb = fb_helper->fb;
786 if (var->pixclock != 0 || in_dbg_master())
789 /* Need to resize the fb object !!! */
790 if (var->bits_per_pixel > fb->bits_per_pixel ||
791 var->xres > fb->width || var->yres > fb->height ||
792 var->xres_virtual > fb->width || var->yres_virtual > fb->height) {
793 DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb "
794 "request %dx%d-%d (virtual %dx%d) > %dx%d-%d\n",
795 var->xres, var->yres, var->bits_per_pixel,
796 var->xres_virtual, var->yres_virtual,
797 fb->width, fb->height, fb->bits_per_pixel);
801 switch (var->bits_per_pixel) {
803 depth = (var->green.length == 6) ? 16 : 15;
806 depth = (var->transp.length > 0) ? 32 : 24;
809 depth = var->bits_per_pixel;
816 var->green.offset = 0;
817 var->blue.offset = 0;
819 var->green.length = 8;
820 var->blue.length = 8;
821 var->transp.length = 0;
822 var->transp.offset = 0;
825 var->red.offset = 10;
826 var->green.offset = 5;
827 var->blue.offset = 0;
829 var->green.length = 5;
830 var->blue.length = 5;
831 var->transp.length = 1;
832 var->transp.offset = 15;
835 var->red.offset = 11;
836 var->green.offset = 5;
837 var->blue.offset = 0;
839 var->green.length = 6;
840 var->blue.length = 5;
841 var->transp.length = 0;
842 var->transp.offset = 0;
845 var->red.offset = 16;
846 var->green.offset = 8;
847 var->blue.offset = 0;
849 var->green.length = 8;
850 var->blue.length = 8;
851 var->transp.length = 0;
852 var->transp.offset = 0;
855 var->red.offset = 16;
856 var->green.offset = 8;
857 var->blue.offset = 0;
859 var->green.length = 8;
860 var->blue.length = 8;
861 var->transp.length = 8;
862 var->transp.offset = 24;
869 EXPORT_SYMBOL(drm_fb_helper_check_var);
872 * drm_fb_helper_set_par - implementation for ->fb_set_par
873 * @info: fbdev registered by the helper
875 * This will let fbcon do the mode init and is called at initialization time by
876 * the fbdev core when registering the driver, and later on through the hotplug
879 int drm_fb_helper_set_par(struct fb_info *info)
881 struct drm_fb_helper *fb_helper = info->par;
882 struct fb_var_screeninfo *var = &info->var;
884 if (var->pixclock != 0) {
885 DRM_ERROR("PIXEL CLOCK SET\n");
889 drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper);
891 if (fb_helper->delayed_hotplug) {
892 fb_helper->delayed_hotplug = false;
893 drm_fb_helper_hotplug_event(fb_helper);
897 EXPORT_SYMBOL(drm_fb_helper_set_par);
900 * drm_fb_helper_pan_display - implementation for ->fb_pan_display
901 * @var: updated screen information
902 * @info: fbdev registered by the helper
904 int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
905 struct fb_info *info)
907 struct drm_fb_helper *fb_helper = info->par;
908 struct drm_device *dev = fb_helper->dev;
909 struct drm_mode_set *modeset;
913 drm_modeset_lock_all(dev);
914 if (!drm_fb_helper_is_bound(fb_helper)) {
915 drm_modeset_unlock_all(dev);
919 for (i = 0; i < fb_helper->crtc_count; i++) {
920 modeset = &fb_helper->crtc_info[i].mode_set;
922 modeset->x = var->xoffset;
923 modeset->y = var->yoffset;
925 if (modeset->num_connectors) {
926 ret = drm_mode_set_config_internal(modeset);
928 info->var.xoffset = var->xoffset;
929 info->var.yoffset = var->yoffset;
933 drm_modeset_unlock_all(dev);
936 EXPORT_SYMBOL(drm_fb_helper_pan_display);
939 * Allocates the backing storage and sets up the fbdev info structure through
940 * the ->fb_probe callback and then registers the fbdev and sets up the panic
943 static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,
949 struct fb_info *info;
950 struct drm_fb_helper_surface_size sizes;
953 memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size));
954 sizes.surface_depth = 24;
955 sizes.surface_bpp = 32;
956 sizes.fb_width = (unsigned)-1;
957 sizes.fb_height = (unsigned)-1;
959 /* if driver picks 8 or 16 by default use that
960 for both depth/bpp */
961 if (preferred_bpp != sizes.surface_bpp)
962 sizes.surface_depth = sizes.surface_bpp = preferred_bpp;
964 /* first up get a count of crtcs now in use and new min/maxes width/heights */
965 for (i = 0; i < fb_helper->connector_count; i++) {
966 struct drm_fb_helper_connector *fb_helper_conn = fb_helper->connector_info[i];
967 struct drm_cmdline_mode *cmdline_mode;
969 cmdline_mode = &fb_helper_conn->connector->cmdline_mode;
971 if (cmdline_mode->bpp_specified) {
972 switch (cmdline_mode->bpp) {
974 sizes.surface_depth = sizes.surface_bpp = 8;
977 sizes.surface_depth = 15;
978 sizes.surface_bpp = 16;
981 sizes.surface_depth = sizes.surface_bpp = 16;
984 sizes.surface_depth = sizes.surface_bpp = 24;
987 sizes.surface_depth = 24;
988 sizes.surface_bpp = 32;
996 for (i = 0; i < fb_helper->crtc_count; i++) {
997 struct drm_display_mode *desired_mode;
998 desired_mode = fb_helper->crtc_info[i].desired_mode;
1001 if (gamma_size == 0)
1002 gamma_size = fb_helper->crtc_info[i].mode_set.crtc->gamma_size;
1003 if (desired_mode->hdisplay < sizes.fb_width)
1004 sizes.fb_width = desired_mode->hdisplay;
1005 if (desired_mode->vdisplay < sizes.fb_height)
1006 sizes.fb_height = desired_mode->vdisplay;
1007 if (desired_mode->hdisplay > sizes.surface_width)
1008 sizes.surface_width = desired_mode->hdisplay;
1009 if (desired_mode->vdisplay > sizes.surface_height)
1010 sizes.surface_height = desired_mode->vdisplay;
1015 if (crtc_count == 0 || sizes.fb_width == -1 || sizes.fb_height == -1) {
1016 /* hmm everyone went away - assume VGA cable just fell out
1017 and will come back later. */
1018 DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n");
1019 sizes.fb_width = sizes.surface_width = 1024;
1020 sizes.fb_height = sizes.surface_height = 768;
1023 /* push down into drivers */
1024 ret = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes);
1028 info = fb_helper->fbdev;
1031 * Set the fb pointer - usually drm_setup_crtcs does this for hotplug
1032 * events, but at init time drm_setup_crtcs needs to be called before
1033 * the fb is allocated (since we need to figure out the desired size of
1034 * the fb before we can allocate it ...). Hence we need to fix things up
1037 for (i = 0; i < fb_helper->crtc_count; i++)
1038 if (fb_helper->crtc_info[i].mode_set.num_connectors)
1039 fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb;
1042 info->var.pixclock = 0;
1043 if (register_framebuffer(info) < 0)
1046 dev_info(fb_helper->dev->dev, "fb%d: %s frame buffer device\n",
1047 info->node, info->fix.id);
1049 /* Switch back to kernel console on panic */
1050 /* multi card linked list maybe */
1051 if (list_empty(&kernel_fb_helper_list)) {
1052 dev_info(fb_helper->dev->dev, "registered panic notifier\n");
1053 atomic_notifier_chain_register(&panic_notifier_list,
1055 register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
1058 list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list);
1064 * drm_fb_helper_fill_fix - initializes fixed fbdev information
1065 * @info: fbdev registered by the helper
1066 * @pitch: desired pitch
1067 * @depth: desired depth
1069 * Helper to fill in the fixed fbdev information useful for a non-accelerated
1070 * fbdev emulations. Drivers which support acceleration methods which impose
1071 * additional constraints need to set up their own limits.
1073 * Drivers should call this (or their equivalent setup code) from their
1074 * ->fb_probe callback.
1076 void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
1079 info->fix.type = FB_TYPE_PACKED_PIXELS;
1080 info->fix.visual = depth == 8 ? FB_VISUAL_PSEUDOCOLOR :
1081 FB_VISUAL_TRUECOLOR;
1082 info->fix.mmio_start = 0;
1083 info->fix.mmio_len = 0;
1084 info->fix.type_aux = 0;
1085 info->fix.xpanstep = 1; /* doing it in hw */
1086 info->fix.ypanstep = 1; /* doing it in hw */
1087 info->fix.ywrapstep = 0;
1088 info->fix.accel = FB_ACCEL_NONE;
1090 info->fix.line_length = pitch;
1093 EXPORT_SYMBOL(drm_fb_helper_fill_fix);
1096 * drm_fb_helper_fill_var - initalizes variable fbdev information
1097 * @info: fbdev instance to set up
1098 * @fb_helper: fb helper instance to use as template
1099 * @fb_width: desired fb width
1100 * @fb_height: desired fb height
1102 * Sets up the variable fbdev metainformation from the given fb helper instance
1103 * and the drm framebuffer allocated in fb_helper->fb.
1105 * Drivers should call this (or their equivalent setup code) from their
1106 * ->fb_probe callback after having allocated the fbdev backing
1107 * storage framebuffer.
1109 void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helper,
1110 uint32_t fb_width, uint32_t fb_height)
1112 struct drm_framebuffer *fb = fb_helper->fb;
1113 info->pseudo_palette = fb_helper->pseudo_palette;
1114 info->var.xres_virtual = fb->width;
1115 info->var.yres_virtual = fb->height;
1116 info->var.bits_per_pixel = fb->bits_per_pixel;
1117 info->var.accel_flags = FB_ACCELF_TEXT;
1118 info->var.xoffset = 0;
1119 info->var.yoffset = 0;
1120 info->var.activate = FB_ACTIVATE_NOW;
1121 info->var.height = -1;
1122 info->var.width = -1;
1124 switch (fb->depth) {
1126 info->var.red.offset = 0;
1127 info->var.green.offset = 0;
1128 info->var.blue.offset = 0;
1129 info->var.red.length = 8; /* 8bit DAC */
1130 info->var.green.length = 8;
1131 info->var.blue.length = 8;
1132 info->var.transp.offset = 0;
1133 info->var.transp.length = 0;
1136 info->var.red.offset = 10;
1137 info->var.green.offset = 5;
1138 info->var.blue.offset = 0;
1139 info->var.red.length = 5;
1140 info->var.green.length = 5;
1141 info->var.blue.length = 5;
1142 info->var.transp.offset = 15;
1143 info->var.transp.length = 1;
1146 info->var.red.offset = 11;
1147 info->var.green.offset = 5;
1148 info->var.blue.offset = 0;
1149 info->var.red.length = 5;
1150 info->var.green.length = 6;
1151 info->var.blue.length = 5;
1152 info->var.transp.offset = 0;
1155 info->var.red.offset = 16;
1156 info->var.green.offset = 8;
1157 info->var.blue.offset = 0;
1158 info->var.red.length = 8;
1159 info->var.green.length = 8;
1160 info->var.blue.length = 8;
1161 info->var.transp.offset = 0;
1162 info->var.transp.length = 0;
1165 info->var.red.offset = 16;
1166 info->var.green.offset = 8;
1167 info->var.blue.offset = 0;
1168 info->var.red.length = 8;
1169 info->var.green.length = 8;
1170 info->var.blue.length = 8;
1171 info->var.transp.offset = 24;
1172 info->var.transp.length = 8;
1178 info->var.xres = fb_width;
1179 info->var.yres = fb_height;
1181 EXPORT_SYMBOL(drm_fb_helper_fill_var);
1183 static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper *fb_helper,
1187 struct drm_connector *connector;
1191 for (i = 0; i < fb_helper->connector_count; i++) {
1192 connector = fb_helper->connector_info[i]->connector;
1193 count += connector->funcs->fill_modes(connector, maxX, maxY);
1199 struct drm_display_mode *drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector, int width, int height)
1201 struct drm_display_mode *mode;
1203 list_for_each_entry(mode, &fb_connector->connector->modes, head) {
1204 if (mode->hdisplay > width ||
1205 mode->vdisplay > height)
1207 if (mode->type & DRM_MODE_TYPE_PREFERRED)
1212 EXPORT_SYMBOL(drm_has_preferred_mode);
1214 static bool drm_has_cmdline_mode(struct drm_fb_helper_connector *fb_connector)
1216 return fb_connector->connector->cmdline_mode.specified;
1219 struct drm_display_mode *drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn,
1220 int width, int height)
1222 struct drm_cmdline_mode *cmdline_mode;
1223 struct drm_display_mode *mode = NULL;
1224 bool prefer_non_interlace;
1226 cmdline_mode = &fb_helper_conn->connector->cmdline_mode;
1227 if (cmdline_mode->specified == false)
1230 /* attempt to find a matching mode in the list of modes
1231 * we have gotten so far, if not add a CVT mode that conforms
1233 if (cmdline_mode->rb || cmdline_mode->margins)
1236 prefer_non_interlace = !cmdline_mode->interlace;
1238 list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
1239 /* check width/height */
1240 if (mode->hdisplay != cmdline_mode->xres ||
1241 mode->vdisplay != cmdline_mode->yres)
1244 if (cmdline_mode->refresh_specified) {
1245 if (mode->vrefresh != cmdline_mode->refresh)
1249 if (cmdline_mode->interlace) {
1250 if (!(mode->flags & DRM_MODE_FLAG_INTERLACE))
1252 } else if (prefer_non_interlace) {
1253 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1259 if (prefer_non_interlace) {
1260 prefer_non_interlace = false;
1265 mode = drm_mode_create_from_cmdline_mode(fb_helper_conn->connector->dev,
1267 list_add(&mode->head, &fb_helper_conn->connector->modes);
1270 EXPORT_SYMBOL(drm_pick_cmdline_mode);
1272 static bool drm_connector_enabled(struct drm_connector *connector, bool strict)
1277 enable = connector->status == connector_status_connected;
1279 enable = connector->status != connector_status_disconnected;
1284 static void drm_enable_connectors(struct drm_fb_helper *fb_helper,
1287 bool any_enabled = false;
1288 struct drm_connector *connector;
1291 for (i = 0; i < fb_helper->connector_count; i++) {
1292 connector = fb_helper->connector_info[i]->connector;
1293 enabled[i] = drm_connector_enabled(connector, true);
1294 DRM_DEBUG_KMS("connector %d enabled? %s\n", connector->base.id,
1295 enabled[i] ? "yes" : "no");
1296 any_enabled |= enabled[i];
1302 for (i = 0; i < fb_helper->connector_count; i++) {
1303 connector = fb_helper->connector_info[i]->connector;
1304 enabled[i] = drm_connector_enabled(connector, false);
1308 static bool drm_target_cloned(struct drm_fb_helper *fb_helper,
1309 struct drm_display_mode **modes,
1310 bool *enabled, int width, int height)
1313 bool can_clone = false;
1314 struct drm_fb_helper_connector *fb_helper_conn;
1315 struct drm_display_mode *dmt_mode, *mode;
1317 /* only contemplate cloning in the single crtc case */
1318 if (fb_helper->crtc_count > 1)
1322 for (i = 0; i < fb_helper->connector_count; i++) {
1327 /* only contemplate cloning if more than one connector is enabled */
1331 /* check the command line or if nothing common pick 1024x768 */
1333 for (i = 0; i < fb_helper->connector_count; i++) {
1336 fb_helper_conn = fb_helper->connector_info[i];
1337 modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
1342 for (j = 0; j < i; j++) {
1345 if (!drm_mode_equal(modes[j], modes[i]))
1351 DRM_DEBUG_KMS("can clone using command line\n");
1355 /* try and find a 1024x768 mode on each connector */
1357 dmt_mode = drm_mode_find_dmt(fb_helper->dev, 1024, 768, 60, false);
1359 for (i = 0; i < fb_helper->connector_count; i++) {
1364 fb_helper_conn = fb_helper->connector_info[i];
1365 list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
1366 if (drm_mode_equal(mode, dmt_mode))
1374 DRM_DEBUG_KMS("can clone using 1024x768\n");
1377 DRM_INFO("kms: can't enable cloning when we probably wanted to.\n");
1381 static bool drm_target_preferred(struct drm_fb_helper *fb_helper,
1382 struct drm_display_mode **modes,
1383 bool *enabled, int width, int height)
1385 struct drm_fb_helper_connector *fb_helper_conn;
1388 for (i = 0; i < fb_helper->connector_count; i++) {
1389 fb_helper_conn = fb_helper->connector_info[i];
1391 if (enabled[i] == false)
1394 DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n",
1395 fb_helper_conn->connector->base.id);
1397 /* got for command line mode first */
1398 modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
1400 DRM_DEBUG_KMS("looking for preferred mode on connector %d\n",
1401 fb_helper_conn->connector->base.id);
1402 modes[i] = drm_has_preferred_mode(fb_helper_conn, width, height);
1404 /* No preferred modes, pick one off the list */
1405 if (!modes[i] && !list_empty(&fb_helper_conn->connector->modes)) {
1406 list_for_each_entry(modes[i], &fb_helper_conn->connector->modes, head)
1409 DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name :
1415 static int drm_pick_crtcs(struct drm_fb_helper *fb_helper,
1416 struct drm_fb_helper_crtc **best_crtcs,
1417 struct drm_display_mode **modes,
1418 int n, int width, int height)
1421 struct drm_device *dev = fb_helper->dev;
1422 struct drm_connector *connector;
1423 struct drm_connector_helper_funcs *connector_funcs;
1424 struct drm_encoder *encoder;
1425 int my_score, best_score, score;
1426 struct drm_fb_helper_crtc **crtcs, *crtc;
1427 struct drm_fb_helper_connector *fb_helper_conn;
1429 if (n == fb_helper->connector_count)
1432 fb_helper_conn = fb_helper->connector_info[n];
1433 connector = fb_helper_conn->connector;
1435 best_crtcs[n] = NULL;
1436 best_score = drm_pick_crtcs(fb_helper, best_crtcs, modes, n+1, width, height);
1437 if (modes[n] == NULL)
1440 crtcs = kzalloc(dev->mode_config.num_connector *
1441 sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
1446 if (connector->status == connector_status_connected)
1448 if (drm_has_cmdline_mode(fb_helper_conn))
1450 if (drm_has_preferred_mode(fb_helper_conn, width, height))
1453 connector_funcs = connector->helper_private;
1454 encoder = connector_funcs->best_encoder(connector);
1458 /* select a crtc for this connector and then attempt to configure
1459 remaining connectors */
1460 for (c = 0; c < fb_helper->crtc_count; c++) {
1461 crtc = &fb_helper->crtc_info[c];
1463 if ((encoder->possible_crtcs & (1 << c)) == 0)
1466 for (o = 0; o < n; o++)
1467 if (best_crtcs[o] == crtc)
1471 /* ignore cloning unless only a single crtc */
1472 if (fb_helper->crtc_count > 1)
1475 if (!drm_mode_equal(modes[o], modes[n]))
1480 memcpy(crtcs, best_crtcs, n * sizeof(struct drm_fb_helper_crtc *));
1481 score = my_score + drm_pick_crtcs(fb_helper, crtcs, modes, n + 1,
1483 if (score > best_score) {
1485 memcpy(best_crtcs, crtcs,
1486 dev->mode_config.num_connector *
1487 sizeof(struct drm_fb_helper_crtc *));
1495 static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
1497 struct drm_device *dev = fb_helper->dev;
1498 struct drm_fb_helper_crtc **crtcs;
1499 struct drm_display_mode **modes;
1500 struct drm_mode_set *modeset;
1505 DRM_DEBUG_KMS("\n");
1507 width = dev->mode_config.max_width;
1508 height = dev->mode_config.max_height;
1510 crtcs = kcalloc(dev->mode_config.num_connector,
1511 sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
1512 modes = kcalloc(dev->mode_config.num_connector,
1513 sizeof(struct drm_display_mode *), GFP_KERNEL);
1514 enabled = kcalloc(dev->mode_config.num_connector,
1515 sizeof(bool), GFP_KERNEL);
1516 if (!crtcs || !modes || !enabled) {
1517 DRM_ERROR("Memory allocation failed\n");
1522 drm_enable_connectors(fb_helper, enabled);
1524 if (!(fb_helper->funcs->initial_config &&
1525 fb_helper->funcs->initial_config(fb_helper, crtcs, modes,
1526 enabled, width, height))) {
1527 memset(modes, 0, dev->mode_config.num_connector*sizeof(modes[0]));
1528 memset(crtcs, 0, dev->mode_config.num_connector*sizeof(crtcs[0]));
1530 if (!drm_target_cloned(fb_helper,
1531 modes, enabled, width, height) &&
1532 !drm_target_preferred(fb_helper,
1533 modes, enabled, width, height))
1534 DRM_ERROR("Unable to find initial modes\n");
1536 DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n",
1539 drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height);
1542 /* need to set the modesets up here for use later */
1543 /* fill out the connector<->crtc mappings into the modesets */
1544 for (i = 0; i < fb_helper->crtc_count; i++) {
1545 modeset = &fb_helper->crtc_info[i].mode_set;
1546 modeset->num_connectors = 0;
1550 for (i = 0; i < fb_helper->connector_count; i++) {
1551 struct drm_display_mode *mode = modes[i];
1552 struct drm_fb_helper_crtc *fb_crtc = crtcs[i];
1553 modeset = &fb_crtc->mode_set;
1555 if (mode && fb_crtc) {
1556 DRM_DEBUG_KMS("desired mode %s set on crtc %d\n",
1557 mode->name, fb_crtc->mode_set.crtc->base.id);
1558 fb_crtc->desired_mode = mode;
1560 drm_mode_destroy(dev, modeset->mode);
1561 modeset->mode = drm_mode_duplicate(dev,
1562 fb_crtc->desired_mode);
1563 modeset->connectors[modeset->num_connectors++] = fb_helper->connector_info[i]->connector;
1564 modeset->fb = fb_helper->fb;
1568 /* Clear out any old modes if there are no more connected outputs. */
1569 for (i = 0; i < fb_helper->crtc_count; i++) {
1570 modeset = &fb_helper->crtc_info[i].mode_set;
1571 if (modeset->num_connectors == 0) {
1572 BUG_ON(modeset->fb);
1573 BUG_ON(modeset->num_connectors);
1575 drm_mode_destroy(dev, modeset->mode);
1576 modeset->mode = NULL;
1586 * drm_fb_helper_initial_config - setup a sane initial connector configuration
1587 * @fb_helper: fb_helper device struct
1588 * @bpp_sel: bpp value to use for the framebuffer configuration
1590 * Scans the CRTCs and connectors and tries to put together an initial setup.
1591 * At the moment, this is a cloned configuration across all heads with
1592 * a new framebuffer object as the backing store.
1594 * Note that this also registers the fbdev and so allows userspace to call into
1595 * the driver through the fbdev interfaces.
1597 * This function will call down into the ->fb_probe callback to let
1598 * the driver allocate and initialize the fbdev info structure and the drm
1599 * framebuffer used to back the fbdev. drm_fb_helper_fill_var() and
1600 * drm_fb_helper_fill_fix() are provided as helpers to setup simple default
1601 * values for the fbdev info structure.
1604 * Zero if everything went ok, nonzero otherwise.
1606 bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel)
1608 struct drm_device *dev = fb_helper->dev;
1611 mutex_lock(&dev->mode_config.mutex);
1612 count = drm_fb_helper_probe_connector_modes(fb_helper,
1613 dev->mode_config.max_width,
1614 dev->mode_config.max_height);
1615 mutex_unlock(&dev->mode_config.mutex);
1617 * we shouldn't end up with no modes here.
1620 dev_info(fb_helper->dev->dev, "No connectors reported connected with modes\n");
1622 drm_setup_crtcs(fb_helper);
1624 return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel);
1626 EXPORT_SYMBOL(drm_fb_helper_initial_config);
1629 * drm_fb_helper_hotplug_event - respond to a hotplug notification by
1630 * probing all the outputs attached to the fb
1631 * @fb_helper: the drm_fb_helper
1633 * Scan the connectors attached to the fb_helper and try to put together a
1634 * setup after *notification of a change in output configuration.
1636 * Called at runtime, takes the mode config locks to be able to check/change the
1637 * modeset configuration. Must be run from process context (which usually means
1638 * either the output polling work or a work item launched from the driver's
1639 * hotplug interrupt).
1641 * Note that drivers may call this even before calling
1642 * drm_fb_helper_initial_config but only aftert drm_fb_helper_init. This allows
1643 * for a race-free fbcon setup and will make sure that the fbdev emulation will
1644 * not miss any hotplug events.
1647 * 0 on success and a non-zero error code otherwise.
1649 int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
1651 struct drm_device *dev = fb_helper->dev;
1652 u32 max_width, max_height;
1654 mutex_lock(&fb_helper->dev->mode_config.mutex);
1655 if (!fb_helper->fb || !drm_fb_helper_is_bound(fb_helper)) {
1656 fb_helper->delayed_hotplug = true;
1657 mutex_unlock(&fb_helper->dev->mode_config.mutex);
1660 DRM_DEBUG_KMS("\n");
1662 max_width = fb_helper->fb->width;
1663 max_height = fb_helper->fb->height;
1665 drm_fb_helper_probe_connector_modes(fb_helper, max_width, max_height);
1666 mutex_unlock(&fb_helper->dev->mode_config.mutex);
1668 drm_modeset_lock_all(dev);
1669 drm_setup_crtcs(fb_helper);
1670 drm_modeset_unlock_all(dev);
1671 drm_fb_helper_set_par(fb_helper->fbdev);
1675 EXPORT_SYMBOL(drm_fb_helper_hotplug_event);
1677 /* The Kconfig DRM_KMS_HELPER selects FRAMEBUFFER_CONSOLE (if !EXPERT)
1678 * but the module doesn't depend on any fb console symbols. At least
1679 * attempt to load fbcon to avoid leaving the system without a usable console.
1681 #if defined(CONFIG_FRAMEBUFFER_CONSOLE_MODULE) && !defined(CONFIG_EXPERT)
1682 static int __init drm_fb_helper_modinit(void)
1684 const char *name = "fbcon";
1685 struct module *fbcon;
1687 mutex_lock(&module_mutex);
1688 fbcon = find_module(name);
1689 mutex_unlock(&module_mutex);
1692 request_module_nowait(name);
1696 module_init(drm_fb_helper_modinit);