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