From: nishit.sharma@intel.com
To: igt-dev@lists.freedesktop.org, thomas.hellstrom@intel.com,
kamil.konieczny@intel.com
Subject: [PATCH i-g-t v3 1/2] lib/xe: Introduce aligned buffer mapping
Date: Thu, 12 Mar 2026 08:37:30 +0000 [thread overview]
Message-ID: <20260312083731.644793-2-nishit.sharma@intel.com> (raw)
In-Reply-To: <20260312083731.644793-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 | 42 ++++++++++++++++++++++++++++++++++++++++++
lib/xe/xe_ioctl.h | 1 +
2 files changed, 43 insertions(+)
diff --git a/lib/xe/xe_ioctl.c b/lib/xe/xe_ioctl.c
index 16aae05c9..566a08a8f 100644
--- a/lib/xe/xe_ioctl.c
+++ b/lib/xe/xe_ioctl.c
@@ -579,6 +579,48 @@ void *xe_bo_map_fixed(int fd, uint32_t bo, size_t size, uint64_t addr)
return map;
}
+/**
+ * xe_bo_map_aligned: Maps a buffer object (bo) into
+ * CPU address space with a specified alignment
+ * @fd: The device file-descriptor
+ * @bo: The buffer object
+ * @size: The size of the map
+ * @alignment: The requested map alignment
+ *
+ * Return: pointer to CPU-Mapped BO with requested alignment
+ */
+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);
+ igt_assert(((uintptr_t)map % alignment) == 0);
+
+ /* 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
next prev parent reply other threads:[~2026-03-12 8:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-12 8:37 [PATCH i-g-t v3 0/2] Unify Batch Buffer Alignment and Introduce Aligned Buffer Mapping nishit.sharma
2026-03-12 8:37 ` nishit.sharma [this message]
2026-03-12 13:06 ` [PATCH i-g-t v3 1/2] lib/xe: Introduce aligned buffer mapping Kamil Konieczny
2026-03-12 8:37 ` [PATCH i-g-t v3 2/2] tests/intel/xe_svm_usrptr_madvise: Unify batch buffer alignment nishit.sharma
2026-03-12 13:35 ` ✓ Xe.CI.BAT: success for Unify Batch Buffer Alignment and Introduce Aligned Buffer Mapping (rev3) Patchwork
2026-03-12 13:44 ` ✓ i915.CI.BAT: " Patchwork
2026-03-13 11:13 ` ✗ i915.CI.Full: failure " Patchwork
2026-03-13 11:39 ` ✓ Xe.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=20260312083731.644793-2-nishit.sharma@intel.com \
--to=nishit.sharma@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kamil.konieczny@intel.com \
--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