aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnder Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>2015-03-20 10:18:03 -0400
committerDaniel Vetter <daniel.vetter@ffwll.ch>2015-03-26 11:15:34 -0400
commit83a57153f5de299c7672d0cb241289c349b784d4 (patch)
tree876fe5a7ae0d8c84c9880b030b2cc4530b01ad19
parent49172fee6173d213cf711bfad751e1b38e8fdaaf (diff)
drm/i915: Allocate a drm_atomic_state for the legacy modeset code
For the atomic conversion, the mode set paths need to be changed to rely on an atomic state instead of using the staged config. By using an atomic state for the legacy code, we will be able to convert the code base in small chunks. v2: Squash patch that adds stat argument to intel_set_mode(). (Ander) Make every caller of intel_set_mode() allocate state. (Daniel) Call drm_atomic_state_clear() in set config's error path. (Daniel) v3: Copy staged config to atomic state in force restore path. (Ander) v4: Don't update ->new_config for disabled pipes in __intel_set_mode(), since it is expected to be NULL in that case. (Ander) v5: Don't change return type of intel_modeset_pipe_config(). (Chandra) Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com> [danvet: Remove spurious ret local variable due to changes in v5.] Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
-rw-r--r--drivers/gpu/drm/i915/intel_display.c185
1 files changed, 155 insertions, 30 deletions
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index bbd09aaa055d..66cf0996b881 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -83,7 +83,8 @@ static void ironlake_pch_clock_get(struct intel_crtc *crtc,
83 struct intel_crtc_state *pipe_config); 83 struct intel_crtc_state *pipe_config);
84 84
85static int intel_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode, 85static int intel_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
86 int x, int y, struct drm_framebuffer *old_fb); 86 int x, int y, struct drm_framebuffer *old_fb,
87 struct drm_atomic_state *state);
87static int intel_framebuffer_init(struct drm_device *dev, 88static int intel_framebuffer_init(struct drm_device *dev,
88 struct intel_framebuffer *ifb, 89 struct intel_framebuffer *ifb,
89 struct drm_mode_fb_cmd2 *mode_cmd, 90 struct drm_mode_fb_cmd2 *mode_cmd,
@@ -8907,6 +8908,7 @@ bool intel_get_load_detect_pipe(struct drm_connector *connector,
8907 struct drm_device *dev = encoder->dev; 8908 struct drm_device *dev = encoder->dev;
8908 struct drm_framebuffer *fb; 8909 struct drm_framebuffer *fb;
8909 struct drm_mode_config *config = &dev->mode_config; 8910 struct drm_mode_config *config = &dev->mode_config;
8911 struct drm_atomic_state *state = NULL;
8910 int ret, i = -1; 8912 int ret, i = -1;
8911 8913
8912 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", 8914 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
@@ -8988,6 +8990,12 @@ retry:
8988 old->load_detect_temp = true; 8990 old->load_detect_temp = true;
8989 old->release_fb = NULL; 8991 old->release_fb = NULL;
8990 8992
8993 state = drm_atomic_state_alloc(dev);
8994 if (!state)
8995 return false;
8996
8997 state->acquire_ctx = ctx;
8998
8991 if (!mode) 8999 if (!mode)
8992 mode = &load_detect_mode; 9000 mode = &load_detect_mode;
8993 9001
@@ -9010,7 +9018,7 @@ retry:
9010 goto fail; 9018 goto fail;
9011 } 9019 }
9012 9020
9013 if (intel_set_mode(crtc, mode, 0, 0, fb)) { 9021 if (intel_set_mode(crtc, mode, 0, 0, fb, state)) {
9014 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); 9022 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
9015 if (old->release_fb) 9023 if (old->release_fb)
9016 old->release_fb->funcs->destroy(old->release_fb); 9024 old->release_fb->funcs->destroy(old->release_fb);
@@ -9029,6 +9037,11 @@ retry:
9029 else 9037 else
9030 intel_crtc->new_config = NULL; 9038 intel_crtc->new_config = NULL;
9031fail_unlock: 9039fail_unlock:
9040 if (state) {
9041 drm_atomic_state_free(state);
9042 state = NULL;
9043 }
9044
9032 if (ret == -EDEADLK) { 9045 if (ret == -EDEADLK) {
9033 drm_modeset_backoff(ctx); 9046 drm_modeset_backoff(ctx);
9034 goto retry; 9047 goto retry;
@@ -9041,22 +9054,34 @@ void intel_release_load_detect_pipe(struct drm_connector *connector,
9041 struct intel_load_detect_pipe *old, 9054 struct intel_load_detect_pipe *old,
9042 struct drm_modeset_acquire_ctx *ctx) 9055 struct drm_modeset_acquire_ctx *ctx)
9043{ 9056{
9057 struct drm_device *dev = connector->dev;
9044 struct intel_encoder *intel_encoder = 9058 struct intel_encoder *intel_encoder =
9045 intel_attached_encoder(connector); 9059 intel_attached_encoder(connector);
9046 struct drm_encoder *encoder = &intel_encoder->base; 9060 struct drm_encoder *encoder = &intel_encoder->base;
9047 struct drm_crtc *crtc = encoder->crtc; 9061 struct drm_crtc *crtc = encoder->crtc;
9048 struct intel_crtc *intel_crtc = to_intel_crtc(crtc); 9062 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
9063 struct drm_atomic_state *state;
9049 9064
9050 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", 9065 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
9051 connector->base.id, connector->name, 9066 connector->base.id, connector->name,
9052 encoder->base.id, encoder->name); 9067 encoder->base.id, encoder->name);
9053 9068
9054 if (old->load_detect_temp) { 9069 if (old->load_detect_temp) {
9070 state = drm_atomic_state_alloc(dev);
9071 if (!state) {
9072 DRM_DEBUG_KMS("can't release load detect pipe\n");
9073 return;
9074 }
9075
9076 state->acquire_ctx = ctx;
9077
9055 to_intel_connector(connector)->new_encoder = NULL; 9078 to_intel_connector(connector)->new_encoder = NULL;
9056 intel_encoder->new_crtc = NULL; 9079 intel_encoder->new_crtc = NULL;
9057 intel_crtc->new_enabled = false; 9080 intel_crtc->new_enabled = false;
9058 intel_crtc->new_config = NULL; 9081 intel_crtc->new_config = NULL;
9059 intel_set_mode(crtc, NULL, 0, 0, NULL); 9082 intel_set_mode(crtc, NULL, 0, 0, NULL, state);
9083
9084 drm_atomic_state_free(state);
9060 9085
9061 if (old->release_fb) { 9086 if (old->release_fb) {
9062 drm_framebuffer_unregister_private(old->release_fb); 9087 drm_framebuffer_unregister_private(old->release_fb);
@@ -10449,10 +10474,22 @@ static bool check_digital_port_conflicts(struct drm_device *dev)
10449 return true; 10474 return true;
10450} 10475}
10451 10476
10477static void
10478clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
10479{
10480 struct drm_crtc_state tmp_state;
10481
10482 /* Clear only the intel specific part of the crtc state */
10483 tmp_state = crtc_state->base;
10484 memset(crtc_state, 0, sizeof *crtc_state);
10485 crtc_state->base = tmp_state;
10486}
10487
10452static struct intel_crtc_state * 10488static struct intel_crtc_state *
10453intel_modeset_pipe_config(struct drm_crtc *crtc, 10489intel_modeset_pipe_config(struct drm_crtc *crtc,
10454 struct drm_framebuffer *fb, 10490 struct drm_framebuffer *fb,
10455 struct drm_display_mode *mode) 10491 struct drm_display_mode *mode,
10492 struct drm_atomic_state *state)
10456{ 10493{
10457 struct drm_device *dev = crtc->dev; 10494 struct drm_device *dev = crtc->dev;
10458 struct intel_encoder *encoder; 10495 struct intel_encoder *encoder;
@@ -10470,9 +10507,11 @@ intel_modeset_pipe_config(struct drm_crtc *crtc,
10470 return ERR_PTR(-EINVAL); 10507 return ERR_PTR(-EINVAL);
10471 } 10508 }
10472 10509
10473 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); 10510 pipe_config = intel_atomic_get_crtc_state(state, to_intel_crtc(crtc));
10474 if (!pipe_config) 10511 if (IS_ERR(pipe_config))
10475 return ERR_PTR(-ENOMEM); 10512 return pipe_config;
10513
10514 clear_intel_crtc_state(pipe_config);
10476 10515
10477 pipe_config->base.crtc = crtc; 10516 pipe_config->base.crtc = crtc;
10478 drm_mode_copy(&pipe_config->base.adjusted_mode, mode); 10517 drm_mode_copy(&pipe_config->base.adjusted_mode, mode);
@@ -10569,7 +10608,6 @@ encoder_retry:
10569 10608
10570 return pipe_config; 10609 return pipe_config;
10571fail: 10610fail:
10572 kfree(pipe_config);
10573 return ERR_PTR(ret); 10611 return ERR_PTR(ret);
10574} 10612}
10575 10613
@@ -11248,6 +11286,7 @@ static struct intel_crtc_state *
11248intel_modeset_compute_config(struct drm_crtc *crtc, 11286intel_modeset_compute_config(struct drm_crtc *crtc,
11249 struct drm_display_mode *mode, 11287 struct drm_display_mode *mode,
11250 struct drm_framebuffer *fb, 11288 struct drm_framebuffer *fb,
11289 struct drm_atomic_state *state,
11251 unsigned *modeset_pipes, 11290 unsigned *modeset_pipes,
11252 unsigned *prepare_pipes, 11291 unsigned *prepare_pipes,
11253 unsigned *disable_pipes) 11292 unsigned *disable_pipes)
@@ -11258,7 +11297,7 @@ intel_modeset_compute_config(struct drm_crtc *crtc,
11258 prepare_pipes, disable_pipes); 11297 prepare_pipes, disable_pipes);
11259 11298
11260 if ((*modeset_pipes) == 0) 11299 if ((*modeset_pipes) == 0)
11261 goto out; 11300 return NULL;
11262 11301
11263 /* 11302 /*
11264 * Note this needs changes when we start tracking multiple modes 11303 * Note this needs changes when we start tracking multiple modes
@@ -11266,14 +11305,13 @@ intel_modeset_compute_config(struct drm_crtc *crtc,
11266 * (i.e. one pipe_config for each crtc) rather than just the one 11305 * (i.e. one pipe_config for each crtc) rather than just the one
11267 * for this crtc. 11306 * for this crtc.
11268 */ 11307 */
11269 pipe_config = intel_modeset_pipe_config(crtc, fb, mode); 11308 pipe_config = intel_modeset_pipe_config(crtc, fb, mode, state);
11270 if (IS_ERR(pipe_config)) { 11309 if (IS_ERR(pipe_config))
11271 goto out; 11310 return pipe_config;
11272 } 11311
11273 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, 11312 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
11274 "[modeset]"); 11313 "[modeset]");
11275 11314
11276out:
11277 return pipe_config; 11315 return pipe_config;
11278} 11316}
11279 11317
@@ -11318,6 +11356,7 @@ static int __intel_set_mode(struct drm_crtc *crtc,
11318 struct drm_device *dev = crtc->dev; 11356 struct drm_device *dev = crtc->dev;
11319 struct drm_i915_private *dev_priv = dev->dev_private; 11357 struct drm_i915_private *dev_priv = dev->dev_private;
11320 struct drm_display_mode *saved_mode; 11358 struct drm_display_mode *saved_mode;
11359 struct intel_crtc_state *crtc_state_copy = NULL;
11321 struct intel_crtc *intel_crtc; 11360 struct intel_crtc *intel_crtc;
11322 int ret = 0; 11361 int ret = 0;
11323 11362
@@ -11325,6 +11364,12 @@ static int __intel_set_mode(struct drm_crtc *crtc,
11325 if (!saved_mode) 11364 if (!saved_mode)
11326 return -ENOMEM; 11365 return -ENOMEM;
11327 11366
11367 crtc_state_copy = kmalloc(sizeof(*crtc_state_copy), GFP_KERNEL);
11368 if (!crtc_state_copy) {
11369 ret = -ENOMEM;
11370 goto done;
11371 }
11372
11328 *saved_mode = crtc->mode; 11373 *saved_mode = crtc->mode;
11329 11374
11330 if (modeset_pipes) 11375 if (modeset_pipes)
@@ -11411,6 +11456,22 @@ done:
11411 if (ret && crtc->state->enable) 11456 if (ret && crtc->state->enable)
11412 crtc->mode = *saved_mode; 11457 crtc->mode = *saved_mode;
11413 11458
11459 if (ret == 0 && pipe_config) {
11460 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11461
11462 /* The pipe_config will be freed with the atomic state, so
11463 * make a copy. */
11464 memcpy(crtc_state_copy, intel_crtc->config,
11465 sizeof *crtc_state_copy);
11466 intel_crtc->config = crtc_state_copy;
11467 intel_crtc->base.state = &crtc_state_copy->base;
11468
11469 if (modeset_pipes)
11470 intel_crtc->new_config = intel_crtc->config;
11471 } else {
11472 kfree(crtc_state_copy);
11473 }
11474
11414 kfree(saved_mode); 11475 kfree(saved_mode);
11415 return ret; 11476 return ret;
11416} 11477}
@@ -11436,27 +11497,81 @@ static int intel_set_mode_pipes(struct drm_crtc *crtc,
11436 11497
11437static int intel_set_mode(struct drm_crtc *crtc, 11498static int intel_set_mode(struct drm_crtc *crtc,
11438 struct drm_display_mode *mode, 11499 struct drm_display_mode *mode,
11439 int x, int y, struct drm_framebuffer *fb) 11500 int x, int y, struct drm_framebuffer *fb,
11501 struct drm_atomic_state *state)
11440{ 11502{
11441 struct intel_crtc_state *pipe_config; 11503 struct intel_crtc_state *pipe_config;
11442 unsigned modeset_pipes, prepare_pipes, disable_pipes; 11504 unsigned modeset_pipes, prepare_pipes, disable_pipes;
11505 int ret = 0;
11443 11506
11444 pipe_config = intel_modeset_compute_config(crtc, mode, fb, 11507 pipe_config = intel_modeset_compute_config(crtc, mode, fb, state,
11445 &modeset_pipes, 11508 &modeset_pipes,
11446 &prepare_pipes, 11509 &prepare_pipes,
11447 &disable_pipes); 11510 &disable_pipes);
11448 11511
11449 if (IS_ERR(pipe_config)) 11512 if (IS_ERR(pipe_config)) {
11450 return PTR_ERR(pipe_config); 11513 ret = PTR_ERR(pipe_config);
11514 goto out;
11515 }
11516
11517 ret = intel_set_mode_pipes(crtc, mode, x, y, fb, pipe_config,
11518 modeset_pipes, prepare_pipes,
11519 disable_pipes);
11520 if (ret)
11521 goto out;
11451 11522
11452 return intel_set_mode_pipes(crtc, mode, x, y, fb, pipe_config, 11523out:
11453 modeset_pipes, prepare_pipes, 11524 return ret;
11454 disable_pipes);
11455} 11525}
11456 11526
11457void intel_crtc_restore_mode(struct drm_crtc *crtc) 11527void intel_crtc_restore_mode(struct drm_crtc *crtc)
11458{ 11528{
11459 intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->primary->fb); 11529 struct drm_device *dev = crtc->dev;
11530 struct drm_atomic_state *state;
11531 struct intel_encoder *encoder;
11532 struct intel_connector *connector;
11533 struct drm_connector_state *connector_state;
11534
11535 state = drm_atomic_state_alloc(dev);
11536 if (!state) {
11537 DRM_DEBUG_KMS("[CRTC:%d] mode restore failed, out of memory",
11538 crtc->base.id);
11539 return;
11540 }
11541
11542 state->acquire_ctx = dev->mode_config.acquire_ctx;
11543
11544 /* The force restore path in the HW readout code relies on the staged
11545 * config still keeping the user requested config while the actual
11546 * state has been overwritten by the configuration read from HW. We
11547 * need to copy the staged config to the atomic state, otherwise the
11548 * mode set will just reapply the state the HW is already in. */
11549 for_each_intel_encoder(dev, encoder) {
11550 if (&encoder->new_crtc->base != crtc)
11551 continue;
11552
11553 for_each_intel_connector(dev, connector) {
11554 if (connector->new_encoder != encoder)
11555 continue;
11556
11557 connector_state = drm_atomic_get_connector_state(state, &connector->base);
11558 if (IS_ERR(connector_state)) {
11559 DRM_DEBUG_KMS("Failed to add [CONNECTOR:%d:%s] to state: %ld\n",
11560 connector->base.base.id,
11561 connector->base.name,
11562 PTR_ERR(connector_state));
11563 continue;
11564 }
11565
11566 connector_state->crtc = crtc;
11567 connector_state->best_encoder = &encoder->base;
11568 }
11569 }
11570
11571 intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->primary->fb,
11572 state);
11573
11574 drm_atomic_state_free(state);
11460} 11575}
11461 11576
11462#undef for_each_intel_crtc_masked 11577#undef for_each_intel_crtc_masked
@@ -11781,6 +11896,7 @@ static int intel_crtc_set_config(struct drm_mode_set *set)
11781{ 11896{
11782 struct drm_device *dev; 11897 struct drm_device *dev;
11783 struct drm_mode_set save_set; 11898 struct drm_mode_set save_set;
11899 struct drm_atomic_state *state = NULL;
11784 struct intel_set_config *config; 11900 struct intel_set_config *config;
11785 struct intel_crtc_state *pipe_config; 11901 struct intel_crtc_state *pipe_config;
11786 unsigned modeset_pipes, prepare_pipes, disable_pipes; 11902 unsigned modeset_pipes, prepare_pipes, disable_pipes;
@@ -11825,12 +11941,20 @@ static int intel_crtc_set_config(struct drm_mode_set *set)
11825 * such cases. */ 11941 * such cases. */
11826 intel_set_config_compute_mode_changes(set, config); 11942 intel_set_config_compute_mode_changes(set, config);
11827 11943
11944 state = drm_atomic_state_alloc(dev);
11945 if (!state) {
11946 ret = -ENOMEM;
11947 goto out_config;
11948 }
11949
11950 state->acquire_ctx = dev->mode_config.acquire_ctx;
11951
11828 ret = intel_modeset_stage_output_state(dev, set, config); 11952 ret = intel_modeset_stage_output_state(dev, set, config);
11829 if (ret) 11953 if (ret)
11830 goto fail; 11954 goto fail;
11831 11955
11832 pipe_config = intel_modeset_compute_config(set->crtc, set->mode, 11956 pipe_config = intel_modeset_compute_config(set->crtc, set->mode,
11833 set->fb, 11957 set->fb, state,
11834 &modeset_pipes, 11958 &modeset_pipes,
11835 &prepare_pipes, 11959 &prepare_pipes,
11836 &disable_pipes); 11960 &disable_pipes);
@@ -11850,10 +11974,6 @@ static int intel_crtc_set_config(struct drm_mode_set *set)
11850 */ 11974 */
11851 } 11975 }
11852 11976
11853 /* set_mode will free it in the mode_changed case */
11854 if (!config->mode_changed)
11855 kfree(pipe_config);
11856
11857 intel_update_pipe_size(to_intel_crtc(set->crtc)); 11977 intel_update_pipe_size(to_intel_crtc(set->crtc));
11858 11978
11859 if (config->mode_changed) { 11979 if (config->mode_changed) {
@@ -11899,6 +12019,8 @@ static int intel_crtc_set_config(struct drm_mode_set *set)
11899fail: 12019fail:
11900 intel_set_config_restore_state(dev, config); 12020 intel_set_config_restore_state(dev, config);
11901 12021
12022 drm_atomic_state_clear(state);
12023
11902 /* 12024 /*
11903 * HACK: if the pipe was on, but we didn't have a framebuffer, 12025 * HACK: if the pipe was on, but we didn't have a framebuffer,
11904 * force the pipe off to avoid oopsing in the modeset code 12026 * force the pipe off to avoid oopsing in the modeset code
@@ -11911,11 +12033,15 @@ fail:
11911 /* Try to restore the config */ 12033 /* Try to restore the config */
11912 if (config->mode_changed && 12034 if (config->mode_changed &&
11913 intel_set_mode(save_set.crtc, save_set.mode, 12035 intel_set_mode(save_set.crtc, save_set.mode,
11914 save_set.x, save_set.y, save_set.fb)) 12036 save_set.x, save_set.y, save_set.fb,
12037 state))
11915 DRM_ERROR("failed to restore config after modeset failure\n"); 12038 DRM_ERROR("failed to restore config after modeset failure\n");
11916 } 12039 }
11917 12040
11918out_config: 12041out_config:
12042 if (state)
12043 drm_atomic_state_free(state);
12044
11919 intel_set_config_free(config); 12045 intel_set_config_free(config);
11920 return ret; 12046 return ret;
11921} 12047}
@@ -13968,8 +14094,7 @@ void intel_modeset_setup_hw_state(struct drm_device *dev,
13968 struct drm_crtc *crtc = 14094 struct drm_crtc *crtc =
13969 dev_priv->pipe_to_crtc_mapping[pipe]; 14095 dev_priv->pipe_to_crtc_mapping[pipe];
13970 14096
13971 intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, 14097 intel_crtc_restore_mode(crtc);
13972 crtc->primary->fb);
13973 } 14098 }
13974 } else { 14099 } else {
13975 intel_modeset_update_staged_output_state(dev); 14100 intel_modeset_update_staged_output_state(dev);