summaryrefslogtreecommitdiff
path: root/lib/ioctl_wrappers.c
diff options
context:
space:
mode:
authorAnkitprasad Sharma <ankitprasad.r.sharma@intel.com>2015-12-02 14:54:50 +0530
committerThomas Wood <thomas.wood@intel.com>2015-12-03 10:40:29 +0000
commit70c3be83a0638cb65518ad2536719996d1f5a40c (patch)
treee66b8a24731eb51d25d5e07509c8ecd5b3eb55eb /lib/ioctl_wrappers.c
parent2db78a4995a8ee298ae0cd68879baf80407a0e5e (diff)
igt/gem_stolen: Verifying extended gem_create ioctl
This patch adds the testcases for verifying the new extended gem_create ioctl. By means of this extended ioctl, memory placement of the GEM object can be specified, i.e. either shmem or stolen memory. These testcases include functional tests and interface tests for testing the gem_create ioctl call for stolen memory placement v2: Testing pread/pwrite functionality for stolen backed objects, added local struct for extended gem_create and gem_get_aperture, until headers catch up (Chris) v3: Removed get_aperture related functions, extended gem_pread to compare speeds for user pages with and without page faults, unexposed local_gem_create struct, changed gem_create_stolen usage (Chris) v4: Splitting patch to remove changes from gem_pread/gem_pwrite to another patch (Ankit) v5: Fixed Rebase conflicts (Ankit) Added IGT_TEST_DESCRIPTION (Thomas Wood) v6: Added __gem_create_stolen for user to handle error, updated gem_create_stolen to align with gem_create function, corrected fill_purge test (out of bound access), added testcase to validate allocating of more than 32 bit sized buffers (Tvrtko) v7: Removed unused variables, Corrected comments & formatting (Tvrtko) Signed-off-by: Ankitprasad Sharma <ankitprasad.r.sharma@intel.com> Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Signed-off-by: Thomas Wood <thomas.wood@intel.com>
Diffstat (limited to 'lib/ioctl_wrappers.c')
-rw-r--r--lib/ioctl_wrappers.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index c24f7057..e348f265 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -390,6 +390,78 @@ void gem_sync(int fd, uint32_t handle)
I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
}
+bool gem_create__has_stolen_support(int fd)
+{
+ static int has_stolen_support = -1;
+ struct drm_i915_getparam gp;
+ int val = -1;
+
+ if (has_stolen_support < 0) {
+ memset(&gp, 0, sizeof(gp));
+ gp.param = 36; /* CREATE_VERSION */
+ gp.value = &val;
+
+ /* Do we have the extended gem_create_ioctl? */
+ ioctl(fd, DRM_IOCTL_I915_GETPARAM, &gp);
+ has_stolen_support = val >= 2;
+ }
+
+ return has_stolen_support;
+}
+
+struct local_i915_gem_create_v2 {
+ uint64_t size;
+ uint32_t handle;
+ uint32_t pad;
+#define I915_CREATE_PLACEMENT_STOLEN (1<<0)
+ uint32_t flags;
+};
+
+#define LOCAL_IOCTL_I915_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_CREATE, struct local_i915_gem_create_v2)
+uint32_t __gem_create_stolen(int fd, uint64_t size)
+{
+ struct local_i915_gem_create_v2 create;
+ int ret;
+
+ memset(&create, 0, sizeof(create));
+ create.handle = 0;
+ create.size = size;
+ create.flags = I915_CREATE_PLACEMENT_STOLEN;
+ ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CREATE, &create);
+
+ if (ret < 0)
+ return 0;
+
+ errno = 0;
+ return create.handle;
+}
+
+/**
+ * gem_create_stolen:
+ * @fd: open i915 drm file descriptor
+ * @size: desired size of the buffer
+ *
+ * This wraps the new GEM_CREATE ioctl, which allocates a new gem buffer
+ * object of @size and placement in stolen memory region.
+ *
+ * Returns: The file-private handle of the created buffer object
+ */
+
+uint32_t gem_create_stolen(int fd, uint64_t size)
+{
+ struct local_i915_gem_create_v2 create;
+
+ memset(&create, 0, sizeof(create));
+ create.handle = 0;
+ create.size = size;
+ create.flags = I915_CREATE_PLACEMENT_STOLEN;
+ do_ioctl(fd, LOCAL_IOCTL_I915_GEM_CREATE, &create);
+ igt_assert(create.handle);
+
+ return create.handle;
+}
+
+
uint32_t __gem_create(int fd, int size)
{
struct drm_i915_gem_create create;