From patchwork Sun Aug 19 19:12:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 1345081 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 7F9A93FC33 for ; Sun, 19 Aug 2012 20:44:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 64047A102D for ; Sun, 19 Aug 2012 13:44:00 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com [209.85.212.177]) by gabe.freedesktop.org (Postfix) with ESMTP id 599FEA1030 for ; Sun, 19 Aug 2012 13:21:01 -0700 (PDT) Received: by mail-wi0-f177.google.com with SMTP id hn17so2755791wib.12 for ; Sun, 19 Aug 2012 13:21:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=OwlsGt8J106EKXFICtYecC/SsH2fZlqfnfuMW1tpXrU=; b=Ynr6RYoyG6rx1/GTwwpifj3zmKrL1KNLZC0cn4kle7QfjUX2LwnM1EEsOtKXIuYqyA dn5wmghgJmxQCCobL3YHPTiBBkJISkEhQnWJeDJzcgwakwie4Fb+Kte9P0bPj+Ieg1/v ts9qVjytYaEqS5B7uqcmj5VuF4EDARWmKJ95Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=OwlsGt8J106EKXFICtYecC/SsH2fZlqfnfuMW1tpXrU=; b=nMLP8T+wFmWrbHmw/5slqATIYvXDm26e71jHSRWtR+Ln3WzpCNwTuz5nrahy7lzajK ecoDe9zRFZ8g0PLW6Tx7TrXWFBLz8cf3wMi7jmBEMQuPHFOAKBxn+2Wet6APaTNyNsMP ejvyaksWsa4lHn/eTn1ltryppS++2BG6BpCBeDrl5RAV+EayEmcuayG629HpKjrXrMO1 /pxzzFV/iKgLODWRSOEtnskPgmPIIf3lu9pKmvYEsAYOPPbGI1nmUi3R9vlX6deFZBCS oTOcu5G2HXupSp4s7eL7Oeg7R6PUG8EmvA5Mq0NNwulyY4pwCPmmti8shC3eGaOhLZE2 Rqmw== Received: by 10.180.84.104 with SMTP id x8mr21934389wiy.20.1345407661049; Sun, 19 Aug 2012 13:21:01 -0700 (PDT) Received: from wespe.ffwll.local (178-83-130-250.dynamic.hispeed.ch. [178.83.130.250]) by mx.google.com with ESMTPS id fu8sm24194367wib.5.2012.08.19.13.20.59 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 19 Aug 2012 13:21:00 -0700 (PDT) From: Daniel Vetter To: Intel Graphics Development Date: Sun, 19 Aug 2012 21:12:52 +0200 Message-Id: <1345403595-9678-36-git-send-email-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1345403595-9678-1-git-send-email-daniel.vetter@ffwll.ch> References: <1345403595-9678-1-git-send-email-daniel.vetter@ffwll.ch> X-Gm-Message-State: ALoCoQl84ZEusMebX6azQ7mltBuWNEZUZf3liwSAGLwGCOWNvxyYw5MH77IrEQ+9AGxxmjTxl5ZP Cc: Daniel Vetter Subject: [Intel-gfx] [PATCH 35/58] drm/i915: introduce struct intel_set_config X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+patchwork-intel-gfx=patchwork.kernel.org@lists.freedesktop.org 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. Signed-Off-by: Daniel Vetter Reviewed-by: Jesse Barnes --- drivers/gpu/drm/i915/intel_display.c | 73 ++++++++++++++++++++---------------- drivers/gpu/drm/i915/intel_drv.h | 6 +++ 2 files changed, 47 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index ab4fa7f..63bcc37 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c @@ -6723,17 +6723,28 @@ done: return ret; } +static void intel_set_config_free(struct intel_set_config *config) +{ + if (config) { + 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) { struct drm_device *dev; - struct drm_crtc *save_crtcs, *new_crtc, *crtc; - struct drm_encoder *save_encoders, *new_encoder, *encoder; + struct drm_crtc *new_crtc, *crtc; + struct drm_encoder *new_encoder, *encoder; struct drm_framebuffer *old_fb = NULL; bool mode_changed = false; /* if true do a full mode set */ 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; struct drm_mode_set save_set; + struct intel_set_config *config; int ret; int i; @@ -6762,27 +6773,27 @@ static int intel_crtc_set_config(struct drm_mode_set *set) 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 * connector data. */ - save_crtcs = kzalloc(dev->mode_config.num_crtc * - sizeof(struct drm_crtc), GFP_KERNEL); - if (!save_crtcs) - return -ENOMEM; + config->save_crtcs = kzalloc(dev->mode_config.num_crtc * + sizeof(struct drm_crtc), GFP_KERNEL); + if (!config->save_crtcs) + goto out_config; - save_encoders = kzalloc(dev->mode_config.num_encoder * - sizeof(struct drm_encoder), GFP_KERNEL); - if (!save_encoders) { - kfree(save_crtcs); - return -ENOMEM; - } + config->save_encoders = kzalloc(dev->mode_config.num_encoder * + sizeof(struct drm_encoder), GFP_KERNEL); + if (!config->save_encoders) + goto out_config; - 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; - } + config->save_connectors = kzalloc(dev->mode_config.num_connector * + sizeof(struct drm_connector), GFP_KERNEL); + if (!config->save_connectors) + goto out_config; /* Copy data. Note that driver private data is not affected. * Should anything bad happen only the expected state is @@ -6790,17 +6801,17 @@ static int intel_crtc_set_config(struct drm_mode_set *set) */ count = 0; list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { - save_crtcs[count++] = *crtc; + config->save_crtcs[count++] = *crtc; } count = 0; list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { - save_encoders[count++] = *encoder; + config->save_encoders[count++] = *encoder; } count = 0; 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; @@ -6936,26 +6947,25 @@ static int intel_crtc_set_config(struct drm_mode_set *set) } } - kfree(save_connectors); - kfree(save_encoders); - kfree(save_crtcs); + intel_set_config_free(config); + return 0; fail: /* Restore all previous data. */ count = 0; list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { - *crtc = save_crtcs[count++]; + *crtc = config->save_crtcs[count++]; } count = 0; list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { - *encoder = save_encoders[count++]; + *encoder = config->save_encoders[count++]; } count = 0; 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 */ @@ -6964,9 +6974,8 @@ fail: save_set.x, save_set.y, save_set.fb)) DRM_ERROR("failed to restore config after modeset failure\n"); - kfree(save_connectors); - kfree(save_encoders); - kfree(save_crtcs); +out_config: + intel_set_config_free(config); return ret; } diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h index c080c829..1cb64dd 100644 --- a/drivers/gpu/drm/i915/intel_drv.h +++ b/drivers/gpu/drm/i915/intel_drv.h @@ -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 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, int x, int y, struct drm_framebuffer *old_fb); extern void intel_crtc_load_lut(struct drm_crtc *crtc);