| .. | .. |
|---|
| 24 | 24 | */ |
|---|
| 25 | 25 | |
|---|
| 26 | 26 | #include <linux/list.h> |
|---|
| 27 | | -#include <drm/drmP.h> |
|---|
| 27 | + |
|---|
| 28 | +#include <drm/drm_atomic.h> |
|---|
| 29 | +#include <drm/drm_atomic_helper.h> |
|---|
| 30 | +#include <drm/drm_atomic_uapi.h> |
|---|
| 31 | +#include <drm/drm_crtc_helper.h> |
|---|
| 32 | +#include <drm/drm_device.h> |
|---|
| 33 | +#include <drm/drm_encoder.h> |
|---|
| 28 | 34 | #include <drm/drm_plane_helper.h> |
|---|
| 29 | 35 | #include <drm/drm_rect.h> |
|---|
| 30 | | -#include <drm/drm_atomic.h> |
|---|
| 31 | | -#include <drm/drm_crtc_helper.h> |
|---|
| 32 | | -#include <drm/drm_encoder.h> |
|---|
| 33 | | -#include <drm/drm_atomic_helper.h> |
|---|
| 34 | 36 | |
|---|
| 35 | 37 | #define SUBPIXEL_MASK 0xffff |
|---|
| 36 | 38 | |
|---|
| .. | .. |
|---|
| 41 | 43 | * primary plane support on top of the normal CRTC configuration interface. |
|---|
| 42 | 44 | * Since the legacy &drm_mode_config_funcs.set_config interface ties the primary |
|---|
| 43 | 45 | * plane together with the CRTC state this does not allow userspace to disable |
|---|
| 44 | | - * the primary plane itself. To avoid too much duplicated code use |
|---|
| 45 | | - * drm_plane_helper_check_update() which can be used to enforce the same |
|---|
| 46 | | - * restrictions as primary planes had thus. The default primary plane only |
|---|
| 47 | | - * expose XRBG8888 and ARGB8888 as valid pixel formats for the attached |
|---|
| 48 | | - * framebuffer. |
|---|
| 46 | + * the primary plane itself. The default primary plane only expose XRBG8888 and |
|---|
| 47 | + * ARGB8888 as valid pixel formats for the attached framebuffer. |
|---|
| 49 | 48 | * |
|---|
| 50 | 49 | * Drivers are highly recommended to implement proper support for primary |
|---|
| 51 | 50 | * planes, and newly merged drivers must not rely upon these transitional |
|---|
| .. | .. |
|---|
| 99 | 98 | return count; |
|---|
| 100 | 99 | } |
|---|
| 101 | 100 | |
|---|
| 102 | | -/** |
|---|
| 103 | | - * drm_plane_helper_check_update() - Check plane update for validity |
|---|
| 104 | | - * @plane: plane object to update |
|---|
| 105 | | - * @crtc: owning CRTC of owning plane |
|---|
| 106 | | - * @fb: framebuffer to flip onto plane |
|---|
| 107 | | - * @src: source coordinates in 16.16 fixed point |
|---|
| 108 | | - * @dst: integer destination coordinates |
|---|
| 109 | | - * @rotation: plane rotation |
|---|
| 110 | | - * @min_scale: minimum @src:@dest scaling factor in 16.16 fixed point |
|---|
| 111 | | - * @max_scale: maximum @src:@dest scaling factor in 16.16 fixed point |
|---|
| 112 | | - * @can_position: is it legal to position the plane such that it |
|---|
| 113 | | - * doesn't cover the entire crtc? This will generally |
|---|
| 114 | | - * only be false for primary planes. |
|---|
| 115 | | - * @can_update_disabled: can the plane be updated while the crtc |
|---|
| 116 | | - * is disabled? |
|---|
| 117 | | - * @visible: output parameter indicating whether plane is still visible after |
|---|
| 118 | | - * clipping |
|---|
| 119 | | - * |
|---|
| 120 | | - * Checks that a desired plane update is valid. Drivers that provide |
|---|
| 121 | | - * their own plane handling rather than helper-provided implementations may |
|---|
| 122 | | - * still wish to call this function to avoid duplication of error checking |
|---|
| 123 | | - * code. |
|---|
| 124 | | - * |
|---|
| 125 | | - * RETURNS: |
|---|
| 126 | | - * Zero if update appears valid, error code on failure |
|---|
| 127 | | - */ |
|---|
| 128 | | -int drm_plane_helper_check_update(struct drm_plane *plane, |
|---|
| 129 | | - struct drm_crtc *crtc, |
|---|
| 130 | | - struct drm_framebuffer *fb, |
|---|
| 131 | | - struct drm_rect *src, |
|---|
| 132 | | - struct drm_rect *dst, |
|---|
| 133 | | - unsigned int rotation, |
|---|
| 134 | | - int min_scale, |
|---|
| 135 | | - int max_scale, |
|---|
| 136 | | - bool can_position, |
|---|
| 137 | | - bool can_update_disabled, |
|---|
| 138 | | - bool *visible) |
|---|
| 101 | +static int drm_plane_helper_check_update(struct drm_plane *plane, |
|---|
| 102 | + struct drm_crtc *crtc, |
|---|
| 103 | + struct drm_framebuffer *fb, |
|---|
| 104 | + struct drm_rect *src, |
|---|
| 105 | + struct drm_rect *dst, |
|---|
| 106 | + unsigned int rotation, |
|---|
| 107 | + int min_scale, |
|---|
| 108 | + int max_scale, |
|---|
| 109 | + bool can_position, |
|---|
| 110 | + bool can_update_disabled, |
|---|
| 111 | + bool *visible) |
|---|
| 139 | 112 | { |
|---|
| 140 | 113 | struct drm_plane_state plane_state = { |
|---|
| 141 | 114 | .plane = plane, |
|---|
| .. | .. |
|---|
| 171 | 144 | |
|---|
| 172 | 145 | return 0; |
|---|
| 173 | 146 | } |
|---|
| 174 | | -EXPORT_SYMBOL(drm_plane_helper_check_update); |
|---|
| 175 | 147 | |
|---|
| 176 | | -/** |
|---|
| 177 | | - * drm_primary_helper_update() - Helper for primary plane update |
|---|
| 178 | | - * @plane: plane object to update |
|---|
| 179 | | - * @crtc: owning CRTC of owning plane |
|---|
| 180 | | - * @fb: framebuffer to flip onto plane |
|---|
| 181 | | - * @crtc_x: x offset of primary plane on crtc |
|---|
| 182 | | - * @crtc_y: y offset of primary plane on crtc |
|---|
| 183 | | - * @crtc_w: width of primary plane rectangle on crtc |
|---|
| 184 | | - * @crtc_h: height of primary plane rectangle on crtc |
|---|
| 185 | | - * @src_x: x offset of @fb for panning |
|---|
| 186 | | - * @src_y: y offset of @fb for panning |
|---|
| 187 | | - * @src_w: width of source rectangle in @fb |
|---|
| 188 | | - * @src_h: height of source rectangle in @fb |
|---|
| 189 | | - * @ctx: lock acquire context, not used here |
|---|
| 190 | | - * |
|---|
| 191 | | - * Provides a default plane update handler for primary planes. This is handler |
|---|
| 192 | | - * is called in response to a userspace SetPlane operation on the plane with a |
|---|
| 193 | | - * non-NULL framebuffer. We call the driver's modeset handler to update the |
|---|
| 194 | | - * framebuffer. |
|---|
| 195 | | - * |
|---|
| 196 | | - * SetPlane() on a primary plane of a disabled CRTC is not supported, and will |
|---|
| 197 | | - * return an error. |
|---|
| 198 | | - * |
|---|
| 199 | | - * Note that we make some assumptions about hardware limitations that may not be |
|---|
| 200 | | - * true for all hardware -- |
|---|
| 201 | | - * |
|---|
| 202 | | - * 1. Primary plane cannot be repositioned. |
|---|
| 203 | | - * 2. Primary plane cannot be scaled. |
|---|
| 204 | | - * 3. Primary plane must cover the entire CRTC. |
|---|
| 205 | | - * 4. Subpixel positioning is not supported. |
|---|
| 206 | | - * |
|---|
| 207 | | - * Drivers for hardware that don't have these restrictions can provide their |
|---|
| 208 | | - * own implementation rather than using this helper. |
|---|
| 209 | | - * |
|---|
| 210 | | - * RETURNS: |
|---|
| 211 | | - * Zero on success, error code on failure |
|---|
| 212 | | - */ |
|---|
| 213 | | -int drm_primary_helper_update(struct drm_plane *plane, struct drm_crtc *crtc, |
|---|
| 214 | | - struct drm_framebuffer *fb, |
|---|
| 215 | | - int crtc_x, int crtc_y, |
|---|
| 216 | | - unsigned int crtc_w, unsigned int crtc_h, |
|---|
| 217 | | - uint32_t src_x, uint32_t src_y, |
|---|
| 218 | | - uint32_t src_w, uint32_t src_h, |
|---|
| 219 | | - struct drm_modeset_acquire_ctx *ctx) |
|---|
| 148 | +static int drm_primary_helper_update(struct drm_plane *plane, struct drm_crtc *crtc, |
|---|
| 149 | + struct drm_framebuffer *fb, |
|---|
| 150 | + int crtc_x, int crtc_y, |
|---|
| 151 | + unsigned int crtc_w, unsigned int crtc_h, |
|---|
| 152 | + uint32_t src_x, uint32_t src_y, |
|---|
| 153 | + uint32_t src_w, uint32_t src_h, |
|---|
| 154 | + struct drm_modeset_acquire_ctx *ctx) |
|---|
| 220 | 155 | { |
|---|
| 221 | 156 | struct drm_mode_set set = { |
|---|
| 222 | 157 | .crtc = crtc, |
|---|
| .. | .. |
|---|
| 283 | 218 | kfree(connector_list); |
|---|
| 284 | 219 | return ret; |
|---|
| 285 | 220 | } |
|---|
| 286 | | -EXPORT_SYMBOL(drm_primary_helper_update); |
|---|
| 287 | 221 | |
|---|
| 288 | | -/** |
|---|
| 289 | | - * drm_primary_helper_disable() - Helper for primary plane disable |
|---|
| 290 | | - * @plane: plane to disable |
|---|
| 291 | | - * @ctx: lock acquire context, not used here |
|---|
| 292 | | - * |
|---|
| 293 | | - * Provides a default plane disable handler for primary planes. This is handler |
|---|
| 294 | | - * is called in response to a userspace SetPlane operation on the plane with a |
|---|
| 295 | | - * NULL framebuffer parameter. It unconditionally fails the disable call with |
|---|
| 296 | | - * -EINVAL the only way to disable the primary plane without driver support is |
|---|
| 297 | | - * to disable the entire CRTC. Which does not match the plane |
|---|
| 298 | | - * &drm_plane_funcs.disable_plane hook. |
|---|
| 299 | | - * |
|---|
| 300 | | - * Note that some hardware may be able to disable the primary plane without |
|---|
| 301 | | - * disabling the whole CRTC. Drivers for such hardware should provide their |
|---|
| 302 | | - * own disable handler that disables just the primary plane (and they'll likely |
|---|
| 303 | | - * need to provide their own update handler as well to properly re-enable a |
|---|
| 304 | | - * disabled primary plane). |
|---|
| 305 | | - * |
|---|
| 306 | | - * RETURNS: |
|---|
| 307 | | - * Unconditionally returns -EINVAL. |
|---|
| 308 | | - */ |
|---|
| 309 | | -int drm_primary_helper_disable(struct drm_plane *plane, |
|---|
| 310 | | - struct drm_modeset_acquire_ctx *ctx) |
|---|
| 222 | +static int drm_primary_helper_disable(struct drm_plane *plane, |
|---|
| 223 | + struct drm_modeset_acquire_ctx *ctx) |
|---|
| 311 | 224 | { |
|---|
| 312 | 225 | return -EINVAL; |
|---|
| 313 | 226 | } |
|---|
| 314 | | -EXPORT_SYMBOL(drm_primary_helper_disable); |
|---|
| 315 | 227 | |
|---|
| 316 | 228 | /** |
|---|
| 317 | 229 | * drm_primary_helper_destroy() - Helper for primary plane destruction |
|---|
| .. | .. |
|---|
| 334 | 246 | .destroy = drm_primary_helper_destroy, |
|---|
| 335 | 247 | }; |
|---|
| 336 | 248 | EXPORT_SYMBOL(drm_primary_helper_funcs); |
|---|
| 337 | | - |
|---|
| 338 | | -int drm_plane_helper_commit(struct drm_plane *plane, |
|---|
| 339 | | - struct drm_plane_state *plane_state, |
|---|
| 340 | | - struct drm_framebuffer *old_fb) |
|---|
| 341 | | -{ |
|---|
| 342 | | - const struct drm_plane_helper_funcs *plane_funcs; |
|---|
| 343 | | - struct drm_crtc *crtc[2]; |
|---|
| 344 | | - const struct drm_crtc_helper_funcs *crtc_funcs[2]; |
|---|
| 345 | | - int i, ret = 0; |
|---|
| 346 | | - |
|---|
| 347 | | - plane_funcs = plane->helper_private; |
|---|
| 348 | | - |
|---|
| 349 | | - /* Since this is a transitional helper we can't assume that plane->state |
|---|
| 350 | | - * is always valid. Hence we need to use plane->crtc instead of |
|---|
| 351 | | - * plane->state->crtc as the old crtc. */ |
|---|
| 352 | | - crtc[0] = plane->crtc; |
|---|
| 353 | | - crtc[1] = crtc[0] != plane_state->crtc ? plane_state->crtc : NULL; |
|---|
| 354 | | - |
|---|
| 355 | | - for (i = 0; i < 2; i++) |
|---|
| 356 | | - crtc_funcs[i] = crtc[i] ? crtc[i]->helper_private : NULL; |
|---|
| 357 | | - |
|---|
| 358 | | - if (plane_funcs->atomic_check) { |
|---|
| 359 | | - ret = plane_funcs->atomic_check(plane, plane_state); |
|---|
| 360 | | - if (ret) |
|---|
| 361 | | - goto out; |
|---|
| 362 | | - } |
|---|
| 363 | | - |
|---|
| 364 | | - if (plane_funcs->prepare_fb && plane_state->fb != old_fb) { |
|---|
| 365 | | - ret = plane_funcs->prepare_fb(plane, |
|---|
| 366 | | - plane_state); |
|---|
| 367 | | - if (ret) |
|---|
| 368 | | - goto out; |
|---|
| 369 | | - } |
|---|
| 370 | | - |
|---|
| 371 | | - /* Point of no return, commit sw state. */ |
|---|
| 372 | | - swap(plane->state, plane_state); |
|---|
| 373 | | - |
|---|
| 374 | | - for (i = 0; i < 2; i++) { |
|---|
| 375 | | - if (crtc_funcs[i] && crtc_funcs[i]->atomic_begin) |
|---|
| 376 | | - crtc_funcs[i]->atomic_begin(crtc[i], crtc[i]->state); |
|---|
| 377 | | - } |
|---|
| 378 | | - |
|---|
| 379 | | - /* |
|---|
| 380 | | - * Drivers may optionally implement the ->atomic_disable callback, so |
|---|
| 381 | | - * special-case that here. |
|---|
| 382 | | - */ |
|---|
| 383 | | - if (drm_atomic_plane_disabling(plane_state, plane->state) && |
|---|
| 384 | | - plane_funcs->atomic_disable) |
|---|
| 385 | | - plane_funcs->atomic_disable(plane, plane_state); |
|---|
| 386 | | - else |
|---|
| 387 | | - plane_funcs->atomic_update(plane, plane_state); |
|---|
| 388 | | - |
|---|
| 389 | | - for (i = 0; i < 2; i++) { |
|---|
| 390 | | - if (crtc_funcs[i] && crtc_funcs[i]->atomic_flush) |
|---|
| 391 | | - crtc_funcs[i]->atomic_flush(crtc[i], crtc[i]->state); |
|---|
| 392 | | - } |
|---|
| 393 | | - |
|---|
| 394 | | - /* |
|---|
| 395 | | - * If we only moved the plane and didn't change fb's, there's no need to |
|---|
| 396 | | - * wait for vblank. |
|---|
| 397 | | - */ |
|---|
| 398 | | - if (plane->state->fb == old_fb) |
|---|
| 399 | | - goto out; |
|---|
| 400 | | - |
|---|
| 401 | | - for (i = 0; i < 2; i++) { |
|---|
| 402 | | - if (!crtc[i]) |
|---|
| 403 | | - continue; |
|---|
| 404 | | - |
|---|
| 405 | | - if (crtc[i]->cursor == plane) |
|---|
| 406 | | - continue; |
|---|
| 407 | | - |
|---|
| 408 | | - /* There's no other way to figure out whether the crtc is running. */ |
|---|
| 409 | | - ret = drm_crtc_vblank_get(crtc[i]); |
|---|
| 410 | | - if (ret == 0) { |
|---|
| 411 | | - drm_crtc_wait_one_vblank(crtc[i]); |
|---|
| 412 | | - drm_crtc_vblank_put(crtc[i]); |
|---|
| 413 | | - } |
|---|
| 414 | | - |
|---|
| 415 | | - ret = 0; |
|---|
| 416 | | - } |
|---|
| 417 | | - |
|---|
| 418 | | - if (plane_funcs->cleanup_fb) |
|---|
| 419 | | - plane_funcs->cleanup_fb(plane, plane_state); |
|---|
| 420 | | -out: |
|---|
| 421 | | - if (plane->funcs->atomic_destroy_state) |
|---|
| 422 | | - plane->funcs->atomic_destroy_state(plane, plane_state); |
|---|
| 423 | | - else |
|---|
| 424 | | - drm_atomic_helper_plane_destroy_state(plane, plane_state); |
|---|
| 425 | | - |
|---|
| 426 | | - return ret; |
|---|
| 427 | | -} |
|---|
| 428 | | - |
|---|
| 429 | | -/** |
|---|
| 430 | | - * drm_plane_helper_update() - Transitional helper for plane update |
|---|
| 431 | | - * @plane: plane object to update |
|---|
| 432 | | - * @crtc: owning CRTC of owning plane |
|---|
| 433 | | - * @fb: framebuffer to flip onto plane |
|---|
| 434 | | - * @crtc_x: x offset of primary plane on crtc |
|---|
| 435 | | - * @crtc_y: y offset of primary plane on crtc |
|---|
| 436 | | - * @crtc_w: width of primary plane rectangle on crtc |
|---|
| 437 | | - * @crtc_h: height of primary plane rectangle on crtc |
|---|
| 438 | | - * @src_x: x offset of @fb for panning |
|---|
| 439 | | - * @src_y: y offset of @fb for panning |
|---|
| 440 | | - * @src_w: width of source rectangle in @fb |
|---|
| 441 | | - * @src_h: height of source rectangle in @fb |
|---|
| 442 | | - * @ctx: lock acquire context, not used here |
|---|
| 443 | | - * |
|---|
| 444 | | - * Provides a default plane update handler using the atomic plane update |
|---|
| 445 | | - * functions. It is fully left to the driver to check plane constraints and |
|---|
| 446 | | - * handle corner-cases like a fully occluded or otherwise invisible plane. |
|---|
| 447 | | - * |
|---|
| 448 | | - * This is useful for piecewise transitioning of a driver to the atomic helpers. |
|---|
| 449 | | - * |
|---|
| 450 | | - * RETURNS: |
|---|
| 451 | | - * Zero on success, error code on failure |
|---|
| 452 | | - */ |
|---|
| 453 | | -int drm_plane_helper_update(struct drm_plane *plane, struct drm_crtc *crtc, |
|---|
| 454 | | - struct drm_framebuffer *fb, |
|---|
| 455 | | - int crtc_x, int crtc_y, |
|---|
| 456 | | - unsigned int crtc_w, unsigned int crtc_h, |
|---|
| 457 | | - uint32_t src_x, uint32_t src_y, |
|---|
| 458 | | - uint32_t src_w, uint32_t src_h, |
|---|
| 459 | | - struct drm_modeset_acquire_ctx *ctx) |
|---|
| 460 | | -{ |
|---|
| 461 | | - struct drm_plane_state *plane_state; |
|---|
| 462 | | - |
|---|
| 463 | | - if (plane->funcs->atomic_duplicate_state) |
|---|
| 464 | | - plane_state = plane->funcs->atomic_duplicate_state(plane); |
|---|
| 465 | | - else { |
|---|
| 466 | | - if (!plane->state) |
|---|
| 467 | | - drm_atomic_helper_plane_reset(plane); |
|---|
| 468 | | - |
|---|
| 469 | | - plane_state = drm_atomic_helper_plane_duplicate_state(plane); |
|---|
| 470 | | - } |
|---|
| 471 | | - if (!plane_state) |
|---|
| 472 | | - return -ENOMEM; |
|---|
| 473 | | - plane_state->plane = plane; |
|---|
| 474 | | - |
|---|
| 475 | | - plane_state->crtc = crtc; |
|---|
| 476 | | - drm_atomic_set_fb_for_plane(plane_state, fb); |
|---|
| 477 | | - plane_state->crtc_x = crtc_x; |
|---|
| 478 | | - plane_state->crtc_y = crtc_y; |
|---|
| 479 | | - plane_state->crtc_h = crtc_h; |
|---|
| 480 | | - plane_state->crtc_w = crtc_w; |
|---|
| 481 | | - plane_state->src_x = src_x; |
|---|
| 482 | | - plane_state->src_y = src_y; |
|---|
| 483 | | - plane_state->src_h = src_h; |
|---|
| 484 | | - plane_state->src_w = src_w; |
|---|
| 485 | | - |
|---|
| 486 | | - return drm_plane_helper_commit(plane, plane_state, plane->fb); |
|---|
| 487 | | -} |
|---|
| 488 | | -EXPORT_SYMBOL(drm_plane_helper_update); |
|---|
| 489 | | - |
|---|
| 490 | | -/** |
|---|
| 491 | | - * drm_plane_helper_disable() - Transitional helper for plane disable |
|---|
| 492 | | - * @plane: plane to disable |
|---|
| 493 | | - * @ctx: lock acquire context, not used here |
|---|
| 494 | | - * |
|---|
| 495 | | - * Provides a default plane disable handler using the atomic plane update |
|---|
| 496 | | - * functions. It is fully left to the driver to check plane constraints and |
|---|
| 497 | | - * handle corner-cases like a fully occluded or otherwise invisible plane. |
|---|
| 498 | | - * |
|---|
| 499 | | - * This is useful for piecewise transitioning of a driver to the atomic helpers. |
|---|
| 500 | | - * |
|---|
| 501 | | - * RETURNS: |
|---|
| 502 | | - * Zero on success, error code on failure |
|---|
| 503 | | - */ |
|---|
| 504 | | -int drm_plane_helper_disable(struct drm_plane *plane, |
|---|
| 505 | | - struct drm_modeset_acquire_ctx *ctx) |
|---|
| 506 | | -{ |
|---|
| 507 | | - struct drm_plane_state *plane_state; |
|---|
| 508 | | - struct drm_framebuffer *old_fb; |
|---|
| 509 | | - |
|---|
| 510 | | - /* crtc helpers love to call disable functions for already disabled hw |
|---|
| 511 | | - * functions. So cope with that. */ |
|---|
| 512 | | - if (!plane->crtc) |
|---|
| 513 | | - return 0; |
|---|
| 514 | | - |
|---|
| 515 | | - if (plane->funcs->atomic_duplicate_state) |
|---|
| 516 | | - plane_state = plane->funcs->atomic_duplicate_state(plane); |
|---|
| 517 | | - else { |
|---|
| 518 | | - if (!plane->state) |
|---|
| 519 | | - drm_atomic_helper_plane_reset(plane); |
|---|
| 520 | | - |
|---|
| 521 | | - plane_state = drm_atomic_helper_plane_duplicate_state(plane); |
|---|
| 522 | | - } |
|---|
| 523 | | - if (!plane_state) |
|---|
| 524 | | - return -ENOMEM; |
|---|
| 525 | | - plane_state->plane = plane; |
|---|
| 526 | | - |
|---|
| 527 | | - plane_state->crtc = NULL; |
|---|
| 528 | | - old_fb = plane_state->fb; |
|---|
| 529 | | - drm_atomic_set_fb_for_plane(plane_state, NULL); |
|---|
| 530 | | - |
|---|
| 531 | | - return drm_plane_helper_commit(plane, plane_state, old_fb); |
|---|
| 532 | | -} |
|---|
| 533 | | -EXPORT_SYMBOL(drm_plane_helper_disable); |
|---|