[Intel-gfx] [PATCH i-g-t v2 2/2] lib/ioctl_wrappers: Add gem_has_softpin
Michał Winiarski
michal.winiarski at intel.com
Mon Jan 25 10:35:02 PST 2016
We can move it from softpin test into lib, and since softpin support is
highly unlikely to go away in-between getparam ioctl calls, let's just
do a single call and store the value.
v2: rebase
Signed-off-by: Michał Winiarski <michal.winiarski at intel.com>
Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
---
lib/ioctl_wrappers.c | 29 +++++++++++++++++++++++++++++
lib/ioctl_wrappers.h | 1 +
tests/gem_softpin.c | 22 +---------------------
3 files changed, 31 insertions(+), 21 deletions(-)
diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index b534b03..34351c9 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -1242,6 +1242,35 @@ uint64_t gem_mappable_aperture_size(void)
return pci_dev->regions[bar].size;
}
+#define LOCAL_I915_PARAM_HAS_EXEC_SOFTPIN 37
+/**
+ * gem_has_softpin:
+ * @fd: open i915 drm file descriptor
+ *
+ * Feature test macro to query whether the softpinning functionality is
+ * supported.
+ *
+ * Returns: Whether softpin support is available
+ */
+bool gem_has_softpin(int fd)
+{
+ static int has_softpin = -1;
+
+ if (has_softpin < 0) {
+ struct drm_i915_getparam gp;
+
+ memset(&gp, 0, sizeof(gp));
+ gp.param = LOCAL_I915_PARAM_HAS_EXEC_SOFTPIN;
+ gp.value = &has_softpin;
+
+ has_softpin = 0;
+ ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
+ errno = 0;
+ }
+
+ return has_softpin;
+}
+
/**
* gem_require_caching:
* @fd: open i915 drm file descriptor
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index a6bf700..04ac9bb 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -132,6 +132,7 @@ int gem_available_fences(int fd);
uint64_t gem_available_aperture_size(int fd);
uint64_t gem_aperture_size(int fd);
uint64_t gem_mappable_aperture_size(void);
+bool gem_has_softpin(int fd);
/* check functions which auto-skip tests by calling igt_skip() */
void gem_require_caching(int fd);
diff --git a/tests/gem_softpin.c b/tests/gem_softpin.c
index c2bf37c..bfd02b0 100644
--- a/tests/gem_softpin.c
+++ b/tests/gem_softpin.c
@@ -31,26 +31,6 @@
#define EXEC_OBJECT_PINNED (1<<4)
#define EXEC_OBJECT_SUPPORTS_48B_ADDRESS (1<<3)
-/* has_softpin_support
- * Finds if softpin feature is supported
- * @fd DRM fd
-*/
-static bool has_softpin_support(int fd)
-{
- struct drm_i915_getparam gp;
- int val = 0;
-
- memset(&gp, 0, sizeof(gp));
- gp.param = 37; /* I915_PARAM_HAS_EXEC_SOFTPIN */
- gp.value = &val;
-
- if (drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp))
- return 0;
-
- errno = 0;
- return (val == 1);
-}
-
/* gen8_canonical_addr
* Used to convert any address into canonical form, i.e. [63:48] == [47].
* Based on kernel's sign_extend64 implementation.
@@ -494,7 +474,7 @@ igt_main
igt_fixture {
fd = drm_open_driver_master(DRIVER_INTEL);
- igt_require(has_softpin_support(fd));
+ igt_require(gem_has_softpin(fd));
}
igt_subtest("invalid")
--
2.5.0
More information about the Intel-gfx
mailing list