All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] drm/i915: Introduce intel_fb_obj() macro
@ 2014-07-08  1:21 Matt Roper
  2014-07-08  1:21 ` [PATCH 2/2] drm/i915: Make use of intel_fb_obj() Matt Roper
  0 siblings, 1 reply; 9+ messages in thread
From: Matt Roper @ 2014-07-08  1:21 UTC (permalink / raw)
  To: intel-gfx

Add an intel_fb_obj() macro that returns the GEM object associated with
a DRM framebuffer.  This macro is safe to call on NULL framebuffers (a
NULL object pointer will be returned in this case).

Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
---
 drivers/gpu/drm/i915/intel_drv.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index 45afd25..426c366 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -485,6 +485,7 @@ struct cxsr_latency {
 #define to_intel_encoder(x) container_of(x, struct intel_encoder, base)
 #define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base)
 #define to_intel_plane(x) container_of(x, struct intel_plane, base)
+#define intel_fb_obj(x) (x ? to_intel_framebuffer(x)->obj : NULL)
 
 struct intel_hdmi {
 	u32 hdmi_reg;
-- 
1.8.5.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] drm/i915: Make use of intel_fb_obj()
  2014-07-08  1:21 [PATCH 1/2] drm/i915: Introduce intel_fb_obj() macro Matt Roper
@ 2014-07-08  1:21 ` Matt Roper
  2014-07-08  6:47   ` Chris Wilson
  0 siblings, 1 reply; 9+ messages in thread
From: Matt Roper @ 2014-07-08  1:21 UTC (permalink / raw)
  To: intel-gfx

This should hopefully simplify the display code slightly and also
solves at least one mistake in intel_pipe_set_base() where
to_intel_framebuffer(fb)->obj is referenced during local variable
initialization, before 'if (!fb)' gets checked.

Potential uses of this macro were identified via the following
Coccinelle patch:

        @@
        expression E;
        @@
        * to_intel_framebuffer(E)->obj

        @@
        expression E;
        identifier I;
        @@
          I = to_intel_framebuffer(E);
          ...
        * I->obj

Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
---
 drivers/gpu/drm/i915/intel_display.c | 69 +++++++++++++-----------------------
 drivers/gpu/drm/i915/intel_dp.c      |  3 +-
 drivers/gpu/drm/i915/intel_pm.c      | 24 +++++--------
 3 files changed, 35 insertions(+), 61 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 8c3dcdf..bc2519f 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2356,7 +2356,7 @@ static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
 	struct drm_device *dev = intel_crtc->base.dev;
 	struct drm_crtc *c;
 	struct intel_crtc *i;
-	struct intel_framebuffer *fb;
+	struct drm_i915_gem_object *obj;
 
 	if (!intel_crtc->base.primary->fb)
 		return;
@@ -2380,11 +2380,11 @@ static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
 		if (!i->active || !c->primary->fb)
 			continue;
 
-		fb = to_intel_framebuffer(c->primary->fb);
-		if (i915_gem_obj_ggtt_offset(fb->obj) == plane_config->base) {
+		obj = intel_fb_obj(c->primary->fb);
+		if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) {
 			drm_framebuffer_reference(c->primary->fb);
 			intel_crtc->base.primary->fb = c->primary->fb;
-			fb->obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
+			obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
 			break;
 		}
 	}
@@ -2397,16 +2397,12 @@ static void i9xx_update_primary_plane(struct drm_crtc *crtc,
 	struct drm_device *dev = crtc->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-	struct intel_framebuffer *intel_fb;
-	struct drm_i915_gem_object *obj;
+	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
 	int plane = intel_crtc->plane;
 	unsigned long linear_offset;
 	u32 dspcntr;
 	u32 reg;
 
-	intel_fb = to_intel_framebuffer(fb);
-	obj = intel_fb->obj;
-
 	reg = DSPCNTR(plane);
 	dspcntr = I915_READ(reg);
 	/* Mask out pixel format bits in case we change it */
@@ -2487,16 +2483,12 @@ static void ironlake_update_primary_plane(struct drm_crtc *crtc,
 	struct drm_device *dev = crtc->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-	struct intel_framebuffer *intel_fb;
-	struct drm_i915_gem_object *obj;
+	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
 	int plane = intel_crtc->plane;
 	unsigned long linear_offset;
 	u32 dspcntr;
 	u32 reg;
 
-	intel_fb = to_intel_framebuffer(fb);
-	obj = intel_fb->obj;
-
 	reg = DSPCNTR(plane);
 	dspcntr = I915_READ(reg);
 	/* Mask out pixel format bits in case we change it */
@@ -2627,7 +2619,7 @@ void intel_display_handle_reset(struct drm_device *dev)
 static int
 intel_finish_fb(struct drm_framebuffer *old_fb)
 {
-	struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
+	struct drm_i915_gem_object *obj = intel_fb_obj(old_fb);
 	struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
 	bool was_interruptible = dev_priv->mm.interruptible;
 	int ret;
@@ -2674,9 +2666,9 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 	enum pipe pipe = intel_crtc->pipe;
-	struct drm_framebuffer *old_fb;
-	struct drm_i915_gem_object *obj = to_intel_framebuffer(fb)->obj;
-	struct drm_i915_gem_object *old_obj;
+	struct drm_framebuffer *old_fb = crtc->primary->fb;
+	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
+	struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb);
 	int ret;
 
 	if (intel_crtc_has_pending_flip(crtc)) {
@@ -2697,9 +2689,6 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
 		return -EINVAL;
 	}
 
-	old_fb = crtc->primary->fb;
-	old_obj = old_fb ? to_intel_framebuffer(old_fb)->obj : NULL;
-
 	mutex_lock(&dev->struct_mutex);
 	ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
 	if (ret == 0)
@@ -2755,7 +2744,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
 		if (intel_crtc->active && old_fb != fb)
 			intel_wait_for_vblank(dev, intel_crtc->pipe);
 		mutex_lock(&dev->struct_mutex);
-		intel_unpin_fb_obj(to_intel_framebuffer(old_fb)->obj);
+		intel_unpin_fb_obj(old_obj);
 		mutex_unlock(&dev->struct_mutex);
 	}
 
@@ -4929,7 +4918,7 @@ static void intel_crtc_disable(struct drm_crtc *crtc)
 	struct drm_device *dev = crtc->dev;
 	struct drm_connector *connector;
 	struct drm_i915_private *dev_priv = dev->dev_private;
-	struct drm_i915_gem_object *old_obj;
+	struct drm_i915_gem_object *old_obj = intel_fb_obj(crtc->primary->fb);
 	enum pipe pipe = to_intel_crtc(crtc)->pipe;
 
 	/* crtc should still be enabled when we disable it. */
@@ -4944,7 +4933,6 @@ static void intel_crtc_disable(struct drm_crtc *crtc)
 	assert_pipe_disabled(dev->dev_private, pipe);
 
 	if (crtc->primary->fb) {
-		old_obj = to_intel_framebuffer(crtc->primary->fb)->obj;
 		mutex_lock(&dev->struct_mutex);
 		intel_unpin_fb_obj(old_obj);
 		i915_gem_track_fb(old_obj, NULL,
@@ -9583,7 +9571,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
 	struct drm_device *dev = crtc->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_framebuffer *old_fb = crtc->primary->fb;
-	struct drm_i915_gem_object *obj = to_intel_framebuffer(fb)->obj;
+	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 	enum pipe pipe = intel_crtc->pipe;
 	struct intel_unpin_work *work;
@@ -9613,7 +9601,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
 
 	work->event = event;
 	work->crtc = crtc;
-	work->old_fb_obj = to_intel_framebuffer(old_fb)->obj;
+	work->old_fb_obj = intel_fb_obj(old_fb);
 	INIT_WORK(&work->work, intel_unpin_work_fn);
 
 	ret = drm_crtc_vblank_get(crtc);
@@ -10750,10 +10738,9 @@ static int __intel_set_mode(struct drm_crtc *crtc,
 	 * on the DPLL.
 	 */
 	for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
-		struct drm_framebuffer *old_fb;
-		struct drm_i915_gem_object *old_obj = NULL;
-		struct drm_i915_gem_object *obj =
-			to_intel_framebuffer(fb)->obj;
+		struct drm_framebuffer *old_fb = crtc->primary->fb;
+		struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb);
+		struct drm_i915_gem_object *obj = intel_fb_obj(fb);
 
 		mutex_lock(&dev->struct_mutex);
 		ret = intel_pin_and_fence_fb_obj(dev,
@@ -10764,11 +10751,8 @@ static int __intel_set_mode(struct drm_crtc *crtc,
 			mutex_unlock(&dev->struct_mutex);
 			goto done;
 		}
-		old_fb = crtc->primary->fb;
-		if (old_fb) {
-			old_obj = to_intel_framebuffer(old_fb)->obj;
+		if (old_fb)
 			intel_unpin_fb_obj(old_obj);
-		}
 		i915_gem_track_fb(old_obj, obj,
 				  INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
 		mutex_unlock(&dev->struct_mutex);
@@ -11386,9 +11370,9 @@ intel_primary_plane_disable(struct drm_plane *plane)
 	intel_disable_primary_hw_plane(dev_priv, intel_plane->plane,
 				       intel_plane->pipe);
 disable_unpin:
-	i915_gem_track_fb(to_intel_framebuffer(plane->fb)->obj, NULL,
+	i915_gem_track_fb(intel_fb_obj(plane->fb), NULL,
 			  INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
-	intel_unpin_fb_obj(to_intel_framebuffer(plane->fb)->obj);
+	intel_unpin_fb_obj(intel_fb_obj(plane->fb));
 	plane->fb = NULL;
 
 	return 0;
@@ -11405,7 +11389,8 @@ intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc,
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 	struct intel_plane *intel_plane = to_intel_plane(plane);
-	struct drm_i915_gem_object *obj, *old_obj = NULL;
+	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
+	struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
 	struct drm_rect dest = {
 		/* integer pixels */
 		.x1 = crtc_x,
@@ -11437,10 +11422,6 @@ intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc,
 	if (ret)
 		return ret;
 
-	if (plane->fb)
-		old_obj = to_intel_framebuffer(plane->fb)->obj;
-	obj = to_intel_framebuffer(fb)->obj;
-
 	/*
 	 * If the CRTC isn't enabled, we're just pinning the framebuffer,
 	 * updating the fb pointer, and returning without touching the
@@ -12951,7 +12932,7 @@ void intel_modeset_setup_hw_state(struct drm_device *dev,
 void intel_modeset_gem_init(struct drm_device *dev)
 {
 	struct drm_crtc *c;
-	struct intel_framebuffer *fb;
+	struct drm_i915_gem_object *obj;
 
 	mutex_lock(&dev->struct_mutex);
 	intel_init_gt_powersave(dev);
@@ -12971,8 +12952,8 @@ void intel_modeset_gem_init(struct drm_device *dev)
 		if (!c->primary->fb)
 			continue;
 
-		fb = to_intel_framebuffer(c->primary->fb);
-		if (intel_pin_and_fence_fb_obj(dev, fb->obj, NULL)) {
+		obj = intel_fb_obj(c->primary->fb);
+		if (intel_pin_and_fence_fb_obj(dev, obj, NULL)) {
 			DRM_ERROR("failed to pin boot fb on pipe %d\n",
 				  to_intel_crtc(c)->pipe);
 			drm_framebuffer_unreference(c->primary->fb);
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index faca6d3..a2a81d2 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -1751,7 +1751,7 @@ static bool intel_edp_psr_match_conditions(struct intel_dp *intel_dp)
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_crtc *crtc = dig_port->base.base.crtc;
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-	struct drm_i915_gem_object *obj = to_intel_framebuffer(crtc->primary->fb)->obj;
+	struct drm_i915_gem_object *obj = intel_fb_obj(crtc->primary->fb);
 	struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
 
 	dev_priv->psr.source_ok = false;
@@ -1784,7 +1784,6 @@ static bool intel_edp_psr_match_conditions(struct intel_dp *intel_dp)
 		return false;
 	}
 
-	obj = to_intel_framebuffer(crtc->primary->fb)->obj;
 	if (obj->tiling_mode != I915_TILING_X ||
 	    obj->fence_reg == I915_FENCE_REG_NONE) {
 		DRM_DEBUG_KMS("PSR condition failed: fb not tiled or fenced\n");
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index f2a4056..cb31e18 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -93,8 +93,7 @@ static void i8xx_enable_fbc(struct drm_crtc *crtc)
 	struct drm_device *dev = crtc->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_framebuffer *fb = crtc->primary->fb;
-	struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
-	struct drm_i915_gem_object *obj = intel_fb->obj;
+	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 	int cfb_pitch;
 	int i;
@@ -150,8 +149,7 @@ static void g4x_enable_fbc(struct drm_crtc *crtc)
 	struct drm_device *dev = crtc->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_framebuffer *fb = crtc->primary->fb;
-	struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
-	struct drm_i915_gem_object *obj = intel_fb->obj;
+	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 	u32 dpfc_ctl;
 
@@ -222,8 +220,7 @@ static void ironlake_enable_fbc(struct drm_crtc *crtc)
 	struct drm_device *dev = crtc->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_framebuffer *fb = crtc->primary->fb;
-	struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
-	struct drm_i915_gem_object *obj = intel_fb->obj;
+	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 	u32 dpfc_ctl;
 
@@ -289,8 +286,7 @@ static void gen7_enable_fbc(struct drm_crtc *crtc)
 	struct drm_device *dev = crtc->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_framebuffer *fb = crtc->primary->fb;
-	struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
-	struct drm_i915_gem_object *obj = intel_fb->obj;
+	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 	u32 dpfc_ctl;
 
@@ -485,7 +481,6 @@ void intel_update_fbc(struct drm_device *dev)
 	struct drm_crtc *crtc = NULL, *tmp_crtc;
 	struct intel_crtc *intel_crtc;
 	struct drm_framebuffer *fb;
-	struct intel_framebuffer *intel_fb;
 	struct drm_i915_gem_object *obj;
 	const struct drm_display_mode *adjusted_mode;
 	unsigned int max_width, max_height;
@@ -530,8 +525,7 @@ void intel_update_fbc(struct drm_device *dev)
 
 	intel_crtc = to_intel_crtc(crtc);
 	fb = crtc->primary->fb;
-	intel_fb = to_intel_framebuffer(fb);
-	obj = intel_fb->obj;
+	obj = intel_fb_obj(fb);
 	adjusted_mode = &intel_crtc->config.adjusted_mode;
 
 	if (i915.enable_fbc < 0) {
@@ -589,7 +583,7 @@ void intel_update_fbc(struct drm_device *dev)
 	if (in_dbg_master())
 		goto out_disable;
 
-	if (i915_gem_stolen_setup_compression(dev, intel_fb->obj->base.size,
+	if (i915_gem_stolen_setup_compression(dev, obj->base.size,
 					      drm_format_plane_cpp(fb->pixel_format, 0))) {
 		if (set_no_fbc_reason(dev_priv, FBC_STOLEN_TOO_SMALL))
 			DRM_DEBUG_KMS("framebuffer too large, disabling compression\n");
@@ -1599,12 +1593,12 @@ static void i9xx_update_wm(struct drm_crtc *unused_crtc)
 	DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
 
 	if (IS_I915GM(dev) && enabled) {
-		struct intel_framebuffer *fb;
+		struct drm_i915_gem_object *obj;
 
-		fb = to_intel_framebuffer(enabled->primary->fb);
+		obj = intel_fb_obj(enabled->primary->fb);
 
 		/* self-refresh seems busted with untiled */
-		if (fb->obj->tiling_mode == I915_TILING_NONE)
+		if (obj->tiling_mode == I915_TILING_NONE)
 			enabled = NULL;
 	}
 
-- 
1.8.5.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] drm/i915: Make use of intel_fb_obj()
  2014-07-08  1:21 ` [PATCH 2/2] drm/i915: Make use of intel_fb_obj() Matt Roper
@ 2014-07-08  6:47   ` Chris Wilson
  2014-07-08  9:51     ` Daniel Vetter
  2014-07-08 14:50     ` [PATCH 2/2] drm/i915: Make use of intel_fb_obj() (v2) Matt Roper
  0 siblings, 2 replies; 9+ messages in thread
From: Chris Wilson @ 2014-07-08  6:47 UTC (permalink / raw)
  To: Matt Roper; +Cc: intel-gfx

On Mon, Jul 07, 2014 at 06:21:48PM -0700, Matt Roper wrote:
> This should hopefully simplify the display code slightly and also
> solves at least one mistake in intel_pipe_set_base() where
> to_intel_framebuffer(fb)->obj is referenced during local variable
> initialization, before 'if (!fb)' gets checked.
> 
> Potential uses of this macro were identified via the following
> Coccinelle patch:
> 
>         @@
>         expression E;
>         @@
>         * to_intel_framebuffer(E)->obj
> 
>         @@
>         expression E;
>         identifier I;
>         @@
>           I = to_intel_framebuffer(E);
>           ...
>         * I->obj
> 
> Signed-off-by: Matt Roper <matthew.d.roper@intel.com>

The only drawback is that I am suddenly nervous of potential NULL
objs...

> diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
> index 8c3dcdf..bc2519f 100644
> --- a/drivers/gpu/drm/i915/intel_display.c
> +++ b/drivers/gpu/drm/i915/intel_display.c
> @@ -2356,7 +2356,7 @@ static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
>  	struct drm_device *dev = intel_crtc->base.dev;
>  	struct drm_crtc *c;
>  	struct intel_crtc *i;
> -	struct intel_framebuffer *fb;
> +	struct drm_i915_gem_object *obj;
>  
>  	if (!intel_crtc->base.primary->fb)
>  		return;
> @@ -2380,11 +2380,11 @@ static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
>  		if (!i->active || !c->primary->fb)
>  			continue;
>  
> -		fb = to_intel_framebuffer(c->primary->fb);
> -		if (i915_gem_obj_ggtt_offset(fb->obj) == plane_config->base) {
> +		obj = intel_fb_obj(c->primary->fb);

I would move this before the c->primary->fb test and rewrite the check
in terms of obj.

if (!i->active)
  continue;

obj = intel_fb_obj(c->primary->fb);
if (obj == NULL)
  continue;

> +		if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) {
>  			drm_framebuffer_reference(c->primary->fb);
>  			intel_crtc->base.primary->fb = c->primary->fb;
> -			fb->obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
> +			obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
>  			break;
>  		}
>  	}
>  

> @@ -9613,7 +9601,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
>  
>  	work->event = event;
>  	work->crtc = crtc;
> -	work->old_fb_obj = to_intel_framebuffer(old_fb)->obj;
> +	work->old_fb_obj = intel_fb_obj(old_fb);
>  	INIT_WORK(&work->work, intel_unpin_work_fn);

Here I would appreciate an
if (WARN_ON(intel_fb_obj(old_fb) == NULL))
  return -EBUSY;
at the start of intel_crtc_page_flip.
>  
>  	ret = drm_crtc_vblank_get(crtc);

> @@ -12971,8 +12952,8 @@ void intel_modeset_gem_init(struct drm_device *dev)
>  		if (!c->primary->fb)
>  			continue;
>  
> -		fb = to_intel_framebuffer(c->primary->fb);
> -		if (intel_pin_and_fence_fb_obj(dev, fb->obj, NULL)) {
> +		obj = intel_fb_obj(c->primary->fb);

Same again, change the check on primary->fb to be a check on obj.

> +		if (intel_pin_and_fence_fb_obj(dev, obj, NULL)) {
>  			DRM_ERROR("failed to pin boot fb on pipe %d\n",
>  				  to_intel_crtc(c)->pipe);
>  			drm_framebuffer_unreference(c->primary->fb);

Elsewhere a GPF for a NULL pointer is reasonable.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] drm/i915: Make use of intel_fb_obj()
  2014-07-08  6:47   ` Chris Wilson
@ 2014-07-08  9:51     ` Daniel Vetter
  2014-07-08 10:06       ` Chris Wilson
  2014-07-08 14:50     ` [PATCH 2/2] drm/i915: Make use of intel_fb_obj() (v2) Matt Roper
  1 sibling, 1 reply; 9+ messages in thread
From: Daniel Vetter @ 2014-07-08  9:51 UTC (permalink / raw)
  To: Chris Wilson, Matt Roper, intel-gfx

On Tue, Jul 08, 2014 at 07:47:13AM +0100, Chris Wilson wrote:
> On Mon, Jul 07, 2014 at 06:21:48PM -0700, Matt Roper wrote:
> > This should hopefully simplify the display code slightly and also
> > solves at least one mistake in intel_pipe_set_base() where
> > to_intel_framebuffer(fb)->obj is referenced during local variable
> > initialization, before 'if (!fb)' gets checked.
> > 
> > Potential uses of this macro were identified via the following
> > Coccinelle patch:
> > 
> >         @@
> >         expression E;
> >         @@
> >         * to_intel_framebuffer(E)->obj
> > 
> >         @@
> >         expression E;
> >         identifier I;
> >         @@
> >           I = to_intel_framebuffer(E);
> >           ...
> >         * I->obj
> > 
> > Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
> 
> The only drawback is that I am suddenly nervous of potential NULL
> objs...

I concur with Chris here, I think intel_fb_obj should be a static inline
and first check for fb == NULL. To catch abuse we could do an

if (WARN_ON(!fb))
	return NULL;

return to_intel_framebuffer(fb)->obj;

The most likely abuse is that we call intel_fb_obj before checking fb for
NULL, so the WARN is better than a BUG_ON. With that I don't think we need
to change the checks as Chris suggested here.
-Daniel

> 
> > diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
> > index 8c3dcdf..bc2519f 100644
> > --- a/drivers/gpu/drm/i915/intel_display.c
> > +++ b/drivers/gpu/drm/i915/intel_display.c
> > @@ -2356,7 +2356,7 @@ static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
> >  	struct drm_device *dev = intel_crtc->base.dev;
> >  	struct drm_crtc *c;
> >  	struct intel_crtc *i;
> > -	struct intel_framebuffer *fb;
> > +	struct drm_i915_gem_object *obj;
> >  
> >  	if (!intel_crtc->base.primary->fb)
> >  		return;
> > @@ -2380,11 +2380,11 @@ static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
> >  		if (!i->active || !c->primary->fb)
> >  			continue;
> >  
> > -		fb = to_intel_framebuffer(c->primary->fb);
> > -		if (i915_gem_obj_ggtt_offset(fb->obj) == plane_config->base) {
> > +		obj = intel_fb_obj(c->primary->fb);
> 
> I would move this before the c->primary->fb test and rewrite the check
> in terms of obj.
> 
> if (!i->active)
>   continue;
> 
> obj = intel_fb_obj(c->primary->fb);
> if (obj == NULL)
>   continue;
> 
> > +		if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) {
> >  			drm_framebuffer_reference(c->primary->fb);
> >  			intel_crtc->base.primary->fb = c->primary->fb;
> > -			fb->obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
> > +			obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
> >  			break;
> >  		}
> >  	}
> >  
> 
> > @@ -9613,7 +9601,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
> >  
> >  	work->event = event;
> >  	work->crtc = crtc;
> > -	work->old_fb_obj = to_intel_framebuffer(old_fb)->obj;
> > +	work->old_fb_obj = intel_fb_obj(old_fb);
> >  	INIT_WORK(&work->work, intel_unpin_work_fn);
> 
> Here I would appreciate an
> if (WARN_ON(intel_fb_obj(old_fb) == NULL))
>   return -EBUSY;
> at the start of intel_crtc_page_flip.
> >  
> >  	ret = drm_crtc_vblank_get(crtc);
> 
> > @@ -12971,8 +12952,8 @@ void intel_modeset_gem_init(struct drm_device *dev)
> >  		if (!c->primary->fb)
> >  			continue;
> >  
> > -		fb = to_intel_framebuffer(c->primary->fb);
> > -		if (intel_pin_and_fence_fb_obj(dev, fb->obj, NULL)) {
> > +		obj = intel_fb_obj(c->primary->fb);
> 
> Same again, change the check on primary->fb to be a check on obj.
> 
> > +		if (intel_pin_and_fence_fb_obj(dev, obj, NULL)) {
> >  			DRM_ERROR("failed to pin boot fb on pipe %d\n",
> >  				  to_intel_crtc(c)->pipe);
> >  			drm_framebuffer_unreference(c->primary->fb);
> 
> Elsewhere a GPF for a NULL pointer is reasonable.
> -Chris
> 
> -- 
> Chris Wilson, Intel Open Source Technology Centre
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] drm/i915: Make use of intel_fb_obj()
  2014-07-08  9:51     ` Daniel Vetter
@ 2014-07-08 10:06       ` Chris Wilson
  2014-07-08 11:14         ` Daniel Vetter
  0 siblings, 1 reply; 9+ messages in thread
From: Chris Wilson @ 2014-07-08 10:06 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: intel-gfx

On Tue, Jul 08, 2014 at 11:51:18AM +0200, Daniel Vetter wrote:
> On Tue, Jul 08, 2014 at 07:47:13AM +0100, Chris Wilson wrote:
> > On Mon, Jul 07, 2014 at 06:21:48PM -0700, Matt Roper wrote:
> > > This should hopefully simplify the display code slightly and also
> > > solves at least one mistake in intel_pipe_set_base() where
> > > to_intel_framebuffer(fb)->obj is referenced during local variable
> > > initialization, before 'if (!fb)' gets checked.
> > > 
> > > Potential uses of this macro were identified via the following
> > > Coccinelle patch:
> > > 
> > >         @@
> > >         expression E;
> > >         @@
> > >         * to_intel_framebuffer(E)->obj
> > > 
> > >         @@
> > >         expression E;
> > >         identifier I;
> > >         @@
> > >           I = to_intel_framebuffer(E);
> > >           ...
> > >         * I->obj
> > > 
> > > Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
> > 
> > The only drawback is that I am suddenly nervous of potential NULL
> > objs...
> 
> I concur with Chris here, I think intel_fb_obj should be a static inline
> and first check for fb == NULL. To catch abuse we could do an
> 
> if (WARN_ON(!fb))
> 	return NULL;
> 
> return to_intel_framebuffer(fb)->obj;
> 
> The most likely abuse is that we call intel_fb_obj before checking fb for
> NULL, so the WARN is better than a BUG_ON. With that I don't think we need
> to change the checks as Chris suggested here.

This came about because of one path where we should have expected fb to
be NULL. Having a WARN followed by a GPF isn't any better than the GPF,
in which case this patch is superfluous and you would rather just fix
the single callsite where the bug occurred.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] drm/i915: Make use of intel_fb_obj()
  2014-07-08 10:06       ` Chris Wilson
@ 2014-07-08 11:14         ` Daniel Vetter
  0 siblings, 0 replies; 9+ messages in thread
From: Daniel Vetter @ 2014-07-08 11:14 UTC (permalink / raw)
  To: Chris Wilson, Daniel Vetter, Matt Roper, intel-gfx

On Tue, Jul 08, 2014 at 11:06:49AM +0100, Chris Wilson wrote:
> On Tue, Jul 08, 2014 at 11:51:18AM +0200, Daniel Vetter wrote:
> > On Tue, Jul 08, 2014 at 07:47:13AM +0100, Chris Wilson wrote:
> > > On Mon, Jul 07, 2014 at 06:21:48PM -0700, Matt Roper wrote:
> > > > This should hopefully simplify the display code slightly and also
> > > > solves at least one mistake in intel_pipe_set_base() where
> > > > to_intel_framebuffer(fb)->obj is referenced during local variable
> > > > initialization, before 'if (!fb)' gets checked.
> > > > 
> > > > Potential uses of this macro were identified via the following
> > > > Coccinelle patch:
> > > > 
> > > >         @@
> > > >         expression E;
> > > >         @@
> > > >         * to_intel_framebuffer(E)->obj
> > > > 
> > > >         @@
> > > >         expression E;
> > > >         identifier I;
> > > >         @@
> > > >           I = to_intel_framebuffer(E);
> > > >           ...
> > > >         * I->obj
> > > > 
> > > > Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
> > > 
> > > The only drawback is that I am suddenly nervous of potential NULL
> > > objs...
> > 
> > I concur with Chris here, I think intel_fb_obj should be a static inline
> > and first check for fb == NULL. To catch abuse we could do an
> > 
> > if (WARN_ON(!fb))
> > 	return NULL;
> > 
> > return to_intel_framebuffer(fb)->obj;
> > 
> > The most likely abuse is that we call intel_fb_obj before checking fb for
> > NULL, so the WARN is better than a BUG_ON. With that I don't think we need
> > to change the checks as Chris suggested here.
> 
> This came about because of one path where we should have expected fb to
> be NULL. Having a WARN followed by a GPF isn't any better than the GPF,
> in which case this patch is superfluous and you would rather just fix
> the single callsite where the bug occurred.

Ok, I've missed the context then. Anyway I like the idea of intel_fb_obj
and that it'll make the code more robust against misorderings of fb ==
NULL checks. Please ignore me and proceed ;-)
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/2] drm/i915: Make use of intel_fb_obj() (v2)
  2014-07-08  6:47   ` Chris Wilson
  2014-07-08  9:51     ` Daniel Vetter
@ 2014-07-08 14:50     ` Matt Roper
  2014-07-09  9:29       ` Chris Wilson
  1 sibling, 1 reply; 9+ messages in thread
From: Matt Roper @ 2014-07-08 14:50 UTC (permalink / raw)
  To: intel-gfx

This should hopefully simplify the display code slightly and also
solves at least one mistake in intel_pipe_set_base() where
to_intel_framebuffer(fb)->obj is referenced during local variable
initialization, before 'if (!fb)' gets checked.

Potential uses of this macro were identified via the following
Coccinelle patch:

        @@
        expression E;
        @@
        * to_intel_framebuffer(E)->obj

        @@
        expression E;
        identifier I;
        @@
          I = to_intel_framebuffer(E);
          ...
        * I->obj

v2: Rewrite some NULL tests in terms of the obj rather than the fb.
    Also add a WARN() if trying to pageflip with a disabled primary
    plane.  [Suggested by Chris Wilson]

Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
---
 drivers/gpu/drm/i915/intel_display.c | 84 ++++++++++++++++--------------------
 drivers/gpu/drm/i915/intel_dp.c      |  3 +-
 drivers/gpu/drm/i915/intel_pm.c      | 24 ++++-------
 3 files changed, 48 insertions(+), 63 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index 8c3dcdf..2c72bec 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -2356,7 +2356,7 @@ static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
 	struct drm_device *dev = intel_crtc->base.dev;
 	struct drm_crtc *c;
 	struct intel_crtc *i;
-	struct intel_framebuffer *fb;
+	struct drm_i915_gem_object *obj;
 
 	if (!intel_crtc->base.primary->fb)
 		return;
@@ -2377,14 +2377,17 @@ static void intel_find_plane_obj(struct intel_crtc *intel_crtc,
 		if (c == &intel_crtc->base)
 			continue;
 
-		if (!i->active || !c->primary->fb)
+		if (!i->active)
+			continue;
+
+		obj = intel_fb_obj(c->primary->fb);
+		if (obj == NULL)
 			continue;
 
-		fb = to_intel_framebuffer(c->primary->fb);
-		if (i915_gem_obj_ggtt_offset(fb->obj) == plane_config->base) {
+		if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) {
 			drm_framebuffer_reference(c->primary->fb);
 			intel_crtc->base.primary->fb = c->primary->fb;
-			fb->obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
+			obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe);
 			break;
 		}
 	}
@@ -2397,16 +2400,12 @@ static void i9xx_update_primary_plane(struct drm_crtc *crtc,
 	struct drm_device *dev = crtc->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-	struct intel_framebuffer *intel_fb;
-	struct drm_i915_gem_object *obj;
+	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
 	int plane = intel_crtc->plane;
 	unsigned long linear_offset;
 	u32 dspcntr;
 	u32 reg;
 
-	intel_fb = to_intel_framebuffer(fb);
-	obj = intel_fb->obj;
-
 	reg = DSPCNTR(plane);
 	dspcntr = I915_READ(reg);
 	/* Mask out pixel format bits in case we change it */
@@ -2487,16 +2486,12 @@ static void ironlake_update_primary_plane(struct drm_crtc *crtc,
 	struct drm_device *dev = crtc->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-	struct intel_framebuffer *intel_fb;
-	struct drm_i915_gem_object *obj;
+	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
 	int plane = intel_crtc->plane;
 	unsigned long linear_offset;
 	u32 dspcntr;
 	u32 reg;
 
-	intel_fb = to_intel_framebuffer(fb);
-	obj = intel_fb->obj;
-
 	reg = DSPCNTR(plane);
 	dspcntr = I915_READ(reg);
 	/* Mask out pixel format bits in case we change it */
@@ -2627,7 +2622,7 @@ void intel_display_handle_reset(struct drm_device *dev)
 static int
 intel_finish_fb(struct drm_framebuffer *old_fb)
 {
-	struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
+	struct drm_i915_gem_object *obj = intel_fb_obj(old_fb);
 	struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
 	bool was_interruptible = dev_priv->mm.interruptible;
 	int ret;
@@ -2674,9 +2669,9 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 	enum pipe pipe = intel_crtc->pipe;
-	struct drm_framebuffer *old_fb;
-	struct drm_i915_gem_object *obj = to_intel_framebuffer(fb)->obj;
-	struct drm_i915_gem_object *old_obj;
+	struct drm_framebuffer *old_fb = crtc->primary->fb;
+	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
+	struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb);
 	int ret;
 
 	if (intel_crtc_has_pending_flip(crtc)) {
@@ -2697,9 +2692,6 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
 		return -EINVAL;
 	}
 
-	old_fb = crtc->primary->fb;
-	old_obj = old_fb ? to_intel_framebuffer(old_fb)->obj : NULL;
-
 	mutex_lock(&dev->struct_mutex);
 	ret = intel_pin_and_fence_fb_obj(dev, obj, NULL);
 	if (ret == 0)
@@ -2755,7 +2747,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
 		if (intel_crtc->active && old_fb != fb)
 			intel_wait_for_vblank(dev, intel_crtc->pipe);
 		mutex_lock(&dev->struct_mutex);
-		intel_unpin_fb_obj(to_intel_framebuffer(old_fb)->obj);
+		intel_unpin_fb_obj(old_obj);
 		mutex_unlock(&dev->struct_mutex);
 	}
 
@@ -4929,7 +4921,7 @@ static void intel_crtc_disable(struct drm_crtc *crtc)
 	struct drm_device *dev = crtc->dev;
 	struct drm_connector *connector;
 	struct drm_i915_private *dev_priv = dev->dev_private;
-	struct drm_i915_gem_object *old_obj;
+	struct drm_i915_gem_object *old_obj = intel_fb_obj(crtc->primary->fb);
 	enum pipe pipe = to_intel_crtc(crtc)->pipe;
 
 	/* crtc should still be enabled when we disable it. */
@@ -4944,7 +4936,6 @@ static void intel_crtc_disable(struct drm_crtc *crtc)
 	assert_pipe_disabled(dev->dev_private, pipe);
 
 	if (crtc->primary->fb) {
-		old_obj = to_intel_framebuffer(crtc->primary->fb)->obj;
 		mutex_lock(&dev->struct_mutex);
 		intel_unpin_fb_obj(old_obj);
 		i915_gem_track_fb(old_obj, NULL,
@@ -9583,7 +9574,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
 	struct drm_device *dev = crtc->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_framebuffer *old_fb = crtc->primary->fb;
-	struct drm_i915_gem_object *obj = to_intel_framebuffer(fb)->obj;
+	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 	enum pipe pipe = intel_crtc->pipe;
 	struct intel_unpin_work *work;
@@ -9591,6 +9582,14 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
 	unsigned long flags;
 	int ret;
 
+	/*
+	 * drm_mode_page_flip_ioctl() should already catch this, but double
+	 * check to be safe.  In the future we may enable pageflipping from
+	 * a disabled primary plane.
+	 */
+	if (WARN_ON(intel_fb_obj(old_fb) == NULL))
+		return -EBUSY;
+
 	/* Can't change pixel format via MI display flips. */
 	if (fb->pixel_format != crtc->primary->fb->pixel_format)
 		return -EINVAL;
@@ -9613,7 +9612,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
 
 	work->event = event;
 	work->crtc = crtc;
-	work->old_fb_obj = to_intel_framebuffer(old_fb)->obj;
+	work->old_fb_obj = intel_fb_obj(old_fb);
 	INIT_WORK(&work->work, intel_unpin_work_fn);
 
 	ret = drm_crtc_vblank_get(crtc);
@@ -10750,10 +10749,9 @@ static int __intel_set_mode(struct drm_crtc *crtc,
 	 * on the DPLL.
 	 */
 	for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
-		struct drm_framebuffer *old_fb;
-		struct drm_i915_gem_object *old_obj = NULL;
-		struct drm_i915_gem_object *obj =
-			to_intel_framebuffer(fb)->obj;
+		struct drm_framebuffer *old_fb = crtc->primary->fb;
+		struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb);
+		struct drm_i915_gem_object *obj = intel_fb_obj(fb);
 
 		mutex_lock(&dev->struct_mutex);
 		ret = intel_pin_and_fence_fb_obj(dev,
@@ -10764,11 +10762,8 @@ static int __intel_set_mode(struct drm_crtc *crtc,
 			mutex_unlock(&dev->struct_mutex);
 			goto done;
 		}
-		old_fb = crtc->primary->fb;
-		if (old_fb) {
-			old_obj = to_intel_framebuffer(old_fb)->obj;
+		if (old_fb)
 			intel_unpin_fb_obj(old_obj);
-		}
 		i915_gem_track_fb(old_obj, obj,
 				  INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
 		mutex_unlock(&dev->struct_mutex);
@@ -11386,9 +11381,9 @@ intel_primary_plane_disable(struct drm_plane *plane)
 	intel_disable_primary_hw_plane(dev_priv, intel_plane->plane,
 				       intel_plane->pipe);
 disable_unpin:
-	i915_gem_track_fb(to_intel_framebuffer(plane->fb)->obj, NULL,
+	i915_gem_track_fb(intel_fb_obj(plane->fb), NULL,
 			  INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe));
-	intel_unpin_fb_obj(to_intel_framebuffer(plane->fb)->obj);
+	intel_unpin_fb_obj(intel_fb_obj(plane->fb));
 	plane->fb = NULL;
 
 	return 0;
@@ -11405,7 +11400,8 @@ intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc,
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 	struct intel_plane *intel_plane = to_intel_plane(plane);
-	struct drm_i915_gem_object *obj, *old_obj = NULL;
+	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
+	struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
 	struct drm_rect dest = {
 		/* integer pixels */
 		.x1 = crtc_x,
@@ -11437,10 +11433,6 @@ intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc,
 	if (ret)
 		return ret;
 
-	if (plane->fb)
-		old_obj = to_intel_framebuffer(plane->fb)->obj;
-	obj = to_intel_framebuffer(fb)->obj;
-
 	/*
 	 * If the CRTC isn't enabled, we're just pinning the framebuffer,
 	 * updating the fb pointer, and returning without touching the
@@ -12951,7 +12943,7 @@ void intel_modeset_setup_hw_state(struct drm_device *dev,
 void intel_modeset_gem_init(struct drm_device *dev)
 {
 	struct drm_crtc *c;
-	struct intel_framebuffer *fb;
+	struct drm_i915_gem_object *obj;
 
 	mutex_lock(&dev->struct_mutex);
 	intel_init_gt_powersave(dev);
@@ -12968,11 +12960,11 @@ void intel_modeset_gem_init(struct drm_device *dev)
 	 */
 	mutex_lock(&dev->struct_mutex);
 	for_each_crtc(dev, c) {
-		if (!c->primary->fb)
+		obj = intel_fb_obj(c->primary->fb);
+		if (obj == NULL)
 			continue;
 
-		fb = to_intel_framebuffer(c->primary->fb);
-		if (intel_pin_and_fence_fb_obj(dev, fb->obj, NULL)) {
+		if (intel_pin_and_fence_fb_obj(dev, obj, NULL)) {
 			DRM_ERROR("failed to pin boot fb on pipe %d\n",
 				  to_intel_crtc(c)->pipe);
 			drm_framebuffer_unreference(c->primary->fb);
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index faca6d3..a2a81d2 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -1751,7 +1751,7 @@ static bool intel_edp_psr_match_conditions(struct intel_dp *intel_dp)
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_crtc *crtc = dig_port->base.base.crtc;
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-	struct drm_i915_gem_object *obj = to_intel_framebuffer(crtc->primary->fb)->obj;
+	struct drm_i915_gem_object *obj = intel_fb_obj(crtc->primary->fb);
 	struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
 
 	dev_priv->psr.source_ok = false;
@@ -1784,7 +1784,6 @@ static bool intel_edp_psr_match_conditions(struct intel_dp *intel_dp)
 		return false;
 	}
 
-	obj = to_intel_framebuffer(crtc->primary->fb)->obj;
 	if (obj->tiling_mode != I915_TILING_X ||
 	    obj->fence_reg == I915_FENCE_REG_NONE) {
 		DRM_DEBUG_KMS("PSR condition failed: fb not tiled or fenced\n");
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index f2a4056..cb31e18 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -93,8 +93,7 @@ static void i8xx_enable_fbc(struct drm_crtc *crtc)
 	struct drm_device *dev = crtc->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_framebuffer *fb = crtc->primary->fb;
-	struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
-	struct drm_i915_gem_object *obj = intel_fb->obj;
+	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 	int cfb_pitch;
 	int i;
@@ -150,8 +149,7 @@ static void g4x_enable_fbc(struct drm_crtc *crtc)
 	struct drm_device *dev = crtc->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_framebuffer *fb = crtc->primary->fb;
-	struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
-	struct drm_i915_gem_object *obj = intel_fb->obj;
+	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 	u32 dpfc_ctl;
 
@@ -222,8 +220,7 @@ static void ironlake_enable_fbc(struct drm_crtc *crtc)
 	struct drm_device *dev = crtc->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_framebuffer *fb = crtc->primary->fb;
-	struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
-	struct drm_i915_gem_object *obj = intel_fb->obj;
+	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 	u32 dpfc_ctl;
 
@@ -289,8 +286,7 @@ static void gen7_enable_fbc(struct drm_crtc *crtc)
 	struct drm_device *dev = crtc->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_framebuffer *fb = crtc->primary->fb;
-	struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
-	struct drm_i915_gem_object *obj = intel_fb->obj;
+	struct drm_i915_gem_object *obj = intel_fb_obj(fb);
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 	u32 dpfc_ctl;
 
@@ -485,7 +481,6 @@ void intel_update_fbc(struct drm_device *dev)
 	struct drm_crtc *crtc = NULL, *tmp_crtc;
 	struct intel_crtc *intel_crtc;
 	struct drm_framebuffer *fb;
-	struct intel_framebuffer *intel_fb;
 	struct drm_i915_gem_object *obj;
 	const struct drm_display_mode *adjusted_mode;
 	unsigned int max_width, max_height;
@@ -530,8 +525,7 @@ void intel_update_fbc(struct drm_device *dev)
 
 	intel_crtc = to_intel_crtc(crtc);
 	fb = crtc->primary->fb;
-	intel_fb = to_intel_framebuffer(fb);
-	obj = intel_fb->obj;
+	obj = intel_fb_obj(fb);
 	adjusted_mode = &intel_crtc->config.adjusted_mode;
 
 	if (i915.enable_fbc < 0) {
@@ -589,7 +583,7 @@ void intel_update_fbc(struct drm_device *dev)
 	if (in_dbg_master())
 		goto out_disable;
 
-	if (i915_gem_stolen_setup_compression(dev, intel_fb->obj->base.size,
+	if (i915_gem_stolen_setup_compression(dev, obj->base.size,
 					      drm_format_plane_cpp(fb->pixel_format, 0))) {
 		if (set_no_fbc_reason(dev_priv, FBC_STOLEN_TOO_SMALL))
 			DRM_DEBUG_KMS("framebuffer too large, disabling compression\n");
@@ -1599,12 +1593,12 @@ static void i9xx_update_wm(struct drm_crtc *unused_crtc)
 	DRM_DEBUG_KMS("FIFO watermarks - A: %d, B: %d\n", planea_wm, planeb_wm);
 
 	if (IS_I915GM(dev) && enabled) {
-		struct intel_framebuffer *fb;
+		struct drm_i915_gem_object *obj;
 
-		fb = to_intel_framebuffer(enabled->primary->fb);
+		obj = intel_fb_obj(enabled->primary->fb);
 
 		/* self-refresh seems busted with untiled */
-		if (fb->obj->tiling_mode == I915_TILING_NONE)
+		if (obj->tiling_mode == I915_TILING_NONE)
 			enabled = NULL;
 	}
 
-- 
1.8.5.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] drm/i915: Make use of intel_fb_obj() (v2)
  2014-07-08 14:50     ` [PATCH 2/2] drm/i915: Make use of intel_fb_obj() (v2) Matt Roper
@ 2014-07-09  9:29       ` Chris Wilson
  2014-07-09 11:52         ` Daniel Vetter
  0 siblings, 1 reply; 9+ messages in thread
From: Chris Wilson @ 2014-07-09  9:29 UTC (permalink / raw)
  To: Matt Roper; +Cc: intel-gfx

On Tue, Jul 08, 2014 at 07:50:07AM -0700, Matt Roper wrote:
> This should hopefully simplify the display code slightly and also
> solves at least one mistake in intel_pipe_set_base() where
> to_intel_framebuffer(fb)->obj is referenced during local variable
> initialization, before 'if (!fb)' gets checked.
> 
> Potential uses of this macro were identified via the following
> Coccinelle patch:
> 
>         @@
>         expression E;
>         @@
>         * to_intel_framebuffer(E)->obj
> 
>         @@
>         expression E;
>         identifier I;
>         @@
>           I = to_intel_framebuffer(E);
>           ...
>         * I->obj
> 
> v2: Rewrite some NULL tests in terms of the obj rather than the fb.
>     Also add a WARN() if trying to pageflip with a disabled primary
>     plane.  [Suggested by Chris Wilson]
> 
> Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>

And iirc 1/2 was trivial, so r-b for that as well.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] drm/i915: Make use of intel_fb_obj() (v2)
  2014-07-09  9:29       ` Chris Wilson
@ 2014-07-09 11:52         ` Daniel Vetter
  0 siblings, 0 replies; 9+ messages in thread
From: Daniel Vetter @ 2014-07-09 11:52 UTC (permalink / raw)
  To: Chris Wilson, Matt Roper, intel-gfx

On Wed, Jul 09, 2014 at 10:29:09AM +0100, Chris Wilson wrote:
> On Tue, Jul 08, 2014 at 07:50:07AM -0700, Matt Roper wrote:
> > This should hopefully simplify the display code slightly and also
> > solves at least one mistake in intel_pipe_set_base() where
> > to_intel_framebuffer(fb)->obj is referenced during local variable
> > initialization, before 'if (!fb)' gets checked.
> > 
> > Potential uses of this macro were identified via the following
> > Coccinelle patch:
> > 
> >         @@
> >         expression E;
> >         @@
> >         * to_intel_framebuffer(E)->obj
> > 
> >         @@
> >         expression E;
> >         identifier I;
> >         @@
> >           I = to_intel_framebuffer(E);
> >           ...
> >         * I->obj
> > 
> > v2: Rewrite some NULL tests in terms of the obj rather than the fb.
> >     Also add a WARN() if trying to pageflip with a disabled primary
> >     plane.  [Suggested by Chris Wilson]
> > 
> > Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
> 
> And iirc 1/2 was trivial, so r-b for that as well.

Thanks, both merged to dinq.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-07-09 11:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-08  1:21 [PATCH 1/2] drm/i915: Introduce intel_fb_obj() macro Matt Roper
2014-07-08  1:21 ` [PATCH 2/2] drm/i915: Make use of intel_fb_obj() Matt Roper
2014-07-08  6:47   ` Chris Wilson
2014-07-08  9:51     ` Daniel Vetter
2014-07-08 10:06       ` Chris Wilson
2014-07-08 11:14         ` Daniel Vetter
2014-07-08 14:50     ` [PATCH 2/2] drm/i915: Make use of intel_fb_obj() (v2) Matt Roper
2014-07-09  9:29       ` Chris Wilson
2014-07-09 11:52         ` Daniel Vetter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.