From patchwork Fri Jun 1 17:00:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= X-Patchwork-Id: 10444111 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5B43B6028F for ; Fri, 1 Jun 2018 17:01:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5295028D82 for ; Fri, 1 Jun 2018 17:01:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4576228CA7; Fri, 1 Jun 2018 17:01:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C0DBA28CE2 for ; Fri, 1 Jun 2018 17:01:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 23C4D6E710; Fri, 1 Jun 2018 17:01:05 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id C7AF86E734 for ; Fri, 1 Jun 2018 17:01:03 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Jun 2018 10:01:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,467,1520924400"; d="scan'208";a="61011759" Received: from stinkbox.fi.intel.com (HELO stinkbox) ([10.237.72.174]) by orsmga001.jf.intel.com with SMTP; 01 Jun 2018 10:01:01 -0700 Received: by stinkbox (sSMTP sendmail emulation); Fri, 01 Jun 2018 20:01:00 +0300 From: Ville Syrjala To: intel-gfx@lists.freedesktop.org Date: Fri, 1 Jun 2018 20:00:30 +0300 Message-Id: <20180601170034.13095-9-ville.syrjala@linux.intel.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180601170034.13095-1-ville.syrjala@linux.intel.com> References: <20180601170034.13095-1-ville.syrjala@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v3 08/12] drm/i915: Introduce intel_plane_alloc() X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Ville Syrjälä Pull the common plane+plane_state allocation into a small helper. Reduces the amount of boilerplate in the plane initialization functions. Signed-off-by: Ville Syrjälä Reviewed-by: Chris Wilson --- drivers/gpu/drm/i915/intel_display.c | 44 ++++++++----------------------- drivers/gpu/drm/i915/intel_drv.h | 3 +++ drivers/gpu/drm/i915/intel_sprite.c | 50 ++++++++++++++++++++++++------------ 3 files changed, 47 insertions(+), 50 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index a061e9a7eb6a..13de4e9e276a 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c @@ -13542,8 +13542,7 @@ bool skl_plane_has_planar(struct drm_i915_private *dev_priv, static struct intel_plane * intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe) { - struct intel_plane *primary = NULL; - struct intel_plane_state *state = NULL; + struct intel_plane *primary; const struct drm_plane_funcs *plane_funcs; const uint32_t *intel_primary_formats; unsigned int supported_rotations; @@ -13552,19 +13551,9 @@ intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe) const uint64_t *modifiers; int ret; - primary = kzalloc(sizeof(*primary), GFP_KERNEL); - if (!primary) { - ret = -ENOMEM; - goto fail; - } - - state = intel_create_plane_state(&primary->base); - if (!state) { - ret = -ENOMEM; - goto fail; - } - - primary->base.state = &state->base; + primary = intel_plane_alloc(); + if (IS_ERR(primary)) + return primary; primary->can_scale = false; primary->max_downscale = 1; @@ -13708,8 +13697,7 @@ intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe) return primary; fail: - kfree(state); - kfree(primary); + intel_plane_free(primary); return ERR_PTR(ret); } @@ -13718,24 +13706,13 @@ static struct intel_plane * intel_cursor_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe) { - struct intel_plane *cursor = NULL; - struct intel_plane_state *state = NULL; unsigned int possible_crtcs; + struct intel_plane *cursor; int ret; - cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); - if (!cursor) { - ret = -ENOMEM; - goto fail; - } - - state = intel_create_plane_state(&cursor->base); - if (!state) { - ret = -ENOMEM; - goto fail; - } - - cursor->base.state = &state->base; + cursor = intel_plane_alloc(); + if (IS_ERR(cursor)) + return cursor; cursor->can_scale = false; cursor->max_downscale = 1; @@ -13785,8 +13762,7 @@ intel_cursor_plane_create(struct drm_i915_private *dev_priv, return cursor; fail: - kfree(state); - kfree(cursor); + intel_plane_free(cursor); return ERR_PTR(ret); } diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h index 497b482b9c58..88adf31ef1c2 100644 --- a/drivers/gpu/drm/i915/intel_drv.h +++ b/drivers/gpu/drm/i915/intel_drv.h @@ -2091,6 +2091,9 @@ bool skl_plane_has_ccs(struct drm_i915_private *dev_priv, bool intel_format_is_yuv(uint32_t format); bool skl_plane_has_planar(struct drm_i915_private *dev_priv, enum pipe pipe, enum plane_id plane_id); +struct intel_plane *intel_plane_alloc(void); +void intel_plane_free(struct intel_plane *plane); + /* intel_tv.c */ void intel_tv_init(struct drm_i915_private *dev_priv); diff --git a/drivers/gpu/drm/i915/intel_sprite.c b/drivers/gpu/drm/i915/intel_sprite.c index dd1fa32f0bd4..cc78d6b14bf0 100644 --- a/drivers/gpu/drm/i915/intel_sprite.c +++ b/drivers/gpu/drm/i915/intel_sprite.c @@ -1457,12 +1457,40 @@ bool skl_plane_has_ccs(struct drm_i915_private *dev_priv, plane_id == PLANE_SPRITE0); } +struct intel_plane *intel_plane_alloc(void) +{ + struct intel_plane_state *plane_state; + struct intel_plane *plane; + + plane = kzalloc(sizeof(*plane), GFP_KERNEL); + if (!plane) + return ERR_PTR(-ENOMEM); + + plane_state = intel_create_plane_state(&plane->base); + if (!plane_state) { + kfree(plane); + return ERR_PTR(-ENOMEM); + } + + plane->base.state = &plane_state->base; + + return plane; +} + +void intel_plane_free(struct intel_plane *plane) +{ + struct intel_plane_state *plane_state = + to_intel_plane_state(plane->base.state); + + kfree(plane_state); + kfree(plane); +} + struct intel_plane * intel_sprite_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe, int plane) { - struct intel_plane *intel_plane = NULL; - struct intel_plane_state *state = NULL; + struct intel_plane *intel_plane; const struct drm_plane_funcs *plane_funcs; unsigned long possible_crtcs; const uint32_t *plane_formats; @@ -1471,18 +1499,9 @@ intel_sprite_plane_create(struct drm_i915_private *dev_priv, int num_plane_formats; int ret; - intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL); - if (!intel_plane) { - ret = -ENOMEM; - goto fail; - } - - state = intel_create_plane_state(&intel_plane->base); - if (!state) { - ret = -ENOMEM; - goto fail; - } - intel_plane->base.state = &state->base; + intel_plane = intel_plane_alloc(); + if (IS_ERR(intel_plane)) + return intel_plane; if (INTEL_GEN(dev_priv) >= 9) { intel_plane->can_scale = true; @@ -1621,8 +1640,7 @@ intel_sprite_plane_create(struct drm_i915_private *dev_priv, return intel_plane; fail: - kfree(state); - kfree(intel_plane); + intel_plane_free(intel_plane); return ERR_PTR(ret); }