Ville Syrjälä | 918e763 | 2013-04-09 17:45:37 +0300 | [diff] [blame] | 1 | /* |
| 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 Wood | 804e11f | 2015-08-17 17:57:43 +0100 | [diff] [blame] | 28 | #include "igt.h" |
Ville Syrjälä | 918e763 | 2013-04-09 17:45:37 +0300 | [diff] [blame] | 29 | #include <unistd.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <stdio.h> |
| 32 | #include <string.h> |
Ville Syrjälä | 918e763 | 2013-04-09 17:45:37 +0300 | [diff] [blame] | 33 | #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ä | 918e763 | 2013-04-09 17:45:37 +0300 | [diff] [blame] | 39 | #include "drm.h" |
Ville Syrjälä | 918e763 | 2013-04-09 17:45:37 +0300 | [diff] [blame] | 40 | |
Thomas Wood | b2ac264 | 2014-11-28 11:02:44 +0000 | [diff] [blame] | 41 | IGT_TEST_DESCRIPTION("Check that max fence stride works."); |
| 42 | |
Ville Syrjälä | 918e763 | 2013-04-09 17:45:37 +0300 | [diff] [blame] | 43 | static void do_test_invalid_tiling(int fd, uint32_t handle, int tiling, int stride) |
| 44 | { |
Daniel Vetter | 590f610 | 2013-10-09 20:50:50 +0200 | [diff] [blame] | 45 | igt_assert(__gem_set_tiling(fd, handle, tiling, tiling ? stride : 0) == -EINVAL); |
Ville Syrjälä | 918e763 | 2013-04-09 17:45:37 +0300 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static 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 Vetter | dda85fb | 2013-12-10 10:18:32 +0100 | [diff] [blame] | 58 | igt_simple_main |
Ville Syrjälä | 918e763 | 2013-04-09 17:45:37 +0300 | [diff] [blame] | 59 | { |
| 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 Fedke | c81d293 | 2015-07-22 21:54:02 +0000 | [diff] [blame] | 71 | fd = drm_open_driver(DRIVER_INTEL); |
Ville Syrjälä | 918e763 | 2013-04-09 17:45:37 +0300 | [diff] [blame] | 72 | |
| 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 Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 90 | igt_assert(data); |
Ville Syrjälä | 918e763 | 2013-04-09 17:45:37 +0300 | [diff] [blame] | 91 | |
| 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ä | f52e7ec | 2015-10-09 19:11:39 +0300 | [diff] [blame] | 100 | ptr = gem_mmap__gtt(fd, handle, size, PROT_READ | PROT_WRITE); |
Ville Syrjälä | 918e763 | 2013-04-09 17:45:37 +0300 | [diff] [blame] | 101 | |
| 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 Vetter | 8344095 | 2013-08-13 12:35:58 +0200 | [diff] [blame] | 128 | igt_assert(y == data[i]); |
Ville Syrjälä | 918e763 | 2013-04-09 17:45:37 +0300 | [diff] [blame] | 129 | i++; |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | munmap(ptr, size); |
| 135 | |
| 136 | close(fd); |
Ville Syrjälä | 918e763 | 2013-04-09 17:45:37 +0300 | [diff] [blame] | 137 | } |