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 | |
Andy Shevchenko | 3b40a44 | 2010-02-02 14:40:32 -0800 | [diff] [blame] | 32 | #include <linux/kernel.h> |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 33 | #include <linux/sysrq.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 35 | #include <linux/fb.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> |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 41 | |
| 42 | static LIST_HEAD(kernel_fb_helper_list); |
| 43 | |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 44 | /** |
| 45 | * DOC: fbdev helpers |
| 46 | * |
| 47 | * 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] | 48 | * mode setting driver. They can be used mostly independently from the crtc |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 49 | * helper functions used by many drivers to implement the kernel mode setting |
| 50 | * interfaces. |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 51 | * |
Thierry Reding | 10a2310 | 2014-06-27 17:19:24 +0200 | [diff] [blame] | 52 | * Initialization is done as a four-step process with drm_fb_helper_prepare(), |
| 53 | * drm_fb_helper_init(), drm_fb_helper_single_add_all_connectors() and |
| 54 | * drm_fb_helper_initial_config(). Drivers with fancier requirements than the |
| 55 | * default behaviour can override the third step with their own code. |
| 56 | * Teardown is done with drm_fb_helper_fini(). |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 57 | * |
| 58 | * At runtime drivers should restore the fbdev console by calling |
| 59 | * drm_fb_helper_restore_fbdev_mode() from their ->lastclose callback. They |
| 60 | * should also notify the fb helper code from updates to the output |
| 61 | * configuration by calling drm_fb_helper_hotplug_event(). For easier |
| 62 | * integration with the output polling code in drm_crtc_helper.c the modeset |
Thierry Reding | 83c617c | 2014-04-29 11:44:35 +0200 | [diff] [blame] | 63 | * code provides a ->output_poll_changed callback. |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 64 | * |
| 65 | * All other functions exported by the fb helper library can be used to |
| 66 | * implement the fbdev driver interface by the driver. |
Thierry Reding | 10a2310 | 2014-06-27 17:19:24 +0200 | [diff] [blame] | 67 | * |
| 68 | * It is possible, though perhaps somewhat tricky, to implement race-free |
| 69 | * hotplug detection using the fbdev helpers. The drm_fb_helper_prepare() |
| 70 | * helper must be called first to initialize the minimum required to make |
| 71 | * hotplug detection work. Drivers also need to make sure to properly set up |
| 72 | * the dev->mode_config.funcs member. After calling drm_kms_helper_poll_init() |
| 73 | * it is safe to enable interrupts and start processing hotplug events. At the |
| 74 | * same time, drivers should initialize all modeset objects such as CRTCs, |
| 75 | * encoders and connectors. To finish up the fbdev helper initialization, the |
| 76 | * drm_fb_helper_init() function is called. To probe for all attached displays |
| 77 | * and set up an initial configuration using the detected hardware, drivers |
| 78 | * should call drm_fb_helper_single_add_all_connectors() followed by |
| 79 | * drm_fb_helper_initial_config(). |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 80 | */ |
| 81 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 82 | /** |
| 83 | * drm_fb_helper_single_add_all_connectors() - add all connectors to fbdev |
| 84 | * emulation helper |
| 85 | * @fb_helper: fbdev initialized with drm_fb_helper_init |
| 86 | * |
| 87 | * This functions adds all the available connectors for use with the given |
| 88 | * fb_helper. This is a separate step to allow drivers to freely assign |
| 89 | * connectors to the fbdev, e.g. if some are reserved for special purposes or |
| 90 | * not adequate to be used for the fbcon. |
| 91 | * |
Daniel Vetter | 169faec | 2015-07-09 23:44:27 +0200 | [diff] [blame] | 92 | * This function is protected against concurrent connector hotadds/removals |
| 93 | * using drm_fb_helper_add_one_connector() and |
| 94 | * drm_fb_helper_remove_one_connector(). |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 95 | */ |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 96 | 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] | 97 | { |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 98 | struct drm_device *dev = fb_helper->dev; |
| 99 | struct drm_connector *connector; |
| 100 | int i; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 101 | |
Daniel Vetter | 169faec | 2015-07-09 23:44:27 +0200 | [diff] [blame] | 102 | mutex_lock(&dev->mode_config.mutex); |
Daniel Vetter | 6295d60 | 2015-07-09 23:44:25 +0200 | [diff] [blame] | 103 | drm_for_each_connector(connector, dev) { |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 104 | struct drm_fb_helper_connector *fb_helper_connector; |
| 105 | |
| 106 | fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL); |
| 107 | if (!fb_helper_connector) |
| 108 | goto fail; |
| 109 | |
| 110 | fb_helper_connector->connector = connector; |
| 111 | fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector; |
| 112 | } |
Daniel Vetter | 169faec | 2015-07-09 23:44:27 +0200 | [diff] [blame] | 113 | mutex_unlock(&dev->mode_config.mutex); |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 114 | return 0; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 115 | fail: |
| 116 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 117 | kfree(fb_helper->connector_info[i]); |
| 118 | fb_helper->connector_info[i] = NULL; |
| 119 | } |
| 120 | fb_helper->connector_count = 0; |
Daniel Vetter | 169faec | 2015-07-09 23:44:27 +0200 | [diff] [blame] | 121 | mutex_unlock(&dev->mode_config.mutex); |
| 122 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 123 | return -ENOMEM; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 124 | } |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 125 | EXPORT_SYMBOL(drm_fb_helper_single_add_all_connectors); |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 126 | |
Dave Airlie | 65c2a89 | 2014-06-05 14:01:30 +1000 | [diff] [blame] | 127 | int drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper, struct drm_connector *connector) |
| 128 | { |
| 129 | struct drm_fb_helper_connector **temp; |
| 130 | struct drm_fb_helper_connector *fb_helper_connector; |
| 131 | |
| 132 | WARN_ON(!mutex_is_locked(&fb_helper->dev->mode_config.mutex)); |
| 133 | if (fb_helper->connector_count + 1 > fb_helper->connector_info_alloc_count) { |
Damien Lespiau | 14f476f | 2014-08-08 19:15:20 +0100 | [diff] [blame] | 134 | temp = krealloc(fb_helper->connector_info, sizeof(struct drm_fb_helper_connector *) * (fb_helper->connector_count + 1), GFP_KERNEL); |
Dave Airlie | 65c2a89 | 2014-06-05 14:01:30 +1000 | [diff] [blame] | 135 | if (!temp) |
| 136 | return -ENOMEM; |
| 137 | |
| 138 | fb_helper->connector_info_alloc_count = fb_helper->connector_count + 1; |
| 139 | fb_helper->connector_info = temp; |
| 140 | } |
| 141 | |
| 142 | |
| 143 | fb_helper_connector = kzalloc(sizeof(struct drm_fb_helper_connector), GFP_KERNEL); |
| 144 | if (!fb_helper_connector) |
| 145 | return -ENOMEM; |
| 146 | |
| 147 | fb_helper_connector->connector = connector; |
| 148 | fb_helper->connector_info[fb_helper->connector_count++] = fb_helper_connector; |
| 149 | return 0; |
| 150 | } |
| 151 | EXPORT_SYMBOL(drm_fb_helper_add_one_connector); |
| 152 | |
Rob Clark | 2148f18 | 2015-01-26 10:11:08 -0500 | [diff] [blame] | 153 | static void remove_from_modeset(struct drm_mode_set *set, |
| 154 | struct drm_connector *connector) |
| 155 | { |
| 156 | int i, j; |
| 157 | |
| 158 | for (i = 0; i < set->num_connectors; i++) { |
| 159 | if (set->connectors[i] == connector) |
| 160 | break; |
| 161 | } |
| 162 | |
| 163 | if (i == set->num_connectors) |
| 164 | return; |
| 165 | |
| 166 | for (j = i + 1; j < set->num_connectors; j++) { |
| 167 | set->connectors[j - 1] = set->connectors[j]; |
| 168 | } |
| 169 | set->num_connectors--; |
| 170 | |
| 171 | /* because i915 is pissy about this.. |
| 172 | * TODO maybe need to makes sure we set it back to !=NULL somewhere? |
| 173 | */ |
| 174 | if (set->num_connectors == 0) |
| 175 | set->fb = NULL; |
| 176 | } |
| 177 | |
Dave Airlie | 65c2a89 | 2014-06-05 14:01:30 +1000 | [diff] [blame] | 178 | int drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper, |
| 179 | struct drm_connector *connector) |
| 180 | { |
| 181 | struct drm_fb_helper_connector *fb_helper_connector; |
| 182 | int i, j; |
| 183 | |
| 184 | WARN_ON(!mutex_is_locked(&fb_helper->dev->mode_config.mutex)); |
| 185 | |
| 186 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 187 | if (fb_helper->connector_info[i]->connector == connector) |
| 188 | break; |
| 189 | } |
| 190 | |
| 191 | if (i == fb_helper->connector_count) |
| 192 | return -EINVAL; |
| 193 | fb_helper_connector = fb_helper->connector_info[i]; |
| 194 | |
| 195 | for (j = i + 1; j < fb_helper->connector_count; j++) { |
| 196 | fb_helper->connector_info[j - 1] = fb_helper->connector_info[j]; |
| 197 | } |
| 198 | fb_helper->connector_count--; |
| 199 | kfree(fb_helper_connector); |
Rob Clark | 2148f18 | 2015-01-26 10:11:08 -0500 | [diff] [blame] | 200 | |
| 201 | /* also cleanup dangling references to the connector: */ |
| 202 | for (i = 0; i < fb_helper->crtc_count; i++) |
| 203 | remove_from_modeset(&fb_helper->crtc_info[i].mode_set, connector); |
| 204 | |
Dave Airlie | 65c2a89 | 2014-06-05 14:01:30 +1000 | [diff] [blame] | 205 | return 0; |
| 206 | } |
| 207 | EXPORT_SYMBOL(drm_fb_helper_remove_one_connector); |
| 208 | |
Jason Wessel | 9923102 | 2010-10-13 14:09:43 -0500 | [diff] [blame] | 209 | static void drm_fb_helper_save_lut_atomic(struct drm_crtc *crtc, struct drm_fb_helper *helper) |
| 210 | { |
| 211 | uint16_t *r_base, *g_base, *b_base; |
| 212 | int i; |
| 213 | |
Ville Syrjälä | 04c0c56 | 2013-05-27 20:19:57 +0300 | [diff] [blame] | 214 | if (helper->funcs->gamma_get == NULL) |
| 215 | return; |
| 216 | |
Jason Wessel | 9923102 | 2010-10-13 14:09:43 -0500 | [diff] [blame] | 217 | r_base = crtc->gamma_store; |
| 218 | g_base = r_base + crtc->gamma_size; |
| 219 | b_base = g_base + crtc->gamma_size; |
| 220 | |
| 221 | for (i = 0; i < crtc->gamma_size; i++) |
| 222 | helper->funcs->gamma_get(crtc, &r_base[i], &g_base[i], &b_base[i], i); |
| 223 | } |
| 224 | |
| 225 | static void drm_fb_helper_restore_lut_atomic(struct drm_crtc *crtc) |
| 226 | { |
| 227 | uint16_t *r_base, *g_base, *b_base; |
| 228 | |
Laurent Pinchart | ebe0f24 | 2012-05-17 13:27:24 +0200 | [diff] [blame] | 229 | if (crtc->funcs->gamma_set == NULL) |
| 230 | return; |
| 231 | |
Jason Wessel | 9923102 | 2010-10-13 14:09:43 -0500 | [diff] [blame] | 232 | r_base = crtc->gamma_store; |
| 233 | g_base = r_base + crtc->gamma_size; |
| 234 | b_base = g_base + crtc->gamma_size; |
| 235 | |
| 236 | crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size); |
| 237 | } |
| 238 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 239 | /** |
| 240 | * drm_fb_helper_debug_enter - implementation for ->fb_debug_enter |
| 241 | * @info: fbdev registered by the helper |
| 242 | */ |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 243 | int drm_fb_helper_debug_enter(struct fb_info *info) |
| 244 | { |
| 245 | struct drm_fb_helper *helper = info->par; |
Jani Nikula | be26a66 | 2015-03-11 11:51:06 +0200 | [diff] [blame] | 246 | const struct drm_crtc_helper_funcs *funcs; |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 247 | int i; |
| 248 | |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 249 | list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) { |
| 250 | for (i = 0; i < helper->crtc_count; i++) { |
| 251 | struct drm_mode_set *mode_set = |
| 252 | &helper->crtc_info[i].mode_set; |
| 253 | |
| 254 | if (!mode_set->crtc->enabled) |
| 255 | continue; |
| 256 | |
| 257 | funcs = mode_set->crtc->helper_private; |
Jason Wessel | 9923102 | 2010-10-13 14:09:43 -0500 | [diff] [blame] | 258 | drm_fb_helper_save_lut_atomic(mode_set->crtc, helper); |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 259 | funcs->mode_set_base_atomic(mode_set->crtc, |
| 260 | mode_set->fb, |
| 261 | mode_set->x, |
Jason Wessel | 413d45d | 2010-09-26 06:47:25 -0500 | [diff] [blame] | 262 | mode_set->y, |
Jason Wessel | 21c74a8 | 2010-10-13 14:09:44 -0500 | [diff] [blame] | 263 | ENTER_ATOMIC_MODE_SET); |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | EXPORT_SYMBOL(drm_fb_helper_debug_enter); |
| 270 | |
| 271 | /* Find the real fb for a given fb helper CRTC */ |
| 272 | static struct drm_framebuffer *drm_mode_config_fb(struct drm_crtc *crtc) |
| 273 | { |
| 274 | struct drm_device *dev = crtc->dev; |
| 275 | struct drm_crtc *c; |
| 276 | |
Daniel Vetter | 6295d60 | 2015-07-09 23:44:25 +0200 | [diff] [blame] | 277 | drm_for_each_crtc(c, dev) { |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 278 | if (crtc->base.id == c->base.id) |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 279 | return c->primary->fb; |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | return NULL; |
| 283 | } |
| 284 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 285 | /** |
| 286 | * drm_fb_helper_debug_leave - implementation for ->fb_debug_leave |
| 287 | * @info: fbdev registered by the helper |
| 288 | */ |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 289 | int drm_fb_helper_debug_leave(struct fb_info *info) |
| 290 | { |
| 291 | struct drm_fb_helper *helper = info->par; |
| 292 | struct drm_crtc *crtc; |
Jani Nikula | be26a66 | 2015-03-11 11:51:06 +0200 | [diff] [blame] | 293 | const struct drm_crtc_helper_funcs *funcs; |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 294 | struct drm_framebuffer *fb; |
| 295 | int i; |
| 296 | |
| 297 | for (i = 0; i < helper->crtc_count; i++) { |
| 298 | struct drm_mode_set *mode_set = &helper->crtc_info[i].mode_set; |
| 299 | crtc = mode_set->crtc; |
| 300 | funcs = crtc->helper_private; |
| 301 | fb = drm_mode_config_fb(crtc); |
| 302 | |
| 303 | if (!crtc->enabled) |
| 304 | continue; |
| 305 | |
| 306 | if (!fb) { |
| 307 | DRM_ERROR("no fb to restore??\n"); |
| 308 | continue; |
| 309 | } |
| 310 | |
Jason Wessel | 9923102 | 2010-10-13 14:09:43 -0500 | [diff] [blame] | 311 | drm_fb_helper_restore_lut_atomic(mode_set->crtc); |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 312 | funcs->mode_set_base_atomic(mode_set->crtc, fb, crtc->x, |
Jason Wessel | 21c74a8 | 2010-10-13 14:09:44 -0500 | [diff] [blame] | 313 | crtc->y, LEAVE_ATOMIC_MODE_SET); |
Jesse Barnes | 1a7aba7 | 2010-08-05 09:22:31 -0500 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | return 0; |
| 317 | } |
| 318 | EXPORT_SYMBOL(drm_fb_helper_debug_leave); |
| 319 | |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 320 | static bool restore_fbdev_mode(struct drm_fb_helper *fb_helper) |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 321 | { |
Ville Syrjälä | 3858bc5 | 2013-06-03 16:10:42 +0300 | [diff] [blame] | 322 | struct drm_device *dev = fb_helper->dev; |
| 323 | struct drm_plane *plane; |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 324 | bool error = false; |
Ville Syrjälä | 3858bc5 | 2013-06-03 16:10:42 +0300 | [diff] [blame] | 325 | int i; |
Daniel Vetter | 6aed8ec | 2013-01-20 17:32:21 +0100 | [diff] [blame] | 326 | |
Ville Syrjälä | 3858bc5 | 2013-06-03 16:10:42 +0300 | [diff] [blame] | 327 | drm_warn_on_modeset_not_all_locked(dev); |
| 328 | |
Daniel Vetter | 6295d60 | 2015-07-09 23:44:25 +0200 | [diff] [blame] | 329 | drm_for_each_plane(plane, dev) { |
Matt Roper | e27dde3 | 2014-04-01 15:22:30 -0700 | [diff] [blame] | 330 | if (plane->type != DRM_PLANE_TYPE_PRIMARY) |
| 331 | drm_plane_force_disable(plane); |
Daniel Vetter | 6aed8ec | 2013-01-20 17:32:21 +0100 | [diff] [blame] | 332 | |
Sonika Jindal | 9783de2 | 2014-08-05 11:26:57 +0530 | [diff] [blame] | 333 | if (dev->mode_config.rotation_property) { |
Thomas Wood | 3a5f87c | 2014-08-20 14:45:00 +0100 | [diff] [blame] | 334 | drm_mode_plane_set_obj_prop(plane, |
| 335 | dev->mode_config.rotation_property, |
| 336 | BIT(DRM_ROTATE_0)); |
Sonika Jindal | 9783de2 | 2014-08-05 11:26:57 +0530 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 340 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 341 | 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] | 342 | struct drm_crtc *crtc = mode_set->crtc; |
| 343 | int ret; |
| 344 | |
| 345 | if (crtc->funcs->cursor_set) { |
| 346 | ret = crtc->funcs->cursor_set(crtc, NULL, 0, 0, 0); |
| 347 | if (ret) |
| 348 | error = true; |
| 349 | } |
| 350 | |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 351 | ret = drm_mode_set_config_internal(mode_set); |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 352 | if (ret) |
| 353 | error = true; |
| 354 | } |
| 355 | return error; |
| 356 | } |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 357 | /** |
| 358 | * drm_fb_helper_restore_fbdev_mode - restore fbdev configuration |
| 359 | * @fb_helper: fbcon to restore |
| 360 | * |
| 361 | * This should be called from driver's drm ->lastclose callback |
| 362 | * when implementing an fbcon on top of kms using this helper. This ensures that |
| 363 | * the user isn't greeted with a black screen when e.g. X dies. |
| 364 | * |
| 365 | * Use this variant if you need to bypass locking (panic), or already |
| 366 | * hold all modeset locks. Otherwise use drm_fb_helper_restore_fbdev_mode_unlocked() |
| 367 | */ |
| 368 | static bool drm_fb_helper_restore_fbdev_mode(struct drm_fb_helper *fb_helper) |
| 369 | { |
| 370 | return restore_fbdev_mode(fb_helper); |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * drm_fb_helper_restore_fbdev_mode_unlocked - restore fbdev configuration |
| 375 | * @fb_helper: fbcon to restore |
| 376 | * |
| 377 | * This should be called from driver's drm ->lastclose callback |
| 378 | * when implementing an fbcon on top of kms using this helper. This ensures that |
| 379 | * the user isn't greeted with a black screen when e.g. X dies. |
| 380 | */ |
| 381 | bool drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper) |
| 382 | { |
| 383 | struct drm_device *dev = fb_helper->dev; |
| 384 | bool ret; |
Dave Airlie | e2809c7 | 2014-11-26 13:15:24 +1000 | [diff] [blame] | 385 | bool do_delayed = false; |
| 386 | |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 387 | drm_modeset_lock_all(dev); |
| 388 | ret = restore_fbdev_mode(fb_helper); |
Dave Airlie | e2809c7 | 2014-11-26 13:15:24 +1000 | [diff] [blame] | 389 | |
| 390 | do_delayed = fb_helper->delayed_hotplug; |
| 391 | if (do_delayed) |
| 392 | fb_helper->delayed_hotplug = false; |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 393 | drm_modeset_unlock_all(dev); |
Dave Airlie | e2809c7 | 2014-11-26 13:15:24 +1000 | [diff] [blame] | 394 | |
| 395 | if (do_delayed) |
| 396 | drm_fb_helper_hotplug_event(fb_helper); |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 397 | return ret; |
| 398 | } |
| 399 | EXPORT_SYMBOL(drm_fb_helper_restore_fbdev_mode_unlocked); |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 400 | |
Daniel Vetter | d21bf46 | 2013-01-20 18:09:52 +0100 | [diff] [blame] | 401 | /* |
| 402 | * restore fbcon display for all kms driver's using this helper, used for sysrq |
| 403 | * and panic handling. |
| 404 | */ |
Sachin Kamat | 78b9c35 | 2012-08-01 17:15:32 +0530 | [diff] [blame] | 405 | static bool drm_fb_helper_force_kernel_mode(void) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 406 | { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 407 | bool ret, error = false; |
| 408 | struct drm_fb_helper *helper; |
| 409 | |
| 410 | if (list_empty(&kernel_fb_helper_list)) |
| 411 | return false; |
| 412 | |
| 413 | list_for_each_entry(helper, &kernel_fb_helper_list, kernel_fb_list) { |
Thierry Reding | b77f076 | 2014-04-29 11:44:32 +0200 | [diff] [blame] | 414 | struct drm_device *dev = helper->dev; |
| 415 | |
| 416 | if (dev->switch_power_state == DRM_SWITCH_POWER_OFF) |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 417 | continue; |
| 418 | |
Daniel Vetter | cb597bb | 2014-07-27 19:09:33 +0200 | [diff] [blame] | 419 | /* |
| 420 | * NOTE: Use trylock mode to avoid deadlocks and sleeping in |
| 421 | * panic context. |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 422 | */ |
Daniel Vetter | cb597bb | 2014-07-27 19:09:33 +0200 | [diff] [blame] | 423 | if (__drm_modeset_lock_all(dev, true) != 0) { |
Thierry Reding | b77f076 | 2014-04-29 11:44:32 +0200 | [diff] [blame] | 424 | error = true; |
| 425 | continue; |
| 426 | } |
| 427 | |
Dave Airlie | e8e7a2b | 2011-04-21 22:18:32 +0100 | [diff] [blame] | 428 | ret = drm_fb_helper_restore_fbdev_mode(helper); |
| 429 | if (ret) |
| 430 | error = true; |
Thierry Reding | b77f076 | 2014-04-29 11:44:32 +0200 | [diff] [blame] | 431 | |
Daniel Vetter | cb597bb | 2014-07-27 19:09:33 +0200 | [diff] [blame] | 432 | drm_modeset_unlock_all(dev); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 433 | } |
| 434 | return error; |
| 435 | } |
| 436 | |
Daniel Vetter | 20c60c3 | 2012-12-17 12:13:23 +0100 | [diff] [blame] | 437 | static bool drm_fb_helper_is_bound(struct drm_fb_helper *fb_helper) |
| 438 | { |
| 439 | struct drm_device *dev = fb_helper->dev; |
| 440 | struct drm_crtc *crtc; |
| 441 | int bound = 0, crtcs_bound = 0; |
| 442 | |
Paulo Zanoni | 520edd1 | 2013-11-27 18:24:08 -0200 | [diff] [blame] | 443 | /* Sometimes user space wants everything disabled, so don't steal the |
| 444 | * display if there's a master. */ |
| 445 | if (dev->primary->master) |
| 446 | return false; |
| 447 | |
Daniel Vetter | 6295d60 | 2015-07-09 23:44:25 +0200 | [diff] [blame] | 448 | drm_for_each_crtc(crtc, dev) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 449 | if (crtc->primary->fb) |
Daniel Vetter | 20c60c3 | 2012-12-17 12:13:23 +0100 | [diff] [blame] | 450 | crtcs_bound++; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 451 | if (crtc->primary->fb == fb_helper->fb) |
Daniel Vetter | 20c60c3 | 2012-12-17 12:13:23 +0100 | [diff] [blame] | 452 | bound++; |
| 453 | } |
| 454 | |
| 455 | if (bound < crtcs_bound) |
| 456 | return false; |
Paulo Zanoni | 520edd1 | 2013-11-27 18:24:08 -0200 | [diff] [blame] | 457 | |
Daniel Vetter | 20c60c3 | 2012-12-17 12:13:23 +0100 | [diff] [blame] | 458 | return true; |
| 459 | } |
| 460 | |
Mikael Pettersson | bea1d35 | 2009-09-28 18:26:25 +0200 | [diff] [blame] | 461 | #ifdef CONFIG_MAGIC_SYSRQ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 462 | static void drm_fb_helper_restore_work_fn(struct work_struct *ignored) |
| 463 | { |
Daniel Vetter | d21bf46 | 2013-01-20 18:09:52 +0100 | [diff] [blame] | 464 | bool ret; |
| 465 | ret = drm_fb_helper_force_kernel_mode(); |
| 466 | if (ret == true) |
| 467 | DRM_ERROR("Failed to restore crtc configuration\n"); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 468 | } |
| 469 | static DECLARE_WORK(drm_fb_helper_restore_work, drm_fb_helper_restore_work_fn); |
| 470 | |
Dmitry Torokhov | 1495cc9 | 2010-08-17 21:15:46 -0700 | [diff] [blame] | 471 | static void drm_fb_helper_sysrq(int dummy1) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 472 | { |
| 473 | schedule_work(&drm_fb_helper_restore_work); |
| 474 | } |
| 475 | |
| 476 | static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { |
| 477 | .handler = drm_fb_helper_sysrq, |
| 478 | .help_msg = "force-fb(V)", |
| 479 | .action_msg = "Restore framebuffer console", |
| 480 | }; |
Randy Dunlap | b8c40d6 | 2010-03-25 18:29:05 +0000 | [diff] [blame] | 481 | #else |
| 482 | static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { }; |
Mikael Pettersson | bea1d35 | 2009-09-28 18:26:25 +0200 | [diff] [blame] | 483 | #endif |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 484 | |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 485 | 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] | 486 | { |
| 487 | struct drm_fb_helper *fb_helper = info->par; |
| 488 | struct drm_device *dev = fb_helper->dev; |
| 489 | struct drm_crtc *crtc; |
Jesse Barnes | 023eb57 | 2010-07-02 10:48:08 -0700 | [diff] [blame] | 490 | struct drm_connector *connector; |
Jesse Barnes | 023eb57 | 2010-07-02 10:48:08 -0700 | [diff] [blame] | 491 | int i, j; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 492 | |
| 493 | /* |
Daniel Vetter | 1b1d539 | 2013-01-24 16:42:07 +0100 | [diff] [blame] | 494 | * fbdev->blank can be called from irq context in case of a panic. |
| 495 | * Since we already have our own special panic handler which will |
| 496 | * restore the fbdev console mode completely, just bail out early. |
| 497 | */ |
| 498 | if (oops_in_progress) |
| 499 | return; |
| 500 | |
| 501 | /* |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 502 | * For each CRTC in this fb, turn the connectors on/off. |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 503 | */ |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 504 | drm_modeset_lock_all(dev); |
Daniel Vetter | 20c60c3 | 2012-12-17 12:13:23 +0100 | [diff] [blame] | 505 | if (!drm_fb_helper_is_bound(fb_helper)) { |
| 506 | drm_modeset_unlock_all(dev); |
| 507 | return; |
| 508 | } |
| 509 | |
Jesse Barnes | e87b2c4 | 2009-09-17 18:14:41 -0700 | [diff] [blame] | 510 | for (i = 0; i < fb_helper->crtc_count; i++) { |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 511 | crtc = fb_helper->crtc_info[i].mode_set.crtc; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 512 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 513 | if (!crtc->enabled) |
| 514 | continue; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 515 | |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 516 | /* Walk the connectors & encoders on this fb turning them on/off */ |
Jesse Barnes | 023eb57 | 2010-07-02 10:48:08 -0700 | [diff] [blame] | 517 | for (j = 0; j < fb_helper->connector_count; j++) { |
| 518 | connector = fb_helper->connector_info[j]->connector; |
Daniel Vetter | e04190e | 2012-09-07 10:14:52 +0200 | [diff] [blame] | 519 | connector->funcs->dpms(connector, dpms_mode); |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 520 | drm_object_property_set_value(&connector->base, |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 521 | dev->mode_config.dpms_property, dpms_mode); |
Jesse Barnes | 023eb57 | 2010-07-02 10:48:08 -0700 | [diff] [blame] | 522 | } |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 523 | } |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 524 | drm_modeset_unlock_all(dev); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 525 | } |
| 526 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 527 | /** |
| 528 | * drm_fb_helper_blank - implementation for ->fb_blank |
| 529 | * @blank: desired blanking state |
| 530 | * @info: fbdev registered by the helper |
| 531 | */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 532 | int drm_fb_helper_blank(int blank, struct fb_info *info) |
| 533 | { |
| 534 | switch (blank) { |
James Simmons | 731b5a1 | 2009-10-29 20:39:07 +0000 | [diff] [blame] | 535 | /* Display: On; HSync: On, VSync: On */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 536 | case FB_BLANK_UNBLANK: |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 537 | drm_fb_helper_dpms(info, DRM_MODE_DPMS_ON); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 538 | break; |
James Simmons | 731b5a1 | 2009-10-29 20:39:07 +0000 | [diff] [blame] | 539 | /* Display: Off; HSync: On, VSync: On */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 540 | case FB_BLANK_NORMAL: |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 541 | drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 542 | break; |
James Simmons | 731b5a1 | 2009-10-29 20:39:07 +0000 | [diff] [blame] | 543 | /* Display: Off; HSync: Off, VSync: On */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 544 | case FB_BLANK_HSYNC_SUSPEND: |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 545 | drm_fb_helper_dpms(info, DRM_MODE_DPMS_STANDBY); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 546 | break; |
James Simmons | 731b5a1 | 2009-10-29 20:39:07 +0000 | [diff] [blame] | 547 | /* Display: Off; HSync: On, VSync: Off */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 548 | case FB_BLANK_VSYNC_SUSPEND: |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 549 | drm_fb_helper_dpms(info, DRM_MODE_DPMS_SUSPEND); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 550 | break; |
James Simmons | 731b5a1 | 2009-10-29 20:39:07 +0000 | [diff] [blame] | 551 | /* Display: Off; HSync: Off, VSync: Off */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 552 | case FB_BLANK_POWERDOWN: |
Sascha Hauer | 3a8148c | 2012-02-01 11:38:24 +0100 | [diff] [blame] | 553 | drm_fb_helper_dpms(info, DRM_MODE_DPMS_OFF); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 554 | break; |
| 555 | } |
| 556 | return 0; |
| 557 | } |
| 558 | EXPORT_SYMBOL(drm_fb_helper_blank); |
| 559 | |
| 560 | static void drm_fb_helper_crtc_free(struct drm_fb_helper *helper) |
| 561 | { |
| 562 | int i; |
| 563 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 564 | for (i = 0; i < helper->connector_count; i++) |
| 565 | kfree(helper->connector_info[i]); |
| 566 | kfree(helper->connector_info); |
Sascha Hauer | a1b7736 | 2012-02-01 11:38:22 +0100 | [diff] [blame] | 567 | for (i = 0; i < helper->crtc_count; i++) { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 568 | kfree(helper->crtc_info[i].mode_set.connectors); |
Sascha Hauer | a1b7736 | 2012-02-01 11:38:22 +0100 | [diff] [blame] | 569 | if (helper->crtc_info[i].mode_set.mode) |
| 570 | drm_mode_destroy(helper->dev, helper->crtc_info[i].mode_set.mode); |
| 571 | } |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 572 | kfree(helper->crtc_info); |
| 573 | } |
| 574 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 575 | /** |
Thierry Reding | 10a2310 | 2014-06-27 17:19:24 +0200 | [diff] [blame] | 576 | * drm_fb_helper_prepare - setup a drm_fb_helper structure |
| 577 | * @dev: DRM device |
| 578 | * @helper: driver-allocated fbdev helper structure to set up |
| 579 | * @funcs: pointer to structure of functions associate with this helper |
| 580 | * |
| 581 | * Sets up the bare minimum to make the framebuffer helper usable. This is |
| 582 | * useful to implement race-free initialization of the polling helpers. |
| 583 | */ |
| 584 | void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper, |
| 585 | const struct drm_fb_helper_funcs *funcs) |
| 586 | { |
| 587 | INIT_LIST_HEAD(&helper->kernel_fb_list); |
| 588 | helper->funcs = funcs; |
| 589 | helper->dev = dev; |
| 590 | } |
| 591 | EXPORT_SYMBOL(drm_fb_helper_prepare); |
| 592 | |
| 593 | /** |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 594 | * drm_fb_helper_init - initialize a drm_fb_helper structure |
| 595 | * @dev: drm device |
| 596 | * @fb_helper: driver-allocated fbdev helper structure to initialize |
| 597 | * @crtc_count: maximum number of crtcs to support in this fbdev emulation |
| 598 | * @max_conn_count: max connector count |
| 599 | * |
| 600 | * This allocates the structures for the fbdev helper with the given limits. |
| 601 | * Note that this won't yet touch the hardware (through the driver interfaces) |
| 602 | * nor register the fbdev. This is only done in drm_fb_helper_initial_config() |
| 603 | * to allow driver writes more control over the exact init sequence. |
| 604 | * |
Thierry Reding | 10a2310 | 2014-06-27 17:19:24 +0200 | [diff] [blame] | 605 | * Drivers must call drm_fb_helper_prepare() before calling this function. |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 606 | * |
| 607 | * RETURNS: |
| 608 | * Zero if everything went ok, nonzero otherwise. |
| 609 | */ |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 610 | int drm_fb_helper_init(struct drm_device *dev, |
| 611 | struct drm_fb_helper *fb_helper, |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 612 | int crtc_count, int max_conn_count) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 613 | { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 614 | struct drm_crtc *crtc; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 615 | int i; |
| 616 | |
Xiubo Li | 04cfe97 | 2014-03-10 09:33:58 +0800 | [diff] [blame] | 617 | if (!max_conn_count) |
| 618 | return -EINVAL; |
| 619 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 620 | fb_helper->crtc_info = kcalloc(crtc_count, sizeof(struct drm_fb_helper_crtc), GFP_KERNEL); |
| 621 | if (!fb_helper->crtc_info) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 622 | return -ENOMEM; |
| 623 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 624 | fb_helper->crtc_count = crtc_count; |
| 625 | fb_helper->connector_info = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_fb_helper_connector *), GFP_KERNEL); |
| 626 | if (!fb_helper->connector_info) { |
| 627 | kfree(fb_helper->crtc_info); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 628 | return -ENOMEM; |
| 629 | } |
Dave Airlie | 65c2a89 | 2014-06-05 14:01:30 +1000 | [diff] [blame] | 630 | fb_helper->connector_info_alloc_count = dev->mode_config.num_connector; |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 631 | fb_helper->connector_count = 0; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 632 | |
| 633 | for (i = 0; i < crtc_count; i++) { |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 634 | fb_helper->crtc_info[i].mode_set.connectors = |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 635 | kcalloc(max_conn_count, |
| 636 | sizeof(struct drm_connector *), |
| 637 | GFP_KERNEL); |
| 638 | |
Laurent Pinchart | 4a1b071 | 2012-05-17 13:27:21 +0200 | [diff] [blame] | 639 | if (!fb_helper->crtc_info[i].mode_set.connectors) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 640 | goto out_free; |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 641 | fb_helper->crtc_info[i].mode_set.num_connectors = 0; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | i = 0; |
Daniel Vetter | 6295d60 | 2015-07-09 23:44:25 +0200 | [diff] [blame] | 645 | drm_for_each_crtc(crtc, dev) { |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 646 | fb_helper->crtc_info[i].mode_set.crtc = crtc; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 647 | i++; |
| 648 | } |
Sascha Hauer | e9ad318 | 2012-02-01 11:38:25 +0100 | [diff] [blame] | 649 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 650 | return 0; |
| 651 | out_free: |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 652 | drm_fb_helper_crtc_free(fb_helper); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 653 | return -ENOMEM; |
| 654 | } |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 655 | EXPORT_SYMBOL(drm_fb_helper_init); |
| 656 | |
Archit Taneja | b8017d6 | 2015-07-22 14:57:56 +0530 | [diff] [blame] | 657 | /** |
| 658 | * drm_fb_helper_alloc_fbi - allocate fb_info and some of its members |
| 659 | * @fb_helper: driver-allocated fbdev helper |
| 660 | * |
| 661 | * A helper to alloc fb_info and the members cmap and apertures. Called |
| 662 | * by the driver within the fb_probe fb_helper callback function. |
| 663 | * |
| 664 | * RETURNS: |
| 665 | * fb_info pointer if things went okay, pointer containing error code |
| 666 | * otherwise |
| 667 | */ |
| 668 | struct fb_info *drm_fb_helper_alloc_fbi(struct drm_fb_helper *fb_helper) |
| 669 | { |
| 670 | struct device *dev = fb_helper->dev->dev; |
| 671 | struct fb_info *info; |
| 672 | int ret; |
| 673 | |
| 674 | info = framebuffer_alloc(0, dev); |
| 675 | if (!info) |
| 676 | return ERR_PTR(-ENOMEM); |
| 677 | |
| 678 | ret = fb_alloc_cmap(&info->cmap, 256, 0); |
| 679 | if (ret) |
| 680 | goto err_release; |
| 681 | |
| 682 | info->apertures = alloc_apertures(1); |
| 683 | if (!info->apertures) { |
| 684 | ret = -ENOMEM; |
| 685 | goto err_free_cmap; |
| 686 | } |
| 687 | |
| 688 | fb_helper->fbdev = info; |
| 689 | |
| 690 | return info; |
| 691 | |
| 692 | err_free_cmap: |
| 693 | fb_dealloc_cmap(&info->cmap); |
| 694 | err_release: |
| 695 | framebuffer_release(info); |
| 696 | return ERR_PTR(ret); |
| 697 | } |
| 698 | EXPORT_SYMBOL(drm_fb_helper_alloc_fbi); |
| 699 | |
| 700 | /** |
| 701 | * drm_fb_helper_unregister_fbi - unregister fb_info framebuffer device |
| 702 | * @fb_helper: driver-allocated fbdev helper |
| 703 | * |
| 704 | * A wrapper around unregister_framebuffer, to release the fb_info |
| 705 | * framebuffer device |
| 706 | */ |
| 707 | void drm_fb_helper_unregister_fbi(struct drm_fb_helper *fb_helper) |
| 708 | { |
| 709 | if (fb_helper && fb_helper->fbdev) |
| 710 | unregister_framebuffer(fb_helper->fbdev); |
| 711 | } |
| 712 | EXPORT_SYMBOL(drm_fb_helper_unregister_fbi); |
| 713 | |
| 714 | /** |
| 715 | * drm_fb_helper_release_fbi - dealloc fb_info and its members |
| 716 | * @fb_helper: driver-allocated fbdev helper |
| 717 | * |
| 718 | * A helper to free memory taken by fb_info and the members cmap and |
| 719 | * apertures |
| 720 | */ |
| 721 | void drm_fb_helper_release_fbi(struct drm_fb_helper *fb_helper) |
| 722 | { |
| 723 | if (fb_helper) { |
| 724 | struct fb_info *info = fb_helper->fbdev; |
| 725 | |
| 726 | if (info) { |
| 727 | if (info->cmap.len) |
| 728 | fb_dealloc_cmap(&info->cmap); |
| 729 | framebuffer_release(info); |
| 730 | } |
| 731 | |
| 732 | fb_helper->fbdev = NULL; |
| 733 | } |
| 734 | } |
| 735 | EXPORT_SYMBOL(drm_fb_helper_release_fbi); |
| 736 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 737 | void drm_fb_helper_fini(struct drm_fb_helper *fb_helper) |
| 738 | { |
| 739 | if (!list_empty(&fb_helper->kernel_fb_list)) { |
| 740 | list_del(&fb_helper->kernel_fb_list); |
| 741 | if (list_empty(&kernel_fb_helper_list)) { |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 742 | unregister_sysrq_key('v', &sysrq_drm_fb_helper_restore_op); |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | drm_fb_helper_crtc_free(fb_helper); |
| 747 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 748 | } |
| 749 | EXPORT_SYMBOL(drm_fb_helper_fini); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 750 | |
Archit Taneja | 47074ab | 2015-07-22 14:57:57 +0530 | [diff] [blame] | 751 | /** |
| 752 | * drm_fb_helper_unlink_fbi - wrapper around unlink_framebuffer |
| 753 | * @fb_helper: driver-allocated fbdev helper |
| 754 | * |
| 755 | * A wrapper around unlink_framebuffer implemented by fbdev core |
| 756 | */ |
| 757 | void drm_fb_helper_unlink_fbi(struct drm_fb_helper *fb_helper) |
| 758 | { |
| 759 | if (fb_helper && fb_helper->fbdev) |
| 760 | unlink_framebuffer(fb_helper->fbdev); |
| 761 | } |
| 762 | EXPORT_SYMBOL(drm_fb_helper_unlink_fbi); |
| 763 | |
Archit Taneja | cbb1a82 | 2015-07-31 16:21:41 +0530 | [diff] [blame] | 764 | /** |
| 765 | * drm_fb_helper_sys_read - wrapper around fb_sys_read |
| 766 | * @info: fb_info struct pointer |
| 767 | * @buf: userspace buffer to read from framebuffer memory |
| 768 | * @count: number of bytes to read from framebuffer memory |
| 769 | * @ppos: read offset within framebuffer memory |
| 770 | * |
| 771 | * A wrapper around fb_sys_read implemented by fbdev core |
| 772 | */ |
| 773 | ssize_t drm_fb_helper_sys_read(struct fb_info *info, char __user *buf, |
| 774 | size_t count, loff_t *ppos) |
| 775 | { |
| 776 | return fb_sys_read(info, buf, count, ppos); |
| 777 | } |
| 778 | EXPORT_SYMBOL(drm_fb_helper_sys_read); |
| 779 | |
| 780 | /** |
| 781 | * drm_fb_helper_sys_write - wrapper around fb_sys_write |
| 782 | * @info: fb_info struct pointer |
| 783 | * @buf: userspace buffer to write to framebuffer memory |
| 784 | * @count: number of bytes to write to framebuffer memory |
| 785 | * @ppos: write offset within framebuffer memory |
| 786 | * |
| 787 | * A wrapper around fb_sys_write implemented by fbdev core |
| 788 | */ |
| 789 | ssize_t drm_fb_helper_sys_write(struct fb_info *info, const char __user *buf, |
| 790 | size_t count, loff_t *ppos) |
| 791 | { |
| 792 | return fb_sys_write(info, buf, count, ppos); |
| 793 | } |
| 794 | EXPORT_SYMBOL(drm_fb_helper_sys_write); |
| 795 | |
Archit Taneja | 742547b | 2015-07-31 16:21:42 +0530 | [diff] [blame] | 796 | /** |
| 797 | * drm_fb_helper_sys_fillrect - wrapper around sys_fillrect |
| 798 | * @info: fbdev registered by the helper |
| 799 | * @rect: info about rectangle to fill |
| 800 | * |
| 801 | * A wrapper around sys_fillrect implemented by fbdev core |
| 802 | */ |
| 803 | void drm_fb_helper_sys_fillrect(struct fb_info *info, |
| 804 | const struct fb_fillrect *rect) |
| 805 | { |
| 806 | sys_fillrect(info, rect); |
| 807 | } |
| 808 | EXPORT_SYMBOL(drm_fb_helper_sys_fillrect); |
| 809 | |
| 810 | /** |
| 811 | * drm_fb_helper_sys_copyarea - wrapper around sys_copyarea |
| 812 | * @info: fbdev registered by the helper |
| 813 | * @area: info about area to copy |
| 814 | * |
| 815 | * A wrapper around sys_copyarea implemented by fbdev core |
| 816 | */ |
| 817 | void drm_fb_helper_sys_copyarea(struct fb_info *info, |
| 818 | const struct fb_copyarea *area) |
| 819 | { |
| 820 | sys_copyarea(info, area); |
| 821 | } |
| 822 | EXPORT_SYMBOL(drm_fb_helper_sys_copyarea); |
| 823 | |
| 824 | /** |
| 825 | * drm_fb_helper_sys_imageblit - wrapper around sys_imageblit |
| 826 | * @info: fbdev registered by the helper |
| 827 | * @image: info about image to blit |
| 828 | * |
| 829 | * A wrapper around sys_imageblit implemented by fbdev core |
| 830 | */ |
| 831 | void drm_fb_helper_sys_imageblit(struct fb_info *info, |
| 832 | const struct fb_image *image) |
| 833 | { |
| 834 | sys_imageblit(info, image); |
| 835 | } |
| 836 | EXPORT_SYMBOL(drm_fb_helper_sys_imageblit); |
| 837 | |
| 838 | /** |
| 839 | * drm_fb_helper_cfb_fillrect - wrapper around cfb_fillrect |
| 840 | * @info: fbdev registered by the helper |
| 841 | * @rect: info about rectangle to fill |
| 842 | * |
| 843 | * A wrapper around cfb_imageblit implemented by fbdev core |
| 844 | */ |
| 845 | void drm_fb_helper_cfb_fillrect(struct fb_info *info, |
| 846 | const struct fb_fillrect *rect) |
| 847 | { |
| 848 | cfb_fillrect(info, rect); |
| 849 | } |
| 850 | EXPORT_SYMBOL(drm_fb_helper_cfb_fillrect); |
| 851 | |
| 852 | /** |
| 853 | * drm_fb_helper_cfb_copyarea - wrapper around cfb_copyarea |
| 854 | * @info: fbdev registered by the helper |
| 855 | * @area: info about area to copy |
| 856 | * |
| 857 | * A wrapper around cfb_copyarea implemented by fbdev core |
| 858 | */ |
| 859 | void drm_fb_helper_cfb_copyarea(struct fb_info *info, |
| 860 | const struct fb_copyarea *area) |
| 861 | { |
| 862 | cfb_copyarea(info, area); |
| 863 | } |
| 864 | EXPORT_SYMBOL(drm_fb_helper_cfb_copyarea); |
| 865 | |
| 866 | /** |
| 867 | * drm_fb_helper_cfb_imageblit - wrapper around cfb_imageblit |
| 868 | * @info: fbdev registered by the helper |
| 869 | * @image: info about image to blit |
| 870 | * |
| 871 | * A wrapper around cfb_imageblit implemented by fbdev core |
| 872 | */ |
| 873 | void drm_fb_helper_cfb_imageblit(struct fb_info *info, |
| 874 | const struct fb_image *image) |
| 875 | { |
| 876 | cfb_imageblit(info, image); |
| 877 | } |
| 878 | EXPORT_SYMBOL(drm_fb_helper_cfb_imageblit); |
| 879 | |
Archit Taneja | fdefa58 | 2015-07-31 16:21:43 +0530 | [diff] [blame^] | 880 | /** |
| 881 | * drm_fb_helper_set_suspend - wrapper around fb_set_suspend |
| 882 | * @fb_helper: driver-allocated fbdev helper |
| 883 | * @state: desired state, zero to resume, non-zero to suspend |
| 884 | * |
| 885 | * A wrapper around fb_set_suspend implemented by fbdev core |
| 886 | */ |
| 887 | void drm_fb_helper_set_suspend(struct drm_fb_helper *fb_helper, int state) |
| 888 | { |
| 889 | if (fb_helper && fb_helper->fbdev) |
| 890 | fb_set_suspend(fb_helper->fbdev, state); |
| 891 | } |
| 892 | EXPORT_SYMBOL(drm_fb_helper_set_suspend); |
| 893 | |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 894 | static int setcolreg(struct drm_crtc *crtc, u16 red, u16 green, |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 895 | u16 blue, u16 regno, struct fb_info *info) |
| 896 | { |
| 897 | struct drm_fb_helper *fb_helper = info->par; |
| 898 | struct drm_framebuffer *fb = fb_helper->fb; |
| 899 | int pindex; |
| 900 | |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 901 | if (info->fix.visual == FB_VISUAL_TRUECOLOR) { |
| 902 | u32 *palette; |
| 903 | u32 value; |
| 904 | /* place color in psuedopalette */ |
| 905 | if (regno > 16) |
| 906 | return -EINVAL; |
| 907 | palette = (u32 *)info->pseudo_palette; |
| 908 | red >>= (16 - info->var.red.length); |
| 909 | green >>= (16 - info->var.green.length); |
| 910 | blue >>= (16 - info->var.blue.length); |
| 911 | value = (red << info->var.red.offset) | |
| 912 | (green << info->var.green.offset) | |
| 913 | (blue << info->var.blue.offset); |
Rob Clark | 9da12b6a | 2011-02-16 02:45:51 +0000 | [diff] [blame] | 914 | if (info->var.transp.length > 0) { |
| 915 | u32 mask = (1 << info->var.transp.length) - 1; |
| 916 | mask <<= info->var.transp.offset; |
| 917 | value |= mask; |
| 918 | } |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 919 | palette[regno] = value; |
| 920 | return 0; |
| 921 | } |
| 922 | |
Ville Syrjälä | 04c0c56 | 2013-05-27 20:19:57 +0300 | [diff] [blame] | 923 | /* |
| 924 | * The driver really shouldn't advertise pseudo/directcolor |
| 925 | * visuals if it can't deal with the palette. |
| 926 | */ |
| 927 | if (WARN_ON(!fb_helper->funcs->gamma_set || |
| 928 | !fb_helper->funcs->gamma_get)) |
| 929 | return -EINVAL; |
| 930 | |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 931 | pindex = regno; |
| 932 | |
| 933 | if (fb->bits_per_pixel == 16) { |
| 934 | pindex = regno << 3; |
| 935 | |
| 936 | if (fb->depth == 16 && regno > 63) |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 937 | return -EINVAL; |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 938 | if (fb->depth == 15 && regno > 31) |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 939 | return -EINVAL; |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 940 | |
| 941 | if (fb->depth == 16) { |
| 942 | u16 r, g, b; |
| 943 | int i; |
| 944 | if (regno < 32) { |
| 945 | for (i = 0; i < 8; i++) |
| 946 | fb_helper->funcs->gamma_set(crtc, red, |
| 947 | green, blue, pindex + i); |
| 948 | } |
| 949 | |
| 950 | fb_helper->funcs->gamma_get(crtc, &r, |
| 951 | &g, &b, |
| 952 | pindex >> 1); |
| 953 | |
| 954 | for (i = 0; i < 4; i++) |
| 955 | fb_helper->funcs->gamma_set(crtc, r, |
| 956 | green, b, |
| 957 | (pindex >> 1) + i); |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | if (fb->depth != 16) |
| 962 | fb_helper->funcs->gamma_set(crtc, red, green, blue, pindex); |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 963 | return 0; |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 964 | } |
| 965 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 966 | /** |
| 967 | * drm_fb_helper_setcmap - implementation for ->fb_setcmap |
| 968 | * @cmap: cmap to set |
| 969 | * @info: fbdev registered by the helper |
| 970 | */ |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 971 | int drm_fb_helper_setcmap(struct fb_cmap *cmap, struct fb_info *info) |
| 972 | { |
| 973 | struct drm_fb_helper *fb_helper = info->par; |
Ville Syrjälä | 8391a3d | 2013-05-27 20:19:56 +0300 | [diff] [blame] | 974 | struct drm_device *dev = fb_helper->dev; |
Jani Nikula | be26a66 | 2015-03-11 11:51:06 +0200 | [diff] [blame] | 975 | const struct drm_crtc_helper_funcs *crtc_funcs; |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 976 | u16 *red, *green, *blue, *transp; |
| 977 | struct drm_crtc *crtc; |
roel | 062ac62 | 2011-03-07 18:00:34 +0100 | [diff] [blame] | 978 | int i, j, rc = 0; |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 979 | int start; |
| 980 | |
Rui Wang | 9aa609e | 2014-12-15 11:28:26 -0800 | [diff] [blame] | 981 | if (__drm_modeset_lock_all(dev, !!oops_in_progress)) { |
| 982 | return -EBUSY; |
| 983 | } |
Ville Syrjälä | 8391a3d | 2013-05-27 20:19:56 +0300 | [diff] [blame] | 984 | if (!drm_fb_helper_is_bound(fb_helper)) { |
| 985 | drm_modeset_unlock_all(dev); |
| 986 | return -EBUSY; |
| 987 | } |
| 988 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 989 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 990 | crtc = fb_helper->crtc_info[i].mode_set.crtc; |
| 991 | crtc_funcs = crtc->helper_private; |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 992 | |
| 993 | red = cmap->red; |
| 994 | green = cmap->green; |
| 995 | blue = cmap->blue; |
| 996 | transp = cmap->transp; |
| 997 | start = cmap->start; |
| 998 | |
roel | 062ac62 | 2011-03-07 18:00:34 +0100 | [diff] [blame] | 999 | for (j = 0; j < cmap->len; j++) { |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 1000 | u16 hred, hgreen, hblue, htransp = 0xffff; |
| 1001 | |
| 1002 | hred = *red++; |
| 1003 | hgreen = *green++; |
| 1004 | hblue = *blue++; |
| 1005 | |
| 1006 | if (transp) |
| 1007 | htransp = *transp++; |
| 1008 | |
Dave Airlie | c850cb7 | 2009-10-23 18:49:03 +1000 | [diff] [blame] | 1009 | rc = setcolreg(crtc, hred, hgreen, hblue, start++, info); |
| 1010 | if (rc) |
Ville Syrjälä | 8391a3d | 2013-05-27 20:19:56 +0300 | [diff] [blame] | 1011 | goto out; |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 1012 | } |
Ville Syrjälä | 04c0c56 | 2013-05-27 20:19:57 +0300 | [diff] [blame] | 1013 | if (crtc_funcs->load_lut) |
| 1014 | crtc_funcs->load_lut(crtc); |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 1015 | } |
Ville Syrjälä | 8391a3d | 2013-05-27 20:19:56 +0300 | [diff] [blame] | 1016 | out: |
| 1017 | drm_modeset_unlock_all(dev); |
Dave Airlie | 068143d | 2009-10-05 09:58:02 +1000 | [diff] [blame] | 1018 | return rc; |
| 1019 | } |
| 1020 | EXPORT_SYMBOL(drm_fb_helper_setcmap); |
| 1021 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1022 | /** |
| 1023 | * drm_fb_helper_check_var - implementation for ->fb_check_var |
| 1024 | * @var: screeninfo to check |
| 1025 | * @info: fbdev registered by the helper |
| 1026 | */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1027 | int drm_fb_helper_check_var(struct fb_var_screeninfo *var, |
| 1028 | struct fb_info *info) |
| 1029 | { |
| 1030 | struct drm_fb_helper *fb_helper = info->par; |
| 1031 | struct drm_framebuffer *fb = fb_helper->fb; |
| 1032 | int depth; |
| 1033 | |
Jason Wessel | f90ebd9 | 2010-08-05 09:22:32 -0500 | [diff] [blame] | 1034 | if (var->pixclock != 0 || in_dbg_master()) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1035 | return -EINVAL; |
| 1036 | |
| 1037 | /* Need to resize the fb object !!! */ |
Chris Wilson | 62fb376 | 2012-03-26 21:15:53 +0100 | [diff] [blame] | 1038 | if (var->bits_per_pixel > fb->bits_per_pixel || |
| 1039 | var->xres > fb->width || var->yres > fb->height || |
| 1040 | var->xres_virtual > fb->width || var->yres_virtual > fb->height) { |
Dave Airlie | 509c7d8 | 2010-01-08 09:27:08 +1000 | [diff] [blame] | 1041 | DRM_DEBUG("fb userspace requested width/height/bpp is greater than current fb " |
Chris Wilson | 62fb376 | 2012-03-26 21:15:53 +0100 | [diff] [blame] | 1042 | "request %dx%d-%d (virtual %dx%d) > %dx%d-%d\n", |
| 1043 | var->xres, var->yres, var->bits_per_pixel, |
| 1044 | var->xres_virtual, var->yres_virtual, |
Dave Airlie | 509c7d8 | 2010-01-08 09:27:08 +1000 | [diff] [blame] | 1045 | fb->width, fb->height, fb->bits_per_pixel); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1046 | return -EINVAL; |
| 1047 | } |
| 1048 | |
| 1049 | switch (var->bits_per_pixel) { |
| 1050 | case 16: |
| 1051 | depth = (var->green.length == 6) ? 16 : 15; |
| 1052 | break; |
| 1053 | case 32: |
| 1054 | depth = (var->transp.length > 0) ? 32 : 24; |
| 1055 | break; |
| 1056 | default: |
| 1057 | depth = var->bits_per_pixel; |
| 1058 | break; |
| 1059 | } |
| 1060 | |
| 1061 | switch (depth) { |
| 1062 | case 8: |
| 1063 | var->red.offset = 0; |
| 1064 | var->green.offset = 0; |
| 1065 | var->blue.offset = 0; |
| 1066 | var->red.length = 8; |
| 1067 | var->green.length = 8; |
| 1068 | var->blue.length = 8; |
| 1069 | var->transp.length = 0; |
| 1070 | var->transp.offset = 0; |
| 1071 | break; |
| 1072 | case 15: |
| 1073 | var->red.offset = 10; |
| 1074 | var->green.offset = 5; |
| 1075 | var->blue.offset = 0; |
| 1076 | var->red.length = 5; |
| 1077 | var->green.length = 5; |
| 1078 | var->blue.length = 5; |
| 1079 | var->transp.length = 1; |
| 1080 | var->transp.offset = 15; |
| 1081 | break; |
| 1082 | case 16: |
| 1083 | var->red.offset = 11; |
| 1084 | var->green.offset = 5; |
| 1085 | var->blue.offset = 0; |
| 1086 | var->red.length = 5; |
| 1087 | var->green.length = 6; |
| 1088 | var->blue.length = 5; |
| 1089 | var->transp.length = 0; |
| 1090 | var->transp.offset = 0; |
| 1091 | break; |
| 1092 | case 24: |
| 1093 | var->red.offset = 16; |
| 1094 | var->green.offset = 8; |
| 1095 | var->blue.offset = 0; |
| 1096 | var->red.length = 8; |
| 1097 | var->green.length = 8; |
| 1098 | var->blue.length = 8; |
| 1099 | var->transp.length = 0; |
| 1100 | var->transp.offset = 0; |
| 1101 | break; |
| 1102 | case 32: |
| 1103 | var->red.offset = 16; |
| 1104 | var->green.offset = 8; |
| 1105 | var->blue.offset = 0; |
| 1106 | var->red.length = 8; |
| 1107 | var->green.length = 8; |
| 1108 | var->blue.length = 8; |
| 1109 | var->transp.length = 8; |
| 1110 | var->transp.offset = 24; |
| 1111 | break; |
| 1112 | default: |
| 1113 | return -EINVAL; |
| 1114 | } |
| 1115 | return 0; |
| 1116 | } |
| 1117 | EXPORT_SYMBOL(drm_fb_helper_check_var); |
| 1118 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1119 | /** |
| 1120 | * drm_fb_helper_set_par - implementation for ->fb_set_par |
| 1121 | * @info: fbdev registered by the helper |
| 1122 | * |
| 1123 | * This will let fbcon do the mode init and is called at initialization time by |
| 1124 | * the fbdev core when registering the driver, and later on through the hotplug |
| 1125 | * callback. |
| 1126 | */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1127 | int drm_fb_helper_set_par(struct fb_info *info) |
| 1128 | { |
| 1129 | struct drm_fb_helper *fb_helper = info->par; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1130 | struct fb_var_screeninfo *var = &info->var; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1131 | |
Clemens Ladisch | 5349ef3 | 2009-11-04 09:42:52 +0100 | [diff] [blame] | 1132 | if (var->pixclock != 0) { |
Pavel Roskin | 172e91f | 2010-02-11 14:31:32 +1000 | [diff] [blame] | 1133 | DRM_ERROR("PIXEL CLOCK SET\n"); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1134 | return -EINVAL; |
| 1135 | } |
| 1136 | |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 1137 | drm_fb_helper_restore_fbdev_mode_unlocked(fb_helper); |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 1138 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1139 | return 0; |
| 1140 | } |
| 1141 | EXPORT_SYMBOL(drm_fb_helper_set_par); |
| 1142 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1143 | /** |
| 1144 | * drm_fb_helper_pan_display - implementation for ->fb_pan_display |
| 1145 | * @var: updated screen information |
| 1146 | * @info: fbdev registered by the helper |
| 1147 | */ |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1148 | int drm_fb_helper_pan_display(struct fb_var_screeninfo *var, |
| 1149 | struct fb_info *info) |
| 1150 | { |
| 1151 | struct drm_fb_helper *fb_helper = info->par; |
| 1152 | struct drm_device *dev = fb_helper->dev; |
| 1153 | struct drm_mode_set *modeset; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1154 | int ret = 0; |
| 1155 | int i; |
| 1156 | |
Rui Wang | 9aa609e | 2014-12-15 11:28:26 -0800 | [diff] [blame] | 1157 | if (__drm_modeset_lock_all(dev, !!oops_in_progress)) { |
| 1158 | return -EBUSY; |
| 1159 | } |
Daniel Vetter | 20c60c3 | 2012-12-17 12:13:23 +0100 | [diff] [blame] | 1160 | if (!drm_fb_helper_is_bound(fb_helper)) { |
| 1161 | drm_modeset_unlock_all(dev); |
| 1162 | return -EBUSY; |
| 1163 | } |
| 1164 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1165 | for (i = 0; i < fb_helper->crtc_count; i++) { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1166 | modeset = &fb_helper->crtc_info[i].mode_set; |
| 1167 | |
| 1168 | modeset->x = var->xoffset; |
| 1169 | modeset->y = var->yoffset; |
| 1170 | |
| 1171 | if (modeset->num_connectors) { |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 1172 | ret = drm_mode_set_config_internal(modeset); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1173 | if (!ret) { |
| 1174 | info->var.xoffset = var->xoffset; |
| 1175 | info->var.yoffset = var->yoffset; |
| 1176 | } |
| 1177 | } |
| 1178 | } |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1179 | drm_modeset_unlock_all(dev); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1180 | return ret; |
| 1181 | } |
| 1182 | EXPORT_SYMBOL(drm_fb_helper_pan_display); |
| 1183 | |
Daniel Vetter | 8acf658 | 2013-01-21 23:38:37 +0100 | [diff] [blame] | 1184 | /* |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1185 | * Allocates the backing storage and sets up the fbdev info structure through |
| 1186 | * the ->fb_probe callback and then registers the fbdev and sets up the panic |
| 1187 | * notifier. |
Daniel Vetter | 8acf658 | 2013-01-21 23:38:37 +0100 | [diff] [blame] | 1188 | */ |
Daniel Vetter | de1ace5 | 2013-01-20 21:50:49 +0100 | [diff] [blame] | 1189 | static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper, |
| 1190 | int preferred_bpp) |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1191 | { |
Daniel Vetter | 8acf658 | 2013-01-21 23:38:37 +0100 | [diff] [blame] | 1192 | int ret = 0; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1193 | int crtc_count = 0; |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 1194 | int i; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1195 | struct fb_info *info; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1196 | struct drm_fb_helper_surface_size sizes; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1197 | int gamma_size = 0; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1198 | |
| 1199 | memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size)); |
| 1200 | sizes.surface_depth = 24; |
| 1201 | sizes.surface_bpp = 32; |
| 1202 | sizes.fb_width = (unsigned)-1; |
| 1203 | sizes.fb_height = (unsigned)-1; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1204 | |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 1205 | /* if driver picks 8 or 16 by default use that |
| 1206 | for both depth/bpp */ |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1207 | if (preferred_bpp != sizes.surface_bpp) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1208 | sizes.surface_depth = sizes.surface_bpp = preferred_bpp; |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1209 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1210 | /* first up get a count of crtcs now in use and new min/maxes width/heights */ |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1211 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1212 | 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] | 1213 | struct drm_cmdline_mode *cmdline_mode; |
Dave Airlie | 8ef8678 | 2009-09-26 06:39:00 +1000 | [diff] [blame] | 1214 | |
Chris Wilson | eaf99c7 | 2014-08-06 10:08:32 +0200 | [diff] [blame] | 1215 | cmdline_mode = &fb_helper_conn->connector->cmdline_mode; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 1216 | |
| 1217 | if (cmdline_mode->bpp_specified) { |
| 1218 | switch (cmdline_mode->bpp) { |
| 1219 | case 8: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1220 | sizes.surface_depth = sizes.surface_bpp = 8; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 1221 | break; |
| 1222 | case 15: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1223 | sizes.surface_depth = 15; |
| 1224 | sizes.surface_bpp = 16; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 1225 | break; |
| 1226 | case 16: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1227 | sizes.surface_depth = sizes.surface_bpp = 16; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 1228 | break; |
| 1229 | case 24: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1230 | sizes.surface_depth = sizes.surface_bpp = 24; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 1231 | break; |
| 1232 | case 32: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1233 | sizes.surface_depth = 24; |
| 1234 | sizes.surface_bpp = 32; |
Dave Airlie | d50ba25 | 2009-09-23 14:44:08 +1000 | [diff] [blame] | 1235 | break; |
| 1236 | } |
| 1237 | break; |
| 1238 | } |
| 1239 | } |
| 1240 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1241 | crtc_count = 0; |
| 1242 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 1243 | struct drm_display_mode *desired_mode; |
Rob Clark | 0e3704c | 2015-03-11 10:23:14 -0400 | [diff] [blame] | 1244 | struct drm_mode_set *mode_set; |
| 1245 | int x, y, j; |
| 1246 | /* in case of tile group, are we the last tile vert or horiz? |
| 1247 | * If no tile group you are always the last one both vertically |
| 1248 | * and horizontally |
| 1249 | */ |
| 1250 | bool lastv = true, lasth = true; |
Rob Clark | 675c832 | 2015-03-11 10:23:13 -0400 | [diff] [blame] | 1251 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1252 | desired_mode = fb_helper->crtc_info[i].desired_mode; |
Rob Clark | 0e3704c | 2015-03-11 10:23:14 -0400 | [diff] [blame] | 1253 | mode_set = &fb_helper->crtc_info[i].mode_set; |
Rob Clark | 675c832 | 2015-03-11 10:23:13 -0400 | [diff] [blame] | 1254 | |
| 1255 | if (!desired_mode) |
| 1256 | continue; |
| 1257 | |
| 1258 | crtc_count++; |
| 1259 | |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1260 | x = fb_helper->crtc_info[i].x; |
| 1261 | y = fb_helper->crtc_info[i].y; |
Rob Clark | 675c832 | 2015-03-11 10:23:13 -0400 | [diff] [blame] | 1262 | |
| 1263 | if (gamma_size == 0) |
| 1264 | gamma_size = fb_helper->crtc_info[i].mode_set.crtc->gamma_size; |
| 1265 | |
| 1266 | sizes.surface_width = max_t(u32, desired_mode->hdisplay + x, sizes.surface_width); |
| 1267 | 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] | 1268 | |
| 1269 | for (j = 0; j < mode_set->num_connectors; j++) { |
| 1270 | struct drm_connector *connector = mode_set->connectors[j]; |
| 1271 | if (connector->has_tile) { |
| 1272 | lasth = (connector->tile_h_loc == (connector->num_h_tile - 1)); |
| 1273 | lastv = (connector->tile_v_loc == (connector->num_v_tile - 1)); |
| 1274 | /* cloning to multiple tiles is just crazy-talk, so: */ |
| 1275 | break; |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | if (lasth) |
| 1280 | sizes.fb_width = min_t(u32, desired_mode->hdisplay + x, sizes.fb_width); |
| 1281 | if (lastv) |
| 1282 | 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] | 1283 | } |
| 1284 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1285 | if (crtc_count == 0 || sizes.fb_width == -1 || sizes.fb_height == -1) { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1286 | /* hmm everyone went away - assume VGA cable just fell out |
| 1287 | and will come back later. */ |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1288 | DRM_INFO("Cannot find any crtc or sizes - going 1024x768\n"); |
Dave Airlie | 19b4b44 | 2010-03-30 05:34:16 +0000 | [diff] [blame] | 1289 | sizes.fb_width = sizes.surface_width = 1024; |
| 1290 | sizes.fb_height = sizes.surface_height = 768; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1291 | } |
| 1292 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1293 | /* push down into drivers */ |
Daniel Vetter | 8acf658 | 2013-01-21 23:38:37 +0100 | [diff] [blame] | 1294 | ret = (*fb_helper->funcs->fb_probe)(fb_helper, &sizes); |
| 1295 | if (ret < 0) |
| 1296 | return ret; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1297 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1298 | info = fb_helper->fbdev; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1299 | |
Daniel Vetter | 7e53f3a | 2013-01-21 10:52:17 +0100 | [diff] [blame] | 1300 | /* |
| 1301 | * Set the fb pointer - usually drm_setup_crtcs does this for hotplug |
| 1302 | * events, but at init time drm_setup_crtcs needs to be called before |
| 1303 | * the fb is allocated (since we need to figure out the desired size of |
| 1304 | * the fb before we can allocate it ...). Hence we need to fix things up |
| 1305 | * here again. |
| 1306 | */ |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1307 | for (i = 0; i < fb_helper->crtc_count; i++) |
Daniel Vetter | 7e53f3a | 2013-01-21 10:52:17 +0100 | [diff] [blame] | 1308 | if (fb_helper->crtc_info[i].mode_set.num_connectors) |
| 1309 | fb_helper->crtc_info[i].mode_set.fb = fb_helper->fb; |
| 1310 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1311 | |
Daniel Vetter | 8acf658 | 2013-01-21 23:38:37 +0100 | [diff] [blame] | 1312 | info->var.pixclock = 0; |
| 1313 | if (register_framebuffer(info) < 0) |
| 1314 | return -EINVAL; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1315 | |
Daniel Vetter | 8acf658 | 2013-01-21 23:38:37 +0100 | [diff] [blame] | 1316 | dev_info(fb_helper->dev->dev, "fb%d: %s frame buffer device\n", |
| 1317 | info->node, info->fix.id); |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1318 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1319 | if (list_empty(&kernel_fb_helper_list)) { |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1320 | register_sysrq_key('v', &sysrq_drm_fb_helper_restore_op); |
| 1321 | } |
Daniel Vetter | 8acf658 | 2013-01-21 23:38:37 +0100 | [diff] [blame] | 1322 | |
| 1323 | list_add(&fb_helper->kernel_fb_list, &kernel_fb_helper_list); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1324 | |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1325 | return 0; |
| 1326 | } |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1327 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1328 | /** |
| 1329 | * drm_fb_helper_fill_fix - initializes fixed fbdev information |
| 1330 | * @info: fbdev registered by the helper |
| 1331 | * @pitch: desired pitch |
| 1332 | * @depth: desired depth |
| 1333 | * |
| 1334 | * Helper to fill in the fixed fbdev information useful for a non-accelerated |
| 1335 | * fbdev emulations. Drivers which support acceleration methods which impose |
| 1336 | * additional constraints need to set up their own limits. |
| 1337 | * |
| 1338 | * Drivers should call this (or their equivalent setup code) from their |
| 1339 | * ->fb_probe callback. |
| 1340 | */ |
Dave Airlie | 3632ef8 | 2011-01-15 09:27:00 +1000 | [diff] [blame] | 1341 | void drm_fb_helper_fill_fix(struct fb_info *info, uint32_t pitch, |
| 1342 | uint32_t depth) |
| 1343 | { |
| 1344 | info->fix.type = FB_TYPE_PACKED_PIXELS; |
| 1345 | info->fix.visual = depth == 8 ? FB_VISUAL_PSEUDOCOLOR : |
| 1346 | FB_VISUAL_TRUECOLOR; |
| 1347 | info->fix.mmio_start = 0; |
| 1348 | info->fix.mmio_len = 0; |
| 1349 | info->fix.type_aux = 0; |
| 1350 | info->fix.xpanstep = 1; /* doing it in hw */ |
| 1351 | info->fix.ypanstep = 1; /* doing it in hw */ |
| 1352 | info->fix.ywrapstep = 0; |
| 1353 | info->fix.accel = FB_ACCEL_NONE; |
Dave Airlie | 3632ef8 | 2011-01-15 09:27:00 +1000 | [diff] [blame] | 1354 | |
| 1355 | info->fix.line_length = pitch; |
| 1356 | return; |
| 1357 | } |
| 1358 | EXPORT_SYMBOL(drm_fb_helper_fill_fix); |
| 1359 | |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1360 | /** |
| 1361 | * drm_fb_helper_fill_var - initalizes variable fbdev information |
| 1362 | * @info: fbdev instance to set up |
| 1363 | * @fb_helper: fb helper instance to use as template |
| 1364 | * @fb_width: desired fb width |
| 1365 | * @fb_height: desired fb height |
| 1366 | * |
| 1367 | * Sets up the variable fbdev metainformation from the given fb helper instance |
| 1368 | * and the drm framebuffer allocated in fb_helper->fb. |
| 1369 | * |
| 1370 | * Drivers should call this (or their equivalent setup code) from their |
| 1371 | * ->fb_probe callback after having allocated the fbdev backing |
| 1372 | * storage framebuffer. |
| 1373 | */ |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1374 | 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] | 1375 | uint32_t fb_width, uint32_t fb_height) |
| 1376 | { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1377 | struct drm_framebuffer *fb = fb_helper->fb; |
| 1378 | info->pseudo_palette = fb_helper->pseudo_palette; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1379 | info->var.xres_virtual = fb->width; |
| 1380 | info->var.yres_virtual = fb->height; |
| 1381 | info->var.bits_per_pixel = fb->bits_per_pixel; |
James Simmons | 57084d0 | 2010-12-20 19:10:39 +0000 | [diff] [blame] | 1382 | info->var.accel_flags = FB_ACCELF_TEXT; |
Dave Airlie | 785b93e | 2009-08-28 15:46:53 +1000 | [diff] [blame] | 1383 | info->var.xoffset = 0; |
| 1384 | info->var.yoffset = 0; |
| 1385 | info->var.activate = FB_ACTIVATE_NOW; |
| 1386 | info->var.height = -1; |
| 1387 | info->var.width = -1; |
| 1388 | |
| 1389 | switch (fb->depth) { |
| 1390 | case 8: |
| 1391 | info->var.red.offset = 0; |
| 1392 | info->var.green.offset = 0; |
| 1393 | info->var.blue.offset = 0; |
| 1394 | info->var.red.length = 8; /* 8bit DAC */ |
| 1395 | info->var.green.length = 8; |
| 1396 | info->var.blue.length = 8; |
| 1397 | info->var.transp.offset = 0; |
| 1398 | info->var.transp.length = 0; |
| 1399 | break; |
| 1400 | case 15: |
| 1401 | info->var.red.offset = 10; |
| 1402 | info->var.green.offset = 5; |
| 1403 | info->var.blue.offset = 0; |
| 1404 | info->var.red.length = 5; |
| 1405 | info->var.green.length = 5; |
| 1406 | info->var.blue.length = 5; |
| 1407 | info->var.transp.offset = 15; |
| 1408 | info->var.transp.length = 1; |
| 1409 | break; |
| 1410 | case 16: |
| 1411 | info->var.red.offset = 11; |
| 1412 | info->var.green.offset = 5; |
| 1413 | info->var.blue.offset = 0; |
| 1414 | info->var.red.length = 5; |
| 1415 | info->var.green.length = 6; |
| 1416 | info->var.blue.length = 5; |
| 1417 | info->var.transp.offset = 0; |
| 1418 | break; |
| 1419 | case 24: |
| 1420 | info->var.red.offset = 16; |
| 1421 | info->var.green.offset = 8; |
| 1422 | info->var.blue.offset = 0; |
| 1423 | info->var.red.length = 8; |
| 1424 | info->var.green.length = 8; |
| 1425 | info->var.blue.length = 8; |
| 1426 | info->var.transp.offset = 0; |
| 1427 | info->var.transp.length = 0; |
| 1428 | break; |
| 1429 | case 32: |
| 1430 | info->var.red.offset = 16; |
| 1431 | info->var.green.offset = 8; |
| 1432 | info->var.blue.offset = 0; |
| 1433 | info->var.red.length = 8; |
| 1434 | info->var.green.length = 8; |
| 1435 | info->var.blue.length = 8; |
| 1436 | info->var.transp.offset = 24; |
| 1437 | info->var.transp.length = 8; |
| 1438 | break; |
| 1439 | default: |
| 1440 | break; |
| 1441 | } |
| 1442 | |
| 1443 | info->var.xres = fb_width; |
| 1444 | info->var.yres = fb_height; |
| 1445 | } |
| 1446 | EXPORT_SYMBOL(drm_fb_helper_fill_var); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1447 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1448 | static int drm_fb_helper_probe_connector_modes(struct drm_fb_helper *fb_helper, |
| 1449 | uint32_t maxX, |
| 1450 | uint32_t maxY) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1451 | { |
| 1452 | struct drm_connector *connector; |
| 1453 | int count = 0; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1454 | int i; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1455 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1456 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1457 | connector = fb_helper->connector_info[i]->connector; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1458 | count += connector->funcs->fill_modes(connector, maxX, maxY); |
| 1459 | } |
| 1460 | |
| 1461 | return count; |
| 1462 | } |
| 1463 | |
Jesse Barnes | 2f1046f | 2014-02-12 12:26:24 -0800 | [diff] [blame] | 1464 | 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] | 1465 | { |
| 1466 | struct drm_display_mode *mode; |
| 1467 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1468 | list_for_each_entry(mode, &fb_connector->connector->modes, head) { |
Daniel Vetter | 9d3de13 | 2014-01-23 16:27:56 +0100 | [diff] [blame] | 1469 | if (mode->hdisplay > width || |
| 1470 | mode->vdisplay > height) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1471 | continue; |
| 1472 | if (mode->type & DRM_MODE_TYPE_PREFERRED) |
| 1473 | return mode; |
| 1474 | } |
| 1475 | return NULL; |
| 1476 | } |
Jesse Barnes | 2f1046f | 2014-02-12 12:26:24 -0800 | [diff] [blame] | 1477 | EXPORT_SYMBOL(drm_has_preferred_mode); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1478 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1479 | 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] | 1480 | { |
Chris Wilson | eaf99c7 | 2014-08-06 10:08:32 +0200 | [diff] [blame] | 1481 | return fb_connector->connector->cmdline_mode.specified; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
Jesse Barnes | 2f1046f | 2014-02-12 12:26:24 -0800 | [diff] [blame] | 1484 | struct drm_display_mode *drm_pick_cmdline_mode(struct drm_fb_helper_connector *fb_helper_conn, |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1485 | int width, int height) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1486 | { |
Chris Wilson | 1794d25 | 2011-04-17 07:43:32 +0100 | [diff] [blame] | 1487 | struct drm_cmdline_mode *cmdline_mode; |
Daniel Stone | f3af5c7 | 2015-03-19 04:33:01 +0000 | [diff] [blame] | 1488 | struct drm_display_mode *mode; |
Takashi Iwai | c683f42 | 2014-03-19 14:53:13 +0100 | [diff] [blame] | 1489 | bool prefer_non_interlace; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1490 | |
Chris Wilson | eaf99c7 | 2014-08-06 10:08:32 +0200 | [diff] [blame] | 1491 | cmdline_mode = &fb_helper_conn->connector->cmdline_mode; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1492 | if (cmdline_mode->specified == false) |
Daniel Stone | f3af5c7 | 2015-03-19 04:33:01 +0000 | [diff] [blame] | 1493 | return NULL; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1494 | |
| 1495 | /* attempt to find a matching mode in the list of modes |
| 1496 | * we have gotten so far, if not add a CVT mode that conforms |
| 1497 | */ |
| 1498 | if (cmdline_mode->rb || cmdline_mode->margins) |
| 1499 | goto create_mode; |
| 1500 | |
Takashi Iwai | c683f42 | 2014-03-19 14:53:13 +0100 | [diff] [blame] | 1501 | prefer_non_interlace = !cmdline_mode->interlace; |
Daniel Stone | f3af5c7 | 2015-03-19 04:33:01 +0000 | [diff] [blame] | 1502 | again: |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1503 | list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1504 | /* check width/height */ |
| 1505 | if (mode->hdisplay != cmdline_mode->xres || |
| 1506 | mode->vdisplay != cmdline_mode->yres) |
| 1507 | continue; |
| 1508 | |
| 1509 | if (cmdline_mode->refresh_specified) { |
| 1510 | if (mode->vrefresh != cmdline_mode->refresh) |
| 1511 | continue; |
| 1512 | } |
| 1513 | |
| 1514 | if (cmdline_mode->interlace) { |
| 1515 | if (!(mode->flags & DRM_MODE_FLAG_INTERLACE)) |
| 1516 | continue; |
Takashi Iwai | c683f42 | 2014-03-19 14:53:13 +0100 | [diff] [blame] | 1517 | } else if (prefer_non_interlace) { |
| 1518 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 1519 | continue; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1520 | } |
| 1521 | return mode; |
| 1522 | } |
| 1523 | |
Takashi Iwai | c683f42 | 2014-03-19 14:53:13 +0100 | [diff] [blame] | 1524 | if (prefer_non_interlace) { |
| 1525 | prefer_non_interlace = false; |
| 1526 | goto again; |
| 1527 | } |
| 1528 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1529 | create_mode: |
Chris Wilson | 1794d25 | 2011-04-17 07:43:32 +0100 | [diff] [blame] | 1530 | mode = drm_mode_create_from_cmdline_mode(fb_helper_conn->connector->dev, |
| 1531 | cmdline_mode); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1532 | list_add(&mode->head, &fb_helper_conn->connector->modes); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1533 | return mode; |
| 1534 | } |
Jesse Barnes | 2f1046f | 2014-02-12 12:26:24 -0800 | [diff] [blame] | 1535 | EXPORT_SYMBOL(drm_pick_cmdline_mode); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1536 | |
| 1537 | static bool drm_connector_enabled(struct drm_connector *connector, bool strict) |
| 1538 | { |
| 1539 | bool enable; |
| 1540 | |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1541 | if (strict) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1542 | enable = connector->status == connector_status_connected; |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1543 | else |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1544 | enable = connector->status != connector_status_disconnected; |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1545 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1546 | return enable; |
| 1547 | } |
| 1548 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1549 | static void drm_enable_connectors(struct drm_fb_helper *fb_helper, |
| 1550 | bool *enabled) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1551 | { |
| 1552 | bool any_enabled = false; |
| 1553 | struct drm_connector *connector; |
| 1554 | int i = 0; |
| 1555 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1556 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1557 | connector = fb_helper->connector_info[i]->connector; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1558 | enabled[i] = drm_connector_enabled(connector, true); |
| 1559 | DRM_DEBUG_KMS("connector %d enabled? %s\n", connector->base.id, |
| 1560 | enabled[i] ? "yes" : "no"); |
| 1561 | any_enabled |= enabled[i]; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1562 | } |
| 1563 | |
| 1564 | if (any_enabled) |
| 1565 | return; |
| 1566 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1567 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1568 | connector = fb_helper->connector_info[i]->connector; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1569 | enabled[i] = drm_connector_enabled(connector, false); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1570 | } |
| 1571 | } |
| 1572 | |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1573 | static bool drm_target_cloned(struct drm_fb_helper *fb_helper, |
| 1574 | struct drm_display_mode **modes, |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1575 | struct drm_fb_offset *offsets, |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1576 | bool *enabled, int width, int height) |
| 1577 | { |
| 1578 | int count, i, j; |
| 1579 | bool can_clone = false; |
| 1580 | struct drm_fb_helper_connector *fb_helper_conn; |
| 1581 | struct drm_display_mode *dmt_mode, *mode; |
| 1582 | |
| 1583 | /* only contemplate cloning in the single crtc case */ |
| 1584 | if (fb_helper->crtc_count > 1) |
| 1585 | return false; |
| 1586 | |
| 1587 | count = 0; |
| 1588 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1589 | if (enabled[i]) |
| 1590 | count++; |
| 1591 | } |
| 1592 | |
| 1593 | /* only contemplate cloning if more than one connector is enabled */ |
| 1594 | if (count <= 1) |
| 1595 | return false; |
| 1596 | |
| 1597 | /* check the command line or if nothing common pick 1024x768 */ |
| 1598 | can_clone = true; |
| 1599 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1600 | if (!enabled[i]) |
| 1601 | continue; |
| 1602 | fb_helper_conn = fb_helper->connector_info[i]; |
| 1603 | modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height); |
| 1604 | if (!modes[i]) { |
| 1605 | can_clone = false; |
| 1606 | break; |
| 1607 | } |
| 1608 | for (j = 0; j < i; j++) { |
| 1609 | if (!enabled[j]) |
| 1610 | continue; |
| 1611 | if (!drm_mode_equal(modes[j], modes[i])) |
| 1612 | can_clone = false; |
| 1613 | } |
| 1614 | } |
| 1615 | |
| 1616 | if (can_clone) { |
| 1617 | DRM_DEBUG_KMS("can clone using command line\n"); |
| 1618 | return true; |
| 1619 | } |
| 1620 | |
| 1621 | /* try and find a 1024x768 mode on each connector */ |
| 1622 | can_clone = true; |
Adam Jackson | f6e252b | 2012-04-13 16:33:31 -0400 | [diff] [blame] | 1623 | 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] | 1624 | |
| 1625 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1626 | |
| 1627 | if (!enabled[i]) |
| 1628 | continue; |
| 1629 | |
| 1630 | fb_helper_conn = fb_helper->connector_info[i]; |
| 1631 | list_for_each_entry(mode, &fb_helper_conn->connector->modes, head) { |
| 1632 | if (drm_mode_equal(mode, dmt_mode)) |
| 1633 | modes[i] = mode; |
| 1634 | } |
| 1635 | if (!modes[i]) |
| 1636 | can_clone = false; |
| 1637 | } |
| 1638 | |
| 1639 | if (can_clone) { |
| 1640 | DRM_DEBUG_KMS("can clone using 1024x768\n"); |
| 1641 | return true; |
| 1642 | } |
| 1643 | DRM_INFO("kms: can't enable cloning when we probably wanted to.\n"); |
| 1644 | return false; |
| 1645 | } |
| 1646 | |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1647 | static int drm_get_tile_offsets(struct drm_fb_helper *fb_helper, |
| 1648 | struct drm_display_mode **modes, |
| 1649 | struct drm_fb_offset *offsets, |
| 1650 | int idx, |
| 1651 | int h_idx, int v_idx) |
| 1652 | { |
| 1653 | struct drm_fb_helper_connector *fb_helper_conn; |
| 1654 | int i; |
| 1655 | int hoffset = 0, voffset = 0; |
| 1656 | |
| 1657 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1658 | fb_helper_conn = fb_helper->connector_info[i]; |
| 1659 | if (!fb_helper_conn->connector->has_tile) |
| 1660 | continue; |
| 1661 | |
| 1662 | if (!modes[i] && (h_idx || v_idx)) { |
| 1663 | DRM_DEBUG_KMS("no modes for connector tiled %d %d\n", i, |
| 1664 | fb_helper_conn->connector->base.id); |
| 1665 | continue; |
| 1666 | } |
| 1667 | if (fb_helper_conn->connector->tile_h_loc < h_idx) |
| 1668 | hoffset += modes[i]->hdisplay; |
| 1669 | |
| 1670 | if (fb_helper_conn->connector->tile_v_loc < v_idx) |
| 1671 | voffset += modes[i]->vdisplay; |
| 1672 | } |
| 1673 | offsets[idx].x = hoffset; |
| 1674 | offsets[idx].y = voffset; |
| 1675 | DRM_DEBUG_KMS("returned %d %d for %d %d\n", hoffset, voffset, h_idx, v_idx); |
| 1676 | return 0; |
| 1677 | } |
| 1678 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1679 | static bool drm_target_preferred(struct drm_fb_helper *fb_helper, |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1680 | struct drm_display_mode **modes, |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1681 | struct drm_fb_offset *offsets, |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1682 | bool *enabled, int width, int height) |
| 1683 | { |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1684 | struct drm_fb_helper_connector *fb_helper_conn; |
| 1685 | int i; |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1686 | uint64_t conn_configured = 0, mask; |
| 1687 | int tile_pass = 0; |
| 1688 | mask = (1 << fb_helper->connector_count) - 1; |
| 1689 | retry: |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1690 | for (i = 0; i < fb_helper->connector_count; i++) { |
| 1691 | fb_helper_conn = fb_helper->connector_info[i]; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1692 | |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1693 | if (conn_configured & (1 << i)) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1694 | continue; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1695 | |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1696 | if (enabled[i] == false) { |
| 1697 | conn_configured |= (1 << i); |
| 1698 | continue; |
| 1699 | } |
| 1700 | |
| 1701 | /* first pass over all the untiled connectors */ |
| 1702 | if (tile_pass == 0 && fb_helper_conn->connector->has_tile) |
| 1703 | continue; |
| 1704 | |
| 1705 | if (tile_pass == 1) { |
| 1706 | if (fb_helper_conn->connector->tile_h_loc != 0 || |
| 1707 | fb_helper_conn->connector->tile_v_loc != 0) |
| 1708 | continue; |
| 1709 | |
| 1710 | } else { |
| 1711 | if (fb_helper_conn->connector->tile_h_loc != tile_pass -1 && |
| 1712 | fb_helper_conn->connector->tile_v_loc != tile_pass - 1) |
| 1713 | /* if this tile_pass doesn't cover any of the tiles - keep going */ |
| 1714 | continue; |
| 1715 | |
| 1716 | /* find the tile offsets for this pass - need |
| 1717 | to find all tiles left and above */ |
| 1718 | drm_get_tile_offsets(fb_helper, modes, offsets, |
| 1719 | i, fb_helper_conn->connector->tile_h_loc, fb_helper_conn->connector->tile_v_loc); |
| 1720 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1721 | DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n", |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1722 | fb_helper_conn->connector->base.id); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1723 | |
| 1724 | /* got for command line mode first */ |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1725 | modes[i] = drm_pick_cmdline_mode(fb_helper_conn, width, height); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1726 | if (!modes[i]) { |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1727 | DRM_DEBUG_KMS("looking for preferred mode on connector %d %d\n", |
| 1728 | 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] | 1729 | modes[i] = drm_has_preferred_mode(fb_helper_conn, width, height); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1730 | } |
| 1731 | /* No preferred modes, pick one off the list */ |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1732 | if (!modes[i] && !list_empty(&fb_helper_conn->connector->modes)) { |
| 1733 | list_for_each_entry(modes[i], &fb_helper_conn->connector->modes, head) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1734 | break; |
| 1735 | } |
| 1736 | DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name : |
| 1737 | "none"); |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1738 | conn_configured |= (1 << i); |
| 1739 | } |
| 1740 | |
| 1741 | if ((conn_configured & mask) != mask) { |
| 1742 | tile_pass++; |
| 1743 | goto retry; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1744 | } |
| 1745 | return true; |
| 1746 | } |
| 1747 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1748 | static int drm_pick_crtcs(struct drm_fb_helper *fb_helper, |
| 1749 | struct drm_fb_helper_crtc **best_crtcs, |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1750 | struct drm_display_mode **modes, |
| 1751 | int n, int width, int height) |
| 1752 | { |
| 1753 | int c, o; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1754 | struct drm_device *dev = fb_helper->dev; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1755 | struct drm_connector *connector; |
Jani Nikula | be26a66 | 2015-03-11 11:51:06 +0200 | [diff] [blame] | 1756 | const struct drm_connector_helper_funcs *connector_funcs; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1757 | struct drm_encoder *encoder; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1758 | int my_score, best_score, score; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1759 | struct drm_fb_helper_crtc **crtcs, *crtc; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1760 | struct drm_fb_helper_connector *fb_helper_conn; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1761 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1762 | if (n == fb_helper->connector_count) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1763 | return 0; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1764 | |
| 1765 | fb_helper_conn = fb_helper->connector_info[n]; |
| 1766 | connector = fb_helper_conn->connector; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1767 | |
| 1768 | best_crtcs[n] = NULL; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1769 | 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] | 1770 | if (modes[n] == NULL) |
| 1771 | return best_score; |
| 1772 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1773 | crtcs = kzalloc(dev->mode_config.num_connector * |
| 1774 | sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1775 | if (!crtcs) |
| 1776 | return best_score; |
| 1777 | |
| 1778 | my_score = 1; |
| 1779 | if (connector->status == connector_status_connected) |
| 1780 | my_score++; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1781 | if (drm_has_cmdline_mode(fb_helper_conn)) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1782 | my_score++; |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1783 | if (drm_has_preferred_mode(fb_helper_conn, width, height)) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1784 | my_score++; |
| 1785 | |
| 1786 | connector_funcs = connector->helper_private; |
| 1787 | encoder = connector_funcs->best_encoder(connector); |
| 1788 | if (!encoder) |
| 1789 | goto out; |
| 1790 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1791 | /* select a crtc for this connector and then attempt to configure |
| 1792 | remaining connectors */ |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1793 | for (c = 0; c < fb_helper->crtc_count; c++) { |
| 1794 | crtc = &fb_helper->crtc_info[c]; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1795 | |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1796 | if ((encoder->possible_crtcs & (1 << c)) == 0) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1797 | continue; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1798 | |
| 1799 | for (o = 0; o < n; o++) |
| 1800 | if (best_crtcs[o] == crtc) |
| 1801 | break; |
| 1802 | |
| 1803 | if (o < n) { |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1804 | /* ignore cloning unless only a single crtc */ |
| 1805 | if (fb_helper->crtc_count > 1) |
| 1806 | continue; |
| 1807 | |
| 1808 | if (!drm_mode_equal(modes[o], modes[n])) |
| 1809 | continue; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | crtcs[n] = crtc; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1813 | memcpy(crtcs, best_crtcs, n * sizeof(struct drm_fb_helper_crtc *)); |
| 1814 | score = my_score + drm_pick_crtcs(fb_helper, crtcs, modes, n + 1, |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1815 | width, height); |
| 1816 | if (score > best_score) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1817 | best_score = score; |
| 1818 | memcpy(best_crtcs, crtcs, |
| 1819 | dev->mode_config.num_connector * |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1820 | sizeof(struct drm_fb_helper_crtc *)); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1821 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1822 | } |
| 1823 | out: |
| 1824 | kfree(crtcs); |
| 1825 | return best_score; |
| 1826 | } |
| 1827 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1828 | static void drm_setup_crtcs(struct drm_fb_helper *fb_helper) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1829 | { |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1830 | struct drm_device *dev = fb_helper->dev; |
| 1831 | struct drm_fb_helper_crtc **crtcs; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1832 | struct drm_display_mode **modes; |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1833 | struct drm_fb_offset *offsets; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1834 | struct drm_mode_set *modeset; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1835 | bool *enabled; |
| 1836 | int width, height; |
Jesse Barnes | 11e17a0 | 2013-02-19 13:31:39 -0800 | [diff] [blame] | 1837 | int i; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1838 | |
| 1839 | DRM_DEBUG_KMS("\n"); |
| 1840 | |
| 1841 | width = dev->mode_config.max_width; |
| 1842 | height = dev->mode_config.max_height; |
| 1843 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1844 | crtcs = kcalloc(dev->mode_config.num_connector, |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1845 | sizeof(struct drm_fb_helper_crtc *), GFP_KERNEL); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1846 | modes = kcalloc(dev->mode_config.num_connector, |
| 1847 | sizeof(struct drm_display_mode *), GFP_KERNEL); |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1848 | offsets = kcalloc(dev->mode_config.num_connector, |
| 1849 | sizeof(struct drm_fb_offset), GFP_KERNEL); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1850 | enabled = kcalloc(dev->mode_config.num_connector, |
| 1851 | sizeof(bool), GFP_KERNEL); |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1852 | if (!crtcs || !modes || !enabled || !offsets) { |
Sachin Kamat | 8c5eaca | 2012-11-19 09:44:58 +0000 | [diff] [blame] | 1853 | DRM_ERROR("Memory allocation failed\n"); |
| 1854 | goto out; |
| 1855 | } |
| 1856 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1857 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1858 | drm_enable_connectors(fb_helper, enabled); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1859 | |
Jesse Barnes | 11e17a0 | 2013-02-19 13:31:39 -0800 | [diff] [blame] | 1860 | if (!(fb_helper->funcs->initial_config && |
| 1861 | fb_helper->funcs->initial_config(fb_helper, crtcs, modes, |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1862 | offsets, |
Jesse Barnes | 11e17a0 | 2013-02-19 13:31:39 -0800 | [diff] [blame] | 1863 | enabled, width, height))) { |
| 1864 | memset(modes, 0, dev->mode_config.num_connector*sizeof(modes[0])); |
| 1865 | memset(crtcs, 0, dev->mode_config.num_connector*sizeof(crtcs[0])); |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1866 | memset(offsets, 0, dev->mode_config.num_connector*sizeof(offsets[0])); |
Jesse Barnes | 11e17a0 | 2013-02-19 13:31:39 -0800 | [diff] [blame] | 1867 | |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1868 | if (!drm_target_cloned(fb_helper, modes, offsets, |
| 1869 | enabled, width, height) && |
| 1870 | !drm_target_preferred(fb_helper, modes, offsets, |
| 1871 | enabled, width, height)) |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1872 | DRM_ERROR("Unable to find initial modes\n"); |
Jesse Barnes | 11e17a0 | 2013-02-19 13:31:39 -0800 | [diff] [blame] | 1873 | |
| 1874 | DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n", |
| 1875 | width, height); |
| 1876 | |
| 1877 | drm_pick_crtcs(fb_helper, crtcs, modes, 0, width, height); |
Dave Airlie | 1d42bbc | 2010-05-07 05:02:30 +0000 | [diff] [blame] | 1878 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1879 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1880 | /* need to set the modesets up here for use later */ |
| 1881 | /* fill out the connector<->crtc mappings into the modesets */ |
| 1882 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 1883 | modeset = &fb_helper->crtc_info[i].mode_set; |
| 1884 | modeset->num_connectors = 0; |
Daniel Vetter | 7e53f3a | 2013-01-21 10:52:17 +0100 | [diff] [blame] | 1885 | modeset->fb = NULL; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1886 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1887 | |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1888 | for (i = 0; i < fb_helper->connector_count; i++) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1889 | struct drm_display_mode *mode = modes[i]; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1890 | struct drm_fb_helper_crtc *fb_crtc = crtcs[i]; |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1891 | struct drm_fb_offset *offset = &offsets[i]; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1892 | modeset = &fb_crtc->mode_set; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1893 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1894 | if (mode && fb_crtc) { |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1895 | DRM_DEBUG_KMS("desired mode %s set on crtc %d (%d,%d)\n", |
| 1896 | mode->name, fb_crtc->mode_set.crtc->base.id, offset->x, offset->y); |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1897 | fb_crtc->desired_mode = mode; |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1898 | fb_crtc->x = offset->x; |
| 1899 | fb_crtc->y = offset->y; |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1900 | if (modeset->mode) |
| 1901 | drm_mode_destroy(dev, modeset->mode); |
| 1902 | modeset->mode = drm_mode_duplicate(dev, |
| 1903 | fb_crtc->desired_mode); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1904 | modeset->connectors[modeset->num_connectors++] = fb_helper->connector_info[i]->connector; |
Daniel Vetter | 7e53f3a | 2013-01-21 10:52:17 +0100 | [diff] [blame] | 1905 | modeset->fb = fb_helper->fb; |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1906 | modeset->x = offset->x; |
| 1907 | modeset->y = offset->y; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1908 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1909 | } |
| 1910 | |
Daniel Vetter | 7e53f3a | 2013-01-21 10:52:17 +0100 | [diff] [blame] | 1911 | /* Clear out any old modes if there are no more connected outputs. */ |
| 1912 | for (i = 0; i < fb_helper->crtc_count; i++) { |
| 1913 | modeset = &fb_helper->crtc_info[i].mode_set; |
| 1914 | if (modeset->num_connectors == 0) { |
| 1915 | BUG_ON(modeset->fb); |
Daniel Vetter | 7e53f3a | 2013-01-21 10:52:17 +0100 | [diff] [blame] | 1916 | if (modeset->mode) |
| 1917 | drm_mode_destroy(dev, modeset->mode); |
| 1918 | modeset->mode = NULL; |
| 1919 | } |
| 1920 | } |
Sachin Kamat | 8c5eaca | 2012-11-19 09:44:58 +0000 | [diff] [blame] | 1921 | out: |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1922 | kfree(crtcs); |
| 1923 | kfree(modes); |
Dave Airlie | b0ee9e7 | 2014-10-20 16:31:53 +1000 | [diff] [blame] | 1924 | kfree(offsets); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1925 | kfree(enabled); |
| 1926 | } |
| 1927 | |
| 1928 | /** |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1929 | * drm_fb_helper_initial_config - setup a sane initial connector configuration |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 1930 | * @fb_helper: fb_helper device struct |
| 1931 | * @bpp_sel: bpp value to use for the framebuffer configuration |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1932 | * |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 1933 | * 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] | 1934 | * At the moment, this is a cloned configuration across all heads with |
| 1935 | * a new framebuffer object as the backing store. |
| 1936 | * |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1937 | * Note that this also registers the fbdev and so allows userspace to call into |
| 1938 | * the driver through the fbdev interfaces. |
| 1939 | * |
| 1940 | * This function will call down into the ->fb_probe callback to let |
| 1941 | * the driver allocate and initialize the fbdev info structure and the drm |
| 1942 | * framebuffer used to back the fbdev. drm_fb_helper_fill_var() and |
| 1943 | * drm_fb_helper_fill_fix() are provided as helpers to setup simple default |
| 1944 | * values for the fbdev info structure. |
| 1945 | * |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1946 | * RETURNS: |
| 1947 | * Zero if everything went ok, nonzero otherwise. |
| 1948 | */ |
Thierry Reding | 01934c2 | 2014-12-19 11:21:32 +0100 | [diff] [blame] | 1949 | 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] | 1950 | { |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1951 | struct drm_device *dev = fb_helper->dev; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1952 | int count = 0; |
| 1953 | |
Daniel Vetter | 53f1904 | 2014-03-20 14:26:35 +0100 | [diff] [blame] | 1954 | mutex_lock(&dev->mode_config.mutex); |
Dave Airlie | 0b4c0f3 | 2010-03-30 05:34:15 +0000 | [diff] [blame] | 1955 | count = drm_fb_helper_probe_connector_modes(fb_helper, |
| 1956 | dev->mode_config.max_width, |
| 1957 | dev->mode_config.max_height); |
Daniel Vetter | 53f1904 | 2014-03-20 14:26:35 +0100 | [diff] [blame] | 1958 | mutex_unlock(&dev->mode_config.mutex); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1959 | /* |
| 1960 | * we shouldn't end up with no modes here. |
| 1961 | */ |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1962 | if (count == 0) |
Sachin Kamat | d56b1b9 | 2012-11-15 03:43:29 +0000 | [diff] [blame] | 1963 | dev_info(fb_helper->dev->dev, "No connectors reported connected with modes\n"); |
Sachin Kamat | 96081cd | 2012-11-15 03:43:30 +0000 | [diff] [blame] | 1964 | |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1965 | drm_setup_crtcs(fb_helper); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1966 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 1967 | return drm_fb_helper_single_fb_probe(fb_helper, bpp_sel); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1968 | } |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 1969 | EXPORT_SYMBOL(drm_fb_helper_initial_config); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1970 | |
Chris Wilson | 7394371 | 2011-04-22 11:03:57 +0100 | [diff] [blame] | 1971 | /** |
| 1972 | * drm_fb_helper_hotplug_event - respond to a hotplug notification by |
Daniel Vetter | d0ddc033 | 2012-11-01 14:45:17 +0100 | [diff] [blame] | 1973 | * probing all the outputs attached to the fb |
Chris Wilson | 7394371 | 2011-04-22 11:03:57 +0100 | [diff] [blame] | 1974 | * @fb_helper: the drm_fb_helper |
| 1975 | * |
Chris Wilson | 7394371 | 2011-04-22 11:03:57 +0100 | [diff] [blame] | 1976 | * Scan the connectors attached to the fb_helper and try to put together a |
| 1977 | * setup after *notification of a change in output configuration. |
| 1978 | * |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1979 | * Called at runtime, takes the mode config locks to be able to check/change the |
| 1980 | * modeset configuration. Must be run from process context (which usually means |
| 1981 | * either the output polling work or a work item launched from the driver's |
| 1982 | * hotplug interrupt). |
| 1983 | * |
Daniel Vetter | 50c3dc9 | 2014-06-27 17:19:22 +0200 | [diff] [blame] | 1984 | * Note that drivers may call this even before calling |
| 1985 | * drm_fb_helper_initial_config but only aftert drm_fb_helper_init. This allows |
| 1986 | * for a race-free fbcon setup and will make sure that the fbdev emulation will |
| 1987 | * not miss any hotplug events. |
Daniel Vetter | 207fd32 | 2013-01-20 22:13:14 +0100 | [diff] [blame] | 1988 | * |
Chris Wilson | 7394371 | 2011-04-22 11:03:57 +0100 | [diff] [blame] | 1989 | * RETURNS: |
| 1990 | * 0 on success and a non-zero error code otherwise. |
| 1991 | */ |
| 1992 | int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 1993 | { |
Chris Wilson | 7394371 | 2011-04-22 11:03:57 +0100 | [diff] [blame] | 1994 | struct drm_device *dev = fb_helper->dev; |
Lespiau, Damien | 51bbd27 | 2013-09-28 16:24:05 +0100 | [diff] [blame] | 1995 | u32 max_width, max_height; |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 1996 | |
Daniel Vetter | 89ced12 | 2013-04-11 14:26:55 +0000 | [diff] [blame] | 1997 | mutex_lock(&fb_helper->dev->mode_config.mutex); |
Daniel Vetter | 50c3dc9 | 2014-06-27 17:19:22 +0200 | [diff] [blame] | 1998 | if (!fb_helper->fb || !drm_fb_helper_is_bound(fb_helper)) { |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 1999 | fb_helper->delayed_hotplug = true; |
Daniel Vetter | 89ced12 | 2013-04-11 14:26:55 +0000 | [diff] [blame] | 2000 | mutex_unlock(&fb_helper->dev->mode_config.mutex); |
Chris Wilson | 7394371 | 2011-04-22 11:03:57 +0100 | [diff] [blame] | 2001 | return 0; |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 2002 | } |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2003 | DRM_DEBUG_KMS("\n"); |
| 2004 | |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 2005 | max_width = fb_helper->fb->width; |
| 2006 | max_height = fb_helper->fb->height; |
Dave Airlie | 4abe352 | 2010-03-30 05:34:18 +0000 | [diff] [blame] | 2007 | |
Lespiau, Damien | 51bbd27 | 2013-09-28 16:24:05 +0100 | [diff] [blame] | 2008 | drm_fb_helper_probe_connector_modes(fb_helper, max_width, max_height); |
Daniel Vetter | 89ced12 | 2013-04-11 14:26:55 +0000 | [diff] [blame] | 2009 | mutex_unlock(&fb_helper->dev->mode_config.mutex); |
| 2010 | |
| 2011 | drm_modeset_lock_all(dev); |
Dave Airlie | 8be48d9 | 2010-03-30 05:34:14 +0000 | [diff] [blame] | 2012 | drm_setup_crtcs(fb_helper); |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 2013 | drm_modeset_unlock_all(dev); |
Daniel Vetter | 2180c3c | 2013-01-21 23:12:36 +0100 | [diff] [blame] | 2014 | drm_fb_helper_set_par(fb_helper->fbdev); |
| 2015 | |
| 2016 | return 0; |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 2017 | } |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 2018 | EXPORT_SYMBOL(drm_fb_helper_hotplug_event); |
Dave Airlie | 5c4426a | 2010-03-30 05:34:17 +0000 | [diff] [blame] | 2019 | |
David Rientjes | 6a108a1 | 2011-01-20 14:44:16 -0800 | [diff] [blame] | 2020 | /* The Kconfig DRM_KMS_HELPER selects FRAMEBUFFER_CONSOLE (if !EXPERT) |
David Fries | 3ce0516 | 2010-12-12 12:39:22 -0600 | [diff] [blame] | 2021 | * but the module doesn't depend on any fb console symbols. At least |
| 2022 | * attempt to load fbcon to avoid leaving the system without a usable console. |
| 2023 | */ |
David Rientjes | 6a108a1 | 2011-01-20 14:44:16 -0800 | [diff] [blame] | 2024 | #if defined(CONFIG_FRAMEBUFFER_CONSOLE_MODULE) && !defined(CONFIG_EXPERT) |
David Fries | 3ce0516 | 2010-12-12 12:39:22 -0600 | [diff] [blame] | 2025 | static int __init drm_fb_helper_modinit(void) |
| 2026 | { |
| 2027 | const char *name = "fbcon"; |
| 2028 | struct module *fbcon; |
| 2029 | |
| 2030 | mutex_lock(&module_mutex); |
| 2031 | fbcon = find_module(name); |
| 2032 | mutex_unlock(&module_mutex); |
| 2033 | |
| 2034 | if (!fbcon) |
| 2035 | request_module_nowait(name); |
| 2036 | return 0; |
| 2037 | } |
| 2038 | |
| 2039 | module_init(drm_fb_helper_modinit); |
| 2040 | #endif |