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>
38 #include <drm/drm_atomic.h>
39 #include <drm/drm_atomic_helper.h>
41 static bool drm_fbdev_emulation
= true;
42 module_param_named(fbdev_emulation
, drm_fbdev_emulation
, bool, 0600);
43 MODULE_PARM_DESC(fbdev_emulation
,
44 "Enable legacy fbdev emulation [default=true]");
46 static LINUX_LIST_HEAD(kernel_fb_helper_list
);
51 * The fb helper functions are useful to provide an fbdev on top of a drm kernel
52 * mode setting driver. They can be used mostly independently from the crtc
53 * helper functions used by many drivers to implement the kernel mode setting
56 * Initialization is done as a four-step process with drm_fb_helper_prepare(),
57 * drm_fb_helper_init(), drm_fb_helper_single_add_all_connectors() and
58 * drm_fb_helper_initial_config(). Drivers with fancier requirements than the
59 * default behaviour can override the third step with their own code.
60 * Teardown is done with drm_fb_helper_fini().
62 * At runtime drivers should restore the fbdev console by calling
63 * drm_fb_helper_restore_fbdev_mode_unlocked() from their ->lastclose callback.
64 * They should also notify the fb helper code from updates to the output
65 * configuration by calling drm_fb_helper_hotplug_event(). For easier
66 * integration with the output polling code in drm_crtc_helper.c the modeset
67 * code provides a ->output_poll_changed callback.
69 * All other functions exported by the fb helper library can be used to
70 * implement the fbdev driver interface by the driver.
72 * It is possible, though perhaps somewhat tricky, to implement race-free
73 * hotplug detection using the fbdev helpers. The drm_fb_helper_prepare()
74 * helper must be called first to initialize the minimum required to make
75 * hotplug detection work. Drivers also need to make sure to properly set up
76 * the dev->mode_config.funcs member. After calling drm_kms_helper_poll_init()
77 * it is safe to enable interrupts and start processing hotplug events. At the
78 * same time, drivers should initialize all modeset objects such as CRTCs,
79 * encoders and connectors. To finish up the fbdev helper initialization, the
80 * drm_fb_helper_init() function is called. To probe for all attached displays
81 * and set up an initial configuration using the detected hardware, drivers
82 * should call drm_fb_helper_single_add_all_connectors() followed by
83 * drm_fb_helper_initial_config().
85 * If &drm_framebuffer_funcs ->dirty is set, the
86 * drm_fb_helper_{cfb,sys}_{write,fillrect,copyarea,imageblit} functions will
87 * accumulate changes and schedule &drm_fb_helper ->dirty_work to run right
88 * away. This worker then calls the dirty() function ensuring that it will
89 * always run in process context since the fb_*() function could be running in
90 * atomic context. If drm_fb_helper_deferred_io() is used as the deferred_io
91 * callback it will also schedule dirty_work with the damage collected from the
96 * drm_fb_helper_single_add_all_connectors() - add all connectors to fbdev
98 * @fb_helper: fbdev initialized with drm_fb_helper_init
100 * This functions adds all the available connectors for use with the given
101 * fb_helper. This is a separate step to allow drivers to freely assign
102 * connectors to the fbdev, e.g. if some are reserved for special purposes or
103 * not adequate to be used for the fbcon.
105 * This function is protected against concurrent connector hotadds/removals
106 * using drm_fb_helper_add_one_connector() and
107 * drm_fb_helper_remove_one_connector().
109 int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper
*fb_helper
)
111 struct drm_device
*dev
= fb_helper
->dev
;
112 struct drm_connector
*connector
;
115 if (!drm_fbdev_emulation
)
118 mutex_lock(&dev
->mode_config
.mutex
);
119 drm_for_each_connector(connector
, dev
) {
120 ret
= drm_fb_helper_add_one_connector(fb_helper
, connector
);
125 mutex_unlock(&dev
->mode_config
.mutex
);
128 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
129 kfree(fb_helper
->connector_info
[i
]);
130 fb_helper
->connector_info
[i
] = NULL
;
132 fb_helper
->connector_count
= 0;
133 mutex_unlock(&dev
->mode_config
.mutex
);
137 EXPORT_SYMBOL(drm_fb_helper_single_add_all_connectors
);
139 int drm_fb_helper_add_one_connector(struct drm_fb_helper
*fb_helper
, struct drm_connector
*connector
)
141 struct drm_fb_helper_connector
**temp
;
142 struct drm_fb_helper_connector
*fb_helper_connector
;
144 if (!drm_fbdev_emulation
)
147 WARN_ON(!mutex_is_locked(&fb_helper
->dev
->mode_config
.mutex
));
148 if (fb_helper
->connector_count
+ 1 > fb_helper
->connector_info_alloc_count
) {
149 temp
= krealloc(fb_helper
->connector_info
, sizeof(struct drm_fb_helper_connector
*) * (fb_helper
->connector_count
+ 1), M_DRM
, M_WAITOK
);
153 fb_helper
->connector_info_alloc_count
= fb_helper
->connector_count
+ 1;
154 fb_helper
->connector_info
= temp
;
158 fb_helper_connector
= kzalloc(sizeof(struct drm_fb_helper_connector
), GFP_KERNEL
);
159 if (!fb_helper_connector
)
162 drm_connector_reference(connector
);
163 fb_helper_connector
->connector
= connector
;
164 fb_helper
->connector_info
[fb_helper
->connector_count
++] = fb_helper_connector
;
167 EXPORT_SYMBOL(drm_fb_helper_add_one_connector
);
169 int drm_fb_helper_remove_one_connector(struct drm_fb_helper
*fb_helper
,
170 struct drm_connector
*connector
)
172 struct drm_fb_helper_connector
*fb_helper_connector
;
175 if (!drm_fbdev_emulation
)
178 WARN_ON(!mutex_is_locked(&fb_helper
->dev
->mode_config
.mutex
));
180 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
181 if (fb_helper
->connector_info
[i
]->connector
== connector
)
185 if (i
== fb_helper
->connector_count
)
187 fb_helper_connector
= fb_helper
->connector_info
[i
];
188 drm_connector_unreference(fb_helper_connector
->connector
);
190 for (j
= i
+ 1; j
< fb_helper
->connector_count
; j
++) {
191 fb_helper
->connector_info
[j
- 1] = fb_helper
->connector_info
[j
];
193 fb_helper
->connector_count
--;
194 kfree(fb_helper_connector
);
198 EXPORT_SYMBOL(drm_fb_helper_remove_one_connector
);
201 static void drm_fb_helper_save_lut_atomic(struct drm_crtc
*crtc
, struct drm_fb_helper
*helper
)
203 uint16_t *r_base
, *g_base
, *b_base
;
206 if (helper
->funcs
->gamma_get
== NULL
)
209 r_base
= crtc
->gamma_store
;
210 g_base
= r_base
+ crtc
->gamma_size
;
211 b_base
= g_base
+ crtc
->gamma_size
;
213 for (i
= 0; i
< crtc
->gamma_size
; i
++)
214 helper
->funcs
->gamma_get(crtc
, &r_base
[i
], &g_base
[i
], &b_base
[i
], i
);
217 static void drm_fb_helper_restore_lut_atomic(struct drm_crtc
*crtc
)
219 uint16_t *r_base
, *g_base
, *b_base
;
221 if (crtc
->funcs
->gamma_set
== NULL
)
224 r_base
= crtc
->gamma_store
;
225 g_base
= r_base
+ crtc
->gamma_size
;
226 b_base
= g_base
+ crtc
->gamma_size
;
228 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, 0, crtc
->gamma_size
);
233 * drm_fb_helper_debug_enter - implementation for ->fb_debug_enter
234 * @info: fbdev registered by the helper
236 int drm_fb_helper_debug_enter(struct fb_info
*info
)
238 struct drm_fb_helper
*helper
= info
->par
;
239 const struct drm_crtc_helper_funcs
*funcs
;
242 list_for_each_entry(helper
, &kernel_fb_helper_list
, kernel_fb_list
) {
243 for (i
= 0; i
< helper
->crtc_count
; i
++) {
244 struct drm_mode_set
*mode_set
=
245 &helper
->crtc_info
[i
].mode_set
;
247 if (!mode_set
->crtc
->enabled
)
250 funcs
= mode_set
->crtc
->helper_private
;
252 drm_fb_helper_save_lut_atomic(mode_set
->crtc
, helper
);
254 funcs
->mode_set_base_atomic(mode_set
->crtc
,
258 ENTER_ATOMIC_MODE_SET
);
264 EXPORT_SYMBOL(drm_fb_helper_debug_enter
);
267 /* Find the real fb for a given fb helper CRTC */
268 static struct drm_framebuffer
*drm_mode_config_fb(struct drm_crtc
*crtc
)
270 struct drm_device
*dev
= crtc
->dev
;
273 drm_for_each_crtc(c
, dev
) {
274 if (crtc
->base
.id
== c
->base
.id
)
275 return c
->primary
->fb
;
282 * drm_fb_helper_debug_leave - implementation for ->fb_debug_leave
283 * @info: fbdev registered by the helper
285 int drm_fb_helper_debug_leave(struct fb_info
*info
)
287 struct drm_fb_helper
*helper
= info
->par
;
288 struct drm_crtc
*crtc
;
289 const struct drm_crtc_helper_funcs
*funcs
;
290 struct drm_framebuffer
*fb
;
293 for (i
= 0; i
< helper
->crtc_count
; i
++) {
294 struct drm_mode_set
*mode_set
= &helper
->crtc_info
[i
].mode_set
;
295 crtc
= mode_set
->crtc
;
296 funcs
= crtc
->helper_private
;
297 fb
= drm_mode_config_fb(crtc
);
303 DRM_ERROR("no fb to restore??\n");
307 drm_fb_helper_restore_lut_atomic(mode_set
->crtc
);
308 funcs
->mode_set_base_atomic(mode_set
->crtc
, fb
, crtc
->x
,
309 crtc
->y
, LEAVE_ATOMIC_MODE_SET
);
314 EXPORT_SYMBOL(drm_fb_helper_debug_leave
);
317 static int restore_fbdev_mode_atomic(struct drm_fb_helper
*fb_helper
)
319 struct drm_device
*dev
= fb_helper
->dev
;
320 struct drm_plane
*plane
;
321 struct drm_atomic_state
*state
;
325 state
= drm_atomic_state_alloc(dev
);
329 state
->acquire_ctx
= dev
->mode_config
.acquire_ctx
;
332 drm_for_each_plane(plane
, dev
) {
333 struct drm_plane_state
*plane_state
;
335 plane_state
= drm_atomic_get_plane_state(state
, plane
);
336 if (IS_ERR(plane_state
)) {
337 ret
= PTR_ERR(plane_state
);
341 plane_state
->rotation
= BIT(DRM_ROTATE_0
);
343 plane
->old_fb
= plane
->fb
;
344 plane_mask
|= 1 << drm_plane_index(plane
);
346 /* disable non-primary: */
347 if (plane
->type
== DRM_PLANE_TYPE_PRIMARY
)
350 ret
= __drm_atomic_helper_disable_plane(plane
, plane_state
);
355 for(i
= 0; i
< fb_helper
->crtc_count
; i
++) {
356 struct drm_mode_set
*mode_set
= &fb_helper
->crtc_info
[i
].mode_set
;
358 ret
= __drm_atomic_helper_set_config(mode_set
, state
);
363 ret
= drm_atomic_commit(state
);
366 drm_atomic_clean_old_fb(dev
, plane_mask
, ret
);
372 drm_atomic_state_free(state
);
377 drm_atomic_state_clear(state
);
378 drm_atomic_legacy_backoff(state
);
383 static bool restore_fbdev_mode(struct drm_fb_helper
*fb_helper
)
385 struct drm_device
*dev
= fb_helper
->dev
;
386 struct drm_plane
*plane
;
390 drm_warn_on_modeset_not_all_locked(dev
);
392 if (fb_helper
->atomic
)
393 return restore_fbdev_mode_atomic(fb_helper
);
395 drm_for_each_plane(plane
, dev
) {
396 if (plane
->type
!= DRM_PLANE_TYPE_PRIMARY
)
397 drm_plane_force_disable(plane
);
399 if (dev
->mode_config
.rotation_property
) {
400 drm_mode_plane_set_obj_prop(plane
,
401 dev
->mode_config
.rotation_property
,
406 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
407 struct drm_mode_set
*mode_set
= &fb_helper
->crtc_info
[i
].mode_set
;
408 struct drm_crtc
*crtc
= mode_set
->crtc
;
411 if (crtc
->funcs
->cursor_set
) {
412 ret
= crtc
->funcs
->cursor_set(crtc
, NULL
, 0, 0, 0);
417 ret
= drm_mode_set_config_internal(mode_set
);
425 * drm_fb_helper_restore_fbdev_mode_unlocked - restore fbdev configuration
426 * @fb_helper: fbcon to restore
428 * This should be called from driver's drm ->lastclose callback
429 * when implementing an fbcon on top of kms using this helper. This ensures that
430 * the user isn't greeted with a black screen when e.g. X dies.
433 * Zero if everything went ok, negative error code otherwise.
435 int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper
*fb_helper
)
437 struct drm_device
*dev
= fb_helper
->dev
;
441 if (!drm_fbdev_emulation
)
444 drm_modeset_lock_all(dev
);
445 ret
= restore_fbdev_mode(fb_helper
);
447 do_delayed
= fb_helper
->delayed_hotplug
;
449 fb_helper
->delayed_hotplug
= false;
450 drm_modeset_unlock_all(dev
);
453 drm_fb_helper_hotplug_event(fb_helper
);
456 EXPORT_SYMBOL(drm_fb_helper_restore_fbdev_mode_unlocked
);
458 static bool drm_fb_helper_is_bound(struct drm_fb_helper
*fb_helper
)
460 struct drm_device
*dev
= fb_helper
->dev
;
461 struct drm_crtc
*crtc
;
462 int bound
= 0, crtcs_bound
= 0;
464 /* Sometimes user space wants everything disabled, so don't steal the
465 * display if there's a master. */
467 if (dev
->primary
->master
)
471 drm_for_each_crtc(crtc
, dev
) {
472 if (crtc
->primary
->fb
)
474 if (crtc
->primary
->fb
== fb_helper
->fb
)
478 if (bound
< crtcs_bound
)
484 #ifdef CONFIG_MAGIC_SYSRQ
486 * restore fbcon display for all kms driver's using this helper, used for sysrq
487 * and panic handling.
489 static bool drm_fb_helper_force_kernel_mode(void)
491 bool ret
, error
= false;
492 struct drm_fb_helper
*helper
;
494 if (list_empty(&kernel_fb_helper_list
))
497 list_for_each_entry(helper
, &kernel_fb_helper_list
, kernel_fb_list
) {
498 struct drm_device
*dev
= helper
->dev
;
500 if (dev
->switch_power_state
== DRM_SWITCH_POWER_OFF
)
503 drm_modeset_lock_all(dev
);
504 ret
= restore_fbdev_mode(helper
);
507 drm_modeset_unlock_all(dev
);
513 static void drm_fb_helper_restore_work_fn(struct work_struct
*ignored
)
516 ret
= drm_fb_helper_force_kernel_mode();
518 DRM_ERROR("Failed to restore crtc configuration\n");
520 static DECLARE_WORK(drm_fb_helper_restore_work
, drm_fb_helper_restore_work_fn
);
522 static void drm_fb_helper_sysrq(int dummy1
)
524 schedule_work(&drm_fb_helper_restore_work
);
527 static struct sysrq_key_op sysrq_drm_fb_helper_restore_op
= {
528 .handler
= drm_fb_helper_sysrq
,
529 .help_msg
= "force-fb(V)",
530 .action_msg
= "Restore framebuffer console",
533 static struct sysrq_key_op sysrq_drm_fb_helper_restore_op
= { };
537 static void drm_fb_helper_dpms(struct fb_info
*info
, int dpms_mode
)
539 struct drm_fb_helper
*fb_helper
= info
->par
;
540 struct drm_device
*dev
= fb_helper
->dev
;
541 struct drm_crtc
*crtc
;
542 struct drm_connector
*connector
;
546 * For each CRTC in this fb, turn the connectors on/off.
548 drm_modeset_lock_all(dev
);
549 if (!drm_fb_helper_is_bound(fb_helper
)) {
550 drm_modeset_unlock_all(dev
);
554 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
555 crtc
= fb_helper
->crtc_info
[i
].mode_set
.crtc
;
560 /* Walk the connectors & encoders on this fb turning them on/off */
561 for (j
= 0; j
< fb_helper
->connector_count
; j
++) {
562 connector
= fb_helper
->connector_info
[j
]->connector
;
563 connector
->funcs
->dpms(connector
, dpms_mode
);
564 drm_object_property_set_value(&connector
->base
,
565 dev
->mode_config
.dpms_property
, dpms_mode
);
568 drm_modeset_unlock_all(dev
);
572 * drm_fb_helper_blank - implementation for ->fb_blank
573 * @blank: desired blanking state
574 * @info: fbdev registered by the helper
576 int drm_fb_helper_blank(int blank
, struct fb_info
*info
)
582 if (oops_in_progress
)
587 /* Display: On; HSync: On, VSync: On */
588 case FB_BLANK_UNBLANK
:
589 drm_fb_helper_dpms(info
, DRM_MODE_DPMS_ON
);
592 /* Display: Off; HSync: On, VSync: On */
593 case FB_BLANK_NORMAL
:
594 drm_fb_helper_dpms(info
, DRM_MODE_DPMS_STANDBY
);
596 /* Display: Off; HSync: Off, VSync: On */
597 case FB_BLANK_HSYNC_SUSPEND
:
598 drm_fb_helper_dpms(info
, DRM_MODE_DPMS_STANDBY
);
600 /* Display: Off; HSync: On, VSync: Off */
601 case FB_BLANK_VSYNC_SUSPEND
:
602 drm_fb_helper_dpms(info
, DRM_MODE_DPMS_SUSPEND
);
605 /* Display: Off; HSync: Off, VSync: Off */
606 case FB_BLANK_POWERDOWN
:
607 drm_fb_helper_dpms(info
, DRM_MODE_DPMS_OFF
);
612 EXPORT_SYMBOL(drm_fb_helper_blank
);
614 static void drm_fb_helper_crtc_free(struct drm_fb_helper
*helper
)
618 for (i
= 0; i
< helper
->connector_count
; i
++) {
619 drm_connector_unreference(helper
->connector_info
[i
]->connector
);
620 kfree(helper
->connector_info
[i
]);
622 kfree(helper
->connector_info
);
623 for (i
= 0; i
< helper
->crtc_count
; i
++) {
624 kfree(helper
->crtc_info
[i
].mode_set
.connectors
);
625 if (helper
->crtc_info
[i
].mode_set
.mode
)
626 drm_mode_destroy(helper
->dev
, helper
->crtc_info
[i
].mode_set
.mode
);
628 kfree(helper
->crtc_info
);
631 static void drm_fb_helper_dirty_work(struct work_struct
*work
)
633 struct drm_fb_helper
*helper
= container_of(work
, struct drm_fb_helper
,
635 struct drm_clip_rect
*clip
= &helper
->dirty_clip
;
636 struct drm_clip_rect clip_copy
;
639 spin_lock_irqsave(&helper
->dirty_lock
, flags
);
641 clip
->x1
= clip
->y1
= ~0;
642 clip
->x2
= clip
->y2
= 0;
643 spin_unlock_irqrestore(&helper
->dirty_lock
, flags
);
645 helper
->fb
->funcs
->dirty(helper
->fb
, NULL
, 0, 0, &clip_copy
, 1);
649 * drm_fb_helper_prepare - setup a drm_fb_helper structure
651 * @helper: driver-allocated fbdev helper structure to set up
652 * @funcs: pointer to structure of functions associate with this helper
654 * Sets up the bare minimum to make the framebuffer helper usable. This is
655 * useful to implement race-free initialization of the polling helpers.
657 void drm_fb_helper_prepare(struct drm_device
*dev
, struct drm_fb_helper
*helper
,
658 const struct drm_fb_helper_funcs
*funcs
)
660 INIT_LIST_HEAD(&helper
->kernel_fb_list
);
661 lockinit(&helper
->dirty_lock
, "drm_fb_helper dirty_lock", 0, LK_CANRECURSE
);
662 INIT_WORK(&helper
->dirty_work
, drm_fb_helper_dirty_work
);
663 helper
->dirty_clip
.x1
= helper
->dirty_clip
.y1
= ~0;
664 helper
->funcs
= funcs
;
667 EXPORT_SYMBOL(drm_fb_helper_prepare
);
670 * drm_fb_helper_init - initialize a drm_fb_helper structure
672 * @fb_helper: driver-allocated fbdev helper structure to initialize
673 * @crtc_count: maximum number of crtcs to support in this fbdev emulation
674 * @max_conn_count: max connector count
676 * This allocates the structures for the fbdev helper with the given limits.
677 * Note that this won't yet touch the hardware (through the driver interfaces)
678 * nor register the fbdev. This is only done in drm_fb_helper_initial_config()
679 * to allow driver writes more control over the exact init sequence.
681 * Drivers must call drm_fb_helper_prepare() before calling this function.
684 * Zero if everything went ok, nonzero otherwise.
686 int drm_fb_helper_init(struct drm_device
*dev
,
687 struct drm_fb_helper
*fb_helper
,
688 int crtc_count
, int max_conn_count
)
690 struct drm_crtc
*crtc
;
693 if (!drm_fbdev_emulation
)
699 fb_helper
->crtc_info
= kcalloc(crtc_count
, sizeof(struct drm_fb_helper_crtc
), GFP_KERNEL
);
700 if (!fb_helper
->crtc_info
)
703 fb_helper
->crtc_count
= crtc_count
;
704 fb_helper
->connector_info
= kcalloc(dev
->mode_config
.num_connector
, sizeof(struct drm_fb_helper_connector
*), GFP_KERNEL
);
705 if (!fb_helper
->connector_info
) {
706 kfree(fb_helper
->crtc_info
);
709 fb_helper
->connector_info_alloc_count
= dev
->mode_config
.num_connector
;
710 fb_helper
->connector_count
= 0;
712 for (i
= 0; i
< crtc_count
; i
++) {
713 fb_helper
->crtc_info
[i
].mode_set
.connectors
=
714 kcalloc(max_conn_count
,
715 sizeof(struct drm_connector
*),
718 if (!fb_helper
->crtc_info
[i
].mode_set
.connectors
)
720 fb_helper
->crtc_info
[i
].mode_set
.num_connectors
= 0;
724 drm_for_each_crtc(crtc
, dev
) {
725 fb_helper
->crtc_info
[i
].mode_set
.crtc
= crtc
;
729 fb_helper
->atomic
= !!drm_core_check_feature(dev
, DRIVER_ATOMIC
);
733 drm_fb_helper_crtc_free(fb_helper
);
736 EXPORT_SYMBOL(drm_fb_helper_init
);
739 * drm_fb_helper_alloc_fbi - allocate fb_info and some of its members
740 * @fb_helper: driver-allocated fbdev helper
742 * A helper to alloc fb_info and the members cmap and apertures. Called
743 * by the driver within the fb_probe fb_helper callback function.
746 * fb_info pointer if things went okay, pointer containing error code
749 struct fb_info
*drm_fb_helper_alloc_fbi(struct drm_fb_helper
*fb_helper
)
751 struct fb_info
*info
;
754 info
= kzalloc(sizeof(struct fb_info
), GFP_KERNEL
);
756 info
= framebuffer_alloc(0, dev
);
759 return ERR_PTR(-ENOMEM
);
762 ret
= fb_alloc_cmap(&info
->cmap
, 256, 0);
766 info
->apertures
= alloc_apertures(1);
767 if (!info
->apertures
) {
773 fb_helper
->fbdev
= info
;
779 fb_dealloc_cmap(&info
->cmap
);
781 framebuffer_release(info
);
785 EXPORT_SYMBOL(drm_fb_helper_alloc_fbi
);
788 * drm_fb_helper_unregister_fbi - unregister fb_info framebuffer device
789 * @fb_helper: driver-allocated fbdev helper
791 * A wrapper around unregister_framebuffer, to release the fb_info
794 void drm_fb_helper_unregister_fbi(struct drm_fb_helper
*fb_helper
)
796 if (fb_helper
&& fb_helper
->fbdev
)
797 unregister_framebuffer(fb_helper
->fbdev
);
799 EXPORT_SYMBOL(drm_fb_helper_unregister_fbi
);
802 * drm_fb_helper_release_fbi - dealloc fb_info and its members
803 * @fb_helper: driver-allocated fbdev helper
805 * A helper to free memory taken by fb_info and the members cmap and
808 void drm_fb_helper_release_fbi(struct drm_fb_helper
*fb_helper
)
811 struct fb_info
*info
= fb_helper
->fbdev
;
818 fb_dealloc_cmap(&info
->cmap
);
819 framebuffer_release(info
);
823 fb_helper
->fbdev
= NULL
;
826 EXPORT_SYMBOL(drm_fb_helper_release_fbi
);
828 void drm_fb_helper_fini(struct drm_fb_helper
*fb_helper
)
830 if (!drm_fbdev_emulation
)
833 if (!list_empty(&fb_helper
->kernel_fb_list
)) {
834 list_del(&fb_helper
->kernel_fb_list
);
835 if (list_empty(&kernel_fb_helper_list
)) {
837 unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op
);
842 drm_fb_helper_crtc_free(fb_helper
);
845 EXPORT_SYMBOL(drm_fb_helper_fini
);
849 * drm_fb_helper_unlink_fbi - wrapper around unlink_framebuffer
850 * @fb_helper: driver-allocated fbdev helper
852 * A wrapper around unlink_framebuffer implemented by fbdev core
854 void drm_fb_helper_unlink_fbi(struct drm_fb_helper
*fb_helper
)
856 if (fb_helper
&& fb_helper
->fbdev
)
857 unlink_framebuffer(fb_helper
->fbdev
);
859 EXPORT_SYMBOL(drm_fb_helper_unlink_fbi
);
861 static void drm_fb_helper_dirty(struct fb_info
*info
, u32 x
, u32 y
,
862 u32 width
, u32 height
)
864 struct drm_fb_helper
*helper
= info
->par
;
865 struct drm_clip_rect
*clip
= &helper
->dirty_clip
;
868 if (!helper
->fb
->funcs
->dirty
)
871 spin_lock_irqsave(&helper
->dirty_lock
, flags
);
872 clip
->x1
= min_t(u32
, clip
->x1
, x
);
873 clip
->y1
= min_t(u32
, clip
->y1
, y
);
874 clip
->x2
= max_t(u32
, clip
->x2
, x
+ width
);
875 clip
->y2
= max_t(u32
, clip
->y2
, y
+ height
);
876 spin_unlock_irqrestore(&helper
->dirty_lock
, flags
);
878 schedule_work(&helper
->dirty_work
);
882 * drm_fb_helper_deferred_io() - fbdev deferred_io callback function
883 * @info: fb_info struct pointer
884 * @pagelist: list of dirty mmap framebuffer pages
886 * This function is used as the &fb_deferred_io ->deferred_io
887 * callback function for flushing the fbdev mmap writes.
889 void drm_fb_helper_deferred_io(struct fb_info
*info
,
890 struct list_head
*pagelist
)
892 unsigned long start
, end
, min
, max
;
898 list_for_each_entry(page
, pagelist
, lru
) {
899 start
= page
->index
<< PAGE_SHIFT
;
900 end
= start
+ PAGE_SIZE
- 1;
901 min
= min(min
, start
);
906 y1
= min
/ info
->fix
.line_length
;
907 y2
= min_t(u32
, DIV_ROUND_UP(max
, info
->fix
.line_length
),
909 drm_fb_helper_dirty(info
, 0, y1
, info
->var
.xres
, y2
- y1
);
912 EXPORT_SYMBOL(drm_fb_helper_deferred_io
);
915 * drm_fb_helper_sys_read - wrapper around fb_sys_read
916 * @info: fb_info struct pointer
917 * @buf: userspace buffer to read from framebuffer memory
918 * @count: number of bytes to read from framebuffer memory
919 * @ppos: read offset within framebuffer memory
921 * A wrapper around fb_sys_read implemented by fbdev core
923 ssize_t
drm_fb_helper_sys_read(struct fb_info
*info
, char __user
*buf
,
924 size_t count
, loff_t
*ppos
)
926 return fb_sys_read(info
, buf
, count
, ppos
);
928 EXPORT_SYMBOL(drm_fb_helper_sys_read
);
931 * drm_fb_helper_sys_write - wrapper around fb_sys_write
932 * @info: fb_info struct pointer
933 * @buf: userspace buffer to write to framebuffer memory
934 * @count: number of bytes to write to framebuffer memory
935 * @ppos: write offset within framebuffer memory
937 * A wrapper around fb_sys_write implemented by fbdev core
939 ssize_t
drm_fb_helper_sys_write(struct fb_info
*info
, const char __user
*buf
,
940 size_t count
, loff_t
*ppos
)
944 ret
= fb_sys_write(info
, buf
, count
, ppos
);
946 drm_fb_helper_dirty(info
, 0, 0, info
->var
.xres
,
951 EXPORT_SYMBOL(drm_fb_helper_sys_write
);
954 * drm_fb_helper_sys_fillrect - wrapper around sys_fillrect
955 * @info: fbdev registered by the helper
956 * @rect: info about rectangle to fill
958 * A wrapper around sys_fillrect implemented by fbdev core
960 void drm_fb_helper_sys_fillrect(struct fb_info
*info
,
961 const struct fb_fillrect
*rect
)
963 sys_fillrect(info
, rect
);
964 drm_fb_helper_dirty(info
, rect
->dx
, rect
->dy
,
965 rect
->width
, rect
->height
);
967 EXPORT_SYMBOL(drm_fb_helper_sys_fillrect
);
970 * drm_fb_helper_sys_copyarea - wrapper around sys_copyarea
971 * @info: fbdev registered by the helper
972 * @area: info about area to copy
974 * A wrapper around sys_copyarea implemented by fbdev core
976 void drm_fb_helper_sys_copyarea(struct fb_info
*info
,
977 const struct fb_copyarea
*area
)
979 sys_copyarea(info
, area
);
980 drm_fb_helper_dirty(info
, area
->dx
, area
->dy
,
981 area
->width
, area
->height
);
983 EXPORT_SYMBOL(drm_fb_helper_sys_copyarea
);
986 * drm_fb_helper_sys_imageblit - wrapper around sys_imageblit
987 * @info: fbdev registered by the helper
988 * @image: info about image to blit
990 * A wrapper around sys_imageblit implemented by fbdev core
992 void drm_fb_helper_sys_imageblit(struct fb_info
*info
,
993 const struct fb_image
*image
)
995 sys_imageblit(info
, image
);
996 drm_fb_helper_dirty(info
, image
->dx
, image
->dy
,
997 image
->width
, image
->height
);
999 EXPORT_SYMBOL(drm_fb_helper_sys_imageblit
);
1002 * drm_fb_helper_cfb_fillrect - wrapper around cfb_fillrect
1003 * @info: fbdev registered by the helper
1004 * @rect: info about rectangle to fill
1006 * A wrapper around cfb_imageblit implemented by fbdev core
1008 void drm_fb_helper_cfb_fillrect(struct fb_info
*info
,
1009 const struct fb_fillrect
*rect
)
1011 cfb_fillrect(info
, rect
);
1012 drm_fb_helper_dirty(info
, rect
->dx
, rect
->dy
,
1013 rect
->width
, rect
->height
);
1015 EXPORT_SYMBOL(drm_fb_helper_cfb_fillrect
);
1018 * drm_fb_helper_cfb_copyarea - wrapper around cfb_copyarea
1019 * @info: fbdev registered by the helper
1020 * @area: info about area to copy
1022 * A wrapper around cfb_copyarea implemented by fbdev core
1024 void drm_fb_helper_cfb_copyarea(struct fb_info
*info
,
1025 const struct fb_copyarea
*area
)
1027 cfb_copyarea(info
, area
);
1028 drm_fb_helper_dirty(info
, area
->dx
, area
->dy
,
1029 area
->width
, area
->height
);
1031 EXPORT_SYMBOL(drm_fb_helper_cfb_copyarea
);
1034 * drm_fb_helper_cfb_imageblit - wrapper around cfb_imageblit
1035 * @info: fbdev registered by the helper
1036 * @image: info about image to blit
1038 * A wrapper around cfb_imageblit implemented by fbdev core
1040 void drm_fb_helper_cfb_imageblit(struct fb_info
*info
,
1041 const struct fb_image
*image
)
1043 cfb_imageblit(info
, image
);
1044 drm_fb_helper_dirty(info
, image
->dx
, image
->dy
,
1045 image
->width
, image
->height
);
1047 EXPORT_SYMBOL(drm_fb_helper_cfb_imageblit
);
1050 * drm_fb_helper_set_suspend - wrapper around fb_set_suspend
1051 * @fb_helper: driver-allocated fbdev helper
1052 * @state: desired state, zero to resume, non-zero to suspend
1054 * A wrapper around fb_set_suspend implemented by fbdev core
1056 void drm_fb_helper_set_suspend(struct drm_fb_helper
*fb_helper
, int state
)
1058 if (fb_helper
&& fb_helper
->fbdev
)
1059 fb_set_suspend(fb_helper
->fbdev
, state
);
1061 EXPORT_SYMBOL(drm_fb_helper_set_suspend
);
1063 static int setcolreg(struct drm_crtc
*crtc
, u16 red
, u16 green
,
1064 u16 blue
, u16 regno
, struct fb_info
*info
)
1066 struct drm_fb_helper
*fb_helper
= info
->par
;
1067 struct drm_framebuffer
*fb
= fb_helper
->fb
;
1070 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
) {
1073 /* place color in psuedopalette */
1076 palette
= (u32
*)info
->pseudo_palette
;
1077 red
>>= (16 - info
->var
.red
.length
);
1078 green
>>= (16 - info
->var
.green
.length
);
1079 blue
>>= (16 - info
->var
.blue
.length
);
1080 value
= (red
<< info
->var
.red
.offset
) |
1081 (green
<< info
->var
.green
.offset
) |
1082 (blue
<< info
->var
.blue
.offset
);
1083 if (info
->var
.transp
.length
> 0) {
1084 u32 mask
= (1 << info
->var
.transp
.length
) - 1;
1085 mask
<<= info
->var
.transp
.offset
;
1088 palette
[regno
] = value
;
1093 * The driver really shouldn't advertise pseudo/directcolor
1094 * visuals if it can't deal with the palette.
1096 if (WARN_ON(!fb_helper
->funcs
->gamma_set
||
1097 !fb_helper
->funcs
->gamma_get
))
1102 if (fb
->bits_per_pixel
== 16) {
1103 pindex
= regno
<< 3;
1105 if (fb
->depth
== 16 && regno
> 63)
1107 if (fb
->depth
== 15 && regno
> 31)
1110 if (fb
->depth
== 16) {
1114 for (i
= 0; i
< 8; i
++)
1115 fb_helper
->funcs
->gamma_set(crtc
, red
,
1116 green
, blue
, pindex
+ i
);
1119 fb_helper
->funcs
->gamma_get(crtc
, &r
,
1123 for (i
= 0; i
< 4; i
++)
1124 fb_helper
->funcs
->gamma_set(crtc
, r
,
1130 if (fb
->depth
!= 16)
1131 fb_helper
->funcs
->gamma_set(crtc
, red
, green
, blue
, pindex
);
1136 * drm_fb_helper_setcmap - implementation for ->fb_setcmap
1137 * @cmap: cmap to set
1138 * @info: fbdev registered by the helper
1140 int drm_fb_helper_setcmap(struct fb_cmap
*cmap
, struct fb_info
*info
)
1142 struct drm_fb_helper
*fb_helper
= info
->par
;
1143 struct drm_device
*dev
= fb_helper
->dev
;
1144 const struct drm_crtc_helper_funcs
*crtc_funcs
;
1145 u16
*red
, *green
, *blue
, *transp
;
1146 struct drm_crtc
*crtc
;
1150 if (oops_in_progress
)
1153 drm_modeset_lock_all(dev
);
1154 if (!drm_fb_helper_is_bound(fb_helper
)) {
1155 drm_modeset_unlock_all(dev
);
1159 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
1160 crtc
= fb_helper
->crtc_info
[i
].mode_set
.crtc
;
1161 crtc_funcs
= crtc
->helper_private
;
1164 green
= cmap
->green
;
1166 transp
= cmap
->transp
;
1167 start
= cmap
->start
;
1169 for (j
= 0; j
< cmap
->len
; j
++) {
1170 u16 hred
, hgreen
, hblue
, htransp
= 0xffff;
1177 htransp
= *transp
++;
1179 rc
= setcolreg(crtc
, hred
, hgreen
, hblue
, start
++, info
);
1183 if (crtc_funcs
->load_lut
)
1184 crtc_funcs
->load_lut(crtc
);
1187 drm_modeset_unlock_all(dev
);
1190 EXPORT_SYMBOL(drm_fb_helper_setcmap
);
1193 * drm_fb_helper_check_var - implementation for ->fb_check_var
1194 * @var: screeninfo to check
1195 * @info: fbdev registered by the helper
1197 int drm_fb_helper_check_var(struct fb_var_screeninfo
*var
,
1198 struct fb_info
*info
)
1200 struct drm_fb_helper
*fb_helper
= info
->par
;
1201 struct drm_framebuffer
*fb
= fb_helper
->fb
;
1204 if (var
->pixclock
!= 0 || in_dbg_master())
1207 /* Need to resize the fb object !!! */
1208 if (var
->bits_per_pixel
> fb
->bits_per_pixel
||
1209 var
->xres
> fb
->width
|| var
->yres
> fb
->height
||
1210 var
->xres_virtual
> fb
->width
|| var
->yres_virtual
> fb
->height
) {
1211 DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb "
1212 "request %dx%d-%d (virtual %dx%d) > %dx%d-%d\n",
1213 var
->xres
, var
->yres
, var
->bits_per_pixel
,
1214 var
->xres_virtual
, var
->yres_virtual
,
1215 fb
->width
, fb
->height
, fb
->bits_per_pixel
);
1219 switch (var
->bits_per_pixel
) {
1221 depth
= (var
->green
.length
== 6) ? 16 : 15;
1224 depth
= (var
->transp
.length
> 0) ? 32 : 24;
1227 depth
= var
->bits_per_pixel
;
1233 var
->red
.offset
= 0;
1234 var
->green
.offset
= 0;
1235 var
->blue
.offset
= 0;
1236 var
->red
.length
= 8;
1237 var
->green
.length
= 8;
1238 var
->blue
.length
= 8;
1239 var
->transp
.length
= 0;
1240 var
->transp
.offset
= 0;
1243 var
->red
.offset
= 10;
1244 var
->green
.offset
= 5;
1245 var
->blue
.offset
= 0;
1246 var
->red
.length
= 5;
1247 var
->green
.length
= 5;
1248 var
->blue
.length
= 5;
1249 var
->transp
.length
= 1;
1250 var
->transp
.offset
= 15;
1253 var
->red
.offset
= 11;
1254 var
->green
.offset
= 5;
1255 var
->blue
.offset
= 0;
1256 var
->red
.length
= 5;
1257 var
->green
.length
= 6;
1258 var
->blue
.length
= 5;
1259 var
->transp
.length
= 0;
1260 var
->transp
.offset
= 0;
1263 var
->red
.offset
= 16;
1264 var
->green
.offset
= 8;
1265 var
->blue
.offset
= 0;
1266 var
->red
.length
= 8;
1267 var
->green
.length
= 8;
1268 var
->blue
.length
= 8;
1269 var
->transp
.length
= 0;
1270 var
->transp
.offset
= 0;
1273 var
->red
.offset
= 16;
1274 var
->green
.offset
= 8;
1275 var
->blue
.offset
= 0;
1276 var
->red
.length
= 8;
1277 var
->green
.length
= 8;
1278 var
->blue
.length
= 8;
1279 var
->transp
.length
= 8;
1280 var
->transp
.offset
= 24;
1287 EXPORT_SYMBOL(drm_fb_helper_check_var
);
1291 * drm_fb_helper_set_par - implementation for ->fb_set_par
1292 * @info: fbdev registered by the helper
1294 * This will let fbcon do the mode init and is called at initialization time by
1295 * the fbdev core when registering the driver, and later on through the hotplug
1298 int drm_fb_helper_set_par(struct fb_info
*info
)
1300 struct drm_fb_helper
*fb_helper
= info
->par
;
1302 struct fb_var_screeninfo
*var
= &info
->var
;
1305 #ifdef __DragonFly__
1309 if (oops_in_progress
)
1314 if (var
->pixclock
!= 0) {
1315 DRM_ERROR("PIXEL CLOCK SET\n");
1320 drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper
);
1324 EXPORT_SYMBOL(drm_fb_helper_set_par
);
1327 static int pan_display_atomic(struct fb_var_screeninfo
*var
,
1328 struct fb_info
*info
)
1330 struct drm_fb_helper
*fb_helper
= info
->par
;
1331 struct drm_device
*dev
= fb_helper
->dev
;
1332 struct drm_atomic_state
*state
;
1333 struct drm_plane
*plane
;
1335 unsigned plane_mask
;
1337 state
= drm_atomic_state_alloc(dev
);
1341 state
->acquire_ctx
= dev
->mode_config
.acquire_ctx
;
1344 for(i
= 0; i
< fb_helper
->crtc_count
; i
++) {
1345 struct drm_mode_set
*mode_set
;
1347 mode_set
= &fb_helper
->crtc_info
[i
].mode_set
;
1349 mode_set
->x
= var
->xoffset
;
1350 mode_set
->y
= var
->yoffset
;
1352 ret
= __drm_atomic_helper_set_config(mode_set
, state
);
1356 plane
= mode_set
->crtc
->primary
;
1357 plane_mask
|= (1 << drm_plane_index(plane
));
1358 plane
->old_fb
= plane
->fb
;
1361 ret
= drm_atomic_commit(state
);
1365 info
->var
.xoffset
= var
->xoffset
;
1366 info
->var
.yoffset
= var
->yoffset
;
1370 drm_atomic_clean_old_fb(dev
, plane_mask
, ret
);
1372 if (ret
== -EDEADLK
)
1376 drm_atomic_state_free(state
);
1381 drm_atomic_state_clear(state
);
1382 drm_atomic_legacy_backoff(state
);
1388 * drm_fb_helper_pan_display - implementation for ->fb_pan_display
1389 * @var: updated screen information
1390 * @info: fbdev registered by the helper
1392 int drm_fb_helper_pan_display(struct fb_var_screeninfo
*var
,
1393 struct fb_info
*info
)
1395 struct drm_fb_helper
*fb_helper
= info
->par
;
1396 struct drm_device
*dev
= fb_helper
->dev
;
1397 struct drm_mode_set
*modeset
;
1401 if (oops_in_progress
)
1404 drm_modeset_lock_all(dev
);
1405 if (!drm_fb_helper_is_bound(fb_helper
)) {
1406 drm_modeset_unlock_all(dev
);
1410 if (fb_helper
->atomic
) {
1411 ret
= pan_display_atomic(var
, info
);
1415 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
1416 modeset
= &fb_helper
->crtc_info
[i
].mode_set
;
1418 modeset
->x
= var
->xoffset
;
1419 modeset
->y
= var
->yoffset
;
1421 if (modeset
->num_connectors
) {
1422 ret
= drm_mode_set_config_internal(modeset
);
1424 info
->var
.xoffset
= var
->xoffset
;
1425 info
->var
.yoffset
= var
->yoffset
;
1430 drm_modeset_unlock_all(dev
);
1433 EXPORT_SYMBOL(drm_fb_helper_pan_display
);
1437 * Allocates the backing storage and sets up the fbdev info structure through
1438 * the ->fb_probe callback and then registers the fbdev and sets up the panic
1441 static int drm_fb_helper_single_fb_probe(struct drm_fb_helper
*fb_helper
,
1447 struct fb_info
*info
;
1448 struct drm_fb_helper_surface_size sizes
;
1450 #ifdef __DragonFly__
1451 int kms_console
= 1;
1454 memset(&sizes
, 0, sizeof(struct drm_fb_helper_surface_size
));
1455 sizes
.surface_depth
= 24;
1456 sizes
.surface_bpp
= 32;
1457 sizes
.fb_width
= (unsigned)-1;
1458 sizes
.fb_height
= (unsigned)-1;
1460 /* if driver picks 8 or 16 by default use that
1461 for both depth/bpp */
1462 if (preferred_bpp
!= sizes
.surface_bpp
)
1463 sizes
.surface_depth
= sizes
.surface_bpp
= preferred_bpp
;
1465 /* first up get a count of crtcs now in use and new min/maxes width/heights */
1466 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1467 struct drm_fb_helper_connector
*fb_helper_conn
= fb_helper
->connector_info
[i
];
1468 struct drm_cmdline_mode
*cmdline_mode
;
1470 cmdline_mode
= &fb_helper_conn
->connector
->cmdline_mode
;
1472 if (cmdline_mode
->bpp_specified
) {
1473 switch (cmdline_mode
->bpp
) {
1475 sizes
.surface_depth
= sizes
.surface_bpp
= 8;
1478 sizes
.surface_depth
= 15;
1479 sizes
.surface_bpp
= 16;
1482 sizes
.surface_depth
= sizes
.surface_bpp
= 16;
1485 sizes
.surface_depth
= sizes
.surface_bpp
= 24;
1488 sizes
.surface_depth
= 24;
1489 sizes
.surface_bpp
= 32;
1497 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
1498 struct drm_display_mode
*desired_mode
;
1499 struct drm_mode_set
*mode_set
;
1501 /* in case of tile group, are we the last tile vert or horiz?
1502 * If no tile group you are always the last one both vertically
1505 bool lastv
= true, lasth
= true;
1507 desired_mode
= fb_helper
->crtc_info
[i
].desired_mode
;
1508 mode_set
= &fb_helper
->crtc_info
[i
].mode_set
;
1515 x
= fb_helper
->crtc_info
[i
].x
;
1516 y
= fb_helper
->crtc_info
[i
].y
;
1518 if (gamma_size
== 0)
1519 gamma_size
= fb_helper
->crtc_info
[i
].mode_set
.crtc
->gamma_size
;
1521 sizes
.surface_width
= max_t(u32
, desired_mode
->hdisplay
+ x
, sizes
.surface_width
);
1522 sizes
.surface_height
= max_t(u32
, desired_mode
->vdisplay
+ y
, sizes
.surface_height
);
1524 for (j
= 0; j
< mode_set
->num_connectors
; j
++) {
1525 struct drm_connector
*connector
= mode_set
->connectors
[j
];
1526 if (connector
->has_tile
) {
1527 lasth
= (connector
->tile_h_loc
== (connector
->num_h_tile
- 1));
1528 lastv
= (connector
->tile_v_loc
== (connector
->num_v_tile
- 1));
1529 /* cloning to multiple tiles is just crazy-talk, so: */
1535 sizes
.fb_width
= min_t(u32
, desired_mode
->hdisplay
+ x
, sizes
.fb_width
);
1537 sizes
.fb_height
= min_t(u32
, desired_mode
->vdisplay
+ y
, sizes
.fb_height
);
1540 if (crtc_count
== 0 || sizes
.fb_width
== -1 || sizes
.fb_height
== -1) {
1541 /* hmm everyone went away - assume VGA cable just fell out
1542 and will come back later. */
1543 DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n");
1544 sizes
.fb_width
= sizes
.surface_width
= 1024;
1545 sizes
.fb_height
= sizes
.surface_height
= 768;
1548 /* push down into drivers */
1549 ret
= (*fb_helper
->funcs
->fb_probe
)(fb_helper
, &sizes
);
1553 info
= fb_helper
->fbdev
;
1556 * Set the fb pointer - usually drm_setup_crtcs does this for hotplug
1557 * events, but at init time drm_setup_crtcs needs to be called before
1558 * the fb is allocated (since we need to figure out the desired size of
1559 * the fb before we can allocate it ...). Hence we need to fix things up
1562 for (i
= 0; i
< fb_helper
->crtc_count
; i
++)
1563 if (fb_helper
->crtc_info
[i
].mode_set
.num_connectors
)
1564 fb_helper
->crtc_info
[i
].mode_set
.fb
= fb_helper
->fb
;
1566 #ifdef __DragonFly__
1567 TUNABLE_INT_FETCH("kern.kms_console", &kms_console
);
1569 if (register_framebuffer(info
) < 0)
1572 list_add(&fb_helper
->kernel_fb_list
, &kernel_fb_helper_list
);
1575 info
->var
.pixclock
= 0;
1576 if (register_framebuffer(info
) < 0)
1579 dev_info(fb_helper
->dev
->dev
, "fb%d: %s frame buffer device\n",
1580 info
->node
, info
->fix
.id
);
1582 if (list_empty(&kernel_fb_helper_list
)) {
1583 register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op
);
1586 list_add(&fb_helper
->kernel_fb_list
, &kernel_fb_helper_list
);
1594 * drm_fb_helper_fill_fix - initializes fixed fbdev information
1595 * @info: fbdev registered by the helper
1596 * @pitch: desired pitch
1597 * @depth: desired depth
1599 * Helper to fill in the fixed fbdev information useful for a non-accelerated
1600 * fbdev emulations. Drivers which support acceleration methods which impose
1601 * additional constraints need to set up their own limits.
1603 * Drivers should call this (or their equivalent setup code) from their
1604 * ->fb_probe callback.
1606 void drm_fb_helper_fill_fix(struct fb_info
*info
, uint32_t pitch
,
1609 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
1610 info
->fix
.visual
= depth
== 8 ? FB_VISUAL_PSEUDOCOLOR
:
1611 FB_VISUAL_TRUECOLOR
;
1612 info
->fix
.mmio_start
= 0;
1613 info
->fix
.mmio_len
= 0;
1614 info
->fix
.type_aux
= 0;
1615 info
->fix
.xpanstep
= 1; /* doing it in hw */
1616 info
->fix
.ypanstep
= 1; /* doing it in hw */
1617 info
->fix
.ywrapstep
= 0;
1618 info
->fix
.accel
= FB_ACCEL_NONE
;
1620 info
->fix
.line_length
= pitch
;
1623 EXPORT_SYMBOL(drm_fb_helper_fill_fix
);
1626 * drm_fb_helper_fill_var - initalizes variable fbdev information
1627 * @info: fbdev instance to set up
1628 * @fb_helper: fb helper instance to use as template
1629 * @fb_width: desired fb width
1630 * @fb_height: desired fb height
1632 * Sets up the variable fbdev metainformation from the given fb helper instance
1633 * and the drm framebuffer allocated in fb_helper->fb.
1635 * Drivers should call this (or their equivalent setup code) from their
1636 * ->fb_probe callback after having allocated the fbdev backing
1637 * storage framebuffer.
1639 void drm_fb_helper_fill_var(struct fb_info
*info
, struct drm_fb_helper
*fb_helper
,
1640 uint32_t fb_width
, uint32_t fb_height
)
1642 struct drm_framebuffer
*fb
= fb_helper
->fb
;
1643 info
->pseudo_palette
= fb_helper
->pseudo_palette
;
1644 info
->var
.xres_virtual
= fb
->width
;
1645 info
->var
.yres_virtual
= fb
->height
;
1646 info
->var
.bits_per_pixel
= fb
->bits_per_pixel
;
1647 info
->var
.accel_flags
= FB_ACCELF_TEXT
;
1648 info
->var
.xoffset
= 0;
1649 info
->var
.yoffset
= 0;
1650 info
->var
.activate
= FB_ACTIVATE_NOW
;
1651 info
->var
.height
= -1;
1652 info
->var
.width
= -1;
1654 switch (fb
->depth
) {
1656 info
->var
.red
.offset
= 0;
1657 info
->var
.green
.offset
= 0;
1658 info
->var
.blue
.offset
= 0;
1659 info
->var
.red
.length
= 8; /* 8bit DAC */
1660 info
->var
.green
.length
= 8;
1661 info
->var
.blue
.length
= 8;
1662 info
->var
.transp
.offset
= 0;
1663 info
->var
.transp
.length
= 0;
1666 info
->var
.red
.offset
= 10;
1667 info
->var
.green
.offset
= 5;
1668 info
->var
.blue
.offset
= 0;
1669 info
->var
.red
.length
= 5;
1670 info
->var
.green
.length
= 5;
1671 info
->var
.blue
.length
= 5;
1672 info
->var
.transp
.offset
= 15;
1673 info
->var
.transp
.length
= 1;
1676 info
->var
.red
.offset
= 11;
1677 info
->var
.green
.offset
= 5;
1678 info
->var
.blue
.offset
= 0;
1679 info
->var
.red
.length
= 5;
1680 info
->var
.green
.length
= 6;
1681 info
->var
.blue
.length
= 5;
1682 info
->var
.transp
.offset
= 0;
1685 info
->var
.red
.offset
= 16;
1686 info
->var
.green
.offset
= 8;
1687 info
->var
.blue
.offset
= 0;
1688 info
->var
.red
.length
= 8;
1689 info
->var
.green
.length
= 8;
1690 info
->var
.blue
.length
= 8;
1691 info
->var
.transp
.offset
= 0;
1692 info
->var
.transp
.length
= 0;
1695 info
->var
.red
.offset
= 16;
1696 info
->var
.green
.offset
= 8;
1697 info
->var
.blue
.offset
= 0;
1698 info
->var
.red
.length
= 8;
1699 info
->var
.green
.length
= 8;
1700 info
->var
.blue
.length
= 8;
1701 info
->var
.transp
.offset
= 24;
1702 info
->var
.transp
.length
= 8;
1708 info
->var
.xres
= fb_width
;
1709 info
->var
.yres
= fb_height
;
1711 EXPORT_SYMBOL(drm_fb_helper_fill_var
);
1714 static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper
*fb_helper
,
1718 struct drm_connector
*connector
;
1722 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1723 connector
= fb_helper
->connector_info
[i
]->connector
;
1724 count
+= connector
->funcs
->fill_modes(connector
, maxX
, maxY
);
1730 struct drm_display_mode
*drm_has_preferred_mode(struct drm_fb_helper_connector
*fb_connector
, int width
, int height
)
1732 struct drm_display_mode
*mode
;
1734 list_for_each_entry(mode
, &fb_connector
->connector
->modes
, head
) {
1735 if (mode
->hdisplay
> width
||
1736 mode
->vdisplay
> height
)
1738 if (mode
->type
& DRM_MODE_TYPE_PREFERRED
)
1743 EXPORT_SYMBOL(drm_has_preferred_mode
);
1745 static bool drm_has_cmdline_mode(struct drm_fb_helper_connector
*fb_connector
)
1747 return fb_connector
->connector
->cmdline_mode
.specified
;
1750 struct drm_display_mode
*drm_pick_cmdline_mode(struct drm_fb_helper_connector
*fb_helper_conn
,
1751 int width
, int height
)
1753 struct drm_cmdline_mode
*cmdline_mode
;
1754 struct drm_display_mode
*mode
;
1755 bool prefer_non_interlace
;
1757 cmdline_mode
= &fb_helper_conn
->connector
->cmdline_mode
;
1758 if (cmdline_mode
->specified
== false)
1761 /* attempt to find a matching mode in the list of modes
1762 * we have gotten so far, if not add a CVT mode that conforms
1764 if (cmdline_mode
->rb
|| cmdline_mode
->margins
)
1767 prefer_non_interlace
= !cmdline_mode
->interlace
;
1769 list_for_each_entry(mode
, &fb_helper_conn
->connector
->modes
, head
) {
1770 /* check width/height */
1771 if (mode
->hdisplay
!= cmdline_mode
->xres
||
1772 mode
->vdisplay
!= cmdline_mode
->yres
)
1775 if (cmdline_mode
->refresh_specified
) {
1776 if (mode
->vrefresh
!= cmdline_mode
->refresh
)
1780 if (cmdline_mode
->interlace
) {
1781 if (!(mode
->flags
& DRM_MODE_FLAG_INTERLACE
))
1783 } else if (prefer_non_interlace
) {
1784 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
1790 if (prefer_non_interlace
) {
1791 prefer_non_interlace
= false;
1796 mode
= drm_mode_create_from_cmdline_mode(fb_helper_conn
->connector
->dev
,
1798 list_add(&mode
->head
, &fb_helper_conn
->connector
->modes
);
1801 EXPORT_SYMBOL(drm_pick_cmdline_mode
);
1803 static bool drm_connector_enabled(struct drm_connector
*connector
, bool strict
)
1808 enable
= connector
->status
== connector_status_connected
;
1810 enable
= connector
->status
!= connector_status_disconnected
;
1815 static void drm_enable_connectors(struct drm_fb_helper
*fb_helper
,
1818 bool any_enabled
= false;
1819 struct drm_connector
*connector
;
1822 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1823 connector
= fb_helper
->connector_info
[i
]->connector
;
1824 enabled
[i
] = drm_connector_enabled(connector
, true);
1825 DRM_DEBUG_KMS("connector %d enabled? %s\n", connector
->base
.id
,
1826 enabled
[i
] ? "yes" : "no");
1827 any_enabled
|= enabled
[i
];
1833 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1834 connector
= fb_helper
->connector_info
[i
]->connector
;
1835 enabled
[i
] = drm_connector_enabled(connector
, false);
1839 static bool drm_target_cloned(struct drm_fb_helper
*fb_helper
,
1840 struct drm_display_mode
**modes
,
1841 struct drm_fb_offset
*offsets
,
1842 bool *enabled
, int width
, int height
)
1845 bool can_clone
= false;
1846 struct drm_fb_helper_connector
*fb_helper_conn
;
1847 struct drm_display_mode
*dmt_mode
, *mode
;
1849 /* only contemplate cloning in the single crtc case */
1850 if (fb_helper
->crtc_count
> 1)
1854 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1859 /* only contemplate cloning if more than one connector is enabled */
1863 /* check the command line or if nothing common pick 1024x768 */
1865 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1868 fb_helper_conn
= fb_helper
->connector_info
[i
];
1869 modes
[i
] = drm_pick_cmdline_mode(fb_helper_conn
, width
, height
);
1874 for (j
= 0; j
< i
; j
++) {
1877 if (!drm_mode_equal(modes
[j
], modes
[i
]))
1883 DRM_DEBUG_KMS("can clone using command line\n");
1887 /* try and find a 1024x768 mode on each connector */
1889 dmt_mode
= drm_mode_find_dmt(fb_helper
->dev
, 1024, 768, 60, false);
1891 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1896 fb_helper_conn
= fb_helper
->connector_info
[i
];
1897 list_for_each_entry(mode
, &fb_helper_conn
->connector
->modes
, head
) {
1898 if (drm_mode_equal(mode
, dmt_mode
))
1906 DRM_DEBUG_KMS("can clone using 1024x768\n");
1909 DRM_INFO("kms: can't enable cloning when we probably wanted to.\n");
1913 static int drm_get_tile_offsets(struct drm_fb_helper
*fb_helper
,
1914 struct drm_display_mode
**modes
,
1915 struct drm_fb_offset
*offsets
,
1917 int h_idx
, int v_idx
)
1919 struct drm_fb_helper_connector
*fb_helper_conn
;
1921 int hoffset
= 0, voffset
= 0;
1923 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1924 fb_helper_conn
= fb_helper
->connector_info
[i
];
1925 if (!fb_helper_conn
->connector
->has_tile
)
1928 if (!modes
[i
] && (h_idx
|| v_idx
)) {
1929 DRM_DEBUG_KMS("no modes for connector tiled %d %d\n", i
,
1930 fb_helper_conn
->connector
->base
.id
);
1933 if (fb_helper_conn
->connector
->tile_h_loc
< h_idx
)
1934 hoffset
+= modes
[i
]->hdisplay
;
1936 if (fb_helper_conn
->connector
->tile_v_loc
< v_idx
)
1937 voffset
+= modes
[i
]->vdisplay
;
1939 offsets
[idx
].x
= hoffset
;
1940 offsets
[idx
].y
= voffset
;
1941 DRM_DEBUG_KMS("returned %d %d for %d %d\n", hoffset
, voffset
, h_idx
, v_idx
);
1945 static bool drm_target_preferred(struct drm_fb_helper
*fb_helper
,
1946 struct drm_display_mode
**modes
,
1947 struct drm_fb_offset
*offsets
,
1948 bool *enabled
, int width
, int height
)
1950 struct drm_fb_helper_connector
*fb_helper_conn
;
1952 uint64_t conn_configured
= 0, mask
;
1954 mask
= (1 << fb_helper
->connector_count
) - 1;
1956 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1957 fb_helper_conn
= fb_helper
->connector_info
[i
];
1959 if (conn_configured
& (1 << i
))
1962 if (enabled
[i
] == false) {
1963 conn_configured
|= (1 << i
);
1967 /* first pass over all the untiled connectors */
1968 if (tile_pass
== 0 && fb_helper_conn
->connector
->has_tile
)
1971 if (tile_pass
== 1) {
1972 if (fb_helper_conn
->connector
->tile_h_loc
!= 0 ||
1973 fb_helper_conn
->connector
->tile_v_loc
!= 0)
1977 if (fb_helper_conn
->connector
->tile_h_loc
!= tile_pass
-1 &&
1978 fb_helper_conn
->connector
->tile_v_loc
!= tile_pass
- 1)
1979 /* if this tile_pass doesn't cover any of the tiles - keep going */
1982 /* find the tile offsets for this pass - need
1983 to find all tiles left and above */
1984 drm_get_tile_offsets(fb_helper
, modes
, offsets
,
1985 i
, fb_helper_conn
->connector
->tile_h_loc
, fb_helper_conn
->connector
->tile_v_loc
);
1987 DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n",
1988 fb_helper_conn
->connector
->base
.id
);
1990 /* got for command line mode first */
1991 modes
[i
] = drm_pick_cmdline_mode(fb_helper_conn
, width
, height
);
1993 DRM_DEBUG_KMS("looking for preferred mode on connector %d %d\n",
1994 fb_helper_conn
->connector
->base
.id
, fb_helper_conn
->connector
->tile_group
? fb_helper_conn
->connector
->tile_group
->id
: 0);
1995 modes
[i
] = drm_has_preferred_mode(fb_helper_conn
, width
, height
);
1997 /* No preferred modes, pick one off the list */
1998 if (!modes
[i
] && !list_empty(&fb_helper_conn
->connector
->modes
)) {
1999 list_for_each_entry(modes
[i
], &fb_helper_conn
->connector
->modes
, head
)
2002 DRM_DEBUG_KMS("found mode %s\n", modes
[i
] ? modes
[i
]->name
:
2004 conn_configured
|= (1 << i
);
2007 if ((conn_configured
& mask
) != mask
) {
2014 static int drm_pick_crtcs(struct drm_fb_helper
*fb_helper
,
2015 struct drm_fb_helper_crtc
**best_crtcs
,
2016 struct drm_display_mode
**modes
,
2017 int n
, int width
, int height
)
2020 struct drm_connector
*connector
;
2021 const struct drm_connector_helper_funcs
*connector_funcs
;
2022 struct drm_encoder
*encoder
;
2023 int my_score
, best_score
, score
;
2024 struct drm_fb_helper_crtc
**crtcs
, *crtc
;
2025 struct drm_fb_helper_connector
*fb_helper_conn
;
2027 if (n
== fb_helper
->connector_count
)
2030 fb_helper_conn
= fb_helper
->connector_info
[n
];
2031 connector
= fb_helper_conn
->connector
;
2033 best_crtcs
[n
] = NULL
;
2034 best_score
= drm_pick_crtcs(fb_helper
, best_crtcs
, modes
, n
+1, width
, height
);
2035 if (modes
[n
] == NULL
)
2038 crtcs
= kzalloc(fb_helper
->connector_count
*
2039 sizeof(struct drm_fb_helper_crtc
*), GFP_KERNEL
);
2044 if (connector
->status
== connector_status_connected
)
2046 if (drm_has_cmdline_mode(fb_helper_conn
))
2048 if (drm_has_preferred_mode(fb_helper_conn
, width
, height
))
2051 connector_funcs
= connector
->helper_private
;
2052 encoder
= connector_funcs
->best_encoder(connector
);
2056 /* select a crtc for this connector and then attempt to configure
2057 remaining connectors */
2058 for (c
= 0; c
< fb_helper
->crtc_count
; c
++) {
2059 crtc
= &fb_helper
->crtc_info
[c
];
2061 if ((encoder
->possible_crtcs
& (1 << c
)) == 0)
2064 for (o
= 0; o
< n
; o
++)
2065 if (best_crtcs
[o
] == crtc
)
2069 /* ignore cloning unless only a single crtc */
2070 if (fb_helper
->crtc_count
> 1)
2073 if (!drm_mode_equal(modes
[o
], modes
[n
]))
2078 memcpy(crtcs
, best_crtcs
, n
* sizeof(struct drm_fb_helper_crtc
*));
2079 score
= my_score
+ drm_pick_crtcs(fb_helper
, crtcs
, modes
, n
+ 1,
2081 if (score
> best_score
) {
2083 memcpy(best_crtcs
, crtcs
,
2084 fb_helper
->connector_count
*
2085 sizeof(struct drm_fb_helper_crtc
*));
2093 static void drm_setup_crtcs(struct drm_fb_helper
*fb_helper
)
2095 struct drm_device
*dev
= fb_helper
->dev
;
2096 struct drm_fb_helper_crtc
**crtcs
;
2097 struct drm_display_mode
**modes
;
2098 struct drm_fb_offset
*offsets
;
2099 struct drm_mode_set
*modeset
;
2104 DRM_DEBUG_KMS("\n");
2106 width
= dev
->mode_config
.max_width
;
2107 height
= dev
->mode_config
.max_height
;
2109 crtcs
= kcalloc(fb_helper
->connector_count
,
2110 sizeof(struct drm_fb_helper_crtc
*), GFP_KERNEL
);
2111 modes
= kcalloc(fb_helper
->connector_count
,
2112 sizeof(struct drm_display_mode
*), GFP_KERNEL
);
2113 offsets
= kcalloc(fb_helper
->connector_count
,
2114 sizeof(struct drm_fb_offset
), GFP_KERNEL
);
2115 enabled
= kcalloc(fb_helper
->connector_count
,
2116 sizeof(bool), GFP_KERNEL
);
2117 if (!crtcs
|| !modes
|| !enabled
|| !offsets
) {
2118 DRM_ERROR("Memory allocation failed\n");
2123 drm_enable_connectors(fb_helper
, enabled
);
2125 if (!(fb_helper
->funcs
->initial_config
&&
2126 fb_helper
->funcs
->initial_config(fb_helper
, crtcs
, modes
,
2128 enabled
, width
, height
))) {
2129 memset(modes
, 0, fb_helper
->connector_count
*sizeof(modes
[0]));
2130 memset(crtcs
, 0, fb_helper
->connector_count
*sizeof(crtcs
[0]));
2131 memset(offsets
, 0, fb_helper
->connector_count
*sizeof(offsets
[0]));
2133 if (!drm_target_cloned(fb_helper
, modes
, offsets
,
2134 enabled
, width
, height
) &&
2135 !drm_target_preferred(fb_helper
, modes
, offsets
,
2136 enabled
, width
, height
))
2137 DRM_ERROR("Unable to find initial modes\n");
2139 DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n",
2142 drm_pick_crtcs(fb_helper
, crtcs
, modes
, 0, width
, height
);
2145 /* need to set the modesets up here for use later */
2146 /* fill out the connector<->crtc mappings into the modesets */
2147 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
2148 modeset
= &fb_helper
->crtc_info
[i
].mode_set
;
2149 modeset
->num_connectors
= 0;
2153 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
2154 struct drm_display_mode
*mode
= modes
[i
];
2155 struct drm_fb_helper_crtc
*fb_crtc
= crtcs
[i
];
2156 struct drm_fb_offset
*offset
= &offsets
[i
];
2157 modeset
= &fb_crtc
->mode_set
;
2159 if (mode
&& fb_crtc
) {
2160 DRM_DEBUG_KMS("desired mode %s set on crtc %d (%d,%d)\n",
2161 mode
->name
, fb_crtc
->mode_set
.crtc
->base
.id
, offset
->x
, offset
->y
);
2162 fb_crtc
->desired_mode
= mode
;
2163 fb_crtc
->x
= offset
->x
;
2164 fb_crtc
->y
= offset
->y
;
2166 drm_mode_destroy(dev
, modeset
->mode
);
2167 modeset
->mode
= drm_mode_duplicate(dev
,
2168 fb_crtc
->desired_mode
);
2169 modeset
->connectors
[modeset
->num_connectors
++] = fb_helper
->connector_info
[i
]->connector
;
2170 modeset
->fb
= fb_helper
->fb
;
2171 modeset
->x
= offset
->x
;
2172 modeset
->y
= offset
->y
;
2176 /* Clear out any old modes if there are no more connected outputs. */
2177 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
2178 modeset
= &fb_helper
->crtc_info
[i
].mode_set
;
2179 if (modeset
->num_connectors
== 0) {
2180 BUG_ON(modeset
->fb
);
2182 drm_mode_destroy(dev
, modeset
->mode
);
2183 modeset
->mode
= NULL
;
2194 * drm_fb_helper_initial_config - setup a sane initial connector configuration
2195 * @fb_helper: fb_helper device struct
2196 * @bpp_sel: bpp value to use for the framebuffer configuration
2198 * Scans the CRTCs and connectors and tries to put together an initial setup.
2199 * At the moment, this is a cloned configuration across all heads with
2200 * a new framebuffer object as the backing store.
2202 * Note that this also registers the fbdev and so allows userspace to call into
2203 * the driver through the fbdev interfaces.
2205 * This function will call down into the ->fb_probe callback to let
2206 * the driver allocate and initialize the fbdev info structure and the drm
2207 * framebuffer used to back the fbdev. drm_fb_helper_fill_var() and
2208 * drm_fb_helper_fill_fix() are provided as helpers to setup simple default
2209 * values for the fbdev info structure.
2213 * When you have fbcon support built-in or already loaded, this function will do
2214 * a full modeset to setup the fbdev console. Due to locking misdesign in the
2215 * VT/fbdev subsystem that entire modeset sequence has to be done while holding
2216 * console_lock. Until console_unlock is called no dmesg lines will be sent out
2217 * to consoles, not even serial console. This means when your driver crashes,
2218 * you will see absolutely nothing else but a system stuck in this function,
2219 * with no further output. Any kind of printk() you place within your own driver
2220 * or in the drm core modeset code will also never show up.
2222 * Standard debug practice is to run the fbcon setup without taking the
2223 * console_lock as a hack, to be able to see backtraces and crashes on the
2224 * serial line. This can be done by setting the fb.lockless_register_fb=1 kernel
2227 * The other option is to just disable fbdev emulation since very likely the
2228 * first modeset from userspace will crash in the same way, and is even easier
2229 * to debug. This can be done by setting the drm_kms_helper.fbdev_emulation=0
2230 * kernel cmdline option.
2233 * Zero if everything went ok, nonzero otherwise.
2235 int drm_fb_helper_initial_config(struct drm_fb_helper
*fb_helper
, int bpp_sel
)
2237 struct drm_device
*dev
= fb_helper
->dev
;
2240 if (!drm_fbdev_emulation
)
2243 mutex_lock(&dev
->mode_config
.mutex
);
2244 count
= drm_fb_helper_probe_connector_modes(fb_helper
,
2245 dev
->mode_config
.max_width
,
2246 dev
->mode_config
.max_height
);
2247 mutex_unlock(&dev
->mode_config
.mutex
);
2249 * we shouldn't end up with no modes here.
2252 dev_info(fb_helper
->dev
->dev
, "No connectors reported connected with modes\n");
2254 drm_setup_crtcs(fb_helper
);
2256 return drm_fb_helper_single_fb_probe(fb_helper
, bpp_sel
);
2258 EXPORT_SYMBOL(drm_fb_helper_initial_config
);
2261 * drm_fb_helper_hotplug_event - respond to a hotplug notification by
2262 * probing all the outputs attached to the fb
2263 * @fb_helper: the drm_fb_helper
2265 * Scan the connectors attached to the fb_helper and try to put together a
2266 * setup after *notification of a change in output configuration.
2268 * Called at runtime, takes the mode config locks to be able to check/change the
2269 * modeset configuration. Must be run from process context (which usually means
2270 * either the output polling work or a work item launched from the driver's
2271 * hotplug interrupt).
2273 * Note that drivers may call this even before calling
2274 * drm_fb_helper_initial_config but only after drm_fb_helper_init. This allows
2275 * for a race-free fbcon setup and will make sure that the fbdev emulation will
2276 * not miss any hotplug events.
2279 * 0 on success and a non-zero error code otherwise.
2281 int drm_fb_helper_hotplug_event(struct drm_fb_helper
*fb_helper
)
2283 struct drm_device
*dev
= fb_helper
->dev
;
2284 u32 max_width
, max_height
;
2286 if (!drm_fbdev_emulation
)
2289 mutex_lock(&fb_helper
->dev
->mode_config
.mutex
);
2290 if (!fb_helper
->fb
|| !drm_fb_helper_is_bound(fb_helper
)) {
2291 fb_helper
->delayed_hotplug
= true;
2292 mutex_unlock(&fb_helper
->dev
->mode_config
.mutex
);
2295 DRM_DEBUG_KMS("\n");
2297 max_width
= fb_helper
->fb
->width
;
2298 max_height
= fb_helper
->fb
->height
;
2300 drm_fb_helper_probe_connector_modes(fb_helper
, max_width
, max_height
);
2301 mutex_unlock(&fb_helper
->dev
->mode_config
.mutex
);
2303 drm_modeset_lock_all(dev
);
2304 drm_setup_crtcs(fb_helper
);
2305 drm_modeset_unlock_all(dev
);
2306 drm_fb_helper_set_par(fb_helper
->fbdev
);
2310 EXPORT_SYMBOL(drm_fb_helper_hotplug_event
);
2312 /* The Kconfig DRM_KMS_HELPER selects FRAMEBUFFER_CONSOLE (if !EXPERT)
2313 * but the module doesn't depend on any fb console symbols. At least
2314 * attempt to load fbcon to avoid leaving the system without a usable console.
2316 int __init
drm_fb_helper_modinit(void)
2318 #if defined(CONFIG_FRAMEBUFFER_CONSOLE_MODULE) && !defined(CONFIG_EXPERT)
2319 const char *name
= "fbcon";
2320 struct module
*fbcon
;
2322 mutex_lock(&module_mutex
);
2323 fbcon
= find_module(name
);
2324 mutex_unlock(&module_mutex
);
2327 request_module_nowait(name
);
2331 EXPORT_SYMBOL(drm_fb_helper_modinit
);