Reduce global state boilerplate by using INTEL_GLOBAL_STATE_DEFAULTS(). The only case that requires customization is for the duplication of CDCLK state, which is resolved by wrapping the generic implementation. Signed-off-by: Gustavo Sousa <gustavo.sousa@xxxxxxxxx> --- drivers/gpu/drm/i915/display/intel_bw.c | 21 +------------------ drivers/gpu/drm/i915/display/intel_cdclk.c | 18 +++++++--------- drivers/gpu/drm/i915/display/intel_pmdemand.c | 21 +------------------ drivers/gpu/drm/i915/display/skl_watermark.c | 20 +----------------- 4 files changed, 10 insertions(+), 70 deletions(-) diff --git a/drivers/gpu/drm/i915/display/intel_bw.c b/drivers/gpu/drm/i915/display/intel_bw.c index 30236010e0ed..f040dfa70fd9 100644 --- a/drivers/gpu/drm/i915/display/intel_bw.c +++ b/drivers/gpu/drm/i915/display/intel_bw.c @@ -1422,27 +1422,8 @@ int intel_bw_atomic_check(struct intel_atomic_state *state) return 0; } -static struct intel_global_state * -intel_bw_duplicate_state(struct intel_global_obj *obj) -{ - struct intel_bw_state *state = to_intel_bw_state(obj->state); - - state = kmemdup(state, sizeof(*state), GFP_KERNEL); - if (!state) - return NULL; - - return &state->base; -} - -static void intel_bw_destroy_state(struct intel_global_obj *obj, - struct intel_global_state *state) -{ - kfree(state); -} - static const struct intel_global_state_funcs intel_bw_funcs = { - .atomic_duplicate_state = intel_bw_duplicate_state, - .atomic_destroy_state = intel_bw_destroy_state, + INTEL_GLOBAL_STATE_DEFAULTS(struct intel_bw_state, base), }; int intel_bw_init(struct drm_i915_private *i915) diff --git a/drivers/gpu/drm/i915/display/intel_cdclk.c b/drivers/gpu/drm/i915/display/intel_cdclk.c index fc084e2a4c6a..a9dfbd53e812 100644 --- a/drivers/gpu/drm/i915/display/intel_cdclk.c +++ b/drivers/gpu/drm/i915/display/intel_cdclk.c @@ -3130,27 +3130,23 @@ static int fixed_modeset_calc_cdclk(struct intel_atomic_state *state) static struct intel_global_state *intel_cdclk_duplicate_state(struct intel_global_obj *obj) { - struct intel_cdclk_state *cdclk_state = to_intel_cdclk_state(obj->state); + struct intel_global_state *obj_state; + struct intel_cdclk_state *cdclk_state; - cdclk_state = kmemdup(cdclk_state, sizeof(*cdclk_state), GFP_KERNEL); - if (!cdclk_state) + obj_state = intel_atomic_global_duplicate_state_common(obj); + if (!obj_state) return NULL; + cdclk_state = to_intel_cdclk_state(obj_state); cdclk_state->pipe = INVALID_PIPE; cdclk_state->disable_pipes = false; - return &cdclk_state->base; -} - -static void intel_cdclk_destroy_state(struct intel_global_obj *obj, - struct intel_global_state *state) -{ - kfree(state); + return obj_state; } static const struct intel_global_state_funcs intel_cdclk_funcs = { + INTEL_GLOBAL_STATE_DEFAULTS(struct intel_cdclk_state, base), .atomic_duplicate_state = intel_cdclk_duplicate_state, - .atomic_destroy_state = intel_cdclk_destroy_state, }; struct intel_cdclk_state * diff --git a/drivers/gpu/drm/i915/display/intel_pmdemand.c b/drivers/gpu/drm/i915/display/intel_pmdemand.c index 1f71efb7d04d..5bf245a9ac8d 100644 --- a/drivers/gpu/drm/i915/display/intel_pmdemand.c +++ b/drivers/gpu/drm/i915/display/intel_pmdemand.c @@ -15,27 +15,8 @@ #include "intel_pmdemand.h" #include "skl_watermark.h" -static struct intel_global_state * -intel_pmdemand_duplicate_state(struct intel_global_obj *obj) -{ - struct intel_pmdemand_state *pmdemand_state = to_intel_pmdemand_state(obj->state); - - pmdemand_state = kmemdup(pmdemand_state, sizeof(*pmdemand_state), GFP_KERNEL); - if (!pmdemand_state) - return NULL; - - return &pmdemand_state->base; -} - -static void intel_pmdemand_destroy_state(struct intel_global_obj *obj, - struct intel_global_state *state) -{ - kfree(state); -} - static const struct intel_global_state_funcs intel_pmdemand_funcs = { - .atomic_duplicate_state = intel_pmdemand_duplicate_state, - .atomic_destroy_state = intel_pmdemand_destroy_state, + INTEL_GLOBAL_STATE_DEFAULTS(struct intel_pmdemand_state, base), }; static struct intel_pmdemand_state * diff --git a/drivers/gpu/drm/i915/display/skl_watermark.c b/drivers/gpu/drm/i915/display/skl_watermark.c index b3d38e09df5a..8aa041be8277 100644 --- a/drivers/gpu/drm/i915/display/skl_watermark.c +++ b/drivers/gpu/drm/i915/display/skl_watermark.c @@ -3289,26 +3289,8 @@ static void skl_setup_wm_latency(struct drm_i915_private *i915) intel_print_wm_latency(i915, "Gen9 Plane", display->wm.skl_latency); } -static struct intel_global_state *intel_dbuf_duplicate_state(struct intel_global_obj *obj) -{ - struct intel_dbuf_state *dbuf_state = to_intel_dbuf_state(obj->state); - - dbuf_state = kmemdup(dbuf_state, sizeof(*dbuf_state), GFP_KERNEL); - if (!dbuf_state) - return NULL; - - return &dbuf_state->base; -} - -static void intel_dbuf_destroy_state(struct intel_global_obj *obj, - struct intel_global_state *state) -{ - kfree(state); -} - static const struct intel_global_state_funcs intel_dbuf_funcs = { - .atomic_duplicate_state = intel_dbuf_duplicate_state, - .atomic_destroy_state = intel_dbuf_destroy_state, + INTEL_GLOBAL_STATE_DEFAULTS(struct intel_dbuf_state, base), }; struct intel_dbuf_state * -- 2.47.1