diff mbox series

drm/i915/rpm: add rpm_to_i915() helper around container_of()

Message ID 20231205121545.2338665-1-jani.nikula@intel.com (mailing list archive)
State New, archived
Headers show
Series drm/i915/rpm: add rpm_to_i915() helper around container_of() | expand

Commit Message

Jani Nikula Dec. 5, 2023, 12:15 p.m. UTC
Reduce the duplication.

Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 drivers/gpu/drm/i915/intel_runtime_pm.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

Comments

Rodrigo Vivi Dec. 5, 2023, 1:30 p.m. UTC | #1
On Tue, Dec 05, 2023 at 02:15:45PM +0200, Jani Nikula wrote:
> Reduce the duplication.
> 
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

> ---
>  drivers/gpu/drm/i915/intel_runtime_pm.c | 24 ++++++++++--------------
>  1 file changed, 10 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.c b/drivers/gpu/drm/i915/intel_runtime_pm.c
> index 91491111dbd5..860b51b56a92 100644
> --- a/drivers/gpu/drm/i915/intel_runtime_pm.c
> +++ b/drivers/gpu/drm/i915/intel_runtime_pm.c
> @@ -50,6 +50,11 @@
>   * present for a given platform.
>   */
>  
> +static struct drm_i915_private *rpm_to_i915(struct intel_runtime_pm *rpm)
> +{
> +	return container_of(rpm, struct drm_i915_private, runtime_pm);
> +}
> +
>  #if IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)
>  
>  static void init_intel_runtime_pm_wakeref(struct intel_runtime_pm *rpm)
> @@ -158,9 +163,7 @@ intel_runtime_pm_release(struct intel_runtime_pm *rpm, int wakelock)
>  static intel_wakeref_t __intel_runtime_pm_get(struct intel_runtime_pm *rpm,
>  					      bool wakelock)
>  {
> -	struct drm_i915_private *i915 = container_of(rpm,
> -						     struct drm_i915_private,
> -						     runtime_pm);
> +	struct drm_i915_private *i915 = rpm_to_i915(rpm);
>  	int ret;
>  
>  	ret = pm_runtime_get_sync(rpm->kdev);
> @@ -365,9 +368,7 @@ void intel_runtime_pm_put(struct intel_runtime_pm *rpm, intel_wakeref_t wref)
>   */
>  void intel_runtime_pm_enable(struct intel_runtime_pm *rpm)
>  {
> -	struct drm_i915_private *i915 = container_of(rpm,
> -						     struct drm_i915_private,
> -						     runtime_pm);
> +	struct drm_i915_private *i915 = rpm_to_i915(rpm);
>  	struct device *kdev = rpm->kdev;
>  
>  	/*
> @@ -420,9 +421,7 @@ void intel_runtime_pm_enable(struct intel_runtime_pm *rpm)
>  
>  void intel_runtime_pm_disable(struct intel_runtime_pm *rpm)
>  {
> -	struct drm_i915_private *i915 = container_of(rpm,
> -						     struct drm_i915_private,
> -						     runtime_pm);
> +	struct drm_i915_private *i915 = rpm_to_i915(rpm);
>  	struct device *kdev = rpm->kdev;
>  
>  	/* Transfer rpm ownership back to core */
> @@ -437,9 +436,7 @@ void intel_runtime_pm_disable(struct intel_runtime_pm *rpm)
>  
>  void intel_runtime_pm_driver_release(struct intel_runtime_pm *rpm)
>  {
> -	struct drm_i915_private *i915 = container_of(rpm,
> -						     struct drm_i915_private,
> -						     runtime_pm);
> +	struct drm_i915_private *i915 = rpm_to_i915(rpm);
>  	int count = atomic_read(&rpm->wakeref_count);
>  
>  	intel_wakeref_auto_fini(&rpm->userfault_wakeref);
> @@ -458,8 +455,7 @@ void intel_runtime_pm_driver_last_release(struct intel_runtime_pm *rpm)
>  
>  void intel_runtime_pm_init_early(struct intel_runtime_pm *rpm)
>  {
> -	struct drm_i915_private *i915 =
> -			container_of(rpm, struct drm_i915_private, runtime_pm);
> +	struct drm_i915_private *i915 = rpm_to_i915(rpm);
>  	struct pci_dev *pdev = to_pci_dev(i915->drm.dev);
>  	struct device *kdev = &pdev->dev;
>  
> -- 
> 2.39.2
>
Gustavo Sousa Dec. 6, 2023, 1:03 p.m. UTC | #2
Quoting Jani Nikula (2023-12-05 09:15:45-03:00)
>Reduce the duplication.

By the way, is it too ambitious to dream of a to_i915() using generics?

--
Gustavo Sousa

>
>Signed-off-by: Jani Nikula <jani.nikula@intel.com>
>---
> drivers/gpu/drm/i915/intel_runtime_pm.c | 24 ++++++++++--------------
> 1 file changed, 10 insertions(+), 14 deletions(-)
>
>diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.c b/drivers/gpu/drm/i915/intel_runtime_pm.c
>index 91491111dbd5..860b51b56a92 100644
>--- a/drivers/gpu/drm/i915/intel_runtime_pm.c
>+++ b/drivers/gpu/drm/i915/intel_runtime_pm.c
>@@ -50,6 +50,11 @@
>  * present for a given platform.
>  */
> 
>+static struct drm_i915_private *rpm_to_i915(struct intel_runtime_pm *rpm)
>+{
>+        return container_of(rpm, struct drm_i915_private, runtime_pm);
>+}
>+
> #if IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)
> 
> static void init_intel_runtime_pm_wakeref(struct intel_runtime_pm *rpm)
>@@ -158,9 +163,7 @@ intel_runtime_pm_release(struct intel_runtime_pm *rpm, int wakelock)
> static intel_wakeref_t __intel_runtime_pm_get(struct intel_runtime_pm *rpm,
>                                               bool wakelock)
> {
>-        struct drm_i915_private *i915 = container_of(rpm,
>-                                                     struct drm_i915_private,
>-                                                     runtime_pm);
>+        struct drm_i915_private *i915 = rpm_to_i915(rpm);
>         int ret;
> 
>         ret = pm_runtime_get_sync(rpm->kdev);
>@@ -365,9 +368,7 @@ void intel_runtime_pm_put(struct intel_runtime_pm *rpm, intel_wakeref_t wref)
>  */
> void intel_runtime_pm_enable(struct intel_runtime_pm *rpm)
> {
>-        struct drm_i915_private *i915 = container_of(rpm,
>-                                                     struct drm_i915_private,
>-                                                     runtime_pm);
>+        struct drm_i915_private *i915 = rpm_to_i915(rpm);
>         struct device *kdev = rpm->kdev;
> 
>         /*
>@@ -420,9 +421,7 @@ void intel_runtime_pm_enable(struct intel_runtime_pm *rpm)
> 
> void intel_runtime_pm_disable(struct intel_runtime_pm *rpm)
> {
>-        struct drm_i915_private *i915 = container_of(rpm,
>-                                                     struct drm_i915_private,
>-                                                     runtime_pm);
>+        struct drm_i915_private *i915 = rpm_to_i915(rpm);
>         struct device *kdev = rpm->kdev;
> 
>         /* Transfer rpm ownership back to core */
>@@ -437,9 +436,7 @@ void intel_runtime_pm_disable(struct intel_runtime_pm *rpm)
> 
> void intel_runtime_pm_driver_release(struct intel_runtime_pm *rpm)
> {
>-        struct drm_i915_private *i915 = container_of(rpm,
>-                                                     struct drm_i915_private,
>-                                                     runtime_pm);
>+        struct drm_i915_private *i915 = rpm_to_i915(rpm);
>         int count = atomic_read(&rpm->wakeref_count);
> 
>         intel_wakeref_auto_fini(&rpm->userfault_wakeref);
>@@ -458,8 +455,7 @@ void intel_runtime_pm_driver_last_release(struct intel_runtime_pm *rpm)
> 
> void intel_runtime_pm_init_early(struct intel_runtime_pm *rpm)
> {
>-        struct drm_i915_private *i915 =
>-                        container_of(rpm, struct drm_i915_private, runtime_pm);
>+        struct drm_i915_private *i915 = rpm_to_i915(rpm);
>         struct pci_dev *pdev = to_pci_dev(i915->drm.dev);
>         struct device *kdev = &pdev->dev;
> 
>-- 
>2.39.2
>
Jani Nikula Dec. 7, 2023, 10:53 a.m. UTC | #3
On Tue, 05 Dec 2023, Rodrigo Vivi <rodrigo.vivi@intel.com> wrote:
> On Tue, Dec 05, 2023 at 02:15:45PM +0200, Jani Nikula wrote:
>> Reduce the duplication.
>> 
>> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
>
> Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

Thanks, pushed to din.

BR,
Jani.
Jani Nikula Dec. 7, 2023, 11:16 a.m. UTC | #4
On Wed, 06 Dec 2023, Gustavo Sousa <gustavo.sousa@intel.com> wrote:
> Quoting Jani Nikula (2023-12-05 09:15:45-03:00)
>>Reduce the duplication.
>
> By the way, is it too ambitious to dream of a to_i915() using generics?

I'm not fundamentally opposed, but there are a few open questions here.

_Generic() has been slowly cropping up since commit e8c07082a810
("Kbuild: move to -std=gnu11"). Well, maybe even before that in some
cases. But there are only 30 or so users. I'm kind of uneasy about going
"all in" with it in this fashion before there's more general approval
that it's fine. Dave, Sima, thoughts?

The other thing is that with i915 and xe display integration, we're not
sure yet where it'll go. It's possible the display code will cease to
use i915 and switch to some other device struct. See [1] for some draft
ideas. At least for display code, I'd prefer not embarking on this kind
of changes yet so we don't have to churn many times in a row.


BR,
Jani.


[1] https://patchwork.freedesktop.org/series/124286/
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/intel_runtime_pm.c b/drivers/gpu/drm/i915/intel_runtime_pm.c
index 91491111dbd5..860b51b56a92 100644
--- a/drivers/gpu/drm/i915/intel_runtime_pm.c
+++ b/drivers/gpu/drm/i915/intel_runtime_pm.c
@@ -50,6 +50,11 @@ 
  * present for a given platform.
  */
 
+static struct drm_i915_private *rpm_to_i915(struct intel_runtime_pm *rpm)
+{
+	return container_of(rpm, struct drm_i915_private, runtime_pm);
+}
+
 #if IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)
 
 static void init_intel_runtime_pm_wakeref(struct intel_runtime_pm *rpm)
@@ -158,9 +163,7 @@  intel_runtime_pm_release(struct intel_runtime_pm *rpm, int wakelock)
 static intel_wakeref_t __intel_runtime_pm_get(struct intel_runtime_pm *rpm,
 					      bool wakelock)
 {
-	struct drm_i915_private *i915 = container_of(rpm,
-						     struct drm_i915_private,
-						     runtime_pm);
+	struct drm_i915_private *i915 = rpm_to_i915(rpm);
 	int ret;
 
 	ret = pm_runtime_get_sync(rpm->kdev);
@@ -365,9 +368,7 @@  void intel_runtime_pm_put(struct intel_runtime_pm *rpm, intel_wakeref_t wref)
  */
 void intel_runtime_pm_enable(struct intel_runtime_pm *rpm)
 {
-	struct drm_i915_private *i915 = container_of(rpm,
-						     struct drm_i915_private,
-						     runtime_pm);
+	struct drm_i915_private *i915 = rpm_to_i915(rpm);
 	struct device *kdev = rpm->kdev;
 
 	/*
@@ -420,9 +421,7 @@  void intel_runtime_pm_enable(struct intel_runtime_pm *rpm)
 
 void intel_runtime_pm_disable(struct intel_runtime_pm *rpm)
 {
-	struct drm_i915_private *i915 = container_of(rpm,
-						     struct drm_i915_private,
-						     runtime_pm);
+	struct drm_i915_private *i915 = rpm_to_i915(rpm);
 	struct device *kdev = rpm->kdev;
 
 	/* Transfer rpm ownership back to core */
@@ -437,9 +436,7 @@  void intel_runtime_pm_disable(struct intel_runtime_pm *rpm)
 
 void intel_runtime_pm_driver_release(struct intel_runtime_pm *rpm)
 {
-	struct drm_i915_private *i915 = container_of(rpm,
-						     struct drm_i915_private,
-						     runtime_pm);
+	struct drm_i915_private *i915 = rpm_to_i915(rpm);
 	int count = atomic_read(&rpm->wakeref_count);
 
 	intel_wakeref_auto_fini(&rpm->userfault_wakeref);
@@ -458,8 +455,7 @@  void intel_runtime_pm_driver_last_release(struct intel_runtime_pm *rpm)
 
 void intel_runtime_pm_init_early(struct intel_runtime_pm *rpm)
 {
-	struct drm_i915_private *i915 =
-			container_of(rpm, struct drm_i915_private, runtime_pm);
+	struct drm_i915_private *i915 = rpm_to_i915(rpm);
 	struct pci_dev *pdev = to_pci_dev(i915->drm.dev);
 	struct device *kdev = &pdev->dev;