Commit e67aae79 authored by Maarten Maathuis's avatar Maarten Maathuis Committed by Dave Airlie

drm/crtc_helper: replace modeset fail path with something simpler

- The previous system was not very transparent, nor flexible.
- This is needed to be able to fix a few bugs in the mechanism.
Signed-off-by: default avatarMaarten Maathuis <madman2003@gmail.com>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent 689d7c2a
...@@ -704,13 +704,12 @@ EXPORT_SYMBOL(drm_crtc_helper_set_mode); ...@@ -704,13 +704,12 @@ EXPORT_SYMBOL(drm_crtc_helper_set_mode);
int drm_crtc_helper_set_config(struct drm_mode_set *set) int drm_crtc_helper_set_config(struct drm_mode_set *set)
{ {
struct drm_device *dev; struct drm_device *dev;
struct drm_crtc **save_crtcs, *new_crtc; struct drm_crtc *save_crtcs, *new_crtc, *crtc;
struct drm_encoder **save_encoders, *new_encoder; struct drm_encoder *save_encoders, *new_encoder, *encoder;
struct drm_framebuffer *old_fb = NULL; struct drm_framebuffer *old_fb = NULL;
bool save_enabled;
bool mode_changed = false; /* if true do a full mode set */ bool mode_changed = false; /* if true do a full mode set */
bool fb_changed = false; /* if true and !mode_changed just do a flip */ bool fb_changed = false; /* if true and !mode_changed just do a flip */
struct drm_connector *connector; struct drm_connector *save_connectors, *connector;
int count = 0, ro, fail = 0; int count = 0, ro, fail = 0;
struct drm_crtc_helper_funcs *crtc_funcs; struct drm_crtc_helper_funcs *crtc_funcs;
int ret = 0; int ret = 0;
...@@ -735,25 +734,47 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set) ...@@ -735,25 +734,47 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
dev = set->crtc->dev; dev = set->crtc->dev;
/* save previous config */ /* Allocate space for the backup of all (non-pointer) crtc, encoder and
save_enabled = set->crtc->enabled; * connector data. */
save_crtcs = kzalloc(dev->mode_config.num_crtc *
/* sizeof(struct drm_crtc), GFP_KERNEL);
* We do mode_config.num_connectors here since we'll look at the
* CRTC and encoder associated with each connector later.
*/
save_crtcs = kzalloc(dev->mode_config.num_connector *
sizeof(struct drm_crtc *), GFP_KERNEL);
if (!save_crtcs) if (!save_crtcs)
return -ENOMEM; return -ENOMEM;
save_encoders = kzalloc(dev->mode_config.num_connector * save_encoders = kzalloc(dev->mode_config.num_encoder *
sizeof(struct drm_encoders *), GFP_KERNEL); sizeof(struct drm_encoder), GFP_KERNEL);
if (!save_encoders) { if (!save_encoders) {
kfree(save_crtcs); kfree(save_crtcs);
return -ENOMEM; return -ENOMEM;
} }
save_connectors = kzalloc(dev->mode_config.num_connector *
sizeof(struct drm_connector), GFP_KERNEL);
if (!save_connectors) {
kfree(save_crtcs);
kfree(save_encoders);
return -ENOMEM;
}
/* Copy data. Note that driver private data is not affected.
* Should anything bad happen only the expected state is
* restored, not the drivers personal bookkeeping.
*/
count = 0;
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
save_crtcs[count++] = *crtc;
}
count = 0;
list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
save_encoders[count++] = *encoder;
}
count = 0;
list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
save_connectors[count++] = *connector;
}
/* We should be able to check here if the fb has the same properties /* We should be able to check here if the fb has the same properties
* and then just flip_or_move it */ * and then just flip_or_move it */
if (set->crtc->fb != set->fb) { if (set->crtc->fb != set->fb) {
...@@ -786,7 +807,6 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set) ...@@ -786,7 +807,6 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
list_for_each_entry(connector, &dev->mode_config.connector_list, head) { list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
struct drm_connector_helper_funcs *connector_funcs = struct drm_connector_helper_funcs *connector_funcs =
connector->helper_private; connector->helper_private;
save_encoders[count++] = connector->encoder;
new_encoder = connector->encoder; new_encoder = connector->encoder;
for (ro = 0; ro < set->num_connectors; ro++) { for (ro = 0; ro < set->num_connectors; ro++) {
if (set->connectors[ro] == connector) { if (set->connectors[ro] == connector) {
...@@ -809,7 +829,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set) ...@@ -809,7 +829,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
if (fail) { if (fail) {
ret = -EINVAL; ret = -EINVAL;
goto fail_no_encoder; goto fail;
} }
count = 0; count = 0;
...@@ -817,8 +837,6 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set) ...@@ -817,8 +837,6 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
if (!connector->encoder) if (!connector->encoder)
continue; continue;
save_crtcs[count++] = connector->encoder->crtc;
if (connector->encoder->crtc == set->crtc) if (connector->encoder->crtc == set->crtc)
new_crtc = NULL; new_crtc = NULL;
else else
...@@ -833,7 +851,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set) ...@@ -833,7 +851,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
if (new_crtc && if (new_crtc &&
!drm_encoder_crtc_ok(connector->encoder, new_crtc)) { !drm_encoder_crtc_ok(connector->encoder, new_crtc)) {
ret = -EINVAL; ret = -EINVAL;
goto fail_set_mode; goto fail;
} }
if (new_crtc != connector->encoder->crtc) { if (new_crtc != connector->encoder->crtc) {
DRM_DEBUG_KMS("crtc changed, full mode switch\n"); DRM_DEBUG_KMS("crtc changed, full mode switch\n");
...@@ -862,7 +880,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set) ...@@ -862,7 +880,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
DRM_ERROR("failed to set mode on crtc %p\n", DRM_ERROR("failed to set mode on crtc %p\n",
set->crtc); set->crtc);
ret = -EINVAL; ret = -EINVAL;
goto fail_set_mode; goto fail;
} }
/* TODO are these needed? */ /* TODO are these needed? */
set->crtc->desired_x = set->x; set->crtc->desired_x = set->x;
...@@ -877,30 +895,34 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set) ...@@ -877,30 +895,34 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set)
ret = crtc_funcs->mode_set_base(set->crtc, ret = crtc_funcs->mode_set_base(set->crtc,
set->x, set->y, old_fb); set->x, set->y, old_fb);
if (ret != 0) if (ret != 0)
goto fail_set_mode; goto fail;
} }
kfree(save_connectors);
kfree(save_encoders); kfree(save_encoders);
kfree(save_crtcs); kfree(save_crtcs);
return 0; return 0;
fail_set_mode: fail:
set->crtc->enabled = save_enabled; /* Restore all previous data. */
set->crtc->fb = old_fb;
count = 0; count = 0;
list_for_each_entry(connector, &dev->mode_config.connector_list, head) { list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
if (!connector->encoder) *crtc = save_crtcs[count++];
continue; }
connector->encoder->crtc = save_crtcs[count++]; count = 0;
list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
*encoder = save_encoders[count++];
} }
fail_no_encoder:
kfree(save_crtcs);
count = 0; count = 0;
list_for_each_entry(connector, &dev->mode_config.connector_list, head) { list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
connector->encoder = save_encoders[count++]; *connector = save_connectors[count++];
} }
kfree(save_connectors);
kfree(save_encoders); kfree(save_encoders);
kfree(save_crtcs);
return ret; return ret;
} }
EXPORT_SYMBOL(drm_crtc_helper_set_config); EXPORT_SYMBOL(drm_crtc_helper_set_config);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment