From: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t] lib/i915/gem_mman.c: add cpu coherency mapping wrapper
Date: Tue, 14 Jan 2020 06:27:28 +0100 [thread overview]
Message-ID: <20200114052728.13313-1-zbigniew.kempczynski@intel.com> (raw)
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
next reply other threads:[~2020-01-14 5:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-14 5:27 Zbigniew Kempczyński [this message]
2020-01-14 5:59 ` [igt-dev] [PATCH i-g-t] lib/i915/gem_mman.c: add cpu coherency mapping wrapper 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
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=20200114052728.13313-1-zbigniew.kempczynski@intel.com \
--to=zbigniew.kempczynski@intel.com \
--cc=igt-dev@lists.freedesktop.org \
/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