summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrzej Turko <andrzej.turko@linux.intel.com>2021-01-11 11:17:50 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2021-01-11 11:51:48 +0000
commit97a6f0b56ad9c4339be49a955671ebfc47b3133d (patch)
tree5235230793c120339e644526733ab2f942dce7d2
parent65c5eea699141e6f942ce0a8fc85db76ce53cd19 (diff)
lib/i915: Split gem_create.c from ioctl_wrappers.c
In preparation for a variation on the exisiting GEM_CREATE API, split the ioctl from out of the large ioctl_wrappers.c Signed-off-by: Andrzej Turko <andrzej.turko@linux.intel.com> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r--benchmarks/gem_blt.c1
-rw-r--r--benchmarks/gem_busy.c1
-rw-r--r--benchmarks/gem_create.c3
-rw-r--r--benchmarks/gem_exec_ctx.c3
-rw-r--r--benchmarks/gem_exec_fault.c5
-rw-r--r--benchmarks/gem_exec_nop.c5
-rw-r--r--benchmarks/gem_exec_reloc.c8
-rw-r--r--benchmarks/gem_exec_trace.c5
-rw-r--r--benchmarks/gem_latency.c3
-rw-r--r--benchmarks/gem_prw.c3
-rw-r--r--benchmarks/gem_set_domain.c3
-rw-r--r--benchmarks/gem_syslatency.c1
-rw-r--r--benchmarks/gem_wsim.c7
-rw-r--r--benchmarks/prime_lookup.c5
-rw-r--r--lib/Makefile.sources1
-rw-r--r--lib/i915/gem.h5
-rw-r--r--lib/i915/gem_create.c48
-rw-r--r--lib/i915/gem_mman.c1
-rw-r--r--lib/i915/gem_mman.h4
-rw-r--r--lib/igt_draw.c1
-rw-r--r--lib/igt_fb.c3
-rw-r--r--lib/intel_batchbuffer.c1
-rw-r--r--lib/intel_bufops.c2
-rw-r--r--lib/ioctl_wrappers.c38
-rw-r--r--lib/ioctl_wrappers.h2
-rw-r--r--lib/meson.build1
-rw-r--r--tests/i915/gem_basic.c2
-rw-r--r--tests/i915/gem_exec_basic.c2
-rw-r--r--tests/i915/gem_fd_exhaustion.c2
-rw-r--r--tests/i915/gem_fence_thrash.c1
-rw-r--r--tests/i915/gem_fence_upload.c2
-rw-r--r--tests/i915/gem_flink_race.c1
-rw-r--r--tests/i915/gem_gtt_cpu_tlb.c2
-rw-r--r--tests/i915/gem_gtt_speed.c2
-rw-r--r--tests/i915/gem_lut_handle.c2
-rw-r--r--tests/i915/gem_madvise.c1
-rw-r--r--tests/i915/gem_mmap.c2
-rw-r--r--tests/i915/gem_mmap_wc.c2
-rw-r--r--tests/i915/gem_pread.c3
-rw-r--r--tests/i915/gem_pwrite.c2
-rw-r--r--tests/i915/gem_readwrite.c2
-rw-r--r--tests/i915/gem_set_tiling_vs_gtt.c2
-rw-r--r--tests/i915/gem_set_tiling_vs_pwrite.c2
-rw-r--r--tests/i915/gem_tiled_pread_basic.c3
-rw-r--r--tests/i915/gem_tiled_pread_pwrite.c4
-rw-r--r--tests/i915/gem_tiled_swapping.c4
-rw-r--r--tests/i915/gem_tiled_wb.c2
-rw-r--r--tests/i915/gem_tiled_wc.c2
-rw-r--r--tests/i915/gem_tiling_max_stride.c2
-rw-r--r--tests/i915/i915_module_load.c13
-rw-r--r--tests/kms_available_modes_crc.c1
-rw-r--r--tests/kms_big_fb.c2
-rw-r--r--tests/kms_ccs.c2
-rwxr-xr-xtests/kms_flip.c1
-rw-r--r--tests/kms_getfb.c3
-rw-r--r--tests/prime_mmap.c5
-rw-r--r--tests/prime_mmap_kms.c2
-rw-r--r--tests/prime_self_import.c1
-rw-r--r--tools/intel_reg.c1
59 files changed, 161 insertions, 79 deletions
diff --git a/benchmarks/gem_blt.c b/benchmarks/gem_blt.c
index 5c6d28d3..34b82a87 100644
--- a/benchmarks/gem_blt.c
+++ b/benchmarks/gem_blt.c
@@ -41,6 +41,7 @@
#include <time.h>
#include "drm.h"
+#include "i915/gem.h"
#define COPY_BLT_CMD (2<<29|0x53<<22|0x6)
#define BLT_WRITE_ALPHA (1<<21)
diff --git a/benchmarks/gem_busy.c b/benchmarks/gem_busy.c
index 50410150..69be8c17 100644
--- a/benchmarks/gem_busy.c
+++ b/benchmarks/gem_busy.c
@@ -45,6 +45,7 @@
#include "intel_chipset.h"
#include "intel_reg.h"
#include "igt_stats.h"
+#include "i915/gem.h"
#include "i915/gem_mman.h"
#define ENGINE_FLAGS (I915_EXEC_RING_MASK | I915_EXEC_BSD_MASK)
diff --git a/benchmarks/gem_create.c b/benchmarks/gem_create.c
index 5dd996c9..d4e297ed 100644
--- a/benchmarks/gem_create.c
+++ b/benchmarks/gem_create.c
@@ -39,11 +39,12 @@
#include <time.h>
#include "drm.h"
-#include "ioctl_wrappers.h"
#include "drmtest.h"
+#include "i915/gem.h"
#include "igt_aux.h"
#include "igt_stats.h"
#include "intel_reg.h"
+#include "ioctl_wrappers.h"
#define OBJECT_SIZE (1<<23)
diff --git a/benchmarks/gem_exec_ctx.c b/benchmarks/gem_exec_ctx.c
index a2e8d93e..b6f403fb 100644
--- a/benchmarks/gem_exec_ctx.c
+++ b/benchmarks/gem_exec_ctx.c
@@ -39,11 +39,12 @@
#include <time.h>
#include "drm.h"
-#include "ioctl_wrappers.h"
#include "drmtest.h"
+#include "i915/gem.h"
#include "intel_io.h"
#include "intel_reg.h"
#include "igt_stats.h"
+#include "ioctl_wrappers.h"
enum mode { NOP, CREATE, SWITCH, DEFAULT };
#define SYNC 0x1
diff --git a/benchmarks/gem_exec_fault.c b/benchmarks/gem_exec_fault.c
index 4bd05372..a3a0992c 100644
--- a/benchmarks/gem_exec_fault.c
+++ b/benchmarks/gem_exec_fault.c
@@ -41,11 +41,12 @@
#include <time.h>
#include "drm.h"
-#include "ioctl_wrappers.h"
#include "drmtest.h"
+#include "i915/gem.h"
+#include "igt_stats.h"
#include "intel_io.h"
#include "intel_reg.h"
-#include "igt_stats.h"
+#include "ioctl_wrappers.h"
#define ENGINE_FLAGS (I915_EXEC_RING_MASK | I915_EXEC_BSD_MASK)
diff --git a/benchmarks/gem_exec_nop.c b/benchmarks/gem_exec_nop.c
index 0f17d232..c44d3454 100644
--- a/benchmarks/gem_exec_nop.c
+++ b/benchmarks/gem_exec_nop.c
@@ -39,11 +39,12 @@
#include <time.h>
#include "drm.h"
-#include "ioctl_wrappers.h"
#include "drmtest.h"
+#include "i915/gem.h"
+#include "igt_stats.h"
#include "intel_io.h"
#include "intel_reg.h"
-#include "igt_stats.h"
+#include "ioctl_wrappers.h"
#define ENGINE_FLAGS (I915_EXEC_RING_MASK | I915_EXEC_BSD_MASK)
diff --git a/benchmarks/gem_exec_reloc.c b/benchmarks/gem_exec_reloc.c
index a0736b51..abaf9345 100644
--- a/benchmarks/gem_exec_reloc.c
+++ b/benchmarks/gem_exec_reloc.c
@@ -35,12 +35,14 @@
#include <errno.h>
#include <sys/stat.h>
#include <sys/time.h>
+
#include "drm.h"
-#include "intel_reg.h"
-#include "ioctl_wrappers.h"
-#include "igt_debugfs.h"
#include "drmtest.h"
+#include "i915/gem.h"
#include "i915/gem_mman.h"
+#include "igt_debugfs.h"
+#include "intel_reg.h"
+#include "ioctl_wrappers.h"
#define SKIP_RELOC 0x1
#define NO_RELOC 0x2
diff --git a/benchmarks/gem_exec_trace.c b/benchmarks/gem_exec_trace.c
index 2724ee92..e37f6fb7 100644
--- a/benchmarks/gem_exec_trace.c
+++ b/benchmarks/gem_exec_trace.c
@@ -40,10 +40,11 @@
#include <assert.h>
#include "drm.h"
-#include "ioctl_wrappers.h"
#include "drmtest.h"
-#include "intel_io.h"
+#include "i915/gem.h"
#include "igt_stats.h"
+#include "intel_io.h"
+#include "ioctl_wrappers.h"
enum {
ADD_BO = 0,
diff --git a/benchmarks/gem_latency.c b/benchmarks/gem_latency.c
index 774a33d3..9b3d22b7 100644
--- a/benchmarks/gem_latency.c
+++ b/benchmarks/gem_latency.c
@@ -41,8 +41,9 @@
#include <sys/time.h>
#include <sys/poll.h>
#include <sys/resource.h>
-#include "drm.h"
+#include "drm.h"
+#include "i915/gem.h"
#include "igt.h"
#include "igt_device.h"
diff --git a/benchmarks/gem_prw.c b/benchmarks/gem_prw.c
index c2846040..5d3fda9a 100644
--- a/benchmarks/gem_prw.c
+++ b/benchmarks/gem_prw.c
@@ -39,10 +39,11 @@
#include <time.h>
#include "drm.h"
-#include "ioctl_wrappers.h"
#include "drmtest.h"
+#include "i915/gem.h"
#include "igt_aux.h"
#include "igt_stats.h"
+#include "ioctl_wrappers.h"
#define OBJECT_SIZE (1<<23)
diff --git a/benchmarks/gem_set_domain.c b/benchmarks/gem_set_domain.c
index afb410dc..1c9d797c 100644
--- a/benchmarks/gem_set_domain.c
+++ b/benchmarks/gem_set_domain.c
@@ -39,9 +39,10 @@
#include <time.h>
#include "drm.h"
-#include "ioctl_wrappers.h"
#include "drmtest.h"
+#include "i915/gem.h"
#include "igt_aux.h"
+#include "ioctl_wrappers.h"
static double elapsed(const struct timespec *start,
const struct timespec *end)
diff --git a/benchmarks/gem_syslatency.c b/benchmarks/gem_syslatency.c
index 9e57df3a..c10d4f50 100644
--- a/benchmarks/gem_syslatency.c
+++ b/benchmarks/gem_syslatency.c
@@ -44,6 +44,7 @@
#include <linux/unistd.h>
+#include "i915/gem.h"
#include "i915/gem_ring.h"
#define sigev_notify_thread_id _sigev_un._tid
diff --git a/benchmarks/gem_wsim.c b/benchmarks/gem_wsim.c
index 1c0c591e..1b66e63e 100644
--- a/benchmarks/gem_wsim.c
+++ b/benchmarks/gem_wsim.c
@@ -43,21 +43,22 @@
#include <pthread.h>
#include <math.h>
+#include "drm.h"
+#include "drmtest.h"
#include "igt_device_scan.h"
#include "intel_chipset.h"
#include "intel_reg.h"
-#include "drm.h"
#include "ioctl_wrappers.h"
-#include "drmtest.h"
#include "intel_io.h"
#include "igt_aux.h"
#include "igt_rand.h"
#include "igt_perf.h"
#include "sw_sync.h"
-#include "i915/gem_mman.h"
+#include "i915/gem.h"
#include "i915/gem_engine_topology.h"
+#include "i915/gem_mman.h"
enum intel_engine_id {
DEFAULT,
diff --git a/benchmarks/prime_lookup.c b/benchmarks/prime_lookup.c
index d6c39729..b1891756 100644
--- a/benchmarks/prime_lookup.c
+++ b/benchmarks/prime_lookup.c
@@ -37,10 +37,11 @@
#include <time.h>
#include "drm.h"
-#include "ioctl_wrappers.h"
#include "drmtest.h"
-#include "intel_io.h"
+#include "i915/gem.h"
#include "igt_rand.h"
+#include "intel_io.h"
+#include "ioctl_wrappers.h"
#define CLOSE_DEVICE 0x1
diff --git a/lib/Makefile.sources b/lib/Makefile.sources
index 7102f95e..4f6389f8 100644
--- a/lib/Makefile.sources
+++ b/lib/Makefile.sources
@@ -7,6 +7,7 @@ lib_source_list = \
i915/gem.h \
i915/gem_context.c \
i915/gem_context.h \
+ i915/gem_create.c \
i915/gem_engine_topology.c \
i915/gem_engine_topology.h \
i915/gem_scheduler.c \
diff --git a/lib/i915/gem.h b/lib/i915/gem.h
index e5403f09..9178b773 100644
--- a/lib/i915/gem.h
+++ b/lib/i915/gem.h
@@ -25,9 +25,14 @@
#ifndef I915_GEM_H
#define I915_GEM_H
+#include <stdint.h>
+
void igt_require_gem(int i915);
void gem_quiescent_gpu(int i915);
int gem_reopen_driver(int i915);
+int __gem_create(int fd, uint64_t size, uint32_t *handle);
+uint32_t gem_create(int fd, uint64_t size);
+
#endif /* I915_GEM_H */
diff --git a/lib/i915/gem_create.c b/lib/i915/gem_create.c
new file mode 100644
index 00000000..fa2ca1e3
--- /dev/null
+++ b/lib/i915/gem_create.c
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2021 Intel Corporation
+ */
+
+#include <errno.h>
+
+#include "gem.h"
+#include "i915_drm.h"
+#include "igt_core.h"
+#include "ioctl_wrappers.h"
+
+int __gem_create(int fd, uint64_t size, uint32_t *handle)
+{
+ struct drm_i915_gem_create create = {
+ .size = size,
+ };
+ int err = 0;
+
+ if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create) == 0) {
+ *handle = create.handle;
+ } else {
+ err = -errno;
+ igt_assume(err != 0);
+ }
+
+ errno = 0;
+ return err;
+}
+
+/**
+ * gem_create:
+ * @fd: open i915 drm file descriptor
+ * @size: desired size of the buffer
+ *
+ * This wraps the GEM_CREATE ioctl, which allocates a new gem buffer object of
+ * @size.
+ *
+ * Returns: The file-private handle of the created buffer object
+ */
+uint32_t gem_create(int fd, uint64_t size)
+{
+ uint32_t handle;
+
+ igt_assert_eq(__gem_create(fd, size, &handle), 0);
+
+ return handle;
+}
diff --git a/lib/i915/gem_mman.c b/lib/i915/gem_mman.c
index 728f6e96..ab04cbec 100644
--- a/lib/i915/gem_mman.c
+++ b/lib/i915/gem_mman.c
@@ -31,6 +31,7 @@
#include "ioctl_wrappers.h"
#include "intel_chipset.h"
+#include "gem.h"
#include "gem_mman.h"
#ifdef HAVE_VALGRIND
diff --git a/lib/i915/gem_mman.h b/lib/i915/gem_mman.h
index ec2899ff..4a69b259 100644
--- a/lib/i915/gem_mman.h
+++ b/lib/i915/gem_mman.h
@@ -42,10 +42,6 @@ void *gem_mmap__device_coherent(int fd, uint32_t handle, uint64_t offset,
void *gem_mmap__cpu_coherent(int fd, uint32_t handle, uint64_t offset,
uint64_t size, unsigned prot);
-#ifndef I915_GEM_DOMAIN_WC
-#define I915_GEM_DOMAIN_WC 0x80
-#endif
-
bool gem_has_mappable_ggtt(int i915);
void gem_require_mappable_ggtt(int i915);
bool gem_has_mmap_offset(int fd);
diff --git a/lib/igt_draw.c b/lib/igt_draw.c
index 353467a2..949c0d77 100644
--- a/lib/igt_draw.c
+++ b/lib/igt_draw.c
@@ -34,6 +34,7 @@
#include "igt_fb.h"
#include "ioctl_wrappers.h"
#include "i830_reg.h"
+#include "i915/gem.h"
#include "i915/gem_mman.h"
#ifndef PAGE_ALIGN
diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 422a9e06..4b9be47e 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -33,6 +33,8 @@
#include <pixman.h>
#include "drmtest.h"
+#include "i915/gem.h"
+#include "i915/gem_mman.h"
#include "igt_aux.h"
#include "igt_color_encoding.h"
#include "igt_fb.h"
@@ -45,7 +47,6 @@
#include "ioctl_wrappers.h"
#include "intel_batchbuffer.h"
#include "intel_chipset.h"
-#include "i915/gem_mman.h"
#include "intel_bufops.h"
/**
diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
index ead890d1..8118dc94 100644
--- a/lib/intel_batchbuffer.c
+++ b/lib/intel_batchbuffer.c
@@ -35,6 +35,7 @@
#include "drm.h"
#include "drmtest.h"
+#include "i915/gem.h"
#include "intel_batchbuffer.h"
#include "intel_bufmgr.h"
#include "intel_bufops.h"
diff --git a/lib/intel_bufops.c b/lib/intel_bufops.c
index a1e9ba55..a50035e4 100644
--- a/lib/intel_bufops.c
+++ b/lib/intel_bufops.c
@@ -24,6 +24,8 @@
#include <sys/ioctl.h>
#include <cairo.h>
+
+#include "i915/gem.h"
#include "igt.h"
#include "igt_x86.h"
#include "intel_bufops.h"
diff --git a/lib/ioctl_wrappers.c b/lib/ioctl_wrappers.c
index a928f894..45415621 100644
--- a/lib/ioctl_wrappers.c
+++ b/lib/ioctl_wrappers.c
@@ -49,6 +49,7 @@
#include "drmtest.h"
#include "i915_drm.h"
+#include "i915/gem.h"
#include "intel_batchbuffer.h"
#include "intel_chipset.h"
#include "intel_io.h"
@@ -469,43 +470,6 @@ void gem_sync(int fd, uint32_t handle)
errno = 0;
}
-int __gem_create(int fd, uint64_t size, uint32_t *handle)
-{
- struct drm_i915_gem_create create = {
- .size = size,
- };
- int err = 0;
-
- if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create) == 0) {
- *handle = create.handle;
- } else {
- err = -errno;
- igt_assume(err != 0);
- }
-
- errno = 0;
- return err;
-}
-
-/**
- * gem_create:
- * @fd: open i915 drm file descriptor
- * @size: desired size of the buffer
- *
- * This wraps the GEM_CREATE ioctl, which allocates a new gem buffer object of
- * @size.
- *
- * Returns: The file-private handle of the created buffer object
- */
-uint32_t gem_create(int fd, uint64_t size)
-{
- uint32_t handle;
-
- igt_assert_eq(__gem_create(fd, size, &handle), 0);
-
- return handle;
-}
-
/**
* __gem_execbuf:
* @fd: open i915 drm file descriptor
diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h
index 07879ae9..69e19841 100644
--- a/lib/ioctl_wrappers.h
+++ b/lib/ioctl_wrappers.h
@@ -75,8 +75,6 @@ int __gem_set_domain(int fd, uint32_t handle, uint32_t read, uint32_t write);
void gem_set_domain(int fd, uint32_t handle, uint32_t read, uint32_t write);
int gem_wait(int fd, uint32_t handle, int64_t *timeout_ns);
void gem_sync(int fd, uint32_t handle);
-int __gem_create(int fd, uint64_t size, uint32_t *handle);
-uint32_t gem_create(int fd, uint64_t size);
void gem_execbuf_wr(int fd, struct drm_i915_gem_execbuffer2 *execbuf);
int __gem_execbuf_wr(int fd, struct drm_i915_gem_execbuffer2 *execbuf);
void gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf);
diff --git a/lib/meson.build b/lib/meson.build
index 3abc42cb..02ecef53 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -3,6 +3,7 @@ lib_sources = [
'huc_copy.c',
'i915/gem.c',
'i915/gem_context.c',
+ 'i915/gem_create.c',
'i915/gem_engine_topology.c',
'i915/gem_scheduler.c',
'i915/gem_submission.c',
diff --git a/tests/i915/gem_basic.c b/tests/i915/gem_basic.c
index 9f7412f2..984bdf60 100644
--- a/tests/i915/gem_basic.c
+++ b/tests/i915/gem_basic.c
@@ -35,7 +35,9 @@
#include <errno.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
+
#include "drm.h"
+#include "i915/gem.h"
static void
test_bad_close(int fd)
diff --git a/tests/i915/gem_exec_basic.c b/tests/i915/gem_exec_basic.c
index 0d05819c..31f6a234 100644
--- a/tests/i915/gem_exec_basic.c
+++ b/tests/i915/gem_exec_basic.c
@@ -23,6 +23,8 @@
#include "igt.h"
+#include "i915/gem.h"
+
IGT_TEST_DESCRIPTION("Basic sanity check of execbuf-ioctl rings.");
static uint32_t batch_create(int fd)
diff --git a/tests/i915/gem_fd_exhaustion.c b/tests/i915/gem_fd_exhaustion.c
index 23602b98..37c84e6c 100644
--- a/tests/i915/gem_fd_exhaustion.c
+++ b/tests/i915/gem_fd_exhaustion.c
@@ -33,6 +33,8 @@
#include <fcntl.h>
#include <limits.h>
+#include "i915/gem.h"
+
igt_simple_main
{
int fd;
diff --git a/tests/i915/gem_fence_thrash.c b/tests/i915/gem_fence_thrash.c
index 97902890..872dc554 100644
--- a/tests/i915/gem_fence_thrash.c
+++ b/tests/i915/gem_fence_thrash.c
@@ -40,6 +40,7 @@
#include <pthread.h>
#include "drm.h"
+#include "i915/gem.h"
#include "igt.h"
#include "igt_x86.h"
diff --git a/tests/i915/gem_fence_upload.c b/tests/i915/gem_fence_upload.c
index 17580aff..87ed1edf 100644
--- a/tests/i915/gem_fence_upload.c
+++ b/tests/i915/gem_fence_upload.c
@@ -37,8 +37,10 @@
#include <errno.h>
#include <sys/time.h>
#include <pthread.h>
+
#include "drm.h"
#include "i915_drm.h"
+#include "i915/gem.h"
#define OBJECT_SIZE (1024*1024) /* restricted to 1MiB alignment on i915 fences */
diff --git a/tests/i915/gem_flink_race.c b/tests/i915/gem_flink_race.c
index 00363c04..58431b36 100644
--- a/tests/i915/gem_flink_race.c
+++ b/tests/i915/gem_flink_race.c
@@ -32,6 +32,7 @@
#include <pthread.h>
#include <errno.h>
+#include "i915/gem.h"
#include "igt.h"
#include "igt_stats.h"
diff --git a/tests/i915/gem_gtt_cpu_tlb.c b/tests/i915/gem_gtt_cpu_tlb.c
index 0af6a1c4..07f8f1a3 100644
--- a/tests/i915/gem_gtt_cpu_tlb.c
+++ b/tests/i915/gem_gtt_cpu_tlb.c
@@ -40,7 +40,9 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/ioctl.h>
+
#include "drm.h"
+#include "i915/gem.h"
IGT_TEST_DESCRIPTION("Check whether gtt tlbs for cpu access are correctly"
" invalidated.");
diff --git a/tests/i915/gem_gtt_speed.c b/tests/i915/gem_gtt_speed.c
index f0c1954f..06fe70f8 100644
--- a/tests/i915/gem_gtt_speed.c
+++ b/tests/i915/gem_gtt_speed.c
@@ -39,7 +39,9 @@
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/time.h>
+
#include "drm.h"
+#include "i915/gem.h"
#define OBJECT_SIZE 16384
diff --git a/tests/i915/gem_lut_handle.c b/tests/i915/gem_lut_handle.c
index d0c58b8b..f14a9bda 100644
--- a/tests/i915/gem_lut_handle.c
+++ b/tests/i915/gem_lut_handle.c
@@ -36,7 +36,9 @@
#include <errno.h>
#include <sys/stat.h>
#include <sys/time.h>
+
#include "drm.h"
+#include "i915/gem.h"
IGT_TEST_DESCRIPTION("Exercises the basic execbuffer using the handle LUT"
" interface.");
diff --git a/tests/i915/gem_madvise.c b/tests/i915/gem_madvise.c
index 54c9beff..623c8b09 100644
--- a/tests/i915/gem_madvise.c
+++ b/tests/i915/gem_madvise.c
@@ -37,6 +37,7 @@
#include <signal.h>
#include "drm.h"
+#include "i915/gem.h"
IGT_TEST_DESCRIPTION("Checks that the kernel reports EFAULT when trying to use"
" purged bo.");
diff --git a/tests/i915/gem_mmap.c b/tests/i915/gem_mmap.c
index 60a64c13..7c36571c 100644
--- a/tests/i915/gem_mmap.c
+++ b/tests/i915/gem_mmap.c
@@ -35,7 +35,9 @@
#include <errno.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
+
#include "drm.h"
+#include "i915/gem.h"
#define OBJECT_SIZE 16384
#define PAGE_SIZE 4096
diff --git a/tests/i915/gem_mmap_wc.c b/tests/i915/gem_mmap_wc.c
index cd2c8f83..4a2192b3 100644
--- a/tests/i915/gem_mmap_wc.c
+++ b/tests/i915/gem_mmap_wc.c
@@ -36,7 +36,9 @@
#include <errno.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
+
#include "drm.h"
+#include "i915/gem.h"
struct local_i915_gem_mmap_v2 {
uint32_t handle;
diff --git a/tests/i915/gem_pread.c b/tests/i915/gem_pread.c
index d4d022f1..0c4ec0d2 100644
--- a/tests/i915/gem_pread.c
+++ b/tests/i915/gem_pread.c
@@ -41,8 +41,9 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <pthread.h>
-#include "drm.h"
+#include "drm.h"
+#include "i915/gem.h"
#include "igt_vgem.h"
#define MiB(x) ((x) * 1024 * 1024)
diff --git a/tests/i915/gem_pwrite.c b/tests/i915/gem_pwrite.c
index f76d2bc7..98bec558 100644
--- a/tests/i915/gem_pwrite.c
+++ b/tests/i915/gem_pwrite.c
@@ -42,7 +42,7 @@
#include <sys/time.h>
#include "drm.h"
-
+#include "i915/gem.h"
#include "igt.h"
#include "igt_rand.h"
#include "igt_vgem.h"
diff --git a/tests/i915/gem_readwrite.c b/tests/i915/gem_readwrite.c
index 6b2977c1..d675810e 100644
--- a/tests/i915/gem_readwrite.c
+++ b/tests/i915/gem_readwrite.c
@@ -35,7 +35,9 @@
#include <errno.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
+
#include "drm.h"
+#include "i915/gem.h"
#define OBJECT_SIZE 16384
diff --git a/tests/i915/gem_set_tiling_vs_gtt.c b/tests/i915/gem_set_tiling_vs_gtt.c
index cee9c02c..f09022c6 100644
--- a/tests/i915/gem_set_tiling_vs_gtt.c
+++ b/tests/i915/gem_set_tiling_vs_gtt.c
@@ -35,7 +35,9 @@
#include <errno.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
+
#include "drm.h"
+#include "i915/gem.h"
IGT_TEST_DESCRIPTION("Check set_tiling vs gtt mmap coherency.");
diff --git a/tests/i915/gem_set_tiling_vs_pwrite.c b/tests/i915/gem_set_tiling_vs_pwrite.c
index 302ea24b..771dd2e1 100644
--- a/tests/i915/gem_set_tiling_vs_pwrite.c
+++ b/tests/i915/gem_set_tiling_vs_pwrite.c
@@ -35,7 +35,9 @@
#include <errno.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
+
#include "drm.h"
+#include "i915/gem.h"
IGT_TEST_DESCRIPTION("Check set_tiling vs pwrite coherency.");
diff --git a/tests/i915/gem_tiled_pread_basic.c b/tests/i915/gem_tiled_pread_basic.c
index 7cb64410..86271414 100644
--- a/tests/i915/gem_tiled_pread_basic.c
+++ b/tests/i915/gem_tiled_pread_basic.c
@@ -45,8 +45,9 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/ioctl.h>
-#include "drm.h"
+#include "drm.h"
+#include "i915/gem.h"
IGT_TEST_DESCRIPTION("Test pread behavior on tiled objects with respect to the"
" reported swizzling value.");
diff --git a/tests/i915/gem_tiled_pread_pwrite.c b/tests/i915/gem_tiled_pread_pwrite.c
index f58048fa..b73fa126 100644
--- a/tests/i915/gem_tiled_pread_pwrite.c
+++ b/tests/i915/gem_tiled_pread_pwrite.c
@@ -56,8 +56,8 @@
#include <sys/time.h>
#include <sys/ioctl.h>
-#include <drm.h>
-
+#include "drm.h"
+#include "i915/gem.h"
IGT_TEST_DESCRIPTION("Test swizzling by testing pwrite does the inverse of"
" pread.");
diff --git a/tests/i915/gem_tiled_swapping.c b/tests/i915/gem_tiled_swapping.c
index 9e0540ba..1bcf2fa4 100644
--- a/tests/i915/gem_tiled_swapping.c
+++ b/tests/i915/gem_tiled_swapping.c
@@ -56,8 +56,8 @@
#include <sys/ioctl.h>
#include <pthread.h>
-#include <drm.h>
-
+#include "drm.h"
+#include "i915/gem.h"
IGT_TEST_DESCRIPTION("Exercise swizzle code for swapping.");
diff --git a/tests/i915/gem_tiled_wb.c b/tests/i915/gem_tiled_wb.c
index aedec4d4..2ba424e8 100644
--- a/tests/i915/gem_tiled_wb.c
+++ b/tests/i915/gem_tiled_wb.c
@@ -42,7 +42,9 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/ioctl.h>
+
#include "drm.h"
+#include "i915/gem.h"
IGT_TEST_DESCRIPTION("This is a test of write-combining mmap's behavior on"
" tiled objects with respect to the reported swizzling"
diff --git a/tests/i915/gem_tiled_wc.c b/tests/i915/gem_tiled_wc.c
index 3213b5d5..898aad40 100644
--- a/tests/i915/gem_tiled_wc.c
+++ b/tests/i915/gem_tiled_wc.c
@@ -42,7 +42,9 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/ioctl.h>
+
#include "drm.h"
+#include "i915/gem.h"
#define WIDTH 512
#define HEIGHT 512
diff --git a/tests/i915/gem_tiling_max_stride.c b/tests/i915/gem_tiling_max_stride.c
index 77f7223b..4a273441 100644
--- a/tests/i915/gem_tiling_max_stride.c
+++ b/tests/i915/gem_tiling_max_stride.c
@@ -36,7 +36,9 @@
#include <limits.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
+
#include "drm.h"
+#include "i915/gem.h"
IGT_TEST_DESCRIPTION("Check that max fence stride works.");
diff --git a/tests/i915/i915_module_load.c b/tests/i915/i915_module_load.c
index 189fd48b..06522ba6 100644
--- a/tests/i915/i915_module_load.c
+++ b/tests/i915/i915_module_load.c
@@ -21,12 +21,6 @@
* IN THE SOFTWARE.
*/
#include "igt.h"
-#include "igt_debugfs.h"
-#include "igt_aux.h"
-#include "igt_kmod.h"
-#include "igt_sysfs.h"
-#include "igt_core.h"
-
#include <dirent.h>
#include <sys/utsname.h>
#include <linux/limits.h>
@@ -36,6 +30,13 @@
#include <sys/ioctl.h>
#include <fcntl.h>
+#include "i915/gem.h"
+#include "igt_debugfs.h"
+#include "igt_aux.h"
+#include "igt_kmod.h"
+#include "igt_sysfs.h"
+#include "igt_core.h"
+
static void store_all(int fd)
{
const unsigned int gen = intel_gen(intel_get_drm_devid(fd));
diff --git a/tests/kms_available_modes_crc.c b/tests/kms_available_modes_crc.c
index 1c400bbe..17e0f237 100644
--- a/tests/kms_available_modes_crc.c
+++ b/tests/kms_available_modes_crc.c
@@ -24,6 +24,7 @@
#include "drm_mode.h"
#include "drm_fourcc.h"
+#include "i915/gem.h"
#include "igt.h"
IGT_TEST_DESCRIPTION("CRC test all different plane modes which kernel advertises.");
diff --git a/tests/kms_big_fb.c b/tests/kms_big_fb.c
index 8794ace0..5260176e 100644
--- a/tests/kms_big_fb.c
+++ b/tests/kms_big_fb.c
@@ -27,6 +27,8 @@
#include <stdio.h>
#include <string.h>
+#include "i915/gem.h"
+
IGT_TEST_DESCRIPTION("Test big framebuffers");
typedef struct {
diff --git a/tests/kms_ccs.c b/tests/kms_ccs.c
index e89bddaa..c0b02474 100644
--- a/tests/kms_ccs.c
+++ b/tests/kms_ccs.c
@@ -24,6 +24,8 @@
#include "igt.h"
+#include "i915/gem.h"
+
#define SDR_PLANE_BASE 3
IGT_TEST_DESCRIPTION("Test render compression (RC), in which the main surface "
diff --git a/tests/kms_flip.c b/tests/kms_flip.c
index 0f0565cf..e0d009d2 100755
--- a/tests/kms_flip.c
+++ b/tests/kms_flip.c
@@ -42,6 +42,7 @@
#include <time.h>
#include <pthread.h>
+#include "i915/gem.h"
#include "igt_stats.h"
#define TEST_DPMS (1 << 0)
diff --git a/tests/kms_getfb.c b/tests/kms_getfb.c
index c3d3c930..8c59b8a9 100644
--- a/tests/kms_getfb.c
+++ b/tests/kms_getfb.c
@@ -37,9 +37,10 @@
#include <errno.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
+
#include "drm.h"
#include "drm_fourcc.h"
-
+#include "i915/gem.h"
#include "igt_device.h"
IGT_TEST_DESCRIPTION("Tests GETFB and GETFB2 ioctls.");
diff --git a/tests/prime_mmap.c b/tests/prime_mmap.c
index 7c43ced8..cdf2d514 100644
--- a/tests/prime_mmap.c
+++ b/tests/prime_mmap.c
@@ -41,11 +41,12 @@
#include <pthread.h>
#include "drm.h"
-#include "i915_drm.h"
#include "drmtest.h"
+#include "i915_drm.h"
+#include "i915/gem.h"
+#include "i915/gem_mman.h"
#include "igt_debugfs.h"
#include "ioctl_wrappers.h"
-#include "i915/gem_mman.h"
#define BO_SIZE (16*1024)
diff --git a/tests/prime_mmap_kms.c b/tests/prime_mmap_kms.c
index c06d4ab2..6cc1db87 100644
--- a/tests/prime_mmap_kms.c
+++ b/tests/prime_mmap_kms.c
@@ -32,6 +32,8 @@
#include "igt.h"
+#include "i915/gem.h"
+
IGT_TEST_DESCRIPTION(
"Efficiently sharing CPU and GPU buffers");
diff --git a/tests/prime_self_import.c b/tests/prime_self_import.c
index 45b70e81..4a0a9803 100644
--- a/tests/prime_self_import.c
+++ b/tests/prime_self_import.c
@@ -44,6 +44,7 @@
#include <pthread.h>
#include "drm.h"
+#include "i915/gem.h"
IGT_TEST_DESCRIPTION("Check whether prime import/export works on the same"
" device... but with different fds.");
diff --git a/tools/intel_reg.c b/tools/intel_reg.c
index 5f1beba4..da1832be 100644
--- a/tools/intel_reg.c
+++ b/tools/intel_reg.c
@@ -32,6 +32,7 @@
#include <sys/types.h>
#include <unistd.h>
+#include "i915/gem.h"
#include "igt.h"
#include "igt_gt.h"
#include "intel_io.h"