110f3db8dd05b93673671eea4ebf620c04c13a96
[deliverable/linux.git] / drivers / gpu / drm / drm_atomic_helper.c
1 /*
2 * Copyright (C) 2014 Red Hat
3 * Copyright (C) 2014 Intel Corp.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Rob Clark <robdclark@gmail.com>
25 * Daniel Vetter <daniel.vetter@ffwll.ch>
26 */
27
28 #include <drm/drmP.h>
29 #include <drm/drm_atomic.h>
30 #include <drm/drm_plane_helper.h>
31 #include <drm/drm_crtc_helper.h>
32 #include <drm/drm_atomic_helper.h>
33 #include <linux/fence.h>
34
35 /**
36 * DOC: overview
37 *
38 * This helper library provides implementations of check and commit functions on
39 * top of the CRTC modeset helper callbacks and the plane helper callbacks. It
40 * also provides convenience implementations for the atomic state handling
41 * callbacks for drivers which don't need to subclass the drm core structures to
42 * add their own additional internal state.
43 *
44 * This library also provides default implementations for the check callback in
45 * drm_atomic_helper_check() and for the commit callback with
46 * drm_atomic_helper_commit(). But the individual stages and callbacks are
47 * exposed to allow drivers to mix and match and e.g. use the plane helpers only
48 * together with a driver private modeset implementation.
49 *
50 * This library also provides implementations for all the legacy driver
51 * interfaces on top of the atomic interface. See drm_atomic_helper_set_config(),
52 * drm_atomic_helper_disable_plane(), drm_atomic_helper_disable_plane() and the
53 * various functions to implement set_property callbacks. New drivers must not
54 * implement these functions themselves but must use the provided helpers.
55 *
56 * The atomic helper uses the same function table structures as all other
57 * modesetting helpers. See the documentation for struct &drm_crtc_helper_funcs,
58 * struct &drm_encoder_helper_funcs and struct &drm_connector_helper_funcs. It
59 * also shares the struct &drm_plane_helper_funcs function table with the plane
60 * helpers.
61 */
62 static void
63 drm_atomic_helper_plane_changed(struct drm_atomic_state *state,
64 struct drm_plane_state *plane_state,
65 struct drm_plane *plane)
66 {
67 struct drm_crtc_state *crtc_state;
68
69 if (plane->state->crtc) {
70 crtc_state = state->crtc_states[drm_crtc_index(plane->state->crtc)];
71
72 if (WARN_ON(!crtc_state))
73 return;
74
75 crtc_state->planes_changed = true;
76 }
77
78 if (plane_state->crtc) {
79 crtc_state =
80 state->crtc_states[drm_crtc_index(plane_state->crtc)];
81
82 if (WARN_ON(!crtc_state))
83 return;
84
85 crtc_state->planes_changed = true;
86 }
87 }
88
89 static bool
90 check_pending_encoder_assignment(struct drm_atomic_state *state,
91 struct drm_encoder *new_encoder,
92 struct drm_connector *new_connector)
93 {
94 struct drm_connector *connector;
95 struct drm_connector_state *conn_state;
96 int i;
97
98 for_each_connector_in_state(state, connector, conn_state, i) {
99 if (conn_state->best_encoder != new_encoder)
100 continue;
101
102 /* encoder already assigned and we're trying to re-steal it! */
103 if (connector->state->best_encoder != conn_state->best_encoder)
104 return false;
105 }
106
107 return true;
108 }
109
110 static struct drm_crtc *
111 get_current_crtc_for_encoder(struct drm_device *dev,
112 struct drm_encoder *encoder)
113 {
114 struct drm_mode_config *config = &dev->mode_config;
115 struct drm_connector *connector;
116
117 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
118
119 drm_for_each_connector(connector, dev) {
120 if (connector->state->best_encoder != encoder)
121 continue;
122
123 return connector->state->crtc;
124 }
125
126 return NULL;
127 }
128
129 static int
130 steal_encoder(struct drm_atomic_state *state,
131 struct drm_encoder *encoder,
132 struct drm_crtc *encoder_crtc)
133 {
134 struct drm_mode_config *config = &state->dev->mode_config;
135 struct drm_crtc_state *crtc_state;
136 struct drm_connector *connector;
137 struct drm_connector_state *connector_state;
138 int ret;
139
140 /*
141 * We can only steal an encoder coming from a connector, which means we
142 * must already hold the connection_mutex.
143 */
144 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
145
146 DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] in use on [CRTC:%d], stealing it\n",
147 encoder->base.id, encoder->name,
148 encoder_crtc->base.id);
149
150 crtc_state = drm_atomic_get_crtc_state(state, encoder_crtc);
151 if (IS_ERR(crtc_state))
152 return PTR_ERR(crtc_state);
153
154 crtc_state->connectors_changed = true;
155
156 list_for_each_entry(connector, &config->connector_list, head) {
157 if (connector->state->best_encoder != encoder)
158 continue;
159
160 DRM_DEBUG_ATOMIC("Stealing encoder from [CONNECTOR:%d:%s]\n",
161 connector->base.id,
162 connector->name);
163
164 connector_state = drm_atomic_get_connector_state(state,
165 connector);
166 if (IS_ERR(connector_state))
167 return PTR_ERR(connector_state);
168
169 ret = drm_atomic_set_crtc_for_connector(connector_state, NULL);
170 if (ret)
171 return ret;
172 connector_state->best_encoder = NULL;
173 }
174
175 return 0;
176 }
177
178 static int
179 update_connector_routing(struct drm_atomic_state *state, int conn_idx)
180 {
181 const struct drm_connector_helper_funcs *funcs;
182 struct drm_encoder *new_encoder;
183 struct drm_crtc *encoder_crtc;
184 struct drm_connector *connector;
185 struct drm_connector_state *connector_state;
186 struct drm_crtc_state *crtc_state;
187 int idx, ret;
188
189 connector = state->connectors[conn_idx];
190 connector_state = state->connector_states[conn_idx];
191
192 if (!connector)
193 return 0;
194
195 DRM_DEBUG_ATOMIC("Updating routing for [CONNECTOR:%d:%s]\n",
196 connector->base.id,
197 connector->name);
198
199 if (connector->state->crtc != connector_state->crtc) {
200 if (connector->state->crtc) {
201 idx = drm_crtc_index(connector->state->crtc);
202
203 crtc_state = state->crtc_states[idx];
204 crtc_state->connectors_changed = true;
205 }
206
207 if (connector_state->crtc) {
208 idx = drm_crtc_index(connector_state->crtc);
209
210 crtc_state = state->crtc_states[idx];
211 crtc_state->connectors_changed = true;
212 }
213 }
214
215 if (!connector_state->crtc) {
216 DRM_DEBUG_ATOMIC("Disabling [CONNECTOR:%d:%s]\n",
217 connector->base.id,
218 connector->name);
219
220 connector_state->best_encoder = NULL;
221
222 return 0;
223 }
224
225 funcs = connector->helper_private;
226
227 if (funcs->atomic_best_encoder)
228 new_encoder = funcs->atomic_best_encoder(connector,
229 connector_state);
230 else
231 new_encoder = funcs->best_encoder(connector);
232
233 if (!new_encoder) {
234 DRM_DEBUG_ATOMIC("No suitable encoder found for [CONNECTOR:%d:%s]\n",
235 connector->base.id,
236 connector->name);
237 return -EINVAL;
238 }
239
240 if (!drm_encoder_crtc_ok(new_encoder, connector_state->crtc)) {
241 DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] incompatible with [CRTC:%d]\n",
242 new_encoder->base.id,
243 new_encoder->name,
244 connector_state->crtc->base.id);
245 return -EINVAL;
246 }
247
248 if (new_encoder == connector_state->best_encoder) {
249 DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] keeps [ENCODER:%d:%s], now on [CRTC:%d]\n",
250 connector->base.id,
251 connector->name,
252 new_encoder->base.id,
253 new_encoder->name,
254 connector_state->crtc->base.id);
255
256 return 0;
257 }
258
259 if (!check_pending_encoder_assignment(state, new_encoder, connector)) {
260 DRM_DEBUG_ATOMIC("Encoder for [CONNECTOR:%d:%s] already assigned\n",
261 connector->base.id,
262 connector->name);
263 return -EINVAL;
264 }
265
266 encoder_crtc = get_current_crtc_for_encoder(state->dev,
267 new_encoder);
268
269 if (encoder_crtc) {
270 ret = steal_encoder(state, new_encoder, encoder_crtc);
271 if (ret) {
272 DRM_DEBUG_ATOMIC("Encoder stealing failed for [CONNECTOR:%d:%s]\n",
273 connector->base.id,
274 connector->name);
275 return ret;
276 }
277 }
278
279 if (WARN_ON(!connector_state->crtc))
280 return -EINVAL;
281
282 connector_state->best_encoder = new_encoder;
283 idx = drm_crtc_index(connector_state->crtc);
284
285 crtc_state = state->crtc_states[idx];
286 crtc_state->connectors_changed = true;
287
288 DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] using [ENCODER:%d:%s] on [CRTC:%d]\n",
289 connector->base.id,
290 connector->name,
291 new_encoder->base.id,
292 new_encoder->name,
293 connector_state->crtc->base.id);
294
295 return 0;
296 }
297
298 static int
299 mode_fixup(struct drm_atomic_state *state)
300 {
301 struct drm_crtc *crtc;
302 struct drm_crtc_state *crtc_state;
303 struct drm_connector *connector;
304 struct drm_connector_state *conn_state;
305 int i;
306 bool ret;
307
308 for_each_crtc_in_state(state, crtc, crtc_state, i) {
309 if (!crtc_state->mode_changed &&
310 !crtc_state->connectors_changed)
311 continue;
312
313 drm_mode_copy(&crtc_state->adjusted_mode, &crtc_state->mode);
314 }
315
316 for_each_connector_in_state(state, connector, conn_state, i) {
317 const struct drm_encoder_helper_funcs *funcs;
318 struct drm_encoder *encoder;
319
320 WARN_ON(!!conn_state->best_encoder != !!conn_state->crtc);
321
322 if (!conn_state->crtc || !conn_state->best_encoder)
323 continue;
324
325 crtc_state =
326 state->crtc_states[drm_crtc_index(conn_state->crtc)];
327
328 /*
329 * Each encoder has at most one connector (since we always steal
330 * it away), so we won't call ->mode_fixup twice.
331 */
332 encoder = conn_state->best_encoder;
333 funcs = encoder->helper_private;
334 if (!funcs)
335 continue;
336
337 ret = drm_bridge_mode_fixup(encoder->bridge, &crtc_state->mode,
338 &crtc_state->adjusted_mode);
339 if (!ret) {
340 DRM_DEBUG_ATOMIC("Bridge fixup failed\n");
341 return -EINVAL;
342 }
343
344 if (funcs->atomic_check) {
345 ret = funcs->atomic_check(encoder, crtc_state,
346 conn_state);
347 if (ret) {
348 DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] check failed\n",
349 encoder->base.id, encoder->name);
350 return ret;
351 }
352 } else if (funcs->mode_fixup) {
353 ret = funcs->mode_fixup(encoder, &crtc_state->mode,
354 &crtc_state->adjusted_mode);
355 if (!ret) {
356 DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] fixup failed\n",
357 encoder->base.id, encoder->name);
358 return -EINVAL;
359 }
360 }
361 }
362
363 for_each_crtc_in_state(state, crtc, crtc_state, i) {
364 const struct drm_crtc_helper_funcs *funcs;
365
366 if (!crtc_state->mode_changed &&
367 !crtc_state->connectors_changed)
368 continue;
369
370 funcs = crtc->helper_private;
371 if (!funcs->mode_fixup)
372 continue;
373
374 ret = funcs->mode_fixup(crtc, &crtc_state->mode,
375 &crtc_state->adjusted_mode);
376 if (!ret) {
377 DRM_DEBUG_ATOMIC("[CRTC:%d] fixup failed\n",
378 crtc->base.id);
379 return -EINVAL;
380 }
381 }
382
383 return 0;
384 }
385
386 /**
387 * drm_atomic_helper_check_modeset - validate state object for modeset changes
388 * @dev: DRM device
389 * @state: the driver state object
390 *
391 * Check the state object to see if the requested state is physically possible.
392 * This does all the crtc and connector related computations for an atomic
393 * update and adds any additional connectors needed for full modesets and calls
394 * down into ->mode_fixup functions of the driver backend.
395 *
396 * crtc_state->mode_changed is set when the input mode is changed.
397 * crtc_state->connectors_changed is set when a connector is added or
398 * removed from the crtc.
399 * crtc_state->active_changed is set when crtc_state->active changes,
400 * which is used for dpms.
401 *
402 * IMPORTANT:
403 *
404 * Drivers which update ->mode_changed (e.g. in their ->atomic_check hooks if a
405 * plane update can't be done without a full modeset) _must_ call this function
406 * afterwards after that change. It is permitted to call this function multiple
407 * times for the same update, e.g. when the ->atomic_check functions depend upon
408 * the adjusted dotclock for fifo space allocation and watermark computation.
409 *
410 * RETURNS
411 * Zero for success or -errno
412 */
413 int
414 drm_atomic_helper_check_modeset(struct drm_device *dev,
415 struct drm_atomic_state *state)
416 {
417 struct drm_crtc *crtc;
418 struct drm_crtc_state *crtc_state;
419 struct drm_connector *connector;
420 struct drm_connector_state *connector_state;
421 int i, ret;
422
423 for_each_crtc_in_state(state, crtc, crtc_state, i) {
424 if (!drm_mode_equal(&crtc->state->mode, &crtc_state->mode)) {
425 DRM_DEBUG_ATOMIC("[CRTC:%d] mode changed\n",
426 crtc->base.id);
427 crtc_state->mode_changed = true;
428 }
429
430 if (crtc->state->enable != crtc_state->enable) {
431 DRM_DEBUG_ATOMIC("[CRTC:%d] enable changed\n",
432 crtc->base.id);
433
434 /*
435 * For clarity this assignment is done here, but
436 * enable == 0 is only true when there are no
437 * connectors and a NULL mode.
438 *
439 * The other way around is true as well. enable != 0
440 * iff connectors are attached and a mode is set.
441 */
442 crtc_state->mode_changed = true;
443 crtc_state->connectors_changed = true;
444 }
445 }
446
447 for_each_connector_in_state(state, connector, connector_state, i) {
448 /*
449 * This only sets crtc->mode_changed for routing changes,
450 * drivers must set crtc->mode_changed themselves when connector
451 * properties need to be updated.
452 */
453 ret = update_connector_routing(state, i);
454 if (ret)
455 return ret;
456 }
457
458 /*
459 * After all the routing has been prepared we need to add in any
460 * connector which is itself unchanged, but who's crtc changes it's
461 * configuration. This must be done before calling mode_fixup in case a
462 * crtc only changed its mode but has the same set of connectors.
463 */
464 for_each_crtc_in_state(state, crtc, crtc_state, i) {
465 int num_connectors;
466
467 /*
468 * We must set ->active_changed after walking connectors for
469 * otherwise an update that only changes active would result in
470 * a full modeset because update_connector_routing force that.
471 */
472 if (crtc->state->active != crtc_state->active) {
473 DRM_DEBUG_ATOMIC("[CRTC:%d] active changed\n",
474 crtc->base.id);
475 crtc_state->active_changed = true;
476 }
477
478 if (!drm_atomic_crtc_needs_modeset(crtc_state))
479 continue;
480
481 DRM_DEBUG_ATOMIC("[CRTC:%d] needs all connectors, enable: %c, active: %c\n",
482 crtc->base.id,
483 crtc_state->enable ? 'y' : 'n',
484 crtc_state->active ? 'y' : 'n');
485
486 ret = drm_atomic_add_affected_connectors(state, crtc);
487 if (ret != 0)
488 return ret;
489
490 ret = drm_atomic_add_affected_planes(state, crtc);
491 if (ret != 0)
492 return ret;
493
494 num_connectors = drm_atomic_connectors_for_crtc(state,
495 crtc);
496
497 if (crtc_state->enable != !!num_connectors) {
498 DRM_DEBUG_ATOMIC("[CRTC:%d] enabled/connectors mismatch\n",
499 crtc->base.id);
500
501 return -EINVAL;
502 }
503 }
504
505 return mode_fixup(state);
506 }
507 EXPORT_SYMBOL(drm_atomic_helper_check_modeset);
508
509 /**
510 * drm_atomic_helper_check_planes - validate state object for planes changes
511 * @dev: DRM device
512 * @state: the driver state object
513 *
514 * Check the state object to see if the requested state is physically possible.
515 * This does all the plane update related checks using by calling into the
516 * ->atomic_check hooks provided by the driver.
517 *
518 * It also sets crtc_state->planes_changed to indicate that a crtc has
519 * updated planes.
520 *
521 * RETURNS
522 * Zero for success or -errno
523 */
524 int
525 drm_atomic_helper_check_planes(struct drm_device *dev,
526 struct drm_atomic_state *state)
527 {
528 struct drm_crtc *crtc;
529 struct drm_crtc_state *crtc_state;
530 struct drm_plane *plane;
531 struct drm_plane_state *plane_state;
532 int i, ret = 0;
533
534 for_each_plane_in_state(state, plane, plane_state, i) {
535 const struct drm_plane_helper_funcs *funcs;
536
537 funcs = plane->helper_private;
538
539 drm_atomic_helper_plane_changed(state, plane_state, plane);
540
541 if (!funcs || !funcs->atomic_check)
542 continue;
543
544 ret = funcs->atomic_check(plane, plane_state);
545 if (ret) {
546 DRM_DEBUG_ATOMIC("[PLANE:%d] atomic driver check failed\n",
547 plane->base.id);
548 return ret;
549 }
550 }
551
552 for_each_crtc_in_state(state, crtc, crtc_state, i) {
553 const struct drm_crtc_helper_funcs *funcs;
554
555 funcs = crtc->helper_private;
556
557 if (!funcs || !funcs->atomic_check)
558 continue;
559
560 ret = funcs->atomic_check(crtc, state->crtc_states[i]);
561 if (ret) {
562 DRM_DEBUG_ATOMIC("[CRTC:%d] atomic driver check failed\n",
563 crtc->base.id);
564 return ret;
565 }
566 }
567
568 return ret;
569 }
570 EXPORT_SYMBOL(drm_atomic_helper_check_planes);
571
572 /**
573 * drm_atomic_helper_check - validate state object
574 * @dev: DRM device
575 * @state: the driver state object
576 *
577 * Check the state object to see if the requested state is physically possible.
578 * Only crtcs and planes have check callbacks, so for any additional (global)
579 * checking that a driver needs it can simply wrap that around this function.
580 * Drivers without such needs can directly use this as their ->atomic_check()
581 * callback.
582 *
583 * This just wraps the two parts of the state checking for planes and modeset
584 * state in the default order: First it calls drm_atomic_helper_check_modeset()
585 * and then drm_atomic_helper_check_planes(). The assumption is that the
586 * ->atomic_check functions depend upon an updated adjusted_mode.clock to
587 * e.g. properly compute watermarks.
588 *
589 * RETURNS
590 * Zero for success or -errno
591 */
592 int drm_atomic_helper_check(struct drm_device *dev,
593 struct drm_atomic_state *state)
594 {
595 int ret;
596
597 ret = drm_atomic_helper_check_modeset(dev, state);
598 if (ret)
599 return ret;
600
601 ret = drm_atomic_helper_check_planes(dev, state);
602 if (ret)
603 return ret;
604
605 return ret;
606 }
607 EXPORT_SYMBOL(drm_atomic_helper_check);
608
609 static void
610 disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state)
611 {
612 struct drm_connector *connector;
613 struct drm_connector_state *old_conn_state;
614 struct drm_crtc *crtc;
615 struct drm_crtc_state *old_crtc_state;
616 int i;
617
618 for_each_connector_in_state(old_state, connector, old_conn_state, i) {
619 const struct drm_encoder_helper_funcs *funcs;
620 struct drm_encoder *encoder;
621 struct drm_crtc_state *old_crtc_state;
622
623 /* Shut down everything that's in the changeset and currently
624 * still on. So need to check the old, saved state. */
625 if (!old_conn_state->crtc)
626 continue;
627
628 old_crtc_state = old_state->crtc_states[drm_crtc_index(old_conn_state->crtc)];
629
630 if (!old_crtc_state->active ||
631 !drm_atomic_crtc_needs_modeset(old_conn_state->crtc->state))
632 continue;
633
634 encoder = old_conn_state->best_encoder;
635
636 /* We shouldn't get this far if we didn't previously have
637 * an encoder.. but WARN_ON() rather than explode.
638 */
639 if (WARN_ON(!encoder))
640 continue;
641
642 funcs = encoder->helper_private;
643
644 DRM_DEBUG_ATOMIC("disabling [ENCODER:%d:%s]\n",
645 encoder->base.id, encoder->name);
646
647 /*
648 * Each encoder has at most one connector (since we always steal
649 * it away), so we won't call disable hooks twice.
650 */
651 drm_bridge_disable(encoder->bridge);
652
653 /* Right function depends upon target state. */
654 if (connector->state->crtc && funcs->prepare)
655 funcs->prepare(encoder);
656 else if (funcs->disable)
657 funcs->disable(encoder);
658 else
659 funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
660
661 drm_bridge_post_disable(encoder->bridge);
662 }
663
664 for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
665 const struct drm_crtc_helper_funcs *funcs;
666
667 /* Shut down everything that needs a full modeset. */
668 if (!drm_atomic_crtc_needs_modeset(crtc->state))
669 continue;
670
671 if (!old_crtc_state->active)
672 continue;
673
674 funcs = crtc->helper_private;
675
676 DRM_DEBUG_ATOMIC("disabling [CRTC:%d]\n",
677 crtc->base.id);
678
679
680 /* Right function depends upon target state. */
681 if (crtc->state->enable && funcs->prepare)
682 funcs->prepare(crtc);
683 else if (funcs->disable)
684 funcs->disable(crtc);
685 else
686 funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
687 }
688 }
689
690 /**
691 * drm_atomic_helper_update_legacy_modeset_state - update legacy modeset state
692 * @dev: DRM device
693 * @old_state: atomic state object with old state structures
694 *
695 * This function updates all the various legacy modeset state pointers in
696 * connectors, encoders and crtcs. It also updates the timestamping constants
697 * used for precise vblank timestamps by calling
698 * drm_calc_timestamping_constants().
699 *
700 * Drivers can use this for building their own atomic commit if they don't have
701 * a pure helper-based modeset implementation.
702 */
703 void
704 drm_atomic_helper_update_legacy_modeset_state(struct drm_device *dev,
705 struct drm_atomic_state *old_state)
706 {
707 struct drm_connector *connector;
708 struct drm_connector_state *old_conn_state;
709 struct drm_crtc *crtc;
710 struct drm_crtc_state *old_crtc_state;
711 int i;
712
713 /* clear out existing links and update dpms */
714 for_each_connector_in_state(old_state, connector, old_conn_state, i) {
715 if (connector->encoder) {
716 WARN_ON(!connector->encoder->crtc);
717
718 connector->encoder->crtc = NULL;
719 connector->encoder = NULL;
720 }
721
722 crtc = connector->state->crtc;
723 if ((!crtc && old_conn_state->crtc) ||
724 (crtc && drm_atomic_crtc_needs_modeset(crtc->state))) {
725 struct drm_property *dpms_prop =
726 dev->mode_config.dpms_property;
727 int mode = DRM_MODE_DPMS_OFF;
728
729 if (crtc && crtc->state->active)
730 mode = DRM_MODE_DPMS_ON;
731
732 connector->dpms = mode;
733 drm_object_property_set_value(&connector->base,
734 dpms_prop, mode);
735 }
736 }
737
738 /* set new links */
739 for_each_connector_in_state(old_state, connector, old_conn_state, i) {
740 if (!connector->state->crtc)
741 continue;
742
743 if (WARN_ON(!connector->state->best_encoder))
744 continue;
745
746 connector->encoder = connector->state->best_encoder;
747 connector->encoder->crtc = connector->state->crtc;
748 }
749
750 /* set legacy state in the crtc structure */
751 for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
752 struct drm_plane *primary = crtc->primary;
753
754 crtc->mode = crtc->state->mode;
755 crtc->enabled = crtc->state->enable;
756
757 if (drm_atomic_get_existing_plane_state(old_state, primary) &&
758 primary->state->crtc == crtc) {
759 crtc->x = primary->state->src_x >> 16;
760 crtc->y = primary->state->src_y >> 16;
761 }
762
763 if (crtc->state->enable)
764 drm_calc_timestamping_constants(crtc,
765 &crtc->state->adjusted_mode);
766 }
767 }
768 EXPORT_SYMBOL(drm_atomic_helper_update_legacy_modeset_state);
769
770 static void
771 crtc_set_mode(struct drm_device *dev, struct drm_atomic_state *old_state)
772 {
773 struct drm_crtc *crtc;
774 struct drm_crtc_state *old_crtc_state;
775 struct drm_connector *connector;
776 struct drm_connector_state *old_conn_state;
777 int i;
778
779 for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
780 const struct drm_crtc_helper_funcs *funcs;
781
782 if (!crtc->state->mode_changed)
783 continue;
784
785 funcs = crtc->helper_private;
786
787 if (crtc->state->enable && funcs->mode_set_nofb) {
788 DRM_DEBUG_ATOMIC("modeset on [CRTC:%d]\n",
789 crtc->base.id);
790
791 funcs->mode_set_nofb(crtc);
792 }
793 }
794
795 for_each_connector_in_state(old_state, connector, old_conn_state, i) {
796 const struct drm_encoder_helper_funcs *funcs;
797 struct drm_crtc_state *new_crtc_state;
798 struct drm_encoder *encoder;
799 struct drm_display_mode *mode, *adjusted_mode;
800
801 if (!connector->state->best_encoder)
802 continue;
803
804 encoder = connector->state->best_encoder;
805 funcs = encoder->helper_private;
806 new_crtc_state = connector->state->crtc->state;
807 mode = &new_crtc_state->mode;
808 adjusted_mode = &new_crtc_state->adjusted_mode;
809
810 if (!new_crtc_state->mode_changed)
811 continue;
812
813 DRM_DEBUG_ATOMIC("modeset on [ENCODER:%d:%s]\n",
814 encoder->base.id, encoder->name);
815
816 /*
817 * Each encoder has at most one connector (since we always steal
818 * it away), so we won't call mode_set hooks twice.
819 */
820 if (funcs->mode_set)
821 funcs->mode_set(encoder, mode, adjusted_mode);
822
823 drm_bridge_mode_set(encoder->bridge, mode, adjusted_mode);
824 }
825 }
826
827 /**
828 * drm_atomic_helper_commit_modeset_disables - modeset commit to disable outputs
829 * @dev: DRM device
830 * @old_state: atomic state object with old state structures
831 *
832 * This function shuts down all the outputs that need to be shut down and
833 * prepares them (if required) with the new mode.
834 *
835 * For compatibility with legacy crtc helpers this should be called before
836 * drm_atomic_helper_commit_planes(), which is what the default commit function
837 * does. But drivers with different needs can group the modeset commits together
838 * and do the plane commits at the end. This is useful for drivers doing runtime
839 * PM since planes updates then only happen when the CRTC is actually enabled.
840 */
841 void drm_atomic_helper_commit_modeset_disables(struct drm_device *dev,
842 struct drm_atomic_state *old_state)
843 {
844 disable_outputs(dev, old_state);
845
846 drm_atomic_helper_update_legacy_modeset_state(dev, old_state);
847
848 crtc_set_mode(dev, old_state);
849 }
850 EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_disables);
851
852 /**
853 * drm_atomic_helper_commit_modeset_enables - modeset commit to enable outputs
854 * @dev: DRM device
855 * @old_state: atomic state object with old state structures
856 *
857 * This function enables all the outputs with the new configuration which had to
858 * be turned off for the update.
859 *
860 * For compatibility with legacy crtc helpers this should be called after
861 * drm_atomic_helper_commit_planes(), which is what the default commit function
862 * does. But drivers with different needs can group the modeset commits together
863 * and do the plane commits at the end. This is useful for drivers doing runtime
864 * PM since planes updates then only happen when the CRTC is actually enabled.
865 */
866 void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev,
867 struct drm_atomic_state *old_state)
868 {
869 struct drm_crtc *crtc;
870 struct drm_crtc_state *old_crtc_state;
871 struct drm_connector *connector;
872 struct drm_connector_state *old_conn_state;
873 int i;
874
875 for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
876 const struct drm_crtc_helper_funcs *funcs;
877
878 /* Need to filter out CRTCs where only planes change. */
879 if (!drm_atomic_crtc_needs_modeset(crtc->state))
880 continue;
881
882 if (!crtc->state->active)
883 continue;
884
885 funcs = crtc->helper_private;
886
887 if (crtc->state->enable) {
888 DRM_DEBUG_ATOMIC("enabling [CRTC:%d]\n",
889 crtc->base.id);
890
891 if (funcs->enable)
892 funcs->enable(crtc);
893 else
894 funcs->commit(crtc);
895 }
896 }
897
898 for_each_connector_in_state(old_state, connector, old_conn_state, i) {
899 const struct drm_encoder_helper_funcs *funcs;
900 struct drm_encoder *encoder;
901
902 if (!connector->state->best_encoder)
903 continue;
904
905 if (!connector->state->crtc->state->active ||
906 !drm_atomic_crtc_needs_modeset(connector->state->crtc->state))
907 continue;
908
909 encoder = connector->state->best_encoder;
910 funcs = encoder->helper_private;
911
912 DRM_DEBUG_ATOMIC("enabling [ENCODER:%d:%s]\n",
913 encoder->base.id, encoder->name);
914
915 /*
916 * Each encoder has at most one connector (since we always steal
917 * it away), so we won't call enable hooks twice.
918 */
919 drm_bridge_pre_enable(encoder->bridge);
920
921 if (funcs->enable)
922 funcs->enable(encoder);
923 else
924 funcs->commit(encoder);
925
926 drm_bridge_enable(encoder->bridge);
927 }
928 }
929 EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_enables);
930
931 static void wait_for_fences(struct drm_device *dev,
932 struct drm_atomic_state *state)
933 {
934 struct drm_plane *plane;
935 struct drm_plane_state *plane_state;
936 int i;
937
938 for_each_plane_in_state(state, plane, plane_state, i) {
939 if (!plane->state->fence)
940 continue;
941
942 WARN_ON(!plane->state->fb);
943
944 fence_wait(plane->state->fence, false);
945 fence_put(plane->state->fence);
946 plane->state->fence = NULL;
947 }
948 }
949
950 static bool framebuffer_changed(struct drm_device *dev,
951 struct drm_atomic_state *old_state,
952 struct drm_crtc *crtc)
953 {
954 struct drm_plane *plane;
955 struct drm_plane_state *old_plane_state;
956 int i;
957
958 for_each_plane_in_state(old_state, plane, old_plane_state, i) {
959 if (plane->state->crtc != crtc &&
960 old_plane_state->crtc != crtc)
961 continue;
962
963 if (plane->state->fb != old_plane_state->fb)
964 return true;
965 }
966
967 return false;
968 }
969
970 /**
971 * drm_atomic_helper_wait_for_vblanks - wait for vblank on crtcs
972 * @dev: DRM device
973 * @old_state: atomic state object with old state structures
974 *
975 * Helper to, after atomic commit, wait for vblanks on all effected
976 * crtcs (ie. before cleaning up old framebuffers using
977 * drm_atomic_helper_cleanup_planes()). It will only wait on crtcs where the
978 * framebuffers have actually changed to optimize for the legacy cursor and
979 * plane update use-case.
980 */
981 void
982 drm_atomic_helper_wait_for_vblanks(struct drm_device *dev,
983 struct drm_atomic_state *old_state)
984 {
985 struct drm_crtc *crtc;
986 struct drm_crtc_state *old_crtc_state;
987 int i, ret;
988
989 for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
990 /* No one cares about the old state, so abuse it for tracking
991 * and store whether we hold a vblank reference (and should do a
992 * vblank wait) in the ->enable boolean. */
993 old_crtc_state->enable = false;
994
995 if (!crtc->state->enable)
996 continue;
997
998 /* Legacy cursor ioctls are completely unsynced, and userspace
999 * relies on that (by doing tons of cursor updates). */
1000 if (old_state->legacy_cursor_update)
1001 continue;
1002
1003 if (!framebuffer_changed(dev, old_state, crtc))
1004 continue;
1005
1006 ret = drm_crtc_vblank_get(crtc);
1007 if (ret != 0)
1008 continue;
1009
1010 old_crtc_state->enable = true;
1011 old_crtc_state->last_vblank_count = drm_crtc_vblank_count(crtc);
1012 }
1013
1014 for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
1015 if (!old_crtc_state->enable)
1016 continue;
1017
1018 ret = wait_event_timeout(dev->vblank[i].queue,
1019 old_crtc_state->last_vblank_count !=
1020 drm_crtc_vblank_count(crtc),
1021 msecs_to_jiffies(50));
1022
1023 drm_crtc_vblank_put(crtc);
1024 }
1025 }
1026 EXPORT_SYMBOL(drm_atomic_helper_wait_for_vblanks);
1027
1028 /**
1029 * drm_atomic_helper_commit - commit validated state object
1030 * @dev: DRM device
1031 * @state: the driver state object
1032 * @async: asynchronous commit
1033 *
1034 * This function commits a with drm_atomic_helper_check() pre-validated state
1035 * object. This can still fail when e.g. the framebuffer reservation fails. For
1036 * now this doesn't implement asynchronous commits.
1037 *
1038 * Note that right now this function does not support async commits, and hence
1039 * driver writers must implement their own version for now. Also note that the
1040 * default ordering of how the various stages are called is to match the legacy
1041 * modeset helper library closest. One peculiarity of that is that it doesn't
1042 * mesh well with runtime PM at all.
1043 *
1044 * For drivers supporting runtime PM the recommended sequence is
1045 *
1046 * drm_atomic_helper_commit_modeset_disables(dev, state);
1047 *
1048 * drm_atomic_helper_commit_modeset_enables(dev, state);
1049 *
1050 * drm_atomic_helper_commit_planes(dev, state, true);
1051 *
1052 * See the kerneldoc entries for these three functions for more details.
1053 *
1054 * RETURNS
1055 * Zero for success or -errno.
1056 */
1057 int drm_atomic_helper_commit(struct drm_device *dev,
1058 struct drm_atomic_state *state,
1059 bool async)
1060 {
1061 int ret;
1062
1063 if (async)
1064 return -EBUSY;
1065
1066 ret = drm_atomic_helper_prepare_planes(dev, state);
1067 if (ret)
1068 return ret;
1069
1070 /*
1071 * This is the point of no return - everything below never fails except
1072 * when the hw goes bonghits. Which means we can commit the new state on
1073 * the software side now.
1074 */
1075
1076 drm_atomic_helper_swap_state(dev, state);
1077
1078 /*
1079 * Everything below can be run asynchronously without the need to grab
1080 * any modeset locks at all under one condition: It must be guaranteed
1081 * that the asynchronous work has either been cancelled (if the driver
1082 * supports it, which at least requires that the framebuffers get
1083 * cleaned up with drm_atomic_helper_cleanup_planes()) or completed
1084 * before the new state gets committed on the software side with
1085 * drm_atomic_helper_swap_state().
1086 *
1087 * This scheme allows new atomic state updates to be prepared and
1088 * checked in parallel to the asynchronous completion of the previous
1089 * update. Which is important since compositors need to figure out the
1090 * composition of the next frame right after having submitted the
1091 * current layout.
1092 */
1093
1094 wait_for_fences(dev, state);
1095
1096 drm_atomic_helper_commit_modeset_disables(dev, state);
1097
1098 drm_atomic_helper_commit_planes(dev, state, false);
1099
1100 drm_atomic_helper_commit_modeset_enables(dev, state);
1101
1102 drm_atomic_helper_wait_for_vblanks(dev, state);
1103
1104 drm_atomic_helper_cleanup_planes(dev, state);
1105
1106 drm_atomic_state_free(state);
1107
1108 return 0;
1109 }
1110 EXPORT_SYMBOL(drm_atomic_helper_commit);
1111
1112 /**
1113 * DOC: implementing async commit
1114 *
1115 * For now the atomic helpers don't support async commit directly. If there is
1116 * real need it could be added though, using the dma-buf fence infrastructure
1117 * for generic synchronization with outstanding rendering.
1118 *
1119 * For now drivers have to implement async commit themselves, with the following
1120 * sequence being the recommended one:
1121 *
1122 * 1. Run drm_atomic_helper_prepare_planes() first. This is the only function
1123 * which commit needs to call which can fail, so we want to run it first and
1124 * synchronously.
1125 *
1126 * 2. Synchronize with any outstanding asynchronous commit worker threads which
1127 * might be affected the new state update. This can be done by either cancelling
1128 * or flushing the work items, depending upon whether the driver can deal with
1129 * cancelled updates. Note that it is important to ensure that the framebuffer
1130 * cleanup is still done when cancelling.
1131 *
1132 * For sufficient parallelism it is recommended to have a work item per crtc
1133 * (for updates which don't touch global state) and a global one. Then we only
1134 * need to synchronize with the crtc work items for changed crtcs and the global
1135 * work item, which allows nice concurrent updates on disjoint sets of crtcs.
1136 *
1137 * 3. The software state is updated synchronously with
1138 * drm_atomic_helper_swap_state(). Doing this under the protection of all modeset
1139 * locks means concurrent callers never see inconsistent state. And doing this
1140 * while it's guaranteed that no relevant async worker runs means that async
1141 * workers do not need grab any locks. Actually they must not grab locks, for
1142 * otherwise the work flushing will deadlock.
1143 *
1144 * 4. Schedule a work item to do all subsequent steps, using the split-out
1145 * commit helpers: a) pre-plane commit b) plane commit c) post-plane commit and
1146 * then cleaning up the framebuffers after the old framebuffer is no longer
1147 * being displayed.
1148 */
1149
1150 /**
1151 * drm_atomic_helper_prepare_planes - prepare plane resources before commit
1152 * @dev: DRM device
1153 * @state: atomic state object with new state structures
1154 *
1155 * This function prepares plane state, specifically framebuffers, for the new
1156 * configuration. If any failure is encountered this function will call
1157 * ->cleanup_fb on any already successfully prepared framebuffer.
1158 *
1159 * Returns:
1160 * 0 on success, negative error code on failure.
1161 */
1162 int drm_atomic_helper_prepare_planes(struct drm_device *dev,
1163 struct drm_atomic_state *state)
1164 {
1165 int nplanes = dev->mode_config.num_total_plane;
1166 int ret, i;
1167
1168 for (i = 0; i < nplanes; i++) {
1169 const struct drm_plane_helper_funcs *funcs;
1170 struct drm_plane *plane = state->planes[i];
1171 struct drm_plane_state *plane_state = state->plane_states[i];
1172
1173 if (!plane)
1174 continue;
1175
1176 funcs = plane->helper_private;
1177
1178 if (funcs->prepare_fb) {
1179 ret = funcs->prepare_fb(plane, plane_state);
1180 if (ret)
1181 goto fail;
1182 }
1183 }
1184
1185 return 0;
1186
1187 fail:
1188 for (i--; i >= 0; i--) {
1189 const struct drm_plane_helper_funcs *funcs;
1190 struct drm_plane *plane = state->planes[i];
1191 struct drm_plane_state *plane_state = state->plane_states[i];
1192
1193 if (!plane)
1194 continue;
1195
1196 funcs = plane->helper_private;
1197
1198 if (funcs->cleanup_fb)
1199 funcs->cleanup_fb(plane, plane_state);
1200
1201 }
1202
1203 return ret;
1204 }
1205 EXPORT_SYMBOL(drm_atomic_helper_prepare_planes);
1206
1207 bool plane_crtc_active(struct drm_plane_state *state)
1208 {
1209 return state->crtc && state->crtc->state->active;
1210 }
1211
1212 /**
1213 * drm_atomic_helper_commit_planes - commit plane state
1214 * @dev: DRM device
1215 * @old_state: atomic state object with old state structures
1216 * @active_only: Only commit on active CRTC if set
1217 *
1218 * This function commits the new plane state using the plane and atomic helper
1219 * functions for planes and crtcs. It assumes that the atomic state has already
1220 * been pushed into the relevant object state pointers, since this step can no
1221 * longer fail.
1222 *
1223 * It still requires the global state object @old_state to know which planes and
1224 * crtcs need to be updated though.
1225 *
1226 * Note that this function does all plane updates across all CRTCs in one step.
1227 * If the hardware can't support this approach look at
1228 * drm_atomic_helper_commit_planes_on_crtc() instead.
1229 *
1230 * Plane parameters can be updated by applications while the associated CRTC is
1231 * disabled. The DRM/KMS core will store the parameters in the plane state,
1232 * which will be available to the driver when the CRTC is turned on. As a result
1233 * most drivers don't need to be immediately notified of plane updates for a
1234 * disabled CRTC.
1235 *
1236 * Unless otherwise needed, drivers are advised to set the @active_only
1237 * parameters to true in order not to receive plane update notifications related
1238 * to a disabled CRTC. This avoids the need to manually ignore plane updates in
1239 * driver code when the driver and/or hardware can't or just don't need to deal
1240 * with updates on disabled CRTCs, for example when supporting runtime PM.
1241 *
1242 * The drm_atomic_helper_commit() default implementation only sets @active_only
1243 * to false to most closely match the behaviour of the legacy helpers. This should
1244 * not be copied blindly by drivers.
1245 */
1246 void drm_atomic_helper_commit_planes(struct drm_device *dev,
1247 struct drm_atomic_state *old_state,
1248 bool active_only)
1249 {
1250 struct drm_crtc *crtc;
1251 struct drm_crtc_state *old_crtc_state;
1252 struct drm_plane *plane;
1253 struct drm_plane_state *old_plane_state;
1254 int i;
1255
1256 for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
1257 const struct drm_crtc_helper_funcs *funcs;
1258
1259 funcs = crtc->helper_private;
1260
1261 if (!funcs || !funcs->atomic_begin)
1262 continue;
1263
1264 if (active_only && !crtc->state->active)
1265 continue;
1266
1267 funcs->atomic_begin(crtc, old_crtc_state);
1268 }
1269
1270 for_each_plane_in_state(old_state, plane, old_plane_state, i) {
1271 const struct drm_plane_helper_funcs *funcs;
1272 bool disabling;
1273
1274 funcs = plane->helper_private;
1275
1276 if (!funcs)
1277 continue;
1278
1279 disabling = drm_atomic_plane_disabling(plane, old_plane_state);
1280
1281 if (active_only) {
1282 /*
1283 * Skip planes related to inactive CRTCs. If the plane
1284 * is enabled use the state of the current CRTC. If the
1285 * plane is being disabled use the state of the old
1286 * CRTC to avoid skipping planes being disabled on an
1287 * active CRTC.
1288 */
1289 if (!disabling && !plane_crtc_active(plane->state))
1290 continue;
1291 if (disabling && !plane_crtc_active(old_plane_state))
1292 continue;
1293 }
1294
1295 /*
1296 * Special-case disabling the plane if drivers support it.
1297 */
1298 if (disabling && funcs->atomic_disable)
1299 funcs->atomic_disable(plane, old_plane_state);
1300 else if (plane->state->crtc || disabling)
1301 funcs->atomic_update(plane, old_plane_state);
1302 }
1303
1304 for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) {
1305 const struct drm_crtc_helper_funcs *funcs;
1306
1307 funcs = crtc->helper_private;
1308
1309 if (!funcs || !funcs->atomic_flush)
1310 continue;
1311
1312 if (active_only && !crtc->state->active)
1313 continue;
1314
1315 funcs->atomic_flush(crtc, old_crtc_state);
1316 }
1317 }
1318 EXPORT_SYMBOL(drm_atomic_helper_commit_planes);
1319
1320 /**
1321 * drm_atomic_helper_commit_planes_on_crtc - commit plane state for a crtc
1322 * @old_crtc_state: atomic state object with the old crtc state
1323 *
1324 * This function commits the new plane state using the plane and atomic helper
1325 * functions for planes on the specific crtc. It assumes that the atomic state
1326 * has already been pushed into the relevant object state pointers, since this
1327 * step can no longer fail.
1328 *
1329 * This function is useful when plane updates should be done crtc-by-crtc
1330 * instead of one global step like drm_atomic_helper_commit_planes() does.
1331 *
1332 * This function can only be savely used when planes are not allowed to move
1333 * between different CRTCs because this function doesn't handle inter-CRTC
1334 * depencies. Callers need to ensure that either no such depencies exist,
1335 * resolve them through ordering of commit calls or through some other means.
1336 */
1337 void
1338 drm_atomic_helper_commit_planes_on_crtc(struct drm_crtc_state *old_crtc_state)
1339 {
1340 const struct drm_crtc_helper_funcs *crtc_funcs;
1341 struct drm_crtc *crtc = old_crtc_state->crtc;
1342 struct drm_atomic_state *old_state = old_crtc_state->state;
1343 struct drm_plane *plane;
1344 unsigned plane_mask;
1345
1346 plane_mask = old_crtc_state->plane_mask;
1347 plane_mask |= crtc->state->plane_mask;
1348
1349 crtc_funcs = crtc->helper_private;
1350 if (crtc_funcs && crtc_funcs->atomic_begin)
1351 crtc_funcs->atomic_begin(crtc, old_crtc_state);
1352
1353 drm_for_each_plane_mask(plane, crtc->dev, plane_mask) {
1354 struct drm_plane_state *old_plane_state =
1355 drm_atomic_get_existing_plane_state(old_state, plane);
1356 const struct drm_plane_helper_funcs *plane_funcs;
1357
1358 plane_funcs = plane->helper_private;
1359
1360 if (!old_plane_state || !plane_funcs)
1361 continue;
1362
1363 WARN_ON(plane->state->crtc && plane->state->crtc != crtc);
1364
1365 if (drm_atomic_plane_disabling(plane, old_plane_state) &&
1366 plane_funcs->atomic_disable)
1367 plane_funcs->atomic_disable(plane, old_plane_state);
1368 else if (plane->state->crtc ||
1369 drm_atomic_plane_disabling(plane, old_plane_state))
1370 plane_funcs->atomic_update(plane, old_plane_state);
1371 }
1372
1373 if (crtc_funcs && crtc_funcs->atomic_flush)
1374 crtc_funcs->atomic_flush(crtc, old_crtc_state);
1375 }
1376 EXPORT_SYMBOL(drm_atomic_helper_commit_planes_on_crtc);
1377
1378 /**
1379 * drm_atomic_helper_disable_planes_on_crtc - helper to disable CRTC's planes
1380 * @crtc: CRTC
1381 * @atomic: if set, synchronize with CRTC's atomic_begin/flush hooks
1382 *
1383 * Disables all planes associated with the given CRTC. This can be
1384 * used for instance in the CRTC helper disable callback to disable
1385 * all planes before shutting down the display pipeline.
1386 *
1387 * If the atomic-parameter is set the function calls the CRTC's
1388 * atomic_begin hook before and atomic_flush hook after disabling the
1389 * planes.
1390 *
1391 * It is a bug to call this function without having implemented the
1392 * ->atomic_disable() plane hook.
1393 */
1394 void drm_atomic_helper_disable_planes_on_crtc(struct drm_crtc *crtc,
1395 bool atomic)
1396 {
1397 const struct drm_crtc_helper_funcs *crtc_funcs =
1398 crtc->helper_private;
1399 struct drm_plane *plane;
1400
1401 if (atomic && crtc_funcs && crtc_funcs->atomic_begin)
1402 crtc_funcs->atomic_begin(crtc, NULL);
1403
1404 drm_for_each_plane(plane, crtc->dev) {
1405 const struct drm_plane_helper_funcs *plane_funcs =
1406 plane->helper_private;
1407
1408 if (plane->state->crtc != crtc || !plane_funcs)
1409 continue;
1410
1411 WARN_ON(!plane_funcs->atomic_disable);
1412 if (plane_funcs->atomic_disable)
1413 plane_funcs->atomic_disable(plane, NULL);
1414 }
1415
1416 if (atomic && crtc_funcs && crtc_funcs->atomic_flush)
1417 crtc_funcs->atomic_flush(crtc, NULL);
1418 }
1419 EXPORT_SYMBOL(drm_atomic_helper_disable_planes_on_crtc);
1420
1421 /**
1422 * drm_atomic_helper_cleanup_planes - cleanup plane resources after commit
1423 * @dev: DRM device
1424 * @old_state: atomic state object with old state structures
1425 *
1426 * This function cleans up plane state, specifically framebuffers, from the old
1427 * configuration. Hence the old configuration must be perserved in @old_state to
1428 * be able to call this function.
1429 *
1430 * This function must also be called on the new state when the atomic update
1431 * fails at any point after calling drm_atomic_helper_prepare_planes().
1432 */
1433 void drm_atomic_helper_cleanup_planes(struct drm_device *dev,
1434 struct drm_atomic_state *old_state)
1435 {
1436 struct drm_plane *plane;
1437 struct drm_plane_state *plane_state;
1438 int i;
1439
1440 for_each_plane_in_state(old_state, plane, plane_state, i) {
1441 const struct drm_plane_helper_funcs *funcs;
1442
1443 funcs = plane->helper_private;
1444
1445 if (funcs->cleanup_fb)
1446 funcs->cleanup_fb(plane, plane_state);
1447 }
1448 }
1449 EXPORT_SYMBOL(drm_atomic_helper_cleanup_planes);
1450
1451 /**
1452 * drm_atomic_helper_swap_state - store atomic state into current sw state
1453 * @dev: DRM device
1454 * @state: atomic state
1455 *
1456 * This function stores the atomic state into the current state pointers in all
1457 * driver objects. It should be called after all failing steps have been done
1458 * and succeeded, but before the actual hardware state is committed.
1459 *
1460 * For cleanup and error recovery the current state for all changed objects will
1461 * be swaped into @state.
1462 *
1463 * With that sequence it fits perfectly into the plane prepare/cleanup sequence:
1464 *
1465 * 1. Call drm_atomic_helper_prepare_planes() with the staged atomic state.
1466 *
1467 * 2. Do any other steps that might fail.
1468 *
1469 * 3. Put the staged state into the current state pointers with this function.
1470 *
1471 * 4. Actually commit the hardware state.
1472 *
1473 * 5. Call drm_atomic_helper_cleanup_planes() with @state, which since step 3
1474 * contains the old state. Also do any other cleanup required with that state.
1475 */
1476 void drm_atomic_helper_swap_state(struct drm_device *dev,
1477 struct drm_atomic_state *state)
1478 {
1479 int i;
1480
1481 for (i = 0; i < dev->mode_config.num_connector; i++) {
1482 struct drm_connector *connector = state->connectors[i];
1483
1484 if (!connector)
1485 continue;
1486
1487 connector->state->state = state;
1488 swap(state->connector_states[i], connector->state);
1489 connector->state->state = NULL;
1490 }
1491
1492 for (i = 0; i < dev->mode_config.num_crtc; i++) {
1493 struct drm_crtc *crtc = state->crtcs[i];
1494
1495 if (!crtc)
1496 continue;
1497
1498 crtc->state->state = state;
1499 swap(state->crtc_states[i], crtc->state);
1500 crtc->state->state = NULL;
1501 }
1502
1503 for (i = 0; i < dev->mode_config.num_total_plane; i++) {
1504 struct drm_plane *plane = state->planes[i];
1505
1506 if (!plane)
1507 continue;
1508
1509 plane->state->state = state;
1510 swap(state->plane_states[i], plane->state);
1511 plane->state->state = NULL;
1512 }
1513 }
1514 EXPORT_SYMBOL(drm_atomic_helper_swap_state);
1515
1516 /**
1517 * drm_atomic_helper_update_plane - Helper for primary plane update using atomic
1518 * @plane: plane object to update
1519 * @crtc: owning CRTC of owning plane
1520 * @fb: framebuffer to flip onto plane
1521 * @crtc_x: x offset of primary plane on crtc
1522 * @crtc_y: y offset of primary plane on crtc
1523 * @crtc_w: width of primary plane rectangle on crtc
1524 * @crtc_h: height of primary plane rectangle on crtc
1525 * @src_x: x offset of @fb for panning
1526 * @src_y: y offset of @fb for panning
1527 * @src_w: width of source rectangle in @fb
1528 * @src_h: height of source rectangle in @fb
1529 *
1530 * Provides a default plane update handler using the atomic driver interface.
1531 *
1532 * RETURNS:
1533 * Zero on success, error code on failure
1534 */
1535 int drm_atomic_helper_update_plane(struct drm_plane *plane,
1536 struct drm_crtc *crtc,
1537 struct drm_framebuffer *fb,
1538 int crtc_x, int crtc_y,
1539 unsigned int crtc_w, unsigned int crtc_h,
1540 uint32_t src_x, uint32_t src_y,
1541 uint32_t src_w, uint32_t src_h)
1542 {
1543 struct drm_atomic_state *state;
1544 struct drm_plane_state *plane_state;
1545 int ret = 0;
1546
1547 state = drm_atomic_state_alloc(plane->dev);
1548 if (!state)
1549 return -ENOMEM;
1550
1551 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
1552 retry:
1553 plane_state = drm_atomic_get_plane_state(state, plane);
1554 if (IS_ERR(plane_state)) {
1555 ret = PTR_ERR(plane_state);
1556 goto fail;
1557 }
1558
1559 ret = drm_atomic_set_crtc_for_plane(plane_state, crtc);
1560 if (ret != 0)
1561 goto fail;
1562 drm_atomic_set_fb_for_plane(plane_state, fb);
1563 plane_state->crtc_x = crtc_x;
1564 plane_state->crtc_y = crtc_y;
1565 plane_state->crtc_w = crtc_w;
1566 plane_state->crtc_h = crtc_h;
1567 plane_state->src_x = src_x;
1568 plane_state->src_y = src_y;
1569 plane_state->src_w = src_w;
1570 plane_state->src_h = src_h;
1571
1572 if (plane == crtc->cursor)
1573 state->legacy_cursor_update = true;
1574
1575 ret = drm_atomic_commit(state);
1576 if (ret != 0)
1577 goto fail;
1578
1579 /* Driver takes ownership of state on successful commit. */
1580 return 0;
1581 fail:
1582 if (ret == -EDEADLK)
1583 goto backoff;
1584
1585 drm_atomic_state_free(state);
1586
1587 return ret;
1588 backoff:
1589 drm_atomic_state_clear(state);
1590 drm_atomic_legacy_backoff(state);
1591
1592 /*
1593 * Someone might have exchanged the framebuffer while we dropped locks
1594 * in the backoff code. We need to fix up the fb refcount tracking the
1595 * core does for us.
1596 */
1597 plane->old_fb = plane->fb;
1598
1599 goto retry;
1600 }
1601 EXPORT_SYMBOL(drm_atomic_helper_update_plane);
1602
1603 /**
1604 * drm_atomic_helper_disable_plane - Helper for primary plane disable using * atomic
1605 * @plane: plane to disable
1606 *
1607 * Provides a default plane disable handler using the atomic driver interface.
1608 *
1609 * RETURNS:
1610 * Zero on success, error code on failure
1611 */
1612 int drm_atomic_helper_disable_plane(struct drm_plane *plane)
1613 {
1614 struct drm_atomic_state *state;
1615 struct drm_plane_state *plane_state;
1616 int ret = 0;
1617
1618 /*
1619 * FIXME: Without plane->crtc set we can't get at the implicit legacy
1620 * acquire context. The real fix will be to wire the acquire ctx through
1621 * everywhere we need it, but meanwhile prevent chaos by just skipping
1622 * this noop. The critical case is the cursor ioctls which a) only grab
1623 * crtc/cursor-plane locks (so we need the crtc to get at the right
1624 * acquire context) and b) can try to disable the plane multiple times.
1625 */
1626 if (!plane->crtc)
1627 return 0;
1628
1629 state = drm_atomic_state_alloc(plane->dev);
1630 if (!state)
1631 return -ENOMEM;
1632
1633 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(plane->crtc);
1634 retry:
1635 plane_state = drm_atomic_get_plane_state(state, plane);
1636 if (IS_ERR(plane_state)) {
1637 ret = PTR_ERR(plane_state);
1638 goto fail;
1639 }
1640
1641 if (plane_state->crtc && (plane == plane->crtc->cursor))
1642 plane_state->state->legacy_cursor_update = true;
1643
1644 ret = __drm_atomic_helper_disable_plane(plane, plane_state);
1645 if (ret != 0)
1646 goto fail;
1647
1648 ret = drm_atomic_commit(state);
1649 if (ret != 0)
1650 goto fail;
1651
1652 /* Driver takes ownership of state on successful commit. */
1653 return 0;
1654 fail:
1655 if (ret == -EDEADLK)
1656 goto backoff;
1657
1658 drm_atomic_state_free(state);
1659
1660 return ret;
1661 backoff:
1662 drm_atomic_state_clear(state);
1663 drm_atomic_legacy_backoff(state);
1664
1665 /*
1666 * Someone might have exchanged the framebuffer while we dropped locks
1667 * in the backoff code. We need to fix up the fb refcount tracking the
1668 * core does for us.
1669 */
1670 plane->old_fb = plane->fb;
1671
1672 goto retry;
1673 }
1674 EXPORT_SYMBOL(drm_atomic_helper_disable_plane);
1675
1676 /* just used from fb-helper and atomic-helper: */
1677 int __drm_atomic_helper_disable_plane(struct drm_plane *plane,
1678 struct drm_plane_state *plane_state)
1679 {
1680 int ret;
1681
1682 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
1683 if (ret != 0)
1684 return ret;
1685
1686 drm_atomic_set_fb_for_plane(plane_state, NULL);
1687 plane_state->crtc_x = 0;
1688 plane_state->crtc_y = 0;
1689 plane_state->crtc_w = 0;
1690 plane_state->crtc_h = 0;
1691 plane_state->src_x = 0;
1692 plane_state->src_y = 0;
1693 plane_state->src_w = 0;
1694 plane_state->src_h = 0;
1695
1696 return 0;
1697 }
1698
1699 static int update_output_state(struct drm_atomic_state *state,
1700 struct drm_mode_set *set)
1701 {
1702 struct drm_device *dev = set->crtc->dev;
1703 struct drm_crtc *crtc;
1704 struct drm_crtc_state *crtc_state;
1705 struct drm_connector *connector;
1706 struct drm_connector_state *conn_state;
1707 int ret, i, j;
1708
1709 ret = drm_modeset_lock(&dev->mode_config.connection_mutex,
1710 state->acquire_ctx);
1711 if (ret)
1712 return ret;
1713
1714 /* First grab all affected connector/crtc states. */
1715 for (i = 0; i < set->num_connectors; i++) {
1716 conn_state = drm_atomic_get_connector_state(state,
1717 set->connectors[i]);
1718 if (IS_ERR(conn_state))
1719 return PTR_ERR(conn_state);
1720 }
1721
1722 for_each_crtc_in_state(state, crtc, crtc_state, i) {
1723 ret = drm_atomic_add_affected_connectors(state, crtc);
1724 if (ret)
1725 return ret;
1726 }
1727
1728 /* Then recompute connector->crtc links and crtc enabling state. */
1729 for_each_connector_in_state(state, connector, conn_state, i) {
1730 if (conn_state->crtc == set->crtc) {
1731 ret = drm_atomic_set_crtc_for_connector(conn_state,
1732 NULL);
1733 if (ret)
1734 return ret;
1735 }
1736
1737 for (j = 0; j < set->num_connectors; j++) {
1738 if (set->connectors[j] == connector) {
1739 ret = drm_atomic_set_crtc_for_connector(conn_state,
1740 set->crtc);
1741 if (ret)
1742 return ret;
1743 break;
1744 }
1745 }
1746 }
1747
1748 for_each_crtc_in_state(state, crtc, crtc_state, i) {
1749 /* Don't update ->enable for the CRTC in the set_config request,
1750 * since a mismatch would indicate a bug in the upper layers.
1751 * The actual modeset code later on will catch any
1752 * inconsistencies here. */
1753 if (crtc == set->crtc)
1754 continue;
1755
1756 if (!drm_atomic_connectors_for_crtc(state, crtc)) {
1757 ret = drm_atomic_set_mode_prop_for_crtc(crtc_state,
1758 NULL);
1759 if (ret < 0)
1760 return ret;
1761
1762 crtc_state->active = false;
1763 }
1764 }
1765
1766 return 0;
1767 }
1768
1769 /**
1770 * drm_atomic_helper_set_config - set a new config from userspace
1771 * @set: mode set configuration
1772 *
1773 * Provides a default crtc set_config handler using the atomic driver interface.
1774 *
1775 * Returns:
1776 * Returns 0 on success, negative errno numbers on failure.
1777 */
1778 int drm_atomic_helper_set_config(struct drm_mode_set *set)
1779 {
1780 struct drm_atomic_state *state;
1781 struct drm_crtc *crtc = set->crtc;
1782 int ret = 0;
1783
1784 state = drm_atomic_state_alloc(crtc->dev);
1785 if (!state)
1786 return -ENOMEM;
1787
1788 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
1789 retry:
1790 ret = __drm_atomic_helper_set_config(set, state);
1791 if (ret != 0)
1792 goto fail;
1793
1794 ret = drm_atomic_commit(state);
1795 if (ret != 0)
1796 goto fail;
1797
1798 /* Driver takes ownership of state on successful commit. */
1799 return 0;
1800 fail:
1801 if (ret == -EDEADLK)
1802 goto backoff;
1803
1804 drm_atomic_state_free(state);
1805
1806 return ret;
1807 backoff:
1808 drm_atomic_state_clear(state);
1809 drm_atomic_legacy_backoff(state);
1810
1811 /*
1812 * Someone might have exchanged the framebuffer while we dropped locks
1813 * in the backoff code. We need to fix up the fb refcount tracking the
1814 * core does for us.
1815 */
1816 crtc->primary->old_fb = crtc->primary->fb;
1817
1818 goto retry;
1819 }
1820 EXPORT_SYMBOL(drm_atomic_helper_set_config);
1821
1822 /* just used from fb-helper and atomic-helper: */
1823 int __drm_atomic_helper_set_config(struct drm_mode_set *set,
1824 struct drm_atomic_state *state)
1825 {
1826 struct drm_crtc_state *crtc_state;
1827 struct drm_plane_state *primary_state;
1828 struct drm_crtc *crtc = set->crtc;
1829 int hdisplay, vdisplay;
1830 int ret;
1831
1832 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1833 if (IS_ERR(crtc_state))
1834 return PTR_ERR(crtc_state);
1835
1836 primary_state = drm_atomic_get_plane_state(state, crtc->primary);
1837 if (IS_ERR(primary_state))
1838 return PTR_ERR(primary_state);
1839
1840 if (!set->mode) {
1841 WARN_ON(set->fb);
1842 WARN_ON(set->num_connectors);
1843
1844 ret = drm_atomic_set_mode_for_crtc(crtc_state, NULL);
1845 if (ret != 0)
1846 return ret;
1847
1848 crtc_state->active = false;
1849
1850 ret = drm_atomic_set_crtc_for_plane(primary_state, NULL);
1851 if (ret != 0)
1852 return ret;
1853
1854 drm_atomic_set_fb_for_plane(primary_state, NULL);
1855
1856 goto commit;
1857 }
1858
1859 WARN_ON(!set->fb);
1860 WARN_ON(!set->num_connectors);
1861
1862 ret = drm_atomic_set_mode_for_crtc(crtc_state, set->mode);
1863 if (ret != 0)
1864 return ret;
1865
1866 crtc_state->active = true;
1867
1868 ret = drm_atomic_set_crtc_for_plane(primary_state, crtc);
1869 if (ret != 0)
1870 return ret;
1871
1872 drm_crtc_get_hv_timing(set->mode, &hdisplay, &vdisplay);
1873
1874 drm_atomic_set_fb_for_plane(primary_state, set->fb);
1875 primary_state->crtc_x = 0;
1876 primary_state->crtc_y = 0;
1877 primary_state->crtc_w = hdisplay;
1878 primary_state->crtc_h = vdisplay;
1879 primary_state->src_x = set->x << 16;
1880 primary_state->src_y = set->y << 16;
1881 if (primary_state->rotation & (BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270))) {
1882 primary_state->src_w = vdisplay << 16;
1883 primary_state->src_h = hdisplay << 16;
1884 } else {
1885 primary_state->src_w = hdisplay << 16;
1886 primary_state->src_h = vdisplay << 16;
1887 }
1888
1889 commit:
1890 ret = update_output_state(state, set);
1891 if (ret)
1892 return ret;
1893
1894 return 0;
1895 }
1896
1897 /**
1898 * drm_atomic_helper_disable_all - disable all currently active outputs
1899 * @dev: DRM device
1900 * @ctx: lock acquisition context
1901 *
1902 * Loops through all connectors, finding those that aren't turned off and then
1903 * turns them off by setting their DPMS mode to OFF and deactivating the CRTC
1904 * that they are connected to.
1905 *
1906 * This is used for example in suspend/resume to disable all currently active
1907 * functions when suspending.
1908 *
1909 * Note that if callers haven't already acquired all modeset locks this might
1910 * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
1911 *
1912 * Returns:
1913 * 0 on success or a negative error code on failure.
1914 *
1915 * See also:
1916 * drm_atomic_helper_suspend(), drm_atomic_helper_resume()
1917 */
1918 int drm_atomic_helper_disable_all(struct drm_device *dev,
1919 struct drm_modeset_acquire_ctx *ctx)
1920 {
1921 struct drm_atomic_state *state;
1922 struct drm_connector *conn;
1923 int err;
1924
1925 state = drm_atomic_state_alloc(dev);
1926 if (!state)
1927 return -ENOMEM;
1928
1929 state->acquire_ctx = ctx;
1930
1931 drm_for_each_connector(conn, dev) {
1932 struct drm_crtc *crtc = conn->state->crtc;
1933 struct drm_crtc_state *crtc_state;
1934
1935 if (!crtc || conn->dpms != DRM_MODE_DPMS_ON)
1936 continue;
1937
1938 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1939 if (IS_ERR(crtc_state)) {
1940 err = PTR_ERR(crtc_state);
1941 goto free;
1942 }
1943
1944 crtc_state->active = false;
1945 }
1946
1947 err = drm_atomic_commit(state);
1948
1949 free:
1950 if (err < 0)
1951 drm_atomic_state_free(state);
1952
1953 return err;
1954 }
1955 EXPORT_SYMBOL(drm_atomic_helper_disable_all);
1956
1957 /**
1958 * drm_atomic_helper_suspend - subsystem-level suspend helper
1959 * @dev: DRM device
1960 *
1961 * Duplicates the current atomic state, disables all active outputs and then
1962 * returns a pointer to the original atomic state to the caller. Drivers can
1963 * pass this pointer to the drm_atomic_helper_resume() helper upon resume to
1964 * restore the output configuration that was active at the time the system
1965 * entered suspend.
1966 *
1967 * Note that it is potentially unsafe to use this. The atomic state object
1968 * returned by this function is assumed to be persistent. Drivers must ensure
1969 * that this holds true. Before calling this function, drivers must make sure
1970 * to suspend fbdev emulation so that nothing can be using the device.
1971 *
1972 * Returns:
1973 * A pointer to a copy of the state before suspend on success or an ERR_PTR()-
1974 * encoded error code on failure. Drivers should store the returned atomic
1975 * state object and pass it to the drm_atomic_helper_resume() helper upon
1976 * resume.
1977 *
1978 * See also:
1979 * drm_atomic_helper_duplicate_state(), drm_atomic_helper_disable_all(),
1980 * drm_atomic_helper_resume()
1981 */
1982 struct drm_atomic_state *drm_atomic_helper_suspend(struct drm_device *dev)
1983 {
1984 struct drm_modeset_acquire_ctx ctx;
1985 struct drm_atomic_state *state;
1986 int err;
1987
1988 drm_modeset_acquire_init(&ctx, 0);
1989
1990 retry:
1991 err = drm_modeset_lock_all_ctx(dev, &ctx);
1992 if (err < 0) {
1993 state = ERR_PTR(err);
1994 goto unlock;
1995 }
1996
1997 state = drm_atomic_helper_duplicate_state(dev, &ctx);
1998 if (IS_ERR(state))
1999 goto unlock;
2000
2001 err = drm_atomic_helper_disable_all(dev, &ctx);
2002 if (err < 0) {
2003 drm_atomic_state_free(state);
2004 state = ERR_PTR(err);
2005 goto unlock;
2006 }
2007
2008 unlock:
2009 if (PTR_ERR(state) == -EDEADLK) {
2010 drm_modeset_backoff(&ctx);
2011 goto retry;
2012 }
2013
2014 drm_modeset_drop_locks(&ctx);
2015 drm_modeset_acquire_fini(&ctx);
2016 return state;
2017 }
2018 EXPORT_SYMBOL(drm_atomic_helper_suspend);
2019
2020 /**
2021 * drm_atomic_helper_resume - subsystem-level resume helper
2022 * @dev: DRM device
2023 * @state: atomic state to resume to
2024 *
2025 * Calls drm_mode_config_reset() to synchronize hardware and software states,
2026 * grabs all modeset locks and commits the atomic state object. This can be
2027 * used in conjunction with the drm_atomic_helper_suspend() helper to
2028 * implement suspend/resume for drivers that support atomic mode-setting.
2029 *
2030 * Returns:
2031 * 0 on success or a negative error code on failure.
2032 *
2033 * See also:
2034 * drm_atomic_helper_suspend()
2035 */
2036 int drm_atomic_helper_resume(struct drm_device *dev,
2037 struct drm_atomic_state *state)
2038 {
2039 struct drm_mode_config *config = &dev->mode_config;
2040 int err;
2041
2042 drm_mode_config_reset(dev);
2043 drm_modeset_lock_all(dev);
2044 state->acquire_ctx = config->acquire_ctx;
2045 err = drm_atomic_commit(state);
2046 drm_modeset_unlock_all(dev);
2047
2048 return err;
2049 }
2050 EXPORT_SYMBOL(drm_atomic_helper_resume);
2051
2052 /**
2053 * drm_atomic_helper_crtc_set_property - helper for crtc properties
2054 * @crtc: DRM crtc
2055 * @property: DRM property
2056 * @val: value of property
2057 *
2058 * Provides a default crtc set_property handler using the atomic driver
2059 * interface.
2060 *
2061 * RETURNS:
2062 * Zero on success, error code on failure
2063 */
2064 int
2065 drm_atomic_helper_crtc_set_property(struct drm_crtc *crtc,
2066 struct drm_property *property,
2067 uint64_t val)
2068 {
2069 struct drm_atomic_state *state;
2070 struct drm_crtc_state *crtc_state;
2071 int ret = 0;
2072
2073 state = drm_atomic_state_alloc(crtc->dev);
2074 if (!state)
2075 return -ENOMEM;
2076
2077 /* ->set_property is always called with all locks held. */
2078 state->acquire_ctx = crtc->dev->mode_config.acquire_ctx;
2079 retry:
2080 crtc_state = drm_atomic_get_crtc_state(state, crtc);
2081 if (IS_ERR(crtc_state)) {
2082 ret = PTR_ERR(crtc_state);
2083 goto fail;
2084 }
2085
2086 ret = drm_atomic_crtc_set_property(crtc, crtc_state,
2087 property, val);
2088 if (ret)
2089 goto fail;
2090
2091 ret = drm_atomic_commit(state);
2092 if (ret != 0)
2093 goto fail;
2094
2095 /* Driver takes ownership of state on successful commit. */
2096 return 0;
2097 fail:
2098 if (ret == -EDEADLK)
2099 goto backoff;
2100
2101 drm_atomic_state_free(state);
2102
2103 return ret;
2104 backoff:
2105 drm_atomic_state_clear(state);
2106 drm_atomic_legacy_backoff(state);
2107
2108 goto retry;
2109 }
2110 EXPORT_SYMBOL(drm_atomic_helper_crtc_set_property);
2111
2112 /**
2113 * drm_atomic_helper_plane_set_property - helper for plane properties
2114 * @plane: DRM plane
2115 * @property: DRM property
2116 * @val: value of property
2117 *
2118 * Provides a default plane set_property handler using the atomic driver
2119 * interface.
2120 *
2121 * RETURNS:
2122 * Zero on success, error code on failure
2123 */
2124 int
2125 drm_atomic_helper_plane_set_property(struct drm_plane *plane,
2126 struct drm_property *property,
2127 uint64_t val)
2128 {
2129 struct drm_atomic_state *state;
2130 struct drm_plane_state *plane_state;
2131 int ret = 0;
2132
2133 state = drm_atomic_state_alloc(plane->dev);
2134 if (!state)
2135 return -ENOMEM;
2136
2137 /* ->set_property is always called with all locks held. */
2138 state->acquire_ctx = plane->dev->mode_config.acquire_ctx;
2139 retry:
2140 plane_state = drm_atomic_get_plane_state(state, plane);
2141 if (IS_ERR(plane_state)) {
2142 ret = PTR_ERR(plane_state);
2143 goto fail;
2144 }
2145
2146 ret = drm_atomic_plane_set_property(plane, plane_state,
2147 property, val);
2148 if (ret)
2149 goto fail;
2150
2151 ret = drm_atomic_commit(state);
2152 if (ret != 0)
2153 goto fail;
2154
2155 /* Driver takes ownership of state on successful commit. */
2156 return 0;
2157 fail:
2158 if (ret == -EDEADLK)
2159 goto backoff;
2160
2161 drm_atomic_state_free(state);
2162
2163 return ret;
2164 backoff:
2165 drm_atomic_state_clear(state);
2166 drm_atomic_legacy_backoff(state);
2167
2168 goto retry;
2169 }
2170 EXPORT_SYMBOL(drm_atomic_helper_plane_set_property);
2171
2172 /**
2173 * drm_atomic_helper_connector_set_property - helper for connector properties
2174 * @connector: DRM connector
2175 * @property: DRM property
2176 * @val: value of property
2177 *
2178 * Provides a default connector set_property handler using the atomic driver
2179 * interface.
2180 *
2181 * RETURNS:
2182 * Zero on success, error code on failure
2183 */
2184 int
2185 drm_atomic_helper_connector_set_property(struct drm_connector *connector,
2186 struct drm_property *property,
2187 uint64_t val)
2188 {
2189 struct drm_atomic_state *state;
2190 struct drm_connector_state *connector_state;
2191 int ret = 0;
2192
2193 state = drm_atomic_state_alloc(connector->dev);
2194 if (!state)
2195 return -ENOMEM;
2196
2197 /* ->set_property is always called with all locks held. */
2198 state->acquire_ctx = connector->dev->mode_config.acquire_ctx;
2199 retry:
2200 connector_state = drm_atomic_get_connector_state(state, connector);
2201 if (IS_ERR(connector_state)) {
2202 ret = PTR_ERR(connector_state);
2203 goto fail;
2204 }
2205
2206 ret = drm_atomic_connector_set_property(connector, connector_state,
2207 property, val);
2208 if (ret)
2209 goto fail;
2210
2211 ret = drm_atomic_commit(state);
2212 if (ret != 0)
2213 goto fail;
2214
2215 /* Driver takes ownership of state on successful commit. */
2216 return 0;
2217 fail:
2218 if (ret == -EDEADLK)
2219 goto backoff;
2220
2221 drm_atomic_state_free(state);
2222
2223 return ret;
2224 backoff:
2225 drm_atomic_state_clear(state);
2226 drm_atomic_legacy_backoff(state);
2227
2228 goto retry;
2229 }
2230 EXPORT_SYMBOL(drm_atomic_helper_connector_set_property);
2231
2232 /**
2233 * drm_atomic_helper_page_flip - execute a legacy page flip
2234 * @crtc: DRM crtc
2235 * @fb: DRM framebuffer
2236 * @event: optional DRM event to signal upon completion
2237 * @flags: flip flags for non-vblank sync'ed updates
2238 *
2239 * Provides a default page flip implementation using the atomic driver interface.
2240 *
2241 * Note that for now so called async page flips (i.e. updates which are not
2242 * synchronized to vblank) are not supported, since the atomic interfaces have
2243 * no provisions for this yet.
2244 *
2245 * Returns:
2246 * Returns 0 on success, negative errno numbers on failure.
2247 */
2248 int drm_atomic_helper_page_flip(struct drm_crtc *crtc,
2249 struct drm_framebuffer *fb,
2250 struct drm_pending_vblank_event *event,
2251 uint32_t flags)
2252 {
2253 struct drm_plane *plane = crtc->primary;
2254 struct drm_atomic_state *state;
2255 struct drm_plane_state *plane_state;
2256 struct drm_crtc_state *crtc_state;
2257 int ret = 0;
2258
2259 if (flags & DRM_MODE_PAGE_FLIP_ASYNC)
2260 return -EINVAL;
2261
2262 state = drm_atomic_state_alloc(plane->dev);
2263 if (!state)
2264 return -ENOMEM;
2265
2266 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
2267 retry:
2268 crtc_state = drm_atomic_get_crtc_state(state, crtc);
2269 if (IS_ERR(crtc_state)) {
2270 ret = PTR_ERR(crtc_state);
2271 goto fail;
2272 }
2273 crtc_state->event = event;
2274
2275 plane_state = drm_atomic_get_plane_state(state, plane);
2276 if (IS_ERR(plane_state)) {
2277 ret = PTR_ERR(plane_state);
2278 goto fail;
2279 }
2280
2281 ret = drm_atomic_set_crtc_for_plane(plane_state, crtc);
2282 if (ret != 0)
2283 goto fail;
2284 drm_atomic_set_fb_for_plane(plane_state, fb);
2285
2286 ret = drm_atomic_async_commit(state);
2287 if (ret != 0)
2288 goto fail;
2289
2290 /* Driver takes ownership of state on successful async commit. */
2291 return 0;
2292 fail:
2293 if (ret == -EDEADLK)
2294 goto backoff;
2295
2296 drm_atomic_state_free(state);
2297
2298 return ret;
2299 backoff:
2300 drm_atomic_state_clear(state);
2301 drm_atomic_legacy_backoff(state);
2302
2303 /*
2304 * Someone might have exchanged the framebuffer while we dropped locks
2305 * in the backoff code. We need to fix up the fb refcount tracking the
2306 * core does for us.
2307 */
2308 plane->old_fb = plane->fb;
2309
2310 goto retry;
2311 }
2312 EXPORT_SYMBOL(drm_atomic_helper_page_flip);
2313
2314 /**
2315 * drm_atomic_helper_connector_dpms() - connector dpms helper implementation
2316 * @connector: affected connector
2317 * @mode: DPMS mode
2318 *
2319 * This is the main helper function provided by the atomic helper framework for
2320 * implementing the legacy DPMS connector interface. It computes the new desired
2321 * ->active state for the corresponding CRTC (if the connector is enabled) and
2322 * updates it.
2323 *
2324 * Returns:
2325 * Returns 0 on success, negative errno numbers on failure.
2326 */
2327 int drm_atomic_helper_connector_dpms(struct drm_connector *connector,
2328 int mode)
2329 {
2330 struct drm_mode_config *config = &connector->dev->mode_config;
2331 struct drm_atomic_state *state;
2332 struct drm_crtc_state *crtc_state;
2333 struct drm_crtc *crtc;
2334 struct drm_connector *tmp_connector;
2335 int ret;
2336 bool active = false;
2337 int old_mode = connector->dpms;
2338
2339 if (mode != DRM_MODE_DPMS_ON)
2340 mode = DRM_MODE_DPMS_OFF;
2341
2342 connector->dpms = mode;
2343 crtc = connector->state->crtc;
2344
2345 if (!crtc)
2346 return 0;
2347
2348 state = drm_atomic_state_alloc(connector->dev);
2349 if (!state)
2350 return -ENOMEM;
2351
2352 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
2353 retry:
2354 crtc_state = drm_atomic_get_crtc_state(state, crtc);
2355 if (IS_ERR(crtc_state)) {
2356 ret = PTR_ERR(crtc_state);
2357 goto fail;
2358 }
2359
2360 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
2361
2362 drm_for_each_connector(tmp_connector, connector->dev) {
2363 if (tmp_connector->state->crtc != crtc)
2364 continue;
2365
2366 if (tmp_connector->dpms == DRM_MODE_DPMS_ON) {
2367 active = true;
2368 break;
2369 }
2370 }
2371 crtc_state->active = active;
2372
2373 ret = drm_atomic_commit(state);
2374 if (ret != 0)
2375 goto fail;
2376
2377 /* Driver takes ownership of state on successful commit. */
2378 return 0;
2379 fail:
2380 if (ret == -EDEADLK)
2381 goto backoff;
2382
2383 connector->dpms = old_mode;
2384 drm_atomic_state_free(state);
2385
2386 return ret;
2387 backoff:
2388 drm_atomic_state_clear(state);
2389 drm_atomic_legacy_backoff(state);
2390
2391 goto retry;
2392 }
2393 EXPORT_SYMBOL(drm_atomic_helper_connector_dpms);
2394
2395 /**
2396 * DOC: atomic state reset and initialization
2397 *
2398 * Both the drm core and the atomic helpers assume that there is always the full
2399 * and correct atomic software state for all connectors, CRTCs and planes
2400 * available. Which is a bit a problem on driver load and also after system
2401 * suspend. One way to solve this is to have a hardware state read-out
2402 * infrastructure which reconstructs the full software state (e.g. the i915
2403 * driver).
2404 *
2405 * The simpler solution is to just reset the software state to everything off,
2406 * which is easiest to do by calling drm_mode_config_reset(). To facilitate this
2407 * the atomic helpers provide default reset implementations for all hooks.
2408 *
2409 * On the upside the precise state tracking of atomic simplifies system suspend
2410 * and resume a lot. For drivers using drm_mode_config_reset() a complete recipe
2411 * is implemented in drm_atomic_helper_suspend() and drm_atomic_helper_resume().
2412 * For other drivers the building blocks are split out, see the documentation
2413 * for these functions.
2414 */
2415
2416 /**
2417 * drm_atomic_helper_crtc_reset - default ->reset hook for CRTCs
2418 * @crtc: drm CRTC
2419 *
2420 * Resets the atomic state for @crtc by freeing the state pointer (which might
2421 * be NULL, e.g. at driver load time) and allocating a new empty state object.
2422 */
2423 void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc)
2424 {
2425 if (crtc->state)
2426 drm_property_unreference_blob(crtc->state->mode_blob);
2427 kfree(crtc->state);
2428 crtc->state = kzalloc(sizeof(*crtc->state), GFP_KERNEL);
2429
2430 if (crtc->state)
2431 crtc->state->crtc = crtc;
2432 }
2433 EXPORT_SYMBOL(drm_atomic_helper_crtc_reset);
2434
2435 /**
2436 * __drm_atomic_helper_crtc_duplicate_state - copy atomic CRTC state
2437 * @crtc: CRTC object
2438 * @state: atomic CRTC state
2439 *
2440 * Copies atomic state from a CRTC's current state and resets inferred values.
2441 * This is useful for drivers that subclass the CRTC state.
2442 */
2443 void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc,
2444 struct drm_crtc_state *state)
2445 {
2446 memcpy(state, crtc->state, sizeof(*state));
2447
2448 if (state->mode_blob)
2449 drm_property_reference_blob(state->mode_blob);
2450 state->mode_changed = false;
2451 state->active_changed = false;
2452 state->planes_changed = false;
2453 state->connectors_changed = false;
2454 state->event = NULL;
2455 }
2456 EXPORT_SYMBOL(__drm_atomic_helper_crtc_duplicate_state);
2457
2458 /**
2459 * drm_atomic_helper_crtc_duplicate_state - default state duplicate hook
2460 * @crtc: drm CRTC
2461 *
2462 * Default CRTC state duplicate hook for drivers which don't have their own
2463 * subclassed CRTC state structure.
2464 */
2465 struct drm_crtc_state *
2466 drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc)
2467 {
2468 struct drm_crtc_state *state;
2469
2470 if (WARN_ON(!crtc->state))
2471 return NULL;
2472
2473 state = kmalloc(sizeof(*state), GFP_KERNEL);
2474 if (state)
2475 __drm_atomic_helper_crtc_duplicate_state(crtc, state);
2476
2477 return state;
2478 }
2479 EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state);
2480
2481 /**
2482 * __drm_atomic_helper_crtc_destroy_state - release CRTC state
2483 * @crtc: CRTC object
2484 * @state: CRTC state object to release
2485 *
2486 * Releases all resources stored in the CRTC state without actually freeing
2487 * the memory of the CRTC state. This is useful for drivers that subclass the
2488 * CRTC state.
2489 */
2490 void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
2491 struct drm_crtc_state *state)
2492 {
2493 drm_property_unreference_blob(state->mode_blob);
2494 }
2495 EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state);
2496
2497 /**
2498 * drm_atomic_helper_crtc_destroy_state - default state destroy hook
2499 * @crtc: drm CRTC
2500 * @state: CRTC state object to release
2501 *
2502 * Default CRTC state destroy hook for drivers which don't have their own
2503 * subclassed CRTC state structure.
2504 */
2505 void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
2506 struct drm_crtc_state *state)
2507 {
2508 __drm_atomic_helper_crtc_destroy_state(crtc, state);
2509 kfree(state);
2510 }
2511 EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state);
2512
2513 /**
2514 * drm_atomic_helper_plane_reset - default ->reset hook for planes
2515 * @plane: drm plane
2516 *
2517 * Resets the atomic state for @plane by freeing the state pointer (which might
2518 * be NULL, e.g. at driver load time) and allocating a new empty state object.
2519 */
2520 void drm_atomic_helper_plane_reset(struct drm_plane *plane)
2521 {
2522 if (plane->state && plane->state->fb)
2523 drm_framebuffer_unreference(plane->state->fb);
2524
2525 kfree(plane->state);
2526 plane->state = kzalloc(sizeof(*plane->state), GFP_KERNEL);
2527
2528 if (plane->state)
2529 plane->state->plane = plane;
2530 }
2531 EXPORT_SYMBOL(drm_atomic_helper_plane_reset);
2532
2533 /**
2534 * __drm_atomic_helper_plane_duplicate_state - copy atomic plane state
2535 * @plane: plane object
2536 * @state: atomic plane state
2537 *
2538 * Copies atomic state from a plane's current state. This is useful for
2539 * drivers that subclass the plane state.
2540 */
2541 void __drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane,
2542 struct drm_plane_state *state)
2543 {
2544 memcpy(state, plane->state, sizeof(*state));
2545
2546 if (state->fb)
2547 drm_framebuffer_reference(state->fb);
2548 }
2549 EXPORT_SYMBOL(__drm_atomic_helper_plane_duplicate_state);
2550
2551 /**
2552 * drm_atomic_helper_plane_duplicate_state - default state duplicate hook
2553 * @plane: drm plane
2554 *
2555 * Default plane state duplicate hook for drivers which don't have their own
2556 * subclassed plane state structure.
2557 */
2558 struct drm_plane_state *
2559 drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane)
2560 {
2561 struct drm_plane_state *state;
2562
2563 if (WARN_ON(!plane->state))
2564 return NULL;
2565
2566 state = kmalloc(sizeof(*state), GFP_KERNEL);
2567 if (state)
2568 __drm_atomic_helper_plane_duplicate_state(plane, state);
2569
2570 return state;
2571 }
2572 EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state);
2573
2574 /**
2575 * __drm_atomic_helper_plane_destroy_state - release plane state
2576 * @plane: plane object
2577 * @state: plane state object to release
2578 *
2579 * Releases all resources stored in the plane state without actually freeing
2580 * the memory of the plane state. This is useful for drivers that subclass the
2581 * plane state.
2582 */
2583 void __drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
2584 struct drm_plane_state *state)
2585 {
2586 if (state->fb)
2587 drm_framebuffer_unreference(state->fb);
2588 }
2589 EXPORT_SYMBOL(__drm_atomic_helper_plane_destroy_state);
2590
2591 /**
2592 * drm_atomic_helper_plane_destroy_state - default state destroy hook
2593 * @plane: drm plane
2594 * @state: plane state object to release
2595 *
2596 * Default plane state destroy hook for drivers which don't have their own
2597 * subclassed plane state structure.
2598 */
2599 void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
2600 struct drm_plane_state *state)
2601 {
2602 __drm_atomic_helper_plane_destroy_state(plane, state);
2603 kfree(state);
2604 }
2605 EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state);
2606
2607 /**
2608 * drm_atomic_helper_connector_reset - default ->reset hook for connectors
2609 * @connector: drm connector
2610 *
2611 * Resets the atomic state for @connector by freeing the state pointer (which
2612 * might be NULL, e.g. at driver load time) and allocating a new empty state
2613 * object.
2614 */
2615 void drm_atomic_helper_connector_reset(struct drm_connector *connector)
2616 {
2617 kfree(connector->state);
2618 connector->state = kzalloc(sizeof(*connector->state), GFP_KERNEL);
2619
2620 if (connector->state)
2621 connector->state->connector = connector;
2622 }
2623 EXPORT_SYMBOL(drm_atomic_helper_connector_reset);
2624
2625 /**
2626 * __drm_atomic_helper_connector_duplicate_state - copy atomic connector state
2627 * @connector: connector object
2628 * @state: atomic connector state
2629 *
2630 * Copies atomic state from a connector's current state. This is useful for
2631 * drivers that subclass the connector state.
2632 */
2633 void
2634 __drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector,
2635 struct drm_connector_state *state)
2636 {
2637 memcpy(state, connector->state, sizeof(*state));
2638 }
2639 EXPORT_SYMBOL(__drm_atomic_helper_connector_duplicate_state);
2640
2641 /**
2642 * drm_atomic_helper_connector_duplicate_state - default state duplicate hook
2643 * @connector: drm connector
2644 *
2645 * Default connector state duplicate hook for drivers which don't have their own
2646 * subclassed connector state structure.
2647 */
2648 struct drm_connector_state *
2649 drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector)
2650 {
2651 struct drm_connector_state *state;
2652
2653 if (WARN_ON(!connector->state))
2654 return NULL;
2655
2656 state = kmalloc(sizeof(*state), GFP_KERNEL);
2657 if (state)
2658 __drm_atomic_helper_connector_duplicate_state(connector, state);
2659
2660 return state;
2661 }
2662 EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state);
2663
2664 /**
2665 * drm_atomic_helper_duplicate_state - duplicate an atomic state object
2666 * @dev: DRM device
2667 * @ctx: lock acquisition context
2668 *
2669 * Makes a copy of the current atomic state by looping over all objects and
2670 * duplicating their respective states. This is used for example by suspend/
2671 * resume support code to save the state prior to suspend such that it can
2672 * be restored upon resume.
2673 *
2674 * Note that this treats atomic state as persistent between save and restore.
2675 * Drivers must make sure that this is possible and won't result in confusion
2676 * or erroneous behaviour.
2677 *
2678 * Note that if callers haven't already acquired all modeset locks this might
2679 * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
2680 *
2681 * Returns:
2682 * A pointer to the copy of the atomic state object on success or an
2683 * ERR_PTR()-encoded error code on failure.
2684 *
2685 * See also:
2686 * drm_atomic_helper_suspend(), drm_atomic_helper_resume()
2687 */
2688 struct drm_atomic_state *
2689 drm_atomic_helper_duplicate_state(struct drm_device *dev,
2690 struct drm_modeset_acquire_ctx *ctx)
2691 {
2692 struct drm_atomic_state *state;
2693 struct drm_connector *conn;
2694 struct drm_plane *plane;
2695 struct drm_crtc *crtc;
2696 int err = 0;
2697
2698 state = drm_atomic_state_alloc(dev);
2699 if (!state)
2700 return ERR_PTR(-ENOMEM);
2701
2702 state->acquire_ctx = ctx;
2703
2704 drm_for_each_crtc(crtc, dev) {
2705 struct drm_crtc_state *crtc_state;
2706
2707 crtc_state = drm_atomic_get_crtc_state(state, crtc);
2708 if (IS_ERR(crtc_state)) {
2709 err = PTR_ERR(crtc_state);
2710 goto free;
2711 }
2712 }
2713
2714 drm_for_each_plane(plane, dev) {
2715 struct drm_plane_state *plane_state;
2716
2717 plane_state = drm_atomic_get_plane_state(state, plane);
2718 if (IS_ERR(plane_state)) {
2719 err = PTR_ERR(plane_state);
2720 goto free;
2721 }
2722 }
2723
2724 drm_for_each_connector(conn, dev) {
2725 struct drm_connector_state *conn_state;
2726
2727 conn_state = drm_atomic_get_connector_state(state, conn);
2728 if (IS_ERR(conn_state)) {
2729 err = PTR_ERR(conn_state);
2730 goto free;
2731 }
2732 }
2733
2734 /* clear the acquire context so that it isn't accidentally reused */
2735 state->acquire_ctx = NULL;
2736
2737 free:
2738 if (err < 0) {
2739 drm_atomic_state_free(state);
2740 state = ERR_PTR(err);
2741 }
2742
2743 return state;
2744 }
2745 EXPORT_SYMBOL(drm_atomic_helper_duplicate_state);
2746
2747 /**
2748 * __drm_atomic_helper_connector_destroy_state - release connector state
2749 * @connector: connector object
2750 * @state: connector state object to release
2751 *
2752 * Releases all resources stored in the connector state without actually
2753 * freeing the memory of the connector state. This is useful for drivers that
2754 * subclass the connector state.
2755 */
2756 void
2757 __drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
2758 struct drm_connector_state *state)
2759 {
2760 /*
2761 * This is currently a placeholder so that drivers that subclass the
2762 * state will automatically do the right thing if code is ever added
2763 * to this function.
2764 */
2765 }
2766 EXPORT_SYMBOL(__drm_atomic_helper_connector_destroy_state);
2767
2768 /**
2769 * drm_atomic_helper_connector_destroy_state - default state destroy hook
2770 * @connector: drm connector
2771 * @state: connector state object to release
2772 *
2773 * Default connector state destroy hook for drivers which don't have their own
2774 * subclassed connector state structure.
2775 */
2776 void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
2777 struct drm_connector_state *state)
2778 {
2779 __drm_atomic_helper_connector_destroy_state(connector, state);
2780 kfree(state);
2781 }
2782 EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state);
This page took 0.119288 seconds and 4 git commands to generate.