diff options
author | Antonio Argenziano <antonio.argenziano@intel.com> | 2018-02-06 16:27:14 -0800 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2018-02-07 08:26:14 +0000 |
commit | 2baf7ece5b6d2faccedc56527ec91623f41a85e4 (patch) | |
tree | c2362e443cd7b61e51e6b92f939e16a107734be5 /lib | |
parent | 3fd9b578b3138b04178b4ce8ee4a60e74a16ec91 (diff) |
lib: Move __gem_context_create to common ioctl wrapper library.
This patch adds a context creation ioctl wrapper that returns the error
for the caller to consume. Multiple tests that implemented this already,
have been changed to use the new library function.
v2:
- Add gem_require_contexts() to check for contexts support (Chris)
v3:
- Add gem_has_contexts to check for contexts support and change
gem_require_contexts to skip if contests support is not available.
(Chris)
v4:
- Cosmetic changes and use lib function in gem_ctx_create where
possible. (Michal)
v5:
- Use gem_contexts_require() in tests and fixtures. (Chris)
Signed-off-by: Antonio Argenziano <antonio.argenziano@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Michał Winiarski <michal.winiarski@intel.com>
Reviewed-by: Michał Winiarski <michal.winiarski@intel.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/i915/gem_context.c | 60 | ||||
-rw-r--r-- | lib/i915/gem_context.h | 5 |
2 files changed, 55 insertions, 10 deletions
diff --git a/lib/i915/gem_context.c b/lib/i915/gem_context.c index 8f383a97..669bd318 100644 --- a/lib/i915/gem_context.c +++ b/lib/i915/gem_context.c @@ -44,6 +44,52 @@ */ /** + * gem_has_contexts: + * @fd: open i915 drm file descriptor + * + * Queries whether context creation is supported or not. + * + * Returns: Context creation availability. + */ +bool gem_has_contexts(int fd) +{ + uint32_t ctx_id = 0; + + __gem_context_create(fd, &ctx_id); + if (ctx_id) + gem_context_destroy(fd, ctx_id); + + return ctx_id; +} + +/** + * gem_require_contexts: + * @fd: open i915 drm file descriptor + * + * This helper will automatically skip the test on platforms where context + * support is not available. + */ +void gem_require_contexts(int fd) +{ + igt_require(gem_has_contexts(fd)); +} + +int __gem_context_create(int fd, uint32_t *ctx_id) +{ + struct drm_i915_gem_context_create create; + int err = 0; + + memset(&create, 0, sizeof(create)); + if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create) == 0) + *ctx_id = create.ctx_id; + else + err = -errno; + + errno = 0; + return err; +} + +/** * gem_context_create: * @fd: open i915 drm file descriptor * @@ -55,18 +101,12 @@ */ uint32_t gem_context_create(int fd) { - struct drm_i915_gem_context_create create; + uint32_t ctx_id; - memset(&create, 0, sizeof(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); - } - igt_assert(create.ctx_id != 0); - errno = 0; + igt_assert_eq(__gem_context_create(fd, &ctx_id), 0); + igt_assert(ctx_id != 0); - return create.ctx_id; + return ctx_id; } int __gem_context_destroy(int fd, uint32_t ctx_id) diff --git a/lib/i915/gem_context.h b/lib/i915/gem_context.h index 96106b71..aef68dda 100644 --- a/lib/i915/gem_context.h +++ b/lib/i915/gem_context.h @@ -25,10 +25,15 @@ #define GEM_CONTEXT_H uint32_t gem_context_create(int fd); +int __gem_context_create(int fd, uint32_t *ctx_id); void gem_context_destroy(int fd, uint32_t ctx_id); int __gem_context_destroy(int fd, uint32_t ctx_id); + +bool gem_has_contexts(int fd); +void gem_require_contexts(int fd); void gem_context_require_bannable(int fd); void gem_context_require_param(int fd, uint64_t param); + void gem_context_get_param(int fd, struct drm_i915_gem_context_param *p); void gem_context_set_param(int fd, struct drm_i915_gem_context_param *p); int __gem_context_set_param(int fd, struct drm_i915_gem_context_param *p); |