diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2016-01-21 09:53:50 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2016-01-21 17:48:01 +0000 |
commit | 0143d4f3379b60650e4951f167822fcc76bb24d9 (patch) | |
tree | 0749af5abc1809e116cc6a5c006a698fc5d515b2 /tests/gem_concurrent_all.c | |
parent | a4493a54f348e547027eff3cb1607805f39f955d (diff) |
igt/gem_concurrent_blit: Add userptr backing storage tests
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'tests/gem_concurrent_all.c')
-rw-r--r-- | tests/gem_concurrent_all.c | 105 |
1 files changed, 104 insertions, 1 deletions
diff --git a/tests/gem_concurrent_all.c b/tests/gem_concurrent_all.c index 4b19960a..9fcced73 100644 --- a/tests/gem_concurrent_all.c +++ b/tests/gem_concurrent_all.c @@ -53,6 +53,15 @@ IGT_TEST_DESCRIPTION("Test of pread/pwrite/mmap behavior when writing to active" " buffers."); +#define LOCAL_I915_GEM_USERPTR 0x33 +#define LOCAL_IOCTL_I915_GEM_USERPTR DRM_IOWR (DRM_COMMAND_BASE + LOCAL_I915_GEM_USERPTR, struct local_i915_gem_userptr) +struct local_i915_gem_userptr { + uint64_t user_ptr; + uint64_t user_size; + uint32_t flags; + uint32_t handle; +}; + int fd, devid, gen; struct intel_batchbuffer *batch; int all; @@ -192,6 +201,14 @@ unmapped_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) return create_func(bufmgr, (uint64_t)4*width*height); } +static bool create_snoop_require(void) +{ + if (!create_cpu_require()) + return false; + + return !gem_has_llc(fd); +} + static drm_intel_bo * snoop_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) { @@ -206,6 +223,84 @@ snoop_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) return bo; } +static bool create_userptr_require(void) +{ + static int found = -1; + if (found < 0) { + struct drm_i915_gem_userptr arg; + + found = 0; + + memset(&arg, 0, sizeof(arg)); + arg.user_ptr = -4096ULL; + arg.user_size = 8192; + errno = 0; + drmIoctl(fd, LOCAL_IOCTL_I915_GEM_USERPTR, &arg); + if (errno == EFAULT) { + igt_assert(posix_memalign((void **)&arg.user_ptr, + 4096, arg.user_size) == 0); + found = drmIoctl(fd, + LOCAL_IOCTL_I915_GEM_USERPTR, + &arg) == 0; + free((void *)(uintptr_t)arg.user_ptr); + } + + } + return found; +} + +static drm_intel_bo * +userptr_create_bo(drm_intel_bufmgr *bufmgr, int width, int height) +{ + struct local_i915_gem_userptr userptr; + drm_intel_bo *bo; + + memset(&userptr, 0, sizeof(userptr)); + userptr.user_size = width * height * 4; + userptr.user_size = (userptr.user_size + 4095) & -4096; + igt_assert(posix_memalign((void **)&userptr.user_ptr, + 4096, userptr.user_size) == 0); + + do_or_die(drmIoctl(fd, LOCAL_IOCTL_I915_GEM_USERPTR, &userptr)); + bo = gem_handle_to_libdrm_bo(bufmgr, fd, "userptr", userptr.handle); + bo->virtual = (void *)(uintptr_t)userptr.user_ptr; + + return bo; +} + +static void +userptr_set_bo(drm_intel_bo *bo, uint32_t val, int width, int height) +{ + int size = width * height; + uint32_t *vaddr = bo->virtual; + + gem_set_domain(fd, bo->handle, + I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU); + while (size--) + *vaddr++ = val; +} + +static void +userptr_cmp_bo(drm_intel_bo *bo, uint32_t val, int width, int height, drm_intel_bo *tmp) +{ + int size = width * height; + uint32_t *vaddr = bo->virtual; + + gem_set_domain(fd, bo->handle, + I915_GEM_DOMAIN_CPU, 0); + while (size--) + igt_assert_eq_u32(*vaddr++, val); +} + +static void +userptr_release_bo(drm_intel_bo *bo) +{ + free(bo->virtual); + bo->virtual = NULL; + + drm_intel_bo_unreference(bo); +} + static void gtt_set_bo(drm_intel_bo *bo, uint32_t val, int width, int height) { @@ -431,13 +526,21 @@ const struct access_mode { }, { .name = "snoop", - .require = create_cpu_require, + .require = create_snoop_require, .set_bo = cpu_set_bo, .cmp_bo = cpu_cmp_bo, .create_bo = snoop_create_bo, .release_bo = nop_release_bo, }, { + .name = "userptr", + .require = create_userptr_require, + .set_bo = userptr_set_bo, + .cmp_bo = userptr_cmp_bo, + .create_bo = userptr_create_bo, + .release_bo = userptr_release_bo, + }, + { .name = "gtt", .set_bo = gtt_set_bo, .cmp_bo = gtt_cmp_bo, |