提交 cc98b413 编写于 作者: C Chris Wilson 提交者: Daniel Vetter

drm/i915: Track when an object is pinned for use by the display engine

The display engine has unique coherency rules such that it requires
special handling to ensure that all writes to cursors, scanouts and
sprites are clflushed. This patch introduces the infrastructure to
simply track when an object is being accessed by the display engine.

v2: Explain the is_pin_display() magic as the sources for obj->pin_count
and their individual rules is not obvious. (Ville)
Signed-off-by: NChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: NVille Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
上级 c76ce038
...@@ -117,6 +117,8 @@ describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj) ...@@ -117,6 +117,8 @@ describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
seq_printf(m, " (name: %d)", obj->base.name); seq_printf(m, " (name: %d)", obj->base.name);
if (obj->pin_count) if (obj->pin_count)
seq_printf(m, " (pinned x %d)", obj->pin_count); seq_printf(m, " (pinned x %d)", obj->pin_count);
if (obj->pin_display)
seq_printf(m, " (display)");
if (obj->fence_reg != I915_FENCE_REG_NONE) if (obj->fence_reg != I915_FENCE_REG_NONE)
seq_printf(m, " (fence: %d)", obj->fence_reg); seq_printf(m, " (fence: %d)", obj->fence_reg);
list_for_each_entry(vma, &obj->vma_list, vma_link) { list_for_each_entry(vma, &obj->vma_list, vma_link) {
......
...@@ -1377,6 +1377,7 @@ struct drm_i915_gem_object { ...@@ -1377,6 +1377,7 @@ struct drm_i915_gem_object {
*/ */
unsigned int fault_mappable:1; unsigned int fault_mappable:1;
unsigned int pin_mappable:1; unsigned int pin_mappable:1;
unsigned int pin_display:1;
/* /*
* Is the GPU currently using a fence to access this buffer, * Is the GPU currently using a fence to access this buffer,
...@@ -1867,6 +1868,7 @@ int __must_check ...@@ -1867,6 +1868,7 @@ int __must_check
i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj, i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
u32 alignment, u32 alignment,
struct intel_ring_buffer *pipelined); struct intel_ring_buffer *pipelined);
void i915_gem_object_unpin_from_display_plane(struct drm_i915_gem_object *obj);
int i915_gem_attach_phys_object(struct drm_device *dev, int i915_gem_attach_phys_object(struct drm_device *dev,
struct drm_i915_gem_object *obj, struct drm_i915_gem_object *obj,
int id, int id,
......
...@@ -3501,6 +3501,22 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data, ...@@ -3501,6 +3501,22 @@ int i915_gem_set_caching_ioctl(struct drm_device *dev, void *data,
return ret; return ret;
} }
static bool is_pin_display(struct drm_i915_gem_object *obj)
{
/* There are 3 sources that pin objects:
* 1. The display engine (scanouts, sprites, cursors);
* 2. Reservations for execbuffer;
* 3. The user.
*
* We can ignore reservations as we hold the struct_mutex and
* are only called outside of the reservation path. The user
* can only increment pin_count once, and so if after
* subtracting the potential reference by the user, any pin_count
* remains, it must be due to another use by the display engine.
*/
return obj->pin_count - !!obj->user_pin_count;
}
/* /*
* Prepare buffer for display plane (scanout, cursors, etc). * Prepare buffer for display plane (scanout, cursors, etc).
* Can be called from an uninterruptible phase (modesetting) and allows * Can be called from an uninterruptible phase (modesetting) and allows
...@@ -3520,6 +3536,11 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj, ...@@ -3520,6 +3536,11 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
return ret; return ret;
} }
/* Mark the pin_display early so that we account for the
* display coherency whilst setting up the cache domains.
*/
obj->pin_display = true;
/* The display engine is not coherent with the LLC cache on gen6. As /* The display engine is not coherent with the LLC cache on gen6. As
* a result, we make sure that the pinning that is about to occur is * a result, we make sure that the pinning that is about to occur is
* done with uncached PTEs. This is lowest common denominator for all * done with uncached PTEs. This is lowest common denominator for all
...@@ -3531,7 +3552,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj, ...@@ -3531,7 +3552,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
*/ */
ret = i915_gem_object_set_cache_level(obj, I915_CACHE_NONE); ret = i915_gem_object_set_cache_level(obj, I915_CACHE_NONE);
if (ret) if (ret)
return ret; goto err_unpin_display;
/* As the user may map the buffer once pinned in the display plane /* As the user may map the buffer once pinned in the display plane
* (e.g. libkms for the bootup splash), we have to ensure that we * (e.g. libkms for the bootup splash), we have to ensure that we
...@@ -3539,7 +3560,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj, ...@@ -3539,7 +3560,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
*/ */
ret = i915_gem_obj_ggtt_pin(obj, alignment, true, false); ret = i915_gem_obj_ggtt_pin(obj, alignment, true, false);
if (ret) if (ret)
return ret; goto err_unpin_display;
i915_gem_object_flush_cpu_write_domain(obj); i915_gem_object_flush_cpu_write_domain(obj);
...@@ -3557,6 +3578,17 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj, ...@@ -3557,6 +3578,17 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
old_write_domain); old_write_domain);
return 0; return 0;
err_unpin_display:
obj->pin_display = is_pin_display(obj);
return ret;
}
void
i915_gem_object_unpin_from_display_plane(struct drm_i915_gem_object *obj)
{
i915_gem_object_unpin(obj);
obj->pin_display = is_pin_display(obj);
} }
int int
......
...@@ -1877,7 +1877,7 @@ intel_pin_and_fence_fb_obj(struct drm_device *dev, ...@@ -1877,7 +1877,7 @@ intel_pin_and_fence_fb_obj(struct drm_device *dev,
return 0; return 0;
err_unpin: err_unpin:
i915_gem_object_unpin(obj); i915_gem_object_unpin_from_display_plane(obj);
err_interruptible: err_interruptible:
dev_priv->mm.interruptible = true; dev_priv->mm.interruptible = true;
return ret; return ret;
...@@ -1886,7 +1886,7 @@ intel_pin_and_fence_fb_obj(struct drm_device *dev, ...@@ -1886,7 +1886,7 @@ intel_pin_and_fence_fb_obj(struct drm_device *dev,
void intel_unpin_fb_obj(struct drm_i915_gem_object *obj) void intel_unpin_fb_obj(struct drm_i915_gem_object *obj)
{ {
i915_gem_object_unpin_fence(obj); i915_gem_object_unpin_fence(obj);
i915_gem_object_unpin(obj); i915_gem_object_unpin_from_display_plane(obj);
} }
/* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
...@@ -6759,7 +6759,7 @@ static int intel_crtc_cursor_set(struct drm_crtc *crtc, ...@@ -6759,7 +6759,7 @@ static int intel_crtc_cursor_set(struct drm_crtc *crtc,
if (intel_crtc->cursor_bo != obj) if (intel_crtc->cursor_bo != obj)
i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo); i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
} else } else
i915_gem_object_unpin(intel_crtc->cursor_bo); i915_gem_object_unpin_from_display_plane(intel_crtc->cursor_bo);
drm_gem_object_unreference(&intel_crtc->cursor_bo->base); drm_gem_object_unreference(&intel_crtc->cursor_bo->base);
} }
...@@ -6774,7 +6774,7 @@ static int intel_crtc_cursor_set(struct drm_crtc *crtc, ...@@ -6774,7 +6774,7 @@ static int intel_crtc_cursor_set(struct drm_crtc *crtc,
return 0; return 0;
fail_unpin: fail_unpin:
i915_gem_object_unpin(obj); i915_gem_object_unpin_from_display_plane(obj);
fail_locked: fail_locked:
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
fail: fail:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册