lib/igt.cocci: Add s/assert/igt_assert/
[platform/upstream/intel-gpu-tools.git] / tests / gem_pwrite_pread.c
index 00eaa55..c2dc74b 100644 (file)
 #include <sys/ioctl.h>
 #include <sys/time.h>
 #include "drm.h"
-#include "i915_drm.h"
+#include "ioctl_wrappers.h"
 #include "drmtest.h"
+#include "intel_chipset.h"
 #include "intel_bufmgr.h"
 #include "intel_batchbuffer.h"
-#include "intel_gpu_tools.h"
+#include "intel_io.h"
 
 #define OBJECT_SIZE 16384
 
@@ -64,43 +65,42 @@ static inline void build_batch(uint32_t *batch, int len, uint32_t *batch_len)
        batch[i++] = 1 << 16 | (len / 4);
        batch[i++] = 0; /* dst */
        if (is_64bit)
-               batch[i++] = 0; /* FIXME */
+               batch[i++] = 0;
        batch[i++] = 0;
        batch[i++] = len;
        batch[i++] = 0; /* src */
        if (is_64bit)
-               batch[i++] = 0; /* FIXME */
+               batch[i++] = 0;
        batch[i++] = MI_BATCH_BUFFER_END;
        batch[i++] = 0;
 
        *batch_len = i * 4;
 }
 
-#define GPP_BATCH_SIZE (12 * 4)
+#define BUILD_EXEC \
+       uint32_t batch[12]; \
+       struct drm_i915_gem_relocation_entry reloc[] = { \
+               { dst, 0, 4*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER }, \
+               { src, 0, (is_64bit ? 8 : 7)*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, 0 }, \
+       }; \
+       struct drm_i915_gem_exec_object2 exec[] = { \
+               { src }, \
+               { dst }, \
+               { gem_create(fd, 4096), 2, (uintptr_t)reloc } \
+       }; \
+       struct drm_i915_gem_execbuffer2 execbuf = { \
+               (uintptr_t)exec, 3, \
+               0, 0, \
+               0, 0, 0, 0, \
+               exec_flags, \
+       }; \
+       build_batch(batch, len, &execbuf.batch_len); \
+       gem_write(fd, exec[2].handle, 0, batch, execbuf.batch_len);
+
 
 static void copy(int fd, uint32_t src, uint32_t dst, void *buf, int len, int loops)
 {
-       uint32_t batch[GPP_BATCH_SIZE] = {0};
-
-       struct drm_i915_gem_relocation_entry reloc[] = {
-               { dst, 0, 4*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER },
-               { src, 0, (is_64bit ? 8 : 7)*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, 0 },
-       };
-       struct drm_i915_gem_exec_object2 exec[] = {
-               { src },
-               { dst },
-               { gem_create(fd, 4096), 2, (uintptr_t)reloc }
-       };
-       struct drm_i915_gem_execbuffer2 execbuf = {
-               (uintptr_t)exec, 3,
-               0, 0,
-               0, 0, 0, 0,
-               exec_flags,
-       };
-
-       build_batch(batch, len, &execbuf.batch_len);
-
-       gem_write(fd, exec[2].handle, 0, batch, execbuf.batch_len);
+       BUILD_EXEC;
 
        while (loops--) {
                gem_write(fd, src, 0, buf, len);
@@ -113,28 +113,8 @@ static void copy(int fd, uint32_t src, uint32_t dst, void *buf, int len, int loo
 
 static void as_gtt_mmap(int fd, uint32_t src, uint32_t dst, void *buf, int len, int loops)
 {
-       uint32_t batch[GPP_BATCH_SIZE] = {0};
-
-       struct drm_i915_gem_relocation_entry reloc[] = {
-               { dst, 0, 4*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER },
-               { src, 0, 7*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, 0 },
-       };
-       struct drm_i915_gem_exec_object2 exec[] = {
-               { src },
-               { dst },
-               { gem_create(fd, 4096), 2, (uintptr_t)reloc }
-       };
-       struct drm_i915_gem_execbuffer2 execbuf = {
-               (uintptr_t)exec, 3,
-               0, GPP_BATCH_SIZE,
-               0, 0, 0, 0,
-               exec_flags,
-       };
        uint32_t *src_ptr, *dst_ptr;
-
-       build_batch(batch, len, &execbuf.batch_len);
-
-       gem_write(fd, exec[2].handle, 0, batch, execbuf.batch_len);
+       BUILD_EXEC;
 
        src_ptr = gem_mmap__gtt(fd, src, OBJECT_SIZE, PROT_WRITE);
        dst_ptr = gem_mmap__gtt(fd, dst, OBJECT_SIZE, PROT_READ);
@@ -158,28 +138,8 @@ static void as_gtt_mmap(int fd, uint32_t src, uint32_t dst, void *buf, int len,
 
 static void as_cpu_mmap(int fd, uint32_t src, uint32_t dst, void *buf, int len, int loops)
 {
-       uint32_t batch[GPP_BATCH_SIZE] = {0};
-
-       struct drm_i915_gem_relocation_entry reloc[] = {
-               { dst, 0, 4*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER },
-               { src, 0, 7*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, 0 },
-       };
-       struct drm_i915_gem_exec_object2 exec[] = {
-               { src },
-               { dst },
-               { gem_create(fd, 4096), 2, (uintptr_t)reloc }
-       };
-       struct drm_i915_gem_execbuffer2 execbuf = {
-               (uintptr_t)exec, 3,
-               0, GPP_BATCH_SIZE,
-               0, 0, 0, 0,
-               exec_flags,
-       };
        uint32_t *src_ptr, *dst_ptr;
-
-       build_batch(batch, len, &execbuf.batch_len);
-
-       gem_write(fd, exec[2].handle, 0, batch, execbuf.batch_len);
+       BUILD_EXEC;
 
        src_ptr = gem_mmap__cpu(fd, src, OBJECT_SIZE, PROT_WRITE);
        dst_ptr = gem_mmap__cpu(fd, dst, OBJECT_SIZE, PROT_READ);
@@ -202,28 +162,8 @@ static void as_cpu_mmap(int fd, uint32_t src, uint32_t dst, void *buf, int len,
 
 static void test_copy(int fd, uint32_t src, uint32_t dst, uint32_t *buf, int len)
 {
-       uint32_t batch[GPP_BATCH_SIZE] = {0};
-
-       struct drm_i915_gem_relocation_entry reloc[] = {
-               { dst, 0, 4*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER },
-               { src, 0, 7*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, 0 },
-       };
-       struct drm_i915_gem_exec_object2 exec[] = {
-               { src },
-               { dst },
-               { gem_create(fd, 4096), 2, (uintptr_t)reloc }
-       };
-       struct drm_i915_gem_execbuffer2 execbuf = {
-               (uintptr_t)exec, 3,
-               0, GPP_BATCH_SIZE,
-               0, 0, 0, 0,
-               exec_flags,
-       };
        int i;
-
-       build_batch(batch, len, &execbuf.batch_len);
-
-       gem_write(fd, exec[2].handle, 0, batch, execbuf.batch_len);
+       BUILD_EXEC;
 
        for (i = 0; i < len/4; i++)
                buf[i] = i;
@@ -242,29 +182,9 @@ static void test_copy(int fd, uint32_t src, uint32_t dst, uint32_t *buf, int len
 
 static void test_as_gtt_mmap(int fd, uint32_t src, uint32_t dst, int len)
 {
-       uint32_t batch[GPP_BATCH_SIZE] = {0};
-
-       struct drm_i915_gem_relocation_entry reloc[] = {
-               { dst, 0, 4*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER },
-               { src, 0, 7*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, 0 },
-       };
-       struct drm_i915_gem_exec_object2 exec[] = {
-               { src },
-               { dst },
-               { gem_create(fd, 4096), 2, (uintptr_t)reloc }
-       };
-       struct drm_i915_gem_execbuffer2 execbuf = {
-               (uintptr_t)exec, 3,
-               0, GPP_BATCH_SIZE,
-               0, 0, 0, 0,
-               exec_flags,
-       };
        uint32_t *src_ptr, *dst_ptr;
        int i;
-
-       build_batch(batch, len, &execbuf.batch_len);
-
-       gem_write(fd, exec[2].handle, 0, batch, execbuf.batch_len);
+       BUILD_EXEC;
 
        src_ptr = gem_mmap__gtt(fd, src, OBJECT_SIZE, PROT_WRITE);
        dst_ptr = gem_mmap__gtt(fd, dst, OBJECT_SIZE, PROT_READ);
@@ -286,29 +206,9 @@ static void test_as_gtt_mmap(int fd, uint32_t src, uint32_t dst, int len)
 
 static void test_as_cpu_mmap(int fd, uint32_t src, uint32_t dst, int len)
 {
-       uint32_t batch[GPP_BATCH_SIZE] = {0};
-
-       struct drm_i915_gem_relocation_entry reloc[] = {
-               { dst, 0, 4*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER },
-               { src, 0, 7*sizeof(uint32_t), 0, I915_GEM_DOMAIN_RENDER, 0 },
-       };
-       struct drm_i915_gem_exec_object2 exec[] = {
-               { src },
-               { dst },
-               { gem_create(fd, 4096), 2, (uintptr_t)reloc }
-       };
-       struct drm_i915_gem_execbuffer2 execbuf = {
-               (uintptr_t)exec, 3,
-               0, GPP_BATCH_SIZE,
-               0, 0, 0, 0,
-               exec_flags,
-       };
        uint32_t *src_ptr, *dst_ptr;
        int i;
-
-       build_batch(batch, len, &execbuf.batch_len);
-
-       gem_write(fd, exec[2].handle, 0, batch, execbuf.batch_len);
+       BUILD_EXEC;
 
        src_ptr = gem_mmap__cpu(fd, src, OBJECT_SIZE, PROT_WRITE);
        dst_ptr = gem_mmap__cpu(fd, dst, OBJECT_SIZE, PROT_READ);
@@ -398,10 +298,10 @@ int main(int argc, char **argv)
                        gettimeofday(&start, NULL);
                        copy(fd, src, dst, tmp, object_size, count);
                        gettimeofday(&end, NULL);
-                       printf("Time to uncached copy %d bytes x %6d:   %7.3fµs, %s\n",
-                              object_size, count,
-                              elapsed(&start, &end, count),
-                              bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
+                       igt_info("Time to uncached copy %d bytes x %6d: %7.3fµs, %s\n",
+                                object_size, count,
+                                elapsed(&start, &end, count),
+                                bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
                        fflush(stdout);
                }
        }
@@ -415,10 +315,10 @@ int main(int argc, char **argv)
                        gettimeofday(&start, NULL);
                        as_gtt_mmap(fd, src, dst, tmp, object_size, count);
                        gettimeofday(&end, NULL);
-                       printf("** mmap uncached copy %d bytes x %6d:   %7.3fµs, %s\n",
-                              object_size, count,
-                              elapsed(&start, &end, count),
-                              bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
+                       igt_info("** mmap uncached copy %d bytes x %6d: %7.3fµs, %s\n",
+                                object_size, count,
+                                elapsed(&start, &end, count),
+                                bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
                        fflush(stdout);
                }
        }
@@ -437,10 +337,10 @@ int main(int argc, char **argv)
                        gettimeofday(&start, NULL);
                        copy(fd, src, dst, tmp, object_size, count);
                        gettimeofday(&end, NULL);
-                       printf("Time to snooped copy %d bytes x %6d:    %7.3fµs, %s\n",
-                              object_size, count,
-                              elapsed(&start, &end, count),
-                              bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
+                       igt_info("Time to snooped copy %d bytes x %6d:  %7.3fµs, %s\n",
+                                object_size, count,
+                                elapsed(&start, &end, count),
+                                bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
                        fflush(stdout);
                }
        }
@@ -454,10 +354,10 @@ int main(int argc, char **argv)
                        gettimeofday(&start, NULL);
                        as_cpu_mmap(fd, src, dst, tmp, object_size, count);
                        gettimeofday(&end, NULL);
-                       printf("** mmap snooped copy %d bytes x %6d:    %7.3fµs, %s\n",
-                              object_size, count,
-                              elapsed(&start, &end, count),
-                              bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
+                       igt_info("** mmap snooped copy %d bytes x %6d:  %7.3fµs, %s\n",
+                                object_size, count,
+                                elapsed(&start, &end, count),
+                                bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
                        fflush(stdout);
                }
        }
@@ -476,10 +376,10 @@ int main(int argc, char **argv)
                        gettimeofday(&start, NULL);
                        copy(fd, src, dst, tmp, object_size, count);
                        gettimeofday(&end, NULL);
-                       printf("Time to display copy %d bytes x %6d:    %7.3fµs, %s\n",
-                              object_size, count,
-                              elapsed(&start, &end, count),
-                              bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
+                       igt_info("Time to display copy %d bytes x %6d:  %7.3fµs, %s\n",
+                                object_size, count,
+                                elapsed(&start, &end, count),
+                                bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
                        fflush(stdout);
                }
        }
@@ -493,10 +393,10 @@ int main(int argc, char **argv)
                        gettimeofday(&start, NULL);
                        as_gtt_mmap(fd, src, dst, tmp, object_size, count);
                        gettimeofday(&end, NULL);
-                       printf("** mmap display copy %d bytes x %6d:    %7.3fµs, %s\n",
-                              object_size, count,
-                              elapsed(&start, &end, count),
-                              bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
+                       igt_info("** mmap display copy %d bytes x %6d:  %7.3fµs, %s\n",
+                                object_size, count,
+                                elapsed(&start, &end, count),
+                                bytes_per_sec((char *)buf, object_size/elapsed(&start, &end, count)*1e6));
                        fflush(stdout);
                }
        }