Commit d9e55608 authored by Daniel Vetter's avatar Daniel Vetter

drm/i915: introduce struct intel_set_config

intel_crtc_set_config is an unwidly beast and is in serious need of
some function extraction. To facilitate that, introduce a struct to
keep track of all the state involved. Atm it doesn't do much more than
keep track of all the allocated memory.

v2: Apply some bikeshed to intel_set_config_free, as suggested by
Jesse Barnes.
Reviewed-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
Signed-Off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 7fad798e
...@@ -6723,17 +6723,29 @@ bool intel_set_mode(struct drm_crtc *crtc, ...@@ -6723,17 +6723,29 @@ bool intel_set_mode(struct drm_crtc *crtc,
return ret; return ret;
} }
static void intel_set_config_free(struct intel_set_config *config)
{
if (!config)
return;
kfree(config->save_connectors);
kfree(config->save_encoders);
kfree(config->save_crtcs);
kfree(config);
}
static int intel_crtc_set_config(struct drm_mode_set *set) static int intel_crtc_set_config(struct drm_mode_set *set)
{ {
struct drm_device *dev; struct drm_device *dev;
struct drm_crtc *save_crtcs, *new_crtc, *crtc; struct drm_crtc *new_crtc, *crtc;
struct drm_encoder *save_encoders, *new_encoder, *encoder; struct drm_encoder *new_encoder, *encoder;
struct drm_framebuffer *old_fb = NULL; struct drm_framebuffer *old_fb = NULL;
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 *save_connectors, *connector; struct drm_connector *connector;
int count = 0, ro; int count = 0, ro;
struct drm_mode_set save_set; struct drm_mode_set save_set;
struct intel_set_config *config;
int ret; int ret;
int i; int i;
...@@ -6762,27 +6774,27 @@ static int intel_crtc_set_config(struct drm_mode_set *set) ...@@ -6762,27 +6774,27 @@ static int intel_crtc_set_config(struct drm_mode_set *set)
dev = set->crtc->dev; dev = set->crtc->dev;
ret = -ENOMEM;
config = kzalloc(sizeof(*config), GFP_KERNEL);
if (!config)
goto out_config;
/* Allocate space for the backup of all (non-pointer) crtc, encoder and /* Allocate space for the backup of all (non-pointer) crtc, encoder and
* connector data. */ * connector data. */
save_crtcs = kzalloc(dev->mode_config.num_crtc * config->save_crtcs = kzalloc(dev->mode_config.num_crtc *
sizeof(struct drm_crtc), GFP_KERNEL); sizeof(struct drm_crtc), GFP_KERNEL);
if (!save_crtcs) if (!config->save_crtcs)
return -ENOMEM; goto out_config;
save_encoders = kzalloc(dev->mode_config.num_encoder * config->save_encoders = kzalloc(dev->mode_config.num_encoder *
sizeof(struct drm_encoder), GFP_KERNEL); sizeof(struct drm_encoder), GFP_KERNEL);
if (!save_encoders) { if (!config->save_encoders)
kfree(save_crtcs); goto out_config;
return -ENOMEM;
}
save_connectors = kzalloc(dev->mode_config.num_connector * config->save_connectors = kzalloc(dev->mode_config.num_connector *
sizeof(struct drm_connector), GFP_KERNEL); sizeof(struct drm_connector), GFP_KERNEL);
if (!save_connectors) { if (!config->save_connectors)
kfree(save_crtcs); goto out_config;
kfree(save_encoders);
return -ENOMEM;
}
/* Copy data. Note that driver private data is not affected. /* Copy data. Note that driver private data is not affected.
* Should anything bad happen only the expected state is * Should anything bad happen only the expected state is
...@@ -6790,17 +6802,17 @@ static int intel_crtc_set_config(struct drm_mode_set *set) ...@@ -6790,17 +6802,17 @@ static int intel_crtc_set_config(struct drm_mode_set *set)
*/ */
count = 0; count = 0;
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
save_crtcs[count++] = *crtc; config->save_crtcs[count++] = *crtc;
} }
count = 0; count = 0;
list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
save_encoders[count++] = *encoder; config->save_encoders[count++] = *encoder;
} }
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) {
save_connectors[count++] = *connector; config->save_connectors[count++] = *connector;
} }
save_set.crtc = set->crtc; save_set.crtc = set->crtc;
...@@ -6936,26 +6948,25 @@ static int intel_crtc_set_config(struct drm_mode_set *set) ...@@ -6936,26 +6948,25 @@ static int intel_crtc_set_config(struct drm_mode_set *set)
} }
} }
kfree(save_connectors); intel_set_config_free(config);
kfree(save_encoders);
kfree(save_crtcs);
return 0; return 0;
fail: fail:
/* Restore all previous data. */ /* Restore all previous data. */
count = 0; count = 0;
list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
*crtc = save_crtcs[count++]; *crtc = config->save_crtcs[count++];
} }
count = 0; count = 0;
list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
*encoder = save_encoders[count++]; *encoder = config->save_encoders[count++];
} }
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 = save_connectors[count++]; *connector = config->save_connectors[count++];
} }
/* Try to restore the config */ /* Try to restore the config */
...@@ -6964,9 +6975,8 @@ static int intel_crtc_set_config(struct drm_mode_set *set) ...@@ -6964,9 +6975,8 @@ static int intel_crtc_set_config(struct drm_mode_set *set)
save_set.x, save_set.y, save_set.fb)) save_set.x, save_set.y, save_set.fb))
DRM_ERROR("failed to restore config after modeset failure\n"); DRM_ERROR("failed to restore config after modeset failure\n");
kfree(save_connectors); out_config:
kfree(save_encoders); intel_set_config_free(config);
kfree(save_crtcs);
return ret; return ret;
} }
......
...@@ -423,6 +423,12 @@ extern void intel_panel_disable_backlight(struct drm_device *dev); ...@@ -423,6 +423,12 @@ extern void intel_panel_disable_backlight(struct drm_device *dev);
extern void intel_panel_destroy_backlight(struct drm_device *dev); extern void intel_panel_destroy_backlight(struct drm_device *dev);
extern enum drm_connector_status intel_panel_detect(struct drm_device *dev); extern enum drm_connector_status intel_panel_detect(struct drm_device *dev);
struct intel_set_config {
struct drm_connector *save_connectors;
struct drm_encoder *save_encoders;
struct drm_crtc *save_crtcs;
};
extern bool intel_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode, extern bool intel_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode,
int x, int y, struct drm_framebuffer *old_fb); int x, int y, struct drm_framebuffer *old_fb);
extern void intel_crtc_load_lut(struct drm_crtc *crtc); extern void intel_crtc_load_lut(struct drm_crtc *crtc);
......
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