Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2006-2009 Red Hat Inc. |
| 3 | * Copyright (c) 2006-2008 Intel Corporation |
| 4 | * Copyright (c) 2007 Dave Airlie <airlied@linux.ie> |
| 5 | * |
| 6 | * DRM framebuffer helper functions |
| 7 | * |
| 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. |
| 17 | * |
| 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 |
| 24 | * OF THIS SOFTWARE. |
| 25 | * |
| 26 | * Authors: |
| 27 | * Dave Airlie <airlied@linux.ie> |
| 28 | * Jesse Barnes <jesse.barnes@intel.com> |
| 29 | */ |
Sachin Kamat | d56b1b9 | 2012-11-15 03:43:29 +0000 | [diff] [blame] | 30 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 31 | |
Noralf Trønnes | cfe6342 | 2016-08-23 13:54:06 +0200 | [diff] [blame] | 32 | #include <linux/console.h> |
Andy Shevchenko | 3b40a44 | 2010-02-02 14:40:32 -0800 | [diff] [blame] | 33 | #include <linux/kernel.h> |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 34 | #include <linux/sysrq.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 35 | #include <linux/slab.h> |
Paul Gortmaker | e0cd360 | 2011-08-30 11:04:30 -0400 | [diff] [blame] | 36 | #include <linux/module.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 37 | #include <drm/drmP.h> |
| 38 | #include <drm/drm_crtc.h> |
| 39 | #include <drm/drm_fb_helper.h> |
| 40 | #include <drm/drm_crtc_helper.h> |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 41 | #include <drm/drm_atomic.h> |
| 42 | #include <drm/drm_atomic_helper.h> |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 43 | |
Ville Syrjälä | 699fbee | 2016-09-19 16:33:44 +0300 | [diff] [blame] | 44 | #include "drm_crtc_helper_internal.h" |
| 45 | |
Daniel Vetter | f64c557 | 2015-08-25 15:45:13 +0200 | [diff] [blame] | 46 | static bool drm_fbdev_emulation = true; |
| 47 | module_param_named(fbdev_emulation, drm_fbdev_emulation, bool, 0600); |
| 48 | MODULE_PARM_DESC(fbdev_emulation, |
| 49 | "Enable legacy fbdev emulation [default=true]"); |
| 50 | |
Xinliang Liu | 5f15257 | 2017-02-15 17:19:08 +0100 | [diff] [blame] | 51 | static int drm_fbdev_overalloc = CONFIG_DRM_FBDEV_OVERALLOC; |
| 52 | module_param(drm_fbdev_overalloc, int, 0444); |
| 53 | MODULE_PARM_DESC(drm_fbdev_overalloc, |
| 54 | "Overallocation of the fbdev buffer (%) [default=" |
| 55 | __MODULE_STRING(CONFIG_DRM_FBDEV_OVERALLOC) "]"); |
| 56 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 57 | static LIST_HEAD(kernel_fb_helper_list); |
Chris Wilson | a53ca63 | 2016-11-29 12:02:17 +0000 | [diff] [blame] | 58 | static DEFINE_MUTEX(kernel_fb_helper_lock); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 59 | |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 60 | /** |
| 61 | * DOC: fbdev helpers |
| 62 | * |
| 63 | * The fb helper functions are useful to provide an fbdev on top of a drm kernel |
Thierry Reding | 83c617c | 2014-04-29 11:44:35 +0200 | [diff] [blame] | 64 | * mode setting driver. They can be used mostly independently from the crtc |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 65 | * helper functions used by many drivers to implement the kernel mode setting |
| 66 | * interfaces. |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 67 | * |
Thierry Reding | 10a2310 | 2014-06-27 17:19:24 +0200 | [diff] [blame] | 68 | * Initialization is done as a four-step process with drm_fb_helper_prepare(), |
| 69 | * drm_fb_helper_init(), drm_fb_helper_single_add_all_connectors() and |
| 70 | * drm_fb_helper_initial_config(). Drivers with fancier requirements than the |
| 71 | * default behaviour can override the third step with their own code. |
Daniel Vetter | ed84e25 | 2017-02-07 15:10:49 +0100 | [diff] [blame] | 72 | * Teardown is done with drm_fb_helper_fini() after the fbdev device is |
| 73 | * unregisters using drm_fb_helper_unregister_fbi(). |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 74 | * |
| 75 | * At runtime drivers should restore the fbdev console by calling |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 76 | * drm_fb_helper_restore_fbdev_mode_unlocked() from their &drm_driver.lastclose |
| 77 | * callback. They should also notify the fb helper code from updates to the |
| 78 | * output configuration by calling drm_fb_helper_hotplug_event(). For easier |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 79 | * integration with the output polling code in drm_crtc_helper.c the modeset |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 80 | * code provides a &drm_mode_config_funcs.output_poll_changed callback. |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 81 | * |
| 82 | * All other functions exported by the fb helper library can be used to |
| 83 | * implement the fbdev driver interface by the driver. |
Thierry Reding | 10a2310 | 2014-06-27 17:19:24 +0200 | [diff] [blame] | 84 | * |
| 85 | * It is possible, though perhaps somewhat tricky, to implement race-free |
| 86 | * hotplug detection using the fbdev helpers. The drm_fb_helper_prepare() |
| 87 | * helper must be called first to initialize the minimum required to make |
| 88 | * hotplug detection work. Drivers also need to make sure to properly set up |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 89 | * the &drm_mode_config.funcs member. After calling drm_kms_helper_poll_init() |
Thierry Reding | 10a2310 | 2014-06-27 17:19:24 +0200 | [diff] [blame] | 90 | * it is safe to enable interrupts and start processing hotplug events. At the |
| 91 | * same time, drivers should initialize all modeset objects such as CRTCs, |
| 92 | * encoders and connectors. To finish up the fbdev helper initialization, the |
| 93 | * drm_fb_helper_init() function is called. To probe for all attached displays |
| 94 | * and set up an initial configuration using the detected hardware, drivers |
| 95 | * should call drm_fb_helper_single_add_all_connectors() followed by |
| 96 | * drm_fb_helper_initial_config(). |
Noralf Trønnes | eaa434d | 2016-04-28 17:18:33 +0200 | [diff] [blame] | 97 | * |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 98 | * If &drm_framebuffer_funcs.dirty is set, the |
Noralf Trønnes | 2dad551 | 2016-05-11 18:09:17 +0200 | [diff] [blame] | 99 | * drm_fb_helper_{cfb,sys}_{write,fillrect,copyarea,imageblit} functions will |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 100 | * accumulate changes and schedule &drm_fb_helper.dirty_work to run right |
Noralf Trønnes | 2dad551 | 2016-05-11 18:09:17 +0200 | [diff] [blame] | 101 | * away. This worker then calls the dirty() function ensuring that it will |
| 102 | * always run in process context since the fb_*() function could be running in |
| 103 | * atomic context. If drm_fb_helper_deferred_io() is used as the deferred_io |
| 104 | * callback it will also schedule dirty_work with the damage collected from the |
| 105 | * mmap page writes. |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 106 | */ |
| 107 | |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 108 | #define drm_fb_helper_for_each_connector(fbh, i__) \ |
| 109 | for (({ lockdep_assert_held(&(fbh)->dev->mode_config.mutex); }), \ |
| 110 | i__ = 0; i__ < (fbh)->connector_count; i__++) |
| 111 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 112 | /** |
| 113 | * drm_fb_helper_single_add_all_connectors() - add all connectors to fbdev |
| 114 | * emulation helper |
| 115 | * @fb_helper: fbdev initialized with drm_fb_helper_init |
| 116 | * |
| 117 | * This functions adds all the available connectors for use with the given |
| 118 | * fb_helper. This is a separate step to allow drivers to freely assign |
| 119 | * connectors to the fbdev, e.g. if some are reserved for special purposes or |
| 120 | * not adequate to be used for the fbcon. |
| 121 | * |
Daniel Vetter | 169faec | 2015-07-09 23:44:27 +0200 | [diff] [blame] | 122 | * This function is protected against concurrent connector hotadds/removals |
| 123 | * using drm_fb_helper_add_one_connector() and |
| 124 | * drm_fb_helper_remove_one_connector(). |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 125 | */ |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 126 | int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper) |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 127 | { |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 128 | struct drm_device *dev = fb_helper->dev; |
| 129 | struct drm_connector *connector; |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame] | 130 | struct drm_connector_list_iter conn_iter; |
| 131 | int i, ret = 0; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 132 | |
Daniel Vetter | f64c557 | 2015-08-25 15:45:13 +0200 | [diff] [blame] | 133 | if (!drm_fbdev_emulation) |
| 134 | return 0; |
| 135 | |
Daniel Vetter | 169faec | 2015-07-09 23:44:27 +0200 | [diff] [blame] | 136 | mutex_lock(&dev->mode_config.mutex); |
Thierry Reding | b982dab | 2017-02-28 15:46:43 +0100 | [diff] [blame] | 137 | drm_connector_list_iter_begin(dev, &conn_iter); |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame] | 138 | drm_for_each_connector_iter(connector, &conn_iter) { |
Maarten Lankhorst | 15fce29 | 2016-02-15 13:45:16 +0100 | [diff] [blame] | 139 | ret = drm_fb_helper_add_one_connector(fb_helper, connector); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 140 | |
Maarten Lankhorst | 15fce29 | 2016-02-15 13:45:16 +0100 | [diff] [blame] | 141 | if (ret) |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 142 | goto fail; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 143 | } |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame] | 144 | goto out; |
| 145 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 146 | fail: |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 147 | drm_fb_helper_for_each_connector(fb_helper, i) { |
Ville Syrjälä | 7dfcb36 | 2016-10-26 12:05:52 +0300 | [diff] [blame] | 148 | struct drm_fb_helper_connector *fb_helper_connector = |
| 149 | fb_helper->connector_info[i]; |
| 150 | |
Thierry Reding | ad09360 | 2017-02-28 15:46:39 +0100 | [diff] [blame] | 151 | drm_connector_put(fb_helper_connector->connector); |
Ville Syrjälä | 7dfcb36 | 2016-10-26 12:05:52 +0300 | [diff] [blame] | 152 | |
| 153 | kfree(fb_helper_connector); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 154 | fb_helper->connector_info[i] = NULL; |
| 155 | } |
| 156 | fb_helper->connector_count = 0; |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame] | 157 | out: |
Thierry Reding | b982dab | 2017-02-28 15:46:43 +0100 | [diff] [blame] | 158 | drm_connector_list_iter_end(&conn_iter); |
Daniel Vetter | 169faec | 2015-07-09 23:44:27 +0200 | [diff] [blame] | 159 | mutex_unlock(&dev->mode_config.mutex); |
| 160 | |
Maarten Lankhorst | 15fce29 | 2016-02-15 13:45:16 +0100 | [diff] [blame] | 161 | return ret; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 162 | } |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 163 | EXPORT_SYMBOL(drm_fb_helper_single_add_all_connectors); |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 164 | |
Dave Airlie | 65c2a89 | 2014-06-05 14:01:30 +1000 | [diff] [blame] | 165 | int drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper, struct drm_connector *connector) |
| 166 | { |
| 167 | struct drm_fb_helper_connector **temp; |
| 168 | struct drm_fb_helper_connector *fb_helper_connector; |
| 169 | |
Daniel Vetter | f64c557 | 2015-08-25 15:45:13 +0200 | [diff] [blame] | 170 | if (!drm_fbdev_emulation) |
| 171 | return 0; |
| 172 | |
Dave Airlie | 65c2a89 | 2014-06-05 14:01:30 +1000 | [diff] [blame] | 173 | WARN_ON(!mutex_is_locked(&fb_helper->dev->mode_config.mutex)); |
| 174 | if (fb_helper->connector_count + 1 > fb_helper->connector_info_alloc_count) { |
Damien Lespiau | 14f476f | 2014-08-08 19:15:20 +0100 | [diff] [blame] | 175 | temp = krealloc(fb_helper->connector_info, sizeof(struct drm_fb_helper_connector *) * (fb_helper->connector_count + 1), GFP_KERNEL); |
Dave Airlie | 65c2a89 | 2014-06-05 14:01:30 +1000 | [diff] [blame] | 176 | if (!temp) |
| 177 | return -ENOMEM; |
| 178 | |
| 179 | fb_helper->connector_info_alloc_count = fb_helper->connector_count + 1; |
| 180 | fb_helper->connector_info = temp; |
| 181 | } |
| 182 | |
| 183 | |
| 184 | fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL); |
| 185 | if (!fb_helper_connector) |
| 186 | return -ENOMEM; |
| 187 | |
Thierry Reding | ad09360 | 2017-02-28 15:46:39 +0100 | [diff] [blame] | 188 | drm_connector_get(connector); |
Dave Airlie | 65c2a89 | 2014-06-05 14:01:30 +1000 | [diff] [blame] | 189 | fb_helper_connector->connector = connector; |
| 190 | fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector; |
| 191 | return 0; |
| 192 | } |
| 193 | EXPORT_SYMBOL(drm_fb_helper_add_one_connector); |
| 194 | |
| 195 | int drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper, |
| 196 | struct drm_connector *connector) |
| 197 | { |
| 198 | struct drm_fb_helper_connector *fb_helper_connector; |
| 199 | int i, j; |
| 200 | |
Daniel Vetter | f64c557 | 2015-08-25 15:45:13 +0200 | [diff] [blame] | 201 | if (!drm_fbdev_emulation) |
| 202 | return 0; |
| 203 | |
Dave Airlie | 65c2a89 | 2014-06-05 14:01:30 +1000 | [diff] [blame] | 204 | WARN_ON(!mutex_is_locked(&fb_helper->dev->mode_config.mutex)); |
| 205 | |
| 206 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 207 | if (fb_helper->connector_info[i]->connector == connector) |
| 208 | break; |
| 209 | } |
| 210 | |
| 211 | if (i == fb_helper->connector_count) |
| 212 | return -EINVAL; |
| 213 | fb_helper_connector = fb_helper->connector_info[i]; |
Thierry Reding | ad09360 | 2017-02-28 15:46:39 +0100 | [diff] [blame] | 214 | drm_connector_put(fb_helper_connector->connector); |
Dave Airlie | 65c2a89 | 2014-06-05 14:01:30 +1000 | [diff] [blame] | 215 | |
| 216 | for (j = i + 1; j < fb_helper->connector_count; j++) { |
| 217 | fb_helper->connector_info[j - 1] = fb_helper->connector_info[j]; |
| 218 | } |
| 219 | fb_helper->connector_count--; |
| 220 | kfree(fb_helper_connector); |
Rob Clark | 2148f18 | 2015-01-26 10:11:08 -0500 | [diff] [blame] | 221 | |
Dave Airlie | 65c2a89 | 2014-06-05 14:01:30 +1000 | [diff] [blame] | 222 | return 0; |
| 223 | } |
| 224 | EXPORT_SYMBOL(drm_fb_helper_remove_one_connector); |
| 225 | |
Jason Wessel | 9923102 | 2010-10-13 14:09:43 -0500 | [diff] [blame] | 226 | static void drm_fb_helper_save_lut_atomic(struct drm_crtc *crtc, struct drm_fb_helper *helper) |
| 227 | { |
| 228 | uint16_t *r_base, *g_base, *b_base; |
| 229 | int i; |
| 230 | |
Ville Syrjälä | 04c0c56 | 2013-05-27 20:19:57 +0300 | [diff] [blame] | 231 | if (helper->funcs->gamma_get == NULL) |
| 232 | return; |
| 233 | |
Jason Wessel | 9923102 | 2010-10-13 14:09:43 -0500 | [diff] [blame] | 234 | r_base = crtc->gamma_store; |
| 235 | g_base = r_base + crtc->gamma_size; |
| 236 | b_base = g_base + crtc->gamma_size; |
| 237 | |
| 238 | for (i = 0; i < crtc->gamma_size; i++) |
| 239 | helper->funcs->gamma_get(crtc, &r_base[i], &g_base[i], &b_base[i], i); |
| 240 | } |
| 241 | |
| 242 | static void drm_fb_helper_restore_lut_atomic(struct drm_crtc *crtc) |
| 243 | { |
| 244 | uint16_t *r_base, *g_base, *b_base; |
| 245 | |
Laurent Pinchart | ebe0f24 | 2012-05-17 13:27:24 +0200 | [diff] [blame] | 246 | if (crtc->funcs->gamma_set == NULL) |
| 247 | return; |
| 248 | |
Jason Wessel | 9923102 | 2010-10-13 14:09:43 -0500 | [diff] [blame] | 249 | r_base = crtc->gamma_store; |
| 250 | g_base = r_base + crtc->gamma_size; |
| 251 | b_base = g_base + crtc->gamma_size; |
| 252 | |
Maarten Lankhorst | 7ea7728 | 2016-06-07 12:49:30 +0200 | [diff] [blame] | 253 | crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, crtc->gamma_size); |
Jason Wessel | 9923102 | 2010-10-13 14:09:43 -0500 | [diff] [blame] | 254 | } |
| 255 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 256 | /** |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 257 | * drm_fb_helper_debug_enter - implementation for &fb_ops.fb_debug_enter |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 258 | * @info: fbdev registered by the helper |
| 259 | */ |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 260 | int drm_fb_helper_debug_enter(struct fb_info *info) |
| 261 | { |
| 262 | struct drm_fb_helper *helper = info->par; |
Jani Nikula | be26a66 | 2015-03-11 11:51:06 +0200 | [diff] [blame] | 263 | const struct drm_crtc_helper_funcs *funcs; |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 264 | int i; |
| 265 | |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 266 | list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) { |
| 267 | for (i = 0; i < helper->crtc_count; i++) { |
| 268 | struct drm_mode_set *mode_set = |
| 269 | &helper->crtc_info[i].mode_set; |
| 270 | |
| 271 | if (!mode_set->crtc->enabled) |
| 272 | continue; |
| 273 | |
| 274 | funcs = mode_set->crtc->helper_private; |
Stefan Christ | 1b99b72 | 2016-11-14 00:03:11 +0100 | [diff] [blame] | 275 | if (funcs->mode_set_base_atomic == NULL) |
| 276 | continue; |
| 277 | |
Jason Wessel | 9923102 | 2010-10-13 14:09:43 -0500 | [diff] [blame] | 278 | drm_fb_helper_save_lut_atomic(mode_set->crtc, helper); |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 279 | funcs->mode_set_base_atomic(mode_set->crtc, |
| 280 | mode_set->fb, |
| 281 | mode_set->x, |
Jason Wessel | 413d45d | 2010-09-26 06:47:25 -0500 | [diff] [blame] | 282 | mode_set->y, |
Jason Wessel | 21c74a8 | 2010-10-13 14:09:44 -0500 | [diff] [blame] | 283 | ENTER_ATOMIC_MODE_SET); |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | EXPORT_SYMBOL(drm_fb_helper_debug_enter); |
| 290 | |
| 291 | /* Find the real fb for a given fb helper CRTC */ |
| 292 | static struct drm_framebuffer *drm_mode_config_fb(struct drm_crtc *crtc) |
| 293 | { |
| 294 | struct drm_device *dev = crtc->dev; |
| 295 | struct drm_crtc *c; |
| 296 | |
Daniel Vetter | 6295d60 | 2015-07-09 23:44:25 +0200 | [diff] [blame] | 297 | drm_for_each_crtc(c, dev) { |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 298 | if (crtc->base.id == c->base.id) |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 299 | return c->primary->fb; |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | return NULL; |
| 303 | } |
| 304 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 305 | /** |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 306 | * drm_fb_helper_debug_leave - implementation for &fb_ops.fb_debug_leave |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 307 | * @info: fbdev registered by the helper |
| 308 | */ |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 309 | int drm_fb_helper_debug_leave(struct fb_info *info) |
| 310 | { |
| 311 | struct drm_fb_helper *helper = info->par; |
| 312 | struct drm_crtc *crtc; |
Jani Nikula | be26a66 | 2015-03-11 11:51:06 +0200 | [diff] [blame] | 313 | const struct drm_crtc_helper_funcs *funcs; |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 314 | struct drm_framebuffer *fb; |
| 315 | int i; |
| 316 | |
| 317 | for (i = 0; i < helper->crtc_count; i++) { |
| 318 | struct drm_mode_set *mode_set = &helper->crtc_info[i].mode_set; |
| 319 | crtc = mode_set->crtc; |
| 320 | funcs = crtc->helper_private; |
| 321 | fb = drm_mode_config_fb(crtc); |
| 322 | |
| 323 | if (!crtc->enabled) |
| 324 | continue; |
| 325 | |
| 326 | if (!fb) { |
| 327 | DRM_ERROR("no fb to restore??\n"); |
| 328 | continue; |
| 329 | } |
| 330 | |
Stefan Christ | 1b99b72 | 2016-11-14 00:03:11 +0100 | [diff] [blame] | 331 | if (funcs->mode_set_base_atomic == NULL) |
| 332 | continue; |
| 333 | |
Jason Wessel | 9923102 | 2010-10-13 14:09:43 -0500 | [diff] [blame] | 334 | drm_fb_helper_restore_lut_atomic(mode_set->crtc); |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 335 | funcs->mode_set_base_atomic(mode_set->crtc, fb, crtc->x, |
Jason Wessel | 21c74a8 | 2010-10-13 14:09:44 -0500 | [diff] [blame] | 336 | crtc->y, LEAVE_ATOMIC_MODE_SET); |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | return 0; |
| 340 | } |
| 341 | EXPORT_SYMBOL(drm_fb_helper_debug_leave); |
| 342 | |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 343 | static int restore_fbdev_mode_atomic(struct drm_fb_helper *fb_helper) |
| 344 | { |
| 345 | struct drm_device *dev = fb_helper->dev; |
| 346 | struct drm_plane *plane; |
| 347 | struct drm_atomic_state *state; |
| 348 | int i, ret; |
Maarten Lankhorst | f72c6b3 | 2015-11-11 11:29:10 +0100 | [diff] [blame] | 349 | unsigned plane_mask; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 350 | |
| 351 | state = drm_atomic_state_alloc(dev); |
| 352 | if (!state) |
| 353 | return -ENOMEM; |
| 354 | |
| 355 | state->acquire_ctx = dev->mode_config.acquire_ctx; |
| 356 | retry: |
Maarten Lankhorst | f72c6b3 | 2015-11-11 11:29:10 +0100 | [diff] [blame] | 357 | plane_mask = 0; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 358 | drm_for_each_plane(plane, dev) { |
| 359 | struct drm_plane_state *plane_state; |
| 360 | |
| 361 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 362 | if (IS_ERR(plane_state)) { |
| 363 | ret = PTR_ERR(plane_state); |
| 364 | goto fail; |
| 365 | } |
| 366 | |
Joonas Lahtinen | 31ad61e | 2016-07-29 08:50:05 +0300 | [diff] [blame] | 367 | plane_state->rotation = DRM_ROTATE_0; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 368 | |
Maarten Lankhorst | f72c6b3 | 2015-11-11 11:29:10 +0100 | [diff] [blame] | 369 | plane->old_fb = plane->fb; |
| 370 | plane_mask |= 1 << drm_plane_index(plane); |
| 371 | |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 372 | /* disable non-primary: */ |
| 373 | if (plane->type == DRM_PLANE_TYPE_PRIMARY) |
| 374 | continue; |
| 375 | |
| 376 | ret = __drm_atomic_helper_disable_plane(plane, plane_state); |
| 377 | if (ret != 0) |
| 378 | goto fail; |
| 379 | } |
| 380 | |
| 381 | for(i = 0; i < fb_helper->crtc_count; i++) { |
| 382 | struct drm_mode_set *mode_set = &fb_helper->crtc_info[i].mode_set; |
| 383 | |
| 384 | ret = __drm_atomic_helper_set_config(mode_set, state); |
| 385 | if (ret != 0) |
| 386 | goto fail; |
| 387 | } |
| 388 | |
| 389 | ret = drm_atomic_commit(state); |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 390 | |
| 391 | fail: |
Maarten Lankhorst | f72c6b3 | 2015-11-11 11:29:10 +0100 | [diff] [blame] | 392 | drm_atomic_clean_old_fb(dev, plane_mask, ret); |
Matt Roper | 9428403 | 2015-09-21 17:21:48 -0700 | [diff] [blame] | 393 | |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 394 | if (ret == -EDEADLK) |
| 395 | goto backoff; |
| 396 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 397 | drm_atomic_state_put(state); |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 398 | return ret; |
| 399 | |
| 400 | backoff: |
| 401 | drm_atomic_state_clear(state); |
| 402 | drm_atomic_legacy_backoff(state); |
| 403 | |
| 404 | goto retry; |
| 405 | } |
| 406 | |
Daniel Vetter | b7bdf0a8 | 2015-08-25 17:20:28 +0200 | [diff] [blame] | 407 | static int restore_fbdev_mode(struct drm_fb_helper *fb_helper) |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 408 | { |
Ville Syrjälä | 3858bc5 | 2013-06-03 16:10:42 +0300 | [diff] [blame] | 409 | struct drm_device *dev = fb_helper->dev; |
| 410 | struct drm_plane *plane; |
Ville Syrjälä | 3858bc5 | 2013-06-03 16:10:42 +0300 | [diff] [blame] | 411 | int i; |
Daniel Vetter | 6aed8ec | 2013-01-20 17:32:21 +0100 | [diff] [blame] | 412 | |
Ville Syrjälä | 3858bc5 | 2013-06-03 16:10:42 +0300 | [diff] [blame] | 413 | drm_warn_on_modeset_not_all_locked(dev); |
| 414 | |
Dhinakaran Pandiyan | a743d75 | 2016-12-22 00:50:42 -0800 | [diff] [blame] | 415 | if (drm_drv_uses_atomic_modeset(dev)) |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 416 | return restore_fbdev_mode_atomic(fb_helper); |
| 417 | |
Daniel Vetter | 6295d60 | 2015-07-09 23:44:25 +0200 | [diff] [blame] | 418 | drm_for_each_plane(plane, dev) { |
Matt Roper | e27dde3 | 2014-04-01 15:22:30 -0700 | [diff] [blame] | 419 | if (plane->type != DRM_PLANE_TYPE_PRIMARY) |
| 420 | drm_plane_force_disable(plane); |
Daniel Vetter | 6aed8ec | 2013-01-20 17:32:21 +0100 | [diff] [blame] | 421 | |
Ville Syrjälä | 6686df8 | 2016-10-21 22:22:45 +0300 | [diff] [blame] | 422 | if (plane->rotation_property) |
Ville Syrjälä | d138dd3 | 2016-09-26 19:30:48 +0300 | [diff] [blame] | 423 | drm_mode_plane_set_obj_prop(plane, |
| 424 | plane->rotation_property, |
| 425 | DRM_ROTATE_0); |
Sonika Jindal | 9783de2 | 2014-08-05 11:26:57 +0530 | [diff] [blame] | 426 | } |
| 427 | |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 428 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 429 | struct drm_mode_set *mode_set = &fb_helper->crtc_info[i].mode_set; |
Ville Syrjälä | 3858bc5 | 2013-06-03 16:10:42 +0300 | [diff] [blame] | 430 | struct drm_crtc *crtc = mode_set->crtc; |
| 431 | int ret; |
| 432 | |
Alex Deucher | 03f9abb | 2015-09-30 14:47:37 -0400 | [diff] [blame] | 433 | if (crtc->funcs->cursor_set2) { |
| 434 | ret = crtc->funcs->cursor_set2(crtc, NULL, 0, 0, 0, 0, 0); |
| 435 | if (ret) |
Dave Airlie | 48f87dd | 2015-10-16 10:10:32 +1000 | [diff] [blame] | 436 | return ret; |
Alex Deucher | 03f9abb | 2015-09-30 14:47:37 -0400 | [diff] [blame] | 437 | } else if (crtc->funcs->cursor_set) { |
Ville Syrjälä | 3858bc5 | 2013-06-03 16:10:42 +0300 | [diff] [blame] | 438 | ret = crtc->funcs->cursor_set(crtc, NULL, 0, 0, 0); |
| 439 | if (ret) |
Daniel Vetter | b7bdf0a8 | 2015-08-25 17:20:28 +0200 | [diff] [blame] | 440 | return ret; |
Ville Syrjälä | 3858bc5 | 2013-06-03 16:10:42 +0300 | [diff] [blame] | 441 | } |
| 442 | |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 443 | ret = drm_mode_set_config_internal(mode_set); |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 444 | if (ret) |
Daniel Vetter | b7bdf0a8 | 2015-08-25 17:20:28 +0200 | [diff] [blame] | 445 | return ret; |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 446 | } |
Daniel Vetter | b7bdf0a8 | 2015-08-25 17:20:28 +0200 | [diff] [blame] | 447 | |
| 448 | return 0; |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 449 | } |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 450 | |
| 451 | /** |
| 452 | * drm_fb_helper_restore_fbdev_mode_unlocked - restore fbdev configuration |
| 453 | * @fb_helper: fbcon to restore |
| 454 | * |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 455 | * This should be called from driver's drm &drm_driver.lastclose callback |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 456 | * when implementing an fbcon on top of kms using this helper. This ensures that |
| 457 | * the user isn't greeted with a black screen when e.g. X dies. |
Daniel Vetter | b7bdf0a8 | 2015-08-25 17:20:28 +0200 | [diff] [blame] | 458 | * |
| 459 | * RETURNS: |
| 460 | * Zero if everything went ok, negative error code otherwise. |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 461 | */ |
Daniel Vetter | b7bdf0a8 | 2015-08-25 17:20:28 +0200 | [diff] [blame] | 462 | int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper) |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 463 | { |
| 464 | struct drm_device *dev = fb_helper->dev; |
Daniel Vetter | b7bdf0a8 | 2015-08-25 17:20:28 +0200 | [diff] [blame] | 465 | bool do_delayed; |
| 466 | int ret; |
Dave Airlie | e2809c7 | 2014-11-26 13:15:24 +1000 | [diff] [blame] | 467 | |
Daniel Vetter | f64c557 | 2015-08-25 15:45:13 +0200 | [diff] [blame] | 468 | if (!drm_fbdev_emulation) |
| 469 | return -ENODEV; |
| 470 | |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 471 | drm_modeset_lock_all(dev); |
| 472 | ret = restore_fbdev_mode(fb_helper); |
Dave Airlie | e2809c7 | 2014-11-26 13:15:24 +1000 | [diff] [blame] | 473 | |
| 474 | do_delayed = fb_helper->delayed_hotplug; |
| 475 | if (do_delayed) |
| 476 | fb_helper->delayed_hotplug = false; |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 477 | drm_modeset_unlock_all(dev); |
Dave Airlie | e2809c7 | 2014-11-26 13:15:24 +1000 | [diff] [blame] | 478 | |
| 479 | if (do_delayed) |
| 480 | drm_fb_helper_hotplug_event(fb_helper); |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 481 | return ret; |
| 482 | } |
| 483 | EXPORT_SYMBOL(drm_fb_helper_restore_fbdev_mode_unlocked); |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 484 | |
Geert Uytterhoeven | 2c4124f | 2015-08-04 15:22:11 +0200 | [diff] [blame] | 485 | static bool drm_fb_helper_is_bound(struct drm_fb_helper *fb_helper) |
| 486 | { |
| 487 | struct drm_device *dev = fb_helper->dev; |
| 488 | struct drm_crtc *crtc; |
| 489 | int bound = 0, crtcs_bound = 0; |
| 490 | |
| 491 | /* Sometimes user space wants everything disabled, so don't steal the |
| 492 | * display if there's a master. */ |
Johannes Berg | f17b3ea | 2016-08-11 11:50:21 +0200 | [diff] [blame] | 493 | if (READ_ONCE(dev->master)) |
Geert Uytterhoeven | 2c4124f | 2015-08-04 15:22:11 +0200 | [diff] [blame] | 494 | return false; |
| 495 | |
| 496 | drm_for_each_crtc(crtc, dev) { |
| 497 | if (crtc->primary->fb) |
| 498 | crtcs_bound++; |
| 499 | if (crtc->primary->fb == fb_helper->fb) |
| 500 | bound++; |
| 501 | } |
| 502 | |
| 503 | if (bound < crtcs_bound) |
| 504 | return false; |
| 505 | |
| 506 | return true; |
| 507 | } |
| 508 | |
| 509 | #ifdef CONFIG_MAGIC_SYSRQ |
Daniel Vetter | d21bf46 | 2013-01-20 18:09:52 +0100 | [diff] [blame] | 510 | /* |
| 511 | * restore fbcon display for all kms driver's using this helper, used for sysrq |
| 512 | * and panic handling. |
| 513 | */ |
Sachin Kamat | 78b9c35 | 2012-08-01 17:15:32 +0530 | [diff] [blame] | 514 | static bool drm_fb_helper_force_kernel_mode(void) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 515 | { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 516 | bool ret, error = false; |
| 517 | struct drm_fb_helper *helper; |
| 518 | |
| 519 | if (list_empty(&kernel_fb_helper_list)) |
| 520 | return false; |
| 521 | |
| 522 | list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) { |
Thierry Reding | b77f076 | 2014-04-29 11:44:32 +0200 | [diff] [blame] | 523 | struct drm_device *dev = helper->dev; |
| 524 | |
| 525 | if (dev->switch_power_state == DRM_SWITCH_POWER_OFF) |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 526 | continue; |
| 527 | |
Daniel Vetter | dd908c8 | 2015-07-28 13:18:41 +0200 | [diff] [blame] | 528 | drm_modeset_lock_all(dev); |
Geert Uytterhoeven | 3d9e35a | 2015-08-04 15:22:10 +0200 | [diff] [blame] | 529 | ret = restore_fbdev_mode(helper); |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 530 | if (ret) |
| 531 | error = true; |
Daniel Vetter | cb597bb | 2014-07-27 19:09:33 +0200 | [diff] [blame] | 532 | drm_modeset_unlock_all(dev); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 533 | } |
| 534 | return error; |
| 535 | } |
| 536 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 537 | static void drm_fb_helper_restore_work_fn(struct work_struct *ignored) |
| 538 | { |
Daniel Vetter | d21bf46 | 2013-01-20 18:09:52 +0100 | [diff] [blame] | 539 | bool ret; |
| 540 | ret = drm_fb_helper_force_kernel_mode(); |
| 541 | if (ret == true) |
| 542 | DRM_ERROR("Failed to restore crtc configuration\n"); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 543 | } |
| 544 | static DECLARE_WORK(drm_fb_helper_restore_work, drm_fb_helper_restore_work_fn); |
| 545 | |
Dmitry Torokhov | 1495cc9 | 2010-08-17 21:15:46 -0700 | [diff] [blame] | 546 | static void drm_fb_helper_sysrq(int dummy1) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 547 | { |
| 548 | schedule_work(&drm_fb_helper_restore_work); |
| 549 | } |
| 550 | |
| 551 | static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { |
| 552 | .handler = drm_fb_helper_sysrq, |
| 553 | .help_msg = "force-fb(V)", |
| 554 | .action_msg = "Restore framebuffer console", |
| 555 | }; |
Randy Dunlap | b8c40d6 | 2010-03-25 18:29:05 +0000 | [diff] [blame] | 556 | #else |
| 557 | static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { }; |
Mikael Pettersson | bea1d35 | 2009-09-28 18:26:25 +0200 | [diff] [blame] | 558 | #endif |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 559 | |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 560 | static void drm_fb_helper_dpms(struct fb_info *info, int dpms_mode) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 561 | { |
| 562 | struct drm_fb_helper *fb_helper = info->par; |
| 563 | struct drm_device *dev = fb_helper->dev; |
| 564 | struct drm_crtc *crtc; |
Jesse Barnes | 023eb57 | 2010-07-02 10:48:08 -0700 | [diff] [blame] | 565 | struct drm_connector *connector; |
Jesse Barnes | 023eb57 | 2010-07-02 10:48:08 -0700 | [diff] [blame] | 566 | int i, j; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 567 | |
| 568 | /* |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 569 | * For each CRTC in this fb, turn the connectors on/off. |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 570 | */ |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 571 | drm_modeset_lock_all(dev); |
Daniel Vetter | 20c60c3 | 2012-12-17 12:13:23 +0100 | [diff] [blame] | 572 | if (!drm_fb_helper_is_bound(fb_helper)) { |
| 573 | drm_modeset_unlock_all(dev); |
| 574 | return; |
| 575 | } |
| 576 | |
Jesse Barnes | e87b2c4 | 2009-09-17 18:14:41 -0700 | [diff] [blame] | 577 | for (i = 0; i < fb_helper->crtc_count; i++) { |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 578 | crtc = fb_helper->crtc_info[i].mode_set.crtc; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 579 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 580 | if (!crtc->enabled) |
| 581 | continue; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 582 | |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 583 | /* Walk the connectors & encoders on this fb turning them on/off */ |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 584 | drm_fb_helper_for_each_connector(fb_helper, j) { |
Jesse Barnes | 023eb57 | 2010-07-02 10:48:08 -0700 | [diff] [blame] | 585 | connector = fb_helper->connector_info[j]->connector; |
Daniel Vetter | e04190e | 2012-09-07 10:14:52 +0200 | [diff] [blame] | 586 | connector->funcs->dpms(connector, dpms_mode); |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 587 | drm_object_property_set_value(&connector->base, |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 588 | dev->mode_config.dpms_property, dpms_mode); |
Jesse Barnes | 023eb57 | 2010-07-02 10:48:08 -0700 | [diff] [blame] | 589 | } |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 590 | } |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 591 | drm_modeset_unlock_all(dev); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 592 | } |
| 593 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 594 | /** |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 595 | * drm_fb_helper_blank - implementation for &fb_ops.fb_blank |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 596 | * @blank: desired blanking state |
| 597 | * @info: fbdev registered by the helper |
| 598 | */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 599 | int drm_fb_helper_blank(int blank, struct fb_info *info) |
| 600 | { |
Daniel Vetter | c50bfd0 | 2015-07-28 13:18:40 +0200 | [diff] [blame] | 601 | if (oops_in_progress) |
| 602 | return -EBUSY; |
| 603 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 604 | switch (blank) { |
James Simmons | 731b5a1 | 2009-10-29 20:39:07 +0000 | [diff] [blame] | 605 | /* Display: On; HSync: On, VSync: On */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 606 | case FB_BLANK_UNBLANK: |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 607 | drm_fb_helper_dpms(info, DRM_MODE_DPMS_ON); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 608 | break; |
James Simmons | 731b5a1 | 2009-10-29 20:39:07 +0000 | [diff] [blame] | 609 | /* Display: Off; HSync: On, VSync: On */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 610 | case FB_BLANK_NORMAL: |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 611 | drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 612 | break; |
James Simmons | 731b5a1 | 2009-10-29 20:39:07 +0000 | [diff] [blame] | 613 | /* Display: Off; HSync: Off, VSync: On */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 614 | case FB_BLANK_HSYNC_SUSPEND: |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 615 | drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 616 | break; |
James Simmons | 731b5a1 | 2009-10-29 20:39:07 +0000 | [diff] [blame] | 617 | /* Display: Off; HSync: On, VSync: Off */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 618 | case FB_BLANK_VSYNC_SUSPEND: |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 619 | drm_fb_helper_dpms(info, DRM_MODE_DPMS_SUSPEND); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 620 | break; |
James Simmons | 731b5a1 | 2009-10-29 20:39:07 +0000 | [diff] [blame] | 621 | /* Display: Off; HSync: Off, VSync: Off */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 622 | case FB_BLANK_POWERDOWN: |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 623 | drm_fb_helper_dpms(info, DRM_MODE_DPMS_OFF); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 624 | break; |
| 625 | } |
| 626 | return 0; |
| 627 | } |
| 628 | EXPORT_SYMBOL(drm_fb_helper_blank); |
| 629 | |
Ville Syrjälä | a288960 | 2016-10-26 17:41:18 +0300 | [diff] [blame] | 630 | static void drm_fb_helper_modeset_release(struct drm_fb_helper *helper, |
| 631 | struct drm_mode_set *modeset) |
| 632 | { |
| 633 | int i; |
| 634 | |
| 635 | for (i = 0; i < modeset->num_connectors; i++) { |
Thierry Reding | ad09360 | 2017-02-28 15:46:39 +0100 | [diff] [blame] | 636 | drm_connector_put(modeset->connectors[i]); |
Ville Syrjälä | a288960 | 2016-10-26 17:41:18 +0300 | [diff] [blame] | 637 | modeset->connectors[i] = NULL; |
| 638 | } |
| 639 | modeset->num_connectors = 0; |
| 640 | |
| 641 | drm_mode_destroy(helper->dev, modeset->mode); |
| 642 | modeset->mode = NULL; |
| 643 | |
| 644 | /* FIXME should hold a ref? */ |
| 645 | modeset->fb = NULL; |
| 646 | } |
| 647 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 648 | static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper) |
| 649 | { |
| 650 | int i; |
| 651 | |
Dave Airlie | 6e86d58 | 2016-04-27 11:24:51 +1000 | [diff] [blame] | 652 | for (i = 0; i < helper->connector_count; i++) { |
Thierry Reding | ad09360 | 2017-02-28 15:46:39 +0100 | [diff] [blame] | 653 | drm_connector_put(helper->connector_info[i]->connector); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 654 | kfree(helper->connector_info[i]); |
Dave Airlie | 6e86d58 | 2016-04-27 11:24:51 +1000 | [diff] [blame] | 655 | } |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 656 | kfree(helper->connector_info); |
Ville Syrjälä | a288960 | 2016-10-26 17:41:18 +0300 | [diff] [blame] | 657 | |
Sascha Hauer | a1b7736 | 2012-02-01 11:38:22 +0100 | [diff] [blame] | 658 | for (i = 0; i < helper->crtc_count; i++) { |
Ville Syrjälä | a288960 | 2016-10-26 17:41:18 +0300 | [diff] [blame] | 659 | struct drm_mode_set *modeset = &helper->crtc_info[i].mode_set; |
| 660 | |
| 661 | drm_fb_helper_modeset_release(helper, modeset); |
| 662 | kfree(modeset->connectors); |
Sascha Hauer | a1b7736 | 2012-02-01 11:38:22 +0100 | [diff] [blame] | 663 | } |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 664 | kfree(helper->crtc_info); |
| 665 | } |
| 666 | |
Noralf Trønnes | cfe6342 | 2016-08-23 13:54:06 +0200 | [diff] [blame] | 667 | static void drm_fb_helper_resume_worker(struct work_struct *work) |
| 668 | { |
| 669 | struct drm_fb_helper *helper = container_of(work, struct drm_fb_helper, |
| 670 | resume_work); |
| 671 | |
| 672 | console_lock(); |
| 673 | fb_set_suspend(helper->fbdev, 0); |
| 674 | console_unlock(); |
| 675 | } |
| 676 | |
Noralf Trønnes | eaa434d | 2016-04-28 17:18:33 +0200 | [diff] [blame] | 677 | static void drm_fb_helper_dirty_work(struct work_struct *work) |
| 678 | { |
| 679 | struct drm_fb_helper *helper = container_of(work, struct drm_fb_helper, |
| 680 | dirty_work); |
| 681 | struct drm_clip_rect *clip = &helper->dirty_clip; |
| 682 | struct drm_clip_rect clip_copy; |
| 683 | unsigned long flags; |
| 684 | |
| 685 | spin_lock_irqsave(&helper->dirty_lock, flags); |
| 686 | clip_copy = *clip; |
| 687 | clip->x1 = clip->y1 = ~0; |
| 688 | clip->x2 = clip->y2 = 0; |
| 689 | spin_unlock_irqrestore(&helper->dirty_lock, flags); |
| 690 | |
Takashi Iwai | 87d3b65 | 2016-10-20 17:05:30 +0200 | [diff] [blame] | 691 | /* call dirty callback only when it has been really touched */ |
| 692 | if (clip_copy.x1 < clip_copy.x2 && clip_copy.y1 < clip_copy.y2) |
| 693 | helper->fb->funcs->dirty(helper->fb, NULL, 0, 0, &clip_copy, 1); |
Noralf Trønnes | eaa434d | 2016-04-28 17:18:33 +0200 | [diff] [blame] | 694 | } |
| 695 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 696 | /** |
Thierry Reding | 10a2310 | 2014-06-27 17:19:24 +0200 | [diff] [blame] | 697 | * drm_fb_helper_prepare - setup a drm_fb_helper structure |
| 698 | * @dev: DRM device |
| 699 | * @helper: driver-allocated fbdev helper structure to set up |
| 700 | * @funcs: pointer to structure of functions associate with this helper |
| 701 | * |
| 702 | * Sets up the bare minimum to make the framebuffer helper usable. This is |
| 703 | * useful to implement race-free initialization of the polling helpers. |
| 704 | */ |
| 705 | void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper, |
| 706 | const struct drm_fb_helper_funcs *funcs) |
| 707 | { |
| 708 | INIT_LIST_HEAD(&helper->kernel_fb_list); |
Noralf Trønnes | eaa434d | 2016-04-28 17:18:33 +0200 | [diff] [blame] | 709 | spin_lock_init(&helper->dirty_lock); |
Noralf Trønnes | cfe6342 | 2016-08-23 13:54:06 +0200 | [diff] [blame] | 710 | INIT_WORK(&helper->resume_work, drm_fb_helper_resume_worker); |
Noralf Trønnes | eaa434d | 2016-04-28 17:18:33 +0200 | [diff] [blame] | 711 | INIT_WORK(&helper->dirty_work, drm_fb_helper_dirty_work); |
| 712 | helper->dirty_clip.x1 = helper->dirty_clip.y1 = ~0; |
Thierry Reding | 10a2310 | 2014-06-27 17:19:24 +0200 | [diff] [blame] | 713 | helper->funcs = funcs; |
| 714 | helper->dev = dev; |
| 715 | } |
| 716 | EXPORT_SYMBOL(drm_fb_helper_prepare); |
| 717 | |
| 718 | /** |
Daniel Vetter | ed84e25 | 2017-02-07 15:10:49 +0100 | [diff] [blame] | 719 | * drm_fb_helper_init - initialize a &struct drm_fb_helper |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 720 | * @dev: drm device |
| 721 | * @fb_helper: driver-allocated fbdev helper structure to initialize |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 722 | * @max_conn_count: max connector count |
| 723 | * |
| 724 | * This allocates the structures for the fbdev helper with the given limits. |
| 725 | * Note that this won't yet touch the hardware (through the driver interfaces) |
| 726 | * nor register the fbdev. This is only done in drm_fb_helper_initial_config() |
| 727 | * to allow driver writes more control over the exact init sequence. |
| 728 | * |
Thierry Reding | 10a2310 | 2014-06-27 17:19:24 +0200 | [diff] [blame] | 729 | * Drivers must call drm_fb_helper_prepare() before calling this function. |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 730 | * |
| 731 | * RETURNS: |
| 732 | * Zero if everything went ok, nonzero otherwise. |
| 733 | */ |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 734 | int drm_fb_helper_init(struct drm_device *dev, |
| 735 | struct drm_fb_helper *fb_helper, |
Gabriel Krisman Bertazi | e4563f6 | 2017-02-02 14:26:40 -0200 | [diff] [blame] | 736 | int max_conn_count) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 737 | { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 738 | struct drm_crtc *crtc; |
Gabriel Krisman Bertazi | e4563f6 | 2017-02-02 14:26:40 -0200 | [diff] [blame] | 739 | struct drm_mode_config *config = &dev->mode_config; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 740 | int i; |
| 741 | |
Daniel Vetter | f64c557 | 2015-08-25 15:45:13 +0200 | [diff] [blame] | 742 | if (!drm_fbdev_emulation) |
| 743 | return 0; |
| 744 | |
Xiubo Li | 04cfe97 | 2014-03-10 09:33:58 +0800 | [diff] [blame] | 745 | if (!max_conn_count) |
| 746 | return -EINVAL; |
| 747 | |
Gabriel Krisman Bertazi | e4563f6 | 2017-02-02 14:26:40 -0200 | [diff] [blame] | 748 | fb_helper->crtc_info = kcalloc(config->num_crtc, sizeof(struct drm_fb_helper_crtc), GFP_KERNEL); |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 749 | if (!fb_helper->crtc_info) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 750 | return -ENOMEM; |
| 751 | |
Gabriel Krisman Bertazi | e4563f6 | 2017-02-02 14:26:40 -0200 | [diff] [blame] | 752 | fb_helper->crtc_count = config->num_crtc; |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 753 | fb_helper->connector_info = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_fb_helper_connector *), GFP_KERNEL); |
| 754 | if (!fb_helper->connector_info) { |
| 755 | kfree(fb_helper->crtc_info); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 756 | return -ENOMEM; |
| 757 | } |
Dave Airlie | 65c2a89 | 2014-06-05 14:01:30 +1000 | [diff] [blame] | 758 | fb_helper->connector_info_alloc_count = dev->mode_config.num_connector; |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 759 | fb_helper->connector_count = 0; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 760 | |
Gabriel Krisman Bertazi | e4563f6 | 2017-02-02 14:26:40 -0200 | [diff] [blame] | 761 | for (i = 0; i < fb_helper->crtc_count; i++) { |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 762 | fb_helper->crtc_info[i].mode_set.connectors = |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 763 | kcalloc(max_conn_count, |
| 764 | sizeof(struct drm_connector *), |
| 765 | GFP_KERNEL); |
| 766 | |
Laurent Pinchart | 4a1b071 | 2012-05-17 13:27:21 +0200 | [diff] [blame] | 767 | if (!fb_helper->crtc_info[i].mode_set.connectors) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 768 | goto out_free; |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 769 | fb_helper->crtc_info[i].mode_set.num_connectors = 0; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | i = 0; |
Daniel Vetter | 6295d60 | 2015-07-09 23:44:25 +0200 | [diff] [blame] | 773 | drm_for_each_crtc(crtc, dev) { |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 774 | fb_helper->crtc_info[i].mode_set.crtc = crtc; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 775 | i++; |
| 776 | } |
Sascha Hauer | e9ad318 | 2012-02-01 11:38:25 +0100 | [diff] [blame] | 777 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 778 | return 0; |
| 779 | out_free: |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 780 | drm_fb_helper_crtc_free(fb_helper); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 781 | return -ENOMEM; |
| 782 | } |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 783 | EXPORT_SYMBOL(drm_fb_helper_init); |
| 784 | |
Archit Taneja | b8017d6 | 2015-07-22 14:57:56 +0530 | [diff] [blame] | 785 | /** |
| 786 | * drm_fb_helper_alloc_fbi - allocate fb_info and some of its members |
| 787 | * @fb_helper: driver-allocated fbdev helper |
| 788 | * |
| 789 | * A helper to alloc fb_info and the members cmap and apertures. Called |
Daniel Vetter | da7bdda | 2017-02-07 17:16:03 +0100 | [diff] [blame] | 790 | * by the driver within the fb_probe fb_helper callback function. Drivers do not |
| 791 | * need to release the allocated fb_info structure themselves, this is |
| 792 | * automatically done when calling drm_fb_helper_fini(). |
Archit Taneja | b8017d6 | 2015-07-22 14:57:56 +0530 | [diff] [blame] | 793 | * |
| 794 | * RETURNS: |
| 795 | * fb_info pointer if things went okay, pointer containing error code |
| 796 | * otherwise |
| 797 | */ |
| 798 | struct fb_info *drm_fb_helper_alloc_fbi(struct drm_fb_helper *fb_helper) |
| 799 | { |
| 800 | struct device *dev = fb_helper->dev->dev; |
| 801 | struct fb_info *info; |
| 802 | int ret; |
| 803 | |
| 804 | info = framebuffer_alloc(0, dev); |
| 805 | if (!info) |
| 806 | return ERR_PTR(-ENOMEM); |
| 807 | |
| 808 | ret = fb_alloc_cmap(&info->cmap, 256, 0); |
| 809 | if (ret) |
| 810 | goto err_release; |
| 811 | |
| 812 | info->apertures = alloc_apertures(1); |
| 813 | if (!info->apertures) { |
| 814 | ret = -ENOMEM; |
| 815 | goto err_free_cmap; |
| 816 | } |
| 817 | |
| 818 | fb_helper->fbdev = info; |
| 819 | |
| 820 | return info; |
| 821 | |
| 822 | err_free_cmap: |
| 823 | fb_dealloc_cmap(&info->cmap); |
| 824 | err_release: |
| 825 | framebuffer_release(info); |
| 826 | return ERR_PTR(ret); |
| 827 | } |
| 828 | EXPORT_SYMBOL(drm_fb_helper_alloc_fbi); |
| 829 | |
| 830 | /** |
| 831 | * drm_fb_helper_unregister_fbi - unregister fb_info framebuffer device |
| 832 | * @fb_helper: driver-allocated fbdev helper |
| 833 | * |
| 834 | * A wrapper around unregister_framebuffer, to release the fb_info |
Daniel Vetter | ed84e25 | 2017-02-07 15:10:49 +0100 | [diff] [blame] | 835 | * framebuffer device. This must be called before releasing all resources for |
| 836 | * @fb_helper by calling drm_fb_helper_fini(). |
Archit Taneja | b8017d6 | 2015-07-22 14:57:56 +0530 | [diff] [blame] | 837 | */ |
| 838 | void drm_fb_helper_unregister_fbi(struct drm_fb_helper *fb_helper) |
| 839 | { |
| 840 | if (fb_helper && fb_helper->fbdev) |
| 841 | unregister_framebuffer(fb_helper->fbdev); |
| 842 | } |
| 843 | EXPORT_SYMBOL(drm_fb_helper_unregister_fbi); |
| 844 | |
| 845 | /** |
Daniel Vetter | ed84e25 | 2017-02-07 15:10:49 +0100 | [diff] [blame] | 846 | * drm_fb_helper_fini - finialize a &struct drm_fb_helper |
| 847 | * @fb_helper: driver-allocated fbdev helper |
| 848 | * |
| 849 | * This cleans up all remaining resources associated with @fb_helper. Must be |
| 850 | * called after drm_fb_helper_unlink_fbi() was called. |
| 851 | */ |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 852 | void drm_fb_helper_fini(struct drm_fb_helper *fb_helper) |
| 853 | { |
Daniel Vetter | da7bdda | 2017-02-07 17:16:03 +0100 | [diff] [blame] | 854 | struct fb_info *info; |
| 855 | |
| 856 | if (!drm_fbdev_emulation || !fb_helper) |
Daniel Vetter | f64c557 | 2015-08-25 15:45:13 +0200 | [diff] [blame] | 857 | return; |
| 858 | |
Daniel Vetter | da7bdda | 2017-02-07 17:16:03 +0100 | [diff] [blame] | 859 | info = fb_helper->fbdev; |
| 860 | if (info) { |
| 861 | if (info->cmap.len) |
| 862 | fb_dealloc_cmap(&info->cmap); |
| 863 | framebuffer_release(info); |
| 864 | } |
| 865 | fb_helper->fbdev = NULL; |
| 866 | |
Chris Wilson | 24f76b2 | 2017-02-07 12:49:56 +0000 | [diff] [blame] | 867 | cancel_work_sync(&fb_helper->resume_work); |
Chris Wilson | f21b9a9 | 2017-02-07 12:49:55 +0000 | [diff] [blame] | 868 | cancel_work_sync(&fb_helper->dirty_work); |
| 869 | |
Chris Wilson | a53ca63 | 2016-11-29 12:02:17 +0000 | [diff] [blame] | 870 | mutex_lock(&kernel_fb_helper_lock); |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 871 | if (!list_empty(&fb_helper->kernel_fb_list)) { |
| 872 | list_del(&fb_helper->kernel_fb_list); |
| 873 | if (list_empty(&kernel_fb_helper_list)) { |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 874 | unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op); |
| 875 | } |
| 876 | } |
Chris Wilson | a53ca63 | 2016-11-29 12:02:17 +0000 | [diff] [blame] | 877 | mutex_unlock(&kernel_fb_helper_lock); |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 878 | |
| 879 | drm_fb_helper_crtc_free(fb_helper); |
| 880 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 881 | } |
| 882 | EXPORT_SYMBOL(drm_fb_helper_fini); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 883 | |
Archit Taneja | 47074ab | 2015-07-22 14:57:57 +0530 | [diff] [blame] | 884 | /** |
| 885 | * drm_fb_helper_unlink_fbi - wrapper around unlink_framebuffer |
| 886 | * @fb_helper: driver-allocated fbdev helper |
| 887 | * |
| 888 | * A wrapper around unlink_framebuffer implemented by fbdev core |
| 889 | */ |
| 890 | void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper) |
| 891 | { |
| 892 | if (fb_helper && fb_helper->fbdev) |
| 893 | unlink_framebuffer(fb_helper->fbdev); |
| 894 | } |
| 895 | EXPORT_SYMBOL(drm_fb_helper_unlink_fbi); |
| 896 | |
Noralf Trønnes | eaa434d | 2016-04-28 17:18:33 +0200 | [diff] [blame] | 897 | static void drm_fb_helper_dirty(struct fb_info *info, u32 x, u32 y, |
| 898 | u32 width, u32 height) |
| 899 | { |
| 900 | struct drm_fb_helper *helper = info->par; |
| 901 | struct drm_clip_rect *clip = &helper->dirty_clip; |
| 902 | unsigned long flags; |
| 903 | |
| 904 | if (!helper->fb->funcs->dirty) |
| 905 | return; |
| 906 | |
| 907 | spin_lock_irqsave(&helper->dirty_lock, flags); |
| 908 | clip->x1 = min_t(u32, clip->x1, x); |
| 909 | clip->y1 = min_t(u32, clip->y1, y); |
| 910 | clip->x2 = max_t(u32, clip->x2, x + width); |
| 911 | clip->y2 = max_t(u32, clip->y2, y + height); |
| 912 | spin_unlock_irqrestore(&helper->dirty_lock, flags); |
| 913 | |
| 914 | schedule_work(&helper->dirty_work); |
| 915 | } |
| 916 | |
| 917 | /** |
| 918 | * drm_fb_helper_deferred_io() - fbdev deferred_io callback function |
| 919 | * @info: fb_info struct pointer |
| 920 | * @pagelist: list of dirty mmap framebuffer pages |
| 921 | * |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 922 | * This function is used as the &fb_deferred_io.deferred_io |
Noralf Trønnes | eaa434d | 2016-04-28 17:18:33 +0200 | [diff] [blame] | 923 | * callback function for flushing the fbdev mmap writes. |
| 924 | */ |
| 925 | void drm_fb_helper_deferred_io(struct fb_info *info, |
| 926 | struct list_head *pagelist) |
| 927 | { |
| 928 | unsigned long start, end, min, max; |
| 929 | struct page *page; |
| 930 | u32 y1, y2; |
| 931 | |
| 932 | min = ULONG_MAX; |
| 933 | max = 0; |
| 934 | list_for_each_entry(page, pagelist, lru) { |
| 935 | start = page->index << PAGE_SHIFT; |
| 936 | end = start + PAGE_SIZE - 1; |
| 937 | min = min(min, start); |
| 938 | max = max(max, end); |
| 939 | } |
| 940 | |
| 941 | if (min < max) { |
| 942 | y1 = min / info->fix.line_length; |
| 943 | y2 = min_t(u32, DIV_ROUND_UP(max, info->fix.line_length), |
| 944 | info->var.yres); |
| 945 | drm_fb_helper_dirty(info, 0, y1, info->var.xres, y2 - y1); |
| 946 | } |
| 947 | } |
| 948 | EXPORT_SYMBOL(drm_fb_helper_deferred_io); |
| 949 | |
Archit Taneja | cbb1a82 | 2015-07-31 16:21:41 +0530 | [diff] [blame] | 950 | /** |
| 951 | * drm_fb_helper_sys_read - wrapper around fb_sys_read |
| 952 | * @info: fb_info struct pointer |
| 953 | * @buf: userspace buffer to read from framebuffer memory |
| 954 | * @count: number of bytes to read from framebuffer memory |
| 955 | * @ppos: read offset within framebuffer memory |
| 956 | * |
| 957 | * A wrapper around fb_sys_read implemented by fbdev core |
| 958 | */ |
| 959 | ssize_t drm_fb_helper_sys_read(struct fb_info *info, char __user *buf, |
| 960 | size_t count, loff_t *ppos) |
| 961 | { |
| 962 | return fb_sys_read(info, buf, count, ppos); |
| 963 | } |
| 964 | EXPORT_SYMBOL(drm_fb_helper_sys_read); |
| 965 | |
| 966 | /** |
| 967 | * drm_fb_helper_sys_write - wrapper around fb_sys_write |
| 968 | * @info: fb_info struct pointer |
| 969 | * @buf: userspace buffer to write to framebuffer memory |
| 970 | * @count: number of bytes to write to framebuffer memory |
| 971 | * @ppos: write offset within framebuffer memory |
| 972 | * |
| 973 | * A wrapper around fb_sys_write implemented by fbdev core |
| 974 | */ |
| 975 | ssize_t drm_fb_helper_sys_write(struct fb_info *info, const char __user *buf, |
| 976 | size_t count, loff_t *ppos) |
| 977 | { |
Noralf Trønnes | eaa434d | 2016-04-28 17:18:33 +0200 | [diff] [blame] | 978 | ssize_t ret; |
| 979 | |
| 980 | ret = fb_sys_write(info, buf, count, ppos); |
| 981 | if (ret > 0) |
| 982 | drm_fb_helper_dirty(info, 0, 0, info->var.xres, |
| 983 | info->var.yres); |
| 984 | |
| 985 | return ret; |
Archit Taneja | cbb1a82 | 2015-07-31 16:21:41 +0530 | [diff] [blame] | 986 | } |
| 987 | EXPORT_SYMBOL(drm_fb_helper_sys_write); |
| 988 | |
Archit Taneja | 742547b | 2015-07-31 16:21:42 +0530 | [diff] [blame] | 989 | /** |
| 990 | * drm_fb_helper_sys_fillrect - wrapper around sys_fillrect |
| 991 | * @info: fbdev registered by the helper |
| 992 | * @rect: info about rectangle to fill |
| 993 | * |
| 994 | * A wrapper around sys_fillrect implemented by fbdev core |
| 995 | */ |
| 996 | void drm_fb_helper_sys_fillrect(struct fb_info *info, |
| 997 | const struct fb_fillrect *rect) |
| 998 | { |
| 999 | sys_fillrect(info, rect); |
Noralf Trønnes | eaa434d | 2016-04-28 17:18:33 +0200 | [diff] [blame] | 1000 | drm_fb_helper_dirty(info, rect->dx, rect->dy, |
| 1001 | rect->width, rect->height); |
Archit Taneja | 742547b | 2015-07-31 16:21:42 +0530 | [diff] [blame] | 1002 | } |
| 1003 | EXPORT_SYMBOL(drm_fb_helper_sys_fillrect); |
| 1004 | |
| 1005 | /** |
| 1006 | * drm_fb_helper_sys_copyarea - wrapper around sys_copyarea |
| 1007 | * @info: fbdev registered by the helper |
| 1008 | * @area: info about area to copy |
| 1009 | * |
| 1010 | * A wrapper around sys_copyarea implemented by fbdev core |
| 1011 | */ |
| 1012 | void drm_fb_helper_sys_copyarea(struct fb_info *info, |
| 1013 | const struct fb_copyarea *area) |
| 1014 | { |
| 1015 | sys_copyarea(info, area); |
Noralf Trønnes | eaa434d | 2016-04-28 17:18:33 +0200 | [diff] [blame] | 1016 | drm_fb_helper_dirty(info, area->dx, area->dy, |
| 1017 | area->width, area->height); |
Archit Taneja | 742547b | 2015-07-31 16:21:42 +0530 | [diff] [blame] | 1018 | } |
| 1019 | EXPORT_SYMBOL(drm_fb_helper_sys_copyarea); |
| 1020 | |
| 1021 | /** |
| 1022 | * drm_fb_helper_sys_imageblit - wrapper around sys_imageblit |
| 1023 | * @info: fbdev registered by the helper |
| 1024 | * @image: info about image to blit |
| 1025 | * |
| 1026 | * A wrapper around sys_imageblit implemented by fbdev core |
| 1027 | */ |
| 1028 | void drm_fb_helper_sys_imageblit(struct fb_info *info, |
| 1029 | const struct fb_image *image) |
| 1030 | { |
| 1031 | sys_imageblit(info, image); |
Noralf Trønnes | eaa434d | 2016-04-28 17:18:33 +0200 | [diff] [blame] | 1032 | drm_fb_helper_dirty(info, image->dx, image->dy, |
| 1033 | image->width, image->height); |
Archit Taneja | 742547b | 2015-07-31 16:21:42 +0530 | [diff] [blame] | 1034 | } |
| 1035 | EXPORT_SYMBOL(drm_fb_helper_sys_imageblit); |
| 1036 | |
| 1037 | /** |
| 1038 | * drm_fb_helper_cfb_fillrect - wrapper around cfb_fillrect |
| 1039 | * @info: fbdev registered by the helper |
| 1040 | * @rect: info about rectangle to fill |
| 1041 | * |
| 1042 | * A wrapper around cfb_imageblit implemented by fbdev core |
| 1043 | */ |
| 1044 | void drm_fb_helper_cfb_fillrect(struct fb_info *info, |
| 1045 | const struct fb_fillrect *rect) |
| 1046 | { |
| 1047 | cfb_fillrect(info, rect); |
Noralf Trønnes | eaa434d | 2016-04-28 17:18:33 +0200 | [diff] [blame] | 1048 | drm_fb_helper_dirty(info, rect->dx, rect->dy, |
| 1049 | rect->width, rect->height); |
Archit Taneja | 742547b | 2015-07-31 16:21:42 +0530 | [diff] [blame] | 1050 | } |
| 1051 | EXPORT_SYMBOL(drm_fb_helper_cfb_fillrect); |
| 1052 | |
| 1053 | /** |
| 1054 | * drm_fb_helper_cfb_copyarea - wrapper around cfb_copyarea |
| 1055 | * @info: fbdev registered by the helper |
| 1056 | * @area: info about area to copy |
| 1057 | * |
| 1058 | * A wrapper around cfb_copyarea implemented by fbdev core |
| 1059 | */ |
| 1060 | void drm_fb_helper_cfb_copyarea(struct fb_info *info, |
| 1061 | const struct fb_copyarea *area) |
| 1062 | { |
| 1063 | cfb_copyarea(info, area); |
Noralf Trønnes | eaa434d | 2016-04-28 17:18:33 +0200 | [diff] [blame] | 1064 | drm_fb_helper_dirty(info, area->dx, area->dy, |
| 1065 | area->width, area->height); |
Archit Taneja | 742547b | 2015-07-31 16:21:42 +0530 | [diff] [blame] | 1066 | } |
| 1067 | EXPORT_SYMBOL(drm_fb_helper_cfb_copyarea); |
| 1068 | |
| 1069 | /** |
| 1070 | * drm_fb_helper_cfb_imageblit - wrapper around cfb_imageblit |
| 1071 | * @info: fbdev registered by the helper |
| 1072 | * @image: info about image to blit |
| 1073 | * |
| 1074 | * A wrapper around cfb_imageblit implemented by fbdev core |
| 1075 | */ |
| 1076 | void drm_fb_helper_cfb_imageblit(struct fb_info *info, |
| 1077 | const struct fb_image *image) |
| 1078 | { |
| 1079 | cfb_imageblit(info, image); |
Noralf Trønnes | eaa434d | 2016-04-28 17:18:33 +0200 | [diff] [blame] | 1080 | drm_fb_helper_dirty(info, image->dx, image->dy, |
| 1081 | image->width, image->height); |
Archit Taneja | 742547b | 2015-07-31 16:21:42 +0530 | [diff] [blame] | 1082 | } |
| 1083 | EXPORT_SYMBOL(drm_fb_helper_cfb_imageblit); |
| 1084 | |
Archit Taneja | fdefa58 | 2015-07-31 16:21:43 +0530 | [diff] [blame] | 1085 | /** |
| 1086 | * drm_fb_helper_set_suspend - wrapper around fb_set_suspend |
| 1087 | * @fb_helper: driver-allocated fbdev helper |
Daniel Vetter | 28579f3 | 2016-08-23 17:27:27 +0200 | [diff] [blame] | 1088 | * @suspend: whether to suspend or resume |
Archit Taneja | fdefa58 | 2015-07-31 16:21:43 +0530 | [diff] [blame] | 1089 | * |
Noralf Trønnes | cfe6342 | 2016-08-23 13:54:06 +0200 | [diff] [blame] | 1090 | * A wrapper around fb_set_suspend implemented by fbdev core. |
| 1091 | * Use drm_fb_helper_set_suspend_unlocked() if you don't need to take |
| 1092 | * the lock yourself |
Archit Taneja | fdefa58 | 2015-07-31 16:21:43 +0530 | [diff] [blame] | 1093 | */ |
Daniel Vetter | 28579f3 | 2016-08-23 17:27:27 +0200 | [diff] [blame] | 1094 | void drm_fb_helper_set_suspend(struct drm_fb_helper *fb_helper, bool suspend) |
Archit Taneja | fdefa58 | 2015-07-31 16:21:43 +0530 | [diff] [blame] | 1095 | { |
| 1096 | if (fb_helper && fb_helper->fbdev) |
Daniel Vetter | 28579f3 | 2016-08-23 17:27:27 +0200 | [diff] [blame] | 1097 | fb_set_suspend(fb_helper->fbdev, suspend); |
Archit Taneja | fdefa58 | 2015-07-31 16:21:43 +0530 | [diff] [blame] | 1098 | } |
| 1099 | EXPORT_SYMBOL(drm_fb_helper_set_suspend); |
| 1100 | |
Noralf Trønnes | cfe6342 | 2016-08-23 13:54:06 +0200 | [diff] [blame] | 1101 | /** |
| 1102 | * drm_fb_helper_set_suspend_unlocked - wrapper around fb_set_suspend that also |
| 1103 | * takes the console lock |
| 1104 | * @fb_helper: driver-allocated fbdev helper |
Daniel Vetter | 28579f3 | 2016-08-23 17:27:27 +0200 | [diff] [blame] | 1105 | * @suspend: whether to suspend or resume |
Noralf Trønnes | cfe6342 | 2016-08-23 13:54:06 +0200 | [diff] [blame] | 1106 | * |
| 1107 | * A wrapper around fb_set_suspend() that takes the console lock. If the lock |
| 1108 | * isn't available on resume, a worker is tasked with waiting for the lock |
| 1109 | * to become available. The console lock can be pretty contented on resume |
| 1110 | * due to all the printk activity. |
| 1111 | * |
| 1112 | * This function can be called multiple times with the same state since |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 1113 | * &fb_info.state is checked to see if fbdev is running or not before locking. |
Noralf Trønnes | cfe6342 | 2016-08-23 13:54:06 +0200 | [diff] [blame] | 1114 | * |
| 1115 | * Use drm_fb_helper_set_suspend() if you need to take the lock yourself. |
| 1116 | */ |
| 1117 | void drm_fb_helper_set_suspend_unlocked(struct drm_fb_helper *fb_helper, |
Daniel Vetter | 28579f3 | 2016-08-23 17:27:27 +0200 | [diff] [blame] | 1118 | bool suspend) |
Noralf Trønnes | cfe6342 | 2016-08-23 13:54:06 +0200 | [diff] [blame] | 1119 | { |
| 1120 | if (!fb_helper || !fb_helper->fbdev) |
| 1121 | return; |
| 1122 | |
| 1123 | /* make sure there's no pending/ongoing resume */ |
| 1124 | flush_work(&fb_helper->resume_work); |
| 1125 | |
| 1126 | if (suspend) { |
| 1127 | if (fb_helper->fbdev->state != FBINFO_STATE_RUNNING) |
| 1128 | return; |
| 1129 | |
| 1130 | console_lock(); |
| 1131 | |
| 1132 | } else { |
| 1133 | if (fb_helper->fbdev->state == FBINFO_STATE_RUNNING) |
| 1134 | return; |
| 1135 | |
| 1136 | if (!console_trylock()) { |
| 1137 | schedule_work(&fb_helper->resume_work); |
| 1138 | return; |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | fb_set_suspend(fb_helper->fbdev, suspend); |
| 1143 | console_unlock(); |
| 1144 | } |
| 1145 | EXPORT_SYMBOL(drm_fb_helper_set_suspend_unlocked); |
| 1146 | |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 1147 | static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green, |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 1148 | u16 blue, u16 regno, struct fb_info *info) |
| 1149 | { |
| 1150 | struct drm_fb_helper *fb_helper = info->par; |
| 1151 | struct drm_framebuffer *fb = fb_helper->fb; |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 1152 | |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 1153 | if (info->fix.visual == FB_VISUAL_TRUECOLOR) { |
| 1154 | u32 *palette; |
| 1155 | u32 value; |
| 1156 | /* place color in psuedopalette */ |
| 1157 | if (regno > 16) |
| 1158 | return -EINVAL; |
| 1159 | palette = (u32 *)info->pseudo_palette; |
| 1160 | red >>= (16 - info->var.red.length); |
| 1161 | green >>= (16 - info->var.green.length); |
| 1162 | blue >>= (16 - info->var.blue.length); |
| 1163 | value = (red << info->var.red.offset) | |
| 1164 | (green << info->var.green.offset) | |
| 1165 | (blue << info->var.blue.offset); |
Rob Clark | 9da12b6a | 2011-02-16 02:45:51 +0000 | [diff] [blame] | 1166 | if (info->var.transp.length > 0) { |
| 1167 | u32 mask = (1 << info->var.transp.length) - 1; |
| 1168 | mask <<= info->var.transp.offset; |
| 1169 | value |= mask; |
| 1170 | } |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 1171 | palette[regno] = value; |
| 1172 | return 0; |
| 1173 | } |
| 1174 | |
Ville Syrjälä | 04c0c56 | 2013-05-27 20:19:57 +0300 | [diff] [blame] | 1175 | /* |
| 1176 | * The driver really shouldn't advertise pseudo/directcolor |
| 1177 | * visuals if it can't deal with the palette. |
| 1178 | */ |
| 1179 | if (WARN_ON(!fb_helper->funcs->gamma_set || |
| 1180 | !fb_helper->funcs->gamma_get)) |
| 1181 | return -EINVAL; |
| 1182 | |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 1183 | WARN_ON(fb->format->cpp[0] != 1); |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 1184 | |
Daniel Vetter | fef1480 | 2016-03-30 11:51:17 +0200 | [diff] [blame] | 1185 | fb_helper->funcs->gamma_set(crtc, red, green, blue, regno); |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 1186 | |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 1187 | return 0; |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 1188 | } |
| 1189 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1190 | /** |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 1191 | * drm_fb_helper_setcmap - implementation for &fb_ops.fb_setcmap |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1192 | * @cmap: cmap to set |
| 1193 | * @info: fbdev registered by the helper |
| 1194 | */ |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 1195 | int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info) |
| 1196 | { |
| 1197 | struct drm_fb_helper *fb_helper = info->par; |
Ville Syrjälä | 8391a3d | 2013-05-27 20:19:56 +0300 | [diff] [blame] | 1198 | struct drm_device *dev = fb_helper->dev; |
Jani Nikula | be26a66 | 2015-03-11 11:51:06 +0200 | [diff] [blame] | 1199 | const struct drm_crtc_helper_funcs *crtc_funcs; |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 1200 | u16 *red, *green, *blue, *transp; |
| 1201 | struct drm_crtc *crtc; |
roel | 062ac62 | 2011-03-07 18:00:34 +0100 | [diff] [blame] | 1202 | int i, j, rc = 0; |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 1203 | int start; |
| 1204 | |
Daniel Vetter | c50bfd0 | 2015-07-28 13:18:40 +0200 | [diff] [blame] | 1205 | if (oops_in_progress) |
Rui Wang | 9aa609e | 2014-12-15 11:28:26 -0800 | [diff] [blame] | 1206 | return -EBUSY; |
Daniel Vetter | c50bfd0 | 2015-07-28 13:18:40 +0200 | [diff] [blame] | 1207 | |
| 1208 | drm_modeset_lock_all(dev); |
Ville Syrjälä | 8391a3d | 2013-05-27 20:19:56 +0300 | [diff] [blame] | 1209 | if (!drm_fb_helper_is_bound(fb_helper)) { |
| 1210 | drm_modeset_unlock_all(dev); |
| 1211 | return -EBUSY; |
| 1212 | } |
| 1213 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1214 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 1215 | crtc = fb_helper->crtc_info[i].mode_set.crtc; |
| 1216 | crtc_funcs = crtc->helper_private; |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 1217 | |
| 1218 | red = cmap->red; |
| 1219 | green = cmap->green; |
| 1220 | blue = cmap->blue; |
| 1221 | transp = cmap->transp; |
| 1222 | start = cmap->start; |
| 1223 | |
roel | 062ac62 | 2011-03-07 18:00:34 +0100 | [diff] [blame] | 1224 | for (j = 0; j < cmap->len; j++) { |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 1225 | u16 hred, hgreen, hblue, htransp = 0xffff; |
| 1226 | |
| 1227 | hred = *red++; |
| 1228 | hgreen = *green++; |
| 1229 | hblue = *blue++; |
| 1230 | |
| 1231 | if (transp) |
| 1232 | htransp = *transp++; |
| 1233 | |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 1234 | rc = setcolreg(crtc, hred, hgreen, hblue, start++, info); |
| 1235 | if (rc) |
Ville Syrjälä | 8391a3d | 2013-05-27 20:19:56 +0300 | [diff] [blame] | 1236 | goto out; |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 1237 | } |
Ville Syrjälä | 04c0c56 | 2013-05-27 20:19:57 +0300 | [diff] [blame] | 1238 | if (crtc_funcs->load_lut) |
| 1239 | crtc_funcs->load_lut(crtc); |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 1240 | } |
Ville Syrjälä | 8391a3d | 2013-05-27 20:19:56 +0300 | [diff] [blame] | 1241 | out: |
| 1242 | drm_modeset_unlock_all(dev); |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 1243 | return rc; |
| 1244 | } |
| 1245 | EXPORT_SYMBOL(drm_fb_helper_setcmap); |
| 1246 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1247 | /** |
Maxime Ripard | 0f3bbe0 | 2017-02-28 16:36:51 +0100 | [diff] [blame^] | 1248 | * drm_fb_helper_ioctl - legacy ioctl implementation |
| 1249 | * @info: fbdev registered by the helper |
| 1250 | * @cmd: ioctl command |
| 1251 | * @arg: ioctl argument |
| 1252 | * |
| 1253 | * A helper to implement the standard fbdev ioctl. Only |
| 1254 | * FBIO_WAITFORVSYNC is implemented for now. |
| 1255 | */ |
| 1256 | int drm_fb_helper_ioctl(struct fb_info *info, unsigned int cmd, |
| 1257 | unsigned long arg) |
| 1258 | { |
| 1259 | struct drm_fb_helper *fb_helper = info->par; |
| 1260 | struct drm_device *dev = fb_helper->dev; |
| 1261 | struct drm_mode_set *mode_set; |
| 1262 | struct drm_crtc *crtc; |
| 1263 | int ret = 0; |
| 1264 | |
| 1265 | mutex_lock(&dev->mode_config.mutex); |
| 1266 | if (!drm_fb_helper_is_bound(fb_helper)) { |
| 1267 | ret = -EBUSY; |
| 1268 | goto unlock; |
| 1269 | } |
| 1270 | |
| 1271 | switch (cmd) { |
| 1272 | case FBIO_WAITFORVSYNC: |
| 1273 | /* |
| 1274 | * Only consider the first CRTC. |
| 1275 | * |
| 1276 | * This ioctl is supposed to take the CRTC number as |
| 1277 | * an argument, but in fbdev times, what that number |
| 1278 | * was supposed to be was quite unclear, different |
| 1279 | * drivers were passing that argument differently |
| 1280 | * (some by reference, some by value), and most of the |
| 1281 | * userspace applications were just hardcoding 0 as an |
| 1282 | * argument. |
| 1283 | * |
| 1284 | * The first CRTC should be the integrated panel on |
| 1285 | * most drivers, so this is the best choice we can |
| 1286 | * make. If we're not smart enough here, one should |
| 1287 | * just consider switch the userspace to KMS. |
| 1288 | */ |
| 1289 | mode_set = &fb_helper->crtc_info[0].mode_set; |
| 1290 | crtc = mode_set->crtc; |
| 1291 | |
| 1292 | /* |
| 1293 | * Only wait for a vblank event if the CRTC is |
| 1294 | * enabled, otherwise just don't do anythintg, |
| 1295 | * not even report an error. |
| 1296 | */ |
| 1297 | ret = drm_crtc_vblank_get(crtc); |
| 1298 | if (!ret) { |
| 1299 | drm_crtc_wait_one_vblank(crtc); |
| 1300 | drm_crtc_vblank_put(crtc); |
| 1301 | } |
| 1302 | |
| 1303 | ret = 0; |
| 1304 | goto unlock; |
| 1305 | default: |
| 1306 | ret = -ENOTTY; |
| 1307 | } |
| 1308 | |
| 1309 | unlock: |
| 1310 | mutex_unlock(&dev->mode_config.mutex); |
| 1311 | return ret; |
| 1312 | } |
| 1313 | EXPORT_SYMBOL(drm_fb_helper_ioctl); |
| 1314 | |
| 1315 | /** |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 1316 | * drm_fb_helper_check_var - implementation for &fb_ops.fb_check_var |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1317 | * @var: screeninfo to check |
| 1318 | * @info: fbdev registered by the helper |
| 1319 | */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1320 | int drm_fb_helper_check_var(struct fb_var_screeninfo *var, |
| 1321 | struct fb_info *info) |
| 1322 | { |
| 1323 | struct drm_fb_helper *fb_helper = info->par; |
| 1324 | struct drm_framebuffer *fb = fb_helper->fb; |
| 1325 | int depth; |
| 1326 | |
Jason Wessel | f90ebd9 | 2010-08-05 09:22:32 -0500 | [diff] [blame] | 1327 | if (var->pixclock != 0 || in_dbg_master()) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1328 | return -EINVAL; |
| 1329 | |
Stefan Agner | 865afb1 | 2016-10-11 16:15:04 -0700 | [diff] [blame] | 1330 | /* |
| 1331 | * Changes struct fb_var_screeninfo are currently not pushed back |
| 1332 | * to KMS, hence fail if different settings are requested. |
| 1333 | */ |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 1334 | if (var->bits_per_pixel != fb->format->cpp[0] * 8 || |
Stefan Agner | 865afb1 | 2016-10-11 16:15:04 -0700 | [diff] [blame] | 1335 | var->xres != fb->width || var->yres != fb->height || |
| 1336 | var->xres_virtual != fb->width || var->yres_virtual != fb->height) { |
| 1337 | DRM_DEBUG("fb userspace requested width/height/bpp different than current fb " |
Chris Wilson | 62fb376 | 2012-03-26 21:15:53 +0100 | [diff] [blame] | 1338 | "request %dx%d-%d (virtual %dx%d) > %dx%d-%d\n", |
| 1339 | var->xres, var->yres, var->bits_per_pixel, |
| 1340 | var->xres_virtual, var->yres_virtual, |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 1341 | fb->width, fb->height, fb->format->cpp[0] * 8); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1342 | return -EINVAL; |
| 1343 | } |
| 1344 | |
| 1345 | switch (var->bits_per_pixel) { |
| 1346 | case 16: |
| 1347 | depth = (var->green.length == 6) ? 16 : 15; |
| 1348 | break; |
| 1349 | case 32: |
| 1350 | depth = (var->transp.length > 0) ? 32 : 24; |
| 1351 | break; |
| 1352 | default: |
| 1353 | depth = var->bits_per_pixel; |
| 1354 | break; |
| 1355 | } |
| 1356 | |
| 1357 | switch (depth) { |
| 1358 | case 8: |
| 1359 | var->red.offset = 0; |
| 1360 | var->green.offset = 0; |
| 1361 | var->blue.offset = 0; |
| 1362 | var->red.length = 8; |
| 1363 | var->green.length = 8; |
| 1364 | var->blue.length = 8; |
| 1365 | var->transp.length = 0; |
| 1366 | var->transp.offset = 0; |
| 1367 | break; |
| 1368 | case 15: |
| 1369 | var->red.offset = 10; |
| 1370 | var->green.offset = 5; |
| 1371 | var->blue.offset = 0; |
| 1372 | var->red.length = 5; |
| 1373 | var->green.length = 5; |
| 1374 | var->blue.length = 5; |
| 1375 | var->transp.length = 1; |
| 1376 | var->transp.offset = 15; |
| 1377 | break; |
| 1378 | case 16: |
| 1379 | var->red.offset = 11; |
| 1380 | var->green.offset = 5; |
| 1381 | var->blue.offset = 0; |
| 1382 | var->red.length = 5; |
| 1383 | var->green.length = 6; |
| 1384 | var->blue.length = 5; |
| 1385 | var->transp.length = 0; |
| 1386 | var->transp.offset = 0; |
| 1387 | break; |
| 1388 | case 24: |
| 1389 | var->red.offset = 16; |
| 1390 | var->green.offset = 8; |
| 1391 | var->blue.offset = 0; |
| 1392 | var->red.length = 8; |
| 1393 | var->green.length = 8; |
| 1394 | var->blue.length = 8; |
| 1395 | var->transp.length = 0; |
| 1396 | var->transp.offset = 0; |
| 1397 | break; |
| 1398 | case 32: |
| 1399 | var->red.offset = 16; |
| 1400 | var->green.offset = 8; |
| 1401 | var->blue.offset = 0; |
| 1402 | var->red.length = 8; |
| 1403 | var->green.length = 8; |
| 1404 | var->blue.length = 8; |
| 1405 | var->transp.length = 8; |
| 1406 | var->transp.offset = 24; |
| 1407 | break; |
| 1408 | default: |
| 1409 | return -EINVAL; |
| 1410 | } |
| 1411 | return 0; |
| 1412 | } |
| 1413 | EXPORT_SYMBOL(drm_fb_helper_check_var); |
| 1414 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1415 | /** |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 1416 | * drm_fb_helper_set_par - implementation for &fb_ops.fb_set_par |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1417 | * @info: fbdev registered by the helper |
| 1418 | * |
| 1419 | * This will let fbcon do the mode init and is called at initialization time by |
| 1420 | * the fbdev core when registering the driver, and later on through the hotplug |
| 1421 | * callback. |
| 1422 | */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1423 | int drm_fb_helper_set_par(struct fb_info *info) |
| 1424 | { |
| 1425 | struct drm_fb_helper *fb_helper = info->par; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1426 | struct fb_var_screeninfo *var = &info->var; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1427 | |
Daniel Vetter | c50bfd0 | 2015-07-28 13:18:40 +0200 | [diff] [blame] | 1428 | if (oops_in_progress) |
| 1429 | return -EBUSY; |
| 1430 | |
Clemens Ladisch | 5349ef3 | 2009-11-04 09:42:52 +0100 | [diff] [blame] | 1431 | if (var->pixclock != 0) { |
Pavel Roskin | 172e91f | 2010-02-11 14:31:32 +1000 | [diff] [blame] | 1432 | DRM_ERROR("PIXEL CLOCK SET\n"); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1433 | return -EINVAL; |
| 1434 | } |
| 1435 | |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 1436 | drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper); |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 1437 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1438 | return 0; |
| 1439 | } |
| 1440 | EXPORT_SYMBOL(drm_fb_helper_set_par); |
| 1441 | |
Rob Clark | 1edf026 | 2015-08-25 15:35:59 -0400 | [diff] [blame] | 1442 | static int pan_display_atomic(struct fb_var_screeninfo *var, |
Daniel Vetter | a0fb6ad | 2015-10-16 19:11:30 +0200 | [diff] [blame] | 1443 | struct fb_info *info) |
Rob Clark | 1edf026 | 2015-08-25 15:35:59 -0400 | [diff] [blame] | 1444 | { |
| 1445 | struct drm_fb_helper *fb_helper = info->par; |
| 1446 | struct drm_device *dev = fb_helper->dev; |
| 1447 | struct drm_atomic_state *state; |
Maarten Lankhorst | 07d3bad | 2015-11-11 11:29:11 +0100 | [diff] [blame] | 1448 | struct drm_plane *plane; |
Rob Clark | 1edf026 | 2015-08-25 15:35:59 -0400 | [diff] [blame] | 1449 | int i, ret; |
Maarten Lankhorst | 07d3bad | 2015-11-11 11:29:11 +0100 | [diff] [blame] | 1450 | unsigned plane_mask; |
Rob Clark | 1edf026 | 2015-08-25 15:35:59 -0400 | [diff] [blame] | 1451 | |
| 1452 | state = drm_atomic_state_alloc(dev); |
| 1453 | if (!state) |
| 1454 | return -ENOMEM; |
| 1455 | |
| 1456 | state->acquire_ctx = dev->mode_config.acquire_ctx; |
| 1457 | retry: |
Maarten Lankhorst | 07d3bad | 2015-11-11 11:29:11 +0100 | [diff] [blame] | 1458 | plane_mask = 0; |
Rob Clark | 1edf026 | 2015-08-25 15:35:59 -0400 | [diff] [blame] | 1459 | for(i = 0; i < fb_helper->crtc_count; i++) { |
| 1460 | struct drm_mode_set *mode_set; |
| 1461 | |
| 1462 | mode_set = &fb_helper->crtc_info[i].mode_set; |
| 1463 | |
| 1464 | mode_set->x = var->xoffset; |
| 1465 | mode_set->y = var->yoffset; |
| 1466 | |
| 1467 | ret = __drm_atomic_helper_set_config(mode_set, state); |
| 1468 | if (ret != 0) |
| 1469 | goto fail; |
Maarten Lankhorst | 07d3bad | 2015-11-11 11:29:11 +0100 | [diff] [blame] | 1470 | |
| 1471 | plane = mode_set->crtc->primary; |
Matt Roper | 7118fd9 | 2015-12-18 17:27:01 -0800 | [diff] [blame] | 1472 | plane_mask |= (1 << drm_plane_index(plane)); |
Maarten Lankhorst | 07d3bad | 2015-11-11 11:29:11 +0100 | [diff] [blame] | 1473 | plane->old_fb = plane->fb; |
Rob Clark | 1edf026 | 2015-08-25 15:35:59 -0400 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | ret = drm_atomic_commit(state); |
| 1477 | if (ret != 0) |
| 1478 | goto fail; |
| 1479 | |
| 1480 | info->var.xoffset = var->xoffset; |
| 1481 | info->var.yoffset = var->yoffset; |
| 1482 | |
Rob Clark | 1edf026 | 2015-08-25 15:35:59 -0400 | [diff] [blame] | 1483 | fail: |
Maarten Lankhorst | 07d3bad | 2015-11-11 11:29:11 +0100 | [diff] [blame] | 1484 | drm_atomic_clean_old_fb(dev, plane_mask, ret); |
Daniel Vetter | a0fb6ad | 2015-10-16 19:11:30 +0200 | [diff] [blame] | 1485 | |
Rob Clark | 1edf026 | 2015-08-25 15:35:59 -0400 | [diff] [blame] | 1486 | if (ret == -EDEADLK) |
| 1487 | goto backoff; |
| 1488 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 1489 | drm_atomic_state_put(state); |
Rob Clark | 1edf026 | 2015-08-25 15:35:59 -0400 | [diff] [blame] | 1490 | return ret; |
| 1491 | |
| 1492 | backoff: |
| 1493 | drm_atomic_state_clear(state); |
| 1494 | drm_atomic_legacy_backoff(state); |
| 1495 | |
| 1496 | goto retry; |
| 1497 | } |
| 1498 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1499 | /** |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 1500 | * drm_fb_helper_pan_display - implementation for &fb_ops.fb_pan_display |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1501 | * @var: updated screen information |
| 1502 | * @info: fbdev registered by the helper |
| 1503 | */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1504 | int drm_fb_helper_pan_display(struct fb_var_screeninfo *var, |
| 1505 | struct fb_info *info) |
| 1506 | { |
| 1507 | struct drm_fb_helper *fb_helper = info->par; |
| 1508 | struct drm_device *dev = fb_helper->dev; |
| 1509 | struct drm_mode_set *modeset; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1510 | int ret = 0; |
| 1511 | int i; |
| 1512 | |
Daniel Vetter | c50bfd0 | 2015-07-28 13:18:40 +0200 | [diff] [blame] | 1513 | if (oops_in_progress) |
Rui Wang | 9aa609e | 2014-12-15 11:28:26 -0800 | [diff] [blame] | 1514 | return -EBUSY; |
Daniel Vetter | c50bfd0 | 2015-07-28 13:18:40 +0200 | [diff] [blame] | 1515 | |
| 1516 | drm_modeset_lock_all(dev); |
Daniel Vetter | 20c60c3 | 2012-12-17 12:13:23 +0100 | [diff] [blame] | 1517 | if (!drm_fb_helper_is_bound(fb_helper)) { |
| 1518 | drm_modeset_unlock_all(dev); |
| 1519 | return -EBUSY; |
| 1520 | } |
| 1521 | |
Dhinakaran Pandiyan | a743d75 | 2016-12-22 00:50:42 -0800 | [diff] [blame] | 1522 | if (drm_drv_uses_atomic_modeset(dev)) { |
Rob Clark | 1edf026 | 2015-08-25 15:35:59 -0400 | [diff] [blame] | 1523 | ret = pan_display_atomic(var, info); |
| 1524 | goto unlock; |
| 1525 | } |
| 1526 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1527 | for (i = 0; i < fb_helper->crtc_count; i++) { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1528 | modeset = &fb_helper->crtc_info[i].mode_set; |
| 1529 | |
| 1530 | modeset->x = var->xoffset; |
| 1531 | modeset->y = var->yoffset; |
| 1532 | |
| 1533 | if (modeset->num_connectors) { |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 1534 | ret = drm_mode_set_config_internal(modeset); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1535 | if (!ret) { |
| 1536 | info->var.xoffset = var->xoffset; |
| 1537 | info->var.yoffset = var->yoffset; |
| 1538 | } |
| 1539 | } |
| 1540 | } |
Rob Clark | 1edf026 | 2015-08-25 15:35:59 -0400 | [diff] [blame] | 1541 | unlock: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1542 | drm_modeset_unlock_all(dev); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1543 | return ret; |
| 1544 | } |
| 1545 | EXPORT_SYMBOL(drm_fb_helper_pan_display); |
| 1546 | |
Daniel Vetter | 8acf658 | 2013-01-21 23:38:37 +0100 | [diff] [blame] | 1547 | /* |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1548 | * Allocates the backing storage and sets up the fbdev info structure through |
| 1549 | * the ->fb_probe callback and then registers the fbdev and sets up the panic |
| 1550 | * notifier. |
Daniel Vetter | 8acf658 | 2013-01-21 23:38:37 +0100 | [diff] [blame] | 1551 | */ |
Daniel Vetter | de1ace5 | 2013-01-20 21:50:49 +0100 | [diff] [blame] | 1552 | static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper, |
| 1553 | int preferred_bpp) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1554 | { |
Daniel Vetter | 8acf658 | 2013-01-21 23:38:37 +0100 | [diff] [blame] | 1555 | int ret = 0; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1556 | int crtc_count = 0; |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 1557 | int i; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1558 | struct drm_fb_helper_surface_size sizes; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1559 | int gamma_size = 0; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1560 | |
| 1561 | memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size)); |
| 1562 | sizes.surface_depth = 24; |
| 1563 | sizes.surface_bpp = 32; |
| 1564 | sizes.fb_width = (unsigned)-1; |
| 1565 | sizes.fb_height = (unsigned)-1; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1566 | |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 1567 | /* if driver picks 8 or 16 by default use that |
| 1568 | for both depth/bpp */ |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1569 | if (preferred_bpp != sizes.surface_bpp) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1570 | sizes.surface_depth = sizes.surface_bpp = preferred_bpp; |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1571 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1572 | /* first up get a count of crtcs now in use and new min/maxes width/heights */ |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 1573 | drm_fb_helper_for_each_connector(fb_helper, i) { |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1574 | struct drm_fb_helper_connector *fb_helper_conn = fb_helper->connector_info[i]; |
Chris Wilson | 1794d25 | 2011-04-17 07:43:32 +0100 | [diff] [blame] | 1575 | struct drm_cmdline_mode *cmdline_mode; |
Dave Airlie | 8ef8678 | 2009-09-26 06:39:00 +1000 | [diff] [blame] | 1576 | |
Chris Wilson | eaf99c7 | 2014-08-06 10:08:32 +0200 | [diff] [blame] | 1577 | cmdline_mode = &fb_helper_conn->connector->cmdline_mode; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 1578 | |
| 1579 | if (cmdline_mode->bpp_specified) { |
| 1580 | switch (cmdline_mode->bpp) { |
| 1581 | case 8: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1582 | sizes.surface_depth = sizes.surface_bpp = 8; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 1583 | break; |
| 1584 | case 15: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1585 | sizes.surface_depth = 15; |
| 1586 | sizes.surface_bpp = 16; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 1587 | break; |
| 1588 | case 16: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1589 | sizes.surface_depth = sizes.surface_bpp = 16; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 1590 | break; |
| 1591 | case 24: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1592 | sizes.surface_depth = sizes.surface_bpp = 24; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 1593 | break; |
| 1594 | case 32: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1595 | sizes.surface_depth = 24; |
| 1596 | sizes.surface_bpp = 32; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 1597 | break; |
| 1598 | } |
| 1599 | break; |
| 1600 | } |
| 1601 | } |
| 1602 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1603 | crtc_count = 0; |
| 1604 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 1605 | struct drm_display_mode *desired_mode; |
Rob Clark | 0e3704c | 2015-03-11 10:23:14 -0400 | [diff] [blame] | 1606 | struct drm_mode_set *mode_set; |
| 1607 | int x, y, j; |
| 1608 | /* in case of tile group, are we the last tile vert or horiz? |
| 1609 | * If no tile group you are always the last one both vertically |
| 1610 | * and horizontally |
| 1611 | */ |
| 1612 | bool lastv = true, lasth = true; |
Rob Clark | 675c832 | 2015-03-11 10:23:13 -0400 | [diff] [blame] | 1613 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1614 | desired_mode = fb_helper->crtc_info[i].desired_mode; |
Rob Clark | 0e3704c | 2015-03-11 10:23:14 -0400 | [diff] [blame] | 1615 | mode_set = &fb_helper->crtc_info[i].mode_set; |
Rob Clark | 675c832 | 2015-03-11 10:23:13 -0400 | [diff] [blame] | 1616 | |
| 1617 | if (!desired_mode) |
| 1618 | continue; |
| 1619 | |
| 1620 | crtc_count++; |
| 1621 | |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1622 | x = fb_helper->crtc_info[i].x; |
| 1623 | y = fb_helper->crtc_info[i].y; |
Rob Clark | 675c832 | 2015-03-11 10:23:13 -0400 | [diff] [blame] | 1624 | |
| 1625 | if (gamma_size == 0) |
| 1626 | gamma_size = fb_helper->crtc_info[i].mode_set.crtc->gamma_size; |
| 1627 | |
| 1628 | sizes.surface_width = max_t(u32, desired_mode->hdisplay + x, sizes.surface_width); |
| 1629 | sizes.surface_height = max_t(u32, desired_mode->vdisplay + y, sizes.surface_height); |
Rob Clark | 0e3704c | 2015-03-11 10:23:14 -0400 | [diff] [blame] | 1630 | |
| 1631 | for (j = 0; j < mode_set->num_connectors; j++) { |
| 1632 | struct drm_connector *connector = mode_set->connectors[j]; |
| 1633 | if (connector->has_tile) { |
| 1634 | lasth = (connector->tile_h_loc == (connector->num_h_tile - 1)); |
| 1635 | lastv = (connector->tile_v_loc == (connector->num_v_tile - 1)); |
| 1636 | /* cloning to multiple tiles is just crazy-talk, so: */ |
| 1637 | break; |
| 1638 | } |
| 1639 | } |
| 1640 | |
| 1641 | if (lasth) |
| 1642 | sizes.fb_width = min_t(u32, desired_mode->hdisplay + x, sizes.fb_width); |
| 1643 | if (lastv) |
| 1644 | sizes.fb_height = min_t(u32, desired_mode->vdisplay + y, sizes.fb_height); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1645 | } |
| 1646 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1647 | if (crtc_count == 0 || sizes.fb_width == -1 || sizes.fb_height == -1) { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1648 | /* hmm everyone went away - assume VGA cable just fell out |
| 1649 | and will come back later. */ |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1650 | DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n"); |
Dave Airlie | 19b4b44 | 2010-03-30 05:34:16 +0000 | [diff] [blame] | 1651 | sizes.fb_width = sizes.surface_width = 1024; |
| 1652 | sizes.fb_height = sizes.surface_height = 768; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1653 | } |
| 1654 | |
Xinliang Liu | 5f15257 | 2017-02-15 17:19:08 +0100 | [diff] [blame] | 1655 | /* Handle our overallocation */ |
| 1656 | sizes.surface_height *= drm_fbdev_overalloc; |
| 1657 | sizes.surface_height /= 100; |
| 1658 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1659 | /* push down into drivers */ |
Daniel Vetter | 8acf658 | 2013-01-21 23:38:37 +0100 | [diff] [blame] | 1660 | ret = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes); |
| 1661 | if (ret < 0) |
| 1662 | return ret; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1663 | |
Daniel Vetter | 7e53f3a | 2013-01-21 10:52:17 +0100 | [diff] [blame] | 1664 | /* |
| 1665 | * Set the fb pointer - usually drm_setup_crtcs does this for hotplug |
| 1666 | * events, but at init time drm_setup_crtcs needs to be called before |
| 1667 | * the fb is allocated (since we need to figure out the desired size of |
| 1668 | * the fb before we can allocate it ...). Hence we need to fix things up |
| 1669 | * here again. |
| 1670 | */ |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1671 | for (i = 0; i < fb_helper->crtc_count; i++) |
Daniel Vetter | 7e53f3a | 2013-01-21 10:52:17 +0100 | [diff] [blame] | 1672 | if (fb_helper->crtc_info[i].mode_set.num_connectors) |
| 1673 | fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb; |
| 1674 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1675 | return 0; |
| 1676 | } |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1677 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1678 | /** |
| 1679 | * drm_fb_helper_fill_fix - initializes fixed fbdev information |
| 1680 | * @info: fbdev registered by the helper |
| 1681 | * @pitch: desired pitch |
| 1682 | * @depth: desired depth |
| 1683 | * |
| 1684 | * Helper to fill in the fixed fbdev information useful for a non-accelerated |
| 1685 | * fbdev emulations. Drivers which support acceleration methods which impose |
| 1686 | * additional constraints need to set up their own limits. |
| 1687 | * |
| 1688 | * Drivers should call this (or their equivalent setup code) from their |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 1689 | * &drm_fb_helper_funcs.fb_probe callback. |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1690 | */ |
Dave Airlie | 3632ef8 | 2011-01-15 09:27:00 +1000 | [diff] [blame] | 1691 | void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch, |
| 1692 | uint32_t depth) |
| 1693 | { |
| 1694 | info->fix.type = FB_TYPE_PACKED_PIXELS; |
| 1695 | info->fix.visual = depth == 8 ? FB_VISUAL_PSEUDOCOLOR : |
| 1696 | FB_VISUAL_TRUECOLOR; |
| 1697 | info->fix.mmio_start = 0; |
| 1698 | info->fix.mmio_len = 0; |
| 1699 | info->fix.type_aux = 0; |
| 1700 | info->fix.xpanstep = 1; /* doing it in hw */ |
| 1701 | info->fix.ypanstep = 1; /* doing it in hw */ |
| 1702 | info->fix.ywrapstep = 0; |
| 1703 | info->fix.accel = FB_ACCEL_NONE; |
Dave Airlie | 3632ef8 | 2011-01-15 09:27:00 +1000 | [diff] [blame] | 1704 | |
| 1705 | info->fix.line_length = pitch; |
| 1706 | return; |
| 1707 | } |
| 1708 | EXPORT_SYMBOL(drm_fb_helper_fill_fix); |
| 1709 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1710 | /** |
| 1711 | * drm_fb_helper_fill_var - initalizes variable fbdev information |
| 1712 | * @info: fbdev instance to set up |
| 1713 | * @fb_helper: fb helper instance to use as template |
| 1714 | * @fb_width: desired fb width |
| 1715 | * @fb_height: desired fb height |
| 1716 | * |
| 1717 | * Sets up the variable fbdev metainformation from the given fb helper instance |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 1718 | * and the drm framebuffer allocated in &drm_fb_helper.fb. |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1719 | * |
| 1720 | * Drivers should call this (or their equivalent setup code) from their |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 1721 | * &drm_fb_helper_funcs.fb_probe callback after having allocated the fbdev |
| 1722 | * backing storage framebuffer. |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1723 | */ |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1724 | void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helper, |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1725 | uint32_t fb_width, uint32_t fb_height) |
| 1726 | { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1727 | struct drm_framebuffer *fb = fb_helper->fb; |
| 1728 | info->pseudo_palette = fb_helper->pseudo_palette; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1729 | info->var.xres_virtual = fb->width; |
| 1730 | info->var.yres_virtual = fb->height; |
Ville Syrjälä | 272725c | 2016-12-14 23:32:20 +0200 | [diff] [blame] | 1731 | info->var.bits_per_pixel = fb->format->cpp[0] * 8; |
James Simmons | 57084d0 | 2010-12-20 19:10:39 +0000 | [diff] [blame] | 1732 | info->var.accel_flags = FB_ACCELF_TEXT; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1733 | info->var.xoffset = 0; |
| 1734 | info->var.yoffset = 0; |
| 1735 | info->var.activate = FB_ACTIVATE_NOW; |
| 1736 | info->var.height = -1; |
| 1737 | info->var.width = -1; |
| 1738 | |
Ville Syrjälä | b00c600 | 2016-12-14 23:31:35 +0200 | [diff] [blame] | 1739 | switch (fb->format->depth) { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1740 | case 8: |
| 1741 | info->var.red.offset = 0; |
| 1742 | info->var.green.offset = 0; |
| 1743 | info->var.blue.offset = 0; |
| 1744 | info->var.red.length = 8; /* 8bit DAC */ |
| 1745 | info->var.green.length = 8; |
| 1746 | info->var.blue.length = 8; |
| 1747 | info->var.transp.offset = 0; |
| 1748 | info->var.transp.length = 0; |
| 1749 | break; |
| 1750 | case 15: |
| 1751 | info->var.red.offset = 10; |
| 1752 | info->var.green.offset = 5; |
| 1753 | info->var.blue.offset = 0; |
| 1754 | info->var.red.length = 5; |
| 1755 | info->var.green.length = 5; |
| 1756 | info->var.blue.length = 5; |
| 1757 | info->var.transp.offset = 15; |
| 1758 | info->var.transp.length = 1; |
| 1759 | break; |
| 1760 | case 16: |
| 1761 | info->var.red.offset = 11; |
| 1762 | info->var.green.offset = 5; |
| 1763 | info->var.blue.offset = 0; |
| 1764 | info->var.red.length = 5; |
| 1765 | info->var.green.length = 6; |
| 1766 | info->var.blue.length = 5; |
| 1767 | info->var.transp.offset = 0; |
| 1768 | break; |
| 1769 | case 24: |
| 1770 | info->var.red.offset = 16; |
| 1771 | info->var.green.offset = 8; |
| 1772 | info->var.blue.offset = 0; |
| 1773 | info->var.red.length = 8; |
| 1774 | info->var.green.length = 8; |
| 1775 | info->var.blue.length = 8; |
| 1776 | info->var.transp.offset = 0; |
| 1777 | info->var.transp.length = 0; |
| 1778 | break; |
| 1779 | case 32: |
| 1780 | info->var.red.offset = 16; |
| 1781 | info->var.green.offset = 8; |
| 1782 | info->var.blue.offset = 0; |
| 1783 | info->var.red.length = 8; |
| 1784 | info->var.green.length = 8; |
| 1785 | info->var.blue.length = 8; |
| 1786 | info->var.transp.offset = 24; |
| 1787 | info->var.transp.length = 8; |
| 1788 | break; |
| 1789 | default: |
| 1790 | break; |
| 1791 | } |
| 1792 | |
| 1793 | info->var.xres = fb_width; |
| 1794 | info->var.yres = fb_height; |
| 1795 | } |
| 1796 | EXPORT_SYMBOL(drm_fb_helper_fill_var); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1797 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1798 | static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper *fb_helper, |
| 1799 | uint32_t maxX, |
| 1800 | uint32_t maxY) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1801 | { |
| 1802 | struct drm_connector *connector; |
| 1803 | int count = 0; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1804 | int i; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1805 | |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 1806 | drm_fb_helper_for_each_connector(fb_helper, i) { |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1807 | connector = fb_helper->connector_info[i]->connector; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1808 | count += connector->funcs->fill_modes(connector, maxX, maxY); |
| 1809 | } |
| 1810 | |
| 1811 | return count; |
| 1812 | } |
| 1813 | |
Jesse Barnes | 2f1046f | 2014-02-12 12:26:24 -0800 | [diff] [blame] | 1814 | struct drm_display_mode *drm_has_preferred_mode(struct drm_fb_helper_connector *fb_connector, int width, int height) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1815 | { |
| 1816 | struct drm_display_mode *mode; |
| 1817 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1818 | list_for_each_entry(mode, &fb_connector->connector->modes, head) { |
Daniel Vetter | 9d3de13 | 2014-01-23 16:27:56 +0100 | [diff] [blame] | 1819 | if (mode->hdisplay > width || |
| 1820 | mode->vdisplay > height) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1821 | continue; |
| 1822 | if (mode->type & DRM_MODE_TYPE_PREFERRED) |
| 1823 | return mode; |
| 1824 | } |
| 1825 | return NULL; |
| 1826 | } |
Jesse Barnes | 2f1046f | 2014-02-12 12:26:24 -0800 | [diff] [blame] | 1827 | EXPORT_SYMBOL(drm_has_preferred_mode); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1828 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1829 | static bool drm_has_cmdline_mode(struct drm_fb_helper_connector *fb_connector) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1830 | { |
Chris Wilson | eaf99c7 | 2014-08-06 10:08:32 +0200 | [diff] [blame] | 1831 | return fb_connector->connector->cmdline_mode.specified; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
Vincent Abriou | a09759e | 2017-01-06 17:44:43 +0100 | [diff] [blame] | 1834 | struct drm_display_mode *drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1835 | { |
Chris Wilson | 1794d25 | 2011-04-17 07:43:32 +0100 | [diff] [blame] | 1836 | struct drm_cmdline_mode *cmdline_mode; |
Daniel Stone | f3af5c7 | 2015-03-19 04:33:01 +0000 | [diff] [blame] | 1837 | struct drm_display_mode *mode; |
Takashi Iwai | c683f42 | 2014-03-19 14:53:13 +0100 | [diff] [blame] | 1838 | bool prefer_non_interlace; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1839 | |
Chris Wilson | eaf99c7 | 2014-08-06 10:08:32 +0200 | [diff] [blame] | 1840 | cmdline_mode = &fb_helper_conn->connector->cmdline_mode; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1841 | if (cmdline_mode->specified == false) |
Daniel Stone | f3af5c7 | 2015-03-19 04:33:01 +0000 | [diff] [blame] | 1842 | return NULL; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1843 | |
| 1844 | /* attempt to find a matching mode in the list of modes |
| 1845 | * we have gotten so far, if not add a CVT mode that conforms |
| 1846 | */ |
| 1847 | if (cmdline_mode->rb || cmdline_mode->margins) |
| 1848 | goto create_mode; |
| 1849 | |
Takashi Iwai | c683f42 | 2014-03-19 14:53:13 +0100 | [diff] [blame] | 1850 | prefer_non_interlace = !cmdline_mode->interlace; |
Daniel Stone | f3af5c7 | 2015-03-19 04:33:01 +0000 | [diff] [blame] | 1851 | again: |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1852 | list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1853 | /* check width/height */ |
| 1854 | if (mode->hdisplay != cmdline_mode->xres || |
| 1855 | mode->vdisplay != cmdline_mode->yres) |
| 1856 | continue; |
| 1857 | |
| 1858 | if (cmdline_mode->refresh_specified) { |
| 1859 | if (mode->vrefresh != cmdline_mode->refresh) |
| 1860 | continue; |
| 1861 | } |
| 1862 | |
| 1863 | if (cmdline_mode->interlace) { |
| 1864 | if (!(mode->flags & DRM_MODE_FLAG_INTERLACE)) |
| 1865 | continue; |
Takashi Iwai | c683f42 | 2014-03-19 14:53:13 +0100 | [diff] [blame] | 1866 | } else if (prefer_non_interlace) { |
| 1867 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 1868 | continue; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1869 | } |
| 1870 | return mode; |
| 1871 | } |
| 1872 | |
Takashi Iwai | c683f42 | 2014-03-19 14:53:13 +0100 | [diff] [blame] | 1873 | if (prefer_non_interlace) { |
| 1874 | prefer_non_interlace = false; |
| 1875 | goto again; |
| 1876 | } |
| 1877 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1878 | create_mode: |
Chris Wilson | 1794d25 | 2011-04-17 07:43:32 +0100 | [diff] [blame] | 1879 | mode = drm_mode_create_from_cmdline_mode(fb_helper_conn->connector->dev, |
| 1880 | cmdline_mode); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1881 | list_add(&mode->head, &fb_helper_conn->connector->modes); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1882 | return mode; |
| 1883 | } |
Jesse Barnes | 2f1046f | 2014-02-12 12:26:24 -0800 | [diff] [blame] | 1884 | EXPORT_SYMBOL(drm_pick_cmdline_mode); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1885 | |
| 1886 | static bool drm_connector_enabled(struct drm_connector *connector, bool strict) |
| 1887 | { |
| 1888 | bool enable; |
| 1889 | |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1890 | if (strict) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1891 | enable = connector->status == connector_status_connected; |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1892 | else |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1893 | enable = connector->status != connector_status_disconnected; |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1894 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1895 | return enable; |
| 1896 | } |
| 1897 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1898 | static void drm_enable_connectors(struct drm_fb_helper *fb_helper, |
| 1899 | bool *enabled) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1900 | { |
| 1901 | bool any_enabled = false; |
| 1902 | struct drm_connector *connector; |
| 1903 | int i = 0; |
| 1904 | |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 1905 | drm_fb_helper_for_each_connector(fb_helper, i) { |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1906 | connector = fb_helper->connector_info[i]->connector; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1907 | enabled[i] = drm_connector_enabled(connector, true); |
| 1908 | DRM_DEBUG_KMS("connector %d enabled? %s\n", connector->base.id, |
| 1909 | enabled[i] ? "yes" : "no"); |
| 1910 | any_enabled |= enabled[i]; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | if (any_enabled) |
| 1914 | return; |
| 1915 | |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 1916 | drm_fb_helper_for_each_connector(fb_helper, i) { |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1917 | connector = fb_helper->connector_info[i]->connector; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1918 | enabled[i] = drm_connector_enabled(connector, false); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1919 | } |
| 1920 | } |
| 1921 | |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1922 | static bool drm_target_cloned(struct drm_fb_helper *fb_helper, |
| 1923 | struct drm_display_mode **modes, |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1924 | struct drm_fb_offset *offsets, |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1925 | bool *enabled, int width, int height) |
| 1926 | { |
| 1927 | int count, i, j; |
| 1928 | bool can_clone = false; |
| 1929 | struct drm_fb_helper_connector *fb_helper_conn; |
| 1930 | struct drm_display_mode *dmt_mode, *mode; |
| 1931 | |
| 1932 | /* only contemplate cloning in the single crtc case */ |
| 1933 | if (fb_helper->crtc_count > 1) |
| 1934 | return false; |
| 1935 | |
| 1936 | count = 0; |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 1937 | drm_fb_helper_for_each_connector(fb_helper, i) { |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1938 | if (enabled[i]) |
| 1939 | count++; |
| 1940 | } |
| 1941 | |
| 1942 | /* only contemplate cloning if more than one connector is enabled */ |
| 1943 | if (count <= 1) |
| 1944 | return false; |
| 1945 | |
| 1946 | /* check the command line or if nothing common pick 1024x768 */ |
| 1947 | can_clone = true; |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 1948 | drm_fb_helper_for_each_connector(fb_helper, i) { |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1949 | if (!enabled[i]) |
| 1950 | continue; |
| 1951 | fb_helper_conn = fb_helper->connector_info[i]; |
Vincent Abriou | a09759e | 2017-01-06 17:44:43 +0100 | [diff] [blame] | 1952 | modes[i] = drm_pick_cmdline_mode(fb_helper_conn); |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1953 | if (!modes[i]) { |
| 1954 | can_clone = false; |
| 1955 | break; |
| 1956 | } |
| 1957 | for (j = 0; j < i; j++) { |
| 1958 | if (!enabled[j]) |
| 1959 | continue; |
| 1960 | if (!drm_mode_equal(modes[j], modes[i])) |
| 1961 | can_clone = false; |
| 1962 | } |
| 1963 | } |
| 1964 | |
| 1965 | if (can_clone) { |
| 1966 | DRM_DEBUG_KMS("can clone using command line\n"); |
| 1967 | return true; |
| 1968 | } |
| 1969 | |
| 1970 | /* try and find a 1024x768 mode on each connector */ |
| 1971 | can_clone = true; |
Adam Jackson | f6e252b | 2012-04-13 16:33:31 -0400 | [diff] [blame] | 1972 | dmt_mode = drm_mode_find_dmt(fb_helper->dev, 1024, 768, 60, false); |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1973 | |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 1974 | drm_fb_helper_for_each_connector(fb_helper, i) { |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1975 | if (!enabled[i]) |
| 1976 | continue; |
| 1977 | |
| 1978 | fb_helper_conn = fb_helper->connector_info[i]; |
| 1979 | list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) { |
| 1980 | if (drm_mode_equal(mode, dmt_mode)) |
| 1981 | modes[i] = mode; |
| 1982 | } |
| 1983 | if (!modes[i]) |
| 1984 | can_clone = false; |
| 1985 | } |
| 1986 | |
| 1987 | if (can_clone) { |
| 1988 | DRM_DEBUG_KMS("can clone using 1024x768\n"); |
| 1989 | return true; |
| 1990 | } |
| 1991 | DRM_INFO("kms: can't enable cloning when we probably wanted to.\n"); |
| 1992 | return false; |
| 1993 | } |
| 1994 | |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1995 | static int drm_get_tile_offsets(struct drm_fb_helper *fb_helper, |
| 1996 | struct drm_display_mode **modes, |
| 1997 | struct drm_fb_offset *offsets, |
| 1998 | int idx, |
| 1999 | int h_idx, int v_idx) |
| 2000 | { |
| 2001 | struct drm_fb_helper_connector *fb_helper_conn; |
| 2002 | int i; |
| 2003 | int hoffset = 0, voffset = 0; |
| 2004 | |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 2005 | drm_fb_helper_for_each_connector(fb_helper, i) { |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 2006 | fb_helper_conn = fb_helper->connector_info[i]; |
| 2007 | if (!fb_helper_conn->connector->has_tile) |
| 2008 | continue; |
| 2009 | |
| 2010 | if (!modes[i] && (h_idx || v_idx)) { |
| 2011 | DRM_DEBUG_KMS("no modes for connector tiled %d %d\n", i, |
| 2012 | fb_helper_conn->connector->base.id); |
| 2013 | continue; |
| 2014 | } |
| 2015 | if (fb_helper_conn->connector->tile_h_loc < h_idx) |
| 2016 | hoffset += modes[i]->hdisplay; |
| 2017 | |
| 2018 | if (fb_helper_conn->connector->tile_v_loc < v_idx) |
| 2019 | voffset += modes[i]->vdisplay; |
| 2020 | } |
| 2021 | offsets[idx].x = hoffset; |
| 2022 | offsets[idx].y = voffset; |
| 2023 | DRM_DEBUG_KMS("returned %d %d for %d %d\n", hoffset, voffset, h_idx, v_idx); |
| 2024 | return 0; |
| 2025 | } |
| 2026 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 2027 | static bool drm_target_preferred(struct drm_fb_helper *fb_helper, |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2028 | struct drm_display_mode **modes, |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 2029 | struct drm_fb_offset *offsets, |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2030 | bool *enabled, int width, int height) |
| 2031 | { |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 2032 | struct drm_fb_helper_connector *fb_helper_conn; |
Chris Wilson | c96521e | 2016-11-27 17:09:10 +0000 | [diff] [blame] | 2033 | const u64 mask = BIT_ULL(fb_helper->connector_count) - 1; |
| 2034 | u64 conn_configured = 0; |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 2035 | int tile_pass = 0; |
Chris Wilson | c96521e | 2016-11-27 17:09:10 +0000 | [diff] [blame] | 2036 | int i; |
| 2037 | |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 2038 | retry: |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 2039 | drm_fb_helper_for_each_connector(fb_helper, i) { |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 2040 | fb_helper_conn = fb_helper->connector_info[i]; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2041 | |
Chris Wilson | c96521e | 2016-11-27 17:09:10 +0000 | [diff] [blame] | 2042 | if (conn_configured & BIT_ULL(i)) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2043 | continue; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2044 | |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 2045 | if (enabled[i] == false) { |
Chris Wilson | c96521e | 2016-11-27 17:09:10 +0000 | [diff] [blame] | 2046 | conn_configured |= BIT_ULL(i); |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 2047 | continue; |
| 2048 | } |
| 2049 | |
| 2050 | /* first pass over all the untiled connectors */ |
| 2051 | if (tile_pass == 0 && fb_helper_conn->connector->has_tile) |
| 2052 | continue; |
| 2053 | |
| 2054 | if (tile_pass == 1) { |
| 2055 | if (fb_helper_conn->connector->tile_h_loc != 0 || |
| 2056 | fb_helper_conn->connector->tile_v_loc != 0) |
| 2057 | continue; |
| 2058 | |
| 2059 | } else { |
| 2060 | if (fb_helper_conn->connector->tile_h_loc != tile_pass -1 && |
| 2061 | fb_helper_conn->connector->tile_v_loc != tile_pass - 1) |
| 2062 | /* if this tile_pass doesn't cover any of the tiles - keep going */ |
| 2063 | continue; |
| 2064 | |
| 2065 | /* find the tile offsets for this pass - need |
| 2066 | to find all tiles left and above */ |
| 2067 | drm_get_tile_offsets(fb_helper, modes, offsets, |
| 2068 | i, fb_helper_conn->connector->tile_h_loc, fb_helper_conn->connector->tile_v_loc); |
| 2069 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2070 | DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n", |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 2071 | fb_helper_conn->connector->base.id); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2072 | |
| 2073 | /* got for command line mode first */ |
Vincent Abriou | a09759e | 2017-01-06 17:44:43 +0100 | [diff] [blame] | 2074 | modes[i] = drm_pick_cmdline_mode(fb_helper_conn); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2075 | if (!modes[i]) { |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 2076 | DRM_DEBUG_KMS("looking for preferred mode on connector %d %d\n", |
| 2077 | fb_helper_conn->connector->base.id, fb_helper_conn->connector->tile_group ? fb_helper_conn->connector->tile_group->id : 0); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 2078 | modes[i] = drm_has_preferred_mode(fb_helper_conn, width, height); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2079 | } |
| 2080 | /* No preferred modes, pick one off the list */ |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 2081 | if (!modes[i] && !list_empty(&fb_helper_conn->connector->modes)) { |
| 2082 | list_for_each_entry(modes[i], &fb_helper_conn->connector->modes, head) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2083 | break; |
| 2084 | } |
| 2085 | DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name : |
| 2086 | "none"); |
Chris Wilson | c96521e | 2016-11-27 17:09:10 +0000 | [diff] [blame] | 2087 | conn_configured |= BIT_ULL(i); |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 2088 | } |
| 2089 | |
| 2090 | if ((conn_configured & mask) != mask) { |
| 2091 | tile_pass++; |
| 2092 | goto retry; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2093 | } |
| 2094 | return true; |
| 2095 | } |
| 2096 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 2097 | static int drm_pick_crtcs(struct drm_fb_helper *fb_helper, |
| 2098 | struct drm_fb_helper_crtc **best_crtcs, |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2099 | struct drm_display_mode **modes, |
| 2100 | int n, int width, int height) |
| 2101 | { |
| 2102 | int c, o; |
| 2103 | struct drm_connector *connector; |
Jani Nikula | be26a66 | 2015-03-11 11:51:06 +0200 | [diff] [blame] | 2104 | const struct drm_connector_helper_funcs *connector_funcs; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2105 | struct drm_encoder *encoder; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2106 | int my_score, best_score, score; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 2107 | struct drm_fb_helper_crtc **crtcs, *crtc; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 2108 | struct drm_fb_helper_connector *fb_helper_conn; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2109 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 2110 | if (n == fb_helper->connector_count) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2111 | return 0; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 2112 | |
| 2113 | fb_helper_conn = fb_helper->connector_info[n]; |
| 2114 | connector = fb_helper_conn->connector; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2115 | |
| 2116 | best_crtcs[n] = NULL; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 2117 | best_score = drm_pick_crtcs(fb_helper, best_crtcs, modes, n+1, width, height); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2118 | if (modes[n] == NULL) |
| 2119 | return best_score; |
| 2120 | |
Lyude | 255f0e7 | 2016-05-12 10:56:59 -0400 | [diff] [blame] | 2121 | crtcs = kzalloc(fb_helper->connector_count * |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 2122 | sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2123 | if (!crtcs) |
| 2124 | return best_score; |
| 2125 | |
| 2126 | my_score = 1; |
| 2127 | if (connector->status == connector_status_connected) |
| 2128 | my_score++; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 2129 | if (drm_has_cmdline_mode(fb_helper_conn)) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2130 | my_score++; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 2131 | if (drm_has_preferred_mode(fb_helper_conn, width, height)) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2132 | my_score++; |
| 2133 | |
| 2134 | connector_funcs = connector->helper_private; |
Boris Brezillon | c61b93f | 2016-06-07 13:47:56 +0200 | [diff] [blame] | 2135 | |
| 2136 | /* |
| 2137 | * If the DRM device implements atomic hooks and ->best_encoder() is |
| 2138 | * NULL we fallback to the default drm_atomic_helper_best_encoder() |
| 2139 | * helper. |
| 2140 | */ |
Dhinakaran Pandiyan | a743d75 | 2016-12-22 00:50:42 -0800 | [diff] [blame] | 2141 | if (drm_drv_uses_atomic_modeset(fb_helper->dev) && |
Boris Brezillon | c61b93f | 2016-06-07 13:47:56 +0200 | [diff] [blame] | 2142 | !connector_funcs->best_encoder) |
| 2143 | encoder = drm_atomic_helper_best_encoder(connector); |
| 2144 | else |
| 2145 | encoder = connector_funcs->best_encoder(connector); |
| 2146 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2147 | if (!encoder) |
| 2148 | goto out; |
| 2149 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2150 | /* select a crtc for this connector and then attempt to configure |
| 2151 | remaining connectors */ |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 2152 | for (c = 0; c < fb_helper->crtc_count; c++) { |
| 2153 | crtc = &fb_helper->crtc_info[c]; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2154 | |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 2155 | if ((encoder->possible_crtcs & (1 << c)) == 0) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2156 | continue; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2157 | |
| 2158 | for (o = 0; o < n; o++) |
| 2159 | if (best_crtcs[o] == crtc) |
| 2160 | break; |
| 2161 | |
| 2162 | if (o < n) { |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 2163 | /* ignore cloning unless only a single crtc */ |
| 2164 | if (fb_helper->crtc_count > 1) |
| 2165 | continue; |
| 2166 | |
| 2167 | if (!drm_mode_equal(modes[o], modes[n])) |
| 2168 | continue; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2169 | } |
| 2170 | |
| 2171 | crtcs[n] = crtc; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 2172 | memcpy(crtcs, best_crtcs, n * sizeof(struct drm_fb_helper_crtc *)); |
| 2173 | score = my_score + drm_pick_crtcs(fb_helper, crtcs, modes, n + 1, |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2174 | width, height); |
| 2175 | if (score > best_score) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2176 | best_score = score; |
| 2177 | memcpy(best_crtcs, crtcs, |
Lyude | 255f0e7 | 2016-05-12 10:56:59 -0400 | [diff] [blame] | 2178 | fb_helper->connector_count * |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 2179 | sizeof(struct drm_fb_helper_crtc *)); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2180 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2181 | } |
| 2182 | out: |
| 2183 | kfree(crtcs); |
| 2184 | return best_score; |
| 2185 | } |
| 2186 | |
Chris Wilson | 64e9440 | 2016-11-29 12:02:16 +0000 | [diff] [blame] | 2187 | static void drm_setup_crtcs(struct drm_fb_helper *fb_helper, |
| 2188 | u32 width, u32 height) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2189 | { |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 2190 | struct drm_device *dev = fb_helper->dev; |
| 2191 | struct drm_fb_helper_crtc **crtcs; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2192 | struct drm_display_mode **modes; |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 2193 | struct drm_fb_offset *offsets; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2194 | bool *enabled; |
Jesse Barnes | 11e17a0 | 2013-02-19 13:31:39 -0800 | [diff] [blame] | 2195 | int i; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2196 | |
| 2197 | DRM_DEBUG_KMS("\n"); |
Chris Wilson | 64e9440 | 2016-11-29 12:02:16 +0000 | [diff] [blame] | 2198 | if (drm_fb_helper_probe_connector_modes(fb_helper, width, height) == 0) |
| 2199 | DRM_DEBUG_KMS("No connectors reported connected with modes\n"); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2200 | |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 2201 | /* prevent concurrent modification of connector_count by hotplug */ |
| 2202 | lockdep_assert_held(&fb_helper->dev->mode_config.mutex); |
| 2203 | |
Maarten Lankhorst | 383b2e5 | 2016-02-15 13:45:15 +0100 | [diff] [blame] | 2204 | crtcs = kcalloc(fb_helper->connector_count, |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 2205 | sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL); |
Maarten Lankhorst | 383b2e5 | 2016-02-15 13:45:15 +0100 | [diff] [blame] | 2206 | modes = kcalloc(fb_helper->connector_count, |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2207 | sizeof(struct drm_display_mode *), GFP_KERNEL); |
Maarten Lankhorst | 383b2e5 | 2016-02-15 13:45:15 +0100 | [diff] [blame] | 2208 | offsets = kcalloc(fb_helper->connector_count, |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 2209 | sizeof(struct drm_fb_offset), GFP_KERNEL); |
Maarten Lankhorst | 383b2e5 | 2016-02-15 13:45:15 +0100 | [diff] [blame] | 2210 | enabled = kcalloc(fb_helper->connector_count, |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2211 | sizeof(bool), GFP_KERNEL); |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 2212 | if (!crtcs || !modes || !enabled || !offsets) { |
Sachin Kamat | 8c5eaca | 2012-11-19 09:44:58 +0000 | [diff] [blame] | 2213 | DRM_ERROR("Memory allocation failed\n"); |
| 2214 | goto out; |
| 2215 | } |
| 2216 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 2217 | drm_enable_connectors(fb_helper, enabled); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2218 | |
Jesse Barnes | 11e17a0 | 2013-02-19 13:31:39 -0800 | [diff] [blame] | 2219 | if (!(fb_helper->funcs->initial_config && |
| 2220 | fb_helper->funcs->initial_config(fb_helper, crtcs, modes, |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 2221 | offsets, |
Jesse Barnes | 11e17a0 | 2013-02-19 13:31:39 -0800 | [diff] [blame] | 2222 | enabled, width, height))) { |
Maarten Lankhorst | 383b2e5 | 2016-02-15 13:45:15 +0100 | [diff] [blame] | 2223 | memset(modes, 0, fb_helper->connector_count*sizeof(modes[0])); |
| 2224 | memset(crtcs, 0, fb_helper->connector_count*sizeof(crtcs[0])); |
| 2225 | memset(offsets, 0, fb_helper->connector_count*sizeof(offsets[0])); |
Jesse Barnes | 11e17a0 | 2013-02-19 13:31:39 -0800 | [diff] [blame] | 2226 | |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 2227 | if (!drm_target_cloned(fb_helper, modes, offsets, |
| 2228 | enabled, width, height) && |
| 2229 | !drm_target_preferred(fb_helper, modes, offsets, |
| 2230 | enabled, width, height)) |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 2231 | DRM_ERROR("Unable to find initial modes\n"); |
Jesse Barnes | 11e17a0 | 2013-02-19 13:31:39 -0800 | [diff] [blame] | 2232 | |
| 2233 | DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n", |
| 2234 | width, height); |
| 2235 | |
| 2236 | drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height); |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 2237 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2238 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 2239 | /* need to set the modesets up here for use later */ |
| 2240 | /* fill out the connector<->crtc mappings into the modesets */ |
Ville Syrjälä | a288960 | 2016-10-26 17:41:18 +0300 | [diff] [blame] | 2241 | for (i = 0; i < fb_helper->crtc_count; i++) |
| 2242 | drm_fb_helper_modeset_release(fb_helper, |
| 2243 | &fb_helper->crtc_info[i].mode_set); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2244 | |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 2245 | drm_fb_helper_for_each_connector(fb_helper, i) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2246 | struct drm_display_mode *mode = modes[i]; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 2247 | struct drm_fb_helper_crtc *fb_crtc = crtcs[i]; |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 2248 | struct drm_fb_offset *offset = &offsets[i]; |
Ville Syrjälä | a288960 | 2016-10-26 17:41:18 +0300 | [diff] [blame] | 2249 | struct drm_mode_set *modeset = &fb_crtc->mode_set; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2250 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 2251 | if (mode && fb_crtc) { |
Ville Syrjälä | a288960 | 2016-10-26 17:41:18 +0300 | [diff] [blame] | 2252 | struct drm_connector *connector = |
| 2253 | fb_helper->connector_info[i]->connector; |
| 2254 | |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 2255 | DRM_DEBUG_KMS("desired mode %s set on crtc %d (%d,%d)\n", |
| 2256 | mode->name, fb_crtc->mode_set.crtc->base.id, offset->x, offset->y); |
Ville Syrjälä | a288960 | 2016-10-26 17:41:18 +0300 | [diff] [blame] | 2257 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 2258 | fb_crtc->desired_mode = mode; |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 2259 | fb_crtc->x = offset->x; |
| 2260 | fb_crtc->y = offset->y; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 2261 | modeset->mode = drm_mode_duplicate(dev, |
| 2262 | fb_crtc->desired_mode); |
Thierry Reding | ad09360 | 2017-02-28 15:46:39 +0100 | [diff] [blame] | 2263 | drm_connector_get(connector); |
Ville Syrjälä | a288960 | 2016-10-26 17:41:18 +0300 | [diff] [blame] | 2264 | modeset->connectors[modeset->num_connectors++] = connector; |
Daniel Vetter | 7e53f3a | 2013-01-21 10:52:17 +0100 | [diff] [blame] | 2265 | modeset->fb = fb_helper->fb; |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 2266 | modeset->x = offset->x; |
| 2267 | modeset->y = offset->y; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2268 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2269 | } |
Sachin Kamat | 8c5eaca | 2012-11-19 09:44:58 +0000 | [diff] [blame] | 2270 | out: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2271 | kfree(crtcs); |
| 2272 | kfree(modes); |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 2273 | kfree(offsets); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2274 | kfree(enabled); |
| 2275 | } |
| 2276 | |
| 2277 | /** |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 2278 | * drm_fb_helper_initial_config - setup a sane initial connector configuration |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 2279 | * @fb_helper: fb_helper device struct |
| 2280 | * @bpp_sel: bpp value to use for the framebuffer configuration |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2281 | * |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 2282 | * Scans the CRTCs and connectors and tries to put together an initial setup. |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2283 | * At the moment, this is a cloned configuration across all heads with |
| 2284 | * a new framebuffer object as the backing store. |
| 2285 | * |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 2286 | * Note that this also registers the fbdev and so allows userspace to call into |
| 2287 | * the driver through the fbdev interfaces. |
| 2288 | * |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 2289 | * This function will call down into the &drm_fb_helper_funcs.fb_probe callback |
| 2290 | * to let the driver allocate and initialize the fbdev info structure and the |
| 2291 | * drm framebuffer used to back the fbdev. drm_fb_helper_fill_var() and |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 2292 | * drm_fb_helper_fill_fix() are provided as helpers to setup simple default |
| 2293 | * values for the fbdev info structure. |
| 2294 | * |
Daniel Vetter | 40f8cf4 | 2016-01-22 08:53:45 +0100 | [diff] [blame] | 2295 | * HANG DEBUGGING: |
| 2296 | * |
| 2297 | * When you have fbcon support built-in or already loaded, this function will do |
| 2298 | * a full modeset to setup the fbdev console. Due to locking misdesign in the |
| 2299 | * VT/fbdev subsystem that entire modeset sequence has to be done while holding |
| 2300 | * console_lock. Until console_unlock is called no dmesg lines will be sent out |
| 2301 | * to consoles, not even serial console. This means when your driver crashes, |
| 2302 | * you will see absolutely nothing else but a system stuck in this function, |
| 2303 | * with no further output. Any kind of printk() you place within your own driver |
| 2304 | * or in the drm core modeset code will also never show up. |
| 2305 | * |
| 2306 | * Standard debug practice is to run the fbcon setup without taking the |
| 2307 | * console_lock as a hack, to be able to see backtraces and crashes on the |
| 2308 | * serial line. This can be done by setting the fb.lockless_register_fb=1 kernel |
| 2309 | * cmdline option. |
| 2310 | * |
| 2311 | * The other option is to just disable fbdev emulation since very likely the |
Lyude | af509d3 | 2016-05-04 11:28:53 -0400 | [diff] [blame] | 2312 | * first modeset from userspace will crash in the same way, and is even easier |
| 2313 | * to debug. This can be done by setting the drm_kms_helper.fbdev_emulation=0 |
Daniel Vetter | 40f8cf4 | 2016-01-22 08:53:45 +0100 | [diff] [blame] | 2314 | * kernel cmdline option. |
| 2315 | * |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2316 | * RETURNS: |
| 2317 | * Zero if everything went ok, nonzero otherwise. |
| 2318 | */ |
Thierry Reding | 01934c2 | 2014-12-19 11:21:32 +0100 | [diff] [blame] | 2319 | int drm_fb_helper_initial_config(struct drm_fb_helper *fb_helper, int bpp_sel) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2320 | { |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 2321 | struct drm_device *dev = fb_helper->dev; |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 2322 | struct fb_info *info; |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 2323 | int ret; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2324 | |
Daniel Vetter | f64c557 | 2015-08-25 15:45:13 +0200 | [diff] [blame] | 2325 | if (!drm_fbdev_emulation) |
| 2326 | return 0; |
| 2327 | |
Daniel Vetter | 53f1904 | 2014-03-20 14:26:35 +0100 | [diff] [blame] | 2328 | mutex_lock(&dev->mode_config.mutex); |
Chris Wilson | 64e9440 | 2016-11-29 12:02:16 +0000 | [diff] [blame] | 2329 | drm_setup_crtcs(fb_helper, |
| 2330 | dev->mode_config.max_width, |
| 2331 | dev->mode_config.max_height); |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 2332 | ret = drm_fb_helper_single_fb_probe(fb_helper, bpp_sel); |
| 2333 | mutex_unlock(&dev->mode_config.mutex); |
| 2334 | if (ret) |
| 2335 | return ret; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2336 | |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 2337 | info = fb_helper->fbdev; |
| 2338 | info->var.pixclock = 0; |
| 2339 | ret = register_framebuffer(info); |
| 2340 | if (ret < 0) |
| 2341 | return ret; |
| 2342 | |
| 2343 | dev_info(dev->dev, "fb%d: %s frame buffer device\n", |
| 2344 | info->node, info->fix.id); |
| 2345 | |
Chris Wilson | a53ca63 | 2016-11-29 12:02:17 +0000 | [diff] [blame] | 2346 | mutex_lock(&kernel_fb_helper_lock); |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 2347 | if (list_empty(&kernel_fb_helper_list)) |
| 2348 | register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op); |
| 2349 | |
| 2350 | list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list); |
Chris Wilson | a53ca63 | 2016-11-29 12:02:17 +0000 | [diff] [blame] | 2351 | mutex_unlock(&kernel_fb_helper_lock); |
Chris Wilson | 966a6a1 | 2016-11-29 12:02:15 +0000 | [diff] [blame] | 2352 | |
| 2353 | return 0; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2354 | } |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 2355 | EXPORT_SYMBOL(drm_fb_helper_initial_config); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2356 | |
Chris Wilson | 7394371 | 2011-04-22 11:03:57 +0100 | [diff] [blame] | 2357 | /** |
| 2358 | * drm_fb_helper_hotplug_event - respond to a hotplug notification by |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 2359 | * probing all the outputs attached to the fb |
Chris Wilson | 7394371 | 2011-04-22 11:03:57 +0100 | [diff] [blame] | 2360 | * @fb_helper: the drm_fb_helper |
| 2361 | * |
Chris Wilson | 7394371 | 2011-04-22 11:03:57 +0100 | [diff] [blame] | 2362 | * Scan the connectors attached to the fb_helper and try to put together a |
Daniel Vetter | 62cacc7 | 2016-08-12 22:48:37 +0200 | [diff] [blame] | 2363 | * setup after notification of a change in output configuration. |
Chris Wilson | 7394371 | 2011-04-22 11:03:57 +0100 | [diff] [blame] | 2364 | * |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 2365 | * Called at runtime, takes the mode config locks to be able to check/change the |
| 2366 | * modeset configuration. Must be run from process context (which usually means |
| 2367 | * either the output polling work or a work item launched from the driver's |
| 2368 | * hotplug interrupt). |
| 2369 | * |
Daniel Vetter | 50c3dc9 | 2014-06-27 17:19:22 +0200 | [diff] [blame] | 2370 | * Note that drivers may call this even before calling |
Lyude | af509d3 | 2016-05-04 11:28:53 -0400 | [diff] [blame] | 2371 | * drm_fb_helper_initial_config but only after drm_fb_helper_init. This allows |
Daniel Vetter | 50c3dc9 | 2014-06-27 17:19:22 +0200 | [diff] [blame] | 2372 | * for a race-free fbcon setup and will make sure that the fbdev emulation will |
| 2373 | * not miss any hotplug events. |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 2374 | * |
Chris Wilson | 7394371 | 2011-04-22 11:03:57 +0100 | [diff] [blame] | 2375 | * RETURNS: |
| 2376 | * 0 on success and a non-zero error code otherwise. |
| 2377 | */ |
| 2378 | int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2379 | { |
Chris Wilson | 7394371 | 2011-04-22 11:03:57 +0100 | [diff] [blame] | 2380 | struct drm_device *dev = fb_helper->dev; |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 2381 | |
Daniel Vetter | f64c557 | 2015-08-25 15:45:13 +0200 | [diff] [blame] | 2382 | if (!drm_fbdev_emulation) |
| 2383 | return 0; |
| 2384 | |
Chris Wilson | 64e9440 | 2016-11-29 12:02:16 +0000 | [diff] [blame] | 2385 | mutex_lock(&dev->mode_config.mutex); |
Daniel Vetter | 50c3dc9 | 2014-06-27 17:19:22 +0200 | [diff] [blame] | 2386 | if (!fb_helper->fb || !drm_fb_helper_is_bound(fb_helper)) { |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 2387 | fb_helper->delayed_hotplug = true; |
Chris Wilson | 64e9440 | 2016-11-29 12:02:16 +0000 | [diff] [blame] | 2388 | mutex_unlock(&dev->mode_config.mutex); |
Chris Wilson | 7394371 | 2011-04-22 11:03:57 +0100 | [diff] [blame] | 2389 | return 0; |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 2390 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2391 | DRM_DEBUG_KMS("\n"); |
| 2392 | |
Chris Wilson | 64e9440 | 2016-11-29 12:02:16 +0000 | [diff] [blame] | 2393 | drm_setup_crtcs(fb_helper, fb_helper->fb->width, fb_helper->fb->height); |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 2394 | |
Chris Wilson | 64e9440 | 2016-11-29 12:02:16 +0000 | [diff] [blame] | 2395 | mutex_unlock(&dev->mode_config.mutex); |
Daniel Vetter | 89ced12 | 2013-04-11 14:26:55 +0000 | [diff] [blame] | 2396 | |
Daniel Vetter | 2180c3c | 2013-01-21 23:12:36 +0100 | [diff] [blame] | 2397 | drm_fb_helper_set_par(fb_helper->fbdev); |
| 2398 | |
| 2399 | return 0; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2400 | } |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 2401 | EXPORT_SYMBOL(drm_fb_helper_hotplug_event); |
Dave Airlie | 5c4426a | 2010-03-30 05:34:17 +0000 | [diff] [blame] | 2402 | |
David Rientjes | 6a108a1 | 2011-01-20 14:44:16 -0800 | [diff] [blame] | 2403 | /* The Kconfig DRM_KMS_HELPER selects FRAMEBUFFER_CONSOLE (if !EXPERT) |
David Fries | 3ce0516 | 2010-12-12 12:39:22 -0600 | [diff] [blame] | 2404 | * but the module doesn't depend on any fb console symbols. At least |
| 2405 | * attempt to load fbcon to avoid leaving the system without a usable console. |
| 2406 | */ |
Rafael Antognolli | 70412cf | 2016-01-21 15:10:18 -0800 | [diff] [blame] | 2407 | int __init drm_fb_helper_modinit(void) |
David Fries | 3ce0516 | 2010-12-12 12:39:22 -0600 | [diff] [blame] | 2408 | { |
Rafael Antognolli | 70412cf | 2016-01-21 15:10:18 -0800 | [diff] [blame] | 2409 | #if defined(CONFIG_FRAMEBUFFER_CONSOLE_MODULE) && !defined(CONFIG_EXPERT) |
David Fries | 3ce0516 | 2010-12-12 12:39:22 -0600 | [diff] [blame] | 2410 | const char *name = "fbcon"; |
| 2411 | struct module *fbcon; |
| 2412 | |
| 2413 | mutex_lock(&module_mutex); |
| 2414 | fbcon = find_module(name); |
| 2415 | mutex_unlock(&module_mutex); |
| 2416 | |
| 2417 | if (!fbcon) |
| 2418 | request_module_nowait(name); |
Rafael Antognolli | 70412cf | 2016-01-21 15:10:18 -0800 | [diff] [blame] | 2419 | #endif |
David Fries | 3ce0516 | 2010-12-12 12:39:22 -0600 | [diff] [blame] | 2420 | return 0; |
| 2421 | } |
Rafael Antognolli | 70412cf | 2016-01-21 15:10:18 -0800 | [diff] [blame] | 2422 | EXPORT_SYMBOL(drm_fb_helper_modinit); |