summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2016-03-19 13:00:29 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2016-03-19 13:15:08 +0000
commitc1fed522ae98b7c74700521f7b3e0368f0f0948e (patch)
tree73351e9723929faf2e75f894500fbcfdee64f50b
parent4e4f5b4fdca7ea2a9da79fe5b0266d1d31908e1c (diff)
lib: Replace drmIoctl() with a layer of indirection
Insted of calling drmIoctl() directly, call igt_ioctl() instead. In the normal scenario this is function pointer that calls drmIoctl() (so no penalty), but allows us to divert ioctls into our own routines for nefarious purposes. One such purpose will be to control interrupt generation into the ioctl, to be able to detect when we successfully interrupt the ioctl and when we no longer need more interrupts. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r--lib/drmtest.h4
-rw-r--r--lib/ioctl_wrappers.c41
-rw-r--r--lib/ioctl_wrappers.h2
3 files changed, 26 insertions, 21 deletions
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 9fcab931..d4884666 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -102,7 +102,7 @@ void gem_quiescent_gpu(int fd);
* successfully executed.
*/
#define do_ioctl(fd, ioc, ioc_data) do { \
- igt_assert_eq(drmIoctl((fd), (ioc), (ioc_data)), 0); \
+ igt_assert_eq(igt_ioctl((fd), (ioc), (ioc_data)), 0); \
errno = 0; \
} while (0)
@@ -117,7 +117,7 @@ void gem_quiescent_gpu(int fd);
* returning a particular value in errno.
*/
#define do_ioctl_err(fd, ioc, ioc_data, err) do { \
- igt_assert_eq(drmIoctl((fd), (ioc), (ioc_data)), -1); \
+ igt_assert_eq(igt_ioctl((fd), (ioc), (ioc_data)), -1); \
igt_assert_eq(errno, err); \
errno = 0; \
} while (0)
diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index e7577084..076bce8e 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -77,6 +77,9 @@
* distinguish them.
*/
+int (*igt_ioctl)(int fd, unsigned long request, void *arg) = drmIoctl;
+
+
/**
* gem_handle_to_libdrm_bo:
* @bufmgr: libdrm buffer manager instance
@@ -126,7 +129,7 @@ gem_get_tiling(int fd, uint32_t handle, uint32_t *tiling, uint32_t *swizzle)
memset(&get_tiling, 0, sizeof(get_tiling));
get_tiling.handle = handle;
- ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_GET_TILING, &get_tiling);
+ ret = igt_ioctl(fd, DRM_IOCTL_I915_GEM_GET_TILING, &get_tiling);
igt_assert(ret == 0);
*tiling = get_tiling.tiling_mode;
@@ -190,7 +193,7 @@ static int __gem_set_caching(int fd, uint32_t handle, uint32_t caching)
arg.caching = caching;
err = 0;
- if (drmIoctl(fd, LOCAL_DRM_IOCTL_I915_GEM_SET_CACHEING, &arg)) {
+ if (igt_ioctl(fd, LOCAL_DRM_IOCTL_I915_GEM_SET_CACHEING, &arg)) {
err = -errno;
igt_assert(errno == ENOTTY || errno == EINVAL);
}
@@ -397,7 +400,7 @@ int gem_wait(int fd, uint32_t handle, int64_t *timeout_ns)
wait.flags = 0;
ret = 0;
- if (drmIoctl(fd, DRM_IOCTL_I915_GEM_WAIT, &wait))
+ if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_WAIT, &wait))
ret = -errno;
if (timeout_ns)
@@ -460,7 +463,7 @@ uint32_t __gem_create_stolen(int fd, uint64_t size)
create.handle = 0;
create.size = size;
create.flags = I915_CREATE_PLACEMENT_STOLEN;
- ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CREATE, &create);
+ ret = igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CREATE, &create);
if (ret < 0)
return 0;
@@ -503,7 +506,7 @@ uint32_t __gem_create(int fd, int size)
memset(&create, 0, sizeof(create));
create.handle = 0;
create.size = size;
- ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
+ ret = igt_ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create);
if (ret < 0)
return 0;
@@ -546,7 +549,7 @@ uint32_t gem_create(int fd, uint64_t size)
int __gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf)
{
int err = 0;
- if (drmIoctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, execbuf))
+ if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_EXECBUFFER2, execbuf))
err = -errno;
errno = 0;
return err;
@@ -584,7 +587,7 @@ void *__gem_mmap__gtt(int fd, uint32_t handle, uint64_t size, unsigned prot)
memset(&mmap_arg, 0, sizeof(mmap_arg));
mmap_arg.handle = handle;
- if (drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg))
+ if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg))
return NULL;
ptr = mmap64(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);
@@ -650,7 +653,7 @@ bool gem_mmap__has_wc(int fd)
arg.offset = 0;
arg.size = 4096;
arg.flags = I915_MMAP_WC;
- has_wc = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_MMAP_v2, &arg) == 0;
+ has_wc = igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_MMAP_v2, &arg) == 0;
gem_close(fd, arg.handle);
}
errno = 0;
@@ -688,7 +691,7 @@ void *__gem_mmap__wc(int fd, uint32_t handle, uint64_t offset, uint64_t size, un
arg.offset = offset;
arg.size = size;
arg.flags = I915_MMAP_WC;
- if (drmIoctl(fd, LOCAL_IOCTL_I915_GEM_MMAP_v2, &arg))
+ if (igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_MMAP_v2, &arg))
return NULL;
errno = 0;
@@ -735,7 +738,7 @@ void *__gem_mmap__cpu(int fd, uint32_t handle, uint64_t offset, uint64_t size, u
mmap_arg.handle = handle;
mmap_arg.offset = offset;
mmap_arg.size = size;
- if (drmIoctl(fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg))
+ if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg))
return NULL;
errno = 0;
@@ -804,7 +807,7 @@ uint32_t gem_context_create(int fd)
struct drm_i915_gem_context_create create;
memset(&create, 0, sizeof(create));
- if (drmIoctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create)) {
+ if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create)) {
int err = -errno;
igt_skip_on(err == -ENODEV || errno == -EINVAL);
igt_assert_eq(err, 0);
@@ -823,7 +826,7 @@ int __gem_context_destroy(int fd, uint32_t ctx_id)
memset(&destroy, 0, sizeof(destroy));
destroy.ctx_id = ctx_id;
- ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_DESTROY, &destroy);
+ ret = igt_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_DESTROY, &destroy);
if (ret)
return -errno;
return 0;
@@ -868,7 +871,7 @@ int __gem_context_set_param(int fd, struct local_i915_gem_context_param *p)
{
#define LOCAL_I915_GEM_CONTEXT_SETPARAM 0x35
#define LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM DRM_IOWR (DRM_COMMAND_BASE + LOCAL_I915_GEM_CONTEXT_SETPARAM, struct local_i915_gem_context_param)
- if (drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM, p))
+ if (igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM, p))
return -errno;
errno = 0;
@@ -906,7 +909,7 @@ void gem_context_require_param(int fd, uint64_t param)
p.value = 0;
p.size = 0;
- igt_require(drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0);
+ igt_require(igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0);
}
void gem_context_require_ban_period(int fd)
@@ -921,7 +924,7 @@ void gem_context_require_ban_period(int fd)
p.value = 0;
p.size = 0;
- has_ban_period = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0;
+ has_ban_period = igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0;
}
igt_require(has_ban_period);
@@ -939,7 +942,7 @@ int __gem_userptr(int fd, void *ptr, int size, int read_only, uint32_t flags, ui
if (read_only)
userptr.flags |= LOCAL_I915_USERPTR_READ_ONLY;
- ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_USERPTR, &userptr);
+ ret = igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_USERPTR, &userptr);
if (ret)
ret = errno;
igt_skip_on_f(ret == ENODEV &&
@@ -1125,7 +1128,7 @@ static bool has_param(int fd, int param)
gp.value = &tmp;
gp.param = param;
- if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp))
+ if (igt_ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp))
return false;
errno = 0;
@@ -1425,7 +1428,7 @@ int prime_handle_to_fd_for_mmap(int fd, uint32_t handle)
args.flags = DRM_CLOEXEC | DRM_RDWR;
args.fd = -1;
- if (drmIoctl(fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args) != 0)
+ if (igt_ioctl(fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args) != 0)
return -1;
return args.fd;
@@ -1551,7 +1554,7 @@ int __kms_addfb(int fd, uint32_t handle, uint32_t width, uint32_t height,
f.pitches[0] = stride;
f.modifier[0] = modifier;
- ret = drmIoctl(fd, LOCAL_DRM_IOCTL_MODE_ADDFB2, &f);
+ ret = igt_ioctl(fd, LOCAL_DRM_IOCTL_MODE_ADDFB2, &f);
*buf_id = f.fb_id;
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index c25c4e21..d986f61f 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -35,6 +35,8 @@
#include <intel_bufmgr.h>
#include <i915_drm.h>
+extern int (*igt_ioctl)(int fd, unsigned long request, void *arg);
+
/* libdrm interfacing */
drm_intel_bo * gem_handle_to_libdrm_bo(drm_intel_bufmgr *bufmgr, int fd,
const char *name, uint32_t handle);