···1470 int i;14711472 BUG_ON(obj_priv->pages_refcount == 0);014731474 if (--obj_priv->pages_refcount != 0)1475 return;···1535static void1536i915_gem_object_truncate(struct drm_gem_object *obj)1537{1538- struct inode *inode;015391540- inode = obj->filp->f_path.dentry->d_inode;1541- if (inode->i_op->truncate)1542- inode->i_op->truncate (inode);001543}15441545static inline int···2563 if (dev_priv->mm.suspended)2564 return -EBUSY;25652566- if (obj_priv->madv == I915_MADV_DONTNEED) {2567 DRM_ERROR("Attempting to bind a purgeable object\n");2568 return -EINVAL;2569 }···3932 }3933 obj_priv = obj->driver_private;39343935- if (obj_priv->madv == I915_MADV_DONTNEED) {3936- DRM_ERROR("Attempting to pin a I915_MADV_DONTNEED buffer\n");3937 drm_gem_object_unreference(obj);3938 mutex_unlock(&dev->struct_mutex);3939 return -EINVAL;···4085 return -EINVAL;4086 }40874088- obj_priv->madv = args->madv;4089- args->retained = obj_priv->gtt_space != NULL;40904091 /* if the object is no longer bound, discard its backing storage */4092 if (i915_gem_object_is_purgeable(obj_priv) &&4093 obj_priv->gtt_space == NULL)4094 i915_gem_object_truncate(obj);0040954096 drm_gem_object_unreference(obj);4097 mutex_unlock(&dev->struct_mutex);
···1470 int i;14711472 BUG_ON(obj_priv->pages_refcount == 0);1473+ BUG_ON(obj_priv->madv == __I915_MADV_PURGED);14741475 if (--obj_priv->pages_refcount != 0)1476 return;···1534static void1535i915_gem_object_truncate(struct drm_gem_object *obj)1536{1537+ struct drm_i915_gem_object *obj_priv = obj->driver_private;1538+ struct inode *inode;15391540+ inode = obj->filp->f_path.dentry->d_inode;1541+ if (inode->i_op->truncate)1542+ inode->i_op->truncate (inode);1543+1544+ obj_priv->madv = __I915_MADV_PURGED;1545}15461547static inline int···2559 if (dev_priv->mm.suspended)2560 return -EBUSY;25612562+ if (obj_priv->madv != I915_MADV_WILLNEED) {2563 DRM_ERROR("Attempting to bind a purgeable object\n");2564 return -EINVAL;2565 }···3928 }3929 obj_priv = obj->driver_private;39303931+ if (obj_priv->madv != I915_MADV_WILLNEED) {3932+ DRM_ERROR("Attempting to pin a purgeable buffer\n");3933 drm_gem_object_unreference(obj);3934 mutex_unlock(&dev->struct_mutex);3935 return -EINVAL;···4081 return -EINVAL;4082 }40834084+ if (obj_priv->madv != __I915_MADV_PURGED)4085+ obj_priv->madv = args->madv;40864087 /* if the object is no longer bound, discard its backing storage */4088 if (i915_gem_object_is_purgeable(obj_priv) &&4089 obj_priv->gtt_space == NULL)4090 i915_gem_object_truncate(obj);4091+4092+ args->retained = obj_priv->madv != __I915_MADV_PURGED;40934094 drm_gem_object_unreference(obj);4095 mutex_unlock(&dev->struct_mutex);
+1
include/drm/i915_drm.h
···671672#define I915_MADV_WILLNEED 0673#define I915_MADV_DONTNEED 10674675struct drm_i915_gem_madvise {676 /** Handle of the buffer to change the backing store advice */
···671672#define I915_MADV_WILLNEED 0673#define I915_MADV_DONTNEED 1674+#define __I915_MADV_PURGED 2 /* internal state */675676struct drm_i915_gem_madvise {677 /** Handle of the buffer to change the backing store advice */