aboutsummaryrefslogtreecommitdiffstats
path: root/src/intel/vulkan/anv_gem.c
diff options
context:
space:
mode:
authorRafael Antognolli <[email protected]>2019-01-18 15:05:55 -0800
committerRafael Antognolli <[email protected]>2020-04-20 10:59:06 -0700
commit4abf0837cdb14b10a58d28766d5c1d3698d8a6d8 (patch)
tree856033574b4b094543fc86a38ff984d81bb2ec3d /src/intel/vulkan/anv_gem.c
parent0d387da08349e1bdd222efae0657fc74009d9955 (diff)
anv: Add support for new MMAP_OFFSET ioctl.
v2: Update getparam check (Ken). [[email protected]: use 0 offset for MMAP_OFFSET] Signed-off-by: Jordan Justen <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Reviewed-by: Jordan Justen <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/1675>
Diffstat (limited to 'src/intel/vulkan/anv_gem.c')
-rw-r--r--src/intel/vulkan/anv_gem.c44
1 files changed, 40 insertions, 4 deletions
diff --git a/src/intel/vulkan/anv_gem.c b/src/intel/vulkan/anv_gem.c
index bdaebb9bc27..3ad8400caf3 100644
--- a/src/intel/vulkan/anv_gem.c
+++ b/src/intel/vulkan/anv_gem.c
@@ -67,9 +67,31 @@ anv_gem_close(struct anv_device *device, uint32_t gem_handle)
/**
* Wrapper around DRM_IOCTL_I915_GEM_MMAP. Returns MAP_FAILED on error.
*/
-void*
-anv_gem_mmap(struct anv_device *device, uint32_t gem_handle,
- uint64_t offset, uint64_t size, uint32_t flags)
+static void*
+anv_gem_mmap_offset(struct anv_device *device, uint32_t gem_handle,
+ uint64_t offset, uint64_t size, uint32_t flags)
+{
+ struct drm_i915_gem_mmap_offset gem_mmap = {
+ .handle = gem_handle,
+ .flags = (flags & I915_MMAP_WC) ?
+ I915_MMAP_OFFSET_WC : I915_MMAP_OFFSET_WB,
+ };
+ assert(offset == 0);
+
+ /* Get the fake offset back */
+ int ret = gen_ioctl(device->fd, DRM_IOCTL_I915_GEM_MMAP_OFFSET, &gem_mmap);
+ if (ret != 0)
+ return MAP_FAILED;
+
+ /* And map it */
+ void *map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
+ device->fd, gem_mmap.offset);
+ return map;
+}
+
+static void*
+anv_gem_mmap_legacy(struct anv_device *device, uint32_t gem_handle,
+ uint64_t offset, uint64_t size, uint32_t flags)
{
struct drm_i915_gem_mmap gem_mmap = {
.handle = gem_handle,
@@ -86,13 +108,27 @@ anv_gem_mmap(struct anv_device *device, uint32_t gem_handle,
return (void *)(uintptr_t) gem_mmap.addr_ptr;
}
+/**
+ * Wrapper around DRM_IOCTL_I915_GEM_MMAP. Returns MAP_FAILED on error.
+ */
+void*
+anv_gem_mmap(struct anv_device *device, uint32_t gem_handle,
+ uint64_t offset, uint64_t size, uint32_t flags)
+{
+ if (device->physical->has_mmap_offset)
+ return anv_gem_mmap_offset(device, gem_handle, offset, size, flags);
+ else
+ return anv_gem_mmap_legacy(device, gem_handle, offset, size, flags);
+}
+
/* This is just a wrapper around munmap, but it also notifies valgrind that
* this map is no longer valid. Pair this with anv_gem_mmap().
*/
void
anv_gem_munmap(struct anv_device *device, void *p, uint64_t size)
{
- VG(VALGRIND_FREELIKE_BLOCK(p, 0));
+ if (!device->physical->has_mmap_offset)
+ VG(VALGRIND_FREELIKE_BLOCK(p, 0));
munmap(p, size);
}