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