drm/i915: i915_gem_object_pin() takes 4 arguments
authorFrançois Tigeot <ftigeot@wolfpond.org>
Sat, 13 Sep 2014 07:13:09 +0000 (09:13 +0200)
committerFrançois Tigeot <ftigeot@wolfpond.org>
Sat, 13 Sep 2014 07:22:09 +0000 (09:22 +0200)
Obtained-from: Linux 3.8.13

sys/dev/drm/i915/i915_drv.h
sys/dev/drm/i915/i915_gem.c
sys/dev/drm/i915/i915_gem_context.c
sys/dev/drm/i915/i915_gem_execbuffer.c
sys/dev/drm/i915/intel_overlay.c
sys/dev/drm/i915/intel_pm.c
sys/dev/drm/i915/intel_ringbuffer.c

index 2ee2655..33dba21 100644 (file)
@@ -1418,8 +1418,10 @@ void i915_gem_object_init(struct drm_i915_gem_object *obj,
 struct drm_i915_gem_object *i915_gem_alloc_object(struct drm_device *dev,
                                                  size_t size);
 void i915_gem_free_object(struct drm_gem_object *obj);
-int i915_gem_object_pin(struct drm_i915_gem_object *obj, uint32_t alignment,
-    bool map_and_fenceable);
+int __must_check i915_gem_object_pin(struct drm_i915_gem_object *obj,
+                                    uint32_t alignment,
+                                    bool map_and_fenceable,
+                                    bool nonblocking);
 void i915_gem_object_unpin(struct drm_i915_gem_object *obj);
 int __must_check i915_gem_object_unbind(struct drm_i915_gem_object *obj);
 void i915_gem_release_mmap(struct drm_i915_gem_object *obj);
index 2429755..f61181d 100644 (file)
 static __must_check int i915_gem_object_flush_gpu_write_domain(struct drm_i915_gem_object *obj);
 static void i915_gem_object_flush_gtt_write_domain(struct drm_i915_gem_object *obj);
 static void i915_gem_object_flush_cpu_write_domain(struct drm_i915_gem_object *obj);
-static int i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj,
-    unsigned alignment, bool map_and_fenceable);
+static __must_check int i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj,
+                                                   unsigned alignment,
+                                                   bool map_and_fenceable,
+                                                   bool nonblocking);
 static int i915_gem_phys_pwrite(struct drm_device *dev,
     struct drm_i915_gem_object *obj, uint64_t data_ptr, uint64_t offset,
     uint64_t size, struct drm_file *file_priv);
@@ -1993,7 +1995,8 @@ i915_gem_object_get_fence(struct drm_i915_gem_object *obj)
 static int
 i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj,
                            unsigned alignment,
-                           bool map_and_fenceable)
+                           bool map_and_fenceable,
+                           bool nonblocking)
 {
        struct drm_device *dev = obj->base.dev;
        drm_i915_private_t *dev_priv = dev->dev_private;
@@ -2001,7 +2004,6 @@ i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj,
        uint32_t size, fence_size, fence_alignment, unfenced_alignment;
        bool mappable, fenceable;
        int ret;
-       bool nonblocking = false;
 
        if (obj->madv != I915_MADV_WILLNEED) {
                DRM_ERROR("Attempting to bind a purgeable object\n");
@@ -2389,7 +2391,7 @@ i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
         * (e.g. libkms for the bootup splash), we have to ensure that we
         * always use map_and_fenceable for all scanout buffers.
         */
-       ret = i915_gem_object_pin(obj, alignment, true);
+       ret = i915_gem_object_pin(obj, alignment, true, false);
        if (ret)
                return ret;
 
@@ -2529,7 +2531,8 @@ i915_gem_ring_throttle(struct drm_device *dev, struct drm_file *file)
 int
 i915_gem_object_pin(struct drm_i915_gem_object *obj,
                    uint32_t alignment,
-                   bool map_and_fenceable)
+                   bool map_and_fenceable,
+                   bool nonblocking)
 {
        int ret;
 
@@ -2553,10 +2556,16 @@ i915_gem_object_pin(struct drm_i915_gem_object *obj,
        }
 
        if (obj->gtt_space == NULL) {
+               struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
+
                ret = i915_gem_object_bind_to_gtt(obj, alignment,
-                                                 map_and_fenceable);
+                                                 map_and_fenceable,
+                                                 nonblocking);
                if (ret)
                        return ret;
+
+               if (!dev_priv->mm.aliasing_ppgtt)
+                       i915_gem_gtt_bind_object(obj, obj->cache_level);
        }
 
        if (!obj->has_global_gtt_mapping && map_and_fenceable)
@@ -2584,19 +2593,17 @@ i915_gem_pin_ioctl(struct drm_device *dev, void *data,
 {
        struct drm_i915_gem_pin *args = data;
        struct drm_i915_gem_object *obj;
-       struct drm_gem_object *gobj;
        int ret;
 
        ret = i915_mutex_lock_interruptible(dev);
        if (ret)
                return ret;
 
-       gobj = drm_gem_object_lookup(dev, file, args->handle);
-       if (gobj == NULL) {
+       obj = to_intel_bo(drm_gem_object_lookup(dev, file, args->handle));
+       if (&obj->base == NULL) {
                ret = -ENOENT;
                goto unlock;
        }
-       obj = to_intel_bo(gobj);
 
        if (obj->madv != I915_MADV_WILLNEED) {
                DRM_ERROR("Attempting to pin a purgeable buffer\n");
@@ -2606,19 +2613,20 @@ i915_gem_pin_ioctl(struct drm_device *dev, void *data,
 
        if (obj->pin_filp != NULL && obj->pin_filp != file) {
                DRM_ERROR("Already pinned in i915_gem_pin_ioctl(): %d\n",
-                       args->handle);
+                         args->handle);
                ret = -EINVAL;
                goto out;
        }
 
-       obj->user_pin_count++;
-       obj->pin_filp = file;
-       if (obj->user_pin_count == 1) {
-               ret = i915_gem_object_pin(obj, args->alignment, true);
-               if (ret != 0)
+       if (obj->user_pin_count == 0) {
+               ret = i915_gem_object_pin(obj, args->alignment, true, false);
+               if (ret)
                        goto out;
        }
 
+       obj->user_pin_count++;
+       obj->pin_filp = file;
+
        /* XXX - flush the CPU caches for pinned objects
         * as the X server doesn't manage domains yet
         */
@@ -2628,7 +2636,7 @@ out:
        drm_gem_object_unreference(&obj->base);
 unlock:
        DRM_UNLOCK(dev);
-       return (ret);
+       return ret;
 }
 
 int
@@ -3628,7 +3636,7 @@ i915_gem_obj_io(struct drm_device *dev, uint32_t handle, uint64_t data_ptr,
                            size, file);
                } else if (obj->gtt_space &&
                    obj->base.write_domain != I915_GEM_DOMAIN_CPU) {
-                       ret = i915_gem_object_pin(obj, 0, true);
+                       ret = i915_gem_object_pin(obj, 0, true, false);
                        if (ret != 0)
                                goto out;
                        ret = i915_gem_object_set_to_gtt_domain(obj, true);
@@ -3754,7 +3762,7 @@ unlocked_vmobj:
                }
        }
        if (!obj->gtt_space) {
-               ret = i915_gem_object_bind_to_gtt(obj, 0, true);
+               ret = i915_gem_object_bind_to_gtt(obj, 0, true, false);
                if (ret != 0) {
                        cause = 30;
                        goto unlock;
index 592c125..af608fb 100644 (file)
@@ -229,7 +229,7 @@ static int create_default_context(struct drm_i915_private *dev_priv)
         * default context.
         */
        dev_priv->ring[RCS].default_context = ctx;
-       ret = i915_gem_object_pin(ctx->obj, CONTEXT_ALIGN, false);
+       ret = i915_gem_object_pin(ctx->obj, CONTEXT_ALIGN, false, false);
        if (ret)
                goto err_destroy;
 
@@ -382,7 +382,7 @@ static int do_switch(struct i915_hw_context *to)
        if (from_obj == to->obj)
                return 0;
 
-       ret = i915_gem_object_pin(to->obj, CONTEXT_ALIGN, false);
+       ret = i915_gem_object_pin(to->obj, CONTEXT_ALIGN, false, false);
        if (ret)
                return ret;
 
index 1d4e721..ceb6180 100644 (file)
@@ -350,7 +350,7 @@ i915_gem_execbuffer_reserve_object(struct drm_i915_gem_object *obj,
                obj->tiling_mode != I915_TILING_NONE;
        need_mappable = need_fence || need_reloc_mappable(obj);
 
-       ret = i915_gem_object_pin(obj, entry->alignment, need_mappable);
+       ret = i915_gem_object_pin(obj, entry->alignment, need_mappable, false);
        if (ret)
                return ret;
 
index ca1100a..59bc427 100644 (file)
@@ -1342,7 +1342,7 @@ void intel_setup_overlay(struct drm_device *dev)
                }
                overlay->flip_addr = reg_bo->phys_obj->handle->busaddr;
        } else {
-               ret = i915_gem_object_pin(reg_bo, PAGE_SIZE, true);
+               ret = i915_gem_object_pin(reg_bo, PAGE_SIZE, true, false);
                if (ret) {
                        DRM_ERROR("failed to pin overlay register bo\n");
                        goto out_free_bo;
index 0ee2929..ef442f1 100644 (file)
@@ -2270,7 +2270,7 @@ intel_alloc_context_page(struct drm_device *dev)
                return NULL;
        }
 
-       ret = i915_gem_object_pin(ctx, 4096, true);
+       ret = i915_gem_object_pin(ctx, 4096, true, false);
        if (ret) {
                DRM_ERROR("failed to pin power context: %d\n", ret);
                goto err_unref;
index 3330317..f581560 100644 (file)
@@ -459,7 +459,7 @@ init_pipe_control(struct intel_ring_buffer *ring)
 
        i915_gem_object_set_cache_level(obj, I915_CACHE_LLC);
 
-       ret = i915_gem_object_pin(obj, 4096, true);
+       ret = i915_gem_object_pin(obj, 4096, true, false);
        if (ret)
                goto err_unref;
 
@@ -1085,7 +1085,7 @@ static int init_status_page(struct intel_ring_buffer *ring)
 
        i915_gem_object_set_cache_level(obj, I915_CACHE_LLC);
 
-       ret = i915_gem_object_pin(obj, 4096, true);
+       ret = i915_gem_object_pin(obj, 4096, true, false);
        if (ret != 0) {
                goto err_unref;
        }
@@ -1180,7 +1180,7 @@ static int intel_init_ring_buffer(struct drm_device *dev,
 
        ring->obj = obj;
 
-       ret = i915_gem_object_pin(obj, PAGE_SIZE, true);
+       ret = i915_gem_object_pin(obj, PAGE_SIZE, true, false);
        if (ret)
                goto err_unref;
 
@@ -1666,7 +1666,7 @@ int intel_init_render_ring_buffer(struct drm_device *dev)
                        return -ENOMEM;
                }
 
-               ret = i915_gem_object_pin(obj, 0, true);
+               ret = i915_gem_object_pin(obj, 0, true, false);
                if (ret != 0) {
                        drm_gem_object_unreference(&obj->base);
                        DRM_ERROR("Failed to ping batch bo\n");