All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maarten Lankhorst <dev@lankhorst.se>
To: intel-xe@lists.freedesktop.org
Cc: Maarten Lankhorst <dev@lankhorst.se>
Subject: [PATCH v3 1/2] drm/xe/bo: Add xe_bo_addr_iter.
Date: Tue, 27 Oct 2026 19:03:55 +0100	[thread overview]
Message-ID: <20261027180354.340849-3-dev@lankhorst.se> (raw)

For display we iterate often over the pinned VRAM/system memory BO.
Add some code to speed up DPT/GGTT programming.

Signed-off-by: Maarten Lankhorst <dev@lankhorst.se>
---
Changes since v1:
- Add documentation.
---
 drivers/gpu/drm/xe/xe_bo.c | 64 +++++++++++++++++++++++++++-----------
 drivers/gpu/drm/xe/xe_bo.h |  3 ++
 2 files changed, 48 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 42a6aa1a2e4a0..0202028d38e5d 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -3478,37 +3478,63 @@ bool xe_bo_is_xe_bo(struct ttm_buffer_object *bo)
 	return false;
 }
 
-/*
- * Resolve a BO address. There is no assert to check if the proper lock is held
- * so it should only be used in cases where it is not fatal to get the wrong
- * address, such as printing debug information, but not in cases where memory is
- * written based on this result.
+/**
+ * xe_bo_addr_iter_first - Iterate over a bo
+ * @bo: The BO
+ * @cur: Pointer to a &xe_res_cursor for iteration
+ * @offset: Offset into BO.
+ * @size: Size of iteration.
+ *
+ * Initializes @cur for iteration over all GPU addresses in the range
+ * [@offset...@offset+@size).
+ *
+ * This is useful for getting the GPU address for a range of pages,
+ * rather than calling xe_bo_addr separately for each page.
  */
-dma_addr_t __xe_bo_addr(struct xe_bo *bo, u64 offset, size_t page_size)
+void xe_bo_addr_iter_first(struct xe_bo *bo, struct xe_res_cursor *cur, u64 offset, u64 size)
 {
 	struct xe_device *xe = xe_bo_device(bo);
-	struct xe_res_cursor cur;
-	u64 page;
-
-	xe_assert(xe, page_size <= PAGE_SIZE);
-	page = offset >> PAGE_SHIFT;
-	offset &= (PAGE_SIZE - 1);
 
 	if (!xe_bo_is_vram(bo) && !xe_bo_is_stolen(bo)) {
 		xe_assert(xe, bo->ttm.ttm);
 
-		xe_res_first_sg(xe_bo_sg(bo), page << PAGE_SHIFT,
-				page_size, &cur);
-		return xe_res_dma(&cur) + offset;
+		xe_res_first_sg(xe_bo_sg(bo), offset, size, cur);
 	} else {
-		struct xe_res_cursor cur;
+		xe_res_first(bo->ttm.resource, offset, size, cur);
 
-		xe_res_first(bo->ttm.resource, page << PAGE_SHIFT,
-			     page_size, &cur);
-		return cur.start + offset + vram_region_gpu_offset(bo->ttm.resource);
+		xe_assert(xe, !cur->dma_addr);
+		cur->dma_start = vram_region_gpu_offset(bo->ttm.resource);
 	}
 }
 
+/**
+ * xe_bo_addr_iter_addr - Get the BO's GPU address at current cursor.
+ * @cur: Pointer to a &xe_res_cursor initialized by xe_bo_addr_iter_first()
+ *
+ * Returns: a 64-bits DMA address for usage on the device.
+ */
+dma_addr_t xe_bo_addr_iter_addr(struct xe_res_cursor *cur)
+{
+	if (cur->mem_type == XE_PL_TT)
+		return xe_res_dma(cur);
+
+	return cur->start + cur->dma_start;
+}
+
+/*
+ * Resolve a BO address. There is no assert to check if the proper lock is held
+ * so it should only be used in cases where it is not fatal to get the wrong
+ * address, such as printing debug information, but not in cases where memory is
+ * written based on this result.
+ */
+dma_addr_t __xe_bo_addr(struct xe_bo *bo, u64 offset, size_t page_size)
+{
+	struct xe_res_cursor cur;
+
+	xe_bo_addr_iter_first(bo, &cur, offset, page_size);
+	return xe_bo_addr_iter_addr(&cur);
+}
+
 dma_addr_t xe_bo_addr(struct xe_bo *bo, u64 offset, size_t page_size)
 {
 	if (!READ_ONCE(bo->ttm.pin_count))
diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h
index 77b3a02e9b8eb..286f52225bc79 100644
--- a/drivers/gpu/drm/xe/xe_bo.h
+++ b/drivers/gpu/drm/xe/xe_bo.h
@@ -113,6 +113,7 @@ enum xe_madv_purgeable_state {
 };
 
 struct sg_table;
+struct xe_res_cursor;
 
 struct xe_bo *xe_bo_alloc(void);
 void xe_bo_free(struct xe_bo *bo);
@@ -375,6 +376,8 @@ static inline void xe_bo_unpin_map_no_vm(struct xe_bo *bo)
 }
 
 bool xe_bo_is_xe_bo(struct ttm_buffer_object *bo);
+void xe_bo_addr_iter_first(struct xe_bo *bo, struct xe_res_cursor *cur, u64 offset, u64 size);
+dma_addr_t xe_bo_addr_iter_addr(struct xe_res_cursor *cur);
 dma_addr_t __xe_bo_addr(struct xe_bo *bo, u64 offset, size_t page_size);
 dma_addr_t xe_bo_addr(struct xe_bo *bo, u64 offset, size_t page_size);
 
-- 
2.55.0


             reply	other threads:[~2026-10-27 18:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 18:03 Maarten Lankhorst [this message]
2026-10-27 18:03 ` [PATCH v3 2/2] drm/xe/display: Use xe_bo_addr_iter in remapped DPT pinning Maarten Lankhorst
2026-10-28 10:40   ` Jani Nikula
2026-10-27 18:09 ` ✗ CI.checkpatch: warning for series starting with [v3,1/2] drm/xe/bo: Add xe_bo_addr_iter Patchwork
2026-10-27 18:11 ` ✓ CI.KUnit: success " Patchwork
2026-10-27 18:49 ` ✓ Xe.CI.BAT: " Patchwork
2026-10-27 22:26 ` ✗ Xe.CI.FULL: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261027180354.340849-3-dev@lankhorst.se \
    --to=dev@lankhorst.se \
    --cc=intel-xe@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.