kms_rotation_crc: Remove useless comments
[platform/upstream/intel-gpu-tools.git] / tests / gem_tiled_pread_pwrite.c
1 /*
2  * Copyright © 2009 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  * Authors:
24  *    Eric Anholt <eric@anholt.net>
25  *
26  */
27
28 /** @file gem_tiled_pread_pwrite.c
29  *
30  * This is a test of pread's behavior on tiled objects with respect to the
31  * reported swizzling value.
32  *
33  * The goal is to exercise the slow_bit17_copy path for reading on bit17
34  * machines, but will also be useful for catching swizzling value bugs on
35  * other systems.
36  */
37
38 /*
39  * Testcase: Test swizzling by testing pwrite does the invers of pread
40  *
41  * Together with the explicit pread testcase, this should cover our swizzle
42  * handling.
43  *
44  * Note that this test will use swap in an effort to test all of ram.
45  */
46
47 #include <stdlib.h>
48 #include <stdio.h>
49 #include <string.h>
50 #include <fcntl.h>
51 #include <inttypes.h>
52 #include <errno.h>
53 #include <sys/stat.h>
54 #include <sys/time.h>
55 #include <sys/ioctl.h>
56
57 #include <drm.h>
58
59 #include "ioctl_wrappers.h"
60 #include "drmtest.h"
61 #include "intel_io.h"
62 #include "igt_aux.h"
63
64 #define WIDTH 512
65 #define HEIGHT 512
66 static uint32_t linear[WIDTH * HEIGHT];
67 static uint32_t current_tiling_mode;
68
69 #define PAGE_SIZE 4096
70
71 static void
72 gem_get_tiling(int fd, uint32_t handle, uint32_t *tiling, uint32_t *swizzle)
73 {
74         struct drm_i915_gem_get_tiling get_tiling;
75         int ret;
76
77         memset(&get_tiling, 0, sizeof(get_tiling));
78         get_tiling.handle = handle;
79
80         ret = drmIoctl(fd, DRM_IOCTL_I915_GEM_GET_TILING, &get_tiling);
81         igt_assert(ret == 0);
82
83         *tiling = get_tiling.tiling_mode;
84         *swizzle = get_tiling.swizzle_mode;
85 }
86
87 static uint32_t
88 create_bo_and_fill(int fd)
89 {
90         uint32_t handle;
91         uint32_t *data;
92         int i;
93
94         handle = gem_create(fd, sizeof(linear));
95         gem_set_tiling(fd, handle, current_tiling_mode, WIDTH * sizeof(uint32_t));
96
97         /* Fill the BO with dwords starting at start_val */
98         data = gem_mmap(fd, handle, sizeof(linear), PROT_READ | PROT_WRITE);
99         for (i = 0; i < WIDTH*HEIGHT; i++)
100                 data[i] = i;
101         munmap(data, sizeof(linear));
102
103         return handle;
104 }
105
106 static uint32_t
107 create_bo(int fd)
108 {
109         uint32_t handle;
110
111         handle = gem_create(fd, sizeof(linear));
112         gem_set_tiling(fd, handle, current_tiling_mode, WIDTH * sizeof(uint32_t));
113
114         return handle;
115 }
116
117 igt_simple_main
118 {
119         int fd;
120         uint32_t *data;
121         int i, j;
122         uint32_t tiling, swizzle;
123         uint32_t handle, handle_target;
124         int count;
125         
126         fd = drm_open_any();
127         count = SLOW_QUICK(intel_get_total_ram_mb() * 9 / 10, 8) ;
128
129         for (i = 0; i < count/2; i++) {
130                 current_tiling_mode = I915_TILING_X;
131
132                 handle = create_bo_and_fill(fd);
133                 gem_get_tiling(fd, handle, &tiling, &swizzle);
134
135                 gem_read(fd, handle, 0, linear, sizeof(linear));
136
137                 handle_target = create_bo(fd);
138                 gem_write(fd, handle_target, 0, linear, sizeof(linear));
139
140                 /* Check the target bo's contents. */
141                 data = gem_mmap(fd, handle_target, sizeof(linear), PROT_READ | PROT_WRITE);
142                 for (j = 0; j < WIDTH*HEIGHT; j++)
143                         igt_assert_f(data[j] == j,
144                                      "mismatch at %i: %i\n",
145                                      j, data[j]);
146                 munmap(data, sizeof(linear));
147
148                 /* Leak both bos so that we use all of system mem! */
149                 gem_madvise(fd, handle_target, I915_MADV_DONTNEED);
150                 gem_madvise(fd, handle, I915_MADV_DONTNEED);
151
152                 igt_progress("gem_tiled_pread_pwrite: ", i, count/2);
153         }
154
155         close(fd);
156 }