@@ -52,9 +52,36 @@ static LIST_HEAD(kernel_fb_helper_list);
5252 * mode setting driver. They can be used mostly independantely from the crtc
5353 * helper functions used by many drivers to implement the kernel mode setting
5454 * interfaces.
55+ *
56+ * Initialization is done as a three-step process with drm_fb_helper_init(),
57+ * drm_fb_helper_single_add_all_connectors() and drm_fb_helper_initial_config().
58+ * Drivers with fancier requirements than the default beheviour can override the
59+ * second step with their own code. Teardown is done with drm_fb_helper_fini().
60+ *
61+ * At runtime drivers should restore the fbdev console by calling
62+ * drm_fb_helper_restore_fbdev_mode() from their ->lastclose callback. They
63+ * should also notify the fb helper code from updates to the output
64+ * configuration by calling drm_fb_helper_hotplug_event(). For easier
65+ * integration with the output polling code in drm_crtc_helper.c the modeset
66+ * code proves a ->output_poll_changed callback.
67+ *
68+ * All other functions exported by the fb helper library can be used to
69+ * implement the fbdev driver interface by the driver.
5570 */
5671
57- /* simple single crtc case helper function */
72+ /**
73+ * drm_fb_helper_single_add_all_connectors() - add all connectors to fbdev
74+ * emulation helper
75+ * @fb_helper: fbdev initialized with drm_fb_helper_init
76+ *
77+ * This functions adds all the available connectors for use with the given
78+ * fb_helper. This is a separate step to allow drivers to freely assign
79+ * connectors to the fbdev, e.g. if some are reserved for special purposes or
80+ * not adequate to be used for the fbcon.
81+ *
82+ * Since this is part of the initial setup before the fbdev is published, no
83+ * locking is required.
84+ */
5885int drm_fb_helper_single_add_all_connectors (struct drm_fb_helper * fb_helper )
5986{
6087 struct drm_device * dev = fb_helper -> dev ;
@@ -163,6 +190,10 @@ static void drm_fb_helper_restore_lut_atomic(struct drm_crtc *crtc)
163190 crtc -> funcs -> gamma_set (crtc , r_base , g_base , b_base , 0 , crtc -> gamma_size );
164191}
165192
193+ /**
194+ * drm_fb_helper_debug_enter - implementation for ->fb_debug_enter
195+ * @info: fbdev registered by the helper
196+ */
166197int drm_fb_helper_debug_enter (struct fb_info * info )
167198{
168199 struct drm_fb_helper * helper = info -> par ;
@@ -208,6 +239,10 @@ static struct drm_framebuffer *drm_mode_config_fb(struct drm_crtc *crtc)
208239 return NULL ;
209240}
210241
242+ /**
243+ * drm_fb_helper_debug_leave - implementation for ->fb_debug_leave
244+ * @info: fbdev registered by the helper
245+ */
211246int drm_fb_helper_debug_leave (struct fb_info * info )
212247{
213248 struct drm_fb_helper * helper = info -> par ;
@@ -243,9 +278,9 @@ EXPORT_SYMBOL(drm_fb_helper_debug_leave);
243278 * drm_fb_helper_restore_fbdev_mode - restore fbdev configuration
244279 * @fb_helper: fbcon to restore
245280 *
246- * This should be called from driver's drm->lastclose callback when implementing
247- * an fbcon on top of kms using this helper. This ensures that the user isn't
248- * greeted with a black screen when e.g. X dies.
281+ * This should be called from driver's drm ->lastclose callback
282+ * when implementing an fbcon on top of kms using this helper. This ensures that
283+ * the user isn't greeted with a black screen when e.g. X dies.
249284 */
250285bool drm_fb_helper_restore_fbdev_mode (struct drm_fb_helper * fb_helper )
251286{
@@ -381,6 +416,11 @@ static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode)
381416 drm_modeset_unlock_all (dev );
382417}
383418
419+ /**
420+ * drm_fb_helper_blank - implementation for ->fb_blank
421+ * @blank: desired blanking state
422+ * @info: fbdev registered by the helper
423+ */
384424int drm_fb_helper_blank (int blank , struct fb_info * info )
385425{
386426 switch (blank ) {
@@ -424,6 +464,24 @@ static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper)
424464 kfree (helper -> crtc_info );
425465}
426466
467+ /**
468+ * drm_fb_helper_init - initialize a drm_fb_helper structure
469+ * @dev: drm device
470+ * @fb_helper: driver-allocated fbdev helper structure to initialize
471+ * @crtc_count: maximum number of crtcs to support in this fbdev emulation
472+ * @max_conn_count: max connector count
473+ *
474+ * This allocates the structures for the fbdev helper with the given limits.
475+ * Note that this won't yet touch the hardware (through the driver interfaces)
476+ * nor register the fbdev. This is only done in drm_fb_helper_initial_config()
477+ * to allow driver writes more control over the exact init sequence.
478+ *
479+ * Drivers must set fb_helper->funcs before calling
480+ * drm_fb_helper_initial_config().
481+ *
482+ * RETURNS:
483+ * Zero if everything went ok, nonzero otherwise.
484+ */
427485int drm_fb_helper_init (struct drm_device * dev ,
428486 struct drm_fb_helper * fb_helper ,
429487 int crtc_count , int max_conn_count )
@@ -552,6 +610,11 @@ static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green,
552610 return 0 ;
553611}
554612
613+ /**
614+ * drm_fb_helper_setcmap - implementation for ->fb_setcmap
615+ * @cmap: cmap to set
616+ * @info: fbdev registered by the helper
617+ */
555618int drm_fb_helper_setcmap (struct fb_cmap * cmap , struct fb_info * info )
556619{
557620 struct drm_fb_helper * fb_helper = info -> par ;
@@ -591,6 +654,11 @@ int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info)
591654}
592655EXPORT_SYMBOL (drm_fb_helper_setcmap );
593656
657+ /**
658+ * drm_fb_helper_check_var - implementation for ->fb_check_var
659+ * @var: screeninfo to check
660+ * @info: fbdev registered by the helper
661+ */
594662int drm_fb_helper_check_var (struct fb_var_screeninfo * var ,
595663 struct fb_info * info )
596664{
@@ -683,7 +751,14 @@ int drm_fb_helper_check_var(struct fb_var_screeninfo *var,
683751}
684752EXPORT_SYMBOL (drm_fb_helper_check_var );
685753
686- /* this will let fbcon do the mode init */
754+ /**
755+ * drm_fb_helper_set_par - implementation for ->fb_set_par
756+ * @info: fbdev registered by the helper
757+ *
758+ * This will let fbcon do the mode init and is called at initialization time by
759+ * the fbdev core when registering the driver, and later on through the hotplug
760+ * callback.
761+ */
687762int drm_fb_helper_set_par (struct fb_info * info )
688763{
689764 struct drm_fb_helper * fb_helper = info -> par ;
@@ -715,6 +790,11 @@ int drm_fb_helper_set_par(struct fb_info *info)
715790}
716791EXPORT_SYMBOL (drm_fb_helper_set_par );
717792
793+ /**
794+ * drm_fb_helper_pan_display - implementation for ->fb_pan_display
795+ * @var: updated screen information
796+ * @info: fbdev registered by the helper
797+ */
718798int drm_fb_helper_pan_display (struct fb_var_screeninfo * var ,
719799 struct fb_info * info )
720800{
@@ -753,8 +833,9 @@ int drm_fb_helper_pan_display(struct fb_var_screeninfo *var,
753833EXPORT_SYMBOL (drm_fb_helper_pan_display );
754834
755835/*
756- * Allocates the backing storage through the ->fb_probe callback and then
757- * registers the fbdev and sets up the panic notifier.
836+ * Allocates the backing storage and sets up the fbdev info structure through
837+ * the ->fb_probe callback and then registers the fbdev and sets up the panic
838+ * notifier.
758839 */
759840static int drm_fb_helper_single_fb_probe (struct drm_fb_helper * fb_helper ,
760841 int preferred_bpp )
@@ -876,6 +957,19 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper,
876957 return 0 ;
877958}
878959
960+ /**
961+ * drm_fb_helper_fill_fix - initializes fixed fbdev information
962+ * @info: fbdev registered by the helper
963+ * @pitch: desired pitch
964+ * @depth: desired depth
965+ *
966+ * Helper to fill in the fixed fbdev information useful for a non-accelerated
967+ * fbdev emulations. Drivers which support acceleration methods which impose
968+ * additional constraints need to set up their own limits.
969+ *
970+ * Drivers should call this (or their equivalent setup code) from their
971+ * ->fb_probe callback.
972+ */
879973void drm_fb_helper_fill_fix (struct fb_info * info , uint32_t pitch ,
880974 uint32_t depth )
881975{
@@ -896,6 +990,20 @@ void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch,
896990}
897991EXPORT_SYMBOL (drm_fb_helper_fill_fix );
898992
993+ /**
994+ * drm_fb_helper_fill_var - initalizes variable fbdev information
995+ * @info: fbdev instance to set up
996+ * @fb_helper: fb helper instance to use as template
997+ * @fb_width: desired fb width
998+ * @fb_height: desired fb height
999+ *
1000+ * Sets up the variable fbdev metainformation from the given fb helper instance
1001+ * and the drm framebuffer allocated in fb_helper->fb.
1002+ *
1003+ * Drivers should call this (or their equivalent setup code) from their
1004+ * ->fb_probe callback after having allocated the fbdev backing
1005+ * storage framebuffer.
1006+ */
8991007void drm_fb_helper_fill_var (struct fb_info * info , struct drm_fb_helper * fb_helper ,
9001008 uint32_t fb_width , uint32_t fb_height )
9011009{
@@ -1358,18 +1466,23 @@ static void drm_setup_crtcs(struct drm_fb_helper *fb_helper)
13581466}
13591467
13601468/**
1361- * drm_helper_initial_config - setup a sane initial connector configuration
1469+ * drm_fb_helper_initial_config - setup a sane initial connector configuration
13621470 * @fb_helper: fb_helper device struct
13631471 * @bpp_sel: bpp value to use for the framebuffer configuration
13641472 *
1365- * LOCKING:
1366- * Called at init time by the driver to set up the @fb_helper initial
1367- * configuration, must take the mode config lock.
1368- *
13691473 * Scans the CRTCs and connectors and tries to put together an initial setup.
13701474 * At the moment, this is a cloned configuration across all heads with
13711475 * a new framebuffer object as the backing store.
13721476 *
1477+ * Note that this also registers the fbdev and so allows userspace to call into
1478+ * the driver through the fbdev interfaces.
1479+ *
1480+ * This function will call down into the ->fb_probe callback to let
1481+ * the driver allocate and initialize the fbdev info structure and the drm
1482+ * framebuffer used to back the fbdev. drm_fb_helper_fill_var() and
1483+ * drm_fb_helper_fill_fix() are provided as helpers to setup simple default
1484+ * values for the fbdev info structure.
1485+ *
13731486 * RETURNS:
13741487 * Zero if everything went ok, nonzero otherwise.
13751488 */
@@ -1400,12 +1513,17 @@ EXPORT_SYMBOL(drm_fb_helper_initial_config);
14001513 * probing all the outputs attached to the fb
14011514 * @fb_helper: the drm_fb_helper
14021515 *
1403- * LOCKING:
1404- * Called at runtime, must take mode config lock.
1405- *
14061516 * Scan the connectors attached to the fb_helper and try to put together a
14071517 * setup after *notification of a change in output configuration.
14081518 *
1519+ * Called at runtime, takes the mode config locks to be able to check/change the
1520+ * modeset configuration. Must be run from process context (which usually means
1521+ * either the output polling work or a work item launched from the driver's
1522+ * hotplug interrupt).
1523+ *
1524+ * Note that the driver must ensure that this is only called _after_ the fb has
1525+ * been fully set up, i.e. after the call to drm_fb_helper_initial_config.
1526+ *
14091527 * RETURNS:
14101528 * 0 on success and a non-zero error code otherwise.
14111529 */
0 commit comments