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