1 /* 2 * Copyright (C) 2018 Intel Corp. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * Authors: 23 * Rob Clark <robdclark@gmail.com> 24 * Daniel Vetter <daniel.vetter@ffwll.ch> 25 */ 26 27 #include <drm/drm_atomic.h> 28 #include <drm/drm_atomic_state_helper.h> 29 #include <drm/drm_blend.h> 30 #include <drm/drm_bridge.h> 31 #include <drm/drm_connector.h> 32 #include <drm/drm_crtc.h> 33 #include <drm/drm_device.h> 34 #include <drm/drm_framebuffer.h> 35 #include <drm/drm_plane.h> 36 #include <drm/drm_print.h> 37 #include <drm/drm_vblank.h> 38 #include <drm/drm_writeback.h> 39 40 #include <linux/export.h> 41 #include <linux/slab.h> 42 #include <linux/dma-fence.h> 43 44 /** 45 * DOC: atomic state reset and initialization 46 * 47 * Both the drm core and the atomic helpers assume that there is always the full 48 * and correct atomic software state for all connectors, CRTCs and planes 49 * available. Which is a bit a problem on driver load and also after system 50 * suspend. One way to solve this is to have a hardware state read-out 51 * infrastructure which reconstructs the full software state (e.g. the i915 52 * driver). 53 * 54 * The simpler solution is to just reset the software state to everything off, 55 * which is easiest to do by calling drm_mode_config_reset(). To facilitate this 56 * the atomic helpers provide default reset implementations for all hooks. 57 * 58 * On the upside the precise state tracking of atomic simplifies system suspend 59 * and resume a lot. For drivers using drm_mode_config_reset() a complete recipe 60 * is implemented in drm_atomic_helper_suspend() and drm_atomic_helper_resume(). 61 * For other drivers the building blocks are split out, see the documentation 62 * for these functions. 63 */ 64 65 /** 66 * __drm_atomic_helper_crtc_state_reset - reset the CRTC state 67 * @crtc_state: atomic CRTC state, must not be NULL 68 * @crtc: CRTC object, must not be NULL 69 * 70 * Initializes the newly allocated @crtc_state with default 71 * values. This is useful for drivers that subclass the CRTC state. 72 */ 73 void 74 __drm_atomic_helper_crtc_state_reset(struct drm_crtc_state *crtc_state, 75 struct drm_crtc *crtc) 76 { 77 crtc_state->crtc = crtc; 78 crtc_state->background_color = DRM_ARGB64_PREP(0xffff, 0, 0, 0); 79 } 80 EXPORT_SYMBOL(__drm_atomic_helper_crtc_state_reset); 81 82 /** 83 * __drm_atomic_helper_crtc_reset - reset state on CRTC 84 * @crtc: drm CRTC 85 * @crtc_state: CRTC state to assign 86 * 87 * Initializes the newly allocated @crtc_state and assigns it to 88 * the &drm_crtc->state pointer of @crtc, usually required when 89 * initializing the drivers or when called from the &drm_crtc_funcs.reset 90 * hook. 91 * 92 * This is useful for drivers that subclass the CRTC state. 93 */ 94 void 95 __drm_atomic_helper_crtc_reset(struct drm_crtc *crtc, 96 struct drm_crtc_state *crtc_state) 97 { 98 if (crtc_state) 99 __drm_atomic_helper_crtc_state_reset(crtc_state, crtc); 100 101 if (drm_dev_has_vblank(crtc->dev)) 102 drm_crtc_vblank_reset(crtc); 103 104 crtc->state = crtc_state; 105 } 106 EXPORT_SYMBOL(__drm_atomic_helper_crtc_reset); 107 108 /** 109 * drm_atomic_helper_crtc_reset - default &drm_crtc_funcs.reset hook for CRTCs 110 * @crtc: drm CRTC 111 * 112 * Resets the atomic state for @crtc by freeing the state pointer (which might 113 * be NULL, e.g. at driver load time) and allocating a new empty state object. 114 */ 115 void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc) 116 { 117 struct drm_crtc_state *crtc_state = 118 kzalloc_obj(*crtc->state); 119 120 if (crtc->state) 121 crtc->funcs->atomic_destroy_state(crtc, crtc->state); 122 123 __drm_atomic_helper_crtc_reset(crtc, crtc_state); 124 } 125 EXPORT_SYMBOL(drm_atomic_helper_crtc_reset); 126 127 /** 128 * __drm_atomic_helper_crtc_duplicate_state - copy atomic CRTC state 129 * @crtc: CRTC object 130 * @state: atomic CRTC state 131 * 132 * Copies atomic state from a CRTC's current state and resets inferred values. 133 * This is useful for drivers that subclass the CRTC state. 134 */ 135 void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc, 136 struct drm_crtc_state *state) 137 { 138 memcpy(state, crtc->state, sizeof(*state)); 139 140 if (state->mode_blob) 141 drm_property_blob_get(state->mode_blob); 142 if (state->degamma_lut) 143 drm_property_blob_get(state->degamma_lut); 144 if (state->ctm) 145 drm_property_blob_get(state->ctm); 146 if (state->gamma_lut) 147 drm_property_blob_get(state->gamma_lut); 148 state->mode_changed = false; 149 state->active_changed = false; 150 state->planes_changed = false; 151 state->connectors_changed = false; 152 state->color_mgmt_changed = false; 153 state->zpos_changed = false; 154 state->commit = NULL; 155 state->event = NULL; 156 state->async_flip = false; 157 158 /* Self refresh should be canceled when a new update is available */ 159 state->active = drm_atomic_crtc_effectively_active(state); 160 state->self_refresh_active = false; 161 } 162 EXPORT_SYMBOL(__drm_atomic_helper_crtc_duplicate_state); 163 164 /** 165 * drm_atomic_helper_crtc_duplicate_state - default state duplicate hook 166 * @crtc: drm CRTC 167 * 168 * Default CRTC state duplicate hook for drivers which don't have their own 169 * subclassed CRTC state structure. 170 */ 171 struct drm_crtc_state * 172 drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc) 173 { 174 struct drm_crtc_state *state; 175 176 if (WARN_ON(!crtc->state)) 177 return NULL; 178 179 state = kmalloc_obj(*state); 180 if (state) 181 __drm_atomic_helper_crtc_duplicate_state(crtc, state); 182 183 return state; 184 } 185 EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state); 186 187 /** 188 * __drm_atomic_helper_crtc_destroy_state - release CRTC state 189 * @state: CRTC state object to release 190 * 191 * Releases all resources stored in the CRTC state without actually freeing 192 * the memory of the CRTC state. This is useful for drivers that subclass the 193 * CRTC state. 194 */ 195 void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state) 196 { 197 if (state->commit) { 198 /* 199 * In the event that a non-blocking commit returns 200 * -ERESTARTSYS before the commit_tail work is queued, we will 201 * have an extra reference to the commit object. Release it, if 202 * the event has not been consumed by the worker. 203 * 204 * state->event may be freed, so we can't directly look at 205 * state->event->base.completion. 206 */ 207 if (state->event && state->commit->abort_completion) 208 drm_crtc_commit_put(state->commit); 209 210 kfree(state->commit->event); 211 state->commit->event = NULL; 212 213 drm_crtc_commit_put(state->commit); 214 } 215 216 drm_property_blob_put(state->mode_blob); 217 drm_property_blob_put(state->degamma_lut); 218 drm_property_blob_put(state->ctm); 219 drm_property_blob_put(state->gamma_lut); 220 } 221 EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state); 222 223 /** 224 * drm_atomic_helper_crtc_destroy_state - default state destroy hook 225 * @crtc: drm CRTC 226 * @state: CRTC state object to release 227 * 228 * Default CRTC state destroy hook for drivers which don't have their own 229 * subclassed CRTC state structure. 230 */ 231 void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc, 232 struct drm_crtc_state *state) 233 { 234 __drm_atomic_helper_crtc_destroy_state(state); 235 kfree(state); 236 } 237 EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state); 238 239 /** 240 * __drm_atomic_helper_plane_state_reset - resets plane state to default values 241 * @plane_state: atomic plane state, must not be NULL 242 * @plane: plane object, must not be NULL 243 * 244 * Initializes the newly allocated @plane_state with default 245 * values. This is useful for drivers that subclass the CRTC state. 246 */ 247 void __drm_atomic_helper_plane_state_reset(struct drm_plane_state *plane_state, 248 struct drm_plane *plane) 249 { 250 u64 val; 251 252 plane_state->plane = plane; 253 plane_state->rotation = DRM_MODE_ROTATE_0; 254 255 plane_state->alpha = DRM_BLEND_ALPHA_OPAQUE; 256 plane_state->pixel_blend_mode = DRM_MODE_BLEND_PREMULTI; 257 258 if (plane->color_encoding_property) { 259 if (!drm_object_property_get_default_value(&plane->base, 260 plane->color_encoding_property, 261 &val)) 262 plane_state->color_encoding = val; 263 } 264 265 if (plane->color_range_property) { 266 if (!drm_object_property_get_default_value(&plane->base, 267 plane->color_range_property, 268 &val)) 269 plane_state->color_range = val; 270 } 271 272 if (plane->color_pipeline_property) { 273 /* default is always NULL, i.e., bypass */ 274 plane_state->color_pipeline = NULL; 275 } 276 277 if (plane->zpos_property) { 278 if (!drm_object_property_get_default_value(&plane->base, 279 plane->zpos_property, 280 &val)) { 281 plane_state->zpos = val; 282 plane_state->normalized_zpos = val; 283 } 284 } 285 286 if (plane->hotspot_x_property) { 287 if (!drm_object_property_get_default_value(&plane->base, 288 plane->hotspot_x_property, 289 &val)) 290 plane_state->hotspot_x = val; 291 } 292 293 if (plane->hotspot_y_property) { 294 if (!drm_object_property_get_default_value(&plane->base, 295 plane->hotspot_y_property, 296 &val)) 297 plane_state->hotspot_y = val; 298 } 299 } 300 EXPORT_SYMBOL(__drm_atomic_helper_plane_state_reset); 301 302 /** 303 * __drm_atomic_helper_plane_reset - reset state on plane 304 * @plane: drm plane 305 * @plane_state: plane state to assign 306 * 307 * Initializes the newly allocated @plane_state and assigns it to 308 * the &drm_crtc->state pointer of @plane, usually required when 309 * initializing the drivers or when called from the &drm_plane_funcs.reset 310 * hook. 311 * 312 * This is useful for drivers that subclass the plane state. 313 */ 314 void __drm_atomic_helper_plane_reset(struct drm_plane *plane, 315 struct drm_plane_state *plane_state) 316 { 317 if (plane_state) 318 __drm_atomic_helper_plane_state_reset(plane_state, plane); 319 320 plane->state = plane_state; 321 } 322 EXPORT_SYMBOL(__drm_atomic_helper_plane_reset); 323 324 /** 325 * drm_atomic_helper_plane_reset - default &drm_plane_funcs.reset hook for planes 326 * @plane: drm plane 327 * 328 * Resets the atomic state for @plane by freeing the state pointer (which might 329 * be NULL, e.g. at driver load time) and allocating a new empty state object. 330 */ 331 void drm_atomic_helper_plane_reset(struct drm_plane *plane) 332 { 333 if (plane->state) 334 __drm_atomic_helper_plane_destroy_state(plane->state); 335 336 kfree(plane->state); 337 plane->state = kzalloc_obj(*plane->state); 338 if (plane->state) 339 __drm_atomic_helper_plane_reset(plane, plane->state); 340 } 341 EXPORT_SYMBOL(drm_atomic_helper_plane_reset); 342 343 /** 344 * __drm_atomic_helper_plane_duplicate_state - copy atomic plane state 345 * @plane: plane object 346 * @state: atomic plane state 347 * 348 * Copies atomic state from a plane's current state. This is useful for 349 * drivers that subclass the plane state. 350 */ 351 void __drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane, 352 struct drm_plane_state *state) 353 { 354 memcpy(state, plane->state, sizeof(*state)); 355 356 if (state->fb) 357 drm_framebuffer_get(state->fb); 358 359 state->fence = NULL; 360 state->commit = NULL; 361 state->fb_damage_clips = NULL; 362 state->color_mgmt_changed = false; 363 } 364 EXPORT_SYMBOL(__drm_atomic_helper_plane_duplicate_state); 365 366 /** 367 * drm_atomic_helper_plane_duplicate_state - default state duplicate hook 368 * @plane: drm plane 369 * 370 * Default plane state duplicate hook for drivers which don't have their own 371 * subclassed plane state structure. 372 */ 373 struct drm_plane_state * 374 drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane) 375 { 376 struct drm_plane_state *state; 377 378 if (WARN_ON(!plane->state)) 379 return NULL; 380 381 state = kmalloc_obj(*state); 382 if (state) 383 __drm_atomic_helper_plane_duplicate_state(plane, state); 384 385 return state; 386 } 387 EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state); 388 389 /** 390 * __drm_atomic_helper_plane_destroy_state - release plane state 391 * @state: plane state object to release 392 * 393 * Releases all resources stored in the plane state without actually freeing 394 * the memory of the plane state. This is useful for drivers that subclass the 395 * plane state. 396 */ 397 void __drm_atomic_helper_plane_destroy_state(struct drm_plane_state *state) 398 { 399 if (state->fb) 400 drm_framebuffer_put(state->fb); 401 402 if (state->fence) 403 dma_fence_put(state->fence); 404 405 if (state->commit) 406 drm_crtc_commit_put(state->commit); 407 408 drm_property_blob_put(state->fb_damage_clips); 409 } 410 EXPORT_SYMBOL(__drm_atomic_helper_plane_destroy_state); 411 412 /** 413 * drm_atomic_helper_plane_destroy_state - default state destroy hook 414 * @plane: drm plane 415 * @state: plane state object to release 416 * 417 * Default plane state destroy hook for drivers which don't have their own 418 * subclassed plane state structure. 419 */ 420 void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane, 421 struct drm_plane_state *state) 422 { 423 __drm_atomic_helper_plane_destroy_state(state); 424 kfree(state); 425 } 426 EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state); 427 428 /** 429 * __drm_atomic_helper_connector_state_reset - reset the connector state 430 * @conn_state: atomic connector state, must not be NULL 431 * @connector: connectotr object, must not be NULL 432 * 433 * Initializes the newly allocated @conn_state with default 434 * values. This is useful for drivers that subclass the connector state. 435 */ 436 void 437 __drm_atomic_helper_connector_state_reset(struct drm_connector_state *conn_state, 438 struct drm_connector *connector) 439 { 440 conn_state->connector = connector; 441 } 442 EXPORT_SYMBOL(__drm_atomic_helper_connector_state_reset); 443 444 /** 445 * __drm_atomic_helper_connector_reset - reset state on connector 446 * @connector: drm connector 447 * @conn_state: connector state to assign 448 * 449 * Initializes the newly allocated @conn_state and assigns it to 450 * the &drm_connector->state pointer of @connector, usually required when 451 * initializing the drivers or when called from the &drm_connector_funcs.reset 452 * hook. 453 * 454 * This is useful for drivers that subclass the connector state. 455 */ 456 void 457 __drm_atomic_helper_connector_reset(struct drm_connector *connector, 458 struct drm_connector_state *conn_state) 459 { 460 if (conn_state) 461 __drm_atomic_helper_connector_state_reset(conn_state, connector); 462 463 connector->state = conn_state; 464 } 465 EXPORT_SYMBOL(__drm_atomic_helper_connector_reset); 466 467 /** 468 * drm_atomic_helper_connector_reset - default &drm_connector_funcs.reset hook for connectors 469 * @connector: drm connector 470 * 471 * Resets the atomic state for @connector by freeing the state pointer (which 472 * might be NULL, e.g. at driver load time) and allocating a new empty state 473 * object. 474 */ 475 void drm_atomic_helper_connector_reset(struct drm_connector *connector) 476 { 477 struct drm_connector_state *conn_state = kzalloc_obj(*conn_state); 478 479 if (connector->state) 480 __drm_atomic_helper_connector_destroy_state(connector->state); 481 482 kfree(connector->state); 483 __drm_atomic_helper_connector_reset(connector, conn_state); 484 } 485 EXPORT_SYMBOL(drm_atomic_helper_connector_reset); 486 487 /** 488 * drm_atomic_helper_connector_tv_margins_reset - Resets TV connector properties 489 * @connector: DRM connector 490 * 491 * Resets the TV-related properties attached to a connector. 492 */ 493 void drm_atomic_helper_connector_tv_margins_reset(struct drm_connector *connector) 494 { 495 struct drm_cmdline_mode *cmdline = &connector->cmdline_mode; 496 struct drm_connector_state *state = connector->state; 497 498 state->tv.margins.left = cmdline->tv_margins.left; 499 state->tv.margins.right = cmdline->tv_margins.right; 500 state->tv.margins.top = cmdline->tv_margins.top; 501 state->tv.margins.bottom = cmdline->tv_margins.bottom; 502 } 503 EXPORT_SYMBOL(drm_atomic_helper_connector_tv_margins_reset); 504 505 /** 506 * drm_atomic_helper_connector_tv_reset - Resets Analog TV connector properties 507 * @connector: DRM connector 508 * 509 * Resets the analog TV properties attached to a connector 510 */ 511 void drm_atomic_helper_connector_tv_reset(struct drm_connector *connector) 512 { 513 struct drm_device *dev = connector->dev; 514 struct drm_cmdline_mode *cmdline = &connector->cmdline_mode; 515 struct drm_connector_state *state = connector->state; 516 struct drm_property *prop; 517 uint64_t val; 518 519 prop = dev->mode_config.tv_mode_property; 520 if (prop) 521 if (!drm_object_property_get_default_value(&connector->base, 522 prop, &val)) 523 state->tv.mode = val; 524 525 if (cmdline->tv_mode_specified) 526 state->tv.mode = cmdline->tv_mode; 527 528 prop = dev->mode_config.tv_select_subconnector_property; 529 if (prop) 530 if (!drm_object_property_get_default_value(&connector->base, 531 prop, &val)) 532 state->tv.select_subconnector = val; 533 534 prop = dev->mode_config.tv_subconnector_property; 535 if (prop) 536 if (!drm_object_property_get_default_value(&connector->base, 537 prop, &val)) 538 state->tv.subconnector = val; 539 540 prop = dev->mode_config.tv_brightness_property; 541 if (prop) 542 if (!drm_object_property_get_default_value(&connector->base, 543 prop, &val)) 544 state->tv.brightness = val; 545 546 prop = dev->mode_config.tv_contrast_property; 547 if (prop) 548 if (!drm_object_property_get_default_value(&connector->base, 549 prop, &val)) 550 state->tv.contrast = val; 551 552 prop = dev->mode_config.tv_flicker_reduction_property; 553 if (prop) 554 if (!drm_object_property_get_default_value(&connector->base, 555 prop, &val)) 556 state->tv.flicker_reduction = val; 557 558 prop = dev->mode_config.tv_overscan_property; 559 if (prop) 560 if (!drm_object_property_get_default_value(&connector->base, 561 prop, &val)) 562 state->tv.overscan = val; 563 564 prop = dev->mode_config.tv_saturation_property; 565 if (prop) 566 if (!drm_object_property_get_default_value(&connector->base, 567 prop, &val)) 568 state->tv.saturation = val; 569 570 prop = dev->mode_config.tv_hue_property; 571 if (prop) 572 if (!drm_object_property_get_default_value(&connector->base, 573 prop, &val)) 574 state->tv.hue = val; 575 576 drm_atomic_helper_connector_tv_margins_reset(connector); 577 } 578 EXPORT_SYMBOL(drm_atomic_helper_connector_tv_reset); 579 580 /** 581 * drm_atomic_helper_connector_tv_check - Validate an analog TV connector state 582 * @connector: DRM Connector 583 * @state: the DRM State object 584 * 585 * Checks the state object to see if the requested state is valid for an 586 * analog TV connector. 587 * 588 * Return: 589 * %0 for success, a negative error code on error. 590 */ 591 int drm_atomic_helper_connector_tv_check(struct drm_connector *connector, 592 struct drm_atomic_state *state) 593 { 594 struct drm_connector_state *old_conn_state = 595 drm_atomic_get_old_connector_state(state, connector); 596 struct drm_connector_state *new_conn_state = 597 drm_atomic_get_new_connector_state(state, connector); 598 struct drm_crtc_state *crtc_state; 599 struct drm_crtc *crtc; 600 601 crtc = new_conn_state->crtc; 602 if (!crtc) 603 return 0; 604 605 crtc_state = drm_atomic_get_new_crtc_state(state, crtc); 606 if (!crtc_state) 607 return -EINVAL; 608 609 if (old_conn_state->tv.mode != new_conn_state->tv.mode) 610 crtc_state->mode_changed = true; 611 612 if (old_conn_state->tv.margins.left != new_conn_state->tv.margins.left || 613 old_conn_state->tv.margins.right != new_conn_state->tv.margins.right || 614 old_conn_state->tv.margins.top != new_conn_state->tv.margins.top || 615 old_conn_state->tv.margins.bottom != new_conn_state->tv.margins.bottom || 616 old_conn_state->tv.mode != new_conn_state->tv.mode || 617 old_conn_state->tv.brightness != new_conn_state->tv.brightness || 618 old_conn_state->tv.contrast != new_conn_state->tv.contrast || 619 old_conn_state->tv.flicker_reduction != new_conn_state->tv.flicker_reduction || 620 old_conn_state->tv.overscan != new_conn_state->tv.overscan || 621 old_conn_state->tv.saturation != new_conn_state->tv.saturation || 622 old_conn_state->tv.hue != new_conn_state->tv.hue) 623 crtc_state->connectors_changed = true; 624 625 return 0; 626 } 627 EXPORT_SYMBOL(drm_atomic_helper_connector_tv_check); 628 629 /** 630 * __drm_atomic_helper_connector_duplicate_state - copy atomic connector state 631 * @connector: connector object 632 * @state: atomic connector state 633 * 634 * Copies atomic state from a connector's current state. This is useful for 635 * drivers that subclass the connector state. 636 */ 637 void 638 __drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector, 639 struct drm_connector_state *state) 640 { 641 memcpy(state, connector->state, sizeof(*state)); 642 if (state->crtc) 643 drm_connector_get(connector); 644 state->commit = NULL; 645 646 if (state->hdr_output_metadata) 647 drm_property_blob_get(state->hdr_output_metadata); 648 649 /* Don't copy over a writeback job, they are used only once */ 650 state->writeback_job = NULL; 651 } 652 EXPORT_SYMBOL(__drm_atomic_helper_connector_duplicate_state); 653 654 /** 655 * drm_atomic_helper_connector_duplicate_state - default state duplicate hook 656 * @connector: drm connector 657 * 658 * Default connector state duplicate hook for drivers which don't have their own 659 * subclassed connector state structure. 660 */ 661 struct drm_connector_state * 662 drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector) 663 { 664 struct drm_connector_state *state; 665 666 if (WARN_ON(!connector->state)) 667 return NULL; 668 669 state = kmalloc_obj(*state); 670 if (state) 671 __drm_atomic_helper_connector_duplicate_state(connector, state); 672 673 return state; 674 } 675 EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state); 676 677 /** 678 * __drm_atomic_helper_connector_destroy_state - release connector state 679 * @state: connector state object to release 680 * 681 * Releases all resources stored in the connector state without actually 682 * freeing the memory of the connector state. This is useful for drivers that 683 * subclass the connector state. 684 */ 685 void 686 __drm_atomic_helper_connector_destroy_state(struct drm_connector_state *state) 687 { 688 if (state->crtc) 689 drm_connector_put(state->connector); 690 691 if (state->commit) 692 drm_crtc_commit_put(state->commit); 693 694 if (state->writeback_job) 695 drm_writeback_cleanup_job(state->writeback_job); 696 697 drm_property_blob_put(state->hdr_output_metadata); 698 } 699 EXPORT_SYMBOL(__drm_atomic_helper_connector_destroy_state); 700 701 /** 702 * drm_atomic_helper_connector_destroy_state - default state destroy hook 703 * @connector: drm connector 704 * @state: connector state object to release 705 * 706 * Default connector state destroy hook for drivers which don't have their own 707 * subclassed connector state structure. 708 */ 709 void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector, 710 struct drm_connector_state *state) 711 { 712 __drm_atomic_helper_connector_destroy_state(state); 713 kfree(state); 714 } 715 EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state); 716 717 /** 718 * __drm_atomic_helper_private_obj_create_state - initializes private object state 719 * @obj: private object 720 * @state: new state to initialize 721 * 722 * Initializes the newly allocated @state, usually required when 723 * initializing the drivers. 724 * 725 * @obj is assumed to be zeroed. 726 * 727 * This is useful for drivers that use private states. 728 */ 729 void __drm_atomic_helper_private_obj_create_state(struct drm_private_obj *obj, 730 struct drm_private_state *state) 731 { 732 if (state) 733 state->obj = obj; 734 735 obj->state = state; 736 } 737 EXPORT_SYMBOL(__drm_atomic_helper_private_obj_create_state); 738 739 /** 740 * __drm_atomic_helper_private_obj_duplicate_state - copy atomic private state 741 * @obj: CRTC object 742 * @state: new private object state 743 * 744 * Copies atomic state from a private objects's current state and resets inferred values. 745 * This is useful for drivers that subclass the private state. 746 */ 747 void __drm_atomic_helper_private_obj_duplicate_state(struct drm_private_obj *obj, 748 struct drm_private_state *state) 749 { 750 memcpy(state, obj->state, sizeof(*state)); 751 } 752 EXPORT_SYMBOL(__drm_atomic_helper_private_obj_duplicate_state); 753 754 /** 755 * __drm_atomic_helper_bridge_duplicate_state() - Copy atomic bridge state 756 * @bridge: bridge object 757 * @state: atomic bridge state 758 * 759 * Copies atomic state from a bridge's current state and resets inferred values. 760 * This is useful for drivers that subclass the bridge state. 761 */ 762 void __drm_atomic_helper_bridge_duplicate_state(struct drm_bridge *bridge, 763 struct drm_bridge_state *state) 764 { 765 __drm_atomic_helper_private_obj_duplicate_state(&bridge->base, 766 &state->base); 767 state->bridge = bridge; 768 } 769 EXPORT_SYMBOL(__drm_atomic_helper_bridge_duplicate_state); 770 771 /** 772 * drm_atomic_helper_bridge_duplicate_state() - Duplicate a bridge state object 773 * @bridge: bridge object 774 * 775 * Allocates a new bridge state and initializes it with the current bridge 776 * state values. This helper is meant to be used as a bridge 777 * &drm_bridge_funcs.atomic_duplicate_state hook for bridges that don't 778 * subclass the bridge state. 779 */ 780 struct drm_bridge_state * 781 drm_atomic_helper_bridge_duplicate_state(struct drm_bridge *bridge) 782 { 783 struct drm_bridge_state *new; 784 785 if (WARN_ON(!bridge->base.state)) 786 return NULL; 787 788 new = kzalloc_obj(*new); 789 if (new) 790 __drm_atomic_helper_bridge_duplicate_state(bridge, new); 791 792 return new; 793 } 794 EXPORT_SYMBOL(drm_atomic_helper_bridge_duplicate_state); 795 796 /** 797 * drm_atomic_helper_bridge_destroy_state() - Destroy a bridge state object 798 * @bridge: the bridge this state refers to 799 * @state: bridge state to destroy 800 * 801 * Destroys a bridge state previously created by 802 * &drm_atomic_helper_bridge_reset() or 803 * &drm_atomic_helper_bridge_duplicate_state(). This helper is meant to be 804 * used as a bridge &drm_bridge_funcs.atomic_destroy_state hook for bridges 805 * that don't subclass the bridge state. 806 */ 807 void drm_atomic_helper_bridge_destroy_state(struct drm_bridge *bridge, 808 struct drm_bridge_state *state) 809 { 810 kfree(state); 811 } 812 EXPORT_SYMBOL(drm_atomic_helper_bridge_destroy_state); 813 814 /** 815 * __drm_atomic_helper_bridge_reset() - Initialize a bridge state to its 816 * default 817 * @bridge: the bridge this state refers to 818 * @state: bridge state to initialize 819 * 820 * Initializes the bridge state to default values. This is meant to be called 821 * by the bridge &drm_bridge_funcs.atomic_reset hook for bridges that subclass 822 * the bridge state. 823 */ 824 void __drm_atomic_helper_bridge_reset(struct drm_bridge *bridge, 825 struct drm_bridge_state *state) 826 { 827 memset(state, 0, sizeof(*state)); 828 __drm_atomic_helper_private_obj_create_state(&bridge->base, &state->base); 829 state->bridge = bridge; 830 } 831 EXPORT_SYMBOL(__drm_atomic_helper_bridge_reset); 832 833 /** 834 * drm_atomic_helper_bridge_reset() - Allocate and initialize a bridge state 835 * to its default 836 * @bridge: the bridge this state refers to 837 * 838 * Allocates the bridge state and initializes it to default values. This helper 839 * is meant to be used as a bridge &drm_bridge_funcs.atomic_reset hook for 840 * bridges that don't subclass the bridge state. 841 */ 842 struct drm_bridge_state * 843 drm_atomic_helper_bridge_reset(struct drm_bridge *bridge) 844 { 845 struct drm_bridge_state *bridge_state; 846 847 bridge_state = kzalloc_obj(*bridge_state); 848 if (!bridge_state) 849 return ERR_PTR(-ENOMEM); 850 851 __drm_atomic_helper_bridge_reset(bridge, bridge_state); 852 return bridge_state; 853 } 854 EXPORT_SYMBOL(drm_atomic_helper_bridge_reset); 855