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>
30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32 #include <linux/kernel.h>
33 #include <linux/sysrq.h>
34 #include <linux/slab.h>
35 #include <linux/module.h>
37 #include <drm/drm_crtc.h>
38 #include <drm/drm_fb_helper.h>
39 #include <drm/drm_crtc_helper.h>
40 #include <drm/drm_atomic.h>
41 #include <drm/drm_atomic_helper.h>
43 static bool drm_fbdev_emulation
= true;
44 module_param_named(fbdev_emulation
, drm_fbdev_emulation
, bool, 0600);
45 MODULE_PARM_DESC(fbdev_emulation
,
46 "Enable legacy fbdev emulation [default=true]");
48 static LIST_HEAD(kernel_fb_helper_list
);
53 * The fb helper functions are useful to provide an fbdev on top of a drm kernel
54 * mode setting driver. They can be used mostly independently from the crtc
55 * helper functions used by many drivers to implement the kernel mode setting
58 * Initialization is done as a four-step process with drm_fb_helper_prepare(),
59 * drm_fb_helper_init(), drm_fb_helper_single_add_all_connectors() and
60 * drm_fb_helper_initial_config(). Drivers with fancier requirements than the
61 * default behaviour can override the third step with their own code.
62 * Teardown is done with drm_fb_helper_fini().
64 * At runtime drivers should restore the fbdev console by calling
65 * drm_fb_helper_restore_fbdev_mode_unlocked() from their ->lastclose callback.
66 * They should also notify the fb helper code from updates to the output
67 * configuration by calling drm_fb_helper_hotplug_event(). For easier
68 * integration with the output polling code in drm_crtc_helper.c the modeset
69 * code provides a ->output_poll_changed callback.
71 * All other functions exported by the fb helper library can be used to
72 * implement the fbdev driver interface by the driver.
74 * It is possible, though perhaps somewhat tricky, to implement race-free
75 * hotplug detection using the fbdev helpers. The drm_fb_helper_prepare()
76 * helper must be called first to initialize the minimum required to make
77 * hotplug detection work. Drivers also need to make sure to properly set up
78 * the dev->mode_config.funcs member. After calling drm_kms_helper_poll_init()
79 * it is safe to enable interrupts and start processing hotplug events. At the
80 * same time, drivers should initialize all modeset objects such as CRTCs,
81 * encoders and connectors. To finish up the fbdev helper initialization, the
82 * drm_fb_helper_init() function is called. To probe for all attached displays
83 * and set up an initial configuration using the detected hardware, drivers
84 * should call drm_fb_helper_single_add_all_connectors() followed by
85 * drm_fb_helper_initial_config().
87 * If &drm_framebuffer_funcs ->dirty is set, the
88 * drm_fb_helper_{cfb,sys}_{write,fillrect,copyarea,imageblit} functions will
89 * accumulate changes and schedule &drm_fb_helper ->dirty_work to run right
90 * away. This worker then calls the dirty() function ensuring that it will
91 * always run in process context since the fb_*() function could be running in
92 * atomic context. If drm_fb_helper_deferred_io() is used as the deferred_io
93 * callback it will also schedule dirty_work with the damage collected from the
98 * drm_fb_helper_single_add_all_connectors() - add all connectors to fbdev
100 * @fb_helper: fbdev initialized with drm_fb_helper_init
102 * This functions adds all the available connectors for use with the given
103 * fb_helper. This is a separate step to allow drivers to freely assign
104 * connectors to the fbdev, e.g. if some are reserved for special purposes or
105 * not adequate to be used for the fbcon.
107 * This function is protected against concurrent connector hotadds/removals
108 * using drm_fb_helper_add_one_connector() and
109 * drm_fb_helper_remove_one_connector().
111 int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper
*fb_helper
)
113 struct drm_device
*dev
= fb_helper
->dev
;
114 struct drm_connector
*connector
;
117 if (!drm_fbdev_emulation
)
120 mutex_lock(&dev
->mode_config
.mutex
);
121 drm_for_each_connector(connector
, dev
) {
122 ret
= drm_fb_helper_add_one_connector(fb_helper
, connector
);
127 mutex_unlock(&dev
->mode_config
.mutex
);
130 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
131 kfree(fb_helper
->connector_info
[i
]);
132 fb_helper
->connector_info
[i
] = NULL
;
134 fb_helper
->connector_count
= 0;
135 mutex_unlock(&dev
->mode_config
.mutex
);
139 EXPORT_SYMBOL(drm_fb_helper_single_add_all_connectors
);
141 int drm_fb_helper_add_one_connector(struct drm_fb_helper
*fb_helper
, struct drm_connector
*connector
)
143 struct drm_fb_helper_connector
**temp
;
144 struct drm_fb_helper_connector
*fb_helper_connector
;
146 if (!drm_fbdev_emulation
)
149 WARN_ON(!mutex_is_locked(&fb_helper
->dev
->mode_config
.mutex
));
150 if (fb_helper
->connector_count
+ 1 > fb_helper
->connector_info_alloc_count
) {
151 temp
= krealloc(fb_helper
->connector_info
, sizeof(struct drm_fb_helper_connector
*) * (fb_helper
->connector_count
+ 1), GFP_KERNEL
);
155 fb_helper
->connector_info_alloc_count
= fb_helper
->connector_count
+ 1;
156 fb_helper
->connector_info
= temp
;
160 fb_helper_connector
= kzalloc(sizeof(struct drm_fb_helper_connector
), GFP_KERNEL
);
161 if (!fb_helper_connector
)
164 drm_connector_reference(connector
);
165 fb_helper_connector
->connector
= connector
;
166 fb_helper
->connector_info
[fb_helper
->connector_count
++] = fb_helper_connector
;
169 EXPORT_SYMBOL(drm_fb_helper_add_one_connector
);
171 int drm_fb_helper_remove_one_connector(struct drm_fb_helper
*fb_helper
,
172 struct drm_connector
*connector
)
174 struct drm_fb_helper_connector
*fb_helper_connector
;
177 if (!drm_fbdev_emulation
)
180 WARN_ON(!mutex_is_locked(&fb_helper
->dev
->mode_config
.mutex
));
182 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
183 if (fb_helper
->connector_info
[i
]->connector
== connector
)
187 if (i
== fb_helper
->connector_count
)
189 fb_helper_connector
= fb_helper
->connector_info
[i
];
190 drm_connector_unreference(fb_helper_connector
->connector
);
192 for (j
= i
+ 1; j
< fb_helper
->connector_count
; j
++) {
193 fb_helper
->connector_info
[j
- 1] = fb_helper
->connector_info
[j
];
195 fb_helper
->connector_count
--;
196 kfree(fb_helper_connector
);
200 EXPORT_SYMBOL(drm_fb_helper_remove_one_connector
);
202 static void drm_fb_helper_save_lut_atomic(struct drm_crtc
*crtc
, struct drm_fb_helper
*helper
)
204 uint16_t *r_base
, *g_base
, *b_base
;
207 if (helper
->funcs
->gamma_get
== NULL
)
210 r_base
= crtc
->gamma_store
;
211 g_base
= r_base
+ crtc
->gamma_size
;
212 b_base
= g_base
+ crtc
->gamma_size
;
214 for (i
= 0; i
< crtc
->gamma_size
; i
++)
215 helper
->funcs
->gamma_get(crtc
, &r_base
[i
], &g_base
[i
], &b_base
[i
], i
);
218 static void drm_fb_helper_restore_lut_atomic(struct drm_crtc
*crtc
)
220 uint16_t *r_base
, *g_base
, *b_base
;
222 if (crtc
->funcs
->gamma_set
== NULL
)
225 r_base
= crtc
->gamma_store
;
226 g_base
= r_base
+ crtc
->gamma_size
;
227 b_base
= g_base
+ crtc
->gamma_size
;
229 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, 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
;
251 drm_fb_helper_save_lut_atomic(mode_set
->crtc
, helper
);
252 funcs
->mode_set_base_atomic(mode_set
->crtc
,
256 ENTER_ATOMIC_MODE_SET
);
262 EXPORT_SYMBOL(drm_fb_helper_debug_enter
);
264 /* Find the real fb for a given fb helper CRTC */
265 static struct drm_framebuffer
*drm_mode_config_fb(struct drm_crtc
*crtc
)
267 struct drm_device
*dev
= crtc
->dev
;
270 drm_for_each_crtc(c
, dev
) {
271 if (crtc
->base
.id
== c
->base
.id
)
272 return c
->primary
->fb
;
279 * drm_fb_helper_debug_leave - implementation for ->fb_debug_leave
280 * @info: fbdev registered by the helper
282 int drm_fb_helper_debug_leave(struct fb_info
*info
)
284 struct drm_fb_helper
*helper
= info
->par
;
285 struct drm_crtc
*crtc
;
286 const struct drm_crtc_helper_funcs
*funcs
;
287 struct drm_framebuffer
*fb
;
290 for (i
= 0; i
< helper
->crtc_count
; i
++) {
291 struct drm_mode_set
*mode_set
= &helper
->crtc_info
[i
].mode_set
;
292 crtc
= mode_set
->crtc
;
293 funcs
= crtc
->helper_private
;
294 fb
= drm_mode_config_fb(crtc
);
300 DRM_ERROR("no fb to restore??\n");
304 drm_fb_helper_restore_lut_atomic(mode_set
->crtc
);
305 funcs
->mode_set_base_atomic(mode_set
->crtc
, fb
, crtc
->x
,
306 crtc
->y
, LEAVE_ATOMIC_MODE_SET
);
311 EXPORT_SYMBOL(drm_fb_helper_debug_leave
);
313 static int restore_fbdev_mode_atomic(struct drm_fb_helper
*fb_helper
)
315 struct drm_device
*dev
= fb_helper
->dev
;
316 struct drm_plane
*plane
;
317 struct drm_atomic_state
*state
;
321 state
= drm_atomic_state_alloc(dev
);
325 state
->acquire_ctx
= dev
->mode_config
.acquire_ctx
;
328 drm_for_each_plane(plane
, dev
) {
329 struct drm_plane_state
*plane_state
;
331 plane_state
= drm_atomic_get_plane_state(state
, plane
);
332 if (IS_ERR(plane_state
)) {
333 ret
= PTR_ERR(plane_state
);
337 plane_state
->rotation
= DRM_ROTATE_0
;
339 plane
->old_fb
= plane
->fb
;
340 plane_mask
|= 1 << drm_plane_index(plane
);
342 /* disable non-primary: */
343 if (plane
->type
== DRM_PLANE_TYPE_PRIMARY
)
346 ret
= __drm_atomic_helper_disable_plane(plane
, plane_state
);
351 for(i
= 0; i
< fb_helper
->crtc_count
; i
++) {
352 struct drm_mode_set
*mode_set
= &fb_helper
->crtc_info
[i
].mode_set
;
354 ret
= __drm_atomic_helper_set_config(mode_set
, state
);
359 ret
= drm_atomic_commit(state
);
362 drm_atomic_clean_old_fb(dev
, plane_mask
, ret
);
368 drm_atomic_state_free(state
);
373 drm_atomic_state_clear(state
);
374 drm_atomic_legacy_backoff(state
);
379 static int restore_fbdev_mode(struct drm_fb_helper
*fb_helper
)
381 struct drm_device
*dev
= fb_helper
->dev
;
382 struct drm_plane
*plane
;
385 drm_warn_on_modeset_not_all_locked(dev
);
387 if (dev
->mode_config
.funcs
->atomic_commit
)
388 return restore_fbdev_mode_atomic(fb_helper
);
390 drm_for_each_plane(plane
, dev
) {
391 if (plane
->type
!= DRM_PLANE_TYPE_PRIMARY
)
392 drm_plane_force_disable(plane
);
394 if (dev
->mode_config
.rotation_property
) {
395 drm_mode_plane_set_obj_prop(plane
,
396 dev
->mode_config
.rotation_property
,
401 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
402 struct drm_mode_set
*mode_set
= &fb_helper
->crtc_info
[i
].mode_set
;
403 struct drm_crtc
*crtc
= mode_set
->crtc
;
406 if (crtc
->funcs
->cursor_set2
) {
407 ret
= crtc
->funcs
->cursor_set2(crtc
, NULL
, 0, 0, 0, 0, 0);
410 } else if (crtc
->funcs
->cursor_set
) {
411 ret
= crtc
->funcs
->cursor_set(crtc
, NULL
, 0, 0, 0);
416 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. */
466 if (lockless_dereference(dev
->master
))
469 drm_for_each_crtc(crtc
, dev
) {
470 if (crtc
->primary
->fb
)
472 if (crtc
->primary
->fb
== fb_helper
->fb
)
476 if (bound
< crtcs_bound
)
482 #ifdef CONFIG_MAGIC_SYSRQ
484 * restore fbcon display for all kms driver's using this helper, used for sysrq
485 * and panic handling.
487 static bool drm_fb_helper_force_kernel_mode(void)
489 bool ret
, error
= false;
490 struct drm_fb_helper
*helper
;
492 if (list_empty(&kernel_fb_helper_list
))
495 list_for_each_entry(helper
, &kernel_fb_helper_list
, kernel_fb_list
) {
496 struct drm_device
*dev
= helper
->dev
;
498 if (dev
->switch_power_state
== DRM_SWITCH_POWER_OFF
)
501 drm_modeset_lock_all(dev
);
502 ret
= restore_fbdev_mode(helper
);
505 drm_modeset_unlock_all(dev
);
510 static void drm_fb_helper_restore_work_fn(struct work_struct
*ignored
)
513 ret
= drm_fb_helper_force_kernel_mode();
515 DRM_ERROR("Failed to restore crtc configuration\n");
517 static DECLARE_WORK(drm_fb_helper_restore_work
, drm_fb_helper_restore_work_fn
);
519 static void drm_fb_helper_sysrq(int dummy1
)
521 schedule_work(&drm_fb_helper_restore_work
);
524 static struct sysrq_key_op sysrq_drm_fb_helper_restore_op
= {
525 .handler
= drm_fb_helper_sysrq
,
526 .help_msg
= "force-fb(V)",
527 .action_msg
= "Restore framebuffer console",
530 static struct sysrq_key_op sysrq_drm_fb_helper_restore_op
= { };
533 static void drm_fb_helper_dpms(struct fb_info
*info
, int dpms_mode
)
535 struct drm_fb_helper
*fb_helper
= info
->par
;
536 struct drm_device
*dev
= fb_helper
->dev
;
537 struct drm_crtc
*crtc
;
538 struct drm_connector
*connector
;
542 * For each CRTC in this fb, turn the connectors on/off.
544 drm_modeset_lock_all(dev
);
545 if (!drm_fb_helper_is_bound(fb_helper
)) {
546 drm_modeset_unlock_all(dev
);
550 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
551 crtc
= fb_helper
->crtc_info
[i
].mode_set
.crtc
;
556 /* Walk the connectors & encoders on this fb turning them on/off */
557 for (j
= 0; j
< fb_helper
->connector_count
; j
++) {
558 connector
= fb_helper
->connector_info
[j
]->connector
;
559 connector
->funcs
->dpms(connector
, dpms_mode
);
560 drm_object_property_set_value(&connector
->base
,
561 dev
->mode_config
.dpms_property
, dpms_mode
);
564 drm_modeset_unlock_all(dev
);
568 * drm_fb_helper_blank - implementation for ->fb_blank
569 * @blank: desired blanking state
570 * @info: fbdev registered by the helper
572 int drm_fb_helper_blank(int blank
, struct fb_info
*info
)
574 if (oops_in_progress
)
578 /* Display: On; HSync: On, VSync: On */
579 case FB_BLANK_UNBLANK
:
580 drm_fb_helper_dpms(info
, DRM_MODE_DPMS_ON
);
582 /* Display: Off; HSync: On, VSync: On */
583 case FB_BLANK_NORMAL
:
584 drm_fb_helper_dpms(info
, DRM_MODE_DPMS_STANDBY
);
586 /* Display: Off; HSync: Off, VSync: On */
587 case FB_BLANK_HSYNC_SUSPEND
:
588 drm_fb_helper_dpms(info
, DRM_MODE_DPMS_STANDBY
);
590 /* Display: Off; HSync: On, VSync: Off */
591 case FB_BLANK_VSYNC_SUSPEND
:
592 drm_fb_helper_dpms(info
, DRM_MODE_DPMS_SUSPEND
);
594 /* Display: Off; HSync: Off, VSync: Off */
595 case FB_BLANK_POWERDOWN
:
596 drm_fb_helper_dpms(info
, DRM_MODE_DPMS_OFF
);
601 EXPORT_SYMBOL(drm_fb_helper_blank
);
603 static void drm_fb_helper_crtc_free(struct drm_fb_helper
*helper
)
607 for (i
= 0; i
< helper
->connector_count
; i
++) {
608 drm_connector_unreference(helper
->connector_info
[i
]->connector
);
609 kfree(helper
->connector_info
[i
]);
611 kfree(helper
->connector_info
);
612 for (i
= 0; i
< helper
->crtc_count
; i
++) {
613 kfree(helper
->crtc_info
[i
].mode_set
.connectors
);
614 if (helper
->crtc_info
[i
].mode_set
.mode
)
615 drm_mode_destroy(helper
->dev
, helper
->crtc_info
[i
].mode_set
.mode
);
617 kfree(helper
->crtc_info
);
620 static void drm_fb_helper_dirty_work(struct work_struct
*work
)
622 struct drm_fb_helper
*helper
= container_of(work
, struct drm_fb_helper
,
624 struct drm_clip_rect
*clip
= &helper
->dirty_clip
;
625 struct drm_clip_rect clip_copy
;
628 spin_lock_irqsave(&helper
->dirty_lock
, flags
);
630 clip
->x1
= clip
->y1
= ~0;
631 clip
->x2
= clip
->y2
= 0;
632 spin_unlock_irqrestore(&helper
->dirty_lock
, flags
);
634 helper
->fb
->funcs
->dirty(helper
->fb
, NULL
, 0, 0, &clip_copy
, 1);
638 * drm_fb_helper_prepare - setup a drm_fb_helper structure
640 * @helper: driver-allocated fbdev helper structure to set up
641 * @funcs: pointer to structure of functions associate with this helper
643 * Sets up the bare minimum to make the framebuffer helper usable. This is
644 * useful to implement race-free initialization of the polling helpers.
646 void drm_fb_helper_prepare(struct drm_device
*dev
, struct drm_fb_helper
*helper
,
647 const struct drm_fb_helper_funcs
*funcs
)
649 INIT_LIST_HEAD(&helper
->kernel_fb_list
);
650 spin_lock_init(&helper
->dirty_lock
);
651 INIT_WORK(&helper
->dirty_work
, drm_fb_helper_dirty_work
);
652 helper
->dirty_clip
.x1
= helper
->dirty_clip
.y1
= ~0;
653 helper
->funcs
= funcs
;
656 EXPORT_SYMBOL(drm_fb_helper_prepare
);
659 * drm_fb_helper_init - initialize a drm_fb_helper structure
661 * @fb_helper: driver-allocated fbdev helper structure to initialize
662 * @crtc_count: maximum number of crtcs to support in this fbdev emulation
663 * @max_conn_count: max connector count
665 * This allocates the structures for the fbdev helper with the given limits.
666 * Note that this won't yet touch the hardware (through the driver interfaces)
667 * nor register the fbdev. This is only done in drm_fb_helper_initial_config()
668 * to allow driver writes more control over the exact init sequence.
670 * Drivers must call drm_fb_helper_prepare() before calling this function.
673 * Zero if everything went ok, nonzero otherwise.
675 int drm_fb_helper_init(struct drm_device
*dev
,
676 struct drm_fb_helper
*fb_helper
,
677 int crtc_count
, int max_conn_count
)
679 struct drm_crtc
*crtc
;
682 if (!drm_fbdev_emulation
)
688 fb_helper
->crtc_info
= kcalloc(crtc_count
, sizeof(struct drm_fb_helper_crtc
), GFP_KERNEL
);
689 if (!fb_helper
->crtc_info
)
692 fb_helper
->crtc_count
= crtc_count
;
693 fb_helper
->connector_info
= kcalloc(dev
->mode_config
.num_connector
, sizeof(struct drm_fb_helper_connector
*), GFP_KERNEL
);
694 if (!fb_helper
->connector_info
) {
695 kfree(fb_helper
->crtc_info
);
698 fb_helper
->connector_info_alloc_count
= dev
->mode_config
.num_connector
;
699 fb_helper
->connector_count
= 0;
701 for (i
= 0; i
< crtc_count
; i
++) {
702 fb_helper
->crtc_info
[i
].mode_set
.connectors
=
703 kcalloc(max_conn_count
,
704 sizeof(struct drm_connector
*),
707 if (!fb_helper
->crtc_info
[i
].mode_set
.connectors
)
709 fb_helper
->crtc_info
[i
].mode_set
.num_connectors
= 0;
713 drm_for_each_crtc(crtc
, dev
) {
714 fb_helper
->crtc_info
[i
].mode_set
.crtc
= crtc
;
720 drm_fb_helper_crtc_free(fb_helper
);
723 EXPORT_SYMBOL(drm_fb_helper_init
);
726 * drm_fb_helper_alloc_fbi - allocate fb_info and some of its members
727 * @fb_helper: driver-allocated fbdev helper
729 * A helper to alloc fb_info and the members cmap and apertures. Called
730 * by the driver within the fb_probe fb_helper callback function.
733 * fb_info pointer if things went okay, pointer containing error code
736 struct fb_info
*drm_fb_helper_alloc_fbi(struct drm_fb_helper
*fb_helper
)
738 struct device
*dev
= fb_helper
->dev
->dev
;
739 struct fb_info
*info
;
742 info
= framebuffer_alloc(0, dev
);
744 return ERR_PTR(-ENOMEM
);
746 ret
= fb_alloc_cmap(&info
->cmap
, 256, 0);
750 info
->apertures
= alloc_apertures(1);
751 if (!info
->apertures
) {
756 fb_helper
->fbdev
= info
;
761 fb_dealloc_cmap(&info
->cmap
);
763 framebuffer_release(info
);
766 EXPORT_SYMBOL(drm_fb_helper_alloc_fbi
);
769 * drm_fb_helper_unregister_fbi - unregister fb_info framebuffer device
770 * @fb_helper: driver-allocated fbdev helper
772 * A wrapper around unregister_framebuffer, to release the fb_info
775 void drm_fb_helper_unregister_fbi(struct drm_fb_helper
*fb_helper
)
777 if (fb_helper
&& fb_helper
->fbdev
)
778 unregister_framebuffer(fb_helper
->fbdev
);
780 EXPORT_SYMBOL(drm_fb_helper_unregister_fbi
);
783 * drm_fb_helper_release_fbi - dealloc fb_info and its members
784 * @fb_helper: driver-allocated fbdev helper
786 * A helper to free memory taken by fb_info and the members cmap and
789 void drm_fb_helper_release_fbi(struct drm_fb_helper
*fb_helper
)
792 struct fb_info
*info
= fb_helper
->fbdev
;
796 fb_dealloc_cmap(&info
->cmap
);
797 framebuffer_release(info
);
800 fb_helper
->fbdev
= NULL
;
803 EXPORT_SYMBOL(drm_fb_helper_release_fbi
);
805 void drm_fb_helper_fini(struct drm_fb_helper
*fb_helper
)
807 if (!drm_fbdev_emulation
)
810 if (!list_empty(&fb_helper
->kernel_fb_list
)) {
811 list_del(&fb_helper
->kernel_fb_list
);
812 if (list_empty(&kernel_fb_helper_list
)) {
813 unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op
);
817 drm_fb_helper_crtc_free(fb_helper
);
820 EXPORT_SYMBOL(drm_fb_helper_fini
);
823 * drm_fb_helper_unlink_fbi - wrapper around unlink_framebuffer
824 * @fb_helper: driver-allocated fbdev helper
826 * A wrapper around unlink_framebuffer implemented by fbdev core
828 void drm_fb_helper_unlink_fbi(struct drm_fb_helper
*fb_helper
)
830 if (fb_helper
&& fb_helper
->fbdev
)
831 unlink_framebuffer(fb_helper
->fbdev
);
833 EXPORT_SYMBOL(drm_fb_helper_unlink_fbi
);
835 static void drm_fb_helper_dirty(struct fb_info
*info
, u32 x
, u32 y
,
836 u32 width
, u32 height
)
838 struct drm_fb_helper
*helper
= info
->par
;
839 struct drm_clip_rect
*clip
= &helper
->dirty_clip
;
842 if (!helper
->fb
->funcs
->dirty
)
845 spin_lock_irqsave(&helper
->dirty_lock
, flags
);
846 clip
->x1
= min_t(u32
, clip
->x1
, x
);
847 clip
->y1
= min_t(u32
, clip
->y1
, y
);
848 clip
->x2
= max_t(u32
, clip
->x2
, x
+ width
);
849 clip
->y2
= max_t(u32
, clip
->y2
, y
+ height
);
850 spin_unlock_irqrestore(&helper
->dirty_lock
, flags
);
852 schedule_work(&helper
->dirty_work
);
856 * drm_fb_helper_deferred_io() - fbdev deferred_io callback function
857 * @info: fb_info struct pointer
858 * @pagelist: list of dirty mmap framebuffer pages
860 * This function is used as the &fb_deferred_io ->deferred_io
861 * callback function for flushing the fbdev mmap writes.
863 void drm_fb_helper_deferred_io(struct fb_info
*info
,
864 struct list_head
*pagelist
)
866 unsigned long start
, end
, min
, max
;
872 list_for_each_entry(page
, pagelist
, lru
) {
873 start
= page
->index
<< PAGE_SHIFT
;
874 end
= start
+ PAGE_SIZE
- 1;
875 min
= min(min
, start
);
880 y1
= min
/ info
->fix
.line_length
;
881 y2
= min_t(u32
, DIV_ROUND_UP(max
, info
->fix
.line_length
),
883 drm_fb_helper_dirty(info
, 0, y1
, info
->var
.xres
, y2
- y1
);
886 EXPORT_SYMBOL(drm_fb_helper_deferred_io
);
889 * drm_fb_helper_sys_read - wrapper around fb_sys_read
890 * @info: fb_info struct pointer
891 * @buf: userspace buffer to read from framebuffer memory
892 * @count: number of bytes to read from framebuffer memory
893 * @ppos: read offset within framebuffer memory
895 * A wrapper around fb_sys_read implemented by fbdev core
897 ssize_t
drm_fb_helper_sys_read(struct fb_info
*info
, char __user
*buf
,
898 size_t count
, loff_t
*ppos
)
900 return fb_sys_read(info
, buf
, count
, ppos
);
902 EXPORT_SYMBOL(drm_fb_helper_sys_read
);
905 * drm_fb_helper_sys_write - wrapper around fb_sys_write
906 * @info: fb_info struct pointer
907 * @buf: userspace buffer to write to framebuffer memory
908 * @count: number of bytes to write to framebuffer memory
909 * @ppos: write offset within framebuffer memory
911 * A wrapper around fb_sys_write implemented by fbdev core
913 ssize_t
drm_fb_helper_sys_write(struct fb_info
*info
, const char __user
*buf
,
914 size_t count
, loff_t
*ppos
)
918 ret
= fb_sys_write(info
, buf
, count
, ppos
);
920 drm_fb_helper_dirty(info
, 0, 0, info
->var
.xres
,
925 EXPORT_SYMBOL(drm_fb_helper_sys_write
);
928 * drm_fb_helper_sys_fillrect - wrapper around sys_fillrect
929 * @info: fbdev registered by the helper
930 * @rect: info about rectangle to fill
932 * A wrapper around sys_fillrect implemented by fbdev core
934 void drm_fb_helper_sys_fillrect(struct fb_info
*info
,
935 const struct fb_fillrect
*rect
)
937 sys_fillrect(info
, rect
);
938 drm_fb_helper_dirty(info
, rect
->dx
, rect
->dy
,
939 rect
->width
, rect
->height
);
941 EXPORT_SYMBOL(drm_fb_helper_sys_fillrect
);
944 * drm_fb_helper_sys_copyarea - wrapper around sys_copyarea
945 * @info: fbdev registered by the helper
946 * @area: info about area to copy
948 * A wrapper around sys_copyarea implemented by fbdev core
950 void drm_fb_helper_sys_copyarea(struct fb_info
*info
,
951 const struct fb_copyarea
*area
)
953 sys_copyarea(info
, area
);
954 drm_fb_helper_dirty(info
, area
->dx
, area
->dy
,
955 area
->width
, area
->height
);
957 EXPORT_SYMBOL(drm_fb_helper_sys_copyarea
);
960 * drm_fb_helper_sys_imageblit - wrapper around sys_imageblit
961 * @info: fbdev registered by the helper
962 * @image: info about image to blit
964 * A wrapper around sys_imageblit implemented by fbdev core
966 void drm_fb_helper_sys_imageblit(struct fb_info
*info
,
967 const struct fb_image
*image
)
969 sys_imageblit(info
, image
);
970 drm_fb_helper_dirty(info
, image
->dx
, image
->dy
,
971 image
->width
, image
->height
);
973 EXPORT_SYMBOL(drm_fb_helper_sys_imageblit
);
976 * drm_fb_helper_cfb_fillrect - wrapper around cfb_fillrect
977 * @info: fbdev registered by the helper
978 * @rect: info about rectangle to fill
980 * A wrapper around cfb_imageblit implemented by fbdev core
982 void drm_fb_helper_cfb_fillrect(struct fb_info
*info
,
983 const struct fb_fillrect
*rect
)
985 cfb_fillrect(info
, rect
);
986 drm_fb_helper_dirty(info
, rect
->dx
, rect
->dy
,
987 rect
->width
, rect
->height
);
989 EXPORT_SYMBOL(drm_fb_helper_cfb_fillrect
);
992 * drm_fb_helper_cfb_copyarea - wrapper around cfb_copyarea
993 * @info: fbdev registered by the helper
994 * @area: info about area to copy
996 * A wrapper around cfb_copyarea implemented by fbdev core
998 void drm_fb_helper_cfb_copyarea(struct fb_info
*info
,
999 const struct fb_copyarea
*area
)
1001 cfb_copyarea(info
, area
);
1002 drm_fb_helper_dirty(info
, area
->dx
, area
->dy
,
1003 area
->width
, area
->height
);
1005 EXPORT_SYMBOL(drm_fb_helper_cfb_copyarea
);
1008 * drm_fb_helper_cfb_imageblit - wrapper around cfb_imageblit
1009 * @info: fbdev registered by the helper
1010 * @image: info about image to blit
1012 * A wrapper around cfb_imageblit implemented by fbdev core
1014 void drm_fb_helper_cfb_imageblit(struct fb_info
*info
,
1015 const struct fb_image
*image
)
1017 cfb_imageblit(info
, image
);
1018 drm_fb_helper_dirty(info
, image
->dx
, image
->dy
,
1019 image
->width
, image
->height
);
1021 EXPORT_SYMBOL(drm_fb_helper_cfb_imageblit
);
1024 * drm_fb_helper_set_suspend - wrapper around fb_set_suspend
1025 * @fb_helper: driver-allocated fbdev helper
1026 * @state: desired state, zero to resume, non-zero to suspend
1028 * A wrapper around fb_set_suspend implemented by fbdev core
1030 void drm_fb_helper_set_suspend(struct drm_fb_helper
*fb_helper
, int state
)
1032 if (fb_helper
&& fb_helper
->fbdev
)
1033 fb_set_suspend(fb_helper
->fbdev
, state
);
1035 EXPORT_SYMBOL(drm_fb_helper_set_suspend
);
1037 static int setcolreg(struct drm_crtc
*crtc
, u16 red
, u16 green
,
1038 u16 blue
, u16 regno
, struct fb_info
*info
)
1040 struct drm_fb_helper
*fb_helper
= info
->par
;
1041 struct drm_framebuffer
*fb
= fb_helper
->fb
;
1043 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
) {
1046 /* place color in psuedopalette */
1049 palette
= (u32
*)info
->pseudo_palette
;
1050 red
>>= (16 - info
->var
.red
.length
);
1051 green
>>= (16 - info
->var
.green
.length
);
1052 blue
>>= (16 - info
->var
.blue
.length
);
1053 value
= (red
<< info
->var
.red
.offset
) |
1054 (green
<< info
->var
.green
.offset
) |
1055 (blue
<< info
->var
.blue
.offset
);
1056 if (info
->var
.transp
.length
> 0) {
1057 u32 mask
= (1 << info
->var
.transp
.length
) - 1;
1058 mask
<<= info
->var
.transp
.offset
;
1061 palette
[regno
] = value
;
1066 * The driver really shouldn't advertise pseudo/directcolor
1067 * visuals if it can't deal with the palette.
1069 if (WARN_ON(!fb_helper
->funcs
->gamma_set
||
1070 !fb_helper
->funcs
->gamma_get
))
1073 WARN_ON(fb
->bits_per_pixel
!= 8);
1075 fb_helper
->funcs
->gamma_set(crtc
, red
, green
, blue
, regno
);
1081 * drm_fb_helper_setcmap - implementation for ->fb_setcmap
1082 * @cmap: cmap to set
1083 * @info: fbdev registered by the helper
1085 int drm_fb_helper_setcmap(struct fb_cmap
*cmap
, struct fb_info
*info
)
1087 struct drm_fb_helper
*fb_helper
= info
->par
;
1088 struct drm_device
*dev
= fb_helper
->dev
;
1089 const struct drm_crtc_helper_funcs
*crtc_funcs
;
1090 u16
*red
, *green
, *blue
, *transp
;
1091 struct drm_crtc
*crtc
;
1095 if (oops_in_progress
)
1098 drm_modeset_lock_all(dev
);
1099 if (!drm_fb_helper_is_bound(fb_helper
)) {
1100 drm_modeset_unlock_all(dev
);
1104 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
1105 crtc
= fb_helper
->crtc_info
[i
].mode_set
.crtc
;
1106 crtc_funcs
= crtc
->helper_private
;
1109 green
= cmap
->green
;
1111 transp
= cmap
->transp
;
1112 start
= cmap
->start
;
1114 for (j
= 0; j
< cmap
->len
; j
++) {
1115 u16 hred
, hgreen
, hblue
, htransp
= 0xffff;
1122 htransp
= *transp
++;
1124 rc
= setcolreg(crtc
, hred
, hgreen
, hblue
, start
++, info
);
1128 if (crtc_funcs
->load_lut
)
1129 crtc_funcs
->load_lut(crtc
);
1132 drm_modeset_unlock_all(dev
);
1135 EXPORT_SYMBOL(drm_fb_helper_setcmap
);
1138 * drm_fb_helper_check_var - implementation for ->fb_check_var
1139 * @var: screeninfo to check
1140 * @info: fbdev registered by the helper
1142 int drm_fb_helper_check_var(struct fb_var_screeninfo
*var
,
1143 struct fb_info
*info
)
1145 struct drm_fb_helper
*fb_helper
= info
->par
;
1146 struct drm_framebuffer
*fb
= fb_helper
->fb
;
1149 if (var
->pixclock
!= 0 || in_dbg_master())
1152 /* Need to resize the fb object !!! */
1153 if (var
->bits_per_pixel
> fb
->bits_per_pixel
||
1154 var
->xres
> fb
->width
|| var
->yres
> fb
->height
||
1155 var
->xres_virtual
> fb
->width
|| var
->yres_virtual
> fb
->height
) {
1156 DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb "
1157 "request %dx%d-%d (virtual %dx%d) > %dx%d-%d\n",
1158 var
->xres
, var
->yres
, var
->bits_per_pixel
,
1159 var
->xres_virtual
, var
->yres_virtual
,
1160 fb
->width
, fb
->height
, fb
->bits_per_pixel
);
1164 switch (var
->bits_per_pixel
) {
1166 depth
= (var
->green
.length
== 6) ? 16 : 15;
1169 depth
= (var
->transp
.length
> 0) ? 32 : 24;
1172 depth
= var
->bits_per_pixel
;
1178 var
->red
.offset
= 0;
1179 var
->green
.offset
= 0;
1180 var
->blue
.offset
= 0;
1181 var
->red
.length
= 8;
1182 var
->green
.length
= 8;
1183 var
->blue
.length
= 8;
1184 var
->transp
.length
= 0;
1185 var
->transp
.offset
= 0;
1188 var
->red
.offset
= 10;
1189 var
->green
.offset
= 5;
1190 var
->blue
.offset
= 0;
1191 var
->red
.length
= 5;
1192 var
->green
.length
= 5;
1193 var
->blue
.length
= 5;
1194 var
->transp
.length
= 1;
1195 var
->transp
.offset
= 15;
1198 var
->red
.offset
= 11;
1199 var
->green
.offset
= 5;
1200 var
->blue
.offset
= 0;
1201 var
->red
.length
= 5;
1202 var
->green
.length
= 6;
1203 var
->blue
.length
= 5;
1204 var
->transp
.length
= 0;
1205 var
->transp
.offset
= 0;
1208 var
->red
.offset
= 16;
1209 var
->green
.offset
= 8;
1210 var
->blue
.offset
= 0;
1211 var
->red
.length
= 8;
1212 var
->green
.length
= 8;
1213 var
->blue
.length
= 8;
1214 var
->transp
.length
= 0;
1215 var
->transp
.offset
= 0;
1218 var
->red
.offset
= 16;
1219 var
->green
.offset
= 8;
1220 var
->blue
.offset
= 0;
1221 var
->red
.length
= 8;
1222 var
->green
.length
= 8;
1223 var
->blue
.length
= 8;
1224 var
->transp
.length
= 8;
1225 var
->transp
.offset
= 24;
1232 EXPORT_SYMBOL(drm_fb_helper_check_var
);
1235 * drm_fb_helper_set_par - implementation for ->fb_set_par
1236 * @info: fbdev registered by the helper
1238 * This will let fbcon do the mode init and is called at initialization time by
1239 * the fbdev core when registering the driver, and later on through the hotplug
1242 int drm_fb_helper_set_par(struct fb_info
*info
)
1244 struct drm_fb_helper
*fb_helper
= info
->par
;
1245 struct fb_var_screeninfo
*var
= &info
->var
;
1247 if (oops_in_progress
)
1250 if (var
->pixclock
!= 0) {
1251 DRM_ERROR("PIXEL CLOCK SET\n");
1255 drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper
);
1259 EXPORT_SYMBOL(drm_fb_helper_set_par
);
1261 static int pan_display_atomic(struct fb_var_screeninfo
*var
,
1262 struct fb_info
*info
)
1264 struct drm_fb_helper
*fb_helper
= info
->par
;
1265 struct drm_device
*dev
= fb_helper
->dev
;
1266 struct drm_atomic_state
*state
;
1267 struct drm_plane
*plane
;
1269 unsigned plane_mask
;
1271 state
= drm_atomic_state_alloc(dev
);
1275 state
->acquire_ctx
= dev
->mode_config
.acquire_ctx
;
1278 for(i
= 0; i
< fb_helper
->crtc_count
; i
++) {
1279 struct drm_mode_set
*mode_set
;
1281 mode_set
= &fb_helper
->crtc_info
[i
].mode_set
;
1283 mode_set
->x
= var
->xoffset
;
1284 mode_set
->y
= var
->yoffset
;
1286 ret
= __drm_atomic_helper_set_config(mode_set
, state
);
1290 plane
= mode_set
->crtc
->primary
;
1291 plane_mask
|= (1 << drm_plane_index(plane
));
1292 plane
->old_fb
= plane
->fb
;
1295 ret
= drm_atomic_commit(state
);
1299 info
->var
.xoffset
= var
->xoffset
;
1300 info
->var
.yoffset
= var
->yoffset
;
1304 drm_atomic_clean_old_fb(dev
, plane_mask
, ret
);
1306 if (ret
== -EDEADLK
)
1310 drm_atomic_state_free(state
);
1315 drm_atomic_state_clear(state
);
1316 drm_atomic_legacy_backoff(state
);
1322 * drm_fb_helper_pan_display - implementation for ->fb_pan_display
1323 * @var: updated screen information
1324 * @info: fbdev registered by the helper
1326 int drm_fb_helper_pan_display(struct fb_var_screeninfo
*var
,
1327 struct fb_info
*info
)
1329 struct drm_fb_helper
*fb_helper
= info
->par
;
1330 struct drm_device
*dev
= fb_helper
->dev
;
1331 struct drm_mode_set
*modeset
;
1335 if (oops_in_progress
)
1338 drm_modeset_lock_all(dev
);
1339 if (!drm_fb_helper_is_bound(fb_helper
)) {
1340 drm_modeset_unlock_all(dev
);
1344 if (dev
->mode_config
.funcs
->atomic_commit
) {
1345 ret
= pan_display_atomic(var
, info
);
1349 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
1350 modeset
= &fb_helper
->crtc_info
[i
].mode_set
;
1352 modeset
->x
= var
->xoffset
;
1353 modeset
->y
= var
->yoffset
;
1355 if (modeset
->num_connectors
) {
1356 ret
= drm_mode_set_config_internal(modeset
);
1358 info
->var
.xoffset
= var
->xoffset
;
1359 info
->var
.yoffset
= var
->yoffset
;
1364 drm_modeset_unlock_all(dev
);
1367 EXPORT_SYMBOL(drm_fb_helper_pan_display
);
1370 * Allocates the backing storage and sets up the fbdev info structure through
1371 * the ->fb_probe callback and then registers the fbdev and sets up the panic
1374 static int drm_fb_helper_single_fb_probe(struct drm_fb_helper
*fb_helper
,
1380 struct fb_info
*info
;
1381 struct drm_fb_helper_surface_size sizes
;
1384 memset(&sizes
, 0, sizeof(struct drm_fb_helper_surface_size
));
1385 sizes
.surface_depth
= 24;
1386 sizes
.surface_bpp
= 32;
1387 sizes
.fb_width
= (unsigned)-1;
1388 sizes
.fb_height
= (unsigned)-1;
1390 /* if driver picks 8 or 16 by default use that
1391 for both depth/bpp */
1392 if (preferred_bpp
!= sizes
.surface_bpp
)
1393 sizes
.surface_depth
= sizes
.surface_bpp
= preferred_bpp
;
1395 /* first up get a count of crtcs now in use and new min/maxes width/heights */
1396 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1397 struct drm_fb_helper_connector
*fb_helper_conn
= fb_helper
->connector_info
[i
];
1398 struct drm_cmdline_mode
*cmdline_mode
;
1400 cmdline_mode
= &fb_helper_conn
->connector
->cmdline_mode
;
1402 if (cmdline_mode
->bpp_specified
) {
1403 switch (cmdline_mode
->bpp
) {
1405 sizes
.surface_depth
= sizes
.surface_bpp
= 8;
1408 sizes
.surface_depth
= 15;
1409 sizes
.surface_bpp
= 16;
1412 sizes
.surface_depth
= sizes
.surface_bpp
= 16;
1415 sizes
.surface_depth
= sizes
.surface_bpp
= 24;
1418 sizes
.surface_depth
= 24;
1419 sizes
.surface_bpp
= 32;
1427 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
1428 struct drm_display_mode
*desired_mode
;
1429 struct drm_mode_set
*mode_set
;
1431 /* in case of tile group, are we the last tile vert or horiz?
1432 * If no tile group you are always the last one both vertically
1435 bool lastv
= true, lasth
= true;
1437 desired_mode
= fb_helper
->crtc_info
[i
].desired_mode
;
1438 mode_set
= &fb_helper
->crtc_info
[i
].mode_set
;
1445 x
= fb_helper
->crtc_info
[i
].x
;
1446 y
= fb_helper
->crtc_info
[i
].y
;
1448 if (gamma_size
== 0)
1449 gamma_size
= fb_helper
->crtc_info
[i
].mode_set
.crtc
->gamma_size
;
1451 sizes
.surface_width
= max_t(u32
, desired_mode
->hdisplay
+ x
, sizes
.surface_width
);
1452 sizes
.surface_height
= max_t(u32
, desired_mode
->vdisplay
+ y
, sizes
.surface_height
);
1454 for (j
= 0; j
< mode_set
->num_connectors
; j
++) {
1455 struct drm_connector
*connector
= mode_set
->connectors
[j
];
1456 if (connector
->has_tile
) {
1457 lasth
= (connector
->tile_h_loc
== (connector
->num_h_tile
- 1));
1458 lastv
= (connector
->tile_v_loc
== (connector
->num_v_tile
- 1));
1459 /* cloning to multiple tiles is just crazy-talk, so: */
1465 sizes
.fb_width
= min_t(u32
, desired_mode
->hdisplay
+ x
, sizes
.fb_width
);
1467 sizes
.fb_height
= min_t(u32
, desired_mode
->vdisplay
+ y
, sizes
.fb_height
);
1470 if (crtc_count
== 0 || sizes
.fb_width
== -1 || sizes
.fb_height
== -1) {
1471 /* hmm everyone went away - assume VGA cable just fell out
1472 and will come back later. */
1473 DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n");
1474 sizes
.fb_width
= sizes
.surface_width
= 1024;
1475 sizes
.fb_height
= sizes
.surface_height
= 768;
1478 /* push down into drivers */
1479 ret
= (*fb_helper
->funcs
->fb_probe
)(fb_helper
, &sizes
);
1483 info
= fb_helper
->fbdev
;
1486 * Set the fb pointer - usually drm_setup_crtcs does this for hotplug
1487 * events, but at init time drm_setup_crtcs needs to be called before
1488 * the fb is allocated (since we need to figure out the desired size of
1489 * the fb before we can allocate it ...). Hence we need to fix things up
1492 for (i
= 0; i
< fb_helper
->crtc_count
; i
++)
1493 if (fb_helper
->crtc_info
[i
].mode_set
.num_connectors
)
1494 fb_helper
->crtc_info
[i
].mode_set
.fb
= fb_helper
->fb
;
1497 info
->var
.pixclock
= 0;
1498 if (register_framebuffer(info
) < 0)
1501 dev_info(fb_helper
->dev
->dev
, "fb%d: %s frame buffer device\n",
1502 info
->node
, info
->fix
.id
);
1504 if (list_empty(&kernel_fb_helper_list
)) {
1505 register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op
);
1508 list_add(&fb_helper
->kernel_fb_list
, &kernel_fb_helper_list
);
1514 * drm_fb_helper_fill_fix - initializes fixed fbdev information
1515 * @info: fbdev registered by the helper
1516 * @pitch: desired pitch
1517 * @depth: desired depth
1519 * Helper to fill in the fixed fbdev information useful for a non-accelerated
1520 * fbdev emulations. Drivers which support acceleration methods which impose
1521 * additional constraints need to set up their own limits.
1523 * Drivers should call this (or their equivalent setup code) from their
1524 * ->fb_probe callback.
1526 void drm_fb_helper_fill_fix(struct fb_info
*info
, uint32_t pitch
,
1529 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
1530 info
->fix
.visual
= depth
== 8 ? FB_VISUAL_PSEUDOCOLOR
:
1531 FB_VISUAL_TRUECOLOR
;
1532 info
->fix
.mmio_start
= 0;
1533 info
->fix
.mmio_len
= 0;
1534 info
->fix
.type_aux
= 0;
1535 info
->fix
.xpanstep
= 1; /* doing it in hw */
1536 info
->fix
.ypanstep
= 1; /* doing it in hw */
1537 info
->fix
.ywrapstep
= 0;
1538 info
->fix
.accel
= FB_ACCEL_NONE
;
1540 info
->fix
.line_length
= pitch
;
1543 EXPORT_SYMBOL(drm_fb_helper_fill_fix
);
1546 * drm_fb_helper_fill_var - initalizes variable fbdev information
1547 * @info: fbdev instance to set up
1548 * @fb_helper: fb helper instance to use as template
1549 * @fb_width: desired fb width
1550 * @fb_height: desired fb height
1552 * Sets up the variable fbdev metainformation from the given fb helper instance
1553 * and the drm framebuffer allocated in fb_helper->fb.
1555 * Drivers should call this (or their equivalent setup code) from their
1556 * ->fb_probe callback after having allocated the fbdev backing
1557 * storage framebuffer.
1559 void drm_fb_helper_fill_var(struct fb_info
*info
, struct drm_fb_helper
*fb_helper
,
1560 uint32_t fb_width
, uint32_t fb_height
)
1562 struct drm_framebuffer
*fb
= fb_helper
->fb
;
1563 info
->pseudo_palette
= fb_helper
->pseudo_palette
;
1564 info
->var
.xres_virtual
= fb
->width
;
1565 info
->var
.yres_virtual
= fb
->height
;
1566 info
->var
.bits_per_pixel
= fb
->bits_per_pixel
;
1567 info
->var
.accel_flags
= FB_ACCELF_TEXT
;
1568 info
->var
.xoffset
= 0;
1569 info
->var
.yoffset
= 0;
1570 info
->var
.activate
= FB_ACTIVATE_NOW
;
1571 info
->var
.height
= -1;
1572 info
->var
.width
= -1;
1574 switch (fb
->depth
) {
1576 info
->var
.red
.offset
= 0;
1577 info
->var
.green
.offset
= 0;
1578 info
->var
.blue
.offset
= 0;
1579 info
->var
.red
.length
= 8; /* 8bit DAC */
1580 info
->var
.green
.length
= 8;
1581 info
->var
.blue
.length
= 8;
1582 info
->var
.transp
.offset
= 0;
1583 info
->var
.transp
.length
= 0;
1586 info
->var
.red
.offset
= 10;
1587 info
->var
.green
.offset
= 5;
1588 info
->var
.blue
.offset
= 0;
1589 info
->var
.red
.length
= 5;
1590 info
->var
.green
.length
= 5;
1591 info
->var
.blue
.length
= 5;
1592 info
->var
.transp
.offset
= 15;
1593 info
->var
.transp
.length
= 1;
1596 info
->var
.red
.offset
= 11;
1597 info
->var
.green
.offset
= 5;
1598 info
->var
.blue
.offset
= 0;
1599 info
->var
.red
.length
= 5;
1600 info
->var
.green
.length
= 6;
1601 info
->var
.blue
.length
= 5;
1602 info
->var
.transp
.offset
= 0;
1605 info
->var
.red
.offset
= 16;
1606 info
->var
.green
.offset
= 8;
1607 info
->var
.blue
.offset
= 0;
1608 info
->var
.red
.length
= 8;
1609 info
->var
.green
.length
= 8;
1610 info
->var
.blue
.length
= 8;
1611 info
->var
.transp
.offset
= 0;
1612 info
->var
.transp
.length
= 0;
1615 info
->var
.red
.offset
= 16;
1616 info
->var
.green
.offset
= 8;
1617 info
->var
.blue
.offset
= 0;
1618 info
->var
.red
.length
= 8;
1619 info
->var
.green
.length
= 8;
1620 info
->var
.blue
.length
= 8;
1621 info
->var
.transp
.offset
= 24;
1622 info
->var
.transp
.length
= 8;
1628 info
->var
.xres
= fb_width
;
1629 info
->var
.yres
= fb_height
;
1631 EXPORT_SYMBOL(drm_fb_helper_fill_var
);
1633 static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper
*fb_helper
,
1637 struct drm_connector
*connector
;
1641 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1642 connector
= fb_helper
->connector_info
[i
]->connector
;
1643 count
+= connector
->funcs
->fill_modes(connector
, maxX
, maxY
);
1649 struct drm_display_mode
*drm_has_preferred_mode(struct drm_fb_helper_connector
*fb_connector
, int width
, int height
)
1651 struct drm_display_mode
*mode
;
1653 list_for_each_entry(mode
, &fb_connector
->connector
->modes
, head
) {
1654 if (mode
->hdisplay
> width
||
1655 mode
->vdisplay
> height
)
1657 if (mode
->type
& DRM_MODE_TYPE_PREFERRED
)
1662 EXPORT_SYMBOL(drm_has_preferred_mode
);
1664 static bool drm_has_cmdline_mode(struct drm_fb_helper_connector
*fb_connector
)
1666 return fb_connector
->connector
->cmdline_mode
.specified
;
1669 struct drm_display_mode
*drm_pick_cmdline_mode(struct drm_fb_helper_connector
*fb_helper_conn
,
1670 int width
, int height
)
1672 struct drm_cmdline_mode
*cmdline_mode
;
1673 struct drm_display_mode
*mode
;
1674 bool prefer_non_interlace
;
1676 cmdline_mode
= &fb_helper_conn
->connector
->cmdline_mode
;
1677 if (cmdline_mode
->specified
== false)
1680 /* attempt to find a matching mode in the list of modes
1681 * we have gotten so far, if not add a CVT mode that conforms
1683 if (cmdline_mode
->rb
|| cmdline_mode
->margins
)
1686 prefer_non_interlace
= !cmdline_mode
->interlace
;
1688 list_for_each_entry(mode
, &fb_helper_conn
->connector
->modes
, head
) {
1689 /* check width/height */
1690 if (mode
->hdisplay
!= cmdline_mode
->xres
||
1691 mode
->vdisplay
!= cmdline_mode
->yres
)
1694 if (cmdline_mode
->refresh_specified
) {
1695 if (mode
->vrefresh
!= cmdline_mode
->refresh
)
1699 if (cmdline_mode
->interlace
) {
1700 if (!(mode
->flags
& DRM_MODE_FLAG_INTERLACE
))
1702 } else if (prefer_non_interlace
) {
1703 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
1709 if (prefer_non_interlace
) {
1710 prefer_non_interlace
= false;
1715 mode
= drm_mode_create_from_cmdline_mode(fb_helper_conn
->connector
->dev
,
1717 list_add(&mode
->head
, &fb_helper_conn
->connector
->modes
);
1720 EXPORT_SYMBOL(drm_pick_cmdline_mode
);
1722 static bool drm_connector_enabled(struct drm_connector
*connector
, bool strict
)
1727 enable
= connector
->status
== connector_status_connected
;
1729 enable
= connector
->status
!= connector_status_disconnected
;
1734 static void drm_enable_connectors(struct drm_fb_helper
*fb_helper
,
1737 bool any_enabled
= false;
1738 struct drm_connector
*connector
;
1741 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1742 connector
= fb_helper
->connector_info
[i
]->connector
;
1743 enabled
[i
] = drm_connector_enabled(connector
, true);
1744 DRM_DEBUG_KMS("connector %d enabled? %s\n", connector
->base
.id
,
1745 enabled
[i
] ? "yes" : "no");
1746 any_enabled
|= enabled
[i
];
1752 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1753 connector
= fb_helper
->connector_info
[i
]->connector
;
1754 enabled
[i
] = drm_connector_enabled(connector
, false);
1758 static bool drm_target_cloned(struct drm_fb_helper
*fb_helper
,
1759 struct drm_display_mode
**modes
,
1760 struct drm_fb_offset
*offsets
,
1761 bool *enabled
, int width
, int height
)
1764 bool can_clone
= false;
1765 struct drm_fb_helper_connector
*fb_helper_conn
;
1766 struct drm_display_mode
*dmt_mode
, *mode
;
1768 /* only contemplate cloning in the single crtc case */
1769 if (fb_helper
->crtc_count
> 1)
1773 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1778 /* only contemplate cloning if more than one connector is enabled */
1782 /* check the command line or if nothing common pick 1024x768 */
1784 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1787 fb_helper_conn
= fb_helper
->connector_info
[i
];
1788 modes
[i
] = drm_pick_cmdline_mode(fb_helper_conn
, width
, height
);
1793 for (j
= 0; j
< i
; j
++) {
1796 if (!drm_mode_equal(modes
[j
], modes
[i
]))
1802 DRM_DEBUG_KMS("can clone using command line\n");
1806 /* try and find a 1024x768 mode on each connector */
1808 dmt_mode
= drm_mode_find_dmt(fb_helper
->dev
, 1024, 768, 60, false);
1810 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1815 fb_helper_conn
= fb_helper
->connector_info
[i
];
1816 list_for_each_entry(mode
, &fb_helper_conn
->connector
->modes
, head
) {
1817 if (drm_mode_equal(mode
, dmt_mode
))
1825 DRM_DEBUG_KMS("can clone using 1024x768\n");
1828 DRM_INFO("kms: can't enable cloning when we probably wanted to.\n");
1832 static int drm_get_tile_offsets(struct drm_fb_helper
*fb_helper
,
1833 struct drm_display_mode
**modes
,
1834 struct drm_fb_offset
*offsets
,
1836 int h_idx
, int v_idx
)
1838 struct drm_fb_helper_connector
*fb_helper_conn
;
1840 int hoffset
= 0, voffset
= 0;
1842 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1843 fb_helper_conn
= fb_helper
->connector_info
[i
];
1844 if (!fb_helper_conn
->connector
->has_tile
)
1847 if (!modes
[i
] && (h_idx
|| v_idx
)) {
1848 DRM_DEBUG_KMS("no modes for connector tiled %d %d\n", i
,
1849 fb_helper_conn
->connector
->base
.id
);
1852 if (fb_helper_conn
->connector
->tile_h_loc
< h_idx
)
1853 hoffset
+= modes
[i
]->hdisplay
;
1855 if (fb_helper_conn
->connector
->tile_v_loc
< v_idx
)
1856 voffset
+= modes
[i
]->vdisplay
;
1858 offsets
[idx
].x
= hoffset
;
1859 offsets
[idx
].y
= voffset
;
1860 DRM_DEBUG_KMS("returned %d %d for %d %d\n", hoffset
, voffset
, h_idx
, v_idx
);
1864 static bool drm_target_preferred(struct drm_fb_helper
*fb_helper
,
1865 struct drm_display_mode
**modes
,
1866 struct drm_fb_offset
*offsets
,
1867 bool *enabled
, int width
, int height
)
1869 struct drm_fb_helper_connector
*fb_helper_conn
;
1871 uint64_t conn_configured
= 0, mask
;
1873 mask
= (1 << fb_helper
->connector_count
) - 1;
1875 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
1876 fb_helper_conn
= fb_helper
->connector_info
[i
];
1878 if (conn_configured
& (1 << i
))
1881 if (enabled
[i
] == false) {
1882 conn_configured
|= (1 << i
);
1886 /* first pass over all the untiled connectors */
1887 if (tile_pass
== 0 && fb_helper_conn
->connector
->has_tile
)
1890 if (tile_pass
== 1) {
1891 if (fb_helper_conn
->connector
->tile_h_loc
!= 0 ||
1892 fb_helper_conn
->connector
->tile_v_loc
!= 0)
1896 if (fb_helper_conn
->connector
->tile_h_loc
!= tile_pass
-1 &&
1897 fb_helper_conn
->connector
->tile_v_loc
!= tile_pass
- 1)
1898 /* if this tile_pass doesn't cover any of the tiles - keep going */
1901 /* find the tile offsets for this pass - need
1902 to find all tiles left and above */
1903 drm_get_tile_offsets(fb_helper
, modes
, offsets
,
1904 i
, fb_helper_conn
->connector
->tile_h_loc
, fb_helper_conn
->connector
->tile_v_loc
);
1906 DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n",
1907 fb_helper_conn
->connector
->base
.id
);
1909 /* got for command line mode first */
1910 modes
[i
] = drm_pick_cmdline_mode(fb_helper_conn
, width
, height
);
1912 DRM_DEBUG_KMS("looking for preferred mode on connector %d %d\n",
1913 fb_helper_conn
->connector
->base
.id
, fb_helper_conn
->connector
->tile_group
? fb_helper_conn
->connector
->tile_group
->id
: 0);
1914 modes
[i
] = drm_has_preferred_mode(fb_helper_conn
, width
, height
);
1916 /* No preferred modes, pick one off the list */
1917 if (!modes
[i
] && !list_empty(&fb_helper_conn
->connector
->modes
)) {
1918 list_for_each_entry(modes
[i
], &fb_helper_conn
->connector
->modes
, head
)
1921 DRM_DEBUG_KMS("found mode %s\n", modes
[i
] ? modes
[i
]->name
:
1923 conn_configured
|= (1 << i
);
1926 if ((conn_configured
& mask
) != mask
) {
1933 static int drm_pick_crtcs(struct drm_fb_helper
*fb_helper
,
1934 struct drm_fb_helper_crtc
**best_crtcs
,
1935 struct drm_display_mode
**modes
,
1936 int n
, int width
, int height
)
1939 struct drm_connector
*connector
;
1940 const struct drm_connector_helper_funcs
*connector_funcs
;
1941 struct drm_encoder
*encoder
;
1942 int my_score
, best_score
, score
;
1943 struct drm_fb_helper_crtc
**crtcs
, *crtc
;
1944 struct drm_fb_helper_connector
*fb_helper_conn
;
1946 if (n
== fb_helper
->connector_count
)
1949 fb_helper_conn
= fb_helper
->connector_info
[n
];
1950 connector
= fb_helper_conn
->connector
;
1952 best_crtcs
[n
] = NULL
;
1953 best_score
= drm_pick_crtcs(fb_helper
, best_crtcs
, modes
, n
+1, width
, height
);
1954 if (modes
[n
] == NULL
)
1957 crtcs
= kzalloc(fb_helper
->connector_count
*
1958 sizeof(struct drm_fb_helper_crtc
*), GFP_KERNEL
);
1963 if (connector
->status
== connector_status_connected
)
1965 if (drm_has_cmdline_mode(fb_helper_conn
))
1967 if (drm_has_preferred_mode(fb_helper_conn
, width
, height
))
1970 connector_funcs
= connector
->helper_private
;
1973 * If the DRM device implements atomic hooks and ->best_encoder() is
1974 * NULL we fallback to the default drm_atomic_helper_best_encoder()
1977 if (fb_helper
->dev
->mode_config
.funcs
->atomic_commit
&&
1978 !connector_funcs
->best_encoder
)
1979 encoder
= drm_atomic_helper_best_encoder(connector
);
1981 encoder
= connector_funcs
->best_encoder(connector
);
1986 /* select a crtc for this connector and then attempt to configure
1987 remaining connectors */
1988 for (c
= 0; c
< fb_helper
->crtc_count
; c
++) {
1989 crtc
= &fb_helper
->crtc_info
[c
];
1991 if ((encoder
->possible_crtcs
& (1 << c
)) == 0)
1994 for (o
= 0; o
< n
; o
++)
1995 if (best_crtcs
[o
] == crtc
)
1999 /* ignore cloning unless only a single crtc */
2000 if (fb_helper
->crtc_count
> 1)
2003 if (!drm_mode_equal(modes
[o
], modes
[n
]))
2008 memcpy(crtcs
, best_crtcs
, n
* sizeof(struct drm_fb_helper_crtc
*));
2009 score
= my_score
+ drm_pick_crtcs(fb_helper
, crtcs
, modes
, n
+ 1,
2011 if (score
> best_score
) {
2013 memcpy(best_crtcs
, crtcs
,
2014 fb_helper
->connector_count
*
2015 sizeof(struct drm_fb_helper_crtc
*));
2023 static void drm_setup_crtcs(struct drm_fb_helper
*fb_helper
)
2025 struct drm_device
*dev
= fb_helper
->dev
;
2026 struct drm_fb_helper_crtc
**crtcs
;
2027 struct drm_display_mode
**modes
;
2028 struct drm_fb_offset
*offsets
;
2029 struct drm_mode_set
*modeset
;
2034 DRM_DEBUG_KMS("\n");
2036 width
= dev
->mode_config
.max_width
;
2037 height
= dev
->mode_config
.max_height
;
2039 crtcs
= kcalloc(fb_helper
->connector_count
,
2040 sizeof(struct drm_fb_helper_crtc
*), GFP_KERNEL
);
2041 modes
= kcalloc(fb_helper
->connector_count
,
2042 sizeof(struct drm_display_mode
*), GFP_KERNEL
);
2043 offsets
= kcalloc(fb_helper
->connector_count
,
2044 sizeof(struct drm_fb_offset
), GFP_KERNEL
);
2045 enabled
= kcalloc(fb_helper
->connector_count
,
2046 sizeof(bool), GFP_KERNEL
);
2047 if (!crtcs
|| !modes
|| !enabled
|| !offsets
) {
2048 DRM_ERROR("Memory allocation failed\n");
2053 drm_enable_connectors(fb_helper
, enabled
);
2055 if (!(fb_helper
->funcs
->initial_config
&&
2056 fb_helper
->funcs
->initial_config(fb_helper
, crtcs
, modes
,
2058 enabled
, width
, height
))) {
2059 memset(modes
, 0, fb_helper
->connector_count
*sizeof(modes
[0]));
2060 memset(crtcs
, 0, fb_helper
->connector_count
*sizeof(crtcs
[0]));
2061 memset(offsets
, 0, fb_helper
->connector_count
*sizeof(offsets
[0]));
2063 if (!drm_target_cloned(fb_helper
, modes
, offsets
,
2064 enabled
, width
, height
) &&
2065 !drm_target_preferred(fb_helper
, modes
, offsets
,
2066 enabled
, width
, height
))
2067 DRM_ERROR("Unable to find initial modes\n");
2069 DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n",
2072 drm_pick_crtcs(fb_helper
, crtcs
, modes
, 0, width
, height
);
2075 /* need to set the modesets up here for use later */
2076 /* fill out the connector<->crtc mappings into the modesets */
2077 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
2078 modeset
= &fb_helper
->crtc_info
[i
].mode_set
;
2079 modeset
->num_connectors
= 0;
2083 for (i
= 0; i
< fb_helper
->connector_count
; i
++) {
2084 struct drm_display_mode
*mode
= modes
[i
];
2085 struct drm_fb_helper_crtc
*fb_crtc
= crtcs
[i
];
2086 struct drm_fb_offset
*offset
= &offsets
[i
];
2087 modeset
= &fb_crtc
->mode_set
;
2089 if (mode
&& fb_crtc
) {
2090 DRM_DEBUG_KMS("desired mode %s set on crtc %d (%d,%d)\n",
2091 mode
->name
, fb_crtc
->mode_set
.crtc
->base
.id
, offset
->x
, offset
->y
);
2092 fb_crtc
->desired_mode
= mode
;
2093 fb_crtc
->x
= offset
->x
;
2094 fb_crtc
->y
= offset
->y
;
2096 drm_mode_destroy(dev
, modeset
->mode
);
2097 modeset
->mode
= drm_mode_duplicate(dev
,
2098 fb_crtc
->desired_mode
);
2099 modeset
->connectors
[modeset
->num_connectors
++] = fb_helper
->connector_info
[i
]->connector
;
2100 modeset
->fb
= fb_helper
->fb
;
2101 modeset
->x
= offset
->x
;
2102 modeset
->y
= offset
->y
;
2106 /* Clear out any old modes if there are no more connected outputs. */
2107 for (i
= 0; i
< fb_helper
->crtc_count
; i
++) {
2108 modeset
= &fb_helper
->crtc_info
[i
].mode_set
;
2109 if (modeset
->num_connectors
== 0) {
2110 BUG_ON(modeset
->fb
);
2112 drm_mode_destroy(dev
, modeset
->mode
);
2113 modeset
->mode
= NULL
;
2124 * drm_fb_helper_initial_config - setup a sane initial connector configuration
2125 * @fb_helper: fb_helper device struct
2126 * @bpp_sel: bpp value to use for the framebuffer configuration
2128 * Scans the CRTCs and connectors and tries to put together an initial setup.
2129 * At the moment, this is a cloned configuration across all heads with
2130 * a new framebuffer object as the backing store.
2132 * Note that this also registers the fbdev and so allows userspace to call into
2133 * the driver through the fbdev interfaces.
2135 * This function will call down into the ->fb_probe callback to let
2136 * the driver allocate and initialize the fbdev info structure and the drm
2137 * framebuffer used to back the fbdev. drm_fb_helper_fill_var() and
2138 * drm_fb_helper_fill_fix() are provided as helpers to setup simple default
2139 * values for the fbdev info structure.
2143 * When you have fbcon support built-in or already loaded, this function will do
2144 * a full modeset to setup the fbdev console. Due to locking misdesign in the
2145 * VT/fbdev subsystem that entire modeset sequence has to be done while holding
2146 * console_lock. Until console_unlock is called no dmesg lines will be sent out
2147 * to consoles, not even serial console. This means when your driver crashes,
2148 * you will see absolutely nothing else but a system stuck in this function,
2149 * with no further output. Any kind of printk() you place within your own driver
2150 * or in the drm core modeset code will also never show up.
2152 * Standard debug practice is to run the fbcon setup without taking the
2153 * console_lock as a hack, to be able to see backtraces and crashes on the
2154 * serial line. This can be done by setting the fb.lockless_register_fb=1 kernel
2157 * The other option is to just disable fbdev emulation since very likely the
2158 * first modeset from userspace will crash in the same way, and is even easier
2159 * to debug. This can be done by setting the drm_kms_helper.fbdev_emulation=0
2160 * kernel cmdline option.
2163 * Zero if everything went ok, nonzero otherwise.
2165 int drm_fb_helper_initial_config(struct drm_fb_helper
*fb_helper
, int bpp_sel
)
2167 struct drm_device
*dev
= fb_helper
->dev
;
2170 if (!drm_fbdev_emulation
)
2173 mutex_lock(&dev
->mode_config
.mutex
);
2174 count
= drm_fb_helper_probe_connector_modes(fb_helper
,
2175 dev
->mode_config
.max_width
,
2176 dev
->mode_config
.max_height
);
2177 mutex_unlock(&dev
->mode_config
.mutex
);
2179 * we shouldn't end up with no modes here.
2182 dev_info(fb_helper
->dev
->dev
, "No connectors reported connected with modes\n");
2184 drm_setup_crtcs(fb_helper
);
2186 return drm_fb_helper_single_fb_probe(fb_helper
, bpp_sel
);
2188 EXPORT_SYMBOL(drm_fb_helper_initial_config
);
2191 * drm_fb_helper_hotplug_event - respond to a hotplug notification by
2192 * probing all the outputs attached to the fb
2193 * @fb_helper: the drm_fb_helper
2195 * Scan the connectors attached to the fb_helper and try to put together a
2196 * setup after *notification of a change in output configuration.
2198 * Called at runtime, takes the mode config locks to be able to check/change the
2199 * modeset configuration. Must be run from process context (which usually means
2200 * either the output polling work or a work item launched from the driver's
2201 * hotplug interrupt).
2203 * Note that drivers may call this even before calling
2204 * drm_fb_helper_initial_config but only after drm_fb_helper_init. This allows
2205 * for a race-free fbcon setup and will make sure that the fbdev emulation will
2206 * not miss any hotplug events.
2209 * 0 on success and a non-zero error code otherwise.
2211 int drm_fb_helper_hotplug_event(struct drm_fb_helper
*fb_helper
)
2213 struct drm_device
*dev
= fb_helper
->dev
;
2214 u32 max_width
, max_height
;
2216 if (!drm_fbdev_emulation
)
2219 mutex_lock(&fb_helper
->dev
->mode_config
.mutex
);
2220 if (!fb_helper
->fb
|| !drm_fb_helper_is_bound(fb_helper
)) {
2221 fb_helper
->delayed_hotplug
= true;
2222 mutex_unlock(&fb_helper
->dev
->mode_config
.mutex
);
2225 DRM_DEBUG_KMS("\n");
2227 max_width
= fb_helper
->fb
->width
;
2228 max_height
= fb_helper
->fb
->height
;
2230 drm_fb_helper_probe_connector_modes(fb_helper
, max_width
, max_height
);
2231 mutex_unlock(&fb_helper
->dev
->mode_config
.mutex
);
2233 drm_modeset_lock_all(dev
);
2234 drm_setup_crtcs(fb_helper
);
2235 drm_modeset_unlock_all(dev
);
2236 drm_fb_helper_set_par(fb_helper
->fbdev
);
2240 EXPORT_SYMBOL(drm_fb_helper_hotplug_event
);
2242 /* The Kconfig DRM_KMS_HELPER selects FRAMEBUFFER_CONSOLE (if !EXPERT)
2243 * but the module doesn't depend on any fb console symbols. At least
2244 * attempt to load fbcon to avoid leaving the system without a usable console.
2246 int __init
drm_fb_helper_modinit(void)
2248 #if defined(CONFIG_FRAMEBUFFER_CONSOLE_MODULE) && !defined(CONFIG_EXPERT)
2249 const char *name
= "fbcon";
2250 struct module
*fbcon
;
2252 mutex_lock(&module_mutex
);
2253 fbcon
= find_module(name
);
2254 mutex_unlock(&module_mutex
);
2257 request_module_nowait(name
);
2261 EXPORT_SYMBOL(drm_fb_helper_modinit
);