dt-bindings: mtd: ingenic: Use standard ecc-engine property
[linux/fpc-iii.git] / drivers / gpu / drm / drm_atomic_state_helper.c
blob4985384e51f6e5cc7308efc670d08a05e92ff4ec
1 /*
2 * Copyright (C) 2018 Intel Corp.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
22 * Authors:
23 * Rob Clark <robdclark@gmail.com>
24 * Daniel Vetter <daniel.vetter@ffwll.ch>
27 #include <drm/drm_atomic_state_helper.h>
28 #include <drm/drm_crtc.h>
29 #include <drm/drm_plane.h>
30 #include <drm/drm_connector.h>
31 #include <drm/drm_atomic.h>
32 #include <drm/drm_device.h>
34 #include <linux/slab.h>
35 #include <linux/dma-fence.h>
37 /**
38 * DOC: atomic state reset and initialization
40 * Both the drm core and the atomic helpers assume that there is always the full
41 * and correct atomic software state for all connectors, CRTCs and planes
42 * available. Which is a bit a problem on driver load and also after system
43 * suspend. One way to solve this is to have a hardware state read-out
44 * infrastructure which reconstructs the full software state (e.g. the i915
45 * driver).
47 * The simpler solution is to just reset the software state to everything off,
48 * which is easiest to do by calling drm_mode_config_reset(). To facilitate this
49 * the atomic helpers provide default reset implementations for all hooks.
51 * On the upside the precise state tracking of atomic simplifies system suspend
52 * and resume a lot. For drivers using drm_mode_config_reset() a complete recipe
53 * is implemented in drm_atomic_helper_suspend() and drm_atomic_helper_resume().
54 * For other drivers the building blocks are split out, see the documentation
55 * for these functions.
58 /**
59 * drm_atomic_helper_crtc_reset - default &drm_crtc_funcs.reset hook for CRTCs
60 * @crtc: drm CRTC
62 * Resets the atomic state for @crtc by freeing the state pointer (which might
63 * be NULL, e.g. at driver load time) and allocating a new empty state object.
65 void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc)
67 if (crtc->state)
68 __drm_atomic_helper_crtc_destroy_state(crtc->state);
70 kfree(crtc->state);
71 crtc->state = kzalloc(sizeof(*crtc->state), GFP_KERNEL);
73 if (crtc->state)
74 crtc->state->crtc = crtc;
76 EXPORT_SYMBOL(drm_atomic_helper_crtc_reset);
78 /**
79 * __drm_atomic_helper_crtc_duplicate_state - copy atomic CRTC state
80 * @crtc: CRTC object
81 * @state: atomic CRTC state
83 * Copies atomic state from a CRTC's current state and resets inferred values.
84 * This is useful for drivers that subclass the CRTC state.
86 void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc,
87 struct drm_crtc_state *state)
89 memcpy(state, crtc->state, sizeof(*state));
91 if (state->mode_blob)
92 drm_property_blob_get(state->mode_blob);
93 if (state->degamma_lut)
94 drm_property_blob_get(state->degamma_lut);
95 if (state->ctm)
96 drm_property_blob_get(state->ctm);
97 if (state->gamma_lut)
98 drm_property_blob_get(state->gamma_lut);
99 state->mode_changed = false;
100 state->active_changed = false;
101 state->planes_changed = false;
102 state->connectors_changed = false;
103 state->color_mgmt_changed = false;
104 state->zpos_changed = false;
105 state->commit = NULL;
106 state->event = NULL;
107 state->pageflip_flags = 0;
109 EXPORT_SYMBOL(__drm_atomic_helper_crtc_duplicate_state);
112 * drm_atomic_helper_crtc_duplicate_state - default state duplicate hook
113 * @crtc: drm CRTC
115 * Default CRTC state duplicate hook for drivers which don't have their own
116 * subclassed CRTC state structure.
118 struct drm_crtc_state *
119 drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc)
121 struct drm_crtc_state *state;
123 if (WARN_ON(!crtc->state))
124 return NULL;
126 state = kmalloc(sizeof(*state), GFP_KERNEL);
127 if (state)
128 __drm_atomic_helper_crtc_duplicate_state(crtc, state);
130 return state;
132 EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state);
135 * __drm_atomic_helper_crtc_destroy_state - release CRTC state
136 * @state: CRTC state object to release
138 * Releases all resources stored in the CRTC state without actually freeing
139 * the memory of the CRTC state. This is useful for drivers that subclass the
140 * CRTC state.
142 void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state)
144 if (state->commit) {
146 * In the event that a non-blocking commit returns
147 * -ERESTARTSYS before the commit_tail work is queued, we will
148 * have an extra reference to the commit object. Release it, if
149 * the event has not been consumed by the worker.
151 * state->event may be freed, so we can't directly look at
152 * state->event->base.completion.
154 if (state->event && state->commit->abort_completion)
155 drm_crtc_commit_put(state->commit);
157 kfree(state->commit->event);
158 state->commit->event = NULL;
160 drm_crtc_commit_put(state->commit);
163 drm_property_blob_put(state->mode_blob);
164 drm_property_blob_put(state->degamma_lut);
165 drm_property_blob_put(state->ctm);
166 drm_property_blob_put(state->gamma_lut);
168 EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state);
171 * drm_atomic_helper_crtc_destroy_state - default state destroy hook
172 * @crtc: drm CRTC
173 * @state: CRTC state object to release
175 * Default CRTC state destroy hook for drivers which don't have their own
176 * subclassed CRTC state structure.
178 void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
179 struct drm_crtc_state *state)
181 __drm_atomic_helper_crtc_destroy_state(state);
182 kfree(state);
184 EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state);
187 * __drm_atomic_helper_plane_reset - resets planes state to default values
188 * @plane: plane object, must not be NULL
189 * @state: atomic plane state, must not be NULL
191 * Initializes plane state to default. This is useful for drivers that subclass
192 * the plane state.
194 void __drm_atomic_helper_plane_reset(struct drm_plane *plane,
195 struct drm_plane_state *state)
197 state->plane = plane;
198 state->rotation = DRM_MODE_ROTATE_0;
200 state->alpha = DRM_BLEND_ALPHA_OPAQUE;
201 state->pixel_blend_mode = DRM_MODE_BLEND_PREMULTI;
203 plane->state = state;
205 EXPORT_SYMBOL(__drm_atomic_helper_plane_reset);
208 * drm_atomic_helper_plane_reset - default &drm_plane_funcs.reset hook for planes
209 * @plane: drm plane
211 * Resets the atomic state for @plane by freeing the state pointer (which might
212 * be NULL, e.g. at driver load time) and allocating a new empty state object.
214 void drm_atomic_helper_plane_reset(struct drm_plane *plane)
216 if (plane->state)
217 __drm_atomic_helper_plane_destroy_state(plane->state);
219 kfree(plane->state);
220 plane->state = kzalloc(sizeof(*plane->state), GFP_KERNEL);
221 if (plane->state)
222 __drm_atomic_helper_plane_reset(plane, plane->state);
224 EXPORT_SYMBOL(drm_atomic_helper_plane_reset);
227 * __drm_atomic_helper_plane_duplicate_state - copy atomic plane state
228 * @plane: plane object
229 * @state: atomic plane state
231 * Copies atomic state from a plane's current state. This is useful for
232 * drivers that subclass the plane state.
234 void __drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane,
235 struct drm_plane_state *state)
237 memcpy(state, plane->state, sizeof(*state));
239 if (state->fb)
240 drm_framebuffer_get(state->fb);
242 state->fence = NULL;
243 state->commit = NULL;
244 state->fb_damage_clips = NULL;
246 EXPORT_SYMBOL(__drm_atomic_helper_plane_duplicate_state);
249 * drm_atomic_helper_plane_duplicate_state - default state duplicate hook
250 * @plane: drm plane
252 * Default plane state duplicate hook for drivers which don't have their own
253 * subclassed plane state structure.
255 struct drm_plane_state *
256 drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane)
258 struct drm_plane_state *state;
260 if (WARN_ON(!plane->state))
261 return NULL;
263 state = kmalloc(sizeof(*state), GFP_KERNEL);
264 if (state)
265 __drm_atomic_helper_plane_duplicate_state(plane, state);
267 return state;
269 EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state);
272 * __drm_atomic_helper_plane_destroy_state - release plane state
273 * @state: plane state object to release
275 * Releases all resources stored in the plane state without actually freeing
276 * the memory of the plane state. This is useful for drivers that subclass the
277 * plane state.
279 void __drm_atomic_helper_plane_destroy_state(struct drm_plane_state *state)
281 if (state->fb)
282 drm_framebuffer_put(state->fb);
284 if (state->fence)
285 dma_fence_put(state->fence);
287 if (state->commit)
288 drm_crtc_commit_put(state->commit);
290 drm_property_blob_put(state->fb_damage_clips);
292 EXPORT_SYMBOL(__drm_atomic_helper_plane_destroy_state);
295 * drm_atomic_helper_plane_destroy_state - default state destroy hook
296 * @plane: drm plane
297 * @state: plane state object to release
299 * Default plane state destroy hook for drivers which don't have their own
300 * subclassed plane state structure.
302 void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
303 struct drm_plane_state *state)
305 __drm_atomic_helper_plane_destroy_state(state);
306 kfree(state);
308 EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state);
311 * __drm_atomic_helper_connector_reset - reset state on connector
312 * @connector: drm connector
313 * @conn_state: connector state to assign
315 * Initializes the newly allocated @conn_state and assigns it to
316 * the &drm_conector->state pointer of @connector, usually required when
317 * initializing the drivers or when called from the &drm_connector_funcs.reset
318 * hook.
320 * This is useful for drivers that subclass the connector state.
322 void
323 __drm_atomic_helper_connector_reset(struct drm_connector *connector,
324 struct drm_connector_state *conn_state)
326 if (conn_state)
327 conn_state->connector = connector;
329 connector->state = conn_state;
331 EXPORT_SYMBOL(__drm_atomic_helper_connector_reset);
334 * drm_atomic_helper_connector_reset - default &drm_connector_funcs.reset hook for connectors
335 * @connector: drm connector
337 * Resets the atomic state for @connector by freeing the state pointer (which
338 * might be NULL, e.g. at driver load time) and allocating a new empty state
339 * object.
341 void drm_atomic_helper_connector_reset(struct drm_connector *connector)
343 struct drm_connector_state *conn_state =
344 kzalloc(sizeof(*conn_state), GFP_KERNEL);
346 if (connector->state)
347 __drm_atomic_helper_connector_destroy_state(connector->state);
349 kfree(connector->state);
350 __drm_atomic_helper_connector_reset(connector, conn_state);
352 EXPORT_SYMBOL(drm_atomic_helper_connector_reset);
355 * __drm_atomic_helper_connector_duplicate_state - copy atomic connector state
356 * @connector: connector object
357 * @state: atomic connector state
359 * Copies atomic state from a connector's current state. This is useful for
360 * drivers that subclass the connector state.
362 void
363 __drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector,
364 struct drm_connector_state *state)
366 memcpy(state, connector->state, sizeof(*state));
367 if (state->crtc)
368 drm_connector_get(connector);
369 state->commit = NULL;
371 /* Don't copy over a writeback job, they are used only once */
372 state->writeback_job = NULL;
374 EXPORT_SYMBOL(__drm_atomic_helper_connector_duplicate_state);
377 * drm_atomic_helper_connector_duplicate_state - default state duplicate hook
378 * @connector: drm connector
380 * Default connector state duplicate hook for drivers which don't have their own
381 * subclassed connector state structure.
383 struct drm_connector_state *
384 drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector)
386 struct drm_connector_state *state;
388 if (WARN_ON(!connector->state))
389 return NULL;
391 state = kmalloc(sizeof(*state), GFP_KERNEL);
392 if (state)
393 __drm_atomic_helper_connector_duplicate_state(connector, state);
395 return state;
397 EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state);
400 * __drm_atomic_helper_connector_destroy_state - release connector state
401 * @state: connector state object to release
403 * Releases all resources stored in the connector state without actually
404 * freeing the memory of the connector state. This is useful for drivers that
405 * subclass the connector state.
407 void
408 __drm_atomic_helper_connector_destroy_state(struct drm_connector_state *state)
410 if (state->crtc)
411 drm_connector_put(state->connector);
413 if (state->commit)
414 drm_crtc_commit_put(state->commit);
416 EXPORT_SYMBOL(__drm_atomic_helper_connector_destroy_state);
419 * drm_atomic_helper_connector_destroy_state - default state destroy hook
420 * @connector: drm connector
421 * @state: connector state object to release
423 * Default connector state destroy hook for drivers which don't have their own
424 * subclassed connector state structure.
426 void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
427 struct drm_connector_state *state)
429 __drm_atomic_helper_connector_destroy_state(state);
430 kfree(state);
432 EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state);
435 * __drm_atomic_helper_private_duplicate_state - copy atomic private state
436 * @obj: CRTC object
437 * @state: new private object state
439 * Copies atomic state from a private objects's current state and resets inferred values.
440 * This is useful for drivers that subclass the private state.
442 void __drm_atomic_helper_private_obj_duplicate_state(struct drm_private_obj *obj,
443 struct drm_private_state *state)
445 memcpy(state, obj->state, sizeof(*state));
447 EXPORT_SYMBOL(__drm_atomic_helper_private_obj_duplicate_state);