From patchwork Thu Dec 19 21:48:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Sousa X-Patchwork-Id: 13915872 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7B98AE7718A for ; Thu, 19 Dec 2024 21:49:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D567810EDE6; Thu, 19 Dec 2024 21:49:37 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="d5+Vxf0f"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9450710EDC4; Thu, 19 Dec 2024 21:49:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1734644976; x=1766180976; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=doBFyzUkjio72P5VzM+oZyIJzOUxB2DMHfpFKKtOD/I=; b=d5+Vxf0ffLjVZA5gGrxmrKzC5afdlQEidCnKYrLsENGRg8LsSpKnlhr1 AiMsmz6VH7JZaZ6Nuez2TQHIXGMJAhvgqQTbz0bxE9tlI7Q/RmDTLkTyG eN5NGMdLjgkpagDPc4rvmbXoGJ4CuJ+paww4mOsBv89XjlahDfWBsOsUN FpovWD7dHtletow/vzwmtAtuSnR3F2Ud2l9RQEkqgNTsW1PqONg5petPM lDCMpcuxM5RhMAXlWia8lH09fbMjzZkE0bD46IHROgk110cM5zQuWHczx Z/l4+OlMJhDKj1vTOrINzx6vS+UsSrpopJ2W4az9HCh72A98ugIKrD0Wj Q==; X-CSE-ConnectionGUID: 6PWPetZlRRqzNsjQn7XBmw== X-CSE-MsgGUID: 1D78aEGDQpyenAkhpVS5yA== X-IronPort-AV: E=McAfee;i="6700,10204,11291"; a="52710909" X-IronPort-AV: E=Sophos;i="6.12,248,1728975600"; d="scan'208";a="52710909" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Dec 2024 13:49:36 -0800 X-CSE-ConnectionGUID: J5CBYBaqSGGIP5rDrhV7Dw== X-CSE-MsgGUID: 6BQzlqJ0RLmPGjBLTrricw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="98150130" Received: from ldmartin-desk2.corp.intel.com (HELO gjsousa-mobl2.corp.amr.intel.com) ([10.125.108.53]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Dec 2024 13:49:36 -0800 From: Gustavo Sousa To: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org Cc: =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= , Jani Nikula Subject: [PATCH 1/3] drm/i915/display: Do not assume zero offset when duplicating global state Date: Thu, 19 Dec 2024 18:48:36 -0300 Message-ID: <20241219214909.104869-2-gustavo.sousa@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219214909.104869-1-gustavo.sousa@intel.com> References: <20241219214909.104869-1-gustavo.sousa@intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" The current intel_*_duplicate_state() functions assume the offset for the base member of their state structures is zero when calling kmemdup(). While that is true today, such assumption should not be made and proper offset must be applied when calling kmemdup(), otherwise we will be duplicating the wrong memory area if, for some reason, the offset is changed in the future. As such, update each of those functions to use its respective to_*_state() as the parameter to kmemdup(). Signed-off-by: Gustavo Sousa Reviewed-by: Jonathan Cavitt --- drivers/gpu/drm/i915/display/intel_bw.c | 4 ++-- drivers/gpu/drm/i915/display/intel_cdclk.c | 4 ++-- drivers/gpu/drm/i915/display/intel_pmdemand.c | 4 ++-- drivers/gpu/drm/i915/display/skl_watermark.c | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/i915/display/intel_bw.c b/drivers/gpu/drm/i915/display/intel_bw.c index 08e8a67ca74c..30236010e0ed 100644 --- a/drivers/gpu/drm/i915/display/intel_bw.c +++ b/drivers/gpu/drm/i915/display/intel_bw.c @@ -1425,9 +1425,9 @@ int intel_bw_atomic_check(struct intel_atomic_state *state) static struct intel_global_state * intel_bw_duplicate_state(struct intel_global_obj *obj) { - struct intel_bw_state *state; + struct intel_bw_state *state = to_intel_bw_state(obj->state); - state = kmemdup(obj->state, sizeof(*state), GFP_KERNEL); + state = kmemdup(state, sizeof(*state), GFP_KERNEL); if (!state) return NULL; diff --git a/drivers/gpu/drm/i915/display/intel_cdclk.c b/drivers/gpu/drm/i915/display/intel_cdclk.c index 3506e576bf6b..fc084e2a4c6a 100644 --- a/drivers/gpu/drm/i915/display/intel_cdclk.c +++ b/drivers/gpu/drm/i915/display/intel_cdclk.c @@ -3130,9 +3130,9 @@ 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; + struct intel_cdclk_state *cdclk_state = to_intel_cdclk_state(obj->state); - cdclk_state = kmemdup(obj->state, sizeof(*cdclk_state), GFP_KERNEL); + cdclk_state = kmemdup(cdclk_state, sizeof(*cdclk_state), GFP_KERNEL); if (!cdclk_state) return NULL; diff --git a/drivers/gpu/drm/i915/display/intel_pmdemand.c b/drivers/gpu/drm/i915/display/intel_pmdemand.c index cdd314956a31..1f71efb7d04d 100644 --- a/drivers/gpu/drm/i915/display/intel_pmdemand.c +++ b/drivers/gpu/drm/i915/display/intel_pmdemand.c @@ -18,9 +18,9 @@ static struct intel_global_state * intel_pmdemand_duplicate_state(struct intel_global_obj *obj) { - struct intel_pmdemand_state *pmdemand_state; + struct intel_pmdemand_state *pmdemand_state = to_intel_pmdemand_state(obj->state); - pmdemand_state = kmemdup(obj->state, sizeof(*pmdemand_state), GFP_KERNEL); + pmdemand_state = kmemdup(pmdemand_state, sizeof(*pmdemand_state), GFP_KERNEL); if (!pmdemand_state) return NULL; diff --git a/drivers/gpu/drm/i915/display/skl_watermark.c b/drivers/gpu/drm/i915/display/skl_watermark.c index 29e8ea91c858..b3d38e09df5a 100644 --- a/drivers/gpu/drm/i915/display/skl_watermark.c +++ b/drivers/gpu/drm/i915/display/skl_watermark.c @@ -3291,9 +3291,9 @@ static void skl_setup_wm_latency(struct drm_i915_private *i915) static struct intel_global_state *intel_dbuf_duplicate_state(struct intel_global_obj *obj) { - struct intel_dbuf_state *dbuf_state; + struct intel_dbuf_state *dbuf_state = to_intel_dbuf_state(obj->state); - dbuf_state = kmemdup(obj->state, sizeof(*dbuf_state), GFP_KERNEL); + dbuf_state = kmemdup(dbuf_state, sizeof(*dbuf_state), GFP_KERNEL); if (!dbuf_state) return NULL; From patchwork Thu Dec 19 21:48:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Sousa X-Patchwork-Id: 13915874 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3280BE77184 for ; Thu, 19 Dec 2024 21:49:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CB2C610EDEA; Thu, 19 Dec 2024 21:49:40 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="OABZa8q2"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0377310EDE9; Thu, 19 Dec 2024 21:49:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1734644978; x=1766180978; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+aLyViMRZcrU+UhnzHpYZ3m8y4lf7UX6OdTuaAzEN50=; b=OABZa8q2Q2rNXGS8mExCWn3hN+NSdrbOgRD3oI5OiaMu2aD3SwJYEfwq GnRJK2bC4tuo7ASEWRZPcOq7F+xO9N/Zme6xDXaL+f4uQHnCfceequjrz gcAEKjpCHfmQOtFakQfX+HzjmOHeh9moPRnY/eec7q2JuU8y3WFIOvsPV 90ar7KQlZ2uq19PM/rjEYa8jekkkJYEp9kLRiFCNFyvROrMSsExTJI+S4 arVN94j2+UDM56MWYOln4oYMyuB2atRUE1CQ0jr15QjdGnH9aIlGxHy2X tV8HWRS2hZT+KwuZk6wwFTdlHi+KmoWCr9ML1idpUI+vX9m5S/RsSsYF0 Q==; X-CSE-ConnectionGUID: alrG5nwSR3ep347VKgOoyw== X-CSE-MsgGUID: JNBqwqQlTu2A1gmQdwu6Cw== X-IronPort-AV: E=McAfee;i="6700,10204,11291"; a="52710911" X-IronPort-AV: E=Sophos;i="6.12,248,1728975600"; d="scan'208";a="52710911" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Dec 2024 13:49:37 -0800 X-CSE-ConnectionGUID: x4J3y6PtSUaQh/7fHzSyHg== X-CSE-MsgGUID: gTr/pD0XRwCILRaJc50pvg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="98150144" Received: from ldmartin-desk2.corp.intel.com (HELO gjsousa-mobl2.corp.amr.intel.com) ([10.125.108.53]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Dec 2024 13:49:37 -0800 From: Gustavo Sousa To: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org Cc: =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= , Jani Nikula Subject: [PATCH 2/3] drm/i915/display: Add infra to reduce global state funcs boilerplate Date: Thu, 19 Dec 2024 18:48:37 -0300 Message-ID: <20241219214909.104869-3-gustavo.sousa@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219214909.104869-1-gustavo.sousa@intel.com> References: <20241219214909.104869-1-gustavo.sousa@intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" If we look at how the members of struct intel_global_state_funcs, we see a common pattern repeating itself. Let's add the necessary infra-structure to allow reducing the boilerplate. We do that by adding common generic implementations for each member and adding a macro INTEL_GLOBAL_STATE_DEFAULTS() to be used when initializing an instance of struct intel_global_state_funcs. That way, a global state that does not need custom behavior can have its funcs structure be initialized as in the following example, static const struct intel_global_state_funcs _funcs = { INTEL_GLOBAL_STATE_DEFAULTS(struct _state, ), }; , without the need to implementing the functions. That doesn't come without cost - we will need to store two size_t members -, but that cost is arguably justified by the simplification gained. In an upcoming change we will put that infra into action on existing users. Signed-off-by: Gustavo Sousa Reviewed-by: Jonathan Cavitt --- .../gpu/drm/i915/display/intel_global_state.c | 41 ++++++++++++++++++- .../gpu/drm/i915/display/intel_global_state.h | 15 +++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/display/intel_global_state.c b/drivers/gpu/drm/i915/display/intel_global_state.c index cbcd1e91b7be..4b4c33fa99fb 100644 --- a/drivers/gpu/drm/i915/display/intel_global_state.c +++ b/drivers/gpu/drm/i915/display/intel_global_state.c @@ -59,7 +59,10 @@ static void __intel_atomic_global_state_free(struct kref *kref) commit_put(obj_state->commit); - obj->funcs->atomic_destroy_state(obj, obj_state); + if (obj->funcs->atomic_destroy_state) + obj->funcs->atomic_destroy_state(obj, obj_state); + else + intel_atomic_global_destroy_state_common(obj, obj_state); } static void intel_atomic_global_state_put(struct intel_global_state *obj_state) @@ -164,7 +167,11 @@ intel_atomic_get_global_obj_state(struct intel_atomic_state *state, index = state->num_global_objs; memset(&state->global_objs[index], 0, sizeof(*state->global_objs)); - obj_state = obj->funcs->atomic_duplicate_state(obj); + if (obj->funcs->atomic_duplicate_state) + obj_state = obj->funcs->atomic_duplicate_state(obj); + else + obj_state = intel_atomic_global_duplicate_state_common(obj); + if (!obj_state) return ERR_PTR(-ENOMEM); @@ -382,3 +389,33 @@ intel_atomic_global_state_commit_done(struct intel_atomic_state *state) complete_all(&commit->done); } } + +struct intel_global_state * +intel_atomic_global_duplicate_state_common(struct intel_global_obj *obj) +{ + void *state_wrapper; + + if (WARN_ON(obj->funcs->state_size == 0)) + return NULL; + + state_wrapper = (void *)obj->state - obj->funcs->base_offset; + + state_wrapper = kmemdup(state_wrapper, obj->funcs->state_size, GFP_KERNEL); + if (!state_wrapper) + return NULL; + + return state_wrapper + obj->funcs->base_offset; +} + +void intel_atomic_global_destroy_state_common(struct intel_global_obj *obj, + struct intel_global_state *state) +{ + void *state_wrapper; + + if (WARN_ON(obj->funcs->state_size == 0)) + return; + + state_wrapper = (void *)state - obj->funcs->base_offset; + + kfree(state_wrapper); +} diff --git a/drivers/gpu/drm/i915/display/intel_global_state.h b/drivers/gpu/drm/i915/display/intel_global_state.h index 6506a8e32972..e47e007225cc 100644 --- a/drivers/gpu/drm/i915/display/intel_global_state.h +++ b/drivers/gpu/drm/i915/display/intel_global_state.h @@ -8,6 +8,8 @@ #include #include +#include +#include struct drm_i915_private; struct intel_atomic_state; @@ -15,6 +17,10 @@ struct intel_global_obj; struct intel_global_state; struct intel_global_state_funcs { + /* state_size and base_offset are initialized by INTEL_GLOBAL_STATE_DEFAULTS() */ + size_t state_size; + size_t base_offset; + struct intel_global_state *(*atomic_duplicate_state)(struct intel_global_obj *obj); void (*atomic_destroy_state)(struct intel_global_obj *obj, struct intel_global_state *state); @@ -26,6 +32,10 @@ struct intel_global_obj { const struct intel_global_state_funcs *funcs; }; +#define INTEL_GLOBAL_STATE_DEFAULTS(type, base_member) \ + .state_size = sizeof(type), \ + .base_offset = offsetof(type, base_member) + #define intel_for_each_global_obj(obj, dev_priv) \ list_for_each_entry(obj, &(dev_priv)->display.global.obj_list, head) @@ -96,4 +106,9 @@ int intel_atomic_global_state_wait_for_dependencies(struct intel_atomic_state *s bool intel_atomic_global_state_is_serialized(struct intel_atomic_state *state); +struct intel_global_state * +intel_atomic_global_duplicate_state_common(struct intel_global_obj *obj); +void intel_atomic_global_destroy_state_common(struct intel_global_obj *obj, + struct intel_global_state *state); + #endif From patchwork Thu Dec 19 21:48:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Sousa X-Patchwork-Id: 13915873 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F0BCE7718D for ; Thu, 19 Dec 2024 21:49:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DC0B110EDE9; Thu, 19 Dec 2024 21:49:39 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="ml6LBZLQ"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by gabe.freedesktop.org (Postfix) with ESMTPS id 73BB110EDE9; Thu, 19 Dec 2024 21:49:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1734644979; x=1766180979; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=h7B9pCEcsDRpbCbnTIvSw39Hasy5sUXB1hhaaRUp3iQ=; b=ml6LBZLQOCt+9JDIP6hHCL4zVIiNGvwC9mxBJlwGKqejINad13PJKmJJ zEYV9Z5QsLT2vmDs3Ta3vsVA24J3QIppR9WJoLYNpMlBNww8sAyCxwpwn bQdqTfk0x4iosmvxVK1ucOXflDiEPr7ulAvrB0p+J62kllIqGIapDlV+i nU+bq1IE4NnQozc2KVmeNIhXDx01bxKqtjYfFDjKVYMLqV0srzbOpkj5O MUb4gf/iPK7ym/LU5jOv1GFGmnRMYgN+El2EnTkHqCvCH3sxepF215JUs swVP7ubxAG/Lm1ftOiU6yoo7L6/VMZUuf6zfQNtp4Y+iqCdI9QlZKo23U w==; X-CSE-ConnectionGUID: 803fmK9xTT6Tt6jcA+SuiA== X-CSE-MsgGUID: 6xEPZdAYTtOMobyfhbbecw== X-IronPort-AV: E=McAfee;i="6700,10204,11291"; a="52710912" X-IronPort-AV: E=Sophos;i="6.12,248,1728975600"; d="scan'208";a="52710912" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Dec 2024 13:49:39 -0800 X-CSE-ConnectionGUID: VyXXR4lwSf+qbk6iQUMznA== X-CSE-MsgGUID: X9KHqIL2Rq+gg7TSea9GxQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="98150148" Received: from ldmartin-desk2.corp.intel.com (HELO gjsousa-mobl2.corp.amr.intel.com) ([10.125.108.53]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Dec 2024 13:49:38 -0800 From: Gustavo Sousa To: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org Cc: =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= , Jani Nikula Subject: [PATCH 3/3] drm/i915/display: Use INTEL_GLOBAL_STATE_DEFAULTS Date: Thu, 19 Dec 2024 18:48:38 -0300 Message-ID: <20241219214909.104869-4-gustavo.sousa@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219214909.104869-1-gustavo.sousa@intel.com> References: <20241219214909.104869-1-gustavo.sousa@intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" 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 Reviewed-by: Jonathan Cavitt --- 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 *