Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'topic/drm-misc-2015-05-27' of git://anongit.freedesktop.org/drm-intel into drm-next

One more round of drm-misc, again mostly atomic. Big thing is the
userspace blob code from Daniel Stone, with support for the mode_id blob
now added to the atomic ioctl. Finally we can do atomic modesets!

Note that the atomic ioctl is still behind the module knob since the
weston patches aren't quite ready yet imo - they lack TEST_ONLY support,
which is a fairly crucial bit of the atomic api. But besides that I think
it's all good to go. That's also why we didn't bother to hide the new blob
ioctls behind the knob, that part won't need to change. And if weston
patches get in shape in time we could throw the "atomic by default patch"
on top for 4.2.

* tag 'topic/drm-misc-2015-05-27' of git://anongit.freedesktop.org/drm-intel:
drm: Fix off-by-one in vblank hardware counter wraparound handling
drm/atomic: fix out of bounds read in for_each_*_in_state helpers
drm/atomic: Add MODE_ID property
drm/atomic: Add current-mode blob to CRTC state
drm: Add drm_atomic_set_mode_for_crtc
drm: check for garbage in unused addfb2 fields
drm: Retain reference to blob properties in lookup
drm/mode: Add user blob-creation ioctl
drm: Return error value from blob creation
drm: Allow creating blob properties without copy
drm/mode: Unstatic kernel-userspace mode conversion
drm/mode: Validate modes inside drm_crtc_convert_umode
drm/crtc_helper: Replace open-coded CRTC state helpers
drm: kerneldoc fixes for blob properties
drm/DocBook: Add more drm_bridge documentation
drm: bridge: Allow daisy chaining of bridges
drm/atomic: add all affected planes in drm_atomic_helper_check_modeset
drm/atomic: add drm_atomic_add_affected_planes
drm/atomic: add commit_planes_on_crtc helper

+923 -205
+12
Documentation/DocBook/drm.tmpl
··· 2439 2439 <title>Tile group</title> 2440 2440 !Pdrivers/gpu/drm/drm_crtc.c Tile group 2441 2441 </sect2> 2442 + <sect2> 2443 + <title>Bridges</title> 2444 + <sect3> 2445 + <title>Overview</title> 2446 + !Pdrivers/gpu/drm/drm_bridge.c overview 2447 + </sect3> 2448 + <sect3> 2449 + <title>Default bridge callback sequence</title> 2450 + !Pdrivers/gpu/drm/drm_bridge.c bridge callbacks 2451 + </sect3> 2452 + !Edrivers/gpu/drm/drm_bridge.c 2453 + </sect2> 2442 2454 </sect1> 2443 2455 2444 2456 <!-- Internals: kms properties -->
+161 -1
drivers/gpu/drm/drm_atomic.c
··· 290 290 EXPORT_SYMBOL(drm_atomic_get_crtc_state); 291 291 292 292 /** 293 + * drm_atomic_set_mode_for_crtc - set mode for CRTC 294 + * @state: the CRTC whose incoming state to update 295 + * @mode: kernel-internal mode to use for the CRTC, or NULL to disable 296 + * 297 + * Set a mode (originating from the kernel) on the desired CRTC state. Does 298 + * not change any other state properties, including enable, active, or 299 + * mode_changed. 300 + * 301 + * RETURNS: 302 + * Zero on success, error code on failure. Cannot return -EDEADLK. 303 + */ 304 + int drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state, 305 + struct drm_display_mode *mode) 306 + { 307 + struct drm_mode_modeinfo umode; 308 + 309 + /* Early return for no change. */ 310 + if (mode && memcmp(&state->mode, mode, sizeof(*mode)) == 0) 311 + return 0; 312 + 313 + if (state->mode_blob) 314 + drm_property_unreference_blob(state->mode_blob); 315 + state->mode_blob = NULL; 316 + 317 + if (mode) { 318 + drm_mode_convert_to_umode(&umode, mode); 319 + state->mode_blob = 320 + drm_property_create_blob(state->crtc->dev, 321 + sizeof(umode), 322 + &umode); 323 + if (IS_ERR(state->mode_blob)) 324 + return PTR_ERR(state->mode_blob); 325 + 326 + drm_mode_copy(&state->mode, mode); 327 + state->enable = true; 328 + DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n", 329 + mode->name, state); 330 + } else { 331 + memset(&state->mode, 0, sizeof(state->mode)); 332 + state->enable = false; 333 + DRM_DEBUG_ATOMIC("Set [NOMODE] for CRTC state %p\n", 334 + state); 335 + } 336 + 337 + return 0; 338 + } 339 + EXPORT_SYMBOL(drm_atomic_set_mode_for_crtc); 340 + 341 + /** 342 + * drm_atomic_set_mode_prop_for_crtc - set mode for CRTC 343 + * @state: the CRTC whose incoming state to update 344 + * @blob: pointer to blob property to use for mode 345 + * 346 + * Set a mode (originating from a blob property) on the desired CRTC state. 347 + * This function will take a reference on the blob property for the CRTC state, 348 + * and release the reference held on the state's existing mode property, if any 349 + * was set. 350 + * 351 + * RETURNS: 352 + * Zero on success, error code on failure. Cannot return -EDEADLK. 353 + */ 354 + int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state, 355 + struct drm_property_blob *blob) 356 + { 357 + if (blob == state->mode_blob) 358 + return 0; 359 + 360 + if (state->mode_blob) 361 + drm_property_unreference_blob(state->mode_blob); 362 + state->mode_blob = NULL; 363 + 364 + if (blob) { 365 + if (blob->length != sizeof(struct drm_mode_modeinfo) || 366 + drm_mode_convert_umode(&state->mode, 367 + (const struct drm_mode_modeinfo *) 368 + blob->data)) 369 + return -EINVAL; 370 + 371 + state->mode_blob = drm_property_reference_blob(blob); 372 + state->enable = true; 373 + DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n", 374 + state->mode.name, state); 375 + } else { 376 + memset(&state->mode, 0, sizeof(state->mode)); 377 + state->enable = false; 378 + DRM_DEBUG_ATOMIC("Set [NOMODE] for CRTC state %p\n", 379 + state); 380 + } 381 + 382 + return 0; 383 + } 384 + EXPORT_SYMBOL(drm_atomic_set_mode_prop_for_crtc); 385 + 386 + /** 293 387 * drm_atomic_crtc_set_property - set property on CRTC 294 388 * @crtc: the drm CRTC to set a property on 295 389 * @state: the state object to update with the new property value ··· 405 311 { 406 312 struct drm_device *dev = crtc->dev; 407 313 struct drm_mode_config *config = &dev->mode_config; 314 + int ret; 408 315 409 - /* FIXME: Mode prop is missing, which also controls ->enable. */ 410 316 if (property == config->prop_active) 411 317 state->active = val; 318 + else if (property == config->prop_mode_id) { 319 + struct drm_property_blob *mode = 320 + drm_property_lookup_blob(dev, val); 321 + ret = drm_atomic_set_mode_prop_for_crtc(state, mode); 322 + if (mode) 323 + drm_property_unreference_blob(mode); 324 + return ret; 325 + } 412 326 else if (crtc->funcs->atomic_set_property) 413 327 return crtc->funcs->atomic_set_property(crtc, state, property, val); 414 328 else ··· 441 339 442 340 if (property == config->prop_active) 443 341 *val = state->active; 342 + else if (property == config->prop_mode_id) 343 + *val = (state->mode_blob) ? state->mode_blob->base.id : 0; 444 344 else if (crtc->funcs->atomic_get_property) 445 345 return crtc->funcs->atomic_get_property(crtc, state, property, val); 446 346 else ··· 474 370 475 371 if (state->active && !state->enable) { 476 372 DRM_DEBUG_ATOMIC("[CRTC:%d] active without enabled\n", 373 + crtc->base.id); 374 + return -EINVAL; 375 + } 376 + 377 + /* The state->enable vs. state->mode_blob checks can be WARN_ON, 378 + * as this is a kernel-internal detail that userspace should never 379 + * be able to trigger. */ 380 + if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) && 381 + WARN_ON(state->enable && !state->mode_blob)) { 382 + DRM_DEBUG_ATOMIC("[CRTC:%d] enabled without mode blob\n", 383 + crtc->base.id); 384 + return -EINVAL; 385 + } 386 + 387 + if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) && 388 + WARN_ON(!state->enable && state->mode_blob)) { 389 + DRM_DEBUG_ATOMIC("[CRTC:%d] disabled with mode blob\n", 477 390 crtc->base.id); 478 391 return -EINVAL; 479 392 } ··· 1075 954 return 0; 1076 955 } 1077 956 EXPORT_SYMBOL(drm_atomic_add_affected_connectors); 957 + 958 + /** 959 + * drm_atomic_add_affected_planes - add planes for crtc 960 + * @state: atomic state 961 + * @crtc: DRM crtc 962 + * 963 + * This function walks the current configuration and adds all planes 964 + * currently used by @crtc to the atomic configuration @state. This is useful 965 + * when an atomic commit also needs to check all currently enabled plane on 966 + * @crtc, e.g. when changing the mode. It's also useful when re-enabling a CRTC 967 + * to avoid special code to force-enable all planes. 968 + * 969 + * Since acquiring a plane state will always also acquire the w/w mutex of the 970 + * current CRTC for that plane (if there is any) adding all the plane states for 971 + * a CRTC will not reduce parallism of atomic updates. 972 + * 973 + * Returns: 974 + * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK 975 + * then the w/w mutex code has detected a deadlock and the entire atomic 976 + * sequence must be restarted. All other errors are fatal. 977 + */ 978 + int 979 + drm_atomic_add_affected_planes(struct drm_atomic_state *state, 980 + struct drm_crtc *crtc) 981 + { 982 + struct drm_plane *plane; 983 + 984 + WARN_ON(!drm_atomic_get_existing_crtc_state(state, crtc)); 985 + 986 + drm_for_each_plane_mask(plane, state->dev, crtc->state->plane_mask) { 987 + struct drm_plane_state *plane_state = 988 + drm_atomic_get_plane_state(state, plane); 989 + 990 + if (IS_ERR(plane_state)) 991 + return PTR_ERR(plane_state); 992 + } 993 + return 0; 994 + } 995 + EXPORT_SYMBOL(drm_atomic_add_affected_planes); 1078 996 1079 997 /** 1080 998 * drm_atomic_connectors_for_crtc - count number of connected outputs
+90 -27
drivers/gpu/drm/drm_atomic_helper.c
··· 283 283 if (!funcs) 284 284 continue; 285 285 286 - if (encoder->bridge && encoder->bridge->funcs->mode_fixup) { 287 - ret = encoder->bridge->funcs->mode_fixup( 288 - encoder->bridge, &crtc_state->mode, 289 - &crtc_state->adjusted_mode); 290 - if (!ret) { 291 - DRM_DEBUG_ATOMIC("Bridge fixup failed\n"); 292 - return -EINVAL; 293 - } 286 + ret = drm_bridge_mode_fixup(encoder->bridge, &crtc_state->mode, 287 + &crtc_state->adjusted_mode); 288 + if (!ret) { 289 + DRM_DEBUG_ATOMIC("Bridge fixup failed\n"); 290 + return -EINVAL; 294 291 } 295 292 296 293 if (funcs->atomic_check) { ··· 423 426 crtc_state->active ? 'y' : 'n'); 424 427 425 428 ret = drm_atomic_add_affected_connectors(state, crtc); 429 + if (ret != 0) 430 + return ret; 431 + 432 + ret = drm_atomic_add_affected_planes(state, crtc); 426 433 if (ret != 0) 427 434 return ret; 428 435 ··· 584 583 * Each encoder has at most one connector (since we always steal 585 584 * it away), so we won't call disable hooks twice. 586 585 */ 587 - if (encoder->bridge) 588 - encoder->bridge->funcs->disable(encoder->bridge); 586 + drm_bridge_disable(encoder->bridge); 589 587 590 588 /* Right function depends upon target state. */ 591 589 if (connector->state->crtc && funcs->prepare) ··· 594 594 else 595 595 funcs->dpms(encoder, DRM_MODE_DPMS_OFF); 596 596 597 - if (encoder->bridge) 598 - encoder->bridge->funcs->post_disable(encoder->bridge); 597 + drm_bridge_post_disable(encoder->bridge); 599 598 } 600 599 601 600 for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { ··· 736 737 if (funcs->mode_set) 737 738 funcs->mode_set(encoder, mode, adjusted_mode); 738 739 739 - if (encoder->bridge && encoder->bridge->funcs->mode_set) 740 - encoder->bridge->funcs->mode_set(encoder->bridge, 741 - mode, adjusted_mode); 740 + drm_bridge_mode_set(encoder->bridge, mode, adjusted_mode); 742 741 } 743 742 } 744 743 ··· 832 835 * Each encoder has at most one connector (since we always steal 833 836 * it away), so we won't call enable hooks twice. 834 837 */ 835 - if (encoder->bridge) 836 - encoder->bridge->funcs->pre_enable(encoder->bridge); 838 + drm_bridge_pre_enable(encoder->bridge); 837 839 838 840 if (funcs->enable) 839 841 funcs->enable(encoder); 840 842 else 841 843 funcs->commit(encoder); 842 844 843 - if (encoder->bridge) 844 - encoder->bridge->funcs->enable(encoder->bridge); 845 + drm_bridge_enable(encoder->bridge); 845 846 } 846 847 } 847 848 EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_enables); ··· 1122 1127 * 1123 1128 * It still requires the global state object @old_state to know which planes and 1124 1129 * crtcs need to be updated though. 1130 + * 1131 + * Note that this function does all plane updates across all CRTCs in one step. 1132 + * If the hardware can't support this approach look at 1133 + * drm_atomic_helper_commit_planes_on_crtc() instead. 1125 1134 */ 1126 1135 void drm_atomic_helper_commit_planes(struct drm_device *dev, 1127 1136 struct drm_atomic_state *old_state) ··· 1178 1179 } 1179 1180 } 1180 1181 EXPORT_SYMBOL(drm_atomic_helper_commit_planes); 1182 + 1183 + /** 1184 + * drm_atomic_helper_commit_planes_on_crtc - commit plane state for a crtc 1185 + * @old_crtc_state: atomic state object with the old crtc state 1186 + * 1187 + * This function commits the new plane state using the plane and atomic helper 1188 + * functions for planes on the specific crtc. It assumes that the atomic state 1189 + * has already been pushed into the relevant object state pointers, since this 1190 + * step can no longer fail. 1191 + * 1192 + * This function is useful when plane updates should be done crtc-by-crtc 1193 + * instead of one global step like drm_atomic_helper_commit_planes() does. 1194 + * 1195 + * This function can only be savely used when planes are not allowed to move 1196 + * between different CRTCs because this function doesn't handle inter-CRTC 1197 + * depencies. Callers need to ensure that either no such depencies exist, 1198 + * resolve them through ordering of commit calls or through some other means. 1199 + */ 1200 + void 1201 + drm_atomic_helper_commit_planes_on_crtc(struct drm_crtc_state *old_crtc_state) 1202 + { 1203 + const struct drm_crtc_helper_funcs *crtc_funcs; 1204 + struct drm_crtc *crtc = old_crtc_state->crtc; 1205 + struct drm_atomic_state *old_state = old_crtc_state->state; 1206 + struct drm_plane *plane; 1207 + unsigned plane_mask; 1208 + 1209 + plane_mask = old_crtc_state->plane_mask; 1210 + plane_mask |= crtc->state->plane_mask; 1211 + 1212 + crtc_funcs = crtc->helper_private; 1213 + if (crtc_funcs && crtc_funcs->atomic_begin) 1214 + crtc_funcs->atomic_begin(crtc); 1215 + 1216 + drm_for_each_plane_mask(plane, crtc->dev, plane_mask) { 1217 + struct drm_plane_state *old_plane_state = 1218 + drm_atomic_get_existing_plane_state(old_state, plane); 1219 + const struct drm_plane_helper_funcs *plane_funcs; 1220 + 1221 + plane_funcs = plane->helper_private; 1222 + 1223 + if (!old_plane_state || !plane_funcs) 1224 + continue; 1225 + 1226 + WARN_ON(plane->state->crtc && plane->state->crtc != crtc); 1227 + 1228 + if (drm_atomic_plane_disabling(plane, old_plane_state) && 1229 + plane_funcs->atomic_disable) 1230 + plane_funcs->atomic_disable(plane, old_plane_state); 1231 + else if (plane->state->crtc || 1232 + drm_atomic_plane_disabling(plane, old_plane_state)) 1233 + plane_funcs->atomic_update(plane, old_plane_state); 1234 + } 1235 + 1236 + if (crtc_funcs && crtc_funcs->atomic_flush) 1237 + crtc_funcs->atomic_flush(crtc); 1238 + } 1239 + EXPORT_SYMBOL(drm_atomic_helper_commit_planes_on_crtc); 1181 1240 1182 1241 /** 1183 1242 * drm_atomic_helper_cleanup_planes - cleanup plane resources after commit ··· 1607 1550 WARN_ON(set->fb); 1608 1551 WARN_ON(set->num_connectors); 1609 1552 1610 - crtc_state->enable = false; 1553 + ret = drm_atomic_set_mode_for_crtc(crtc_state, NULL); 1554 + if (ret != 0) 1555 + goto fail; 1556 + 1611 1557 crtc_state->active = false; 1612 1558 1613 1559 ret = drm_atomic_set_crtc_for_plane(primary_state, NULL); ··· 1625 1565 WARN_ON(!set->fb); 1626 1566 WARN_ON(!set->num_connectors); 1627 1567 1628 - crtc_state->enable = true; 1568 + ret = drm_atomic_set_mode_for_crtc(crtc_state, set->mode); 1569 + if (ret != 0) 1570 + goto fail; 1571 + 1629 1572 crtc_state->active = true; 1630 - drm_mode_copy(&crtc_state->mode, set->mode); 1631 1573 1632 1574 ret = drm_atomic_set_crtc_for_plane(primary_state, crtc); 1633 1575 if (ret != 0) ··· 2044 1982 */ 2045 1983 void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc) 2046 1984 { 1985 + if (crtc->state && crtc->state->mode_blob) 1986 + drm_property_unreference_blob(crtc->state->mode_blob); 2047 1987 kfree(crtc->state); 2048 1988 crtc->state = kzalloc(sizeof(*crtc->state), GFP_KERNEL); 2049 1989 ··· 2067 2003 { 2068 2004 memcpy(state, crtc->state, sizeof(*state)); 2069 2005 2006 + if (state->mode_blob) 2007 + drm_property_reference_blob(state->mode_blob); 2070 2008 state->mode_changed = false; 2071 2009 state->active_changed = false; 2072 2010 state->planes_changed = false; ··· 2111 2045 void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc, 2112 2046 struct drm_crtc_state *state) 2113 2047 { 2114 - /* 2115 - * This is currently a placeholder so that drivers that subclass the 2116 - * state will automatically do the right thing if code is ever added 2117 - * to this function. 2118 - */ 2048 + if (state->mode_blob) 2049 + drm_property_unreference_blob(state->mode_blob); 2119 2050 } 2120 2051 EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state); 2121 2052
+242
drivers/gpu/drm/drm_bridge.c
··· 28 28 29 29 #include "drm/drmP.h" 30 30 31 + /** 32 + * DOC: overview 33 + * 34 + * drm_bridge represents a device that hangs on to an encoder. These are handy 35 + * when a regular drm_encoder entity isn't enough to represent the entire 36 + * encoder chain. 37 + * 38 + * A bridge is always associated to a single drm_encoder at a time, but can be 39 + * either connected to it directly, or through an intermediate bridge: 40 + * 41 + * encoder ---> bridge B ---> bridge A 42 + * 43 + * Here, the output of the encoder feeds to bridge B, and that furthers feeds to 44 + * bridge A. 45 + * 46 + * The driver using the bridge is responsible to make the associations between 47 + * the encoder and bridges. Once these links are made, the bridges will 48 + * participate along with encoder functions to perform mode_set/enable/disable 49 + * through the ops provided in drm_bridge_funcs. 50 + * 51 + * drm_bridge, like drm_panel, aren't drm_mode_object entities like planes, 52 + * crtcs, encoders or connectors. They just provide additional hooks to get the 53 + * desired output at the end of the encoder chain. 54 + */ 55 + 31 56 static DEFINE_MUTEX(bridge_lock); 32 57 static LIST_HEAD(bridge_list); 33 58 59 + /** 60 + * drm_bridge_add - add the given bridge to the global bridge list 61 + * 62 + * @bridge: bridge control structure 63 + * 64 + * RETURNS: 65 + * Unconditionally returns Zero. 66 + */ 34 67 int drm_bridge_add(struct drm_bridge *bridge) 35 68 { 36 69 mutex_lock(&bridge_lock); ··· 74 41 } 75 42 EXPORT_SYMBOL(drm_bridge_add); 76 43 44 + /** 45 + * drm_bridge_remove - remove the given bridge from the global bridge list 46 + * 47 + * @bridge: bridge control structure 48 + */ 77 49 void drm_bridge_remove(struct drm_bridge *bridge) 78 50 { 79 51 mutex_lock(&bridge_lock); ··· 87 49 } 88 50 EXPORT_SYMBOL(drm_bridge_remove); 89 51 52 + /** 53 + * drm_bridge_attach - associate given bridge to our DRM device 54 + * 55 + * @dev: DRM device 56 + * @bridge: bridge control structure 57 + * 58 + * called by a kms driver to link one of our encoder/bridge to the given 59 + * bridge. 60 + * 61 + * Note that setting up links between the bridge and our encoder/bridge 62 + * objects needs to be handled by the kms driver itself 63 + * 64 + * RETURNS: 65 + * Zero on success, error code on failure 66 + */ 90 67 int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge) 91 68 { 92 69 if (!dev || !bridge) ··· 119 66 } 120 67 EXPORT_SYMBOL(drm_bridge_attach); 121 68 69 + /** 70 + * DOC: bridge callbacks 71 + * 72 + * The drm_bridge_funcs ops are populated by the bridge driver. The drm 73 + * internals(atomic and crtc helpers) use the helpers defined in drm_bridge.c 74 + * These helpers call a specific drm_bridge_funcs op for all the bridges 75 + * during encoder configuration. 76 + * 77 + * When creating a bridge driver, one can implement drm_bridge_funcs op with 78 + * the help of these rough rules: 79 + * 80 + * pre_enable: this contains things needed to be done for the bridge before 81 + * its clock and timings are enabled by its source. For a bridge, its source 82 + * is generally the encoder or bridge just before it in the encoder chain. 83 + * 84 + * enable: this contains things needed to be done for the bridge once its 85 + * source is enabled. In other words, enable is called once the source is 86 + * ready with clock and timing needed by the bridge. 87 + * 88 + * disable: this contains things needed to be done for the bridge assuming 89 + * that its source is still enabled, i.e. clock and timings are still on. 90 + * 91 + * post_disable: this contains things needed to be done for the bridge once 92 + * its source is disabled, i.e. once clocks and timings are off. 93 + * 94 + * mode_fixup: this should fixup the given mode for the bridge. It is called 95 + * after the encoder's mode fixup. mode_fixup can also reject a mode completely 96 + * if it's unsuitable for the hardware. 97 + * 98 + * mode_set: this sets up the mode for the bridge. It assumes that its source 99 + * (an encoder or a bridge) has set the mode too. 100 + */ 101 + 102 + /** 103 + * drm_bridge_mode_fixup - fixup proposed mode for all bridges in the 104 + * encoder chain 105 + * @bridge: bridge control structure 106 + * @mode: desired mode to be set for the bridge 107 + * @adjusted_mode: updated mode that works for this bridge 108 + * 109 + * Calls 'mode_fixup' drm_bridge_funcs op for all the bridges in the 110 + * encoder chain, starting from the first bridge to the last. 111 + * 112 + * Note: the bridge passed should be the one closest to the encoder 113 + * 114 + * RETURNS: 115 + * true on success, false on failure 116 + */ 117 + bool drm_bridge_mode_fixup(struct drm_bridge *bridge, 118 + const struct drm_display_mode *mode, 119 + struct drm_display_mode *adjusted_mode) 120 + { 121 + bool ret = true; 122 + 123 + if (!bridge) 124 + return true; 125 + 126 + if (bridge->funcs->mode_fixup) 127 + ret = bridge->funcs->mode_fixup(bridge, mode, adjusted_mode); 128 + 129 + ret = ret && drm_bridge_mode_fixup(bridge->next, mode, adjusted_mode); 130 + 131 + return ret; 132 + } 133 + EXPORT_SYMBOL(drm_bridge_mode_fixup); 134 + 135 + /** 136 + * drm_bridge_disable - calls 'disable' drm_bridge_funcs op for all 137 + * bridges in the encoder chain. 138 + * @bridge: bridge control structure 139 + * 140 + * Calls 'disable' drm_bridge_funcs op for all the bridges in the encoder 141 + * chain, starting from the last bridge to the first. These are called before 142 + * calling the encoder's prepare op. 143 + * 144 + * Note: the bridge passed should be the one closest to the encoder 145 + */ 146 + void drm_bridge_disable(struct drm_bridge *bridge) 147 + { 148 + if (!bridge) 149 + return; 150 + 151 + drm_bridge_disable(bridge->next); 152 + 153 + bridge->funcs->disable(bridge); 154 + } 155 + EXPORT_SYMBOL(drm_bridge_disable); 156 + 157 + /** 158 + * drm_bridge_post_disable - calls 'post_disable' drm_bridge_funcs op for 159 + * all bridges in the encoder chain. 160 + * @bridge: bridge control structure 161 + * 162 + * Calls 'post_disable' drm_bridge_funcs op for all the bridges in the 163 + * encoder chain, starting from the first bridge to the last. These are called 164 + * after completing the encoder's prepare op. 165 + * 166 + * Note: the bridge passed should be the one closest to the encoder 167 + */ 168 + void drm_bridge_post_disable(struct drm_bridge *bridge) 169 + { 170 + if (!bridge) 171 + return; 172 + 173 + bridge->funcs->post_disable(bridge); 174 + 175 + drm_bridge_post_disable(bridge->next); 176 + } 177 + EXPORT_SYMBOL(drm_bridge_post_disable); 178 + 179 + /** 180 + * drm_bridge_mode_set - set proposed mode for all bridges in the 181 + * encoder chain 182 + * @bridge: bridge control structure 183 + * @mode: desired mode to be set for the bridge 184 + * @adjusted_mode: updated mode that works for this bridge 185 + * 186 + * Calls 'mode_set' drm_bridge_funcs op for all the bridges in the 187 + * encoder chain, starting from the first bridge to the last. 188 + * 189 + * Note: the bridge passed should be the one closest to the encoder 190 + */ 191 + void drm_bridge_mode_set(struct drm_bridge *bridge, 192 + struct drm_display_mode *mode, 193 + struct drm_display_mode *adjusted_mode) 194 + { 195 + if (!bridge) 196 + return; 197 + 198 + if (bridge->funcs->mode_set) 199 + bridge->funcs->mode_set(bridge, mode, adjusted_mode); 200 + 201 + drm_bridge_mode_set(bridge->next, mode, adjusted_mode); 202 + } 203 + EXPORT_SYMBOL(drm_bridge_mode_set); 204 + 205 + /** 206 + * drm_bridge_pre_enable - calls 'pre_enable' drm_bridge_funcs op for all 207 + * bridges in the encoder chain. 208 + * @bridge: bridge control structure 209 + * 210 + * Calls 'pre_enable' drm_bridge_funcs op for all the bridges in the encoder 211 + * chain, starting from the last bridge to the first. These are called 212 + * before calling the encoder's commit op. 213 + * 214 + * Note: the bridge passed should be the one closest to the encoder 215 + */ 216 + void drm_bridge_pre_enable(struct drm_bridge *bridge) 217 + { 218 + if (!bridge) 219 + return; 220 + 221 + drm_bridge_pre_enable(bridge->next); 222 + 223 + bridge->funcs->pre_enable(bridge); 224 + } 225 + EXPORT_SYMBOL(drm_bridge_pre_enable); 226 + 227 + /** 228 + * drm_bridge_enable - calls 'enable' drm_bridge_funcs op for all bridges 229 + * in the encoder chain. 230 + * @bridge: bridge control structure 231 + * 232 + * Calls 'enable' drm_bridge_funcs op for all the bridges in the encoder 233 + * chain, starting from the first bridge to the last. These are called 234 + * after completing the encoder's commit op. 235 + * 236 + * Note that the bridge passed should be the one closest to the encoder 237 + */ 238 + void drm_bridge_enable(struct drm_bridge *bridge) 239 + { 240 + if (!bridge) 241 + return; 242 + 243 + bridge->funcs->enable(bridge); 244 + 245 + drm_bridge_enable(bridge->next); 246 + } 247 + EXPORT_SYMBOL(drm_bridge_enable); 248 + 122 249 #ifdef CONFIG_OF 250 + /** 251 + * of_drm_find_bridge - find the bridge corresponding to the device node in 252 + * the global bridge list 253 + * 254 + * @np: device node 255 + * 256 + * RETURNS: 257 + * drm_bridge control struct on success, NULL on failure 258 + */ 123 259 struct drm_bridge *of_drm_find_bridge(struct device_node *np) 124 260 { 125 261 struct drm_bridge *bridge;
+202 -102
drivers/gpu/drm/drm_crtc.c
··· 688 688 689 689 if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { 690 690 drm_object_attach_property(&crtc->base, config->prop_active, 0); 691 + drm_object_attach_property(&crtc->base, config->prop_mode_id, 0); 691 692 } 692 693 693 694 return 0; ··· 1455 1454 return -ENOMEM; 1456 1455 dev->mode_config.prop_active = prop; 1457 1456 1457 + prop = drm_property_create(dev, 1458 + DRM_MODE_PROP_ATOMIC | DRM_MODE_PROP_BLOB, 1459 + "MODE_ID", 0); 1460 + if (!prop) 1461 + return -ENOMEM; 1462 + dev->mode_config.prop_mode_id = prop; 1463 + 1458 1464 return 0; 1459 1465 } 1460 1466 ··· 1744 1736 EXPORT_SYMBOL(drm_reinit_primary_mode_group); 1745 1737 1746 1738 /** 1747 - * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo 1748 - * @out: drm_mode_modeinfo struct to return to the user 1749 - * @in: drm_display_mode to use 1750 - * 1751 - * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to 1752 - * the user. 1753 - */ 1754 - static void drm_crtc_convert_to_umode(struct drm_mode_modeinfo *out, 1755 - const struct drm_display_mode *in) 1756 - { 1757 - WARN(in->hdisplay > USHRT_MAX || in->hsync_start > USHRT_MAX || 1758 - in->hsync_end > USHRT_MAX || in->htotal > USHRT_MAX || 1759 - in->hskew > USHRT_MAX || in->vdisplay > USHRT_MAX || 1760 - in->vsync_start > USHRT_MAX || in->vsync_end > USHRT_MAX || 1761 - in->vtotal > USHRT_MAX || in->vscan > USHRT_MAX, 1762 - "timing values too large for mode info\n"); 1763 - 1764 - out->clock = in->clock; 1765 - out->hdisplay = in->hdisplay; 1766 - out->hsync_start = in->hsync_start; 1767 - out->hsync_end = in->hsync_end; 1768 - out->htotal = in->htotal; 1769 - out->hskew = in->hskew; 1770 - out->vdisplay = in->vdisplay; 1771 - out->vsync_start = in->vsync_start; 1772 - out->vsync_end = in->vsync_end; 1773 - out->vtotal = in->vtotal; 1774 - out->vscan = in->vscan; 1775 - out->vrefresh = in->vrefresh; 1776 - out->flags = in->flags; 1777 - out->type = in->type; 1778 - strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN); 1779 - out->name[DRM_DISPLAY_MODE_LEN-1] = 0; 1780 - } 1781 - 1782 - /** 1783 - * drm_crtc_convert_umode - convert a modeinfo into a drm_display_mode 1784 - * @out: drm_display_mode to return to the user 1785 - * @in: drm_mode_modeinfo to use 1786 - * 1787 - * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to 1788 - * the caller. 1789 - * 1790 - * Returns: 1791 - * Zero on success, negative errno on failure. 1792 - */ 1793 - static int drm_crtc_convert_umode(struct drm_display_mode *out, 1794 - const struct drm_mode_modeinfo *in) 1795 - { 1796 - if (in->clock > INT_MAX || in->vrefresh > INT_MAX) 1797 - return -ERANGE; 1798 - 1799 - if ((in->flags & DRM_MODE_FLAG_3D_MASK) > DRM_MODE_FLAG_3D_MAX) 1800 - return -EINVAL; 1801 - 1802 - out->clock = in->clock; 1803 - out->hdisplay = in->hdisplay; 1804 - out->hsync_start = in->hsync_start; 1805 - out->hsync_end = in->hsync_end; 1806 - out->htotal = in->htotal; 1807 - out->hskew = in->hskew; 1808 - out->vdisplay = in->vdisplay; 1809 - out->vsync_start = in->vsync_start; 1810 - out->vsync_end = in->vsync_end; 1811 - out->vtotal = in->vtotal; 1812 - out->vscan = in->vscan; 1813 - out->vrefresh = in->vrefresh; 1814 - out->flags = in->flags; 1815 - out->type = in->type; 1816 - strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN); 1817 - out->name[DRM_DISPLAY_MODE_LEN-1] = 0; 1818 - 1819 - return 0; 1820 - } 1821 - 1822 - /** 1823 1739 * drm_mode_getresources - get graphics configuration 1824 1740 * @dev: drm device for the ioctl 1825 1741 * @data: data pointer for the ioctl ··· 1969 2037 crtc_resp->x = crtc->primary->state->src_x >> 16; 1970 2038 crtc_resp->y = crtc->primary->state->src_y >> 16; 1971 2039 if (crtc->state->enable) { 1972 - drm_crtc_convert_to_umode(&crtc_resp->mode, &crtc->state->mode); 2040 + drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->state->mode); 1973 2041 crtc_resp->mode_valid = 1; 1974 2042 1975 2043 } else { ··· 1979 2047 crtc_resp->x = crtc->x; 1980 2048 crtc_resp->y = crtc->y; 1981 2049 if (crtc->enabled) { 1982 - drm_crtc_convert_to_umode(&crtc_resp->mode, &crtc->mode); 2050 + drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->mode); 1983 2051 crtc_resp->mode_valid = 1; 1984 2052 1985 2053 } else { ··· 2136 2204 if (!drm_mode_expose_to_userspace(mode, file_priv)) 2137 2205 continue; 2138 2206 2139 - drm_crtc_convert_to_umode(&u_mode, mode); 2207 + drm_mode_convert_to_umode(&u_mode, mode); 2140 2208 if (copy_to_user(mode_ptr + copied, 2141 2209 &u_mode, sizeof(u_mode))) { 2142 2210 ret = -EFAULT; ··· 2747 2815 goto out; 2748 2816 } 2749 2817 2750 - ret = drm_crtc_convert_umode(mode, &crtc_req->mode); 2818 + ret = drm_mode_convert_umode(mode, &crtc_req->mode); 2751 2819 if (ret) { 2752 2820 DRM_DEBUG_KMS("Invalid mode\n"); 2753 - goto out; 2754 - } 2755 - 2756 - mode->status = drm_mode_validate_basic(mode); 2757 - if (mode->status != MODE_OK) { 2758 - ret = -EINVAL; 2759 2821 goto out; 2760 2822 } 2761 2823 ··· 3253 3327 if (r->modifier[i] && !(r->flags & DRM_MODE_FB_MODIFIERS)) { 3254 3328 DRM_DEBUG_KMS("bad fb modifier %llu for plane %d\n", 3255 3329 r->modifier[i], i); 3330 + return -EINVAL; 3331 + } 3332 + } 3333 + 3334 + for (i = num_planes; i < 4; i++) { 3335 + if (r->modifier[i]) { 3336 + DRM_DEBUG_KMS("non-zero modifier for unused plane %d\n", i); 3337 + return -EINVAL; 3338 + } 3339 + 3340 + /* Pre-FB_MODIFIERS userspace didn't clear the structs properly. */ 3341 + if (!(r->flags & DRM_MODE_FB_MODIFIERS)) 3342 + continue; 3343 + 3344 + if (r->handles[i]) { 3345 + DRM_DEBUG_KMS("buffer object handle for unused plane %d\n", i); 3346 + return -EINVAL; 3347 + } 3348 + 3349 + if (r->pitches[i]) { 3350 + DRM_DEBUG_KMS("non-zero pitch for unused plane %d\n", i); 3351 + return -EINVAL; 3352 + } 3353 + 3354 + if (r->offsets[i]) { 3355 + DRM_DEBUG_KMS("non-zero offset for unused plane %d\n", i); 3256 3356 return -EINVAL; 3257 3357 } 3258 3358 } ··· 4179 4227 return ret; 4180 4228 } 4181 4229 4230 + /** 4231 + * drm_property_create_blob - Create new blob property 4232 + * 4233 + * Creates a new blob property for a specified DRM device, optionally 4234 + * copying data. 4235 + * 4236 + * @dev: DRM device to create property for 4237 + * @length: Length to allocate for blob data 4238 + * @data: If specified, copies data into blob 4239 + * 4240 + * Returns: 4241 + * New blob property with a single reference on success, or an ERR_PTR 4242 + * value on failure. 4243 + */ 4182 4244 struct drm_property_blob * 4183 4245 drm_property_create_blob(struct drm_device *dev, size_t length, 4184 4246 const void *data) ··· 4200 4234 struct drm_property_blob *blob; 4201 4235 int ret; 4202 4236 4203 - if (!length || !data) 4204 - return NULL; 4237 + if (!length) 4238 + return ERR_PTR(-EINVAL); 4205 4239 4206 4240 blob = kzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL); 4207 4241 if (!blob) 4208 - return NULL; 4242 + return ERR_PTR(-ENOMEM); 4209 4243 4244 + /* This must be explicitly initialised, so we can safely call list_del 4245 + * on it in the removal handler, even if it isn't in a file list. */ 4246 + INIT_LIST_HEAD(&blob->head_file); 4210 4247 blob->length = length; 4211 4248 blob->dev = dev; 4212 4249 4213 - memcpy(blob->data, data, length); 4250 + if (data) 4251 + memcpy(blob->data, data, length); 4214 4252 4215 4253 mutex_lock(&dev->mode_config.blob_lock); 4216 4254 ··· 4222 4252 if (ret) { 4223 4253 kfree(blob); 4224 4254 mutex_unlock(&dev->mode_config.blob_lock); 4225 - return NULL; 4255 + return ERR_PTR(-EINVAL); 4226 4256 } 4227 4257 4228 4258 kref_init(&blob->refcount); 4229 4259 4230 - list_add_tail(&blob->head, &dev->mode_config.property_blob_list); 4260 + list_add_tail(&blob->head_global, 4261 + &dev->mode_config.property_blob_list); 4231 4262 4232 4263 mutex_unlock(&dev->mode_config.blob_lock); 4233 4264 ··· 4241 4270 * 4242 4271 * Internal free function for blob properties; must not be used directly. 4243 4272 * 4244 - * @param kref Reference 4273 + * @kref: Reference 4245 4274 */ 4246 4275 static void drm_property_free_blob(struct kref *kref) 4247 4276 { ··· 4250 4279 4251 4280 WARN_ON(!mutex_is_locked(&blob->dev->mode_config.blob_lock)); 4252 4281 4253 - list_del(&blob->head); 4282 + list_del(&blob->head_global); 4283 + list_del(&blob->head_file); 4254 4284 drm_mode_object_put(blob->dev, &blob->base); 4255 4285 4256 4286 kfree(blob); ··· 4262 4290 * 4263 4291 * Drop a reference on a blob property. May free the object. 4264 4292 * 4265 - * @param blob Pointer to blob property 4293 + * @blob: Pointer to blob property 4266 4294 */ 4267 4295 void drm_property_unreference_blob(struct drm_property_blob *blob) 4268 4296 { ··· 4290 4318 * Drop a reference on a blob property. May free the object. This must be 4291 4319 * called with blob_lock held. 4292 4320 * 4293 - * @param dev Device the blob was created on 4294 - * @param blob Pointer to blob property 4321 + * @blob: Pointer to blob property 4295 4322 */ 4296 4323 static void drm_property_unreference_blob_locked(struct drm_property_blob *blob) 4297 4324 { ··· 4303 4332 } 4304 4333 4305 4334 /** 4335 + * drm_property_destroy_user_blobs - destroy all blobs created by this client 4336 + * @dev: DRM device 4337 + * @file_priv: destroy all blobs owned by this file handle 4338 + */ 4339 + void drm_property_destroy_user_blobs(struct drm_device *dev, 4340 + struct drm_file *file_priv) 4341 + { 4342 + struct drm_property_blob *blob, *bt; 4343 + 4344 + mutex_lock(&dev->mode_config.blob_lock); 4345 + 4346 + list_for_each_entry_safe(blob, bt, &file_priv->blobs, head_file) { 4347 + list_del_init(&blob->head_file); 4348 + drm_property_unreference_blob_locked(blob); 4349 + } 4350 + 4351 + mutex_unlock(&dev->mode_config.blob_lock); 4352 + } 4353 + 4354 + /** 4306 4355 * drm_property_reference_blob - Take a reference on an existing property 4307 4356 * 4308 4357 * Take a new reference on an existing blob property. 4309 4358 * 4310 - * @param blob Pointer to blob property 4359 + * @blob: Pointer to blob property 4311 4360 */ 4312 4361 struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob) 4313 4362 { ··· 4433 4442 4434 4443 if (length && data) { 4435 4444 new_blob = drm_property_create_blob(dev, length, data); 4436 - if (!new_blob) 4437 - return -EINVAL; 4445 + if (IS_ERR(new_blob)) 4446 + return PTR_ERR(new_blob); 4438 4447 } 4439 4448 4440 4449 /* This does not need to be synchronised with blob_lock, as the ··· 4508 4517 done: 4509 4518 mutex_unlock(&dev->mode_config.blob_lock); 4510 4519 drm_modeset_unlock_all(dev); 4520 + return ret; 4521 + } 4522 + 4523 + /** 4524 + * drm_mode_createblob_ioctl - create a new blob property 4525 + * @dev: DRM device 4526 + * @data: ioctl data 4527 + * @file_priv: DRM file info 4528 + * 4529 + * This function creates a new blob property with user-defined values. In order 4530 + * to give us sensible validation and checking when creating, rather than at 4531 + * every potential use, we also require a type to be provided upfront. 4532 + * 4533 + * Called by the user via ioctl. 4534 + * 4535 + * Returns: 4536 + * Zero on success, negative errno on failure. 4537 + */ 4538 + int drm_mode_createblob_ioctl(struct drm_device *dev, 4539 + void *data, struct drm_file *file_priv) 4540 + { 4541 + struct drm_mode_create_blob *out_resp = data; 4542 + struct drm_property_blob *blob; 4543 + void __user *blob_ptr; 4544 + int ret = 0; 4545 + 4546 + if (!drm_core_check_feature(dev, DRIVER_MODESET)) 4547 + return -EINVAL; 4548 + 4549 + blob = drm_property_create_blob(dev, out_resp->length, NULL); 4550 + if (IS_ERR(blob)) 4551 + return PTR_ERR(blob); 4552 + 4553 + blob_ptr = (void __user *)(unsigned long)out_resp->data; 4554 + if (copy_from_user(blob->data, blob_ptr, out_resp->length)) { 4555 + ret = -EFAULT; 4556 + goto out_blob; 4557 + } 4558 + 4559 + /* Dropping the lock between create_blob and our access here is safe 4560 + * as only the same file_priv can remove the blob; at this point, it is 4561 + * not associated with any file_priv. */ 4562 + mutex_lock(&dev->mode_config.blob_lock); 4563 + out_resp->blob_id = blob->base.id; 4564 + list_add_tail(&file_priv->blobs, &blob->head_file); 4565 + mutex_unlock(&dev->mode_config.blob_lock); 4566 + 4567 + return 0; 4568 + 4569 + out_blob: 4570 + drm_property_unreference_blob(blob); 4571 + return ret; 4572 + } 4573 + 4574 + /** 4575 + * drm_mode_destroyblob_ioctl - destroy a user blob property 4576 + * @dev: DRM device 4577 + * @data: ioctl data 4578 + * @file_priv: DRM file info 4579 + * 4580 + * Destroy an existing user-defined blob property. 4581 + * 4582 + * Called by the user via ioctl. 4583 + * 4584 + * Returns: 4585 + * Zero on success, negative errno on failure. 4586 + */ 4587 + int drm_mode_destroyblob_ioctl(struct drm_device *dev, 4588 + void *data, struct drm_file *file_priv) 4589 + { 4590 + struct drm_mode_destroy_blob *out_resp = data; 4591 + struct drm_property_blob *blob = NULL, *bt; 4592 + bool found = false; 4593 + int ret = 0; 4594 + 4595 + if (!drm_core_check_feature(dev, DRIVER_MODESET)) 4596 + return -EINVAL; 4597 + 4598 + mutex_lock(&dev->mode_config.blob_lock); 4599 + blob = __drm_property_lookup_blob(dev, out_resp->blob_id); 4600 + if (!blob) { 4601 + ret = -ENOENT; 4602 + goto err; 4603 + } 4604 + 4605 + /* Ensure the property was actually created by this user. */ 4606 + list_for_each_entry(bt, &file_priv->blobs, head_file) { 4607 + if (bt == blob) { 4608 + found = true; 4609 + break; 4610 + } 4611 + } 4612 + 4613 + if (!found) { 4614 + ret = -EPERM; 4615 + goto err; 4616 + } 4617 + 4618 + /* We must drop head_file here, because we may not be the last 4619 + * reference on the blob. */ 4620 + list_del_init(&blob->head_file); 4621 + drm_property_unreference_blob_locked(blob); 4622 + mutex_unlock(&dev->mode_config.blob_lock); 4623 + 4624 + return 0; 4625 + 4626 + err: 4627 + mutex_unlock(&dev->mode_config.blob_lock); 4511 4628 return ret; 4512 4629 } 4513 4630 ··· 4809 4710 if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) { 4810 4711 if (property->values[0] == DRM_MODE_OBJECT_FB) 4811 4712 drm_framebuffer_unreference(obj_to_fb(ref)); 4812 - } 4713 + } else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) 4714 + drm_property_unreference_blob(obj_to_blob(ref)); 4813 4715 } 4814 4716 4815 4717 /** ··· 5823 5723 } 5824 5724 5825 5725 list_for_each_entry_safe(blob, bt, &dev->mode_config.property_blob_list, 5826 - head) { 5726 + head_global) { 5827 5727 drm_property_unreference_blob(blob); 5828 5728 } 5829 5729
+42 -59
drivers/gpu/drm/drm_crtc_helper.c
··· 163 163 { 164 164 const struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; 165 165 166 - if (encoder->bridge) 167 - encoder->bridge->funcs->disable(encoder->bridge); 166 + drm_bridge_disable(encoder->bridge); 168 167 169 168 if (encoder_funcs->disable) 170 169 (*encoder_funcs->disable)(encoder); 171 170 else 172 171 (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF); 173 172 174 - if (encoder->bridge) 175 - encoder->bridge->funcs->post_disable(encoder->bridge); 173 + drm_bridge_post_disable(encoder->bridge); 176 174 } 177 175 178 176 static void __drm_helper_disable_unused_functions(struct drm_device *dev) ··· 310 312 if (encoder->crtc != crtc) 311 313 continue; 312 314 313 - if (encoder->bridge && encoder->bridge->funcs->mode_fixup) { 314 - ret = encoder->bridge->funcs->mode_fixup( 315 - encoder->bridge, mode, adjusted_mode); 316 - if (!ret) { 317 - DRM_DEBUG_KMS("Bridge fixup failed\n"); 318 - goto done; 319 - } 315 + ret = drm_bridge_mode_fixup(encoder->bridge, 316 + mode, adjusted_mode); 317 + if (!ret) { 318 + DRM_DEBUG_KMS("Bridge fixup failed\n"); 319 + goto done; 320 320 } 321 321 322 322 encoder_funcs = encoder->helper_private; ··· 339 343 if (encoder->crtc != crtc) 340 344 continue; 341 345 342 - if (encoder->bridge) 343 - encoder->bridge->funcs->disable(encoder->bridge); 346 + drm_bridge_disable(encoder->bridge); 344 347 345 348 encoder_funcs = encoder->helper_private; 346 349 /* Disable the encoders as the first thing we do. */ 347 350 encoder_funcs->prepare(encoder); 348 351 349 - if (encoder->bridge) 350 - encoder->bridge->funcs->post_disable(encoder->bridge); 352 + drm_bridge_post_disable(encoder->bridge); 351 353 } 352 354 353 355 drm_crtc_prepare_encoders(dev); ··· 370 376 encoder_funcs = encoder->helper_private; 371 377 encoder_funcs->mode_set(encoder, mode, adjusted_mode); 372 378 373 - if (encoder->bridge && encoder->bridge->funcs->mode_set) 374 - encoder->bridge->funcs->mode_set(encoder->bridge, mode, 375 - adjusted_mode); 379 + drm_bridge_mode_set(encoder->bridge, mode, adjusted_mode); 376 380 } 377 381 378 382 /* Now enable the clocks, plane, pipe, and connectors that we set up. */ ··· 381 389 if (encoder->crtc != crtc) 382 390 continue; 383 391 384 - if (encoder->bridge) 385 - encoder->bridge->funcs->pre_enable(encoder->bridge); 392 + drm_bridge_pre_enable(encoder->bridge); 386 393 387 394 encoder_funcs = encoder->helper_private; 388 395 encoder_funcs->commit(encoder); 389 396 390 - if (encoder->bridge) 391 - encoder->bridge->funcs->enable(encoder->bridge); 397 + drm_bridge_enable(encoder->bridge); 392 398 } 393 399 394 400 /* Calculate and store various constants which ··· 725 735 struct drm_bridge *bridge = encoder->bridge; 726 736 const struct drm_encoder_helper_funcs *encoder_funcs; 727 737 728 - if (bridge) { 729 - if (mode == DRM_MODE_DPMS_ON) 730 - bridge->funcs->pre_enable(bridge); 731 - else 732 - bridge->funcs->disable(bridge); 733 - } 738 + if (mode == DRM_MODE_DPMS_ON) 739 + drm_bridge_pre_enable(bridge); 740 + else 741 + drm_bridge_disable(bridge); 734 742 735 743 encoder_funcs = encoder->helper_private; 736 744 if (encoder_funcs->dpms) 737 745 encoder_funcs->dpms(encoder, mode); 738 746 739 - if (bridge) { 740 - if (mode == DRM_MODE_DPMS_ON) 741 - bridge->funcs->enable(bridge); 742 - else 743 - bridge->funcs->post_disable(bridge); 744 - } 747 + if (mode == DRM_MODE_DPMS_ON) 748 + drm_bridge_enable(bridge); 749 + else 750 + drm_bridge_post_disable(bridge); 745 751 } 746 752 747 753 static int drm_helper_choose_crtc_dpms(struct drm_crtc *crtc) ··· 927 941 928 942 if (crtc->funcs->atomic_duplicate_state) 929 943 crtc_state = crtc->funcs->atomic_duplicate_state(crtc); 930 - else if (crtc->state) 931 - crtc_state = kmemdup(crtc->state, sizeof(*crtc_state), 932 - GFP_KERNEL); 933 - else 944 + else { 934 945 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); 935 - if (!crtc_state) 936 - return -ENOMEM; 937 - crtc_state->crtc = crtc; 946 + if (!crtc_state) 947 + return -ENOMEM; 948 + if (crtc->state) 949 + __drm_atomic_helper_crtc_duplicate_state(crtc, crtc_state); 950 + else 951 + crtc_state->crtc = crtc; 952 + } 938 953 939 - crtc_state->enable = true; 940 954 crtc_state->planes_changed = true; 941 955 crtc_state->mode_changed = true; 942 - drm_mode_copy(&crtc_state->mode, mode); 956 + ret = drm_atomic_set_mode_for_crtc(crtc_state, mode); 957 + if (ret) 958 + goto out; 943 959 drm_mode_copy(&crtc_state->adjusted_mode, adjusted_mode); 944 960 945 961 if (crtc_funcs->atomic_check) { 946 962 ret = crtc_funcs->atomic_check(crtc, crtc_state); 947 - if (ret) { 948 - if (crtc->funcs->atomic_destroy_state) { 949 - crtc->funcs->atomic_destroy_state(crtc, 950 - crtc_state); 951 - } else { 952 - kfree(crtc_state); 953 - } 954 - 955 - return ret; 956 - } 963 + if (ret) 964 + goto out; 957 965 } 958 966 959 967 swap(crtc->state, crtc_state); 960 968 961 969 crtc_funcs->mode_set_nofb(crtc); 962 970 963 - if (crtc_state) { 964 - if (crtc->funcs->atomic_destroy_state) 965 - crtc->funcs->atomic_destroy_state(crtc, crtc_state); 966 - else 967 - kfree(crtc_state); 971 + ret = drm_helper_crtc_mode_set_base(crtc, x, y, old_fb); 972 + 973 + out: 974 + if (crtc->funcs->atomic_destroy_state) 975 + crtc->funcs->atomic_destroy_state(crtc, crtc_state); 976 + else { 977 + __drm_atomic_helper_crtc_destroy_state(crtc, crtc_state); 978 + kfree(crtc_state); 968 979 } 969 980 970 - return drm_helper_crtc_mode_set_base(crtc, x, y, old_fb); 981 + return ret; 971 982 } 972 983 EXPORT_SYMBOL(drm_helper_crtc_mode_set); 973 984
+4 -1
drivers/gpu/drm/drm_fops.c
··· 167 167 INIT_LIST_HEAD(&priv->lhead); 168 168 INIT_LIST_HEAD(&priv->fbs); 169 169 mutex_init(&priv->fbs_lock); 170 + INIT_LIST_HEAD(&priv->blobs); 170 171 INIT_LIST_HEAD(&priv->event_list); 171 172 init_waitqueue_head(&priv->event_wait); 172 173 priv->event_space = 4096; /* set aside 4k for event buffer */ ··· 406 405 407 406 drm_events_release(file_priv); 408 407 409 - if (drm_core_check_feature(dev, DRIVER_MODESET)) 408 + if (drm_core_check_feature(dev, DRIVER_MODESET)) { 410 409 drm_fb_release(file_priv); 410 + drm_property_destroy_user_blobs(dev, file_priv); 411 + } 411 412 412 413 if (drm_core_check_feature(dev, DRIVER_GEM)) 413 414 drm_gem_release(dev, file_priv);
+2
drivers/gpu/drm/drm_ioctl.c
··· 641 641 DRM_IOCTL_DEF(DRM_IOCTL_MODE_OBJ_SETPROPERTY, drm_mode_obj_set_property_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), 642 642 DRM_IOCTL_DEF(DRM_IOCTL_MODE_CURSOR2, drm_mode_cursor2_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), 643 643 DRM_IOCTL_DEF(DRM_IOCTL_MODE_ATOMIC, drm_mode_atomic_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), 644 + DRM_IOCTL_DEF(DRM_IOCTL_MODE_CREATEPROPBLOB, drm_mode_createblob_ioctl, DRM_CONTROL_ALLOW|DRM_UNLOCKED), 645 + DRM_IOCTL_DEF(DRM_IOCTL_MODE_DESTROYPROPBLOB, drm_mode_destroyblob_ioctl, DRM_CONTROL_ALLOW|DRM_UNLOCKED), 644 646 }; 645 647 646 648 #define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )
+2 -2
drivers/gpu/drm/drm_irq.c
··· 130 130 /* 131 131 * Interrupts were disabled prior to this call, so deal with counter 132 132 * wrap if needed. 133 - * NOTE! It's possible we lost a full dev->max_vblank_count events 133 + * NOTE! It's possible we lost a full dev->max_vblank_count + 1 events 134 134 * here if the register is small or we had vblank interrupts off for 135 135 * a long time. 136 136 * ··· 147 147 /* Deal with counter wrap */ 148 148 diff = cur_vblank - vblank->last; 149 149 if (cur_vblank < vblank->last) { 150 - diff += dev->max_vblank_count; 150 + diff += dev->max_vblank_count + 1; 151 151 152 152 DRM_DEBUG("last_vblank[%d]=0x%x, cur_vblank=0x%x => diff=0x%x\n", 153 153 crtc, vblank->last, cur_vblank, diff);
+87
drivers/gpu/drm/drm_modes.c
··· 1405 1405 return mode; 1406 1406 } 1407 1407 EXPORT_SYMBOL(drm_mode_create_from_cmdline_mode); 1408 + 1409 + /** 1410 + * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo 1411 + * @out: drm_mode_modeinfo struct to return to the user 1412 + * @in: drm_display_mode to use 1413 + * 1414 + * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to 1415 + * the user. 1416 + */ 1417 + void drm_mode_convert_to_umode(struct drm_mode_modeinfo *out, 1418 + const struct drm_display_mode *in) 1419 + { 1420 + WARN(in->hdisplay > USHRT_MAX || in->hsync_start > USHRT_MAX || 1421 + in->hsync_end > USHRT_MAX || in->htotal > USHRT_MAX || 1422 + in->hskew > USHRT_MAX || in->vdisplay > USHRT_MAX || 1423 + in->vsync_start > USHRT_MAX || in->vsync_end > USHRT_MAX || 1424 + in->vtotal > USHRT_MAX || in->vscan > USHRT_MAX, 1425 + "timing values too large for mode info\n"); 1426 + 1427 + out->clock = in->clock; 1428 + out->hdisplay = in->hdisplay; 1429 + out->hsync_start = in->hsync_start; 1430 + out->hsync_end = in->hsync_end; 1431 + out->htotal = in->htotal; 1432 + out->hskew = in->hskew; 1433 + out->vdisplay = in->vdisplay; 1434 + out->vsync_start = in->vsync_start; 1435 + out->vsync_end = in->vsync_end; 1436 + out->vtotal = in->vtotal; 1437 + out->vscan = in->vscan; 1438 + out->vrefresh = in->vrefresh; 1439 + out->flags = in->flags; 1440 + out->type = in->type; 1441 + strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN); 1442 + out->name[DRM_DISPLAY_MODE_LEN-1] = 0; 1443 + } 1444 + 1445 + /** 1446 + * drm_crtc_convert_umode - convert a modeinfo into a drm_display_mode 1447 + * @out: drm_display_mode to return to the user 1448 + * @in: drm_mode_modeinfo to use 1449 + * 1450 + * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to 1451 + * the caller. 1452 + * 1453 + * Returns: 1454 + * Zero on success, negative errno on failure. 1455 + */ 1456 + int drm_mode_convert_umode(struct drm_display_mode *out, 1457 + const struct drm_mode_modeinfo *in) 1458 + { 1459 + int ret = -EINVAL; 1460 + 1461 + if (in->clock > INT_MAX || in->vrefresh > INT_MAX) { 1462 + ret = -ERANGE; 1463 + goto out; 1464 + } 1465 + 1466 + if ((in->flags & DRM_MODE_FLAG_3D_MASK) > DRM_MODE_FLAG_3D_MAX) 1467 + goto out; 1468 + 1469 + out->clock = in->clock; 1470 + out->hdisplay = in->hdisplay; 1471 + out->hsync_start = in->hsync_start; 1472 + out->hsync_end = in->hsync_end; 1473 + out->htotal = in->htotal; 1474 + out->hskew = in->hskew; 1475 + out->vdisplay = in->vdisplay; 1476 + out->vsync_start = in->vsync_start; 1477 + out->vsync_end = in->vsync_end; 1478 + out->vtotal = in->vtotal; 1479 + out->vscan = in->vscan; 1480 + out->vrefresh = in->vrefresh; 1481 + out->flags = in->flags; 1482 + out->type = in->type; 1483 + strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN); 1484 + out->name[DRM_DISPLAY_MODE_LEN-1] = 0; 1485 + 1486 + out->status = drm_mode_validate_basic(out); 1487 + if (out->status != MODE_OK) 1488 + goto out; 1489 + 1490 + ret = 0; 1491 + 1492 + out: 1493 + return ret; 1494 + }
+4
include/drm/drmP.h
··· 326 326 struct list_head fbs; 327 327 struct mutex fbs_lock; 328 328 329 + /** User-created blob properties; this retains a reference on the 330 + * property. */ 331 + struct list_head blobs; 332 + 329 333 wait_queue_head_t event_wait; 330 334 struct list_head event_list; 331 335 int event_space;
+22 -12
include/drm/drm_atomic.h
··· 110 110 } 111 111 112 112 int __must_check 113 + drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state, 114 + struct drm_display_mode *mode); 115 + int __must_check 116 + drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state, 117 + struct drm_property_blob *blob); 118 + int __must_check 113 119 drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state, 114 120 struct drm_crtc *crtc); 115 121 void drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state, ··· 126 120 int __must_check 127 121 drm_atomic_add_affected_connectors(struct drm_atomic_state *state, 128 122 struct drm_crtc *crtc); 123 + int __must_check 124 + drm_atomic_add_affected_planes(struct drm_atomic_state *state, 125 + struct drm_crtc *crtc); 126 + 129 127 int 130 128 drm_atomic_connectors_for_crtc(struct drm_atomic_state *state, 131 129 struct drm_crtc *crtc); ··· 142 132 143 133 #define for_each_connector_in_state(state, connector, connector_state, __i) \ 144 134 for ((__i) = 0; \ 145 - (connector) = (state)->connectors[__i], \ 146 - (connector_state) = (state)->connector_states[__i], \ 147 - (__i) < (state)->num_connector; \ 135 + (__i) < (state)->num_connector && \ 136 + ((connector) = (state)->connectors[__i], \ 137 + (connector_state) = (state)->connector_states[__i], 1); \ 148 138 (__i)++) \ 149 139 if (connector) 150 140 151 141 #define for_each_crtc_in_state(state, crtc, crtc_state, __i) \ 152 142 for ((__i) = 0; \ 153 - (crtc) = (state)->crtcs[__i], \ 154 - (crtc_state) = (state)->crtc_states[__i], \ 155 - (__i) < (state)->dev->mode_config.num_crtc; \ 143 + (__i) < (state)->dev->mode_config.num_crtc && \ 144 + ((crtc) = (state)->crtcs[__i], \ 145 + (crtc_state) = (state)->crtc_states[__i], 1); \ 156 146 (__i)++) \ 157 147 if (crtc_state) 158 148 159 - #define for_each_plane_in_state(state, plane, plane_state, __i) \ 160 - for ((__i) = 0; \ 161 - (plane) = (state)->planes[__i], \ 162 - (plane_state) = (state)->plane_states[__i], \ 163 - (__i) < (state)->dev->mode_config.num_total_plane; \ 164 - (__i)++) \ 149 + #define for_each_plane_in_state(state, plane, plane_state, __i) \ 150 + for ((__i) = 0; \ 151 + (__i) < (state)->dev->mode_config.num_total_plane && \ 152 + ((plane) = (state)->planes[__i], \ 153 + (plane_state) = (state)->plane_states[__i], 1); \ 154 + (__i)++) \ 165 155 if (plane_state) 166 156 167 157 #endif /* DRM_ATOMIC_H_ */
+1
include/drm/drm_atomic_helper.h
··· 58 58 struct drm_atomic_state *state); 59 59 void drm_atomic_helper_cleanup_planes(struct drm_device *dev, 60 60 struct drm_atomic_state *old_state); 61 + void drm_atomic_helper_commit_planes_on_crtc(struct drm_crtc_state *old_crtc_state); 61 62 62 63 void drm_atomic_helper_swap_state(struct drm_device *dev, 63 64 struct drm_atomic_state *state);
+26 -1
include/drm/drm_crtc.h
··· 218 218 struct drm_mode_object base; 219 219 struct drm_device *dev; 220 220 struct kref refcount; 221 - struct list_head head; 221 + struct list_head head_global; 222 + struct list_head head_file; 222 223 size_t length; 223 224 unsigned char data[]; 224 225 }; ··· 298 297 struct drm_display_mode adjusted_mode; 299 298 300 299 struct drm_display_mode mode; 300 + 301 + /* blob property to expose current mode to atomic userspace */ 302 + struct drm_property_blob *mode_blob; 301 303 302 304 struct drm_pending_vblank_event *event; 303 305 ··· 907 903 /** 908 904 * struct drm_bridge - central DRM bridge control structure 909 905 * @dev: DRM device this bridge belongs to 906 + * @encoder: encoder to which this bridge is connected 907 + * @next: the next bridge in the encoder chain 910 908 * @of_node: device node pointer to the bridge 911 909 * @list: to keep track of all added bridges 912 910 * @base: base mode object ··· 918 912 struct drm_bridge { 919 913 struct drm_device *dev; 920 914 struct drm_encoder *encoder; 915 + struct drm_bridge *next; 921 916 #ifdef CONFIG_OF 922 917 struct device_node *of_node; 923 918 #endif ··· 1146 1139 struct drm_property *prop_fb_id; 1147 1140 struct drm_property *prop_crtc_id; 1148 1141 struct drm_property *prop_active; 1142 + struct drm_property *prop_mode_id; 1149 1143 1150 1144 /* DVI-I properties */ 1151 1145 struct drm_property *dvi_i_subconnector_property; ··· 1255 1247 extern struct drm_bridge *of_drm_find_bridge(struct device_node *np); 1256 1248 extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge); 1257 1249 1250 + bool drm_bridge_mode_fixup(struct drm_bridge *bridge, 1251 + const struct drm_display_mode *mode, 1252 + struct drm_display_mode *adjusted_mode); 1253 + void drm_bridge_disable(struct drm_bridge *bridge); 1254 + void drm_bridge_post_disable(struct drm_bridge *bridge); 1255 + void drm_bridge_mode_set(struct drm_bridge *bridge, 1256 + struct drm_display_mode *mode, 1257 + struct drm_display_mode *adjusted_mode); 1258 + void drm_bridge_pre_enable(struct drm_bridge *bridge); 1259 + void drm_bridge_enable(struct drm_bridge *bridge); 1260 + 1258 1261 extern int drm_encoder_init(struct drm_device *dev, 1259 1262 struct drm_encoder *encoder, 1260 1263 const struct drm_encoder_funcs *funcs, ··· 1320 1301 extern const char *drm_get_tv_subconnector_name(int val); 1321 1302 extern const char *drm_get_tv_select_name(int val); 1322 1303 extern void drm_fb_release(struct drm_file *file_priv); 1304 + extern void drm_property_destroy_user_blobs(struct drm_device *dev, 1305 + struct drm_file *file_priv); 1323 1306 extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group); 1324 1307 extern void drm_mode_group_destroy(struct drm_mode_group *group); 1325 1308 extern void drm_reinit_primary_mode_group(struct drm_device *dev); ··· 1467 1446 void *data, struct drm_file *file_priv); 1468 1447 extern int drm_mode_getblob_ioctl(struct drm_device *dev, 1469 1448 void *data, struct drm_file *file_priv); 1449 + extern int drm_mode_createblob_ioctl(struct drm_device *dev, 1450 + void *data, struct drm_file *file_priv); 1451 + extern int drm_mode_destroyblob_ioctl(struct drm_device *dev, 1452 + void *data, struct drm_file *file_priv); 1470 1453 extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev, 1471 1454 void *data, struct drm_file *file_priv); 1472 1455 extern int drm_mode_getencoder(struct drm_device *dev,
+4
include/drm/drm_modes.h
··· 182 182 183 183 struct drm_display_mode *drm_mode_create(struct drm_device *dev); 184 184 void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode); 185 + void drm_mode_convert_to_umode(struct drm_mode_modeinfo *out, 186 + const struct drm_display_mode *in); 187 + int drm_mode_convert_umode(struct drm_display_mode *out, 188 + const struct drm_mode_modeinfo *in); 185 189 void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode); 186 190 void drm_mode_debug_printmodeline(const struct drm_display_mode *mode); 187 191
+2
include/uapi/drm/drm.h
··· 786 786 #define DRM_IOCTL_MODE_OBJ_SETPROPERTY DRM_IOWR(0xBA, struct drm_mode_obj_set_property) 787 787 #define DRM_IOCTL_MODE_CURSOR2 DRM_IOWR(0xBB, struct drm_mode_cursor2) 788 788 #define DRM_IOCTL_MODE_ATOMIC DRM_IOWR(0xBC, struct drm_mode_atomic) 789 + #define DRM_IOCTL_MODE_CREATEPROPBLOB DRM_IOWR(0xBD, struct drm_mode_create_blob) 790 + #define DRM_IOCTL_MODE_DESTROYPROPBLOB DRM_IOWR(0xBE, struct drm_mode_destroy_blob) 789 791 790 792 /** 791 793 * Device specific ioctls should only be in their respective headers
+20
include/uapi/drm/drm_mode.h
··· 558 558 __u64 user_data; 559 559 }; 560 560 561 + /** 562 + * Create a new 'blob' data property, copying length bytes from data pointer, 563 + * and returning new blob ID. 564 + */ 565 + struct drm_mode_create_blob { 566 + /** Pointer to data to copy. */ 567 + __u64 data; 568 + /** Length of data to copy. */ 569 + __u32 length; 570 + /** Return: new property ID. */ 571 + __u32 blob_id; 572 + }; 573 + 574 + /** 575 + * Destroy a user-created blob property. 576 + */ 577 + struct drm_mode_destroy_blob { 578 + __u32 blob_id; 579 + }; 580 + 561 581 #endif