[Intel-gfx] [PATCH 5/5] drm/i915: Add support for getting size of the stolen region

ankitprasad.r.sharma at intel.com ankitprasad.r.sharma at intel.com
Wed Apr 29 02:31:59 PDT 2015


From: Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>

This patch extends the get_aperture_ioctl to add support
for getting total size of the stolen region and available
size of the stolen region.

testcase: igt/gem_create_stolen

Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>
---
 drivers/gpu/drm/i915/i915_drv.h |  6 ++++++
 drivers/gpu/drm/i915/i915_gem.c | 15 ++++++++++++++-
 include/uapi/drm/i915_drm.h     |  6 ++++++
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index a568cd1..a40b44f 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -3277,4 +3277,10 @@ inline static bool i915_gem_obj_is_prw_allowed(struct drm_i915_gem_object *obj)
 	return !obj->userptr.mm;
 }
 
+inline static bool i915_gem_obj_is_stolen_used(struct drm_i915_gem_object *obj)
+{
+	return obj->stolen && (i915_gem_obj_is_pinned(obj)
+			       || obj->madv == I915_MADV_WILLNEED);
+}
+
 #endif
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 3491bd3..ee93508 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -150,17 +150,30 @@ i915_gem_get_aperture_ioctl(struct drm_device *dev, void *data,
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_i915_gem_get_aperture *args = data;
 	struct drm_i915_gem_object *obj;
-	size_t pinned;
+	size_t pinned, pinned_stolen;
 
 	pinned = 0;
+	pinned_stolen = 0;
 	mutex_lock(&dev->struct_mutex);
 	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list)
 		if (i915_gem_obj_is_pinned(obj))
 			pinned += i915_gem_obj_ggtt_size(obj);
+
+	/* Calculating available stolen size */
+	list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list)
+		if (i915_gem_obj_is_stolen_used(obj))
+			pinned_stolen += i915_gem_obj_ggtt_size(obj);
+
+	list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list)
+		if (i915_gem_obj_is_stolen_used(obj))
+			pinned_stolen += i915_gem_obj_ggtt_size(obj);
+
 	mutex_unlock(&dev->struct_mutex);
 
 	args->aper_size = dev_priv->gtt.base.total;
 	args->aper_available_size = args->aper_size - pinned;
+	args->stolen_size = dev_priv->gtt.stolen_size;
+	args->stolen_available_size = args->stolen_size - pinned_stolen;
 
 	return 0;
 }
diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h
index ab4f3a9..49766b8 100644
--- a/include/uapi/drm/i915_drm.h
+++ b/include/uapi/drm/i915_drm.h
@@ -932,6 +932,12 @@ struct drm_i915_gem_get_aperture {
 	 * bytes
 	 */
 	__u64 aper_available_size;
+
+	/** Total size of the stolen region, in bytes */
+	__u64 stolen_size;
+
+	/* Available space in the stolen region, in bytes */
+	__u64 stolen_available_size;
 };
 
 struct drm_i915_get_pipe_from_crtc_id {
-- 
1.9.1



More information about the Intel-gfx mailing list