public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: nishit.sharma@intel.com
To: igt-dev@lists.freedesktop.org, thomas.hellstrom@intel.com
Subject: [PATCH i-g-t 1/2] lib/xe: Introduce aligned buffer mapping
Date: Wed, 11 Mar 2026 17:03:53 +0000	[thread overview]
Message-ID: <20260311170354.475828-2-nishit.sharma@intel.com> (raw)
In-Reply-To: <20260311170354.475828-1-nishit.sharma@intel.com>

From: Nishit Sharma <nishit.sharma@intel.com>

Added aligned buffer mapping which is providing an interface for mapping
buffer objects with a specified alignment. This API improves
cross-platform compatibility and simplifies batch buffer setup by
eliminating the need for platform-specific address handling.

Signed-off-by: Thomas Hellstrom <thomas.hellstrom@intel.com>
Signed-off-by: Nishit Sharma <nishit.sharma@intel.com>
---
 lib/xe/xe_ioctl.c | 40 ++++++++++++++++++++++++++++++++++++++++
 lib/xe/xe_ioctl.h |  1 +
 2 files changed, 41 insertions(+)

diff --git a/lib/xe/xe_ioctl.c b/lib/xe/xe_ioctl.c
index 16aae05c9..2e9e75656 100644
--- a/lib/xe/xe_ioctl.c
+++ b/lib/xe/xe_ioctl.c
@@ -579,6 +579,46 @@ void *xe_bo_map_fixed(int fd, uint32_t bo, size_t size, uint64_t addr)
 	return map;
 }
 
+/**
+ * xe_bo_map_aligned() - Create a bo CPU map requiring an alignment for the
+ * returned address.
+ * @fd: The device file-descriptor
+ * @bo: The buffer object
+ * @size: The size of the map
+ * @alignment: The requested map alingment.
+ */
+void *xe_bo_map_aligned(int fd, uint32_t bo, size_t size, size_t alignment)
+{
+	size_t anon_size = size + alignment;
+	uint64_t anon_addr;
+	void *anon_map, *map;
+	uint64_t map_addr;
+	size_t hole_size;
+
+
+	/* Reserve a range of virtual space where we can fit an aligned map */
+	anon_map = mmap(NULL, anon_size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+	igt_assert(anon_map != MAP_FAILED);
+	anon_addr = to_user_pointer(anon_map);
+
+	/* Compute the first aligned address within the virtual space. */
+	map_addr = ALIGN(anon_addr, alignment);
+	/* Map the bo there, replacing part of the reserved virtual range. */
+	map = xe_bo_map_fixed(fd, bo, size, map_addr);
+
+	/* Unreserve part of the virtual range (if any) *before* the bo map */
+	hole_size = map_addr - anon_addr;
+	if (hole_size)
+		igt_assert(munmap(anon_map, hole_size) == 0);
+
+	/* Unreserve part of the virtual range (if any) *after* the bo map */
+	hole_size = anon_size - hole_size - size;
+	if (hole_size)
+		igt_assert(munmap(map + size, hole_size) == 0);
+
+	return map;
+}
+
 void *xe_bo_mmap_ext(int fd, uint32_t bo, size_t size, int prot)
 {
 	return __xe_bo_map(fd, bo, size, prot);
diff --git a/lib/xe/xe_ioctl.h b/lib/xe/xe_ioctl.h
index 3ea651063..b62d259fd 100644
--- a/lib/xe/xe_ioctl.h
+++ b/lib/xe/xe_ioctl.h
@@ -91,6 +91,7 @@ void xe_exec_queue_destroy(int fd, uint32_t exec_queue);
 uint64_t xe_bo_mmap_offset(int fd, uint32_t bo);
 void *xe_bo_map(int fd, uint32_t bo, size_t size);
 void *xe_bo_map_fixed(int fd, uint32_t bo, size_t size, uint64_t addr);
+void *xe_bo_map_aligned(int fd, uint32_t bo, size_t size, size_t alignment);
 void *xe_bo_mmap_ext(int fd, uint32_t bo, size_t size, int prot);
 int __xe_exec(int fd, struct drm_xe_exec *exec);
 void xe_exec(int fd, struct drm_xe_exec *exec);
-- 
2.34.1


  reply	other threads:[~2026-03-11 17:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-11 17:03 [PATCH i-g-t 0/2] Unify Batch Buffer Alignment and Introduce Aligned Buffer Mapping nishit.sharma
2026-03-11 17:03 ` nishit.sharma [this message]
2026-03-11 18:53   ` [PATCH i-g-t 1/2] lib/xe: Introduce aligned buffer mapping Hellstrom, Thomas
2026-03-11 17:03 ` [PATCH i-g-t 2/2] tests/intel/xe_svm_usrptr_madvise: Unify batch buffer alignment nishit.sharma
2026-03-11 18:54   ` Hellstrom, Thomas
2026-03-12  1:39 ` ✓ Xe.CI.BAT: success for Unify Batch Buffer Alignment and Introduce Aligned Buffer Mapping Patchwork
2026-03-12  1:48 ` ✓ i915.CI.BAT: " Patchwork
2026-03-12 21:03 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-03-12 21:45 ` ✓ i915.CI.Full: success " 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=20260311170354.475828-2-nishit.sharma@intel.com \
    --to=nishit.sharma@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=thomas.hellstrom@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox