[PATCH i-g-t 1/8] lib/xe/xe_ioctl: Add a helper to map the buffer

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Thu Mar 23 21:11:56 UTC 2023


From: Bhanuprakash Modem <bhanuprakash.modem at intel.com>

Create a new helper to map the buffer with the user PROT flags.

Signed-off-by: Bhanuprakash Modem <bhanuprakash.modem at intel.com>
---
 lib/xe/xe_ioctl.c | 15 +++++++++++++--
 lib/xe/xe_ioctl.h |  2 ++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/lib/xe/xe_ioctl.c b/lib/xe/xe_ioctl.c
index 9d5793dff7..0b5df7426c 100644
--- a/lib/xe/xe_ioctl.c
+++ b/lib/xe/xe_ioctl.c
@@ -22,6 +22,7 @@
 #include <string.h>
 #include <termios.h>
 #include <unistd.h>
+#include <stddef.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
@@ -334,18 +335,28 @@ uint64_t xe_bo_mmap_offset(int fd, uint32_t bo)
 	return mmo.offset;
 }
 
-void *xe_bo_map(int fd, uint32_t bo, size_t size)
+static void *__xe_bo_map(int fd, uint16_t bo, size_t size, int prot)
 {
 	uint64_t mmo;
 	void *map;
 
 	mmo = xe_bo_mmap_offset(fd, bo);
-	map = mmap(NULL, size, PROT_WRITE, MAP_SHARED, fd, mmo);
+	map = mmap(NULL, size, prot, MAP_SHARED, fd, mmo);
 	igt_assert(map != MAP_FAILED);
 
 	return map;
 }
 
+void *xe_bo_map(int fd, uint32_t bo, size_t size)
+{
+	return __xe_bo_map(fd, bo, size, PROT_WRITE);
+}
+
+void *xe_bo_mmap_ext(int fd, uint32_t bo, size_t size, int prot)
+{
+	return __xe_bo_map(fd, bo, size, prot);
+}
+
 static int __xe_exec(int fd, struct drm_xe_exec *exec)
 {
 	int err = 0;
diff --git a/lib/xe/xe_ioctl.h b/lib/xe/xe_ioctl.h
index 5c7e773faa..049cd183d6 100644
--- a/lib/xe/xe_ioctl.h
+++ b/lib/xe/xe_ioctl.h
@@ -11,6 +11,7 @@
 #ifndef XE_IOCTL_H
 #define XE_IOCTL_H
 
+#include <stddef.h>
 #include <stdint.h>
 #include <xe_drm.h>
 
@@ -73,6 +74,7 @@ uint32_t xe_engine_create_class(int fd, uint32_t vm, uint16_t class);
 void xe_engine_destroy(int fd, uint32_t engine);
 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_mmap_ext(int fd, uint32_t bo, size_t size, int prot);
 void xe_exec(int fd, struct drm_xe_exec *exec);
 void xe_exec_sync(int fd, uint32_t engine, uint64_t addr,
 		  struct drm_xe_sync *sync, uint32_t num_syncs);
-- 
2.34.1



More information about the Intel-gfx-trybot mailing list