|
@@ -1637,10 +1637,12 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data,
|
|
|
if (err)
|
|
|
goto out_unpin;
|
|
|
|
|
|
- if (read_domains & I915_GEM_DOMAIN_GTT)
|
|
|
- err = i915_gem_object_set_to_gtt_domain(obj, write_domain != 0);
|
|
|
+ if (read_domains & I915_GEM_DOMAIN_WC)
|
|
|
+ err = i915_gem_object_set_to_wc_domain(obj, write_domain);
|
|
|
+ else if (read_domains & I915_GEM_DOMAIN_GTT)
|
|
|
+ err = i915_gem_object_set_to_gtt_domain(obj, write_domain);
|
|
|
else
|
|
|
- err = i915_gem_object_set_to_cpu_domain(obj, write_domain != 0);
|
|
|
+ err = i915_gem_object_set_to_cpu_domain(obj, write_domain);
|
|
|
|
|
|
/* And bump the LRU for this access */
|
|
|
i915_gem_object_bump_inactive_ggtt(obj);
|
|
@@ -1784,6 +1786,9 @@ static unsigned int tile_row_pages(struct drm_i915_gem_object *obj)
|
|
|
* into userspace. (This view is aligned and sized appropriately for
|
|
|
* fenced access.)
|
|
|
*
|
|
|
+ * 2 - Recognise WC as a separate cache domain so that we can flush the
|
|
|
+ * delayed writes via GTT before performing direct access via WC.
|
|
|
+ *
|
|
|
* Restrictions:
|
|
|
*
|
|
|
* * snoopable objects cannot be accessed via the GTT. It can cause machine
|
|
@@ -1811,7 +1816,7 @@ static unsigned int tile_row_pages(struct drm_i915_gem_object *obj)
|
|
|
*/
|
|
|
int i915_gem_mmap_gtt_version(void)
|
|
|
{
|
|
|
- return 1;
|
|
|
+ return 2;
|
|
|
}
|
|
|
|
|
|
static inline struct i915_ggtt_view
|
|
@@ -3386,6 +3391,69 @@ void i915_gem_object_flush_if_display(struct drm_i915_gem_object *obj)
|
|
|
mutex_unlock(&obj->base.dev->struct_mutex);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Moves a single object to the WC read, and possibly write domain.
|
|
|
+ * @obj: object to act on
|
|
|
+ * @write: ask for write access or read only
|
|
|
+ *
|
|
|
+ * This function returns when the move is complete, including waiting on
|
|
|
+ * flushes to occur.
|
|
|
+ */
|
|
|
+int
|
|
|
+i915_gem_object_set_to_wc_domain(struct drm_i915_gem_object *obj, bool write)
|
|
|
+{
|
|
|
+ int ret;
|
|
|
+
|
|
|
+ lockdep_assert_held(&obj->base.dev->struct_mutex);
|
|
|
+
|
|
|
+ ret = i915_gem_object_wait(obj,
|
|
|
+ I915_WAIT_INTERRUPTIBLE |
|
|
|
+ I915_WAIT_LOCKED |
|
|
|
+ (write ? I915_WAIT_ALL : 0),
|
|
|
+ MAX_SCHEDULE_TIMEOUT,
|
|
|
+ NULL);
|
|
|
+ if (ret)
|
|
|
+ return ret;
|
|
|
+
|
|
|
+ if (obj->base.write_domain == I915_GEM_DOMAIN_WC)
|
|
|
+ return 0;
|
|
|
+
|
|
|
+ /* Flush and acquire obj->pages so that we are coherent through
|
|
|
+ * direct access in memory with previous cached writes through
|
|
|
+ * shmemfs and that our cache domain tracking remains valid.
|
|
|
+ * For example, if the obj->filp was moved to swap without us
|
|
|
+ * being notified and releasing the pages, we would mistakenly
|
|
|
+ * continue to assume that the obj remained out of the CPU cached
|
|
|
+ * domain.
|
|
|
+ */
|
|
|
+ ret = i915_gem_object_pin_pages(obj);
|
|
|
+ if (ret)
|
|
|
+ return ret;
|
|
|
+
|
|
|
+ flush_write_domain(obj, ~I915_GEM_DOMAIN_WC);
|
|
|
+
|
|
|
+ /* Serialise direct access to this object with the barriers for
|
|
|
+ * coherent writes from the GPU, by effectively invalidating the
|
|
|
+ * WC domain upon first access.
|
|
|
+ */
|
|
|
+ if ((obj->base.read_domains & I915_GEM_DOMAIN_WC) == 0)
|
|
|
+ mb();
|
|
|
+
|
|
|
+ /* It should now be out of any other write domains, and we can update
|
|
|
+ * the domain values for our changes.
|
|
|
+ */
|
|
|
+ GEM_BUG_ON((obj->base.write_domain & ~I915_GEM_DOMAIN_WC) != 0);
|
|
|
+ obj->base.read_domains |= I915_GEM_DOMAIN_WC;
|
|
|
+ if (write) {
|
|
|
+ obj->base.read_domains = I915_GEM_DOMAIN_WC;
|
|
|
+ obj->base.write_domain = I915_GEM_DOMAIN_WC;
|
|
|
+ obj->mm.dirty = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ i915_gem_object_unpin_pages(obj);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Moves a single object to the GTT read, and possibly write domain.
|
|
|
* @obj: object to act on
|