Rev 5271 | Rev 6660 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5271 | Rev 6084 | ||
---|---|---|---|
Line 28... | Line 28... | ||
28 | 28 | ||
29 | #include |
29 | #include |
30 | #include |
30 | #include |
Line -... | Line 31... | ||
- | 31 | #include |
|
- | 32 | ||
- | 33 | /** |
|
- | 34 | * drm_atomic_state_default_release - |
|
- | 35 | * release memory initialized by drm_atomic_state_init |
|
- | 36 | * @state: atomic state |
|
- | 37 | * |
|
- | 38 | * Free all the memory allocated by drm_atomic_state_init. |
|
31 | #include |
39 | * This is useful for drivers that subclass the atomic state. |
32 | 40 | */ |
|
33 | static void kfree_state(struct drm_atomic_state *state) |
41 | void drm_atomic_state_default_release(struct drm_atomic_state *state) |
34 | { |
42 | { |
35 | kfree(state->connectors); |
43 | kfree(state->connectors); |
36 | kfree(state->connector_states); |
44 | kfree(state->connector_states); |
37 | kfree(state->crtcs); |
45 | kfree(state->crtcs); |
38 | kfree(state->crtc_states); |
46 | kfree(state->crtc_states); |
39 | kfree(state->planes); |
- | |
40 | kfree(state->plane_states); |
47 | kfree(state->planes); |
- | 48 | kfree(state->plane_states); |
|
Line 41... | Line 49... | ||
41 | kfree(state); |
49 | } |
42 | } |
50 | EXPORT_SYMBOL(drm_atomic_state_default_release); |
43 | 51 | ||
- | 52 | /** |
|
44 | /** |
53 | * drm_atomic_state_init - init new atomic state |
- | 54 | * @dev: DRM device |
|
45 | * drm_atomic_state_alloc - allocate atomic state |
55 | * @state: atomic state |
46 | * @dev: DRM device |
56 | * |
47 | * |
57 | * Default implementation for filling in a new atomic state. |
48 | * This allocates an empty atomic state to track updates. |
58 | * This is useful for drivers that subclass the atomic state. |
49 | */ |
59 | */ |
50 | struct drm_atomic_state * |
60 | int |
51 | drm_atomic_state_alloc(struct drm_device *dev) |
- | |
52 | { |
61 | drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state) |
53 | struct drm_atomic_state *state; |
62 | { |
54 | 63 | /* TODO legacy paths should maybe do a better job about |
|
Line 55... | Line 64... | ||
55 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
64 | * setting this appropriately? |
Line 56... | Line 65... | ||
56 | if (!state) |
65 | */ |
57 | return NULL; |
66 | state->allow_modeset = true; |
Line 85... | Line 94... | ||
85 | if (!state->connector_states) |
94 | if (!state->connector_states) |
86 | goto fail; |
95 | goto fail; |
Line 87... | Line 96... | ||
87 | 96 | ||
Line 88... | Line 97... | ||
88 | state->dev = dev; |
97 | state->dev = dev; |
Line 89... | Line 98... | ||
89 | 98 | ||
90 | DRM_DEBUG_KMS("Allocate atomic state %p\n", state); |
99 | DRM_DEBUG_ATOMIC("Allocated atomic state %p\n", state); |
- | 100 | ||
91 | 101 | return 0; |
|
- | 102 | fail: |
|
- | 103 | drm_atomic_state_default_release(state); |
|
Line -... | Line 104... | ||
- | 104 | return -ENOMEM; |
|
- | 105 | } |
|
- | 106 | EXPORT_SYMBOL(drm_atomic_state_init); |
|
- | 107 | ||
- | 108 | /** |
|
- | 109 | * drm_atomic_state_alloc - allocate atomic state |
|
- | 110 | * @dev: DRM device |
|
- | 111 | * |
|
- | 112 | * This allocates an empty atomic state to track updates. |
|
- | 113 | */ |
|
- | 114 | struct drm_atomic_state * |
|
- | 115 | drm_atomic_state_alloc(struct drm_device *dev) |
|
- | 116 | { |
|
- | 117 | struct drm_mode_config *config = &dev->mode_config; |
|
- | 118 | struct drm_atomic_state *state; |
|
- | 119 | ||
- | 120 | if (!config->funcs->atomic_state_alloc) { |
|
- | 121 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
|
92 | return state; |
122 | if (!state) |
93 | fail: |
123 | return NULL; |
- | 124 | if (drm_atomic_state_init(dev, state) < 0) { |
|
- | 125 | kfree(state); |
|
- | 126 | return NULL; |
|
- | 127 | } |
|
- | 128 | return state; |
|
94 | kfree_state(state); |
129 | } |
Line 95... | Line 130... | ||
95 | 130 | ||
96 | return NULL; |
131 | return config->funcs->atomic_state_alloc(dev); |
97 | } |
132 | } |
98 | EXPORT_SYMBOL(drm_atomic_state_alloc); |
133 | EXPORT_SYMBOL(drm_atomic_state_alloc); |
99 | - | ||
100 | /** |
- | |
101 | * drm_atomic_state_clear - clear state object |
134 | |
102 | * @state: atomic state |
- | |
103 | * |
- | |
104 | * When the w/w mutex algorithm detects a deadlock we need to back off and drop |
- | |
105 | * all locks. So someone else could sneak in and change the current modeset |
- | |
106 | * configuration. Which means that all the state assembled in @state is no |
135 | /** |
107 | * longer an atomic update to the current state, but to some arbitrary earlier |
- | |
108 | * state. Which could break assumptions the driver's ->atomic_check likely |
136 | * drm_atomic_state_default_clear - clear base atomic state |
109 | * relies on. |
137 | * @state: atomic state |
110 | * |
138 | * |
111 | * Hence we must clear all cached state and completely start over, using this |
139 | * Default implementation for clearing atomic state. |
112 | * function. |
140 | * This is useful for drivers that subclass the atomic state. |
113 | */ |
141 | */ |
Line 114... | Line 142... | ||
114 | void drm_atomic_state_clear(struct drm_atomic_state *state) |
142 | void drm_atomic_state_default_clear(struct drm_atomic_state *state) |
Line 115... | Line 143... | ||
115 | { |
143 | { |
116 | struct drm_device *dev = state->dev; |
144 | struct drm_device *dev = state->dev; |
Line 117... | Line 145... | ||
117 | struct drm_mode_config *config = &dev->mode_config; |
145 | struct drm_mode_config *config = &dev->mode_config; |
118 | int i; |
146 | int i; |
Line -... | Line 147... | ||
- | 147 | ||
119 | 148 | DRM_DEBUG_ATOMIC("Clearing atomic state %p\n", state); |
|
- | 149 | ||
- | 150 | for (i = 0; i < state->num_connector; i++) { |
|
- | 151 | struct drm_connector *connector = state->connectors[i]; |
|
- | 152 | ||
120 | DRM_DEBUG_KMS("Clearing atomic state %p\n", state); |
153 | if (!connector) |
- | 154 | continue; |
|
121 | 155 | ||
122 | for (i = 0; i < state->num_connector; i++) { |
156 | /* |
- | 157 | * FIXME: Async commits can race with connector unplugging and |
|
- | 158 | * there's currently nothing that prevents cleanup up state for |
|
123 | struct drm_connector *connector = state->connectors[i]; |
159 | * deleted connectors. As long as the callback doesn't look at |
Line 124... | Line 160... | ||
124 | 160 | * the connector we'll be fine though, so make sure that's the |
|
125 | if (!connector) |
161 | * case by setting all connector pointers to NULL. |
Line 126... | Line 162... | ||
126 | continue; |
162 | */ |
127 | 163 | state->connector_states[i]->connector = NULL; |
|
Line 128... | Line 164... | ||
128 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
164 | connector->funcs->atomic_destroy_state(NULL, |
129 | 165 | state->connector_states[i]); |
|
- | 166 | state->connectors[i] = NULL; |
|
- | 167 | state->connector_states[i] = NULL; |
|
130 | connector->funcs->atomic_destroy_state(connector, |
168 | } |
Line 131... | Line 169... | ||
131 | state->connector_states[i]); |
169 | |
132 | } |
170 | for (i = 0; i < config->num_crtc; i++) { |
Line 133... | Line 171... | ||
133 | 171 | struct drm_crtc *crtc = state->crtcs[i]; |
|
134 | for (i = 0; i < config->num_crtc; i++) { |
172 | |
Line 135... | Line 173... | ||
135 | struct drm_crtc *crtc = state->crtcs[i]; |
173 | if (!crtc) |
136 | 174 | continue; |
|
- | 175 | ||
- | 176 | crtc->funcs->atomic_destroy_state(crtc, |
|
137 | if (!crtc) |
177 | state->crtc_states[i]); |
138 | continue; |
178 | state->crtcs[i] = NULL; |
- | 179 | state->crtc_states[i] = NULL; |
|
- | 180 | } |
|
- | 181 | ||
- | 182 | for (i = 0; i < config->num_total_plane; i++) { |
|
- | 183 | struct drm_plane *plane = state->planes[i]; |
|
- | 184 | ||
- | 185 | if (!plane) |
|
- | 186 | continue; |
|
- | 187 | ||
- | 188 | plane->funcs->atomic_destroy_state(plane, |
|
- | 189 | state->plane_states[i]); |
|
- | 190 | state->planes[i] = NULL; |
|
- | 191 | state->plane_states[i] = NULL; |
|
- | 192 | } |
|
- | 193 | } |
|
- | 194 | EXPORT_SYMBOL(drm_atomic_state_default_clear); |
|
- | 195 | ||
- | 196 | /** |
|
- | 197 | * drm_atomic_state_clear - clear state object |
|
- | 198 | * @state: atomic state |
|
- | 199 | * |
|
- | 200 | * When the w/w mutex algorithm detects a deadlock we need to back off and drop |
|
- | 201 | * all locks. So someone else could sneak in and change the current modeset |
|
- | 202 | * configuration. Which means that all the state assembled in @state is no |
|
- | 203 | * longer an atomic update to the current state, but to some arbitrary earlier |
|
- | 204 | * state. Which could break assumptions the driver's ->atomic_check likely |
|
139 | 205 | * relies on. |
|
Line 140... | Line 206... | ||
140 | crtc->funcs->atomic_destroy_state(crtc, |
206 | * |
141 | state->crtc_states[i]); |
207 | * Hence we must clear all cached state and completely start over, using this |
142 | } |
208 | * function. |
Line 160... | Line 226... | ||
160 | * This frees all memory associated with an atomic state, including all the |
226 | * This frees all memory associated with an atomic state, including all the |
161 | * per-object state for planes, crtcs and connectors. |
227 | * per-object state for planes, crtcs and connectors. |
162 | */ |
228 | */ |
163 | void drm_atomic_state_free(struct drm_atomic_state *state) |
229 | void drm_atomic_state_free(struct drm_atomic_state *state) |
164 | { |
230 | { |
- | 231 | struct drm_device *dev; |
|
- | 232 | struct drm_mode_config *config; |
|
- | 233 | ||
- | 234 | if (!state) |
|
- | 235 | return; |
|
- | 236 | ||
- | 237 | dev = state->dev; |
|
- | 238 | config = &dev->mode_config; |
|
- | 239 | ||
165 | drm_atomic_state_clear(state); |
240 | drm_atomic_state_clear(state); |
Line 166... | Line 241... | ||
166 | 241 | ||
Line -... | Line 242... | ||
- | 242 | DRM_DEBUG_ATOMIC("Freeing atomic state %p\n", state); |
|
- | 243 | ||
- | 244 | if (config->funcs->atomic_state_free) { |
|
- | 245 | config->funcs->atomic_state_free(state); |
|
167 | DRM_DEBUG_KMS("Freeing atomic state %p\n", state); |
246 | } else { |
- | 247 | drm_atomic_state_default_release(state); |
|
168 | 248 | kfree(state); |
|
169 | kfree_state(state); |
249 | } |
Line 170... | Line 250... | ||
170 | } |
250 | } |
171 | EXPORT_SYMBOL(drm_atomic_state_free); |
251 | EXPORT_SYMBOL(drm_atomic_state_free); |
Line 187... | Line 267... | ||
187 | */ |
267 | */ |
188 | struct drm_crtc_state * |
268 | struct drm_crtc_state * |
189 | drm_atomic_get_crtc_state(struct drm_atomic_state *state, |
269 | drm_atomic_get_crtc_state(struct drm_atomic_state *state, |
190 | struct drm_crtc *crtc) |
270 | struct drm_crtc *crtc) |
191 | { |
271 | { |
192 | int ret, index; |
272 | int ret, index = drm_crtc_index(crtc); |
193 | struct drm_crtc_state *crtc_state; |
273 | struct drm_crtc_state *crtc_state; |
Line 194... | Line 274... | ||
194 | 274 | ||
195 | index = drm_crtc_index(crtc); |
- | |
196 | 275 | crtc_state = drm_atomic_get_existing_crtc_state(state, crtc); |
|
197 | if (state->crtc_states[index]) |
276 | if (crtc_state) |
Line 198... | Line 277... | ||
198 | return state->crtc_states[index]; |
277 | return crtc_state; |
199 | 278 | ||
200 | ret = drm_modeset_lock(&crtc->mutex, state->acquire_ctx); |
279 | ret = drm_modeset_lock(&crtc->mutex, state->acquire_ctx); |
Line 207... | Line 286... | ||
207 | 286 | ||
208 | state->crtc_states[index] = crtc_state; |
287 | state->crtc_states[index] = crtc_state; |
209 | state->crtcs[index] = crtc; |
288 | state->crtcs[index] = crtc; |
Line 210... | Line 289... | ||
210 | crtc_state->state = state; |
289 | crtc_state->state = state; |
211 | 290 | ||
Line 212... | Line 291... | ||
212 | DRM_DEBUG_KMS("Added [CRTC:%d] %p state to %p\n", |
291 | DRM_DEBUG_ATOMIC("Added [CRTC:%d] %p state to %p\n", |
213 | crtc->base.id, crtc_state, state); |
292 | crtc->base.id, crtc_state, state); |
214 | 293 | ||
Line 215... | Line 294... | ||
215 | return crtc_state; |
294 | return crtc_state; |
- | 295 | } |
|
- | 296 | EXPORT_SYMBOL(drm_atomic_get_crtc_state); |
|
- | 297 | ||
- | 298 | /** |
|
- | 299 | * drm_atomic_set_mode_for_crtc - set mode for CRTC |
|
- | 300 | * @state: the CRTC whose incoming state to update |
|
- | 301 | * @mode: kernel-internal mode to use for the CRTC, or NULL to disable |
|
- | 302 | * |
|
- | 303 | * Set a mode (originating from the kernel) on the desired CRTC state. Does |
|
- | 304 | * not change any other state properties, including enable, active, or |
|
- | 305 | * mode_changed. |
|
- | 306 | * |
|
- | 307 | * RETURNS: |
|
- | 308 | * Zero on success, error code on failure. Cannot return -EDEADLK. |
|
- | 309 | */ |
|
- | 310 | int drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state, |
|
- | 311 | struct drm_display_mode *mode) |
|
- | 312 | { |
|
- | 313 | struct drm_mode_modeinfo umode; |
|
- | 314 | ||
- | 315 | /* Early return for no change. */ |
|
- | 316 | if (mode && memcmp(&state->mode, mode, sizeof(*mode)) == 0) |
|
- | 317 | return 0; |
|
- | 318 | ||
- | 319 | if (state->mode_blob) |
|
- | 320 | drm_property_unreference_blob(state->mode_blob); |
|
- | 321 | state->mode_blob = NULL; |
|
- | 322 | ||
- | 323 | if (mode) { |
|
- | 324 | drm_mode_convert_to_umode(&umode, mode); |
|
- | 325 | state->mode_blob = |
|
- | 326 | drm_property_create_blob(state->crtc->dev, |
|
- | 327 | sizeof(umode), |
|
- | 328 | &umode); |
|
- | 329 | if (IS_ERR(state->mode_blob)) |
|
- | 330 | return PTR_ERR(state->mode_blob); |
|
- | 331 | ||
- | 332 | drm_mode_copy(&state->mode, mode); |
|
- | 333 | state->enable = true; |
|
- | 334 | DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n", |
|
- | 335 | mode->name, state); |
|
- | 336 | } else { |
|
- | 337 | memset(&state->mode, 0, sizeof(state->mode)); |
|
- | 338 | state->enable = false; |
|
- | 339 | DRM_DEBUG_ATOMIC("Set [NOMODE] for CRTC state %p\n", |
|
- | 340 | state); |
|
- | 341 | } |
|
- | 342 | ||
- | 343 | return 0; |
|
- | 344 | } |
|
- | 345 | EXPORT_SYMBOL(drm_atomic_set_mode_for_crtc); |
|
- | 346 | ||
- | 347 | /** |
|
- | 348 | * drm_atomic_set_mode_prop_for_crtc - set mode for CRTC |
|
- | 349 | * @state: the CRTC whose incoming state to update |
|
- | 350 | * @blob: pointer to blob property to use for mode |
|
- | 351 | * |
|
- | 352 | * Set a mode (originating from a blob property) on the desired CRTC state. |
|
- | 353 | * This function will take a reference on the blob property for the CRTC state, |
|
- | 354 | * and release the reference held on the state's existing mode property, if any |
|
- | 355 | * was set. |
|
- | 356 | * |
|
- | 357 | * RETURNS: |
|
- | 358 | * Zero on success, error code on failure. Cannot return -EDEADLK. |
|
- | 359 | */ |
|
- | 360 | int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state, |
|
- | 361 | struct drm_property_blob *blob) |
|
- | 362 | { |
|
- | 363 | if (blob == state->mode_blob) |
|
- | 364 | return 0; |
|
- | 365 | ||
- | 366 | if (state->mode_blob) |
|
- | 367 | drm_property_unreference_blob(state->mode_blob); |
|
- | 368 | state->mode_blob = NULL; |
|
- | 369 | ||
- | 370 | if (blob) { |
|
- | 371 | if (blob->length != sizeof(struct drm_mode_modeinfo) || |
|
- | 372 | drm_mode_convert_umode(&state->mode, |
|
- | 373 | (const struct drm_mode_modeinfo *) |
|
- | 374 | blob->data)) |
|
- | 375 | return -EINVAL; |
|
- | 376 | ||
- | 377 | state->mode_blob = drm_property_reference_blob(blob); |
|
- | 378 | state->enable = true; |
|
- | 379 | DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n", |
|
- | 380 | state->mode.name, state); |
|
- | 381 | } else { |
|
- | 382 | memset(&state->mode, 0, sizeof(state->mode)); |
|
- | 383 | state->enable = false; |
|
- | 384 | DRM_DEBUG_ATOMIC("Set [NOMODE] for CRTC state %p\n", |
|
- | 385 | state); |
|
- | 386 | } |
|
- | 387 | ||
- | 388 | return 0; |
|
- | 389 | } |
|
- | 390 | EXPORT_SYMBOL(drm_atomic_set_mode_prop_for_crtc); |
|
- | 391 | ||
- | 392 | /** |
|
- | 393 | * drm_atomic_crtc_set_property - set property on CRTC |
|
- | 394 | * @crtc: the drm CRTC to set a property on |
|
- | 395 | * @state: the state object to update with the new property value |
|
- | 396 | * @property: the property to set |
|
- | 397 | * @val: the new property value |
|
- | 398 | * |
|
- | 399 | * Use this instead of calling crtc->atomic_set_property directly. |
|
- | 400 | * This function handles generic/core properties and calls out to |
|
- | 401 | * driver's ->atomic_set_property() for driver properties. To ensure |
|
- | 402 | * consistent behavior you must call this function rather than the |
|
- | 403 | * driver hook directly. |
|
- | 404 | * |
|
- | 405 | * RETURNS: |
|
- | 406 | * Zero on success, error code on failure |
|
- | 407 | */ |
|
- | 408 | int drm_atomic_crtc_set_property(struct drm_crtc *crtc, |
|
- | 409 | struct drm_crtc_state *state, struct drm_property *property, |
|
- | 410 | uint64_t val) |
|
- | 411 | { |
|
- | 412 | struct drm_device *dev = crtc->dev; |
|
- | 413 | struct drm_mode_config *config = &dev->mode_config; |
|
- | 414 | int ret; |
|
- | 415 | ||
- | 416 | if (property == config->prop_active) |
|
- | 417 | state->active = val; |
|
- | 418 | else if (property == config->prop_mode_id) { |
|
- | 419 | struct drm_property_blob *mode = |
|
- | 420 | drm_property_lookup_blob(dev, val); |
|
- | 421 | ret = drm_atomic_set_mode_prop_for_crtc(state, mode); |
|
- | 422 | if (mode) |
|
- | 423 | drm_property_unreference_blob(mode); |
|
- | 424 | return ret; |
|
- | 425 | } |
|
- | 426 | else if (crtc->funcs->atomic_set_property) |
|
- | 427 | return crtc->funcs->atomic_set_property(crtc, state, property, val); |
|
- | 428 | else |
|
- | 429 | return -EINVAL; |
|
- | 430 | ||
- | 431 | return 0; |
|
- | 432 | } |
|
- | 433 | EXPORT_SYMBOL(drm_atomic_crtc_set_property); |
|
- | 434 | ||
- | 435 | /* |
|
- | 436 | * This function handles generic/core properties and calls out to |
|
- | 437 | * driver's ->atomic_get_property() for driver properties. To ensure |
|
- | 438 | * consistent behavior you must call this function rather than the |
|
- | 439 | * driver hook directly. |
|
- | 440 | */ |
|
- | 441 | static int |
|
- | 442 | drm_atomic_crtc_get_property(struct drm_crtc *crtc, |
|
- | 443 | const struct drm_crtc_state *state, |
|
- | 444 | struct drm_property *property, uint64_t *val) |
|
- | 445 | { |
|
- | 446 | struct drm_device *dev = crtc->dev; |
|
- | 447 | struct drm_mode_config *config = &dev->mode_config; |
|
- | 448 | ||
- | 449 | if (property == config->prop_active) |
|
- | 450 | *val = state->active; |
|
- | 451 | else if (property == config->prop_mode_id) |
|
- | 452 | *val = (state->mode_blob) ? state->mode_blob->base.id : 0; |
|
- | 453 | else if (crtc->funcs->atomic_get_property) |
|
- | 454 | return crtc->funcs->atomic_get_property(crtc, state, property, val); |
|
- | 455 | else |
|
- | 456 | return -EINVAL; |
|
- | 457 | ||
- | 458 | return 0; |
|
- | 459 | } |
|
- | 460 | ||
- | 461 | /** |
|
- | 462 | * drm_atomic_crtc_check - check crtc state |
|
- | 463 | * @crtc: crtc to check |
|
- | 464 | * @state: crtc state to check |
|
- | 465 | * |
|
- | 466 | * Provides core sanity checks for crtc state. |
|
- | 467 | * |
|
- | 468 | * RETURNS: |
|
- | 469 | * Zero on success, error code on failure |
|
- | 470 | */ |
|
- | 471 | static int drm_atomic_crtc_check(struct drm_crtc *crtc, |
|
- | 472 | struct drm_crtc_state *state) |
|
- | 473 | { |
|
- | 474 | /* NOTE: we explicitly don't enforce constraints such as primary |
|
- | 475 | * layer covering entire screen, since that is something we want |
|
- | 476 | * to allow (on hw that supports it). For hw that does not, it |
|
- | 477 | * should be checked in driver's crtc->atomic_check() vfunc. |
|
- | 478 | * |
|
- | 479 | * TODO: Add generic modeset state checks once we support those. |
|
- | 480 | */ |
|
- | 481 | ||
- | 482 | if (state->active && !state->enable) { |
|
- | 483 | DRM_DEBUG_ATOMIC("[CRTC:%d] active without enabled\n", |
|
- | 484 | crtc->base.id); |
|
- | 485 | return -EINVAL; |
|
- | 486 | } |
|
- | 487 | ||
- | 488 | /* The state->enable vs. state->mode_blob checks can be WARN_ON, |
|
- | 489 | * as this is a kernel-internal detail that userspace should never |
|
- | 490 | * be able to trigger. */ |
|
- | 491 | if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) && |
|
- | 492 | WARN_ON(state->enable && !state->mode_blob)) { |
|
- | 493 | DRM_DEBUG_ATOMIC("[CRTC:%d] enabled without mode blob\n", |
|
- | 494 | crtc->base.id); |
|
- | 495 | return -EINVAL; |
|
- | 496 | } |
|
- | 497 | ||
- | 498 | if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) && |
|
- | 499 | WARN_ON(!state->enable && state->mode_blob)) { |
|
- | 500 | DRM_DEBUG_ATOMIC("[CRTC:%d] disabled with mode blob\n", |
|
- | 501 | crtc->base.id); |
|
- | 502 | return -EINVAL; |
|
- | 503 | } |
|
- | 504 | ||
216 | } |
505 | return 0; |
217 | EXPORT_SYMBOL(drm_atomic_get_crtc_state); |
506 | } |
218 | 507 | ||
219 | /** |
508 | /** |
220 | * drm_atomic_get_plane_state - get plane state |
509 | * drm_atomic_get_plane_state - get plane state |
Line 233... | Line 522... | ||
233 | */ |
522 | */ |
234 | struct drm_plane_state * |
523 | struct drm_plane_state * |
235 | drm_atomic_get_plane_state(struct drm_atomic_state *state, |
524 | drm_atomic_get_plane_state(struct drm_atomic_state *state, |
236 | struct drm_plane *plane) |
525 | struct drm_plane *plane) |
237 | { |
526 | { |
238 | int ret, index; |
527 | int ret, index = drm_plane_index(plane); |
239 | struct drm_plane_state *plane_state; |
528 | struct drm_plane_state *plane_state; |
Line 240... | Line 529... | ||
240 | 529 | ||
241 | index = drm_plane_index(plane); |
- | |
242 | 530 | plane_state = drm_atomic_get_existing_plane_state(state, plane); |
|
243 | if (state->plane_states[index]) |
531 | if (plane_state) |
Line 244... | Line 532... | ||
244 | return state->plane_states[index]; |
532 | return plane_state; |
245 | 533 | ||
246 | ret = drm_modeset_lock(&plane->mutex, state->acquire_ctx); |
534 | ret = drm_modeset_lock(&plane->mutex, state->acquire_ctx); |
Line 253... | Line 541... | ||
253 | 541 | ||
254 | state->plane_states[index] = plane_state; |
542 | state->plane_states[index] = plane_state; |
255 | state->planes[index] = plane; |
543 | state->planes[index] = plane; |
Line 256... | Line 544... | ||
256 | plane_state->state = state; |
544 | plane_state->state = state; |
257 | 545 | ||
Line 258... | Line 546... | ||
258 | DRM_DEBUG_KMS("Added [PLANE:%d] %p state to %p\n", |
546 | DRM_DEBUG_ATOMIC("Added [PLANE:%d] %p state to %p\n", |
259 | plane->base.id, plane_state, state); |
547 | plane->base.id, plane_state, state); |
Line 270... | Line 558... | ||
270 | return plane_state; |
558 | return plane_state; |
271 | } |
559 | } |
272 | EXPORT_SYMBOL(drm_atomic_get_plane_state); |
560 | EXPORT_SYMBOL(drm_atomic_get_plane_state); |
Line 273... | Line 561... | ||
273 | 561 | ||
- | 562 | /** |
|
- | 563 | * drm_atomic_plane_set_property - set property on plane |
|
- | 564 | * @plane: the drm plane to set a property on |
|
- | 565 | * @state: the state object to update with the new property value |
|
- | 566 | * @property: the property to set |
|
- | 567 | * @val: the new property value |
|
- | 568 | * |
|
- | 569 | * Use this instead of calling plane->atomic_set_property directly. |
|
- | 570 | * This function handles generic/core properties and calls out to |
|
- | 571 | * driver's ->atomic_set_property() for driver properties. To ensure |
|
- | 572 | * consistent behavior you must call this function rather than the |
|
- | 573 | * driver hook directly. |
|
- | 574 | * |
|
- | 575 | * RETURNS: |
|
- | 576 | * Zero on success, error code on failure |
|
- | 577 | */ |
|
- | 578 | int drm_atomic_plane_set_property(struct drm_plane *plane, |
|
- | 579 | struct drm_plane_state *state, struct drm_property *property, |
|
- | 580 | uint64_t val) |
|
- | 581 | { |
|
- | 582 | struct drm_device *dev = plane->dev; |
|
- | 583 | struct drm_mode_config *config = &dev->mode_config; |
|
- | 584 | ||
- | 585 | if (property == config->prop_fb_id) { |
|
- | 586 | struct drm_framebuffer *fb = drm_framebuffer_lookup(dev, val); |
|
- | 587 | drm_atomic_set_fb_for_plane(state, fb); |
|
- | 588 | if (fb) |
|
- | 589 | drm_framebuffer_unreference(fb); |
|
- | 590 | } else if (property == config->prop_crtc_id) { |
|
- | 591 | struct drm_crtc *crtc = drm_crtc_find(dev, val); |
|
- | 592 | return drm_atomic_set_crtc_for_plane(state, crtc); |
|
- | 593 | } else if (property == config->prop_crtc_x) { |
|
- | 594 | state->crtc_x = U642I64(val); |
|
- | 595 | } else if (property == config->prop_crtc_y) { |
|
- | 596 | state->crtc_y = U642I64(val); |
|
- | 597 | } else if (property == config->prop_crtc_w) { |
|
- | 598 | state->crtc_w = val; |
|
- | 599 | } else if (property == config->prop_crtc_h) { |
|
- | 600 | state->crtc_h = val; |
|
- | 601 | } else if (property == config->prop_src_x) { |
|
- | 602 | state->src_x = val; |
|
- | 603 | } else if (property == config->prop_src_y) { |
|
- | 604 | state->src_y = val; |
|
- | 605 | } else if (property == config->prop_src_w) { |
|
- | 606 | state->src_w = val; |
|
- | 607 | } else if (property == config->prop_src_h) { |
|
- | 608 | state->src_h = val; |
|
- | 609 | } else if (property == config->rotation_property) { |
|
- | 610 | state->rotation = val; |
|
- | 611 | } else if (plane->funcs->atomic_set_property) { |
|
- | 612 | return plane->funcs->atomic_set_property(plane, state, |
|
- | 613 | property, val); |
|
- | 614 | } else { |
|
- | 615 | return -EINVAL; |
|
- | 616 | } |
|
- | 617 | ||
- | 618 | return 0; |
|
- | 619 | } |
|
- | 620 | EXPORT_SYMBOL(drm_atomic_plane_set_property); |
|
- | 621 | ||
- | 622 | /* |
|
- | 623 | * This function handles generic/core properties and calls out to |
|
- | 624 | * driver's ->atomic_get_property() for driver properties. To ensure |
|
- | 625 | * consistent behavior you must call this function rather than the |
|
- | 626 | * driver hook directly. |
|
- | 627 | */ |
|
- | 628 | static int |
|
- | 629 | drm_atomic_plane_get_property(struct drm_plane *plane, |
|
- | 630 | const struct drm_plane_state *state, |
|
- | 631 | struct drm_property *property, uint64_t *val) |
|
- | 632 | { |
|
- | 633 | struct drm_device *dev = plane->dev; |
|
- | 634 | struct drm_mode_config *config = &dev->mode_config; |
|
- | 635 | ||
- | 636 | if (property == config->prop_fb_id) { |
|
- | 637 | *val = (state->fb) ? state->fb->base.id : 0; |
|
- | 638 | } else if (property == config->prop_crtc_id) { |
|
- | 639 | *val = (state->crtc) ? state->crtc->base.id : 0; |
|
- | 640 | } else if (property == config->prop_crtc_x) { |
|
- | 641 | *val = I642U64(state->crtc_x); |
|
- | 642 | } else if (property == config->prop_crtc_y) { |
|
- | 643 | *val = I642U64(state->crtc_y); |
|
- | 644 | } else if (property == config->prop_crtc_w) { |
|
- | 645 | *val = state->crtc_w; |
|
- | 646 | } else if (property == config->prop_crtc_h) { |
|
- | 647 | *val = state->crtc_h; |
|
- | 648 | } else if (property == config->prop_src_x) { |
|
- | 649 | *val = state->src_x; |
|
- | 650 | } else if (property == config->prop_src_y) { |
|
- | 651 | *val = state->src_y; |
|
- | 652 | } else if (property == config->prop_src_w) { |
|
- | 653 | *val = state->src_w; |
|
- | 654 | } else if (property == config->prop_src_h) { |
|
- | 655 | *val = state->src_h; |
|
- | 656 | } else if (property == config->rotation_property) { |
|
- | 657 | *val = state->rotation; |
|
- | 658 | } else if (plane->funcs->atomic_get_property) { |
|
- | 659 | return plane->funcs->atomic_get_property(plane, state, property, val); |
|
- | 660 | } else { |
|
- | 661 | return -EINVAL; |
|
- | 662 | } |
|
- | 663 | ||
- | 664 | return 0; |
|
- | 665 | } |
|
- | 666 | ||
- | 667 | static bool |
|
- | 668 | plane_switching_crtc(struct drm_atomic_state *state, |
|
- | 669 | struct drm_plane *plane, |
|
- | 670 | struct drm_plane_state *plane_state) |
|
- | 671 | { |
|
- | 672 | if (!plane->state->crtc || !plane_state->crtc) |
|
- | 673 | return false; |
|
- | 674 | ||
- | 675 | if (plane->state->crtc == plane_state->crtc) |
|
- | 676 | return false; |
|
- | 677 | ||
- | 678 | /* This could be refined, but currently there's no helper or driver code |
|
- | 679 | * to implement direct switching of active planes nor userspace to take |
|
- | 680 | * advantage of more direct plane switching without the intermediate |
|
- | 681 | * full OFF state. |
|
- | 682 | */ |
|
- | 683 | return true; |
|
- | 684 | } |
|
- | 685 | ||
- | 686 | /** |
|
- | 687 | * drm_atomic_plane_check - check plane state |
|
- | 688 | * @plane: plane to check |
|
- | 689 | * @state: plane state to check |
|
- | 690 | * |
|
- | 691 | * Provides core sanity checks for plane state. |
|
- | 692 | * |
|
- | 693 | * RETURNS: |
|
- | 694 | * Zero on success, error code on failure |
|
- | 695 | */ |
|
- | 696 | static int drm_atomic_plane_check(struct drm_plane *plane, |
|
- | 697 | struct drm_plane_state *state) |
|
- | 698 | { |
|
- | 699 | unsigned int fb_width, fb_height; |
|
- | 700 | int ret; |
|
- | 701 | ||
- | 702 | /* either *both* CRTC and FB must be set, or neither */ |
|
- | 703 | if (WARN_ON(state->crtc && !state->fb)) { |
|
- | 704 | DRM_DEBUG_ATOMIC("CRTC set but no FB\n"); |
|
- | 705 | return -EINVAL; |
|
- | 706 | } else if (WARN_ON(state->fb && !state->crtc)) { |
|
- | 707 | DRM_DEBUG_ATOMIC("FB set but no CRTC\n"); |
|
- | 708 | return -EINVAL; |
|
- | 709 | } |
|
- | 710 | ||
- | 711 | /* if disabled, we don't care about the rest of the state: */ |
|
- | 712 | if (!state->crtc) |
|
- | 713 | return 0; |
|
- | 714 | ||
- | 715 | /* Check whether this plane is usable on this CRTC */ |
|
- | 716 | if (!(plane->possible_crtcs & drm_crtc_mask(state->crtc))) { |
|
- | 717 | DRM_DEBUG_ATOMIC("Invalid crtc for plane\n"); |
|
- | 718 | return -EINVAL; |
|
- | 719 | } |
|
- | 720 | ||
- | 721 | /* Check whether this plane supports the fb pixel format. */ |
|
- | 722 | ret = drm_plane_check_pixel_format(plane, state->fb->pixel_format); |
|
- | 723 | if (ret) { |
|
- | 724 | DRM_DEBUG_ATOMIC("Invalid pixel format %s\n", |
|
- | 725 | drm_get_format_name(state->fb->pixel_format)); |
|
- | 726 | return ret; |
|
- | 727 | } |
|
- | 728 | ||
- | 729 | /* Give drivers some help against integer overflows */ |
|
- | 730 | if (state->crtc_w > INT_MAX || |
|
- | 731 | state->crtc_x > INT_MAX - (int32_t) state->crtc_w || |
|
- | 732 | state->crtc_h > INT_MAX || |
|
- | 733 | state->crtc_y > INT_MAX - (int32_t) state->crtc_h) { |
|
- | 734 | DRM_DEBUG_ATOMIC("Invalid CRTC coordinates %ux%u+%d+%d\n", |
|
- | 735 | state->crtc_w, state->crtc_h, |
|
- | 736 | state->crtc_x, state->crtc_y); |
|
- | 737 | return -ERANGE; |
|
- | 738 | } |
|
- | 739 | ||
- | 740 | fb_width = state->fb->width << 16; |
|
- | 741 | fb_height = state->fb->height << 16; |
|
- | 742 | ||
- | 743 | /* Make sure source coordinates are inside the fb. */ |
|
- | 744 | if (state->src_w > fb_width || |
|
- | 745 | state->src_x > fb_width - state->src_w || |
|
- | 746 | state->src_h > fb_height || |
|
- | 747 | state->src_y > fb_height - state->src_h) { |
|
- | 748 | DRM_DEBUG_ATOMIC("Invalid source coordinates " |
|
- | 749 | "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n", |
|
- | 750 | state->src_w >> 16, ((state->src_w & 0xffff) * 15625) >> 10, |
|
- | 751 | state->src_h >> 16, ((state->src_h & 0xffff) * 15625) >> 10, |
|
- | 752 | state->src_x >> 16, ((state->src_x & 0xffff) * 15625) >> 10, |
|
- | 753 | state->src_y >> 16, ((state->src_y & 0xffff) * 15625) >> 10); |
|
- | 754 | return -ENOSPC; |
|
- | 755 | } |
|
- | 756 | ||
- | 757 | if (plane_switching_crtc(state->state, plane, state)) { |
|
- | 758 | DRM_DEBUG_ATOMIC("[PLANE:%d] switching CRTC directly\n", |
|
- | 759 | plane->base.id); |
|
- | 760 | return -EINVAL; |
|
- | 761 | } |
|
- | 762 | ||
- | 763 | return 0; |
|
- | 764 | } |
|
- | 765 | ||
274 | /** |
766 | /** |
275 | * drm_atomic_get_connector_state - get connector state |
767 | * drm_atomic_get_connector_state - get connector state |
276 | * @state: global atomic state object |
768 | * @state: global atomic state object |
277 | * @connector: connector to get state object for |
769 | * @connector: connector to get state object for |
278 | * |
770 | * |
Line 309... | Line 801... | ||
309 | * Note that we only grab the indexes once we have the right lock to |
801 | * Note that we only grab the indexes once we have the right lock to |
310 | * prevent hotplug/unplugging of connectors. So removal is no problem, |
802 | * prevent hotplug/unplugging of connectors. So removal is no problem, |
311 | * at most the array is a bit too large. |
803 | * at most the array is a bit too large. |
312 | */ |
804 | */ |
313 | if (index >= state->num_connector) { |
805 | if (index >= state->num_connector) { |
314 | DRM_DEBUG_KMS("Hot-added connector would overflow state array, restarting\n"); |
806 | DRM_DEBUG_ATOMIC("Hot-added connector would overflow state array, restarting\n"); |
315 | return ERR_PTR(-EAGAIN); |
807 | return ERR_PTR(-EAGAIN); |
316 | } |
808 | } |
Line 317... | Line 809... | ||
317 | 809 | ||
318 | if (state->connector_states[index]) |
810 | if (state->connector_states[index]) |
Line 324... | Line 816... | ||
324 | 816 | ||
325 | state->connector_states[index] = connector_state; |
817 | state->connector_states[index] = connector_state; |
326 | state->connectors[index] = connector; |
818 | state->connectors[index] = connector; |
Line 327... | Line 819... | ||
327 | connector_state->state = state; |
819 | connector_state->state = state; |
328 | 820 | ||
Line 329... | Line 821... | ||
329 | DRM_DEBUG_KMS("Added [CONNECTOR:%d] %p state to %p\n", |
821 | DRM_DEBUG_ATOMIC("Added [CONNECTOR:%d] %p state to %p\n", |
330 | connector->base.id, connector_state, state); |
822 | connector->base.id, connector_state, state); |
Line 341... | Line 833... | ||
341 | return connector_state; |
833 | return connector_state; |
342 | } |
834 | } |
343 | EXPORT_SYMBOL(drm_atomic_get_connector_state); |
835 | EXPORT_SYMBOL(drm_atomic_get_connector_state); |
Line 344... | Line 836... | ||
344 | 836 | ||
- | 837 | /** |
|
- | 838 | * drm_atomic_connector_set_property - set property on connector. |
|
- | 839 | * @connector: the drm connector to set a property on |
|
- | 840 | * @state: the state object to update with the new property value |
|
- | 841 | * @property: the property to set |
|
- | 842 | * @val: the new property value |
|
- | 843 | * |
|
- | 844 | * Use this instead of calling connector->atomic_set_property directly. |
|
- | 845 | * This function handles generic/core properties and calls out to |
|
- | 846 | * driver's ->atomic_set_property() for driver properties. To ensure |
|
- | 847 | * consistent behavior you must call this function rather than the |
|
- | 848 | * driver hook directly. |
|
- | 849 | * |
|
- | 850 | * RETURNS: |
|
- | 851 | * Zero on success, error code on failure |
|
- | 852 | */ |
|
- | 853 | int drm_atomic_connector_set_property(struct drm_connector *connector, |
|
- | 854 | struct drm_connector_state *state, struct drm_property *property, |
|
- | 855 | uint64_t val) |
|
- | 856 | { |
|
- | 857 | struct drm_device *dev = connector->dev; |
|
- | 858 | struct drm_mode_config *config = &dev->mode_config; |
|
- | 859 | ||
- | 860 | if (property == config->prop_crtc_id) { |
|
- | 861 | struct drm_crtc *crtc = drm_crtc_find(dev, val); |
|
- | 862 | return drm_atomic_set_crtc_for_connector(state, crtc); |
|
- | 863 | } else if (property == config->dpms_property) { |
|
- | 864 | /* setting DPMS property requires special handling, which |
|
- | 865 | * is done in legacy setprop path for us. Disallow (for |
|
- | 866 | * now?) atomic writes to DPMS property: |
|
- | 867 | */ |
|
- | 868 | return -EINVAL; |
|
- | 869 | } else if (connector->funcs->atomic_set_property) { |
|
- | 870 | return connector->funcs->atomic_set_property(connector, |
|
- | 871 | state, property, val); |
|
- | 872 | } else { |
|
- | 873 | return -EINVAL; |
|
- | 874 | } |
|
- | 875 | } |
|
- | 876 | EXPORT_SYMBOL(drm_atomic_connector_set_property); |
|
- | 877 | ||
- | 878 | /* |
|
- | 879 | * This function handles generic/core properties and calls out to |
|
- | 880 | * driver's ->atomic_get_property() for driver properties. To ensure |
|
- | 881 | * consistent behavior you must call this function rather than the |
|
- | 882 | * driver hook directly. |
|
- | 883 | */ |
|
- | 884 | static int |
|
- | 885 | drm_atomic_connector_get_property(struct drm_connector *connector, |
|
- | 886 | const struct drm_connector_state *state, |
|
- | 887 | struct drm_property *property, uint64_t *val) |
|
- | 888 | { |
|
- | 889 | struct drm_device *dev = connector->dev; |
|
- | 890 | struct drm_mode_config *config = &dev->mode_config; |
|
- | 891 | ||
- | 892 | if (property == config->prop_crtc_id) { |
|
- | 893 | *val = (state->crtc) ? state->crtc->base.id : 0; |
|
- | 894 | } else if (property == config->dpms_property) { |
|
- | 895 | *val = connector->dpms; |
|
- | 896 | } else if (connector->funcs->atomic_get_property) { |
|
- | 897 | return connector->funcs->atomic_get_property(connector, |
|
- | 898 | state, property, val); |
|
- | 899 | } else { |
|
- | 900 | return -EINVAL; |
|
- | 901 | } |
|
- | 902 | ||
- | 903 | return 0; |
|
- | 904 | } |
|
- | 905 | ||
- | 906 | int drm_atomic_get_property(struct drm_mode_object *obj, |
|
- | 907 | struct drm_property *property, uint64_t *val) |
|
- | 908 | { |
|
- | 909 | struct drm_device *dev = property->dev; |
|
- | 910 | int ret; |
|
- | 911 | ||
- | 912 | switch (obj->type) { |
|
- | 913 | case DRM_MODE_OBJECT_CONNECTOR: { |
|
- | 914 | struct drm_connector *connector = obj_to_connector(obj); |
|
- | 915 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
|
- | 916 | ret = drm_atomic_connector_get_property(connector, |
|
- | 917 | connector->state, property, val); |
|
- | 918 | break; |
|
- | 919 | } |
|
- | 920 | case DRM_MODE_OBJECT_CRTC: { |
|
- | 921 | struct drm_crtc *crtc = obj_to_crtc(obj); |
|
- | 922 | WARN_ON(!drm_modeset_is_locked(&crtc->mutex)); |
|
- | 923 | ret = drm_atomic_crtc_get_property(crtc, |
|
- | 924 | crtc->state, property, val); |
|
- | 925 | break; |
|
- | 926 | } |
|
- | 927 | case DRM_MODE_OBJECT_PLANE: { |
|
- | 928 | struct drm_plane *plane = obj_to_plane(obj); |
|
- | 929 | WARN_ON(!drm_modeset_is_locked(&plane->mutex)); |
|
- | 930 | ret = drm_atomic_plane_get_property(plane, |
|
- | 931 | plane->state, property, val); |
|
- | 932 | break; |
|
- | 933 | } |
|
- | 934 | default: |
|
- | 935 | ret = -EINVAL; |
|
- | 936 | break; |
|
- | 937 | } |
|
- | 938 | ||
- | 939 | return ret; |
|
- | 940 | } |
|
- | 941 | ||
345 | /** |
942 | /** |
346 | * drm_atomic_set_crtc_for_plane - set crtc for plane |
- | |
347 | * @state: the incoming atomic state |
943 | * drm_atomic_set_crtc_for_plane - set crtc for plane |
348 | * @plane: the plane whose incoming state to update |
944 | * @plane_state: the plane whose incoming state to update |
349 | * @crtc: crtc to use for the plane |
945 | * @crtc: crtc to use for the plane |
350 | * |
946 | * |
351 | * Changing the assigned crtc for a plane requires us to grab the lock and state |
947 | * Changing the assigned crtc for a plane requires us to grab the lock and state |
352 | * for the new crtc, as needed. This function takes care of all these details |
948 | * for the new crtc, as needed. This function takes care of all these details |
Line 356... | Line 952... | ||
356 | * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK |
952 | * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK |
357 | * then the w/w mutex code has detected a deadlock and the entire atomic |
953 | * then the w/w mutex code has detected a deadlock and the entire atomic |
358 | * sequence must be restarted. All other errors are fatal. |
954 | * sequence must be restarted. All other errors are fatal. |
359 | */ |
955 | */ |
360 | int |
956 | int |
361 | drm_atomic_set_crtc_for_plane(struct drm_atomic_state *state, |
957 | drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state, |
362 | struct drm_plane *plane, struct drm_crtc *crtc) |
958 | struct drm_crtc *crtc) |
363 | { |
959 | { |
364 | struct drm_plane_state *plane_state = |
960 | struct drm_plane *plane = plane_state->plane; |
365 | drm_atomic_get_plane_state(state, plane); |
- | |
366 | struct drm_crtc_state *crtc_state; |
961 | struct drm_crtc_state *crtc_state; |
Line 367... | Line -... | ||
367 | - | ||
368 | if (WARN_ON(IS_ERR(plane_state))) |
- | |
369 | return PTR_ERR(plane_state); |
- | |
370 | 962 | ||
371 | if (plane_state->crtc) { |
963 | if (plane_state->crtc) { |
372 | crtc_state = drm_atomic_get_crtc_state(plane_state->state, |
964 | crtc_state = drm_atomic_get_crtc_state(plane_state->state, |
373 | plane_state->crtc); |
965 | plane_state->crtc); |
374 | if (WARN_ON(IS_ERR(crtc_state))) |
966 | if (WARN_ON(IS_ERR(crtc_state))) |
Line 386... | Line 978... | ||
386 | return PTR_ERR(crtc_state); |
978 | return PTR_ERR(crtc_state); |
387 | crtc_state->plane_mask |= (1 << drm_plane_index(plane)); |
979 | crtc_state->plane_mask |= (1 << drm_plane_index(plane)); |
388 | } |
980 | } |
Line 389... | Line 981... | ||
389 | 981 | ||
390 | if (crtc) |
982 | if (crtc) |
391 | DRM_DEBUG_KMS("Link plane state %p to [CRTC:%d]\n", |
983 | DRM_DEBUG_ATOMIC("Link plane state %p to [CRTC:%d]\n", |
392 | plane_state, crtc->base.id); |
984 | plane_state, crtc->base.id); |
393 | else |
985 | else |
- | 986 | DRM_DEBUG_ATOMIC("Link plane state %p to [NOCRTC]\n", |
|
Line 394... | Line 987... | ||
394 | DRM_DEBUG_KMS("Link plane state %p to [NOCRTC]\n", plane_state); |
987 | plane_state); |
395 | 988 | ||
396 | return 0; |
989 | return 0; |
Line 397... | Line 990... | ||
397 | } |
990 | } |
398 | EXPORT_SYMBOL(drm_atomic_set_crtc_for_plane); |
991 | EXPORT_SYMBOL(drm_atomic_set_crtc_for_plane); |
399 | 992 | ||
400 | /** |
993 | /** |
401 | * drm_atomic_set_fb_for_plane - set crtc for plane |
994 | * drm_atomic_set_fb_for_plane - set framebuffer for plane |
402 | * @plane_state: atomic state object for the plane |
995 | * @plane_state: atomic state object for the plane |
403 | * @fb: fb to use for the plane |
996 | * @fb: fb to use for the plane |
Line 416... | Line 1009... | ||
416 | if (fb) |
1009 | if (fb) |
417 | drm_framebuffer_reference(fb); |
1010 | drm_framebuffer_reference(fb); |
418 | plane_state->fb = fb; |
1011 | plane_state->fb = fb; |
Line 419... | Line 1012... | ||
419 | 1012 | ||
420 | if (fb) |
1013 | if (fb) |
421 | DRM_DEBUG_KMS("Set [FB:%d] for plane state %p\n", |
1014 | DRM_DEBUG_ATOMIC("Set [FB:%d] for plane state %p\n", |
422 | fb->base.id, plane_state); |
1015 | fb->base.id, plane_state); |
423 | else |
1016 | else |
- | 1017 | DRM_DEBUG_ATOMIC("Set [NOFB] for plane state %p\n", |
|
424 | DRM_DEBUG_KMS("Set [NOFB] for plane state %p\n", plane_state); |
1018 | plane_state); |
425 | } |
1019 | } |
Line 426... | Line 1020... | ||
426 | EXPORT_SYMBOL(drm_atomic_set_fb_for_plane); |
1020 | EXPORT_SYMBOL(drm_atomic_set_fb_for_plane); |
427 | 1021 | ||
Line 452... | Line 1046... | ||
452 | } |
1046 | } |
Line 453... | Line 1047... | ||
453 | 1047 | ||
Line 454... | Line 1048... | ||
454 | conn_state->crtc = crtc; |
1048 | conn_state->crtc = crtc; |
455 | 1049 | ||
456 | if (crtc) |
1050 | if (crtc) |
457 | DRM_DEBUG_KMS("Link connector state %p to [CRTC:%d]\n", |
1051 | DRM_DEBUG_ATOMIC("Link connector state %p to [CRTC:%d]\n", |
458 | conn_state, crtc->base.id); |
1052 | conn_state, crtc->base.id); |
459 | else |
1053 | else |
Line 460... | Line 1054... | ||
460 | DRM_DEBUG_KMS("Link connector state %p to [NOCRTC]\n", |
1054 | DRM_DEBUG_ATOMIC("Link connector state %p to [NOCRTC]\n", |
461 | conn_state); |
1055 | conn_state); |
462 | 1056 | ||
Line 492... | Line 1086... | ||
492 | 1086 | ||
493 | ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx); |
1087 | ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx); |
494 | if (ret) |
1088 | if (ret) |
Line 495... | Line 1089... | ||
495 | return ret; |
1089 | return ret; |
496 | 1090 | ||
Line 497... | Line 1091... | ||
497 | DRM_DEBUG_KMS("Adding all current connectors for [CRTC:%d] to %p\n", |
1091 | DRM_DEBUG_ATOMIC("Adding all current connectors for [CRTC:%d] to %p\n", |
498 | crtc->base.id, state); |
1092 | crtc->base.id, state); |
499 | 1093 | ||
500 | /* |
1094 | /* |
501 | * Changed connectors are already in @state, so only need to look at the |
1095 | * Changed connectors are already in @state, so only need to look at the |
502 | * current configuration. |
1096 | * current configuration. |
503 | */ |
1097 | */ |
Line 504... | Line 1098... | ||
504 | list_for_each_entry(connector, &config->connector_list, head) { |
1098 | drm_for_each_connector(connector, state->dev) { |
505 | if (connector->state->crtc != crtc) |
1099 | if (connector->state->crtc != crtc) |
Line 513... | Line 1107... | ||
513 | return 0; |
1107 | return 0; |
514 | } |
1108 | } |
515 | EXPORT_SYMBOL(drm_atomic_add_affected_connectors); |
1109 | EXPORT_SYMBOL(drm_atomic_add_affected_connectors); |
Line 516... | Line 1110... | ||
516 | 1110 | ||
- | 1111 | /** |
|
- | 1112 | * drm_atomic_add_affected_planes - add planes for crtc |
|
- | 1113 | * @state: atomic state |
|
- | 1114 | * @crtc: DRM crtc |
|
- | 1115 | * |
|
- | 1116 | * This function walks the current configuration and adds all planes |
|
- | 1117 | * currently used by @crtc to the atomic configuration @state. This is useful |
|
- | 1118 | * when an atomic commit also needs to check all currently enabled plane on |
|
- | 1119 | * @crtc, e.g. when changing the mode. It's also useful when re-enabling a CRTC |
|
- | 1120 | * to avoid special code to force-enable all planes. |
|
- | 1121 | * |
|
- | 1122 | * Since acquiring a plane state will always also acquire the w/w mutex of the |
|
- | 1123 | * current CRTC for that plane (if there is any) adding all the plane states for |
|
- | 1124 | * a CRTC will not reduce parallism of atomic updates. |
|
- | 1125 | * |
|
- | 1126 | * Returns: |
|
- | 1127 | * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK |
|
- | 1128 | * then the w/w mutex code has detected a deadlock and the entire atomic |
|
- | 1129 | * sequence must be restarted. All other errors are fatal. |
|
- | 1130 | */ |
|
- | 1131 | int |
|
- | 1132 | drm_atomic_add_affected_planes(struct drm_atomic_state *state, |
|
- | 1133 | struct drm_crtc *crtc) |
|
- | 1134 | { |
|
- | 1135 | struct drm_plane *plane; |
|
- | 1136 | ||
- | 1137 | WARN_ON(!drm_atomic_get_existing_crtc_state(state, crtc)); |
|
- | 1138 | ||
- | 1139 | drm_for_each_plane_mask(plane, state->dev, crtc->state->plane_mask) { |
|
- | 1140 | struct drm_plane_state *plane_state = |
|
- | 1141 | drm_atomic_get_plane_state(state, plane); |
|
- | 1142 | ||
- | 1143 | if (IS_ERR(plane_state)) |
|
- | 1144 | return PTR_ERR(plane_state); |
|
- | 1145 | } |
|
- | 1146 | return 0; |
|
- | 1147 | } |
|
- | 1148 | EXPORT_SYMBOL(drm_atomic_add_affected_planes); |
|
- | 1149 | ||
517 | /** |
1150 | /** |
518 | * drm_atomic_connectors_for_crtc - count number of connected outputs |
1151 | * drm_atomic_connectors_for_crtc - count number of connected outputs |
519 | * @state: atomic state |
1152 | * @state: atomic state |
520 | * @crtc: DRM crtc |
1153 | * @crtc: DRM crtc |
521 | * |
1154 | * |
Line 524... | Line 1157... | ||
524 | */ |
1157 | */ |
525 | int |
1158 | int |
526 | drm_atomic_connectors_for_crtc(struct drm_atomic_state *state, |
1159 | drm_atomic_connectors_for_crtc(struct drm_atomic_state *state, |
527 | struct drm_crtc *crtc) |
1160 | struct drm_crtc *crtc) |
528 | { |
1161 | { |
529 | int i, num_connected_connectors = 0; |
1162 | struct drm_connector *connector; |
530 | - | ||
531 | for (i = 0; i < state->num_connector; i++) { |
- | |
532 | struct drm_connector_state *conn_state; |
1163 | struct drm_connector_state *conn_state; |
Line 533... | Line 1164... | ||
533 | 1164 | ||
Line -... | Line 1165... | ||
- | 1165 | int i, num_connected_connectors = 0; |
|
534 | conn_state = state->connector_states[i]; |
1166 | |
535 | 1167 | for_each_connector_in_state(state, connector, conn_state, i) { |
|
536 | if (conn_state && conn_state->crtc == crtc) |
1168 | if (conn_state->crtc == crtc) |
Line 537... | Line 1169... | ||
537 | num_connected_connectors++; |
1169 | num_connected_connectors++; |
538 | } |
1170 | } |
Line 539... | Line 1171... | ||
539 | 1171 | ||
540 | DRM_DEBUG_KMS("State %p has %i connectors for [CRTC:%d]\n", |
1172 | DRM_DEBUG_ATOMIC("State %p has %i connectors for [CRTC:%d]\n", |
541 | state, num_connected_connectors, crtc->base.id); |
1173 | state, num_connected_connectors, crtc->base.id); |
Line 581... | Line 1213... | ||
581 | * Returns: |
1213 | * Returns: |
582 | * 0 on success, negative error code on failure. |
1214 | * 0 on success, negative error code on failure. |
583 | */ |
1215 | */ |
584 | int drm_atomic_check_only(struct drm_atomic_state *state) |
1216 | int drm_atomic_check_only(struct drm_atomic_state *state) |
585 | { |
1217 | { |
- | 1218 | struct drm_device *dev = state->dev; |
|
586 | struct drm_mode_config *config = &state->dev->mode_config; |
1219 | struct drm_mode_config *config = &dev->mode_config; |
- | 1220 | struct drm_plane *plane; |
|
- | 1221 | struct drm_plane_state *plane_state; |
|
- | 1222 | struct drm_crtc *crtc; |
|
- | 1223 | struct drm_crtc_state *crtc_state; |
|
- | 1224 | int i, ret = 0; |
|
- | 1225 | ||
- | 1226 | DRM_DEBUG_ATOMIC("checking %p\n", state); |
|
- | 1227 | ||
- | 1228 | for_each_plane_in_state(state, plane, plane_state, i) { |
|
- | 1229 | ret = drm_atomic_plane_check(plane, plane_state); |
|
- | 1230 | if (ret) { |
|
- | 1231 | DRM_DEBUG_ATOMIC("[PLANE:%d] atomic core check failed\n", |
|
- | 1232 | plane->base.id); |
|
- | 1233 | return ret; |
|
- | 1234 | } |
|
- | 1235 | } |
|
Line -... | Line 1236... | ||
- | 1236 | ||
587 | 1237 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
|
- | 1238 | ret = drm_atomic_crtc_check(crtc, crtc_state); |
|
- | 1239 | if (ret) { |
|
- | 1240 | DRM_DEBUG_ATOMIC("[CRTC:%d] atomic core check failed\n", |
|
- | 1241 | crtc->base.id); |
|
- | 1242 | return ret; |
|
- | 1243 | } |
|
Line 588... | Line 1244... | ||
588 | DRM_DEBUG_KMS("checking %p\n", state); |
1244 | } |
589 | 1245 | ||
- | 1246 | if (config->funcs->atomic_check) |
|
- | 1247 | ret = config->funcs->atomic_check(state->dev, state); |
|
- | 1248 | ||
- | 1249 | if (!state->allow_modeset) { |
|
- | 1250 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
|
- | 1251 | if (drm_atomic_crtc_needs_modeset(crtc_state)) { |
|
- | 1252 | DRM_DEBUG_ATOMIC("[CRTC:%d] requires full modeset\n", |
|
590 | if (config->funcs->atomic_check) |
1253 | crtc->base.id); |
- | 1254 | return -EINVAL; |
|
- | 1255 | } |
|
- | 1256 | } |
|
591 | return config->funcs->atomic_check(state->dev, state); |
1257 | } |
592 | else |
1258 | |
593 | return 0; |
1259 | return ret; |
Line 594... | Line 1260... | ||
594 | } |
1260 | } |
595 | EXPORT_SYMBOL(drm_atomic_check_only); |
1261 | EXPORT_SYMBOL(drm_atomic_check_only); |
Line 617... | Line 1283... | ||
617 | 1283 | ||
618 | ret = drm_atomic_check_only(state); |
1284 | ret = drm_atomic_check_only(state); |
619 | if (ret) |
1285 | if (ret) |
Line 620... | Line 1286... | ||
620 | return ret; |
1286 | return ret; |
Line 621... | Line 1287... | ||
621 | 1287 | ||
622 | DRM_DEBUG_KMS("commiting %p\n", state); |
1288 | DRM_DEBUG_ATOMIC("commiting %p\n", state); |
623 | 1289 | ||
Line 648... | Line 1314... | ||
648 | 1314 | ||
649 | ret = drm_atomic_check_only(state); |
1315 | ret = drm_atomic_check_only(state); |
650 | if (ret) |
1316 | if (ret) |
Line 651... | Line 1317... | ||
651 | return ret; |
1317 | return ret; |
Line 652... | Line 1318... | ||
652 | 1318 | ||
653 | DRM_DEBUG_KMS("commiting %p asynchronously\n", state); |
1319 | DRM_DEBUG_ATOMIC("commiting %p asynchronously\n", state); |
654 | 1320 | ||
Line 655... | Line 1321... | ||
655 | return config->funcs->atomic_commit(state->dev, state, true); |
1321 | return config->funcs->atomic_commit(state->dev, state, true); |
656 | } |
- | |
657 | EXPORT_SYMBOL(drm_atomic_async_commit); |
1322 | } |
658 | - | ||
659 | /** |
- | |
660 | * drm_atomic_helper_plane_duplicate_state - default state duplicate hook |
- | |
661 | * @plane: drm plane |
1323 | EXPORT_SYMBOL(drm_atomic_async_commit); |
- | 1324 | ||
662 | * |
1325 | /* |
663 | * Default plane state duplicate hook for drivers which don't have their own |
1326 | * The big monstor ioctl |
664 | * subclassed plane state structure. |
1327 | */ |
665 | */ |
1328 | |
- | 1329 | static struct drm_pending_vblank_event *create_vblank_event( |
|
Line -... | Line 1330... | ||
- | 1330 | struct drm_device *dev, struct drm_file *file_priv, uint64_t user_data) |
|
- | 1331 | { |
|
- | 1332 | struct drm_pending_vblank_event *e = NULL; |
|
- | 1333 | unsigned long flags; |
|
- | 1334 | ||
- | 1335 | spin_lock_irqsave(&dev->event_lock, flags); |
|
- | 1336 | if (file_priv->event_space < sizeof e->event) { |
|
- | 1337 | spin_unlock_irqrestore(&dev->event_lock, flags); |
|
666 | struct drm_plane_state * |
1338 | goto out; |
667 | drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane) |
1339 | } |
- | 1340 | file_priv->event_space -= sizeof e->event; |
|
- | 1341 | spin_unlock_irqrestore(&dev->event_lock, flags); |
|
- | 1342 | ||
- | 1343 | e = kzalloc(sizeof *e, GFP_KERNEL); |
|
- | 1344 | if (e == NULL) { |
|
- | 1345 | spin_lock_irqsave(&dev->event_lock, flags); |
|
- | 1346 | file_priv->event_space += sizeof e->event; |
|
- | 1347 | spin_unlock_irqrestore(&dev->event_lock, flags); |
|
- | 1348 | goto out; |
|
- | 1349 | } |
|
- | 1350 | ||
- | 1351 | e->event.base.type = DRM_EVENT_FLIP_COMPLETE; |
|
Line -... | Line 1352... | ||
- | 1352 | e->event.base.length = sizeof e->event; |
|
668 | { |
1353 | e->event.user_data = user_data; |
- | 1354 | e->base.event = &e->event.base; |
|
Line 669... | Line 1355... | ||
669 | struct drm_plane_state *state; |
1355 | e->base.file_priv = file_priv; |
670 | 1356 | e->base.destroy = (void (*) (struct drm_pending_event *)) kfree; |
|
- | 1357 | ||
- | 1358 | out: |
|
Line -... | Line 1359... | ||
- | 1359 | return e; |
|
- | 1360 | } |
|
- | 1361 | ||
671 | if (WARN_ON(!plane->state)) |
1362 | static void destroy_vblank_event(struct drm_device *dev, |
672 | return NULL; |
1363 | struct drm_file *file_priv, struct drm_pending_vblank_event *e) |
673 | - | ||
674 | state = kmemdup(plane->state, sizeof(*plane->state), GFP_KERNEL); |
- | |
Line 675... | Line -... | ||
675 | - | ||
676 | if (state && state->fb) |
1364 | { |
677 | drm_framebuffer_reference(state->fb); |
- | |
678 | - | ||
679 | return state; |
- | |
680 | } |
- | |
681 | EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state); |
- | |
682 | - | ||
683 | 1365 | unsigned long flags; |
|
684 | /** |
1366 | |
685 | * drm_atomic_helper_crtc_destroy_state - default state destroy hook |
1367 | spin_lock_irqsave(&dev->event_lock, flags); |
- | 1368 | file_priv->event_space += sizeof e->event; |
|
- | 1369 | spin_unlock_irqrestore(&dev->event_lock, flags); |
|
- | 1370 | kfree(e); |
|
- | 1371 | } |
|
- | 1372 | ||
- | 1373 | static int atomic_set_prop(struct drm_atomic_state *state, |
|
- | 1374 | struct drm_mode_object *obj, struct drm_property *prop, |
|
- | 1375 | uint64_t prop_value) |
|
- | 1376 | { |
|
- | 1377 | struct drm_mode_object *ref; |
|
- | 1378 | int ret; |
|
- | 1379 | ||
- | 1380 | if (!drm_property_change_valid_get(prop, prop_value, &ref)) |
|
- | 1381 | return -EINVAL; |
|
- | 1382 | ||
- | 1383 | switch (obj->type) { |
|
- | 1384 | case DRM_MODE_OBJECT_CONNECTOR: { |
|
- | 1385 | struct drm_connector *connector = obj_to_connector(obj); |
|
- | 1386 | struct drm_connector_state *connector_state; |
|
- | 1387 | ||
- | 1388 | connector_state = drm_atomic_get_connector_state(state, connector); |
|
- | 1389 | if (IS_ERR(connector_state)) { |
|
- | 1390 | ret = PTR_ERR(connector_state); |
|
- | 1391 | break; |
|
- | 1392 | } |
|
- | 1393 | ||
- | 1394 | ret = drm_atomic_connector_set_property(connector, |
|
686 | * @crtc: drm CRTC |
1395 | connector_state, prop, prop_value); |
- | 1396 | break; |
|
- | 1397 | } |
|
- | 1398 | case DRM_MODE_OBJECT_CRTC: { |
|
- | 1399 | struct drm_crtc *crtc = obj_to_crtc(obj); |
|
- | 1400 | struct drm_crtc_state *crtc_state; |
|
- | 1401 | ||
- | 1402 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
|
- | 1403 | if (IS_ERR(crtc_state)) { |
|
- | 1404 | ret = PTR_ERR(crtc_state); |
|
- | 1405 | break; |
|
- | 1406 | } |
|
- | 1407 | ||
- | 1408 | ret = drm_atomic_crtc_set_property(crtc, |
|
- | 1409 | crtc_state, prop, prop_value); |
|
- | 1410 | break; |
|
- | 1411 | } |
|
- | 1412 | case DRM_MODE_OBJECT_PLANE: { |
|
- | 1413 | struct drm_plane *plane = obj_to_plane(obj); |
|
- | 1414 | struct drm_plane_state *plane_state; |
|
- | 1415 | ||
- | 1416 | plane_state = drm_atomic_get_plane_state(state, plane); |
|
- | 1417 | if (IS_ERR(plane_state)) { |
|
- | 1418 | ret = PTR_ERR(plane_state); |
|
- | 1419 | break; |
|
- | 1420 | } |
|
- | 1421 | ||
- | 1422 | ret = drm_atomic_plane_set_property(plane, |
|
- | 1423 | plane_state, prop, prop_value); |
|
687 | * @state: CRTC state object to release |
1424 | break; |
688 | * |
- | |
Line 689... | Line 1425... | ||
689 | * Default CRTC state destroy hook for drivers which don't have their own |
1425 | } |
690 | * subclassed CRTC state structure. |
1426 | default: |
691 | */ |
- | |
692 | void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc, |
- | |
693 | struct drm_crtc_state *state) |
1427 | ret = -EINVAL; |
- | 1428 | break; |
|
694 | { |
1429 | } |
695 | kfree(state); |
1430 | |
- | 1431 | drm_property_change_valid_put(prop, ref); |
|
- | 1432 | return ret; |
|
- | 1433 | } |
|
- | 1434 | ||
- | 1435 | /** |
|
696 | } |
1436 | * drm_atomic_update_old_fb -- Unset old_fb pointers and set plane->fb pointers. |
697 | EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state); |
1437 | * |
698 | 1438 | * @dev: drm device to check. |
|
- | 1439 | * @plane_mask: plane mask for planes that were updated. |
|
699 | /** |
1440 | * @ret: return value, can be -EDEADLK for a retry. |
700 | * drm_atomic_helper_plane_destroy_state - default state destroy hook |
1441 | * |
701 | * @plane: drm plane |
- | |
Line -... | Line 1442... | ||
- | 1442 | * Before doing an update plane->old_fb is set to plane->fb, |
|
- | 1443 | * but before dropping the locks old_fb needs to be set to NULL |
|
- | 1444 | * and plane->fb updated. This is a common operation for each |
|
- | 1445 | * atomic update, so this call is split off as a helper. |
|
- | 1446 | */ |
|
- | 1447 | void drm_atomic_clean_old_fb(struct drm_device *dev, |
|
702 | * @state: plane state object to release |
1448 | unsigned plane_mask, |
- | 1449 | int ret) |
|
- | 1450 | { |
|
- | 1451 | struct drm_plane *plane; |
|
- | 1452 | ||
- | 1453 | /* if succeeded, fixup legacy plane crtc/fb ptrs before dropping |
|
- | 1454 | * locks (ie. while it is still safe to deref plane->state). We |
|
- | 1455 | * need to do this here because the driver entry points cannot |
|
- | 1456 | * distinguish between legacy and atomic ioctls. |
|
- | 1457 | */ |
|
- | 1458 | drm_for_each_plane_mask(plane, dev, plane_mask) { |
|
- | 1459 | if (ret == 0) { |
|
703 | * |
1460 | struct drm_framebuffer *new_fb = plane->state->fb; |
704 | * Default plane state destroy hook for drivers which don't have their own |
1461 | if (new_fb) |