blob: a6f97a91518dc7e28b164b255d53a1d9f248bc65 [file] [log] [blame]
Ville Syrjälä918e7632013-04-09 17:45:37 +03001/*
2 * Copyright © 2013 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 * Ville Syrjälä <ville.syrjala@linux.intel.com>
25 *
26 */
27
Thomas Wood804e11f2015-08-17 17:57:43 +010028#include "igt.h"
Ville Syrjälä918e7632013-04-09 17:45:37 +030029#include <unistd.h>
30#include <stdlib.h>
31#include <stdio.h>
32#include <string.h>
Ville Syrjälä918e7632013-04-09 17:45:37 +030033#include <fcntl.h>
34#include <inttypes.h>
35#include <errno.h>
36#include <limits.h>
37#include <sys/stat.h>
38#include <sys/ioctl.h>
Ville Syrjälä918e7632013-04-09 17:45:37 +030039#include "drm.h"
Ville Syrjälä918e7632013-04-09 17:45:37 +030040
Thomas Woodb2ac2642014-11-28 11:02:44 +000041IGT_TEST_DESCRIPTION("Check that max fence stride works.");
42
Ville Syrjälä918e7632013-04-09 17:45:37 +030043static void do_test_invalid_tiling(int fd, uint32_t handle, int tiling, int stride)
44{
Daniel Vetter590f6102013-10-09 20:50:50 +020045 igt_assert(__gem_set_tiling(fd, handle, tiling, tiling ? stride : 0) == -EINVAL);
Ville Syrjälä918e7632013-04-09 17:45:37 +030046}
47
48static void test_invalid_tiling(int fd, uint32_t handle, int stride)
49{
50 do_test_invalid_tiling(fd, handle, I915_TILING_X, stride);
51 do_test_invalid_tiling(fd, handle, I915_TILING_Y, stride);
52}
53
54/**
55 * Testcase: Check that max fence stride works
56 */
57
Daniel Vetterdda85fb2013-12-10 10:18:32 +010058igt_simple_main
Ville Syrjälä918e7632013-04-09 17:45:37 +030059{
60 int fd;
61 uint32_t *ptr;
62 uint32_t *data;
63 uint32_t handle;
64 uint32_t stride;
65 uint32_t size;
66 uint32_t devid;
67 int i = 0, x, y;
68 int tile_width = 512;
69 int tile_height = 8;
70
Micah Fedkec81d2932015-07-22 21:54:02 +000071 fd = drm_open_driver(DRIVER_INTEL);
Ville Syrjälä918e7632013-04-09 17:45:37 +030072
73 devid = intel_get_drm_devid(fd);
74
75 if (intel_gen(devid) >= 7)
76 stride = 256 * 1024;
77 else if (intel_gen(devid) >= 4)
78 stride = 128 * 1024;
79 else {
80 if (IS_GEN2(devid)) {
81 tile_width = 128;
82 tile_height = 16;
83 }
84 stride = 8 * 1024;
85 }
86
87 size = stride * tile_height;
88
89 data = malloc(size);
Daniel Vetter83440952013-08-13 12:35:58 +020090 igt_assert(data);
Ville Syrjälä918e7632013-04-09 17:45:37 +030091
92 /* Fill each line with the line number */
93 for (y = 0; y < tile_height; y++) {
94 for (x = 0; x < stride / 4; x++)
95 data[i++] = y;
96 }
97
98 handle = gem_create(fd, size);
99
Ville Syrjäläf52e7ec2015-10-09 19:11:39 +0300100 ptr = gem_mmap__gtt(fd, handle, size, PROT_READ | PROT_WRITE);
Ville Syrjälä918e7632013-04-09 17:45:37 +0300101
102 test_invalid_tiling(fd, handle, 0);
103 test_invalid_tiling(fd, handle, 64);
104 test_invalid_tiling(fd, handle, stride - 1);
105 test_invalid_tiling(fd, handle, stride + 1);
106 test_invalid_tiling(fd, handle, stride + 127);
107 test_invalid_tiling(fd, handle, stride + 128);
108 test_invalid_tiling(fd, handle, stride + tile_width - 1);
109 test_invalid_tiling(fd, handle, stride + tile_width);
110 test_invalid_tiling(fd, handle, stride * 2);
111 test_invalid_tiling(fd, handle, INT_MAX);
112 test_invalid_tiling(fd, handle, UINT_MAX);
113
114 gem_set_tiling(fd, handle, I915_TILING_X, stride);
115
116 gem_set_domain(fd, handle, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
117
118 memcpy(ptr, data, size);
119
120 gem_set_tiling(fd, handle, I915_TILING_NONE, 0);
121
122 memcpy(data, ptr, size);
123
124 /* Check that each tile contains the expected pattern */
125 for (i = 0; i < size / 4; ) {
126 for (y = 0; y < tile_height; y++) {
127 for (x = 0; x < tile_width / 4; x++) {
Daniel Vetter83440952013-08-13 12:35:58 +0200128 igt_assert(y == data[i]);
Ville Syrjälä918e7632013-04-09 17:45:37 +0300129 i++;
130 }
131 }
132 }
133
134 munmap(ptr, size);
135
136 close(fd);
Ville Syrjälä918e7632013-04-09 17:45:37 +0300137}