[PATCH v2 3/4] drm/xe: Add read/write debugfs helpers for GGTT node

Michal Wajdeczko michal.wajdeczko at intel.com
Tue Nov 12 20:04:53 UTC 2024


In upcoming patch we want to allow copying and updating PTEs
of some GGTT nodes over debugfs. Add simple helpers for that.

Signed-off-by: Michal Wajdeczko <michal.wajdeczko at intel.com>
Reviewed-by: Tomasz Lis <tomasz.lis at intel.com> #v1
Cc: Matthew Brost <matthew.brost at intel.com>
---
v2: promote simple_{read,write}_{from,to}_iomem (Matt)
---
 drivers/gpu/drm/xe/xe_ggtt.c | 52 ++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_ggtt.h |  7 +++++
 2 files changed, 59 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c
index 558fac8bb6fb..07f5b4c0e6c9 100644
--- a/drivers/gpu/drm/xe/xe_ggtt.c
+++ b/drivers/gpu/drm/xe/xe_ggtt.c
@@ -838,3 +838,55 @@ u64 xe_ggtt_print_holes(struct xe_ggtt *ggtt, u64 alignment, struct drm_printer
 
 	return total;
 }
+
+#ifdef CONFIG_DEBUG_FS
+
+/**
+ * xe_ggtt_node_read() - Copy PTEs from the GGTT node to the user space buffer
+ * @node: the GGTT node to read from
+ * @buf: the user space buffer to read to
+ * @count: the maximum number of bytes to read
+ * @ppos: the current position
+ *
+ * Return: On success, the number of bytes read is returned and the offset
+ * @ppos is advanced by this number, or negative value is returned on error.
+ */
+ssize_t xe_ggtt_node_read(struct xe_ggtt_node *node, char __user *buf,
+			  size_t count, loff_t *ppos)
+{
+	if (!xe_ggtt_node_allocated(node))
+		return 0;
+
+	xe_tile_assert(node->ggtt->tile, IS_ALIGNED(node->base.start, XE_PAGE_SIZE));
+	xe_tile_assert(node->ggtt->tile, IS_ALIGNED(node->base.size, XE_PAGE_SIZE));
+
+	return simple_read_from_iomem(buf, count, ppos,
+				      &node->ggtt->gsm[node->base.start / XE_PAGE_SIZE],
+				      size_mul(sizeof(u64), node->base.size / XE_PAGE_SIZE));
+}
+
+/**
+ * xe_ggtt_node_write() - Update PTEs of the GGTT node using data from the user space buffer
+ * @node: the GGTT node to write to
+ * @buf: the user space buffer to read from
+ * @count: the maximum number of bytes to read
+ * @ppos: the current position
+ *
+ * Return: On success, the number of bytes written is returned and the offset
+ * @ppos is advanced by this number, or negative value is returned on error.
+ */
+ssize_t xe_ggtt_node_write(struct xe_ggtt_node *node, const char __user *buf,
+			   size_t count, loff_t *ppos)
+{
+	if (!xe_ggtt_node_allocated(node))
+		return -ENXIO;
+
+	xe_tile_assert(node->ggtt->tile, IS_ALIGNED(node->base.start, XE_PAGE_SIZE));
+	xe_tile_assert(node->ggtt->tile, IS_ALIGNED(node->base.size, XE_PAGE_SIZE));
+
+	return simple_write_to_iomem(&node->ggtt->gsm[node->base.start / XE_PAGE_SIZE],
+				     size_mul(sizeof(u64), node->base.size / XE_PAGE_SIZE),
+				     ppos, buf, count);
+}
+
+#endif
diff --git a/drivers/gpu/drm/xe/xe_ggtt.h b/drivers/gpu/drm/xe/xe_ggtt.h
index 27e7d67de004..64746e23053e 100644
--- a/drivers/gpu/drm/xe/xe_ggtt.h
+++ b/drivers/gpu/drm/xe/xe_ggtt.h
@@ -34,6 +34,13 @@ u64 xe_ggtt_largest_hole(struct xe_ggtt *ggtt, u64 alignment, u64 *spare);
 int xe_ggtt_dump(struct xe_ggtt *ggtt, struct drm_printer *p);
 u64 xe_ggtt_print_holes(struct xe_ggtt *ggtt, u64 alignment, struct drm_printer *p);
 
+#ifdef CONFIG_DEBUG_FS
+ssize_t xe_ggtt_node_read(struct xe_ggtt_node *node, char __user *buf,
+			  size_t count, loff_t *pos);
+ssize_t xe_ggtt_node_write(struct xe_ggtt_node *node, const char __user *buf,
+			   size_t count, loff_t *pos);
+#endif
+
 #ifdef CONFIG_PCI_IOV
 void xe_ggtt_assign(const struct xe_ggtt_node *node, u16 vfid);
 #endif
-- 
2.43.0



More information about the Intel-xe mailing list