Commit c539b579 authored by Ville Syrjälä's avatar Ville Syrjälä

drm/i915: Introduce intel_plane_alloc()

Pull the common plane+plane_state allocation into a small helper.
Reduces the amount of boilerplate in the plane initialization
functions.
Signed-off-by: default avatarVille Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: default avatarStanislav Lisovskiy <stanislav.lisovskiy@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20181005125817.22576-9-ville.syrjala@linux.intel.com
parent 2d72dc8b
...@@ -13759,8 +13759,7 @@ bool skl_plane_has_planar(struct drm_i915_private *dev_priv, ...@@ -13759,8 +13759,7 @@ bool skl_plane_has_planar(struct drm_i915_private *dev_priv,
static struct intel_plane * static struct intel_plane *
intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe) intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
{ {
struct intel_plane *primary = NULL; struct intel_plane *primary;
struct intel_plane_state *state = NULL;
const struct drm_plane_funcs *plane_funcs; const struct drm_plane_funcs *plane_funcs;
const uint32_t *intel_primary_formats; const uint32_t *intel_primary_formats;
unsigned int supported_rotations; unsigned int supported_rotations;
...@@ -13769,19 +13768,9 @@ intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe) ...@@ -13769,19 +13768,9 @@ intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
const uint64_t *modifiers; const uint64_t *modifiers;
int ret; int ret;
primary = kzalloc(sizeof(*primary), GFP_KERNEL); primary = intel_plane_alloc();
if (!primary) { if (IS_ERR(primary))
ret = -ENOMEM; return primary;
goto fail;
}
state = intel_create_plane_state(&primary->base);
if (!state) {
ret = -ENOMEM;
goto fail;
}
primary->base.state = &state->base;
primary->pipe = pipe; primary->pipe = pipe;
/* /*
...@@ -13932,8 +13921,7 @@ intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe) ...@@ -13932,8 +13921,7 @@ intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
return primary; return primary;
fail: fail:
kfree(state); intel_plane_free(primary);
kfree(primary);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
...@@ -13942,24 +13930,13 @@ static struct intel_plane * ...@@ -13942,24 +13930,13 @@ static struct intel_plane *
intel_cursor_plane_create(struct drm_i915_private *dev_priv, intel_cursor_plane_create(struct drm_i915_private *dev_priv,
enum pipe pipe) enum pipe pipe)
{ {
struct intel_plane *cursor = NULL;
struct intel_plane_state *state = NULL;
unsigned int possible_crtcs; unsigned int possible_crtcs;
struct intel_plane *cursor;
int ret; int ret;
cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); cursor = intel_plane_alloc();
if (!cursor) { if (IS_ERR(cursor))
ret = -ENOMEM; return cursor;
goto fail;
}
state = intel_create_plane_state(&cursor->base);
if (!state) {
ret = -ENOMEM;
goto fail;
}
cursor->base.state = &state->base;
cursor->pipe = pipe; cursor->pipe = pipe;
cursor->i9xx_plane = (enum i9xx_plane_id) pipe; cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
...@@ -14009,8 +13986,7 @@ intel_cursor_plane_create(struct drm_i915_private *dev_priv, ...@@ -14009,8 +13986,7 @@ intel_cursor_plane_create(struct drm_i915_private *dev_priv,
return cursor; return cursor;
fail: fail:
kfree(state); intel_plane_free(cursor);
kfree(cursor);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
......
...@@ -2141,6 +2141,8 @@ int skl_plane_check(struct intel_crtc_state *crtc_state, ...@@ -2141,6 +2141,8 @@ int skl_plane_check(struct intel_crtc_state *crtc_state,
int intel_plane_check_stride(const struct intel_plane_state *plane_state); int intel_plane_check_stride(const struct intel_plane_state *plane_state);
int intel_plane_check_src_coordinates(struct intel_plane_state *plane_state); int intel_plane_check_src_coordinates(struct intel_plane_state *plane_state);
int chv_plane_check_rotation(const struct intel_plane_state *plane_state); int chv_plane_check_rotation(const struct intel_plane_state *plane_state);
struct intel_plane *intel_plane_alloc(void);
void intel_plane_free(struct intel_plane *plane);
/* intel_tv.c */ /* intel_tv.c */
void intel_tv_init(struct drm_i915_private *dev_priv); void intel_tv_init(struct drm_i915_private *dev_priv);
......
...@@ -1793,12 +1793,40 @@ bool skl_plane_has_ccs(struct drm_i915_private *dev_priv, ...@@ -1793,12 +1793,40 @@ bool skl_plane_has_ccs(struct drm_i915_private *dev_priv,
plane_id == PLANE_SPRITE0); 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 * struct intel_plane *
intel_sprite_plane_create(struct drm_i915_private *dev_priv, intel_sprite_plane_create(struct drm_i915_private *dev_priv,
enum pipe pipe, int plane) enum pipe pipe, int plane)
{ {
struct intel_plane *intel_plane = NULL; struct intel_plane *intel_plane;
struct intel_plane_state *state = NULL;
const struct drm_plane_funcs *plane_funcs; const struct drm_plane_funcs *plane_funcs;
unsigned long possible_crtcs; unsigned long possible_crtcs;
const uint32_t *plane_formats; const uint32_t *plane_formats;
...@@ -1807,18 +1835,9 @@ intel_sprite_plane_create(struct drm_i915_private *dev_priv, ...@@ -1807,18 +1835,9 @@ intel_sprite_plane_create(struct drm_i915_private *dev_priv,
int num_plane_formats; int num_plane_formats;
int ret; int ret;
intel_plane = kzalloc(sizeof(*intel_plane), GFP_KERNEL); intel_plane = intel_plane_alloc();
if (!intel_plane) { if (IS_ERR(intel_plane))
ret = -ENOMEM; return intel_plane;
goto fail;
}
state = intel_create_plane_state(&intel_plane->base);
if (!state) {
ret = -ENOMEM;
goto fail;
}
intel_plane->base.state = &state->base;
if (INTEL_GEN(dev_priv) >= 9) { if (INTEL_GEN(dev_priv) >= 9) {
intel_plane->has_ccs = skl_plane_has_ccs(dev_priv, pipe, intel_plane->has_ccs = skl_plane_has_ccs(dev_priv, pipe,
...@@ -1957,8 +1976,7 @@ intel_sprite_plane_create(struct drm_i915_private *dev_priv, ...@@ -1957,8 +1976,7 @@ intel_sprite_plane_create(struct drm_i915_private *dev_priv,
return intel_plane; return intel_plane;
fail: fail:
kfree(state); intel_plane_free(intel_plane);
kfree(intel_plane);
return ERR_PTR(ret); return ERR_PTR(ret);
} }
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