Merge remote-tracking branch 'stable/linux-5.15.y' into rpi-5.15.y
[platform/kernel/linux-rpi.git] / drivers / gpu / drm / drm_atomic_state_helper.c
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  */
70 void
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 }
76 EXPORT_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  */
90 void
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 }
102 EXPORT_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  */
111 void 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 }
121 EXPORT_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  */
131 void __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 }
158 EXPORT_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  */
167 struct drm_crtc_state *
168 drm_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 }
181 EXPORT_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  */
191 void __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 }
217 EXPORT_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  */
227 void 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 }
233 EXPORT_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  */
243 void __drm_atomic_helper_plane_state_reset(struct drm_plane_state *plane_state,
244                                            struct drm_plane *plane)
245 {
246         u64 val;
247
248         plane_state->plane = plane;
249         plane_state->rotation = DRM_MODE_ROTATE_0;
250
251         plane_state->alpha = DRM_BLEND_ALPHA_OPAQUE;
252         plane_state->pixel_blend_mode = DRM_MODE_BLEND_PREMULTI;
253
254         if (plane->color_encoding_property) {
255                 if (!drm_object_property_get_default_value(&plane->base,
256                                                            plane->color_encoding_property,
257                                                            &val))
258                         plane_state->color_encoding = val;
259         }
260
261         if (plane->color_range_property) {
262                 if (!drm_object_property_get_default_value(&plane->base,
263                                                            plane->color_range_property,
264                                                            &val))
265                         plane_state->color_range = val;
266         }
267
268         if (plane->chroma_siting_h_property) {
269                 if (!drm_object_property_get_default_value(&plane->base,
270                                                            plane->chroma_siting_h_property,
271                                                            &val))
272                         plane_state->chroma_siting_h = val;
273         }
274
275         if (plane->chroma_siting_v_property) {
276                 if (!drm_object_property_get_default_value(&plane->base,
277                                                            plane->chroma_siting_v_property,
278                                                            &val))
279                         plane_state->chroma_siting_v = val;
280         }
281
282         if (plane->zpos_property) {
283                 if (!drm_object_property_get_default_value(&plane->base,
284                                                            plane->zpos_property,
285                                                            &val)) {
286                         plane_state->zpos = val;
287                         plane_state->normalized_zpos = val;
288                 }
289         }
290 }
291 EXPORT_SYMBOL(__drm_atomic_helper_plane_state_reset);
292
293 /**
294  * __drm_atomic_helper_plane_reset - reset state on plane
295  * @plane: drm plane
296  * @plane_state: plane state to assign
297  *
298  * Initializes the newly allocated @plane_state and assigns it to
299  * the &drm_crtc->state pointer of @plane, usually required when
300  * initializing the drivers or when called from the &drm_plane_funcs.reset
301  * hook.
302  *
303  * This is useful for drivers that subclass the plane state.
304  */
305 void __drm_atomic_helper_plane_reset(struct drm_plane *plane,
306                                      struct drm_plane_state *plane_state)
307 {
308         if (plane_state)
309                 __drm_atomic_helper_plane_state_reset(plane_state, plane);
310
311         plane->state = plane_state;
312 }
313 EXPORT_SYMBOL(__drm_atomic_helper_plane_reset);
314
315 /**
316  * drm_atomic_helper_plane_reset - default &drm_plane_funcs.reset hook for planes
317  * @plane: drm plane
318  *
319  * Resets the atomic state for @plane by freeing the state pointer (which might
320  * be NULL, e.g. at driver load time) and allocating a new empty state object.
321  */
322 void drm_atomic_helper_plane_reset(struct drm_plane *plane)
323 {
324         if (plane->state)
325                 __drm_atomic_helper_plane_destroy_state(plane->state);
326
327         kfree(plane->state);
328         plane->state = kzalloc(sizeof(*plane->state), GFP_KERNEL);
329         if (plane->state)
330                 __drm_atomic_helper_plane_reset(plane, plane->state);
331 }
332 EXPORT_SYMBOL(drm_atomic_helper_plane_reset);
333
334 /**
335  * __drm_atomic_helper_plane_duplicate_state - copy atomic plane state
336  * @plane: plane object
337  * @state: atomic plane state
338  *
339  * Copies atomic state from a plane's current state. This is useful for
340  * drivers that subclass the plane state.
341  */
342 void __drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane,
343                                                struct drm_plane_state *state)
344 {
345         memcpy(state, plane->state, sizeof(*state));
346
347         if (state->fb)
348                 drm_framebuffer_get(state->fb);
349
350         state->fence = NULL;
351         state->commit = NULL;
352         state->fb_damage_clips = NULL;
353 }
354 EXPORT_SYMBOL(__drm_atomic_helper_plane_duplicate_state);
355
356 /**
357  * drm_atomic_helper_plane_duplicate_state - default state duplicate hook
358  * @plane: drm plane
359  *
360  * Default plane state duplicate hook for drivers which don't have their own
361  * subclassed plane state structure.
362  */
363 struct drm_plane_state *
364 drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane)
365 {
366         struct drm_plane_state *state;
367
368         if (WARN_ON(!plane->state))
369                 return NULL;
370
371         state = kmalloc(sizeof(*state), GFP_KERNEL);
372         if (state)
373                 __drm_atomic_helper_plane_duplicate_state(plane, state);
374
375         return state;
376 }
377 EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state);
378
379 /**
380  * __drm_atomic_helper_plane_destroy_state - release plane state
381  * @state: plane state object to release
382  *
383  * Releases all resources stored in the plane state without actually freeing
384  * the memory of the plane state. This is useful for drivers that subclass the
385  * plane state.
386  */
387 void __drm_atomic_helper_plane_destroy_state(struct drm_plane_state *state)
388 {
389         if (state->fb)
390                 drm_framebuffer_put(state->fb);
391
392         if (state->fence)
393                 dma_fence_put(state->fence);
394
395         if (state->commit)
396                 drm_crtc_commit_put(state->commit);
397
398         drm_property_blob_put(state->fb_damage_clips);
399 }
400 EXPORT_SYMBOL(__drm_atomic_helper_plane_destroy_state);
401
402 /**
403  * drm_atomic_helper_plane_destroy_state - default state destroy hook
404  * @plane: drm plane
405  * @state: plane state object to release
406  *
407  * Default plane state destroy hook for drivers which don't have their own
408  * subclassed plane state structure.
409  */
410 void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
411                                            struct drm_plane_state *state)
412 {
413         __drm_atomic_helper_plane_destroy_state(state);
414         kfree(state);
415 }
416 EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state);
417
418 /**
419  * __drm_atomic_helper_connector_state_reset - reset the connector state
420  * @conn_state: atomic connector state, must not be NULL
421  * @connector: connectotr object, must not be NULL
422  *
423  * Initializes the newly allocated @conn_state with default
424  * values. This is useful for drivers that subclass the connector state.
425  */
426 void
427 __drm_atomic_helper_connector_state_reset(struct drm_connector_state *conn_state,
428                                           struct drm_connector *connector)
429 {
430         conn_state->connector = connector;
431 }
432 EXPORT_SYMBOL(__drm_atomic_helper_connector_state_reset);
433
434 /**
435  * __drm_atomic_helper_connector_reset - reset state on connector
436  * @connector: drm connector
437  * @conn_state: connector state to assign
438  *
439  * Initializes the newly allocated @conn_state and assigns it to
440  * the &drm_connector->state pointer of @connector, usually required when
441  * initializing the drivers or when called from the &drm_connector_funcs.reset
442  * hook.
443  *
444  * This is useful for drivers that subclass the connector state.
445  */
446 void
447 __drm_atomic_helper_connector_reset(struct drm_connector *connector,
448                                     struct drm_connector_state *conn_state)
449 {
450         if (conn_state)
451                 __drm_atomic_helper_connector_state_reset(conn_state, connector);
452
453         connector->state = conn_state;
454 }
455 EXPORT_SYMBOL(__drm_atomic_helper_connector_reset);
456
457 /**
458  * drm_atomic_helper_connector_reset - default &drm_connector_funcs.reset hook for connectors
459  * @connector: drm connector
460  *
461  * Resets the atomic state for @connector by freeing the state pointer (which
462  * might be NULL, e.g. at driver load time) and allocating a new empty state
463  * object.
464  */
465 void drm_atomic_helper_connector_reset(struct drm_connector *connector)
466 {
467         struct drm_connector_state *conn_state =
468                 kzalloc(sizeof(*conn_state), GFP_KERNEL);
469
470         if (connector->state)
471                 __drm_atomic_helper_connector_destroy_state(connector->state);
472
473         kfree(connector->state);
474         __drm_atomic_helper_connector_reset(connector, conn_state);
475 }
476 EXPORT_SYMBOL(drm_atomic_helper_connector_reset);
477
478 /**
479  * drm_atomic_helper_connector_tv_reset - Resets TV connector properties
480  * @connector: DRM connector
481  *
482  * Resets the TV-related properties attached to a connector.
483  */
484 void drm_atomic_helper_connector_tv_reset(struct drm_connector *connector)
485 {
486         struct drm_cmdline_mode *cmdline = &connector->cmdline_mode;
487         struct drm_connector_state *state = connector->state;
488
489         state->tv.margins.left = cmdline->tv_margins.left;
490         state->tv.margins.right = cmdline->tv_margins.right;
491         state->tv.margins.top = cmdline->tv_margins.top;
492         state->tv.margins.bottom = cmdline->tv_margins.bottom;
493 }
494 EXPORT_SYMBOL(drm_atomic_helper_connector_tv_reset);
495
496 /**
497  * __drm_atomic_helper_connector_duplicate_state - copy atomic connector state
498  * @connector: connector object
499  * @state: atomic connector state
500  *
501  * Copies atomic state from a connector's current state. This is useful for
502  * drivers that subclass the connector state.
503  */
504 void
505 __drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector,
506                                             struct drm_connector_state *state)
507 {
508         memcpy(state, connector->state, sizeof(*state));
509         if (state->crtc)
510                 drm_connector_get(connector);
511         state->commit = NULL;
512
513         if (state->hdr_output_metadata)
514                 drm_property_blob_get(state->hdr_output_metadata);
515
516         /* Don't copy over a writeback job, they are used only once */
517         state->writeback_job = NULL;
518 }
519 EXPORT_SYMBOL(__drm_atomic_helper_connector_duplicate_state);
520
521 /**
522  * drm_atomic_helper_connector_duplicate_state - default state duplicate hook
523  * @connector: drm connector
524  *
525  * Default connector state duplicate hook for drivers which don't have their own
526  * subclassed connector state structure.
527  */
528 struct drm_connector_state *
529 drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector)
530 {
531         struct drm_connector_state *state;
532
533         if (WARN_ON(!connector->state))
534                 return NULL;
535
536         state = kmalloc(sizeof(*state), GFP_KERNEL);
537         if (state)
538                 __drm_atomic_helper_connector_duplicate_state(connector, state);
539
540         return state;
541 }
542 EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state);
543
544 /**
545  * __drm_atomic_helper_connector_destroy_state - release connector state
546  * @state: connector state object to release
547  *
548  * Releases all resources stored in the connector state without actually
549  * freeing the memory of the connector state. This is useful for drivers that
550  * subclass the connector state.
551  */
552 void
553 __drm_atomic_helper_connector_destroy_state(struct drm_connector_state *state)
554 {
555         if (state->crtc)
556                 drm_connector_put(state->connector);
557
558         if (state->commit)
559                 drm_crtc_commit_put(state->commit);
560
561         if (state->writeback_job)
562                 drm_writeback_cleanup_job(state->writeback_job);
563
564         drm_property_blob_put(state->hdr_output_metadata);
565 }
566 EXPORT_SYMBOL(__drm_atomic_helper_connector_destroy_state);
567
568 /**
569  * drm_atomic_helper_connector_destroy_state - default state destroy hook
570  * @connector: drm connector
571  * @state: connector state object to release
572  *
573  * Default connector state destroy hook for drivers which don't have their own
574  * subclassed connector state structure.
575  */
576 void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
577                                           struct drm_connector_state *state)
578 {
579         __drm_atomic_helper_connector_destroy_state(state);
580         kfree(state);
581 }
582 EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state);
583
584 /**
585  * __drm_atomic_helper_private_obj_duplicate_state - copy atomic private state
586  * @obj: CRTC object
587  * @state: new private object state
588  *
589  * Copies atomic state from a private objects's current state and resets inferred values.
590  * This is useful for drivers that subclass the private state.
591  */
592 void __drm_atomic_helper_private_obj_duplicate_state(struct drm_private_obj *obj,
593                                                      struct drm_private_state *state)
594 {
595         memcpy(state, obj->state, sizeof(*state));
596 }
597 EXPORT_SYMBOL(__drm_atomic_helper_private_obj_duplicate_state);
598
599 /**
600  * __drm_atomic_helper_bridge_duplicate_state() - Copy atomic bridge state
601  * @bridge: bridge object
602  * @state: atomic bridge state
603  *
604  * Copies atomic state from a bridge's current state and resets inferred values.
605  * This is useful for drivers that subclass the bridge state.
606  */
607 void __drm_atomic_helper_bridge_duplicate_state(struct drm_bridge *bridge,
608                                                 struct drm_bridge_state *state)
609 {
610         __drm_atomic_helper_private_obj_duplicate_state(&bridge->base,
611                                                         &state->base);
612         state->bridge = bridge;
613 }
614 EXPORT_SYMBOL(__drm_atomic_helper_bridge_duplicate_state);
615
616 /**
617  * drm_atomic_helper_bridge_duplicate_state() - Duplicate a bridge state object
618  * @bridge: bridge object
619  *
620  * Allocates a new bridge state and initializes it with the current bridge
621  * state values. This helper is meant to be used as a bridge
622  * &drm_bridge_funcs.atomic_duplicate_state hook for bridges that don't
623  * subclass the bridge state.
624  */
625 struct drm_bridge_state *
626 drm_atomic_helper_bridge_duplicate_state(struct drm_bridge *bridge)
627 {
628         struct drm_bridge_state *new;
629
630         if (WARN_ON(!bridge->base.state))
631                 return NULL;
632
633         new = kzalloc(sizeof(*new), GFP_KERNEL);
634         if (new)
635                 __drm_atomic_helper_bridge_duplicate_state(bridge, new);
636
637         return new;
638 }
639 EXPORT_SYMBOL(drm_atomic_helper_bridge_duplicate_state);
640
641 /**
642  * drm_atomic_helper_bridge_destroy_state() - Destroy a bridge state object
643  * @bridge: the bridge this state refers to
644  * @state: bridge state to destroy
645  *
646  * Destroys a bridge state previously created by
647  * &drm_atomic_helper_bridge_reset() or
648  * &drm_atomic_helper_bridge_duplicate_state(). This helper is meant to be
649  * used as a bridge &drm_bridge_funcs.atomic_destroy_state hook for bridges
650  * that don't subclass the bridge state.
651  */
652 void drm_atomic_helper_bridge_destroy_state(struct drm_bridge *bridge,
653                                             struct drm_bridge_state *state)
654 {
655         kfree(state);
656 }
657 EXPORT_SYMBOL(drm_atomic_helper_bridge_destroy_state);
658
659 /**
660  * __drm_atomic_helper_bridge_reset() - Initialize a bridge state to its
661  *                                      default
662  * @bridge: the bridge this state refers to
663  * @state: bridge state to initialize
664  *
665  * Initializes the bridge state to default values. This is meant to be called
666  * by the bridge &drm_bridge_funcs.atomic_reset hook for bridges that subclass
667  * the bridge state.
668  */
669 void __drm_atomic_helper_bridge_reset(struct drm_bridge *bridge,
670                                       struct drm_bridge_state *state)
671 {
672         memset(state, 0, sizeof(*state));
673         state->bridge = bridge;
674 }
675 EXPORT_SYMBOL(__drm_atomic_helper_bridge_reset);
676
677 /**
678  * drm_atomic_helper_bridge_reset() - Allocate and initialize a bridge state
679  *                                    to its default
680  * @bridge: the bridge this state refers to
681  *
682  * Allocates the bridge state and initializes it to default values. This helper
683  * is meant to be used as a bridge &drm_bridge_funcs.atomic_reset hook for
684  * bridges that don't subclass the bridge state.
685  */
686 struct drm_bridge_state *
687 drm_atomic_helper_bridge_reset(struct drm_bridge *bridge)
688 {
689         struct drm_bridge_state *bridge_state;
690
691         bridge_state = kzalloc(sizeof(*bridge_state), GFP_KERNEL);
692         if (!bridge_state)
693                 return ERR_PTR(-ENOMEM);
694
695         __drm_atomic_helper_bridge_reset(bridge, bridge_state);
696         return bridge_state;
697 }
698 EXPORT_SYMBOL(drm_atomic_helper_bridge_reset);