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