]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/gpu/drm/drm_atomic.c
Merge tag 'amd-drm-next-5.14-2021-05-19' of https://gitlab.freedesktop.org/agd5f...
[mirror_ubuntu-jammy-kernel.git] / drivers / gpu / drm / drm_atomic.c
CommitLineData
cc4ceb48
DV
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
0500c04e
SR
29#include <linux/sync_file.h>
30
cc4ceb48 31#include <drm/drm_atomic.h>
72fdb40c 32#include <drm/drm_atomic_uapi.h>
75146591 33#include <drm/drm_bridge.h>
0500c04e
SR
34#include <drm/drm_debugfs.h>
35#include <drm/drm_device.h>
36#include <drm/drm_drv.h>
37#include <drm/drm_file.h>
38#include <drm/drm_fourcc.h>
5488dc16 39#include <drm/drm_mode.h>
fceffb32 40#include <drm/drm_print.h>
935774cd 41#include <drm/drm_writeback.h>
cc4ceb48 42
be35f94f 43#include "drm_crtc_internal.h"
f02b604b 44#include "drm_internal.h"
be35f94f 45
b3ba3f6f 46void __drm_crtc_commit_free(struct kref *kref)
3b24f7d6
DV
47{
48 struct drm_crtc_commit *commit =
49 container_of(kref, struct drm_crtc_commit, ref);
50
51 kfree(commit);
52}
b3ba3f6f 53EXPORT_SYMBOL(__drm_crtc_commit_free);
3b24f7d6 54
b99c2c95
MR
55/**
56 * drm_crtc_commit_wait - Waits for a commit to complete
57 * @commit: &drm_crtc_commit to wait for
58 *
59 * Waits for a given &drm_crtc_commit to be programmed into the
60 * hardware and flipped to.
61 *
62 * Returns:
63 *
64 * 0 on success, a negative error code otherwise.
65 */
66int drm_crtc_commit_wait(struct drm_crtc_commit *commit)
67{
68 unsigned long timeout = 10 * HZ;
69 int ret;
70
71 if (!commit)
72 return 0;
73
74 ret = wait_for_completion_timeout(&commit->hw_done, timeout);
75 if (!ret) {
76 DRM_ERROR("hw_done timed out\n");
77 return -ETIMEDOUT;
78 }
79
80 /*
81 * Currently no support for overwriting flips, hence
82 * stall for previous one to execute completely.
83 */
84 ret = wait_for_completion_timeout(&commit->flip_done, timeout);
85 if (!ret) {
86 DRM_ERROR("flip_done timed out\n");
87 return -ETIMEDOUT;
88 }
89
90 return 0;
91}
92EXPORT_SYMBOL(drm_crtc_commit_wait);
93
036ef573
ML
94/**
95 * drm_atomic_state_default_release -
96 * release memory initialized by drm_atomic_state_init
97 * @state: atomic state
98 *
99 * Free all the memory allocated by drm_atomic_state_init.
da6c0596
DV
100 * This should only be used by drivers which are still subclassing
101 * &drm_atomic_state and haven't switched to &drm_private_state yet.
036ef573
ML
102 */
103void drm_atomic_state_default_release(struct drm_atomic_state *state)
cc4ceb48
DV
104{
105 kfree(state->connectors);
cc4ceb48 106 kfree(state->crtcs);
cc4ceb48 107 kfree(state->planes);
b430c27a 108 kfree(state->private_objs);
cc4ceb48 109}
036ef573 110EXPORT_SYMBOL(drm_atomic_state_default_release);
cc4ceb48
DV
111
112/**
036ef573 113 * drm_atomic_state_init - init new atomic state
cc4ceb48 114 * @dev: DRM device
036ef573 115 * @state: atomic state
cc4ceb48 116 *
036ef573 117 * Default implementation for filling in a new atomic state.
da6c0596
DV
118 * This should only be used by drivers which are still subclassing
119 * &drm_atomic_state and haven't switched to &drm_private_state yet.
cc4ceb48 120 */
036ef573
ML
121int
122drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state)
cc4ceb48 123{
0853695c
CW
124 kref_init(&state->ref);
125
d34f20d6
RC
126 /* TODO legacy paths should maybe do a better job about
127 * setting this appropriately?
128 */
129 state->allow_modeset = true;
130
cc4ceb48
DV
131 state->crtcs = kcalloc(dev->mode_config.num_crtc,
132 sizeof(*state->crtcs), GFP_KERNEL);
133 if (!state->crtcs)
134 goto fail;
cc4ceb48
DV
135 state->planes = kcalloc(dev->mode_config.num_total_plane,
136 sizeof(*state->planes), GFP_KERNEL);
137 if (!state->planes)
138 goto fail;
cc4ceb48
DV
139
140 state->dev = dev;
141
036ef573 142 DRM_DEBUG_ATOMIC("Allocated atomic state %p\n", state);
cc4ceb48 143
036ef573 144 return 0;
cc4ceb48 145fail:
036ef573
ML
146 drm_atomic_state_default_release(state);
147 return -ENOMEM;
148}
149EXPORT_SYMBOL(drm_atomic_state_init);
150
151/**
152 * drm_atomic_state_alloc - allocate atomic state
153 * @dev: DRM device
154 *
155 * This allocates an empty atomic state to track updates.
156 */
157struct drm_atomic_state *
158drm_atomic_state_alloc(struct drm_device *dev)
159{
160 struct drm_mode_config *config = &dev->mode_config;
036ef573
ML
161
162 if (!config->funcs->atomic_state_alloc) {
ac7c7483
DK
163 struct drm_atomic_state *state;
164
036ef573
ML
165 state = kzalloc(sizeof(*state), GFP_KERNEL);
166 if (!state)
167 return NULL;
168 if (drm_atomic_state_init(dev, state) < 0) {
169 kfree(state);
170 return NULL;
171 }
172 return state;
173 }
cc4ceb48 174
036ef573 175 return config->funcs->atomic_state_alloc(dev);
cc4ceb48
DV
176}
177EXPORT_SYMBOL(drm_atomic_state_alloc);
178
179/**
036ef573 180 * drm_atomic_state_default_clear - clear base atomic state
cc4ceb48
DV
181 * @state: atomic state
182 *
036ef573 183 * Default implementation for clearing atomic state.
da6c0596
DV
184 * This should only be used by drivers which are still subclassing
185 * &drm_atomic_state and haven't switched to &drm_private_state yet.
cc4ceb48 186 */
036ef573 187void drm_atomic_state_default_clear(struct drm_atomic_state *state)
cc4ceb48
DV
188{
189 struct drm_device *dev = state->dev;
6f75cea6 190 struct drm_mode_config *config = &dev->mode_config;
cc4ceb48
DV
191 int i;
192
17a38d9c 193 DRM_DEBUG_ATOMIC("Clearing atomic state %p\n", state);
cc4ceb48 194
f52b69f1 195 for (i = 0; i < state->num_connector; i++) {
63e83c1d 196 struct drm_connector *connector = state->connectors[i].ptr;
cc4ceb48
DV
197
198 if (!connector)
199 continue;
200
d2307dea 201 connector->funcs->atomic_destroy_state(connector,
63e83c1d
DV
202 state->connectors[i].state);
203 state->connectors[i].ptr = NULL;
204 state->connectors[i].state = NULL;
f0b408ee
VS
205 state->connectors[i].old_state = NULL;
206 state->connectors[i].new_state = NULL;
ad093607 207 drm_connector_put(connector);
cc4ceb48
DV
208 }
209
6f75cea6 210 for (i = 0; i < config->num_crtc; i++) {
5d943aa6 211 struct drm_crtc *crtc = state->crtcs[i].ptr;
cc4ceb48
DV
212
213 if (!crtc)
214 continue;
215
216 crtc->funcs->atomic_destroy_state(crtc,
5d943aa6 217 state->crtcs[i].state);
3b24f7d6 218
5d943aa6
DV
219 state->crtcs[i].ptr = NULL;
220 state->crtcs[i].state = NULL;
f0b408ee
VS
221 state->crtcs[i].old_state = NULL;
222 state->crtcs[i].new_state = NULL;
4364bcb2
LL
223
224 if (state->crtcs[i].commit) {
225 drm_crtc_commit_put(state->crtcs[i].commit);
226 state->crtcs[i].commit = NULL;
227 }
cc4ceb48
DV
228 }
229
6f75cea6 230 for (i = 0; i < config->num_total_plane; i++) {
b8b5342b 231 struct drm_plane *plane = state->planes[i].ptr;
cc4ceb48
DV
232
233 if (!plane)
234 continue;
235
236 plane->funcs->atomic_destroy_state(plane,
b8b5342b
DV
237 state->planes[i].state);
238 state->planes[i].ptr = NULL;
239 state->planes[i].state = NULL;
f0b408ee
VS
240 state->planes[i].old_state = NULL;
241 state->planes[i].new_state = NULL;
cc4ceb48 242 }
b430c27a
PD
243
244 for (i = 0; i < state->num_private_objs; i++) {
a4370c77 245 struct drm_private_obj *obj = state->private_objs[i].ptr;
b430c27a 246
a4370c77
VS
247 obj->funcs->atomic_destroy_state(obj,
248 state->private_objs[i].state);
249 state->private_objs[i].ptr = NULL;
250 state->private_objs[i].state = NULL;
b5cb2e5a
VS
251 state->private_objs[i].old_state = NULL;
252 state->private_objs[i].new_state = NULL;
b430c27a
PD
253 }
254 state->num_private_objs = 0;
255
21a01abb
ML
256 if (state->fake_commit) {
257 drm_crtc_commit_put(state->fake_commit);
258 state->fake_commit = NULL;
259 }
cc4ceb48 260}
036ef573
ML
261EXPORT_SYMBOL(drm_atomic_state_default_clear);
262
263/**
264 * drm_atomic_state_clear - clear state object
265 * @state: atomic state
266 *
267 * When the w/w mutex algorithm detects a deadlock we need to back off and drop
268 * all locks. So someone else could sneak in and change the current modeset
269 * configuration. Which means that all the state assembled in @state is no
270 * longer an atomic update to the current state, but to some arbitrary earlier
d574528a
DV
271 * state. Which could break assumptions the driver's
272 * &drm_mode_config_funcs.atomic_check likely relies on.
036ef573
ML
273 *
274 * Hence we must clear all cached state and completely start over, using this
275 * function.
276 */
277void drm_atomic_state_clear(struct drm_atomic_state *state)
278{
279 struct drm_device *dev = state->dev;
280 struct drm_mode_config *config = &dev->mode_config;
281
282 if (config->funcs->atomic_state_clear)
283 config->funcs->atomic_state_clear(state);
284 else
285 drm_atomic_state_default_clear(state);
286}
cc4ceb48
DV
287EXPORT_SYMBOL(drm_atomic_state_clear);
288
289/**
0853695c
CW
290 * __drm_atomic_state_free - free all memory for an atomic state
291 * @ref: This atomic state to deallocate
cc4ceb48
DV
292 *
293 * This frees all memory associated with an atomic state, including all the
42240c90 294 * per-object state for planes, CRTCs and connectors.
cc4ceb48 295 */
0853695c 296void __drm_atomic_state_free(struct kref *ref)
cc4ceb48 297{
0853695c
CW
298 struct drm_atomic_state *state = container_of(ref, typeof(*state), ref);
299 struct drm_mode_config *config = &state->dev->mode_config;
036ef573 300
cc4ceb48
DV
301 drm_atomic_state_clear(state);
302
17a38d9c 303 DRM_DEBUG_ATOMIC("Freeing atomic state %p\n", state);
cc4ceb48 304
036ef573
ML
305 if (config->funcs->atomic_state_free) {
306 config->funcs->atomic_state_free(state);
307 } else {
308 drm_atomic_state_default_release(state);
309 kfree(state);
310 }
cc4ceb48 311}
0853695c 312EXPORT_SYMBOL(__drm_atomic_state_free);
cc4ceb48
DV
313
314/**
42240c90 315 * drm_atomic_get_crtc_state - get CRTC state
cc4ceb48 316 * @state: global atomic state object
42240c90 317 * @crtc: CRTC to get state object for
cc4ceb48 318 *
42240c90
TR
319 * This function returns the CRTC state for the given CRTC, allocating it if
320 * needed. It will also grab the relevant CRTC lock to make sure that the state
cc4ceb48
DV
321 * is consistent.
322 *
fb6473a4
DV
323 * WARNING: Drivers may only add new CRTC states to a @state if
324 * drm_atomic_state.allow_modeset is set, or if it's a driver-internal commit
325 * not created by userspace through an IOCTL call.
326 *
cc4ceb48
DV
327 * Returns:
328 *
329 * Either the allocated state or the error code encoded into the pointer. When
330 * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
331 * entire atomic sequence must be restarted. All other errors are fatal.
332 */
333struct drm_crtc_state *
334drm_atomic_get_crtc_state(struct drm_atomic_state *state,
335 struct drm_crtc *crtc)
336{
1b26a5e1 337 int ret, index = drm_crtc_index(crtc);
cc4ceb48
DV
338 struct drm_crtc_state *crtc_state;
339
7f4eaa89
ML
340 WARN_ON(!state->acquire_ctx);
341
1b26a5e1
ML
342 crtc_state = drm_atomic_get_existing_crtc_state(state, crtc);
343 if (crtc_state)
344 return crtc_state;
cc4ceb48
DV
345
346 ret = drm_modeset_lock(&crtc->mutex, state->acquire_ctx);
347 if (ret)
348 return ERR_PTR(ret);
349
350 crtc_state = crtc->funcs->atomic_duplicate_state(crtc);
351 if (!crtc_state)
352 return ERR_PTR(-ENOMEM);
353
5d943aa6 354 state->crtcs[index].state = crtc_state;
581e49fe
ML
355 state->crtcs[index].old_state = crtc->state;
356 state->crtcs[index].new_state = crtc_state;
5d943aa6 357 state->crtcs[index].ptr = crtc;
cc4ceb48
DV
358 crtc_state->state = state;
359
fa3ab4c2
VS
360 DRM_DEBUG_ATOMIC("Added [CRTC:%d:%s] %p state to %p\n",
361 crtc->base.id, crtc->name, crtc_state, state);
cc4ceb48
DV
362
363 return crtc_state;
364}
365EXPORT_SYMBOL(drm_atomic_get_crtc_state);
366
b2432adf
VS
367static int drm_atomic_crtc_check(const struct drm_crtc_state *old_crtc_state,
368 const struct drm_crtc_state *new_crtc_state)
5e743737 369{
b2432adf
VS
370 struct drm_crtc *crtc = new_crtc_state->crtc;
371
5e743737
RC
372 /* NOTE: we explicitly don't enforce constraints such as primary
373 * layer covering entire screen, since that is something we want
374 * to allow (on hw that supports it). For hw that does not, it
375 * should be checked in driver's crtc->atomic_check() vfunc.
376 *
377 * TODO: Add generic modeset state checks once we support those.
378 */
eab3bbef 379
b2432adf 380 if (new_crtc_state->active && !new_crtc_state->enable) {
fa3ab4c2
VS
381 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] active without enabled\n",
382 crtc->base.id, crtc->name);
eab3bbef
DV
383 return -EINVAL;
384 }
385
99cf4a29
DS
386 /* The state->enable vs. state->mode_blob checks can be WARN_ON,
387 * as this is a kernel-internal detail that userspace should never
060726c5
BMC
388 * be able to trigger.
389 */
99cf4a29 390 if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) &&
b2432adf 391 WARN_ON(new_crtc_state->enable && !new_crtc_state->mode_blob)) {
fa3ab4c2
VS
392 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] enabled without mode blob\n",
393 crtc->base.id, crtc->name);
99cf4a29
DS
394 return -EINVAL;
395 }
396
397 if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) &&
b2432adf 398 WARN_ON(!new_crtc_state->enable && new_crtc_state->mode_blob)) {
fa3ab4c2
VS
399 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] disabled with mode blob\n",
400 crtc->base.id, crtc->name);
99cf4a29
DS
401 return -EINVAL;
402 }
403
4cba6850
DV
404 /*
405 * Reject event generation for when a CRTC is off and stays off.
406 * It wouldn't be hard to implement this, but userspace has a track
407 * record of happily burning through 100% cpu (or worse, crash) when the
408 * display pipe is suspended. To avoid all that fun just reject updates
409 * that ask for events since likely that indicates a bug in the
410 * compositor's drawing loop. This is consistent with the vblank IOCTL
411 * and legacy page_flip IOCTL which also reject service on a disabled
412 * pipe.
413 */
b2432adf
VS
414 if (new_crtc_state->event &&
415 !new_crtc_state->active && !old_crtc_state->active) {
6ac7c548
RK
416 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] requesting event but off\n",
417 crtc->base.id, crtc->name);
4cba6850
DV
418 return -EINVAL;
419 }
420
5e743737
RC
421 return 0;
422}
423
fceffb32
RC
424static void drm_atomic_crtc_print_state(struct drm_printer *p,
425 const struct drm_crtc_state *state)
426{
427 struct drm_crtc *crtc = state->crtc;
428
429 drm_printf(p, "crtc[%u]: %s\n", crtc->base.id, crtc->name);
430 drm_printf(p, "\tenable=%d\n", state->enable);
431 drm_printf(p, "\tactive=%d\n", state->active);
1452c25b 432 drm_printf(p, "\tself_refresh_active=%d\n", state->self_refresh_active);
fceffb32
RC
433 drm_printf(p, "\tplanes_changed=%d\n", state->planes_changed);
434 drm_printf(p, "\tmode_changed=%d\n", state->mode_changed);
435 drm_printf(p, "\tactive_changed=%d\n", state->active_changed);
436 drm_printf(p, "\tconnectors_changed=%d\n", state->connectors_changed);
437 drm_printf(p, "\tcolor_mgmt_changed=%d\n", state->color_mgmt_changed);
438 drm_printf(p, "\tplane_mask=%x\n", state->plane_mask);
439 drm_printf(p, "\tconnector_mask=%x\n", state->connector_mask);
440 drm_printf(p, "\tencoder_mask=%x\n", state->encoder_mask);
441 drm_printf(p, "\tmode: " DRM_MODE_FMT "\n", DRM_MODE_ARG(&state->mode));
442
443 if (crtc->funcs->atomic_print_state)
444 crtc->funcs->atomic_print_state(p, state);
445}
446
935774cd
BS
447static int drm_atomic_connector_check(struct drm_connector *connector,
448 struct drm_connector_state *state)
449{
450 struct drm_crtc_state *crtc_state;
451 struct drm_writeback_job *writeback_job = state->writeback_job;
47e22ff1
RS
452 const struct drm_display_info *info = &connector->display_info;
453
454 state->max_bpc = info->bpc ? info->bpc : 8;
455 if (connector->max_bpc_property)
456 state->max_bpc = min(state->max_bpc, state->max_requested_bpc);
935774cd
BS
457
458 if ((connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK) || !writeback_job)
459 return 0;
460
461 if (writeback_job->fb && !state->crtc) {
462 DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] framebuffer without CRTC\n",
463 connector->base.id, connector->name);
464 return -EINVAL;
465 }
466
467 if (state->crtc)
468 crtc_state = drm_atomic_get_existing_crtc_state(state->state,
469 state->crtc);
470
471 if (writeback_job->fb && !crtc_state->active) {
472 DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] has framebuffer, but [CRTC:%d] is off\n",
473 connector->base.id, connector->name,
474 state->crtc->base.id);
475 return -EINVAL;
476 }
477
8581d510
LLATC
478 if (!writeback_job->fb) {
479 if (writeback_job->out_fence) {
480 DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] requesting out-fence without framebuffer\n",
481 connector->base.id, connector->name);
482 return -EINVAL;
483 }
484
485 drm_writeback_cleanup_job(writeback_job);
486 state->writeback_job = NULL;
b13cc8dd
BS
487 }
488
935774cd
BS
489 return 0;
490}
491
cc4ceb48
DV
492/**
493 * drm_atomic_get_plane_state - get plane state
494 * @state: global atomic state object
495 * @plane: plane to get state object for
496 *
497 * This function returns the plane state for the given plane, allocating it if
498 * needed. It will also grab the relevant plane lock to make sure that the state
499 * is consistent.
500 *
501 * Returns:
502 *
503 * Either the allocated state or the error code encoded into the pointer. When
504 * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
505 * entire atomic sequence must be restarted. All other errors are fatal.
506 */
507struct drm_plane_state *
508drm_atomic_get_plane_state(struct drm_atomic_state *state,
509 struct drm_plane *plane)
510{
1b26a5e1 511 int ret, index = drm_plane_index(plane);
cc4ceb48
DV
512 struct drm_plane_state *plane_state;
513
7f4eaa89
ML
514 WARN_ON(!state->acquire_ctx);
515
e00fb856
VS
516 /* the legacy pointers should never be set */
517 WARN_ON(plane->fb);
518 WARN_ON(plane->old_fb);
519 WARN_ON(plane->crtc);
520
1b26a5e1
ML
521 plane_state = drm_atomic_get_existing_plane_state(state, plane);
522 if (plane_state)
523 return plane_state;
cc4ceb48 524
4d02e2de 525 ret = drm_modeset_lock(&plane->mutex, state->acquire_ctx);
cc4ceb48
DV
526 if (ret)
527 return ERR_PTR(ret);
528
529 plane_state = plane->funcs->atomic_duplicate_state(plane);
530 if (!plane_state)
531 return ERR_PTR(-ENOMEM);
532
b8b5342b
DV
533 state->planes[index].state = plane_state;
534 state->planes[index].ptr = plane;
581e49fe
ML
535 state->planes[index].old_state = plane->state;
536 state->planes[index].new_state = plane_state;
cc4ceb48
DV
537 plane_state->state = state;
538
9f4c97a2
VS
539 DRM_DEBUG_ATOMIC("Added [PLANE:%d:%s] %p state to %p\n",
540 plane->base.id, plane->name, plane_state, state);
cc4ceb48
DV
541
542 if (plane_state->crtc) {
543 struct drm_crtc_state *crtc_state;
544
545 crtc_state = drm_atomic_get_crtc_state(state,
546 plane_state->crtc);
547 if (IS_ERR(crtc_state))
548 return ERR_CAST(crtc_state);
549 }
550
551 return plane_state;
552}
553EXPORT_SYMBOL(drm_atomic_get_plane_state);
554
f8aeb41c 555static bool
d9be05b7
VS
556plane_switching_crtc(const struct drm_plane_state *old_plane_state,
557 const struct drm_plane_state *new_plane_state)
f8aeb41c 558{
d9be05b7 559 if (!old_plane_state->crtc || !new_plane_state->crtc)
f8aeb41c
DV
560 return false;
561
d9be05b7 562 if (old_plane_state->crtc == new_plane_state->crtc)
f8aeb41c
DV
563 return false;
564
565 /* This could be refined, but currently there's no helper or driver code
566 * to implement direct switching of active planes nor userspace to take
567 * advantage of more direct plane switching without the intermediate
568 * full OFF state.
569 */
570 return true;
571}
572
5e743737
RC
573/**
574 * drm_atomic_plane_check - check plane state
d9be05b7
VS
575 * @old_plane_state: old plane state to check
576 * @new_plane_state: new plane state to check
5e743737
RC
577 *
578 * Provides core sanity checks for plane state.
579 *
580 * RETURNS:
581 * Zero on success, error code on failure
582 */
d9be05b7
VS
583static int drm_atomic_plane_check(const struct drm_plane_state *old_plane_state,
584 const struct drm_plane_state *new_plane_state)
5e743737 585{
d9be05b7
VS
586 struct drm_plane *plane = new_plane_state->plane;
587 struct drm_crtc *crtc = new_plane_state->crtc;
588 const struct drm_framebuffer *fb = new_plane_state->fb;
5e743737 589 unsigned int fb_width, fb_height;
d3b21767
LS
590 struct drm_mode_rect *clips;
591 uint32_t num_clips;
ead8610d 592 int ret;
5e743737
RC
593
594 /* either *both* CRTC and FB must be set, or neither */
d9be05b7 595 if (crtc && !fb) {
b6f690ab
VS
596 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] CRTC set but no FB\n",
597 plane->base.id, plane->name);
5e743737 598 return -EINVAL;
d9be05b7 599 } else if (fb && !crtc) {
b6f690ab
VS
600 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] FB set but no CRTC\n",
601 plane->base.id, plane->name);
5e743737
RC
602 return -EINVAL;
603 }
604
605 /* if disabled, we don't care about the rest of the state: */
d9be05b7 606 if (!crtc)
5e743737
RC
607 return 0;
608
609 /* Check whether this plane is usable on this CRTC */
d9be05b7 610 if (!(plane->possible_crtcs & drm_crtc_mask(crtc))) {
b6f690ab 611 DRM_DEBUG_ATOMIC("Invalid [CRTC:%d:%s] for [PLANE:%d:%s]\n",
d9be05b7 612 crtc->base.id, crtc->name,
b6f690ab 613 plane->base.id, plane->name);
5e743737
RC
614 return -EINVAL;
615 }
616
617 /* Check whether this plane supports the fb pixel format. */
d9be05b7
VS
618 ret = drm_plane_check_pixel_format(plane, fb->format->format,
619 fb->modifier);
ead8610d 620 if (ret) {
92f1d09c 621 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] invalid pixel format %p4cc, modifier 0x%llx\n",
b6f690ab 622 plane->base.id, plane->name,
92f1d09c 623 &fb->format->format, fb->modifier);
ead8610d 624 return ret;
5e743737
RC
625 }
626
627 /* Give drivers some help against integer overflows */
d9be05b7
VS
628 if (new_plane_state->crtc_w > INT_MAX ||
629 new_plane_state->crtc_x > INT_MAX - (int32_t) new_plane_state->crtc_w ||
630 new_plane_state->crtc_h > INT_MAX ||
631 new_plane_state->crtc_y > INT_MAX - (int32_t) new_plane_state->crtc_h) {
b6f690ab
VS
632 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] invalid CRTC coordinates %ux%u+%d+%d\n",
633 plane->base.id, plane->name,
d9be05b7
VS
634 new_plane_state->crtc_w, new_plane_state->crtc_h,
635 new_plane_state->crtc_x, new_plane_state->crtc_y);
5e743737
RC
636 return -ERANGE;
637 }
638
d9be05b7
VS
639 fb_width = fb->width << 16;
640 fb_height = fb->height << 16;
5e743737
RC
641
642 /* Make sure source coordinates are inside the fb. */
d9be05b7
VS
643 if (new_plane_state->src_w > fb_width ||
644 new_plane_state->src_x > fb_width - new_plane_state->src_w ||
645 new_plane_state->src_h > fb_height ||
646 new_plane_state->src_y > fb_height - new_plane_state->src_h) {
b6f690ab 647 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] invalid source coordinates "
0338f0d0 648 "%u.%06ux%u.%06u+%u.%06u+%u.%06u (fb %ux%u)\n",
b6f690ab 649 plane->base.id, plane->name,
d9be05b7
VS
650 new_plane_state->src_w >> 16,
651 ((new_plane_state->src_w & 0xffff) * 15625) >> 10,
652 new_plane_state->src_h >> 16,
653 ((new_plane_state->src_h & 0xffff) * 15625) >> 10,
654 new_plane_state->src_x >> 16,
655 ((new_plane_state->src_x & 0xffff) * 15625) >> 10,
656 new_plane_state->src_y >> 16,
657 ((new_plane_state->src_y & 0xffff) * 15625) >> 10,
658 fb->width, fb->height);
5e743737
RC
659 return -ENOSPC;
660 }
661
d3b21767
LS
662 clips = drm_plane_get_damage_clips(new_plane_state);
663 num_clips = drm_plane_get_damage_clips_count(new_plane_state);
664
665 /* Make sure damage clips are valid and inside the fb. */
666 while (num_clips > 0) {
667 if (clips->x1 >= clips->x2 ||
668 clips->y1 >= clips->y2 ||
669 clips->x1 < 0 ||
670 clips->y1 < 0 ||
671 clips->x2 > fb_width ||
672 clips->y2 > fb_height) {
673 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] invalid damage clip %d %d %d %d\n",
674 plane->base.id, plane->name, clips->x1,
675 clips->y1, clips->x2, clips->y2);
676 return -EINVAL;
677 }
678 clips++;
679 num_clips--;
680 }
681
d9be05b7 682 if (plane_switching_crtc(old_plane_state, new_plane_state)) {
9f4c97a2
VS
683 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] switching CRTC directly\n",
684 plane->base.id, plane->name);
f8aeb41c
DV
685 return -EINVAL;
686 }
687
5e743737
RC
688 return 0;
689}
690
fceffb32
RC
691static void drm_atomic_plane_print_state(struct drm_printer *p,
692 const struct drm_plane_state *state)
693{
694 struct drm_plane *plane = state->plane;
695 struct drm_rect src = drm_plane_state_src(state);
696 struct drm_rect dest = drm_plane_state_dest(state);
697
698 drm_printf(p, "plane[%u]: %s\n", plane->base.id, plane->name);
699 drm_printf(p, "\tcrtc=%s\n", state->crtc ? state->crtc->name : "(null)");
700 drm_printf(p, "\tfb=%u\n", state->fb ? state->fb->base.id : 0);
f02b604b
NT
701 if (state->fb)
702 drm_framebuffer_print_info(p, 2, state->fb);
fceffb32
RC
703 drm_printf(p, "\tcrtc-pos=" DRM_RECT_FMT "\n", DRM_RECT_ARG(&dest));
704 drm_printf(p, "\tsrc-pos=" DRM_RECT_FP_FMT "\n", DRM_RECT_FP_ARG(&src));
705 drm_printf(p, "\trotation=%x\n", state->rotation);
f8878bb2 706 drm_printf(p, "\tnormalized-zpos=%x\n", state->normalized_zpos);
56dbbaff
VS
707 drm_printf(p, "\tcolor-encoding=%s\n",
708 drm_get_color_encoding_name(state->color_encoding));
709 drm_printf(p, "\tcolor-range=%s\n",
710 drm_get_color_range_name(state->color_range));
fceffb32
RC
711
712 if (plane->funcs->atomic_print_state)
713 plane->funcs->atomic_print_state(p, state);
714}
715
da6c0596
DV
716/**
717 * DOC: handling driver private state
718 *
719 * Very often the DRM objects exposed to userspace in the atomic modeset api
720 * (&drm_connector, &drm_crtc and &drm_plane) do not map neatly to the
721 * underlying hardware. Especially for any kind of shared resources (e.g. shared
722 * clocks, scaler units, bandwidth and fifo limits shared among a group of
723 * planes or CRTCs, and so on) it makes sense to model these as independent
724 * objects. Drivers then need to do similar state tracking and commit ordering for
725 * such private (since not exposed to userpace) objects as the atomic core and
726 * helpers already provide for connectors, planes and CRTCs.
727 *
728 * To make this easier on drivers the atomic core provides some support to track
729 * driver private state objects using struct &drm_private_obj, with the
730 * associated state struct &drm_private_state.
731 *
732 * Similar to userspace-exposed objects, private state structures can be
0380c684
DV
733 * acquired by calling drm_atomic_get_private_obj_state(). This also takes care
734 * of locking, hence drivers should not have a need to call drm_modeset_lock()
735 * directly. Sequence of the actual hardware state commit is not handled,
736 * drivers might need to keep track of struct drm_crtc_commit within subclassed
737 * structure of &drm_private_state as necessary, e.g. similar to
738 * &drm_plane_state.commit. See also &drm_atomic_state.fake_commit.
da6c0596
DV
739 *
740 * All private state structures contained in a &drm_atomic_state update can be
741 * iterated using for_each_oldnew_private_obj_in_state(),
742 * for_each_new_private_obj_in_state() and for_each_old_private_obj_in_state().
743 * Drivers are recommended to wrap these for each type of driver private state
744 * object they have, filtering on &drm_private_obj.funcs using for_each_if(), at
745 * least if they want to iterate over all objects of a given type.
746 *
747 * An earlier way to handle driver private state was by subclassing struct
748 * &drm_atomic_state. But since that encourages non-standard ways to implement
749 * the check/commit split atomic requires (by using e.g. "check and rollback or
750 * commit instead" of "duplicate state, check, then either commit or release
751 * duplicated state) it is deprecated in favour of using &drm_private_state.
752 */
753
a4370c77
VS
754/**
755 * drm_atomic_private_obj_init - initialize private object
b962a120 756 * @dev: DRM device this object will be attached to
a4370c77
VS
757 * @obj: private object
758 * @state: initial private object state
759 * @funcs: pointer to the struct of function pointers that identify the object
760 * type
761 *
762 * Initialize the private object, which can be embedded into any
763 * driver private object that needs its own atomic state.
764 */
765void
b962a120
RC
766drm_atomic_private_obj_init(struct drm_device *dev,
767 struct drm_private_obj *obj,
a4370c77
VS
768 struct drm_private_state *state,
769 const struct drm_private_state_funcs *funcs)
770{
771 memset(obj, 0, sizeof(*obj));
772
b962a120
RC
773 drm_modeset_lock_init(&obj->lock);
774
a4370c77
VS
775 obj->state = state;
776 obj->funcs = funcs;
b962a120 777 list_add_tail(&obj->head, &dev->mode_config.privobj_list);
a4370c77
VS
778}
779EXPORT_SYMBOL(drm_atomic_private_obj_init);
780
781/**
782 * drm_atomic_private_obj_fini - finalize private object
783 * @obj: private object
784 *
785 * Finalize the private object.
786 */
787void
788drm_atomic_private_obj_fini(struct drm_private_obj *obj)
789{
b962a120 790 list_del(&obj->head);
a4370c77 791 obj->funcs->atomic_destroy_state(obj, obj->state);
b962a120 792 drm_modeset_lock_fini(&obj->lock);
a4370c77
VS
793}
794EXPORT_SYMBOL(drm_atomic_private_obj_fini);
795
b430c27a
PD
796/**
797 * drm_atomic_get_private_obj_state - get private object state
798 * @state: global atomic state
799 * @obj: private object to get the state for
b430c27a
PD
800 *
801 * This function returns the private object state for the given private object,
b962a120
RC
802 * allocating the state if needed. It will also grab the relevant private
803 * object lock to make sure that the state is consistent.
b430c27a
PD
804 *
805 * RETURNS:
806 *
807 * Either the allocated state or the error code encoded into a pointer.
808 */
a4370c77
VS
809struct drm_private_state *
810drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
811 struct drm_private_obj *obj)
b430c27a 812{
b962a120 813 int index, num_objs, i, ret;
b430c27a
PD
814 size_t size;
815 struct __drm_private_objs_state *arr;
a4370c77 816 struct drm_private_state *obj_state;
b430c27a
PD
817
818 for (i = 0; i < state->num_private_objs; i++)
a4370c77
VS
819 if (obj == state->private_objs[i].ptr)
820 return state->private_objs[i].state;
b430c27a 821
b962a120
RC
822 ret = drm_modeset_lock(&obj->lock, state->acquire_ctx);
823 if (ret)
824 return ERR_PTR(ret);
825
b430c27a
PD
826 num_objs = state->num_private_objs + 1;
827 size = sizeof(*state->private_objs) * num_objs;
828 arr = krealloc(state->private_objs, size, GFP_KERNEL);
829 if (!arr)
830 return ERR_PTR(-ENOMEM);
831
832 state->private_objs = arr;
833 index = state->num_private_objs;
834 memset(&state->private_objs[index], 0, sizeof(*state->private_objs));
835
a4370c77
VS
836 obj_state = obj->funcs->atomic_duplicate_state(obj);
837 if (!obj_state)
b430c27a
PD
838 return ERR_PTR(-ENOMEM);
839
a4370c77
VS
840 state->private_objs[index].state = obj_state;
841 state->private_objs[index].old_state = obj->state;
842 state->private_objs[index].new_state = obj_state;
843 state->private_objs[index].ptr = obj;
e89ea355 844 obj_state->state = state;
a4370c77 845
b430c27a
PD
846 state->num_private_objs = num_objs;
847
a4370c77
VS
848 DRM_DEBUG_ATOMIC("Added new private object %p state %p to %p\n",
849 obj, obj_state, state);
b430c27a 850
a4370c77 851 return obj_state;
b430c27a
PD
852}
853EXPORT_SYMBOL(drm_atomic_get_private_obj_state);
854
9801a7ea
ATC
855/**
856 * drm_atomic_get_old_private_obj_state
857 * @state: global atomic state object
858 * @obj: private_obj to grab
859 *
860 * This function returns the old private object state for the given private_obj,
861 * or NULL if the private_obj is not part of the global atomic state.
862 */
863struct drm_private_state *
864drm_atomic_get_old_private_obj_state(struct drm_atomic_state *state,
865 struct drm_private_obj *obj)
866{
867 int i;
868
869 for (i = 0; i < state->num_private_objs; i++)
870 if (obj == state->private_objs[i].ptr)
871 return state->private_objs[i].old_state;
872
873 return NULL;
874}
875EXPORT_SYMBOL(drm_atomic_get_old_private_obj_state);
876
877/**
878 * drm_atomic_get_new_private_obj_state
879 * @state: global atomic state object
880 * @obj: private_obj to grab
881 *
882 * This function returns the new private object state for the given private_obj,
883 * or NULL if the private_obj is not part of the global atomic state.
884 */
885struct drm_private_state *
886drm_atomic_get_new_private_obj_state(struct drm_atomic_state *state,
887 struct drm_private_obj *obj)
888{
889 int i;
890
891 for (i = 0; i < state->num_private_objs; i++)
892 if (obj == state->private_objs[i].ptr)
893 return state->private_objs[i].new_state;
894
895 return NULL;
896}
897EXPORT_SYMBOL(drm_atomic_get_new_private_obj_state);
898
1b27fbdd
LP
899/**
900 * drm_atomic_get_old_connector_for_encoder - Get old connector for an encoder
901 * @state: Atomic state
902 * @encoder: The encoder to fetch the connector state for
903 *
904 * This function finds and returns the connector that was connected to @encoder
905 * as specified by the @state.
906 *
907 * If there is no connector in @state which previously had @encoder connected to
908 * it, this function will return NULL. While this may seem like an invalid use
909 * case, it is sometimes useful to differentiate commits which had no prior
910 * connectors attached to @encoder vs ones that did (and to inspect their
911 * state). This is especially true in enable hooks because the pipeline has
912 * changed.
913 *
914 * Returns: The old connector connected to @encoder, or NULL if the encoder is
915 * not connected.
916 */
917struct drm_connector *
918drm_atomic_get_old_connector_for_encoder(struct drm_atomic_state *state,
919 struct drm_encoder *encoder)
920{
921 struct drm_connector_state *conn_state;
922 struct drm_connector *connector;
923 unsigned int i;
924
925 for_each_old_connector_in_state(state, connector, conn_state, i) {
926 if (conn_state->best_encoder == encoder)
927 return connector;
928 }
929
930 return NULL;
931}
932EXPORT_SYMBOL(drm_atomic_get_old_connector_for_encoder);
933
934/**
935 * drm_atomic_get_new_connector_for_encoder - Get new connector for an encoder
936 * @state: Atomic state
937 * @encoder: The encoder to fetch the connector state for
938 *
939 * This function finds and returns the connector that will be connected to
940 * @encoder as specified by the @state.
941 *
942 * If there is no connector in @state which will have @encoder connected to it,
943 * this function will return NULL. While this may seem like an invalid use case,
944 * it is sometimes useful to differentiate commits which have no connectors
945 * attached to @encoder vs ones that do (and to inspect their state). This is
946 * especially true in disable hooks because the pipeline will change.
947 *
948 * Returns: The new connector connected to @encoder, or NULL if the encoder is
949 * not connected.
950 */
951struct drm_connector *
952drm_atomic_get_new_connector_for_encoder(struct drm_atomic_state *state,
953 struct drm_encoder *encoder)
954{
955 struct drm_connector_state *conn_state;
956 struct drm_connector *connector;
957 unsigned int i;
958
959 for_each_new_connector_in_state(state, connector, conn_state, i) {
960 if (conn_state->best_encoder == encoder)
961 return connector;
962 }
963
964 return NULL;
965}
966EXPORT_SYMBOL(drm_atomic_get_new_connector_for_encoder);
967
cc4ceb48
DV
968/**
969 * drm_atomic_get_connector_state - get connector state
970 * @state: global atomic state object
971 * @connector: connector to get state object for
972 *
973 * This function returns the connector state for the given connector,
974 * allocating it if needed. It will also grab the relevant connector lock to
975 * make sure that the state is consistent.
976 *
977 * Returns:
978 *
979 * Either the allocated state or the error code encoded into the pointer. When
980 * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
981 * entire atomic sequence must be restarted. All other errors are fatal.
982 */
983struct drm_connector_state *
984drm_atomic_get_connector_state(struct drm_atomic_state *state,
985 struct drm_connector *connector)
986{
987 int ret, index;
988 struct drm_mode_config *config = &connector->dev->mode_config;
989 struct drm_connector_state *connector_state;
990
7f4eaa89
ML
991 WARN_ON(!state->acquire_ctx);
992
c7eb76f4
DV
993 ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
994 if (ret)
995 return ERR_PTR(ret);
996
cc4ceb48
DV
997 index = drm_connector_index(connector);
998
f52b69f1 999 if (index >= state->num_connector) {
63e83c1d 1000 struct __drm_connnectors_state *c;
5fff80bb
ML
1001 int alloc = max(index + 1, config->num_connector);
1002
32ce2553
BG
1003 c = krealloc_array(state->connectors, alloc,
1004 sizeof(*state->connectors), GFP_KERNEL);
5fff80bb
ML
1005 if (!c)
1006 return ERR_PTR(-ENOMEM);
1007
1008 state->connectors = c;
1009 memset(&state->connectors[state->num_connector], 0,
1010 sizeof(*state->connectors) * (alloc - state->num_connector));
1011
5fff80bb 1012 state->num_connector = alloc;
f52b69f1
DV
1013 }
1014
63e83c1d
DV
1015 if (state->connectors[index].state)
1016 return state->connectors[index].state;
cc4ceb48 1017
cc4ceb48
DV
1018 connector_state = connector->funcs->atomic_duplicate_state(connector);
1019 if (!connector_state)
1020 return ERR_PTR(-ENOMEM);
1021
ad093607 1022 drm_connector_get(connector);
63e83c1d 1023 state->connectors[index].state = connector_state;
581e49fe
ML
1024 state->connectors[index].old_state = connector->state;
1025 state->connectors[index].new_state = connector_state;
63e83c1d 1026 state->connectors[index].ptr = connector;
cc4ceb48
DV
1027 connector_state->state = state;
1028
6ac7c548
RK
1029 DRM_DEBUG_ATOMIC("Added [CONNECTOR:%d:%s] %p state to %p\n",
1030 connector->base.id, connector->name,
1031 connector_state, state);
cc4ceb48
DV
1032
1033 if (connector_state->crtc) {
1034 struct drm_crtc_state *crtc_state;
1035
1036 crtc_state = drm_atomic_get_crtc_state(state,
1037 connector_state->crtc);
1038 if (IS_ERR(crtc_state))
1039 return ERR_CAST(crtc_state);
1040 }
1041
1042 return connector_state;
1043}
1044EXPORT_SYMBOL(drm_atomic_get_connector_state);
1045
fceffb32
RC
1046static void drm_atomic_connector_print_state(struct drm_printer *p,
1047 const struct drm_connector_state *state)
1048{
1049 struct drm_connector *connector = state->connector;
1050
1051 drm_printf(p, "connector[%u]: %s\n", connector->base.id, connector->name);
1052 drm_printf(p, "\tcrtc=%s\n", state->crtc ? state->crtc->name : "(null)");
1452c25b 1053 drm_printf(p, "\tself_refresh_aware=%d\n", state->self_refresh_aware);
fceffb32 1054
8cbc5caf
BS
1055 if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK)
1056 if (state->writeback_job && state->writeback_job->fb)
1057 drm_printf(p, "\tfb=%d\n", state->writeback_job->fb->base.id);
1058
fceffb32
RC
1059 if (connector->funcs->atomic_print_state)
1060 connector->funcs->atomic_print_state(p, state);
1061}
1062
75146591
BB
1063/**
1064 * drm_atomic_get_bridge_state - get bridge state
1065 * @state: global atomic state object
1066 * @bridge: bridge to get state object for
1067 *
1068 * This function returns the bridge state for the given bridge, allocating it
1069 * if needed. It will also grab the relevant bridge lock to make sure that the
1070 * state is consistent.
1071 *
1072 * Returns:
1073 *
1074 * Either the allocated state or the error code encoded into the pointer. When
1075 * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
1076 * entire atomic sequence must be restarted.
1077 */
1078struct drm_bridge_state *
1079drm_atomic_get_bridge_state(struct drm_atomic_state *state,
1080 struct drm_bridge *bridge)
1081{
1082 struct drm_private_state *obj_state;
1083
1084 obj_state = drm_atomic_get_private_obj_state(state, &bridge->base);
1085 if (IS_ERR(obj_state))
1086 return ERR_CAST(obj_state);
1087
1088 return drm_priv_to_bridge_state(obj_state);
1089}
1090EXPORT_SYMBOL(drm_atomic_get_bridge_state);
1091
1092/**
1093 * drm_atomic_get_old_bridge_state - get old bridge state, if it exists
1094 * @state: global atomic state object
1095 * @bridge: bridge to grab
1096 *
1097 * This function returns the old bridge state for the given bridge, or NULL if
1098 * the bridge is not part of the global atomic state.
1099 */
1100struct drm_bridge_state *
1101drm_atomic_get_old_bridge_state(struct drm_atomic_state *state,
1102 struct drm_bridge *bridge)
1103{
1104 struct drm_private_state *obj_state;
1105
1106 obj_state = drm_atomic_get_old_private_obj_state(state, &bridge->base);
1107 if (!obj_state)
1108 return NULL;
1109
1110 return drm_priv_to_bridge_state(obj_state);
1111}
1112EXPORT_SYMBOL(drm_atomic_get_old_bridge_state);
1113
1114/**
1115 * drm_atomic_get_new_bridge_state - get new bridge state, if it exists
1116 * @state: global atomic state object
1117 * @bridge: bridge to grab
1118 *
1119 * This function returns the new bridge state for the given bridge, or NULL if
1120 * the bridge is not part of the global atomic state.
1121 */
1122struct drm_bridge_state *
1123drm_atomic_get_new_bridge_state(struct drm_atomic_state *state,
1124 struct drm_bridge *bridge)
1125{
1126 struct drm_private_state *obj_state;
1127
1128 obj_state = drm_atomic_get_new_private_obj_state(state, &bridge->base);
1129 if (!obj_state)
1130 return NULL;
1131
1132 return drm_priv_to_bridge_state(obj_state);
1133}
1134EXPORT_SYMBOL(drm_atomic_get_new_bridge_state);
1135
1136/**
1137 * drm_atomic_add_encoder_bridges - add bridges attached to an encoder
1138 * @state: atomic state
1139 * @encoder: DRM encoder
1140 *
1141 * This function adds all bridges attached to @encoder. This is needed to add
1142 * bridge states to @state and make them available when
91ea8330
BB
1143 * &drm_bridge_funcs.atomic_check(), &drm_bridge_funcs.atomic_pre_enable(),
1144 * &drm_bridge_funcs.atomic_enable(),
1145 * &drm_bridge_funcs.atomic_disable_post_disable() are called.
75146591
BB
1146 *
1147 * Returns:
1148 * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
1149 * then the w/w mutex code has detected a deadlock and the entire atomic
1150 * sequence must be restarted. All other errors are fatal.
1151 */
1152int
1153drm_atomic_add_encoder_bridges(struct drm_atomic_state *state,
1154 struct drm_encoder *encoder)
1155{
1156 struct drm_bridge_state *bridge_state;
1157 struct drm_bridge *bridge;
1158
1159 if (!encoder)
1160 return 0;
1161
1162 DRM_DEBUG_ATOMIC("Adding all bridges for [encoder:%d:%s] to %p\n",
1163 encoder->base.id, encoder->name, state);
1164
1165 drm_for_each_bridge_in_chain(encoder, bridge) {
1166 /* Skip bridges that don't implement the atomic state hooks. */
1167 if (!bridge->funcs->atomic_duplicate_state)
1168 continue;
1169
1170 bridge_state = drm_atomic_get_bridge_state(state, bridge);
1171 if (IS_ERR(bridge_state))
1172 return PTR_ERR(bridge_state);
1173 }
1174
1175 return 0;
1176}
1177EXPORT_SYMBOL(drm_atomic_add_encoder_bridges);
1178
cc4ceb48 1179/**
42240c90 1180 * drm_atomic_add_affected_connectors - add connectors for CRTC
cc4ceb48 1181 * @state: atomic state
42240c90 1182 * @crtc: DRM CRTC
cc4ceb48
DV
1183 *
1184 * This function walks the current configuration and adds all connectors
1185 * currently using @crtc to the atomic configuration @state. Note that this
1186 * function must acquire the connection mutex. This can potentially cause
a8a1de90 1187 * unneeded serialization if the update is just for the planes on one CRTC. Hence
cc4ceb48
DV
1188 * drivers and helpers should only call this when really needed (e.g. when a
1189 * full modeset needs to happen due to some change).
1190 *
1191 * Returns:
1192 * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
1193 * then the w/w mutex code has detected a deadlock and the entire atomic
1194 * sequence must be restarted. All other errors are fatal.
1195 */
1196int
1197drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
1198 struct drm_crtc *crtc)
1199{
1200 struct drm_mode_config *config = &state->dev->mode_config;
1201 struct drm_connector *connector;
1202 struct drm_connector_state *conn_state;
613051da 1203 struct drm_connector_list_iter conn_iter;
5351bbdd 1204 struct drm_crtc_state *crtc_state;
cc4ceb48
DV
1205 int ret;
1206
5351bbdd
ML
1207 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1208 if (IS_ERR(crtc_state))
1209 return PTR_ERR(crtc_state);
1210
cc4ceb48
DV
1211 ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
1212 if (ret)
1213 return ret;
1214
fa3ab4c2
VS
1215 DRM_DEBUG_ATOMIC("Adding all current connectors for [CRTC:%d:%s] to %p\n",
1216 crtc->base.id, crtc->name, state);
cc4ceb48
DV
1217
1218 /*
5351bbdd
ML
1219 * Changed connectors are already in @state, so only need to look
1220 * at the connector_mask in crtc_state.
cc4ceb48 1221 */
b982dab1 1222 drm_connector_list_iter_begin(state->dev, &conn_iter);
613051da 1223 drm_for_each_connector_iter(connector, &conn_iter) {
73705732 1224 if (!(crtc_state->connector_mask & drm_connector_mask(connector)))
cc4ceb48
DV
1225 continue;
1226
1227 conn_state = drm_atomic_get_connector_state(state, connector);
613051da 1228 if (IS_ERR(conn_state)) {
b982dab1 1229 drm_connector_list_iter_end(&conn_iter);
cc4ceb48 1230 return PTR_ERR(conn_state);
613051da 1231 }
cc4ceb48 1232 }
b982dab1 1233 drm_connector_list_iter_end(&conn_iter);
cc4ceb48
DV
1234
1235 return 0;
1236}
1237EXPORT_SYMBOL(drm_atomic_add_affected_connectors);
1238
e01e9f75 1239/**
42240c90 1240 * drm_atomic_add_affected_planes - add planes for CRTC
e01e9f75 1241 * @state: atomic state
42240c90 1242 * @crtc: DRM CRTC
e01e9f75
ML
1243 *
1244 * This function walks the current configuration and adds all planes
1245 * currently used by @crtc to the atomic configuration @state. This is useful
1246 * when an atomic commit also needs to check all currently enabled plane on
1247 * @crtc, e.g. when changing the mode. It's also useful when re-enabling a CRTC
1248 * to avoid special code to force-enable all planes.
1249 *
1250 * Since acquiring a plane state will always also acquire the w/w mutex of the
1251 * current CRTC for that plane (if there is any) adding all the plane states for
a8a1de90 1252 * a CRTC will not reduce parallelism of atomic updates.
e01e9f75
ML
1253 *
1254 * Returns:
1255 * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
1256 * then the w/w mutex code has detected a deadlock and the entire atomic
1257 * sequence must be restarted. All other errors are fatal.
1258 */
1259int
1260drm_atomic_add_affected_planes(struct drm_atomic_state *state,
1261 struct drm_crtc *crtc)
1262{
534903d6
VS
1263 const struct drm_crtc_state *old_crtc_state =
1264 drm_atomic_get_old_crtc_state(state, crtc);
e01e9f75
ML
1265 struct drm_plane *plane;
1266
b4d93679 1267 WARN_ON(!drm_atomic_get_new_crtc_state(state, crtc));
e01e9f75 1268
b6f690ab
VS
1269 DRM_DEBUG_ATOMIC("Adding all current planes for [CRTC:%d:%s] to %p\n",
1270 crtc->base.id, crtc->name, state);
1271
534903d6 1272 drm_for_each_plane_mask(plane, state->dev, old_crtc_state->plane_mask) {
e01e9f75
ML
1273 struct drm_plane_state *plane_state =
1274 drm_atomic_get_plane_state(state, plane);
1275
1276 if (IS_ERR(plane_state))
1277 return PTR_ERR(plane_state);
1278 }
1279 return 0;
1280}
1281EXPORT_SYMBOL(drm_atomic_add_affected_planes);
1282
cc4ceb48
DV
1283/**
1284 * drm_atomic_check_only - check whether a given config would work
1285 * @state: atomic configuration to check
1286 *
1287 * Note that this function can return -EDEADLK if the driver needed to acquire
1288 * more locks but encountered a deadlock. The caller must then do the usual w/w
1289 * backoff dance and restart. All other errors are fatal.
1290 *
1291 * Returns:
1292 * 0 on success, negative error code on failure.
1293 */
1294int drm_atomic_check_only(struct drm_atomic_state *state)
1295{
5e743737
RC
1296 struct drm_device *dev = state->dev;
1297 struct drm_mode_config *config = &dev->mode_config;
df63b999 1298 struct drm_plane *plane;
d9be05b7
VS
1299 struct drm_plane_state *old_plane_state;
1300 struct drm_plane_state *new_plane_state;
df63b999 1301 struct drm_crtc *crtc;
b2432adf
VS
1302 struct drm_crtc_state *old_crtc_state;
1303 struct drm_crtc_state *new_crtc_state;
935774cd
BS
1304 struct drm_connector *conn;
1305 struct drm_connector_state *conn_state;
1cdb005d
FDF
1306 unsigned int requested_crtc = 0;
1307 unsigned int affected_crtc = 0;
5e743737 1308 int i, ret = 0;
cc4ceb48 1309
17a38d9c 1310 DRM_DEBUG_ATOMIC("checking %p\n", state);
cc4ceb48 1311
fb6473a4
DV
1312 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
1313 requested_crtc |= drm_crtc_mask(crtc);
1314
d9be05b7
VS
1315 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
1316 ret = drm_atomic_plane_check(old_plane_state, new_plane_state);
5e743737 1317 if (ret) {
9f4c97a2
VS
1318 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] atomic core check failed\n",
1319 plane->base.id, plane->name);
5e743737
RC
1320 return ret;
1321 }
1322 }
1323
b2432adf
VS
1324 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
1325 ret = drm_atomic_crtc_check(old_crtc_state, new_crtc_state);
5e743737 1326 if (ret) {
fa3ab4c2
VS
1327 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] atomic core check failed\n",
1328 crtc->base.id, crtc->name);
5e743737
RC
1329 return ret;
1330 }
1331 }
1332
935774cd
BS
1333 for_each_new_connector_in_state(state, conn, conn_state, i) {
1334 ret = drm_atomic_connector_check(conn, conn_state);
1335 if (ret) {
1336 DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] atomic core check failed\n",
1337 conn->base.id, conn->name);
1338 return ret;
1339 }
1340 }
1341
14d4e522 1342 if (config->funcs->atomic_check) {
5e743737
RC
1343 ret = config->funcs->atomic_check(state->dev, state);
1344
14d4e522
LP
1345 if (ret) {
1346 DRM_DEBUG_ATOMIC("atomic driver check for %p failed: %d\n",
1347 state, ret);
1348 return ret;
1349 }
1350 }
a0ffc51e 1351
d34f20d6 1352 if (!state->allow_modeset) {
b2432adf
VS
1353 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
1354 if (drm_atomic_crtc_needs_modeset(new_crtc_state)) {
fa3ab4c2
VS
1355 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] requires full modeset\n",
1356 crtc->base.id, crtc->name);
d34f20d6
RC
1357 return -EINVAL;
1358 }
1359 }
1360 }
1361
fb6473a4
DV
1362 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
1363 affected_crtc |= drm_crtc_mask(crtc);
1364
1365 /*
1366 * For commits that allow modesets drivers can add other CRTCs to the
1367 * atomic commit, e.g. when they need to reallocate global resources.
1368 * This can cause spurious EBUSY, which robs compositors of a very
1369 * effective sanity check for their drawing loop. Therefor only allow
1370 * drivers to add unrelated CRTC states for modeset commits.
1371 *
1372 * FIXME: Should add affected_crtc mask to the ATOMIC IOCTL as an output
1373 * so compositors know what's going on.
1374 */
1375 if (affected_crtc != requested_crtc) {
1376 DRM_DEBUG_ATOMIC("driver added CRTC to commit: requested 0x%x, affected 0x%0x\n",
1377 requested_crtc, affected_crtc);
1378 WARN(!state->allow_modeset, "adding CRTC not allowed without modesets: requested 0x%x, affected 0x%0x\n",
1379 requested_crtc, affected_crtc);
1380 }
1381
a0ffc51e 1382 return 0;
cc4ceb48
DV
1383}
1384EXPORT_SYMBOL(drm_atomic_check_only);
1385
1386/**
1387 * drm_atomic_commit - commit configuration atomically
1388 * @state: atomic configuration to check
1389 *
1390 * Note that this function can return -EDEADLK if the driver needed to acquire
1391 * more locks but encountered a deadlock. The caller must then do the usual w/w
1392 * backoff dance and restart. All other errors are fatal.
1393 *
76fede2f
ML
1394 * This function will take its own reference on @state.
1395 * Callers should always release their reference with drm_atomic_state_put().
cc4ceb48
DV
1396 *
1397 * Returns:
1398 * 0 on success, negative error code on failure.
1399 */
1400int drm_atomic_commit(struct drm_atomic_state *state)
1401{
1402 struct drm_mode_config *config = &state->dev->mode_config;
1403 int ret;
1404
1405 ret = drm_atomic_check_only(state);
1406 if (ret)
1407 return ret;
1408
a0752d4a 1409 DRM_DEBUG_ATOMIC("committing %p\n", state);
cc4ceb48
DV
1410
1411 return config->funcs->atomic_commit(state->dev, state, false);
1412}
1413EXPORT_SYMBOL(drm_atomic_commit);
1414
1415/**
d574528a 1416 * drm_atomic_nonblocking_commit - atomic nonblocking commit
cc4ceb48
DV
1417 * @state: atomic configuration to check
1418 *
1419 * Note that this function can return -EDEADLK if the driver needed to acquire
1420 * more locks but encountered a deadlock. The caller must then do the usual w/w
1421 * backoff dance and restart. All other errors are fatal.
1422 *
76fede2f
ML
1423 * This function will take its own reference on @state.
1424 * Callers should always release their reference with drm_atomic_state_put().
cc4ceb48
DV
1425 *
1426 * Returns:
1427 * 0 on success, negative error code on failure.
1428 */
b837ba0a 1429int drm_atomic_nonblocking_commit(struct drm_atomic_state *state)
cc4ceb48
DV
1430{
1431 struct drm_mode_config *config = &state->dev->mode_config;
1432 int ret;
1433
1434 ret = drm_atomic_check_only(state);
1435 if (ret)
1436 return ret;
1437
a0752d4a 1438 DRM_DEBUG_ATOMIC("committing %p nonblocking\n", state);
cc4ceb48
DV
1439
1440 return config->funcs->atomic_commit(state->dev, state, true);
1441}
b837ba0a 1442EXPORT_SYMBOL(drm_atomic_nonblocking_commit);
d34f20d6 1443
df737895
NT
1444/* just used from drm-client and atomic-helper: */
1445int __drm_atomic_helper_disable_plane(struct drm_plane *plane,
1446 struct drm_plane_state *plane_state)
1447{
1448 int ret;
1449
1450 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
1451 if (ret != 0)
1452 return ret;
1453
1454 drm_atomic_set_fb_for_plane(plane_state, NULL);
1455 plane_state->crtc_x = 0;
1456 plane_state->crtc_y = 0;
1457 plane_state->crtc_w = 0;
1458 plane_state->crtc_h = 0;
1459 plane_state->src_x = 0;
1460 plane_state->src_y = 0;
1461 plane_state->src_w = 0;
1462 plane_state->src_h = 0;
1463
1464 return 0;
1465}
1466EXPORT_SYMBOL(__drm_atomic_helper_disable_plane);
1467
1468static int update_output_state(struct drm_atomic_state *state,
1469 struct drm_mode_set *set)
1470{
1471 struct drm_device *dev = set->crtc->dev;
1472 struct drm_crtc *crtc;
1473 struct drm_crtc_state *new_crtc_state;
1474 struct drm_connector *connector;
1475 struct drm_connector_state *new_conn_state;
1476 int ret, i;
1477
1478 ret = drm_modeset_lock(&dev->mode_config.connection_mutex,
1479 state->acquire_ctx);
1480 if (ret)
1481 return ret;
1482
1483 /* First disable all connectors on the target crtc. */
1484 ret = drm_atomic_add_affected_connectors(state, set->crtc);
1485 if (ret)
1486 return ret;
1487
1488 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
1489 if (new_conn_state->crtc == set->crtc) {
1490 ret = drm_atomic_set_crtc_for_connector(new_conn_state,
1491 NULL);
1492 if (ret)
1493 return ret;
1494
1495 /* Make sure legacy setCrtc always re-trains */
1496 new_conn_state->link_status = DRM_LINK_STATUS_GOOD;
1497 }
1498 }
1499
1500 /* Then set all connectors from set->connectors on the target crtc */
1501 for (i = 0; i < set->num_connectors; i++) {
1502 new_conn_state = drm_atomic_get_connector_state(state,
1503 set->connectors[i]);
1504 if (IS_ERR(new_conn_state))
1505 return PTR_ERR(new_conn_state);
1506
1507 ret = drm_atomic_set_crtc_for_connector(new_conn_state,
1508 set->crtc);
1509 if (ret)
1510 return ret;
1511 }
1512
1513 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
1514 /*
1515 * Don't update ->enable for the CRTC in the set_config request,
1516 * since a mismatch would indicate a bug in the upper layers.
1517 * The actual modeset code later on will catch any
1518 * inconsistencies here.
1519 */
1520 if (crtc == set->crtc)
1521 continue;
1522
1523 if (!new_crtc_state->connector_mask) {
1524 ret = drm_atomic_set_mode_prop_for_crtc(new_crtc_state,
1525 NULL);
1526 if (ret < 0)
1527 return ret;
1528
1529 new_crtc_state->active = false;
1530 }
1531 }
1532
1533 return 0;
1534}
1535
1536/* just used from drm-client and atomic-helper: */
1537int __drm_atomic_helper_set_config(struct drm_mode_set *set,
1538 struct drm_atomic_state *state)
1539{
1540 struct drm_crtc_state *crtc_state;
1541 struct drm_plane_state *primary_state;
1542 struct drm_crtc *crtc = set->crtc;
1543 int hdisplay, vdisplay;
1544 int ret;
1545
1546 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1547 if (IS_ERR(crtc_state))
1548 return PTR_ERR(crtc_state);
1549
1550 primary_state = drm_atomic_get_plane_state(state, crtc->primary);
1551 if (IS_ERR(primary_state))
1552 return PTR_ERR(primary_state);
1553
1554 if (!set->mode) {
1555 WARN_ON(set->fb);
1556 WARN_ON(set->num_connectors);
1557
1558 ret = drm_atomic_set_mode_for_crtc(crtc_state, NULL);
1559 if (ret != 0)
1560 return ret;
1561
1562 crtc_state->active = false;
1563
1564 ret = drm_atomic_set_crtc_for_plane(primary_state, NULL);
1565 if (ret != 0)
1566 return ret;
1567
1568 drm_atomic_set_fb_for_plane(primary_state, NULL);
1569
1570 goto commit;
1571 }
1572
1573 WARN_ON(!set->fb);
1574 WARN_ON(!set->num_connectors);
1575
1576 ret = drm_atomic_set_mode_for_crtc(crtc_state, set->mode);
1577 if (ret != 0)
1578 return ret;
1579
1580 crtc_state->active = true;
1581
1582 ret = drm_atomic_set_crtc_for_plane(primary_state, crtc);
1583 if (ret != 0)
1584 return ret;
1585
1586 drm_mode_get_hv_timing(set->mode, &hdisplay, &vdisplay);
1587
1588 drm_atomic_set_fb_for_plane(primary_state, set->fb);
1589 primary_state->crtc_x = 0;
1590 primary_state->crtc_y = 0;
1591 primary_state->crtc_w = hdisplay;
1592 primary_state->crtc_h = vdisplay;
1593 primary_state->src_x = set->x << 16;
1594 primary_state->src_y = set->y << 16;
1595 if (drm_rotation_90_or_270(primary_state->rotation)) {
1596 primary_state->src_w = vdisplay << 16;
1597 primary_state->src_h = hdisplay << 16;
1598 } else {
1599 primary_state->src_w = hdisplay << 16;
1600 primary_state->src_h = vdisplay << 16;
1601 }
1602
1603commit:
1604 ret = update_output_state(state, set);
1605 if (ret)
1606 return ret;
1607
1608 return 0;
1609}
1610EXPORT_SYMBOL(__drm_atomic_helper_set_config);
1611
72fdb40c 1612void drm_atomic_print_state(const struct drm_atomic_state *state)
fceffb32
RC
1613{
1614 struct drm_printer p = drm_info_printer(state->dev->dev);
1615 struct drm_plane *plane;
1616 struct drm_plane_state *plane_state;
1617 struct drm_crtc *crtc;
1618 struct drm_crtc_state *crtc_state;
1619 struct drm_connector *connector;
1620 struct drm_connector_state *connector_state;
1621 int i;
1622
1623 DRM_DEBUG_ATOMIC("checking %p\n", state);
1624
5721a380 1625 for_each_new_plane_in_state(state, plane, plane_state, i)
fceffb32
RC
1626 drm_atomic_plane_print_state(&p, plane_state);
1627
5721a380 1628 for_each_new_crtc_in_state(state, crtc, crtc_state, i)
fceffb32
RC
1629 drm_atomic_crtc_print_state(&p, crtc_state);
1630
5721a380 1631 for_each_new_connector_in_state(state, connector, connector_state, i)
fceffb32
RC
1632 drm_atomic_connector_print_state(&p, connector_state);
1633}
1634
c2d85564
DV
1635static void __drm_state_dump(struct drm_device *dev, struct drm_printer *p,
1636 bool take_locks)
6559c901
RC
1637{
1638 struct drm_mode_config *config = &dev->mode_config;
1639 struct drm_plane *plane;
1640 struct drm_crtc *crtc;
1641 struct drm_connector *connector;
613051da 1642 struct drm_connector_list_iter conn_iter;
6559c901 1643
3c499ea0 1644 if (!drm_drv_uses_atomic_modeset(dev))
6559c901
RC
1645 return;
1646
c2d85564
DV
1647 list_for_each_entry(plane, &config->plane_list, head) {
1648 if (take_locks)
1649 drm_modeset_lock(&plane->mutex, NULL);
6559c901 1650 drm_atomic_plane_print_state(p, plane->state);
c2d85564
DV
1651 if (take_locks)
1652 drm_modeset_unlock(&plane->mutex);
1653 }
6559c901 1654
c2d85564
DV
1655 list_for_each_entry(crtc, &config->crtc_list, head) {
1656 if (take_locks)
1657 drm_modeset_lock(&crtc->mutex, NULL);
6559c901 1658 drm_atomic_crtc_print_state(p, crtc->state);
c2d85564
DV
1659 if (take_locks)
1660 drm_modeset_unlock(&crtc->mutex);
1661 }
6559c901 1662
b982dab1 1663 drm_connector_list_iter_begin(dev, &conn_iter);
c2d85564
DV
1664 if (take_locks)
1665 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
613051da 1666 drm_for_each_connector_iter(connector, &conn_iter)
6559c901 1667 drm_atomic_connector_print_state(p, connector->state);
c2d85564
DV
1668 if (take_locks)
1669 drm_modeset_unlock(&dev->mode_config.connection_mutex);
b982dab1 1670 drm_connector_list_iter_end(&conn_iter);
6559c901 1671}
c2d85564
DV
1672
1673/**
1674 * drm_state_dump - dump entire device atomic state
1675 * @dev: the drm device
1676 * @p: where to print the state to
1677 *
1678 * Just for debugging. Drivers might want an option to dump state
1679 * to dmesg in case of error irq's. (Hint, you probably want to
1680 * ratelimit this!)
1681 *
bd1fbef7
DV
1682 * The caller must wrap this drm_modeset_lock_all_ctx() and
1683 * drm_modeset_drop_locks(). If this is called from error irq handler, it should
1684 * not be enabled by default - if you are debugging errors you might
1685 * not care that this is racey, but calling this without all modeset locks held
1686 * is inherently unsafe.
c2d85564
DV
1687 */
1688void drm_state_dump(struct drm_device *dev, struct drm_printer *p)
1689{
1690 __drm_state_dump(dev, p, false);
1691}
6559c901
RC
1692EXPORT_SYMBOL(drm_state_dump);
1693
1694#ifdef CONFIG_DEBUG_FS
1695static int drm_state_info(struct seq_file *m, void *data)
1696{
1697 struct drm_info_node *node = (struct drm_info_node *) m->private;
1698 struct drm_device *dev = node->minor->dev;
1699 struct drm_printer p = drm_seq_file_printer(m);
1700
c2d85564 1701 __drm_state_dump(dev, &p, true);
6559c901
RC
1702
1703 return 0;
1704}
1705
1706/* any use in debugfs files to dump individual planes/crtc/etc? */
1707static const struct drm_info_list drm_atomic_debugfs_list[] = {
1708 {"state", drm_state_info, 0},
1709};
1710
7ce84471 1711void drm_atomic_debugfs_init(struct drm_minor *minor)
6559c901 1712{
e196e140
WK
1713 drm_debugfs_create_files(drm_atomic_debugfs_list,
1714 ARRAY_SIZE(drm_atomic_debugfs_list),
1715 minor->debugfs_root, minor);
6559c901
RC
1716}
1717#endif