public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
* [igt-dev] [PATCH i-g-t] lib/i915/gem_mman.c: add cpu coherency mapping wrapper
@ 2020-01-14  5:27 Zbigniew Kempczyński
  2020-01-14  5:59 ` Dixit, Ashutosh
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Zbigniew Kempczyński @ 2020-01-14  5:27 UTC (permalink / raw)
  To: igt-dev

For reduce code redundancy adding a wrapper for cpu memory mapping.

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Suggested-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/i915/gem_mman.c | 50 +++++++++++++++++++++++++++++++++++++++++++++
 lib/i915/gem_mman.h |  5 +++++
 2 files changed, 55 insertions(+)

diff --git a/lib/i915/gem_mman.c b/lib/i915/gem_mman.c
index c98f02ae..c034f317 100644
--- a/lib/i915/gem_mman.c
+++ b/lib/i915/gem_mman.c
@@ -470,6 +470,56 @@ void *gem_mmap_offset__cpu(int fd, uint32_t handle, uint64_t offset,
 	return ptr;
 }
 
+/**
+ * __gem_mmap__cpu_coherent:
+ * @fd: open i915 drm file descriptor
+ * @handle: gem buffer object handle
+ * @offset: offset in the gem buffer of the mmap arena
+ * @size: size of the mmap arena
+ * @prot: memory protection bits as used by mmap()
+ *
+ * This function wraps up procedure to establish a memory mapping through
+ * direct cpu access.
+ */
+void *__gem_mmap__cpu_coherent(int fd, uint32_t handle, uint64_t offset,
+			       uint64_t size, unsigned prot)
+{
+	void *ptr = __gem_mmap_offset__cpu(fd, handle, offset, size, prot);
+
+	if (!ptr)
+		ptr = __gem_mmap__cpu(fd, handle, offset, size, prot);
+
+	return ptr;
+}
+
+/**
+ * gem_mmap__cpu_coherent:
+ * @fd: open i915 drm file descriptor
+ * @handle: gem buffer object handle
+ * @offset: offset in the gem buffer of the mmap arena
+ * @size: size of the mmap arena
+ * @prot: memory protection bits as used by mmap()
+ *
+ * Call __gem_mmap__cpu__coherent(), asserts on fail.
+ * Offset argument passed in function call must be 0. In the future
+ * when driver will allow slice mapping of buffer object this restriction
+ * will be removed.
+ *
+ * Returns: A pointer to the created memory mapping.
+ */
+void *gem_mmap__cpu_coherent(int fd, uint32_t handle, uint64_t offset,
+			     uint64_t size, unsigned prot)
+{
+	void *ptr;
+
+	igt_assert(offset == 0);
+
+	ptr = __gem_mmap__cpu_coherent(fd, handle, offset, size, prot);
+	igt_assert(ptr);
+
+	return ptr;
+}
+
 bool gem_has_mappable_ggtt(int i915)
 {
 	struct drm_i915_gem_mmap_gtt arg = {};
diff --git a/lib/i915/gem_mman.h b/lib/i915/gem_mman.h
index 7b4d6f90..2730295e 100644
--- a/lib/i915/gem_mman.h
+++ b/lib/i915/gem_mman.h
@@ -39,6 +39,9 @@ void *gem_mmap_offset__wc(int fd, uint32_t handle, uint64_t offset,
 			  uint64_t size, unsigned prot);
 void *gem_mmap__device_coherent(int fd, uint32_t handle, uint64_t offset,
 				uint64_t size, unsigned prot);
+void *gem_mmap__cpu_coherent(int fd, uint32_t handle, uint64_t offset,
+			     uint64_t size, unsigned prot);
+
 #ifndef I915_GEM_DOMAIN_WC
 #define I915_GEM_DOMAIN_WC 0x80
 #endif
@@ -58,6 +61,8 @@ void *__gem_mmap__device_coherent(int fd, uint32_t handle, uint64_t offset,
 				  uint64_t size, unsigned prot);
 void *__gem_mmap_offset(int fd, uint32_t handle, uint64_t offset, uint64_t size,
 			unsigned int prot, uint64_t flags);
+void *__gem_mmap__cpu_coherent(int fd, uint32_t handle, uint64_t offset,
+			       uint64_t size, unsigned prot);
 
 int gem_munmap(void *ptr, uint64_t size);
 
-- 
2.23.0

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-01-16 21:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-01-14  5:27 [igt-dev] [PATCH i-g-t] lib/i915/gem_mman.c: add cpu coherency mapping wrapper Zbigniew Kempczyński
2020-01-14  5:59 ` Dixit, Ashutosh
2020-01-14 11:14   ` Chris Wilson
2020-01-16 21:47     ` Dixit, Ashutosh
2020-01-14  6:12 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2020-01-16  9:18 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox