diff mbox

[igt,6/9] igt: Add a helper function for mapping VC4 BOs.

Message ID 1454535703-660-6-git-send-email-eric@anholt.net (mailing list archive)
State New, archived
Headers show

Commit Message

Eric Anholt Feb. 3, 2016, 9:41 p.m. UTC
Signed-off-by: Eric Anholt <eric@anholt.net>
---
 lib/igt_vc4.c | 20 ++++++++++++++++++++
 lib/igt_vc4.h |  1 +
 2 files changed, 21 insertions(+)
diff mbox

Patch

diff --git a/lib/igt_vc4.c b/lib/igt_vc4.c
index 62e1345..15804e9 100644
--- a/lib/igt_vc4.c
+++ b/lib/igt_vc4.c
@@ -25,6 +25,7 @@ 
 #include <string.h>
 #include <signal.h>
 #include <errno.h>
+#include <sys/mman.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
@@ -104,3 +105,22 @@  uint32_t igt_vc4_get_cleared_bo(int fd, size_t size, uint32_t clearval)
 
 	return create.handle;
 }
+
+void *
+igt_vc4_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned prot)
+{
+	struct drm_vc4_mmap_bo mmap_bo = {
+		.handle = handle,
+	};
+	int ret;
+	void *ptr;
+
+	ret = ioctl(fd, DRM_IOCTL_VC4_MMAP_BO, &mmap_bo);
+	igt_assert(ret == 0);
+
+	ptr = mmap(0, size, prot, MAP_SHARED, fd, mmap_bo.offset);
+	if (ptr == MAP_FAILED)
+		return NULL;
+	else
+		return ptr;
+}
diff --git a/lib/igt_vc4.h b/lib/igt_vc4.h
index 4622034..d428f39 100644
--- a/lib/igt_vc4.h
+++ b/lib/igt_vc4.h
@@ -25,5 +25,6 @@ 
 #define IGT_VC4_H
 
 uint32_t igt_vc4_get_cleared_bo(int fd, size_t size, uint32_t clearval);
+void *igt_vc4_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned prot);
 
 #endif /* IGT_VC4_H */