2 * Copyright (c) 2006-2009 Red Hat Inc.
3 * Copyright (c) 2006-2008 Intel Corporation
4 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
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
27 * Dave Airlie <airlied@linux.ie>
28 * Jesse Barnes <jesse.barnes@intel.com>
31 #include <linux/kernel.h>
33 #include <linux/module.h>
35 #include <drm/drm_crtc.h>
36 #include <drm/drm_fb_helper.h>
37 #include <drm/drm_crtc_helper.h>
39 static LINUX_LIST_HEAD(kernel_fb_helper_list);
44 * The fb helper functions are useful to provide an fbdev on top of a drm kernel
45 * mode setting driver. They can be used mostly independently from the crtc
46 * helper functions used by many drivers to implement the kernel mode setting
49 * Initialization is done as a four-step process with drm_fb_helper_prepare(),
50 * drm_fb_helper_init(), drm_fb_helper_single_add_all_connectors() and
51 * drm_fb_helper_initial_config(). Drivers with fancier requirements than the
52 * default behaviour can override the third step with their own code.
53 * Teardown is done with drm_fb_helper_fini().
55 * At runtime drivers should restore the fbdev console by calling
56 * drm_fb_helper_restore_fbdev_mode() from their ->lastclose callback. They
57 * should also notify the fb helper code from updates to the output
58 * configuration by calling drm_fb_helper_hotplug_event(). For easier
59 * integration with the output polling code in drm_crtc_helper.c the modeset
60 * code provides a ->output_poll_changed callback.
62 * All other functions exported by the fb helper library can be used to
63 * implement the fbdev driver interface by the driver.
65 * It is possible, though perhaps somewhat tricky, to implement race-free
66 * hotplug detection using the fbdev helpers. The drm_fb_helper_prepare()
67 * helper must be called first to initialize the minimum required to make
68 * hotplug detection work. Drivers also need to make sure to properly set up
69 * the dev->mode_config.funcs member. After calling drm_kms_helper_poll_init()
70 * it is safe to enable interrupts and start processing hotplug events. At the
71 * same time, drivers should initialize all modeset objects such as CRTCs,
72 * encoders and connectors. To finish up the fbdev helper initialization, the
73 * drm_fb_helper_init() function is called. To probe for all attached displays
74 * and set up an initial configuration using the detected hardware, drivers
75 * should call drm_fb_helper_single_add_all_connectors() followed by
76 * drm_fb_helper_initial_config().
80 * drm_fb_helper_single_add_all_connectors() - add all connectors to fbdev
82 * @fb_helper: fbdev initialized with drm_fb_helper_init
84 * This functions adds all the available connectors for use with the given
85 * fb_helper. This is a separate step to allow drivers to freely assign
86 * connectors to the fbdev, e.g. if some are reserved for special purposes or
87 * not adequate to be used for the fbcon.
89 * Since this is part of the initial setup before the fbdev is published, no
90 * locking is required.
92 int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
94 struct drm_device *dev = fb_helper->dev;
95 struct drm_connector *connector;
98 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
99 struct drm_fb_helper_connector *fb_helper_connector;
101 fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL);
102 if (!fb_helper_connector)
105 fb_helper_connector->connector = connector;
106 fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector;
110 for (i = 0; i < fb_helper->connector_count; i++) {
111 kfree(fb_helper->connector_info[i]);
112 fb_helper->connector_info[i] = NULL;
114 fb_helper->connector_count = 0;
117 EXPORT_SYMBOL(drm_fb_helper_single_add_all_connectors);
119 static int drm_fb_helper_parse_command_line(struct drm_fb_helper *fb_helper)
121 struct drm_fb_helper_connector *fb_helper_conn;
124 for (i = 0; i < fb_helper->connector_count; i++) {
125 struct drm_cmdline_mode *mode;
126 struct drm_connector *connector;
129 fb_helper_conn = fb_helper->connector_info[i];
130 connector = fb_helper_conn->connector;
131 mode = &fb_helper_conn->cmdline_mode;
133 /* do something on return - turn off connector maybe */
134 if (fb_get_options(connector->name, &option))
137 if (drm_mode_parse_command_line_for_connector(option,
142 switch (mode->force) {
146 case DRM_FORCE_ON_DIGITAL:
155 DRM_INFO("forcing %s connector %s\n",
157 connector->force = mode->force;
160 DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
162 mode->xres, mode->yres,
163 mode->refresh_specified ? mode->refresh : 60,
164 mode->rb ? " reduced blanking" : "",
165 mode->margins ? " with margins" : "",
166 mode->interlace ? " interlaced" : "");
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 if (list_empty(&kernel_fb_helper_list))
217 list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) {
218 for (i = 0; i < helper->crtc_count; i++) {
219 struct drm_mode_set *mode_set =
220 &helper->crtc_info[i].mode_set;
222 if (!mode_set->crtc->enabled)
225 funcs = mode_set->crtc->helper_private;
226 drm_fb_helper_save_lut_atomic(mode_set->crtc, helper);
227 funcs->mode_set_base_atomic(mode_set->crtc,
231 ENTER_ATOMIC_MODE_SET);
237 EXPORT_SYMBOL(drm_fb_helper_debug_enter);
239 /* Find the real fb for a given fb helper CRTC */
240 static struct drm_framebuffer *drm_mode_config_fb(struct drm_crtc *crtc)
242 struct drm_device *dev = crtc->dev;
245 list_for_each_entry(c, &dev->mode_config.crtc_list, head) {
246 if (crtc->base.id == c->base.id)
247 return c->primary->fb;
254 * drm_fb_helper_debug_leave - implementation for ->fb_debug_leave
255 * @info: fbdev registered by the helper
257 int drm_fb_helper_debug_leave(struct fb_info *info)
259 struct drm_fb_helper *helper = info->par;
260 struct drm_crtc *crtc;
261 struct drm_crtc_helper_funcs *funcs;
262 struct drm_framebuffer *fb;
265 for (i = 0; i < helper->crtc_count; i++) {
266 struct drm_mode_set *mode_set = &helper->crtc_info[i].mode_set;
267 crtc = mode_set->crtc;
268 funcs = crtc->helper_private;
269 fb = drm_mode_config_fb(crtc);
275 DRM_ERROR("no fb to restore??\n");
279 drm_fb_helper_restore_lut_atomic(mode_set->crtc);
280 funcs->mode_set_base_atomic(mode_set->crtc, fb, crtc->x,
281 crtc->y, LEAVE_ATOMIC_MODE_SET);
286 EXPORT_SYMBOL(drm_fb_helper_debug_leave);
289 static bool restore_fbdev_mode(struct drm_fb_helper *fb_helper)
291 struct drm_device *dev = fb_helper->dev;
292 struct drm_plane *plane;
296 drm_warn_on_modeset_not_all_locked(dev);
298 list_for_each_entry(plane, &dev->mode_config.plane_list, head)
299 if (plane->type != DRM_PLANE_TYPE_PRIMARY)
300 drm_plane_force_disable(plane);
302 for (i = 0; i < fb_helper->crtc_count; i++) {
303 struct drm_mode_set *mode_set = &fb_helper->crtc_info[i].mode_set;
304 struct drm_crtc *crtc = mode_set->crtc;
307 if (crtc->funcs->cursor_set) {
308 ret = crtc->funcs->cursor_set(crtc, NULL, 0, 0, 0);
313 ret = drm_mode_set_config_internal(mode_set);
320 * drm_fb_helper_restore_fbdev_mode - restore fbdev configuration
321 * @fb_helper: fbcon to restore
323 * This should be called from driver's drm ->lastclose callback
324 * when implementing an fbcon on top of kms using this helper. This ensures that
325 * the user isn't greeted with a black screen when e.g. X dies.
327 * Use this variant if you need to bypass locking (panic), or already
328 * hold all modeset locks. Otherwise use drm_fb_helper_restore_fbdev_mode_unlocked()
330 static bool drm_fb_helper_restore_fbdev_mode(struct drm_fb_helper *fb_helper)
332 return restore_fbdev_mode(fb_helper);
336 * drm_fb_helper_restore_fbdev_mode_unlocked - restore fbdev configuration
337 * @fb_helper: fbcon to restore
339 * This should be called from driver's drm ->lastclose callback
340 * when implementing an fbcon on top of kms using this helper. This ensures that
341 * the user isn't greeted with a black screen when e.g. X dies.
343 bool drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper)
345 struct drm_device *dev = fb_helper->dev;
347 drm_modeset_lock_all(dev);
348 ret = restore_fbdev_mode(fb_helper);
349 drm_modeset_unlock_all(dev);
352 EXPORT_SYMBOL(drm_fb_helper_restore_fbdev_mode_unlocked);
356 * restore fbcon display for all kms driver's using this helper, used for sysrq
357 * and panic handling.
359 static bool drm_fb_helper_force_kernel_mode(void)
361 bool ret, error = false;
362 struct drm_fb_helper *helper;
364 if (list_empty(&kernel_fb_helper_list))
367 list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) {
368 struct drm_device *dev = helper->dev;
370 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
373 /* NOTE: we use lockless flag below to avoid grabbing other
374 * modeset locks. So just trylock the underlying mutex
377 if (!mutex_trylock(&dev->mode_config.mutex)) {
382 ret = drm_fb_helper_restore_fbdev_mode(helper);
386 mutex_unlock(&dev->mode_config.mutex);
391 static int drm_fb_helper_panic(struct notifier_block *n, unsigned long ununsed,
395 * It's a waste of time and effort to switch back to text console
396 * if the kernel should reboot before panic messages can be seen.
398 if (panic_timeout < 0)
401 pr_err("panic occurred, switching back to text console\n");
402 return drm_fb_helper_force_kernel_mode();
405 static struct notifier_block paniced = {
406 .notifier_call = drm_fb_helper_panic,
410 static bool drm_fb_helper_is_bound(struct drm_fb_helper *fb_helper)
412 struct drm_device *dev = fb_helper->dev;
413 struct drm_crtc *crtc;
414 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)
423 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
424 if (crtc->primary->fb)
426 if (crtc->primary->fb == fb_helper->fb)
430 if (bound < crtcs_bound)
437 #ifdef CONFIG_MAGIC_SYSRQ
438 static void drm_fb_helper_restore_work_fn(struct work_struct *ignored)
441 ret = drm_fb_helper_force_kernel_mode();
443 DRM_ERROR("Failed to restore crtc configuration\n");
445 static DECLARE_WORK(drm_fb_helper_restore_work, drm_fb_helper_restore_work_fn);
447 static void drm_fb_helper_sysrq(int dummy1)
449 schedule_work(&drm_fb_helper_restore_work);
452 static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = {
453 .handler = drm_fb_helper_sysrq,
454 .help_msg = "force-fb(V)",
455 .action_msg = "Restore framebuffer console",
458 static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { };
461 static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode)
463 struct drm_fb_helper *fb_helper = info->par;
464 struct drm_device *dev = fb_helper->dev;
465 struct drm_crtc *crtc;
466 struct drm_connector *connector;
470 * fbdev->blank can be called from irq context in case of a panic.
471 * Since we already have our own special panic handler which will
472 * restore the fbdev console mode completely, just bail out early.
474 if (oops_in_progress)
478 * For each CRTC in this fb, turn the connectors on/off.
480 drm_modeset_lock_all(dev);
481 if (!drm_fb_helper_is_bound(fb_helper)) {
482 drm_modeset_unlock_all(dev);
486 for (i = 0; i < fb_helper->crtc_count; i++) {
487 crtc = fb_helper->crtc_info[i].mode_set.crtc;
492 /* Walk the connectors & encoders on this fb turning them on/off */
493 for (j = 0; j < fb_helper->connector_count; j++) {
494 connector = fb_helper->connector_info[j]->connector;
495 connector->funcs->dpms(connector, dpms_mode);
496 drm_object_property_set_value(&connector->base,
497 dev->mode_config.dpms_property, dpms_mode);
500 drm_modeset_unlock_all(dev);
504 * drm_fb_helper_blank - implementation for ->fb_blank
505 * @blank: desired blanking state
506 * @info: fbdev registered by the helper
508 int drm_fb_helper_blank(int blank, struct fb_info *info)
511 /* Display: On; HSync: On, VSync: On */
512 case FB_BLANK_UNBLANK:
513 drm_fb_helper_dpms(info, DRM_MODE_DPMS_ON);
515 /* Display: Off; HSync: On, VSync: On */
516 case FB_BLANK_NORMAL:
517 drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY);
519 /* Display: Off; HSync: Off, VSync: On */
520 case FB_BLANK_HSYNC_SUSPEND:
521 drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY);
523 /* Display: Off; HSync: On, VSync: Off */
524 case FB_BLANK_VSYNC_SUSPEND:
525 drm_fb_helper_dpms(info, DRM_MODE_DPMS_SUSPEND);
527 /* Display: Off; HSync: Off, VSync: Off */
528 case FB_BLANK_POWERDOWN:
529 drm_fb_helper_dpms(info, DRM_MODE_DPMS_OFF);
534 EXPORT_SYMBOL(drm_fb_helper_blank);
537 static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper)
541 for (i = 0; i < helper->connector_count; i++)
542 kfree(helper->connector_info[i]);
543 kfree(helper->connector_info);
544 for (i = 0; i < helper->crtc_count; i++) {
545 kfree(helper->crtc_info[i].mode_set.connectors);
546 if (helper->crtc_info[i].mode_set.mode)
547 drm_mode_destroy(helper->dev, helper->crtc_info[i].mode_set.mode);
549 kfree(helper->crtc_info);
553 * drm_fb_helper_prepare - setup a drm_fb_helper structure
555 * @helper: driver-allocated fbdev helper structure to set up
556 * @funcs: pointer to structure of functions associate with this helper
558 * Sets up the bare minimum to make the framebuffer helper usable. This is
559 * useful to implement race-free initialization of the polling helpers.
561 void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,
562 const struct drm_fb_helper_funcs *funcs)
564 INIT_LIST_HEAD(&helper->kernel_fb_list);
565 helper->funcs = funcs;
568 EXPORT_SYMBOL(drm_fb_helper_prepare);
571 * drm_fb_helper_init - initialize a drm_fb_helper structure
573 * @fb_helper: driver-allocated fbdev helper structure to initialize
574 * @crtc_count: maximum number of crtcs to support in this fbdev emulation
575 * @max_conn_count: max connector count
577 * This allocates the structures for the fbdev helper with the given limits.
578 * Note that this won't yet touch the hardware (through the driver interfaces)
579 * nor register the fbdev. This is only done in drm_fb_helper_initial_config()
580 * to allow driver writes more control over the exact init sequence.
582 * Drivers must call drm_fb_helper_prepare() before calling this function.
585 * Zero if everything went ok, nonzero otherwise.
587 int drm_fb_helper_init(struct drm_device *dev,
588 struct drm_fb_helper *fb_helper,
589 int crtc_count, int max_conn_count)
591 struct drm_crtc *crtc;
597 fb_helper->crtc_info = kcalloc(crtc_count, sizeof(struct drm_fb_helper_crtc), GFP_KERNEL);
598 if (!fb_helper->crtc_info)
601 fb_helper->crtc_count = crtc_count;
602 fb_helper->connector_info = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_fb_helper_connector *), GFP_KERNEL);
603 if (!fb_helper->connector_info) {
604 kfree(fb_helper->crtc_info);
607 fb_helper->connector_count = 0;
609 for (i = 0; i < crtc_count; i++) {
610 fb_helper->crtc_info[i].mode_set.connectors =
611 kcalloc(max_conn_count,
612 sizeof(struct drm_connector *),
615 if (!fb_helper->crtc_info[i].mode_set.connectors)
617 fb_helper->crtc_info[i].mode_set.num_connectors = 0;
621 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
622 fb_helper->crtc_info[i].mode_set.crtc = crtc;
628 drm_fb_helper_crtc_free(fb_helper);
631 EXPORT_SYMBOL(drm_fb_helper_init);
633 void drm_fb_helper_fini(struct drm_fb_helper *fb_helper)
635 if (!list_empty(&fb_helper->kernel_fb_list)) {
636 list_del(&fb_helper->kernel_fb_list);
637 if (list_empty(&kernel_fb_helper_list)) {
639 pr_info("drm: unregistered panic notifier\n");
640 atomic_notifier_chain_unregister(&panic_notifier_list,
642 unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
647 drm_fb_helper_crtc_free(fb_helper);
650 EXPORT_SYMBOL(drm_fb_helper_fini);
653 static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green,
654 u16 blue, u16 regno, struct fb_info *info)
656 struct drm_fb_helper *fb_helper = info->par;
657 struct drm_framebuffer *fb = fb_helper->fb;
660 if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
663 /* place color in psuedopalette */
666 palette = (u32 *)info->pseudo_palette;
667 red >>= (16 - info->var.red.length);
668 green >>= (16 - info->var.green.length);
669 blue >>= (16 - info->var.blue.length);
670 value = (red << info->var.red.offset) |
671 (green << info->var.green.offset) |
672 (blue << info->var.blue.offset);
673 if (info->var.transp.length > 0) {
674 u32 mask = (1 << info->var.transp.length) - 1;
675 mask <<= info->var.transp.offset;
678 palette[regno] = value;
683 * The driver really shouldn't advertise pseudo/directcolor
684 * visuals if it can't deal with the palette.
686 if (WARN_ON(!fb_helper->funcs->gamma_set ||
687 !fb_helper->funcs->gamma_get))
692 if (fb->bits_per_pixel == 16) {
695 if (fb->depth == 16 && regno > 63)
697 if (fb->depth == 15 && regno > 31)
700 if (fb->depth == 16) {
704 for (i = 0; i < 8; i++)
705 fb_helper->funcs->gamma_set(crtc, red,
706 green, blue, pindex + i);
709 fb_helper->funcs->gamma_get(crtc, &r,
713 for (i = 0; i < 4; i++)
714 fb_helper->funcs->gamma_set(crtc, r,
721 fb_helper->funcs->gamma_set(crtc, red, green, blue, pindex);
726 * drm_fb_helper_setcmap - implementation for ->fb_setcmap
728 * @info: fbdev registered by the helper
730 int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
732 struct drm_fb_helper *fb_helper = info->par;
733 struct drm_device *dev = fb_helper->dev;
734 struct drm_crtc_helper_funcs *crtc_funcs;
735 u16 *red, *green, *blue, *transp;
736 struct drm_crtc *crtc;
740 drm_modeset_lock_all(dev);
741 if (!drm_fb_helper_is_bound(fb_helper)) {
742 drm_modeset_unlock_all(dev);
746 for (i = 0; i < fb_helper->crtc_count; i++) {
747 crtc = fb_helper->crtc_info[i].mode_set.crtc;
748 crtc_funcs = crtc->helper_private;
753 transp = cmap->transp;
756 for (j = 0; j < cmap->len; j++) {
757 u16 hred, hgreen, hblue, htransp = 0xffff;
766 rc = setcolreg(crtc, hred, hgreen, hblue, start++, info);
770 if (crtc_funcs->load_lut)
771 crtc_funcs->load_lut(crtc);
774 drm_modeset_unlock_all(dev);
777 EXPORT_SYMBOL(drm_fb_helper_setcmap);
780 * drm_fb_helper_check_var - implementation for ->fb_check_var
781 * @var: screeninfo to check
782 * @info: fbdev registered by the helper
784 int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
785 struct fb_info *info)
787 struct drm_fb_helper *fb_helper = info->par;
788 struct drm_framebuffer *fb = fb_helper->fb;
791 if (var->pixclock != 0 || in_dbg_master())
794 /* Need to resize the fb object !!! */
795 if (var->bits_per_pixel > fb->bits_per_pixel ||
796 var->xres > fb->width || var->yres > fb->height ||
797 var->xres_virtual > fb->width || var->yres_virtual > fb->height) {
798 DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb "
799 "request %dx%d-%d (virtual %dx%d) > %dx%d-%d\n",
800 var->xres, var->yres, var->bits_per_pixel,
801 var->xres_virtual, var->yres_virtual,
802 fb->width, fb->height, fb->bits_per_pixel);
806 switch (var->bits_per_pixel) {
808 depth = (var->green.length == 6) ? 16 : 15;
811 depth = (var->transp.length > 0) ? 32 : 24;
814 depth = var->bits_per_pixel;
821 var->green.offset = 0;
822 var->blue.offset = 0;
824 var->green.length = 8;
825 var->blue.length = 8;
826 var->transp.length = 0;
827 var->transp.offset = 0;
830 var->red.offset = 10;
831 var->green.offset = 5;
832 var->blue.offset = 0;
834 var->green.length = 5;
835 var->blue.length = 5;
836 var->transp.length = 1;
837 var->transp.offset = 15;
840 var->red.offset = 11;
841 var->green.offset = 5;
842 var->blue.offset = 0;
844 var->green.length = 6;
845 var->blue.length = 5;
846 var->transp.length = 0;
847 var->transp.offset = 0;
850 var->red.offset = 16;
851 var->green.offset = 8;
852 var->blue.offset = 0;
854 var->green.length = 8;
855 var->blue.length = 8;
856 var->transp.length = 0;
857 var->transp.offset = 0;
860 var->red.offset = 16;
861 var->green.offset = 8;
862 var->blue.offset = 0;
864 var->green.length = 8;
865 var->blue.length = 8;
866 var->transp.length = 8;
867 var->transp.offset = 24;
874 EXPORT_SYMBOL(drm_fb_helper_check_var);
877 * drm_fb_helper_set_par - implementation for ->fb_set_par
878 * @info: fbdev registered by the helper
880 * This will let fbcon do the mode init and is called at initialization time by
881 * the fbdev core when registering the driver, and later on through the hotplug
884 int drm_fb_helper_set_par(struct fb_info *info)
886 struct drm_fb_helper *fb_helper = info->par;
887 struct fb_var_screeninfo *var = &info->var;
889 if (var->pixclock != 0) {
890 DRM_ERROR("PIXEL CLOCK SET\n");
894 drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper);
896 if (fb_helper->delayed_hotplug) {
897 fb_helper->delayed_hotplug = false;
898 drm_fb_helper_hotplug_event(fb_helper);
902 EXPORT_SYMBOL(drm_fb_helper_set_par);
905 * drm_fb_helper_pan_display - implementation for ->fb_pan_display
906 * @var: updated screen information
907 * @info: fbdev registered by the helper
909 int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
910 struct fb_info *info)
912 struct drm_fb_helper *fb_helper = info->par;
913 struct drm_device *dev = fb_helper->dev;
914 struct drm_mode_set *modeset;
918 drm_modeset_lock_all(dev);
919 if (!drm_fb_helper_is_bound(fb_helper)) {
920 drm_modeset_unlock_all(dev);
924 for (i = 0; i < fb_helper->crtc_count; i++) {
925 modeset = &fb_helper->crtc_info[i].mode_set;
927 modeset->x = var->xoffset;
928 modeset->y = var->yoffset;
930 if (modeset->num_connectors) {
931 ret = drm_mode_set_config_internal(modeset);
933 info->var.xoffset = var->xoffset;
934 info->var.yoffset = var->yoffset;
938 drm_modeset_unlock_all(dev);
941 EXPORT_SYMBOL(drm_fb_helper_pan_display);
944 /* XXX: DragonFly-specific */
946 do_restore_fbdev_mode(void *context, int pending)
948 struct drm_fb_helper *fb_helper = context;
949 struct drm_device *dev = fb_helper->dev;
954 drm_modeset_lock_all(dev);
955 drm_fb_helper_restore_fbdev_mode(fb_helper);
956 drm_modeset_unlock_all(dev);
959 /* XXX: DragonFly-specific */
961 sc_restore_fbdev_mode(void *cookie)
963 struct drm_fb_helper *fb_helper = cookie;
968 taskqueue_enqueue(taskqueue_thread[0], &fb_helper->fb_mode_task);
972 * Allocates the backing storage and sets up the fbdev info structure through
973 * the ->fb_probe callback and then registers the fbdev and sets up the panic
976 static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,
982 struct fb_info *info;
983 struct drm_fb_helper_surface_size sizes;
985 int kms_console = 1; /* XXX: DragonFly-specific */
987 memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size));
988 sizes.surface_depth = 24;
989 sizes.surface_bpp = 32;
990 sizes.fb_width = (unsigned)-1;
991 sizes.fb_height = (unsigned)-1;
993 /* if driver picks 8 or 16 by default use that
994 for both depth/bpp */
995 if (preferred_bpp != sizes.surface_bpp)
996 sizes.surface_depth = sizes.surface_bpp = preferred_bpp;
998 /* first up get a count of crtcs now in use and new min/maxes width/heights */
999 for (i = 0; i < fb_helper->connector_count; i++) {
1000 struct drm_fb_helper_connector *fb_helper_conn = fb_helper->connector_info[i];
1001 struct drm_cmdline_mode *cmdline_mode;
1003 cmdline_mode = &fb_helper_conn->cmdline_mode;
1005 if (cmdline_mode->bpp_specified) {
1006 switch (cmdline_mode->bpp) {
1008 sizes.surface_depth = sizes.surface_bpp = 8;
1011 sizes.surface_depth = 15;
1012 sizes.surface_bpp = 16;
1015 sizes.surface_depth = sizes.surface_bpp = 16;
1018 sizes.surface_depth = sizes.surface_bpp = 24;
1021 sizes.surface_depth = 24;
1022 sizes.surface_bpp = 32;
1030 for (i = 0; i < fb_helper->crtc_count; i++) {
1031 struct drm_display_mode *desired_mode;
1032 desired_mode = fb_helper->crtc_info[i].desired_mode;
1035 if (gamma_size == 0)
1036 gamma_size = fb_helper->crtc_info[i].mode_set.crtc->gamma_size;
1037 if (desired_mode->hdisplay < sizes.fb_width)
1038 sizes.fb_width = desired_mode->hdisplay;
1039 if (desired_mode->vdisplay < sizes.fb_height)
1040 sizes.fb_height = desired_mode->vdisplay;
1041 if (desired_mode->hdisplay > sizes.surface_width)
1042 sizes.surface_width = desired_mode->hdisplay;
1043 if (desired_mode->vdisplay > sizes.surface_height)
1044 sizes.surface_height = desired_mode->vdisplay;
1049 if (crtc_count == 0 || sizes.fb_width == -1 || sizes.fb_height == -1) {
1050 /* hmm everyone went away - assume VGA cable just fell out
1051 and will come back later. */
1052 DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n");
1053 sizes.fb_width = sizes.surface_width = 1024;
1054 sizes.fb_height = sizes.surface_height = 768;
1057 /* push down into drivers */
1058 ret = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes);
1062 info = fb_helper->fbdev;
1065 * Set the fb pointer - usually drm_setup_crtcs does this for hotplug
1066 * events, but at init time drm_setup_crtcs needs to be called before
1067 * the fb is allocated (since we need to figure out the desired size of
1068 * the fb before we can allocate it ...). Hence we need to fix things up
1071 for (i = 0; i < fb_helper->crtc_count; i++)
1072 if (fb_helper->crtc_info[i].mode_set.num_connectors)
1073 fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb;
1076 /* XXX: DragonFly-specific */
1077 TUNABLE_INT_FETCH("kern.kms_console", &kms_console);
1079 TASK_INIT(&fb_helper->fb_mode_task, 0, do_restore_fbdev_mode,
1081 info->cookie = fb_helper;
1082 info->restore = (void *)&sc_restore_fbdev_mode;
1083 if (register_framebuffer(info) < 0)
1088 info->var.pixclock = 0;
1089 if (register_framebuffer(info) < 0)
1092 dev_info(fb_helper->dev->dev, "fb%d: %s frame buffer device\n",
1093 info->node, info->fix.id);
1095 /* Switch back to kernel console on panic */
1096 /* multi card linked list maybe */
1097 if (list_empty(&kernel_fb_helper_list)) {
1098 dev_info(fb_helper->dev->dev, "registered panic notifier\n");
1099 atomic_notifier_chain_register(&panic_notifier_list,
1101 register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op);
1104 list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list);
1112 * drm_fb_helper_fill_fix - initializes fixed fbdev information
1113 * @info: fbdev registered by the helper
1114 * @pitch: desired pitch
1115 * @depth: desired depth
1117 * Helper to fill in the fixed fbdev information useful for a non-accelerated
1118 * fbdev emulations. Drivers which support acceleration methods which impose
1119 * additional constraints need to set up their own limits.
1121 * Drivers should call this (or their equivalent setup code) from their
1122 * ->fb_probe callback.
1124 void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
1127 info->fix.type = FB_TYPE_PACKED_PIXELS;
1128 info->fix.visual = depth == 8 ? FB_VISUAL_PSEUDOCOLOR :
1129 FB_VISUAL_TRUECOLOR;
1130 info->fix.mmio_start = 0;
1131 info->fix.mmio_len = 0;
1132 info->fix.type_aux = 0;
1133 info->fix.xpanstep = 1; /* doing it in hw */
1134 info->fix.ypanstep = 1; /* doing it in hw */
1135 info->fix.ywrapstep = 0;
1136 info->fix.accel = FB_ACCEL_NONE;
1137 info->fix.type_aux = 0;
1139 info->fix.line_length = pitch;
1142 EXPORT_SYMBOL(drm_fb_helper_fill_fix);
1145 * drm_fb_helper_fill_var - initalizes variable fbdev information
1146 * @info: fbdev instance to set up
1147 * @fb_helper: fb helper instance to use as template
1148 * @fb_width: desired fb width
1149 * @fb_height: desired fb height
1151 * Sets up the variable fbdev metainformation from the given fb helper instance
1152 * and the drm framebuffer allocated in fb_helper->fb.
1154 * Drivers should call this (or their equivalent setup code) from their
1155 * ->fb_probe callback after having allocated the fbdev backing
1156 * storage framebuffer.
1158 void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helper,
1159 uint32_t fb_width, uint32_t fb_height)
1161 struct drm_framebuffer *fb = fb_helper->fb;
1162 info->pseudo_palette = fb_helper->pseudo_palette;
1163 info->var.xres_virtual = fb->width;
1164 info->var.yres_virtual = fb->height;
1165 info->var.bits_per_pixel = fb->bits_per_pixel;
1166 info->var.accel_flags = FB_ACCELF_TEXT;
1167 info->var.xoffset = 0;
1168 info->var.yoffset = 0;
1169 info->var.activate = FB_ACTIVATE_NOW;
1170 info->var.height = -1;
1171 info->var.width = -1;
1173 switch (fb->depth) {
1175 info->var.red.offset = 0;
1176 info->var.green.offset = 0;
1177 info->var.blue.offset = 0;
1178 info->var.red.length = 8; /* 8bit DAC */
1179 info->var.green.length = 8;
1180 info->var.blue.length = 8;
1181 info->var.transp.offset = 0;
1182 info->var.transp.length = 0;
1185 info->var.red.offset = 10;
1186 info->var.green.offset = 5;
1187 info->var.blue.offset = 0;
1188 info->var.red.length = 5;
1189 info->var.green.length = 5;
1190 info->var.blue.length = 5;
1191 info->var.transp.offset = 15;
1192 info->var.transp.length = 1;
1195 info->var.red.offset = 11;
1196 info->var.green.offset = 5;
1197 info->var.blue.offset = 0;
1198 info->var.red.length = 5;
1199 info->var.green.length = 6;
1200 info->var.blue.length = 5;
1201 info->var.transp.offset = 0;
1204 info->var.red.offset = 16;
1205 info->var.green.offset = 8;
1206 info->var.blue.offset = 0;
1207 info->var.red.length = 8;
1208 info->var.green.length = 8;
1209 info->var.blue.length = 8;
1210 info->var.transp.offset = 0;
1211 info->var.transp.length = 0;
1214 info->var.red.offset = 16;
1215 info->var.green.offset = 8;
1216 info->var.blue.offset = 0;
1217 info->var.red.length = 8;
1218 info->var.green.length = 8;
1219 info->var.blue.length = 8;
1220 info->var.transp.offset = 24;
1221 info->var.transp.length = 8;
1227 info->var.xres = fb_width;
1228 info->var.yres = fb_height;
1230 EXPORT_SYMBOL(drm_fb_helper_fill_var);
1233 static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper *fb_helper,
1237 struct drm_connector *connector;
1241 for (i = 0; i < fb_helper->connector_count; i++) {
1242 connector = fb_helper->connector_info[i]->connector;
1243 count += connector->funcs->fill_modes(connector, maxX, maxY);
1249 struct drm_display_mode *drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector, int width, int height)
1251 struct drm_display_mode *mode;
1253 list_for_each_entry(mode, &fb_connector->connector->modes, head) {
1254 if (mode->hdisplay > width ||
1255 mode->vdisplay > height)
1257 if (mode->type & DRM_MODE_TYPE_PREFERRED)
1262 EXPORT_SYMBOL(drm_has_preferred_mode);
1264 static bool drm_has_cmdline_mode(struct drm_fb_helper_connector *fb_connector)
1266 struct drm_cmdline_mode *cmdline_mode;
1267 cmdline_mode = &fb_connector->cmdline_mode;
1268 return cmdline_mode->specified;
1271 struct drm_display_mode *drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn,
1272 int width, int height)
1274 struct drm_cmdline_mode *cmdline_mode;
1275 struct drm_display_mode *mode = NULL;
1276 bool prefer_non_interlace;
1278 cmdline_mode = &fb_helper_conn->cmdline_mode;
1279 if (cmdline_mode->specified == false)
1282 /* attempt to find a matching mode in the list of modes
1283 * we have gotten so far, if not add a CVT mode that conforms
1285 if (cmdline_mode->rb || cmdline_mode->margins)
1288 prefer_non_interlace = !cmdline_mode->interlace;
1290 list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
1291 /* check width/height */
1292 if (mode->hdisplay != cmdline_mode->xres ||
1293 mode->vdisplay != cmdline_mode->yres)
1296 if (cmdline_mode->refresh_specified) {
1297 if (mode->vrefresh != cmdline_mode->refresh)
1301 if (cmdline_mode->interlace) {
1302 if (!(mode->flags & DRM_MODE_FLAG_INTERLACE))
1304 } else if (prefer_non_interlace) {
1305 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1311 if (prefer_non_interlace) {
1312 prefer_non_interlace = false;
1317 mode = drm_mode_create_from_cmdline_mode(fb_helper_conn->connector->dev,
1319 list_add(&mode->head, &fb_helper_conn->connector->modes);
1322 EXPORT_SYMBOL(drm_pick_cmdline_mode);
1324 static bool drm_connector_enabled(struct drm_connector *connector, bool strict)
1329 enable = connector->status == connector_status_connected;
1331 enable = connector->status != connector_status_disconnected;
1336 static void drm_enable_connectors(struct drm_fb_helper *fb_helper,
1339 bool any_enabled = false;
1340 struct drm_connector *connector;
1343 for (i = 0; i < fb_helper->connector_count; i++) {
1344 connector = fb_helper->connector_info[i]->connector;
1345 enabled[i] = drm_connector_enabled(connector, true);
1346 DRM_DEBUG_KMS("connector %d enabled? %s\n", connector->base.id,
1347 enabled[i] ? "yes" : "no");
1348 any_enabled |= enabled[i];
1354 for (i = 0; i < fb_helper->connector_count; i++) {
1355 connector = fb_helper->connector_info[i]->connector;
1356 enabled[i] = drm_connector_enabled(connector, false);
1360 static bool drm_target_cloned(struct drm_fb_helper *fb_helper,
1361 struct drm_display_mode **modes,
1362 bool *enabled, int width, int height)
1365 bool can_clone = false;
1366 struct drm_fb_helper_connector *fb_helper_conn;
1367 struct drm_display_mode *dmt_mode, *mode;
1369 /* only contemplate cloning in the single crtc case */
1370 if (fb_helper->crtc_count > 1)
1374 for (i = 0; i < fb_helper->connector_count; i++) {
1379 /* only contemplate cloning if more than one connector is enabled */
1383 /* check the command line or if nothing common pick 1024x768 */
1385 for (i = 0; i < fb_helper->connector_count; i++) {
1388 fb_helper_conn = fb_helper->connector_info[i];
1389 modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
1394 for (j = 0; j < i; j++) {
1397 if (!drm_mode_equal(modes[j], modes[i]))
1403 DRM_DEBUG_KMS("can clone using command line\n");
1407 /* try and find a 1024x768 mode on each connector */
1409 dmt_mode = drm_mode_find_dmt(fb_helper->dev, 1024, 768, 60, false);
1411 for (i = 0; i < fb_helper->connector_count; i++) {
1416 fb_helper_conn = fb_helper->connector_info[i];
1417 list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) {
1418 if (drm_mode_equal(mode, dmt_mode))
1426 DRM_DEBUG_KMS("can clone using 1024x768\n");
1429 DRM_INFO("kms: can't enable cloning when we probably wanted to.\n");
1433 static bool drm_target_preferred(struct drm_fb_helper *fb_helper,
1434 struct drm_display_mode **modes,
1435 bool *enabled, int width, int height)
1437 struct drm_fb_helper_connector *fb_helper_conn;
1440 for (i = 0; i < fb_helper->connector_count; i++) {
1441 fb_helper_conn = fb_helper->connector_info[i];
1443 if (enabled[i] == false)
1446 DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n",
1447 fb_helper_conn->connector->base.id);
1449 /* got for command line mode first */
1450 modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height);
1452 DRM_DEBUG_KMS("looking for preferred mode on connector %d\n",
1453 fb_helper_conn->connector->base.id);
1454 modes[i] = drm_has_preferred_mode(fb_helper_conn, width, height);
1456 /* No preferred modes, pick one off the list */
1457 if (!modes[i] && !list_empty(&fb_helper_conn->connector->modes)) {
1458 list_for_each_entry(modes[i], &fb_helper_conn->connector->modes, head)
1461 DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name :
1467 static int drm_pick_crtcs(struct drm_fb_helper *fb_helper,
1468 struct drm_fb_helper_crtc **best_crtcs,
1469 struct drm_display_mode **modes,
1470 int n, int width, int height)
1473 struct drm_device *dev = fb_helper->dev;
1474 struct drm_connector *connector;
1475 struct drm_connector_helper_funcs *connector_funcs;
1476 struct drm_encoder *encoder;
1477 int my_score, best_score, score;
1478 struct drm_fb_helper_crtc **crtcs, *crtc;
1479 struct drm_fb_helper_connector *fb_helper_conn;
1481 if (n == fb_helper->connector_count)
1484 fb_helper_conn = fb_helper->connector_info[n];
1485 connector = fb_helper_conn->connector;
1487 best_crtcs[n] = NULL;
1488 best_score = drm_pick_crtcs(fb_helper, best_crtcs, modes, n+1, width, height);
1489 if (modes[n] == NULL)
1492 crtcs = kzalloc(dev->mode_config.num_connector *
1493 sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
1498 if (connector->status == connector_status_connected)
1500 if (drm_has_cmdline_mode(fb_helper_conn))
1502 if (drm_has_preferred_mode(fb_helper_conn, width, height))
1505 connector_funcs = connector->helper_private;
1506 encoder = connector_funcs->best_encoder(connector);
1510 /* select a crtc for this connector and then attempt to configure
1511 remaining connectors */
1512 for (c = 0; c < fb_helper->crtc_count; c++) {
1513 crtc = &fb_helper->crtc_info[c];
1515 if ((encoder->possible_crtcs & (1 << c)) == 0)
1518 for (o = 0; o < n; o++)
1519 if (best_crtcs[o] == crtc)
1523 /* ignore cloning unless only a single crtc */
1524 if (fb_helper->crtc_count > 1)
1527 if (!drm_mode_equal(modes[o], modes[n]))
1532 memcpy(crtcs, best_crtcs, n * sizeof(struct drm_fb_helper_crtc *));
1533 score = my_score + drm_pick_crtcs(fb_helper, crtcs, modes, n + 1,
1535 if (score > best_score) {
1537 memcpy(best_crtcs, crtcs,
1538 dev->mode_config.num_connector *
1539 sizeof(struct drm_fb_helper_crtc *));
1547 static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
1549 struct drm_device *dev = fb_helper->dev;
1550 struct drm_fb_helper_crtc **crtcs;
1551 struct drm_display_mode **modes;
1552 struct drm_mode_set *modeset;
1557 DRM_DEBUG_KMS("\n");
1559 width = dev->mode_config.max_width;
1560 height = dev->mode_config.max_height;
1562 crtcs = kcalloc(dev->mode_config.num_connector,
1563 sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL);
1564 modes = kcalloc(dev->mode_config.num_connector,
1565 sizeof(struct drm_display_mode *), GFP_KERNEL);
1566 enabled = kcalloc(dev->mode_config.num_connector,
1567 sizeof(bool), GFP_KERNEL);
1568 if (!crtcs || !modes || !enabled) {
1569 DRM_ERROR("Memory allocation failed\n");
1574 drm_enable_connectors(fb_helper, enabled);
1576 if (!(fb_helper->funcs->initial_config &&
1577 fb_helper->funcs->initial_config(fb_helper, crtcs, modes,
1578 enabled, width, height))) {
1579 memset(modes, 0, dev->mode_config.num_connector*sizeof(modes[0]));
1580 memset(crtcs, 0, dev->mode_config.num_connector*sizeof(crtcs[0]));
1582 if (!drm_target_cloned(fb_helper,
1583 modes, enabled, width, height) &&
1584 !drm_target_preferred(fb_helper,
1585 modes, enabled, width, height))
1586 DRM_ERROR("Unable to find initial modes\n");
1588 DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n",
1591 drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height);
1594 /* need to set the modesets up here for use later */
1595 /* fill out the connector<->crtc mappings into the modesets */
1596 for (i = 0; i < fb_helper->crtc_count; i++) {
1597 modeset = &fb_helper->crtc_info[i].mode_set;
1598 modeset->num_connectors = 0;
1602 for (i = 0; i < fb_helper->connector_count; i++) {
1603 struct drm_display_mode *mode = modes[i];
1604 struct drm_fb_helper_crtc *fb_crtc = crtcs[i];
1605 modeset = &fb_crtc->mode_set;
1607 if (mode && fb_crtc) {
1608 DRM_DEBUG_KMS("desired mode %s set on crtc %d\n",
1609 mode->name, fb_crtc->mode_set.crtc->base.id);
1610 fb_crtc->desired_mode = mode;
1612 drm_mode_destroy(dev, modeset->mode);
1613 modeset->mode = drm_mode_duplicate(dev,
1614 fb_crtc->desired_mode);
1615 modeset->connectors[modeset->num_connectors++] = fb_helper->connector_info[i]->connector;
1616 modeset->fb = fb_helper->fb;
1620 /* Clear out any old modes if there are no more connected outputs. */
1621 for (i = 0; i < fb_helper->crtc_count; i++) {
1622 modeset = &fb_helper->crtc_info[i].mode_set;
1623 if (modeset->num_connectors == 0) {
1624 BUG_ON(modeset->fb);
1625 BUG_ON(modeset->num_connectors);
1627 drm_mode_destroy(dev, modeset->mode);
1628 modeset->mode = NULL;
1638 * drm_fb_helper_initial_config - setup a sane initial connector configuration
1639 * @fb_helper: fb_helper device struct
1640 * @bpp_sel: bpp value to use for the framebuffer configuration
1642 * Scans the CRTCs and connectors and tries to put together an initial setup.
1643 * At the moment, this is a cloned configuration across all heads with
1644 * a new framebuffer object as the backing store.
1646 * Note that this also registers the fbdev and so allows userspace to call into
1647 * the driver through the fbdev interfaces.
1649 * This function will call down into the ->fb_probe callback to let
1650 * the driver allocate and initialize the fbdev info structure and the drm
1651 * framebuffer used to back the fbdev. drm_fb_helper_fill_var() and
1652 * drm_fb_helper_fill_fix() are provided as helpers to setup simple default
1653 * values for the fbdev info structure.
1656 * Zero if everything went ok, nonzero otherwise.
1658 bool drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel)
1660 struct drm_device *dev = fb_helper->dev;
1663 drm_fb_helper_parse_command_line(fb_helper);
1665 mutex_lock(&dev->mode_config.mutex);
1666 count = drm_fb_helper_probe_connector_modes(fb_helper,
1667 dev->mode_config.max_width,
1668 dev->mode_config.max_height);
1669 mutex_unlock(&dev->mode_config.mutex);
1671 * we shouldn't end up with no modes here.
1674 dev_info(fb_helper->dev->dev, "No connectors reported connected with modes\n");
1676 drm_setup_crtcs(fb_helper);
1678 return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel);
1680 EXPORT_SYMBOL(drm_fb_helper_initial_config);
1683 * drm_fb_helper_hotplug_event - respond to a hotplug notification by
1684 * probing all the outputs attached to the fb
1685 * @fb_helper: the drm_fb_helper
1687 * Scan the connectors attached to the fb_helper and try to put together a
1688 * setup after *notification of a change in output configuration.
1690 * Called at runtime, takes the mode config locks to be able to check/change the
1691 * modeset configuration. Must be run from process context (which usually means
1692 * either the output polling work or a work item launched from the driver's
1693 * hotplug interrupt).
1695 * Note that the driver must ensure that this is only called _after_ the fb has
1696 * been fully set up, i.e. after the call to drm_fb_helper_initial_config.
1699 * 0 on success and a non-zero error code otherwise.
1701 int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
1703 struct drm_device *dev = fb_helper->dev;
1704 u32 max_width, max_height;
1709 mutex_lock(&fb_helper->dev->mode_config.mutex);
1710 if (!drm_fb_helper_is_bound(fb_helper)) {
1711 fb_helper->delayed_hotplug = true;
1712 mutex_unlock(&fb_helper->dev->mode_config.mutex);
1715 DRM_DEBUG_KMS("\n");
1717 max_width = fb_helper->fb->width;
1718 max_height = fb_helper->fb->height;
1720 drm_fb_helper_probe_connector_modes(fb_helper, max_width, max_height);
1721 mutex_unlock(&fb_helper->dev->mode_config.mutex);
1723 drm_modeset_lock_all(dev);
1724 drm_setup_crtcs(fb_helper);
1725 drm_modeset_unlock_all(dev);
1727 drm_fb_helper_set_par(fb_helper->fbdev);
1732 EXPORT_SYMBOL(drm_fb_helper_hotplug_event);
1734 /* The Kconfig DRM_KMS_HELPER selects FRAMEBUFFER_CONSOLE (if !EXPERT)
1735 * but the module doesn't depend on any fb console symbols. At least
1736 * attempt to load fbcon to avoid leaving the system without a usable console.
1738 #if defined(CONFIG_FRAMEBUFFER_CONSOLE_MODULE) && !defined(CONFIG_EXPERT)
1739 static int __init drm_fb_helper_modinit(void)
1741 const char *name = "fbcon";
1742 struct module *fbcon;
1744 mutex_lock(&module_mutex);
1745 fbcon = find_module(name);
1746 mutex_unlock(&module_mutex);
1749 request_module_nowait(name);
1753 module_init(drm_fb_helper_modinit);