[RFC PATCH 34/42] drm/i915/query: Expose memory regions through the query uAPI

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Abdiel Janulgue <abdiel.janulgue@xxxxxxxxxxxxxxx>

Returns the available memory region areas supported by the HW.

Signed-off-by: Abdiel Janulgue <abdiel.janulgue@xxxxxxxxxxxxxxx>
Signed-off-by: Matthew Auld <matthew.auld@xxxxxxxxx>
Cc: Joonas Lahtinen <joonas.lahtinen@xxxxxxxxxxxxxxx>
---
 drivers/gpu/drm/i915/i915_query.c | 57 +++++++++++++++++++++++++++++++
 include/uapi/drm/i915_drm.h       | 40 +++++++++++++++++++++-
 2 files changed, 96 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/i915_query.c b/drivers/gpu/drm/i915/i915_query.c
index b4f26605f617..e03958c7a384 100644
--- a/drivers/gpu/drm/i915/i915_query.c
+++ b/drivers/gpu/drm/i915/i915_query.c
@@ -95,9 +95,66 @@ static int query_topology_info(struct drm_i915_private *dev_priv,
 	return total_length;
 }
 
+static int query_memregion_info(struct drm_i915_private *dev_priv,
+				struct drm_i915_query_item *query_item)
+{
+	struct drm_i915_query_memory_region_info __user *query_ptr =
+		u64_to_user_ptr(query_item->data_ptr);
+	struct drm_i915_memory_region_info __user *info_ptr =
+		&query_ptr->regions[0];
+	struct drm_i915_memory_region_info info = { };
+	struct drm_i915_query_memory_region_info query;
+	u32 total_length;
+	int ret, i;
+
+	if (query_item->flags != 0)
+		return -EINVAL;
+
+	total_length = sizeof(struct drm_i915_query_memory_region_info);
+	for (i = 0; i < ARRAY_SIZE(dev_priv->regions); ++i) {
+		struct intel_memory_region *region = dev_priv->regions[i];
+
+		if (!region)
+			continue;
+
+		total_length += sizeof(struct drm_i915_memory_region_info);
+	}
+
+	ret = init_query_item_check(&query, sizeof(query), total_length,
+				    query_item);
+	if (ret != 0)
+		return ret;
+
+	if (query.num_regions || query.rsvd[0] || query.rsvd[1] ||
+	    query.rsvd[2])
+		return -EINVAL;
+
+	for (i = 0; i < ARRAY_SIZE(dev_priv->regions); ++i) {
+		struct intel_memory_region *region = dev_priv->regions[i];
+
+		if (!region)
+			continue;
+
+		info.id = region->id;
+		info.size = resource_size(&region->region);
+
+		if (__copy_to_user(info_ptr, &info, sizeof(info)))
+			return -EFAULT;
+
+		query.num_regions++;
+		info_ptr++;
+	}
+
+	if (__copy_to_user(query_ptr, &query, sizeof(query)))
+		return -EFAULT;
+
+	return total_length;
+}
+
 static int (* const i915_query_funcs[])(struct drm_i915_private *dev_priv,
 					struct drm_i915_query_item *query_item) = {
 	query_topology_info,
+	query_memregion_info,
 };
 
 int i915_query_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h
index 26d2274b5d2b..5a102a5cb415 100644
--- a/include/uapi/drm/i915_drm.h
+++ b/include/uapi/drm/i915_drm.h
@@ -1744,6 +1744,7 @@ struct drm_i915_perf_oa_config {
 struct drm_i915_query_item {
 	__u64 query_id;
 #define DRM_I915_QUERY_TOPOLOGY_INFO    1
+#define DRM_I915_QUERY_MEMREGION_INFO   3
 
 	/*
 	 * When set to zero by userspace, this is filled with the size of the
@@ -1832,7 +1833,6 @@ struct drm_i915_query_topology_info {
 	 * Offset in data[] at which the EU masks are stored.
 	 */
 	__u16 eu_offset;
-
 	/*
 	 * Stride at which each of the EU masks for each subslice are stored.
 	 */
@@ -1841,6 +1841,44 @@ struct drm_i915_query_topology_info {
 	__u8 data[];
 };
 
+struct drm_i915_memory_region_info {
+
+	/** Base type of a region
+	 */
+#define I915_SYSTEM_MEMORY         0
+#define I915_DEVICE_MEMORY         1
+
+	/** The region id is encoded in a layout which makes it possible to
+	 *  retrieve the following information:
+	 *
+	 *  Base type: log2(ID >> 16)
+	 *  Instance:  log2(ID & 0xffff)
+	 */
+	__u32 id;
+
+	/** Reserved field. MBZ */
+	__u32 rsvd0;
+
+	/** Unused for now. MBZ */
+	__u64 flags;
+
+	__u64 size;
+
+	/** Reserved fields must be cleared to zero. */
+	__u64 rsvd1[4];
+};
+
+struct drm_i915_query_memory_region_info {
+
+	/** Number of struct drm_i915_memory_region_info structs */
+	__u32 num_regions;
+
+	/** MBZ */
+	__u32 rsvd[3];
+
+	struct drm_i915_memory_region_info regions[];
+};
+
 #if defined(__cplusplus)
 }
 #endif
-- 
2.20.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux