lib: Add gem_userptr and __gem_userptr helpers

This patch moves userptr definitions and helpers implementation that were
locally in gem_userptr_benchmark and gem_userptr_blits to the library, so other
tests can make use of them as well. There's no functional changes.

v2: added __ function to differentiate when errors want to be handled back in
the caller; bring gem_userptr_sync back to gem_userptr_blits; added gtkdoc.
v8: remove local_i915_gem_userptr from gem_concurrent_all.c to use the global
helpers instead.

Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
This commit is contained in:
Tiago Vignatti
2015-08-12 15:57:12 -03:00
parent 7670e286f5
commit dbcaa207a6
5 changed files with 87 additions and 137 deletions
+41
View File
@@ -896,6 +896,47 @@ void gem_context_require_ban_period(int fd)
igt_require(has_ban_period);
}
int __gem_userptr(int fd, void *ptr, int size, int read_only, uint32_t flags, uint32_t *handle)
{
struct local_i915_gem_userptr userptr;
int ret;
memset(&userptr, 0, sizeof(userptr));
userptr.user_ptr = (uintptr_t)ptr;
userptr.user_size = size;
userptr.flags = flags;
if (read_only)
userptr.flags |= LOCAL_I915_USERPTR_READ_ONLY;
ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_USERPTR, &userptr);
if (ret)
ret = errno;
igt_skip_on_f(ret == ENODEV &&
(flags & LOCAL_I915_USERPTR_UNSYNCHRONIZED) == 0 &&
!read_only,
"Skipping, synchronized mappings with no kernel CONFIG_MMU_NOTIFIER?");
if (ret == 0)
*handle = userptr.handle;
return ret;
}
/**
* gem_userptr:
* @fd: open i915 drm file descriptor
* @ptr: userptr pointer to be passed
* @size: desired size of the buffer
* @read_only: specify whether userptr is opened read only
* @flags: other userptr flags
* @handle: returned handle for the object
*
* Returns userptr handle for the GEM object.
*/
void gem_userptr(int fd, void *ptr, int size, int read_only, uint32_t flags, uint32_t *handle)
{
igt_assert_eq(__gem_userptr(fd, ptr, size, read_only, flags, handle), 0);
}
/**
* gem_sw_finish:
* @fd: open i915 drm file descriptor
+13
View File
@@ -114,6 +114,19 @@ void gem_context_get_param(int fd, struct local_i915_gem_context_param *p);
void gem_context_set_param(int fd, struct local_i915_gem_context_param *p);
int __gem_context_set_param(int fd, struct local_i915_gem_context_param *p);
#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;
#define LOCAL_I915_USERPTR_READ_ONLY (1<<0)
#define LOCAL_I915_USERPTR_UNSYNCHRONIZED (1<<31)
uint32_t handle;
};
void gem_userptr(int fd, void *ptr, int size, int read_only, uint32_t flags, uint32_t *handle);
int __gem_userptr(int fd, void *ptr, int size, int read_only, uint32_t flags, uint32_t *handle);
void gem_sw_finish(int fd, uint32_t handle);
bool gem_bo_busy(int fd, uint32_t handle);